Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 1 | //===-- AArch64TargetMachine.cpp - Define TargetMachine for AArch64 -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "AArch64.h" |
| 14 | #include "AArch64TargetMachine.h" |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 15 | #include "AArch64TargetObjectFile.h" |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 16 | #include "AArch64TargetTransformInfo.h" |
Quentin Colombet | d96f495 | 2016-02-11 19:35:06 +0000 | [diff] [blame] | 17 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 18 | # include "llvm/CodeGen/GlobalISel/IRTranslator.h" |
| 19 | #endif |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/Passes.h" |
Arnaud A. de Grandmaison | c75dbbb | 2014-09-10 14:06:10 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/RegAllocRegistry.h" |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Function.h" |
Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 23 | #include "llvm/IR/LegacyPassManager.h" |
Quentin Colombet | f574ab2 | 2016-03-08 01:45:36 +0000 | [diff] [blame] | 24 | #include "llvm/InitializePasses.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 25 | #include "llvm/Support/CommandLine.h" |
| 26 | #include "llvm/Support/TargetRegistry.h" |
| 27 | #include "llvm/Target/TargetOptions.h" |
| 28 | #include "llvm/Transforms/Scalar.h" |
| 29 | using namespace llvm; |
| 30 | |
| 31 | static cl::opt<bool> |
| 32 | EnableCCMP("aarch64-ccmp", cl::desc("Enable the CCMP formation pass"), |
| 33 | cl::init(true), cl::Hidden); |
| 34 | |
Gerolf Hoflehner | 97c383b | 2014-08-07 21:40:58 +0000 | [diff] [blame] | 35 | static cl::opt<bool> EnableMCR("aarch64-mcr", |
| 36 | cl::desc("Enable the machine combiner pass"), |
| 37 | cl::init(true), cl::Hidden); |
| 38 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 39 | static cl::opt<bool> |
| 40 | EnableStPairSuppress("aarch64-stp-suppress", cl::desc("Suppress STP for AArch64"), |
| 41 | cl::init(true), cl::Hidden); |
| 42 | |
| 43 | static cl::opt<bool> |
| 44 | EnableAdvSIMDScalar("aarch64-simd-scalar", cl::desc("Enable use of AdvSIMD scalar" |
| 45 | " integer instructions"), cl::init(false), cl::Hidden); |
| 46 | |
| 47 | static cl::opt<bool> |
| 48 | EnablePromoteConstant("aarch64-promote-const", cl::desc("Enable the promote " |
| 49 | "constant pass"), cl::init(true), cl::Hidden); |
| 50 | |
| 51 | static cl::opt<bool> |
| 52 | EnableCollectLOH("aarch64-collect-loh", cl::desc("Enable the pass that emits the" |
| 53 | " linker optimization hints (LOH)"), cl::init(true), |
| 54 | cl::Hidden); |
| 55 | |
| 56 | static cl::opt<bool> |
| 57 | EnableDeadRegisterElimination("aarch64-dead-def-elimination", cl::Hidden, |
| 58 | cl::desc("Enable the pass that removes dead" |
| 59 | " definitons and replaces stores to" |
| 60 | " them with stores to the zero" |
| 61 | " register"), |
| 62 | cl::init(true)); |
| 63 | |
| 64 | static cl::opt<bool> |
Jun Bum Lim | b389d9b | 2016-02-16 20:02:39 +0000 | [diff] [blame] | 65 | EnableRedundantCopyElimination("aarch64-redundant-copy-elim", |
| 66 | cl::desc("Enable the redundant copy elimination pass"), |
| 67 | cl::init(true), cl::Hidden); |
| 68 | |
| 69 | static cl::opt<bool> |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 70 | EnableLoadStoreOpt("aarch64-load-store-opt", cl::desc("Enable the load/store pair" |
| 71 | " optimization pass"), cl::init(true), cl::Hidden); |
| 72 | |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 73 | static cl::opt<bool> |
| 74 | EnableAtomicTidy("aarch64-atomic-cfg-tidy", cl::Hidden, |
| 75 | cl::desc("Run SimplifyCFG after expanding atomic operations" |
| 76 | " to make use of cmpxchg flow-based information"), |
| 77 | cl::init(true)); |
| 78 | |
James Molloy | 9991794 | 2014-08-06 13:31:32 +0000 | [diff] [blame] | 79 | static cl::opt<bool> |
| 80 | EnableEarlyIfConversion("aarch64-enable-early-ifcvt", cl::Hidden, |
| 81 | cl::desc("Run early if-conversion"), |
| 82 | cl::init(true)); |
| 83 | |
Jiangning Liu | 1a486da | 2014-09-05 02:55:24 +0000 | [diff] [blame] | 84 | static cl::opt<bool> |
| 85 | EnableCondOpt("aarch64-condopt", |
| 86 | cl::desc("Enable the condition optimizer pass"), |
| 87 | cl::init(true), cl::Hidden); |
| 88 | |
Arnaud A. de Grandmaison | c75dbbb | 2014-09-10 14:06:10 +0000 | [diff] [blame] | 89 | static cl::opt<bool> |
Bradley Smith | f2a801d | 2014-10-13 10:12:35 +0000 | [diff] [blame] | 90 | EnableA53Fix835769("aarch64-fix-cortex-a53-835769", cl::Hidden, |
| 91 | cl::desc("Work around Cortex-A53 erratum 835769"), |
| 92 | cl::init(false)); |
| 93 | |
Hao Liu | fd46bea | 2014-11-19 06:39:53 +0000 | [diff] [blame] | 94 | static cl::opt<bool> |
| 95 | EnableGEPOpt("aarch64-gep-opt", cl::Hidden, |
| 96 | cl::desc("Enable optimizations on complex GEPs"), |
James Molloy | cd2334e | 2015-04-22 09:11:38 +0000 | [diff] [blame] | 97 | cl::init(false)); |
Hao Liu | fd46bea | 2014-11-19 06:39:53 +0000 | [diff] [blame] | 98 | |
Ahmed Bougacha | b96444e | 2015-04-11 00:06:36 +0000 | [diff] [blame] | 99 | // FIXME: Unify control over GlobalMerge. |
| 100 | static cl::opt<cl::boolOrDefault> |
| 101 | EnableGlobalMerge("aarch64-global-merge", cl::Hidden, |
| 102 | cl::desc("Enable the global merge pass")); |
| 103 | |
Adam Nemet | 53e758f | 2016-03-18 00:27:29 +0000 | [diff] [blame^] | 104 | static cl::opt<bool> |
| 105 | EnableLoopDataPrefetch("aarch64-loop-data-prefetch", cl::Hidden, |
| 106 | cl::desc("Enable the loop data prefetch pass"), |
| 107 | cl::init(false)); |
| 108 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 109 | extern "C" void LLVMInitializeAArch64Target() { |
| 110 | // Register the target. |
| 111 | RegisterTargetMachine<AArch64leTargetMachine> X(TheAArch64leTarget); |
| 112 | RegisterTargetMachine<AArch64beTargetMachine> Y(TheAArch64beTarget); |
Tim Northover | 35910d7 | 2014-07-23 12:58:11 +0000 | [diff] [blame] | 113 | RegisterTargetMachine<AArch64leTargetMachine> Z(TheARM64Target); |
Quentin Colombet | f574ab2 | 2016-03-08 01:45:36 +0000 | [diff] [blame] | 114 | initializeGlobalISel(*PassRegistry::getPassRegistry()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 117 | //===----------------------------------------------------------------------===// |
| 118 | // AArch64 Lowering public interface. |
| 119 | //===----------------------------------------------------------------------===// |
| 120 | static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) { |
| 121 | if (TT.isOSBinFormatMachO()) |
| 122 | return make_unique<AArch64_MachoTargetObjectFile>(); |
| 123 | |
| 124 | return make_unique<AArch64_ELFTargetObjectFile>(); |
| 125 | } |
| 126 | |
Mehdi Amini | 93e1ea1 | 2015-03-12 00:07:24 +0000 | [diff] [blame] | 127 | // Helper function to build a DataLayout string |
Daniel Sanders | ed64d62 | 2015-06-11 15:34:59 +0000 | [diff] [blame] | 128 | static std::string computeDataLayout(const Triple &TT, bool LittleEndian) { |
| 129 | if (TT.isOSBinFormatMachO()) |
Mehdi Amini | 93e1ea1 | 2015-03-12 00:07:24 +0000 | [diff] [blame] | 130 | return "e-m:o-i64:64-i128:128-n32:64-S128"; |
| 131 | if (LittleEndian) |
| 132 | return "e-m:e-i64:64-i128:128-n32:64-S128"; |
| 133 | return "E-m:e-i64:64-i128:128-n32:64-S128"; |
| 134 | } |
| 135 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 136 | /// TargetMachine ctor - Create an AArch64 architecture model. |
| 137 | /// |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 138 | AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT, |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 139 | StringRef CPU, StringRef FS, |
| 140 | const TargetOptions &Options, |
| 141 | Reloc::Model RM, CodeModel::Model CM, |
| 142 | CodeGenOpt::Level OL, |
| 143 | bool LittleEndian) |
Mehdi Amini | 93e1ea1 | 2015-03-12 00:07:24 +0000 | [diff] [blame] | 144 | // This nested ternary is horrible, but DL needs to be properly |
Eric Christopher | 63ea040 | 2015-03-12 18:23:01 +0000 | [diff] [blame] | 145 | // initialized before TLInfo is constructed. |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 146 | : LLVMTargetMachine(T, computeDataLayout(TT, LittleEndian), TT, CPU, FS, |
| 147 | Options, RM, CM, OL), |
| 148 | TLOF(createTLOF(getTargetTriple())), |
Mehdi Amini | 93e1ea1 | 2015-03-12 00:07:24 +0000 | [diff] [blame] | 149 | isLittle(LittleEndian) { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 150 | initAsmInfo(); |
| 151 | } |
| 152 | |
Reid Kleckner | 357600e | 2014-11-20 23:37:18 +0000 | [diff] [blame] | 153 | AArch64TargetMachine::~AArch64TargetMachine() {} |
| 154 | |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 155 | const AArch64Subtarget * |
| 156 | AArch64TargetMachine::getSubtargetImpl(const Function &F) const { |
Duncan P. N. Exon Smith | 003bb7d | 2015-02-14 02:09:06 +0000 | [diff] [blame] | 157 | Attribute CPUAttr = F.getFnAttribute("target-cpu"); |
| 158 | Attribute FSAttr = F.getFnAttribute("target-features"); |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 159 | |
| 160 | std::string CPU = !CPUAttr.hasAttribute(Attribute::None) |
| 161 | ? CPUAttr.getValueAsString().str() |
| 162 | : TargetCPU; |
| 163 | std::string FS = !FSAttr.hasAttribute(Attribute::None) |
| 164 | ? FSAttr.getValueAsString().str() |
| 165 | : TargetFS; |
| 166 | |
| 167 | auto &I = SubtargetMap[CPU + FS]; |
| 168 | if (!I) { |
| 169 | // This needs to be done before we create a new subtarget since any |
| 170 | // creation will depend on the TM and the code generation flags on the |
| 171 | // function that reside in TargetOptions. |
| 172 | resetTargetOptions(F); |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 173 | I = llvm::make_unique<AArch64Subtarget>(TargetTriple, CPU, FS, *this, |
| 174 | isLittle); |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 175 | } |
| 176 | return I.get(); |
| 177 | } |
| 178 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 179 | void AArch64leTargetMachine::anchor() { } |
| 180 | |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 181 | AArch64leTargetMachine::AArch64leTargetMachine( |
| 182 | const Target &T, const Triple &TT, StringRef CPU, StringRef FS, |
| 183 | const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, |
| 184 | CodeGenOpt::Level OL) |
| 185 | : AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {} |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 186 | |
| 187 | void AArch64beTargetMachine::anchor() { } |
| 188 | |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 189 | AArch64beTargetMachine::AArch64beTargetMachine( |
| 190 | const Target &T, const Triple &TT, StringRef CPU, StringRef FS, |
| 191 | const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, |
| 192 | CodeGenOpt::Level OL) |
| 193 | : AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {} |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 194 | |
| 195 | namespace { |
| 196 | /// AArch64 Code Generator Pass Configuration Options. |
| 197 | class AArch64PassConfig : public TargetPassConfig { |
| 198 | public: |
| 199 | AArch64PassConfig(AArch64TargetMachine *TM, PassManagerBase &PM) |
Chad Rosier | 486e087 | 2014-09-12 17:40:39 +0000 | [diff] [blame] | 200 | : TargetPassConfig(TM, PM) { |
Chad Rosier | 347ed4e | 2014-09-12 22:17:28 +0000 | [diff] [blame] | 201 | if (TM->getOptLevel() != CodeGenOpt::None) |
| 202 | substitutePass(&PostRASchedulerID, &PostMachineSchedulerID); |
Chad Rosier | 486e087 | 2014-09-12 17:40:39 +0000 | [diff] [blame] | 203 | } |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 204 | |
| 205 | AArch64TargetMachine &getAArch64TargetMachine() const { |
| 206 | return getTM<AArch64TargetMachine>(); |
| 207 | } |
| 208 | |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 209 | void addIRPasses() override; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 210 | bool addPreISel() override; |
| 211 | bool addInstSelector() override; |
Quentin Colombet | d96f495 | 2016-02-11 19:35:06 +0000 | [diff] [blame] | 212 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 213 | bool addIRTranslator() override; |
| 214 | #endif |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 215 | bool addILPOpts() override; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 216 | void addPreRegAlloc() override; |
| 217 | void addPostRegAlloc() override; |
| 218 | void addPreSched2() override; |
| 219 | void addPreEmitPass() override; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 220 | }; |
| 221 | } // namespace |
| 222 | |
Chandler Carruth | 8b04c0d | 2015-02-01 13:20:00 +0000 | [diff] [blame] | 223 | TargetIRAnalysis AArch64TargetMachine::getTargetIRAnalysis() { |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 224 | return TargetIRAnalysis([this](const Function &F) { |
Chandler Carruth | 8b04c0d | 2015-02-01 13:20:00 +0000 | [diff] [blame] | 225 | return TargetTransformInfo(AArch64TTIImpl(this, F)); |
| 226 | }); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) { |
| 230 | return new AArch64PassConfig(this, PM); |
| 231 | } |
| 232 | |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 233 | void AArch64PassConfig::addIRPasses() { |
| 234 | // Always expand atomic operations, we don't deal with atomicrmw or cmpxchg |
| 235 | // ourselves. |
Robin Morisset | 59c23cd | 2014-08-21 21:50:01 +0000 | [diff] [blame] | 236 | addPass(createAtomicExpandPass(TM)); |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 237 | |
| 238 | // Cmpxchg instructions are often used with a subsequent comparison to |
| 239 | // determine whether it succeeded. We can exploit existing control-flow in |
| 240 | // ldrex/strex loops to simplify this, but it needs tidying up. |
| 241 | if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy) |
| 242 | addPass(createCFGSimplificationPass()); |
| 243 | |
Adam Nemet | 53e758f | 2016-03-18 00:27:29 +0000 | [diff] [blame^] | 244 | // Run LoopDataPrefetch for Cyclone (the only subtarget that defines a |
| 245 | // non-zero getPrefetchDistance). |
| 246 | // |
| 247 | // Run this before LSR to remove the multiplies involved in computing the |
| 248 | // pointer values N iterations ahead. |
| 249 | if (TM->getOptLevel() != CodeGenOpt::None && EnableLoopDataPrefetch) |
| 250 | addPass(createLoopDataPrefetchPass()); |
| 251 | |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 252 | TargetPassConfig::addIRPasses(); |
Hao Liu | fd46bea | 2014-11-19 06:39:53 +0000 | [diff] [blame] | 253 | |
Hao Liu | 7ec8ee3 | 2015-06-26 02:32:07 +0000 | [diff] [blame] | 254 | // Match interleaved memory accesses to ldN/stN intrinsics. |
| 255 | if (TM->getOptLevel() != CodeGenOpt::None) |
| 256 | addPass(createInterleavedAccessPass(TM)); |
| 257 | |
Hao Liu | fd46bea | 2014-11-19 06:39:53 +0000 | [diff] [blame] | 258 | if (TM->getOptLevel() == CodeGenOpt::Aggressive && EnableGEPOpt) { |
| 259 | // Call SeparateConstOffsetFromGEP pass to extract constants within indices |
| 260 | // and lower a GEP with multiple indices to either arithmetic operations or |
| 261 | // multiple GEPs with single index. |
| 262 | addPass(createSeparateConstOffsetFromGEPPass(TM, true)); |
| 263 | // Call EarlyCSE pass to find and remove subexpressions in the lowered |
| 264 | // result. |
| 265 | addPass(createEarlyCSEPass()); |
| 266 | // Do loop invariant code motion in case part of the lowered result is |
| 267 | // invariant. |
| 268 | addPass(createLICMPass()); |
| 269 | } |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 272 | // Pass Pipeline Configuration |
| 273 | bool AArch64PassConfig::addPreISel() { |
| 274 | // Run promote constant before global merge, so that the promoted constants |
| 275 | // get a chance to be merged |
| 276 | if (TM->getOptLevel() != CodeGenOpt::None && EnablePromoteConstant) |
| 277 | addPass(createAArch64PromoteConstantPass()); |
Eric Christopher | ed47b22 | 2015-02-23 19:28:45 +0000 | [diff] [blame] | 278 | // FIXME: On AArch64, this depends on the type. |
| 279 | // Basically, the addressable offsets are up to 4095 * Ty.getSizeInBytes(). |
| 280 | // and the offset has to be a multiple of the related size in bytes. |
Ahmed Bougacha | 8207641 | 2015-06-04 20:39:23 +0000 | [diff] [blame] | 281 | if ((TM->getOptLevel() != CodeGenOpt::None && |
Ahmed Bougacha | b96444e | 2015-04-11 00:06:36 +0000 | [diff] [blame] | 282 | EnableGlobalMerge == cl::BOU_UNSET) || |
Ahmed Bougacha | 8207641 | 2015-06-04 20:39:23 +0000 | [diff] [blame] | 283 | EnableGlobalMerge == cl::BOU_TRUE) { |
| 284 | bool OnlyOptimizeForSize = (TM->getOptLevel() < CodeGenOpt::Aggressive) && |
| 285 | (EnableGlobalMerge == cl::BOU_UNSET); |
| 286 | addPass(createGlobalMergePass(TM, 4095, OnlyOptimizeForSize)); |
| 287 | } |
| 288 | |
Duncan P. N. Exon Smith | de58870 | 2014-07-02 18:17:40 +0000 | [diff] [blame] | 289 | if (TM->getOptLevel() != CodeGenOpt::None) |
| 290 | addPass(createAArch64AddressTypePromotionPass()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 291 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 292 | return false; |
| 293 | } |
| 294 | |
| 295 | bool AArch64PassConfig::addInstSelector() { |
| 296 | addPass(createAArch64ISelDag(getAArch64TargetMachine(), getOptLevel())); |
| 297 | |
| 298 | // For ELF, cleanup any local-dynamic TLS accesses (i.e. combine as many |
| 299 | // references to _TLS_MODULE_BASE_ as possible. |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 300 | if (TM->getTargetTriple().isOSBinFormatELF() && |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 301 | getOptLevel() != CodeGenOpt::None) |
| 302 | addPass(createAArch64CleanupLocalDynamicTLSPass()); |
| 303 | |
| 304 | return false; |
| 305 | } |
| 306 | |
Quentin Colombet | d96f495 | 2016-02-11 19:35:06 +0000 | [diff] [blame] | 307 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 308 | bool AArch64PassConfig::addIRTranslator() { |
| 309 | addPass(new IRTranslator()); |
| 310 | return false; |
| 311 | } |
| 312 | #endif |
| 313 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 314 | bool AArch64PassConfig::addILPOpts() { |
Jiangning Liu | 1a486da | 2014-09-05 02:55:24 +0000 | [diff] [blame] | 315 | if (EnableCondOpt) |
| 316 | addPass(createAArch64ConditionOptimizerPass()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 317 | if (EnableCCMP) |
| 318 | addPass(createAArch64ConditionalCompares()); |
Gerolf Hoflehner | 97c383b | 2014-08-07 21:40:58 +0000 | [diff] [blame] | 319 | if (EnableMCR) |
| 320 | addPass(&MachineCombinerID); |
James Molloy | 9991794 | 2014-08-06 13:31:32 +0000 | [diff] [blame] | 321 | if (EnableEarlyIfConversion) |
| 322 | addPass(&EarlyIfConverterID); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 323 | if (EnableStPairSuppress) |
| 324 | addPass(createAArch64StorePairSuppressPass()); |
| 325 | return true; |
| 326 | } |
| 327 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 328 | void AArch64PassConfig::addPreRegAlloc() { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 329 | // Use AdvSIMD scalar instructions whenever profitable. |
Quentin Colombet | 0c740d4 | 2014-08-21 18:10:07 +0000 | [diff] [blame] | 330 | if (TM->getOptLevel() != CodeGenOpt::None && EnableAdvSIMDScalar) { |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 331 | addPass(createAArch64AdvSIMDScalar()); |
Quentin Colombet | 0c740d4 | 2014-08-21 18:10:07 +0000 | [diff] [blame] | 332 | // The AdvSIMD pass may produce copies that can be rewritten to |
| 333 | // be register coaleascer friendly. |
| 334 | addPass(&PeepholeOptimizerID); |
| 335 | } |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 338 | void AArch64PassConfig::addPostRegAlloc() { |
Jun Bum Lim | b389d9b | 2016-02-16 20:02:39 +0000 | [diff] [blame] | 339 | // Remove redundant copy instructions. |
| 340 | if (TM->getOptLevel() != CodeGenOpt::None && EnableRedundantCopyElimination) |
| 341 | addPass(createAArch64RedundantCopyEliminationPass()); |
| 342 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 343 | // Change dead register definitions to refer to the zero register. |
| 344 | if (TM->getOptLevel() != CodeGenOpt::None && EnableDeadRegisterElimination) |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 345 | addPass(createAArch64DeadRegisterDefinitions()); |
Eric Christopher | 6f1e568 | 2015-03-03 23:22:40 +0000 | [diff] [blame] | 346 | if (TM->getOptLevel() != CodeGenOpt::None && usingDefaultRegAlloc()) |
James Molloy | 3feea9c | 2014-08-08 12:33:21 +0000 | [diff] [blame] | 347 | // Improve performance for some FP/SIMD code for A57. |
| 348 | addPass(createAArch64A57FPLoadBalancing()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 351 | void AArch64PassConfig::addPreSched2() { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 352 | // Expand some pseudo instructions to allow proper scheduling. |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 353 | addPass(createAArch64ExpandPseudoPass()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 354 | // Use load/store pair instructions when possible. |
| 355 | if (TM->getOptLevel() != CodeGenOpt::None && EnableLoadStoreOpt) |
| 356 | addPass(createAArch64LoadStoreOptimizationPass()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 359 | void AArch64PassConfig::addPreEmitPass() { |
Bradley Smith | f2a801d | 2014-10-13 10:12:35 +0000 | [diff] [blame] | 360 | if (EnableA53Fix835769) |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 361 | addPass(createAArch64A53Fix835769()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 362 | // Relax conditional branch instructions if they're otherwise out of |
| 363 | // range of their destination. |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 364 | addPass(createAArch64BranchRelaxation()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 365 | if (TM->getOptLevel() != CodeGenOpt::None && EnableCollectLOH && |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 366 | TM->getTargetTriple().isOSBinFormatMachO()) |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 367 | addPass(createAArch64CollectLOHPass()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 368 | } |