blob: 33439a78cb58910c64c08edb7da40dea8c63afe1 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002//
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//
Jia Liub22310f2012-02-18 12:03:15 +000010// Implements the info about Hexagon target spec.
Tony Linthicum1213a7a2011-12-12 21:14:40 +000011//
12//===----------------------------------------------------------------------===//
13
Tony Linthicum1213a7a2011-12-12 21:14:40 +000014#include "HexagonTargetMachine.h"
15#include "Hexagon.h"
16#include "HexagonISelLowering.h"
Sergei Larin4d8986a2012-09-04 14:49:56 +000017#include "HexagonMachineScheduler.h"
Jyotsna Verma5eb59802013-05-07 19:53:00 +000018#include "HexagonTargetObjectFile.h"
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000019#include "HexagonTargetTransformInfo.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000020#include "llvm/CodeGen/Passes.h"
Matthias Braun31d19d42016-05-10 03:21:59 +000021#include "llvm/CodeGen/TargetPassConfig.h"
Chandler Carruth30d69c22015-02-13 10:01:29 +000022#include "llvm/IR/LegacyPassManager.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000023#include "llvm/IR/Module.h"
Benjamin Kramerae87d7b2012-02-06 10:19:29 +000024#include "llvm/Support/CommandLine.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000025#include "llvm/Support/TargetRegistry.h"
Krzysztof Parzyszekc8b94382017-01-26 21:41:10 +000026#include "llvm/Transforms/IPO/PassManagerBuilder.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000027#include "llvm/Transforms/Scalar.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000028
Tony Linthicum1213a7a2011-12-12 21:14:40 +000029using namespace llvm;
30
Krzysztof Parzyszek12798812016-01-12 19:09:01 +000031static cl::opt<bool> EnableRDFOpt("rdf-opt", cl::Hidden, cl::ZeroOrMore,
32 cl::init(true), cl::desc("Enable RDF-based optimizations"));
33
34static cl::opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
Krzysztof Parzyszekc05dff12015-03-31 13:35:12 +000035 cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));
Tony Linthicum1213a7a2011-12-12 21:14:40 +000036
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +000037static cl::opt<bool> DisableAModeOpt("disable-hexagon-amodeopt",
38 cl::Hidden, cl::ZeroOrMore, cl::init(false),
39 cl::desc("Disable Hexagon Addressing Mode Optimization"));
40
Jyotsna Verma653d8832013-03-27 11:14:24 +000041static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
Krzysztof Parzyszekc05dff12015-03-31 13:35:12 +000042 cl::Hidden, cl::ZeroOrMore, cl::init(false),
43 cl::desc("Disable Hexagon CFG Optimization"));
44
Krzysztof Parzyszek167d9182016-07-28 20:01:59 +000045static cl::opt<bool> DisableHCP("disable-hcp", cl::init(false), cl::Hidden,
46 cl::ZeroOrMore, cl::desc("Disable Hexagon constant propagation"));
47
Krzysztof Parzyszek5b7dd0c2015-10-16 19:43:56 +000048static cl::opt<bool> DisableStoreWidening("disable-store-widen",
49 cl::Hidden, cl::init(false), cl::desc("Disable store widening"));
50
Krzysztof Parzyszekc05dff12015-03-31 13:35:12 +000051static cl::opt<bool> EnableExpandCondsets("hexagon-expand-condsets",
52 cl::init(true), cl::Hidden, cl::ZeroOrMore,
53 cl::desc("Early expansion of MUX"));
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +000054
Krzysztof Parzyszekfb338242015-10-06 15:49:14 +000055static cl::opt<bool> EnableEarlyIf("hexagon-eif", cl::init(true), cl::Hidden,
56 cl::ZeroOrMore, cl::desc("Enable early if-conversion"));
57
Krzysztof Parzyszek21b53a52015-07-08 14:47:34 +000058static cl::opt<bool> EnableGenInsert("hexagon-insert", cl::init(true),
59 cl::Hidden, cl::desc("Generate \"insert\" instructions"));
Jyotsna Verma653d8832013-03-27 11:14:24 +000060
Krzysztof Parzyszek79b24332015-07-08 19:22:28 +000061static cl::opt<bool> EnableCommGEP("hexagon-commgep", cl::init(true),
62 cl::Hidden, cl::ZeroOrMore, cl::desc("Enable commoning of GEP instructions"));
63
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +000064static cl::opt<bool> EnableGenExtract("hexagon-extract", cl::init(true),
65 cl::Hidden, cl::desc("Generate \"extract\" instructions"));
Krzysztof Parzyszek79b24332015-07-08 19:22:28 +000066
Krzysztof Parzyszek92172202015-07-20 21:23:25 +000067static cl::opt<bool> EnableGenMux("hexagon-mux", cl::init(true), cl::Hidden,
68 cl::desc("Enable converting conditional transfers into MUX instructions"));
69
Krzysztof Parzyszek75874472015-07-14 19:30:21 +000070static cl::opt<bool> EnableGenPred("hexagon-gen-pred", cl::init(true),
71 cl::Hidden, cl::desc("Enable conversion of arithmetic operations to "
72 "predicate instructions"));
73
Krzysztof Parzyszekd3d0a4b2016-07-22 14:22:43 +000074static cl::opt<bool> EnableLoopPrefetch("hexagon-loop-prefetch",
75 cl::init(false), cl::Hidden, cl::ZeroOrMore,
76 cl::desc("Enable loop data prefetch on Hexagon"));
77
Krzysztof Parzyszeka7c5f042015-10-16 20:38:54 +000078static cl::opt<bool> DisableHSDR("disable-hsdr", cl::init(false), cl::Hidden,
79 cl::desc("Disable splitting double registers"));
80
Krzysztof Parzyszekced99412015-10-20 22:57:13 +000081static cl::opt<bool> EnableBitSimplify("hexagon-bit", cl::init(true),
82 cl::Hidden, cl::desc("Bit simplification"));
83
84static cl::opt<bool> EnableLoopResched("hexagon-loop-resched", cl::init(true),
85 cl::Hidden, cl::desc("Loop rescheduling"));
86
Krzysztof Parzyszekd5590052016-05-11 15:01:30 +000087static cl::opt<bool> HexagonNoOpt("hexagon-noopt", cl::init(false),
88 cl::Hidden, cl::desc("Disable backend optimizations"));
89
Ron Lieberman8123b962016-08-01 19:36:39 +000090static cl::opt<bool> EnableVectorPrint("enable-hexagon-vector-print",
91 cl::Hidden, cl::ZeroOrMore, cl::init(false),
92 cl::desc("Enable Hexagon Vector print instr pass"));
93
Krzysztof Parzyszekdaf1a5f2017-09-06 16:22:55 +000094static cl::opt<bool> EnableTrapUnreachable("hexagon-trap-unreachable",
95 cl::Hidden, cl::ZeroOrMore, cl::init(false),
96 cl::desc("Enable generating trap for unreachable"));
97
Tony Linthicum1213a7a2011-12-12 21:14:40 +000098/// HexagonTargetMachineModule - Note that this is used on hosts that
99/// cannot link in a library unless there are references into the
100/// library. In particular, it seems that it is not possible to get
101/// things to work on Win32 without this. Though it is unused, do not
102/// remove it.
103extern "C" int HexagonTargetMachineModule;
104int HexagonTargetMachineModule = 0;
105
Sergei Larin4d8986a2012-09-04 14:49:56 +0000106static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
Krzysztof Parzyszek697297a2017-08-28 15:52:54 +0000107 ScheduleDAGMILive *DAG =
108 new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>());
Krzysztof Parzyszek95da97e2017-08-28 16:24:22 +0000109 DAG->addMutation(make_unique<HexagonSubtarget::UsrOverflowMutation>());
110 DAG->addMutation(make_unique<HexagonSubtarget::HVXMemLatencyMutation>());
111 DAG->addMutation(make_unique<HexagonSubtarget::CallMutation>());
Krzysztof Parzyszek697297a2017-08-28 15:52:54 +0000112 DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI));
113 return DAG;
Sergei Larin4d8986a2012-09-04 14:49:56 +0000114}
115
116static MachineSchedRegistry
117SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
118 createVLIWMachineSched);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000119
Krzysztof Parzyszekc05dff12015-03-31 13:35:12 +0000120namespace llvm {
Krzysztof Parzyszek951fb362016-08-24 22:27:36 +0000121 extern char &HexagonExpandCondsetsID;
Krzysztof Parzyszek1966fd72017-08-09 21:22:05 +0000122 void initializeHexagonEarlyIfConversionPass(PassRegistry&);
Krzysztof Parzyszek951fb362016-08-24 22:27:36 +0000123 void initializeHexagonExpandCondsetsPass(PassRegistry&);
Krzysztof Parzyszekde2ac172017-06-13 16:07:36 +0000124 void initializeHexagonGenMuxPass(PassRegistry&);
Krzysztof Parzyszekdf4a05d2017-07-10 18:38:52 +0000125 void initializeHexagonLoopIdiomRecognizePass(PassRegistry&);
Pranav Bhandarkar931d0b72017-09-21 21:48:23 +0000126 void initializeHexagonVectorLoopCarriedReusePass(PassRegistry&);
Krzysztof Parzyszek5ddd2e52017-06-27 18:37:16 +0000127 void initializeHexagonNewValueJumpPass(PassRegistry&);
Krzysztof Parzyszekdf4a05d2017-07-10 18:38:52 +0000128 void initializeHexagonOptAddrModePass(PassRegistry&);
129 void initializeHexagonPacketizerPass(PassRegistry&);
Krzysztof Parzyszekc8b94382017-01-26 21:41:10 +0000130 Pass *createHexagonLoopIdiomPass();
Pranav Bhandarkar931d0b72017-09-21 21:48:23 +0000131 Pass *createHexagonVectorLoopCarriedReusePass();
Krzysztof Parzyszek951fb362016-08-24 22:27:36 +0000132
Krzysztof Parzyszekced99412015-10-20 22:57:13 +0000133 FunctionPass *createHexagonBitSimplify();
Krzysztof Parzyszek7b59ae22016-04-19 18:30:18 +0000134 FunctionPass *createHexagonBranchRelaxation();
Krzysztof Parzyszekdb867702015-10-19 17:46:01 +0000135 FunctionPass *createHexagonCallFrameInformation();
Colin LeMahieu56efafc2015-06-15 19:05:35 +0000136 FunctionPass *createHexagonCFGOptimizer();
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000137 FunctionPass *createHexagonCommonGEP();
Krzysztof Parzyszek167d9182016-07-28 20:01:59 +0000138 FunctionPass *createHexagonConstPropagationPass();
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000139 FunctionPass *createHexagonCopyToCombine();
Krzysztof Parzyszekfb338242015-10-06 15:49:14 +0000140 FunctionPass *createHexagonEarlyIfConversion();
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000141 FunctionPass *createHexagonFixupHwLoops();
142 FunctionPass *createHexagonGenExtract();
Krzysztof Parzyszek21b53a52015-07-08 14:47:34 +0000143 FunctionPass *createHexagonGenInsert();
Krzysztof Parzyszek92172202015-07-20 21:23:25 +0000144 FunctionPass *createHexagonGenMux();
Krzysztof Parzyszek75874472015-07-14 19:30:21 +0000145 FunctionPass *createHexagonGenPredicate();
Colin LeMahieu56efafc2015-06-15 19:05:35 +0000146 FunctionPass *createHexagonHardwareLoops();
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000147 FunctionPass *createHexagonISelDag(HexagonTargetMachine &TM,
148 CodeGenOpt::Level OptLevel);
Krzysztof Parzyszekced99412015-10-20 22:57:13 +0000149 FunctionPass *createHexagonLoopRescheduling();
Colin LeMahieu56efafc2015-06-15 19:05:35 +0000150 FunctionPass *createHexagonNewValueJump();
Krzysztof Parzyszek055c5fd2015-10-19 19:10:48 +0000151 FunctionPass *createHexagonOptimizeSZextends();
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +0000152 FunctionPass *createHexagonOptAddrMode();
Colin LeMahieu56efafc2015-06-15 19:05:35 +0000153 FunctionPass *createHexagonPacketizer();
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000154 FunctionPass *createHexagonPeephole();
Krzysztof Parzyszek12798812016-01-12 19:09:01 +0000155 FunctionPass *createHexagonRDFOpt();
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000156 FunctionPass *createHexagonSplitConst32AndConst64();
Krzysztof Parzyszeka7c5f042015-10-16 20:38:54 +0000157 FunctionPass *createHexagonSplitDoubleRegs();
Krzysztof Parzyszek5b7dd0c2015-10-16 19:43:56 +0000158 FunctionPass *createHexagonStoreWidening();
Ron Lieberman8123b962016-08-01 19:36:39 +0000159 FunctionPass *createHexagonVectorPrint();
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000160} // end namespace llvm;
Krzysztof Parzyszekc05dff12015-03-31 13:35:12 +0000161
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000162static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
163 if (!RM.hasValue())
164 return Reloc::Static;
165 return *RM;
166}
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000167
Rafael Espindola79e238a2017-08-03 02:16:21 +0000168static CodeModel::Model getEffectiveCodeModel(Optional<CodeModel::Model> CM) {
169 if (CM)
170 return *CM;
171 return CodeModel::Small;
172}
173
Krzysztof Parzyszekc8b94382017-01-26 21:41:10 +0000174extern "C" void LLVMInitializeHexagonTarget() {
175 // Register the target.
176 RegisterTargetMachine<HexagonTargetMachine> X(getTheHexagonTarget());
Krzysztof Parzyszekde2ac172017-06-13 16:07:36 +0000177
178 PassRegistry &PR = *PassRegistry::getPassRegistry();
Krzysztof Parzyszek1966fd72017-08-09 21:22:05 +0000179 initializeHexagonEarlyIfConversionPass(PR);
Krzysztof Parzyszekde2ac172017-06-13 16:07:36 +0000180 initializeHexagonGenMuxPass(PR);
Krzysztof Parzyszekdf4a05d2017-07-10 18:38:52 +0000181 initializeHexagonLoopIdiomRecognizePass(PR);
Pranav Bhandarkar931d0b72017-09-21 21:48:23 +0000182 initializeHexagonVectorLoopCarriedReusePass(PR);
Krzysztof Parzyszek5ddd2e52017-06-27 18:37:16 +0000183 initializeHexagonNewValueJumpPass(PR);
Krzysztof Parzyszekdf4a05d2017-07-10 18:38:52 +0000184 initializeHexagonOptAddrModePass(PR);
185 initializeHexagonPacketizerPass(PR);
Krzysztof Parzyszekc8b94382017-01-26 21:41:10 +0000186}
187
Daniel Sanders3e5de882015-06-11 19:41:26 +0000188HexagonTargetMachine::HexagonTargetMachine(const Target &T, const Triple &TT,
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000189 StringRef CPU, StringRef FS,
Craig Topperb5454082012-03-17 09:24:09 +0000190 const TargetOptions &Options,
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000191 Optional<Reloc::Model> RM,
Rafael Espindola79e238a2017-08-03 02:16:21 +0000192 Optional<CodeModel::Model> CM,
193 CodeGenOpt::Level OL, bool JIT)
Krzysztof Parzyszeke5996432016-02-12 14:47:38 +0000194 // Specify the vector alignment explicitly. For v512x1, the calculated
195 // alignment would be 512*alignment(i1), which is 512 bytes, instead of
196 // the required minimum of 64 bytes.
Matthias Braun3a9c1142017-10-12 22:28:54 +0000197 : TargetMachine(
Rafael Espindola79e238a2017-08-03 02:16:21 +0000198 T,
199 "e-m:e-p:32:32:32-a:0-n16:32-"
200 "i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-"
201 "v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048",
202 TT, CPU, FS, Options, getEffectiveRelocModel(RM),
203 getEffectiveCodeModel(CM), (HexagonNoOpt ? CodeGenOpt::None : OL)),
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000204 TLOF(make_unique<HexagonTargetObjectFile>()) {
Krzysztof Parzyszekdaf1a5f2017-09-06 16:22:55 +0000205 if (EnableTrapUnreachable)
206 this->Options.TrapUnreachable = true;
Krzysztof Parzyszek951fb362016-08-24 22:27:36 +0000207 initializeHexagonExpandCondsetsPass(*PassRegistry::getPassRegistry());
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000208 initAsmInfo();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000209}
210
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000211const HexagonSubtarget *
212HexagonTargetMachine::getSubtargetImpl(const Function &F) const {
Reid Klecknerb5180542017-03-21 16:57:19 +0000213 AttributeList FnAttrs = F.getAttributes();
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000214 Attribute CPUAttr =
Reid Klecknerb5180542017-03-21 16:57:19 +0000215 FnAttrs.getAttribute(AttributeList::FunctionIndex, "target-cpu");
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000216 Attribute FSAttr =
Reid Klecknerb5180542017-03-21 16:57:19 +0000217 FnAttrs.getAttribute(AttributeList::FunctionIndex, "target-features");
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000218
219 std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
220 ? CPUAttr.getValueAsString().str()
221 : TargetCPU;
222 std::string FS = !FSAttr.hasAttribute(Attribute::None)
223 ? FSAttr.getValueAsString().str()
224 : TargetFS;
225
226 auto &I = SubtargetMap[CPU + FS];
227 if (!I) {
228 // This needs to be done before we create a new subtarget since any
229 // creation will depend on the TM and the code generation flags on the
230 // function that reside in TargetOptions.
231 resetTargetOptions(F);
232 I = llvm::make_unique<HexagonSubtarget>(TargetTriple, CPU, FS, *this);
233 }
234 return I.get();
235}
236
Krzysztof Parzyszekc8b94382017-01-26 21:41:10 +0000237void HexagonTargetMachine::adjustPassManager(PassManagerBuilder &PMB) {
238 PMB.addExtension(
239 PassManagerBuilder::EP_LateLoopOptimizations,
240 [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
241 PM.add(createHexagonLoopIdiomPass());
242 });
Pranav Bhandarkar931d0b72017-09-21 21:48:23 +0000243 PMB.addExtension(
244 PassManagerBuilder::EP_LoopOptimizerEnd,
245 [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
246 PM.add(createHexagonVectorLoopCarriedReusePass());
247 });
Krzysztof Parzyszekc8b94382017-01-26 21:41:10 +0000248}
249
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000250TargetIRAnalysis HexagonTargetMachine::getTargetIRAnalysis() {
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000251 return TargetIRAnalysis([this](const Function &F) {
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +0000252 return TargetTransformInfo(HexagonTTIImpl(this, F));
253 });
254}
255
256
Reid Kleckner357600e2014-11-20 23:37:18 +0000257HexagonTargetMachine::~HexagonTargetMachine() {}
258
Andrew Trickccb67362012-02-03 05:12:41 +0000259namespace {
260/// Hexagon Code Generator Pass Configuration Options.
261class HexagonPassConfig : public TargetPassConfig {
262public:
Matthias Braun5e394c32017-05-30 21:36:41 +0000263 HexagonPassConfig(HexagonTargetMachine &TM, PassManagerBase &PM)
Krzysztof Parzyszekd0f8e1c2016-05-27 20:48:39 +0000264 : TargetPassConfig(TM, PM) {}
Andrew Trickccb67362012-02-03 05:12:41 +0000265
266 HexagonTargetMachine &getHexagonTargetMachine() const {
267 return getTM<HexagonTargetMachine>();
268 }
269
Craig Topper906c2cd2014-04-29 07:58:16 +0000270 ScheduleDAGInstrs *
271 createMachineScheduler(MachineSchedContext *C) const override {
Andrew Trick978674b2013-09-20 05:14:41 +0000272 return createVLIWMachineSched(C);
273 }
274
Krzysztof Parzyszek79b24332015-07-08 19:22:28 +0000275 void addIRPasses() override;
Craig Topper906c2cd2014-04-29 07:58:16 +0000276 bool addInstSelector() override;
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000277 void addPreRegAlloc() override;
278 void addPostRegAlloc() override;
279 void addPreSched2() override;
280 void addPreEmitPass() override;
Andrew Trickccb67362012-02-03 05:12:41 +0000281};
282} // namespace
283
Andrew Trickf8ea1082012-02-04 02:56:59 +0000284TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
Matthias Braun5e394c32017-05-30 21:36:41 +0000285 return new HexagonPassConfig(*this, PM);
Andrew Trickccb67362012-02-03 05:12:41 +0000286}
287
Krzysztof Parzyszek79b24332015-07-08 19:22:28 +0000288void HexagonPassConfig::addIRPasses() {
289 TargetPassConfig::addIRPasses();
Krzysztof Parzyszek79b24332015-07-08 19:22:28 +0000290 bool NoOpt = (getOptLevel() == CodeGenOpt::None);
Krzysztof Parzyszekfeaf7b82015-07-09 14:51:21 +0000291
Francis Visoiu Mistrih8b617642017-05-18 17:21:13 +0000292 addPass(createAtomicExpandPass());
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000293 if (!NoOpt) {
Krzysztof Parzyszekd3d0a4b2016-07-22 14:22:43 +0000294 if (EnableLoopPrefetch)
295 addPass(createLoopDataPrefetchPass());
Krzysztof Parzyszeka0ecf072015-07-14 17:07:24 +0000296 if (EnableCommGEP)
297 addPass(createHexagonCommonGEP());
298 // Replace certain combinations of shifts and ands with extracts.
299 if (EnableGenExtract)
300 addPass(createHexagonGenExtract());
301 }
Krzysztof Parzyszek79b24332015-07-08 19:22:28 +0000302}
303
Andrew Trickccb67362012-02-03 05:12:41 +0000304bool HexagonPassConfig::addInstSelector() {
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000305 HexagonTargetMachine &TM = getHexagonTargetMachine();
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000306 bool NoOpt = (getOptLevel() == CodeGenOpt::None);
Jyotsna Verma653d8832013-03-27 11:14:24 +0000307
Krzysztof Parzyszek055c5fd2015-10-19 19:10:48 +0000308 if (!NoOpt)
309 addPass(createHexagonOptimizeSZextends());
310
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000311 addPass(createHexagonISelDag(TM, getOptLevel()));
Jyotsna Verma653d8832013-03-27 11:14:24 +0000312
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000313 if (!NoOpt) {
Krzysztof Parzyszek75874472015-07-14 19:30:21 +0000314 // Create logical operations on predicate registers.
315 if (EnableGenPred)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000316 addPass(createHexagonGenPredicate());
Krzysztof Parzyszekced99412015-10-20 22:57:13 +0000317 // Rotate loops to expose bit-simplification opportunities.
318 if (EnableLoopResched)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000319 addPass(createHexagonLoopRescheduling());
Krzysztof Parzyszeka7c5f042015-10-16 20:38:54 +0000320 // Split double registers.
321 if (!DisableHSDR)
322 addPass(createHexagonSplitDoubleRegs());
Krzysztof Parzyszekced99412015-10-20 22:57:13 +0000323 // Bit simplification.
324 if (EnableBitSimplify)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000325 addPass(createHexagonBitSimplify());
Jyotsna Verma653d8832013-03-27 11:14:24 +0000326 addPass(createHexagonPeephole());
Krzysztof Parzyszek167d9182016-07-28 20:01:59 +0000327 // Constant propagation.
328 if (!DisableHCP) {
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000329 addPass(createHexagonConstPropagationPass());
330 addPass(&UnreachableMachineBlockElimID);
Krzysztof Parzyszek167d9182016-07-28 20:01:59 +0000331 }
Krzysztof Parzyszek21b53a52015-07-08 14:47:34 +0000332 if (EnableGenInsert)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000333 addPass(createHexagonGenInsert());
Krzysztof Parzyszekfb338242015-10-06 15:49:14 +0000334 if (EnableEarlyIf)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000335 addPass(createHexagonEarlyIfConversion());
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000336 }
Jyotsna Verma653d8832013-03-27 11:14:24 +0000337
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000338 return false;
339}
340
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000341void HexagonPassConfig::addPreRegAlloc() {
Krzysztof Parzyszek5b7dd0c2015-10-16 19:43:56 +0000342 if (getOptLevel() != CodeGenOpt::None) {
Krzysztof Parzyszek951fb362016-08-24 22:27:36 +0000343 if (EnableExpandCondsets)
344 insertPass(&RegisterCoalescerID, &HexagonExpandCondsetsID);
Krzysztof Parzyszek5b7dd0c2015-10-16 19:43:56 +0000345 if (!DisableStoreWidening)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000346 addPass(createHexagonStoreWidening());
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000347 if (!DisableHardwareLoops)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000348 addPass(createHexagonHardwareLoops());
Krzysztof Parzyszek5b7dd0c2015-10-16 19:43:56 +0000349 }
Brendon Cahoon254f8892016-07-29 16:44:44 +0000350 if (TM->getOptLevel() >= CodeGenOpt::Default)
351 addPass(&MachinePipelinerID);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000352}
353
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000354void HexagonPassConfig::addPostRegAlloc() {
Krzysztof Parzyszek12798812016-01-12 19:09:01 +0000355 if (getOptLevel() != CodeGenOpt::None) {
356 if (EnableRDFOpt)
357 addPass(createHexagonRDFOpt());
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000358 if (!DisableHexagonCFGOpt)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000359 addPass(createHexagonCFGOptimizer());
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +0000360 if (!DisableAModeOpt)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000361 addPass(createHexagonOptAddrMode());
Krzysztof Parzyszek12798812016-01-12 19:09:01 +0000362 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000363}
364
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000365void HexagonPassConfig::addPreSched2() {
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000366 addPass(createHexagonCopyToCombine());
Jyotsna Verma5eb59802013-05-07 19:53:00 +0000367 if (getOptLevel() != CodeGenOpt::None)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000368 addPass(&IfConverterID);
Eric Christopher01f875e2015-02-02 22:11:43 +0000369 addPass(createHexagonSplitConst32AndConst64());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000370}
371
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000372void HexagonPassConfig::addPreEmitPass() {
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000373 bool NoOpt = (getOptLevel() == CodeGenOpt::None);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000374
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000375 if (!NoOpt)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000376 addPass(createHexagonNewValueJump());
Sirish Pande4bd20c52012-05-12 05:10:30 +0000377
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000378 addPass(createHexagonBranchRelaxation());
Krzysztof Parzyszek7b59ae22016-04-19 18:30:18 +0000379
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000380 // Create Packets.
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000381 if (!NoOpt) {
382 if (!DisableHardwareLoops)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000383 addPass(createHexagonFixupHwLoops());
Krzysztof Parzyszek92172202015-07-20 21:23:25 +0000384 // Generate MUX from pairs of conditional transfers.
385 if (EnableGenMux)
Krzysztof Parzyszekb1ada4e2017-06-08 21:25:36 +0000386 addPass(createHexagonGenMux());
Krzysztof Parzyszek92172202015-07-20 21:23:25 +0000387
Matthias Braun7e37a5f2014-12-11 21:26:47 +0000388 addPass(createHexagonPacketizer(), false);
Krzysztof Parzyszek59df52c2013-05-06 21:25:45 +0000389 }
Ron Lieberman8123b962016-08-01 19:36:39 +0000390 if (EnableVectorPrint)
391 addPass(createHexagonVectorPrint(), false);
Krzysztof Parzyszekdb867702015-10-19 17:46:01 +0000392
393 // Add CFI instructions if necessary.
394 addPass(createHexagonCallFrameInformation(), false);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000395}