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, new 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),
75 "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
76 "f64:64:64-f32:32:32-a0:0-n32") ,
77 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
79 FrameLowering(Subtarget),
80 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() {
129 HexagonTargetMachine &TM = getHexagonTargetMachine();
130 bool NoOpt = (getOptLevel() == CodeGenOpt::None);
133 addPass(createHexagonRemoveExtendArgs(TM));
135 addPass(createHexagonISelDag(TM, getOptLevel()));
138 addPass(createHexagonPeephole());
139 printAndVerify("After hexagon peephole pass");
145 bool HexagonPassConfig::addPreRegAlloc() {
146 if (getOptLevel() != CodeGenOpt::None)
147 if (!DisableHardwareLoops)
148 addPass(createHexagonHardwareLoops());
152 bool HexagonPassConfig::addPostRegAlloc() {
153 const HexagonTargetMachine &TM = getHexagonTargetMachine();
154 if (getOptLevel() != CodeGenOpt::None)
155 if (!DisableHexagonCFGOpt)
156 addPass(createHexagonCFGOptimizer(TM));
160 bool HexagonPassConfig::addPreSched2() {
161 const HexagonTargetMachine &TM = getHexagonTargetMachine();
162 const HexagonTargetObjectFile &TLOF =
163 (const HexagonTargetObjectFile &)getTargetLowering()->getObjFileLowering();
165 addPass(createHexagonCopyToCombine());
166 if (getOptLevel() != CodeGenOpt::None)
167 addPass(&IfConverterID);
168 if (!TLOF.IsSmallDataEnabled()) {
169 addPass(createHexagonSplitConst32AndConst64(TM));
170 printAndVerify("After hexagon split const32/64 pass");
175 bool HexagonPassConfig::addPreEmitPass() {
176 const HexagonTargetMachine &TM = getHexagonTargetMachine();
177 bool NoOpt = (getOptLevel() == CodeGenOpt::None);
180 addPass(createHexagonNewValueJump());
182 // Expand Spill code for predicate registers.
183 addPass(createHexagonExpandPredSpillCode(TM));
185 // Split up TFRcondsets into conditional transfers.
186 addPass(createHexagonSplitTFRCondSets(TM));
190 if (!DisableHardwareLoops)
191 addPass(createHexagonFixupHwLoops());
192 addPass(createHexagonPacketizer());