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 
9 #include "PassDetail.h"
10 #include "mlir/IR/BuiltinOps.h"
11 #include "mlir/IR/Operation.h"
12 #include "mlir/Pass/Pass.h"
13 #include "mlir/Transforms/Passes.h"
14 
15 using namespace mlir;
16 
17 namespace {
18 struct StripDebugInfo : public StripDebugInfoBase<StripDebugInfo> {
19  void runOnOperation() override;
20 };
21 } // namespace
22 
23 void StripDebugInfo::runOnOperation() {
24  auto unknownLoc = UnknownLoc::get(&getContext());
25 
26  // Strip the debug info from all operations.
27  getOperation()->walk([&](Operation *op) {
28  op->setLoc(unknownLoc);
29  // Strip block arguments debug info.
30  for (Region &region : op->getRegions()) {
31  for (Block &block : region.getBlocks()) {
32  for (BlockArgument &arg : block.getArguments()) {
33  arg.setLoc(unknownLoc);
34  }
35  }
36  }
37  });
38 }
39 
40 /// Creates a pass to strip debug information from a function.
41 std::unique_ptr<Pass> mlir::createStripDebugInfoPass() {
42  return std::make_unique<StripDebugInfo>();
43 }
Include the generated interface declarations.
This class contains a list of basic blocks and a link to the parent operation it is attached to...
Definition: Region.h:26
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
Definition: Operation.h:480
Block represents an ordered list of Operations.
Definition: Block.h:29
This class represents an argument of a Block.
Definition: Value.h:300
void setLoc(Location loc)
Set the source location the operation was defined or derived from.
Definition: Operation.h:157
std::unique_ptr< Pass > createStripDebugInfoPass()
Creates a pass to strip debug information from a function.