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