blob: 8c4f583bdb8fcb1cd80de472c426ae4a07597f45 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- PPCSubtarget.h - Define Subtarget for the PPC ----------*- C++ -*--===//
Nate Begeman3bcfcd92005-08-04 07:12:09 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Nate Begeman3bcfcd92005-08-04 07:12:09 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng0d639a22011-07-01 21:01:15 +000010// This file declares the PowerPC specific subclass of TargetSubtargetInfo.
Nate Begeman3bcfcd92005-08-04 07:12:09 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef POWERPCSUBTARGET_H
15#define POWERPCSUBTARGET_H
16
Eric Christopherd104c312014-06-12 20:54:11 +000017#include "PPCFrameLowering.h"
Eric Christopherbd14dc52014-06-12 22:05:46 +000018#include "PPCInstrInfo.h"
Eric Christopherf8c031f2014-06-12 22:50:10 +000019#include "PPCISelLowering.h"
Eric Christopherf55a2242014-06-12 22:28:06 +000020#include "PPCJITInfo.h"
Eric Christopher02ae6902014-06-12 23:02:32 +000021#include "PPCSelectionDAGInfo.h"
Evan Cheng8264e272011-06-29 01:14:12 +000022#include "llvm/ADT/Triple.h"
Eric Christopher49628bc2014-06-12 21:08:06 +000023#include "llvm/IR/DataLayout.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000024#include "llvm/MC/MCInstrItineraries.h"
25#include "llvm/Target/TargetSubtargetInfo.h"
Jim Laskey19058c32005-09-01 21:38:21 +000026#include <string>
27
Evan Cheng54b68e32011-07-01 20:45:01 +000028#define GET_SUBTARGETINFO_HEADER
Evan Chengc9c090d2011-07-01 22:36:09 +000029#include "PPCGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000030
Nick Lewycky28c5b862007-01-19 04:36:02 +000031// GCC #defines PPC on Linux but we use it as our namespace name
32#undef PPC
33
Nate Begeman3bcfcd92005-08-04 07:12:09 +000034namespace llvm {
Evan Cheng1a72add62011-07-07 07:07:08 +000035class StringRef;
Jim Laskey59e7a772006-12-12 20:57:08 +000036
37namespace PPC {
38 // -m directive values.
39 enum {
Dale Johannesen6ca3ccf2008-02-14 23:35:16 +000040 DIR_NONE,
Jim Laskey59e7a772006-12-12 20:57:08 +000041 DIR_32,
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000042 DIR_440,
43 DIR_601,
44 DIR_602,
45 DIR_603,
Jim Laskey59e7a772006-12-12 20:57:08 +000046 DIR_7400,
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000047 DIR_750,
48 DIR_970,
Hal Finkel9f9f8922012-04-01 19:22:40 +000049 DIR_A2,
Hal Finkel742b5352012-08-28 16:12:39 +000050 DIR_E500mc,
51 DIR_E5500,
Bill Schmidt52742c22013-02-01 22:59:51 +000052 DIR_PWR3,
53 DIR_PWR4,
54 DIR_PWR5,
55 DIR_PWR5X,
Hal Finkelf2b9c382012-06-11 15:43:08 +000056 DIR_PWR6,
Bill Schmidt52742c22013-02-01 22:59:51 +000057 DIR_PWR6X,
Hal Finkelf2b9c382012-06-11 15:43:08 +000058 DIR_PWR7,
Will Schmidt970ff642014-06-26 13:36:19 +000059 DIR_PWR8,
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000060 DIR_64
Jim Laskey59e7a772006-12-12 20:57:08 +000061 };
62}
63
Chris Lattnerf4646a72006-12-11 23:22:45 +000064class GlobalValue;
65class TargetMachine;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000066
Evan Cheng54b68e32011-07-01 20:45:01 +000067class PPCSubtarget : public PPCGenSubtargetInfo {
Nate Begeman3bcfcd92005-08-04 07:12:09 +000068protected:
69 /// stackAlignment - The minimum alignment known to hold of the stack frame on
70 /// entry to the function and which must be maintained by every function.
Chris Lattner983a4152005-08-05 22:05:03 +000071 unsigned StackAlignment;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000072
Jim Laskey802748c2005-11-01 20:06:59 +000073 /// Selected instruction itineraries (one entry per itinerary class.)
74 InstrItineraryData InstrItins;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000075
Jim Laskey59e7a772006-12-12 20:57:08 +000076 /// Which cpu directive was used.
77 unsigned DarwinDirective;
Nate Begeman3bcfcd92005-08-04 07:12:09 +000078
79 /// Used by the ISel to turn in optimizations for POWER4-derived architectures
Hal Finkelbfd3d082012-06-11 19:57:01 +000080 bool HasMFOCRF;
Chris Lattnera35f3062006-06-16 17:34:12 +000081 bool Has64BitSupport;
82 bool Use64BitRegs;
Hal Finkel940ab932014-02-28 00:27:01 +000083 bool UseCRBits;
Chris Lattner16682ff2006-06-16 17:50:12 +000084 bool IsPPC64;
Jim Laskeya2b52352005-10-26 17:30:34 +000085 bool HasAltivec;
Hal Finkelefb305e2013-01-30 21:17:42 +000086 bool HasQPX;
Eric Christopher081efcc2013-10-16 20:38:58 +000087 bool HasVSX;
Hal Finkeldbc78e12013-08-19 05:01:02 +000088 bool HasFCPSGN;
Chris Lattneraa3b1fc2005-09-02 18:33:05 +000089 bool HasFSQRT;
Hal Finkel2e103312013-04-03 04:01:11 +000090 bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
91 bool HasRecipPrec;
Chris Lattnerb9f35f02006-02-28 07:08:22 +000092 bool HasSTFIWX;
Hal Finkelbeb296b2013-03-31 10:12:51 +000093 bool HasLFIWAX;
Hal Finkelc20a08d2013-03-29 08:57:48 +000094 bool HasFPRND;
Hal Finkelf6d45f22013-04-01 17:52:07 +000095 bool HasFPCVT;
Hal Finkel460e94d2012-06-22 23:10:08 +000096 bool HasISEL;
Hal Finkela4d07482013-03-28 13:29:47 +000097 bool HasPOPCNTD;
Hal Finkel31d29562013-03-28 19:25:55 +000098 bool HasLDBRX;
Hal Finkel6fa56972011-10-17 04:03:49 +000099 bool IsBookE;
Hal Finkel0096dbd2013-09-12 14:40:06 +0000100 bool DeprecatedMFTB;
101 bool DeprecatedDST;
Chris Lattnerf4646a72006-12-11 23:22:45 +0000102 bool HasLazyResolverStubs;
Torok Edwin31e90d22010-08-04 20:47:44 +0000103 bool IsJITCodeModel;
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000104 bool IsLittleEndian;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000105
Daniel Dunbara37aab22011-04-19 20:54:28 +0000106 /// TargetTriple - What processor and OS we're targeting.
107 Triple TargetTriple;
108
Eric Christopherd1309ee2014-05-13 20:49:08 +0000109 /// OptLevel - What default optimization level we're emitting code for.
110 CodeGenOpt::Level OptLevel;
111
Ulrich Weigand90a5de82014-07-28 13:09:28 +0000112 enum {
113 PPC_ABI_UNKNOWN,
114 PPC_ABI_ELFv1,
115 PPC_ABI_ELFv2
116 } TargetABI;
117
Eric Christopherf55a2242014-06-12 22:28:06 +0000118 PPCFrameLowering FrameLowering;
Eric Christopher49628bc2014-06-12 21:08:06 +0000119 const DataLayout DL;
Eric Christopherbd14dc52014-06-12 22:05:46 +0000120 PPCInstrInfo InstrInfo;
Eric Christopherf55a2242014-06-12 22:28:06 +0000121 PPCJITInfo JITInfo;
Eric Christopherf8c031f2014-06-12 22:50:10 +0000122 PPCTargetLowering TLInfo;
Eric Christopher02ae6902014-06-12 23:02:32 +0000123 PPCSelectionDAGInfo TSInfo;
Eric Christopher49628bc2014-06-12 21:08:06 +0000124
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000125public:
126 /// This constructor initializes the data members to match that
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000127 /// of the specified triple.
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000128 ///
Evan Chengfe6e4052011-06-30 01:53:36 +0000129 PPCSubtarget(const std::string &TT, const std::string &CPU,
Eric Christopherf8c031f2014-06-12 22:50:10 +0000130 const std::string &FS, PPCTargetMachine &TM, bool is64Bit,
Hal Finkel940ab932014-02-28 00:27:01 +0000131 CodeGenOpt::Level OptLevel);
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000132
133 /// ParseSubtargetFeatures - Parses features string setting specified
Jim Laskey75eab3c2005-10-26 18:07:50 +0000134 /// subtarget options. Definition of function is auto generated by tblgen.
Evan Cheng1a72add62011-07-07 07:07:08 +0000135 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000136
Chris Lattnerf4646a72006-12-11 23:22:45 +0000137 /// SetJITMode - This is called to inform the subtarget info that we are
138 /// producing code for the JIT.
139 void SetJITMode();
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000140
141 /// getStackAlignment - Returns the minimum alignment known to hold of the
142 /// stack frame on entry to the function and which must be maintained by every
143 /// function for this subtarget.
Chris Lattner983a4152005-08-05 22:05:03 +0000144 unsigned getStackAlignment() const { return StackAlignment; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000145
Jim Laskey59e7a772006-12-12 20:57:08 +0000146 /// getDarwinDirective - Returns the -m directive specified for the cpu.
147 ///
148 unsigned getDarwinDirective() const { return DarwinDirective; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000149
Eric Christopher170ebcf2014-06-13 22:38:48 +0000150 /// getInstrItins - Return the instruction itineraries based on subtarget
Jim Laskey802748c2005-11-01 20:06:59 +0000151 /// selection.
Chris Lattnerb1f31572006-12-11 21:42:55 +0000152 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
Chris Lattner16682ff2006-06-16 17:50:12 +0000153
Eric Christopherd104c312014-06-12 20:54:11 +0000154 const PPCFrameLowering *getFrameLowering() const { return &FrameLowering; }
Eric Christopher49628bc2014-06-12 21:08:06 +0000155 const DataLayout *getDataLayout() const { return &DL; }
Eric Christopherbd14dc52014-06-12 22:05:46 +0000156 const PPCInstrInfo *getInstrInfo() const { return &InstrInfo; }
Eric Christopherf55a2242014-06-12 22:28:06 +0000157 PPCJITInfo *getJITInfo() { return &JITInfo; }
Eric Christopherf8c031f2014-06-12 22:50:10 +0000158 const PPCTargetLowering *getTargetLowering() const { return &TLInfo; }
Eric Christopher02ae6902014-06-12 23:02:32 +0000159 const PPCSelectionDAGInfo *getSelectionDAGInfo() const { return &TSInfo; }
Eric Christopherd104c312014-06-12 20:54:11 +0000160
161 /// initializeSubtargetDependencies - Initializes using a CPU and feature string
162 /// so that we can use initializer lists for subtarget initialization.
163 PPCSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
164
Hal Finkela0014a52013-07-15 22:29:40 +0000165 /// \brief Reset the features for the PowerPC target.
Craig Topper0d3fa922014-04-29 07:57:37 +0000166 void resetSubtargetFeatures(const MachineFunction *MF) override;
Hal Finkela0014a52013-07-15 22:29:40 +0000167private:
168 void initializeEnvironment();
169 void resetSubtargetFeatures(StringRef CPU, StringRef FS);
170
171public:
Chris Lattner16682ff2006-06-16 17:50:12 +0000172 /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
173 ///
174 bool isPPC64() const { return IsPPC64; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000175
Chris Lattner16682ff2006-06-16 17:50:12 +0000176 /// has64BitSupport - Return true if the selected CPU supports 64-bit
177 /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
178 bool has64BitSupport() const { return Has64BitSupport; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000179
Chris Lattner16682ff2006-06-16 17:50:12 +0000180 /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
181 /// registers in 32-bit mode when possible. This can only true if
182 /// has64BitSupport() returns true.
183 bool use64BitRegs() const { return Use64BitRegs; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000184
Hal Finkel940ab932014-02-28 00:27:01 +0000185 /// useCRBits - Return true if we should store and manipulate i1 values in
186 /// the individual condition register bits.
187 bool useCRBits() const { return UseCRBits; }
188
Chris Lattnerf4646a72006-12-11 23:22:45 +0000189 /// hasLazyResolverStub - Return true if accesses to the specified global have
190 /// to go through a dyld lazy resolution stub. This means that an extra load
191 /// is required to get the address of the global.
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000192 bool hasLazyResolverStub(const GlobalValue *GV,
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000193 const TargetMachine &TM) const;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000194
Torok Edwin31e90d22010-08-04 20:47:44 +0000195 // isJITCodeModel - True if we're generating code for the JIT
196 bool isJITCodeModel() const { return IsJITCodeModel; }
197
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000198 // isLittleEndian - True if generating little-endian code
199 bool isLittleEndian() const { return IsLittleEndian; }
200
Chris Lattner16682ff2006-06-16 17:50:12 +0000201 // Specific obvious features.
Hal Finkeldbc78e12013-08-19 05:01:02 +0000202 bool hasFCPSGN() const { return HasFCPSGN; }
Chris Lattneraa3b1fc2005-09-02 18:33:05 +0000203 bool hasFSQRT() const { return HasFSQRT; }
Hal Finkel2e103312013-04-03 04:01:11 +0000204 bool hasFRE() const { return HasFRE; }
205 bool hasFRES() const { return HasFRES; }
206 bool hasFRSQRTE() const { return HasFRSQRTE; }
207 bool hasFRSQRTES() const { return HasFRSQRTES; }
208 bool hasRecipPrec() const { return HasRecipPrec; }
Chris Lattnerb9f35f02006-02-28 07:08:22 +0000209 bool hasSTFIWX() const { return HasSTFIWX; }
Hal Finkelbeb296b2013-03-31 10:12:51 +0000210 bool hasLFIWAX() const { return HasLFIWAX; }
Hal Finkelc20a08d2013-03-29 08:57:48 +0000211 bool hasFPRND() const { return HasFPRND; }
Hal Finkelf6d45f22013-04-01 17:52:07 +0000212 bool hasFPCVT() const { return HasFPCVT; }
Jim Laskeya2b52352005-10-26 17:30:34 +0000213 bool hasAltivec() const { return HasAltivec; }
Hal Finkelefb305e2013-01-30 21:17:42 +0000214 bool hasQPX() const { return HasQPX; }
Hal Finkel27774d92014-03-13 07:58:58 +0000215 bool hasVSX() const { return HasVSX; }
Hal Finkelbfd3d082012-06-11 19:57:01 +0000216 bool hasMFOCRF() const { return HasMFOCRF; }
Hal Finkel460e94d2012-06-22 23:10:08 +0000217 bool hasISEL() const { return HasISEL; }
Hal Finkela4d07482013-03-28 13:29:47 +0000218 bool hasPOPCNTD() const { return HasPOPCNTD; }
Hal Finkel31d29562013-03-28 19:25:55 +0000219 bool hasLDBRX() const { return HasLDBRX; }
Hal Finkel6fa56972011-10-17 04:03:49 +0000220 bool isBookE() const { return IsBookE; }
Hal Finkel0096dbd2013-09-12 14:40:06 +0000221 bool isDeprecatedMFTB() const { return DeprecatedMFTB; }
222 bool isDeprecatedDST() const { return DeprecatedDST; }
Bill Wendlingc7b2ab92007-01-16 09:29:17 +0000223
Daniel Dunbara37aab22011-04-19 20:54:28 +0000224 const Triple &getTargetTriple() const { return TargetTriple; }
225
Chris Lattnerdcbc0f32008-01-02 19:35:16 +0000226 /// isDarwin - True if this is any darwin platform.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000227 bool isDarwin() const { return TargetTriple.isMacOSX(); }
Hal Finkel7f9e8d32013-01-29 00:22:47 +0000228 /// isBGQ - True if this is a BG/Q platform.
229 bool isBGQ() const { return TargetTriple.getVendor() == Triple::BGQ; }
Rafael Espindola770b4b82008-12-19 10:55:56 +0000230
Hal Finkel3ee2af72014-07-18 23:29:49 +0000231 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
232 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
233
Tilmann Schellerd1aaa322009-08-15 11:54:46 +0000234 bool isDarwinABI() const { return isDarwin(); }
235 bool isSVR4ABI() const { return !isDarwin(); }
Ulrich Weigand90a5de82014-07-28 13:09:28 +0000236 bool isELFv2ABI() const { return TargetABI == PPC_ABI_ELFv2; }
Tilmann Schellerd1aaa322009-08-15 11:54:46 +0000237
Eric Christopher6b0fcfe2014-05-21 23:40:26 +0000238 bool enableEarlyIfConversion() const override { return hasISEL(); }
239
Hal Finkel21442b22013-09-11 23:05:25 +0000240 // Scheduling customization.
Craig Topper0d3fa922014-04-29 07:57:37 +0000241 bool enableMachineScheduler() const override;
Sanjay Patela2f658d2014-07-15 22:39:58 +0000242 // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
243 bool enablePostMachineScheduler() const override;
244 AntiDepBreakMode getAntiDepBreakMode() const override;
245 void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
246
Hal Finkel21442b22013-09-11 23:05:25 +0000247 void overrideSchedPolicy(MachineSchedPolicy &Policy,
248 MachineInstr *begin,
249 MachineInstr *end,
Craig Topper0d3fa922014-04-29 07:57:37 +0000250 unsigned NumRegionInstrs) const override;
251 bool useAA() const override;
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000252};
253} // End llvm namespace
254
255#endif