1 //===- StripDebugInfo.cpp - Pass to strip debug information ---------------===// 2 // 3 // Part of the MLIR 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 "mlir/IR/Function.h" 10 #include "mlir/IR/Operation.h" 11 #include "mlir/Pass/Pass.h" 12 #include "mlir/Transforms/Passes.h" 13 14 using namespace mlir; 15 16 namespace { 17 struct StripDebugInfo : public FunctionPass<StripDebugInfo> { 18 void runOnFunction() override; 19 }; 20 } // end anonymous namespace 21 22 void StripDebugInfo::runOnFunction() { 23 FuncOp func = getFunction(); 24 auto unknownLoc = UnknownLoc::get(&getContext()); 25 26 // Strip the debug info from the function and its operations. 27 func.setLoc(unknownLoc); 28 func.walk([&](Operation *op) { op->setLoc(unknownLoc); }); 29 } 30 31 /// Creates a pass to strip debug information from a function. 32 std::unique_ptr<OpPassBase<FuncOp>> mlir::createStripDebugInfoPass() { 33 return std::make_unique<StripDebugInfo>(); 34 } 35 36 static PassRegistration<StripDebugInfo> 37 pass("strip-debuginfo", "Strip debug info from functions and operations"); 38