1 //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //
10 //===----------------------------------------------------------------------===//
11
12 #include "ARMTargetMachine.h"
13 #include "ARM.h"
14 #include "ARMMacroFusion.h"
15 #include "ARMSubtarget.h"
16 #include "ARMTargetObjectFile.h"
17 #include "ARMTargetTransformInfo.h"
18 #include "MCTargetDesc/ARMMCTargetDesc.h"
19 #include "TargetInfo/ARMTargetInfo.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/Triple.h"
24 #include "llvm/Analysis/TargetTransformInfo.h"
25 #include "llvm/CodeGen/ExecutionDomainFix.h"
26 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
27 #include "llvm/CodeGen/GlobalISel/IRTranslator.h"
28 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
29 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
30 #include "llvm/CodeGen/GlobalISel/Legalizer.h"
31 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
32 #include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
33 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
34 #include "llvm/CodeGen/MachineFunction.h"
35 #include "llvm/CodeGen/MachineScheduler.h"
36 #include "llvm/CodeGen/Passes.h"
37 #include "llvm/CodeGen/TargetPassConfig.h"
38 #include "llvm/IR/Attributes.h"
39 #include "llvm/IR/DataLayout.h"
40 #include "llvm/IR/Function.h"
41 #include "llvm/Pass.h"
42 #include "llvm/Support/CodeGen.h"
43 #include "llvm/Support/CommandLine.h"
44 #include "llvm/Support/ErrorHandling.h"
45 #include "llvm/Support/TargetParser.h"
46 #include "llvm/Support/TargetRegistry.h"
47 #include "llvm/Target/TargetLoweringObjectFile.h"
48 #include "llvm/Target/TargetOptions.h"
49 #include "llvm/Transforms/CFGuard.h"
50 #include "llvm/Transforms/Scalar.h"
51 #include <cassert>
52 #include <memory>
53 #include <string>
54
55 using namespace llvm;
56
57 static cl::opt<bool>
58 DisableA15SDOptimization("disable-a15-sd-optimization", cl::Hidden,
59 cl::desc("Inhibit optimization of S->D register accesses on A15"),
60 cl::init(false));
61
62 static cl::opt<bool>
63 EnableAtomicTidy("arm-atomic-cfg-tidy", cl::Hidden,
64 cl::desc("Run SimplifyCFG after expanding atomic operations"
65 " to make use of cmpxchg flow-based information"),
66 cl::init(true));
67
68 static cl::opt<bool>
69 EnableARMLoadStoreOpt("arm-load-store-opt", cl::Hidden,
70 cl::desc("Enable ARM load/store optimization pass"),
71 cl::init(true));
72
73 // FIXME: Unify control over GlobalMerge.
74 static cl::opt<cl::boolOrDefault>
75 EnableGlobalMerge("arm-global-merge", cl::Hidden,
76 cl::desc("Enable the global merge pass"));
77
78 namespace llvm {
79 void initializeARMExecutionDomainFixPass(PassRegistry&);
80 }
81
LLVMInitializeARMTarget()82 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMTarget() {
83 // Register the target.
84 RegisterTargetMachine<ARMLETargetMachine> X(getTheARMLETarget());
85 RegisterTargetMachine<ARMLETargetMachine> A(getTheThumbLETarget());
86 RegisterTargetMachine<ARMBETargetMachine> Y(getTheARMBETarget());
87 RegisterTargetMachine<ARMBETargetMachine> B(getTheThumbBETarget());
88
89 PassRegistry &Registry = *PassRegistry::getPassRegistry();
90 initializeGlobalISel(Registry);
91 initializeARMLoadStoreOptPass(Registry);
92 initializeARMPreAllocLoadStoreOptPass(Registry);
93 initializeARMParallelDSPPass(Registry);
94 initializeARMConstantIslandsPass(Registry);
95 initializeARMExecutionDomainFixPass(Registry);
96 initializeARMExpandPseudoPass(Registry);
97 initializeThumb2SizeReducePass(Registry);
98 initializeMVEVPTBlockPass(Registry);
99 initializeMVEVPTOptimisationsPass(Registry);
100 initializeMVETailPredicationPass(Registry);
101 initializeARMLowOverheadLoopsPass(Registry);
102 initializeARMBlockPlacementPass(Registry);
103 initializeMVEGatherScatterLoweringPass(Registry);
104 initializeARMSLSHardeningPass(Registry);
105 }
106
createTLOF(const Triple & TT)107 static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
108 if (TT.isOSBinFormatMachO())
109 return std::make_unique<TargetLoweringObjectFileMachO>();
110 if (TT.isOSWindows())
111 return std::make_unique<TargetLoweringObjectFileCOFF>();
112 return std::make_unique<ARMElfTargetObjectFile>();
113 }
114
115 static ARMBaseTargetMachine::ARMABI
computeTargetABI(const Triple & TT,StringRef CPU,const TargetOptions & Options)116 computeTargetABI(const Triple &TT, StringRef CPU,
117 const TargetOptions &Options) {
118 StringRef ABIName = Options.MCOptions.getABIName();
119
120 if (ABIName.empty())
121 ABIName = ARM::computeDefaultTargetABI(TT, CPU);
122
123 if (ABIName == "aapcs16")
124 return ARMBaseTargetMachine::ARM_ABI_AAPCS16;
125 else if (ABIName.startswith("aapcs"))
126 return ARMBaseTargetMachine::ARM_ABI_AAPCS;
127 else if (ABIName.startswith("apcs"))
128 return ARMBaseTargetMachine::ARM_ABI_APCS;
129
130 llvm_unreachable("Unhandled/unknown ABI Name!");
131 return ARMBaseTargetMachine::ARM_ABI_UNKNOWN;
132 }
133
computeDataLayout(const Triple & TT,StringRef CPU,const TargetOptions & Options,bool isLittle)134 static std::string computeDataLayout(const Triple &TT, StringRef CPU,
135 const TargetOptions &Options,
136 bool isLittle) {
137 auto ABI = computeTargetABI(TT, CPU, Options);
138 std::string Ret;
139
140 if (isLittle)
141 // Little endian.
142 Ret += "e";
143 else
144 // Big endian.
145 Ret += "E";
146
147 Ret += DataLayout::getManglingComponent(TT);
148
149 // Pointers are 32 bits and aligned to 32 bits.
150 Ret += "-p:32:32";
151
152 // Function pointers are aligned to 8 bits (because the LSB stores the
153 // ARM/Thumb state).
154 Ret += "-Fi8";
155
156 // ABIs other than APCS have 64 bit integers with natural alignment.
157 if (ABI != ARMBaseTargetMachine::ARM_ABI_APCS)
158 Ret += "-i64:64";
159
160 // We have 64 bits floats. The APCS ABI requires them to be aligned to 32
161 // bits, others to 64 bits. We always try to align to 64 bits.
162 if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS)
163 Ret += "-f64:32:64";
164
165 // We have 128 and 64 bit vectors. The APCS ABI aligns them to 32 bits, others
166 // to 64. We always ty to give them natural alignment.
167 if (ABI == ARMBaseTargetMachine::ARM_ABI_APCS)
168 Ret += "-v64:32:64-v128:32:128";
169 else if (ABI != ARMBaseTargetMachine::ARM_ABI_AAPCS16)
170 Ret += "-v128:64:128";
171
172 // Try to align aggregates to 32 bits (the default is 64 bits, which has no
173 // particular hardware support on 32-bit ARM).
174 Ret += "-a:0:32";
175
176 // Integer registers are 32 bits.
177 Ret += "-n32";
178
179 // The stack is 128 bit aligned on NaCl, 64 bit aligned on AAPCS and 32 bit
180 // aligned everywhere else.
181 if (TT.isOSNaCl() || ABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16)
182 Ret += "-S128";
183 else if (ABI == ARMBaseTargetMachine::ARM_ABI_AAPCS)
184 Ret += "-S64";
185 else
186 Ret += "-S32";
187
188 return Ret;
189 }
190
getEffectiveRelocModel(const Triple & TT,Optional<Reloc::Model> RM)191 static Reloc::Model getEffectiveRelocModel(const Triple &TT,
192 Optional<Reloc::Model> RM) {
193 if (!RM.hasValue())
194 // Default relocation model on Darwin is PIC.
195 return TT.isOSBinFormatMachO() ? Reloc::PIC_ : Reloc::Static;
196
197 if (*RM == Reloc::ROPI || *RM == Reloc::RWPI || *RM == Reloc::ROPI_RWPI)
198 assert(TT.isOSBinFormatELF() &&
199 "ROPI/RWPI currently only supported for ELF");
200
201 // DynamicNoPIC is only used on darwin.
202 if (*RM == Reloc::DynamicNoPIC && !TT.isOSDarwin())
203 return Reloc::Static;
204
205 return *RM;
206 }
207
208 /// Create an ARM architecture model.
209 ///
ARMBaseTargetMachine(const Target & T,const Triple & TT,StringRef CPU,StringRef FS,const TargetOptions & Options,Optional<Reloc::Model> RM,Optional<CodeModel::Model> CM,CodeGenOpt::Level OL,bool isLittle)210 ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT,
211 StringRef CPU, StringRef FS,
212 const TargetOptions &Options,
213 Optional<Reloc::Model> RM,
214 Optional<CodeModel::Model> CM,
215 CodeGenOpt::Level OL, bool isLittle)
216 : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, isLittle), TT,
217 CPU, FS, Options, getEffectiveRelocModel(TT, RM),
218 getEffectiveCodeModel(CM, CodeModel::Small), OL),
219 TargetABI(computeTargetABI(TT, CPU, Options)),
220 TLOF(createTLOF(getTargetTriple())), isLittle(isLittle) {
221
222 // Default to triple-appropriate float ABI
223 if (Options.FloatABIType == FloatABI::Default) {
224 if (isTargetHardFloat())
225 this->Options.FloatABIType = FloatABI::Hard;
226 else
227 this->Options.FloatABIType = FloatABI::Soft;
228 }
229
230 // Default to triple-appropriate EABI
231 if (Options.EABIVersion == EABI::Default ||
232 Options.EABIVersion == EABI::Unknown) {
233 // musl is compatible with glibc with regard to EABI version
234 if ((TargetTriple.getEnvironment() == Triple::GNUEABI ||
235 TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
236 TargetTriple.getEnvironment() == Triple::MuslEABI ||
237 TargetTriple.getEnvironment() == Triple::MuslEABIHF) &&
238 !(TargetTriple.isOSWindows() || TargetTriple.isOSDarwin()))
239 this->Options.EABIVersion = EABI::GNU;
240 else
241 this->Options.EABIVersion = EABI::EABI5;
242 }
243
244 if (TT.isOSBinFormatMachO()) {
245 this->Options.TrapUnreachable = true;
246 this->Options.NoTrapAfterNoreturn = true;
247 }
248
249 // ARM supports the debug entry values.
250 setSupportsDebugEntryValues(true);
251
252 initAsmInfo();
253
254 // ARM supports the MachineOutliner.
255 setMachineOutliner(true);
256 setSupportsDefaultOutlining(true);
257 }
258
259 ARMBaseTargetMachine::~ARMBaseTargetMachine() = default;
260
261 const ARMSubtarget *
getSubtargetImpl(const Function & F) const262 ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
263 Attribute CPUAttr = F.getFnAttribute("target-cpu");
264 Attribute FSAttr = F.getFnAttribute("target-features");
265
266 std::string CPU =
267 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
268 std::string FS =
269 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
270
271 // FIXME: This is related to the code below to reset the target options,
272 // we need to know whether or not the soft float flag is set on the
273 // function before we can generate a subtarget. We also need to use
274 // it as a key for the subtarget since that can be the only difference
275 // between two functions.
276 bool SoftFloat =
277 F.getFnAttribute("use-soft-float").getValueAsString() == "true";
278 // If the soft float attribute is set on the function turn on the soft float
279 // subtarget feature.
280 if (SoftFloat)
281 FS += FS.empty() ? "+soft-float" : ",+soft-float";
282
283 // Use the optminsize to identify the subtarget, but don't use it in the
284 // feature string.
285 std::string Key = CPU + FS;
286 if (F.hasMinSize())
287 Key += "+minsize";
288
289 auto &I = SubtargetMap[Key];
290 if (!I) {
291 // This needs to be done before we create a new subtarget since any
292 // creation will depend on the TM and the code generation flags on the
293 // function that reside in TargetOptions.
294 resetTargetOptions(F);
295 I = std::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle,
296 F.hasMinSize());
297
298 if (!I->isThumb() && !I->hasARMOps())
299 F.getContext().emitError("Function '" + F.getName() + "' uses ARM "
300 "instructions, but the target does not support ARM mode execution.");
301 }
302
303 return I.get();
304 }
305
306 TargetTransformInfo
getTargetTransformInfo(const Function & F)307 ARMBaseTargetMachine::getTargetTransformInfo(const Function &F) {
308 return TargetTransformInfo(ARMTTIImpl(this, F));
309 }
310
ARMLETargetMachine(const Target & T,const Triple & TT,StringRef CPU,StringRef FS,const TargetOptions & Options,Optional<Reloc::Model> RM,Optional<CodeModel::Model> CM,CodeGenOpt::Level OL,bool JIT)311 ARMLETargetMachine::ARMLETargetMachine(const Target &T, const Triple &TT,
312 StringRef CPU, StringRef FS,
313 const TargetOptions &Options,
314 Optional<Reloc::Model> RM,
315 Optional<CodeModel::Model> CM,
316 CodeGenOpt::Level OL, bool JIT)
317 : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
318
ARMBETargetMachine(const Target & T,const Triple & TT,StringRef CPU,StringRef FS,const TargetOptions & Options,Optional<Reloc::Model> RM,Optional<CodeModel::Model> CM,CodeGenOpt::Level OL,bool JIT)319 ARMBETargetMachine::ARMBETargetMachine(const Target &T, const Triple &TT,
320 StringRef CPU, StringRef FS,
321 const TargetOptions &Options,
322 Optional<Reloc::Model> RM,
323 Optional<CodeModel::Model> CM,
324 CodeGenOpt::Level OL, bool JIT)
325 : ARMBaseTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
326
327 namespace {
328
329 /// ARM Code Generator Pass Configuration Options.
330 class ARMPassConfig : public TargetPassConfig {
331 public:
ARMPassConfig(ARMBaseTargetMachine & TM,PassManagerBase & PM)332 ARMPassConfig(ARMBaseTargetMachine &TM, PassManagerBase &PM)
333 : TargetPassConfig(TM, PM) {}
334
getARMTargetMachine() const335 ARMBaseTargetMachine &getARMTargetMachine() const {
336 return getTM<ARMBaseTargetMachine>();
337 }
338
339 ScheduleDAGInstrs *
createMachineScheduler(MachineSchedContext * C) const340 createMachineScheduler(MachineSchedContext *C) const override {
341 ScheduleDAGMILive *DAG = createGenericSchedLive(C);
342 // add DAG Mutations here.
343 const ARMSubtarget &ST = C->MF->getSubtarget<ARMSubtarget>();
344 if (ST.hasFusion())
345 DAG->addMutation(createARMMacroFusionDAGMutation());
346 return DAG;
347 }
348
349 ScheduleDAGInstrs *
createPostMachineScheduler(MachineSchedContext * C) const350 createPostMachineScheduler(MachineSchedContext *C) const override {
351 ScheduleDAGMI *DAG = createGenericSchedPostRA(C);
352 // add DAG Mutations here.
353 const ARMSubtarget &ST = C->MF->getSubtarget<ARMSubtarget>();
354 if (ST.hasFusion())
355 DAG->addMutation(createARMMacroFusionDAGMutation());
356 return DAG;
357 }
358
359 void addIRPasses() override;
360 void addCodeGenPrepare() override;
361 bool addPreISel() override;
362 bool addInstSelector() override;
363 bool addIRTranslator() override;
364 bool addLegalizeMachineIR() override;
365 bool addRegBankSelect() override;
366 bool addGlobalInstructionSelect() override;
367 void addPreRegAlloc() override;
368 void addPreSched2() override;
369 void addPreEmitPass() override;
370 void addPreEmitPass2() override;
371
372 std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
373 };
374
375 class ARMExecutionDomainFix : public ExecutionDomainFix {
376 public:
377 static char ID;
ARMExecutionDomainFix()378 ARMExecutionDomainFix() : ExecutionDomainFix(ID, ARM::DPRRegClass) {}
getPassName() const379 StringRef getPassName() const override {
380 return "ARM Execution Domain Fix";
381 }
382 };
383 char ARMExecutionDomainFix::ID;
384
385 } // end anonymous namespace
386
387 INITIALIZE_PASS_BEGIN(ARMExecutionDomainFix, "arm-execution-domain-fix",
388 "ARM Execution Domain Fix", false, false)
INITIALIZE_PASS_DEPENDENCY(ReachingDefAnalysis)389 INITIALIZE_PASS_DEPENDENCY(ReachingDefAnalysis)
390 INITIALIZE_PASS_END(ARMExecutionDomainFix, "arm-execution-domain-fix",
391 "ARM Execution Domain Fix", false, false)
392
393 TargetPassConfig *ARMBaseTargetMachine::createPassConfig(PassManagerBase &PM) {
394 return new ARMPassConfig(*this, PM);
395 }
396
getCSEConfig() const397 std::unique_ptr<CSEConfigBase> ARMPassConfig::getCSEConfig() const {
398 return getStandardCSEConfigForOpt(TM->getOptLevel());
399 }
400
addIRPasses()401 void ARMPassConfig::addIRPasses() {
402 if (TM->Options.ThreadModel == ThreadModel::Single)
403 addPass(createLowerAtomicPass());
404 else
405 addPass(createAtomicExpandPass());
406
407 // Cmpxchg instructions are often used with a subsequent comparison to
408 // determine whether it succeeded. We can exploit existing control-flow in
409 // ldrex/strex loops to simplify this, but it needs tidying up.
410 if (TM->getOptLevel() != CodeGenOpt::None && EnableAtomicTidy)
411 addPass(createCFGSimplificationPass(
412 SimplifyCFGOptions().hoistCommonInsts(true).sinkCommonInsts(true),
413 [this](const Function &F) {
414 const auto &ST = this->TM->getSubtarget<ARMSubtarget>(F);
415 return ST.hasAnyDataBarrier() && !ST.isThumb1Only();
416 }));
417
418 addPass(createMVEGatherScatterLoweringPass());
419
420 TargetPassConfig::addIRPasses();
421
422 // Run the parallel DSP pass.
423 if (getOptLevel() == CodeGenOpt::Aggressive)
424 addPass(createARMParallelDSPPass());
425
426 // Match interleaved memory accesses to ldN/stN intrinsics.
427 if (TM->getOptLevel() != CodeGenOpt::None)
428 addPass(createInterleavedAccessPass());
429
430 // Add Control Flow Guard checks.
431 if (TM->getTargetTriple().isOSWindows())
432 addPass(createCFGuardCheckPass());
433 }
434
addCodeGenPrepare()435 void ARMPassConfig::addCodeGenPrepare() {
436 if (getOptLevel() != CodeGenOpt::None)
437 addPass(createTypePromotionPass());
438 TargetPassConfig::addCodeGenPrepare();
439 }
440
addPreISel()441 bool ARMPassConfig::addPreISel() {
442 if ((TM->getOptLevel() != CodeGenOpt::None &&
443 EnableGlobalMerge == cl::BOU_UNSET) ||
444 EnableGlobalMerge == cl::BOU_TRUE) {
445 // FIXME: This is using the thumb1 only constant value for
446 // maximal global offset for merging globals. We may want
447 // to look into using the old value for non-thumb1 code of
448 // 4095 based on the TargetMachine, but this starts to become
449 // tricky when doing code gen per function.
450 bool OnlyOptimizeForSize = (TM->getOptLevel() < CodeGenOpt::Aggressive) &&
451 (EnableGlobalMerge == cl::BOU_UNSET);
452 // Merging of extern globals is enabled by default on non-Mach-O as we
453 // expect it to be generally either beneficial or harmless. On Mach-O it
454 // is disabled as we emit the .subsections_via_symbols directive which
455 // means that merging extern globals is not safe.
456 bool MergeExternalByDefault = !TM->getTargetTriple().isOSBinFormatMachO();
457 addPass(createGlobalMergePass(TM, 127, OnlyOptimizeForSize,
458 MergeExternalByDefault));
459 }
460
461 if (TM->getOptLevel() != CodeGenOpt::None) {
462 addPass(createHardwareLoopsPass());
463 addPass(createMVETailPredicationPass());
464 }
465
466 return false;
467 }
468
addInstSelector()469 bool ARMPassConfig::addInstSelector() {
470 addPass(createARMISelDag(getARMTargetMachine(), getOptLevel()));
471 return false;
472 }
473
addIRTranslator()474 bool ARMPassConfig::addIRTranslator() {
475 addPass(new IRTranslator(getOptLevel()));
476 return false;
477 }
478
addLegalizeMachineIR()479 bool ARMPassConfig::addLegalizeMachineIR() {
480 addPass(new Legalizer());
481 return false;
482 }
483
addRegBankSelect()484 bool ARMPassConfig::addRegBankSelect() {
485 addPass(new RegBankSelect());
486 return false;
487 }
488
addGlobalInstructionSelect()489 bool ARMPassConfig::addGlobalInstructionSelect() {
490 addPass(new InstructionSelect());
491 return false;
492 }
493
addPreRegAlloc()494 void ARMPassConfig::addPreRegAlloc() {
495 if (getOptLevel() != CodeGenOpt::None) {
496 addPass(createMVEVPTOptimisationsPass());
497
498 addPass(createMLxExpansionPass());
499
500 if (EnableARMLoadStoreOpt)
501 addPass(createARMLoadStoreOptimizationPass(/* pre-register alloc */ true));
502
503 if (!DisableA15SDOptimization)
504 addPass(createA15SDOptimizerPass());
505 }
506 }
507
addPreSched2()508 void ARMPassConfig::addPreSched2() {
509 if (getOptLevel() != CodeGenOpt::None) {
510 if (EnableARMLoadStoreOpt)
511 addPass(createARMLoadStoreOptimizationPass());
512
513 addPass(new ARMExecutionDomainFix());
514 addPass(createBreakFalseDeps());
515 }
516
517 // Expand some pseudo instructions into multiple instructions to allow
518 // proper scheduling.
519 addPass(createARMExpandPseudoPass());
520
521 if (getOptLevel() != CodeGenOpt::None) {
522 // When optimising for size, always run the Thumb2SizeReduction pass before
523 // IfConversion. Otherwise, check whether IT blocks are restricted
524 // (e.g. in v8, IfConversion depends on Thumb instruction widths)
525 addPass(createThumb2SizeReductionPass([this](const Function &F) {
526 return this->TM->getSubtarget<ARMSubtarget>(F).hasMinSize() ||
527 this->TM->getSubtarget<ARMSubtarget>(F).restrictIT();
528 }));
529
530 addPass(createIfConverter([](const MachineFunction &MF) {
531 return !MF.getSubtarget<ARMSubtarget>().isThumb1Only();
532 }));
533 }
534 addPass(createMVEVPTBlockPass());
535 addPass(createThumb2ITBlockPass());
536
537 // Add both scheduling passes to give the subtarget an opportunity to pick
538 // between them.
539 if (getOptLevel() != CodeGenOpt::None) {
540 addPass(&PostMachineSchedulerID);
541 addPass(&PostRASchedulerID);
542 }
543
544 addPass(createARMIndirectThunks());
545 addPass(createARMSLSHardeningPass());
546 }
547
addPreEmitPass()548 void ARMPassConfig::addPreEmitPass() {
549 addPass(createThumb2SizeReductionPass());
550
551 // Constant island pass work on unbundled instructions.
552 addPass(createUnpackMachineBundles([](const MachineFunction &MF) {
553 return MF.getSubtarget<ARMSubtarget>().isThumb2();
554 }));
555
556 // Don't optimize barriers or block placement at -O0.
557 if (getOptLevel() != CodeGenOpt::None) {
558 addPass(createARMBlockPlacementPass());
559 addPass(createARMOptimizeBarriersPass());
560 }
561 }
562
addPreEmitPass2()563 void ARMPassConfig::addPreEmitPass2() {
564 addPass(createARMConstantIslandPass());
565 addPass(createARMLowOverheadLoopsPass());
566
567 // Identify valid longjmp targets for Windows Control Flow Guard.
568 if (TM->getTargetTriple().isOSWindows())
569 addPass(createCFGuardLongjmpPass());
570 }
571