1 //===- StripDebugInfo.cpp - Pass to strip debug information ---------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Transforms/Passes.h"
11 #include "mlir/IR/BuiltinOps.h"
12 #include "mlir/IR/Operation.h"
13 #include "mlir/Pass/Pass.h"
16 #define GEN_PASS_DEF_STRIPDEBUGINFO
17 #include "mlir/Transforms/Passes.h.inc"
23 struct StripDebugInfo
: public impl::StripDebugInfoBase
<StripDebugInfo
> {
24 void runOnOperation() override
;
28 void StripDebugInfo::runOnOperation() {
29 auto unknownLoc
= UnknownLoc::get(&getContext());
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
);
45 /// Creates a pass to strip debug information from a function.
46 std::unique_ptr
<Pass
> mlir::createStripDebugInfoPass() {
47 return std::make_unique
<StripDebugInfo
>();