Rafael Espindola | ffdc24b | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 1 | //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
Rafael Espindola | ffdc24b | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 13 | #include "ARM.h" |
| 14 | #include "ARMCallLowering.h" |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 15 | #include "ARMLegalizerInfo.h" |
Aaron Ballman | 3234647 | 2017-05-09 15:12:03 +0000 | [diff] [blame] | 16 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 17 | #include "ARMRegisterBankInfo.h" |
Aaron Ballman | 06297e8 | 2017-05-09 14:59:48 +0000 | [diff] [blame] | 18 | #endif |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 19 | #include "ARMSubtarget.h" |
| 20 | #include "ARMTargetMachine.h" |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 21 | #include "ARMTargetObjectFile.h" |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 22 | #include "ARMTargetTransformInfo.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 23 | #include "MCTargetDesc/ARMMCTargetDesc.h" |
| 24 | #include "llvm/ADT/Optional.h" |
| 25 | #include "llvm/ADT/STLExtras.h" |
| 26 | #include "llvm/ADT/StringRef.h" |
| 27 | #include "llvm/ADT/Triple.h" |
| 28 | #include "llvm/Analysis/TargetTransformInfo.h" |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/ExecutionDepsFix.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/GlobalISel/CallLowering.h" |
| 31 | #include "llvm/CodeGen/GlobalISel/GISelAccessor.h" |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/GlobalISel/IRTranslator.h" |
| 33 | #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/GlobalISel/Legalizer.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h" |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/GlobalISel/RegBankSelect.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h" |
| 39 | #include "llvm/CodeGen/MachineFunction.h" |
Evan Cheng | ad3aac71 | 2007-05-16 02:01:49 +0000 | [diff] [blame] | 40 | #include "llvm/CodeGen/Passes.h" |
Matthias Braun | 31d19d4 | 2016-05-10 03:21:59 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/TargetPassConfig.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 42 | #include "llvm/IR/Attributes.h" |
| 43 | #include "llvm/IR/DataLayout.h" |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 44 | #include "llvm/IR/Function.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 45 | #include "llvm/Pass.h" |
| 46 | #include "llvm/Support/CodeGen.h" |
Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 47 | #include "llvm/Support/CommandLine.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 48 | #include "llvm/Support/ErrorHandling.h" |
Zijiao Ma | 53d55f4 | 2016-08-17 02:08:28 +0000 | [diff] [blame] | 49 | #include "llvm/Support/TargetParser.h" |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 50 | #include "llvm/Support/TargetRegistry.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 51 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 52 | #include "llvm/Target/TargetOptions.h" |
Devang Patel | 76c8563 | 2011-10-17 17:17:43 +0000 | [diff] [blame] | 53 | #include "llvm/Transforms/Scalar.h" |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 54 | #include <cassert> |
| 55 | #include <memory> |
| 56 | #include <string> |
| 57 | |
Rafael Espindola | ffdc24b | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 58 | using namespace llvm; |
| 59 | |
Evan Cheng | f066b2f | 2011-08-25 01:00:36 +0000 | [diff] [blame] | 60 | static cl::opt<bool> |
Silviu Baranga | 82dd6ac | 2013-03-15 18:28:25 +0000 | [diff] [blame] | 61 | DisableA15SDOptimization("disable-a15-sd-optimization", cl::Hidden, |
| 62 | cl::desc("Inhibit optimization of S->D register accesses on A15"), |
| 63 | cl::init(false)); |
| 64 | |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 65 | static cl::opt<bool> |
| 66 | EnableAtomicTidy("arm-atomic-cfg-tidy", cl::Hidden, |
| 67 | cl::desc("Run SimplifyCFG after expanding atomic operations" |
| 68 | " to make use of cmpxchg flow-based information"), |
| 69 | cl::init(true)); |
| 70 | |
Renato Golin | 4c87139 | 2015-03-26 18:38:04 +0000 | [diff] [blame] | 71 | static cl::opt<bool> |
| 72 | EnableARMLoadStoreOpt("arm-load-store-opt", cl::Hidden, |
| 73 | cl::desc("Enable ARM load/store optimization pass"), |
| 74 | cl::init(true)); |
| 75 | |
Ahmed Bougacha | b96444e | 2015-04-11 00:06:36 +0000 | [diff] [blame] | 76 | // FIXME: Unify control over GlobalMerge. |
| 77 | static cl::opt<cl::boolOrDefault> |
| 78 | EnableGlobalMerge("arm-global-merge", cl::Hidden, |
| 79 | cl::desc("Enable the global merge pass")); |
| 80 | |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 81 | namespace llvm { |
| 82 | void initializeARMExecutionDepsFixPass(PassRegistry&); |
| 83 | } |
| 84 | |
Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 85 | extern "C" void LLVMInitializeARMTarget() { |
Daniel Dunbar | 5680b4f | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 86 | // Register the target. |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 87 | RegisterTargetMachine<ARMLETargetMachine> X(getTheARMLETarget()); |
Florian Hahn | d211fe7 | 2017-05-24 10:18:57 +0000 | [diff] [blame^] | 88 | RegisterTargetMachine<ARMLETargetMachine> A(getTheThumbLETarget()); |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 89 | RegisterTargetMachine<ARMBETargetMachine> Y(getTheARMBETarget()); |
Florian Hahn | d211fe7 | 2017-05-24 10:18:57 +0000 | [diff] [blame^] | 90 | RegisterTargetMachine<ARMBETargetMachine> B(getTheThumbBETarget()); |
Matthias Braun | 8f456fb | 2016-07-16 02:24:10 +0000 | [diff] [blame] | 91 | |
| 92 | PassRegistry &Registry = *PassRegistry::getPassRegistry(); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 93 | initializeGlobalISel(Registry); |
Matthias Braun | 8f456fb | 2016-07-16 02:24:10 +0000 | [diff] [blame] | 94 | initializeARMLoadStoreOptPass(Registry); |
| 95 | initializeARMPreAllocLoadStoreOptPass(Registry); |
James Molloy | 9b3b899 | 2017-02-13 14:07:25 +0000 | [diff] [blame] | 96 | initializeARMConstantIslandsPass(Registry); |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 97 | initializeARMExecutionDepsFixPass(Registry); |
Daniel Dunbar | 5680b4f | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 98 | } |
Douglas Gregor | 1b731d5 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 99 | |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 100 | static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) { |
| 101 | if (TT.isOSBinFormatMachO()) |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 102 | return llvm::make_unique<TargetLoweringObjectFileMachO>(); |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 103 | if (TT.isOSWindows()) |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 104 | return llvm::make_unique<TargetLoweringObjectFileCOFF>(); |
| 105 | return llvm::make_unique<ARMElfTargetObjectFile>(); |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 108 | static ARMBaseTargetMachine::ARMABI |
| 109 | computeTargetABI(const Triple &TT, StringRef CPU, |
| 110 | const TargetOptions &Options) { |
Tim Northover | e0ccdc6 | 2015-10-28 22:46:43 +0000 | [diff] [blame] | 111 | if (Options.MCOptions.getABIName() == "aapcs16") |
| 112 | return ARMBaseTargetMachine::ARM_ABI_AAPCS16; |
| 113 | else if (Options.MCOptions.getABIName().startswith("aapcs")) |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 114 | return ARMBaseTargetMachine::ARM_ABI_AAPCS; |
Eric Christopher | 6e30cd9 | 2015-01-14 00:50:31 +0000 | [diff] [blame] | 115 | else if (Options.MCOptions.getABIName().startswith("apcs")) |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 116 | return ARMBaseTargetMachine::ARM_ABI_APCS; |
| 117 | |
Eric Christopher | 6e30cd9 | 2015-01-14 00:50:31 +0000 | [diff] [blame] | 118 | assert(Options.MCOptions.getABIName().empty() && |
| 119 | "Unknown target-abi option!"); |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 120 | |
| 121 | ARMBaseTargetMachine::ARMABI TargetABI = |
| 122 | ARMBaseTargetMachine::ARM_ABI_UNKNOWN; |
| 123 | |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 124 | unsigned ArchKind = ARM::parseCPUArch(CPU); |
| 125 | StringRef ArchName = ARM::getArchName(ArchKind); |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 126 | // FIXME: This is duplicated code from the front end and should be unified. |
| 127 | if (TT.isOSBinFormatMachO()) { |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 128 | if (TT.getEnvironment() == Triple::EABI || |
| 129 | (TT.getOS() == Triple::UnknownOS && TT.isOSBinFormatMachO()) || |
| 130 | ARM::parseArchProfile(ArchName) == ARM::PK_M) { |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 131 | TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS; |
Tim Northover | 042a6c1 | 2016-01-27 19:32:29 +0000 | [diff] [blame] | 132 | } else if (TT.isWatchABI()) { |
Tim Northover | e0ccdc6 | 2015-10-28 22:46:43 +0000 | [diff] [blame] | 133 | TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS16; |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 134 | } else { |
| 135 | TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS; |
| 136 | } |
| 137 | } else if (TT.isOSWindows()) { |
| 138 | // FIXME: this is invalid for WindowsCE |
| 139 | TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS; |
| 140 | } else { |
| 141 | // Select the default based on the platform. |
| 142 | switch (TT.getEnvironment()) { |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 143 | case Triple::Android: |
| 144 | case Triple::GNUEABI: |
| 145 | case Triple::GNUEABIHF: |
| 146 | case Triple::MuslEABI: |
| 147 | case Triple::MuslEABIHF: |
| 148 | case Triple::EABIHF: |
| 149 | case Triple::EABI: |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 150 | TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS; |
| 151 | break; |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 152 | case Triple::GNU: |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 153 | TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS; |
| 154 | break; |
| 155 | default: |
Daniel Sanders | fbdab43 | 2015-07-06 16:33:18 +0000 | [diff] [blame] | 156 | if (TT.isOSNetBSD()) |
| 157 | TargetABI = ARMBaseTargetMachine::ARM_ABI_APCS; |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 158 | else |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 159 | TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS; |
Eric Christopher | 661f2d1 | 2014-12-18 02:20:58 +0000 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return TargetABI; |
| 165 | } |
| 166 | |
Daniel Sanders | ed64d62 | 2015-06-11 15:34:59 +0000 | [diff] [blame] | 167 | static std::string computeDataLayout(const Triple &TT, StringRef CPU, |
Mehdi Amini | 93e1ea1 | 2015-03-12 00:07:24 +0000 | [diff] [blame] | 168 | const TargetOptions &Options, |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 169 | bool isLittle) { |
Daniel Sanders | ed64d62 | 2015-06-11 15:34:59 +0000 | [diff] [blame] | 170 | auto ABI = computeTargetABI(TT, CPU, Options); |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 171 | std::string Ret; |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 172 | |
| 173 | if (isLittle) |
| 174 | // Little endian. |
| 175 | Ret += "e"; |
| 176 | else |
| 177 | // Big endian. |
| 178 | Ret += "E"; |
| 179 | |
Daniel Sanders | ed64d62 | 2015-06-11 15:34:59 +0000 | [diff] [blame] | 180 | Ret += DataLayout::getManglingComponent(TT); |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 181 | |
| 182 | // Pointers are 32 bits and aligned to 32 bits. |
| 183 | Ret += "-p:32:32"; |
| 184 | |
| 185 | // ABIs other than APCS have 64 bit integers with natural alignment. |
| 186 | if (ABI != ARMBaseTargetMachine::ARM_ABI_APCS) |
| 187 | Ret += "-i64:64"; |
| 188 | |
| 189 | // We have 64 bits floats. The APCS ABI requires them to be aligned to 32 |
| 190 | // bits, others to 64 bits. We always try to align to 64 bits. |
| 191 | if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS) |
| 192 | Ret += "-f64:32:64"; |
| 193 | |
| 194 | // We have 128 and 64 bit vectors. The APCS ABI aligns them to 32 bits, others |
| 195 | // to 64. We always ty to give them natural alignment. |
| 196 | if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS) |
| 197 | Ret += "-v64:32:64-v128:32:128"; |
Tim Northover | e0ccdc6 | 2015-10-28 22:46:43 +0000 | [diff] [blame] | 198 | else if (ABI != ARMBaseTargetMachine::ARM_ABI_AAPCS16) |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 199 | Ret += "-v128:64:128"; |
| 200 | |
| 201 | // Try to align aggregates to 32 bits (the default is 64 bits, which has no |
| 202 | // particular hardware support on 32-bit ARM). |
| 203 | Ret += "-a:0:32"; |
| 204 | |
| 205 | // Integer registers are 32 bits. |
| 206 | Ret += "-n32"; |
| 207 | |
| 208 | // The stack is 128 bit aligned on NaCl, 64 bit aligned on AAPCS and 32 bit |
| 209 | // aligned everywhere else. |
Tim Northover | e0ccdc6 | 2015-10-28 22:46:43 +0000 | [diff] [blame] | 210 | if (TT.isOSNaCl() || ABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16) |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 211 | Ret += "-S128"; |
| 212 | else if (ABI == ARMBaseTargetMachine::ARM_ABI_AAPCS) |
| 213 | Ret += "-S64"; |
| 214 | else |
| 215 | Ret += "-S32"; |
| 216 | |
| 217 | return Ret; |
| 218 | } |
| 219 | |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 220 | static Reloc::Model getEffectiveRelocModel(const Triple &TT, |
| 221 | Optional<Reloc::Model> RM) { |
| 222 | if (!RM.hasValue()) |
Rafael Espindola | fe796dc | 2016-05-28 10:41:15 +0000 | [diff] [blame] | 223 | // Default relocation model on Darwin is PIC. |
| 224 | return TT.isOSBinFormatMachO() ? Reloc::PIC_ : Reloc::Static; |
Renato Golin | 9be88629 | 2016-05-28 04:47:13 +0000 | [diff] [blame] | 225 | |
Oliver Stannard | 8331aae | 2016-08-08 15:28:31 +0000 | [diff] [blame] | 226 | if (*RM == Reloc::ROPI || *RM == Reloc::RWPI || *RM == Reloc::ROPI_RWPI) |
| 227 | assert(TT.isOSBinFormatELF() && |
| 228 | "ROPI/RWPI currently only supported for ELF"); |
| 229 | |
Renato Golin | 9be88629 | 2016-05-28 04:47:13 +0000 | [diff] [blame] | 230 | // DynamicNoPIC is only used on darwin. |
| 231 | if (*RM == Reloc::DynamicNoPIC && !TT.isOSDarwin()) |
| 232 | return Reloc::Static; |
| 233 | |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 234 | return *RM; |
| 235 | } |
| 236 | |
Rafael Espindola | 38af4d6 | 2016-05-18 16:00:24 +0000 | [diff] [blame] | 237 | /// Create an ARM architecture model. |
Evan Cheng | 9f83014 | 2007-02-23 03:14:31 +0000 | [diff] [blame] | 238 | /// |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 239 | ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT, |
Evan Cheng | 2129f59 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 240 | StringRef CPU, StringRef FS, |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 241 | const TargetOptions &Options, |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 242 | Optional<Reloc::Model> RM, |
| 243 | CodeModel::Model CM, |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 244 | CodeGenOpt::Level OL, bool isLittle) |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 245 | : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, isLittle), TT, |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 246 | CPU, FS, Options, getEffectiveRelocModel(TT, RM), CM, |
| 247 | OL), |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 248 | TargetABI(computeTargetABI(TT, CPU, Options)), |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 249 | TLOF(createTLOF(getTargetTriple())), |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 250 | Subtarget(TT, CPU, FS, *this, isLittle), isLittle(isLittle) { |
Tim Northover | f1c31b9 | 2013-12-18 14:18:36 +0000 | [diff] [blame] | 251 | |
| 252 | // Default to triple-appropriate float ABI |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 253 | if (Options.FloatABIType == FloatABI::Default) |
Tim Northover | 44594ad | 2013-12-18 09:27:33 +0000 | [diff] [blame] | 254 | this->Options.FloatABIType = |
| 255 | Subtarget.isTargetHardFloat() ? FloatABI::Hard : FloatABI::Soft; |
Renato Golin | 6d435f1 | 2015-11-09 12:40:30 +0000 | [diff] [blame] | 256 | |
| 257 | // Default to triple-appropriate EABI |
| 258 | if (Options.EABIVersion == EABI::Default || |
| 259 | Options.EABIVersion == EABI::Unknown) { |
Rafael Espindola | a895a0c | 2016-06-24 21:14:33 +0000 | [diff] [blame] | 260 | // musl is compatible with glibc with regard to EABI version |
| 261 | if (Subtarget.isTargetGNUAEABI() || Subtarget.isTargetMuslAEABI()) |
Renato Golin | 6d435f1 | 2015-11-09 12:40:30 +0000 | [diff] [blame] | 262 | this->Options.EABIVersion = EABI::GNU; |
| 263 | else |
| 264 | this->Options.EABIVersion = EABI::EABI5; |
| 265 | } |
Florian Hahn | d211fe7 | 2017-05-24 10:18:57 +0000 | [diff] [blame^] | 266 | |
| 267 | initAsmInfo(); |
| 268 | if (!Subtarget.isThumb() && !Subtarget.hasARMOps()) |
| 269 | report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not " |
| 270 | "support ARM mode execution!"); |
Evan Cheng | 66cff40 | 2008-10-30 16:10:54 +0000 | [diff] [blame] | 271 | } |
Rafael Espindola | ffdc24b | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 272 | |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 273 | ARMBaseTargetMachine::~ARMBaseTargetMachine() = default; |
Reid Kleckner | 357600e | 2014-11-20 23:37:18 +0000 | [diff] [blame] | 274 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 275 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 276 | namespace { |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 277 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 278 | struct ARMGISelActualAccessor : public GISelAccessor { |
| 279 | std::unique_ptr<CallLowering> CallLoweringInfo; |
| 280 | std::unique_ptr<InstructionSelector> InstSelector; |
| 281 | std::unique_ptr<LegalizerInfo> Legalizer; |
| 282 | std::unique_ptr<RegisterBankInfo> RegBankInfo; |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 283 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 284 | const CallLowering *getCallLowering() const override { |
| 285 | return CallLoweringInfo.get(); |
| 286 | } |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 287 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 288 | const InstructionSelector *getInstructionSelector() const override { |
| 289 | return InstSelector.get(); |
| 290 | } |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 291 | |
Ahmed Bougacha | 5228603 | 2016-12-15 18:45:30 +0000 | [diff] [blame] | 292 | const LegalizerInfo *getLegalizerInfo() const override { |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 293 | return Legalizer.get(); |
| 294 | } |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 295 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 296 | const RegisterBankInfo *getRegBankInfo() const override { |
| 297 | return RegBankInfo.get(); |
| 298 | } |
| 299 | }; |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 300 | |
| 301 | } // end anonymous namespace |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 302 | #endif |
| 303 | |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 304 | const ARMSubtarget * |
| 305 | ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const { |
Duncan P. N. Exon Smith | 2cff9e1 | 2015-02-14 02:24:44 +0000 | [diff] [blame] | 306 | Attribute CPUAttr = F.getFnAttribute("target-cpu"); |
| 307 | Attribute FSAttr = F.getFnAttribute("target-features"); |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 308 | |
| 309 | std::string CPU = !CPUAttr.hasAttribute(Attribute::None) |
| 310 | ? CPUAttr.getValueAsString().str() |
| 311 | : TargetCPU; |
| 312 | std::string FS = !FSAttr.hasAttribute(Attribute::None) |
| 313 | ? FSAttr.getValueAsString().str() |
| 314 | : TargetFS; |
| 315 | |
| 316 | // FIXME: This is related to the code below to reset the target options, |
| 317 | // we need to know whether or not the soft float flag is set on the |
| 318 | // function before we can generate a subtarget. We also need to use |
| 319 | // it as a key for the subtarget since that can be the only difference |
| 320 | // between two functions. |
Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 321 | bool SoftFloat = |
Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 322 | F.getFnAttribute("use-soft-float").getValueAsString() == "true"; |
| 323 | // If the soft float attribute is set on the function turn on the soft float |
| 324 | // subtarget feature. |
| 325 | if (SoftFloat) |
| 326 | FS += FS.empty() ? "+soft-float" : ",+soft-float"; |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 327 | |
Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 328 | auto &I = SubtargetMap[CPU + FS]; |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 329 | if (!I) { |
| 330 | // This needs to be done before we create a new subtarget since any |
| 331 | // creation will depend on the TM and the code generation flags on the |
| 332 | // function that reside in TargetOptions. |
| 333 | resetTargetOptions(F); |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 334 | I = llvm::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 335 | |
| 336 | #ifndef LLVM_BUILD_GLOBAL_ISEL |
Diana Picus | 90f0a84 | 2016-11-15 15:38:15 +0000 | [diff] [blame] | 337 | GISelAccessor *GISel = new GISelAccessor(); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 338 | #else |
Diana Picus | 90f0a84 | 2016-11-15 15:38:15 +0000 | [diff] [blame] | 339 | ARMGISelActualAccessor *GISel = new ARMGISelActualAccessor(); |
| 340 | GISel->CallLoweringInfo.reset(new ARMCallLowering(*I->getTargetLowering())); |
Diana Picus | 7cab078 | 2017-02-17 11:25:17 +0000 | [diff] [blame] | 341 | GISel->Legalizer.reset(new ARMLegalizerInfo(*I)); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 342 | |
Diana Picus | 90f0a84 | 2016-11-15 15:38:15 +0000 | [diff] [blame] | 343 | auto *RBI = new ARMRegisterBankInfo(*I->getRegisterInfo()); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 344 | |
Diana Picus | 90f0a84 | 2016-11-15 15:38:15 +0000 | [diff] [blame] | 345 | // FIXME: At this point, we can't rely on Subtarget having RBI. |
| 346 | // It's awkward to mix passing RBI and the Subtarget; should we pass |
| 347 | // TII/TRI as well? |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 348 | GISel->InstSelector.reset(createARMInstructionSelector(*this, *I, *RBI)); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 349 | |
Diana Picus | 90f0a84 | 2016-11-15 15:38:15 +0000 | [diff] [blame] | 350 | GISel->RegBankInfo.reset(RBI); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 351 | #endif |
Diana Picus | 90f0a84 | 2016-11-15 15:38:15 +0000 | [diff] [blame] | 352 | I->setGISelAccessor(*GISel); |
| 353 | } |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 354 | return I.get(); |
| 355 | } |
| 356 | |
Chandler Carruth | 8b04c0d | 2015-02-01 13:20:00 +0000 | [diff] [blame] | 357 | TargetIRAnalysis ARMBaseTargetMachine::getTargetIRAnalysis() { |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 358 | return TargetIRAnalysis([this](const Function &F) { |
| 359 | return TargetTransformInfo(ARMTTIImpl(this, F)); |
| 360 | }); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 363 | |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 364 | ARMLETargetMachine::ARMLETargetMachine(const Target &T, const Triple &TT, |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 365 | StringRef CPU, StringRef FS, |
| 366 | const TargetOptions &Options, |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 367 | Optional<Reloc::Model> RM, |
| 368 | CodeModel::Model CM, |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 369 | CodeGenOpt::Level OL) |
Florian Hahn | d211fe7 | 2017-05-24 10:18:57 +0000 | [diff] [blame^] | 370 | : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {} |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 371 | |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 372 | ARMBETargetMachine::ARMBETargetMachine(const Target &T, const Triple &TT, |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 373 | StringRef CPU, StringRef FS, |
| 374 | const TargetOptions &Options, |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 375 | Optional<Reloc::Model> RM, |
| 376 | CodeModel::Model CM, |
Eric Christopher | 80b24ef | 2014-06-26 19:30:02 +0000 | [diff] [blame] | 377 | CodeGenOpt::Level OL) |
Florian Hahn | d211fe7 | 2017-05-24 10:18:57 +0000 | [diff] [blame^] | 378 | : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {} |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 379 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 380 | namespace { |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 381 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 382 | /// ARM Code Generator Pass Configuration Options. |
| 383 | class ARMPassConfig : public TargetPassConfig { |
| 384 | public: |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 385 | ARMPassConfig(ARMBaseTargetMachine *TM, PassManagerBase &PM) |
| 386 | : TargetPassConfig(TM, PM) {} |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 387 | |
| 388 | ARMBaseTargetMachine &getARMTargetMachine() const { |
| 389 | return getTM<ARMBaseTargetMachine>(); |
| 390 | } |
| 391 | |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 392 | void addIRPasses() override; |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 393 | bool addPreISel() override; |
| 394 | bool addInstSelector() override; |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 395 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 396 | bool addIRTranslator() override; |
| 397 | bool addLegalizeMachineIR() override; |
| 398 | bool addRegBankSelect() override; |
| 399 | bool addGlobalInstructionSelect() override; |
| 400 | #endif |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 401 | void addPreRegAlloc() override; |
| 402 | void addPreSched2() override; |
| 403 | void addPreEmitPass() override; |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 404 | }; |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 405 | |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 406 | class ARMExecutionDepsFix : public ExecutionDepsFix { |
| 407 | public: |
| 408 | static char ID; |
| 409 | ARMExecutionDepsFix() : ExecutionDepsFix(ID, ARM::DPRRegClass) {} |
| 410 | StringRef getPassName() const override { |
| 411 | return "ARM Execution Dependency Fix"; |
| 412 | } |
| 413 | }; |
| 414 | char ARMExecutionDepsFix::ID; |
| 415 | |
Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 416 | } // end anonymous namespace |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 417 | |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 418 | INITIALIZE_PASS(ARMExecutionDepsFix, "arm-execution-deps-fix", |
| 419 | "ARM Execution Dependency Fix", false, false) |
| 420 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 421 | TargetPassConfig *ARMBaseTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 422 | return new ARMPassConfig(this, PM); |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 425 | void ARMPassConfig::addIRPasses() { |
Jonathan Roelofs | 5e98ff9 | 2014-08-21 14:35:47 +0000 | [diff] [blame] | 426 | if (TM->Options.ThreadModel == ThreadModel::Single) |
| 427 | addPass(createLowerAtomicPass()); |
| 428 | else |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 429 | addPass(createAtomicExpandPass()); |
Tim Northover | c882eb0 | 2014-04-03 11:44:58 +0000 | [diff] [blame] | 430 | |
Eric Christopher | c40e5ed | 2014-06-19 21:03:04 +0000 | [diff] [blame] | 431 | // Cmpxchg instructions are often used with a subsequent comparison to |
| 432 | // determine whether it succeeded. We can exploit existing control-flow in |
| 433 | // ldrex/strex loops to simplify this, but it needs tidying up. |
Akira Hatanaka | 4a61619 | 2015-06-08 18:50:43 +0000 | [diff] [blame] | 434 | if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy) |
| 435 | addPass(createCFGSimplificationPass(-1, [this](const Function &F) { |
| 436 | const auto &ST = this->TM->getSubtarget<ARMSubtarget>(F); |
| 437 | return ST.hasAnyDataBarrier() && !ST.isThumb1Only(); |
| 438 | })); |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 439 | |
| 440 | TargetPassConfig::addIRPasses(); |
Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 441 | |
| 442 | // Match interleaved memory accesses to ldN/stN intrinsics. |
| 443 | if (TM->getOptLevel() != CodeGenOpt::None) |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 444 | addPass(createInterleavedAccessPass()); |
Tim Northover | b4ddc08 | 2014-05-30 10:09:59 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | bool ARMPassConfig::addPreISel() { |
Ahmed Bougacha | 8207641 | 2015-06-04 20:39:23 +0000 | [diff] [blame] | 448 | if ((TM->getOptLevel() != CodeGenOpt::None && |
Ahmed Bougacha | b96444e | 2015-04-11 00:06:36 +0000 | [diff] [blame] | 449 | EnableGlobalMerge == cl::BOU_UNSET) || |
Ahmed Bougacha | 8207641 | 2015-06-04 20:39:23 +0000 | [diff] [blame] | 450 | EnableGlobalMerge == cl::BOU_TRUE) { |
Eric Christopher | ed47b22 | 2015-02-23 19:28:45 +0000 | [diff] [blame] | 451 | // FIXME: This is using the thumb1 only constant value for |
| 452 | // maximal global offset for merging globals. We may want |
| 453 | // to look into using the old value for non-thumb1 code of |
| 454 | // 4095 based on the TargetMachine, but this starts to become |
| 455 | // tricky when doing code gen per function. |
Ahmed Bougacha | 8207641 | 2015-06-04 20:39:23 +0000 | [diff] [blame] | 456 | bool OnlyOptimizeForSize = (TM->getOptLevel() < CodeGenOpt::Aggressive) && |
| 457 | (EnableGlobalMerge == cl::BOU_UNSET); |
John Brawn | f3324cf | 2015-08-03 12:13:33 +0000 | [diff] [blame] | 458 | // Merging of extern globals is enabled by default on non-Mach-O as we |
| 459 | // expect it to be generally either beneficial or harmless. On Mach-O it |
| 460 | // is disabled as we emit the .subsections_via_symbols directive which |
| 461 | // means that merging extern globals is not safe. |
| 462 | bool MergeExternalByDefault = !TM->getTargetTriple().isOSBinFormatMachO(); |
| 463 | addPass(createGlobalMergePass(TM, 127, OnlyOptimizeForSize, |
| 464 | MergeExternalByDefault)); |
Ahmed Bougacha | 8207641 | 2015-06-04 20:39:23 +0000 | [diff] [blame] | 465 | } |
Anton Korobeynikov | 19edda0 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 466 | |
| 467 | return false; |
| 468 | } |
| 469 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 470 | bool ARMPassConfig::addInstSelector() { |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 471 | addPass(createARMISelDag(getARMTargetMachine(), getOptLevel())); |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 472 | return false; |
| 473 | } |
Rafael Espindola | f7d4a99 | 2006-09-19 15:49:25 +0000 | [diff] [blame] | 474 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 475 | #ifdef LLVM_BUILD_GLOBAL_ISEL |
| 476 | bool ARMPassConfig::addIRTranslator() { |
| 477 | addPass(new IRTranslator()); |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | bool ARMPassConfig::addLegalizeMachineIR() { |
| 482 | addPass(new Legalizer()); |
| 483 | return false; |
| 484 | } |
| 485 | |
| 486 | bool ARMPassConfig::addRegBankSelect() { |
| 487 | addPass(new RegBankSelect()); |
| 488 | return false; |
| 489 | } |
| 490 | |
| 491 | bool ARMPassConfig::addGlobalInstructionSelect() { |
| 492 | addPass(new InstructionSelect()); |
| 493 | return false; |
| 494 | } |
| 495 | #endif |
| 496 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 497 | void ARMPassConfig::addPreRegAlloc() { |
Renato Golin | 4c87139 | 2015-03-26 18:38:04 +0000 | [diff] [blame] | 498 | if (getOptLevel() != CodeGenOpt::None) { |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 499 | addPass(createMLxExpansionPass()); |
Renato Golin | 4c87139 | 2015-03-26 18:38:04 +0000 | [diff] [blame] | 500 | |
| 501 | if (EnableARMLoadStoreOpt) |
| 502 | addPass(createARMLoadStoreOptimizationPass(/* pre-register alloc */ true)); |
| 503 | |
| 504 | if (!DisableA15SDOptimization) |
| 505 | addPass(createA15SDOptimizerPass()); |
Silviu Baranga | 82dd6ac | 2013-03-15 18:28:25 +0000 | [diff] [blame] | 506 | } |
Evan Cheng | 185c9ef | 2009-06-13 09:12:55 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 509 | void ARMPassConfig::addPreSched2() { |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 510 | if (getOptLevel() != CodeGenOpt::None) { |
Renato Golin | 4c87139 | 2015-03-26 18:38:04 +0000 | [diff] [blame] | 511 | if (EnableARMLoadStoreOpt) |
| 512 | addPass(createARMLoadStoreOptimizationPass()); |
| 513 | |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 514 | addPass(new ARMExecutionDepsFix()); |
Eric Christopher | 7ae11c6 | 2010-11-11 20:50:14 +0000 | [diff] [blame] | 515 | } |
Evan Cheng | ce5a8ca | 2009-09-30 08:53:01 +0000 | [diff] [blame] | 516 | |
Evan Cheng | 207b246 | 2009-11-06 23:52:48 +0000 | [diff] [blame] | 517 | // Expand some pseudo instructions into multiple instructions to allow |
| 518 | // proper scheduling. |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 519 | addPass(createARMExpandPseudoPass()); |
Evan Cheng | 207b246 | 2009-11-06 23:52:48 +0000 | [diff] [blame] | 520 | |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 521 | if (getOptLevel() != CodeGenOpt::None) { |
Eric Christopher | 63b4488 | 2015-03-05 00:23:40 +0000 | [diff] [blame] | 522 | // in v8, IfConversion depends on Thumb instruction widths |
Akira Hatanaka | 4a61619 | 2015-06-08 18:50:43 +0000 | [diff] [blame] | 523 | addPass(createThumb2SizeReductionPass([this](const Function &F) { |
| 524 | return this->TM->getSubtarget<ARMSubtarget>(F).restrictIT(); |
| 525 | })); |
| 526 | |
Matthias Braun | 8b38ffa | 2016-10-24 23:23:02 +0000 | [diff] [blame] | 527 | addPass(createIfConverter([](const MachineFunction &MF) { |
| 528 | return !MF.getSubtarget<ARMSubtarget>().isThumb1Only(); |
Akira Hatanaka | 4a61619 | 2015-06-08 18:50:43 +0000 | [diff] [blame] | 529 | })); |
Renato Golin | 4c87139 | 2015-03-26 18:38:04 +0000 | [diff] [blame] | 530 | } |
Eric Christopher | 63b4488 | 2015-03-05 00:23:40 +0000 | [diff] [blame] | 531 | addPass(createThumb2ITBlockPass()); |
Evan Cheng | ce5a8ca | 2009-09-30 08:53:01 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 534 | void ARMPassConfig::addPreEmitPass() { |
Eric Christopher | 63b4488 | 2015-03-05 00:23:40 +0000 | [diff] [blame] | 535 | addPass(createThumb2SizeReductionPass()); |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 536 | |
Eric Christopher | 63b4488 | 2015-03-05 00:23:40 +0000 | [diff] [blame] | 537 | // Constant island pass work on unbundled instructions. |
Matthias Braun | 8b38ffa | 2016-10-24 23:23:02 +0000 | [diff] [blame] | 538 | addPass(createUnpackMachineBundles([](const MachineFunction &MF) { |
| 539 | return MF.getSubtarget<ARMSubtarget>().isThumb2(); |
Akira Hatanaka | 4a61619 | 2015-06-08 18:50:43 +0000 | [diff] [blame] | 540 | })); |
Evan Cheng | 0f9cce7 | 2009-07-10 01:54:42 +0000 | [diff] [blame] | 541 | |
Davide Italiano | 141b2891 | 2015-05-20 21:40:38 +0000 | [diff] [blame] | 542 | // Don't optimize barriers at -O0. |
| 543 | if (getOptLevel() != CodeGenOpt::None) |
| 544 | addPass(createARMOptimizeBarriersPass()); |
| 545 | |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 546 | addPass(createARMConstantIslandPass()); |
Rafael Espindola | f7d4a99 | 2006-09-19 15:49:25 +0000 | [diff] [blame] | 547 | } |