forked from OSchip/llvm-project
[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
This commit is contained in:
parent
aeae3e0ba9
commit
6134231a78
|
@ -25,24 +25,6 @@
|
||||||
|
|
||||||
using namespace mlir;
|
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 {
|
namespace {
|
||||||
struct SimpleOperationInfo : public llvm::DenseMapInfo<Operation *> {
|
struct SimpleOperationInfo : public llvm::DenseMapInfo<Operation *> {
|
||||||
static unsigned getHashValue(const Operation *opC) {
|
static unsigned getHashValue(const Operation *opC) {
|
||||||
|
@ -93,8 +75,7 @@ struct CSE : public CSEBase<CSE> {
|
||||||
LogicalResult simplifyOperation(ScopedMapTy &knownValues, Operation *op,
|
LogicalResult simplifyOperation(ScopedMapTy &knownValues, Operation *op,
|
||||||
bool hasSSADominance);
|
bool hasSSADominance);
|
||||||
void simplifyBlock(ScopedMapTy &knownValues, Block *bb, bool hasSSADominance);
|
void simplifyBlock(ScopedMapTy &knownValues, Block *bb, bool hasSSADominance);
|
||||||
void simplifyRegion(ScopedMapTy &knownValues, Region ®ion,
|
void simplifyRegion(ScopedMapTy &knownValues, Region ®ion);
|
||||||
bool hasSSADominance);
|
|
||||||
|
|
||||||
void runOnOperation() override;
|
void runOnOperation() override;
|
||||||
|
|
||||||
|
@ -184,34 +165,29 @@ void CSE::simplifyBlock(ScopedMapTy &knownValues, Block *bb,
|
||||||
if (op.getNumRegions() == 0)
|
if (op.getNumRegions() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto regionKindItf = dyn_cast<RegionKindInterface>(op);
|
|
||||||
|
|
||||||
// If this operation is isolated above, we can't process nested regions with
|
// If this operation is isolated above, we can't process nested regions with
|
||||||
// the given 'knownValues' map. This would cause the insertion of implicit
|
// the given 'knownValues' map. This would cause the insertion of implicit
|
||||||
// captures in explicit capture only regions.
|
// captures in explicit capture only regions.
|
||||||
if (op.mightHaveTrait<OpTrait::IsIsolatedFromAbove>()) {
|
if (op.mightHaveTrait<OpTrait::IsIsolatedFromAbove>()) {
|
||||||
ScopedMapTy nestedKnownValues;
|
ScopedMapTy nestedKnownValues;
|
||||||
for (size_t i = 0, e = op.getNumRegions(); i != e; ++i) {
|
for (auto ®ion : op.getRegions())
|
||||||
simplifyRegion(nestedKnownValues, op.getRegion(i),
|
simplifyRegion(nestedKnownValues, region);
|
||||||
regionHasSSADominance(op, i, regionKindItf));
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, process nested regions normally.
|
// Otherwise, process nested regions normally.
|
||||||
for (size_t i = 0, e = op.getNumRegions(); i != e; ++i) {
|
for (auto ®ion : op.getRegions())
|
||||||
simplifyRegion(knownValues, op.getRegion(i),
|
simplifyRegion(knownValues, region);
|
||||||
regionHasSSADominance(op, i, regionKindItf));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSE::simplifyRegion(ScopedMapTy &knownValues, Region ®ion,
|
void CSE::simplifyRegion(ScopedMapTy &knownValues, Region ®ion) {
|
||||||
bool hasSSADominance) {
|
|
||||||
// If the region is empty there is nothing to do.
|
// If the region is empty there is nothing to do.
|
||||||
if (region.empty())
|
if (region.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool hasSSADominance = domInfo->hasSSADominance(®ion);
|
||||||
|
|
||||||
// If the region only contains one block, then simplify it directly.
|
// If the region only contains one block, then simplify it directly.
|
||||||
if (region.hasOneBlock()) {
|
if (region.hasOneBlock()) {
|
||||||
ScopedMapTy::ScopeTy scope(knownValues);
|
ScopedMapTy::ScopeTy scope(knownValues);
|
||||||
|
@ -267,11 +243,8 @@ void CSE::runOnOperation() {
|
||||||
domInfo = &getAnalysis<DominanceInfo>();
|
domInfo = &getAnalysis<DominanceInfo>();
|
||||||
Operation *rootOp = getOperation();
|
Operation *rootOp = getOperation();
|
||||||
|
|
||||||
auto regionKindItf = dyn_cast<RegionKindInterface>(getOperation());
|
for (auto ®ion : rootOp->getRegions())
|
||||||
for (size_t i = 0, e = rootOp->getNumRegions(); i != e; ++i) {
|
simplifyRegion(knownValues, region);
|
||||||
simplifyRegion(knownValues, rootOp->getRegion(i),
|
|
||||||
regionHasSSADominance(*rootOp, i, regionKindItf));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no operations were erased, then we mark all analyses as preserved.
|
// If no operations were erased, then we mark all analyses as preserved.
|
||||||
if (opsToErase.empty())
|
if (opsToErase.empty())
|
||||||
|
|
Loading…
Reference in New Issue