LLVM 22.0.0git
PPCSubtarget.h
Go to the documentation of this file.
1//===-- PPCSubtarget.h - Define Subtarget for the PPC ----------*- C++ -*--===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the PowerPC specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
14#define LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
15
16#include "PPCFrameLowering.h"
17#include "PPCISelLowering.h"
18#include "PPCInstrInfo.h"
23#include "llvm/IR/DataLayout.h"
26#include <string>
27
28#define GET_SUBTARGETINFO_HEADER
29#include "PPCGenSubtargetInfo.inc"
30
31// GCC #defines PPC on Linux but we use it as our namespace name
32#undef PPC
33
34namespace llvm {
35class SelectionDAGTargetInfo;
36class StringRef;
37
38namespace PPC {
39 // -m directive values.
40enum {
66 DIR_64
67};
68}
69
70class GlobalValue;
71
73public:
78 };
79
80protected:
81 /// TargetTriple - What processor and OS we're targeting.
83
84 /// stackAlignment - The minimum alignment known to hold of the stack frame on
85 /// entry to the function and which must be maintained by every function.
87
88 /// Selected instruction itineraries (one entry per itinerary class.)
90
91// Bool members corresponding to the SubtargetFeatures defined in tablegen.
92#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
93 bool ATTRIBUTE = DEFAULT;
94#include "PPCGenSubtargetInfo.inc"
95
96 /// Which cpu directive was used.
97 unsigned CPUDirective;
98
99 bool IsPPC64;
101
103
108
109 // SelectionDAGISel related APIs.
110 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
111
112 /// GlobalISel related APIs.
113 std::unique_ptr<CallLowering> CallLoweringInfo;
114 std::unique_ptr<LegalizerInfo> Legalizer;
115 std::unique_ptr<RegisterBankInfo> RegBankInfo;
116 std::unique_ptr<InstructionSelector> InstSelector;
117
118public:
119 /// This constructor initializes the data members to match that
120 /// of the specified triple.
121 ///
122 PPCSubtarget(const Triple &TT, const std::string &CPU,
123 const std::string &TuneCPU, const std::string &FS,
124 const PPCTargetMachine &TM);
125
126 ~PPCSubtarget() override;
127
128 /// ParseSubtargetFeatures - Parses features string setting specified
129 /// subtarget options. Definition of function is auto generated by tblgen.
131
132 /// getStackAlignment - Returns the minimum alignment known to hold of the
133 /// stack frame on entry to the function and which must be maintained by every
134 /// function for this subtarget.
136
137 /// getCPUDirective - Returns the -m directive specified for the cpu.
138 ///
139 unsigned getCPUDirective() const { return CPUDirective; }
140
141 /// getInstrItins - Return the instruction itineraries based on subtarget
142 /// selection.
144 return &InstrItins;
145 }
146
147 const PPCFrameLowering *getFrameLowering() const override {
148 return &FrameLowering;
149 }
150 const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
151 const PPCTargetLowering *getTargetLowering() const override {
152 return &TLInfo;
153 }
154
155 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
156
157 const PPCRegisterInfo *getRegisterInfo() const override {
158 return &getInstrInfo()->getRegisterInfo();
159 }
160 const PPCTargetMachine &getTargetMachine() const { return TM; }
161
162 /// initializeSubtargetDependencies - Initializes using a CPU, a TuneCPU, and
163 /// feature string so that we can use initializer lists for subtarget
164 /// initialization.
166 StringRef TuneCPU,
167 StringRef FS);
168
169private:
170 void initializeEnvironment();
171 void initSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
172
173public:
174 /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
175 ///
176 bool isPPC64() const;
177
178 // useSoftFloat - Return true if soft-float option is turned on.
179 bool useSoftFloat() const {
180 if (isAIXABI() && !HasHardFloat)
181 report_fatal_error("soft-float is not yet supported on AIX.");
182 return !HasHardFloat;
183 }
184
185 // isLittleEndian - True if generating little-endian code
186 bool isLittleEndian() const { return IsLittleEndian; }
187
188// Getters for SubtargetFeatures defined in tablegen.
189#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
190 bool GETTER() const { return ATTRIBUTE; }
191#include "PPCGenSubtargetInfo.inc"
192
194 return Align(16);
195 }
196
197 unsigned getRedZoneSize() const {
198 if (isPPC64())
199 // 288 bytes = 18*8 (FPRs) + 18*8 (GPRs, GPR13 reserved)
200 return 288;
201
202 // AIX PPC32: 220 bytes = 18*8 (FPRs) + 19*4 (GPRs);
203 // PPC32 SVR4ABI has no redzone.
204 return isAIXABI() ? 220 : 0;
205 }
206
208 return hasVSX() && isLittleEndian() && !hasP9Vector();
209 }
210
212
213 const Triple &getTargetTriple() const { return TargetTriple; }
214
215 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
217 bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
218
219 bool isAIXABI() const { return TargetTriple.isOSAIX(); }
220 bool isSVR4ABI() const { return !isAIXABI(); }
221 bool isELFv2ABI() const;
222
223 bool is64BitELFABI() const { return isSVR4ABI() && isPPC64(); }
224 bool is32BitELFABI() const { return isSVR4ABI() && !isPPC64(); }
225 bool isUsingPCRelativeCalls() const;
226
227 /// Originally, this function return hasISEL(). Now we always enable it,
228 /// but may expand the ISEL instruction later.
229 bool enableEarlyIfConversion() const override { return true; }
230
231 /// Scheduling customization.
232 bool enableMachineScheduler() const override;
233 /// Pipeliner customization.
234 bool enableMachinePipeliner() const override;
235 /// Machine Pipeliner customization
236 bool useDFAforSMS() const override;
237 /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
238 bool enablePostRAScheduler() const override;
239 AntiDepBreakMode getAntiDepBreakMode() const override;
240 void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
241
243 const SchedRegion &Region) const override;
244
245 bool useAA() const override;
246
247 bool enableSubRegLiveness() const override;
248
249 bool enableSpillageCopyElimination() const override { return true; }
250
251 /// True if the GV will be accessed via an indirect symbol.
252 bool isGVIndirectSymbol(const GlobalValue *GV) const;
253
254 MVT getScalarIntVT() const { return isPPC64() ? MVT::i64 : MVT::i32; }
255
256 /// Calculates the effective code model for argument GV.
258 const GlobalValue *GV) const;
259
260 /// True if the ABI is descriptor based.
262 // Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
263 // v1 ABI uses descriptors.
264 return isAIXABI() || (is64BitELFABI() && !isELFv2ABI());
265 }
266
267 unsigned descriptorTOCAnchorOffset() const {
269 "Should only be called when the target uses descriptors.");
270 return IsPPC64 ? 8 : 4;
271 }
272
275 "Should only be called when the target uses descriptors.");
276 return IsPPC64 ? 16 : 8;
277 }
278
281 "Should only be called when the target uses descriptors.");
282 return IsPPC64 ? PPC::X11 : PPC::R11;
283 }
284
286 assert((is64BitELFABI() || isAIXABI()) &&
287 "Should only be called when the target is a TOC based ABI.");
288 return IsPPC64 ? PPC::X2 : PPC::R2;
289 }
290
292 assert((is64BitELFABI() || isAIXABI()) &&
293 "Should only be called for targets with a thread pointer register.");
294 return IsPPC64 ? PPC::X13 : PPC::R13;
295 }
296
298 return IsPPC64 ? PPC::X1 : PPC::R1;
299 }
300
301 bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
302
304 return PredictableSelectIsExpensive;
305 }
306
307 // Select allocation orders of GPRC and G8RC. It should be strictly consistent
308 // with corresponding AltOrders in PPCRegisterInfo.td.
309 unsigned getGPRAllocationOrderIdx() const {
310 if (is64BitELFABI())
311 return 1;
312 if (isAIXABI())
313 return 2;
314 return 0;
315 }
316
317 // GlobalISEL
318 const CallLowering *getCallLowering() const override;
319 const RegisterBankInfo *getRegBankInfo() const override;
320 const LegalizerInfo *getLegalizerInfo() const override;
322};
323} // End llvm namespace
324
325#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file describes how to lower LLVM calls to machine code calls.
Interface for Targets to specify which operations they can successfully select and how the others sho...
Itinerary data supplied by a subtarget to be used by a target.
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Machine Value Type.
const PPCRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
Definition: PPCInstrInfo.h:381
std::unique_ptr< InstructionSelector > InstSelector
Definition: PPCSubtarget.h:116
bool enableMachinePipeliner() const override
Pipeliner customization.
bool useDFAforSMS() const override
Machine Pipeliner customization.
bool is32BitELFABI() const
Definition: PPCSubtarget.h:224
std::unique_ptr< LegalizerInfo > Legalizer
Definition: PPCSubtarget.h:114
PPCTargetLowering TLInfo
Definition: PPCSubtarget.h:107
unsigned descriptorTOCAnchorOffset() const
Definition: PPCSubtarget.h:267
bool isTargetMachO() const
Definition: PPCSubtarget.h:216
MVT getScalarIntVT() const
Definition: PPCSubtarget.h:254
PPCFrameLowering FrameLowering
Definition: PPCSubtarget.h:105
bool isAIXABI() const
Definition: PPCSubtarget.h:219
const CallLowering * getCallLowering() const override
Triple TargetTriple
TargetTriple - What processor and OS we're targeting.
Definition: PPCSubtarget.h:82
const LegalizerInfo * getLegalizerInfo() const override
unsigned getGPRAllocationOrderIdx() const
Definition: PPCSubtarget.h:309
bool useSoftFloat() const
Definition: PPCSubtarget.h:179
std::unique_ptr< RegisterBankInfo > RegBankInfo
Definition: PPCSubtarget.h:115
~PPCSubtarget() override
bool isXRaySupported() const override
Definition: PPCSubtarget.h:301
POPCNTDKind HasPOPCNTD
Definition: PPCSubtarget.h:102
InstrItineraryData InstrItins
Selected instruction itineraries (one entry per itinerary class.)
Definition: PPCSubtarget.h:89
Align StackAlignment
stackAlignment - The minimum alignment known to hold of the stack frame on entry to the function and ...
Definition: PPCSubtarget.h:86
const PPCFrameLowering * getFrameLowering() const override
Definition: PPCSubtarget.h:147
bool needsSwapsForVSXMemOps() const
Definition: PPCSubtarget.h:207
PPCInstrInfo InstrInfo
Definition: PPCSubtarget.h:106
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override
bool isUsingPCRelativeCalls() const
bool enableSubRegLiveness() const override
bool usesFunctionDescriptors() const
True if the ABI is descriptor based.
Definition: PPCSubtarget.h:261
const PPCTargetLowering * getTargetLowering() const override
Definition: PPCSubtarget.h:151
const InstrItineraryData * getInstrItineraryData() const override
getInstrItins - Return the instruction itineraries based on subtarget selection.
Definition: PPCSubtarget.h:143
InstructionSelector * getInstructionSelector() const override
bool enableEarlyIfConversion() const override
Originally, this function return hasISEL().
Definition: PPCSubtarget.h:229
MCRegister getEnvironmentPointerRegister() const
Definition: PPCSubtarget.h:279
unsigned CPUDirective
Which cpu directive was used.
Definition: PPCSubtarget.h:97
const PPCInstrInfo * getInstrInfo() const override
Definition: PPCSubtarget.h:150
unsigned getRedZoneSize() const
Definition: PPCSubtarget.h:197
AntiDepBreakMode getAntiDepBreakMode() const override
MCRegister getThreadPointerRegister() const
Definition: PPCSubtarget.h:291
bool isSVR4ABI() const
Definition: PPCSubtarget.h:220
unsigned getCPUDirective() const
getCPUDirective - Returns the -m directive specified for the cpu.
Definition: PPCSubtarget.h:139
bool enableSpillageCopyElimination() const override
Definition: PPCSubtarget.h:249
POPCNTDKind hasPOPCNTD() const
Definition: PPCSubtarget.h:211
bool isLittleEndian() const
Definition: PPCSubtarget.h:186
bool isTargetLinux() const
Definition: PPCSubtarget.h:217
MCRegister getTOCPointerRegister() const
Definition: PPCSubtarget.h:285
bool isTargetELF() const
Definition: PPCSubtarget.h:215
MCRegister getStackPointerRegister() const
Definition: PPCSubtarget.h:297
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool useAA() const override
Align getStackAlignment() const
getStackAlignment - Returns the minimum alignment known to hold of the stack frame on entry to the fu...
Definition: PPCSubtarget.h:135
PPCSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef TuneCPU, StringRef FS)
initializeSubtargetDependencies - Initializes using a CPU, a TuneCPU, and feature string so that we c...
bool is64BitELFABI() const
Definition: PPCSubtarget.h:223
CodeModel::Model getCodeModel(const TargetMachine &TM, const GlobalValue *GV) const
Calculates the effective code model for argument GV.
bool isELFv2ABI() const
Align getPlatformStackAlignment() const
Definition: PPCSubtarget.h:193
const PPCTargetMachine & getTargetMachine() const
Definition: PPCSubtarget.h:160
const PPCTargetMachine & TM
Definition: PPCSubtarget.h:104
bool isPredictableSelectIsExpensive() const
Definition: PPCSubtarget.h:303
std::unique_ptr< const SelectionDAGTargetInfo > TSInfo
Definition: PPCSubtarget.h:110
bool enableMachineScheduler() const override
Scheduling customization.
void overrideSchedPolicy(MachineSchedPolicy &Policy, const SchedRegion &Region) const override
const RegisterBankInfo * getRegBankInfo() const override
const PPCRegisterInfo * getRegisterInfo() const override
Definition: PPCSubtarget.h:157
bool isGVIndirectSymbol(const GlobalValue *GV) const
True if the GV will be accessed via an indirect symbol.
const Triple & getTargetTriple() const
Definition: PPCSubtarget.h:213
unsigned descriptorEnvironmentPointerOffset() const
Definition: PPCSubtarget.h:273
std::unique_ptr< CallLowering > CallLoweringInfo
GlobalISel related APIs.
Definition: PPCSubtarget.h:113
bool enablePostRAScheduler() const override
This overrides the PostRAScheduler bit in the SchedModel for each CPU.
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
Common code between 32-bit and 64-bit PowerPC targets.
Holds all the information related to register banks.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:83
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:779
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:725
bool isOSAIX() const
Tests whether the OS is AIX.
Definition: Triple.h:757
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:766
@ DIR_PWR_FUTURE
Definition: PPCSubtarget.h:65
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.
A region of an MBB for scheduling.