@@ -262,29 +262,23 @@ SILDeserializer::readFuncTable(ArrayRef<uint64_t> fields, StringRef blobData) {
262262
263263// / A high-level overview of how forward references work in serializer and
264264// / deserializer:
265- // / In serializer, we pre-assign a value ID in order, to each basic block
265+ // / In the serializer, we pre-assign a value ID in order, to each basic block
266266// / argument and each SILInstruction that has a value.
267- // / In deserializer, we use LocalValues to store the definitions and
268- // / ForwardLocalValues for forward-referenced values (values that are
269- // / used but not yet defined). LocalValues are updated in setLocalValue where
270- // / the ID passed in assumes the same ordering as in serializer: in-order
271- // / for each basic block argument and each SILInstruction that has a value.
272- // / We update ForwardLocalValues in getLocalValue and when a value is defined
273- // / in setLocalValue, the corresponding entry in ForwardLocalValues will be
274- // / erased.
267+ // / In the deserializer, we create a PlaceholderValue for a forward-referenced
268+ // / value (a value that is used but not yet defined). LocalValues are updated in
269+ // / setLocalValue where the ID passed in assumes the same ordering as in
270+ // / serializer: in-order for each basic block argument and each SILInstruction
271+ // / that has a value.
272+ // / When a forward-referenced value is defined, it replaces the PlaceholderValue
273+ // / in LocalValues.
275274void SILDeserializer::setLocalValue (ValueBase *Value, ValueID Id) {
276275 ValueBase *&Entry = LocalValues[Id];
277- assert (!Entry && " We should not redefine the same value." );
278276
279- auto It = ForwardLocalValues.find (Id);
280- if (It != ForwardLocalValues.end ()) {
281- // Take the information about the forward ref out of the map.
282- ValueBase *Placeholder = It->second ;
283-
284- // Remove the entries from the map.
285- ForwardLocalValues.erase (It);
286-
287- Placeholder->replaceAllUsesWith (Value);
277+ if (auto *placeholder = dyn_cast_or_null<PlaceholderValue>(Entry)) {
278+ placeholder->replaceAllUsesWith (Value);
279+ ::delete placeholder;
280+ } else {
281+ assert (!Entry && " We should not redefine the same value." );
288282 }
289283
290284 // Store it in our map.
@@ -301,19 +295,15 @@ SILValue SILDeserializer::getLocalValue(ValueID Id,
301295 " changes that without updating this code if needed" );
302296
303297 // Check to see if this is already defined.
304- ValueBase *Entry = LocalValues.lookup (Id);
305- if (Entry) {
306- // If this value was already defined, check it to make sure types match.
307- assert (Entry->getType () == Type && " Value Type mismatch?" );
308- return Entry;
309- }
310-
311- // Otherwise, this is a forward reference. Create a dummy node to represent
312- // it until we see a real definition.
313- ValueBase *&Placeholder = ForwardLocalValues[Id];
314- if (!Placeholder)
315- Placeholder = new (SILMod) GlobalAddrInst (SILDebugLocation (), Type);
316- return Placeholder;
298+ ValueBase *&Entry = LocalValues[Id];
299+ if (!Entry) {
300+ // Otherwise, this is a forward reference. Create a dummy node to represent
301+ // it until we see a real definition.
302+ Entry = ::new PlaceholderValue (Type);
303+ }
304+ // If this value was already defined, check it to make sure types match.
305+ assert (Entry->getType () == Type && " Value Type mismatch?" );
306+ return Entry;
317307}
318308
319309// / Return the SILBasicBlock of a given ID.
@@ -807,7 +797,6 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
807797 // The first two IDs are reserved for SILUndef.
808798 LastValueID = 1 ;
809799 LocalValues.clear ();
810- ForwardLocalValues.clear ();
811800
812801 SILOpenedArchetypesTracker OpenedArchetypesTracker (fn);
813802 SILBuilder Builder (*fn);
@@ -3034,11 +3023,9 @@ SILGlobalVariable *SILDeserializer::readGlobalVar(StringRef Name) {
30343023 SILBuilder Builder (v);
30353024
30363025 llvm::DenseMap<uint32_t , ValueBase*> SavedLocalValues;
3037- llvm::DenseMap<uint32_t , ValueBase*> SavedForwardLocalValues;
30383026 serialization::ValueID SavedLastValueID = 1 ;
30393027
30403028 SavedLocalValues.swap (LocalValues);
3041- SavedForwardLocalValues.swap (ForwardLocalValues);
30423029 std::swap (SavedLastValueID, LastValueID);
30433030
30443031 while (kind != SIL_FUNCTION && kind != SIL_VTABLE && kind != SIL_GLOBALVAR &&
@@ -3066,7 +3053,6 @@ SILGlobalVariable *SILDeserializer::readGlobalVar(StringRef Name) {
30663053 }
30673054
30683055 SavedLocalValues.swap (LocalValues);
3069- SavedForwardLocalValues.swap (ForwardLocalValues);
30703056 std::swap (SavedLastValueID, LastValueID);
30713057
30723058 return v;
0 commit comments