From: Markus Böck Date: Thu, 29 Dec 2022 19:47:29 +0000 (+0100) Subject: [llvm][AsmPrinter][NFC] Cleanup `GCMetadataPrinters` field X-Git-Tag: upstream/17.0.6~22477 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f8313d53379075af1a2169ee4b45bf67a0a3306;p=platform%2Fupstream%2Fllvm.git [llvm][AsmPrinter][NFC] Cleanup `GCMetadataPrinters` field The field is currently `void*`, which was originlly chosen in 2010 to not need to include `DenseMap`. Since then, `DenseMap` has been included in the header file anyways, so there is no more need to for the indirection via `void*` and the cruft around it can be removed. Differential Revision: https://reviews.llvm.org/D140758 --- diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index 0d3ac9e..a880565 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -182,8 +182,8 @@ private: /// block's address of label. std::unique_ptr AddrLabelSymbols; - // The garbage collection metadata printer table. - void *GCMetadataPrinters = nullptr; // Really a DenseMap. + /// The garbage collection metadata printer table. + DenseMap> GCMetadataPrinters; /// Emit comments in assembly output if this is true. bool VerboseAsm; @@ -854,7 +854,7 @@ private: /// Emit bytes for llvm.commandline metadata. void emitModuleCommandLines(Module &M); - GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy &S); + GCMetadataPrinter *getOrCreateGCPrinter(GCStrategy &S); void emitGlobalAlias(Module &M, const GlobalAlias &GA); void emitGlobalIFunc(Module &M, const GlobalIFunc &GI); diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 7b504e0..db511bf 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -147,14 +147,6 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed"); char AsmPrinter::ID = 0; -using gcp_map_type = DenseMap>; - -static gcp_map_type &getGCMap(void *&P) { - if (!P) - P = new gcp_map_type(); - return *(gcp_map_type*)P; -} - namespace { class AddrLabelMapCallbackPtr final : CallbackVH { AddrLabelMap *Map = nullptr; @@ -363,13 +355,6 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr Streamer) AsmPrinter::~AsmPrinter() { assert(!DD && Handlers.size() == NumUserHandlers && "Debug/EH info didn't get finalized"); - - if (GCMetadataPrinters) { - gcp_map_type &GCMap = getGCMap(GCMetadataPrinters); - - delete &GCMap; - GCMetadataPrinters = nullptr; - } } bool AsmPrinter::isPositionIndependent() const { @@ -491,7 +476,7 @@ bool AsmPrinter::doInitialization(Module &M) { GCModuleInfo *MI = getAnalysisIfAvailable(); assert(MI && "AsmPrinter didn't require GCModuleInfo?"); for (const auto &I : *MI) - if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I)) + if (GCMetadataPrinter *MP = getOrCreateGCPrinter(*I)) MP->beginAssembly(M, *MI, *this); // Emit module-level inline asm if it exists. @@ -2248,7 +2233,7 @@ bool AsmPrinter::doFinalization(Module &M) { GCModuleInfo *MI = getAnalysisIfAvailable(); assert(MI && "AsmPrinter didn't require GCModuleInfo?"); for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; ) - if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(**--I)) + if (GCMetadataPrinter *MP = getOrCreateGCPrinter(**--I)) MP->finishAssembly(M, *MI, *this); // Emit llvm.ident metadata in an '.ident' directive. @@ -3830,13 +3815,12 @@ isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const { return true; } -GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy &S) { +GCMetadataPrinter *AsmPrinter::getOrCreateGCPrinter(GCStrategy &S) { if (!S.usesMetadata()) return nullptr; - gcp_map_type &GCMap = getGCMap(GCMetadataPrinters); - gcp_map_type::iterator GCPI = GCMap.find(&S); - if (GCPI != GCMap.end()) + auto [GCPI, Inserted] = GCMetadataPrinters.insert({&S, nullptr}); + if (!Inserted) return GCPI->second.get(); auto Name = S.getName(); @@ -3846,8 +3830,8 @@ GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy &S) { if (Name == GCMetaPrinter.getName()) { std::unique_ptr GMP = GCMetaPrinter.instantiate(); GMP->S = &S; - auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP))); - return IterBool.first->second.get(); + GCPI->second = std::move(GMP); + return GCPI->second.get(); } report_fatal_error("no GCMetadataPrinter registered for GC: " + Twine(Name)); @@ -3862,7 +3846,7 @@ void AsmPrinter::emitStackMaps() { NeedsDefault = true; else for (const auto &I : *MI) { - if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I)) + if (GCMetadataPrinter *MP = getOrCreateGCPrinter(*I)) if (MP->emitStackMaps(SM, *this)) continue; // The strategy doesn't have printer or doesn't emit custom stack maps.