blob: 33b21dba1ca24146a2b72fe5e40e1997fd2e3982 [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//=====-- PPCSubtarget.h - Define Subtarget for the PPC -------*- C++ -*--====//
Nate Begeman8c00f8c2005-08-04 07:12:09 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Begeman8c00f8c2005-08-04 07:12:09 +00007//
8//===----------------------------------------------------------------------===//
9//
Evan Cheng5b1b44892011-07-01 21:01:15 +000010// This file declares the PowerPC specific subclass of TargetSubtargetInfo.
Nate Begeman8c00f8c2005-08-04 07:12:09 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef POWERPCSUBTARGET_H
15#define POWERPCSUBTARGET_H
16
Evan Cheng5b1b44892011-07-01 21:01:15 +000017#include "llvm/Target/TargetSubtargetInfo.h"
Evan Chengab8be962011-06-29 01:14:12 +000018#include "llvm/MC/MCInstrItineraries.h"
19#include "llvm/ADT/Triple.h"
Jim Laskeyb1e11802005-09-01 21:38:21 +000020#include <string>
21
Evan Cheng94214702011-07-01 20:45:01 +000022#define GET_SUBTARGETINFO_HEADER
Evan Cheng385e9302011-07-01 22:36:09 +000023#include "PPCGenSubtargetInfo.inc"
Evan Cheng94214702011-07-01 20:45:01 +000024
Nick Lewyckybd92d812007-01-19 04:36:02 +000025// GCC #defines PPC on Linux but we use it as our namespace name
26#undef PPC
27
Nate Begeman8c00f8c2005-08-04 07:12:09 +000028namespace llvm {
Jim Laskeyc35010d2006-12-12 20:57:08 +000029
30namespace PPC {
31 // -m directive values.
32 enum {
Dale Johannesendb01c8b2008-02-14 23:35:16 +000033 DIR_NONE,
Jim Laskeyc35010d2006-12-12 20:57:08 +000034 DIR_32,
35 DIR_601,
36 DIR_602,
37 DIR_603,
38 DIR_7400,
39 DIR_750,
40 DIR_970,
41 DIR_64
42 };
43}
44
Chris Lattner57fc62c2006-12-11 23:22:45 +000045class GlobalValue;
46class TargetMachine;
47
Evan Cheng94214702011-07-01 20:45:01 +000048class PPCSubtarget : public PPCGenSubtargetInfo {
Nate Begeman8c00f8c2005-08-04 07:12:09 +000049protected:
50 /// stackAlignment - The minimum alignment known to hold of the stack frame on
51 /// entry to the function and which must be maintained by every function.
Chris Lattner3c304a32005-08-05 22:05:03 +000052 unsigned StackAlignment;
Jim Laskey6cee6302005-11-01 20:06:59 +000053
54 /// Selected instruction itineraries (one entry per itinerary class.)
55 InstrItineraryData InstrItins;
Jim Laskeyc35010d2006-12-12 20:57:08 +000056
57 /// Which cpu directive was used.
58 unsigned DarwinDirective;
Nate Begeman8c00f8c2005-08-04 07:12:09 +000059
60 /// Used by the ISel to turn in optimizations for POWER4-derived architectures
Chris Lattner3c304a32005-08-05 22:05:03 +000061 bool IsGigaProcessor;
Chris Lattnera7a58542006-06-16 17:34:12 +000062 bool Has64BitSupport;
63 bool Use64BitRegs;
Chris Lattner7c1fb5f2006-06-16 17:50:12 +000064 bool IsPPC64;
Jim Laskey581a8f72005-10-26 17:30:34 +000065 bool HasAltivec;
Chris Lattner1e9de3e2005-09-02 18:33:05 +000066 bool HasFSQRT;
Chris Lattnerbf751e22006-02-28 07:08:22 +000067 bool HasSTFIWX;
Chris Lattner57fc62c2006-12-11 23:22:45 +000068 bool HasLazyResolverStubs;
Torok Edwin0e3a1a82010-08-04 20:47:44 +000069 bool IsJITCodeModel;
Chris Lattner564da5d2008-01-02 19:35:16 +000070
Daniel Dunbar869eca12011-04-19 20:54:28 +000071 /// TargetTriple - What processor and OS we're targeting.
72 Triple TargetTriple;
73
Nate Begeman8c00f8c2005-08-04 07:12:09 +000074public:
75 /// This constructor initializes the data members to match that
Daniel Dunbar3be03402009-08-02 22:11:08 +000076 /// of the specified triple.
Nate Begeman8c00f8c2005-08-04 07:12:09 +000077 ///
Evan Cheng276365d2011-06-30 01:53:36 +000078 PPCSubtarget(const std::string &TT, const std::string &CPU,
79 const std::string &FS, bool is64Bit);
Jim Laskey581a8f72005-10-26 17:30:34 +000080
81 /// ParseSubtargetFeatures - Parses features string setting specified
Jim Laskey2cbc2072005-10-26 18:07:50 +000082 /// subtarget options. Definition of function is auto generated by tblgen.
Evan Cheng276365d2011-06-30 01:53:36 +000083 void ParseSubtargetFeatures(const std::string &FS, const std::string &CPU);
Anton Korobeynikov41a02432009-05-23 19:50:50 +000084
Chris Lattner57fc62c2006-12-11 23:22:45 +000085
86 /// SetJITMode - This is called to inform the subtarget info that we are
87 /// producing code for the JIT.
88 void SetJITMode();
Nate Begeman8c00f8c2005-08-04 07:12:09 +000089
90 /// getStackAlignment - Returns the minimum alignment known to hold of the
91 /// stack frame on entry to the function and which must be maintained by every
92 /// function for this subtarget.
Chris Lattner3c304a32005-08-05 22:05:03 +000093 unsigned getStackAlignment() const { return StackAlignment; }
Jim Laskey6cee6302005-11-01 20:06:59 +000094
Jim Laskeyc35010d2006-12-12 20:57:08 +000095 /// getDarwinDirective - Returns the -m directive specified for the cpu.
96 ///
97 unsigned getDarwinDirective() const { return DarwinDirective; }
98
Jim Laskey6cee6302005-11-01 20:06:59 +000099 /// getInstrItins - Return the instruction itineraies based on subtarget
100 /// selection.
Chris Lattner442b9a62006-12-11 21:42:55 +0000101 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
Chris Lattner7c1fb5f2006-06-16 17:50:12 +0000102
103 /// getTargetDataString - Return the pointer size and type alignment
104 /// properties of this subtarget.
Chris Lattner94de9a82006-06-16 01:37:27 +0000105 const char *getTargetDataString() const {
Dale Johannesended2b202009-02-27 00:56:35 +0000106 // Note, the alignment values for f64 and i64 on ppc64 in Darwin
107 // documentation are wrong; these are correct (i.e. "what gcc does").
Chris Lattner59a91782009-11-07 19:07:32 +0000108 return isPPC64() ? "E-p:64:64-f64:64:64-i64:64:64-f128:64:128-n32:64"
109 : "E-p:32:32-f64:32:64-i64:32:64-f128:64:128-n32";
Chris Lattner94de9a82006-06-16 01:37:27 +0000110 }
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000111
Chris Lattner7c1fb5f2006-06-16 17:50:12 +0000112 /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
113 ///
114 bool isPPC64() const { return IsPPC64; }
115
116 /// has64BitSupport - Return true if the selected CPU supports 64-bit
117 /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
118 bool has64BitSupport() const { return Has64BitSupport; }
119
120 /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
121 /// registers in 32-bit mode when possible. This can only true if
122 /// has64BitSupport() returns true.
123 bool use64BitRegs() const { return Use64BitRegs; }
124
Chris Lattner57fc62c2006-12-11 23:22:45 +0000125 /// hasLazyResolverStub - Return true if accesses to the specified global have
126 /// to go through a dyld lazy resolution stub. This means that an extra load
127 /// is required to get the address of the global.
Daniel Dunbar3be03402009-08-02 22:11:08 +0000128 bool hasLazyResolverStub(const GlobalValue *GV,
129 const TargetMachine &TM) const;
Chris Lattner7c1fb5f2006-06-16 17:50:12 +0000130
Torok Edwin0e3a1a82010-08-04 20:47:44 +0000131 // isJITCodeModel - True if we're generating code for the JIT
132 bool isJITCodeModel() const { return IsJITCodeModel; }
133
Chris Lattner7c1fb5f2006-06-16 17:50:12 +0000134 // Specific obvious features.
Chris Lattner1e9de3e2005-09-02 18:33:05 +0000135 bool hasFSQRT() const { return HasFSQRT; }
Chris Lattnerbf751e22006-02-28 07:08:22 +0000136 bool hasSTFIWX() const { return HasSTFIWX; }
Jim Laskey581a8f72005-10-26 17:30:34 +0000137 bool hasAltivec() const { return HasAltivec; }
Chris Lattner7c1fb5f2006-06-16 17:50:12 +0000138 bool isGigaProcessor() const { return IsGigaProcessor; }
Bill Wendlingcb900992007-01-16 09:29:17 +0000139
Daniel Dunbar869eca12011-04-19 20:54:28 +0000140 const Triple &getTargetTriple() const { return TargetTriple; }
141
Chris Lattner564da5d2008-01-02 19:35:16 +0000142 /// isDarwin - True if this is any darwin platform.
Daniel Dunbar558692f2011-04-20 00:14:25 +0000143 bool isDarwin() const { return TargetTriple.isMacOSX(); }
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000144
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000145 bool isDarwinABI() const { return isDarwin(); }
146 bool isSVR4ABI() const { return !isDarwin(); }
147
Nate Begeman8c00f8c2005-08-04 07:12:09 +0000148};
149} // End llvm namespace
150
151#endif