Re-apply r110655 with fixes. Epilogue must restore sp from fp if the function stack...
[oota-llvm.git] / lib / Target / ARM / ARMSubtarget.h
1 //=====---- ARMSubtarget.h - Define Subtarget for the ARM -----*- 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 declares the ARM specific subclass of TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef ARMSUBTARGET_H
15 #define ARMSUBTARGET_H
16
17 #include "llvm/Target/TargetInstrItineraries.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include "llvm/Target/TargetSubtarget.h"
20 #include "ARMBaseRegisterInfo.h"
21 #include <string>
22
23 namespace llvm {
24 class GlobalValue;
25
26 class ARMSubtarget : public TargetSubtarget {
27 protected:
28   enum ARMArchEnum {
29     V4, V4T, V5T, V5TE, V6, V6T2, V7A, V7M
30   };
31
32   enum ARMFPEnum {
33     None, VFPv2, VFPv3, NEON
34   };
35
36   enum ThumbTypeEnum {
37     Thumb1,
38     Thumb2
39   };
40
41   /// ARMArchVersion - ARM architecture version: V4, V4T (base), V5T, V5TE,
42   /// V6, V6T2, V7A, V7M.
43   ARMArchEnum ARMArchVersion;
44
45   /// ARMFPUType - Floating Point Unit type.
46   ARMFPEnum ARMFPUType;
47
48   /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been
49   /// specified. Use the method useNEONForSinglePrecisionFP() to
50   /// determine if NEON should actually be used.
51   bool UseNEONForSinglePrecisionFP;
52
53   /// SlowVMLx - If the VFP2 instructions are available, indicates whether
54   /// the VML[AS] instructions are slow (if so, don't use them).
55   bool SlowVMLx;
56
57   /// SlowFPBrcc - True if floating point compare + branch is slow.
58   bool SlowFPBrcc;
59
60   /// IsThumb - True if we are in thumb mode, false if in ARM mode.
61   bool IsThumb;
62
63   /// ThumbMode - Indicates supported Thumb version.
64   ThumbTypeEnum ThumbMode;
65
66   /// PostRAScheduler - True if using post-register-allocation scheduler.
67   bool PostRAScheduler;
68
69   /// IsR9Reserved - True if R9 is a not available as general purpose register.
70   bool IsR9Reserved;
71
72   /// UseMovt - True if MOVT / MOVW pairs are used for materialization of 32-bit
73   /// imms (including global addresses).
74   bool UseMovt;
75
76   /// HasFP16 - True if subtarget supports half-precision FP (We support VFP+HF
77   /// only so far)
78   bool HasFP16;
79
80   /// HasHardwareDivide - True if subtarget supports [su]div
81   bool HasHardwareDivide;
82
83   /// HasT2ExtractPack - True if subtarget supports thumb2 extract/pack
84   /// instructions.
85   bool HasT2ExtractPack;
86
87   /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions
88   /// over 16-bit ones.
89   bool Pref32BitThumb;
90
91   /// stackAlignment - The minimum alignment known to hold of the stack frame on
92   /// entry to the function and which must be maintained by every function.
93   unsigned stackAlignment;
94
95   /// CPUString - String name of used CPU.
96   std::string CPUString;
97
98   /// Selected instruction itineraries (one entry per itinerary class.)
99   InstrItineraryData InstrItins;
100
101  public:
102   enum {
103     isELF, isDarwin
104   } TargetType;
105
106   enum {
107     ARM_ABI_APCS,
108     ARM_ABI_AAPCS // ARM EABI
109   } TargetABI;
110
111   /// This constructor initializes the data members to match that
112   /// of the specified triple.
113   ///
114   ARMSubtarget(const std::string &TT, const std::string &FS, bool isThumb);
115
116   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
117   /// that still makes it profitable to inline the call.
118   unsigned getMaxInlineSizeThreshold() const {
119     // FIXME: For now, we don't lower memcpy's to loads / stores for Thumb1.
120     // Change this once Thumb1 ldmia / stmia support is added.
121     return isThumb1Only() ? 0 : 64;
122   }
123   /// ParseSubtargetFeatures - Parses features string setting specified
124   /// subtarget options.  Definition of function is auto generated by tblgen.
125   std::string ParseSubtargetFeatures(const std::string &FS,
126                                      const std::string &CPU);
127
128   bool hasV4TOps()  const { return ARMArchVersion >= V4T;  }
129   bool hasV5TOps()  const { return ARMArchVersion >= V5T;  }
130   bool hasV5TEOps() const { return ARMArchVersion >= V5TE; }
131   bool hasV6Ops()   const { return ARMArchVersion >= V6;   }
132   bool hasV6T2Ops() const { return ARMArchVersion >= V6T2; }
133   bool hasV7Ops()   const { return ARMArchVersion >= V7A;  }
134
135   bool hasVFP2() const { return ARMFPUType >= VFPv2; }
136   bool hasVFP3() const { return ARMFPUType >= VFPv3; }
137   bool hasNEON() const { return ARMFPUType >= NEON;  }
138   bool useNEONForSinglePrecisionFP() const {
139     return hasNEON() && UseNEONForSinglePrecisionFP; }
140   bool hasDivide() const { return HasHardwareDivide; }
141   bool hasT2ExtractPack() const { return HasT2ExtractPack; }
142   bool useVMLx() const {return hasVFP2() && !SlowVMLx; }
143   bool isFPBrccSlow() const { return SlowFPBrcc; }
144   bool prefers32BitThumb() const { return Pref32BitThumb; }
145
146   bool hasFP16() const { return HasFP16; }
147
148   bool isTargetDarwin() const { return TargetType == isDarwin; }
149   bool isTargetELF() const { return TargetType == isELF; }
150
151   bool isAPCS_ABI() const { return TargetABI == ARM_ABI_APCS; }
152   bool isAAPCS_ABI() const { return TargetABI == ARM_ABI_AAPCS; }
153
154   bool isThumb() const { return IsThumb; }
155   bool isThumb1Only() const { return IsThumb && (ThumbMode == Thumb1); }
156   bool isThumb2() const { return IsThumb && (ThumbMode == Thumb2); }
157   bool hasThumb2() const { return ThumbMode >= Thumb2; }
158
159   bool isR9Reserved() const { return IsR9Reserved; }
160
161   bool useMovt() const { return UseMovt && hasV6T2Ops(); }
162
163   const std::string & getCPUString() const { return CPUString; }
164
165   /// enablePostRAScheduler - True at 'More' optimization.
166   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
167                              TargetSubtarget::AntiDepBreakMode& Mode,
168                              RegClassVector& CriticalPathRCs) const;
169
170   /// getInstrItins - Return the instruction itineraies based on subtarget
171   /// selection.
172   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
173
174   /// getStackAlignment - Returns the minimum alignment known to hold of the
175   /// stack frame on entry to the function and which must be maintained by every
176   /// function for this subtarget.
177   unsigned getStackAlignment() const { return stackAlignment; }
178
179   /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
180   /// symbol.
181   bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
182 };
183 } // End llvm namespace
184
185 #endif  // ARMSUBTARGET_H