/// block's address of label.
std::unique_ptr<AddrLabelMap> AddrLabelSymbols;
- // The garbage collection metadata printer table.
- void *GCMetadataPrinters = nullptr; // Really a DenseMap.
+ /// The garbage collection metadata printer table.
+ DenseMap<GCStrategy *, std::unique_ptr<GCMetadataPrinter>> GCMetadataPrinters;
/// Emit comments in assembly output if this is true.
bool VerboseAsm;
/// 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);
char AsmPrinter::ID = 0;
-using gcp_map_type = DenseMap<GCStrategy *, std::unique_ptr<GCMetadataPrinter>>;
-
-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;
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 {
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
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.
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
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.
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();
if (Name == GCMetaPrinter.getName()) {
std::unique_ptr<GCMetadataPrinter> 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));
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.