1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00

[Attributor] Improve the Attributor::getAssumedConstant interface

Similar to Attributor::getAssumedSimplified we need to allow IRPs
directly to get the right simplification callback (and context).
This commit is contained in:
Johannes Doerfert 2021-07-21 21:58:00 -05:00
parent 35ac1cb771
commit b93c50b86a
2 changed files with 16 additions and 14 deletions

View File

@ -1499,11 +1499,16 @@ struct Attributor {
ToBeDeletedFunctions.insert(&F);
}
/// If \p V is assumed to be a constant, return it, if it is unclear yet,
/// If \p IRP is assumed to be a constant, return it, if it is unclear yet,
/// return None, otherwise return `nullptr`.
Optional<Constant *> getAssumedConstant(const Value &V,
Optional<Constant *> getAssumedConstant(const IRPosition &IRP,
const AbstractAttribute &AA,
bool &UsedAssumedInformation);
Optional<Constant *> getAssumedConstant(const Value &V,
const AbstractAttribute &AA,
bool &UsedAssumedInformation) {
return getAssumedConstant(IRPosition::value(V), AA, UsedAssumedInformation);
}
/// If \p V is assumed simplified, return it, if it is unclear yet,
/// return None, otherwise return `nullptr`.

View File

@ -648,19 +648,19 @@ void IRPosition::verify() {
}
Optional<Constant *>
Attributor::getAssumedConstant(const Value &V, const AbstractAttribute &AA,
Attributor::getAssumedConstant(const IRPosition &IRP,
const AbstractAttribute &AA,
bool &UsedAssumedInformation) {
// First check all callbacks provided by outside AAs. If any of them returns
// a non-null value that is different from the associated value, or None, we
// assume it's simpliied.
IRPosition IRP = IRPosition::value(V, AA.getCallBaseContext());
for (auto &CB : SimplificationCallbacks[IRP]) {
Optional<Value *> SimplifiedV = CB(IRP, &AA, UsedAssumedInformation);
if (!SimplifiedV.hasValue())
return llvm::None;
if (*SimplifiedV && *SimplifiedV != &IRP.getAssociatedValue() &&
isa<Constant>(*SimplifiedV))
if (isa_and_nonnull<Constant>(*SimplifiedV))
return cast<Constant>(*SimplifiedV);
return nullptr;
}
const auto &ValueSimplifyAA =
getAAFor<AAValueSimplify>(AA, IRP, DepClassTy::NONE);
@ -674,13 +674,12 @@ Attributor::getAssumedConstant(const Value &V, const AbstractAttribute &AA,
}
if (isa_and_nonnull<UndefValue>(SimplifiedV.getValue())) {
recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL);
return UndefValue::get(V.getType());
return UndefValue::get(IRP.getAssociatedType());
}
Constant *CI = dyn_cast_or_null<Constant>(SimplifiedV.getValue());
if (CI && CI->getType() != V.getType()) {
// TODO: Check for a save conversion.
return nullptr;
}
if (CI)
CI = dyn_cast_or_null<Constant>(
AA::getWithType(*CI, *IRP.getAssociatedType()));
if (CI)
recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL);
return CI;
@ -695,9 +694,7 @@ Attributor::getAssumedSimplified(const IRPosition &IRP,
// assume it's simpliied.
for (auto &CB : SimplificationCallbacks[IRP]) {
Optional<Value *> SimplifiedV = CB(IRP, AA, UsedAssumedInformation);
if (!SimplifiedV.hasValue() ||
(*SimplifiedV && *SimplifiedV != &IRP.getAssociatedValue()))
return SimplifiedV;
return SimplifiedV;
}
// If no high-level/outside simplification occured, use AAValueSimplify.