Codegen pass definition cleanup. No functionality.
[oota-llvm.git] / lib / Target / Hexagon / HexagonTargetMachine.cpp
1 //===- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon --------===//
2 //
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
13 #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"
19 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
20 #include "llvm/Transforms/Scalar.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/TargetRegistry.h"
23
24 using namespace llvm;
25
26 static cl::
27 opt<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.
36 extern "C" int HexagonTargetMachineModule;
37 int HexagonTargetMachineModule = 0;
38
39 extern "C" void LLVMInitializeHexagonTarget() {
40   // Register the target.
41   RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
42 }
43
44
45 /// HexagonTargetMachine ctor - Create an ILP32 architecture model.
46 ///
47
48 /// Hexagon_TODO: Do I need an aggregate alignment?
49 ///
50 HexagonTargetMachine::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") ,
58     Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
59     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.
67 bool 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
78 namespace {
79 /// Hexagon Code Generator Pass Configuration Options.
80 class HexagonPassConfig : public TargetPassConfig {
81 public:
82   HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
83     : TargetPassConfig(TM, PM) {}
84
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
97 TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
98   return new HexagonPassConfig(this, PM);
99 }
100
101 bool HexagonPassConfig::addInstSelector() {
102   PM.add(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
103   PM.add(createHexagonISelDag(getHexagonTargetMachine()));
104   return false;
105 }
106
107
108 bool HexagonPassConfig::addPreRegAlloc() {
109   if (!DisableHardwareLoops) {
110     PM.add(createHexagonHardwareLoops());
111   }
112
113   return false;
114 }
115
116 bool HexagonPassConfig::addPostRegAlloc() {
117   PM.add(createHexagonCFGOptimizer(getHexagonTargetMachine()));
118   return true;
119 }
120
121
122 bool HexagonPassConfig::addPreSched2() {
123   addPass(IfConverterID);
124   return true;
125 }
126
127 bool HexagonPassConfig::addPreEmitPass() {
128
129   if (!DisableHardwareLoops) {
130     PM.add(createHexagonFixupHwLoops());
131   }
132
133   // Expand Spill code for predicate registers.
134   PM.add(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
135
136   // Split up TFRcondsets into conditional transfers.
137   PM.add(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
138
139   return false;
140 }