Skip to content

Commit e4f3655

Browse files
committed
[sil] Also give Placeholder a parent SILFunction.
1 parent ac08efd commit e4f3655

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

include/swift/SIL/SILValue.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,16 +1592,20 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SILValue V) {
15921592

15931593
/// Used internally in e.g. the SIL parser and deserializer to handle forward-
15941594
/// referenced values.
1595+
///
15951596
/// A PlaceholderValue must not appear in valid SIL.
15961597
class PlaceholderValue : public ValueBase {
1598+
SILFunction *parentFunction;
15971599
static int numPlaceholderValuesAlive;
15981600

15991601
public:
1600-
PlaceholderValue(SILType type);
1602+
PlaceholderValue(SILFunction *parentFunction, SILType type);
16011603
~PlaceholderValue();
16021604

16031605
static int getNumPlaceholderValuesAlive() { return numPlaceholderValuesAlive; }
16041606

1607+
SILFunction *getParent() const { return parentFunction; }
1608+
16051609
static bool classof(const SILArgument *) = delete;
16061610
static bool classof(const SILInstruction *) = delete;
16071611
static bool classof(SILNodePointer node) {

lib/SIL/IR/SILModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,8 @@ SILValue SILModule::getRootLocalArchetypeDef(CanLocalArchetypeType archetype,
680680
SILValue &def = RootLocalArchetypeDefs[{archetype, inFunction}];
681681
if (!def) {
682682
numUnresolvedLocalArchetypes++;
683-
def = ::new PlaceholderValue(SILType::getPrimitiveAddressType(archetype));
683+
def = ::new PlaceholderValue(inFunction,
684+
SILType::getPrimitiveAddressType(archetype));
684685
}
685686

686687
return def;

lib/SIL/IR/SILValue.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ SILFunction *SILNode::getFunction() const {
224224
if (auto *undef = dyn_cast<SILUndef>(this))
225225
return undef->getParent();
226226

227+
if (auto *placeHolder = dyn_cast<PlaceholderValue>(this))
228+
return placeHolder->getParent();
229+
227230
return nullptr;
228231
}
229232

@@ -540,8 +543,8 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
540543

541544
int PlaceholderValue::numPlaceholderValuesAlive = 0;
542545

543-
PlaceholderValue::PlaceholderValue(SILType type)
544-
: ValueBase(ValueKind::PlaceholderValue, type) {
546+
PlaceholderValue::PlaceholderValue(SILFunction *fn, SILType type)
547+
: ValueBase(ValueKind::PlaceholderValue, type), parentFunction(fn) {
545548
numPlaceholderValuesAlive++;
546549
}
547550

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ SILValue SILParser::getLocalValue(UnresolvedValueName Name, SILType Type,
376376
// it until we see a real definition.
377377
ForwardRefLocalValues[Name.Name] = Name.NameLoc;
378378

379-
Entry = ::new PlaceholderValue(Type);
379+
Entry = ::new PlaceholderValue(&B.getFunction(), Type);
380380
return Entry;
381381
}
382382

lib/Serialization/DeserializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ SILValue SILDeserializer::getLocalValue(SILFunction *inContext, ValueID Id,
319319
if (!Entry) {
320320
// Otherwise, this is a forward reference. Create a dummy node to represent
321321
// it until we see a real definition.
322-
Entry = ::new PlaceholderValue(Type);
322+
Entry = ::new PlaceholderValue(inContext, Type);
323323
}
324324
// If this value was already defined, check it to make sure types match.
325325
assert(Entry->getType() == Type && "Value Type mismatch?");

0 commit comments

Comments
 (0)