blob: 3958bc9c006e0677b952cc0faa40db45c8fb64e7 [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
Evan Cheng8264e272011-06-29 01:14:12 +000017#include "llvm/ADT/Triple.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000018#include "llvm/MC/MCInstrItineraries.h"
19#include "llvm/Target/TargetSubtargetInfo.h"
Jim Laskey19058c32005-09-01 21:38:21 +000020#include <string>
21
Evan Cheng54b68e32011-07-01 20:45:01 +000022#define GET_SUBTARGETINFO_HEADER
Evan Chengc9c090d2011-07-01 22:36:09 +000023#include "PPCGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000024
Nick Lewycky28c5b862007-01-19 04:36:02 +000025// GCC #defines PPC on Linux but we use it as our namespace name
26#undef PPC
27
Nate Begeman3bcfcd92005-08-04 07:12:09 +000028namespace llvm {
Evan Cheng1a72add62011-07-07 07:07:08 +000029class StringRef;
Jim Laskey59e7a772006-12-12 20:57:08 +000030
31namespace PPC {
32 // -m directive values.
33 enum {
Dale Johannesen6ca3ccf2008-02-14 23:35:16 +000034 DIR_NONE,
Jim Laskey59e7a772006-12-12 20:57:08 +000035 DIR_32,
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000036 DIR_440,
37 DIR_601,
38 DIR_602,
39 DIR_603,
Jim Laskey59e7a772006-12-12 20:57:08 +000040 DIR_7400,
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000041 DIR_750,
42 DIR_970,
Hal Finkel9f9f8922012-04-01 19:22:40 +000043 DIR_A2,
Hal Finkel742b5352012-08-28 16:12:39 +000044 DIR_E500mc,
45 DIR_E5500,
Bill Schmidt52742c22013-02-01 22:59:51 +000046 DIR_PWR3,
47 DIR_PWR4,
48 DIR_PWR5,
49 DIR_PWR5X,
Hal Finkelf2b9c382012-06-11 15:43:08 +000050 DIR_PWR6,
Bill Schmidt52742c22013-02-01 22:59:51 +000051 DIR_PWR6X,
Hal Finkelf2b9c382012-06-11 15:43:08 +000052 DIR_PWR7,
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000053 DIR_64
Jim Laskey59e7a772006-12-12 20:57:08 +000054 };
55}
56
Chris Lattnerf4646a72006-12-11 23:22:45 +000057class GlobalValue;
58class TargetMachine;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000059
Evan Cheng54b68e32011-07-01 20:45:01 +000060class PPCSubtarget : public PPCGenSubtargetInfo {
Nate Begeman3bcfcd92005-08-04 07:12:09 +000061protected:
62 /// stackAlignment - The minimum alignment known to hold of the stack frame on
63 /// entry to the function and which must be maintained by every function.
Chris Lattner983a4152005-08-05 22:05:03 +000064 unsigned StackAlignment;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000065
Jim Laskey802748c2005-11-01 20:06:59 +000066 /// Selected instruction itineraries (one entry per itinerary class.)
67 InstrItineraryData InstrItins;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000068
Jim Laskey59e7a772006-12-12 20:57:08 +000069 /// Which cpu directive was used.
70 unsigned DarwinDirective;
Nate Begeman3bcfcd92005-08-04 07:12:09 +000071
72 /// Used by the ISel to turn in optimizations for POWER4-derived architectures
Hal Finkelbfd3d082012-06-11 19:57:01 +000073 bool HasMFOCRF;
Chris Lattnera35f3062006-06-16 17:34:12 +000074 bool Has64BitSupport;
75 bool Use64BitRegs;
Chris Lattner16682ff2006-06-16 17:50:12 +000076 bool IsPPC64;
Jim Laskeya2b52352005-10-26 17:30:34 +000077 bool HasAltivec;
Hal Finkelefb305e2013-01-30 21:17:42 +000078 bool HasQPX;
Chris Lattneraa3b1fc2005-09-02 18:33:05 +000079 bool HasFSQRT;
Chris Lattnerb9f35f02006-02-28 07:08:22 +000080 bool HasSTFIWX;
Hal Finkelbeb296b2013-03-31 10:12:51 +000081 bool HasLFIWAX;
Hal Finkelc20a08d2013-03-29 08:57:48 +000082 bool HasFPRND;
Hal Finkel460e94d2012-06-22 23:10:08 +000083 bool HasISEL;
Hal Finkela4d07482013-03-28 13:29:47 +000084 bool HasPOPCNTD;
Hal Finkel31d29562013-03-28 19:25:55 +000085 bool HasLDBRX;
Hal Finkel6fa56972011-10-17 04:03:49 +000086 bool IsBookE;
Chris Lattnerf4646a72006-12-11 23:22:45 +000087 bool HasLazyResolverStubs;
Torok Edwin31e90d22010-08-04 20:47:44 +000088 bool IsJITCodeModel;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000089
Daniel Dunbara37aab22011-04-19 20:54:28 +000090 /// TargetTriple - What processor and OS we're targeting.
91 Triple TargetTriple;
92
Nate Begeman3bcfcd92005-08-04 07:12:09 +000093public:
94 /// This constructor initializes the data members to match that
Daniel Dunbar31b44e82009-08-02 22:11:08 +000095 /// of the specified triple.
Nate Begeman3bcfcd92005-08-04 07:12:09 +000096 ///
Evan Chengfe6e4052011-06-30 01:53:36 +000097 PPCSubtarget(const std::string &TT, const std::string &CPU,
98 const std::string &FS, bool is64Bit);
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +000099
100 /// ParseSubtargetFeatures - Parses features string setting specified
Jim Laskey75eab3c2005-10-26 18:07:50 +0000101 /// subtarget options. Definition of function is auto generated by tblgen.
Evan Cheng1a72add62011-07-07 07:07:08 +0000102 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000103
Chris Lattnerf4646a72006-12-11 23:22:45 +0000104 /// SetJITMode - This is called to inform the subtarget info that we are
105 /// producing code for the JIT.
106 void SetJITMode();
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000107
108 /// getStackAlignment - Returns the minimum alignment known to hold of the
109 /// stack frame on entry to the function and which must be maintained by every
110 /// function for this subtarget.
Chris Lattner983a4152005-08-05 22:05:03 +0000111 unsigned getStackAlignment() const { return StackAlignment; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000112
Jim Laskey59e7a772006-12-12 20:57:08 +0000113 /// getDarwinDirective - Returns the -m directive specified for the cpu.
114 ///
115 unsigned getDarwinDirective() const { return DarwinDirective; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000116
117 /// getInstrItins - Return the instruction itineraies based on subtarget
Jim Laskey802748c2005-11-01 20:06:59 +0000118 /// selection.
Chris Lattnerb1f31572006-12-11 21:42:55 +0000119 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
Chris Lattner16682ff2006-06-16 17:50:12 +0000120
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000121 /// getDataLayoutString - Return the pointer size and type alignment
Chris Lattner16682ff2006-06-16 17:50:12 +0000122 /// properties of this subtarget.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000123 const char *getDataLayoutString() const {
Dale Johannesen4609dbe2009-02-27 00:56:35 +0000124 // Note, the alignment values for f64 and i64 on ppc64 in Darwin
125 // documentation are wrong; these are correct (i.e. "what gcc does").
NAKAMURA Takumi4bd79922012-10-29 15:51:42 +0000126 if (isPPC64() && isSVR4ABI()) {
Bill Schmidtbbc661e2012-10-29 14:59:36 +0000127 if (TargetTriple.getOS() == llvm::Triple::FreeBSD)
128 return "E-p:64:64-f64:64:64-i64:64:64-f128:64:64-v128:128:128-n32:64";
129 else
130 return "E-p:64:64-f64:64:64-i64:64:64-f128:128:128-v128:128:128-n32:64";
NAKAMURA Takumi4bd79922012-10-29 15:51:42 +0000131 }
Bill Schmidtbbc661e2012-10-29 14:59:36 +0000132
Chris Lattner87143482009-11-07 19:07:32 +0000133 return isPPC64() ? "E-p:64:64-f64:64:64-i64:64:64-f128:64:128-n32:64"
Roman Divacky075491f2011-07-03 16:24:07 +0000134 : "E-p:32:32-f64:64:64-i64:64:64-f128:64:128-n32";
Chris Lattner0c4aa142006-06-16 01:37:27 +0000135 }
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000136
Chris Lattner16682ff2006-06-16 17:50:12 +0000137 /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
138 ///
139 bool isPPC64() const { return IsPPC64; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000140
Chris Lattner16682ff2006-06-16 17:50:12 +0000141 /// has64BitSupport - Return true if the selected CPU supports 64-bit
142 /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
143 bool has64BitSupport() const { return Has64BitSupport; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000144
Chris Lattner16682ff2006-06-16 17:50:12 +0000145 /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
146 /// registers in 32-bit mode when possible. This can only true if
147 /// has64BitSupport() returns true.
148 bool use64BitRegs() const { return Use64BitRegs; }
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000149
Chris Lattnerf4646a72006-12-11 23:22:45 +0000150 /// hasLazyResolverStub - Return true if accesses to the specified global have
151 /// to go through a dyld lazy resolution stub. This means that an extra load
152 /// is required to get the address of the global.
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000153 bool hasLazyResolverStub(const GlobalValue *GV,
Daniel Dunbar31b44e82009-08-02 22:11:08 +0000154 const TargetMachine &TM) const;
NAKAMURA Takumi70b25de2012-10-29 15:51:35 +0000155
Torok Edwin31e90d22010-08-04 20:47:44 +0000156 // isJITCodeModel - True if we're generating code for the JIT
157 bool isJITCodeModel() const { return IsJITCodeModel; }
158
Chris Lattner16682ff2006-06-16 17:50:12 +0000159 // Specific obvious features.
Chris Lattneraa3b1fc2005-09-02 18:33:05 +0000160 bool hasFSQRT() const { return HasFSQRT; }
Chris Lattnerb9f35f02006-02-28 07:08:22 +0000161 bool hasSTFIWX() const { return HasSTFIWX; }
Hal Finkelbeb296b2013-03-31 10:12:51 +0000162 bool hasLFIWAX() const { return HasLFIWAX; }
Hal Finkelc20a08d2013-03-29 08:57:48 +0000163 bool hasFPRND() const { return HasFPRND; }
Jim Laskeya2b52352005-10-26 17:30:34 +0000164 bool hasAltivec() const { return HasAltivec; }
Hal Finkelefb305e2013-01-30 21:17:42 +0000165 bool hasQPX() const { return HasQPX; }
Hal Finkelbfd3d082012-06-11 19:57:01 +0000166 bool hasMFOCRF() const { return HasMFOCRF; }
Hal Finkel460e94d2012-06-22 23:10:08 +0000167 bool hasISEL() const { return HasISEL; }
Hal Finkela4d07482013-03-28 13:29:47 +0000168 bool hasPOPCNTD() const { return HasPOPCNTD; }
Hal Finkel31d29562013-03-28 19:25:55 +0000169 bool hasLDBRX() const { return HasLDBRX; }
Hal Finkel6fa56972011-10-17 04:03:49 +0000170 bool isBookE() const { return IsBookE; }
Bill Wendlingc7b2ab92007-01-16 09:29:17 +0000171
Daniel Dunbara37aab22011-04-19 20:54:28 +0000172 const Triple &getTargetTriple() const { return TargetTriple; }
173
Chris Lattnerdcbc0f32008-01-02 19:35:16 +0000174 /// isDarwin - True if this is any darwin platform.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000175 bool isDarwin() const { return TargetTriple.isMacOSX(); }
Hal Finkel7591afa2012-04-02 19:09:04 +0000176 /// isBGP - True if this is a BG/P platform.
177 bool isBGP() const { return TargetTriple.getVendor() == Triple::BGP; }
Hal Finkel7f9e8d32013-01-29 00:22:47 +0000178 /// isBGQ - True if this is a BG/Q platform.
179 bool isBGQ() const { return TargetTriple.getVendor() == Triple::BGQ; }
Rafael Espindola770b4b82008-12-19 10:55:56 +0000180
Tilmann Schellerd1aaa322009-08-15 11:54:46 +0000181 bool isDarwinABI() const { return isDarwin(); }
182 bool isSVR4ABI() const { return !isDarwin(); }
183
Hal Finkel58ca3602011-12-02 04:58:02 +0000184 /// enablePostRAScheduler - True at 'More' optimization.
185 bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
186 TargetSubtargetInfo::AntiDepBreakMode& Mode,
187 RegClassVector& CriticalPathRCs) const;
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000188};
189} // End llvm namespace
190
191#endif