llvm-project
48 строк · 1.4 Кб
1//===- StripDebugInfo.cpp - Pass to strip debug information ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "mlir/Transforms/Passes.h"10
11#include "mlir/IR/BuiltinOps.h"12#include "mlir/IR/Operation.h"13#include "mlir/Pass/Pass.h"14
15namespace mlir {16#define GEN_PASS_DEF_STRIPDEBUGINFO17#include "mlir/Transforms/Passes.h.inc"18} // namespace mlir19
20using namespace mlir;21
22namespace {23struct StripDebugInfo : public impl::StripDebugInfoBase<StripDebugInfo> {24void runOnOperation() override;25};26} // namespace27
28void StripDebugInfo::runOnOperation() {29auto unknownLoc = UnknownLoc::get(&getContext());30
31// Strip the debug info from all operations.32getOperation()->walk([&](Operation *op) {33op->setLoc(unknownLoc);34// Strip block arguments debug info.35for (Region ®ion : op->getRegions()) {36for (Block &block : region.getBlocks()) {37for (BlockArgument &arg : block.getArguments()) {38arg.setLoc(unknownLoc);39}40}41}42});43}
44
45/// Creates a pass to strip debug information from a function.
46std::unique_ptr<Pass> mlir::createStripDebugInfoPass() {47return std::make_unique<StripDebugInfo>();48}
49