Change TargetAsmInfo to be constructed via TargetRegistry from a Target+Triple
authorChris Lattner <sabre@nondot.org>
Wed, 12 Aug 2009 07:22:17 +0000 (07:22 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 12 Aug 2009 07:22:17 +0000 (07:22 +0000)
pair instead of from a virtual method on TargetMachine.  This cuts the final
ties of TargetAsmInfo to TargetMachine, meaning that MC can now use
TargetAsmInfo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78802 91177308-0d34-0410-b5e6-96231b3b80d8

50 files changed:
include/llvm/Target/TargetMachine.h
include/llvm/Target/TargetRegistry.h
lib/CodeGen/LLVMTargetMachine.cpp
lib/Target/ARM/ARMTargetMachine.cpp
lib/Target/ARM/ARMTargetMachine.h
lib/Target/Alpha/AlphaTargetAsmInfo.cpp
lib/Target/Alpha/AlphaTargetAsmInfo.h
lib/Target/Alpha/AlphaTargetMachine.cpp
lib/Target/Alpha/AlphaTargetMachine.h
lib/Target/Blackfin/BlackfinTargetAsmInfo.cpp
lib/Target/Blackfin/BlackfinTargetAsmInfo.h
lib/Target/Blackfin/BlackfinTargetMachine.cpp
lib/Target/Blackfin/BlackfinTargetMachine.h
lib/Target/CellSPU/SPUTargetAsmInfo.cpp
lib/Target/CellSPU/SPUTargetAsmInfo.h
lib/Target/CellSPU/SPUTargetMachine.cpp
lib/Target/CellSPU/SPUTargetMachine.h
lib/Target/MSP430/MSP430AsmPrinter.cpp
lib/Target/MSP430/MSP430TargetAsmInfo.cpp
lib/Target/MSP430/MSP430TargetAsmInfo.h
lib/Target/MSP430/MSP430TargetMachine.cpp
lib/Target/MSP430/MSP430TargetMachine.h
lib/Target/Mips/MipsTargetAsmInfo.cpp
lib/Target/Mips/MipsTargetAsmInfo.h
lib/Target/Mips/MipsTargetMachine.cpp
lib/Target/Mips/MipsTargetMachine.h
lib/Target/PIC16/PIC16AsmPrinter.cpp
lib/Target/PIC16/PIC16TargetAsmInfo.cpp
lib/Target/PIC16/PIC16TargetAsmInfo.h
lib/Target/PIC16/PIC16TargetMachine.cpp
lib/Target/PIC16/PIC16TargetMachine.h
lib/Target/PowerPC/PPCTargetMachine.cpp
lib/Target/PowerPC/PPCTargetMachine.h
lib/Target/Sparc/SparcTargetAsmInfo.cpp
lib/Target/Sparc/SparcTargetAsmInfo.h
lib/Target/Sparc/SparcTargetMachine.cpp
lib/Target/Sparc/SparcTargetMachine.h
lib/Target/SystemZ/SystemZTargetAsmInfo.cpp
lib/Target/SystemZ/SystemZTargetAsmInfo.h
lib/Target/SystemZ/SystemZTargetMachine.cpp
lib/Target/SystemZ/SystemZTargetMachine.h
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.h
lib/Target/X86/X86TargetMachine.cpp
lib/Target/X86/X86TargetMachine.h
lib/Target/XCore/XCoreAsmPrinter.cpp
lib/Target/XCore/XCoreTargetAsmInfo.cpp
lib/Target/XCore/XCoreTargetAsmInfo.h
lib/Target/XCore/XCoreTargetMachine.cpp
lib/Target/XCore/XCoreTargetMachine.h

index 5328a49234e64ad91fa474fc409f126000eaec3e..e5ea27fb087eab492a17c4a83ec114b34292724d 100644 (file)
@@ -102,12 +102,8 @@ protected: // Can only create subclasses.
   
   /// AsmInfo - Contains target specific asm information.
   ///
-  mutable const TargetAsmInfo *AsmInfo;
+  const TargetAsmInfo *AsmInfo;
   
-  /// createTargetAsmInfo - Create a new instance of target specific asm
-  /// information.
-  virtual const TargetAsmInfo *createTargetAsmInfo() const { return 0; }
-
 public:
   virtual ~TargetMachine();
 
@@ -126,10 +122,7 @@ public:
   
   /// getTargetAsmInfo - Return target specific asm information.
   ///
-  const TargetAsmInfo *getTargetAsmInfo() const {
-    if (!AsmInfo) AsmInfo = createTargetAsmInfo();
-    return AsmInfo;
-  }
+  const TargetAsmInfo *getTargetAsmInfo() const { return AsmInfo; }
   
   /// getSubtarget - This method returns a pointer to the specified type of
   /// TargetSubtarget.  In debug builds, it verifies that the object being
@@ -291,9 +284,8 @@ public:
 ///
 class LLVMTargetMachine : public TargetMachine {
 protected: // Can only create subclasses.
-  LLVMTargetMachine(const Target &T, const std::string &TargetTriple)
-    : TargetMachine(T) { }
-
+  LLVMTargetMachine(const Target &T, const std::string &TargetTriple);
+  
   /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
   /// both emitting to assembly files or machine code output.
   ///
index ea95222d3aaad01f2dd5fec0c8da21e430b7e9ad..87be7f39e5f77a5e9a10f9ee7b053d933d564e04 100644 (file)
@@ -43,20 +43,22 @@ namespace llvm {
   /// will be zero initialized), and pass that instance to the TargetRegistry as
   /// part of their initialization.
   class Target {
-  private:
+  public:
+    friend struct TargetRegistry;
+
     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
 
-    typedef TargetMachine *(*TargetMachineCtorTy)(const Target &,
-                                                  const std::string &,
-                                                  const std::string &);
+    typedef const TargetAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
+                                                    const StringRef &TT);
+    typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
+                                                  const std::string &TT,
+                                                  const std::string &Features);
     typedef FunctionPass *(*AsmPrinterCtorTy)(formatted_raw_ostream &,
                                               TargetMachine &,
                                               bool);
     typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &,
                                                 MCAsmParser &);
-
-    friend struct TargetRegistry;
-
+  private:
     /// Next - The next registered target in the linked list, maintained by the
     /// TargetRegistry.
     Target *Next;
@@ -74,6 +76,8 @@ namespace llvm {
     /// HasJIT - Whether this target supports the JIT.
     bool HasJIT;
 
+    AsmInfoCtorFnTy AsmInfoCtorFn;
+    
     /// TargetMachineCtorFn - Construction function for this target's
     /// TargetMachine, if registered.
     TargetMachineCtorTy TargetMachineCtorFn;
@@ -107,11 +111,23 @@ namespace llvm {
     /// hasAsmParser - Check if this target supports .s parsing.
     bool hasAsmParser() const { return AsmParserCtorFn != 0; }
 
+    
+    /// createAsmInfo - Create a TargetAsmInfo implementation for the specified
+    /// target triple.
+    ///
+    /// \arg Triple - This argument is used to determine the target machine
+    /// feature set; it should always be provided. Generally this should be
+    /// either the target triple from the module, or the target triple of the
+    /// host if that does not exist.
+    const TargetAsmInfo *createAsmInfo(const StringRef &Triple) const {
+      if (!AsmInfoCtorFn)
+        return 0;
+      return AsmInfoCtorFn(*this, Triple);
+    }
+    
     /// createTargetMachine - Create a target specific machine implementation
-    /// for the module \arg M and \arg Triple.
+    /// for the specified \arg Triple.
     ///
-    /// \arg M - This argument is used for some machines to access the target
-    /// data.
     /// \arg Triple - This argument is used to determine the target machine
     /// feature set; it should always be provided. Generally this should be
     /// either the target triple from the module, or the target triple of the
@@ -228,7 +244,22 @@ namespace llvm {
                                const char *ShortDesc,
                                Target::TripleMatchQualityFnTy TQualityFn,
                                bool HasJIT = false);
-                               
+
+    /// RegisterAsmInfo - Register a TargetAsmInfo implementation for the
+    /// given target.
+    /// 
+    /// Clients are responsible for ensuring that registration doesn't occur
+    /// while another thread is attempting to access the registry. Typically
+    /// this is done by initializing all targets at program startup.
+    /// 
+    /// @param T - The target being registered.
+    /// @param Fn - A function to construct a TargetAsmInfo for the target.
+    static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
+      // Ignore duplicate registration.
+      if (!T.AsmInfoCtorFn)
+        T.AsmInfoCtorFn = Fn;
+    }
+    
     /// RegisterTargetMachine - Register a TargetMachine implementation for the
     /// given target.
     /// 
@@ -305,6 +336,41 @@ namespace llvm {
     }
   };
 
+  /// RegisterAsmInfo - Helper template for registering a target assembly info
+  /// implementation.  This invokes the static "Create" method on the class to
+  /// actually do the construction.  Usage:
+  ///
+  /// extern "C" void LLVMInitializeFooTarget() {
+  ///   extern Target TheFooTarget;
+  ///   RegisterAsmInfo<FooTargetAsmInfo> X(TheFooTarget);
+  /// }
+  template<class TargetAsmInfoImpl>
+  struct RegisterAsmInfo {
+    RegisterAsmInfo(Target &T) {
+      TargetRegistry::RegisterAsmInfo(T, &Allocator);
+    }
+  private:
+    static const TargetAsmInfo *Allocator(const Target &T, const StringRef &TT){
+      return new TargetAsmInfoImpl(T, TT);
+    }
+    
+  };
+
+  /// RegisterAsmInfoFn - Helper template for registering a target assembly info
+  /// implementation.  This invokes the specified function to do the
+  /// construction.  Usage:
+  ///
+  /// extern "C" void LLVMInitializeFooTarget() {
+  ///   extern Target TheFooTarget;
+  ///   RegisterAsmInfoFn X(TheFooTarget, TheFunction);
+  /// }
+  struct RegisterAsmInfoFn {
+    RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
+      TargetRegistry::RegisterAsmInfo(T, Fn);
+    }
+  };
+
+
   /// RegisterTargetMachine - Helper template for registering a target machine
   /// implementation, for use in the target machine initialization
   /// function. Usage:
