1 //===-- PPCSubtarget.h - Define Subtarget for the PPC ----------*- C++ -*--===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares the PowerPC specific subclass of TargetSubtargetInfo.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
14 #define LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
16 #include "PPCFrameLowering.h"
17 #include "PPCISelLowering.h"
18 #include "PPCInstrInfo.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
21 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
22 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
23 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
24 #include "llvm/CodeGen/TargetSubtargetInfo.h"
25 #include "llvm/IR/DataLayout.h"
26 #include "llvm/MC/MCInstrItineraries.h"
29 #define GET_SUBTARGETINFO_HEADER
30 #include "PPCGenSubtargetInfo.inc"
32 // GCC #defines PPC on Linux but we use it as our namespace name
39 // -m directive values.
71 class PPCSubtarget
: public PPCGenSubtargetInfo
{
80 /// TargetTriple - What processor and OS we're targeting.
83 /// stackAlignment - The minimum alignment known to hold of the stack frame on
84 /// entry to the function and which must be maintained by every function.
87 /// Selected instruction itineraries (one entry per itinerary class.)
88 InstrItineraryData InstrItins
;
90 /// Which cpu directive was used.
91 unsigned CPUDirective
;
93 /// Used by the ISel to turn in optimizations for POWER4-derived architectures
105 bool NeedsTwoConstNR
;
112 bool HasPrefixInstrs
;
113 bool HasPCRelativeMemops
;
119 bool HasFRE
, HasFRES
, HasFRSQRTE
, HasFRSQRTES
;
136 bool AllowsUnalignedFPAccess
;
140 bool HasInvariantFunctionDescriptors
;
141 bool HasPartwordAtomics
;
142 bool HasQuadwordAtomics
;
148 bool HasAddiLoadFusion
;
149 bool HasAddisLoadFusion
;
155 bool VectorsUseTwoUnits
;
156 bool UsePPCPreRASchedStrategy
;
157 bool UsePPCPostRASchedStrategy
;
158 bool PairedVectorMemops
;
159 bool PredictableSelectIsExpensive
;
163 POPCNTDKind HasPOPCNTD
;
165 const PPCTargetMachine
&TM
;
166 PPCFrameLowering FrameLowering
;
167 PPCInstrInfo InstrInfo
;
168 PPCTargetLowering TLInfo
;
169 SelectionDAGTargetInfo TSInfo
;
171 /// GlobalISel related APIs.
172 std::unique_ptr
<CallLowering
> CallLoweringInfo
;
173 std::unique_ptr
<LegalizerInfo
> Legalizer
;
174 std::unique_ptr
<RegisterBankInfo
> RegBankInfo
;
175 std::unique_ptr
<InstructionSelector
> InstSelector
;
178 /// This constructor initializes the data members to match that
179 /// of the specified triple.
181 PPCSubtarget(const Triple
&TT
, const std::string
&CPU
, const std::string
&FS
,
182 const PPCTargetMachine
&TM
);
184 /// ParseSubtargetFeatures - Parses features string setting specified
185 /// subtarget options. Definition of function is auto generated by tblgen.
186 void ParseSubtargetFeatures(StringRef CPU
, StringRef TuneCPU
, StringRef FS
);
188 /// getStackAlignment - Returns the minimum alignment known to hold of the
189 /// stack frame on entry to the function and which must be maintained by every
190 /// function for this subtarget.
191 Align
getStackAlignment() const { return StackAlignment
; }
193 /// getCPUDirective - Returns the -m directive specified for the cpu.
195 unsigned getCPUDirective() const { return CPUDirective
; }
197 /// getInstrItins - Return the instruction itineraries based on subtarget
199 const InstrItineraryData
*getInstrItineraryData() const override
{
203 const PPCFrameLowering
*getFrameLowering() const override
{
204 return &FrameLowering
;
206 const PPCInstrInfo
*getInstrInfo() const override
{ return &InstrInfo
; }
207 const PPCTargetLowering
*getTargetLowering() const override
{
210 const SelectionDAGTargetInfo
*getSelectionDAGInfo() const override
{
213 const PPCRegisterInfo
*getRegisterInfo() const override
{
214 return &getInstrInfo()->getRegisterInfo();
216 const PPCTargetMachine
&getTargetMachine() const { return TM
; }
218 /// initializeSubtargetDependencies - Initializes using a CPU and feature string
219 /// so that we can use initializer lists for subtarget initialization.
220 PPCSubtarget
&initializeSubtargetDependencies(StringRef CPU
, StringRef FS
);
223 void initializeEnvironment();
224 void initSubtargetFeatures(StringRef CPU
, StringRef FS
);
227 /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
229 bool isPPC64() const;
231 /// has64BitSupport - Return true if the selected CPU supports 64-bit
232 /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
233 bool has64BitSupport() const { return Has64BitSupport
; }
234 // useSoftFloat - Return true if soft-float option is turned on.
235 bool useSoftFloat() const {
236 if (isAIXABI() && !HasHardFloat
)
237 report_fatal_error("soft-float is not yet supported on AIX.");
238 return !HasHardFloat
;
241 /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
242 /// registers in 32-bit mode when possible. This can only true if
243 /// has64BitSupport() returns true.
244 bool use64BitRegs() const { return Use64BitRegs
; }
246 /// useCRBits - Return true if we should store and manipulate i1 values in
247 /// the individual condition register bits.
248 bool useCRBits() const { return UseCRBits
; }
250 // isLittleEndian - True if generating little-endian code
251 bool isLittleEndian() const { return IsLittleEndian
; }
253 // Specific obvious features.
254 bool hasFCPSGN() const { return HasFCPSGN
; }
255 bool hasFSQRT() const { return HasFSQRT
; }
256 bool hasFRE() const { return HasFRE
; }
257 bool hasFRES() const { return HasFRES
; }
258 bool hasFRSQRTE() const { return HasFRSQRTE
; }
259 bool hasFRSQRTES() const { return HasFRSQRTES
; }
260 bool hasRecipPrec() const { return HasRecipPrec
; }
261 bool hasSTFIWX() const { return HasSTFIWX
; }
262 bool hasLFIWAX() const { return HasLFIWAX
; }
263 bool hasFPRND() const { return HasFPRND
; }
264 bool hasFPCVT() const { return HasFPCVT
; }
265 bool hasAltivec() const { return HasAltivec
; }
266 bool hasSPE() const { return HasSPE
; }
267 bool hasEFPU2() const { return HasEFPU2
; }
268 bool hasFPU() const { return HasFPU
; }
269 bool hasVSX() const { return HasVSX
; }
270 bool needsTwoConstNR() const { return NeedsTwoConstNR
; }
271 bool hasP8Vector() const { return HasP8Vector
; }
272 bool hasP8Altivec() const { return HasP8Altivec
; }
273 bool hasP8Crypto() const { return HasP8Crypto
; }
274 bool hasP9Vector() const { return HasP9Vector
; }
275 bool hasP9Altivec() const { return HasP9Altivec
; }
276 bool hasP10Vector() const { return HasP10Vector
; }
277 bool hasPrefixInstrs() const { return HasPrefixInstrs
; }
278 bool hasPCRelativeMemops() const { return HasPCRelativeMemops
; }
279 bool hasMMA() const { return HasMMA
; }
280 bool hasROPProtect() const { return HasROPProtect
; }
281 bool hasPrivileged() const { return HasPrivileged
; }
282 bool pairedVectorMemops() const { return PairedVectorMemops
; }
283 bool hasMFOCRF() const { return HasMFOCRF
; }
284 bool hasISEL() const { return HasISEL
; }
285 bool hasBPERMD() const { return HasBPERMD
; }
286 bool hasExtDiv() const { return HasExtDiv
; }
287 bool hasCMPB() const { return HasCMPB
; }
288 bool hasLDBRX() const { return HasLDBRX
; }
289 bool isBookE() const { return IsBookE
; }
290 bool hasOnlyMSYNC() const { return HasOnlyMSYNC
; }
291 bool isPPC4xx() const { return IsPPC4xx
; }
292 bool isPPC6xx() const { return IsPPC6xx
; }
293 bool isSecurePlt() const {return SecurePlt
; }
294 bool vectorsUseTwoUnits() const {return VectorsUseTwoUnits
; }
295 bool isE500() const { return IsE500
; }
296 bool isFeatureMFTB() const { return FeatureMFTB
; }
297 bool allowsUnalignedFPAccess() const { return AllowsUnalignedFPAccess
; }
298 bool isDeprecatedDST() const { return DeprecatedDST
; }
299 bool hasICBT() const { return HasICBT
; }
300 bool hasInvariantFunctionDescriptors() const {
301 return HasInvariantFunctionDescriptors
;
303 bool usePPCPreRASchedStrategy() const { return UsePPCPreRASchedStrategy
; }
304 bool usePPCPostRASchedStrategy() const { return UsePPCPostRASchedStrategy
; }
305 bool hasPartwordAtomics() const { return HasPartwordAtomics
; }
306 bool hasQuadwordAtomics() const { return HasQuadwordAtomics
; }
307 bool hasDirectMove() const { return HasDirectMove
; }
309 Align
getPlatformStackAlignment() const {
313 unsigned getRedZoneSize() const {
315 // 288 bytes = 18*8 (FPRs) + 18*8 (GPRs, GPR13 reserved)
318 // AIX PPC32: 220 bytes = 18*8 (FPRs) + 19*4 (GPRs);
319 // PPC32 SVR4ABI has no redzone.
320 return isAIXABI() ? 220 : 0;
323 bool hasHTM() const { return HasHTM
; }
324 bool hasFloat128() const { return HasFloat128
; }
325 bool isISA2_07() const { return IsISA2_07
; }
326 bool isISA3_0() const { return IsISA3_0
; }
327 bool isISA3_1() const { return IsISA3_1
; }
328 bool useLongCalls() const { return UseLongCalls
; }
329 bool hasFusion() const { return HasFusion
; }
330 bool hasStoreFusion() const { return HasStoreFusion
; }
331 bool hasAddiLoadFusion() const { return HasAddiLoadFusion
; }
332 bool hasAddisLoadFusion() const { return HasAddisLoadFusion
; }
333 bool needsSwapsForVSXMemOps() const {
334 return hasVSX() && isLittleEndian() && !hasP9Vector();
337 POPCNTDKind
hasPOPCNTD() const { return HasPOPCNTD
; }
339 const Triple
&getTargetTriple() const { return TargetTriple
; }
341 bool isTargetELF() const { return TargetTriple
.isOSBinFormatELF(); }
342 bool isTargetMachO() const { return TargetTriple
.isOSBinFormatMachO(); }
343 bool isTargetLinux() const { return TargetTriple
.isOSLinux(); }
345 bool isAIXABI() const { return TargetTriple
.isOSAIX(); }
346 bool isSVR4ABI() const { return !isAIXABI(); }
347 bool isELFv2ABI() const;
349 bool is64BitELFABI() const { return isSVR4ABI() && isPPC64(); }
350 bool is32BitELFABI() const { return isSVR4ABI() && !isPPC64(); }
351 bool isUsingPCRelativeCalls() const;
353 /// Originally, this function return hasISEL(). Now we always enable it,
354 /// but may expand the ISEL instruction later.
355 bool enableEarlyIfConversion() const override
{ return true; }
357 /// Scheduling customization.
358 bool enableMachineScheduler() const override
;
359 /// Pipeliner customization.
360 bool enableMachinePipeliner() const override
;
361 /// Machine Pipeliner customization
362 bool useDFAforSMS() const override
;
363 /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
364 bool enablePostRAScheduler() const override
;
365 AntiDepBreakMode
getAntiDepBreakMode() const override
;
366 void getCriticalPathRCs(RegClassVector
&CriticalPathRCs
) const override
;
368 void overrideSchedPolicy(MachineSchedPolicy
&Policy
,
369 unsigned NumRegionInstrs
) const override
;
370 bool useAA() const override
;
372 bool enableSubRegLiveness() const override
;
374 /// True if the GV will be accessed via an indirect symbol.
375 bool isGVIndirectSymbol(const GlobalValue
*GV
) const;
377 /// True if the ABI is descriptor based.
378 bool usesFunctionDescriptors() const {
379 // Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
380 // v1 ABI uses descriptors.
381 return isAIXABI() || (is64BitELFABI() && !isELFv2ABI());
384 unsigned descriptorTOCAnchorOffset() const {
385 assert(usesFunctionDescriptors() &&
386 "Should only be called when the target uses descriptors.");
387 return IsPPC64
? 8 : 4;
390 unsigned descriptorEnvironmentPointerOffset() const {
391 assert(usesFunctionDescriptors() &&
392 "Should only be called when the target uses descriptors.");
393 return IsPPC64
? 16 : 8;
396 MCRegister
getEnvironmentPointerRegister() const {
397 assert(usesFunctionDescriptors() &&
398 "Should only be called when the target uses descriptors.");
399 return IsPPC64
? PPC::X11
: PPC::R11
;
402 MCRegister
getTOCPointerRegister() const {
403 assert((is64BitELFABI() || isAIXABI()) &&
404 "Should only be called when the target is a TOC based ABI.");
405 return IsPPC64
? PPC::X2
: PPC::R2
;
408 MCRegister
getStackPointerRegister() const {
409 return IsPPC64
? PPC::X1
: PPC::R1
;
412 bool isXRaySupported() const override
{ return IsPPC64
&& IsLittleEndian
; }
414 bool isPredictableSelectIsExpensive() const {
415 return PredictableSelectIsExpensive
;
418 // Select allocation orders of GPRC and G8RC. It should be strictly consistent
419 // with corresponding AltOrders in PPCRegisterInfo.td.
420 unsigned getGPRAllocationOrderIdx() const {
429 const CallLowering
*getCallLowering() const override
;
430 const RegisterBankInfo
*getRegBankInfo() const override
;
431 const LegalizerInfo
*getLegalizerInfo() const override
;
432 InstructionSelector
*getInstructionSelector() const override
;
434 } // End llvm namespace