4aa249af83035b91ddb466bf2a0934883a5e1d71
[oota-llvm.git] / lib / Target / ARM / ARMSubtarget.cpp
1 //===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the ARM specific subclass of TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARMSubtarget.h"
15 #include "ARMGenSubtarget.inc"
16 #include "llvm/Module.h"
17 #include "llvm/Target/TargetMachine.h"
18 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Support/CommandLine.h"
20 using namespace llvm;
21
22 static cl::opt<bool>
23 ReserveR9("arm-reserve-r9", cl::Hidden,
24           cl::desc("Reserve R9, making it unavailable as GPR"));
25
26 ARMSubtarget::ARMSubtarget(const Module &M, const std::string &FS,
27                            bool isThumb)
28   : ARMArchVersion(V4T)
29   , ARMFPUType(None)
30   , IsThumb(isThumb)
31   , ThumbMode(Thumb1)
32   , IsR9Reserved(ReserveR9)
33   , stackAlignment(4)
34   , CPUString("generic")
35   , TargetType(isELF) // Default to ELF unless otherwise specified.
36   , TargetABI(ARM_ABI_APCS) {
37   // default to soft float ABI
38   if (FloatABIType == FloatABI::Default)
39     FloatABIType = FloatABI::Soft;
40
41   // Determine default and user specified characteristics
42
43   // Parse features string.
44   CPUString = ParseSubtargetFeatures(FS, CPUString);
45
46   // Set the boolean corresponding to the current target triple, or the default
47   // if one cannot be determined, to true.
48   const std::string& TT = M.getTargetTriple();
49   unsigned Len = TT.length();
50   unsigned Idx = 0;
51
52   if (Len >= 5 && TT.substr(0, 4) == "armv")
53     Idx = 4;
54   else if (Len >= 6 && TT.substr(0, 6) == "thumb") {
55     IsThumb = true;
56     if (Len >= 7 && TT[5] == 'v')
57       Idx = 6;
58   }
59   if (Idx) {
60     unsigned SubVer = TT[Idx];
61     if (SubVer > '4' && SubVer <= '9') {
62       if (SubVer >= '7')
63         ARMArchVersion = V7A;
64       else if (SubVer == '6')
65         ARMArchVersion = V6;
66       else if (SubVer == '5') {
67         ARMArchVersion = V5T;
68         if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
69           ARMArchVersion = V5TE;
70       }
71     }
72   }
73
74   if (Len >= 10) {
75     if (TT.find("-darwin") != std::string::npos)
76       // arm-darwin
77       TargetType = isDarwin;
78   } else if (TT.empty()) {
79 #if defined(__APPLE__)
80     TargetType = isDarwin;
81 #endif
82   }
83
84   if (TT.find("eabi") != std::string::npos)
85     TargetABI = ARM_ABI_AAPCS;
86
87   if (isAAPCS_ABI())
88     stackAlignment = 8;
89
90   if (isTargetDarwin())
91     IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
92 }