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 | |
15 | namespace mlir { |
16 | #define GEN_PASS_DEF_STRIPDEBUGINFO |
17 | #include "mlir/Transforms/Passes.h.inc" |
18 | } // namespace mlir |
19 | |
20 | using namespace mlir; |
21 | |
22 | namespace { |
23 | struct StripDebugInfo : public impl::StripDebugInfoBase<StripDebugInfo> { |
24 | void runOnOperation() override; |
25 | }; |
26 | } // namespace |
27 | |
28 | void StripDebugInfo::runOnOperation() { |
29 | auto unknownLoc = UnknownLoc::get(&getContext()); |
30 | |
31 | // Strip the debug info from all operations. |
32 | getOperation()->walk([&](Operation *op) { |
33 | op->setLoc(unknownLoc); |
34 | // Strip block arguments debug info. |
35 | for (Region ®ion : op->getRegions()) { |
36 | for (Block &block : region.getBlocks()) { |
37 | for (BlockArgument &arg : block.getArguments()) { |
38 | arg.setLoc(unknownLoc); |
39 | } |
40 | } |
41 | } |
42 | }); |
43 | } |
44 | |
45 | /// Creates a pass to strip debug information from a function. |
46 | std::unique_ptr<Pass> mlir::createStripDebugInfoPass() { |
47 | return std::make_unique<StripDebugInfo>(); |
48 | } |
49 | |