diff --git a/lib/Target/ARM/ARMSubtarget.cpp b/lib/Target/ARM/ARMSubtarget.cpp index 4363697d3e3..6db36dff29c 100644 --- a/lib/Target/ARM/ARMSubtarget.cpp +++ b/lib/Target/ARM/ARMSubtarget.cpp @@ -14,16 +14,12 @@ #include "ARMSubtarget.h" #include "ARMGenSubtarget.inc" #include "llvm/Module.h" -#include "llvm/Support/CommandLine.h" using namespace llvm; -// FIXME: this is temporary. -static cl::opt Thumb("enable-thumb", - cl::desc("Switch to thumb mode in ARM backend")); - -ARMSubtarget::ARMSubtarget(const Module &M, const std::string &FS) +ARMSubtarget::ARMSubtarget(const Module &M, const std::string &FS, bool thumb) : ARMArchVersion(V4T) , HasVFP2(false) + , IsThumb(thumb) , UseThumbBacktraces(false) , IsR9Reserved(false) , stackAlignment(4) @@ -36,8 +32,6 @@ ARMSubtarget::ARMSubtarget(const Module &M, const std::string &FS) // Parse features string. ParseSubtargetFeatures(FS, CPU); - IsThumb = Thumb; - // Set the boolean corresponding to the current target triple, or the default // if one cannot be determined, to true. const std::string& TT = M.getTargetTriple(); diff --git a/lib/Target/ARM/ARMSubtarget.h b/lib/Target/ARM/ARMSubtarget.h index 88ceaef7b66..62367cadb91 100644 --- a/lib/Target/ARM/ARMSubtarget.h +++ b/lib/Target/ARM/ARMSubtarget.h @@ -60,7 +60,7 @@ protected: /// This constructor initializes the data members to match that /// of the specified module. /// - ARMSubtarget(const Module &M, const std::string &FS); + ARMSubtarget(const Module &M, const std::string &FS, bool thumb); /// ParseSubtargetFeatures - Parses features string setting specified /// subtarget options. Definition of function is auto generated by tblgen. diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp index 2fa70160858..0b22c15ba35 100644 --- a/lib/Target/ARM/ARMTargetMachine.cpp +++ b/lib/Target/ARM/ARMTargetMachine.cpp @@ -27,21 +27,37 @@ static cl::opt DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden, namespace { // Register the target. - RegisterTarget X("arm", " ARM"); + RegisterTarget X("arm", " ARM"); + RegisterTarget Y("thumb", " Thumb"); } -/// TargetMachine ctor - Create an ILP32 architecture model +/// ThumbTargetMachine - Create an Thumb architecture model. /// -ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS) - : Subtarget(M, FS), +unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) { + std::string TT = M.getTargetTriple(); + if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-") + return 20; + + return M.getPointerSize() == Module::Pointer32; +} + +ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS) + : ARMTargetMachine(M, FS, true) { +} + +/// TargetMachine ctor - Create an ARM architecture model. +/// +ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS, + bool isThumb) + : Subtarget(M, FS, isThumb), DataLayout(Subtarget.isAPCS_ABI() ? // APCS ABI - (Subtarget.isThumb() ? + (isThumb ? std::string("e-p:32:32-f64:32:32-i64:32:32-" "i16:16:32-i8:8:32-i1:8:32-a:0:32") : std::string("e-p:32:32-f64:32:32-i64:32:32")) : // AAPCS ABI - (Subtarget.isThumb() ? + (isThumb ? std::string("e-p:32:32-f64:64:64-i64:64:64-" "i16:16:32-i8:8:32-i1:8:32-a:0:32") : std::string("e-p:32:32-f64:64:64-i64:64:64"))), @@ -53,10 +69,7 @@ unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) { if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-") return 20; - if (M.getPointerSize() == Module::Pointer32) - return 1; - else - return 0; + return M.getPointerSize() == Module::Pointer32; } diff --git a/lib/Target/ARM/ARMTargetMachine.h b/lib/Target/ARM/ARMTargetMachine.h index 9c888ea3955..7f45fb6b6c0 100644 --- a/lib/Target/ARM/ARMTargetMachine.h +++ b/lib/Target/ARM/ARMTargetMachine.h @@ -32,7 +32,7 @@ class ARMTargetMachine : public LLVMTargetMachine { ARMInstrInfo InstrInfo; ARMFrameInfo FrameInfo; public: - ARMTargetMachine(const Module &M, const std::string &FS); + ARMTargetMachine(const Module &M, const std::string &FS, bool isThumb = false); virtual const ARMInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; } @@ -52,6 +52,15 @@ public: std::ostream &Out); }; +/// ThumbTargetMachine - Thumb target machine. +/// +class ThumbTargetMachine : public ARMTargetMachine { +public: + ThumbTargetMachine(const Module &M, const std::string &FS); + + static unsigned getModuleMatchQuality(const Module &M); +}; + } // end namespace llvm #endif