2012-02-18 12:03:15 +00:00
|
|
|
//===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
|
2005-08-04 07:12:09 +00:00
|
|
|
//
|
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-08-04 07:12:09 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
2011-07-01 21:01:15 +00:00
|
|
|
// This file implements the PPC specific subclass of TargetSubtargetInfo.
|
2005-08-04 07:12:09 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2005-10-14 23:51:18 +00:00
|
|
|
#include "PPCSubtarget.h"
|
|
|
|
|
#include "PPC.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "PPCRegisterInfo.h"
|
2015-01-26 19:03:15 +00:00
|
|
|
#include "PPCTargetMachine.h"
|
2013-07-15 22:29:40 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2013-09-11 23:05:25 +00:00
|
|
|
#include "llvm/CodeGen/MachineScheduler.h"
|
2013-07-15 22:29:40 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
|
|
|
|
#include "llvm/IR/Function.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/IR/GlobalValue.h"
|
2015-01-09 02:03:11 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2009-01-05 17:59:02 +00:00
|
|
|
#include <cstdlib>
|
2011-07-01 20:45:01 +00:00
|
|
|
|
2014-04-22 02:03:14 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
2014-04-21 22:55:11 +00:00
|
|
|
#define DEBUG_TYPE "ppc-subtarget"
|
|
|
|
|
|
2011-07-01 20:45:01 +00:00
|
|
|
#define GET_SUBTARGETINFO_TARGET_DESC
|
2011-07-08 01:53:10 +00:00
|
|
|
#define GET_SUBTARGETINFO_CTOR
|
2011-07-01 22:36:09 +00:00
|
|
|
#include "PPCGenSubtargetInfo.inc"
|
2011-07-01 20:45:01 +00:00
|
|
|
|
2015-01-09 02:03:11 +00:00
|
|
|
static cl::opt<bool> UseSubRegLiveness("ppc-track-subreg-liveness",
|
|
|
|
|
cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden);
|
|
|
|
|
|
2015-02-25 01:06:45 +00:00
|
|
|
static cl::opt<bool> QPXStackUnaligned("qpx-stack-unaligned",
|
|
|
|
|
cl::desc("Even when QPX is enabled the stack is not 32-byte aligned"),
|
|
|
|
|
cl::Hidden);
|
|
|
|
|
|
2014-06-12 20:54:11 +00:00
|
|
|
PPCSubtarget &PPCSubtarget::initializeSubtargetDependencies(StringRef CPU,
|
|
|
|
|
StringRef FS) {
|
|
|
|
|
initializeEnvironment();
|
2014-09-03 20:36:31 +00:00
|
|
|
initSubtargetFeatures(CPU, FS);
|
2014-06-12 20:54:11 +00:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-10 12:11:26 +00:00
|
|
|
PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU,
|
2014-10-01 21:36:28 +00:00
|
|
|
const std::string &FS, const PPCTargetMachine &TM)
|
2015-09-15 16:17:27 +00:00
|
|
|
: PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT),
|
2014-08-09 04:38:56 +00:00
|
|
|
IsPPC64(TargetTriple.getArch() == Triple::ppc64 ||
|
|
|
|
|
TargetTriple.getArch() == Triple::ppc64le),
|
2015-02-17 06:45:15 +00:00
|
|
|
TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, FS)),
|
2015-07-09 02:10:08 +00:00
|
|
|
InstrInfo(*this), TLInfo(TM, *this) {}
|
2014-08-07 22:02:54 +00:00
|
|
|
|
2013-07-15 22:29:40 +00:00
|
|
|
void PPCSubtarget::initializeEnvironment() {
|
|
|
|
|
StackAlignment = 16;
|
|
|
|
|
DarwinDirective = PPC::DIR_NONE;
|
|
|
|
|
HasMFOCRF = false;
|
|
|
|
|
Has64BitSupport = false;
|
|
|
|
|
Use64BitRegs = false;
|
2014-02-28 00:27:01 +00:00
|
|
|
UseCRBits = false;
|
2016-10-02 02:10:20 +00:00
|
|
|
HasHardFloat = false;
|
2013-07-15 22:29:40 +00:00
|
|
|
HasAltivec = false;
|
2014-08-07 12:18:21 +00:00
|
|
|
HasSPE = false;
|
2013-07-15 22:29:40 +00:00
|
|
|
HasQPX = false;
|
2014-03-13 07:58:58 +00:00
|
|
|
HasVSX = false;
|
2014-10-10 17:21:15 +00:00
|
|
|
HasP8Vector = false;
|
2015-02-03 21:58:23 +00:00
|
|
|
HasP8Altivec = false;
|
2015-03-04 20:44:33 +00:00
|
|
|
HasP8Crypto = false;
|
2016-02-26 21:11:55 +00:00
|
|
|
HasP9Vector = false;
|
|
|
|
|
HasP9Altivec = false;
|
2013-08-19 05:01:02 +00:00
|
|
|
HasFCPSGN = false;
|
2013-07-15 22:29:40 +00:00
|
|
|
HasFSQRT = false;
|
|
|
|
|
HasFRE = false;
|
|
|
|
|
HasFRES = false;
|
|
|
|
|
HasFRSQRTE = false;
|
|
|
|
|
HasFRSQRTES = false;
|
|
|
|
|
HasRecipPrec = false;
|
|
|
|
|
HasSTFIWX = false;
|
|
|
|
|
HasLFIWAX = false;
|
|
|
|
|
HasFPRND = false;
|
|
|
|
|
HasFPCVT = false;
|
|
|
|
|
HasISEL = false;
|
2015-04-09 23:54:37 +00:00
|
|
|
HasBPERMD = false;
|
|
|
|
|
HasExtDiv = false;
|
2015-01-03 01:16:37 +00:00
|
|
|
HasCMPB = false;
|
2013-07-15 22:29:40 +00:00
|
|
|
HasLDBRX = false;
|
|
|
|
|
IsBookE = false;
|
2014-10-02 22:34:22 +00:00
|
|
|
HasOnlyMSYNC = false;
|
2014-08-04 15:47:38 +00:00
|
|
|
IsPPC4xx = false;
|
2014-08-04 17:07:41 +00:00
|
|
|
IsPPC6xx = false;
|
2014-08-04 15:47:38 +00:00
|
|
|
IsE500 = false;
|
2015-06-16 16:01:15 +00:00
|
|
|
FeatureMFTB = false;
|
2013-09-12 14:40:06 +00:00
|
|
|
DeprecatedDST = false;
|
2013-07-15 22:29:40 +00:00
|
|
|
HasLazyResolverStubs = false;
|
2015-01-14 20:17:10 +00:00
|
|
|
HasICBT = false;
|
2015-01-15 21:17:34 +00:00
|
|
|
HasInvariantFunctionDescriptors = false;
|
2015-03-10 20:51:07 +00:00
|
|
|
HasPartwordAtomics = false;
|
2015-04-11 10:40:42 +00:00
|
|
|
HasDirectMove = false;
|
2015-02-25 01:06:45 +00:00
|
|
|
IsQPXStackUnaligned = false;
|
2015-03-25 19:36:23 +00:00
|
|
|
HasHTM = false;
|
2015-11-20 22:38:20 +00:00
|
|
|
HasFusion = false;
|
2015-12-15 12:19:34 +00:00
|
|
|
HasFloat128 = false;
|
2016-03-31 15:26:37 +00:00
|
|
|
IsISA3_0 = false;
|
2016-08-30 00:59:23 +00:00
|
|
|
UseLongCalls = false;
|
2016-03-29 01:36:01 +00:00
|
|
|
|
|
|
|
|
HasPOPCNTD = POPCNTD_Unavailable;
|
2013-07-15 22:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 20:36:31 +00:00
|
|
|
void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
|
2005-09-01 21:38:21 +00:00
|
|
|
// Determine default and user specified characteristics
|
2011-06-30 01:53:36 +00:00
|
|
|
std::string CPUName = CPU;
|
2016-02-29 16:42:27 +00:00
|
|
|
if (CPUName.empty() || CPU == "generic") {
|
2015-01-29 15:59:09 +00:00
|
|
|
// If cross-compiling with -march=ppc64le without -mcpu
|
|
|
|
|
if (TargetTriple.getArch() == Triple::ppc64le)
|
|
|
|
|
CPUName = "ppc64le";
|
|
|
|
|
else
|
|
|
|
|
CPUName = "generic";
|
|
|
|
|
}
|
2005-10-26 17:30:34 +00:00
|
|
|
|
2011-07-01 20:45:01 +00:00
|
|
|
// Initialize scheduling itinerary for the specified CPU.
|
|
|
|
|
InstrItins = getInstrItineraryForCPU(CPUName);
|
|
|
|
|
|
2012-10-25 12:27:42 +00:00
|
|
|
// Parse features string.
|
2014-10-01 20:38:26 +00:00
|
|
|
ParseSubtargetFeatures(CPUName, FS);
|
2012-10-25 12:27:42 +00:00
|
|
|
|
2006-06-16 17:50:12 +00:00
|
|
|
// If the user requested use of 64-bit regs, but the cpu selected doesn't
|
2008-02-15 18:40:53 +00:00
|
|
|
// support it, ignore.
|
2014-10-01 20:38:26 +00:00
|
|
|
if (IsPPC64 && has64BitSupport())
|
|
|
|
|
Use64BitRegs = true;
|
2006-12-11 23:22:45 +00:00
|
|
|
|
|
|
|
|
// Set up darwin-specific properties.
|
2009-08-11 22:49:34 +00:00
|
|
|
if (isDarwin())
|
2006-12-11 23:22:45 +00:00
|
|
|
HasLazyResolverStubs = true;
|
2013-01-30 23:43:27 +00:00
|
|
|
|
|
|
|
|
// QPX requires a 32-byte aligned stack. Note that we need to do this if
|
|
|
|
|
// we're compiling for a BG/Q system regardless of whether or not QPX
|
|
|
|
|
// is enabled because external functions will assume this alignment.
|
2015-02-25 01:06:45 +00:00
|
|
|
IsQPXStackUnaligned = QPXStackUnaligned;
|
|
|
|
|
StackAlignment = getPlatformStackAlignment();
|
2013-07-26 01:35:43 +00:00
|
|
|
|
|
|
|
|
// Determine endianness.
|
2015-02-17 06:45:17 +00:00
|
|
|
// FIXME: Part of the TargetMachine.
|
2013-07-26 01:35:43 +00:00
|
|
|
IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le);
|
2006-12-11 23:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-23 20:50:42 +00:00
|
|
|
/// Return true if accesses to the specified global have to go through a dyld
|
|
|
|
|
/// lazy resolution stub. This means that an extra load is required to get the
|
|
|
|
|
/// address of the global.
|
2015-02-13 22:23:04 +00:00
|
|
|
bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const {
|
2016-06-23 20:50:42 +00:00
|
|
|
if (!HasLazyResolverStubs)
|
2006-12-11 23:22:45 +00:00
|
|
|
return false;
|
2016-06-27 23:15:57 +00:00
|
|
|
if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
|
2016-06-23 20:50:42 +00:00
|
|
|
return true;
|
|
|
|
|
// 32 bit macho has no relocation for a-b if a is undefined, even if b is in
|
|
|
|
|
// the section that is being relocated. This means we have to use o load even
|
|
|
|
|
// for GVs that are known to be local to the dso.
|
|
|
|
|
if (GV->isDeclarationForLinker() || GV->hasCommonLinkage())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2005-08-04 07:12:09 +00:00
|
|
|
}
|
2011-12-02 04:58:02 +00:00
|
|
|
|
2013-11-30 20:55:12 +00:00
|
|
|
// Embedded cores need aggressive scheduling (and some others also benefit).
|
2013-09-11 23:05:25 +00:00
|
|
|
static bool needsAggressiveScheduling(unsigned Directive) {
|
|
|
|
|
switch (Directive) {
|
|
|
|
|
default: return false;
|
|
|
|
|
case PPC::DIR_440:
|
|
|
|
|
case PPC::DIR_A2:
|
|
|
|
|
case PPC::DIR_E500mc:
|
|
|
|
|
case PPC::DIR_E5500:
|
2013-11-30 20:55:12 +00:00
|
|
|
case PPC::DIR_PWR7:
|
2014-06-26 13:36:19 +00:00
|
|
|
case PPC::DIR_PWR8:
|
2016-05-09 18:54:58 +00:00
|
|
|
// FIXME: Same as P8 until POWER9 scheduling info is available
|
|
|
|
|
case PPC::DIR_PWR9:
|
2013-09-11 23:05:25 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PPCSubtarget::enableMachineScheduler() const {
|
|
|
|
|
// Enable MI scheduling for the embedded cores.
|
|
|
|
|
// FIXME: Enable this for all cores (some additional modeling
|
|
|
|
|
// may be necessary).
|
|
|
|
|
return needsAggressiveScheduling(DarwinDirective);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 22:39:58 +00:00
|
|
|
// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
|
2015-06-13 03:42:16 +00:00
|
|
|
bool PPCSubtarget::enablePostRAScheduler() const { return true; }
|
2014-07-15 22:39:58 +00:00
|
|
|
|
|
|
|
|
PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
|
|
|
|
|
return TargetSubtargetInfo::ANTIDEP_ALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
|
|
|
|
|
CriticalPathRCs.clear();
|
|
|
|
|
CriticalPathRCs.push_back(isPPC64() ?
|
|
|
|
|
&PPC::G8RCRegClass : &PPC::GPRCRegClass);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 23:05:25 +00:00
|
|
|
void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
|
|
|
|
unsigned NumRegionInstrs) const {
|
|
|
|
|
if (needsAggressiveScheduling(DarwinDirective)) {
|
|
|
|
|
Policy.OnlyTopDown = false;
|
|
|
|
|
Policy.OnlyBottomUp = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Spilling is generally expensive on all PPC cores, so always enable
|
|
|
|
|
// register-pressure tracking.
|
|
|
|
|
Policy.ShouldTrackPressure = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PPCSubtarget::useAA() const {
|
|
|
|
|
// Use AA during code generation for the embedded cores.
|
|
|
|
|
return needsAggressiveScheduling(DarwinDirective);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 02:03:11 +00:00
|
|
|
bool PPCSubtarget::enableSubRegLiveness() const {
|
|
|
|
|
return UseSubRegLiveness;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 15:02:31 +00:00
|
|
|
unsigned char
|
|
|
|
|
PPCSubtarget::classifyGlobalReference(const GlobalValue *GV) const {
|
2015-11-20 20:51:31 +00:00
|
|
|
// Note that currently we don't generate non-pic references.
|
|
|
|
|
// If a caller wants that, this will have to be updated.
|
|
|
|
|
|
|
|
|
|
// Large code model always uses the TOC even for local symbols.
|
|
|
|
|
if (TM.getCodeModel() == CodeModel::Large)
|
|
|
|
|
return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;
|
|
|
|
|
|
2017-01-26 15:02:31 +00:00
|
|
|
if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
|
|
|
|
|
return PPCII::MO_PIC_FLAG;
|
|
|
|
|
return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;
|
2015-11-20 20:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 06:45:15 +00:00
|
|
|
bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
|
|
|
|
|
bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }
|