@@ -37,7 +37,11 @@ static_assert(std::is_standard_layout<Projection>::value,
37
37
// Utility
38
38
// ===----------------------------------------------------------------------===//
39
39
40
- // / We do not support symbolic projections yet, only 32-bit unsigned integers.
40
+ // / Extract an integer index from a SILValue.
41
+ // /
42
+ // / Return true if IndexVal is a constant index representable as unsigned
43
+ // / int. We do not support symbolic projections yet, only 32-bit unsigned
44
+ // / integers.
41
45
bool swift::getIntegerIndex (SILValue IndexVal, unsigned &IndexConst) {
42
46
if (auto *IndexLiteral = dyn_cast<IntegerLiteralInst>(IndexVal)) {
43
47
APInt ConstInt = IndexLiteral->getValue ();
@@ -187,7 +191,7 @@ Projection::Projection(SILInstruction *I) : Value() {
187
191
188
192
NullablePtr<SILInstruction>
189
193
Projection::createObjectProjection (SILBuilder &B, SILLocation Loc,
190
- SILValue Base) const {
194
+ SILValue Base) const {
191
195
SILType BaseTy = Base->getType ();
192
196
193
197
// We can only create a value projection from an object.
@@ -221,7 +225,7 @@ Projection::createObjectProjection(SILBuilder &B, SILLocation Loc,
221
225
222
226
NullablePtr<SILInstruction>
223
227
Projection::createAddressProjection (SILBuilder &B, SILLocation Loc,
224
- SILValue Base) const {
228
+ SILValue Base) const {
225
229
SILType BaseTy = Base->getType ();
226
230
227
231
// We can only create an address projection from an object, unless we have a
@@ -259,8 +263,8 @@ Projection::createAddressProjection(SILBuilder &B, SILLocation Loc,
259
263
}
260
264
}
261
265
262
- void Projection::getFirstLevelProjections (
263
- SILType Ty, SILModule &Mod, llvm::SmallVectorImpl<Projection> &Out) {
266
+ void Projection::getFirstLevelProjections (SILType Ty, SILModule &Mod,
267
+ llvm::SmallVectorImpl<Projection> &Out) {
264
268
if (auto *S = Ty.getStructOrBoundGenericStruct ()) {
265
269
unsigned Count = 0 ;
266
270
for (auto *VDecl : S->getStoredProperties ()) {
@@ -319,11 +323,11 @@ void Projection::getFirstLevelProjections(
319
323
}
320
324
321
325
// ===----------------------------------------------------------------------===//
322
- // New Projection Path
326
+ // Projection Path
323
327
// ===----------------------------------------------------------------------===//
324
328
325
329
Optional<ProjectionPath> ProjectionPath::getProjectionPath (SILValue Start,
326
- SILValue End) {
330
+ SILValue End) {
327
331
ProjectionPath P (Start->getType (), End->getType ());
328
332
329
333
// If Start == End, there is a "trivial" projection path in between the
@@ -364,8 +368,8 @@ Optional<ProjectionPath> ProjectionPath::getProjectionPath(SILValue Start,
364
368
// /
365
369
// / This means that the two objects have the same base but access different
366
370
// / fields of the base object.
367
- bool ProjectionPath::hasNonEmptySymmetricDifference (
368
- const ProjectionPath &RHS) const {
371
+ bool
372
+ ProjectionPath::hasNonEmptySymmetricDifference ( const ProjectionPath &RHS) const {
369
373
// First make sure that both of our base types are the same.
370
374
if (BaseType != RHS.BaseType )
371
375
return false ;
@@ -489,63 +493,9 @@ ProjectionPath::computeSubSeqRelation(const ProjectionPath &RHS) const {
489
493
return SubSeqRelation_t::RHSStrictSubSeqOfLHS;
490
494
}
491
495
492
- bool ProjectionPath::findMatchingObjectProjectionPaths (
493
- SILInstruction *I, SmallVectorImpl<SILInstruction *> &T) const {
494
- // We only support unary instructions.
495
- if (I->getNumOperands () != 1 )
496
- return false ;
497
-
498
- // Check that the base result type of I is equivalent to this types base path.
499
- if (I->getOperand (0 )->getType ().copyCategory (BaseType) != BaseType)
500
- return false ;
501
-
502
- // We maintain the head of our worklist so we can use our worklist as a queue
503
- // and work in breadth first order. This makes sense since we want to process
504
- // in levels so we can maintain one tail list and delete the tail list when we
505
- // move to the next level.
506
- unsigned WorkListHead = 0 ;
507
- llvm::SmallVector<SILInstruction *, 8 > WorkList;
508
- WorkList.push_back (I);
509
-
510
- // Start at the root of the list.
511
- for (auto PI = rbegin (), PE = rend (); PI != PE; ++PI) {
512
- // When we start a new level, clear the tail list.
513
- T.clear ();
514
-
515
- // If we have an empty worklist, return false. We have been unable to
516
- // complete the list.
517
- unsigned WorkListSize = WorkList.size ();
518
- if (WorkListHead == WorkListSize)
519
- return false ;
520
-
521
- // Otherwise, process each instruction in the worklist.
522
- for (; WorkListHead != WorkListSize; WorkListHead++) {
523
- SILInstruction *Ext = WorkList[WorkListHead];
524
-
525
- // If the current projection does not match I, continue and process the
526
- // next instruction.
527
- if (!PI->matchesObjectProjection (Ext)) {
528
- continue ;
529
- }
530
-
531
- // Otherwise, we know that Ext matched this projection path and we should
532
- // visit all of its uses and add Ext itself to our tail list.
533
- T.push_back (Ext);
534
- for (auto *Op : Ext->getUses ()) {
535
- WorkList.push_back (Op->getUser ());
536
- }
537
- }
538
-
539
- // Reset the worklist size.
540
- WorkListSize = WorkList.size ();
541
- }
542
-
543
- return true ;
544
- }
545
-
546
496
Optional<ProjectionPath>
547
497
ProjectionPath::removePrefix (const ProjectionPath &Path,
548
- const ProjectionPath &Prefix) {
498
+ const ProjectionPath &Prefix) {
549
499
// We can only subtract paths that have the same base.
550
500
if (Path.BaseType != Prefix.BaseType )
551
501
return llvm::NoneType::None;
@@ -575,19 +525,6 @@ ProjectionPath::removePrefix(const ProjectionPath &Path,
575
525
return P;
576
526
}
577
527
578
- SILValue ProjectionPath::createObjectProjections (SILBuilder &B,
579
- SILLocation Loc,
580
- SILValue Base) {
581
- assert (BaseType.isAddress ());
582
- assert (Base->getType ().isObject ());
583
- assert (Base->getType ().getAddressType () == BaseType);
584
- SILValue Val = Base;
585
- for (auto iter : Path) {
586
- Val = iter.createObjectProjection (B, Loc, Val).get ();
587
- }
588
- return Val;
589
- }
590
-
591
528
raw_ostream &ProjectionPath::print (raw_ostream &os, SILModule &M) {
592
529
// Match how the memlocation print tests expect us to print projection paths.
593
530
//
@@ -685,7 +622,7 @@ void ProjectionPath::verify(SILModule &M) {
685
622
686
623
void
687
624
ProjectionPath::expandTypeIntoLeafProjectionPaths (SILType B, SILModule *Mod,
688
- ProjectionPathList &Paths) {
625
+ ProjectionPathList &Paths) {
689
626
// Perform a BFS to expand the given type into projectionpath each of
690
627
// which contains 1 field from the type.
691
628
llvm::SmallVector<ProjectionPath, 8 > Worklist;
@@ -751,7 +688,7 @@ ProjectionPath::expandTypeIntoLeafProjectionPaths(SILType B, SILModule *Mod,
751
688
752
689
void
753
690
ProjectionPath::expandTypeIntoNodeProjectionPaths (SILType B, SILModule *Mod,
754
- ProjectionPathList &Paths) {
691
+ ProjectionPathList &Paths) {
755
692
// Perform a BFS to expand the given type into projectionpath each of
756
693
// which contains 1 field from the type.
757
694
llvm::SmallVector<ProjectionPath, 8 > Worklist;
@@ -905,7 +842,6 @@ ProjectionTreeNode::getChildForProjection(ProjectionTree &Tree,
905
842
return N;
906
843
}
907
844
}
908
-
909
845
return nullptr ;
910
846
}
911
847
@@ -932,10 +868,8 @@ createProjection(SILBuilder &B, SILLocation Loc, SILValue Arg) const {
932
868
return Proj->createProjection (B, Loc, Arg);
933
869
}
934
870
935
-
936
871
void
937
- ProjectionTreeNode::
938
- processUsersOfValue (ProjectionTree &Tree,
872
+ ProjectionTreeNode::processUsersOfValue (ProjectionTree &Tree,
939
873
llvm::SmallVectorImpl<ValueNodePair> &Worklist,
940
874
SILValue Value) {
941
875
DEBUG (llvm::dbgs () << " Looking at Users:\n " );
@@ -1232,14 +1166,14 @@ ProjectionTree::computeExplodedArgumentValueInner(SILBuilder &Builder,
1232
1166
Node->getType (),
1233
1167
ChildValues);
1234
1168
1235
- assert (AI.get () && " Failed to get a part of the debug value" );
1169
+ assert (AI.get () && " Failed to get a part of value" );
1236
1170
return SILValue (AI.get ());
1237
1171
}
1238
1172
1239
1173
SILValue
1240
- ProjectionTree::computeExplodedArgumentValue (SILBuilder &Builder,
1241
- SILLocation Loc,
1242
- llvm::SmallVector<SILValue, 8 > &LeafValues) {
1174
+ ProjectionTree::computeExplodedArgumentValue (
1175
+ SILBuilder &Builder, SILLocation Loc,
1176
+ llvm::SmallVector<SILValue, 8 > &LeafValues) {
1243
1177
// Construct the leaf index to leaf value map.
1244
1178
llvm::DenseMap<unsigned , SILValue> LeafIndexToValue;
1245
1179
for (unsigned i = 0 ; i < LeafValues.size (); ++i) {
@@ -1388,7 +1322,8 @@ getNextValidNode(llvm::SmallVectorImpl<ProjectionTreeNode *> &Worklist,
1388
1322
1389
1323
ProjectionTreeNode *Node = Worklist.back ();
1390
1324
1391
- // If the Node is not complete, then we have reached a dead lock. This should never happen.
1325
+ // If the Node is not complete, then we have reached a dead lock. This should
1326
+ // never happen.
1392
1327
//
1393
1328
// TODO: Prove this and put the proof here.
1394
1329
if (CheckForDeadLock && !isComplete (Node)) {
0 commit comments