| Nate Begeman | 6cca84e | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1 | //=====-- PPCSubtarget.h - Define Subtarget for the PPC -------*- C++ -*--====// | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
| Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
| Andrew Lenharth | bae1f9d | 2005-09-29 21:11:57 +0000 | [diff] [blame] | 10 | // This file declares the PowerPC specific subclass of TargetSubtarget. | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
|  | 13 |  | 
|  | 14 | #ifndef POWERPCSUBTARGET_H | 
|  | 15 | #define POWERPCSUBTARGET_H | 
|  | 16 |  | 
| Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetInstrItineraries.h" | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetSubtarget.h" | 
|  | 19 |  | 
| Jim Laskey | 19058c3 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 20 | #include <string> | 
|  | 21 |  | 
| Nick Lewycky | 28c5b86 | 2007-01-19 04:36:02 +0000 | [diff] [blame] | 22 | // GCC #defines PPC on Linux but we use it as our namespace name | 
|  | 23 | #undef PPC | 
|  | 24 |  | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 25 | namespace llvm { | 
| Jim Laskey | 59e7a77 | 2006-12-12 20:57:08 +0000 | [diff] [blame] | 26 |  | 
|  | 27 | namespace PPC { | 
|  | 28 | // -m directive values. | 
|  | 29 | enum { | 
| Dale Johannesen | 6ca3ccf | 2008-02-14 23:35:16 +0000 | [diff] [blame] | 30 | DIR_NONE, | 
| Jim Laskey | 59e7a77 | 2006-12-12 20:57:08 +0000 | [diff] [blame] | 31 | DIR_32, | 
|  | 32 | DIR_601, | 
|  | 33 | DIR_602, | 
|  | 34 | DIR_603, | 
|  | 35 | DIR_7400, | 
|  | 36 | DIR_750, | 
|  | 37 | DIR_970, | 
|  | 38 | DIR_64 | 
|  | 39 | }; | 
|  | 40 | } | 
|  | 41 |  | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 42 | class Module; | 
| Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 43 | class GlobalValue; | 
|  | 44 | class TargetMachine; | 
|  | 45 |  | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 46 | class PPCSubtarget : public TargetSubtarget { | 
| Bill Wendling | c7b2ab9 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 47 | public: | 
|  | 48 | enum AsmWriterFlavorTy { | 
|  | 49 | OldMnemonic, NewMnemonic, Unset | 
|  | 50 | }; | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 51 | protected: | 
| Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 52 | const TargetMachine &TM; | 
|  | 53 |  | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 54 | /// stackAlignment - The minimum alignment known to hold of the stack frame on | 
|  | 55 | /// entry to the function and which must be maintained by every function. | 
| Chris Lattner | 983a415 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 56 | unsigned StackAlignment; | 
| Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 57 |  | 
|  | 58 | /// Selected instruction itineraries (one entry per itinerary class.) | 
|  | 59 | InstrItineraryData InstrItins; | 
| Jim Laskey | 59e7a77 | 2006-12-12 20:57:08 +0000 | [diff] [blame] | 60 |  | 
|  | 61 | /// Which cpu directive was used. | 
|  | 62 | unsigned DarwinDirective; | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 63 |  | 
| Bill Wendling | c7b2ab9 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 64 | /// AsmFlavor - Which PPC asm dialect to use. | 
|  | 65 | AsmWriterFlavorTy AsmFlavor; | 
|  | 66 |  | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 67 | /// Used by the ISel to turn in optimizations for POWER4-derived architectures | 
| Chris Lattner | 983a415 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 68 | bool IsGigaProcessor; | 
| Chris Lattner | a35f306 | 2006-06-16 17:34:12 +0000 | [diff] [blame] | 69 | bool Has64BitSupport; | 
|  | 70 | bool Use64BitRegs; | 
| Chris Lattner | 16682ff | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 71 | bool IsPPC64; | 
| Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 72 | bool HasAltivec; | 
| Chris Lattner | aa3b1fc | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 73 | bool HasFSQRT; | 
| Chris Lattner | b9f35f0 | 2006-02-28 07:08:22 +0000 | [diff] [blame] | 74 | bool HasSTFIWX; | 
| Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 75 | bool HasLazyResolverStubs; | 
| Chris Lattner | dcbc0f3 | 2008-01-02 19:35:16 +0000 | [diff] [blame] | 76 |  | 
|  | 77 | /// DarwinVers - Nonzero if this is a darwin platform.  Otherwise, the numeric | 
|  | 78 | /// version of the platform, e.g. 8 = 10.4 (Tiger), 9 = 10.5 (Leopard), etc. | 
|  | 79 | unsigned char DarwinVers; // Is any darwin-ppc platform. | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 80 | public: | 
|  | 81 | /// This constructor initializes the data members to match that | 
|  | 82 | /// of the specified module. | 
|  | 83 | /// | 
| Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 84 | PPCSubtarget(const TargetMachine &TM, const Module &M, | 
|  | 85 | const std::string &FS, bool is64Bit); | 
| Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 86 |  | 
|  | 87 | /// ParseSubtargetFeatures - Parses features string setting specified | 
| Jim Laskey | 75eab3c | 2005-10-26 18:07:50 +0000 | [diff] [blame] | 88 | /// subtarget options.  Definition of function is auto generated by tblgen. | 
| Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 89 | void ParseSubtargetFeatures(const std::string &FS, const std::string &CPU); | 
| Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 90 |  | 
|  | 91 | /// SetJITMode - This is called to inform the subtarget info that we are | 
|  | 92 | /// producing code for the JIT. | 
|  | 93 | void SetJITMode(); | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 94 |  | 
|  | 95 | /// getStackAlignment - Returns the minimum alignment known to hold of the | 
|  | 96 | /// stack frame on entry to the function and which must be maintained by every | 
|  | 97 | /// function for this subtarget. | 
| Chris Lattner | 983a415 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 98 | unsigned getStackAlignment() const { return StackAlignment; } | 
| Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 99 |  | 
| Jim Laskey | 59e7a77 | 2006-12-12 20:57:08 +0000 | [diff] [blame] | 100 | /// getDarwinDirective - Returns the -m directive specified for the cpu. | 
|  | 101 | /// | 
|  | 102 | unsigned getDarwinDirective() const { return DarwinDirective; } | 
|  | 103 |  | 
| Jim Laskey | 802748c | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 104 | /// getInstrItins - Return the instruction itineraies based on subtarget | 
|  | 105 | /// selection. | 
| Chris Lattner | b1f3157 | 2006-12-11 21:42:55 +0000 | [diff] [blame] | 106 | const InstrItineraryData &getInstrItineraryData() const { return InstrItins; } | 
| Chris Lattner | 16682ff | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 107 |  | 
|  | 108 | /// getTargetDataString - Return the pointer size and type alignment | 
|  | 109 | /// properties of this subtarget. | 
| Chris Lattner | 0c4aa14 | 2006-06-16 01:37:27 +0000 | [diff] [blame] | 110 | const char *getTargetDataString() const { | 
| Dale Johannesen | c5283ec | 2007-08-03 20:20:50 +0000 | [diff] [blame] | 111 | return isPPC64() ? "E-p:64:64-f64:32:64-i64:32:64-f128:64:128" | 
|  | 112 | : "E-p:32:32-f64:32:64-i64:32:64-f128:64:128"; | 
| Chris Lattner | 0c4aa14 | 2006-06-16 01:37:27 +0000 | [diff] [blame] | 113 | } | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 114 |  | 
| Chris Lattner | 16682ff | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 115 | /// isPPC64 - Return true if we are generating code for 64-bit pointer mode. | 
|  | 116 | /// | 
|  | 117 | bool isPPC64() const { return IsPPC64; } | 
|  | 118 |  | 
|  | 119 | /// has64BitSupport - Return true if the selected CPU supports 64-bit | 
|  | 120 | /// instructions, regardless of whether we are in 32-bit or 64-bit mode. | 
|  | 121 | bool has64BitSupport() const { return Has64BitSupport; } | 
|  | 122 |  | 
|  | 123 | /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit | 
|  | 124 | /// registers in 32-bit mode when possible.  This can only true if | 
|  | 125 | /// has64BitSupport() returns true. | 
|  | 126 | bool use64BitRegs() const { return Use64BitRegs; } | 
|  | 127 |  | 
| Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 128 | /// hasLazyResolverStub - Return true if accesses to the specified global have | 
|  | 129 | /// to go through a dyld lazy resolution stub.  This means that an extra load | 
|  | 130 | /// is required to get the address of the global. | 
|  | 131 | bool hasLazyResolverStub(const GlobalValue *GV) const; | 
| Chris Lattner | 16682ff | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 132 |  | 
|  | 133 | // Specific obvious features. | 
| Chris Lattner | aa3b1fc | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 134 | bool hasFSQRT() const { return HasFSQRT; } | 
| Chris Lattner | b9f35f0 | 2006-02-28 07:08:22 +0000 | [diff] [blame] | 135 | bool hasSTFIWX() const { return HasSTFIWX; } | 
| Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 136 | bool hasAltivec() const { return HasAltivec; } | 
| Chris Lattner | 16682ff | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 137 | bool isGigaProcessor() const { return IsGigaProcessor; } | 
| Bill Wendling | c7b2ab9 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 138 |  | 
| Chris Lattner | dcbc0f3 | 2008-01-02 19:35:16 +0000 | [diff] [blame] | 139 | /// isDarwin - True if this is any darwin platform. | 
|  | 140 | bool isDarwin() const { return DarwinVers != 0; } | 
|  | 141 | /// isDarwin - True if this is darwin9 (leopard, 10.5) or above. | 
|  | 142 | bool isDarwin9() const { return DarwinVers >= 9; } | 
| Bill Wendling | c7b2ab9 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 143 |  | 
| Chris Lattner | dcbc0f3 | 2008-01-02 19:35:16 +0000 | [diff] [blame] | 144 | bool isMachoABI() const { return isDarwin() || IsPPC64; } | 
|  | 145 | bool isELF32_ABI() const { return !isDarwin() && !IsPPC64; } | 
| Chris Lattner | 249edb8 | 2007-02-25 05:04:13 +0000 | [diff] [blame] | 146 |  | 
| Bill Wendling | c7b2ab9 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 147 | unsigned getAsmFlavor() const { | 
|  | 148 | return AsmFlavor != Unset ? unsigned(AsmFlavor) : 0; | 
|  | 149 | } | 
| Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 150 | }; | 
|  | 151 | } // End llvm namespace | 
|  | 152 |  | 
|  | 153 | #endif |