Index: docs/WritingAnLLVMBackend.rst =================================================================== --- docs/WritingAnLLVMBackend.rst +++ docs/WritingAnLLVMBackend.rst @@ -288,11 +288,11 @@ .. code-block:: c++ - Target llvm::TheSparcTarget; + Target llvm::getTheSparcTarget(); extern "C" void LLVMInitializeSparcTargetInfo() { RegisterTarget - X(TheSparcTarget, "sparc", "Sparc"); + X(getTheSparcTarget(), "sparc", "Sparc"); } This allows the ``TargetRegistry`` to look up the target by name or by target @@ -305,7 +305,7 @@ .. code-block:: c++ extern "C" void LLVMInitializeSparcAsmPrinter() { - RegisterAsmPrinter X(TheSparcTarget); + RegisterAsmPrinter X(getTheSparcTarget()); } For more information, see "`llvm/Target/TargetRegistry.h Index: include/llvm/Support/TargetRegistry.h =================================================================== --- include/llvm/Support/TargetRegistry.h +++ include/llvm/Support/TargetRegistry.h @@ -849,10 +849,13 @@ /// target's initialization function. Usage: /// /// -/// Target TheFooTarget; // The global target instance. -/// +/// Target &getTheFooTarget() { // The global target instance. +/// static Target TheFooTarget; +/// return TheFooTarget; +/// } /// extern "C" void LLVMInitializeFooTargetInfo() { -/// RegisterTarget X(TheFooTarget, "foo", "Foo description"); +/// RegisterTarget X(getTheFooTarget(), "foo", "Foo +/// description"); /// } template Index: lib/Target/AArch64/AArch64AsmPrinter.cpp =================================================================== --- lib/Target/AArch64/AArch64AsmPrinter.cpp +++ lib/Target/AArch64/AArch64AsmPrinter.cpp @@ -577,7 +577,7 @@ // Force static initialization. extern "C" void LLVMInitializeAArch64AsmPrinter() { - RegisterAsmPrinter X(TheAArch64leTarget); - RegisterAsmPrinter Y(TheAArch64beTarget); - RegisterAsmPrinter Z(TheARM64Target); + RegisterAsmPrinter X(getTheAArch64leTarget()); + RegisterAsmPrinter Y(getTheAArch64beTarget()); + RegisterAsmPrinter Z(getTheARM64Target()); } Index: lib/Target/AArch64/AArch64TargetMachine.cpp =================================================================== --- lib/Target/AArch64/AArch64TargetMachine.cpp +++ lib/Target/AArch64/AArch64TargetMachine.cpp @@ -126,9 +126,9 @@ extern "C" void LLVMInitializeAArch64Target() { // Register the target. - RegisterTargetMachine X(TheAArch64leTarget); - RegisterTargetMachine Y(TheAArch64beTarget); - RegisterTargetMachine Z(TheARM64Target); + RegisterTargetMachine X(getTheAArch64leTarget()); + RegisterTargetMachine Y(getTheAArch64beTarget()); + RegisterTargetMachine Z(getTheARM64Target()); auto PR = PassRegistry::getPassRegistry(); initializeGlobalISel(*PR); initializeAArch64A53Fix835769Pass(*PR); Index: lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp =================================================================== --- lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -4553,9 +4553,9 @@ /// Force static initialization. extern "C" void LLVMInitializeAArch64AsmParser() { - RegisterMCAsmParser X(TheAArch64leTarget); - RegisterMCAsmParser Y(TheAArch64beTarget); - RegisterMCAsmParser Z(TheARM64Target); + RegisterMCAsmParser X(getTheAArch64leTarget()); + RegisterMCAsmParser Y(getTheAArch64beTarget()); + RegisterMCAsmParser Z(getTheARM64Target()); } #define GET_REGISTER_MATCHER Index: lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp =================================================================== --- lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp +++ lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp @@ -237,18 +237,18 @@ } extern "C" void LLVMInitializeAArch64Disassembler() { - TargetRegistry::RegisterMCDisassembler(TheAArch64leTarget, + TargetRegistry::RegisterMCDisassembler(getTheAArch64leTarget(), createAArch64Disassembler); - TargetRegistry::RegisterMCDisassembler(TheAArch64beTarget, + TargetRegistry::RegisterMCDisassembler(getTheAArch64beTarget(), createAArch64Disassembler); - TargetRegistry::RegisterMCSymbolizer(TheAArch64leTarget, + TargetRegistry::RegisterMCSymbolizer(getTheAArch64leTarget(), createAArch64ExternalSymbolizer); - TargetRegistry::RegisterMCSymbolizer(TheAArch64beTarget, + TargetRegistry::RegisterMCSymbolizer(getTheAArch64beTarget(), createAArch64ExternalSymbolizer); - TargetRegistry::RegisterMCDisassembler(TheARM64Target, + TargetRegistry::RegisterMCDisassembler(getTheARM64Target(), createAArch64Disassembler); - TargetRegistry::RegisterMCSymbolizer(TheARM64Target, + TargetRegistry::RegisterMCSymbolizer(getTheARM64Target(), createAArch64ExternalSymbolizer); } Index: lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h =================================================================== --- lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h +++ lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.h @@ -35,9 +35,9 @@ class raw_ostream; class raw_pwrite_stream; -extern Target TheAArch64leTarget; -extern Target TheAArch64beTarget; -extern Target TheARM64Target; +Target &getTheAArch64leTarget(); +Target &getTheAArch64beTarget(); +Target &getTheARM64Target(); MCCodeEmitter *createAArch64MCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, Index: lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp =================================================================== --- lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp +++ lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp @@ -123,8 +123,8 @@ // Force static initialization. extern "C" void LLVMInitializeAArch64TargetMC() { - for (Target *T : - {&TheAArch64leTarget, &TheAArch64beTarget, &TheARM64Target}) { + for (Target *T : {&getTheAArch64leTarget(), &getTheAArch64beTarget(), + &getTheARM64Target()}) { // Register the MC asm info. RegisterMCAsmInfoFn X(*T, createAArch64MCAsmInfo); @@ -162,8 +162,8 @@ } // Register the asm backend. - for (Target *T : {&TheAArch64leTarget, &TheARM64Target}) + for (Target *T : {&getTheAArch64leTarget(), &getTheARM64Target()}) TargetRegistry::RegisterMCAsmBackend(*T, createAArch64leAsmBackend); - TargetRegistry::RegisterMCAsmBackend(TheAArch64beTarget, + TargetRegistry::RegisterMCAsmBackend(getTheAArch64beTarget(), createAArch64beAsmBackend); } Index: lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp =================================================================== --- lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp +++ lib/Target/AArch64/TargetInfo/AArch64TargetInfo.cpp @@ -10,23 +10,30 @@ #include "llvm/ADT/Triple.h" #include "llvm/Support/TargetRegistry.h" using namespace llvm; - namespace llvm { -Target TheAArch64leTarget; -Target TheAArch64beTarget; -Target TheARM64Target; -} // end namespace llvm +Target &getTheAArch64leTarget() { + static Target TheAArch64leTarget; + return TheAArch64leTarget; +} +Target &getTheAArch64beTarget() { + static Target TheAArch64beTarget; + return TheAArch64beTarget; +} +Target &getTheARM64Target() { + static Target TheARM64Target; + return TheARM64Target; +} +} extern "C" void LLVMInitializeAArch64TargetInfo() { // Now register the "arm64" name for use with "-march". We don't want it to // take possession of the Triple::aarch64 tag though. - TargetRegistry::RegisterTarget(TheARM64Target, "arm64", + TargetRegistry::RegisterTarget(getTheARM64Target(), "arm64", "ARM64 (little endian)", [](Triple::ArchType) { return false; }, true); RegisterTarget Z( - TheAArch64leTarget, "aarch64", "AArch64 (little endian)"); + getTheAArch64leTarget(), "aarch64", "AArch64 (little endian)"); RegisterTarget W( - TheAArch64beTarget, "aarch64_be", "AArch64 (big endian)"); - + getTheAArch64beTarget(), "aarch64_be", "AArch64 (big endian)"); } Index: lib/Target/AMDGPU/AMDGPU.h =================================================================== --- lib/Target/AMDGPU/AMDGPU.h +++ lib/Target/AMDGPU/AMDGPU.h @@ -108,8 +108,8 @@ void initializeSIInsertWaitsPass(PassRegistry&); extern char &SIInsertWaitsID; -extern Target TheAMDGPUTarget; -extern Target TheGCNTarget; +Target &getTheAMDGPUTarget(); +Target &getTheGCNTarget(); namespace AMDGPU { enum TargetIndex { Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -87,8 +87,10 @@ } extern "C" void LLVMInitializeAMDGPUAsmPrinter() { - TargetRegistry::RegisterAsmPrinter(TheAMDGPUTarget, createAMDGPUAsmPrinterPass); - TargetRegistry::RegisterAsmPrinter(TheGCNTarget, createAMDGPUAsmPrinterPass); + TargetRegistry::RegisterAsmPrinter(getTheAMDGPUTarget(), + createAMDGPUAsmPrinterPass); + TargetRegistry::RegisterAsmPrinter(getTheGCNTarget(), + createAMDGPUAsmPrinterPass); } AMDGPUAsmPrinter::AMDGPUAsmPrinter(TargetMachine &TM, Index: lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -63,8 +63,8 @@ extern "C" void LLVMInitializeAMDGPUTarget() { // Register the target - RegisterTargetMachine X(TheAMDGPUTarget); - RegisterTargetMachine Y(TheGCNTarget); + RegisterTargetMachine X(getTheAMDGPUTarget()); + RegisterTargetMachine Y(getTheGCNTarget()); PassRegistry *PR = PassRegistry::getPassRegistry(); initializeSILowerI1CopiesPass(*PR); Index: lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp =================================================================== --- lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -3052,8 +3052,8 @@ /// Force static initialization. extern "C" void LLVMInitializeAMDGPUAsmParser() { - RegisterMCAsmParser A(TheAMDGPUTarget); - RegisterMCAsmParser B(TheGCNTarget); + RegisterMCAsmParser A(getTheAMDGPUTarget()); + RegisterMCAsmParser B(getTheGCNTarget()); } #define GET_REGISTER_MATCHER Index: lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp =================================================================== --- lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp +++ lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp @@ -495,6 +495,8 @@ } extern "C" void LLVMInitializeAMDGPUDisassembler() { - TargetRegistry::RegisterMCDisassembler(TheGCNTarget, createAMDGPUDisassembler); - TargetRegistry::RegisterMCSymbolizer(TheGCNTarget, createAMDGPUSymbolizer); + TargetRegistry::RegisterMCDisassembler(getTheGCNTarget(), + createAMDGPUDisassembler); + TargetRegistry::RegisterMCSymbolizer(getTheGCNTarget(), + createAMDGPUSymbolizer); } Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.h =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.h +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.h @@ -32,8 +32,8 @@ class Triple; class raw_pwrite_stream; -extern Target TheAMDGPUTarget; -extern Target TheGCNTarget; +Target &getTheAMDGPUTarget(); +Target &getTheGCNTarget(); MCCodeEmitter *createR600MCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp @@ -86,7 +86,7 @@ } extern "C" void LLVMInitializeAMDGPUTargetMC() { - for (Target *T : {&TheAMDGPUTarget, &TheGCNTarget}) { + for (Target *T : {&getTheAMDGPUTarget(), &getTheGCNTarget()}) { RegisterMCAsmInfo X(*T); TargetRegistry::RegisterMCInstrInfo(*T, createAMDGPUMCInstrInfo); @@ -98,14 +98,15 @@ } // R600 specific registration - TargetRegistry::RegisterMCCodeEmitter(TheAMDGPUTarget, + TargetRegistry::RegisterMCCodeEmitter(getTheAMDGPUTarget(), createR600MCCodeEmitter); // GCN specific registration - TargetRegistry::RegisterMCCodeEmitter(TheGCNTarget, createSIMCCodeEmitter); + TargetRegistry::RegisterMCCodeEmitter(getTheGCNTarget(), + createSIMCCodeEmitter); - TargetRegistry::RegisterAsmTargetStreamer(TheGCNTarget, + TargetRegistry::RegisterAsmTargetStreamer(getTheGCNTarget(), createAMDGPUAsmTargetStreamer); - TargetRegistry::RegisterObjectTargetStreamer(TheGCNTarget, - createAMDGPUObjectTargetStreamer); + TargetRegistry::RegisterObjectTargetStreamer( + getTheGCNTarget(), createAMDGPUObjectTargetStreamer); } Index: lib/Target/AMDGPU/TargetInfo/AMDGPUTargetInfo.cpp =================================================================== --- lib/Target/AMDGPU/TargetInfo/AMDGPUTargetInfo.cpp +++ lib/Target/AMDGPU/TargetInfo/AMDGPUTargetInfo.cpp @@ -18,13 +18,20 @@ /// \brief The target which suports all AMD GPUs. This will eventually /// be deprecated and there will be a R600 target and a GCN target. -Target llvm::TheAMDGPUTarget; +Target &llvm::getTheAMDGPUTarget() { + static Target TheAMDGPUTarget; + return TheAMDGPUTarget; +} /// \brief The target for GCN GPUs -Target llvm::TheGCNTarget; +Target &llvm::getTheGCNTarget() { + static Target TheGCNTarget; + return TheGCNTarget; +} /// \brief Extern function to initialize the targets for the AMDGPU backend extern "C" void LLVMInitializeAMDGPUTargetInfo() { - RegisterTarget - R600(TheAMDGPUTarget, "r600", "AMD GPUs HD2XXX-HD6XXX"); - RegisterTarget GCN(TheGCNTarget, "amdgcn", "AMD GCN GPUs"); + RegisterTarget R600(getTheAMDGPUTarget(), "r600", + "AMD GPUs HD2XXX-HD6XXX"); + RegisterTarget GCN(getTheGCNTarget(), "amdgcn", + "AMD GCN GPUs"); } Index: lib/Target/ARM/ARMAsmPrinter.cpp =================================================================== --- lib/Target/ARM/ARMAsmPrinter.cpp +++ lib/Target/ARM/ARMAsmPrinter.cpp @@ -2064,8 +2064,8 @@ // Force static initialization. extern "C" void LLVMInitializeARMAsmPrinter() { - RegisterAsmPrinter X(TheARMLETarget); - RegisterAsmPrinter Y(TheARMBETarget); - RegisterAsmPrinter A(TheThumbLETarget); - RegisterAsmPrinter B(TheThumbBETarget); + RegisterAsmPrinter X(getTheARMLETarget()); + RegisterAsmPrinter Y(getTheARMBETarget()); + RegisterAsmPrinter A(getTheThumbLETarget()); + RegisterAsmPrinter B(getTheThumbBETarget()); } Index: lib/Target/ARM/ARMTargetMachine.cpp =================================================================== --- lib/Target/ARM/ARMTargetMachine.cpp +++ lib/Target/ARM/ARMTargetMachine.cpp @@ -51,10 +51,10 @@ extern "C" void LLVMInitializeARMTarget() { // Register the target. - RegisterTargetMachine X(TheARMLETarget); - RegisterTargetMachine Y(TheARMBETarget); - RegisterTargetMachine A(TheThumbLETarget); - RegisterTargetMachine B(TheThumbBETarget); + RegisterTargetMachine X(getTheARMLETarget()); + RegisterTargetMachine Y(getTheARMBETarget()); + RegisterTargetMachine A(getTheThumbLETarget()); + RegisterTargetMachine B(getTheThumbBETarget()); PassRegistry &Registry = *PassRegistry::getPassRegistry(); initializeARMLoadStoreOptPass(Registry); Index: lib/Target/ARM/AsmParser/ARMAsmParser.cpp =================================================================== --- lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -10408,10 +10408,10 @@ /// Force static initialization. extern "C" void LLVMInitializeARMAsmParser() { - RegisterMCAsmParser X(TheARMLETarget); - RegisterMCAsmParser Y(TheARMBETarget); - RegisterMCAsmParser A(TheThumbLETarget); - RegisterMCAsmParser B(TheThumbBETarget); + RegisterMCAsmParser X(getTheARMLETarget()); + RegisterMCAsmParser Y(getTheARMBETarget()); + RegisterMCAsmParser A(getTheThumbLETarget()); + RegisterMCAsmParser B(getTheThumbBETarget()); } #define GET_REGISTER_MATCHER Index: lib/Target/ARM/Disassembler/ARMDisassembler.cpp =================================================================== --- lib/Target/ARM/Disassembler/ARMDisassembler.cpp +++ lib/Target/ARM/Disassembler/ARMDisassembler.cpp @@ -861,13 +861,13 @@ extern "C" void LLVMInitializeARMDisassembler() { - TargetRegistry::RegisterMCDisassembler(TheARMLETarget, + TargetRegistry::RegisterMCDisassembler(getTheARMLETarget(), createARMDisassembler); - TargetRegistry::RegisterMCDisassembler(TheARMBETarget, + TargetRegistry::RegisterMCDisassembler(getTheARMBETarget(), createARMDisassembler); - TargetRegistry::RegisterMCDisassembler(TheThumbLETarget, + TargetRegistry::RegisterMCDisassembler(getTheThumbLETarget(), createThumbDisassembler); - TargetRegistry::RegisterMCDisassembler(TheThumbBETarget, + TargetRegistry::RegisterMCDisassembler(getTheThumbBETarget(), createThumbDisassembler); } Index: lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h =================================================================== --- lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h +++ lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h @@ -37,8 +37,10 @@ class raw_ostream; class raw_pwrite_stream; -extern Target TheARMLETarget, TheThumbLETarget; -extern Target TheARMBETarget, TheThumbBETarget; +Target &getTheARMLETarget(); +Target &getTheThumbLETarget(); +Target &getTheARMBETarget(); +Target &getTheThumbBETarget(); namespace ARM_MC { std::string ParseARMTriple(const Triple &TT, StringRef CPU); Index: lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp =================================================================== --- lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp +++ lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp @@ -274,8 +274,8 @@ // Force static initialization. extern "C" void LLVMInitializeARMTargetMC() { - for (Target *T : {&TheARMLETarget, &TheARMBETarget, &TheThumbLETarget, - &TheThumbBETarget}) { + for (Target *T : {&getTheARMLETarget(), &getTheARMBETarget(), + &getTheThumbLETarget(), &getTheThumbBETarget()}) { // Register the MC asm info. RegisterMCAsmInfoFn X(*T, createARMMCAsmInfo); @@ -314,16 +314,18 @@ } // Register the MC Code Emitter - for (Target *T : {&TheARMLETarget, &TheThumbLETarget}) + for (Target *T : {&getTheARMLETarget(), &getTheThumbLETarget()}) TargetRegistry::RegisterMCCodeEmitter(*T, createARMLEMCCodeEmitter); - for (Target *T : {&TheARMBETarget, &TheThumbBETarget}) + for (Target *T : {&getTheARMBETarget(), &getTheThumbBETarget()}) TargetRegistry::RegisterMCCodeEmitter(*T, createARMBEMCCodeEmitter); // Register the asm backend. - TargetRegistry::RegisterMCAsmBackend(TheARMLETarget, createARMLEAsmBackend); - TargetRegistry::RegisterMCAsmBackend(TheARMBETarget, createARMBEAsmBackend); - TargetRegistry::RegisterMCAsmBackend(TheThumbLETarget, + TargetRegistry::RegisterMCAsmBackend(getTheARMLETarget(), + createARMLEAsmBackend); + TargetRegistry::RegisterMCAsmBackend(getTheARMBETarget(), + createARMBEAsmBackend); + TargetRegistry::RegisterMCAsmBackend(getTheThumbLETarget(), createThumbLEAsmBackend); - TargetRegistry::RegisterMCAsmBackend(TheThumbBETarget, + TargetRegistry::RegisterMCAsmBackend(getTheThumbBETarget(), createThumbBEAsmBackend); } Index: lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp =================================================================== --- lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp +++ lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp @@ -11,17 +11,31 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::TheARMLETarget, llvm::TheARMBETarget; -Target llvm::TheThumbLETarget, llvm::TheThumbBETarget; +Target &llvm::getTheARMLETarget() { + static Target TheARMLETarget; + return TheARMLETarget; +} +Target &llvm::getTheARMBETarget() { + static Target TheARMBETarget; + return TheARMBETarget; +} +Target &llvm::getTheThumbLETarget() { + static Target TheThumbLETarget; + return TheThumbLETarget; +} +Target &llvm::getTheThumbBETarget() { + static Target TheThumbBETarget; + return TheThumbBETarget; +} extern "C" void LLVMInitializeARMTargetInfo() { - RegisterTarget - X(TheARMLETarget, "arm", "ARM"); - RegisterTarget - Y(TheARMBETarget, "armeb", "ARM (big endian)"); + RegisterTarget X(getTheARMLETarget(), "arm", + "ARM"); + RegisterTarget Y(getTheARMBETarget(), "armeb", + "ARM (big endian)"); - RegisterTarget - A(TheThumbLETarget, "thumb", "Thumb"); - RegisterTarget - B(TheThumbBETarget, "thumbeb", "Thumb (big endian)"); + RegisterTarget A(getTheThumbLETarget(), + "thumb", "Thumb"); + RegisterTarget B( + getTheThumbBETarget(), "thumbeb", "Thumb (big endian)"); } Index: lib/Target/AVR/AVRAsmPrinter.cpp =================================================================== --- lib/Target/AVR/AVRAsmPrinter.cpp +++ lib/Target/AVR/AVRAsmPrinter.cpp @@ -177,6 +177,6 @@ } // end of namespace llvm extern "C" void LLVMInitializeAVRAsmPrinter() { - llvm::RegisterAsmPrinter X(llvm::TheAVRTarget); + llvm::RegisterAsmPrinter X(llvm::getTheAVRTarget()); } Index: lib/Target/AVR/AVRTargetMachine.cpp =================================================================== --- lib/Target/AVR/AVRTargetMachine.cpp +++ lib/Target/AVR/AVRTargetMachine.cpp @@ -77,7 +77,7 @@ extern "C" void LLVMInitializeAVRTarget() { // Register the target. - RegisterTargetMachine X(TheAVRTarget); + RegisterTargetMachine X(getTheAVRTarget()); } const AVRSubtarget *AVRTargetMachine::getSubtargetImpl() const { Index: lib/Target/AVR/AsmParser/AVRAsmParser.cpp =================================================================== --- lib/Target/AVR/AsmParser/AVRAsmParser.cpp +++ lib/Target/AVR/AsmParser/AVRAsmParser.cpp @@ -582,7 +582,7 @@ bool AVRAsmParser::ParseDirective(llvm::AsmToken DirectiveID) { return true; } extern "C" void LLVMInitializeAVRAsmParser() { - RegisterMCAsmParser X(TheAVRTarget); + RegisterMCAsmParser X(getTheAVRTarget()); } #define GET_REGISTER_MATCHER Index: lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.h =================================================================== --- lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.h +++ lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.h @@ -30,7 +30,7 @@ class Triple; class raw_pwrite_stream; -extern Target TheAVRTarget; +Target &getTheAVRTarget(); /// Creates a machine code emitter for AVR. MCCodeEmitter *createAVRMCCodeEmitter(const MCInstrInfo &MCII, Index: lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.cpp =================================================================== --- lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.cpp +++ lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.cpp @@ -85,33 +85,34 @@ extern "C" void LLVMInitializeAVRTargetMC() { // Register the MC asm info. - RegisterMCAsmInfo X(TheAVRTarget); + RegisterMCAsmInfo X(getTheAVRTarget()); // Register the MC instruction info. - TargetRegistry::RegisterMCInstrInfo(TheAVRTarget, createAVRMCInstrInfo); + TargetRegistry::RegisterMCInstrInfo(getTheAVRTarget(), createAVRMCInstrInfo); // Register the MC register info. - TargetRegistry::RegisterMCRegInfo(TheAVRTarget, createAVRMCRegisterInfo); + TargetRegistry::RegisterMCRegInfo(getTheAVRTarget(), createAVRMCRegisterInfo); // Register the MC subtarget info. - TargetRegistry::RegisterMCSubtargetInfo(TheAVRTarget, + TargetRegistry::RegisterMCSubtargetInfo(getTheAVRTarget(), createAVRMCSubtargetInfo); // Register the MCInstPrinter. - TargetRegistry::RegisterMCInstPrinter(TheAVRTarget, createAVRMCInstPrinter); + TargetRegistry::RegisterMCInstPrinter(getTheAVRTarget(), + createAVRMCInstPrinter); // Register the ELF streamer - TargetRegistry::RegisterELFStreamer(TheAVRTarget, createMCStreamer); + TargetRegistry::RegisterELFStreamer(getTheAVRTarget(), createMCStreamer); // Register the obj target streamer. - TargetRegistry::RegisterObjectTargetStreamer(TheAVRTarget, + TargetRegistry::RegisterObjectTargetStreamer(getTheAVRTarget(), createAVRObjectTargetStreamer); // Register the asm target streamer. - TargetRegistry::RegisterAsmTargetStreamer(TheAVRTarget, + TargetRegistry::RegisterAsmTargetStreamer(getTheAVRTarget(), createMCAsmTargetStreamer); // Register the asm backend (as little endian). - TargetRegistry::RegisterMCAsmBackend(TheAVRTarget, createAVRAsmBackend); + TargetRegistry::RegisterMCAsmBackend(getTheAVRTarget(), createAVRAsmBackend); } Index: lib/Target/AVR/TargetInfo/AVRTargetInfo.cpp =================================================================== --- lib/Target/AVR/TargetInfo/AVRTargetInfo.cpp +++ lib/Target/AVR/TargetInfo/AVRTargetInfo.cpp @@ -10,12 +10,13 @@ #include "llvm/IR/Module.h" #include "llvm/Support/TargetRegistry.h" -namespace llvm { -Target TheAVRTarget; +Target &llvm::getgetTheAVRTarget()() { + static Target getTheAVRTarget(); + return getTheAVRTarget(); } extern "C" void LLVMInitializeAVRTargetInfo() { - llvm::RegisterTarget X( - llvm::TheAVRTarget, "avr", "Atmel AVR Microcontroller"); + llvm::RegisterTarget X(llvm::getTheAVRTarget(), "avr", + "Atmel AVR Microcontroller"); } Index: lib/Target/BPF/BPFAsmPrinter.cpp =================================================================== --- lib/Target/BPF/BPFAsmPrinter.cpp +++ lib/Target/BPF/BPFAsmPrinter.cpp @@ -55,7 +55,7 @@ // Force static initialization. extern "C" void LLVMInitializeBPFAsmPrinter() { - RegisterAsmPrinter X(TheBPFleTarget); - RegisterAsmPrinter Y(TheBPFbeTarget); - RegisterAsmPrinter Z(TheBPFTarget); + RegisterAsmPrinter X(getTheBPFleTarget()); + RegisterAsmPrinter Y(getTheBPFbeTarget()); + RegisterAsmPrinter Z(getTheBPFTarget()); } Index: lib/Target/BPF/BPFTargetMachine.cpp =================================================================== --- lib/Target/BPF/BPFTargetMachine.cpp +++ lib/Target/BPF/BPFTargetMachine.cpp @@ -24,9 +24,9 @@ extern "C" void LLVMInitializeBPFTarget() { // Register the target. - RegisterTargetMachine X(TheBPFleTarget); - RegisterTargetMachine Y(TheBPFbeTarget); - RegisterTargetMachine Z(TheBPFTarget); + RegisterTargetMachine X(getTheBPFleTarget()); + RegisterTargetMachine Y(getTheBPFbeTarget()); + RegisterTargetMachine Z(getTheBPFTarget()); } // DataLayout: little or big endian Index: lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h =================================================================== --- lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h +++ lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h @@ -32,9 +32,9 @@ class raw_ostream; class raw_pwrite_stream; -extern Target TheBPFleTarget; -extern Target TheBPFbeTarget; -extern Target TheBPFTarget; +Target &getTheBPFleTarget(); +Target &getTheBPFbeTarget(); +Target &getTheBPFTarget(); MCCodeEmitter *createBPFMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, Index: lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp =================================================================== --- lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp +++ lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp @@ -68,7 +68,8 @@ } extern "C" void LLVMInitializeBPFTargetMC() { - for (Target *T : {&TheBPFleTarget, &TheBPFbeTarget, &TheBPFTarget}) { + for (Target *T : + {&getTheBPFleTarget(), &getTheBPFbeTarget(), &getTheBPFTarget()}) { // Register the MC asm info. RegisterMCAsmInfo X(*T); @@ -90,18 +91,26 @@ } // Register the MC code emitter - TargetRegistry::RegisterMCCodeEmitter(TheBPFleTarget, createBPFMCCodeEmitter); - TargetRegistry::RegisterMCCodeEmitter(TheBPFbeTarget, createBPFbeMCCodeEmitter); + TargetRegistry::RegisterMCCodeEmitter(getTheBPFleTarget(), + createBPFMCCodeEmitter); + TargetRegistry::RegisterMCCodeEmitter(getTheBPFbeTarget(), + createBPFbeMCCodeEmitter); // Register the ASM Backend - TargetRegistry::RegisterMCAsmBackend(TheBPFleTarget, createBPFAsmBackend); - TargetRegistry::RegisterMCAsmBackend(TheBPFbeTarget, createBPFbeAsmBackend); + TargetRegistry::RegisterMCAsmBackend(getTheBPFleTarget(), + createBPFAsmBackend); + TargetRegistry::RegisterMCAsmBackend(getTheBPFbeTarget(), + createBPFbeAsmBackend); if (sys::IsLittleEndianHost) { - TargetRegistry::RegisterMCCodeEmitter(TheBPFTarget, createBPFMCCodeEmitter); - TargetRegistry::RegisterMCAsmBackend(TheBPFTarget, createBPFAsmBackend); + TargetRegistry::RegisterMCCodeEmitter(getTheBPFTarget(), + createBPFMCCodeEmitter); + TargetRegistry::RegisterMCAsmBackend(getTheBPFTarget(), + createBPFAsmBackend); } else { - TargetRegistry::RegisterMCCodeEmitter(TheBPFTarget, createBPFbeMCCodeEmitter); - TargetRegistry::RegisterMCAsmBackend(TheBPFTarget, createBPFbeAsmBackend); + TargetRegistry::RegisterMCCodeEmitter(getTheBPFTarget(), + createBPFbeMCCodeEmitter); + TargetRegistry::RegisterMCAsmBackend(getTheBPFTarget(), + createBPFbeAsmBackend); } } Index: lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp =================================================================== --- lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp +++ lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp @@ -12,17 +12,25 @@ using namespace llvm; namespace llvm { -Target TheBPFleTarget; -Target TheBPFbeTarget; -Target TheBPFTarget; +Target &getTheBPFleTarget() { + static Target TheBPFleTarget; + return TheBPFleTarget; +} +Target &getTheBPFbeTarget() { + static Target TheBPFbeTarget; + return TheBPFbeTarget; +} +Target &getTheBPFTarget() { + static Target TheBPFTarget; + return TheBPFTarget; +} } extern "C" void LLVMInitializeBPFTargetInfo() { - TargetRegistry::RegisterTarget(TheBPFTarget, "bpf", - "BPF (host endian)", + TargetRegistry::RegisterTarget(getTheBPFTarget(), "bpf", "BPF (host endian)", [](Triple::ArchType) { return false; }, true); - RegisterTarget X( - TheBPFleTarget, "bpfel", "BPF (little endian)"); - RegisterTarget Y( - TheBPFbeTarget, "bpfeb", "BPF (big endian)"); + RegisterTarget X(getTheBPFleTarget(), "bpfel", + "BPF (little endian)"); + RegisterTarget Y(getTheBPFbeTarget(), "bpfeb", + "BPF (big endian)"); } Index: lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp =================================================================== --- lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp +++ lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp @@ -1065,7 +1065,7 @@ /// Force static initialization. extern "C" void LLVMInitializeHexagonAsmParser() { - RegisterMCAsmParser X(TheHexagonTarget); + RegisterMCAsmParser X(getTheHexagonTarget()); } #define GET_MATCHER_IMPLEMENTATION Index: lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp =================================================================== --- lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp +++ lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp @@ -147,7 +147,7 @@ } extern "C" void LLVMInitializeHexagonDisassembler() { - TargetRegistry::RegisterMCDisassembler(TheHexagonTarget, + TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(), createHexagonDisassembler); } Index: lib/Target/Hexagon/HexagonAsmPrinter.cpp =================================================================== --- lib/Target/Hexagon/HexagonAsmPrinter.cpp +++ lib/Target/Hexagon/HexagonAsmPrinter.cpp @@ -600,5 +600,5 @@ } extern "C" void LLVMInitializeHexagonAsmPrinter() { - RegisterAsmPrinter X(TheHexagonTarget); + RegisterAsmPrinter X(getTheHexagonTarget()); } Index: lib/Target/Hexagon/HexagonTargetMachine.cpp =================================================================== --- lib/Target/Hexagon/HexagonTargetMachine.cpp +++ lib/Target/Hexagon/HexagonTargetMachine.cpp @@ -100,7 +100,7 @@ extern "C" void LLVMInitializeHexagonTarget() { // Register the target. - RegisterTargetMachine X(TheHexagonTarget); + RegisterTargetMachine X(getTheHexagonTarget()); } static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) { Index: lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h =================================================================== --- lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h +++ lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.h @@ -35,7 +35,7 @@ class raw_ostream; class raw_pwrite_stream; -extern Target TheHexagonTarget; +Target &getTheHexagonTarget(); extern cl::opt HexagonDisableCompound; extern cl::opt HexagonDisableDuplex; extern const InstrStage HexagonStages[]; Index: lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp =================================================================== --- lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -230,39 +230,39 @@ // Force static initialization. extern "C" void LLVMInitializeHexagonTargetMC() { // Register the MC asm info. - RegisterMCAsmInfoFn X(TheHexagonTarget, createHexagonMCAsmInfo); + RegisterMCAsmInfoFn X(getTheHexagonTarget(), createHexagonMCAsmInfo); // Register the MC instruction info. - TargetRegistry::RegisterMCInstrInfo(TheHexagonTarget, + TargetRegistry::RegisterMCInstrInfo(getTheHexagonTarget(), createHexagonMCInstrInfo); // Register the MC register info. - TargetRegistry::RegisterMCRegInfo(TheHexagonTarget, + TargetRegistry::RegisterMCRegInfo(getTheHexagonTarget(), createHexagonMCRegisterInfo); // Register the MC subtarget info. - TargetRegistry::RegisterMCSubtargetInfo(TheHexagonTarget, + TargetRegistry::RegisterMCSubtargetInfo(getTheHexagonTarget(), createHexagonMCSubtargetInfo); // Register the MC Code Emitter - TargetRegistry::RegisterMCCodeEmitter(TheHexagonTarget, + TargetRegistry::RegisterMCCodeEmitter(getTheHexagonTarget(), createHexagonMCCodeEmitter); // Register the asm backend - TargetRegistry::RegisterMCAsmBackend(TheHexagonTarget, + TargetRegistry::RegisterMCAsmBackend(getTheHexagonTarget(), createHexagonAsmBackend); // Register the obj streamer - TargetRegistry::RegisterELFStreamer(TheHexagonTarget, createMCStreamer); + TargetRegistry::RegisterELFStreamer(getTheHexagonTarget(), createMCStreamer); // Register the asm streamer - TargetRegistry::RegisterAsmTargetStreamer(TheHexagonTarget, + TargetRegistry::RegisterAsmTargetStreamer(getTheHexagonTarget(), createMCAsmTargetStreamer); // Register the MC Inst Printer - TargetRegistry::RegisterMCInstPrinter(TheHexagonTarget, + TargetRegistry::RegisterMCInstPrinter(getTheHexagonTarget(), createHexagonMCInstPrinter); TargetRegistry::RegisterObjectTargetStreamer( - TheHexagonTarget, createHexagonObjectTargetStreamer); + getTheHexagonTarget(), createHexagonObjectTargetStreamer); } Index: lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp =================================================================== --- lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp +++ lib/Target/Hexagon/TargetInfo/HexagonTargetInfo.cpp @@ -12,8 +12,12 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::TheHexagonTarget; +Target &llvm::getTheHexagonTarget() { + static Target TheHexagonTarget; + return TheHexagonTarget; +} extern "C" void LLVMInitializeHexagonTargetInfo() { - RegisterTarget X(TheHexagonTarget, "hexagon", "Hexagon"); + RegisterTarget X(getTheHexagonTarget(), + "hexagon", "Hexagon"); } Index: lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp =================================================================== --- lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp +++ lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp @@ -1207,7 +1207,7 @@ } // namespace extern "C" void LLVMInitializeLanaiAsmParser() { - RegisterMCAsmParser x(TheLanaiTarget); + RegisterMCAsmParser x(getTheLanaiTarget()); } } // namespace llvm Index: lib/Target/Lanai/Disassembler/LanaiDisassembler.cpp =================================================================== --- lib/Target/Lanai/Disassembler/LanaiDisassembler.cpp +++ lib/Target/Lanai/Disassembler/LanaiDisassembler.cpp @@ -27,7 +27,7 @@ typedef MCDisassembler::DecodeStatus DecodeStatus; namespace llvm { -extern Target TheLanaiTarget; +Target &getTheLanaiTarget(); } static MCDisassembler *createLanaiDisassembler(const Target & /*T*/, @@ -38,7 +38,7 @@ extern "C" void LLVMInitializeLanaiDisassembler() { // Register the disassembler - TargetRegistry::RegisterMCDisassembler(TheLanaiTarget, + TargetRegistry::RegisterMCDisassembler(getTheLanaiTarget(), createLanaiDisassembler); } Index: lib/Target/Lanai/Lanai.h =================================================================== --- lib/Target/Lanai/Lanai.h +++ lib/Target/Lanai/Lanai.h @@ -45,7 +45,7 @@ // operations. FunctionPass *createLanaiSetflagAluCombinerPass(); -extern Target TheLanaiTarget; +Target &getTheLanaiTarget(); } // namespace llvm #endif // LLVM_LIB_TARGET_LANAI_LANAI_H Index: lib/Target/Lanai/LanaiAsmPrinter.cpp =================================================================== --- lib/Target/Lanai/LanaiAsmPrinter.cpp +++ lib/Target/Lanai/LanaiAsmPrinter.cpp @@ -239,5 +239,5 @@ // Force static initialization. extern "C" void LLVMInitializeLanaiAsmPrinter() { - RegisterAsmPrinter X(TheLanaiTarget); + RegisterAsmPrinter X(getTheLanaiTarget()); } Index: lib/Target/Lanai/LanaiTargetMachine.cpp =================================================================== --- lib/Target/Lanai/LanaiTargetMachine.cpp +++ lib/Target/Lanai/LanaiTargetMachine.cpp @@ -32,7 +32,8 @@ extern "C" void LLVMInitializeLanaiTarget() { // Register the target. - RegisterTargetMachine registered_target(TheLanaiTarget); + RegisterTargetMachine registered_target( + getTheLanaiTarget()); } static std::string computeDataLayout() { Index: lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.h =================================================================== --- lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.h +++ lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.h @@ -32,7 +32,7 @@ class StringRef; class raw_pwrite_stream; -extern Target TheLanaiTarget; +Target &getTheLanaiTarget(); MCCodeEmitter *createLanaiMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, Index: lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp =================================================================== --- lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp +++ lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp @@ -113,37 +113,40 @@ extern "C" void LLVMInitializeLanaiTargetMC() { // Register the MC asm info. - RegisterMCAsmInfo X(TheLanaiTarget); + RegisterMCAsmInfo X(getTheLanaiTarget()); // Register the MC instruction info. - TargetRegistry::RegisterMCInstrInfo(TheLanaiTarget, createLanaiMCInstrInfo); + TargetRegistry::RegisterMCInstrInfo(getTheLanaiTarget(), + createLanaiMCInstrInfo); // Register the MC register info. - TargetRegistry::RegisterMCRegInfo(TheLanaiTarget, createLanaiMCRegisterInfo); + TargetRegistry::RegisterMCRegInfo(getTheLanaiTarget(), + createLanaiMCRegisterInfo); // Register the MC subtarget info. - TargetRegistry::RegisterMCSubtargetInfo(TheLanaiTarget, + TargetRegistry::RegisterMCSubtargetInfo(getTheLanaiTarget(), createLanaiMCSubtargetInfo); // Register the MC code emitter - TargetRegistry::RegisterMCCodeEmitter(TheLanaiTarget, + TargetRegistry::RegisterMCCodeEmitter(getTheLanaiTarget(), llvm::createLanaiMCCodeEmitter); // Register the ASM Backend - TargetRegistry::RegisterMCAsmBackend(TheLanaiTarget, createLanaiAsmBackend); + TargetRegistry::RegisterMCAsmBackend(getTheLanaiTarget(), + createLanaiAsmBackend); // Register the MCInstPrinter. - TargetRegistry::RegisterMCInstPrinter(TheLanaiTarget, + TargetRegistry::RegisterMCInstPrinter(getTheLanaiTarget(), createLanaiMCInstPrinter); // Register the ELF streamer. - TargetRegistry::RegisterELFStreamer(TheLanaiTarget, createMCStreamer); + TargetRegistry::RegisterELFStreamer(getTheLanaiTarget(), createMCStreamer); // Register the MC relocation info. - TargetRegistry::RegisterMCRelocationInfo(TheLanaiTarget, + TargetRegistry::RegisterMCRelocationInfo(getTheLanaiTarget(), createLanaiElfRelocation); // Register the MC instruction analyzer. - TargetRegistry::RegisterMCInstrAnalysis(TheLanaiTarget, + TargetRegistry::RegisterMCInstrAnalysis(getTheLanaiTarget(), createLanaiInstrAnalysis); } Index: lib/Target/Lanai/TargetInfo/LanaiTargetInfo.cpp =================================================================== --- lib/Target/Lanai/TargetInfo/LanaiTargetInfo.cpp +++ lib/Target/Lanai/TargetInfo/LanaiTargetInfo.cpp @@ -13,8 +13,13 @@ using namespace llvm; -Target llvm::TheLanaiTarget; +namespace llvm { +Target &getTheLanaiTarget() { + static Target TheLanaiTarget; + return TheLanaiTarget; +} +} extern "C" void LLVMInitializeLanaiTargetInfo() { - RegisterTarget X(TheLanaiTarget, "lanai", "Lanai"); + RegisterTarget X(getTheLanaiTarget(), "lanai", "Lanai"); } Index: lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.h =================================================================== --- lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.h +++ lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.h @@ -19,7 +19,7 @@ namespace llvm { class Target; -extern Target TheMSP430Target; +Target &getTheMSP430Target(); } // End llvm namespace Index: lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.cpp =================================================================== --- lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.cpp +++ lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.cpp @@ -59,20 +59,21 @@ extern "C" void LLVMInitializeMSP430TargetMC() { // Register the MC asm info. - RegisterMCAsmInfo X(TheMSP430Target); + RegisterMCAsmInfo X(getTheMSP430Target()); // Register the MC instruction info. - TargetRegistry::RegisterMCInstrInfo(TheMSP430Target, createMSP430MCInstrInfo); + TargetRegistry::RegisterMCInstrInfo(getTheMSP430Target(), + createMSP430MCInstrInfo); // Register the MC register info. - TargetRegistry::RegisterMCRegInfo(TheMSP430Target, + TargetRegistry::RegisterMCRegInfo(getTheMSP430Target(), createMSP430MCRegisterInfo); // Register the MC subtarget info. - TargetRegistry::RegisterMCSubtargetInfo(TheMSP430Target, + TargetRegistry::RegisterMCSubtargetInfo(getTheMSP430Target(), createMSP430MCSubtargetInfo); // Register the MCInstPrinter. - TargetRegistry::RegisterMCInstPrinter(TheMSP430Target, + TargetRegistry::RegisterMCInstPrinter(getTheMSP430Target(), createMSP430MCInstPrinter); } Index: lib/Target/MSP430/MSP430AsmPrinter.cpp =================================================================== --- lib/Target/MSP430/MSP430AsmPrinter.cpp +++ lib/Target/MSP430/MSP430AsmPrinter.cpp @@ -155,5 +155,5 @@ // Force static initialization. extern "C" void LLVMInitializeMSP430AsmPrinter() { - RegisterAsmPrinter X(TheMSP430Target); + RegisterAsmPrinter X(getTheMSP430Target()); } Index: lib/Target/MSP430/MSP430TargetMachine.cpp =================================================================== --- lib/Target/MSP430/MSP430TargetMachine.cpp +++ lib/Target/MSP430/MSP430TargetMachine.cpp @@ -23,7 +23,7 @@ extern "C" void LLVMInitializeMSP430Target() { // Register the target. - RegisterTargetMachine X(TheMSP430Target); + RegisterTargetMachine X(getTheMSP430Target()); } static Reloc::Model getEffectiveRelocModel(Optional RM) { Index: lib/Target/MSP430/TargetInfo/MSP430TargetInfo.cpp =================================================================== --- lib/Target/MSP430/TargetInfo/MSP430TargetInfo.cpp +++ lib/Target/MSP430/TargetInfo/MSP430TargetInfo.cpp @@ -12,9 +12,12 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::TheMSP430Target; +Target &llvm::getTheMSP430Target() { + static Target TheMSP430Target; + return TheMSP430Target; +} -extern "C" void LLVMInitializeMSP430TargetInfo() { - RegisterTarget - X(TheMSP430Target, "msp430", "MSP430 [experimental]"); +extern "C" void LLVMInitializeMSP430TargetInfo() { + RegisterTarget X(getTheMSP430Target(), "msp430", + "MSP430 [experimental]"); } Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -6469,10 +6469,10 @@ } extern "C" void LLVMInitializeMipsAsmParser() { - RegisterMCAsmParser X(TheMipsTarget); - RegisterMCAsmParser Y(TheMipselTarget); - RegisterMCAsmParser A(TheMips64Target); - RegisterMCAsmParser B(TheMips64elTarget); + RegisterMCAsmParser X(getTheMipsTarget()); + RegisterMCAsmParser Y(getTheMipselTarget()); + RegisterMCAsmParser A(getTheMips64Target()); + RegisterMCAsmParser B(getTheMips64elTarget()); } #define GET_REGISTER_MATCHER Index: lib/Target/Mips/Disassembler/MipsDisassembler.cpp =================================================================== --- lib/Target/Mips/Disassembler/MipsDisassembler.cpp +++ lib/Target/Mips/Disassembler/MipsDisassembler.cpp @@ -519,8 +519,10 @@ const void *Decoder); namespace llvm { -extern Target TheMipselTarget, TheMipsTarget, TheMips64Target, - TheMips64elTarget; +Target &getTheMipselTarget(); +Target &getTheMipsTarget(); +Target &getTheMips64Target(); +Target &getTheMips64elTarget(); } static MCDisassembler *createMipsDisassembler( @@ -539,13 +541,13 @@ extern "C" void LLVMInitializeMipsDisassembler() { // Register the disassembler. - TargetRegistry::RegisterMCDisassembler(TheMipsTarget, + TargetRegistry::RegisterMCDisassembler(getTheMipsTarget(), createMipsDisassembler); - TargetRegistry::RegisterMCDisassembler(TheMipselTarget, + TargetRegistry::RegisterMCDisassembler(getTheMipselTarget(), createMipselDisassembler); - TargetRegistry::RegisterMCDisassembler(TheMips64Target, + TargetRegistry::RegisterMCDisassembler(getTheMips64Target(), createMipsDisassembler); - TargetRegistry::RegisterMCDisassembler(TheMips64elTarget, + TargetRegistry::RegisterMCDisassembler(getTheMips64elTarget(), createMipselDisassembler); } Index: lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.h =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.h +++ lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.h @@ -31,10 +31,10 @@ class raw_ostream; class raw_pwrite_stream; -extern Target TheMipsTarget; -extern Target TheMipselTarget; -extern Target TheMips64Target; -extern Target TheMips64elTarget; +Target &getTheMipsTarget(); +Target &getTheMipselTarget(); +Target &getTheMips64Target(); +Target &getTheMips64elTarget(); MCCodeEmitter *createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, Index: lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp +++ lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp @@ -149,8 +149,8 @@ } extern "C" void LLVMInitializeMipsTargetMC() { - for (Target *T : {&TheMipsTarget, &TheMipselTarget, &TheMips64Target, - &TheMips64elTarget}) { + for (Target *T : {&getTheMipsTarget(), &getTheMipselTarget(), + &getTheMips64Target(), &getTheMips64elTarget()}) { // Register the MC asm info. RegisterMCAsmInfoFn X(*T, createMipsMCAsmInfo); @@ -183,20 +183,19 @@ } // Register the MC Code Emitter - for (Target *T : {&TheMipsTarget, &TheMips64Target}) + for (Target *T : {&getTheMipsTarget(), &getTheMips64Target()}) TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEB); - for (Target *T : {&TheMipselTarget, &TheMips64elTarget}) + for (Target *T : {&getTheMipselTarget(), &getTheMips64elTarget()}) TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEL); // Register the asm backend. - TargetRegistry::RegisterMCAsmBackend(TheMipsTarget, + TargetRegistry::RegisterMCAsmBackend(getTheMipsTarget(), createMipsAsmBackendEB32); - TargetRegistry::RegisterMCAsmBackend(TheMipselTarget, + TargetRegistry::RegisterMCAsmBackend(getTheMipselTarget(), createMipsAsmBackendEL32); - TargetRegistry::RegisterMCAsmBackend(TheMips64Target, + TargetRegistry::RegisterMCAsmBackend(getTheMips64Target(), createMipsAsmBackendEB64); - TargetRegistry::RegisterMCAsmBackend(TheMips64elTarget, + TargetRegistry::RegisterMCAsmBackend(getTheMips64elTarget(), createMipsAsmBackendEL64); - } Index: lib/Target/Mips/MipsAsmPrinter.cpp =================================================================== --- lib/Target/Mips/MipsAsmPrinter.cpp +++ lib/Target/Mips/MipsAsmPrinter.cpp @@ -1066,8 +1066,8 @@ // Force static initialization. extern "C" void LLVMInitializeMipsAsmPrinter() { - RegisterAsmPrinter X(TheMipsTarget); - RegisterAsmPrinter Y(TheMipselTarget); - RegisterAsmPrinter A(TheMips64Target); - RegisterAsmPrinter B(TheMips64elTarget); + RegisterAsmPrinter X(getTheMipsTarget()); + RegisterAsmPrinter Y(getTheMipselTarget()); + RegisterAsmPrinter A(getTheMips64Target()); + RegisterAsmPrinter B(getTheMips64elTarget()); } Index: lib/Target/Mips/MipsTargetMachine.cpp =================================================================== --- lib/Target/Mips/MipsTargetMachine.cpp +++ lib/Target/Mips/MipsTargetMachine.cpp @@ -39,10 +39,10 @@ extern "C" void LLVMInitializeMipsTarget() { // Register the target. - RegisterTargetMachine X(TheMipsTarget); - RegisterTargetMachine Y(TheMipselTarget); - RegisterTargetMachine A(TheMips64Target); - RegisterTargetMachine B(TheMips64elTarget); + RegisterTargetMachine X(getTheMipsTarget()); + RegisterTargetMachine Y(getTheMipselTarget()); + RegisterTargetMachine A(getTheMips64Target()); + RegisterTargetMachine B(getTheMips64elTarget()); } static std::string computeDataLayout(const Triple &TT, StringRef CPU, Index: lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp =================================================================== --- lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp +++ lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp @@ -12,20 +12,37 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::TheMipsTarget, llvm::TheMipselTarget; -Target llvm::TheMips64Target, llvm::TheMips64elTarget; +Target &llvm::getTheMipsTarget() { + static Target TheMipsTarget; + return TheMipsTarget; +} +Target &llvm::getTheMipselTarget() { + static Target TheMipselTarget; + return TheMipselTarget; +} +Target &llvm::getTheMips64Target() { + static Target TheMips64Target; + return TheMips64Target; +} +Target &llvm::getTheMips64elTarget() { + static Target TheMips64elTarget; + return TheMips64elTarget; +} extern "C" void LLVMInitializeMipsTargetInfo() { RegisterTarget X(TheMipsTarget, "mips", "Mips"); + /*HasJIT=*/true> + X(getTheMipsTarget(), "mips", "Mips"); RegisterTarget Y(TheMipselTarget, "mipsel", "Mipsel"); + /*HasJIT=*/true> + Y(getTheMipselTarget(), "mipsel", "Mipsel"); RegisterTarget A(TheMips64Target, "mips64", "Mips64 [experimental]"); + /*HasJIT=*/true> + A(getTheMips64Target(), "mips64", "Mips64 [experimental]"); RegisterTarget B(TheMips64elTarget, - "mips64el", "Mips64el [experimental]"); + /*HasJIT=*/true> + B(getTheMips64elTarget(), "mips64el", "Mips64el [experimental]"); } Index: lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.h =================================================================== --- lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.h +++ lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.h @@ -19,8 +19,8 @@ namespace llvm { class Target; -extern Target TheNVPTXTarget32; -extern Target TheNVPTXTarget64; +Target &getTheNVPTXTarget32(); +Target &getTheNVPTXTarget64(); } // End llvm namespace Index: lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp =================================================================== --- lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp +++ lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp @@ -60,7 +60,7 @@ // Force static initialization. extern "C" void LLVMInitializeNVPTXTargetMC() { - for (Target *T : {&TheNVPTXTarget32, &TheNVPTXTarget64}) { + for (Target *T : {&getTheNVPTXTarget32(), &getTheNVPTXTarget64()}) { // Register the MC asm info. RegisterMCAsmInfo X(*T); Index: lib/Target/NVPTX/NVPTX.h =================================================================== --- lib/Target/NVPTX/NVPTX.h +++ lib/Target/NVPTX/NVPTX.h @@ -57,8 +57,8 @@ BasicBlockPass *createNVPTXLowerAllocaPass(); MachineFunctionPass *createNVPTXPeephole(); -extern Target TheNVPTXTarget32; -extern Target TheNVPTXTarget64; +Target &getTheNVPTXTarget32(); +Target &getTheNVPTXTarget64(); namespace NVPTX { enum DrvInterface { Index: lib/Target/NVPTX/NVPTXAsmPrinter.cpp =================================================================== --- lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -2380,6 +2380,6 @@ // Force static initialization. extern "C" void LLVMInitializeNVPTXAsmPrinter() { - RegisterAsmPrinter X(TheNVPTXTarget32); - RegisterAsmPrinter Y(TheNVPTXTarget64); + RegisterAsmPrinter X(getTheNVPTXTarget32()); + RegisterAsmPrinter Y(getTheNVPTXTarget64()); } Index: lib/Target/NVPTX/NVPTXTargetMachine.cpp =================================================================== --- lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -76,8 +76,8 @@ extern "C" void LLVMInitializeNVPTXTarget() { // Register the target. - RegisterTargetMachine X(TheNVPTXTarget32); - RegisterTargetMachine Y(TheNVPTXTarget64); + RegisterTargetMachine X(getTheNVPTXTarget32()); + RegisterTargetMachine Y(getTheNVPTXTarget64()); // FIXME: This pass is really intended to be invoked during IR optimization, // but it's very NVPTX-specific. Index: lib/Target/NVPTX/TargetInfo/NVPTXTargetInfo.cpp =================================================================== --- lib/Target/NVPTX/TargetInfo/NVPTXTargetInfo.cpp +++ lib/Target/NVPTX/TargetInfo/NVPTXTargetInfo.cpp @@ -12,12 +12,18 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::TheNVPTXTarget32; -Target llvm::TheNVPTXTarget64; +Target &llvm::getTheNVPTXTarget32() { + static Target TheNVPTXTarget32; + return TheNVPTXTarget32; +} +Target &llvm::getTheNVPTXTarget64() { + static Target TheNVPTXTarget64; + return TheNVPTXTarget64; +} extern "C" void LLVMInitializeNVPTXTargetInfo() { - RegisterTarget X(TheNVPTXTarget32, "nvptx", + RegisterTarget X(getTheNVPTXTarget32(), "nvptx", "NVIDIA PTX 32-bit"); - RegisterTarget Y(TheNVPTXTarget64, "nvptx64", + RegisterTarget Y(getTheNVPTXTarget64(), "nvptx64", "NVIDIA PTX 64-bit"); } Index: lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp =================================================================== --- lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp +++ lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp @@ -1980,9 +1980,9 @@ /// Force static initialization. extern "C" void LLVMInitializePowerPCAsmParser() { - RegisterMCAsmParser A(ThePPC32Target); - RegisterMCAsmParser B(ThePPC64Target); - RegisterMCAsmParser C(ThePPC64LETarget); + RegisterMCAsmParser A(getThePPC32Target()); + RegisterMCAsmParser B(getThePPC64Target()); + RegisterMCAsmParser C(getThePPC64LETarget()); } #define GET_REGISTER_MATCHER Index: lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp =================================================================== --- lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp +++ lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp @@ -51,11 +51,11 @@ extern "C" void LLVMInitializePowerPCDisassembler() { // Register the disassembler for each target. - TargetRegistry::RegisterMCDisassembler(ThePPC32Target, + TargetRegistry::RegisterMCDisassembler(getThePPC32Target(), createPPCDisassembler); - TargetRegistry::RegisterMCDisassembler(ThePPC64Target, + TargetRegistry::RegisterMCDisassembler(getThePPC64Target(), createPPCDisassembler); - TargetRegistry::RegisterMCDisassembler(ThePPC64LETarget, + TargetRegistry::RegisterMCDisassembler(getThePPC64LETarget(), createPPCLEDisassembler); } Index: lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h =================================================================== --- lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h +++ lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.h @@ -35,9 +35,9 @@ class raw_pwrite_stream; class raw_ostream; -extern Target ThePPC32Target; -extern Target ThePPC64Target; -extern Target ThePPC64LETarget; +Target &getThePPC32Target(); +Target &getThePPC64Target(); +Target &getThePPC64LETarget(); MCCodeEmitter *createPPCMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, Index: lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp =================================================================== --- lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp +++ lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp @@ -228,7 +228,8 @@ } extern "C" void LLVMInitializePowerPCTargetMC() { - for (Target *T : {&ThePPC32Target, &ThePPC64Target, &ThePPC64LETarget}) { + for (Target *T : + {&getThePPC32Target(), &getThePPC64Target(), &getThePPC64LETarget()}) { // Register the MC asm info. RegisterMCAsmInfoFn C(*T, createPPCMCAsmInfo); Index: lib/Target/PowerPC/PPCAsmPrinter.cpp =================================================================== --- lib/Target/PowerPC/PPCAsmPrinter.cpp +++ lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1447,7 +1447,10 @@ // Force static initialization. extern "C" void LLVMInitializePowerPCAsmPrinter() { - TargetRegistry::RegisterAsmPrinter(ThePPC32Target, createPPCAsmPrinterPass); - TargetRegistry::RegisterAsmPrinter(ThePPC64Target, createPPCAsmPrinterPass); - TargetRegistry::RegisterAsmPrinter(ThePPC64LETarget, createPPCAsmPrinterPass); + TargetRegistry::RegisterAsmPrinter(getThePPC32Target(), + createPPCAsmPrinterPass); + TargetRegistry::RegisterAsmPrinter(getThePPC64Target(), + createPPCAsmPrinterPass); + TargetRegistry::RegisterAsmPrinter(getThePPC64LETarget(), + createPPCAsmPrinterPass); } Index: lib/Target/PowerPC/PPCTargetMachine.cpp =================================================================== --- lib/Target/PowerPC/PPCTargetMachine.cpp +++ lib/Target/PowerPC/PPCTargetMachine.cpp @@ -74,9 +74,9 @@ extern "C" void LLVMInitializePowerPCTarget() { // Register the targets - RegisterTargetMachine A(ThePPC32Target); - RegisterTargetMachine B(ThePPC64Target); - RegisterTargetMachine C(ThePPC64LETarget); + RegisterTargetMachine A(getThePPC32Target()); + RegisterTargetMachine B(getThePPC64Target()); + RegisterTargetMachine C(getThePPC64LETarget()); PassRegistry &PR = *PassRegistry::getPassRegistry(); initializePPCBoolRetToIntPass(PR); Index: lib/Target/PowerPC/TargetInfo/PowerPCTargetInfo.cpp =================================================================== --- lib/Target/PowerPC/TargetInfo/PowerPCTargetInfo.cpp +++ lib/Target/PowerPC/TargetInfo/PowerPCTargetInfo.cpp @@ -12,15 +12,26 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::ThePPC32Target, llvm::ThePPC64Target, llvm::ThePPC64LETarget; +Target &llvm::getThePPC32Target() { + static Target ThePPC32Target; + return ThePPC32Target; +} +Target &llvm::getThePPC64Target() { + static Target ThePPC64Target; + return ThePPC64Target; +} +Target &llvm::getThePPC64LETarget() { + static Target ThePPC64LETarget; + return ThePPC64LETarget; +} extern "C" void LLVMInitializePowerPCTargetInfo() { - RegisterTarget - X(ThePPC32Target, "ppc32", "PowerPC 32"); + RegisterTarget X(getThePPC32Target(), "ppc32", + "PowerPC 32"); - RegisterTarget - Y(ThePPC64Target, "ppc64", "PowerPC 64"); + RegisterTarget Y(getThePPC64Target(), "ppc64", + "PowerPC 64"); - RegisterTarget - Z(ThePPC64LETarget, "ppc64le", "PowerPC 64 LE"); + RegisterTarget Z( + getThePPC64LETarget(), "ppc64le", "PowerPC 64 LE"); } Index: lib/Target/Sparc/AsmParser/SparcAsmParser.cpp =================================================================== --- lib/Target/Sparc/AsmParser/SparcAsmParser.cpp +++ lib/Target/Sparc/AsmParser/SparcAsmParser.cpp @@ -1263,9 +1263,9 @@ } extern "C" void LLVMInitializeSparcAsmParser() { - RegisterMCAsmParser A(TheSparcTarget); - RegisterMCAsmParser B(TheSparcV9Target); - RegisterMCAsmParser C(TheSparcelTarget); + RegisterMCAsmParser A(getTheSparcTarget()); + RegisterMCAsmParser B(getTheSparcV9Target()); + RegisterMCAsmParser C(getTheSparcelTarget()); } #define GET_REGISTER_MATCHER Index: lib/Target/Sparc/Disassembler/SparcDisassembler.cpp =================================================================== --- lib/Target/Sparc/Disassembler/SparcDisassembler.cpp +++ lib/Target/Sparc/Disassembler/SparcDisassembler.cpp @@ -44,7 +44,9 @@ } namespace llvm { -extern Target TheSparcTarget, TheSparcV9Target, TheSparcelTarget; +Target &getTheSparcTarget(); +Target &getTheSparcV9Target(); +Target &getTheSparcelTarget(); } static MCDisassembler *createSparcDisassembler(const Target &T, @@ -56,11 +58,11 @@ extern "C" void LLVMInitializeSparcDisassembler() { // Register the disassembler. - TargetRegistry::RegisterMCDisassembler(TheSparcTarget, + TargetRegistry::RegisterMCDisassembler(getTheSparcTarget(), createSparcDisassembler); - TargetRegistry::RegisterMCDisassembler(TheSparcV9Target, + TargetRegistry::RegisterMCDisassembler(getTheSparcV9Target(), createSparcDisassembler); - TargetRegistry::RegisterMCDisassembler(TheSparcelTarget, + TargetRegistry::RegisterMCDisassembler(getTheSparcelTarget(), createSparcDisassembler); } Index: lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.h =================================================================== --- lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.h +++ lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.h @@ -31,9 +31,9 @@ class raw_pwrite_stream; class raw_ostream; -extern Target TheSparcTarget; -extern Target TheSparcV9Target; -extern Target TheSparcelTarget; +Target &getTheSparcTarget(); +Target &getTheSparcV9Target(); +Target &getTheSparcelTarget(); MCCodeEmitter *createSparcMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, Index: lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp =================================================================== --- lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp +++ lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp @@ -128,11 +128,12 @@ extern "C" void LLVMInitializeSparcTargetMC() { // Register the MC asm info. - RegisterMCAsmInfoFn X(TheSparcTarget, createSparcMCAsmInfo); - RegisterMCAsmInfoFn Y(TheSparcV9Target, createSparcV9MCAsmInfo); - RegisterMCAsmInfoFn Z(TheSparcelTarget, createSparcMCAsmInfo); + RegisterMCAsmInfoFn X(getTheSparcTarget(), createSparcMCAsmInfo); + RegisterMCAsmInfoFn Y(getTheSparcV9Target(), createSparcV9MCAsmInfo); + RegisterMCAsmInfoFn Z(getTheSparcelTarget(), createSparcMCAsmInfo); - for (Target *T : {&TheSparcTarget, &TheSparcV9Target, &TheSparcelTarget}) { + for (Target *T : + {&getTheSparcTarget(), &getTheSparcV9Target(), &getTheSparcelTarget()}) { // Register the MC instruction info. TargetRegistry::RegisterMCInstrInfo(*T, createSparcMCInstrInfo); @@ -160,10 +161,10 @@ } // Register the MC codegen info. - TargetRegistry::registerMCAdjustCodeGenOpts(TheSparcTarget, + TargetRegistry::registerMCAdjustCodeGenOpts(getTheSparcTarget(), adjustCodeGenOpts); - TargetRegistry::registerMCAdjustCodeGenOpts(TheSparcV9Target, + TargetRegistry::registerMCAdjustCodeGenOpts(getTheSparcV9Target(), adjustCodeGenOptsV9); - TargetRegistry::registerMCAdjustCodeGenOpts(TheSparcelTarget, + TargetRegistry::registerMCAdjustCodeGenOpts(getTheSparcelTarget(), adjustCodeGenOpts); } Index: lib/Target/Sparc/SparcAsmPrinter.cpp =================================================================== --- lib/Target/Sparc/SparcAsmPrinter.cpp +++ lib/Target/Sparc/SparcAsmPrinter.cpp @@ -443,7 +443,7 @@ // Force static initialization. extern "C" void LLVMInitializeSparcAsmPrinter() { - RegisterAsmPrinter X(TheSparcTarget); - RegisterAsmPrinter Y(TheSparcV9Target); - RegisterAsmPrinter Z(TheSparcelTarget); + RegisterAsmPrinter X(getTheSparcTarget()); + RegisterAsmPrinter Y(getTheSparcV9Target()); + RegisterAsmPrinter Z(getTheSparcelTarget()); } Index: lib/Target/Sparc/SparcTargetMachine.cpp =================================================================== --- lib/Target/Sparc/SparcTargetMachine.cpp +++ lib/Target/Sparc/SparcTargetMachine.cpp @@ -22,9 +22,9 @@ extern "C" void LLVMInitializeSparcTarget() { // Register the target. - RegisterTargetMachine X(TheSparcTarget); - RegisterTargetMachine Y(TheSparcV9Target); - RegisterTargetMachine Z(TheSparcelTarget); + RegisterTargetMachine X(getTheSparcTarget()); + RegisterTargetMachine Y(getTheSparcV9Target()); + RegisterTargetMachine Z(getTheSparcelTarget()); } static std::string computeDataLayout(const Triple &T, bool is64Bit) { Index: lib/Target/Sparc/TargetInfo/SparcTargetInfo.cpp =================================================================== --- lib/Target/Sparc/TargetInfo/SparcTargetInfo.cpp +++ lib/Target/Sparc/TargetInfo/SparcTargetInfo.cpp @@ -12,15 +12,24 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::TheSparcTarget; -Target llvm::TheSparcV9Target; -Target llvm::TheSparcelTarget; +Target &llvm::getTheSparcTarget() { + static Target TheSparcTarget; + return TheSparcTarget; +} +Target &llvm::getTheSparcV9Target() { + static Target TheSparcV9Target; + return TheSparcV9Target; +} +Target &llvm::getTheSparcelTarget() { + static Target TheSparcelTarget; + return TheSparcelTarget; +} extern "C" void LLVMInitializeSparcTargetInfo() { - RegisterTarget X(TheSparcTarget, "sparc", + RegisterTarget X(getTheSparcTarget(), "sparc", "Sparc"); - RegisterTarget Y(TheSparcV9Target, + RegisterTarget Y(getTheSparcV9Target(), "sparcv9", "Sparc V9"); - RegisterTarget Z(TheSparcelTarget, + RegisterTarget Z(getTheSparcelTarget(), "sparcel", "Sparc LE"); } Index: lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp =================================================================== --- lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp +++ lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp @@ -1171,5 +1171,5 @@ // Force static initialization. extern "C" void LLVMInitializeSystemZAsmParser() { - RegisterMCAsmParser X(TheSystemZTarget); + RegisterMCAsmParser X(getTheSystemZTarget()); } Index: lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp =================================================================== --- lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp +++ lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp @@ -42,7 +42,7 @@ extern "C" void LLVMInitializeSystemZDisassembler() { // Register the disassembler. - TargetRegistry::RegisterMCDisassembler(TheSystemZTarget, + TargetRegistry::RegisterMCDisassembler(getTheSystemZTarget(), createSystemZDisassembler); } Index: lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.h =================================================================== --- lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.h +++ lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.h @@ -28,7 +28,7 @@ class raw_pwrite_stream; class raw_ostream; -extern Target TheSystemZTarget; +Target &getTheSystemZTarget(); namespace SystemZMC { // How many bytes are in the ABI-defined, caller-allocated part of Index: lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp =================================================================== --- lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp +++ lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp @@ -205,34 +205,34 @@ extern "C" void LLVMInitializeSystemZTargetMC() { // Register the MCAsmInfo. - TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget, + TargetRegistry::RegisterMCAsmInfo(getTheSystemZTarget(), createSystemZMCAsmInfo); // Register the adjustCodeGenOpts. - TargetRegistry::registerMCAdjustCodeGenOpts(TheSystemZTarget, + TargetRegistry::registerMCAdjustCodeGenOpts(getTheSystemZTarget(), adjustCodeGenOpts); // Register the MCCodeEmitter. - TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget, + TargetRegistry::RegisterMCCodeEmitter(getTheSystemZTarget(), createSystemZMCCodeEmitter); // Register the MCInstrInfo. - TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget, + TargetRegistry::RegisterMCInstrInfo(getTheSystemZTarget(), createSystemZMCInstrInfo); // Register the MCRegisterInfo. - TargetRegistry::RegisterMCRegInfo(TheSystemZTarget, + TargetRegistry::RegisterMCRegInfo(getTheSystemZTarget(), createSystemZMCRegisterInfo); // Register the MCSubtargetInfo. - TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget, + TargetRegistry::RegisterMCSubtargetInfo(getTheSystemZTarget(), createSystemZMCSubtargetInfo); // Register the MCAsmBackend. - TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget, + TargetRegistry::RegisterMCAsmBackend(getTheSystemZTarget(), createSystemZMCAsmBackend); // Register the MCInstPrinter. - TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget, + TargetRegistry::RegisterMCInstPrinter(getTheSystemZTarget(), createSystemZMCInstPrinter); } Index: lib/Target/SystemZ/SystemZAsmPrinter.cpp =================================================================== --- lib/Target/SystemZ/SystemZAsmPrinter.cpp +++ lib/Target/SystemZ/SystemZAsmPrinter.cpp @@ -523,5 +523,5 @@ // Force static initialization. extern "C" void LLVMInitializeSystemZAsmPrinter() { - RegisterAsmPrinter X(TheSystemZTarget); + RegisterAsmPrinter X(getTheSystemZTarget()); } Index: lib/Target/SystemZ/SystemZTargetMachine.cpp =================================================================== --- lib/Target/SystemZ/SystemZTargetMachine.cpp +++ lib/Target/SystemZ/SystemZTargetMachine.cpp @@ -20,7 +20,7 @@ extern cl::opt MISchedPostRA; extern "C" void LLVMInitializeSystemZTarget() { // Register the target. - RegisterTargetMachine X(TheSystemZTarget); + RegisterTargetMachine X(getTheSystemZTarget()); } // Determine whether we use the vector ABI. Index: lib/Target/SystemZ/TargetInfo/SystemZTargetInfo.cpp =================================================================== --- lib/Target/SystemZ/TargetInfo/SystemZTargetInfo.cpp +++ lib/Target/SystemZ/TargetInfo/SystemZTargetInfo.cpp @@ -12,9 +12,12 @@ using namespace llvm; -Target llvm::TheSystemZTarget; +Target &llvm::getTheSystemZTarget() { + static Target TheSystemZTarget; + return TheSystemZTarget; +} extern "C" void LLVMInitializeSystemZTargetInfo() { - RegisterTarget - X(TheSystemZTarget, "systemz", "SystemZ"); + RegisterTarget X(getTheSystemZTarget(), + "systemz", "SystemZ"); } Index: lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp =================================================================== --- lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp +++ lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp @@ -54,9 +54,9 @@ extern "C" void LLVMInitializeWebAssemblyDisassembler() { // Register the disassembler for each target. - TargetRegistry::RegisterMCDisassembler(TheWebAssemblyTarget32, + TargetRegistry::RegisterMCDisassembler(getTheWebAssemblyTarget32(), createWebAssemblyDisassembler); - TargetRegistry::RegisterMCDisassembler(TheWebAssemblyTarget64, + TargetRegistry::RegisterMCDisassembler(getTheWebAssemblyTarget64(), createWebAssemblyDisassembler); } Index: lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h =================================================================== --- lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -30,8 +30,8 @@ class Triple; class raw_pwrite_stream; -extern Target TheWebAssemblyTarget32; -extern Target TheWebAssemblyTarget64; +Target &getTheWebAssemblyTarget32(); +Target &getTheWebAssemblyTarget64(); MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII); Index: lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp =================================================================== --- lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp +++ lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp @@ -101,7 +101,8 @@ // Force static initialization. extern "C" void LLVMInitializeWebAssemblyTargetMC() { - for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) { + for (Target *T : + {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) { // Register the MC asm info. RegisterMCAsmInfoFn X(*T, createMCAsmInfo); Index: lib/Target/WebAssembly/TargetInfo/WebAssemblyTargetInfo.cpp =================================================================== --- lib/Target/WebAssembly/TargetInfo/WebAssemblyTargetInfo.cpp +++ lib/Target/WebAssembly/TargetInfo/WebAssemblyTargetInfo.cpp @@ -19,12 +19,12 @@ #define DEBUG_TYPE "wasm-target-info" -Target llvm::TheWebAssemblyTarget32; -Target llvm::TheWebAssemblyTarget64; +Target llvm::getTheWebAssemblyTarget32(); +Target llvm::getTheWebAssemblyTarget64(); extern "C" void LLVMInitializeWebAssemblyTargetInfo() { - RegisterTarget X(TheWebAssemblyTarget32, "wasm32", + RegisterTarget X(getTheWebAssemblyTarget32(), "wasm32", "WebAssembly 32-bit"); - RegisterTarget Y(TheWebAssemblyTarget64, "wasm64", + RegisterTarget Y(getTheWebAssemblyTarget64(), "wasm64", "WebAssembly 64-bit"); } Index: lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -313,6 +313,6 @@ // Force static initialization. extern "C" void LLVMInitializeWebAssemblyAsmPrinter() { - RegisterAsmPrinter X(TheWebAssemblyTarget32); - RegisterAsmPrinter Y(TheWebAssemblyTarget64); + RegisterAsmPrinter X(getTheWebAssemblyTarget32()); + RegisterAsmPrinter Y(getTheWebAssemblyTarget64()); } Index: lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -43,8 +43,10 @@ extern "C" void LLVMInitializeWebAssemblyTarget() { // Register the target. - RegisterTargetMachine X(TheWebAssemblyTarget32); - RegisterTargetMachine Y(TheWebAssemblyTarget64); + RegisterTargetMachine X( + getTheWebAssemblyTarget32()); + RegisterTargetMachine Y( + getTheWebAssemblyTarget64()); // Register exception handling pass to opt initializeWebAssemblyLowerEmscriptenEHSjLjPass( Index: lib/Target/X86/AsmParser/X86AsmParser.cpp =================================================================== --- lib/Target/X86/AsmParser/X86AsmParser.cpp +++ lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -3065,8 +3065,8 @@ // Force static initialization. extern "C" void LLVMInitializeX86AsmParser() { - RegisterMCAsmParser X(TheX86_32Target); - RegisterMCAsmParser Y(TheX86_64Target); + RegisterMCAsmParser X(getTheX86_32Target()); + RegisterMCAsmParser Y(getTheX86_64Target()); } #define GET_REGISTER_MATCHER Index: lib/Target/X86/Disassembler/X86Disassembler.cpp =================================================================== --- lib/Target/X86/Disassembler/X86Disassembler.cpp +++ lib/Target/X86/Disassembler/X86Disassembler.cpp @@ -1066,8 +1066,8 @@ extern "C" void LLVMInitializeX86Disassembler() { // Register the disassembler. - TargetRegistry::RegisterMCDisassembler(TheX86_32Target, + TargetRegistry::RegisterMCDisassembler(getTheX86_32Target(), createX86Disassembler); - TargetRegistry::RegisterMCDisassembler(TheX86_64Target, + TargetRegistry::RegisterMCDisassembler(getTheX86_64Target(), createX86Disassembler); } Index: lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h =================================================================== --- lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h +++ lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h @@ -34,7 +34,8 @@ class raw_ostream; class raw_pwrite_stream; -extern Target TheX86_32Target, TheX86_64Target; +Target &getTheX86_32Target(); +Target &getTheX86_64Target(); /// Flavour of dwarf regnumbers /// Index: lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp =================================================================== --- lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -234,7 +234,7 @@ // Force static initialization. extern "C" void LLVMInitializeX86TargetMC() { - for (Target *T : {&TheX86_32Target, &TheX86_64Target}) { + for (Target *T : {&getTheX86_32Target(), &getTheX86_64Target()}) { // Register the MC asm info. RegisterMCAsmInfoFn X(*T, createX86MCAsmInfo); @@ -268,9 +268,9 @@ } // Register the asm backend. - TargetRegistry::RegisterMCAsmBackend(TheX86_32Target, + TargetRegistry::RegisterMCAsmBackend(getTheX86_32Target(), createX86_32AsmBackend); - TargetRegistry::RegisterMCAsmBackend(TheX86_64Target, + TargetRegistry::RegisterMCAsmBackend(getTheX86_64Target(), createX86_64AsmBackend); } Index: lib/Target/X86/TargetInfo/X86TargetInfo.cpp =================================================================== --- lib/Target/X86/TargetInfo/X86TargetInfo.cpp +++ lib/Target/X86/TargetInfo/X86TargetInfo.cpp @@ -11,12 +11,19 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -Target llvm::TheX86_32Target, llvm::TheX86_64Target; +Target &llvm::getTheX86_32Target() { + static Target TheX86_32Target; + return TheX86_32Target; +} +Target &llvm::getTheX86_64Target() { + static Target TheX86_64Target; + return TheX86_64Target; +} extern "C" void LLVMInitializeX86TargetInfo() { - RegisterTarget - X(TheX86_32Target, "x86", "32-bit X86: Pentium-Pro and above"); + RegisterTarget X( + getTheX86_32Target(), "x86", "32-bit X86: Pentium-Pro and above"); - RegisterTarget - Y(TheX86_64Target, "x86-64", "64-bit X86: EM64T and AMD64"); + RegisterTarget Y( + getTheX86_64Target(), "x86-64", "64-bit X86: EM64T and AMD64"); } Index: lib/Target/X86/X86AsmPrinter.cpp =================================================================== --- lib/Target/X86/X86AsmPrinter.cpp +++ lib/Target/X86/X86AsmPrinter.cpp @@ -656,6 +656,6 @@ // Force static initialization. extern "C" void LLVMInitializeX86AsmPrinter() { - RegisterAsmPrinter X(TheX86_32Target); - RegisterAsmPrinter Y(TheX86_64Target); + RegisterAsmPrinter X(getTheX86_32Target()); + RegisterAsmPrinter Y(getTheX86_64Target()); } Index: lib/Target/X86/X86TargetMachine.cpp =================================================================== --- lib/Target/X86/X86TargetMachine.cpp +++ lib/Target/X86/X86TargetMachine.cpp @@ -35,8 +35,8 @@ extern "C" void LLVMInitializeX86Target() { // Register the target. - RegisterTargetMachine X(TheX86_32Target); - RegisterTargetMachine Y(TheX86_64Target); + RegisterTargetMachine X(getTheX86_32Target()); + RegisterTargetMachine Y(getTheX86_64Target()); PassRegistry &PR = *PassRegistry::getPassRegistry(); initializeWinEHStatePassPass(PR);