@@ -39,30 +39,48 @@ static cl::opt<bool> PrintMustModRef("print-mustmodref", cl::ReallyHidden);
39
39
40
40
static cl::opt<bool > EvalAAMD (" evaluate-aa-metadata" , cl::ReallyHidden);
41
41
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) {
44
46
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 ();
45
50
std::string o1, o2;
46
51
{
47
52
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);
50
55
}
51
56
52
57
if (o2 < o1) {
53
58
std::swap (o1, o2);
59
+ std::swap (Ty1, Ty2);
60
+ std::swap (AS1, AS2);
54
61
// Change offset sign for the local AR, for printing only.
55
62
AR.swap ();
56
63
}
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 " ;
58
73
}
59
74
}
60
75
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) {
63
79
if (PrintAll || P) {
64
80
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);
66
84
errs () << " \t <->" << *I << ' \n ' ;
67
85
}
68
86
}
@@ -97,38 +115,21 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
97
115
98
116
++FunctionCount;
99
117
100
- SetVector<Value *> Pointers;
118
+ SetVector<std::pair< const Value *, Type *> > Pointers;
101
119
SmallSetVector<CallBase *, 16 > Calls;
102
120
SetVector<Value *> Loads;
103
121
SetVector<Value *> Stores;
104
122
105
- for (auto &I : F.args ())
106
- if (I.getType ()->isPointerTy ()) // Add all pointer arguments.
107
- Pointers.insert (&I);
108
-
109
123
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);
132
133
}
133
134
134
135
if (PrintAll || PrintNoAlias || PrintMayAlias || PrintPartialAlias ||
@@ -137,20 +138,12 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
137
138
<< " pointers, " << Calls.size () << " call sites\n " ;
138
139
139
140
// 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);
154
147
switch (AR) {
155
148
case AliasResult::NoAlias:
156
149
PrintResults (AR, PrintNoAlias, *I1, *I2, F.getParent ());
@@ -229,13 +222,10 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
229
222
230
223
// Mod/ref alias analysis: compare all pairs of calls and values
231
224
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)) {
239
229
case ModRefInfo::NoModRef:
240
230
PrintModRefResults (" NoModRef" , PrintNoModRef, Call, Pointer,
241
231
F.getParent ());
0 commit comments