1 //===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implements the info about Hexagon target spec.
12 //===----------------------------------------------------------------------===//
14 #include "HexagonTargetMachine.h"
16 #include "HexagonISelLowering.h"
17 #include "HexagonMachineScheduler.h"
18 #include "HexagonTargetObjectFile.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/PassManager.h"
22 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/TargetRegistry.h"
24 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
25 #include "llvm/Transforms/Scalar.h"
29 static cl:: opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
30 cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));
32 static cl::opt<bool> DisableHexagonMISched("disable-hexagon-misched",
33 cl::Hidden, cl::ZeroOrMore, cl::init(false),
34 cl::desc("Disable Hexagon MI Scheduling"));
36 static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
37 cl::Hidden, cl::ZeroOrMore, cl::init(false),
38 cl::desc("Disable Hexagon CFG Optimization"));
41 /// HexagonTargetMachineModule - Note that this is used on hosts that
42 /// cannot link in a library unless there are references into the
43 /// library. In particular, it seems that it is not possible to get
44 /// things to work on Win32 without this. Though it is unused, do not
46 extern "C" int HexagonTargetMachineModule;
47 int HexagonTargetMachineModule = 0;
49 extern "C" void LLVMInitializeHexagonTarget() {
50 // Register the target.
51 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
54 static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
55 return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>());
58 static MachineSchedRegistry
59 SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
60 createVLIWMachineSched);
62 /// HexagonTargetMachine ctor - Create an ILP32 architecture model.
65 /// Hexagon_TODO: Do I need an aggregate alignment?
67 HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
68 StringRef CPU, StringRef FS,
69 const TargetOptions &Options,
73 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
74 DL("e-m:e-p:32:32-i1:32-i64:64-a:0-n32") ,
75 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
77 FrameLowering(Subtarget),
78 InstrItins(&Subtarget.getInstrItineraryData()) {
83 /// Hexagon Code Generator Pass Configuration Options.
84 class HexagonPassConfig : public TargetPassConfig {
86 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
87 : TargetPassConfig(TM, PM) {
88 // FIXME: Rather than calling enablePass(&MachineSchedulerID) below, define
89 // HexagonSubtarget::enableMachineScheduler() { return true; }.
90 // That will bypass the SelectionDAG VLIW scheduler, which is probably just
91 // hurting compile time and will be removed eventually anyway.
92 if (DisableHexagonMISched)
93 disablePass(&MachineSchedulerID);
95 enablePass(&MachineSchedulerID);
98 HexagonTargetMachine &getHexagonTargetMachine() const {
99 return getTM<HexagonTargetMachine>();
103 createMachineScheduler(MachineSchedContext *C) const override {
104 return createVLIWMachineSched(C);
107 bool addInstSelector() override;
108 bool addPreRegAlloc() override;
109 bool addPostRegAlloc() override;
110 bool addPreSched2() override;
111 bool addPreEmitPass() override;
115 TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
116 return new HexagonPassConfig(this, PM);
119 bool HexagonPassConfig::addInstSelector() {
120 HexagonTargetMachine &TM = getHexagonTargetMachine();
121 bool NoOpt = (getOptLevel() == CodeGenOpt::None);
124 addPass(createHexagonRemoveExtendArgs(TM));
126 addPass(createHexagonISelDag(TM, getOptLevel()));
129 addPass(createHexagonPeephole());
130 printAndVerify("After hexagon peephole pass");
136 bool HexagonPassConfig::addPreRegAlloc() {
137 if (getOptLevel() != CodeGenOpt::None)
138 if (!DisableHardwareLoops)
139 addPass(createHexagonHardwareLoops());
143 bool HexagonPassConfig::addPostRegAlloc() {
144 const HexagonTargetMachine &TM = getHexagonTargetMachine();
145 if (getOptLevel() != CodeGenOpt::None)
146 if (!DisableHexagonCFGOpt)
147 addPass(createHexagonCFGOptimizer(TM));
151 bool HexagonPassConfig::addPreSched2() {
152 const HexagonTargetMachine &TM = getHexagonTargetMachine();
154 addPass(createHexagonCopyToCombine());
155 if (getOptLevel() != CodeGenOpt::None)
156 addPass(&IfConverterID);
157 addPass(createHexagonSplitConst32AndConst64(TM));
158 printAndVerify("After hexagon split const32/64 pass");
162 bool HexagonPassConfig::addPreEmitPass() {
163 const HexagonTargetMachine &TM = getHexagonTargetMachine();
164 bool NoOpt = (getOptLevel() == CodeGenOpt::None);
167 addPass(createHexagonNewValueJump());
169 // Expand Spill code for predicate registers.
170 addPass(createHexagonExpandPredSpillCode(TM));
172 // Split up TFRcondsets into conditional transfers.
173 addPass(createHexagonSplitTFRCondSets(TM));
177 if (!DisableHardwareLoops)
178 addPass(createHexagonFixupHwLoops());
179 addPass(createHexagonPacketizer());