1f319bbbdSRiver Riddle //===- StripDebugInfo.cpp - Pass to strip debug information ---------------===// 2f319bbbdSRiver Riddle // 330857107SMehdi Amini // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 456222a06SMehdi Amini // See https://llvm.org/LICENSE.txt for license information. 556222a06SMehdi Amini // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6f319bbbdSRiver Riddle // 756222a06SMehdi Amini //===----------------------------------------------------------------------===// 8f319bbbdSRiver Riddle 9*67d0d7acSMichele Scuttari #include "mlir/Transforms/Passes.h" 10*67d0d7acSMichele Scuttari 1165fcddffSRiver Riddle #include "mlir/IR/BuiltinOps.h" 129ffdc930SRiver Riddle #include "mlir/IR/Operation.h" 1348ccae24SRiver Riddle #include "mlir/Pass/Pass.h" 14*67d0d7acSMichele Scuttari 15*67d0d7acSMichele Scuttari namespace mlir { 16*67d0d7acSMichele Scuttari #define GEN_PASS_DEF_STRIPDEBUGINFO 17*67d0d7acSMichele Scuttari #include "mlir/Transforms/Passes.h.inc" 18*67d0d7acSMichele Scuttari } // namespace mlir 19f319bbbdSRiver Riddle 20f319bbbdSRiver Riddle using namespace mlir; 21f319bbbdSRiver Riddle 22f319bbbdSRiver Riddle namespace { 23*67d0d7acSMichele Scuttari struct StripDebugInfo : public impl::StripDebugInfoBase<StripDebugInfo> { 24c33d6970SRiver Riddle void runOnOperation() override; 25f319bbbdSRiver Riddle }; 26be0a7e9fSMehdi Amini } // namespace 27f319bbbdSRiver Riddle runOnOperation()28039b969bSMichele Scuttarivoid StripDebugInfo::runOnOperation() { 2949162524SRiver Riddle auto unknownLoc = UnknownLoc::get(&getContext()); 30e5eff533Sthomasraoux 31e5eff533Sthomasraoux // Strip the debug info from all operations. 32e5eff533Sthomasraoux getOperation()->walk([&](Operation *op) { 33e5eff533Sthomasraoux op->setLoc(unknownLoc); 34e5eff533Sthomasraoux // Strip block arguments debug info. 35e5eff533Sthomasraoux for (Region ®ion : op->getRegions()) { 36e5eff533Sthomasraoux for (Block &block : region.getBlocks()) { 37e5eff533Sthomasraoux for (BlockArgument &arg : block.getArguments()) { 38e5eff533Sthomasraoux arg.setLoc(unknownLoc); 39e5eff533Sthomasraoux } 40e5eff533Sthomasraoux } 41e5eff533Sthomasraoux } 42e5eff533Sthomasraoux }); 43f319bbbdSRiver Riddle } 44039b969bSMichele Scuttari 45039b969bSMichele Scuttari /// Creates a pass to strip debug information from a function. createStripDebugInfoPass()46039b969bSMichele Scuttaristd::unique_ptr<Pass> mlir::createStripDebugInfoPass() { 47039b969bSMichele Scuttari return std::make_unique<StripDebugInfo>(); 48039b969bSMichele Scuttari } 49