Skip to content

Commit f027d2e

Browse files
Vidush Singhalvidsinghal
Vidush Singhal
authored andcommitted
[Attributor]: Change allocation size and load/store offsets using AAPointerInfo for Alloca instructions
1 parent fcee033 commit f027d2e

15 files changed

+691
-176
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

+58
Original file line numberDiff line numberDiff line change
@@ -5751,8 +5751,10 @@ struct AANonConvergent : public StateWrapper<BooleanState, AbstractAttribute> {
57515751

57525752
/// An abstract interface for struct information.
57535753
struct AAPointerInfo : public AbstractAttribute {
5754+
protected:
57545755
AAPointerInfo(const IRPosition &IRP) : AbstractAttribute(IRP) {}
57555756

5757+
public:
57565758
/// See AbstractAttribute::isValidIRPositionForInit
57575759
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP) {
57585760
if (!IRP.getAssociatedType()->isPtrOrPtrVectorTy())
@@ -6106,6 +6108,56 @@ struct AAPointerInfo : public AbstractAttribute {
61066108
Type *Ty;
61076109
};
61086110

6111+
/// A helper containing a list of offsets computed for a Use. Ideally this
6112+
/// list should be strictly ascending, but we ensure that only when we
6113+
/// actually translate the list of offsets to a RangeList.
6114+
struct OffsetInfo {
6115+
using VecTy = SmallVector<int64_t>;
6116+
using const_iterator = VecTy::const_iterator;
6117+
VecTy Offsets;
6118+
6119+
const_iterator begin() const { return Offsets.begin(); }
6120+
const_iterator end() const { return Offsets.end(); }
6121+
6122+
bool operator==(const OffsetInfo &RHS) const {
6123+
return Offsets == RHS.Offsets;
6124+
}
6125+
6126+
bool operator!=(const OffsetInfo &RHS) const { return !(*this == RHS); }
6127+
6128+
void insert(int64_t Offset) { Offsets.push_back(Offset); }
6129+
bool isUnassigned() const { return Offsets.empty(); }
6130+
6131+
bool isUnknown() const {
6132+
if (isUnassigned())
6133+
return false;
6134+
if (Offsets.size() == 1)
6135+
return Offsets.front() == AA::RangeTy::Unknown;
6136+
return false;
6137+
}
6138+
6139+
void setUnknown() {
6140+
Offsets.clear();
6141+
Offsets.push_back(AA::RangeTy::Unknown);
6142+
}
6143+
6144+
void addToAll(int64_t Inc) {
6145+
for (auto &Offset : Offsets)
6146+
Offset += Inc;
6147+
}
6148+
6149+
/// Copy offsets from \p R into the current list.
6150+
///
6151+
/// Ideally all lists should be strictly ascending, but we defer that to the
6152+
/// actual use of the list. So we just blindly append here.
6153+
void merge(const OffsetInfo &R) {
6154+
Offsets.append(R.Offsets);
6155+
// ensure elements are unique.
6156+
sort(Offsets.begin(), Offsets.end());
6157+
Offsets.erase(std::unique(Offsets.begin(), Offsets.end()), Offsets.end());
6158+
}
6159+
};
6160+
61096161
/// Create an abstract attribute view for the position \p IRP.
61106162
static AAPointerInfo &createForPosition(const IRPosition &IRP, Attributor &A);
61116163

@@ -6120,6 +6172,9 @@ struct AAPointerInfo : public AbstractAttribute {
61206172
virtual const_bin_iterator begin() const = 0;
61216173
virtual const_bin_iterator end() const = 0;
61226174
virtual int64_t numOffsetBins() const = 0;
6175+
virtual void dumpState(raw_ostream &O) const = 0;
6176+
virtual const Access &getBinAccess(unsigned Index) const = 0;
6177+
virtual const DenseMap<Value *, OffsetInfo> &getOffsetInfoMap() const = 0;
61236178

61246179
/// Call \p CB on all accesses that might interfere with \p Range and return
61256180
/// true if all such accesses were known and the callback returned true for
@@ -6291,6 +6346,9 @@ struct AAAllocationInfo : public StateWrapper<BooleanState, AbstractAttribute> {
62916346

62926347
virtual std::optional<TypeSize> getAllocatedSize() const = 0;
62936348

6349+
using NewOffsetsTy = DenseMap<AA::RangeTy, AA::RangeTy>;
6350+
virtual const NewOffsetsTy &getNewOffsets() const = 0;
6351+
62946352
/// See AbstractAttribute::getName()
62956353
const std::string getName() const override { return "AAAllocationInfo"; }
62966354

0 commit comments

Comments
 (0)