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 "llvm/CodeGen/Passes.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/PassManager.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/TargetRegistry.h"
23 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
24 #include "llvm/Transforms/Scalar.h"
29 opt<bool> DisableHardwareLoops(
30 "disable-hexagon-hwloops", cl::Hidden,
31 cl::desc("Disable Hardware Loops for Hexagon target"));
34 opt<bool> DisableHexagonMISched("disable-hexagon-misched",
35 cl::Hidden, cl::ZeroOrMore, cl::init(false),
36 cl::desc("Disable Hexagon MI Scheduling"));
38 static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
39 cl::Hidden, cl::ZeroOrMore, cl::init(false),
40 cl::desc("Disable Hexagon CFG Optimization"));
42 /// HexagonTargetMachineModule - Note that this is used on hosts that
43 /// cannot link in a library unless there are references into the
44 /// library. In particular, it seems that it is not possible to get
45 /// things to work on Win32 without this. Though it is unused, do not
47 extern "C" int HexagonTargetMachineModule;
48 int HexagonTargetMachineModule = 0;
50 extern "C" void LLVMInitializeHexagonTarget() {
51 // Register the target.
52 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
55 static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
56 return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler());
59 static MachineSchedRegistry
60 SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
61 createVLIWMachineSched);
63 /// HexagonTargetMachine ctor - Create an ILP32 architecture model.
66 /// Hexagon_TODO: Do I need an aggregate alignment?
68 HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
69 StringRef CPU, StringRef FS,
70 const TargetOptions &Options,
74 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
76 "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
77 "f64:64:64-f32:32:32-a0:0-n32") ,
78 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
80 FrameLowering(Subtarget),
81 InstrItins(&Subtarget.getInstrItineraryData()) {
85 // addPassesForOptimizations - Allow the backend (target) to add Target
86 // Independent Optimization passes to the Pass Manager.
87 bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
88 if (getOptLevel() != CodeGenOpt::None) {
89 PM.add(createConstantPropagationPass());
90 PM.add(createLoopSimplifyPass());
91 PM.add(createDeadCodeEliminationPass());
92 PM.add(createConstantPropagationPass());
93 PM.add(createLoopUnrollPass());
94 PM.add(createLoopStrengthReducePass());
100 /// Hexagon Code Generator Pass Configuration Options.
101 class HexagonPassConfig : public TargetPassConfig {
103 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
104 : TargetPassConfig(TM, PM) {
105 // Enable MI scheduler.
106 if (!DisableHexagonMISched) {
107 enablePass(&MachineSchedulerID);
108 MachineSchedRegistry::setDefault(createVLIWMachineSched);
112 HexagonTargetMachine &getHexagonTargetMachine() const {
113 return getTM<HexagonTargetMachine>();
116 virtual bool addInstSelector();
117 virtual bool addPreRegAlloc();
118 virtual bool addPostRegAlloc();
119 virtual bool addPreSched2();
120 virtual bool addPreEmitPass();
124 TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
125 return new HexagonPassConfig(this, PM);
128 bool HexagonPassConfig::addInstSelector() {
130 if (getOptLevel() != CodeGenOpt::None)
131 addPass(createHexagonRemoveExtendArgs(getHexagonTargetMachine()));
133 addPass(createHexagonISelDag(getHexagonTargetMachine(), getOptLevel()));
135 if (getOptLevel() != CodeGenOpt::None)
136 addPass(createHexagonPeephole());
142 bool HexagonPassConfig::addPreRegAlloc() {
143 if (!DisableHardwareLoops && getOptLevel() != CodeGenOpt::None)
144 addPass(createHexagonHardwareLoops());
148 bool HexagonPassConfig::addPostRegAlloc() {
149 if (!DisableHexagonCFGOpt && getOptLevel() != CodeGenOpt::None)
150 addPass(createHexagonCFGOptimizer(getHexagonTargetMachine()));
155 bool HexagonPassConfig::addPreSched2() {
156 if (getOptLevel() != CodeGenOpt::None)
157 addPass(&IfConverterID);
161 bool HexagonPassConfig::addPreEmitPass() {
163 if (!DisableHardwareLoops && getOptLevel() != CodeGenOpt::None)
164 addPass(createHexagonFixupHwLoops());
166 if (getOptLevel() != CodeGenOpt::None)
167 addPass(createHexagonNewValueJump());
169 // Expand Spill code for predicate registers.
170 addPass(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
172 // Split up TFRcondsets into conditional transfers.
173 addPass(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
176 if (getOptLevel() != CodeGenOpt::None)
177 addPass(createHexagonPacketizer());