index 6a456dc0e6c28c0cc9896630f39d0b77655e291b..71efa1375ee34e61e2aefe8158d74ebed103efd0 100644 (file)
@@ -55,6 +55,15 @@ static cl::opt<cl::boolOrDefault>
 EnableFastISelOption("fast-isel", cl::Hidden,
   cl::desc("Enable the experimental \"fast\" instruction selector"));
 
+
+LLVMTargetMachine::LLVMTargetMachine(const Target &T,
+                                     const std::string &TargetTriple)
+  : TargetMachine(T) {
+  AsmInfo = T.createAsmInfo(TargetTriple);
+}
+
+
+
 FileModel::Model
 LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
                                        formatted_raw_ostream &Out,
index c66570b2e3cbd4bbee5d8282c17d3d577f3cae06..fbc5f38efea074308bb5284c496f38d53065ea00 100644 (file)
@@ -27,10 +27,26 @@ static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
 static cl::opt<bool> DisableIfConversion("disable-arm-if-conversion",cl::Hidden,
                               cl::desc("Disable if-conversion pass"));
 
+static const TargetAsmInfo *createTargetAsmInfo(const Target &T,
+                                                const StringRef &TT) {
+  Triple TheTriple(TT);
+  switch (TheTriple.getOS()) {
+  case Triple::Darwin:
+    return new ARMDarwinTargetAsmInfo();
+  default:
+    return new ARMELFTargetAsmInfo();
+  }
+}
+
+
 extern "C" void LLVMInitializeARMTarget() {
   // Register the target.
   RegisterTargetMachine<ARMTargetMachine> X(TheARMTarget);
   RegisterTargetMachine<ThumbTargetMachine> Y(TheThumbTarget);
+  
+  // Register the target asm info.
+  RegisterAsmInfoFn A(TheARMTarget, createTargetAsmInfo);
+  RegisterAsmInfoFn B(TheThumbTarget, createTargetAsmInfo);
 }
 
 /// TargetMachine ctor - Create an ARM architecture model.
