@@ -147,9 +147,7 @@ static void mapOperands(SILInstruction *inst,
147
147
static void updateSSAForUseOfValue (
148
148
SILSSAUpdater &updater, SmallVectorImpl<SILPhiArgument *> &insertedPhis,
149
149
const llvm::DenseMap<ValueBase *, SILValue> &valueMap,
150
- SILBasicBlock *Header, SILBasicBlock *EntryCheckBlock, SILValue Res,
151
- SmallVectorImpl<std::pair<SILBasicBlock *, unsigned >>
152
- &accumulatedAddressPhis) {
150
+ SILBasicBlock *Header, SILBasicBlock *EntryCheckBlock, SILValue Res) {
153
151
// Find the mapped instruction.
154
152
assert (valueMap.count (Res) && " Expected to find value in map!" );
155
153
SILValue MappedValue = valueMap.find (Res)->second ;
@@ -179,14 +177,13 @@ static void updateSSAForUseOfValue(
179
177
if (user->getParent () == Header)
180
178
continue ;
181
179
182
- assert (user->getParent () != EntryCheckBlock
183
- && " The entry check block should dominate the header" );
180
+ assert (user->getParent () != EntryCheckBlock &&
181
+ " The entry check block should dominate the header" );
184
182
updater.rewriteUse (*use);
185
183
}
186
184
187
185
// Canonicalize inserted phis to avoid extra BB Args and if we find an address
188
186
// phi, stash it so we can handle it after we are done rewriting.
189
- bool hasOwnership = Header->getParent ()->hasOwnership ();
190
187
for (SILPhiArgument *arg : insertedPhis) {
191
188
if (SILValue inst = replaceBBArgWithCast (arg)) {
192
189
arg->replaceAllUsesWith (inst);
@@ -195,30 +192,24 @@ static void updateSSAForUseOfValue(
195
192
// SimplifyCFG deletes the dead BB arg.
196
193
continue ;
197
194
}
198
-
199
- // If we didn't simplify and have an address phi, stash the value so we can
200
- // fix it up.
201
- if (hasOwnership && arg->getType ().isAddress ())
202
- accumulatedAddressPhis.emplace_back (arg->getParent (), arg->getIndex ());
203
195
}
204
196
}
205
197
206
- static void updateSSAForUseOfInst (
207
- SILSSAUpdater &updater, SmallVectorImpl<SILPhiArgument *> &insertedPhis ,
208
- const llvm::DenseMap<ValueBase *, SILValue > &valueMap ,
209
- SILBasicBlock *header, SILBasicBlock *entryCheckBlock, SILInstruction *inst ,
210
- SmallVectorImpl<std::pair< SILBasicBlock *, unsigned >>
211
- &accumulatedAddressPhis ) {
198
+ static void
199
+ updateSSAForUseOfInst ( SILSSAUpdater &updater,
200
+ SmallVectorImpl<SILPhiArgument * > &insertedPhis ,
201
+ const llvm::DenseMap<ValueBase *, SILValue> &valueMap ,
202
+ SILBasicBlock *header, SILBasicBlock *entryCheckBlock,
203
+ SILInstruction *inst ) {
212
204
for (auto result : inst->getResults ())
213
205
updateSSAForUseOfValue (updater, insertedPhis, valueMap, header,
214
- entryCheckBlock, result, accumulatedAddressPhis );
206
+ entryCheckBlock, result);
215
207
}
216
208
217
209
// / Rewrite the code we just created in the preheader and update SSA form.
218
210
static void rewriteNewLoopEntryCheckBlock (
219
211
SILBasicBlock *header, SILBasicBlock *entryCheckBlock,
220
212
const llvm::DenseMap<ValueBase *, SILValue> &valueMap) {
221
- SmallVector<std::pair<SILBasicBlock *, unsigned >, 8 > accumulatedAddressPhis;
222
213
SmallVector<SILPhiArgument *, 8 > insertedPhis;
223
214
SILSSAUpdater updater (&insertedPhis);
224
215
@@ -227,7 +218,7 @@ static void rewriteNewLoopEntryCheckBlock(
227
218
for (unsigned i : range (header->getNumArguments ())) {
228
219
auto *arg = header->getArguments ()[i];
229
220
updateSSAForUseOfValue (updater, insertedPhis, valueMap, header,
230
- entryCheckBlock, arg, accumulatedAddressPhis );
221
+ entryCheckBlock, arg);
231
222
}
232
223
233
224
auto instIter = header->begin ();
@@ -236,43 +227,9 @@ static void rewriteNewLoopEntryCheckBlock(
236
227
while (instIter != header->end ()) {
237
228
auto &inst = *instIter;
238
229
updateSSAForUseOfInst (updater, insertedPhis, valueMap, header,
239
- entryCheckBlock, &inst, accumulatedAddressPhis );
230
+ entryCheckBlock, &inst);
240
231
++instIter;
241
232
}
242
-
243
- // Then see if any of our phis were address phis. In such a case, rewrite the
244
- // address to be a smuggled through raw pointer. We do this late to
245
- // conservatively not interfere with the previous code's invariants.
246
- //
247
- // We also translate the phis into a BasicBlock, Index form so we are careful
248
- // with invalidation issues around branches/args.
249
- auto rawPointerTy =
250
- SILType::getRawPointerType (header->getParent ()->getASTContext ());
251
- auto rawPointerUndef = SILUndef::get (rawPointerTy, header->getModule ());
252
- auto loc = RegularLocation::getAutoGeneratedLocation ();
253
- while (!accumulatedAddressPhis.empty ()) {
254
- SILBasicBlock *block;
255
- unsigned argIndex;
256
- std::tie (block, argIndex) = accumulatedAddressPhis.pop_back_val ();
257
- auto *arg = cast<SILPhiArgument>(block->getArgument (argIndex));
258
- assert (arg->getType ().isAddress () && " Not an address phi?!" );
259
- for (auto *predBlock : block->getPredecessorBlocks ()) {
260
- Operand *predUse = arg->getIncomingPhiOperand (predBlock);
261
- SILBuilderWithScope builder (predUse->getUser ());
262
- auto *newIncomingValue =
263
- builder.createAddressToPointer (loc, predUse->get (), rawPointerTy);
264
- predUse->set (newIncomingValue);
265
- }
266
- SILBuilderWithScope builder (arg->getNextInstruction ());
267
- SILType oldArgType = arg->getType ();
268
- auto *phiShim = builder.createPointerToAddress (
269
- loc, rawPointerUndef, oldArgType, true /* isStrict*/ ,
270
- false /* is invariant*/ );
271
- arg->replaceAllUsesWith (phiShim);
272
- SILArgument *newArg = block->replacePhiArgument (
273
- argIndex, rawPointerTy, OwnershipKind::None, nullptr );
274
- phiShim->setOperand (newArg);
275
- }
276
233
}
277
234
278
235
// / Update the dominator tree after rotating the loop.
0 commit comments