blob: 6c418854a484c3a38a75b833b45984edc9e204a3 [file] [log] [blame]
Benjamin Kramerf3fd7ee2012-02-06 10:19:29 +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//
10//
11//===----------------------------------------------------------------------===//
12
Tony Linthicumb4b54152011-12-12 21:14:40 +000013#include "HexagonTargetMachine.h"
14#include "Hexagon.h"
15#include "HexagonISelLowering.h"
16#include "llvm/Module.h"
17#include "llvm/CodeGen/Passes.h"
18#include "llvm/PassManager.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000019#include "llvm/Transforms/IPO/PassManagerBuilder.h"
20#include "llvm/Transforms/Scalar.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"
Tony Linthicumb4b54152011-12-12 21:14:40 +000023
Tony Linthicumb4b54152011-12-12 21:14:40 +000024using namespace llvm;
25
26static cl::
27opt<bool> DisableHardwareLoops(
28 "disable-hexagon-hwloops", cl::Hidden,
29 cl::desc("Disable Hardware Loops for Hexagon target"));
30
31/// HexagonTargetMachineModule - Note that this is used on hosts that
32/// cannot link in a library unless there are references into the
33/// library. In particular, it seems that it is not possible to get
34/// things to work on Win32 without this. Though it is unused, do not
35/// remove it.
36extern "C" int HexagonTargetMachineModule;
37int HexagonTargetMachineModule = 0;
38
39extern "C" void LLVMInitializeHexagonTarget() {
40 // Register the target.
41 RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
Tony Linthicumb4b54152011-12-12 21:14:40 +000042}
43
44
45/// HexagonTargetMachine ctor - Create an ILP32 architecture model.
46///
47
48/// Hexagon_TODO: Do I need an aggregate alignment?
49///
50HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
51 StringRef CPU, StringRef FS,
52 TargetOptions Options,
53 Reloc::Model RM,
54 CodeModel::Model CM,
55 CodeGenOpt::Level OL)
56 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
57 DataLayout("e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:32:32-a0:0") ,
Benjamin Kramer90345622011-12-16 19:08:59 +000058 Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
Tony Linthicumb4b54152011-12-12 21:14:40 +000059 TSInfo(*this),
60 FrameLowering(Subtarget),
61 InstrItins(&Subtarget.getInstrItineraryData()) {
62 setMCUseCFI(false);
63}
64
65// addPassesForOptimizations - Allow the backend (target) to add Target
66// Independent Optimization passes to the Pass Manager.
67bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
68
69 PM.add(createConstantPropagationPass());
70 PM.add(createLoopSimplifyPass());
71 PM.add(createDeadCodeEliminationPass());
72 PM.add(createConstantPropagationPass());
73 PM.add(createLoopUnrollPass());
74 PM.add(createLoopStrengthReducePass(getTargetLowering()));
75 return true;
76}
77
Andrew Trick843ee2e2012-02-03 05:12:41 +000078namespace {
79/// Hexagon Code Generator Pass Configuration Options.
80class HexagonPassConfig : public TargetPassConfig {
81public:
Andrew Trick061efcf2012-02-04 02:56:59 +000082 HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
83 : TargetPassConfig(TM, PM) {}
Andrew Trick843ee2e2012-02-03 05:12:41 +000084
85 HexagonTargetMachine &getHexagonTargetMachine() const {
86 return getTM<HexagonTargetMachine>();
87 }
88
89 virtual bool addInstSelector();
90 virtual bool addPreRegAlloc();
91 virtual bool addPostRegAlloc();
92 virtual bool addPreSched2();
93 virtual bool addPreEmitPass();
94};
95} // namespace
96
Andrew Trick061efcf2012-02-04 02:56:59 +000097TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
98 return new HexagonPassConfig(this, PM);
Andrew Trick843ee2e2012-02-03 05:12:41 +000099}
100
101bool HexagonPassConfig::addInstSelector() {
102 PM.add(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
103 PM.add(createHexagonISelDag(getHexagonTargetMachine()));
Sirish Pandeab7955b2012-02-15 18:52:27 +0000104 PM.add(createHexagonPeephole());
Tony Linthicumb4b54152011-12-12 21:14:40 +0000105 return false;
106}
107
108
Andrew Trick843ee2e2012-02-03 05:12:41 +0000109bool HexagonPassConfig::addPreRegAlloc() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000110 if (!DisableHardwareLoops) {
111 PM.add(createHexagonHardwareLoops());
112 }
113
114 return false;
115}
116
Andrew Trick843ee2e2012-02-03 05:12:41 +0000117bool HexagonPassConfig::addPostRegAlloc() {
118 PM.add(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000119 return true;
120}
121
122
Andrew Trick843ee2e2012-02-03 05:12:41 +0000123bool HexagonPassConfig::addPreSched2() {
Andrew Trick1dd8c852012-02-08 21:23:13 +0000124 addPass(IfConverterID);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000125 return true;
126}
127
Andrew Trick843ee2e2012-02-03 05:12:41 +0000128bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000129
130 if (!DisableHardwareLoops) {
131 PM.add(createHexagonFixupHwLoops());
132 }
133
134 // Expand Spill code for predicate registers.
Andrew Trick843ee2e2012-02-03 05:12:41 +0000135 PM.add(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000136
137 // Split up TFRcondsets into conditional transfers.
Andrew Trick843ee2e2012-02-03 05:12:41 +0000138 PM.add(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000139
140 return false;
141}