blob: 1f7bdf052c115ae96dda54ef4932b71696263eb5 [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()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000104 return false;
105}
106
107
Andrew Trick843ee2e2012-02-03 05:12:41 +0000108bool HexagonPassConfig::addPreRegAlloc() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000109 if (!DisableHardwareLoops) {
110 PM.add(createHexagonHardwareLoops());
111 }
112
113 return false;
114}
115
Andrew Trick843ee2e2012-02-03 05:12:41 +0000116bool HexagonPassConfig::addPostRegAlloc() {
117 PM.add(createHexagonCFGOptimizer(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000118 return true;
119}
120
121
Andrew Trick843ee2e2012-02-03 05:12:41 +0000122bool HexagonPassConfig::addPreSched2() {
Andrew Trick1dd8c852012-02-08 21:23:13 +0000123 addPass(IfConverterID);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000124 return true;
125}
126
Andrew Trick843ee2e2012-02-03 05:12:41 +0000127bool HexagonPassConfig::addPreEmitPass() {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000128
129 if (!DisableHardwareLoops) {
130 PM.add(createHexagonFixupHwLoops());
131 }
132
133 // Expand Spill code for predicate registers.
Andrew Trick843ee2e2012-02-03 05:12:41 +0000134 PM.add(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000135
136 // Split up TFRcondsets into conditional transfers.
Andrew Trick843ee2e2012-02-03 05:12:41 +0000137 PM.add(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
Tony Linthicumb4b54152011-12-12 21:14:40 +0000138
139 return false;
140}