blob: a39bf69646a4e45c99530c20229693d720317197 [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
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),
Micah Villmow3574eca2012-10-08 16:38:25 +000071 DL("e-p:32:32:32-"
Sirish Pande7517bbc2012-05-10 20:20:25 +000072 "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),
Nadav Rotemcbd9a192012-10-18 23:22:48 +000077 InstrItins(&Subtarget.getInstrItineraryData()),
Nadav Rotem27048342012-10-24 17:22:41 +000078 STTI(&TLInfo), VTTI(&TLInfo) {
Tony Linthicumb4b54152011-12-12 21:14:40 +000079 setMCUseCFI(false);
80}
81
82// addPassesForOptimizations - Allow the backend (target) to add Target
83// Independent Optimization passes to the Pass Manager.
84bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
85
86 PM.add(createConstantPropagationPass());
87 PM.add(createLoopSimplifyPass());
88 PM.add(createDeadCodeEliminationPass());
89 PM.add(createConstantPropagationPass());
90 PM.add(createLoopUnrollPass());
Nadav Rotemcbd9a192012-10-18 23:22:48 +000091 PM.add(createLoopStrengthReducePass());
Tony Linthicumb4b54152011-12-12 21:14:40 +000092 return true;
93}
94
Andrew Trick843ee2e2012-02-03 05:12:41 +000095namespace {
96/// Hexagon Code Generator Pass Configuration Options.
97class HexagonPassConfig : public TargetPassConfig {
98public:
Andrew Trick061efcf2012-02-04 02:56:59 +000099 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
Sergei Larin3e590402012-09-04 14:49:56 +0000100 : TargetPassConfig(TM, PM) {
101 // Enable MI scheduler.
102 if (!DisableHexagonMISched) {
103 enablePass(&MachineSchedulerID);
104 MachineSchedRegistry::setDefault(createVLIWMachineSched);
105 }
106 }
Andrew Trick843ee2e2012-02-03 05:12:41 +0000107
108 HexagonTargetMachine &getHexagonTargetMachine() const {
109 return getTM<HexagonTargetMachine>();
110 }
111
112 virtual bool addInstSelector();
113 virtual bool addPreRegAlloc();
114 virtual bool addPostRegAlloc();
115 virtual bool addPreSched2();
116 virtual bool addPreEmitPass();
117};
118} // namespace
119
Andrew Trick061efcf2012-02-04 02:56:59 +0000120TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
121 return new HexagonPassConfig(this, PM);
Andrew Trick843ee2e2012-02-03 05:12:41 +0000122}
123
124bool HexagonPassConfig::addInstSelector() {
Bob Wilson564fbf62012-07-02 19:48:31 +0000125 addPass(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
126 addPass(createHexagonISelDag(getHexagonTargetMachine()));
127 addPass(createHexagonPeephole());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000128 return false;
129}
130
131
Andrew Trick843ee2e2012-02-03 05:12:41 +0000132bool HexagonPassConfig::addPreRegAlloc() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000133 if (!DisableHardwareLoops) {
Bob Wilson564fbf62012-07-02 19:48:31 +0000134 addPass(createHexagonHardwareLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000135 }
Tony Linthicumb4b54152011-12-12 21:14:40 +0000136 return false;
137}
138
Andrew Trick843ee2e2012-02-03 05:12:41 +0000139bool HexagonPassConfig::addPostRegAlloc() {
Bob Wilson564fbf62012-07-02 19:48:31 +0000140 addPass(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000141 return true;
142}
143
144
Andrew Trick843ee2e2012-02-03 05:12:41 +0000145bool HexagonPassConfig::addPreSched2() {
Bob Wilson3fb99a72012-07-02 19:48:37 +0000146 addPass(&IfConverterID);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000147 return true;
148}
149
Andrew Trick843ee2e2012-02-03 05:12:41 +0000150bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000151
152 if (!DisableHardwareLoops) {
Bob Wilson564fbf62012-07-02 19:48:31 +0000153 addPass(createHexagonFixupHwLoops());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000154 }
155
Bob Wilson564fbf62012-07-02 19:48:31 +0000156 addPass(createHexagonNewValueJump());
Sirish Pandeb3385702012-05-12 05:10:30 +0000157
Tony Linthicumb4b54152011-12-12 21:14:40 +0000158 // Expand Spill code for predicate registers.
Bob Wilson564fbf62012-07-02 19:48:31 +0000159 addPass(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000160
161 // Split up TFRcondsets into conditional transfers.
Bob Wilson564fbf62012-07-02 19:48:31 +0000162 addPass(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000163
Sirish Pande26f61a12012-05-03 21:52:53 +0000164 // Create Packets.
Bob Wilson564fbf62012-07-02 19:48:31 +0000165 addPass(createHexagonPacketizer());
Sirish Pande26f61a12012-05-03 21:52:53 +0000166
Tony Linthicumb4b54152011-12-12 21:14:40 +0000167 return false;
168}