@@ -121,24 +121,16 @@ using SCCNodeSet = SmallSetVector<Function *, 8>;
121
121
// / result will be based only on AA results for the function declaration; it
122
122
// / will be assumed that some other (perhaps less optimized) version of the
123
123
// / function may be selected at link time.
124
- static MemoryAccessKind checkFunctionMemoryAccess (Function &F, bool ThisBody,
125
- AAResults &AAR,
126
- const SCCNodeSet &SCCNodes) {
124
+ static FunctionModRefBehavior
125
+ checkFunctionMemoryAccess (Function &F, bool ThisBody, AAResults &AAR,
126
+ const SCCNodeSet &SCCNodes) {
127
127
FunctionModRefBehavior MRB = AAR.getModRefBehavior (&F);
128
128
if (MRB == FMRB_DoesNotAccessMemory)
129
129
// Already perfect!
130
- return MAK_ReadNone ;
130
+ return MRB ;
131
131
132
- if (!ThisBody) {
133
- if (AliasAnalysis::onlyReadsMemory (MRB))
134
- return MAK_ReadOnly;
135
-
136
- if (AliasAnalysis::onlyWritesMemory (MRB))
137
- return MAK_WriteOnly;
138
-
139
- // Conservatively assume it reads and writes to memory.
140
- return MAK_MayWrite;
141
- }
132
+ if (!ThisBody)
133
+ return MRB;
142
134
143
135
// Scan the function body for instructions that may read or write memory.
144
136
bool ReadsMemory = false ;
@@ -232,18 +224,18 @@ static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody,
232
224
ReadsMemory |= I.mayReadFromMemory ();
233
225
}
234
226
235
- if (WritesMemory) {
227
+ if (WritesMemory) {
236
228
if (!ReadsMemory)
237
- return MAK_WriteOnly ;
229
+ return FMRB_OnlyWritesMemory ;
238
230
else
239
- return MAK_MayWrite ;
231
+ return FMRB_UnknownModRefBehavior ;
240
232
}
241
233
242
- return ReadsMemory ? MAK_ReadOnly : MAK_ReadNone ;
234
+ return ReadsMemory ? FMRB_OnlyReadsMemory : FMRB_DoesNotAccessMemory ;
243
235
}
244
236
245
- MemoryAccessKind llvm::computeFunctionBodyMemoryAccess (Function &F,
246
- AAResults &AAR) {
237
+ FunctionModRefBehavior llvm::computeFunctionBodyMemoryAccess (Function &F,
238
+ AAResults &AAR) {
247
239
return checkFunctionMemoryAccess (F, /* ThisBody=*/ true , AAR, {});
248
240
}
249
241
@@ -262,20 +254,14 @@ static void addMemoryAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter,
262
254
// Non-exact function definitions may not be selected at link time, and an
263
255
// alternative version that writes to memory may be selected. See the
264
256
// comment on GlobalValue::isDefinitionExact for more details.
265
- switch ( checkFunctionMemoryAccess (*F, F-> hasExactDefinition (),
266
- AAR, SCCNodes)) {
267
- case MAK_MayWrite:
257
+ FunctionModRefBehavior FMRB =
258
+ checkFunctionMemoryAccess (*F, F-> hasExactDefinition (), AAR, SCCNodes);
259
+ if ( isModAndRefSet ( createModRefInfo (FMRB)))
268
260
return ;
269
- case MAK_ReadOnly:
270
- ReadsMemory = true ;
271
- break ;
272
- case MAK_WriteOnly:
273
- WritesMemory = true ;
274
- break ;
275
- case MAK_ReadNone:
276
- // Nothing to do!
277
- break ;
278
- }
261
+ if (FMRB == FMRB_DoesNotAccessMemory)
262
+ continue ;
263
+ ReadsMemory |= AliasAnalysis::onlyReadsMemory (FMRB);
264
+ WritesMemory |= AliasAnalysis::onlyWritesMemory (FMRB);
279
265
}
280
266
281
267
// If the SCC contains both functions that read and functions that write, then
0 commit comments