blob: 5688e9cbec30744aa51adac2ef6f8fd57479b73d [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/Module.h"
19#include "llvm/CodeGen/Passes.h"
20#include "llvm/PassManager.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000021#include "llvm/Transforms/IPO/PassManagerBuilder.h"
22#include "llvm/Transforms/Scalar.h"
Benjamin Kramerf3fd7ee2012-02-06 10:19:29 +000023#include "llvm/Support/CommandLine.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000024#include "llvm/Support/TargetRegistry.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
Tony Linthicumb4b54152011-12-12 21:14:40 +000038/// HexagonTargetMachineModule - Note that this is used on hosts that
39/// cannot link in a library unless there are references into the
40/// library. In particular, it seems that it is not possible to get
41/// things to work on Win32 without this. Though it is unused, do not
42/// remove it.
43extern "C" int HexagonTargetMachineModule;
44int HexagonTargetMachineModule = 0;
45
46extern "C" void LLVMInitializeHexagonTarget() {
47 // Register the target.
48 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
Tony Linthicumb4b54152011-12-12 21:14:40 +000049}
50
Sergei Larin3e590402012-09-04 14:49:56 +000051static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
52 return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler());
53}
54
55static MachineSchedRegistry
56SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
57 createVLIWMachineSched);
Tony Linthicumb4b54152011-12-12 21:14:40 +000058
59/// HexagonTargetMachine ctor - Create an ILP32 architecture model.
60///
61
62/// Hexagon_TODO: Do I need an aggregate alignment?
63///
64HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
65 StringRef CPU, StringRef FS,
Craig Topper1e0c9ab2012-03-17 09:24:09 +000066 const TargetOptions &Options,
Tony Linthicumb4b54152011-12-12 21:14:40 +000067 Reloc::Model RM,
68 CodeModel::Model CM,
69 CodeGenOpt::Level OL)
70 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Sirish Pande7517bbc2012-05-10 20:20:25 +000071 DataLayout("e-p:32:32:32-"
72 "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
73 "f64:64:64-f32:32:32-a0:0-n32") ,
Benjamin Kramer90345622011-12-16 19:08:59 +000074 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
Tony Linthicumb4b54152011-12-12 21:14:40 +000075 TSInfo(*this),
76 FrameLowering(Subtarget),
77 InstrItins(&Subtarget.getInstrItineraryData()) {
78 setMCUseCFI(false);
79}
80
81// addPassesForOptimizations - Allow the backend (target) to add Target
82// Independent Optimization passes to the Pass Manager.
83bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
84
85 PM.add(createConstantPropagationPass());
86 PM.add(createLoopSimplifyPass());
87 PM.add(createDeadCodeEliminationPass());
88 PM.add(createConstantPropagationPass());
89 PM.add(createLoopUnrollPass());
90 PM.add(createLoopStrengthReducePass(getTargetLowering()));
91 return true;
92}
93
Andrew Trick843ee2e2012-02-03 05:12:41 +000094namespace {
95/// Hexagon Code Generator Pass Configuration Options.
96class HexagonPassConfig : public TargetPassConfig {
97public:
Andrew Trick061efcf2012-02-04 02:56:59 +000098 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
Sergei Larin3e590402012-09-04 14:49:56 +000099 : TargetPassConfig(TM, PM) {
100 // Enable MI scheduler.
101 if (!DisableHexagonMISched) {
102 enablePass(&MachineSchedulerID);
103 MachineSchedRegistry::setDefault(createVLIWMachineSched);
104 }
105 }
Andrew Trick843ee2e2012-02-03 05:12:41 +0000106
107 HexagonTargetMachine &getHexagonTargetMachine() const {
108 return getTM<HexagonTargetMachine>();
109 }
110
111 virtual bool addInstSelector();
112 virtual bool addPreRegAlloc();
113 virtual bool addPostRegAlloc();
114 virtual bool addPreSched2();
115 virtual bool addPreEmitPass();
116};
117} // namespace
118
Andrew Trick061efcf2012-02-04 02:56:59 +0000119TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
120 return new HexagonPassConfig(this, PM);
Andrew Trick843ee2e2012-02-03 05:12:41 +0000121}
122
123bool HexagonPassConfig::addInstSelector() {
Bob Wilson564fbf62012-07-02 19:48:31 +0000124 addPass(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
125 addPass(createHexagonISelDag(getHexagonTargetMachine()));
126 addPass(createHexagonPeephole());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000127 return false;
128}
129
130
Andrew Trick843ee2e2012-02-03 05:12:41 +0000131bool HexagonPassConfig::addPreRegAlloc() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000132 if (!DisableHardwareLoops) {
Bob Wilson564fbf62012-07-02 19:48:31 +0000133 addPass(createHexagonHardwareLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000134 }
Tony Linthicumb4b54152011-12-12 21:14:40 +0000135 return false;
136}
137
Andrew Trick843ee2e2012-02-03 05:12:41 +0000138bool HexagonPassConfig::addPostRegAlloc() {
Bob Wilson564fbf62012-07-02 19:48:31 +0000139 addPass(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000140 return true;
141}
142
143
Andrew Trick843ee2e2012-02-03 05:12:41 +0000144bool HexagonPassConfig::addPreSched2() {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000145 addPass(&IfConverterID);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000146 return true;
147}
148
Andrew Trick843ee2e2012-02-03 05:12:41 +0000149bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000150
151 if (!DisableHardwareLoops) {
Bob Wilson564fbf62012-07-02 19:48:31 +0000152 addPass(createHexagonFixupHwLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000153 }
154
Bob Wilson564fbf62012-07-02 19:48:31 +0000155 addPass(createHexagonNewValueJump());
Sirish Pandeb3385702012-05-12 05:10:30 +0000156
Tony Linthicumb4b54152011-12-12 21:14:40 +0000157 // Expand Spill code for predicate registers.
Bob Wilson564fbf62012-07-02 19:48:31 +0000158 addPass(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000159
160 // Split up TFRcondsets into conditional transfers.
Bob Wilson564fbf62012-07-02 19:48:31 +0000161 addPass(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000162
Sirish Pande26f61a12012-05-03 21:52:53 +0000163 // Create Packets.
Bob Wilson564fbf62012-07-02 19:48:31 +0000164 addPass(createHexagonPacketizer());
Sirish Pande26f61a12012-05-03 21:52:53 +0000165
Tony Linthicumb4b54152011-12-12 21:14:40 +0000166 return false;
167}