2019-01-24 12:48:23 +08:00
|
|
|
//===- StripDebugInfo.cpp - Pass to strip debug information ---------------===//
|
|
|
|
//
|
2020-01-26 11:58:30 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-24 01:35:36 +08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-01-24 12:48:23 +08:00
|
|
|
//
|
2019-12-24 01:35:36 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-01-24 12:48:23 +08:00
|
|
|
|
2020-04-08 04:58:12 +08:00
|
|
|
#include "PassDetail.h"
|
2020-11-20 02:43:12 +08:00
|
|
|
#include "mlir/IR/BuiltinOps.h"
|
2019-03-27 05:45:38 +08:00
|
|
|
#include "mlir/IR/Operation.h"
|
2019-02-20 09:17:46 +08:00
|
|
|
#include "mlir/Pass/Pass.h"
|
2019-01-24 12:48:23 +08:00
|
|
|
#include "mlir/Transforms/Passes.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
namespace {
|
2020-04-08 04:58:12 +08:00
|
|
|
struct StripDebugInfo : public StripDebugInfoBase<StripDebugInfo> {
|
2020-02-06 09:10:55 +08:00
|
|
|
void runOnOperation() override;
|
2019-01-24 12:48:23 +08:00
|
|
|
};
|
2021-12-08 02:27:58 +08:00
|
|
|
} // namespace
|
2019-01-24 12:48:23 +08:00
|
|
|
|
2020-02-06 09:10:55 +08:00
|
|
|
void StripDebugInfo::runOnOperation() {
|
2019-06-26 07:57:32 +08:00
|
|
|
auto unknownLoc = UnknownLoc::get(&getContext());
|
2021-05-27 01:28:45 +08:00
|
|
|
|
|
|
|
// Strip the debug info from all operations.
|
|
|
|
getOperation()->walk([&](Operation *op) {
|
|
|
|
op->setLoc(unknownLoc);
|
|
|
|
// Strip block arguments debug info.
|
|
|
|
for (Region ®ion : op->getRegions()) {
|
|
|
|
for (Block &block : region.getBlocks()) {
|
|
|
|
for (BlockArgument &arg : block.getArguments()) {
|
|
|
|
arg.setLoc(unknownLoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-01-24 12:48:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a pass to strip debug information from a function.
|
2020-02-06 09:10:55 +08:00
|
|
|
std::unique_ptr<Pass> mlir::createStripDebugInfoPass() {
|
2019-08-18 02:05:35 +08:00
|
|
|
return std::make_unique<StripDebugInfo>();
|
2019-02-28 02:59:29 +08:00
|
|
|
}
|