[llvm] 14899bc - [Attributor] Generalize interface from ConstantInt to Constant
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 9 03:03:51 PDT 2022
Author: Johannes Doerfert
Date: 2022-06-09T12:00:26+02:00
New Revision: 14899bc43d248c940b05d56a9fc065d25cd5d88c
URL: https://github.com/llvm/llvm-project/commit/14899bc43d248c940b05d56a9fc065d25cd5d88c
DIFF: https://github.com/llvm/llvm-project/commit/14899bc43d248c940b05d56a9fc065d25cd5d88c.diff
LOG: [Attributor] Generalize interface from ConstantInt to Constant
We can use constant to allow undef and there is no need to force
integers in the API anyway. The user can decide if a non integer
constant is fine or not.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 81ee6d5b762f0..59ba92c0c3d4d 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -116,6 +116,7 @@
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/AbstractCallSite.h"
#include "llvm/IR/ConstantRange.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Allocator.h"
@@ -4279,13 +4280,14 @@ struct AAValueConstantRange
/// Return an assumed constant for the associated value a program point \p
/// CtxI.
- Optional<ConstantInt *>
- getAssumedConstantInt(Attributor &A,
- const Instruction *CtxI = nullptr) const {
+ Optional<Constant *>
+ getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const {
ConstantRange RangeV = getAssumedConstantRange(A, CtxI);
- if (auto *C = RangeV.getSingleElement())
- return cast<ConstantInt>(
- ConstantInt::get(getAssociatedValue().getType(), *C));
+ if (auto *C = RangeV.getSingleElement()) {
+ Type *Ty = getAssociatedValue().getType();
+ return cast_or_null<Constant>(
+ AA::getWithType(*ConstantInt::get(Ty->getContext(), *C), *Ty));
+ }
if (RangeV.isEmptySet())
return llvm::None;
return nullptr;
@@ -4522,18 +4524,19 @@ struct AAPotentialConstantValues
Attributor &A);
/// Return assumed constant for the associated value
- Optional<ConstantInt *>
- getAssumedConstantInt(Attributor &A,
- const Instruction *CtxI = nullptr) const {
+ Optional<Constant *>
+ getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const {
if (!isValidState())
return nullptr;
- if (getAssumedSet().size() == 1)
- return cast<ConstantInt>(ConstantInt::get(getAssociatedValue().getType(),
- *(getAssumedSet().begin())));
+ if (getAssumedSet().size() == 1) {
+ Type *Ty = getAssociatedValue().getType();
+ return cast_or_null<Constant>(AA::getWithType(
+ *ConstantInt::get(Ty->getContext(), *(getAssumedSet().begin())),
+ *Ty));
+ }
if (getAssumedSet().size() == 0) {
if (undefIsContained())
- return cast<ConstantInt>(
- ConstantInt::get(getAssociatedValue().getType(), 0));
+ return UndefValue::get(getAssociatedValue().getType());
return llvm::None;
}
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 58f407db5d014..ba2fb1e325039 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5527,7 +5527,7 @@ struct AAValueSimplifyImpl : AAValueSimplify {
const auto &AA =
A.getAAFor<AAType>(*this, getIRPosition(), DepClassTy::NONE);
- Optional<ConstantInt *> COpt = AA.getAssumedConstantInt(A);
+ Optional<Constant *> COpt = AA.getAssumedConstant(A);
if (!COpt.hasValue()) {
SimplifiedAssociatedValue = llvm::None;
More information about the llvm-commits
mailing list