@@ -73,16 +89,6 @@ ThumbTargetMachine::ThumbTargetMachine(const Target &T, const std::string &TT,
 }
 
 
-const TargetAsmInfo *ARMBaseTargetMachine::createTargetAsmInfo() const {
-  switch (Subtarget.TargetType) {
-  default: llvm_unreachable("Unknown ARM subtarget kind");
-  case ARMSubtarget::isDarwin:
-    return new ARMDarwinTargetAsmInfo();
-  case ARMSubtarget::isELF:
-    return new ARMELFTargetAsmInfo();
-  }
-}
-
 
 // Pass Pipeline Configuration
 bool ARMBaseTargetMachine::addInstSelector(PassManagerBase &PM,
index d992f08f2f00fa982fe8883ce4b0b973342d7771..420305500f445ebd4df057761f0af8d169e85196 100644 (file)
@@ -47,8 +47,6 @@ public:
     return InstrItins;
   }
 
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
   // Pass Pipeline Configuration
   virtual bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
   virtual bool addPreRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
index 20be50eff957cc1742bfb717cd38e201254fe8d1..ebb89ecf52628fa791bcd49b79633f530cb0acb5 100644 (file)
@@ -14,7 +14,7 @@
 #include "AlphaTargetAsmInfo.h"
 using namespace llvm;
 
