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