12
12
13
13
#define DEBUG_TYPE " sil-sea"
14
14
#include " swift/SILAnalysis/SideEffectAnalysis.h"
15
+ #include " swift/SILAnalysis/BasicCalleeAnalysis.h"
15
16
#include " swift/SILAnalysis/CallGraphAnalysis.h"
16
17
#include " swift/SILAnalysis/ArraySemantic.h"
17
18
#include " swift/SILPasses/PassManager.h"
@@ -256,7 +257,7 @@ void SideEffectAnalysis::analyzeFunction(SILFunction *F,
256
257
// Check all instructions of the function
257
258
for (auto &BB : *F) {
258
259
for (auto &I : BB) {
259
- analyzeInstruction (NewEffects, &I, CG );
260
+ analyzeInstruction (NewEffects, &I);
260
261
DEBUG (if (RefEffects.mergeFrom (NewEffects))
261
262
llvm::dbgs () << " " << NewEffects << " \t changed in " << I);
262
263
}
@@ -272,10 +273,10 @@ void SideEffectAnalysis::analyzeFunction(SILFunction *F,
272
273
}
273
274
274
275
void SideEffectAnalysis::analyzeInstruction (FunctionEffects &FE,
275
- SILInstruction *I, CallGraph &CG ) {
276
+ SILInstruction *I) {
276
277
if (FullApplySite FAS = FullApplySite::isa (I)) {
277
278
FunctionEffects ApplyEffects;
278
- getEffectsOfApply (ApplyEffects, FAS, CG, true );
279
+ getEffectsOfApply (ApplyEffects, FAS, true );
279
280
FE.mergeFromApply (ApplyEffects, FAS);
280
281
return ;
281
282
}
@@ -358,7 +359,7 @@ void SideEffectAnalysis::analyzeInstruction(FunctionEffects &FE,
358
359
}
359
360
360
361
void SideEffectAnalysis::getEffectsOfApply (FunctionEffects &ApplyEffects,
361
- FullApplySite FAS, CallGraph &CG,
362
+ FullApplySite FAS,
362
363
bool isRecomputing) {
363
364
364
365
assert (ApplyEffects.ParamEffects .size () == 0 &&
@@ -369,20 +370,22 @@ void SideEffectAnalysis::getEffectsOfApply(FunctionEffects &ApplyEffects,
369
370
if (getSemanticEffects (ApplyEffects, FAS))
370
371
return ;
371
372
372
- if (CG.canCallUnknownFunction (FAS.getInstruction ())) {
373
+ auto Callees = BCA->getCalleeList (FAS);
374
+ if (Callees.isIncomplete ()) {
373
375
ApplyEffects.setWorstEffects ();
374
376
return ;
375
377
}
376
378
377
379
// We can see all the callees. So we just merge the effects from all of
378
380
// them.
379
- for (auto *F : CG. getCallees (FAS. getInstruction ()) ) {
381
+ for (auto *F : Callees ) {
380
382
auto *E = getFunctionEffects (F, isRecomputing);
381
383
ApplyEffects.mergeFrom (*E);
382
384
}
383
385
}
384
386
385
387
void SideEffectAnalysis::initialize (SILPassManager *PM) {
388
+ BCA = PM->getAnalysis <BasicCalleeAnalysis>();
386
389
CGA = PM->getAnalysis <CallGraphAnalysis>();
387
390
}
388
391
@@ -414,12 +417,7 @@ void SideEffectAnalysis::recompute() {
414
417
}
415
418
416
419
void SideEffectAnalysis::getEffects (FunctionEffects &FE, FullApplySite FAS) {
417
- CallGraph *CG = CGA->getCallGraphOrNull ();
418
- if (CG) {
419
- getEffectsOfApply (FE, FAS, *CG, false );
420
- return ;
421
- }
422
- FE.setWorstEffects ();
420
+ getEffectsOfApply (FE, FAS, false );
423
421
}
424
422
425
423
SILAnalysis *swift::createSideEffectAnalysis (SILModule *M) {
0 commit comments