Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===// |
Tony Linthicum | 1213a7a | 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 | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 10 | // Implements the info about Hexagon target spec. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 14 | #include "HexagonTargetMachine.h" |
| 15 | #include "Hexagon.h" |
| 16 | #include "HexagonISelLowering.h" |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 17 | #include "HexagonMachineScheduler.h" |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 18 | #include "HexagonTargetObjectFile.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/Passes.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Module.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 21 | #include "llvm/PassManager.h" |
Benjamin Kramer | ae87d7b | 2012-02-06 10:19:29 +0000 | [diff] [blame] | 22 | #include "llvm/Support/CommandLine.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 23 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
| 25 | #include "llvm/Transforms/Scalar.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 26 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 29 | static cl:: opt<bool> DisableHardwareLoops("disable-hexagon-hwloops", |
| 30 | cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target")); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 31 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 32 | static cl::opt<bool> DisableHexagonMISched("disable-hexagon-misched", |
| 33 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 34 | cl::desc("Disable Hexagon MI Scheduling")); |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 35 | |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 36 | static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt", |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 37 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 38 | cl::desc("Disable Hexagon CFG Optimization")); |
| 39 | |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 40 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 41 | /// HexagonTargetMachineModule - Note that this is used on hosts that |
| 42 | /// cannot link in a library unless there are references into the |
| 43 | /// library. In particular, it seems that it is not possible to get |
| 44 | /// things to work on Win32 without this. Though it is unused, do not |
| 45 | /// remove it. |
| 46 | extern "C" int HexagonTargetMachineModule; |
| 47 | int HexagonTargetMachineModule = 0; |
| 48 | |
| 49 | extern "C" void LLVMInitializeHexagonTarget() { |
| 50 | // Register the target. |
| 51 | RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 54 | static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) { |
David Blaikie | 422b93d | 2014-04-21 20:32:32 +0000 | [diff] [blame] | 55 | return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>()); |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static MachineSchedRegistry |
| 59 | SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler", |
| 60 | createVLIWMachineSched); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 61 | |
| 62 | /// HexagonTargetMachine ctor - Create an ILP32 architecture model. |
| 63 | /// |
| 64 | |
| 65 | /// Hexagon_TODO: Do I need an aggregate alignment? |
| 66 | /// |
| 67 | HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT, |
| 68 | StringRef CPU, StringRef FS, |
Craig Topper | b545408 | 2012-03-17 09:24:09 +0000 | [diff] [blame] | 69 | const TargetOptions &Options, |
Eric Christopher | 0d0b360 | 2014-06-27 00:13:43 +0000 | [diff] [blame] | 70 | Reloc::Model RM, CodeModel::Model CM, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 71 | CodeGenOpt::Level OL) |
Eric Christopher | 0d0b360 | 2014-06-27 00:13:43 +0000 | [diff] [blame] | 72 | : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 73 | TLOF(make_unique<HexagonTargetObjectFile>()), |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame^] | 74 | DL("e-m:e-p:32:32-i1:32-i64:64-a:0-n32"), Subtarget(TT, CPU, FS, *this) { |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 75 | initAsmInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Reid Kleckner | 357600e | 2014-11-20 23:37:18 +0000 | [diff] [blame] | 78 | HexagonTargetMachine::~HexagonTargetMachine() {} |
| 79 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 80 | namespace { |
| 81 | /// Hexagon Code Generator Pass Configuration Options. |
| 82 | class HexagonPassConfig : public TargetPassConfig { |
| 83 | public: |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 84 | HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM) |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 85 | : TargetPassConfig(TM, PM) { |
Andrew Trick | 978674b | 2013-09-20 05:14:41 +0000 | [diff] [blame] | 86 | // FIXME: Rather than calling enablePass(&MachineSchedulerID) below, define |
| 87 | // HexagonSubtarget::enableMachineScheduler() { return true; }. |
| 88 | // That will bypass the SelectionDAG VLIW scheduler, which is probably just |
| 89 | // hurting compile time and will be removed eventually anyway. |
| 90 | if (DisableHexagonMISched) |
| 91 | disablePass(&MachineSchedulerID); |
| 92 | else |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 93 | enablePass(&MachineSchedulerID); |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 94 | } |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 95 | |
| 96 | HexagonTargetMachine &getHexagonTargetMachine() const { |
| 97 | return getTM<HexagonTargetMachine>(); |
| 98 | } |
| 99 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 100 | ScheduleDAGInstrs * |
| 101 | createMachineScheduler(MachineSchedContext *C) const override { |
Andrew Trick | 978674b | 2013-09-20 05:14:41 +0000 | [diff] [blame] | 102 | return createVLIWMachineSched(C); |
| 103 | } |
| 104 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 105 | bool addInstSelector() override; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 106 | void addPreRegAlloc() override; |
| 107 | void addPostRegAlloc() override; |
| 108 | void addPreSched2() override; |
| 109 | void addPreEmitPass() override; |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 110 | }; |
| 111 | } // namespace |
| 112 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 113 | TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 114 | return new HexagonPassConfig(this, PM); |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | bool HexagonPassConfig::addInstSelector() { |
Bill Wendling | a3cd350 | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 118 | HexagonTargetMachine &TM = getHexagonTargetMachine(); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 119 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 120 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 121 | if (!NoOpt) |
| 122 | addPass(createHexagonRemoveExtendArgs(TM)); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 123 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 124 | addPass(createHexagonISelDag(TM, getOptLevel())); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 125 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 126 | if (!NoOpt) { |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 127 | addPass(createHexagonPeephole()); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 128 | printAndVerify("After hexagon peephole pass"); |
| 129 | } |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 130 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 131 | return false; |
| 132 | } |
| 133 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 134 | void HexagonPassConfig::addPreRegAlloc() { |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 135 | if (getOptLevel() != CodeGenOpt::None) |
| 136 | if (!DisableHardwareLoops) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 137 | addPass(createHexagonHardwareLoops(), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 140 | void HexagonPassConfig::addPostRegAlloc() { |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 141 | const HexagonTargetMachine &TM = getHexagonTargetMachine(); |
| 142 | if (getOptLevel() != CodeGenOpt::None) |
| 143 | if (!DisableHexagonCFGOpt) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 144 | addPass(createHexagonCFGOptimizer(TM), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 147 | void HexagonPassConfig::addPreSched2() { |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 148 | const HexagonTargetMachine &TM = getHexagonTargetMachine(); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 149 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 150 | addPass(createHexagonCopyToCombine(), false); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 151 | if (getOptLevel() != CodeGenOpt::None) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 152 | addPass(&IfConverterID, false); |
Eric Christopher | 0120db5 | 2014-05-21 22:42:07 +0000 | [diff] [blame] | 153 | addPass(createHexagonSplitConst32AndConst64(TM)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 156 | void HexagonPassConfig::addPreEmitPass() { |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 157 | const HexagonTargetMachine &TM = getHexagonTargetMachine(); |
| 158 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 159 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 160 | if (!NoOpt) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 161 | addPass(createHexagonNewValueJump(), false); |
Sirish Pande | 4bd20c5 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 162 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 163 | // Expand Spill code for predicate registers. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 164 | addPass(createHexagonExpandPredSpillCode(TM), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 165 | |
| 166 | // Split up TFRcondsets into conditional transfers. |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 167 | addPass(createHexagonSplitTFRCondSets(TM), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 168 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 169 | // Create Packets. |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 170 | if (!NoOpt) { |
| 171 | if (!DisableHardwareLoops) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 172 | addPass(createHexagonFixupHwLoops(), false); |
| 173 | addPass(createHexagonPacketizer(), false); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 174 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 175 | } |