Skip to content

Commit ffddffc

Browse files
committed
Update SideEffectAnalysis to use BasicCalleeAnalysis.
This is one step towards removing the full call graph. In the process it removes a bit of brittleness around side effect analysis queries which previously may or may not have returned the most conservative result depending on whether we already had a valid call graph constructed.
1 parent 4cbdfda commit ffddffc

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

include/swift/SILAnalysis/SideEffectAnalysis.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace swift {
2424

25+
class BasicCalleeAnalysis;
2526
class CallGraphAnalysis;
2627
class CallGraph;
2728

@@ -265,6 +266,9 @@ class SideEffectAnalysis : public SILAnalysis {
265266
/// The allocator for the map values in Function2Effects.
266267
llvm::SpecificBumpPtrAllocator<FunctionEffects> Allocator;
267268

269+
/// Callee analysis, used for determining the callees at call sites.
270+
BasicCalleeAnalysis *BCA;
271+
268272
/// This analysis depends on the call graph.
269273
CallGraphAnalysis *CGA;
270274

@@ -286,11 +290,10 @@ class SideEffectAnalysis : public SILAnalysis {
286290
void analyzeFunction(SILFunction *F, WorkListType &WorkList, CallGraph &CG);
287291

288292
/// Analyise the side-effects of a single SIL instruction.
289-
void analyzeInstruction(FunctionEffects &Effects, SILInstruction *I,
290-
CallGraph &CG);
293+
void analyzeInstruction(FunctionEffects &Effects, SILInstruction *I);
291294

292295
/// Get the side-effects of a call site.
293-
void getEffectsOfApply(FunctionEffects &FE, FullApplySite FAS, CallGraph &CG,
296+
void getEffectsOfApply(FunctionEffects &FE, FullApplySite FAS,
294297
bool isRecomputing);
295298

296299
/// Gets or creates FunctionEffects for \p F. If \a isRecomputing is true,

lib/SILAnalysis/SideEffectAnalysis.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#define DEBUG_TYPE "sil-sea"
1414
#include "swift/SILAnalysis/SideEffectAnalysis.h"
15+
#include "swift/SILAnalysis/BasicCalleeAnalysis.h"
1516
#include "swift/SILAnalysis/CallGraphAnalysis.h"
1617
#include "swift/SILAnalysis/ArraySemantic.h"
1718
#include "swift/SILPasses/PassManager.h"
@@ -256,7 +257,7 @@ void SideEffectAnalysis::analyzeFunction(SILFunction *F,
256257
// Check all instructions of the function
257258
for (auto &BB : *F) {
258259
for (auto &I : BB) {
259-
analyzeInstruction(NewEffects, &I, CG);
260+
analyzeInstruction(NewEffects, &I);
260261
DEBUG(if (RefEffects.mergeFrom(NewEffects))
261262
llvm::dbgs() << " " << NewEffects << "\t changed in " << I);
262263
}
@@ -272,10 +273,10 @@ void SideEffectAnalysis::analyzeFunction(SILFunction *F,
272273
}
273274

274275
void SideEffectAnalysis::analyzeInstruction(FunctionEffects &FE,
275-
SILInstruction *I, CallGraph &CG) {
276+
SILInstruction *I) {
276277
if (FullApplySite FAS = FullApplySite::isa(I)) {
277278
FunctionEffects ApplyEffects;
278-
getEffectsOfApply(ApplyEffects, FAS, CG, true);
279+
getEffectsOfApply(ApplyEffects, FAS, true);
279280
FE.mergeFromApply(ApplyEffects, FAS);
280281
return;
281282
}
@@ -358,7 +359,7 @@ void SideEffectAnalysis::analyzeInstruction(FunctionEffects &FE,
358359
}
359360

360361
void SideEffectAnalysis::getEffectsOfApply(FunctionEffects &ApplyEffects,
361-
FullApplySite FAS, CallGraph &CG,
362+
FullApplySite FAS,
362363
bool isRecomputing) {
363364

364365
assert(ApplyEffects.ParamEffects.size() == 0 &&
@@ -369,20 +370,22 @@ void SideEffectAnalysis::getEffectsOfApply(FunctionEffects &ApplyEffects,
369370
if (getSemanticEffects(ApplyEffects, FAS))
370371
return;
371372

372-
if (CG.canCallUnknownFunction(FAS.getInstruction())) {
373+
auto Callees = BCA->getCalleeList(FAS);
374+
if (Callees.isIncomplete()) {
373375
ApplyEffects.setWorstEffects();
374376
return;
375377
}
376378

377379
// We can see all the callees. So we just merge the effects from all of
378380
// them.
379-
for (auto *F : CG.getCallees(FAS.getInstruction())) {
381+
for (auto *F : Callees) {
380382
auto *E = getFunctionEffects(F, isRecomputing);
381383
ApplyEffects.mergeFrom(*E);
382384
}
383385
}
384386

385387
void SideEffectAnalysis::initialize(SILPassManager *PM) {
388+
BCA = PM->getAnalysis<BasicCalleeAnalysis>();
386389
CGA = PM->getAnalysis<CallGraphAnalysis>();
387390
}
388391

@@ -414,12 +417,7 @@ void SideEffectAnalysis::recompute() {
414417
}
415418

416419
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);
423421
}
424422

425423
SILAnalysis *swift::createSideEffectAnalysis(SILModule *M) {

0 commit comments

Comments
 (0)