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