Skip to content

Commit 4db2aa6

Browse files
committed
[sil-combine] Add an OwnershipFixupContext to SILCombine.
1 parent c103503 commit 4db2aa6

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,21 @@ namespace swift {
2929
struct JointPostDominanceSetComputer;
3030

3131
struct OwnershipFixupContext {
32-
InstModCallbacks callbacks;
32+
Optional<InstModCallbacks> inlineCallbacks;
33+
InstModCallbacks &callbacks;
3334
DeadEndBlocks &deBlocks;
3435
JointPostDominanceSetComputer &jointPostDomSetComputer;
3536

37+
OwnershipFixupContext(InstModCallbacks &callbacks, DeadEndBlocks &deBlocks,
38+
JointPostDominanceSetComputer &inputJPDComputer)
39+
: inlineCallbacks(), callbacks(callbacks), deBlocks(deBlocks),
40+
jointPostDomSetComputer(inputJPDComputer) {}
41+
42+
OwnershipFixupContext(DeadEndBlocks &deBlocks,
43+
JointPostDominanceSetComputer &inputJPDComputer)
44+
: inlineCallbacks(InstModCallbacks()), callbacks(*inlineCallbacks),
45+
deBlocks(deBlocks), jointPostDomSetComputer(inputJPDComputer) {}
46+
3647
SILBasicBlock::iterator
3748
replaceAllUsesAndEraseFixingOwnership(SingleValueInstruction *oldValue,
3849
SILValue newValue);

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/SILOptimizer/Utils/CastOptimizer.h"
3333
#include "swift/SILOptimizer/Utils/Existential.h"
3434
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
35+
#include "swift/SILOptimizer/Utils/OwnershipOptUtils.h"
3536
#include "llvm/ADT/DenseMap.h"
3637
#include "llvm/ADT/SmallVector.h"
3738

@@ -87,6 +88,20 @@ class SILCombiner :
8788
/// Centralized InstModCallback that we use for certain utility methods.
8889
InstModCallbacks instModCallbacks;
8990

91+
/// Dead end blocks cache. SILCombine is already not allowed to mess with CFG
92+
/// edges so it is safe to use this here.
93+
DeadEndBlocks deBlocks;
94+
95+
/// A utility struct used by OwnershipFixupContext to map sets of partially
96+
/// post-dominating blocks to a full jointly post-dominating set.
97+
JointPostDominanceSetComputer jPostDomComputer;
98+
99+
/// A utility that we use to perform erase+RAUW that fixes up ownership for us
100+
/// afterwards by lifetime extending/copy values as appropriate. We rely on
101+
/// later optimizations to chew through this traffic. This ensures we can use
102+
/// one code base for both OSSA and non-OSSA.
103+
OwnershipFixupContext ownershipRAUWHelper;
104+
90105
public:
91106
SILCombiner(SILOptFunctionBuilder &FuncBuilder, SILBuilder &B,
92107
AliasAnalysis *AA, DominanceAnalysis *DA,
@@ -117,7 +132,9 @@ class SILCombiner :
117132
[&](Operand *use, SILValue newValue) {
118133
use->set(newValue);
119134
Worklist.add(use->getUser());
120-
}) {}
135+
}),
136+
deBlocks(&B.getFunction()), jPostDomComputer(deBlocks),
137+
ownershipRAUWHelper(instModCallbacks, deBlocks, jPostDomComputer) {}
121138

122139
bool runOnFunction(SILFunction &F);
123140

0 commit comments

Comments
 (0)