Skip to content

Commit 57d57b1

Browse files
committed
[AAEval] Make compatible with opaque pointers
With opaque pointers, we cannot use the pointer element type to determine the LocationSize for the AA query. Instead, -aa-eval tests are now required to have an explicit load or store for any pointer they want to compute alias results for, and the load/store types are used to determine the location size. This may affect ordering of results, and sorting within one result, as the type is not considered part of the sorted string anymore. To somewhat minimize the churn, printing still uses faux typed pointer notation.
1 parent 75acad4 commit 57d57b1

File tree

93 files changed

+1647
-759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1647
-759
lines changed

llvm/lib/Analysis/AliasAnalysisEvaluator.cpp

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,48 @@ static cl::opt<bool> PrintMustModRef("print-mustmodref", cl::ReallyHidden);
3939

4040
static cl::opt<bool> EvalAAMD("evaluate-aa-metadata", cl::ReallyHidden);
4141

42-
static void PrintResults(AliasResult AR, bool P, const Value *V1,
43-
const Value *V2, const Module *M) {
42+
static void PrintResults(AliasResult AR, bool P,
43+
std::pair<const Value *, Type *> Loc1,
44+
std::pair<const Value *, Type *> Loc2,
45+
const Module *M) {
4446
if (PrintAll || P) {
47+
Type *Ty1 = Loc1.second, *Ty2 = Loc2.second;
48+
unsigned AS1 = Loc1.first->getType()->getPointerAddressSpace();
49+
unsigned AS2 = Loc2.first->getType()->getPointerAddressSpace();
4550
std::string o1, o2;
4651
{
4752
raw_string_ostream os1(o1), os2(o2);
48-
V1->printAsOperand(os1, true, M);
49-
V2->printAsOperand(os2, true, M);
53+
Loc1.first->printAsOperand(os1, false, M);
54+
Loc2.first->printAsOperand(os2, false, M);
5055
}
5156

5257
if (o2 < o1) {
5358
std::swap(o1, o2);
59+
std::swap(Ty1, Ty2);
60+
std::swap(AS1, AS2);
5461
// Change offset sign for the local AR, for printing only.
5562
AR.swap();
5663
}
57-
errs() << " " << AR << ":\t" << o1 << ", " << o2 << "\n";
64+
errs() << " " << AR << ":\t";
65+
Ty1->print(errs(), false, /* NoDetails */ true);
66+
if (AS1 != 0)
67+
errs() << " addrspace(" << AS1 << ")";
68+
errs() << "* " << o1 << ", ";
69+
Ty2->print(errs(), false, /* NoDetails */ true);
70+
if (AS2 != 0)
71+
errs() << " addrspace(" << AS2 << ")";
72+
errs() << "* " << o2 << "\n";
5873
}
5974
}
6075

61-
static inline void PrintModRefResults(const char *Msg, bool P, Instruction *I,
62-
Value *Ptr, Module *M) {
76+
static inline void PrintModRefResults(
77+
const char *Msg, bool P, Instruction *I,
78+
std::pair<const Value *, Type *> Loc, Module *M) {
6379
if (PrintAll || P) {
6480
errs() << " " << Msg << ": Ptr: ";
65-
Ptr->printAsOperand(errs(), true, M);
81+
Loc.second->print(errs(), false, /* NoDetails */ true);
82+
errs() << "* ";
83+
Loc.first->printAsOperand(errs(), false, M);
6684
errs() << "\t<->" << *I << '\n';
6785
}
6886
}
@@ -97,38 +115,21 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
97115

98116
++FunctionCount;
99117

100-
SetVector<Value *> Pointers;
118+
SetVector<std::pair<const Value *, Type *>> Pointers;
101119
SmallSetVector<CallBase *, 16> Calls;
102120
SetVector<Value *> Loads;
103121
SetVector<Value *> Stores;
104122

105-
for (auto &I : F.args())
106-
if (I.getType()->isPointerTy()) // Add all pointer arguments.
107-
Pointers.insert(&I);
108-
109123
for (Instruction &Inst : instructions(F)) {
110-
if (Inst.getType()->isPointerTy()) // Add all pointer instructions.
111-
Pointers.insert(&Inst);
112-
if (EvalAAMD && isa<LoadInst>(&Inst))
113-
Loads.insert(&Inst);
114-
if (EvalAAMD && isa<StoreInst>(&Inst))
115-
Stores.insert(&Inst);
116-
if (auto *Call = dyn_cast<CallBase>(&Inst)) {
117-
Value *Callee = Call->getCalledOperand();
118-
// Skip actual functions for direct function calls.
119-
if (!isa<Function>(Callee) && isInterestingPointer(Callee))
120-
Pointers.insert(Callee);
121-
// Consider formals.
122-
for (Use &DataOp : Call->data_ops())
123-
if (isInterestingPointer(DataOp))
124-
Pointers.insert(DataOp);
125-
Calls.insert(Call);
126-
} else {
127-
// Consider all operands.
128-
for (Use &Op : Inst.operands())
129-
if (isInterestingPointer(Op))
130-
Pointers.insert(Op);
131-
}
124+
if (auto *LI = dyn_cast<LoadInst>(&Inst)) {
125+
Pointers.insert({LI->getPointerOperand(), LI->getType()});
126+
Loads.insert(LI);
127+
} else if (auto *SI = dyn_cast<StoreInst>(&Inst)) {
128+
Pointers.insert({SI->getPointerOperand(),
129+
SI->getValueOperand()->getType()});
130+
Stores.insert(SI);
131+
} else if (auto *CB = dyn_cast<CallBase>(&Inst))
132+
Calls.insert(CB);
132133
}
133134

134135
if (PrintAll || PrintNoAlias || PrintMayAlias || PrintPartialAlias ||
@@ -137,20 +138,12 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
137138
<< " pointers, " << Calls.size() << " call sites\n";
138139

139140
// iterate over the worklist, and run the full (n^2)/2 disambiguations
140-
for (SetVector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
141-
I1 != E; ++I1) {
142-
auto I1Size = LocationSize::afterPointer();
143-
Type *I1ElTy = (*I1)->getType()->getPointerElementType();
144-
if (I1ElTy->isSized())
145-
I1Size = LocationSize::precise(DL.getTypeStoreSize(I1ElTy));
146-
147-
for (SetVector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
148-
auto I2Size = LocationSize::afterPointer();
149-
Type *I2ElTy = (*I2)->getType()->getPointerElementType();
150-
if (I2ElTy->isSized())
151-
I2Size = LocationSize::precise(DL.getTypeStoreSize(I2ElTy));
152-
153-
AliasResult AR = AA.alias(*I1, I1Size, *I2, I2Size);
141+
for (auto I1 = Pointers.begin(), E = Pointers.end(); I1 != E; ++I1) {
142+
LocationSize Size1 = LocationSize::precise(DL.getTypeStoreSize(I1->second));
143+
for (auto I2 = Pointers.begin(); I2 != I1; ++I2) {
144+
LocationSize Size2 =
145+
LocationSize::precise(DL.getTypeStoreSize(I2->second));
146+
AliasResult AR = AA.alias(I1->first, Size1, I2->first, Size2);
154147
switch (AR) {
155148
case AliasResult::NoAlias:
156149
PrintResults(AR, PrintNoAlias, *I1, *I2, F.getParent());
@@ -229,13 +222,10 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
229222

230223
// Mod/ref alias analysis: compare all pairs of calls and values
231224
for (CallBase *Call : Calls) {
232-
for (auto Pointer : Pointers) {
233-
auto Size = LocationSize::afterPointer();
234-
Type *ElTy = Pointer->getType()->getPointerElementType();
235-
if (ElTy->isSized())
236-
Size = LocationSize::precise(DL.getTypeStoreSize(ElTy));
237-
238-
switch (AA.getModRefInfo(Call, Pointer, Size)) {
225+
for (const auto &Pointer : Pointers) {
226+
LocationSize Size =
227+
LocationSize::precise(DL.getTypeStoreSize(Pointer.second));
228+
switch (AA.getModRefInfo(Call, Pointer.first, Size)) {
239229
case ModRefInfo::NoModRef:
240230
PrintModRefResults("NoModRef", PrintNoModRef, Call, Pointer,
241231
F.getParent());

llvm/test/Analysis/BasicAA/128-bit-ptr.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ define void @test0(%T addrspace(100)* %P) {
1818
%C = getelementptr %T, %T addrspace(100)* %P, i64 0, i32 1
1919
%D = getelementptr %T, %T addrspace(100)* %P, i64 0, i32 1, i64 0
2020
%E = getelementptr %T, %T addrspace(100)* %P, i64 0, i32 1, i64 5
21+
load %T, %T addrspace(100)* %A
22+
load i32, i32 addrspace(100)* %B
23+
load [10 x i8], [10 x i8] addrspace(100)* %C
24+
load i8, i8 addrspace(100)* %D
25+
load i8, i8 addrspace(100)* %E
2126
ret void
2227
}
2328

@@ -37,6 +42,8 @@ define void @test1(double addrspace(100)* %P, i128 %i) {
3742
%i69 = add i128 %i, 590295810358705651712
3843
%A = getelementptr double, double addrspace(100)* %P, i128 %i70
3944
%B = getelementptr double, double addrspace(100)* %P, i128 %i69
45+
load double, double addrspace(100)* %A
46+
load double, double addrspace(100)* %B
4047
ret void
4148
}
4249

@@ -56,5 +63,7 @@ define void @test2(double addrspace(100)* %P, i128 %i) {
5663
%j70 = add i128 %i69, 590295810358705651712
5764
%A = getelementptr double, double addrspace(100)* %P, i128 %i70
5865
%C = getelementptr double, double addrspace(100)* %P, i128 %j70
66+
load double, double addrspace(100)* %A
67+
load double, double addrspace(100)* %C
5968
ret void
6069
}

llvm/test/Analysis/BasicAA/2006-03-03-BadArraySubscript.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ no_exit: ; preds = %no_exit, %entry
2626
loopexit: ; preds = %no_exit, %entry
2727
%Y.0.1 = phi i32 [ 0, %entry ], [ %tmp.13, %no_exit ] ; <i32> [#uses=1]
2828
%tmp.4 = getelementptr [3 x [3 x i32]], [3 x [3 x i32]]* %X, i32 0, i32 0 ; <[3 x i32]*> [#uses=1]
29+
load [3 x i32], [3 x i32]* %tmp.4
2930
%tmp.15 = call i32 (...) @foo( [3 x i32]* %tmp.4, i32 %Y.0.1 ) ; <i32> [#uses=0]
3031
ret void
3132
}

0 commit comments

Comments
 (0)