diff --git a/llvm/lib/Target/NVPTX/ManagedStringPool.h b/llvm/lib/Target/NVPTX/ManagedStringPool.h deleted file mode 100644 --- a/llvm/lib/Target/NVPTX/ManagedStringPool.h +++ /dev/null @@ -1,48 +0,0 @@ -//===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// The strings allocated from a managed string pool are owned by the string -// pool and will be deleted together with the managed string pool. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H -#define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H - -#include "llvm/ADT/SmallVector.h" -#include - -namespace llvm { - -/// ManagedStringPool - The strings allocated from a managed string pool are -/// owned by the string pool and will be deleted together with the managed -/// string pool. -class ManagedStringPool { - SmallVector Pool; - -public: - ManagedStringPool() = default; - - ~ManagedStringPool() { - SmallVectorImpl::iterator Current = Pool.begin(); - while (Current != Pool.end()) { - delete *Current; - ++Current; - } - } - - std::string *getManagedString(const char *S) { - std::string *Str = new std::string(S); - Pool.push_back(Str); - return Str; - } -}; - -} // end namespace llvm - -#endif // LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -206,9 +206,8 @@ NVPTXTargetMachine &nvTM = static_cast(TM); const NVPTXMachineFunctionInfo *MFI = MF->getInfo(); const char *Sym = MFI->getImageHandleSymbol(Index); - std::string *SymNamePtr = - nvTM.getManagedStrPool()->getManagedString(Sym); - MCOp = GetSymbolRef(OutContext.getOrCreateSymbol(StringRef(*SymNamePtr))); + StringRef SymName = nvTM.getStrPool().save(Sym); + MCOp = GetSymbolRef(OutContext.getOrCreateSymbol(SymName)); } void NVPTXAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) { diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -1822,10 +1822,11 @@ ->getAPIntValue())) : std::nullopt, *CB, UniqueCallSite); - const char *ProtoStr = - nvTM->getManagedStrPool()->getManagedString(Proto.c_str())->c_str(); + const char *ProtoStr = nvTM->getStrPool().save(Proto).data(); SDValue ProtoOps[] = { - Chain, DAG.getTargetExternalSymbol(ProtoStr, MVT::i32), InFlag, + Chain, + DAG.getTargetExternalSymbol(ProtoStr, MVT::i32), + InFlag, }; Chain = DAG.getNode(NVPTXISD::CallPrototype, dl, ProtoVTs, ProtoOps); InFlag = Chain.getValue(1); @@ -2634,9 +2635,9 @@ else ParamStr << "_param_" << idx; - std::string *SavedStr = - nvTM->getManagedStrPool()->getManagedString(ParamSym.c_str()); - return DAG.getTargetExternalSymbol(SavedStr->c_str(), v); + StringRef SavedStr = + nvTM->getStrPool().save(ParamSym); + return DAG.getTargetExternalSymbol(SavedStr.data(), v); } SDValue NVPTXTargetLowering::LowerFormalArguments( diff --git a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.h b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.h --- a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.h +++ b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.h @@ -13,8 +13,8 @@ #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXREGISTERINFO_H #define LLVM_LIB_TARGET_NVPTX_NVPTXREGISTERINFO_H -#include "ManagedStringPool.h" #include "llvm/CodeGen/TargetRegisterInfo.h" +#include "llvm/Support/StringSaver.h" #include #define GET_REGINFO_HEADER @@ -24,7 +24,8 @@ class NVPTXRegisterInfo : public NVPTXGenRegisterInfo { private: // Hold Strings that can be free'd all together with NVPTXRegisterInfo - ManagedStringPool ManagedStrPool; + BumpPtrAllocator StrAlloc; + UniqueStringSaver StrPool; public: NVPTXRegisterInfo(); @@ -45,14 +46,14 @@ Register getFrameRegister(const MachineFunction &MF) const override; Register getFrameLocalRegister(const MachineFunction &MF) const; - ManagedStringPool *getStrPool() const { - return const_cast(&ManagedStrPool); + UniqueStringSaver &getStrPool() const { + return const_cast(StrPool); } const char *getName(unsigned RegNo) const { std::stringstream O; O << "reg" << RegNo; - return getStrPool()->getManagedString(O.str().c_str())->c_str(); + return getStrPool().save(O.str()).data(); } }; diff --git a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp --- a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp @@ -93,7 +93,8 @@ } } -NVPTXRegisterInfo::NVPTXRegisterInfo() : NVPTXGenRegisterInfo(0) {} +NVPTXRegisterInfo::NVPTXRegisterInfo() + : NVPTXGenRegisterInfo(0), StrPool(StrAlloc) {} #define GET_REGINFO_TARGET_DESC #include "NVPTXGenRegisterInfo.inc" diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h --- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h +++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h @@ -13,7 +13,6 @@ #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXTARGETMACHINE_H #define LLVM_LIB_TARGET_NVPTX_NVPTXTARGETMACHINE_H -#include "ManagedStringPool.h" #include "NVPTXSubtarget.h" #include "llvm/Target/TargetMachine.h" #include @@ -32,7 +31,8 @@ NVPTXSubtarget Subtarget; // Hold Strings that can be free'd all together with NVPTXTargetMachine - ManagedStringPool ManagedStrPool; + BumpPtrAllocator StrAlloc; + UniqueStringSaver StrPool; public: NVPTXTargetMachine(const Target &T, const Triple &TT, StringRef CPU, @@ -48,8 +48,8 @@ bool is64Bit() const { return is64bit; } bool useShortPointers() const { return UseShortPointers; } NVPTX::DrvInterface getDrvInterface() const { return drvInterface; } - ManagedStringPool *getManagedStrPool() const { - return const_cast(&ManagedStrPool); + UniqueStringSaver &getStrPool() const { + return const_cast(StrPool); } TargetPassConfig *createPassConfig(PassManagerBase &PM) override; diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp --- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -124,7 +124,8 @@ getEffectiveCodeModel(CM, CodeModel::Small), OL), is64bit(is64bit), UseShortPointers(UseShortPointersOpt), TLOF(std::make_unique()), - Subtarget(TT, std::string(CPU), std::string(FS), *this) { + Subtarget(TT, std::string(CPU), std::string(FS), *this), + StrPool(StrAlloc) { if (TT.getOS() == Triple::NVCL) drvInterface = NVPTX::NVCL; else