Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 1 | //===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===// |
| 2 | // |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 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 |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the PPC specific subclass of TargetSubtargetInfo. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "PPCSubtarget.h" |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 14 | #include "GISel/PPCCallLowering.h" |
| 15 | #include "GISel/PPCLegalizerInfo.h" |
| 16 | #include "GISel/PPCRegisterBankInfo.h" |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 17 | #include "PPC.h" |
| 18 | #include "PPCRegisterInfo.h" |
| 19 | #include "PPCTargetMachine.h" |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 20 | #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineScheduler.h" |
| 23 | #include "llvm/IR/Attributes.h" |
| 24 | #include "llvm/IR/Function.h" |
| 25 | #include "llvm/IR/GlobalValue.h" |
| 26 | #include "llvm/Support/CommandLine.h" |
| 27 | #include "llvm/Support/TargetRegistry.h" |
| 28 | #include "llvm/Target/TargetMachine.h" |
| 29 | #include <cstdlib> |
| 30 | |
| 31 | using namespace llvm; |
| 32 | |
| 33 | #define DEBUG_TYPE "ppc-subtarget" |
| 34 | |
| 35 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 36 | #define GET_SUBTARGETINFO_CTOR |
| 37 | #include "PPCGenSubtargetInfo.inc" |
| 38 | |
| 39 | static cl::opt<bool> UseSubRegLiveness("ppc-track-subreg-liveness", |
| 40 | cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden); |
| 41 | |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 42 | static cl::opt<bool> |
| 43 | EnableMachinePipeliner("ppc-enable-pipeliner", |
| 44 | cl::desc("Enable Machine Pipeliner for PPC"), |
| 45 | cl::init(false), cl::Hidden); |
| 46 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 47 | PPCSubtarget &PPCSubtarget::initializeSubtargetDependencies(StringRef CPU, |
| 48 | StringRef FS) { |
| 49 | initializeEnvironment(); |
| 50 | initSubtargetFeatures(CPU, FS); |
| 51 | return *this; |
| 52 | } |
| 53 | |
| 54 | PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU, |
| 55 | const std::string &FS, const PPCTargetMachine &TM) |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 56 | : PPCGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TargetTriple(TT), |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 57 | IsPPC64(TargetTriple.getArch() == Triple::ppc64 || |
| 58 | TargetTriple.getArch() == Triple::ppc64le), |
| 59 | TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, FS)), |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 60 | InstrInfo(*this), TLInfo(TM, *this) { |
| 61 | CallLoweringInfo.reset(new PPCCallLowering(*getTargetLowering())); |
| 62 | Legalizer.reset(new PPCLegalizerInfo(*this)); |
| 63 | auto *RBI = new PPCRegisterBankInfo(*getRegisterInfo()); |
| 64 | RegBankInfo.reset(RBI); |
| 65 | |
| 66 | InstSelector.reset(createPPCInstructionSelector( |
| 67 | *static_cast<const PPCTargetMachine *>(&TM), *this, *RBI)); |
| 68 | } |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 69 | |
| 70 | void PPCSubtarget::initializeEnvironment() { |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 71 | StackAlignment = Align(16); |
| 72 | CPUDirective = PPC::DIR_NONE; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 73 | HasMFOCRF = false; |
| 74 | Has64BitSupport = false; |
| 75 | Use64BitRegs = false; |
| 76 | UseCRBits = false; |
| 77 | HasHardFloat = false; |
| 78 | HasAltivec = false; |
| 79 | HasSPE = false; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 80 | HasEFPU2 = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 81 | HasFPU = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 82 | HasVSX = false; |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 83 | NeedsTwoConstNR = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 84 | HasP8Vector = false; |
| 85 | HasP8Altivec = false; |
| 86 | HasP8Crypto = false; |
| 87 | HasP9Vector = false; |
| 88 | HasP9Altivec = false; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 89 | HasMMA = false; |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame^] | 90 | HasROPProtect = false; |
| 91 | HasPrivileged = false; |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 92 | HasP10Vector = false; |
| 93 | HasPrefixInstrs = false; |
| 94 | HasPCRelativeMemops = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 95 | HasFCPSGN = false; |
| 96 | HasFSQRT = false; |
| 97 | HasFRE = false; |
| 98 | HasFRES = false; |
| 99 | HasFRSQRTE = false; |
| 100 | HasFRSQRTES = false; |
| 101 | HasRecipPrec = false; |
| 102 | HasSTFIWX = false; |
| 103 | HasLFIWAX = false; |
| 104 | HasFPRND = false; |
| 105 | HasFPCVT = false; |
| 106 | HasISEL = false; |
| 107 | HasBPERMD = false; |
| 108 | HasExtDiv = false; |
| 109 | HasCMPB = false; |
| 110 | HasLDBRX = false; |
| 111 | IsBookE = false; |
| 112 | HasOnlyMSYNC = false; |
| 113 | IsPPC4xx = false; |
| 114 | IsPPC6xx = false; |
| 115 | IsE500 = false; |
| 116 | FeatureMFTB = false; |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 117 | AllowsUnalignedFPAccess = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 118 | DeprecatedDST = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 119 | HasICBT = false; |
| 120 | HasInvariantFunctionDescriptors = false; |
| 121 | HasPartwordAtomics = false; |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame^] | 122 | HasQuadwordAtomics = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 123 | HasDirectMove = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 124 | HasHTM = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 125 | HasFloat128 = false; |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 126 | HasFusion = false; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 127 | HasStoreFusion = false; |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 128 | HasAddiLoadFusion = false; |
| 129 | HasAddisLoadFusion = false; |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame^] | 130 | IsISA2_07 = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 131 | IsISA3_0 = false; |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 132 | IsISA3_1 = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 133 | UseLongCalls = false; |
| 134 | SecurePlt = false; |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 135 | VectorsUseTwoUnits = false; |
| 136 | UsePPCPreRASchedStrategy = false; |
| 137 | UsePPCPostRASchedStrategy = false; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 138 | PairedVectorMemops = false; |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 139 | PredictableSelectIsExpensive = false; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 140 | HasModernAIXAs = false; |
| 141 | IsAIX = false; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 142 | |
| 143 | HasPOPCNTD = POPCNTD_Unavailable; |
| 144 | } |
| 145 | |
| 146 | void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { |
| 147 | // Determine default and user specified characteristics |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 148 | std::string CPUName = std::string(CPU); |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 149 | if (CPUName.empty() || CPU == "generic") { |
| 150 | // If cross-compiling with -march=ppc64le without -mcpu |
| 151 | if (TargetTriple.getArch() == Triple::ppc64le) |
| 152 | CPUName = "ppc64le"; |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 153 | else if (TargetTriple.getSubArch() == Triple::PPCSubArch_spe) |
| 154 | CPUName = "e500"; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 155 | else |
| 156 | CPUName = "generic"; |
| 157 | } |
| 158 | |
| 159 | // Initialize scheduling itinerary for the specified CPU. |
| 160 | InstrItins = getInstrItineraryForCPU(CPUName); |
| 161 | |
| 162 | // Parse features string. |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 163 | ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS); |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 164 | |
| 165 | // If the user requested use of 64-bit regs, but the cpu selected doesn't |
| 166 | // support it, ignore. |
| 167 | if (IsPPC64 && has64BitSupport()) |
| 168 | Use64BitRegs = true; |
| 169 | |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 170 | if ((TargetTriple.isOSFreeBSD() && TargetTriple.getOSMajorVersion() >= 13) || |
| 171 | TargetTriple.isOSNetBSD() || TargetTriple.isOSOpenBSD() || |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 172 | TargetTriple.isMusl()) |
| 173 | SecurePlt = true; |
| 174 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 175 | if (HasSPE && IsPPC64) |
| 176 | report_fatal_error( "SPE is only supported for 32-bit targets.\n", false); |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 177 | if (HasSPE && (HasAltivec || HasVSX || HasFPU)) |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 178 | report_fatal_error( |
| 179 | "SPE and traditional floating point cannot both be enabled.\n", false); |
| 180 | |
| 181 | // If not SPE, set standard FPU |
| 182 | if (!HasSPE) |
| 183 | HasFPU = true; |
| 184 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 185 | StackAlignment = getPlatformStackAlignment(); |
| 186 | |
| 187 | // Determine endianness. |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame^] | 188 | IsLittleEndian = TM.isLittleEndian(); |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 191 | bool PPCSubtarget::enableMachineScheduler() const { return true; } |
| 192 | |
| 193 | bool PPCSubtarget::enableMachinePipeliner() const { |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 194 | return getSchedModel().hasInstrSchedModel() && EnableMachinePipeliner; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 197 | bool PPCSubtarget::useDFAforSMS() const { return false; } |
| 198 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 199 | // This overrides the PostRAScheduler bit in the SchedModel for each CPU. |
| 200 | bool PPCSubtarget::enablePostRAScheduler() const { return true; } |
| 201 | |
| 202 | PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const { |
| 203 | return TargetSubtargetInfo::ANTIDEP_ALL; |
| 204 | } |
| 205 | |
| 206 | void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const { |
| 207 | CriticalPathRCs.clear(); |
| 208 | CriticalPathRCs.push_back(isPPC64() ? |
| 209 | &PPC::G8RCRegClass : &PPC::GPRCRegClass); |
| 210 | } |
| 211 | |
| 212 | void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
| 213 | unsigned NumRegionInstrs) const { |
| 214 | // The GenericScheduler that we use defaults to scheduling bottom up only. |
| 215 | // We want to schedule from both the top and the bottom and so we set |
| 216 | // OnlyBottomUp to false. |
| 217 | // We want to do bi-directional scheduling since it provides a more balanced |
| 218 | // schedule leading to better performance. |
| 219 | Policy.OnlyBottomUp = false; |
| 220 | // Spilling is generally expensive on all PPC cores, so always enable |
| 221 | // register-pressure tracking. |
| 222 | Policy.ShouldTrackPressure = true; |
| 223 | } |
| 224 | |
| 225 | bool PPCSubtarget::useAA() const { |
| 226 | return true; |
| 227 | } |
| 228 | |
| 229 | bool PPCSubtarget::enableSubRegLiveness() const { |
| 230 | return UseSubRegLiveness; |
| 231 | } |
| 232 | |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 233 | bool PPCSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const { |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 234 | // Large code model always uses the TOC even for local symbols. |
| 235 | if (TM.getCodeModel() == CodeModel::Large) |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 236 | return true; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 237 | if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 238 | return false; |
| 239 | return true; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); } |
| 243 | bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); } |
Thiébaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 244 | |
| 245 | bool PPCSubtarget::isUsingPCRelativeCalls() const { |
| 246 | return isPPC64() && hasPCRelativeMemops() && isELFv2ABI() && |
| 247 | CodeModel::Medium == getTargetMachine().getCodeModel(); |
| 248 | } |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 249 | |
| 250 | // GlobalISEL |
| 251 | const CallLowering *PPCSubtarget::getCallLowering() const { |
| 252 | return CallLoweringInfo.get(); |
| 253 | } |
| 254 | |
| 255 | const RegisterBankInfo *PPCSubtarget::getRegBankInfo() const { |
| 256 | return RegBankInfo.get(); |
| 257 | } |
| 258 | |
| 259 | const LegalizerInfo *PPCSubtarget::getLegalizerInfo() const { |
| 260 | return Legalizer.get(); |
| 261 | } |
| 262 | |
| 263 | InstructionSelector *PPCSubtarget::getInstructionSelector() const { |
| 264 | return InstSelector.get(); |
| 265 | } |