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 | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 20 | #include "llvm/IR/LegacyPassManager.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Module.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", |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 30 | cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target")); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 31 | |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 32 | static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt", |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 33 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 34 | cl::desc("Disable Hexagon CFG Optimization")); |
| 35 | |
| 36 | static cl::opt<bool> EnableExpandCondsets("hexagon-expand-condsets", |
| 37 | cl::init(true), cl::Hidden, cl::ZeroOrMore, |
| 38 | cl::desc("Early expansion of MUX")); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 39 | |
Krzysztof Parzyszek | 21b53a5 | 2015-07-08 14:47:34 +0000 | [diff] [blame] | 40 | static cl::opt<bool> EnableGenInsert("hexagon-insert", cl::init(true), |
| 41 | cl::Hidden, cl::desc("Generate \"insert\" instructions")); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 42 | |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 43 | static cl::opt<bool> EnableCommGEP("hexagon-commgep", cl::init(true), |
| 44 | cl::Hidden, cl::ZeroOrMore, cl::desc("Enable commoning of GEP instructions")); |
| 45 | |
| 46 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 47 | /// HexagonTargetMachineModule - Note that this is used on hosts that |
| 48 | /// cannot link in a library unless there are references into the |
| 49 | /// library. In particular, it seems that it is not possible to get |
| 50 | /// things to work on Win32 without this. Though it is unused, do not |
| 51 | /// remove it. |
| 52 | extern "C" int HexagonTargetMachineModule; |
| 53 | int HexagonTargetMachineModule = 0; |
| 54 | |
| 55 | extern "C" void LLVMInitializeHexagonTarget() { |
| 56 | // Register the target. |
| 57 | RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 60 | static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) { |
David Blaikie | 422b93d | 2014-04-21 20:32:32 +0000 | [diff] [blame] | 61 | return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>()); |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static MachineSchedRegistry |
| 65 | SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler", |
| 66 | createVLIWMachineSched); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 67 | |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 68 | namespace llvm { |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 69 | FunctionPass *createHexagonCommonGEP(); |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 70 | FunctionPass *createHexagonExpandCondsets(); |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 71 | FunctionPass *createHexagonISelDag(HexagonTargetMachine &TM, |
| 72 | CodeGenOpt::Level OptLevel); |
| 73 | FunctionPass *createHexagonDelaySlotFillerPass(const TargetMachine &TM); |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 74 | FunctionPass *createHexagonRemoveExtendArgs(const HexagonTargetMachine &TM); |
| 75 | FunctionPass *createHexagonCFGOptimizer(); |
| 76 | |
| 77 | FunctionPass *createHexagonSplitConst32AndConst64(); |
| 78 | FunctionPass *createHexagonExpandPredSpillCode(); |
Krzysztof Parzyszek | 21b53a5 | 2015-07-08 14:47:34 +0000 | [diff] [blame] | 79 | FunctionPass *createHexagonGenInsert(); |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 80 | FunctionPass *createHexagonHardwareLoops(); |
| 81 | FunctionPass *createHexagonPeephole(); |
| 82 | FunctionPass *createHexagonFixupHwLoops(); |
| 83 | FunctionPass *createHexagonNewValueJump(); |
| 84 | FunctionPass *createHexagonCopyToCombine(); |
| 85 | FunctionPass *createHexagonPacketizer(); |
| 86 | FunctionPass *createHexagonNewValueJump(); |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 87 | } // end namespace llvm; |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 88 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 89 | /// HexagonTargetMachine ctor - Create an ILP32 architecture model. |
| 90 | /// |
| 91 | |
| 92 | /// Hexagon_TODO: Do I need an aggregate alignment? |
| 93 | /// |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 94 | HexagonTargetMachine::HexagonTargetMachine(const Target &T, const Triple &TT, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 95 | StringRef CPU, StringRef FS, |
Craig Topper | b545408 | 2012-03-17 09:24:09 +0000 | [diff] [blame] | 96 | const TargetOptions &Options, |
Eric Christopher | 0d0b360 | 2014-06-27 00:13:43 +0000 | [diff] [blame] | 97 | Reloc::Model RM, CodeModel::Model CM, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 98 | CodeGenOpt::Level OL) |
Mehdi Amini | 93e1ea1 | 2015-03-12 00:07:24 +0000 | [diff] [blame] | 99 | : LLVMTargetMachine(T, "e-m:e-p:32:32-i1:32-i64:64-a:0-n32", TT, CPU, FS, |
| 100 | Options, RM, CM, OL), |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 101 | TLOF(make_unique<HexagonTargetObjectFile>()), |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 102 | Subtarget(TT, CPU, FS, *this) { |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 103 | initAsmInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Reid Kleckner | 357600e | 2014-11-20 23:37:18 +0000 | [diff] [blame] | 106 | HexagonTargetMachine::~HexagonTargetMachine() {} |
| 107 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 108 | namespace { |
| 109 | /// Hexagon Code Generator Pass Configuration Options. |
| 110 | class HexagonPassConfig : public TargetPassConfig { |
| 111 | public: |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 112 | HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM) |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 113 | : TargetPassConfig(TM, PM) { |
| 114 | bool NoOpt = (TM->getOptLevel() == CodeGenOpt::None); |
| 115 | if (!NoOpt) { |
| 116 | if (EnableExpandCondsets) { |
| 117 | Pass *Exp = createHexagonExpandCondsets(); |
| 118 | insertPass(&RegisterCoalescerID, IdentifyingPassPtr(Exp)); |
| 119 | } |
| 120 | } |
| 121 | } |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 122 | |
| 123 | HexagonTargetMachine &getHexagonTargetMachine() const { |
| 124 | return getTM<HexagonTargetMachine>(); |
| 125 | } |
| 126 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 127 | ScheduleDAGInstrs * |
| 128 | createMachineScheduler(MachineSchedContext *C) const override { |
Andrew Trick | 978674b | 2013-09-20 05:14:41 +0000 | [diff] [blame] | 129 | return createVLIWMachineSched(C); |
| 130 | } |
| 131 | |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 132 | void addIRPasses() override; |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 133 | bool addInstSelector() override; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 134 | void addPreRegAlloc() override; |
| 135 | void addPostRegAlloc() override; |
| 136 | void addPreSched2() override; |
| 137 | void addPreEmitPass() override; |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 138 | }; |
| 139 | } // namespace |
| 140 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 141 | TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 142 | return new HexagonPassConfig(this, PM); |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 145 | void HexagonPassConfig::addIRPasses() { |
| 146 | TargetPassConfig::addIRPasses(); |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 147 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 148 | |
| 149 | addPass(createAtomicExpandPass(TM)); |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 150 | if (!NoOpt && EnableCommGEP) |
| 151 | addPass(createHexagonCommonGEP()); |
| 152 | } |
| 153 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 154 | bool HexagonPassConfig::addInstSelector() { |
Bill Wendling | a3cd350 | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 155 | HexagonTargetMachine &TM = getHexagonTargetMachine(); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 156 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 157 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 158 | if (!NoOpt) |
| 159 | addPass(createHexagonRemoveExtendArgs(TM)); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 160 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 161 | addPass(createHexagonISelDag(TM, getOptLevel())); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 162 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 163 | if (!NoOpt) { |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 164 | addPass(createHexagonPeephole()); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 165 | printAndVerify("After hexagon peephole pass"); |
Krzysztof Parzyszek | 21b53a5 | 2015-07-08 14:47:34 +0000 | [diff] [blame] | 166 | if (EnableGenInsert) |
| 167 | addPass(createHexagonGenInsert(), false); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 168 | } |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 169 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 170 | return false; |
| 171 | } |
| 172 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 173 | void HexagonPassConfig::addPreRegAlloc() { |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 174 | if (getOptLevel() != CodeGenOpt::None) |
| 175 | if (!DisableHardwareLoops) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 176 | addPass(createHexagonHardwareLoops(), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 179 | void HexagonPassConfig::addPostRegAlloc() { |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 180 | if (getOptLevel() != CodeGenOpt::None) |
| 181 | if (!DisableHexagonCFGOpt) |
Eric Christopher | 5c3376a | 2015-02-02 18:46:27 +0000 | [diff] [blame] | 182 | addPass(createHexagonCFGOptimizer(), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 185 | void HexagonPassConfig::addPreSched2() { |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 186 | addPass(createHexagonCopyToCombine(), false); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 187 | if (getOptLevel() != CodeGenOpt::None) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 188 | addPass(&IfConverterID, false); |
Eric Christopher | 01f875e | 2015-02-02 22:11:43 +0000 | [diff] [blame] | 189 | addPass(createHexagonSplitConst32AndConst64()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 192 | void HexagonPassConfig::addPreEmitPass() { |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 193 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 194 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 195 | if (!NoOpt) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 196 | addPass(createHexagonNewValueJump(), false); |
Sirish Pande | 4bd20c5 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 197 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 198 | // Expand Spill code for predicate registers. |
Eric Christopher | 6ff7ed6 | 2015-02-02 18:46:31 +0000 | [diff] [blame] | 199 | addPass(createHexagonExpandPredSpillCode(), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 200 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 201 | // Create Packets. |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 202 | if (!NoOpt) { |
| 203 | if (!DisableHardwareLoops) |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 204 | addPass(createHexagonFixupHwLoops(), false); |
| 205 | addPass(createHexagonPacketizer(), false); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 206 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 207 | } |