Skip to content

Commit ad6a84f

Browse files
committed
Revert "[Verifier] Speed up and parallelize dominance checking. NFC"
This reverts commit 08664d0, which according to https://reviews.llvm.org/D103373 was pushed accidentally, and I believe it causes timeouts in some internal mlir tests.
1 parent 9965370 commit ad6a84f

File tree

2 files changed

+33
-82
lines changed

2 files changed

+33
-82
lines changed

mlir/include/mlir/IR/Dominance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DominanceInfoBase {
3535
using DomTree = llvm::DominatorTreeBase<Block, IsPostDom>;
3636

3737
public:
38-
DominanceInfoBase(Operation *op = nullptr) {}
38+
DominanceInfoBase(Operation *op) {}
3939
DominanceInfoBase(DominanceInfoBase &&) = default;
4040
DominanceInfoBase &operator=(DominanceInfoBase &&) = default;
4141
~DominanceInfoBase();

mlir/lib/IR/Verifier.cpp

Lines changed: 32 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
#include "mlir/IR/Operation.h"
3232
#include "mlir/IR/RegionKindInterface.h"
3333
#include "llvm/ADT/StringMap.h"
34-
#include "llvm/Support/Parallel.h"
34+
#include "llvm/Support/FormatVariadic.h"
3535
#include "llvm/Support/PrettyStackTrace.h"
36+
#include "llvm/Support/Regex.h"
3637

3738
#include <atomic>
3839

@@ -42,8 +43,7 @@ namespace {
4243
/// This class encapsulates all the state used to verify an operation region.
4344
class OperationVerifier {
4445
public:
45-
explicit OperationVerifier(MLIRContext *context)
46-
: parallelismEnabled(context->isMultithreadingEnabled()) {}
46+
explicit OperationVerifier() {}
4747

4848
/// Verify the given operation.
4949
LogicalResult verifyOpAndDominance(Operation &op);
@@ -56,8 +56,7 @@ class OperationVerifier {
5656

5757
/// Verify the dominance property of regions contained within the given
5858
/// Operation.
59-
LogicalResult verifyDominanceOfContainedRegions(Operation &op,
60-
DominanceInfo &domInfo);
59+
LogicalResult verifyDominanceOfContainedRegions(Operation &op);
6160

6261
/// Emit an error for the given block.
6362
InFlightDiagnostic emitError(Block &bb, const Twine &message) {
@@ -69,8 +68,8 @@ class OperationVerifier {
6968
return mlir::emitError(bb.getParent()->getLoc(), message);
7069
}
7170

72-
/// This is true if parallelism is enabled on the MLIRContext.
73-
const bool parallelismEnabled;
71+
/// Dominance information for this operation, when checking dominance.
72+
DominanceInfo *domInfo = nullptr;
7473
};
7574
} // end anonymous namespace
7675

@@ -84,11 +83,12 @@ LogicalResult OperationVerifier::verifyOpAndDominance(Operation &op) {
8483
// check for any nested regions. We do this as a second pass since malformed
8584
// CFG's can cause dominator analysis constructure to crash and we want the
8685
// verifier to be resilient to malformed code.
87-
if (op.getNumRegions() != 0) {
88-
DominanceInfo domInfo;
89-
if (failed(verifyDominanceOfContainedRegions(op, /*domInfo*/ domInfo)))
90-
return failure();
91-
}
86+
DominanceInfo theDomInfo(&op);
87+
domInfo = &theDomInfo;
88+
if (failed(verifyDominanceOfContainedRegions(op)))
89+
return failure();
90+
91+
domInfo = nullptr;
9292
return success();
9393
}
9494

@@ -301,83 +301,34 @@ static void diagnoseInvalidOperandDominance(Operation &op, unsigned operandNo) {
301301
note << " neither in a parent nor in a child region)";
302302
}
303303

304-
/// Verify the dominance of each of the nested blocks within the given
305-
/// operation. domInfo may be present or absent (null), depending on whether
306-
/// the caller computed it for a higher level.
304+
/// Verify the dominance of each of the nested blocks within the given operation
307305
LogicalResult
308-
OperationVerifier::verifyDominanceOfContainedRegions(Operation &opWithRegions,
309-
DominanceInfo &domInfo) {
310-
// This vector keeps track of ops that have regions which should be checked
311-
// in parallel.
312-
SmallVector<Operation *> opsWithRegionsToCheckInParallel;
313-
314-
// Get information about the requirements on the regions in this op.
315-
for (Region &region : opWithRegions.getRegions()) {
306+
OperationVerifier::verifyDominanceOfContainedRegions(Operation &op) {
307+
for (Region &region : op.getRegions()) {
308+
// Verify the dominance of each of the held operations.
316309
for (Block &block : region) {
317310
// Dominance is only meaningful inside reachable blocks.
318-
bool isReachable = domInfo.isReachableFromEntry(&block);
319-
320-
// Check each operation in this block, and any operations in regions
321-
// that these operations contain.
322-
opsWithRegionsToCheckInParallel.clear();
311+
bool isReachable = domInfo->isReachableFromEntry(&block);
323312

324313
for (Operation &op : block) {
325314
if (isReachable) {
326315
// Check that operands properly dominate this use.
327-
for (auto &operand : op.getOpOperands()) {
328-
// If the operand doesn't dominate the user, then emit an error.
329-
if (!domInfo.properlyDominates(operand.get(), &op)) {
330-
diagnoseInvalidOperandDominance(op, operand.getOperandNumber());
331-
return failure();
332-
}
333-
}
334-
}
316+
for (unsigned operandNo = 0, e = op.getNumOperands(); operandNo != e;
317+
++operandNo) {
318+
if (domInfo->properlyDominates(op.getOperand(operandNo), &op))
319+
continue;
335320

336-
// If this operation has any regions, we need to recursively verify
337-
// dominance of the ops within it.
338-
if (op.getNumRegions() == 0)
339-
continue;
340-
341-
// If this is a non-isolated region (e.g. an affine for loop), pass down
342-
// the current dominator information.
343-
if (!op.hasTrait<OpTrait::IsIsolatedFromAbove>()) {
344-
if (failed(verifyDominanceOfContainedRegions(op, domInfo)))
345-
return failure();
346-
} else if (parallelismEnabled) {
347-
// If this is an IsolatedFromAbove op and parallelism is enabled, then
348-
// enqueue this for processing later.
349-
opsWithRegionsToCheckInParallel.push_back(&op);
350-
} else {
351-
// If not, just verify inline with a local dom scope.
352-
DominanceInfo localDomInfo;
353-
if (failed(verifyDominanceOfContainedRegions(op, localDomInfo)))
321+
diagnoseInvalidOperandDominance(op, operandNo);
354322
return failure();
323+
}
355324
}
356-
}
357325

358-
// If we have multiple parallelizable subregions, check them in parallel.
359-
if (opsWithRegionsToCheckInParallel.size() == 1) {
360-
// Each isolated operation gets its own dom info.
361-
Operation *op = opsWithRegionsToCheckInParallel[0];
362-
DominanceInfo localDomInfo;
363-
if (failed(verifyDominanceOfContainedRegions(*op, localDomInfo)))
364-
return failure();
365-
} else if (!opsWithRegionsToCheckInParallel.empty()) {
366-
ParallelDiagnosticHandler handler(opWithRegions.getContext());
367-
std::atomic<bool> passFailed(false);
368-
llvm::parallelForEachN(
369-
0, opsWithRegionsToCheckInParallel.size(), [&](size_t opIdx) {
370-
handler.setOrderIDForThread(opIdx);
371-
Operation *op = opsWithRegionsToCheckInParallel[opIdx];
372-
373-
// Each isolated operation gets its own dom info.
374-
DominanceInfo localDomInfo;
375-
if (failed(verifyDominanceOfContainedRegions(*op, localDomInfo)))
376-
passFailed = true;
377-
handler.eraseOrderIDForThread();
378-
});
379-
if (passFailed)
380-
return failure();
326+
// Recursively verify dominance within each operation in the
327+
// block, even if the block itself is not reachable, or we are in
328+
// a region which doesn't respect dominance.
329+
if (op.getNumRegions() != 0)
330+
if (failed(verifyDominanceOfContainedRegions(op)))
331+
return failure();
381332
}
382333
}
383334
}
@@ -389,8 +340,8 @@ OperationVerifier::verifyDominanceOfContainedRegions(Operation &opWithRegions,
389340
//===----------------------------------------------------------------------===//
390341

391342
/// Perform (potentially expensive) checks of invariants, used to detect
392-
/// compiler bugs. On error, this reports the error through the MLIRContext
393-
/// and returns failure.
343+
/// compiler bugs. On error, this reports the error through the MLIRContext and
344+
/// returns failure.
394345
LogicalResult mlir::verify(Operation *op) {
395-
return OperationVerifier(op->getContext()).verifyOpAndDominance(*op);
346+
return OperationVerifier().verifyOpAndDominance(*op);
396347
}

0 commit comments

Comments
 (0)