2014-05-24 20:50:23 +08:00
|
|
|
//===-- AArch64TargetMachine.cpp - Define TargetMachine for AArch64 -------===//
|
2014-03-29 18:18:08 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "AArch64.h"
|
|
|
|
#include "AArch64TargetMachine.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2014-07-25 19:42:14 +08:00
|
|
|
#include "llvm/PassManager.h"
|
2014-03-29 18:18:08 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-05-08 00:41:55 +08:00
|
|
|
static cl::opt<bool>
|
2014-05-24 20:50:23 +08:00
|
|
|
EnableCCMP("aarch64-ccmp", cl::desc("Enable the CCMP formation pass"),
|
2014-05-08 00:41:55 +08:00
|
|
|
cl::init(true), cl::Hidden);
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
2014-05-24 20:50:23 +08:00
|
|
|
EnableStPairSuppress("aarch64-stp-suppress", cl::desc("Suppress STP for AArch64"),
|
2014-05-08 00:41:55 +08:00
|
|
|
cl::init(true), cl::Hidden);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-05-08 00:41:55 +08:00
|
|
|
static cl::opt<bool>
|
2014-05-24 20:50:23 +08:00
|
|
|
EnableAdvSIMDScalar("aarch64-simd-scalar", cl::desc("Enable use of AdvSIMD scalar"
|
2014-05-08 00:41:55 +08:00
|
|
|
" integer instructions"), cl::init(false), cl::Hidden);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
static cl::opt<bool>
|
2014-05-24 20:50:23 +08:00
|
|
|
EnablePromoteConstant("aarch64-promote-const", cl::desc("Enable the promote "
|
2014-05-08 00:41:55 +08:00
|
|
|
"constant pass"), cl::init(true), cl::Hidden);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
static cl::opt<bool>
|
2014-05-24 20:50:23 +08:00
|
|
|
EnableCollectLOH("aarch64-collect-loh", cl::desc("Enable the pass that emits the"
|
2014-05-08 00:41:55 +08:00
|
|
|
" linker optimization hints (LOH)"), cl::init(true),
|
|
|
|
cl::Hidden);
|
2014-03-29 18:18:08 +08:00
|
|
|
|
2014-04-15 05:05:02 +08:00
|
|
|
static cl::opt<bool>
|
2014-05-24 20:50:23 +08:00
|
|
|
EnableDeadRegisterElimination("aarch64-dead-def-elimination", cl::Hidden,
|
2014-04-15 05:05:02 +08:00
|
|
|
cl::desc("Enable the pass that removes dead"
|
|
|
|
" definitons and replaces stores to"
|
|
|
|
" them with stores to the zero"
|
|
|
|
" register"),
|
|
|
|
cl::init(true));
|
|
|
|
|
2014-05-08 00:41:55 +08:00
|
|
|
static cl::opt<bool>
|
2014-05-24 20:50:23 +08:00
|
|
|
EnableLoadStoreOpt("aarch64-load-store-opt", cl::desc("Enable the load/store pair"
|
2014-05-08 00:41:55 +08:00
|
|
|
" optimization pass"), cl::init(true), cl::Hidden);
|
|
|
|
|
2014-05-30 18:09:59 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
EnableAtomicTidy("aarch64-atomic-cfg-tidy", cl::Hidden,
|
|
|
|
cl::desc("Run SimplifyCFG after expanding atomic operations"
|
|
|
|
" to make use of cmpxchg flow-based information"),
|
|
|
|
cl::init(true));
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
extern "C" void LLVMInitializeAArch64Target() {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Register the target.
|
2014-05-24 20:50:23 +08:00
|
|
|
RegisterTargetMachine<AArch64leTargetMachine> X(TheAArch64leTarget);
|
|
|
|
RegisterTargetMachine<AArch64beTargetMachine> Y(TheAArch64beTarget);
|
2014-07-23 20:58:11 +08:00
|
|
|
RegisterTargetMachine<AArch64leTargetMachine> Z(TheARM64Target);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
/// TargetMachine ctor - Create an AArch64 architecture model.
|
2014-03-29 18:18:08 +08:00
|
|
|
///
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64TargetMachine::AArch64TargetMachine(const Target &T, StringRef TT,
|
|
|
|
StringRef CPU, StringRef FS,
|
|
|
|
const TargetOptions &Options,
|
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL,
|
|
|
|
bool LittleEndian)
|
2014-03-29 18:18:08 +08:00
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
2014-06-11 07:26:45 +08:00
|
|
|
Subtarget(TT, CPU, FS, *this, LittleEndian) {
|
2014-03-29 18:18:08 +08:00
|
|
|
initAsmInfo();
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
void AArch64leTargetMachine::anchor() { }
|
2014-04-23 18:26:40 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64leTargetMachine::
|
|
|
|
AArch64leTargetMachine(const Target &T, StringRef TT,
|
2014-04-23 18:26:40 +08:00
|
|
|
StringRef CPU, StringRef FS, const TargetOptions &Options,
|
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
2014-05-24 20:50:23 +08:00
|
|
|
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
|
2014-04-23 18:26:40 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
void AArch64beTargetMachine::anchor() { }
|
2014-04-23 18:26:40 +08:00
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64beTargetMachine::
|
|
|
|
AArch64beTargetMachine(const Target &T, StringRef TT,
|
2014-04-23 18:26:40 +08:00
|
|
|
StringRef CPU, StringRef FS, const TargetOptions &Options,
|
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
2014-05-24 20:50:23 +08:00
|
|
|
: AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
|
2014-04-23 18:26:40 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
namespace {
|
2014-05-24 20:50:23 +08:00
|
|
|
/// AArch64 Code Generator Pass Configuration Options.
|
|
|
|
class AArch64PassConfig : public TargetPassConfig {
|
2014-03-29 18:18:08 +08:00
|
|
|
public:
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64PassConfig(AArch64TargetMachine *TM, PassManagerBase &PM)
|
2014-03-29 18:18:08 +08:00
|
|
|
: TargetPassConfig(TM, PM) {}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
AArch64TargetMachine &getAArch64TargetMachine() const {
|
|
|
|
return getTM<AArch64TargetMachine>();
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-30 18:09:59 +08:00
|
|
|
void addIRPasses() override;
|
2014-04-29 15:58:25 +08:00
|
|
|
bool addPreISel() override;
|
|
|
|
bool addInstSelector() override;
|
|
|
|
bool addILPOpts() override;
|
|
|
|
bool addPreRegAlloc() override;
|
|
|
|
bool addPostRegAlloc() override;
|
|
|
|
bool addPreSched2() override;
|
|
|
|
bool addPreEmitPass() override;
|
2014-03-29 18:18:08 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
void AArch64TargetMachine::addAnalysisPasses(PassManagerBase &PM) {
|
|
|
|
// Add first the target-independent BasicTTI pass, then our AArch64 pass. This
|
|
|
|
// allows the AArch64 pass to delegate to the target independent layer when
|
2014-03-29 18:18:08 +08:00
|
|
|
// appropriate.
|
|
|
|
PM.add(createBasicTargetTransformInfoPass(this));
|
2014-05-24 20:50:23 +08:00
|
|
|
PM.add(createAArch64TargetTransformInfoPass(this));
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) {
|
|
|
|
return new AArch64PassConfig(this, PM);
|
2014-03-29 18:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-05-30 18:09:59 +08:00
|
|
|
void AArch64PassConfig::addIRPasses() {
|
|
|
|
// Always expand atomic operations, we don't deal with atomicrmw or cmpxchg
|
|
|
|
// ourselves.
|
|
|
|
addPass(createAtomicExpandLoadLinkedPass(TM));
|
|
|
|
|
|
|
|
// Cmpxchg instructions are often used with a subsequent comparison to
|
|
|
|
// determine whether it succeeded. We can exploit existing control-flow in
|
|
|
|
// ldrex/strex loops to simplify this, but it needs tidying up.
|
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
|
|
|
|
addPass(createCFGSimplificationPass());
|
|
|
|
|
|
|
|
TargetPassConfig::addIRPasses();
|
|
|
|
}
|
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
// Pass Pipeline Configuration
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64PassConfig::addPreISel() {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Run promote constant before global merge, so that the promoted constants
|
|
|
|
// get a chance to be merged
|
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None && EnablePromoteConstant)
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64PromoteConstantPass());
|
2014-03-29 18:18:08 +08:00
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None)
|
|
|
|
addPass(createGlobalMergePass(TM));
|
2014-07-03 02:17:40 +08:00
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None)
|
|
|
|
addPass(createAArch64AddressTypePromotionPass());
|
2014-04-18 04:00:24 +08:00
|
|
|
|
2014-03-29 18:18:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64PassConfig::addInstSelector() {
|
|
|
|
addPass(createAArch64ISelDag(getAArch64TargetMachine(), getOptLevel()));
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
// For ELF, cleanup any local-dynamic TLS accesses (i.e. combine as many
|
|
|
|
// references to _TLS_MODULE_BASE_ as possible.
|
2014-05-24 20:50:23 +08:00
|
|
|
if (TM->getSubtarget<AArch64Subtarget>().isTargetELF() &&
|
2014-03-29 18:18:08 +08:00
|
|
|
getOptLevel() != CodeGenOpt::None)
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64CleanupLocalDynamicTLSPass());
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64PassConfig::addILPOpts() {
|
2014-03-29 18:18:08 +08:00
|
|
|
if (EnableCCMP)
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64ConditionalCompares());
|
2014-05-22 07:40:26 +08:00
|
|
|
addPass(&EarlyIfConverterID);
|
2014-03-29 18:18:08 +08:00
|
|
|
if (EnableStPairSuppress)
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64StorePairSuppressPass());
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64PassConfig::addPreRegAlloc() {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Use AdvSIMD scalar instructions whenever profitable.
|
2014-05-08 00:41:55 +08:00
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None && EnableAdvSIMDScalar)
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64AdvSIMDScalar());
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64PassConfig::addPostRegAlloc() {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Change dead register definitions to refer to the zero register.
|
2014-05-08 00:41:55 +08:00
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None && EnableDeadRegisterElimination)
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64DeadRegisterDefinitions());
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64PassConfig::addPreSched2() {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Expand some pseudo instructions to allow proper scheduling.
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64ExpandPseudoPass());
|
2014-03-29 18:18:08 +08:00
|
|
|
// Use load/store pair instructions when possible.
|
2014-05-08 00:41:55 +08:00
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None && EnableLoadStoreOpt)
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64LoadStoreOptimizationPass());
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
bool AArch64PassConfig::addPreEmitPass() {
|
2014-03-29 18:18:08 +08:00
|
|
|
// Relax conditional branch instructions if they're otherwise out of
|
|
|
|
// range of their destination.
|
2014-05-24 20:50:23 +08:00
|
|
|
addPass(createAArch64BranchRelaxation());
|
2014-04-18 22:54:46 +08:00
|
|
|
if (TM->getOptLevel() != CodeGenOpt::None && EnableCollectLOH &&
|
2014-05-24 20:50:23 +08:00
|
|
|
TM->getSubtarget<AArch64Subtarget>().isTargetMachO())
|
|
|
|
addPass(createAArch64CollectLOHPass());
|
2014-03-29 18:18:08 +08:00
|
|
|
return true;
|
|
|
|
}
|