48 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Transforms/Passes.h"10 11#include "mlir/IR/Operation.h"12#include "mlir/Pass/Pass.h"13 14namespace mlir {15#define GEN_PASS_DEF_STRIPDEBUGINFO16#include "mlir/Transforms/Passes.h.inc"17} // namespace mlir18 19using namespace mlir;20 21namespace {22struct StripDebugInfo : public impl::StripDebugInfoBase<StripDebugInfo> {23 void runOnOperation() override;24};25} // namespace26 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 ®ion : 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}48