1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[Attributor] Disable simplification AAs if a callback is present

AAValueSimplify, AAValueConstantRange, and AAPotentialValues all look at
the IR by default. If queried for a IR position which has a
simplification callback we should either look at the callback return, or
give up. We do the latter for now.
This commit is contained in:
Johannes Doerfert 2021-07-27 13:44:21 -05:00
parent 9aacda281c
commit 0b6fb7b1ef
2 changed files with 43 additions and 12 deletions

View File

@ -1563,6 +1563,11 @@ struct Attributor {
SimplificationCallbacks[IRP].emplace_back(CB);
}
/// Return true if there is a simplification callback for \p IRP.
bool hasSimplificationCallback(const IRPosition &IRP) {
return SimplificationCallbacks.count(IRP);
}
private:
/// The vector with all simplification callbacks registered by outside AAs.
DenseMap<IRPosition, SmallVector<SimplifictionCallbackTy, 1>>

View File

@ -5067,6 +5067,8 @@ struct AAValueSimplifyImpl : AAValueSimplify {
void initialize(Attributor &A) override {
if (getAssociatedValue().getType()->isVoidTy())
indicatePessimisticFixpoint();
if (A.hasSimplificationCallback(getIRPosition()))
indicatePessimisticFixpoint();
}
/// See AbstractAttribute::getAsStr().
@ -5400,9 +5402,7 @@ struct AAValueSimplifyFloating : AAValueSimplifyImpl {
/// See AbstractAttribute::initialize(...).
void initialize(Attributor &A) override {
// FIXME: This might have exposed a SCC iterator update bug in the old PM.
// Needs investigation.
// AAValueSimplifyImpl::initialize(A);
AAValueSimplifyImpl::initialize(A);
Value &V = getAnchorValue();
// TODO: add other stuffs
@ -5639,6 +5639,7 @@ struct AAValueSimplifyCallSiteReturned : AAValueSimplifyImpl {
: AAValueSimplifyImpl(IRP, A) {}
void initialize(Attributor &A) override {
AAValueSimplifyImpl::initialize(A);
if (!getAssociatedFunction())
indicatePessimisticFixpoint();
}
@ -7886,6 +7887,20 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
AAValueConstantRangeImpl(const IRPosition &IRP, Attributor &A)
: AAValueConstantRange(IRP, A) {}
/// See AbstractAttribute::initialize(..).
void initialize(Attributor &A) override {
if (A.hasSimplificationCallback(getIRPosition())) {
indicatePessimisticFixpoint();
return;
}
// Intersect a range given by SCEV.
intersectKnown(getConstantRangeFromSCEV(A, getCtxI()));
// Intersect a range given by LVI.
intersectKnown(getConstantRangeFromLVI(A, getCtxI()));
}
/// See AbstractAttribute::getAsStr().
const std::string getAsStr() const override {
std::string Str;
@ -8017,15 +8032,6 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
return getAssumed().intersectWith(SCEVR).intersectWith(LVIR);
}
/// See AbstractAttribute::initialize(..).
void initialize(Attributor &A) override {
// Intersect a range given by SCEV.
intersectKnown(getConstantRangeFromSCEV(A, getCtxI()));
// Intersect a range given by LVI.
intersectKnown(getConstantRangeFromLVI(A, getCtxI()));
}
/// Helper function to create MDNode for range metadata.
static MDNode *
getMDNodeForConstantRange(Type *Ty, LLVMContext &Ctx,
@ -8155,6 +8161,9 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
/// See AbstractAttribute::initialize(...).
void initialize(Attributor &A) override {
AAValueConstantRangeImpl::initialize(A);
if (isAtFixpoint())
return;
Value &V = getAssociatedValue();
if (auto *C = dyn_cast<ConstantInt>(&V)) {
@ -8175,6 +8184,7 @@ struct AAValueConstantRangeFloating : AAValueConstantRangeImpl {
if (isa<BinaryOperator>(&V) || isa<CmpInst>(&V) || isa<CastInst>(&V))
return;
// If it is a load instruction with range metadata, use it.
if (LoadInst *LI = dyn_cast<LoadInst>(&V))
if (auto *RangeMD = LI->getMetadata(LLVMContext::MD_range)) {
@ -8502,6 +8512,14 @@ struct AAPotentialValuesImpl : AAPotentialValues {
AAPotentialValuesImpl(const IRPosition &IRP, Attributor &A)
: AAPotentialValues(IRP, A) {}
/// See AbstractAttribute::initialize(..).
void initialize(Attributor &A) override {
if (A.hasSimplificationCallback(getIRPosition()))
indicatePessimisticFixpoint();
else
AAPotentialValues::initialize(A);
}
/// See AbstractAttribute::getAsStr().
const std::string getAsStr() const override {
std::string Str;
@ -8559,6 +8577,10 @@ struct AAPotentialValuesFloating : AAPotentialValuesImpl {
/// See AbstractAttribute::initialize(..).
void initialize(Attributor &A) override {
AAPotentialValuesImpl::initialize(A);
if (isAtFixpoint())
return;
Value &V = getAssociatedValue();
if (auto *C = dyn_cast<ConstantInt>(&V)) {
@ -9091,6 +9113,10 @@ struct AAPotentialValuesCallSiteArgument : AAPotentialValuesFloating {
/// See AbstractAttribute::initialize(..).
void initialize(Attributor &A) override {
AAPotentialValuesImpl::initialize(A);
if (isAtFixpoint())
return;
Value &V = getAssociatedValue();
if (auto *C = dyn_cast<ConstantInt>(&V)) {