Auto-registrate target
authorChris Lattner <sabre@nondot.org>
Sun, 11 Jul 2004 02:48:49 +0000 (02:48 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 11 Jul 2004 02:48:49 +0000 (02:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14745 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/CTargetMachine.h
lib/Target/CBackend/Writer.cpp
lib/Target/PowerPC/PPCTargetMachine.cpp
lib/Target/PowerPC/PowerPCTargetMachine.cpp
lib/Target/Sparc/SparcTargetMachine.cpp
lib/Target/SparcV8/SparcV8TargetMachine.cpp
lib/Target/SparcV9/SparcV9TargetMachine.cpp
lib/Target/SparcV9/SparcV9TargetMachine.h
lib/Target/X86/X86TargetMachine.cpp
lib/Target/X86/X86TargetMachine.h

index 1f6b90059797661c171ca601fc69cc3b479bf1c4..2cdf30f0d600b9a85e990c46373ff0eff62f164a 100644 (file)
@@ -27,6 +27,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/CodeGen/IntrinsicLowering.h"
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
@@ -40,6 +41,9 @@
 using namespace llvm;
 
 namespace {
+  // Register the target.
+  RegisterTarget<CTargetMachine> X("c", "C backend");
+
   /// NameAllUsedStructs - This pass inserts names for any unnamed structure
   /// types that are used by the program.
   ///
index 97f880d2fd68e8821fea4f9e2ec168385b884a55..aa672fc6ca5512c57378841eb086dd7ee18e3b0b 100644 (file)
@@ -25,6 +25,9 @@ struct CTargetMachine : public TargetMachine {
 
   // This is the only thing that actually does anything here.
   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
+
+  // This class always works, but shouldn't be the default in most cases.
+  static unsigned getModuleMatchQuality(const Module &M) { return 1; }
 };
 
 } // End llvm namespace
index 1f6b90059797661c171ca601fc69cc3b479bf1c4..2cdf30f0d600b9a85e990c46373ff0eff62f164a 100644 (file)
@@ -27,6 +27,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/CodeGen/IntrinsicLowering.h"
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
@@ -40,6 +41,9 @@
 using namespace llvm;
 
 namespace {
+  // Register the target.
+  RegisterTarget<CTargetMachine> X("c", "C backend");
+
   /// NameAllUsedStructs - This pass inserts names for any unnamed structure
   /// types that are used by the program.
   ///
index 035c31e7de430fe10c6ca0be409c61a9d1705193..1d6898a96cde23e80a43cc076e804542e313a3a1 100644 (file)
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/Target/TargetMachineImpls.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
+#include <iostream>
 using namespace llvm;
 
+namespace {
+  // Register the target.
+  RegisterTarget<PowerPCTargetMachine> X("powerpc", "PowerPC (experimental)");
+}
+
 // allocatePowerPCTargetMachine - Allocate and return a subclass of 
 // TargetMachine that implements the PowerPC backend.
 //
index bf57b155013bc212e3882fcf82c9ec7ffac65958..7132e5de6d5d3cd5de69546da8b56484b94ec0e7 100644 (file)
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/Target/TargetMachineImpls.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/Passes.h"
 using namespace llvm;
 
+namespace {
+  // Register the target.
+  RegisterTarget<PowerPCTargetMachine> X("powerpc", "PowerPC (experimental)");
+}
+
 // allocatePowerPCTargetMachine - Allocate and return a subclass of 
 // TargetMachine that implements the PowerPC backend.
 //
index cdd902cf83118bc1c054891a6ec54d6a659c9f15..4a8a39477738836a0b7b9e0089a23e4cc9847d70 100644 (file)
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/Target/TargetMachineImpls.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
 #include <iostream>
 using namespace llvm;
 
+namespace {
+  // Register the target.
+  RegisterTarget<SparcV8TargetMachine> X("sparcv8", "SPARC V8 (experimental)");
+}
+
 // allocateSparcV8TargetMachine - Allocate and return a subclass of 
 // TargetMachine that implements the SparcV8 backend.
 //
index cdd902cf83118bc1c054891a6ec54d6a659c9f15..4a8a39477738836a0b7b9e0089a23e4cc9847d70 100644 (file)
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/Target/TargetMachineImpls.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
 #include <iostream>
 using namespace llvm;
 
+namespace {
+  // Register the target.
+  RegisterTarget<SparcV8TargetMachine> X("sparcv8", "SPARC V8 (experimental)");
+}
+
 // allocateSparcV8TargetMachine - Allocate and return a subclass of 
 // TargetMachine that implements the SparcV8 backend.
 //
index 78332e1f1048540ec44793e6830bbba15d76005c..e114674eb0d24e329ef95d716aeb595022da9c53 100644 (file)
 #include "llvm/CodeGen/MachineCodeForInstruction.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/Target/TargetMachineImpls.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
 #include "MappingInfo.h" 
 #include "SparcV9Internals.h"
 #include "SparcV9TargetMachine.h"
 #include "Support/CommandLine.h"
-
 using namespace llvm;
 
 static const unsigned ImplicitRegUseList[] = { 0 }; /* not used yet */
@@ -59,6 +59,28 @@ namespace {
 
   cl::opt<bool> DisableStrip("disable-strip",
                       cl::desc("Do not strip the LLVM bytecode in executable"));
+
+  // Register the target.
+  RegisterTarget<SparcV9TargetMachine> X("sparcv9", "SPARC V9");
+}
+
+unsigned SparcV9TargetMachine::getJITMatchQuality() {
+#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
+  return 10;
+#else
+  return 0;
+#endif
+}
+
+unsigned SparcV9TargetMachine::getModuleMatchQuality(const Module &M) {
+  if (M.getEndianness()  == Module::BigEndian &&
+      M.getPointerSize() == Module::Pointer64)
+    return 10;                                   // Direct match
+  else if (M.getEndianness() != Module::AnyEndianness ||
+           M.getPointerSize() != Module::AnyPointerSize)
+    return 0;                                    // Match for some other target
+
+  return getJITMatchQuality()/2;
 }
 
 //===---------------------------------------------------------------------===//
@@ -111,7 +133,8 @@ FunctionPass *llvm::createSparcV9MachineCodeDestructionPass() {
 }
 
 
-SparcV9TargetMachine::SparcV9TargetMachine(IntrinsicLowering *il)
+SparcV9TargetMachine::SparcV9TargetMachine(const Module &M,
+                                           IntrinsicLowering *il)
   : TargetMachine("UltraSparcV9-Native", il, false),
     schedInfo(*this),
     regInfo(*this),
@@ -264,10 +287,11 @@ void SparcV9JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
     PM.add(createMachineFunctionPrinterPass(&std::cerr, "Final code:\n"));
 }
 
-/// allocateSparcV9TargetMachine - Allocate and return a subclass of TargetMachine
-/// that implements the SparcV9 backend. (the llvm/CodeGen/SparcV9.h interface)
+/// allocateSparcV9TargetMachine - Allocate and return a subclass of
+/// TargetMachine that implements the SparcV9 backend. (the
+/// llvm/CodeGen/SparcV9.h interface)
 ///
 TargetMachine *llvm::allocateSparcV9TargetMachine(const Module &M,
                                                 IntrinsicLowering *IL) {
-  return new SparcV9TargetMachine(IL);
+  return new SparcV9TargetMachine(M, IL);
 }
index 65aa8b70bd86e79231319d070c96ba1f7328ed3f..4a1539c3642502edb2a507e27ce43ce2ea648adc 100644 (file)
@@ -32,7 +32,7 @@ class SparcV9TargetMachine : public TargetMachine {
   SparcV9FrameInfo frameInfo;
   SparcV9JITInfo   jitInfo;
 public:
-  SparcV9TargetMachine(IntrinsicLowering *IL);
+  SparcV9TargetMachine(const Module &M, IntrinsicLowering *IL);
   
   virtual const TargetInstrInfo  *getInstrInfo() const { return &instrInfo; }
   virtual const TargetSchedInfo  *getSchedInfo() const { return &schedInfo; }
@@ -46,6 +46,9 @@ public:
   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
                                           MachineCodeEmitter &MCE);
+
+  static unsigned getModuleMatchQuality(const Module &M);
+  static unsigned getJITMatchQuality();
 };
 
 } // End llvm namespace
