@@ -78,104 +78,6 @@ static bool foldInverseReabstractionThunks(PartialApplyInst *PAI,
78
78
return true ;
79
79
}
80
80
81
- ApplyInst *getSingleApplyInBlock (SILBasicBlock &BB) {
82
- ApplyInst *Result = nullptr ;
83
-
84
- for (auto &I : BB) {
85
- if (isa<DebugValueAddrInst>(I) ||
86
- isa<DebugValueInst>(I))
87
- continue ;
88
-
89
- // FIXME: Should also support ClassMethodInst
90
- if (isa<WitnessMethodInst>(I) ||
91
- isa<ReturnInst>(I))
92
- continue ;
93
-
94
- if (auto *TI = dyn_cast<TupleInst>(&I))
95
- if (TI->getElements ().empty ())
96
- continue ;
97
-
98
- if (auto *AI = dyn_cast<ApplyInst>(&I)) {
99
- if (Result == nullptr ) {
100
- Result = AI;
101
- continue ;
102
- }
103
- }
104
-
105
- return nullptr ;
106
- }
107
-
108
- return Result;
109
- }
110
-
111
- static bool foldPartialApplyOfTrivialClosure (PartialApplyInst *PAI,
112
- SILCombiner *Combiner) {
113
- auto *FRI = dyn_cast<FunctionRefInst>(PAI->getCallee ());
114
- if (FRI == nullptr )
115
- return false ;
116
-
117
- auto *F = FRI->getReferencedFunctionOrNull ();
118
- if (F == nullptr )
119
- return false ;
120
-
121
- // The referenced function must consist of a single basic block.
122
- if (F->getBlocks ().size () != 1 )
123
- return false ;
124
-
125
- // The referenced function must not throw.
126
- if (F->getLoweredFunctionType ()->getOptionalErrorResult ())
127
- return false ;
128
-
129
- // The only non-trivial instructions in the function must be an apply
130
- // of a witness_method callee.
131
- auto &BB = *F->getBlocks ().begin ();
132
- auto *AI = getSingleApplyInBlock (BB);
133
- if (AI == nullptr )
134
- return false ;
135
-
136
- // The apply instruction must have the same number of arguments as the
137
- // function that contains it, and they must be passed in order.
138
- auto InnerArgs = AI->getArguments ();
139
- if (InnerArgs.size () != BB.args_size ())
140
- return false ;
141
-
142
- auto ArgsIter = BB.args_begin ();
143
- for (auto Arg : InnerArgs) {
144
- if (Arg != *(ArgsIter++))
145
- return false ;
146
- }
147
-
148
- SILBuilderWithScope B (PAI);
149
-
150
- // FIXME: Should also support ClassMethodInst
151
- auto *WMI = cast<WitnessMethodInst>(AI->getCallee ());
152
- auto InnerSubs = PAI->getSubstitutionMap ();
153
- auto Subs = AI->getSubstitutionMap ().subst (InnerSubs);
154
- auto *NewCallee = B.createWitnessMethod (
155
- WMI->getLoc (),
156
- WMI->getLookupType ().subst (InnerSubs)->getCanonicalType (),
157
- WMI->getConformance ().subst (WMI->getLookupType (), InnerSubs),
158
- WMI->getMember (),
159
- WMI->getType ().subst (F->getModule ().Types , InnerSubs));
160
-
161
- SmallVector<SILValue, 8 > NewArgs;
162
- auto Args = PAI->getArguments ();
163
- NewArgs.append (Args.begin (), Args.end ());
164
-
165
- auto *NewPAI = B.createPartialApply (
166
- PAI->getLoc (),
167
- NewCallee,
168
- Subs,
169
- NewArgs,
170
- PAI->getType ().getAs <SILFunctionType>()->getCalleeConvention (),
171
- PAI->isOnStack ());
172
-
173
- assert (PAI->getType () == NewPAI->getType ());
174
- PAI->replaceAllUsesWith (NewPAI);
175
- Combiner->eraseInstFromFunction (*PAI);
176
- return true ;
177
- }
178
-
179
81
SILInstruction *SILCombiner::visitPartialApplyInst (PartialApplyInst *PAI) {
180
82
if (PAI->getFunction ()->hasOwnership ())
181
83
return nullptr ;
@@ -207,11 +109,6 @@ SILInstruction *SILCombiner::visitPartialApplyInst(PartialApplyInst *PAI) {
207
109
if (foldInverseReabstractionThunks (PAI, this ))
208
110
return nullptr ;
209
111
210
- // partial_apply %function_ref => partial_apply %witness_method if
211
- // the body of the function_ref is just an apply %witness_method
212
- if (foldPartialApplyOfTrivialClosure (PAI, this ))
213
- return nullptr ;
214
-
215
112
bool argsAreKeptAlive = tryOptimizeApplyOfPartialApply (
216
113
PAI, Builder.getBuilderContext (), getInstModCallbacks ());
217
114
if (argsAreKeptAlive)
0 commit comments