[llvm] c819266 - [Attributor] Improve the Attributor::getAssumedConstant interface
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 21 22:08:21 PDT 2021
Author: Johannes Doerfert
Date: 2021-07-22T00:07:55-05:00
New Revision: c819266ecc8fa12e0d567be6b4dd7ea9c4eede87
URL: https://github.com/llvm/llvm-project/commit/c819266ecc8fa12e0d567be6b4dd7ea9c4eede87
DIFF: https://github.com/llvm/llvm-project/commit/c819266ecc8fa12e0d567be6b4dd7ea9c4eede87.diff
LOG: [Attributor] Improve the Attributor::getAssumedConstant interface
Similar to Attributor::getAssumedSimplified we need to allow IRPs
directly to get the right simplification callback (and context).
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/Attributor.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 234a384b36bc..01b40ff7cc23 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -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`.
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 87c772167dcd..61659b295f22 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -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
diff erent 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.
More information about the llvm-commits
mailing list