Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===// |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 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 | // |
Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 10 | // Implements the info about Hexagon target spec. |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 14 | #include "HexagonTargetMachine.h" |
| 15 | #include "Hexagon.h" |
| 16 | #include "HexagonISelLowering.h" |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 17 | #include "HexagonMachineScheduler.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/Passes.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Module.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 20 | #include "llvm/PassManager.h" |
Benjamin Kramer | f3fd7ee | 2012-02-06 10:19:29 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CommandLine.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 22 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
| 24 | #include "llvm/Transforms/Scalar.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
| 28 | static cl:: |
| 29 | opt<bool> DisableHardwareLoops( |
| 30 | "disable-hexagon-hwloops", cl::Hidden, |
| 31 | cl::desc("Disable Hardware Loops for Hexagon target")); |
| 32 | |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 33 | static cl:: |
| 34 | opt<bool> DisableHexagonMISched("disable-hexagon-misched", |
| 35 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 36 | cl::desc("Disable Hexagon MI Scheduling")); |
| 37 | |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 38 | static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt", |
| 39 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 40 | cl::desc("Disable Hexagon CFG Optimization")); |
| 41 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 42 | /// HexagonTargetMachineModule - Note that this is used on hosts that |
| 43 | /// cannot link in a library unless there are references into the |
| 44 | /// library. In particular, it seems that it is not possible to get |
| 45 | /// things to work on Win32 without this. Though it is unused, do not |
| 46 | /// remove it. |
| 47 | extern "C" int HexagonTargetMachineModule; |
| 48 | int HexagonTargetMachineModule = 0; |
| 49 | |
| 50 | extern "C" void LLVMInitializeHexagonTarget() { |
| 51 | // Register the target. |
| 52 | RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 55 | static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) { |
| 56 | return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler()); |
| 57 | } |
| 58 | |
| 59 | static MachineSchedRegistry |
| 60 | SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler", |
| 61 | createVLIWMachineSched); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 62 | |
| 63 | /// HexagonTargetMachine ctor - Create an ILP32 architecture model. |
| 64 | /// |
| 65 | |
| 66 | /// Hexagon_TODO: Do I need an aggregate alignment? |
| 67 | /// |
| 68 | HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT, |
| 69 | StringRef CPU, StringRef FS, |
Craig Topper | 1e0c9ab | 2012-03-17 09:24:09 +0000 | [diff] [blame] | 70 | const TargetOptions &Options, |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 71 | Reloc::Model RM, |
| 72 | CodeModel::Model CM, |
| 73 | CodeGenOpt::Level OL) |
| 74 | : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 75 | DL("e-p:32:32:32-" |
Sirish Pande | 7517bbc | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 76 | "i64:64:64-i32:32:32-i16:16:16-i1:32:32-" |
| 77 | "f64:64:64-f32:32:32-a0:0-n32") , |
Benjamin Kramer | 9034562 | 2011-12-16 19:08:59 +0000 | [diff] [blame] | 78 | Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this), |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 79 | TSInfo(*this), |
| 80 | FrameLowering(Subtarget), |
Chandler Carruth | aeef83c | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 81 | InstrItins(&Subtarget.getInstrItineraryData()) { |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 82 | setMCUseCFI(false); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // addPassesForOptimizations - Allow the backend (target) to add Target |
| 86 | // Independent Optimization passes to the Pass Manager. |
| 87 | bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) { |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 88 | if (getOptLevel() != CodeGenOpt::None) { |
| 89 | PM.add(createConstantPropagationPass()); |
| 90 | PM.add(createLoopSimplifyPass()); |
| 91 | PM.add(createDeadCodeEliminationPass()); |
| 92 | PM.add(createConstantPropagationPass()); |
| 93 | PM.add(createLoopUnrollPass()); |
| 94 | PM.add(createLoopStrengthReducePass()); |
| 95 | } |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 96 | return true; |
| 97 | } |
| 98 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 99 | namespace { |
| 100 | /// Hexagon Code Generator Pass Configuration Options. |
| 101 | class HexagonPassConfig : public TargetPassConfig { |
| 102 | public: |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 103 | HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM) |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 104 | : TargetPassConfig(TM, PM) { |
| 105 | // Enable MI scheduler. |
| 106 | if (!DisableHexagonMISched) { |
| 107 | enablePass(&MachineSchedulerID); |
| 108 | MachineSchedRegistry::setDefault(createVLIWMachineSched); |
| 109 | } |
| 110 | } |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 111 | |
| 112 | HexagonTargetMachine &getHexagonTargetMachine() const { |
| 113 | return getTM<HexagonTargetMachine>(); |
| 114 | } |
| 115 | |
| 116 | virtual bool addInstSelector(); |
| 117 | virtual bool addPreRegAlloc(); |
| 118 | virtual bool addPostRegAlloc(); |
| 119 | virtual bool addPreSched2(); |
| 120 | virtual bool addPreEmitPass(); |
| 121 | }; |
| 122 | } // namespace |
| 123 | |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 124 | TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 125 | return new HexagonPassConfig(this, PM); |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | bool HexagonPassConfig::addInstSelector() { |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 129 | |
| 130 | if (getOptLevel() != CodeGenOpt::None) |
Krzysztof Parzyszek | cc420a0 | 2013-05-04 01:30:49 +0000 | [diff] [blame] | 131 | addPass(createHexagonRemoveExtendArgs(getHexagonTargetMachine())); |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 132 | |
Jyotsna Verma | f656342 | 2013-02-13 21:38:46 +0000 | [diff] [blame] | 133 | addPass(createHexagonISelDag(getHexagonTargetMachine(), getOptLevel())); |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 134 | |
| 135 | if (getOptLevel() != CodeGenOpt::None) |
| 136 | addPass(createHexagonPeephole()); |
| 137 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | |
| 141 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 142 | bool HexagonPassConfig::addPreRegAlloc() { |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 143 | if (!DisableHardwareLoops && getOptLevel() != CodeGenOpt::None) |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 144 | addPass(createHexagonHardwareLoops()); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 145 | return false; |
| 146 | } |
| 147 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 148 | bool HexagonPassConfig::addPostRegAlloc() { |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 149 | if (!DisableHexagonCFGOpt && getOptLevel() != CodeGenOpt::None) |
| 150 | addPass(createHexagonCFGOptimizer(getHexagonTargetMachine())); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 151 | return true; |
| 152 | } |
| 153 | |
| 154 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 155 | bool HexagonPassConfig::addPreSched2() { |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 156 | if (getOptLevel() != CodeGenOpt::None) |
| 157 | addPass(&IfConverterID); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 161 | bool HexagonPassConfig::addPreEmitPass() { |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 162 | |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 163 | if (!DisableHardwareLoops && getOptLevel() != CodeGenOpt::None) |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 164 | addPass(createHexagonFixupHwLoops()); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 165 | |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 166 | if (getOptLevel() != CodeGenOpt::None) |
| 167 | addPass(createHexagonNewValueJump()); |
Sirish Pande | b338570 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 168 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 169 | // Expand Spill code for predicate registers. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 170 | addPass(createHexagonExpandPredSpillCode(getHexagonTargetMachine())); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 171 | |
| 172 | // Split up TFRcondsets into conditional transfers. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 173 | addPass(createHexagonSplitTFRCondSets(getHexagonTargetMachine())); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 174 | |
Sirish Pande | 26f61a1 | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 175 | // Create Packets. |
Jyotsna Verma | 0f68070 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 176 | if (getOptLevel() != CodeGenOpt::None) |
| 177 | addPass(createHexagonPacketizer()); |
Sirish Pande | 26f61a1 | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 178 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 179 | return false; |
| 180 | } |