Index: llvm/include/llvm/Support/YAMLTraits.h =================================================================== --- llvm/include/llvm/Support/YAMLTraits.h +++ llvm/include/llvm/Support/YAMLTraits.h @@ -1154,11 +1154,8 @@ bool canElideEmptySequence() override; class HNode { - virtual void anchor(); - public: HNode(Node *n) : _node(n) { } - virtual ~HNode() = default; static bool classof(const HNode *) { return true; } @@ -1166,8 +1163,6 @@ }; class EmptyHNode : public HNode { - void anchor() override; - public: EmptyHNode(Node *n) : HNode(n) { } @@ -1177,8 +1172,6 @@ }; class ScalarHNode : public HNode { - void anchor() override; - public: ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { } @@ -1196,8 +1189,6 @@ }; class MapHNode : public HNode { - void anchor() override; - public: MapHNode(Node *n) : HNode(n) { } @@ -1207,15 +1198,13 @@ static bool classof(const MapHNode *) { return true; } - using NameToNode = StringMap>; + using NameToNode = StringMap; NameToNode Mapping; SmallVector ValidKeys; }; class SequenceHNode : public HNode { - void anchor() override; - public: SequenceHNode(Node *n) : HNode(n) { } @@ -1225,10 +1214,10 @@ static bool classof(const SequenceHNode *) { return true; } - std::vector> Entries; + std::vector Entries; }; - std::unique_ptr createHNodes(Node *node); + Input::HNode *createHNodes(Node *node); void setError(HNode *hnode, const Twine &message); void setError(Node *node, const Twine &message); @@ -1244,9 +1233,12 @@ private: SourceMgr SrcMgr; // must be before Strm std::unique_ptr Strm; - std::unique_ptr TopNode; + HNode *TopNode; std::error_code EC; BumpPtrAllocator StringAllocator; + BumpPtrAllocator HNodeAllocator; + SpecificBumpPtrAllocator SequenceHNodeAllocator; + SpecificBumpPtrAllocator MapHNodeAllocator; document_iterator DocIterator; std::vector BitValuesUsed; HNode *CurrentNode = nullptr; Index: llvm/lib/Support/YAMLTraits.cpp =================================================================== --- llvm/lib/Support/YAMLTraits.cpp +++ llvm/lib/Support/YAMLTraits.cpp @@ -72,13 +72,6 @@ std::error_code Input::error() { return EC; } -// Pin the vtables to this file. -void Input::HNode::anchor() {} -void Input::EmptyHNode::anchor() {} -void Input::ScalarHNode::anchor() {} -void Input::MapHNode::anchor() {} -void Input::SequenceHNode::anchor() {} - bool Input::outputting() { return false; } @@ -97,8 +90,12 @@ ++DocIterator; return setCurrentDocument(); } + TopNode = CurrentNode = nullptr; + HNodeAllocator.Reset(); + SequenceHNodeAllocator.DestroyAll(); + MapHNodeAllocator.DestroyAll(); TopNode = this->createHNodes(N); - CurrentNode = TopNode.get(); + CurrentNode = TopNode; return true; } return false; @@ -164,7 +161,7 @@ return false; } MN->ValidKeys.push_back(Key); - HNode *Value = MN->Mapping[Key].get(); + HNode *Value = MN->Mapping[Key]; if (!Value) { if (Required) setError(CurrentNode, Twine("missing required key '") + Key + "'"); @@ -190,7 +187,7 @@ return; for (const auto &NN : MN->Mapping) { if (!is_contained(MN->ValidKeys, NN.first())) { - setError(NN.second.get(), Twine("unknown key '") + NN.first() + "'"); + setError(NN.second, Twine("unknown key '") + NN.first() + "'"); break; } } @@ -223,7 +220,7 @@ return false; if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { SaveInfo = CurrentNode; - CurrentNode = SQ->Entries[Index].get(); + CurrentNode = SQ->Entries[Index]; return true; } return false; @@ -240,7 +237,7 @@ return false; if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { SaveInfo = CurrentNode; - CurrentNode = SQ->Entries[index].get(); + CurrentNode = SQ->Entries[index]; return true; } return false; @@ -299,7 +296,7 @@ if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { unsigned Index = 0; for (auto &N : SQ->Entries) { - if (ScalarHNode *SN = dyn_cast(N.get())) { + if (ScalarHNode *SN = dyn_cast(N)) { if (SN->value().equals(Str)) { BitValuesUsed[Index] = true; return true; @@ -322,7 +319,7 @@ assert(BitValuesUsed.size() == SQ->Entries.size()); for (unsigned i = 0; i < SQ->Entries.size(); ++i) { if (!BitValuesUsed[i]) { - setError(SQ->Entries[i].get(), "unknown bit value"); + setError(SQ->Entries[i], "unknown bit value"); return; } } @@ -349,7 +346,7 @@ EC = make_error_code(errc::invalid_argument); } -std::unique_ptr Input::createHNodes(Node *N) { +Input::HNode *Input::createHNodes(Node *N) { SmallString<128> StringStorage; if (ScalarNode *SN = dyn_cast(N)) { StringRef KeyStr = SN->getValue(StringStorage); @@ -357,21 +354,22 @@ // Copy string to permanent storage KeyStr = StringStorage.str().copy(StringAllocator); } - return llvm::make_unique(N, KeyStr); + return new (HNodeAllocator.Allocate()) ScalarHNode(N, KeyStr); } else if (BlockScalarNode *BSN = dyn_cast(N)) { StringRef ValueCopy = BSN->getValue().copy(StringAllocator); - return llvm::make_unique(N, ValueCopy); + return new (HNodeAllocator.Allocate()) + ScalarHNode(N, ValueCopy); } else if (SequenceNode *SQ = dyn_cast(N)) { - auto SQHNode = llvm::make_unique(N); + auto SQHNode = new (SequenceHNodeAllocator.Allocate()) SequenceHNode(N); for (Node &SN : *SQ) { auto Entry = this->createHNodes(&SN); if (EC) break; - SQHNode->Entries.push_back(std::move(Entry)); + SQHNode->Entries.push_back(Entry); } - return std::move(SQHNode); + return SQHNode; } else if (MappingNode *Map = dyn_cast(N)) { - auto mapHNode = llvm::make_unique(N); + auto mapHNode = new (MapHNodeAllocator.Allocate()) MapHNode(N); for (KeyValueNode &KVN : *Map) { Node *KeyNode = KVN.getKey(); ScalarNode *KeyScalar = dyn_cast(KeyNode); @@ -388,11 +386,11 @@ auto ValueHNode = this->createHNodes(KVN.getValue()); if (EC) break; - mapHNode->Mapping[KeyStr] = std::move(ValueHNode); + mapHNode->Mapping[KeyStr] = ValueHNode; } - return std::move(mapHNode); + return mapHNode; } else if (isa(N)) { - return llvm::make_unique(N); + return new (HNodeAllocator.Allocate()) EmptyHNode(N); } else { setError(N, "unknown node kind"); return nullptr;