-AlphaTargetAsmInfo::AlphaTargetAsmInfo() {
+AlphaTargetAsmInfo::AlphaTargetAsmInfo(const Target &T, const StringRef &TT) {
   AlignmentIsInBytes = false;
   PrivateGlobalPrefix = "$";
   PICJumpTableDirective = ".gprel32";
index 1f0259b22c409e9fed2513beb15cc7a891813597..20903c730f27e0d4fac42e98107548c1109bd88a 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class Target;
+  class StringRef;
 
   struct AlphaTargetAsmInfo : public TargetAsmInfo {
-    explicit AlphaTargetAsmInfo();
+    explicit AlphaTargetAsmInfo(const Target &T, const StringRef &TT);
   };
 
 } // namespace llvm
index bb140dca9232fbca7ac709c0da60ad6c855e9ebf..19218704a6f113e2d8c38ae0628d87deecf4a6d4 100644 (file)
 #include "llvm/PassManager.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Target/TargetRegistry.h"
-
 using namespace llvm;
 
 extern "C" void LLVMInitializeAlphaTarget() { 
   // Register the target.
   RegisterTargetMachine<AlphaTargetMachine> X(TheAlphaTarget);
-}
-
-const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
-  return new AlphaTargetAsmInfo();
+  RegisterAsmInfo<AlphaTargetAsmInfo> Y(TheAlphaTarget);
 }
 
 AlphaTargetMachine::AlphaTargetMachine(const Target &T, const std::string &TT,
index fc6439345ab6c4a71c34af4698fa12ab62894db2..f03e9388f7def7e2f53c185ce6116dc0b447636d 100644 (file)
@@ -34,9 +34,6 @@ class AlphaTargetMachine : public LLVMTargetMachine {
   AlphaSubtarget Subtarget;
   AlphaTargetLowering TLInfo;
 
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   AlphaTargetMachine(const Target &T, const std::string &TT,
                      const std::string &FS);
index 3ab02d8c51f5cdb67f9e7b764610cca2163cfeae..21087453efe48e35941381a51c109c447110e111 100644 (file)
@@ -15,7 +15,8 @@
 
 using namespace llvm;
 
-BlackfinTargetAsmInfo::BlackfinTargetAsmInfo() {
+BlackfinTargetAsmInfo::BlackfinTargetAsmInfo(const Target &T,
+                                             const StringRef &TT) {
   GlobalPrefix = "_";
   CommentString = "//";
 }
index fa4cd7c373ad12550aa0e9ef36c4f850e50a8f40..8040f0fb21286953c124c0cd6a51c4d4acb57325 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class Target;
+  class StringRef;
 
   struct BlackfinTargetAsmInfo : public TargetAsmInfo {
-    explicit BlackfinTargetAsmInfo();
+    explicit BlackfinTargetAsmInfo(const Target &T, const StringRef &TT);
   };
 
 } // namespace llvm
index 35dba2568d85bce406b99e0fc352ac8d218917ac..4309a9be4d01eb1c7f766c2bd82b1d73ac91d02c 100644 (file)
@@ -20,10 +20,8 @@ using namespace llvm;
 
 extern "C" void LLVMInitializeBlackfinTarget() {
   RegisterTargetMachine<BlackfinTargetMachine> X(TheBlackfinTarget);
-}
+  RegisterAsmInfo<BlackfinTargetAsmInfo> Y(TheBlackfinTarget);
 
-const TargetAsmInfo* BlackfinTargetMachine::createTargetAsmInfo() const {
-  return new BlackfinTargetAsmInfo();
 }
 
 BlackfinTargetMachine::BlackfinTargetMachine(const Target &T,
index 13a8a631f3cbbfdb9ef773eb998a2f0fe7faa5b8..73ed3143f5309cf81d6699e22928b8421d62cb7e 100644 (file)
@@ -29,10 +29,6 @@ namespace llvm {
     BlackfinTargetLowering TLInfo;
     BlackfinInstrInfo InstrInfo;
     TargetFrameInfo FrameInfo;
-
-  protected:
-    virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
   public:
     BlackfinTargetMachine(const Target &T, const std::string &TT,
                           const std::string &FS);
index a295a4c29df75739f937bfa5a81168369574dc42..4ae852df995d1a21643223ce19fc271321de0f53 100644 (file)
@@ -14,7 +14,7 @@
 #include "SPUTargetAsmInfo.h"
 using namespace llvm;
 
-SPULinuxTargetAsmInfo::SPULinuxTargetAsmInfo() {
+SPULinuxTargetAsmInfo::SPULinuxTargetAsmInfo(const Target &T, const StringRef &TT) {
   ZeroDirective = "\t.space\t";
   SetDirective = "\t.set";
   Data64bitsDirective = "\t.quad\t";
index 9507ff9e59ea35e518c2a9c6c7cd6387dc2869d5..b3c6bdaefd8b16217396e56992cb05f0f6d66780 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
-
+  class Target;
+  class StringRef;
+  
   struct SPULinuxTargetAsmInfo : public TargetAsmInfo {
-    explicit SPULinuxTargetAsmInfo();
+    explicit SPULinuxTargetAsmInfo(const Target &T, const StringRef &TT);
   };
 } // namespace llvm
 
index 85dda310d28896d40b2240bac5cf7df5adbb82fb..b904b9559d00b5594fb8c82733dc52362e1129a3 100644 (file)
@@ -25,6 +25,7 @@ using namespace llvm;
 extern "C" void LLVMInitializeCellSPUTarget() { 
   // Register the target.
   RegisterTargetMachine<SPUTargetMachine> X(TheCellSPUTarget);
+  RegisterAsmInfo<SPULinuxTargetAsmInfo> Y(TheCellSPUTarget);
 }
 
 const std::pair<unsigned, int> *
@@ -33,10 +34,6 @@ SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
   return &LR[0];
 }
 
-const TargetAsmInfo *SPUTargetMachine::createTargetAsmInfo() const {
-  return new SPULinuxTargetAsmInfo();
-}
-
 SPUTargetMachine::SPUTargetMachine(const Target &T, const std::string &TT,
                                    const std::string &FS)
   : LLVMTargetMachine(T, TT),
index a0e71307493fcfdf4318ab9d9bab68726e940568..9fdcfe9ab619b9f2de85aef5852281f4a32dfb62 100644 (file)
@@ -35,10 +35,6 @@ class SPUTargetMachine : public LLVMTargetMachine {
   SPUFrameInfo        FrameInfo;
   SPUTargetLowering   TLInfo;
   InstrItineraryData  InstrItins;
-
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   SPUTargetMachine(const Target &T, const std::string &TT,
                    const std::string &FS);
index 6209fc4c0a155e29c6bc3a8ae0723c192c572e71..fd8c7d1715ee51ad399466f280f67fd7d8069f2c 100644 (file)
@@ -15,6 +15,7 @@
 #define DEBUG_TYPE "asm-printer"
 #include "MSP430.h"
 #include "MSP430InstrInfo.h"
+#include "MSP430TargetAsmInfo.h"
 #include "MSP430TargetMachine.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -25,7 +26,6 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetRegistry.h"
@@ -246,4 +246,5 @@ extern "C" void LLVMInitializeMSP430Target() {
   // Register the target.
   RegisterTargetMachine<MSP430TargetMachine> X(TheMSP430Target);
   RegisterAsmPrinter<MSP430AsmPrinter> Y(TheMSP430Target);
+  RegisterAsmInfo<MSP430TargetAsmInfo> Z(TheMSP430Target);
 }
index 1aae9f259d1fbdca1d063b8f115a28aad642e63f..56560d6c1e74db28ce73ca80c02b6e4e0a938528 100644 (file)
@@ -14,6 +14,6 @@
 #include "MSP430TargetAsmInfo.h"
 using namespace llvm;
 
-MSP430TargetAsmInfo::MSP430TargetAsmInfo() {
+MSP430TargetAsmInfo::MSP430TargetAsmInfo(const Target &T, const StringRef &TT) {
   AlignmentIsInBytes = false;
 }
index 8b4580c5313c58e0cfc383bcfbb8ebc57909902f..510e2390f80e9b66b3976111cf2b7c89f784f15d 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class Target;
+  class StringRef;
   struct MSP430TargetAsmInfo : public TargetAsmInfo {
-    explicit MSP430TargetAsmInfo();
+    explicit MSP430TargetAsmInfo(const Target &T, const StringRef &TT);
   };
 
 } // namespace llvm
index f34e3db32b9e5236f03fcff5d185ca7d8caefd89..56495e6b21b55c1305fe4869c06cf2ab6356cf81 100644 (file)
@@ -29,9 +29,6 @@ MSP430TargetMachine::MSP430TargetMachine(const Target &T,
   InstrInfo(*this), TLInfo(*this),
   FrameInfo(TargetFrameInfo::StackGrowsDown, 2, -2) { }
 
-const TargetAsmInfo *MSP430TargetMachine::createTargetAsmInfo() const {
-  return new MSP430TargetAsmInfo();
-}
 
 bool MSP430TargetMachine::addInstSelector(PassManagerBase &PM,
                                           CodeGenOpt::Level OptLevel) {
index 44cdd54239dff57553d3032fc9a2287ba8805da0..d38614018c8472da3fc2f927b9a3671f8d8c43cb 100644 (file)
@@ -37,9 +37,6 @@ class MSP430TargetMachine : public LLVMTargetMachine {
   // any MSP430 specific FrameInfo class.
   TargetFrameInfo       FrameInfo;
 
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   MSP430TargetMachine(const Target &T, const std::string &TT,
                       const std::string &FS);
index f58717264591ac1f809769f27e886ebd63b169e2..3046f33ac040dde7e76e39025aa4ba92360379c7 100644 (file)
@@ -14,7 +14,7 @@
 #include "MipsTargetAsmInfo.h"
 using namespace llvm;
 
-MipsTargetAsmInfo::MipsTargetAsmInfo() {
+MipsTargetAsmInfo::MipsTargetAsmInfo(const Target &T, const StringRef &TT) {
   AlignmentIsInBytes          = false;
   COMMDirectiveTakesAlignment = true;
   Data16bitsDirective         = "\t.half\t";
index 32e98df87b5d64e731647067e577055e79e6a555..fbb02362893c2d03372d6842cb717d28fdc556d3 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class Target;
+  class StringRef;
+  
   class MipsTargetAsmInfo : public TargetAsmInfo {
   public:
-    explicit MipsTargetAsmInfo();
+    explicit MipsTargetAsmInfo(const Target &T, const StringRef &TT);
   };
 
 } // namespace llvm
index 546c834c080856fc7de6235d932c614d007c60fe..c09b6064c3910a7399fc6b220313cc67affa15a0 100644 (file)
@@ -22,10 +22,8 @@ extern "C" void LLVMInitializeMipsTarget() {
   // Register the target.
   RegisterTargetMachine<MipsTargetMachine> X(TheMipsTarget);
   RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
-}
-
-const TargetAsmInfo *MipsTargetMachine::createTargetAsmInfo() const {
-  return new MipsTargetAsmInfo();
+  RegisterAsmInfo<MipsTargetAsmInfo> A(TheMipsTarget);
+  RegisterAsmInfo<MipsTargetAsmInfo> B(TheMipselTarget);
 }
 
 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
index 5f5de75dab3e9af2600d732ee1159c7c76c928a3..c3428be48f5920ed399f1afb68101424ba2d4466 100644 (file)
@@ -30,10 +30,6 @@ namespace llvm {
     MipsInstrInfo       InstrInfo;
     TargetFrameInfo     FrameInfo;
     MipsTargetLowering  TLInfo;
-  
-  protected:
-    virtual const TargetAsmInfo *createTargetAsmInfo() const;
-    
   public:
     MipsTargetMachine(const Target &T, const std::string &TT,
                       const std::string &FS, bool isLittle);
index 39ebfa4439905cd9cf8d01d91a56aec7391c6328..a981d83752493847c7caf1c0f520bbe6ef579942 100644 (file)
@@ -480,4 +480,7 @@ extern "C" void LLVMInitializePIC16Target() {
   RegisterTargetMachine<CooperTargetMachine> B(TheCooperTarget);
   RegisterAsmPrinter<PIC16AsmPrinter> C(ThePIC16Target);
   RegisterAsmPrinter<PIC16AsmPrinter> D(TheCooperTarget);
+
+  RegisterAsmInfo<PIC16TargetAsmInfo> E(ThePIC16Target);
+  RegisterAsmInfo<PIC16TargetAsmInfo> F(TheCooperTarget);
 }
index fdd1ae008e0a345068a1acc097a912bc9d294e6d..8b302916753c2be1234127d1e2cb0ac3784a5e99 100644 (file)
@@ -19,8 +19,7 @@
 #include "PIC16ISelLowering.h"
 using namespace llvm;
 
-PIC16TargetAsmInfo::
-PIC16TargetAsmInfo() {
+PIC16TargetAsmInfo::PIC16TargetAsmInfo(const Target &T, const StringRef &TT) {
   CommentString = ";";
   GlobalPrefix = PAN::getTagName(PAN::PREFIX_SYMBOL);
   GlobalDirective = "\tglobal\t";
index d24aa6bd620d074bf2a2eea5360b9d2a51b322df..23c5ebced63da207488da9ab9a40601f0e9e47ce 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class Target;
+  class StringRef;
+
   class PIC16TargetAsmInfo : public TargetAsmInfo {
     const char *RomData8bitsDirective;
     const char *RomData16bitsDirective;
     const char *RomData32bitsDirective;
   public:    
-    PIC16TargetAsmInfo();
+    PIC16TargetAsmInfo(const Target &T, const StringRef &TT);
     
     virtual const char *getDataASDirective(unsigned size, unsigned AS) const;
   };
index d09097c17f39c4c30901c17d5f0044e40a932366..6af693f11c0abb85de36f64adc27b47d6ee68002 100644 (file)
@@ -36,10 +36,6 @@ CooperTargetMachine::CooperTargetMachine(const Target &T, const std::string &TT,
   : PIC16TargetMachine(T, TT, FS, true) {}
 
 
-const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const {
-  return new PIC16TargetAsmInfo();
-}
-
 bool PIC16TargetMachine::addInstSelector(PassManagerBase &PM,
                                          CodeGenOpt::Level OptLevel) {
   // Install an instruction selector.
index 649c7ea1dc995fd6f5adffdbb9b49c1fded3ef8f..51efdb22446543e7cf8c164153f11d1130ffca10 100644 (file)
@@ -37,9 +37,6 @@ class PIC16TargetMachine : public LLVMTargetMachine {
   // any PIC16 specific FrameInfo class.
   TargetFrameInfo       FrameInfo;
 
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   PIC16TargetMachine(const Target &T, const std::string &TT,
                      const std::string &FS, bool Cooper = false);
index 07667117a045a02779719c6e2b2274d11fdd51c2..41f4699fc061d4f7cf778107fdec53e8db02a25f 100644 (file)
 #include "llvm/Support/FormattedStream.h"
 using namespace llvm;
 
+static const TargetAsmInfo *createTargetAsmInfo(const Target &T,
+                                                const StringRef &TT) {
+  Triple TheTriple(TT);
+  bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
+  if (TheTriple.getOS() == Triple::Darwin)
+    return new PPCDarwinTargetAsmInfo(isPPC64);
+  return new PPCLinuxTargetAsmInfo(isPPC64);
+  
+}
+
 extern "C" void LLVMInitializePowerPCTarget() {
   // Register the targets
   RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);  
   RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
+  
+  RegisterAsmInfoFn C(ThePPC32Target, createTargetAsmInfo);
+  RegisterAsmInfoFn D(ThePPC64Target, createTargetAsmInfo);
 }
 
-const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
-  if (Subtarget.isDarwin())
-    return new PPCDarwinTargetAsmInfo(Subtarget.isPPC64());
-  return new PPCLinuxTargetAsmInfo(Subtarget.isPPC64());
-}
 
 PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
                                    const std::string &FS, bool is64Bit)
index b7ac6ef8bc38ca08e4f8483f9a4e2ae9d5cd3258..3399ac89188fa66a6386364991247a6c0f5e033e 100644 (file)
@@ -39,9 +39,6 @@ class PPCTargetMachine : public LLVMTargetMachine {
   InstrItineraryData  InstrItins;
   PPCMachOWriterInfo  MachOWriterInfo;
 
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   PPCTargetMachine(const Target &T, const std::string &TT,
                    const std::string &FS, bool is64Bit);
index 6ec74e6e4fc5a198c7aec75a9fc5ae8ad5e1b545..1794ebc5876c46f5f7fbf691790e19424a10f806 100644 (file)
@@ -15,7 +15,8 @@
 #include "llvm/ADT/SmallVector.h"
 using namespace llvm;
 
-SparcELFTargetAsmInfo::SparcELFTargetAsmInfo() {
+SparcELFTargetAsmInfo::SparcELFTargetAsmInfo(const Target &T,
+                                             const StringRef &TT) {
   Data16bitsDirective = "\t.half\t";
   Data32bitsDirective = "\t.word\t";
   Data64bitsDirective = 0;  // .xword is only supported by V9.
index 255a2dfb2d1f72bfbb689302039e27b309755af4..edf8146242861fe54c1203151e0ccc41a8623a81 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
-
+  class Target;
+  class StringRef;
   struct SparcELFTargetAsmInfo : public TargetAsmInfo {
-    explicit SparcELFTargetAsmInfo();
+    explicit SparcELFTargetAsmInfo(const Target &T, const StringRef &TT);
   };
 
 } // namespace llvm
index c9a3cdd6c7bcd9b8e3af8cc1e2e2b0ccee9ebb66..505e2b11d59f73bfb5aa186dedd64e42c6ca64a6 100644 (file)
@@ -20,11 +20,8 @@ using namespace llvm;
 extern "C" void LLVMInitializeSparcTarget() {
   // Register the target.
   RegisterTargetMachine<SparcTargetMachine> X(TheSparcTarget);
-}
+  RegisterAsmInfo<SparcELFTargetAsmInfo> Y(TheSparcTarget);
 
-const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
-  // FIXME: Handle Solaris subtarget someday :)
-  return new SparcELFTargetAsmInfo();
 }
 
 /// SparcTargetMachine ctor - Create an ILP32 architecture model
index 8cdfba3a50a96c4f6942864f34cf0f56de0cfe85..cce55105e76ed5e0ede585ccf35cb38f361fa8cc 100644 (file)
@@ -29,10 +29,6 @@ class SparcTargetMachine : public LLVMTargetMachine {
   SparcTargetLowering TLInfo;
   SparcInstrInfo InstrInfo;
   TargetFrameInfo FrameInfo;
-  
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-  
 public:
   SparcTargetMachine(const Target &T, const std::string &TT,
                      const std::string &FS);
index a2e15d1d9534cd903fb13141a87bcaf91f2e892c..fc102124ba4ea18ed96ca2e5a1482fd446d6f0c6 100644 (file)
@@ -14,7 +14,8 @@
 #include "SystemZTargetAsmInfo.h"
 using namespace llvm;
 
-SystemZTargetAsmInfo::SystemZTargetAsmInfo() {
+SystemZTargetAsmInfo::SystemZTargetAsmInfo(const Target &T,
+                                           const StringRef &TT) {
   AlignmentIsInBytes = true;
 
   PrivateGlobalPrefix = ".L";
index 672524b5b243ba97fc15c6d0fc1213c0aa4c649d..72345c87956c38501930cfbc16e8acf272556fc9 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class Target;
+  class StringRef;
 
   struct SystemZTargetAsmInfo : public TargetAsmInfo {
-    explicit SystemZTargetAsmInfo();
+    explicit SystemZTargetAsmInfo(const Target &T, const StringRef &TT);
   };
 
 } // namespace llvm
index cfd1f39cd3534697085903c763abd9afea1a66f6..48ea5f5ebd706ca76eed79cf21b20c8b5e2fbb49 100644 (file)
@@ -6,9 +6,6 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-//
-//
-//===----------------------------------------------------------------------===//
 
 #include "SystemZTargetAsmInfo.h"
 #include "SystemZTargetMachine.h"
@@ -20,10 +17,7 @@ using namespace llvm;
 extern "C" void LLVMInitializeSystemZTarget() {
   // Register the target.
   RegisterTargetMachine<SystemZTargetMachine> X(TheSystemZTarget);
-}
-
-const TargetAsmInfo *SystemZTargetMachine::createTargetAsmInfo() const {
-  return new SystemZTargetAsmInfo();
+  RegisterAsmInfo<SystemZTargetAsmInfo> Y(TheSystemZTarget);
 }
 
 /// SystemZTargetMachine ctor - Create an ILP64 architecture model
index 6626fd0e50ff50095a67df691376640398ad1d1b..551aeb5a3e47b8643db86be347996403a4869e60 100644 (file)
@@ -36,10 +36,6 @@ class SystemZTargetMachine : public LLVMTargetMachine {
   // SystemZ does not have any call stack frame, therefore not having
   // any SystemZ specific FrameInfo class.
   TargetFrameInfo       FrameInfo;
-
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   SystemZTargetMachine(const Target &T, const std::string &TT,
                        const std::string &FS);
index 859ced7728fe4b4cbbbc721cb84a40aff16d56f3..d978eb179de823116e5466dce0c54061b9a36f9b 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "X86TargetAsmInfo.h"
 #include "X86TargetMachine.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Support/CommandLine.h"
 using namespace llvm;
 
@@ -42,12 +43,11 @@ static const char *const x86_asm_table[] = {
   "{cc}", "cc",
   0,0};
 
-X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM) {
+X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const Triple &Triple) {
   AsmTransCBE = x86_asm_table;
   AssemblerDialect = AsmWriterFlavor;
     
-  const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
-  bool is64Bit = Subtarget->is64Bit();
+  bool is64Bit = Triple.getArch() == Triple::x86_64;
 
   TextAlignFillValue = 0x90;
 
@@ -55,7 +55,7 @@ X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM) {
     Data64bitsDirective = 0;       // we can't emit a 64-bit unit
 
   // Leopard and above support aligned common symbols.
-  COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
+  COMMDirectiveTakesAlignment = Triple.getDarwinMajorNumber() >= 9;
 
   if (is64Bit) {
     PersonalityPrefix = "";
@@ -76,7 +76,7 @@ X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM) {
   AbsoluteEHSectionOffsets = false;
 }
 
-X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM) {
+X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const Triple &Triple) {
   AsmTransCBE = x86_asm_table;
   AssemblerDialect = AsmWriterFlavor;
 
@@ -97,17 +97,17 @@ X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM) {
   AbsoluteEHSectionOffsets = false;
 
   // On Linux we must declare when we can use a non-executable stack.
-  if (TM.getSubtarget<X86Subtarget>().isLinux())
+  if (Triple.getOS() == Triple::Linux)
     NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
 }
 
-X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM) {
+X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const Triple &Triple) {
   AsmTransCBE = x86_asm_table;
   AssemblerDialect = AsmWriterFlavor;
 }
 
 
-X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM) {
+X86WinTargetAsmInfo::X86WinTargetAsmInfo(const Triple &Triple) {
   AsmTransCBE = x86_asm_table;
   AssemblerDialect = AsmWriterFlavor;
 
index 8879b4ba10e1a181cc2db968f664b14105b14df7..91de36825910e649eb7d24f2ffdd53eb0656b514 100644 (file)
 #ifndef X86TARGETASMINFO_H
 #define X86TARGETASMINFO_H
 
-#include "X86TargetMachine.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/COFFTargetAsmInfo.h"
 #include "llvm/Target/DarwinTargetAsmInfo.h"
 
 namespace llvm {
+  class Triple;
 
   struct X86DarwinTargetAsmInfo : public DarwinTargetAsmInfo {
-    explicit X86DarwinTargetAsmInfo(const X86TargetMachine &TM);
+    explicit X86DarwinTargetAsmInfo(const Triple &Triple);
   };
 
   struct X86ELFTargetAsmInfo : public TargetAsmInfo {
-    explicit X86ELFTargetAsmInfo(const X86TargetMachine &TM);
+    explicit X86ELFTargetAsmInfo(const Triple &Triple);
   };
 
   struct X86COFFTargetAsmInfo : public COFFTargetAsmInfo {
-    explicit X86COFFTargetAsmInfo(const X86TargetMachine &TM);
+    explicit X86COFFTargetAsmInfo(const Triple &Triple);
   };
 
   struct X86WinTargetAsmInfo : public TargetAsmInfo {
-    explicit X86WinTargetAsmInfo(const X86TargetMachine &TM);
+    explicit X86WinTargetAsmInfo(const Triple &Triple);
   };
 
 } // namespace llvm
index 76d0165c86edc037db21fe3994a000d032f5eddf..8c4e5d02bec36d1cc571820d29a9e0dfc792edc2 100644 (file)
 #include "llvm/Target/TargetRegistry.h"
 using namespace llvm;
 
+static const TargetAsmInfo *createTargetAsmInfo(const Target &T,
+                                                const StringRef &TT) {
+  Triple TheTriple(TT);
+  switch (TheTriple.getOS()) {
+  case Triple::Darwin:
+    return new X86DarwinTargetAsmInfo(TheTriple);
+  case Triple::MinGW32:
+  case Triple::MinGW64:
+  case Triple::Cygwin:
+    return new X86COFFTargetAsmInfo(TheTriple);
+  case Triple::Win32:
+    return new X86WinTargetAsmInfo(TheTriple);
+  default:
+    return new X86ELFTargetAsmInfo(TheTriple);
+  }
+}
+
 extern "C" void LLVMInitializeX86Target() { 
   // Register the target.
   RegisterTargetMachine<X86_32TargetMachine> X(TheX86_32Target);
   RegisterTargetMachine<X86_64TargetMachine> Y(TheX86_64Target);
-}
 
-const TargetAsmInfo *X86TargetMachine::createTargetAsmInfo() const {
-  switch (Subtarget.TargetType) {
-  default: llvm_unreachable("unknown subtarget type");
-  case X86Subtarget::isDarwin:
-    return new X86DarwinTargetAsmInfo(*this);
-  case X86Subtarget::isELF:
-    return new X86ELFTargetAsmInfo(*this);
-  case X86Subtarget::isMingw:
-  case X86Subtarget::isCygwin:
-    return new X86COFFTargetAsmInfo(*this);
-  case X86Subtarget::isWindows:
-    return new X86WinTargetAsmInfo(*this);
-  }
+  // Register the target asm info.
+  RegisterAsmInfoFn A(TheX86_32Target, createTargetAsmInfo);
+  RegisterAsmInfoFn B(TheX86_64Target, createTargetAsmInfo);
 }
 
+
 X86_32TargetMachine::X86_32TargetMachine(const Target &T, const std::string &TT,
                                          const std::string &FS)
   : X86TargetMachine(T, TT, FS, false) {
index d6187c773c59defc97e9ea50e5d267252e4a0fdf..b538408e8a45f0113c38d3024fb000d038419b6f 100644 (file)
@@ -38,9 +38,6 @@ class X86TargetMachine : public LLVMTargetMachine {
   X86ELFWriterInfo  ELFWriterInfo;
   Reloc::Model      DefRelocModel; // Reloc model before it's overridden.
 
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   X86TargetMachine(const Target &T, const std::string &TT, 
                    const std::string &FS, bool is64Bit);
index 4604b74c8339b05c8013fd8943073f833dc5b45a..2b706ee3f864b8bbbeea26fb923ec7e04bd5f886 100644 (file)
@@ -16,6 +16,7 @@
 #include "XCore.h"
 #include "XCoreInstrInfo.h"
 #include "XCoreSubtarget.h"
+#include "XCoreTargetAsmInfo.h"
 #include "XCoreTargetMachine.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -26,7 +27,6 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetRegistry.h"
@@ -380,4 +380,5 @@ bool XCoreAsmPrinter::doInitialization(Module &M) {
 extern "C" void LLVMInitializeXCoreTarget() { 
   RegisterTargetMachine<XCoreTargetMachine> X(TheXCoreTarget);
   RegisterAsmPrinter<XCoreAsmPrinter> Y(TheXCoreTarget);
+  RegisterAsmInfo<XCoreTargetAsmInfo> Z(TheXCoreTarget);
 }
index eebd6c96ed5cd9ccbf1afad918b5cd4b36e87d88..9cd87a57551ff8e799c84f6587d1cf0c19112e5e 100644 (file)
@@ -10,7 +10,7 @@
 #include "XCoreTargetAsmInfo.h"
 using namespace llvm;
 
-XCoreTargetAsmInfo::XCoreTargetAsmInfo() {
+XCoreTargetAsmInfo::XCoreTargetAsmInfo(const Target &T, const StringRef &TT) {
   SupportsDebugInformation = true;
   Data16bitsDirective = "\t.short\t";
   Data32bitsDirective = "\t.long\t";
index c4f71e43137e52524feb2e26dc844716fcd48d03..784288633ffe09f4bf36d4ccda6d77c9e84fb6db 100644 (file)
 #include "llvm/Target/TargetAsmInfo.h"
 
 namespace llvm {
+  class Target;
+  class StringRef;
   class XCoreTargetAsmInfo : public TargetAsmInfo {
   public:
-    explicit XCoreTargetAsmInfo();
+    explicit XCoreTargetAsmInfo(const Target &T, const StringRef &TT);
   };
 
 } // namespace llvm
index 0a5daf8792e2b62427a3ba5e40ffc5d21eeb1160..57176cca2b6c6e144b912406659b5627c759fc1a 100644 (file)
 #include "llvm/PassManager.h"
 using namespace llvm;
 
-const TargetAsmInfo *XCoreTargetMachine::createTargetAsmInfo() const {
-  return new XCoreTargetAsmInfo();
-}
-
 /// XCoreTargetMachine ctor - Create an ILP32 architecture model
 ///
 XCoreTargetMachine::XCoreTargetMachine(const Target &T, const std::string &TT,
index 136cea29e753e90961e77f24f0e79b1fd4b27e6d..b0b1464dbe0c805643c8e0337594833c1e7a1181 100644 (file)
@@ -29,10 +29,6 @@ class XCoreTargetMachine : public LLVMTargetMachine {
   XCoreInstrInfo InstrInfo;
   XCoreFrameInfo FrameInfo;
   XCoreTargetLowering TLInfo;
-
-protected:
-  virtual const TargetAsmInfo *createTargetAsmInfo() const;
-
 public:
   XCoreTargetMachine(const Target &T, const std::string &TT,
                      const std::string &FS);