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