2012-02-18 12:03:15 +00:00
|
|
|
//===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===//
|
2007-01-19 07:51:42 +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.
|
2007-01-19 07:51:42 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-07-01 21:01:15 +00:00
|
|
|
// This file implements the ARM specific subclass of TargetSubtargetInfo.
|
2007-01-19 07:51:42 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMSubtarget.h"
|
2012-09-18 03:18:56 +00:00
|
|
|
#include "ARMBaseInstrInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "ARMBaseRegisterInfo.h"
|
2013-02-15 22:41:25 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/GlobalValue.h"
|
2013-02-15 22:41:25 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2009-06-22 21:01:46 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2013-03-21 18:47:47 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
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 "ARMGenSubtargetInfo.inc"
|
2011-07-01 20:45:01 +00:00
|
|
|
|
2007-01-19 07:51:42 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-06-22 21:01:46 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
ReserveR9("arm-reserve-r9", cl::Hidden,
|
|
|
|
cl::desc("Reserve R9, making it unavailable as GPR"));
|
|
|
|
|
2009-11-24 00:44:37 +00:00
|
|
|
static cl::opt<bool>
|
2013-08-15 20:54:38 +00:00
|
|
|
ArmUseMOVT("arm-use-movt", cl::init(true), cl::Hidden);
|
2009-11-24 00:44:37 +00:00
|
|
|
|
2012-09-29 21:43:49 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
UseFusedMulOps("arm-use-mulops",
|
|
|
|
cl::init(true), cl::Hidden);
|
|
|
|
|
2013-05-17 23:49:01 +00:00
|
|
|
enum AlignMode {
|
|
|
|
DefaultAlign,
|
|
|
|
StrictAlign,
|
|
|
|
NoStrictAlign
|
|
|
|
};
|
|
|
|
|
|
|
|
static cl::opt<AlignMode>
|
|
|
|
Align(cl::desc("Load/store alignment support"),
|
|
|
|
cl::Hidden, cl::init(DefaultAlign),
|
|
|
|
cl::values(
|
|
|
|
clEnumValN(DefaultAlign, "arm-default-align",
|
|
|
|
"Generate unaligned accesses only on hardware/OS "
|
|
|
|
"combinations that are known to support them"),
|
|
|
|
clEnumValN(StrictAlign, "arm-strict-align",
|
|
|
|
"Disallow all unaligned memory accesses"),
|
|
|
|
clEnumValN(NoStrictAlign, "arm-no-strict-align",
|
|
|
|
"Allow unaligned memory accesses"),
|
|
|
|
clEnumValEnd));
|
2010-09-28 04:09:35 +00:00
|
|
|
|
2013-11-13 18:29:49 +00:00
|
|
|
enum ITMode {
|
|
|
|
DefaultIT,
|
|
|
|
RestrictedIT,
|
|
|
|
NoRestrictedIT
|
|
|
|
};
|
|
|
|
|
|
|
|
static cl::opt<ITMode>
|
|
|
|
IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT),
|
|
|
|
cl::ZeroOrMore,
|
|
|
|
cl::values(clEnumValN(DefaultIT, "arm-default-it",
|
|
|
|
"Generate IT block based on arch"),
|
|
|
|
clEnumValN(RestrictedIT, "arm-restrict-it",
|
|
|
|
"Disallow deprecated IT based on ARMv8"),
|
|
|
|
clEnumValN(NoRestrictedIT, "arm-no-restrict-it",
|
|
|
|
"Allow IT blocks based on ARMv7"),
|
|
|
|
clEnumValEnd));
|
|
|
|
|
2011-06-30 01:53:36 +00:00
|
|
|
ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
|
2013-03-21 18:47:47 +00:00
|
|
|
const std::string &FS, const TargetOptions &Options)
|
2011-07-07 07:07:08 +00:00
|
|
|
: ARMGenSubtargetInfo(TT, CPU, FS)
|
2010-09-10 01:29:16 +00:00
|
|
|
, ARMProcFamily(Others)
|
2013-09-23 14:26:15 +00:00
|
|
|
, ARMProcClass(None)
|
2007-02-13 19:52:28 +00:00
|
|
|
, stackAlignment(4)
|
2011-06-30 01:53:36 +00:00
|
|
|
, CPUString(CPU)
|
2011-01-11 21:46:47 +00:00
|
|
|
, TargetTriple(TT)
|
2013-03-21 18:47:47 +00:00
|
|
|
, Options(Options)
|
2014-01-02 13:40:08 +00:00
|
|
|
, TargetABI(ARM_ABI_UNKNOWN) {
|
2013-02-16 01:36:26 +00:00
|
|
|
initializeEnvironment();
|
2013-02-15 22:41:25 +00:00
|
|
|
resetSubtargetFeatures(CPU, FS);
|
|
|
|
}
|
|
|
|
|
2013-02-16 01:36:26 +00:00
|
|
|
void ARMSubtarget::initializeEnvironment() {
|
|
|
|
HasV4TOps = false;
|
|
|
|
HasV5TOps = false;
|
|
|
|
HasV5TEOps = false;
|
|
|
|
HasV6Ops = false;
|
2013-10-07 16:55:23 +00:00
|
|
|
HasV6MOps = false;
|
2013-02-16 01:36:26 +00:00
|
|
|
HasV6T2Ops = false;
|
|
|
|
HasV7Ops = false;
|
2013-06-26 16:58:26 +00:00
|
|
|
HasV8Ops = false;
|
2013-02-16 01:36:26 +00:00
|
|
|
HasVFPv2 = false;
|
|
|
|
HasVFPv3 = false;
|
|
|
|
HasVFPv4 = false;
|
2013-09-13 13:46:57 +00:00
|
|
|
HasFPARMv8 = false;
|
2013-02-16 01:36:26 +00:00
|
|
|
HasNEON = false;
|
2013-12-02 14:46:26 +00:00
|
|
|
MinSize = false;
|
2013-02-16 01:36:26 +00:00
|
|
|
UseNEONForSinglePrecisionFP = false;
|
|
|
|
UseMulOps = UseFusedMulOps;
|
|
|
|
SlowFPVMLx = false;
|
|
|
|
HasVMLxForwarding = false;
|
|
|
|
SlowFPBrcc = false;
|
|
|
|
InThumbMode = false;
|
|
|
|
HasThumb2 = false;
|
|
|
|
NoARM = false;
|
|
|
|
PostRAScheduler = false;
|
|
|
|
IsR9Reserved = ReserveR9;
|
|
|
|
UseMovt = false;
|
|
|
|
SupportsTailCall = false;
|
|
|
|
HasFP16 = false;
|
|
|
|
HasD16 = false;
|
|
|
|
HasHardwareDivide = false;
|
|
|
|
HasHardwareDivideInARM = false;
|
|
|
|
HasT2ExtractPack = false;
|
|
|
|
HasDataBarrier = false;
|
|
|
|
Pref32BitThumb = false;
|
|
|
|
AvoidCPSRPartialUpdate = false;
|
|
|
|
AvoidMOVsShifterOperand = false;
|
|
|
|
HasRAS = false;
|
|
|
|
HasMPExtension = false;
|
2013-11-01 13:27:35 +00:00
|
|
|
HasVirtualization = false;
|
2013-02-16 01:36:26 +00:00
|
|
|
FPOnlySP = false;
|
2013-05-23 19:11:14 +00:00
|
|
|
HasPerfMon = false;
|
2013-04-10 12:08:35 +00:00
|
|
|
HasTrustZone = false;
|
2013-09-19 11:59:01 +00:00
|
|
|
HasCrypto = false;
|
2013-10-29 16:54:52 +00:00
|
|
|
HasCRC = false;
|
2013-02-16 01:36:26 +00:00
|
|
|
AllowsUnalignedMem = false;
|
|
|
|
Thumb2DSP = false;
|
|
|
|
UseNaClTrap = false;
|
2013-03-21 18:47:47 +00:00
|
|
|
UnsafeFPMath = false;
|
2013-02-16 01:36:26 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 22:41:25 +00:00
|
|
|
void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
|
|
|
|
AttributeSet FnAttrs = MF->getFunction()->getAttributes();
|
|
|
|
Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
|
|
|
|
"target-cpu");
|
|
|
|
Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
|
|
|
|
"target-features");
|
|
|
|
std::string CPU =
|
|
|
|
!CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
|
|
|
|
std::string FS =
|
|
|
|
!FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
|
2013-02-16 01:36:26 +00:00
|
|
|
if (!FS.empty()) {
|
|
|
|
initializeEnvironment();
|
2013-02-15 22:41:25 +00:00
|
|
|
resetSubtargetFeatures(CPU, FS);
|
2013-02-16 01:36:26 +00:00
|
|
|
}
|
2013-12-02 14:46:26 +00:00
|
|
|
|
|
|
|
MinSize =
|
|
|
|
FnAttrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize);
|
2013-02-15 22:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
|
2013-09-02 17:09:01 +00:00
|
|
|
if (CPUString.empty()) {
|
|
|
|
if (isTargetIOS() && TargetTriple.getArchName().endswith("v7s"))
|
|
|
|
// Default to the Swift CPU when targeting armv7s/thumbv7s.
|
|
|
|
CPUString = "swift";
|
|
|
|
else
|
|
|
|
CPUString = "generic";
|
|
|
|
}
|
2009-03-08 04:02:49 +00:00
|
|
|
|
2011-06-30 02:12:44 +00:00
|
|
|
// Insert the architecture feature derived from the target triple into the
|
|
|
|
// feature string. This is important for setting features that are implied
|
|
|
|
// based on the architecture version.
|
2013-02-15 22:41:25 +00:00
|
|
|
std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
|
|
|
|
CPUString);
|
2011-07-07 00:08:19 +00:00
|
|
|
if (!FS.empty()) {
|
|
|
|
if (!ArchFS.empty())
|
2013-02-15 22:41:25 +00:00
|
|
|
ArchFS = ArchFS + "," + FS.str();
|
2011-07-07 00:08:19 +00:00
|
|
|
else
|
|
|
|
ArchFS = FS;
|
|
|
|
}
|
2011-07-07 07:07:08 +00:00
|
|
|
ParseSubtargetFeatures(CPUString, ArchFS);
|
2011-07-07 00:08:19 +00:00
|
|
|
|
2013-12-13 11:16:00 +00:00
|
|
|
// FIXME: This used enable V6T2 support implicitly for Thumb2 mode.
|
|
|
|
// Assert this for now to make the change obvious.
|
|
|
|
assert(hasV6T2Ops() || !hasThumb2());
|
2010-11-09 22:50:47 +00:00
|
|
|
|
2012-08-08 02:44:16 +00:00
|
|
|
// Keep a pointer to static instruction cost data for the specified CPU.
|
|
|
|
SchedModel = getSchedModelForCPU(CPUString);
|
|
|
|
|
2011-07-01 20:45:01 +00:00
|
|
|
// Initialize scheduling itinerary for the specified CPU.
|
|
|
|
InstrItins = getInstrItineraryForCPU(CPUString);
|
|
|
|
|
2014-01-02 13:40:08 +00:00
|
|
|
if (TargetABI == ARM_ABI_UNKNOWN) {
|
|
|
|
switch (TargetTriple.getEnvironment()) {
|
|
|
|
case Triple::Android:
|
|
|
|
case Triple::EABI:
|
|
|
|
case Triple::EABIHF:
|
|
|
|
case Triple::GNUEABI:
|
|
|
|
case Triple::GNUEABIHF:
|
2014-01-06 14:28:05 +00:00
|
|
|
case Triple::MachO:
|
2013-12-15 00:12:52 +00:00
|
|
|
TargetABI = ARM_ABI_AAPCS;
|
2014-01-02 13:40:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (isTargetIOS() && isMClass())
|
|
|
|
TargetABI = ARM_ABI_AAPCS;
|
|
|
|
else
|
|
|
|
TargetABI = ARM_ABI_APCS;
|
|
|
|
break;
|
|
|
|
}
|
2013-12-15 00:12:52 +00:00
|
|
|
}
|
2011-07-07 07:07:08 +00:00
|
|
|
|
2007-02-13 19:52:28 +00:00
|
|
|
if (isAAPCS_ABI())
|
|
|
|
stackAlignment = 8;
|
|
|
|
|
2013-08-15 20:54:38 +00:00
|
|
|
UseMovt = hasV6T2Ops() && ArmUseMOVT;
|
|
|
|
|
2014-01-06 14:28:05 +00:00
|
|
|
if (isTargetMachO()) {
|
2011-07-07 03:55:05 +00:00
|
|
|
IsR9Reserved = ReserveR9 | !HasV6Ops;
|
2014-01-06 14:28:05 +00:00
|
|
|
SupportsTailCall = !isTargetIOS() || !getTargetTriple().isOSVersionLT(5, 0);
|
|
|
|
} else
|
|
|
|
IsR9Reserved = ReserveR9;
|
2009-10-01 21:46:35 +00:00
|
|
|
|
2009-10-16 06:11:08 +00:00
|
|
|
if (!isThumb() || hasThumb2())
|
|
|
|
PostRAScheduler = true;
|
2010-09-28 04:09:35 +00:00
|
|
|
|
2013-05-17 23:49:01 +00:00
|
|
|
switch (Align) {
|
|
|
|
case DefaultAlign:
|
|
|
|
// Assume pre-ARMv6 doesn't support unaligned accesses.
|
|
|
|
//
|
|
|
|
// ARMv6 may or may not support unaligned accesses depending on the
|
|
|
|
// SCTLR.U bit, which is architecture-specific. We assume ARMv6
|
|
|
|
// Darwin targets support unaligned accesses, and others don't.
|
|
|
|
//
|
|
|
|
// ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
|
|
|
|
// which raises an alignment fault on unaligned accesses. Linux
|
|
|
|
// defaults this bit to 0 and handles it as a system-wide (not
|
|
|
|
// per-process) setting. It is therefore safe to assume that ARMv7+
|
|
|
|
// Linux targets support unaligned accesses. The same goes for NaCl.
|
|
|
|
//
|
|
|
|
// The above behavior is consistent with GCC.
|
|
|
|
AllowsUnalignedMem = (
|
|
|
|
(hasV7Ops() && (isTargetLinux() || isTargetNaCl())) ||
|
2014-01-06 14:28:05 +00:00
|
|
|
(hasV6Ops() && isTargetMachO()));
|
2013-05-17 23:49:01 +00:00
|
|
|
break;
|
|
|
|
case StrictAlign:
|
|
|
|
AllowsUnalignedMem = false;
|
|
|
|
break;
|
|
|
|
case NoStrictAlign:
|
|
|
|
AllowsUnalignedMem = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-03-21 18:47:47 +00:00
|
|
|
|
2013-11-13 18:29:49 +00:00
|
|
|
switch (IT) {
|
|
|
|
case DefaultIT:
|
|
|
|
RestrictIT = hasV8Ops() ? true : false;
|
|
|
|
break;
|
|
|
|
case RestrictedIT:
|
|
|
|
RestrictIT = true;
|
|
|
|
break;
|
|
|
|
case NoRestrictedIT:
|
|
|
|
RestrictIT = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-21 18:47:47 +00:00
|
|
|
// NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
|
|
|
|
uint64_t Bits = getFeatureBits();
|
|
|
|
if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters
|
|
|
|
(Options.UnsafeFPMath || isTargetDarwin()))
|
|
|
|
UseNEONForSinglePrecisionFP = true;
|
2007-01-19 07:51:42 +00:00
|
|
|
}
|
2009-08-28 23:18:09 +00:00
|
|
|
|
|
|
|
/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
|
2009-09-03 07:04:02 +00:00
|
|
|
bool
|
2010-04-15 01:51:59 +00:00
|
|
|
ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
|
|
|
|
Reloc::Model RelocM) const {
|
2009-09-03 07:04:02 +00:00
|
|
|
if (RelocM == Reloc::Static)
|
2009-08-28 23:18:09 +00:00
|
|
|
return false;
|
2009-09-03 07:04:02 +00:00
|
|
|
|
2010-01-27 20:34:15 +00:00
|
|
|
// Materializable GVs (in JIT lazy compilation mode) do not require an extra
|
|
|
|
// load from stub.
|
2011-02-22 06:58:34 +00:00
|
|
|
bool isDecl = GV->hasAvailableExternallyLinkage();
|
|
|
|
if (GV->isDeclaration() && !GV->isMaterializable())
|
|
|
|
isDecl = true;
|
2009-09-03 07:04:02 +00:00
|
|
|
|
2014-01-06 14:28:05 +00:00
|
|
|
if (!isTargetMachO()) {
|
2009-09-03 07:04:02 +00:00
|
|
|
// Extra load is needed for all externally visible.
|
|
|
|
if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (RelocM == Reloc::PIC_) {
|
|
|
|
// If this is a strong reference to a definition, it is definitely not
|
|
|
|
// through a stub.
|
|
|
|
if (!isDecl && !GV->isWeakForLinker())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Unless we have a symbol with hidden visibility, we have to go through a
|
|
|
|
// normal $non_lazy_ptr stub because this symbol might be resolved late.
|
|
|
|
if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If symbol visibility is hidden, we have a stub for common symbol
|
|
|
|
// references and external declarations.
|
|
|
|
if (isDecl || GV->hasCommonLinkage())
|
|
|
|
// Hidden $non_lazy_ptr reference.
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// If this is a strong reference to a definition, it is definitely not
|
|
|
|
// through a stub.
|
|
|
|
if (!isDecl && !GV->isWeakForLinker())
|
|
|
|
return false;
|
2010-12-24 04:28:06 +00:00
|
|
|
|
2009-09-03 07:04:02 +00:00
|
|
|
// Unless we have a symbol with hidden visibility, we have to go through a
|
|
|
|
// normal $non_lazy_ptr stub because this symbol might be resolved late.
|
|
|
|
if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-08-28 23:18:09 +00:00
|
|
|
}
|
2009-11-10 00:48:55 +00:00
|
|
|
|
2010-09-28 21:57:50 +00:00
|
|
|
unsigned ARMSubtarget::getMispredictionPenalty() const {
|
2012-08-08 02:44:16 +00:00
|
|
|
return SchedModel->MispredictPenalty;
|
2010-09-28 21:57:50 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 06:14:38 +00:00
|
|
|
bool ARMSubtarget::hasSinCos() const {
|
|
|
|
return getTargetTriple().getOS() == Triple::IOS &&
|
|
|
|
!getTargetTriple().isOSVersionLT(7, 0);
|
|
|
|
}
|
|
|
|
|
2009-11-10 00:48:55 +00:00
|
|
|
bool ARMSubtarget::enablePostRAScheduler(
|
|
|
|
CodeGenOpt::Level OptLevel,
|
2011-07-01 21:01:15 +00:00
|
|
|
TargetSubtargetInfo::AntiDepBreakMode& Mode,
|
2009-11-13 19:52:48 +00:00
|
|
|
RegClassVector& CriticalPathRCs) const {
|
2013-09-25 00:26:16 +00:00
|
|
|
Mode = TargetSubtargetInfo::ANTIDEP_NONE;
|
2009-11-10 00:48:55 +00:00
|
|
|
return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
|
|
|
|
}
|