MLIR  16.0.0git
StripDebugInfo.cpp
Go to the documentation of this file.
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 
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 &region : 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 }
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:31
void setLoc(Location loc)
Set the source location the operation was defined or derived from.
Definition: Operation.h:157
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
Definition: Operation.h:480
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
Include the generated interface declarations.
std::unique_ptr< Pass > createStripDebugInfoPass()
Creates a pass to strip debug information from a function.