Re-apply 72756 with fixes. One of those was introduced by we changed MachineInstrBuil...
[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 using namespace llvm;
18
19 ARMSubtarget::ARMSubtarget(const Module &M, const std::string &FS,
20                            bool isThumb)
21   : ARMArchVersion(V4T)
22   , ARMFPUType(None)
23   , IsThumb(isThumb)
24   , ThumbMode(Thumb1)
25   , UseThumbBacktraces(false)
26   , IsR9Reserved(false)
27   , stackAlignment(4)
28   , CPUString("generic")
29   , TargetType(isELF) // Default to ELF unless otherwise specified.
30   , TargetABI(ARM_ABI_APCS) {
31   // Determine default and user specified characteristics
32
33   // Parse features string.
34   CPUString = ParseSubtargetFeatures(FS, CPUString);
35
36   // Set the boolean corresponding to the current target triple, or the default
37   // if one cannot be determined, to true.
38   const std::string& TT = M.getTargetTriple();
39   unsigned Len = TT.length();
40   unsigned Idx = 0;
41
42   if (Len >= 5 && TT.substr(0, 4) == "armv")
43     Idx = 4;
44   else if (Len >= 6 && TT.substr(0, 6) == "thumb") {
45     IsThumb = true;
46     if (Len >= 7 && TT[5] == 'v')
47       Idx = 6;
48   }
49   if (Idx) {
50     unsigned SubVer = TT[Idx];
51     if (SubVer > '4' && SubVer <= '9') {
52       if (SubVer >= '7')
53         ARMArchVersion = V7A;
54       else if (SubVer == '6')
55         ARMArchVersion = V6;
56       else if (SubVer == '5') {
57         ARMArchVersion = V5T;
58         if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
59           ARMArchVersion = V5TE;
60       }
61     }
62   }
63
64   if (Len >= 10) {
65     if (TT.find("-darwin") != std::string::npos)
66       // arm-darwin
67       TargetType = isDarwin;
68   } else if (TT.empty()) {
69 #if defined(__APPLE__)
70     TargetType = isDarwin;
71 #endif
72   }
73
74   if (TT.find("eabi") != std::string::npos)
75     TargetABI = ARM_ABI_AAPCS;
76
77   if (isAAPCS_ABI())
78     stackAlignment = 8;
79
80   if (isTargetDarwin()) {
81     UseThumbBacktraces = true;
82     IsR9Reserved = true;
83   }
84 }