From c9f9ed1d518c843483179ef568bc74092e78b985 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 29 May 2019 03:28:51 +0000 Subject: [PATCH] IR: Give the TypeAllocator a more generic name and start using it for section names as well. NFCI. This prepares us to start using it for partition names. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361922 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Globals.cpp | 5 ++--- lib/IR/LLVMContextImpl.h | 10 +++------- lib/IR/Type.cpp | 16 ++++++++-------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index b2f5640026f..b3fdcc6a5fc 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -192,9 +192,8 @@ void GlobalObject::setSection(StringRef S) { // Get or create a stable section name string and put it in the table in the // context. - if (!S.empty()) { - S = getContext().pImpl->SectionStrings.insert(S).first->first(); - } + if (!S.empty()) + S = getContext().pImpl->Saver.save(S); getContext().pImpl->GlobalObjectSections[this] = S; // Update the HasSectionHashEntryBit. Setting the section to the empty string diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index aaa765be9fa..e977f051109 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -30,7 +30,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/StringSet.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" @@ -41,6 +40,7 @@ #include "llvm/IR/TrackingMDRef.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/StringSaver.h" #include "llvm/Support/YAMLTraits.h" #include #include @@ -1321,9 +1321,8 @@ public: Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; - /// TypeAllocator - All dynamically allocated types are allocated from this. - /// They live forever until the context is torn down. - BumpPtrAllocator TypeAllocator; + BumpPtrAllocator Alloc; + UniqueStringSaver Saver{Alloc}; DenseMap IntegerTypes; @@ -1357,9 +1356,6 @@ public: /// Collection of per-GlobalObject sections used in this context. DenseMap GlobalObjectSections; - /// Stable collection of section strings. - StringSet<> SectionStrings; - /// DiscriminatorTable - This table maps file:line locations to an /// integer representing the next DWARF path discriminator to assign to /// instructions in different blocks at the same location. diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index c839648a03e..4016bb10ba3 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -255,7 +255,7 @@ IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) { IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits]; if (!Entry) - Entry = new (C.pImpl->TypeAllocator) IntegerType(C, NumBits); + Entry = new (C.pImpl->Alloc) IntegerType(C, NumBits); return Entry; } @@ -307,7 +307,7 @@ FunctionType *FunctionType::get(Type *ReturnType, if (Insertion.second) { // The function type was not found. Allocate one and update FunctionTypes // in-place. - FT = (FunctionType *)pImpl->TypeAllocator.Allocate( + FT = (FunctionType *)pImpl->Alloc.Allocate( sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1), alignof(FunctionType)); new (FT) FunctionType(ReturnType, Params, isVarArg); @@ -353,7 +353,7 @@ StructType *StructType::get(LLVMContext &Context, ArrayRef ETypes, if (Insertion.second) { // The struct type was not found. Allocate one and update AnonStructTypes // in-place. - ST = new (Context.pImpl->TypeAllocator) StructType(Context); + ST = new (Context.pImpl->Alloc) StructType(Context); ST->setSubclassData(SCDB_IsLiteral); // Literal struct. ST->setBody(ETypes, isPacked); *Insertion.first = ST; @@ -379,7 +379,7 @@ void StructType::setBody(ArrayRef Elements, bool isPacked) { return; } - ContainedTys = Elements.copy(getContext().pImpl->TypeAllocator).data(); + ContainedTys = Elements.copy(getContext().pImpl->Alloc).data(); } void StructType::setName(StringRef Name) { @@ -434,7 +434,7 @@ void StructType::setName(StringRef Name) { // StructType Helper functions. StructType *StructType::create(LLVMContext &Context, StringRef Name) { - StructType *ST = new (Context.pImpl->TypeAllocator) StructType(Context); + StructType *ST = new (Context.pImpl->Alloc) StructType(Context); if (!Name.empty()) ST->setName(Name); return ST; @@ -585,7 +585,7 @@ ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) { pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)]; if (!Entry) - Entry = new (pImpl->TypeAllocator) ArrayType(ElementType, NumElements); + Entry = new (pImpl->Alloc) ArrayType(ElementType, NumElements); return Entry; } @@ -613,7 +613,7 @@ VectorType *VectorType::get(Type *ElementType, unsigned NumElements) { ->VectorTypes[std::make_pair(ElementType, NumElements)]; if (!Entry) - Entry = new (pImpl->TypeAllocator) VectorType(ElementType, NumElements); + Entry = new (pImpl->Alloc) VectorType(ElementType, NumElements); return Entry; } @@ -637,7 +637,7 @@ PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) { : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)]; if (!Entry) - Entry = new (CImpl->TypeAllocator) PointerType(EltTy, AddressSpace); + Entry = new (CImpl->Alloc) PointerType(EltTy, AddressSpace); return Entry; } -- 2.40.0