Add support to reduce most of 32-bit Thumb2 arithmetic instructions.
[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/TargetSubtarget.h"
19 #include <string>
20
21 namespace llvm {
22
23 class ARMSubtarget : public TargetSubtarget {
24 protected:
25   enum ARMArchEnum {
26     V4T, V5T, V5TE, V6, V6T2, V7A
27   };
28
29   enum ARMFPEnum {
30     None, VFPv2, VFPv3, NEON
31   };
32
33   enum ThumbTypeEnum {
34     Thumb1,
35     Thumb2
36   };
37
38   /// ARMArchVersion - ARM architecture version: V4T (base), V5T, V5TE,
39   /// V6, V6T2, V7A.
40   ARMArchEnum ARMArchVersion;
41
42   /// ARMFPUType - Floating Point Unit type.
43   ARMFPEnum ARMFPUType;
44
45   /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been
46   /// specified. Use the method useNEONForSinglePrecisionFP() to
47   /// determine if NEON should actually be used.
48   bool UseNEONForSinglePrecisionFP;
49
50   /// IsThumb - True if we are in thumb mode, false if in ARM mode.
51   bool IsThumb;
52
53   /// ThumbMode - Indicates supported Thumb version.
54   ThumbTypeEnum ThumbMode;
55
56   /// IsR9Reserved - True if R9 is a not available as general purpose register.
57   bool IsR9Reserved;
58
59   /// stackAlignment - The minimum alignment known to hold of the stack frame on
60   /// entry to the function and which must be maintained by every function.
61   unsigned stackAlignment;
62
63   /// CPUString - String name of used CPU.
64   std::string CPUString;
65
66   /// Selected instruction itineraries (one entry per itinerary class.)
67   InstrItineraryData InstrItins;
68   
69  public:
70   enum {
71     isELF, isDarwin
72   } TargetType;
73
74   enum {
75     ARM_ABI_APCS,
76     ARM_ABI_AAPCS // ARM EABI
77   } TargetABI;
78
79   /// This constructor initializes the data members to match that
80   /// of the specified triple.
81   ///
82   ARMSubtarget(const std::string &TT, const std::string &FS, bool isThumb);
83
84   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
85   /// that still makes it profitable to inline the call.
86   unsigned getMaxInlineSizeThreshold() const {
87     // FIXME: For now, we don't lower memcpy's to loads / stores for Thumb.
88     // Change this once Thumb ldmia / stmia support is added.
89     return isThumb() ? 0 : 64;
90   }
91   /// ParseSubtargetFeatures - Parses features string setting specified
92   /// subtarget options.  Definition of function is auto generated by tblgen.
93   std::string ParseSubtargetFeatures(const std::string &FS,
94                                      const std::string &CPU);
95
96   bool hasV4TOps()  const { return ARMArchVersion >= V4T;  }
97   bool hasV5TOps()  const { return ARMArchVersion >= V5T;  }
98   bool hasV5TEOps() const { return ARMArchVersion >= V5TE; }
99   bool hasV6Ops()   const { return ARMArchVersion >= V6;   }
100   bool hasV6T2Ops() const { return ARMArchVersion >= V6T2; }
101   bool hasV7Ops()   const { return ARMArchVersion >= V7A;  }
102
103   bool hasVFP2() const { return ARMFPUType >= VFPv2; }
104   bool hasVFP3() const { return ARMFPUType >= VFPv3; }
105   bool hasNEON() const { return ARMFPUType >= NEON;  }
106   bool useNEONForSinglePrecisionFP() const { 
107     return hasNEON() && UseNEONForSinglePrecisionFP; }
108   
109   bool isTargetDarwin() const { return TargetType == isDarwin; }
110   bool isTargetELF() const { return TargetType == isELF; }
111
112   bool isAPCS_ABI() const { return TargetABI == ARM_ABI_APCS; }
113   bool isAAPCS_ABI() const { return TargetABI == ARM_ABI_AAPCS; }
114
115   bool isThumb() const { return IsThumb; }
116   bool isThumb1Only() const { return IsThumb && (ThumbMode == Thumb1); }
117   bool isThumb2() const { return IsThumb && (ThumbMode == Thumb2); }
118   bool hasThumb2() const { return ThumbMode >= Thumb2; }
119
120   bool isR9Reserved() const { return IsR9Reserved; }
121
122   const std::string & getCPUString() const { return CPUString; }
123
124   /// getInstrItins - Return the instruction itineraies based on subtarget 
125   /// selection.
126   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
127
128   /// getStackAlignment - Returns the minimum alignment known to hold of the
129   /// stack frame on entry to the function and which must be maintained by every
130   /// function for this subtarget.
131   unsigned getStackAlignment() const { return stackAlignment; }
132 };
133 } // End llvm namespace
134
135 #endif  // ARMSUBTARGET_H