27
27
#include " swift/SIL/SILValue.h"
28
28
#include " swift/SIL/SILVisitor.h"
29
29
#include " swift/SILOptimizer/Analysis/ArraySemantic.h"
30
+ #include " swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
30
31
#include " swift/SILOptimizer/Analysis/DominanceAnalysis.h"
31
- #include " swift/SILOptimizer/Analysis/SideEffectAnalysis.h"
32
32
#include " swift/SILOptimizer/Analysis/SimplifyInstruction.h"
33
33
#include " swift/SILOptimizer/PassManager/Passes.h"
34
34
#include " swift/SILOptimizer/PassManager/Transforms.h"
@@ -583,7 +583,7 @@ class CSE {
583
583
// / their lookup.
584
584
ScopedHTType *AvailableValues;
585
585
586
- SideEffectAnalysis *SEA ;
586
+ BasicCalleeAnalysis *BCA ;
587
587
588
588
SILOptFunctionBuilder &FuncBuilder;
589
589
@@ -595,10 +595,10 @@ class CSE {
595
595
// / load of the property value.
596
596
llvm::SmallVector<ApplyInst *, 8 > lazyPropertyGetters;
597
597
598
- CSE (bool RunsOnHighLevelSil, SideEffectAnalysis *SEA ,
598
+ CSE (bool RunsOnHighLevelSil, BasicCalleeAnalysis *BCA ,
599
599
SILOptFunctionBuilder &FuncBuilder, DeadEndBlocks &DeadEndBBs,
600
600
OwnershipFixupContext &RAUWFixupContext)
601
- : SEA(SEA ), FuncBuilder(FuncBuilder), DeadEndBBs(DeadEndBBs),
601
+ : BCA(BCA ), FuncBuilder(FuncBuilder), DeadEndBBs(DeadEndBBs),
602
602
RAUWFixupContext (RAUWFixupContext),
603
603
RunsOnHighLevelSil(RunsOnHighLevelSil) {}
604
604
@@ -1064,16 +1064,22 @@ bool CSE::canHandle(SILInstruction *Inst) {
1064
1064
return false ;
1065
1065
}
1066
1066
}
1067
-
1067
+
1068
+ if (!AI->getFunction ()->hasOwnership ()) {
1069
+ // In non-OSSA we don't balance CSE'd apply results which return an
1070
+ // owned value.
1071
+ if (auto ri = AI->getSingleResult ()) {
1072
+ if (ri.getValue ().getConvention () != ResultConvention::Unowned)
1073
+ return false ;
1074
+ }
1075
+ }
1076
+
1068
1077
// We can CSE function calls which do not read or write memory and don't
1069
1078
// have any other side effects.
1070
- FunctionSideEffects Effects;
1071
- SEA->getCalleeEffects (Effects, AI);
1072
-
1073
1079
// Note that the function also may not contain any retains. And there are
1074
1080
// functions which are read-none and have a retain, e.g. functions which
1075
1081
// _convert_ a global_addr to a reference and retain it.
1076
- auto MB = Effects. getMemBehavior (RetainObserveKind::ObserveRetains );
1082
+ auto MB = BCA-> getMemoryBehavior ( ApplySite (AI), /* observeRetains */ false );
1077
1083
if (MB == SILInstruction::MemoryBehavior::None)
1078
1084
return true ;
1079
1085
@@ -1392,14 +1398,14 @@ class SILCSE : public SILFunctionTransform {
1392
1398
1393
1399
DominanceAnalysis* DA = getAnalysis<DominanceAnalysis>();
1394
1400
1395
- auto *SEA = PM->getAnalysis <SideEffectAnalysis >();
1401
+ auto *BCA = PM->getAnalysis <BasicCalleeAnalysis >();
1396
1402
SILOptFunctionBuilder FuncBuilder (*this );
1397
1403
1398
1404
auto *Fn = getFunction ();
1399
1405
DeadEndBlocks DeadEndBBs (Fn);
1400
1406
InstModCallbacks callbacks;
1401
1407
OwnershipFixupContext FixupCtx{callbacks, DeadEndBBs};
1402
- CSE C (RunsOnHighLevelSil, SEA , FuncBuilder, DeadEndBBs, FixupCtx);
1408
+ CSE C (RunsOnHighLevelSil, BCA , FuncBuilder, DeadEndBBs, FixupCtx);
1403
1409
bool Changed = false ;
1404
1410
1405
1411
// Perform the traditional CSE.
0 commit comments