blob: 02c73e16e8ef7a4c019c096110e6253f03cf6ed0 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
Nate Begeman3bcfcd92005-08-04 07:12:09 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Nate Begeman3bcfcd92005-08-04 07:12:09 +00006//
7//===----------------------------------------------------------------------===//
8//
Evan Cheng0d639a22011-07-01 21:01:15 +00009// This file implements the PPC specific subclass of TargetSubtargetInfo.
Nate Begeman3bcfcd92005-08-04 07:12:09 +000010//
11//===----------------------------------------------------------------------===//
12
Chris Lattnerbfca1ab2005-10-14 23:51:18 +000013#include "PPCSubtarget.h"
14#include "PPC.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "PPCRegisterInfo.h"
Eric Christopher8b770652015-01-26 19:03:15 +000016#include "PPCTargetMachine.h"
Hal Finkela0014a52013-07-15 22:29:40 +000017#include "llvm/CodeGen/MachineFunction.h"
Hal Finkel21442b22013-09-11 23:05:25 +000018#include "llvm/CodeGen/MachineScheduler.h"
Hal Finkela0014a52013-07-15 22:29:40 +000019#include "llvm/IR/Attributes.h"
Hal Finkela0014a52013-07-15 22:29:40 +000020#include "llvm/IR/Function.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000021#include "llvm/IR/GlobalValue.h"
Hal Finkel5ff00b42015-01-09 02:03:11 +000022#include "llvm/Support/CommandLine.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000023#include "llvm/Support/TargetRegistry.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/Target/TargetMachine.h"
Dan Gohman906152a2009-01-05 17:59:02 +000025#include <cstdlib>
Evan Cheng54b68e32011-07-01 20:45:01 +000026
Chandler Carruthd174b722014-04-22 02:03:14 +000027using namespace llvm;
28
Chandler Carruthe96dd892014-04-21 22:55:11 +000029#define DEBUG_TYPE "ppc-subtarget"
30
Evan Cheng54b68e32011-07-01 20:45:01 +000031#define GET_SUBTARGETINFO_TARGET_DESC
Evan Cheng4d1ca962011-07-08 01:53:10 +000032#define GET_SUBTARGETINFO_CTOR
Evan Chengc9c090d2011-07-01 22:36:09 +000033#include "PPCGenSubtargetInfo.inc"
Evan Cheng54b68e32011-07-01 20:45:01 +000034
Hal Finkel5ff00b42015-01-09 02:03:11 +000035static cl::opt<bool> UseSubRegLiveness("ppc-track-subreg-liveness",
36cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden);
37
Hal Finkelc93a9a22015-02-25 01:06:45 +000038static cl::opt<bool> QPXStackUnaligned("qpx-stack-unaligned",
39 cl::desc("Even when QPX is enabled the stack is not 32-byte aligned"),
40 cl::Hidden);
41
Eric Christopherd104c312014-06-12 20:54:11 +000042PPCSubtarget &PPCSubtarget::initializeSubtargetDependencies(StringRef CPU,
43 StringRef FS) {
44 initializeEnvironment();
Eric Christopherb68e2532014-09-03 20:36:31 +000045 initSubtargetFeatures(CPU, FS);
Eric Christopherd104c312014-06-12 20:54:11 +000046 return *this;
47}
48
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000049PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU,
Eric Christopherf6ed33e2014-10-01 21:36:28 +000050 const std::string &FS, const PPCTargetMachine &TM)
Daniel Sanders50f17232015-09-15 16:17:27 +000051 : PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT),
Eric Christopher3770cf52014-08-09 04:38:56 +000052 IsPPC64(TargetTriple.getArch() == Triple::ppc64 ||
53 TargetTriple.getArch() == Triple::ppc64le),
Eric Christopherfee6aaf2015-02-17 06:45:15 +000054 TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, FS)),
Mehdi Amini157e5a62015-07-09 02:10:08 +000055 InstrInfo(*this), TLInfo(TM, *this) {}
Eric Christopherb9fd9ed2014-08-07 22:02:54 +000056
Hal Finkela0014a52013-07-15 22:29:40 +000057void PPCSubtarget::initializeEnvironment() {
58 StackAlignment = 16;
59 DarwinDirective = PPC::DIR_NONE;
60 HasMFOCRF = false;
61 Has64BitSupport = false;
62 Use64BitRegs = false;
Hal Finkel940ab932014-02-28 00:27:01 +000063 UseCRBits = false;
Hal Finkela9321052016-10-02 02:10:20 +000064 HasHardFloat = false;
Hal Finkela0014a52013-07-15 22:29:40 +000065 HasAltivec = false;
Joerg Sonnenberger39f095a2014-08-07 12:18:21 +000066 HasSPE = false;
Justin Hibbitsd52990c2018-07-18 04:25:10 +000067 HasFPU = false;
Hal Finkela0014a52013-07-15 22:29:40 +000068 HasQPX = false;
Hal Finkel27774d92014-03-13 07:58:58 +000069 HasVSX = false;
Bill Schmidtdcce0232014-10-10 17:21:15 +000070 HasP8Vector = false;
Bill Schmidtfe88b182015-02-03 21:58:23 +000071 HasP8Altivec = false;
Nemanja Ivanovice8effe12015-03-04 20:44:33 +000072 HasP8Crypto = false;
Kit Barton93612ec2016-02-26 21:11:55 +000073 HasP9Vector = false;
74 HasP9Altivec = false;
Hal Finkeldbc78e12013-08-19 05:01:02 +000075 HasFCPSGN = false;
Hal Finkela0014a52013-07-15 22:29:40 +000076 HasFSQRT = false;
77 HasFRE = false;
78 HasFRES = false;
79 HasFRSQRTE = false;
80 HasFRSQRTES = false;
81 HasRecipPrec = false;
82 HasSTFIWX = false;
83 HasLFIWAX = false;
84 HasFPRND = false;
85 HasFPCVT = false;
86 HasISEL = false;
Nemanja Ivanovicc0904792015-04-09 23:54:37 +000087 HasBPERMD = false;
88 HasExtDiv = false;
Hal Finkel4edc66b2015-01-03 01:16:37 +000089 HasCMPB = false;
Hal Finkela0014a52013-07-15 22:29:40 +000090 HasLDBRX = false;
91 IsBookE = false;
Hal Finkelfe3368c2014-10-02 22:34:22 +000092 HasOnlyMSYNC = false;
Joerg Sonnenberger0b2ebcb2014-08-04 15:47:38 +000093 IsPPC4xx = false;
Joerg Sonnenberger74052102014-08-04 17:07:41 +000094 IsPPC6xx = false;
Joerg Sonnenberger0b2ebcb2014-08-04 15:47:38 +000095 IsE500 = false;
Kit Barton4f79f962015-06-16 16:01:15 +000096 FeatureMFTB = false;
Hal Finkel0096dbd2013-09-12 14:40:06 +000097 DeprecatedDST = false;
Hal Finkela0014a52013-07-15 22:29:40 +000098 HasLazyResolverStubs = false;
Bill Schmidt082cfc02015-01-14 20:17:10 +000099 HasICBT = false;
Hal Finkele2ab0f12015-01-15 21:17:34 +0000100 HasInvariantFunctionDescriptors = false;
Nemanja Ivanovic0adf26b2015-03-10 20:51:07 +0000101 HasPartwordAtomics = false;
Nemanja Ivanovicc38b5312015-04-11 10:40:42 +0000102 HasDirectMove = false;
Hal Finkelc93a9a22015-02-25 01:06:45 +0000103 IsQPXStackUnaligned = false;
Kit Barton535e69d2015-03-25 19:36:23 +0000104 HasHTM = false;
Eric Christopher25bf4a82015-11-20 22:38:20 +0000105 HasFusion = false;
Nemanja Ivanovicb033f672015-12-15 12:19:34 +0000106 HasFloat128 = false;
Nemanja Ivanovica621a7f2016-03-31 15:26:37 +0000107 IsISA3_0 = false;
Hal Finkelb074a602016-08-30 00:59:23 +0000108 UseLongCalls = false;
Sterling Augustine33dc0182018-03-27 21:11:57 +0000109 SecurePlt = false;
Hal Finkelfa7057a2016-03-29 01:36:01 +0000110
111 HasPOPCNTD = POPCNTD_Unavailable;
Hal Finkela0014a52013-07-15 22:29:40 +0000112}
113
Eric Christopherb68e2532014-09-03 20:36:31 +0000114void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
Jim Laskey19058c32005-09-01 21:38:21 +0000115 // Determine default and user specified characteristics
Evan Chengfe6e4052011-06-30 01:53:36 +0000116 std::string CPUName = CPU;
Nemanja Ivanovic1a5706c2016-02-29 16:42:27 +0000117 if (CPUName.empty() || CPU == "generic") {
Bill Schmidt8cf15ce2015-01-29 15:59:09 +0000118 // If cross-compiling with -march=ppc64le without -mcpu
119 if (TargetTriple.getArch() == Triple::ppc64le)
120 CPUName = "ppc64le";
121 else
122 CPUName = "generic";
123 }
Jim Laskeya2b52352005-10-26 17:30:34 +0000124
Evan Cheng54b68e32011-07-01 20:45:01 +0000125 // Initialize scheduling itinerary for the specified CPU.
126 InstrItins = getInstrItineraryForCPU(CPUName);
127
Adhemerval Zanellaf2aceda2012-10-25 12:27:42 +0000128 // Parse features string.
Eric Christopher36448af2014-10-01 20:38:26 +0000129 ParseSubtargetFeatures(CPUName, FS);
Adhemerval Zanellaf2aceda2012-10-25 12:27:42 +0000130
Chris Lattner16682ff2006-06-16 17:50:12 +0000131 // If the user requested use of 64-bit regs, but the cpu selected doesn't
Dale Johannesen2e019122008-02-15 18:40:53 +0000132 // support it, ignore.
Eric Christopher36448af2014-10-01 20:38:26 +0000133 if (IsPPC64 && has64BitSupport())
134 Use64BitRegs = true;
Chris Lattnerf4646a72006-12-11 23:22:45 +0000135
136 // Set up darwin-specific properties.
Chris Lattnere6555212009-08-11 22:49:34 +0000137 if (isDarwin())
Chris Lattnerf4646a72006-12-11 23:22:45 +0000138 HasLazyResolverStubs = true;
Hal Finkele1df9092013-01-30 23:43:27 +0000139
Justin Hibbitsd52990c2018-07-18 04:25:10 +0000140 if (HasSPE && IsPPC64)
141 report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
142 if (HasSPE && (HasAltivec || HasQPX || HasVSX || HasFPU))
143 report_fatal_error(
144 "SPE and traditional floating point cannot both be enabled.\n", false);
145
146 // If not SPE, set standard FPU
147 if (!HasSPE)
148 HasFPU = true;
149
Hal Finkele1df9092013-01-30 23:43:27 +0000150 // QPX requires a 32-byte aligned stack. Note that we need to do this if
151 // we're compiling for a BG/Q system regardless of whether or not QPX
152 // is enabled because external functions will assume this alignment.
Hal Finkelc93a9a22015-02-25 01:06:45 +0000153 IsQPXStackUnaligned = QPXStackUnaligned;
154 StackAlignment = getPlatformStackAlignment();
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000155
156 // Determine endianness.
Eric Christopher75dc3902015-02-17 06:45:17 +0000157 // FIXME: Part of the TargetMachine.
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000158 IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le);
Chris Lattnerf4646a72006-12-11 23:22:45 +0000159}
160
Rafael Espindola65787a92016-06-23 20:50:42 +0000161/// Return true if accesses to the specified global have to go through a dyld
162/// lazy resolution stub. This means that an extra load is required to get the
163/// address of the global.
Eric Christophere8dbfe12015-02-13 22:23:04 +0000164bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const {
Rafael Espindola65787a92016-06-23 20:50:42 +0000165 if (!HasLazyResolverStubs)
Chris Lattnerf4646a72006-12-11 23:22:45 +0000166 return false;
Rafael Espindola3beef8d2016-06-27 23:15:57 +0000167 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
Rafael Espindola65787a92016-06-23 20:50:42 +0000168 return true;
169 // 32 bit macho has no relocation for a-b if a is undefined, even if b is in
170 // the section that is being relocated. This means we have to use o load even
171 // for GVs that are known to be local to the dso.
172 if (GV->isDeclarationForLinker() || GV->hasCommonLinkage())
173 return true;
174 return false;
Nate Begeman3bcfcd92005-08-04 07:12:09 +0000175}
Hal Finkel58ca3602011-12-02 04:58:02 +0000176
Hal Finkel21442b22013-09-11 23:05:25 +0000177bool PPCSubtarget::enableMachineScheduler() const {
Stefan Pintilie0c122d52018-07-19 19:34:18 +0000178 return true;
Hal Finkel21442b22013-09-11 23:05:25 +0000179}
180
Sanjay Patela2f658d2014-07-15 22:39:58 +0000181// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
Matthias Braun39a2afc2015-06-13 03:42:16 +0000182bool PPCSubtarget::enablePostRAScheduler() const { return true; }
Sanjay Patela2f658d2014-07-15 22:39:58 +0000183
184PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
185 return TargetSubtargetInfo::ANTIDEP_ALL;
186}
187
188void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
189 CriticalPathRCs.clear();
190 CriticalPathRCs.push_back(isPPC64() ?
191 &PPC::G8RCRegClass : &PPC::GPRCRegClass);
192}
193
Hal Finkel21442b22013-09-11 23:05:25 +0000194void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Hal Finkel21442b22013-09-11 23:05:25 +0000195 unsigned NumRegionInstrs) const {
Stefan Pintilie0c122d52018-07-19 19:34:18 +0000196 // The GenericScheduler that we use defaults to scheduling bottom up only.
197 // We want to schedule from both the top and the bottom and so we set
198 // OnlyBottomUp to false.
199 // We want to do bi-directional scheduling since it provides a more balanced
200 // schedule leading to better performance.
201 Policy.OnlyBottomUp = false;
Hal Finkel21442b22013-09-11 23:05:25 +0000202 // Spilling is generally expensive on all PPC cores, so always enable
203 // register-pressure tracking.
204 Policy.ShouldTrackPressure = true;
205}
206
207bool PPCSubtarget::useAA() const {
Stefan Pintilie0c122d52018-07-19 19:34:18 +0000208 return true;
Hal Finkel21442b22013-09-11 23:05:25 +0000209}
210
Hal Finkel5ff00b42015-01-09 02:03:11 +0000211bool PPCSubtarget::enableSubRegLiveness() const {
212 return UseSubRegLiveness;
213}
214
Rafael Espindola82149a12017-01-26 15:02:31 +0000215unsigned char
216PPCSubtarget::classifyGlobalReference(const GlobalValue *GV) const {
Eric Christopherc1808362015-11-20 20:51:31 +0000217 // Note that currently we don't generate non-pic references.
218 // If a caller wants that, this will have to be updated.
219
220 // Large code model always uses the TOC even for local symbols.
221 if (TM.getCodeModel() == CodeModel::Large)
222 return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;
223
Rafael Espindola82149a12017-01-26 15:02:31 +0000224 if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
225 return PPCII::MO_PIC_FLAG;
226 return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;
Eric Christopherc1808362015-11-20 20:51:31 +0000227}
228
Eric Christopherfee6aaf2015-02-17 06:45:15 +0000229bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
230bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }