Skip to content

Commit 02e08e2

Browse files
committed
Revert "Update SideEffectAnalysis to use BasicCalleeAnalysis."
This reverts commit ffddffc. It triggers a miscompile in the benchmarks. In addition I had to disable the cse_apply.sil test.
1 parent cbf5495 commit 02e08e2

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

include/swift/SILAnalysis/SideEffectAnalysis.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
namespace swift {
2424

25-
class BasicCalleeAnalysis;
2625
class CallGraphAnalysis;
2726
class CallGraph;
2827

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

269-
/// Callee analysis, used for determining the callees at call sites.
270-
BasicCalleeAnalysis *BCA;
271-
272268
/// This analysis depends on the call graph.
273269
CallGraphAnalysis *CGA;
274270

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

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

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

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

lib/SILAnalysis/SideEffectAnalysis.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#define DEBUG_TYPE "sil-sea"
1414
#include "swift/SILAnalysis/SideEffectAnalysis.h"
15-
#include "swift/SILAnalysis/BasicCalleeAnalysis.h"
1615
#include "swift/SILAnalysis/CallGraphAnalysis.h"
1716
#include "swift/SILAnalysis/ArraySemantic.h"
1817
#include "swift/SILPasses/PassManager.h"
@@ -257,7 +256,7 @@ void SideEffectAnalysis::analyzeFunction(SILFunction *F,
257256
// Check all instructions of the function
258257
for (auto &BB : *F) {
259258
for (auto &I : BB) {
260-
analyzeInstruction(NewEffects, &I);
259+
analyzeInstruction(NewEffects, &I, CG);
261260
DEBUG(if (RefEffects.mergeFrom(NewEffects))
262261
llvm::dbgs() << " " << NewEffects << "\t changed in " << I);
263262
}
@@ -273,10 +272,10 @@ void SideEffectAnalysis::analyzeFunction(SILFunction *F,
273272
}
274273

275274
void SideEffectAnalysis::analyzeInstruction(FunctionEffects &FE,
276-
SILInstruction *I) {
275+
SILInstruction *I, CallGraph &CG) {
277276
if (FullApplySite FAS = FullApplySite::isa(I)) {
278277
FunctionEffects ApplyEffects;
279-
getEffectsOfApply(ApplyEffects, FAS, true);
278+
getEffectsOfApply(ApplyEffects, FAS, CG, true);
280279
FE.mergeFromApply(ApplyEffects, FAS);
281280
return;
282281
}
@@ -359,7 +358,7 @@ void SideEffectAnalysis::analyzeInstruction(FunctionEffects &FE,
359358
}
360359

361360
void SideEffectAnalysis::getEffectsOfApply(FunctionEffects &ApplyEffects,
362-
FullApplySite FAS,
361+
FullApplySite FAS, CallGraph &CG,
363362
bool isRecomputing) {
364363

365364
assert(ApplyEffects.ParamEffects.size() == 0 &&
@@ -370,22 +369,20 @@ void SideEffectAnalysis::getEffectsOfApply(FunctionEffects &ApplyEffects,
370369
if (getSemanticEffects(ApplyEffects, FAS))
371370
return;
372371

373-
auto Callees = BCA->getCalleeList(FAS);
374-
if (Callees.isIncomplete()) {
372+
if (CG.canCallUnknownFunction(FAS.getInstruction())) {
375373
ApplyEffects.setWorstEffects();
376374
return;
377375
}
378376

379377
// We can see all the callees. So we just merge the effects from all of
380378
// them.
381-
for (auto *F : Callees) {
379+
for (auto *F : CG.getCallees(FAS.getInstruction())) {
382380
auto *E = getFunctionEffects(F, isRecomputing);
383381
ApplyEffects.mergeFrom(*E);
384382
}
385383
}
386384

387385
void SideEffectAnalysis::initialize(SILPassManager *PM) {
388-
BCA = PM->getAnalysis<BasicCalleeAnalysis>();
389386
CGA = PM->getAnalysis<CallGraphAnalysis>();
390387
}
391388

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

419416
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();
421423
}
422424

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

test/SILPasses/cse_apply.sil

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all %s -side-effects -cse | FileCheck %s
22

3+
// Currently SideEffectAnalysis has no effect in CSE.
4+
// TODO: reenable this test when this is fixed.
5+
// REQUIRES: FIXME
6+
37
sil_stage canonical
48

59
import Builtin

0 commit comments

Comments
 (0)