blob: ce45c626f7998d173d595a455c1c317d16f720f8 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
Tony Linthicumb4b54152011-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 Liu31d157a2012-02-18 12:03:15 +000010// Implements the info about Hexagon target spec.
Tony Linthicumb4b54152011-12-12 21:14:40 +000011//
12//===----------------------------------------------------------------------===//
13
Tony Linthicumb4b54152011-12-12 21:14:40 +000014#include "HexagonTargetMachine.h"
15#include "Hexagon.h"
16#include "HexagonISelLowering.h"
Sergei Larin3e590402012-09-04 14:49:56 +000017#include "HexagonMachineScheduler.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000018#include "llvm/CodeGen/Passes.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000019#include "llvm/IR/Module.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000020#include "llvm/PassManager.h"
Benjamin Kramerf3fd7ee2012-02-06 10:19:29 +000021#include "llvm/Support/CommandLine.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000022#include "llvm/Support/TargetRegistry.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000023#include "llvm/Transforms/IPO/PassManagerBuilder.h"
24#include "llvm/Transforms/Scalar.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000025
Tony Linthicumb4b54152011-12-12 21:14:40 +000026using namespace llvm;
27
28static cl::
29opt<bool> DisableHardwareLoops(
30 "disable-hexagon-hwloops", cl::Hidden,
31 cl::desc("Disable Hardware Loops for Hexagon target"));
32
Sergei Larin3e590402012-09-04 14:49:56 +000033static cl::
34opt<bool> DisableHexagonMISched("disable-hexagon-misched",
35 cl::Hidden, cl::ZeroOrMore, cl::init(false),
36 cl::desc("Disable Hexagon MI Scheduling"));
37
Jyotsna Verma0f680702013-03-27 11:14:24 +000038static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
39 cl::Hidden, cl::ZeroOrMore, cl::init(false),
40 cl::desc("Disable Hexagon CFG Optimization"));
41
Tony Linthicumb4b54152011-12-12 21:14:40 +000042/// 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
46/// remove it.
47extern "C" int HexagonTargetMachineModule;
48int HexagonTargetMachineModule = 0;
49
50extern "C" void LLVMInitializeHexagonTarget() {
51 // Register the target.
52 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
Tony Linthicumb4b54152011-12-12 21:14:40 +000053}
54
Sergei Larin3e590402012-09-04 14:49:56 +000055static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
56 return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler());
57}
58
59static MachineSchedRegistry
60SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
61 createVLIWMachineSched);
Tony Linthicumb4b54152011-12-12 21:14:40 +000062
63/// HexagonTargetMachine ctor - Create an ILP32 architecture model.
64///
65
66/// Hexagon_TODO: Do I need an aggregate alignment?
67///
68HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
69 StringRef CPU, StringRef FS,
Craig Topper1e0c9ab2012-03-17 09:24:09 +000070 const TargetOptions &Options,
Tony Linthicumb4b54152011-12-12 21:14:40 +000071 Reloc::Model RM,
72 CodeModel::Model CM,
73 CodeGenOpt::Level OL)
74 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Micah Villmow3574eca2012-10-08 16:38:25 +000075 DL("e-p:32:32:32-"
Sirish Pande7517bbc2012-05-10 20:20:25 +000076 "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
77 "f64:64:64-f32:32:32-a0:0-n32") ,
Benjamin Kramer90345622011-12-16 19:08:59 +000078 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
Tony Linthicumb4b54152011-12-12 21:14:40 +000079 TSInfo(*this),
80 FrameLowering(Subtarget),
Chandler Carruthaeef83c2013-01-07 01:37:14 +000081 InstrItins(&Subtarget.getInstrItineraryData()) {
Jyotsna Verma0f680702013-03-27 11:14:24 +000082 setMCUseCFI(false);
Tony Linthicumb4b54152011-12-12 21:14:40 +000083}
84
85// addPassesForOptimizations - Allow the backend (target) to add Target
86// Independent Optimization passes to the Pass Manager.
87bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
Jyotsna Verma0f680702013-03-27 11:14:24 +000088 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());
95 }
Tony Linthicumb4b54152011-12-12 21:14:40 +000096 return true;
97}
98
Andrew Trick843ee2e2012-02-03 05:12:41 +000099namespace {
100/// Hexagon Code Generator Pass Configuration Options.
101class HexagonPassConfig : public TargetPassConfig {
102public:
Andrew Trick061efcf2012-02-04 02:56:59 +0000103 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
Sergei Larin3e590402012-09-04 14:49:56 +0000104 : TargetPassConfig(TM, PM) {
105 // Enable MI scheduler.
106 if (!DisableHexagonMISched) {
107 enablePass(&MachineSchedulerID);
108 MachineSchedRegistry::setDefault(createVLIWMachineSched);
109 }
110 }
Andrew Trick843ee2e2012-02-03 05:12:41 +0000111
112 HexagonTargetMachine &getHexagonTargetMachine() const {
113 return getTM<HexagonTargetMachine>();
114 }
115
116 virtual bool addInstSelector();
117 virtual bool addPreRegAlloc();
118 virtual bool addPostRegAlloc();
119 virtual bool addPreSched2();
120 virtual bool addPreEmitPass();
121};
122} // namespace
123
Andrew Trick061efcf2012-02-04 02:56:59 +0000124TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
125 return new HexagonPassConfig(this, PM);
Andrew Trick843ee2e2012-02-03 05:12:41 +0000126}
127
128bool HexagonPassConfig::addInstSelector() {
Jyotsna Verma0f680702013-03-27 11:14:24 +0000129
130 if (getOptLevel() != CodeGenOpt::None)
131 addPass(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
132
Jyotsna Vermaf6563422013-02-13 21:38:46 +0000133 addPass(createHexagonISelDag(getHexagonTargetMachine(), getOptLevel()));
Jyotsna Verma0f680702013-03-27 11:14:24 +0000134
135 if (getOptLevel() != CodeGenOpt::None)
136 addPass(createHexagonPeephole());
137
Tony Linthicumb4b54152011-12-12 21:14:40 +0000138 return false;
139}
140
141
Andrew Trick843ee2e2012-02-03 05:12:41 +0000142bool HexagonPassConfig::addPreRegAlloc() {
Jyotsna Verma0f680702013-03-27 11:14:24 +0000143 if (!DisableHardwareLoops && getOptLevel() != CodeGenOpt::None)
Bob Wilson564fbf62012-07-02 19:48:31 +0000144 addPass(createHexagonHardwareLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000145 return false;
146}
147
Andrew Trick843ee2e2012-02-03 05:12:41 +0000148bool HexagonPassConfig::addPostRegAlloc() {
Jyotsna Verma0f680702013-03-27 11:14:24 +0000149 if (!DisableHexagonCFGOpt && getOptLevel() != CodeGenOpt::None)
150 addPass(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000151 return true;
152}
153
154
Andrew Trick843ee2e2012-02-03 05:12:41 +0000155bool HexagonPassConfig::addPreSched2() {
Jyotsna Verma0f680702013-03-27 11:14:24 +0000156 if (getOptLevel() != CodeGenOpt::None)
157 addPass(&IfConverterID);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000158 return true;
159}
160
Andrew Trick843ee2e2012-02-03 05:12:41 +0000161bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000162
Jyotsna Verma0f680702013-03-27 11:14:24 +0000163 if (!DisableHardwareLoops && getOptLevel() != CodeGenOpt::None)
Bob Wilson564fbf62012-07-02 19:48:31 +0000164 addPass(createHexagonFixupHwLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000165
Jyotsna Verma0f680702013-03-27 11:14:24 +0000166 if (getOptLevel() != CodeGenOpt::None)
167 addPass(createHexagonNewValueJump());
Sirish Pandeb3385702012-05-12 05:10:30 +0000168
Tony Linthicumb4b54152011-12-12 21:14:40 +0000169 // Expand Spill code for predicate registers.
Bob Wilson564fbf62012-07-02 19:48:31 +0000170 addPass(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000171
172 // Split up TFRcondsets into conditional transfers.
Bob Wilson564fbf62012-07-02 19:48:31 +0000173 addPass(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000174
Sirish Pande26f61a12012-05-03 21:52:53 +0000175 // Create Packets.
Jyotsna Verma0f680702013-03-27 11:14:24 +0000176 if (getOptLevel() != CodeGenOpt::None)
177 addPass(createHexagonPacketizer());
Sirish Pande26f61a12012-05-03 21:52:53 +0000178
Tony Linthicumb4b54152011-12-12 21:14:40 +0000179 return false;
180}