MLIR 22.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/Operation.h"
12#include "mlir/Pass/Pass.h"
13
14namespace mlir {
15#define GEN_PASS_DEF_STRIPDEBUGINFO
16#include "mlir/Transforms/Passes.h.inc"
17} // namespace mlir
18
19using namespace mlir;
20
21namespace {
22struct StripDebugInfo : public impl::StripDebugInfoBase<StripDebugInfo> {
23 void runOnOperation() override;
24};
25} // namespace
26
27void StripDebugInfo::runOnOperation() {
28 auto unknownLoc = UnknownLoc::get(&getContext());
29
30 // Strip the debug info from all operations.
31 getOperation()->walk([&](Operation *op) {
32 op->setLoc(unknownLoc);
33 // Strip block arguments debug info.
34 for (Region &region : op->getRegions()) {
35 for (Block &block : region.getBlocks()) {
36 for (BlockArgument &arg : block.getArguments()) {
37 arg.setLoc(unknownLoc);
38 }
39 }
40 }
41 });
42}
43
44/// Creates a pass to strip debug information from a function.
45std::unique_ptr<Pass> mlir::createStripDebugInfoPass() {
46 return std::make_unique<StripDebugInfo>();
47}
b getContext())
void setLoc(Location loc)
Set the source location the operation was defined or derived from.
Definition Operation.h:226
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
Definition Operation.h:677
Include the generated interface declarations.
std::unique_ptr< Pass > createStripDebugInfoPass()
Creates a pass to strip debug information from a function.