IR: de-duplicate two CmpInst routines (NFC) (#116866)
[llvm-project.git] / mlir / lib / Transforms / StripDebugInfo.cpp
blob87f5f76d3d432a3f1d485f1396a454cc789fcf4a
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 //===----------------------------------------------------------------------===//
9 #include "mlir/Transforms/Passes.h"
11 #include "mlir/IR/BuiltinOps.h"
12 #include "mlir/IR/Operation.h"
13 #include "mlir/Pass/Pass.h"
15 namespace mlir {
16 #define GEN_PASS_DEF_STRIPDEBUGINFO
17 #include "mlir/Transforms/Passes.h.inc"
18 } // namespace mlir
20 using namespace mlir;
22 namespace {
23 struct StripDebugInfo : public impl::StripDebugInfoBase<StripDebugInfo> {
24 void runOnOperation() override;
26 } // namespace
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 &region : op->getRegions()) {
36 for (Block &block : region.getBlocks()) {
37 for (BlockArgument &arg : block.getArguments()) {
38 arg.setLoc(unknownLoc);
42 });
45 /// Creates a pass to strip debug information from a function.
46 std::unique_ptr<Pass> mlir::createStripDebugInfoPass() {
47 return std::make_unique<StripDebugInfo>();