Add a function pass to strip debug info from functions and instructions.

PiperOrigin-RevId: 230654315
This commit is contained in:
River Riddle 2019-01-23 20:48:23 -08:00 committed by jpienaar
parent 98c729d6f1
commit f319bbbd28
3 changed files with 76 additions and 0 deletions

View File

@ -100,6 +100,9 @@ FunctionPass *createLowerVectorTransfersPass();
/// store to load forwarding, elimination of dead stores, and dead allocs.
FunctionPass *createMemRefDataFlowOptPass();
/// Creates a pass to strip debug information from a function.
FunctionPass *createStripDebugInfoPass();
} // end namespace mlir
#endif // MLIR_TRANSFORMS_PASSES_H

View File

@ -0,0 +1,50 @@
//===- StripDebugInfo.cpp - Pass to strip debug information ---------------===//
//
// Copyright 2019 The MLIR Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
#include "mlir/IR/Function.h"
#include "mlir/Pass.h"
#include "mlir/Transforms/Passes.h"
using namespace mlir;
namespace {
struct StripDebugInfo : public FunctionPass {
StripDebugInfo() : FunctionPass(&StripDebugInfo::passID) {}
PassResult runOnFunction(Function *f) override;
static char passID;
};
} // end anonymous namespace
char StripDebugInfo::passID = 0;
PassResult StripDebugInfo::runOnFunction(Function *f) {
UnknownLoc unknownLoc = UnknownLoc::get(f->getContext());
// Strip the debug info from the function and its instructions.
f->setLoc(unknownLoc);
f->walkInsts([&](Instruction *inst) { inst->setLoc(unknownLoc); });
return success();
}
/// Creates a pass to strip debug information from a function.
FunctionPass *mlir::createStripDebugInfoPass() { return new StripDebugInfo(); }
static PassRegistration<StripDebugInfo>
pass("strip-debug-info",
"Strip debug info from functions and instructions");

View File

@ -0,0 +1,23 @@
// RUN: mlir-opt %s -mlir-print-debuginfo -strip-debug-info | FileCheck %s
// This test verifies that debug locations are stripped.
#set0 = (d0) : (1 == 0)
// CHECK-LABEL: inline_notation
// CHECK: () -> i32 loc(unknown) {
func @inline_notation() -> i32 loc("mysource.cc":10:8) {
// CHECK: "foo"() : () -> i32 loc(unknown)
%1 = "foo"() : () -> i32 loc("foo")
// CHECK: for %i0 = 0 to 8 loc(unknown)
for %i0 = 0 to 8 loc(fused["foo", "mysource.cc":10:8]) {
}
// CHECK: if #set0(%c4) loc(unknown)
%2 = constant 4 : index
if #set0(%2) loc(fused<"myPass">["foo", "foo2"]) {
}
// CHECK: return %0 : i32 loc(unknown)
return %1 : i32 loc("bar")
}