index a2efb034f5f064fa15cf5041c03d99795b1b39fa..3ee9dd292febe1bf52a9dde3a2e0c90344f94ab2 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/Target/TargetMachineImpls.h"
+#include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
 #include "Support/CommandLine.h"
 #include "Support/Statistic.h"
@@ -35,6 +36,9 @@ namespace {
                                        "when profiling the code generator."));
   cl::opt<bool> NoSimpleISel("disable-simple-isel", cl::init(true),
             cl::desc("Use the hand coded 'simple' X86 instruction selector"));
+
+  // Register the target.
+  RegisterTarget<X86TargetMachine> X("x86", "IA-32 (Pentium and above)");
 }
 
 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
@@ -45,6 +49,24 @@ TargetMachine *llvm::allocateX86TargetMachine(const Module &M,
   return new X86TargetMachine(M, IL);
 }
 
+unsigned X86TargetMachine::getJITMatchQuality() {
+#if defined(i386) || defined(__i386__) || defined(__x86__)
+  return 10;
+#else
+  return 0;
+#endif
+}
+
+unsigned X86TargetMachine::getModuleMatchQuality(const Module &M) {
+  if (M.getEndianness()  == Module::LittleEndian &&
+      M.getPointerSize() == Module::Pointer32)
+    return 10;                                   // Direct match
+  else if (M.getEndianness() != Module::AnyEndianness ||
+           M.getPointerSize() != Module::AnyPointerSize)
+    return 0;                                    // Match for some other target
+
+  return getJITMatchQuality()/2;
+}
 
 /// X86TargetMachine ctor - Create an ILP32 architecture model
 ///
index 88b91bdc4f19ea141dcb16541394920b71080567..717fdee0011c960986fe27656e1d7838a026310d 100644 (file)
@@ -47,6 +47,9 @@ public:
                                           MachineCodeEmitter &MCE);
   
   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out);
+
+  static unsigned getModuleMatchQuality(const Module &M);
+  static unsigned getJITMatchQuality();
 };
 
   // this is implemented in X86CodeEmitter.cpp