Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lib/Support/SCEVValidator.cpp
Show First 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | if (BaseAddress == V) { | ||||
DEBUG(dbgs() << "INVALID: UnknownExpr references BaseAddress\n"); | DEBUG(dbgs() << "INVALID: UnknownExpr references BaseAddress\n"); | ||||
return ValidatorResult(SCEVType::INVALID); | return ValidatorResult(SCEVType::INVALID); | ||||
} | } | ||||
return ValidatorResult(SCEVType::PARAM, Expr); | return ValidatorResult(SCEVType::PARAM, Expr); | ||||
} | } | ||||
}; | }; | ||||
/// @brief Check whether a SCEV refers to an SSA name defined inside a region. | /// @brief Check whether a SCEV refers to an SSA name defined inside a region. | ||||
jdoerfert: There is another type of "SCEVVisitor", Sebastian pointed it out to me once. IT only has one… | |||||
Not Done ReplyInline ActionsNice find, that simplifies so many things simbuerg: Nice find, that simplifies so many things | |||||
Not Done ReplyInline ActionsChanged. This really reduced the code needed here significantly. grosser: Changed. This really reduced the code needed here significantly. | |||||
/// | /// | ||||
struct SCEVInRegionDependences | struct SCEVInRegionDependences | ||||
: public SCEVVisitor<SCEVInRegionDependences, bool> { | : public SCEVVisitor<SCEVInRegionDependences, bool> { | ||||
public: | public: | ||||
/// Returns true when the SCEV has SSA names defined in region R. | /// Returns true when the SCEV has SSA names defined in region R. | ||||
static bool hasDependences(const SCEV *S, const Region *R) { | static bool hasDependences(const SCEV *S, const Region *R) { | ||||
SCEVInRegionDependences Ignore(R); | SCEVInRegionDependences Ignore(R); | ||||
return Ignore.visit(S); | return Ignore.visit(S); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | bool visitAddRecExpr(const SCEVAddRecExpr *Expr) { | ||||
if (visit(Expr->getStart())) | if (visit(Expr->getStart())) | ||||
return true; | return true; | ||||
for (size_t i = 0; i < Expr->getNumOperands(); ++i) | for (size_t i = 0; i < Expr->getNumOperands(); ++i) | ||||
if (visit(Expr->getOperand(i))) | if (visit(Expr->getOperand(i))) | ||||
return true; | return true; | ||||
return false; | return false; | ||||
} | } | ||||
Not Done ReplyInline ActionsSame as above jdoerfert: Same as above | |||||
Not Done ReplyInline ActionsChanged. grosser: Changed. | |||||
bool visitSMaxExpr(const SCEVSMaxExpr *Expr) { | bool visitSMaxExpr(const SCEVSMaxExpr *Expr) { | ||||
for (size_t i = 0; i < Expr->getNumOperands(); ++i) | for (size_t i = 0; i < Expr->getNumOperands(); ++i) | ||||
if (visit(Expr->getOperand(i))) | if (visit(Expr->getOperand(i))) | ||||
return true; | return true; | ||||
return false; | return false; | ||||
} | } | ||||
Show All 16 Lines | bool visitUnknown(const SCEVUnknown *Expr) { | ||||
return false; | return false; | ||||
} | } | ||||
private: | private: | ||||
const Region *R; | const Region *R; | ||||
}; | }; | ||||
namespace polly { | namespace polly { | ||||
/// Find all loops referenced in SCEVAddRecExprs. | |||||
class SCEVFindLoops { | |||||
SetVector<const Loop *> &Loops; | |||||
public: | |||||
SCEVFindLoops(SetVector<const Loop *> &Loops) : Loops(Loops) {} | |||||
bool follow(const SCEV *S) { | |||||
if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(S)) | |||||
Loops.insert(AddRec->getLoop()); | |||||
return true; | |||||
} | |||||
bool isDone() { return false; } | |||||
}; | |||||
void findLoops(const SCEV *Expr, SetVector<const Loop *> &Loops) { | |||||
SCEVFindLoops FindLoops(Loops); | |||||
SCEVTraversal<SCEVFindLoops> ST(FindLoops); | |||||
ST.visitAll(Expr); | |||||
} | |||||
/// Find all values referenced in SCEVUnknowns. | |||||
class SCEVFindValues { | |||||
SetVector<Value *> &Values; | |||||
public: | |||||
SCEVFindValues(SetVector<Value *> &Values) : Values(Values) {} | |||||
bool follow(const SCEV *S) { | |||||
if (const SCEVUnknown *Unknown = dyn_cast<SCEVUnknown>(S)) | |||||
Values.insert(Unknown->getValue()); | |||||
return true; | |||||
} | |||||
bool isDone() { return false; } | |||||
}; | |||||
void findValues(const SCEV *Expr, SetVector<Value *> &Values) { | |||||
SCEVFindValues FindValues(Values); | |||||
SCEVTraversal<SCEVFindValues> ST(FindValues); | |||||
ST.visitAll(Expr); | |||||
} | |||||
bool hasScalarDepsInsideRegion(const SCEV *Expr, const Region *R) { | bool hasScalarDepsInsideRegion(const SCEV *Expr, const Region *R) { | ||||
return SCEVInRegionDependences::hasDependences(Expr, R); | return SCEVInRegionDependences::hasDependences(Expr, R); | ||||
} | } | ||||
bool isAffineExpr(const Region *R, const SCEV *Expr, ScalarEvolution &SE, | bool isAffineExpr(const Region *R, const SCEV *Expr, ScalarEvolution &SE, | ||||
const Value *BaseAddress) { | const Value *BaseAddress) { | ||||
if (isa<SCEVCouldNotCompute>(Expr)) | if (isa<SCEVCouldNotCompute>(Expr)) | ||||
return false; | return false; | ||||
Show All 33 Lines |
There is another type of "SCEVVisitor", Sebastian pointed it out to me once. IT only has one function something like:
and you cast the SCEV yourself. I would suggest using that for visitors that are only interested in one or two SCEV types.