Skip to content

Commit

Permalink
add extra debug statements
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Nov 14, 2023
1 parent e0b8017 commit b78a997
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/Transform/Noisy/ReduceNoiseOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
#include "mlir/include/mlir/Analysis/DataFlowFramework.h"
#include "mlir/include/mlir/IR/Visitors.h"
#include "mlir/include/mlir/Pass/Pass.h"
#include "llvm/Support/Debug.h"

namespace mlir {
namespace tutorial {
namespace noisy {

#define DEBUG_TYPE "ReduceNoiseOptimizer"

#define GEN_PASS_DEF_REDUCENOISEOPTIMIZER
#include "lib/Transform/Noisy/Passes.h.inc"

Expand Down Expand Up @@ -43,8 +46,11 @@ struct ReduceNoiseOptimizer
// dependence is not automatic and fails silently.
solver.load<dataflow::DeadCodeAnalysis>();
solver.load<dataflow::IntegerRangeAnalysis>();
if (failed(solver.initializeAndRun(module)))
if (failed(solver.initializeAndRun(module))) {
getOperation()->emitOpError() << "Failed to run the analysis.\n";
signalPassFailure();
return;
}

auto result = module->walk([&](Operation *op) {
if (!llvm::isa<noisy::AddOp, noisy::SubOp, noisy::MulOp,
Expand All @@ -61,6 +67,9 @@ struct ReduceNoiseOptimizer
}

ConstantIntRanges range = opRange->getValue().getValue();
LLVM_DEBUG(llvm::dbgs() << "op " << *op << " has error range ["
<< range.umin().getZExtValue() << ", "
<< range.umax().getZExtValue() << "]\n");
if (range.umax().getZExtValue() > MAX_NOISE) {
op->emitOpError() << "Found op after which the noise exceeds the "
"allowable maximum of "
Expand All @@ -73,8 +82,11 @@ struct ReduceNoiseOptimizer
return WalkResult::advance();
});

if (result.wasInterrupted())
if (result.wasInterrupted()) {
getOperation()->emitOpError()
<< "Detected error in the noise analysis.\n";
signalPassFailure();
}
}
};

Expand Down

0 comments on commit b78a997

Please sign in to comment.