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