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 {
67};
68}
69
70class GlobalValue;
71
73public:
79
80protected:
81 /// stackAlignment - The minimum alignment known to hold of the stack frame on
82 /// entry to the function and which must be maintained by every function.
84
85 /// Selected instruction itineraries (one entry per itinerary class.)
87
88// Bool members corresponding to the SubtargetFeatures defined in tablegen.
89#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
90 bool ATTRIBUTE = DEFAULT;
91#include "PPCGenSubtargetInfo.inc"
92
93 /// Which cpu directive was used.
94 unsigned CPUDirective;
95
96 bool IsPPC64;
98
100
105
106 // SelectionDAGISel related APIs.
107 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
108
109 /// GlobalISel related APIs.
110 std::unique_ptr<CallLowering> CallLoweringInfo;
111 std::unique_ptr<LegalizerInfo> Legalizer;
112 std::unique_ptr<RegisterBankInfo> RegBankInfo;
113 std::unique_ptr<InstructionSelector> InstSelector;
114
115public:
116 /// This constructor initializes the data members to match that
117 /// of the specified triple.
118 ///
119 PPCSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
120 const PPCTargetMachine &TM);
121
122 ~PPCSubtarget() override;
123
124 /// ParseSubtargetFeatures - Parses features string setting specified
125 /// subtarget options. Definition of function is auto generated by tblgen.
127
128 /// getStackAlignment - Returns the minimum alignment known to hold of the
129 /// stack frame on entry to the function and which must be maintained by every
130 /// function for this subtarget.
132
133 /// getCPUDirective - Returns the -m directive specified for the cpu.
134 ///
135 unsigned getCPUDirective() const { return CPUDirective; }
136
137 /// getInstrItins - Return the instruction itineraries based on subtarget
138 /// selection.
140 return &InstrItins;
141 }
142
143 const PPCFrameLowering *getFrameLowering() const override {
144 return &FrameLowering;
145 }
146 const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
147 const PPCTargetLowering *getTargetLowering() const override {
148 return &TLInfo;
149 }
150
151 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
152
153 const PPCRegisterInfo *getRegisterInfo() const override {
154 return &getInstrInfo()->getRegisterInfo();
155 }
156 const PPCTargetMachine &getTargetMachine() const { return TM; }
157
158 /// initializeSubtargetDependencies - Initializes using a CPU, a TuneCPU, and
159 /// feature string so that we can use initializer lists for subtarget
160 /// initialization.
162 StringRef TuneCPU,
163 StringRef FS);
164
165private:
166 void initializeEnvironment();
167 void initSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
168
169public:
170 /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
171 ///
172 bool isPPC64() const;
173
174 // useSoftFloat - Return true if soft-float option is turned on.
175 bool useSoftFloat() const {
176 if (isAIXABI() && !HasHardFloat)
177 report_fatal_error("soft-float is not yet supported on AIX.");
178 return !HasHardFloat;
179 }
180
181 // isLittleEndian - True if generating little-endian code
182 bool isLittleEndian() const { return IsLittleEndian; }
183
184// Getters for SubtargetFeatures defined in tablegen.
185#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
186 bool GETTER() const { return ATTRIBUTE; }
187#include "PPCGenSubtargetInfo.inc"
188
190 return Align(16);
191 }
192
193 unsigned getRedZoneSize() const {
194 if (isPPC64())
195 // 288 bytes = 18*8 (FPRs) + 18*8 (GPRs, GPR13 reserved)
196 return 288;
197
198 // AIX PPC32: 220 bytes = 18*8 (FPRs) + 19*4 (GPRs);
199 // PPC32 SVR4ABI has no redzone.
200 return isAIXABI() ? 220 : 0;
201 }
202
204 return hasVSX() && isLittleEndian() && !hasP9Vector();
205 }
206
208
209 bool isTargetELF() const { return getTargetTriple().isOSBinFormatELF(); }
210 bool isTargetMachO() const { return getTargetTriple().isOSBinFormatMachO(); }
211 bool isTargetLinux() const { return getTargetTriple().isOSLinux(); }
212
213 bool isAIXABI() const { return getTargetTriple().isOSAIX(); }
214 bool isSVR4ABI() const { return !isAIXABI(); }
215 bool isELFv2ABI() const;
216
217 bool is64BitELFABI() const { return isSVR4ABI() && isPPC64(); }
218 bool is32BitELFABI() const { return isSVR4ABI() && !isPPC64(); }
219 bool isUsingPCRelativeCalls() const;
220
221 /// Originally, this function return hasISEL(). Now we always enable it,
222 /// but may expand the ISEL instruction later.
223 bool enableEarlyIfConversion() const override { return true; }
224
225 /// Scheduling customization.
226 bool enableMachineScheduler() const override;
227 /// Pipeliner customization.
228 bool enableMachinePipeliner() const override;
229 /// Machine Pipeliner customization
230 bool useDFAforSMS() const override;
231 /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
232 bool enablePostRAScheduler() const override;
233 AntiDepBreakMode getAntiDepBreakMode() const override;
234 void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
235
237 const SchedRegion &Region) const override;
238
239 bool useAA() const override;
240
241 bool enableSubRegLiveness() const override;
242
243 bool enableSpillageCopyElimination() const override { return true; }
244
245 /// True if the GV will be accessed via an indirect symbol.
246 bool isGVIndirectSymbol(const GlobalValue *GV) const;
247
248 MVT getScalarIntVT() const { return isPPC64() ? MVT::i64 : MVT::i32; }
249
250 /// Calculates the effective code model for argument GV.
252 const GlobalValue *GV) const;
253
254 /// True if the ABI is descriptor based.
256 // Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
257 // v1 ABI uses descriptors.
258 return isAIXABI() || (is64BitELFABI() && !isELFv2ABI());
259 }
260
261 unsigned descriptorTOCAnchorOffset() const {
263 "Should only be called when the target uses descriptors.");
264 return IsPPC64 ? 8 : 4;
265 }
266
269 "Should only be called when the target uses descriptors.");
270 return IsPPC64 ? 16 : 8;
271 }
272
275 "Should only be called when the target uses descriptors.");
276 return IsPPC64 ? PPC::X11 : PPC::R11;
277 }
278
280 assert((is64BitELFABI() || isAIXABI()) &&
281 "Should only be called when the target is a TOC based ABI.");
282 return IsPPC64 ? PPC::X2 : PPC::R2;
283 }
284
286 assert((is64BitELFABI() || isAIXABI()) &&
287 "Should only be called for targets with a thread pointer register.");
288 return IsPPC64 ? PPC::X13 : PPC::R13;
289 }
290
292 return IsPPC64 ? PPC::X1 : PPC::R1;
293 }
294
295 bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
296
298 return PredictableSelectIsExpensive;
299 }
300
301 // Select allocation orders of GPRC and G8RC. It should be strictly consistent
302 // with corresponding AltOrders in PPCRegisterInfo.td.
303 unsigned getGPRAllocationOrderIdx() const {
304 if (is64BitELFABI())
305 return 1;
306 if (isAIXABI())
307 return 2;
308 return 0;
309 }
310
311 // GlobalISEL
312 const CallLowering *getCallLowering() const override;
313 const RegisterBankInfo *getRegBankInfo() const override;
314 const LegalizerInfo *getLegalizerInfo() const override;
316};
317} // End llvm namespace
318
319#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.
std::unique_ptr< InstructionSelector > InstSelector
bool enableMachinePipeliner() const override
Pipeliner customization.
bool useDFAforSMS() const override
Machine Pipeliner customization.
bool is32BitELFABI() const
std::unique_ptr< LegalizerInfo > Legalizer
PPCTargetLowering TLInfo
unsigned descriptorTOCAnchorOffset() const
bool isTargetMachO() const
MVT getScalarIntVT() const
PPCFrameLowering FrameLowering
bool isAIXABI() const
const CallLowering * getCallLowering() const override
const LegalizerInfo * getLegalizerInfo() const override
unsigned getGPRAllocationOrderIdx() const
bool useSoftFloat() const
std::unique_ptr< RegisterBankInfo > RegBankInfo
~PPCSubtarget() override
bool isXRaySupported() const override
POPCNTDKind HasPOPCNTD
InstrItineraryData InstrItins
Selected instruction itineraries (one entry per itinerary class.)
Align StackAlignment
stackAlignment - The minimum alignment known to hold of the stack frame on entry to the function and ...
const PPCFrameLowering * getFrameLowering() const override
bool needsSwapsForVSXMemOps() const
PPCInstrInfo InstrInfo
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.
const PPCTargetLowering * getTargetLowering() const override
const InstrItineraryData * getInstrItineraryData() const override
getInstrItins - Return the instruction itineraries based on subtarget selection.
InstructionSelector * getInstructionSelector() const override
bool enableEarlyIfConversion() const override
Originally, this function return hasISEL().
MCRegister getEnvironmentPointerRegister() const
unsigned CPUDirective
Which cpu directive was used.
const PPCInstrInfo * getInstrInfo() const override
unsigned getRedZoneSize() const
AntiDepBreakMode getAntiDepBreakMode() const override
MCRegister getThreadPointerRegister() const
bool isSVR4ABI() const
unsigned getCPUDirective() const
getCPUDirective - Returns the -m directive specified for the cpu.
bool enableSpillageCopyElimination() const override
POPCNTDKind hasPOPCNTD() const
bool isLittleEndian() const
bool isTargetLinux() const
MCRegister getTOCPointerRegister() const
bool isTargetELF() const
MCRegister getStackPointerRegister() const
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...
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
CodeModel::Model getCodeModel(const TargetMachine &TM, const GlobalValue *GV) const
Calculates the effective code model for argument GV.
PPCSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, const PPCTargetMachine &TM)
This constructor initializes the data members to match that of the specified triple.
bool isELFv2ABI() const
Align getPlatformStackAlignment() const
const PPCTargetMachine & getTargetMachine() const
const PPCTargetMachine & TM
bool isPredictableSelectIsExpensive() const
std::unique_ptr< const SelectionDAGTargetInfo > TSInfo
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
bool isGVIndirectSymbol(const GlobalValue *GV) const
True if the GV will be accessed via an indirect symbol.
unsigned descriptorEnvironmentPointerOffset() const
std::unique_ptr< CallLowering > CallLoweringInfo
GlobalISel related APIs.
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.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
This is an optimization pass for GlobalISel generic memory operations.
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.