[Mlir-commits] [mlir] 6134231 - [CSE] Ask DominanceInfo about "hasSSADominance" instead of reconstructing it.
Chris Lattner
llvmlistbot at llvm.org
Tue Jun 1 15:16:31 PDT 2021
Author: Chris Lattner
Date: 2021-06-01T15:16:23-07:00
New Revision: 6134231a78bf667a2f4357a415fac11e2732405a
URL: https://github.com/llvm/llvm-project/commit/6134231a78bf667a2f4357a415fac11e2732405a
DIFF: https://github.com/llvm/llvm-project/commit/6134231a78bf667a2f4357a415fac11e2732405a.diff
LOG: [CSE] Ask DominanceInfo about "hasSSADominance" instead of reconstructing it.
I backed this off to make the previous patch easier to wrangle, but now
this is an efficient query and it is better to not replace it in CSE.
Differential Revision: https://reviews.llvm.org/D103494
Added:
Modified:
mlir/lib/Transforms/CSE.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Transforms/CSE.cpp b/mlir/lib/Transforms/CSE.cpp
index 541b54ae2a6b..4b2ba0e9ce48 100644
--- a/mlir/lib/Transforms/CSE.cpp
+++ b/mlir/lib/Transforms/CSE.cpp
@@ -25,24 +25,6 @@
using namespace mlir;
-/// Return true if the specified region is known to follow SSA dominance
-/// properties, i.e. it isn't a graph region.
-static bool regionHasSSADominance(Operation &op, size_t regionNo,
- RegionKindInterface regionKindItf) {
- // If the op is unregistered, then we don't know if it has SSADominance or
- // not, so assume not.
- if (!op.isRegistered())
- return false;
-
- // If the op is registered but has no RegionKindInterface, then it defaults to
- // SSADominance.
- if (!regionKindItf)
- return true;
-
- // Otherwise, ask the interface.
- return regionKindItf.hasSSADominance(regionNo);
-}
-
namespace {
struct SimpleOperationInfo : public llvm::DenseMapInfo<Operation *> {
static unsigned getHashValue(const Operation *opC) {
@@ -93,8 +75,7 @@ struct CSE : public CSEBase<CSE> {
LogicalResult simplifyOperation(ScopedMapTy &knownValues, Operation *op,
bool hasSSADominance);
void simplifyBlock(ScopedMapTy &knownValues, Block *bb, bool hasSSADominance);
- void simplifyRegion(ScopedMapTy &knownValues, Region ®ion,
- bool hasSSADominance);
+ void simplifyRegion(ScopedMapTy &knownValues, Region ®ion);
void runOnOperation() override;
@@ -184,34 +165,29 @@ void CSE::simplifyBlock(ScopedMapTy &knownValues, Block *bb,
if (op.getNumRegions() == 0)
continue;
- auto regionKindItf = dyn_cast<RegionKindInterface>(op);
-
// If this operation is isolated above, we can't process nested regions with
// the given 'knownValues' map. This would cause the insertion of implicit
// captures in explicit capture only regions.
if (op.mightHaveTrait<OpTrait::IsIsolatedFromAbove>()) {
ScopedMapTy nestedKnownValues;
- for (size_t i = 0, e = op.getNumRegions(); i != e; ++i) {
- simplifyRegion(nestedKnownValues, op.getRegion(i),
- regionHasSSADominance(op, i, regionKindItf));
- }
+ for (auto ®ion : op.getRegions())
+ simplifyRegion(nestedKnownValues, region);
continue;
}
// Otherwise, process nested regions normally.
- for (size_t i = 0, e = op.getNumRegions(); i != e; ++i) {
- simplifyRegion(knownValues, op.getRegion(i),
- regionHasSSADominance(op, i, regionKindItf));
- }
+ for (auto ®ion : op.getRegions())
+ simplifyRegion(knownValues, region);
}
}
-void CSE::simplifyRegion(ScopedMapTy &knownValues, Region ®ion,
- bool hasSSADominance) {
+void CSE::simplifyRegion(ScopedMapTy &knownValues, Region ®ion) {
// If the region is empty there is nothing to do.
if (region.empty())
return;
+ bool hasSSADominance = domInfo->hasSSADominance(®ion);
+
// If the region only contains one block, then simplify it directly.
if (region.hasOneBlock()) {
ScopedMapTy::ScopeTy scope(knownValues);
@@ -267,11 +243,8 @@ void CSE::runOnOperation() {
domInfo = &getAnalysis<DominanceInfo>();
Operation *rootOp = getOperation();
- auto regionKindItf = dyn_cast<RegionKindInterface>(getOperation());
- for (size_t i = 0, e = rootOp->getNumRegions(); i != e; ++i) {
- simplifyRegion(knownValues, rootOp->getRegion(i),
- regionHasSSADominance(*rootOp, i, regionKindItf));
- }
+ for (auto ®ion : rootOp->getRegions())
+ simplifyRegion(knownValues, region);
// If no operations were erased, then we mark all analyses as preserved.
if (opsToErase.empty())
More information about the Mlir-commits
mailing list