LLVM 20.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 unsigned NumRegionInstrs) const override;
244 bool useAA() const override;
245
246 bool enableSubRegLiveness() const override;
247
248 bool enableSpillageCopyElimination() const override { return true; }
249
250 /// True if the GV will be accessed via an indirect symbol.
251 bool isGVIndirectSymbol(const GlobalValue *GV) const;
252
253 MVT getScalarIntVT() const { return isPPC64() ? MVT::i64 : MVT::i32; }
254
255 /// Calculates the effective code model for argument GV.
257 const GlobalValue *GV) const;
258
259 /// True if the ABI is descriptor based.
261 // Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
262 // v1 ABI uses descriptors.
263 return isAIXABI() || (is64BitELFABI() && !isELFv2ABI());
264 }
265
266 unsigned descriptorTOCAnchorOffset() const {
268 "Should only be called when the target uses descriptors.");
269 return IsPPC64 ? 8 : 4;
270 }
271
274 "Should only be called when the target uses descriptors.");
275 return IsPPC64 ? 16 : 8;
276 }
277
280 "Should only be called when the target uses descriptors.");
281 return IsPPC64 ? PPC::X11 : PPC::R11;
282 }
283
285 assert((is64BitELFABI() || isAIXABI()) &&
286 "Should only be called when the target is a TOC based ABI.");
287 return IsPPC64 ? PPC::X2 : PPC::R2;
288 }
289
291 assert((is64BitELFABI() || isAIXABI()) &&
292 "Should only be called for targets with a thread pointer register.");
293 return IsPPC64 ? PPC::X13 : PPC::R13;
294 }
295
297 return IsPPC64 ? PPC::X1 : PPC::R1;
298 }
299
300 bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
301
303 return PredictableSelectIsExpensive;
304 }
305
306 // Select allocation orders of GPRC and G8RC. It should be strictly consistent
307 // with corresponding AltOrders in PPCRegisterInfo.td.
308 unsigned getGPRAllocationOrderIdx() const {
309 if (is64BitELFABI())
310 return 1;
311 if (isAIXABI())
312 return 2;
313 return 0;
314 }
315
316 // GlobalISEL
317 const CallLowering *getCallLowering() const override;
318 const RegisterBankInfo *getRegBankInfo() const override;
319 const LegalizerInfo *getLegalizerInfo() const override;
321};
322} // End llvm namespace
323
324#endif
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:275
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:266
bool isTargetMachO() const
Definition: PPCSubtarget.h:216
MVT getScalarIntVT() const
Definition: PPCSubtarget.h:253
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:308
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:300
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
void overrideSchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const override
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:260
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:278
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:290
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:248
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:284
bool isTargetELF() const
Definition: PPCSubtarget.h:215
MCRegister getStackPointerRegister() const
Definition: PPCSubtarget.h:296
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:302
std::unique_ptr< const SelectionDAGTargetInfo > TSInfo
Definition: PPCSubtarget.h:110
bool enableMachineScheduler() const override
Scheduling customization.
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:272
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:51
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:743
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:689
bool isOSAIX() const
Tests whether the OS is AIX.
Definition: Triple.h:721
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:730
@ DIR_PWR_FUTURE
Definition: PPCSubtarget.h:65
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
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.