Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===// |
Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 10 | // This file implements the PPC specific subclass of TargetSubtargetInfo. |
Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | bfca1ab | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 14 | #include "PPCSubtarget.h" |
| 15 | #include "PPC.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "PPCRegisterInfo.h" |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 17 | #include "PPCTargetMachine.h" |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" |
Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineScheduler.h" |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Attributes.h" |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Function.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 22 | #include "llvm/IR/GlobalValue.h" |
Hal Finkel | 5ff00b4 | 2015-01-09 02:03:11 +0000 | [diff] [blame] | 23 | #include "llvm/Support/CommandLine.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 24 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachine.h" |
Dan Gohman | 906152a | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 26 | #include <cstdlib> |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 27 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 30 | #define DEBUG_TYPE "ppc-subtarget" |
| 31 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 32 | #define GET_SUBTARGETINFO_TARGET_DESC |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 33 | #define GET_SUBTARGETINFO_CTOR |
Evan Cheng | c9c090d | 2011-07-01 22:36:09 +0000 | [diff] [blame] | 34 | #include "PPCGenSubtargetInfo.inc" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 35 | |
Hal Finkel | 5ff00b4 | 2015-01-09 02:03:11 +0000 | [diff] [blame] | 36 | static cl::opt<bool> UseSubRegLiveness("ppc-track-subreg-liveness", |
| 37 | cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden); |
| 38 | |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 39 | static cl::opt<bool> QPXStackUnaligned("qpx-stack-unaligned", |
| 40 | cl::desc("Even when QPX is enabled the stack is not 32-byte aligned"), |
| 41 | cl::Hidden); |
| 42 | |
Eric Christopher | d104c31 | 2014-06-12 20:54:11 +0000 | [diff] [blame] | 43 | PPCSubtarget &PPCSubtarget::initializeSubtargetDependencies(StringRef CPU, |
| 44 | StringRef FS) { |
| 45 | initializeEnvironment(); |
Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 46 | initSubtargetFeatures(CPU, FS); |
Eric Christopher | d104c31 | 2014-06-12 20:54:11 +0000 | [diff] [blame] | 47 | return *this; |
| 48 | } |
| 49 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 50 | PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU, |
Eric Christopher | f6ed33e | 2014-10-01 21:36:28 +0000 | [diff] [blame] | 51 | const std::string &FS, const PPCTargetMachine &TM) |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 52 | : PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT), |
Eric Christopher | 3770cf5 | 2014-08-09 04:38:56 +0000 | [diff] [blame] | 53 | IsPPC64(TargetTriple.getArch() == Triple::ppc64 || |
| 54 | TargetTriple.getArch() == Triple::ppc64le), |
Eric Christopher | fee6aaf | 2015-02-17 06:45:15 +0000 | [diff] [blame] | 55 | TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, FS)), |
Mehdi Amini | 157e5a6 | 2015-07-09 02:10:08 +0000 | [diff] [blame] | 56 | InstrInfo(*this), TLInfo(TM, *this) {} |
Eric Christopher | b9fd9ed | 2014-08-07 22:02:54 +0000 | [diff] [blame] | 57 | |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 58 | void PPCSubtarget::initializeEnvironment() { |
| 59 | StackAlignment = 16; |
| 60 | DarwinDirective = PPC::DIR_NONE; |
| 61 | HasMFOCRF = false; |
| 62 | Has64BitSupport = false; |
| 63 | Use64BitRegs = false; |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 64 | UseCRBits = false; |
Hal Finkel | a932105 | 2016-10-02 02:10:20 +0000 | [diff] [blame] | 65 | HasHardFloat = false; |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 66 | HasAltivec = false; |
Joerg Sonnenberger | 39f095a | 2014-08-07 12:18:21 +0000 | [diff] [blame] | 67 | HasSPE = false; |
Justin Hibbits | d52990c | 2018-07-18 04:25:10 +0000 | [diff] [blame] | 68 | HasFPU = false; |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 69 | HasQPX = false; |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 70 | HasVSX = false; |
Bill Schmidt | dcce023 | 2014-10-10 17:21:15 +0000 | [diff] [blame] | 71 | HasP8Vector = false; |
Bill Schmidt | fe88b18 | 2015-02-03 21:58:23 +0000 | [diff] [blame] | 72 | HasP8Altivec = false; |
Nemanja Ivanovic | e8effe1 | 2015-03-04 20:44:33 +0000 | [diff] [blame] | 73 | HasP8Crypto = false; |
Kit Barton | 93612ec | 2016-02-26 21:11:55 +0000 | [diff] [blame] | 74 | HasP9Vector = false; |
| 75 | HasP9Altivec = false; |
Hal Finkel | dbc78e1 | 2013-08-19 05:01:02 +0000 | [diff] [blame] | 76 | HasFCPSGN = false; |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 77 | HasFSQRT = false; |
| 78 | HasFRE = false; |
| 79 | HasFRES = false; |
| 80 | HasFRSQRTE = false; |
| 81 | HasFRSQRTES = false; |
| 82 | HasRecipPrec = false; |
| 83 | HasSTFIWX = false; |
| 84 | HasLFIWAX = false; |
| 85 | HasFPRND = false; |
| 86 | HasFPCVT = false; |
| 87 | HasISEL = false; |
Nemanja Ivanovic | c090479 | 2015-04-09 23:54:37 +0000 | [diff] [blame] | 88 | HasBPERMD = false; |
| 89 | HasExtDiv = false; |
Hal Finkel | 4edc66b | 2015-01-03 01:16:37 +0000 | [diff] [blame] | 90 | HasCMPB = false; |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 91 | HasLDBRX = false; |
| 92 | IsBookE = false; |
Hal Finkel | fe3368c | 2014-10-02 22:34:22 +0000 | [diff] [blame] | 93 | HasOnlyMSYNC = false; |
Joerg Sonnenberger | 0b2ebcb | 2014-08-04 15:47:38 +0000 | [diff] [blame] | 94 | IsPPC4xx = false; |
Joerg Sonnenberger | 7405210 | 2014-08-04 17:07:41 +0000 | [diff] [blame] | 95 | IsPPC6xx = false; |
Joerg Sonnenberger | 0b2ebcb | 2014-08-04 15:47:38 +0000 | [diff] [blame] | 96 | IsE500 = false; |
Kit Barton | 4f79f96 | 2015-06-16 16:01:15 +0000 | [diff] [blame] | 97 | FeatureMFTB = false; |
Hal Finkel | 0096dbd | 2013-09-12 14:40:06 +0000 | [diff] [blame] | 98 | DeprecatedDST = false; |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 99 | HasLazyResolverStubs = false; |
Bill Schmidt | 082cfc0 | 2015-01-14 20:17:10 +0000 | [diff] [blame] | 100 | HasICBT = false; |
Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 101 | HasInvariantFunctionDescriptors = false; |
Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 102 | HasPartwordAtomics = false; |
Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 103 | HasDirectMove = false; |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 104 | IsQPXStackUnaligned = false; |
Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 105 | HasHTM = false; |
Eric Christopher | 25bf4a8 | 2015-11-20 22:38:20 +0000 | [diff] [blame] | 106 | HasFusion = false; |
Nemanja Ivanovic | b033f67 | 2015-12-15 12:19:34 +0000 | [diff] [blame] | 107 | HasFloat128 = false; |
Nemanja Ivanovic | a621a7f | 2016-03-31 15:26:37 +0000 | [diff] [blame] | 108 | IsISA3_0 = false; |
Hal Finkel | b074a60 | 2016-08-30 00:59:23 +0000 | [diff] [blame] | 109 | UseLongCalls = false; |
Sterling Augustine | 33dc018 | 2018-03-27 21:11:57 +0000 | [diff] [blame] | 110 | SecurePlt = false; |
Hal Finkel | fa7057a | 2016-03-29 01:36:01 +0000 | [diff] [blame] | 111 | |
| 112 | HasPOPCNTD = POPCNTD_Unavailable; |
Hal Finkel | a0014a5 | 2013-07-15 22:29:40 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Eric Christopher | b68e253 | 2014-09-03 20:36:31 +0000 | [diff] [blame] | 115 | void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { |
Jim Laskey | 19058c3 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 116 | // Determine default and user specified characteristics |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 117 | std::string CPUName = CPU; |
Nemanja Ivanovic | 1a5706c | 2016-02-29 16:42:27 +0000 | [diff] [blame] | 118 | if (CPUName.empty() || CPU == "generic") { |
Bill Schmidt | 8cf15ce | 2015-01-29 15:59:09 +0000 | [diff] [blame] | 119 | // If cross-compiling with -march=ppc64le without -mcpu |
| 120 | if (TargetTriple.getArch() == Triple::ppc64le) |
| 121 | CPUName = "ppc64le"; |
| 122 | else |
| 123 | CPUName = "generic"; |
| 124 | } |
Jim Laskey | a2b5235 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 125 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 126 | // Initialize scheduling itinerary for the specified CPU. |
| 127 | InstrItins = getInstrItineraryForCPU(CPUName); |
| 128 | |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 129 | // Parse features string. |
Eric Christopher | 36448af | 2014-10-01 20:38:26 +0000 | [diff] [blame] | 130 | ParseSubtargetFeatures(CPUName, FS); |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 131 | |
Chris Lattner | 16682ff | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 132 | // If the user requested use of 64-bit regs, but the cpu selected doesn't |
Dale Johannesen | 2e01912 | 2008-02-15 18:40:53 +0000 | [diff] [blame] | 133 | // support it, ignore. |
Eric Christopher | 36448af | 2014-10-01 20:38:26 +0000 | [diff] [blame] | 134 | if (IsPPC64 && has64BitSupport()) |
| 135 | Use64BitRegs = true; |
Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 136 | |
| 137 | // Set up darwin-specific properties. |
Chris Lattner | e655521 | 2009-08-11 22:49:34 +0000 | [diff] [blame] | 138 | if (isDarwin()) |
Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 139 | HasLazyResolverStubs = true; |
Hal Finkel | e1df909 | 2013-01-30 23:43:27 +0000 | [diff] [blame] | 140 | |
Justin Hibbits | d52990c | 2018-07-18 04:25:10 +0000 | [diff] [blame] | 141 | if (HasSPE && IsPPC64) |
| 142 | report_fatal_error( "SPE is only supported for 32-bit targets.\n", false); |
| 143 | if (HasSPE && (HasAltivec || HasQPX || HasVSX || HasFPU)) |
| 144 | report_fatal_error( |
| 145 | "SPE and traditional floating point cannot both be enabled.\n", false); |
| 146 | |
| 147 | // If not SPE, set standard FPU |
| 148 | if (!HasSPE) |
| 149 | HasFPU = true; |
| 150 | |
Hal Finkel | e1df909 | 2013-01-30 23:43:27 +0000 | [diff] [blame] | 151 | // QPX requires a 32-byte aligned stack. Note that we need to do this if |
| 152 | // we're compiling for a BG/Q system regardless of whether or not QPX |
| 153 | // is enabled because external functions will assume this alignment. |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 154 | IsQPXStackUnaligned = QPXStackUnaligned; |
| 155 | StackAlignment = getPlatformStackAlignment(); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame] | 156 | |
| 157 | // Determine endianness. |
Eric Christopher | 75dc390 | 2015-02-17 06:45:17 +0000 | [diff] [blame] | 158 | // FIXME: Part of the TargetMachine. |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame] | 159 | IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le); |
Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Rafael Espindola | 65787a9 | 2016-06-23 20:50:42 +0000 | [diff] [blame] | 162 | /// Return true if accesses to the specified global have to go through a dyld |
| 163 | /// lazy resolution stub. This means that an extra load is required to get the |
| 164 | /// address of the global. |
Eric Christopher | e8dbfe1 | 2015-02-13 22:23:04 +0000 | [diff] [blame] | 165 | bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const { |
Rafael Espindola | 65787a9 | 2016-06-23 20:50:42 +0000 | [diff] [blame] | 166 | if (!HasLazyResolverStubs) |
Chris Lattner | f4646a7 | 2006-12-11 23:22:45 +0000 | [diff] [blame] | 167 | return false; |
Rafael Espindola | 3beef8d | 2016-06-27 23:15:57 +0000 | [diff] [blame] | 168 | if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) |
Rafael Espindola | 65787a9 | 2016-06-23 20:50:42 +0000 | [diff] [blame] | 169 | return true; |
| 170 | // 32 bit macho has no relocation for a-b if a is undefined, even if b is in |
| 171 | // the section that is being relocated. This means we have to use o load even |
| 172 | // for GVs that are known to be local to the dso. |
| 173 | if (GV->isDeclarationForLinker() || GV->hasCommonLinkage()) |
| 174 | return true; |
| 175 | return false; |
Nate Begeman | 3bcfcd9 | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 176 | } |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 177 | |
Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 178 | bool PPCSubtarget::enableMachineScheduler() const { |
Stefan Pintilie | 0c122d5 | 2018-07-19 19:34:18 +0000 | [diff] [blame] | 179 | return true; |
Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 182 | // This overrides the PostRAScheduler bit in the SchedModel for each CPU. |
Matthias Braun | 39a2afc | 2015-06-13 03:42:16 +0000 | [diff] [blame] | 183 | bool PPCSubtarget::enablePostRAScheduler() const { return true; } |
Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 184 | |
| 185 | PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const { |
| 186 | return TargetSubtargetInfo::ANTIDEP_ALL; |
| 187 | } |
| 188 | |
| 189 | void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const { |
| 190 | CriticalPathRCs.clear(); |
| 191 | CriticalPathRCs.push_back(isPPC64() ? |
| 192 | &PPC::G8RCRegClass : &PPC::GPRCRegClass); |
| 193 | } |
| 194 | |
Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 195 | void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 196 | unsigned NumRegionInstrs) const { |
Stefan Pintilie | 0c122d5 | 2018-07-19 19:34:18 +0000 | [diff] [blame] | 197 | // The GenericScheduler that we use defaults to scheduling bottom up only. |
| 198 | // We want to schedule from both the top and the bottom and so we set |
| 199 | // OnlyBottomUp to false. |
| 200 | // We want to do bi-directional scheduling since it provides a more balanced |
| 201 | // schedule leading to better performance. |
| 202 | Policy.OnlyBottomUp = false; |
Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 203 | // Spilling is generally expensive on all PPC cores, so always enable |
| 204 | // register-pressure tracking. |
| 205 | Policy.ShouldTrackPressure = true; |
| 206 | } |
| 207 | |
| 208 | bool PPCSubtarget::useAA() const { |
Stefan Pintilie | 0c122d5 | 2018-07-19 19:34:18 +0000 | [diff] [blame] | 209 | return true; |
Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Hal Finkel | 5ff00b4 | 2015-01-09 02:03:11 +0000 | [diff] [blame] | 212 | bool PPCSubtarget::enableSubRegLiveness() const { |
| 213 | return UseSubRegLiveness; |
| 214 | } |
| 215 | |
Rafael Espindola | 82149a1 | 2017-01-26 15:02:31 +0000 | [diff] [blame] | 216 | unsigned char |
| 217 | PPCSubtarget::classifyGlobalReference(const GlobalValue *GV) const { |
Eric Christopher | c180836 | 2015-11-20 20:51:31 +0000 | [diff] [blame] | 218 | // Note that currently we don't generate non-pic references. |
| 219 | // If a caller wants that, this will have to be updated. |
| 220 | |
| 221 | // Large code model always uses the TOC even for local symbols. |
| 222 | if (TM.getCodeModel() == CodeModel::Large) |
| 223 | return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG; |
| 224 | |
Rafael Espindola | 82149a1 | 2017-01-26 15:02:31 +0000 | [diff] [blame] | 225 | if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) |
| 226 | return PPCII::MO_PIC_FLAG; |
| 227 | return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG; |
Eric Christopher | c180836 | 2015-11-20 20:51:31 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Eric Christopher | fee6aaf | 2015-02-17 06:45:15 +0000 | [diff] [blame] | 230 | bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); } |
| 231 | bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); } |