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" |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 19 | #include "HexagonTargetTransformInfo.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/Passes.h" |
Matthias Braun | 31d19d4 | 2016-05-10 03:21:59 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/TargetPassConfig.h" |
Chandler Carruth | 30d69c2 | 2015-02-13 10:01:29 +0000 | [diff] [blame] | 22 | #include "llvm/IR/LegacyPassManager.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Module.h" |
Benjamin Kramer | ae87d7b | 2012-02-06 10:19:29 +0000 | [diff] [blame] | 24 | #include "llvm/Support/CommandLine.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | #include "llvm/Support/TargetRegistry.h" |
Krzysztof Parzyszek | c8b9438 | 2017-01-26 21:41:10 +0000 | [diff] [blame] | 26 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 27 | #include "llvm/Transforms/Scalar.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 28 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Krzysztof Parzyszek | 1279881 | 2016-01-12 19:09:01 +0000 | [diff] [blame] | 31 | static cl::opt<bool> EnableRDFOpt("rdf-opt", cl::Hidden, cl::ZeroOrMore, |
| 32 | cl::init(true), cl::desc("Enable RDF-based optimizations")); |
| 33 | |
| 34 | static cl::opt<bool> DisableHardwareLoops("disable-hexagon-hwloops", |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 35 | cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target")); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 36 | |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 37 | static cl::opt<bool> DisableAModeOpt("disable-hexagon-amodeopt", |
| 38 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 39 | cl::desc("Disable Hexagon Addressing Mode Optimization")); |
| 40 | |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 41 | static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt", |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 42 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 43 | cl::desc("Disable Hexagon CFG Optimization")); |
| 44 | |
Krzysztof Parzyszek | 167d918 | 2016-07-28 20:01:59 +0000 | [diff] [blame] | 45 | static cl::opt<bool> DisableHCP("disable-hcp", cl::init(false), cl::Hidden, |
| 46 | cl::ZeroOrMore, cl::desc("Disable Hexagon constant propagation")); |
| 47 | |
Krzysztof Parzyszek | 5b7dd0c | 2015-10-16 19:43:56 +0000 | [diff] [blame] | 48 | static cl::opt<bool> DisableStoreWidening("disable-store-widen", |
| 49 | cl::Hidden, cl::init(false), cl::desc("Disable store widening")); |
| 50 | |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 51 | static cl::opt<bool> EnableExpandCondsets("hexagon-expand-condsets", |
| 52 | cl::init(true), cl::Hidden, cl::ZeroOrMore, |
| 53 | cl::desc("Early expansion of MUX")); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 54 | |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 55 | static cl::opt<bool> EnableEarlyIf("hexagon-eif", cl::init(true), cl::Hidden, |
| 56 | cl::ZeroOrMore, cl::desc("Enable early if-conversion")); |
| 57 | |
Krzysztof Parzyszek | 21b53a5 | 2015-07-08 14:47:34 +0000 | [diff] [blame] | 58 | static cl::opt<bool> EnableGenInsert("hexagon-insert", cl::init(true), |
| 59 | cl::Hidden, cl::desc("Generate \"insert\" instructions")); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 60 | |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 61 | static cl::opt<bool> EnableCommGEP("hexagon-commgep", cl::init(true), |
| 62 | cl::Hidden, cl::ZeroOrMore, cl::desc("Enable commoning of GEP instructions")); |
| 63 | |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 64 | static cl::opt<bool> EnableGenExtract("hexagon-extract", cl::init(true), |
| 65 | cl::Hidden, cl::desc("Generate \"extract\" instructions")); |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 66 | |
Krzysztof Parzyszek | 9217220 | 2015-07-20 21:23:25 +0000 | [diff] [blame] | 67 | static cl::opt<bool> EnableGenMux("hexagon-mux", cl::init(true), cl::Hidden, |
| 68 | cl::desc("Enable converting conditional transfers into MUX instructions")); |
| 69 | |
Krzysztof Parzyszek | 7587447 | 2015-07-14 19:30:21 +0000 | [diff] [blame] | 70 | static cl::opt<bool> EnableGenPred("hexagon-gen-pred", cl::init(true), |
| 71 | cl::Hidden, cl::desc("Enable conversion of arithmetic operations to " |
| 72 | "predicate instructions")); |
| 73 | |
Krzysztof Parzyszek | d3d0a4b | 2016-07-22 14:22:43 +0000 | [diff] [blame] | 74 | static cl::opt<bool> EnableLoopPrefetch("hexagon-loop-prefetch", |
| 75 | cl::init(false), cl::Hidden, cl::ZeroOrMore, |
| 76 | cl::desc("Enable loop data prefetch on Hexagon")); |
| 77 | |
Krzysztof Parzyszek | a7c5f04 | 2015-10-16 20:38:54 +0000 | [diff] [blame] | 78 | static cl::opt<bool> DisableHSDR("disable-hsdr", cl::init(false), cl::Hidden, |
| 79 | cl::desc("Disable splitting double registers")); |
| 80 | |
Krzysztof Parzyszek | ced9941 | 2015-10-20 22:57:13 +0000 | [diff] [blame] | 81 | static cl::opt<bool> EnableBitSimplify("hexagon-bit", cl::init(true), |
| 82 | cl::Hidden, cl::desc("Bit simplification")); |
| 83 | |
| 84 | static cl::opt<bool> EnableLoopResched("hexagon-loop-resched", cl::init(true), |
| 85 | cl::Hidden, cl::desc("Loop rescheduling")); |
| 86 | |
Krzysztof Parzyszek | d559005 | 2016-05-11 15:01:30 +0000 | [diff] [blame] | 87 | static cl::opt<bool> HexagonNoOpt("hexagon-noopt", cl::init(false), |
| 88 | cl::Hidden, cl::desc("Disable backend optimizations")); |
| 89 | |
Ron Lieberman | 8123b96 | 2016-08-01 19:36:39 +0000 | [diff] [blame] | 90 | static cl::opt<bool> EnableVectorPrint("enable-hexagon-vector-print", |
| 91 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 92 | cl::desc("Enable Hexagon Vector print instr pass")); |
| 93 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 94 | /// HexagonTargetMachineModule - Note that this is used on hosts that |
| 95 | /// cannot link in a library unless there are references into the |
| 96 | /// library. In particular, it seems that it is not possible to get |
| 97 | /// things to work on Win32 without this. Though it is unused, do not |
| 98 | /// remove it. |
| 99 | extern "C" int HexagonTargetMachineModule; |
| 100 | int HexagonTargetMachineModule = 0; |
| 101 | |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 102 | static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) { |
David Blaikie | 422b93d | 2014-04-21 20:32:32 +0000 | [diff] [blame] | 103 | return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>()); |
Sergei Larin | 4d8986a | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static MachineSchedRegistry |
| 107 | SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler", |
| 108 | createVLIWMachineSched); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 109 | |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 110 | namespace llvm { |
Krzysztof Parzyszek | 951fb36 | 2016-08-24 22:27:36 +0000 | [diff] [blame] | 111 | extern char &HexagonExpandCondsetsID; |
| 112 | void initializeHexagonExpandCondsetsPass(PassRegistry&); |
Krzysztof Parzyszek | c8b9438 | 2017-01-26 21:41:10 +0000 | [diff] [blame] | 113 | void initializeHexagonLoopIdiomRecognizePass(PassRegistry&); |
Krzysztof Parzyszek | de2ac17 | 2017-06-13 16:07:36 +0000 | [diff] [blame] | 114 | void initializeHexagonGenMuxPass(PassRegistry&); |
Krzysztof Parzyszek | 333b2bf | 2017-04-19 15:15:51 +0000 | [diff] [blame] | 115 | void initializeHexagonOptAddrModePass(PassRegistry&); |
Krzysztof Parzyszek | 5ddd2e5 | 2017-06-27 18:37:16 +0000 | [diff] [blame^] | 116 | void initializeHexagonNewValueJumpPass(PassRegistry&); |
Krzysztof Parzyszek | c8b9438 | 2017-01-26 21:41:10 +0000 | [diff] [blame] | 117 | Pass *createHexagonLoopIdiomPass(); |
Krzysztof Parzyszek | 951fb36 | 2016-08-24 22:27:36 +0000 | [diff] [blame] | 118 | |
Krzysztof Parzyszek | ced9941 | 2015-10-20 22:57:13 +0000 | [diff] [blame] | 119 | FunctionPass *createHexagonBitSimplify(); |
Krzysztof Parzyszek | 7b59ae2 | 2016-04-19 18:30:18 +0000 | [diff] [blame] | 120 | FunctionPass *createHexagonBranchRelaxation(); |
Krzysztof Parzyszek | db86770 | 2015-10-19 17:46:01 +0000 | [diff] [blame] | 121 | FunctionPass *createHexagonCallFrameInformation(); |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 122 | FunctionPass *createHexagonCFGOptimizer(); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 123 | FunctionPass *createHexagonCommonGEP(); |
Krzysztof Parzyszek | 167d918 | 2016-07-28 20:01:59 +0000 | [diff] [blame] | 124 | FunctionPass *createHexagonConstPropagationPass(); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 125 | FunctionPass *createHexagonCopyToCombine(); |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 126 | FunctionPass *createHexagonEarlyIfConversion(); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 127 | FunctionPass *createHexagonFixupHwLoops(); |
| 128 | FunctionPass *createHexagonGenExtract(); |
Krzysztof Parzyszek | 21b53a5 | 2015-07-08 14:47:34 +0000 | [diff] [blame] | 129 | FunctionPass *createHexagonGenInsert(); |
Krzysztof Parzyszek | 9217220 | 2015-07-20 21:23:25 +0000 | [diff] [blame] | 130 | FunctionPass *createHexagonGenMux(); |
Krzysztof Parzyszek | 7587447 | 2015-07-14 19:30:21 +0000 | [diff] [blame] | 131 | FunctionPass *createHexagonGenPredicate(); |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 132 | FunctionPass *createHexagonHardwareLoops(); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 133 | FunctionPass *createHexagonISelDag(HexagonTargetMachine &TM, |
| 134 | CodeGenOpt::Level OptLevel); |
Krzysztof Parzyszek | ced9941 | 2015-10-20 22:57:13 +0000 | [diff] [blame] | 135 | FunctionPass *createHexagonLoopRescheduling(); |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 136 | FunctionPass *createHexagonNewValueJump(); |
Krzysztof Parzyszek | 055c5fd | 2015-10-19 19:10:48 +0000 | [diff] [blame] | 137 | FunctionPass *createHexagonOptimizeSZextends(); |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 138 | FunctionPass *createHexagonOptAddrMode(); |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 139 | FunctionPass *createHexagonPacketizer(); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 140 | FunctionPass *createHexagonPeephole(); |
Krzysztof Parzyszek | 1279881 | 2016-01-12 19:09:01 +0000 | [diff] [blame] | 141 | FunctionPass *createHexagonRDFOpt(); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 142 | FunctionPass *createHexagonSplitConst32AndConst64(); |
Krzysztof Parzyszek | a7c5f04 | 2015-10-16 20:38:54 +0000 | [diff] [blame] | 143 | FunctionPass *createHexagonSplitDoubleRegs(); |
Krzysztof Parzyszek | 5b7dd0c | 2015-10-16 19:43:56 +0000 | [diff] [blame] | 144 | FunctionPass *createHexagonStoreWidening(); |
Ron Lieberman | 8123b96 | 2016-08-01 19:36:39 +0000 | [diff] [blame] | 145 | FunctionPass *createHexagonVectorPrint(); |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 146 | } // end namespace llvm; |
Krzysztof Parzyszek | c05dff1 | 2015-03-31 13:35:12 +0000 | [diff] [blame] | 147 | |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 148 | static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) { |
| 149 | if (!RM.hasValue()) |
| 150 | return Reloc::Static; |
| 151 | return *RM; |
| 152 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 153 | |
Krzysztof Parzyszek | c8b9438 | 2017-01-26 21:41:10 +0000 | [diff] [blame] | 154 | extern "C" void LLVMInitializeHexagonTarget() { |
| 155 | // Register the target. |
| 156 | RegisterTargetMachine<HexagonTargetMachine> X(getTheHexagonTarget()); |
Krzysztof Parzyszek | de2ac17 | 2017-06-13 16:07:36 +0000 | [diff] [blame] | 157 | |
| 158 | PassRegistry &PR = *PassRegistry::getPassRegistry(); |
| 159 | initializeHexagonLoopIdiomRecognizePass(PR); |
| 160 | initializeHexagonGenMuxPass(PR); |
| 161 | initializeHexagonOptAddrModePass(PR); |
Krzysztof Parzyszek | 5ddd2e5 | 2017-06-27 18:37:16 +0000 | [diff] [blame^] | 162 | initializeHexagonNewValueJumpPass(PR); |
Krzysztof Parzyszek | c8b9438 | 2017-01-26 21:41:10 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 165 | HexagonTargetMachine::HexagonTargetMachine(const Target &T, const Triple &TT, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 166 | StringRef CPU, StringRef FS, |
Craig Topper | b545408 | 2012-03-17 09:24:09 +0000 | [diff] [blame] | 167 | const TargetOptions &Options, |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 168 | Optional<Reloc::Model> RM, |
| 169 | CodeModel::Model CM, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 170 | CodeGenOpt::Level OL) |
Krzysztof Parzyszek | e599643 | 2016-02-12 14:47:38 +0000 | [diff] [blame] | 171 | // Specify the vector alignment explicitly. For v512x1, the calculated |
| 172 | // alignment would be 512*alignment(i1), which is 512 bytes, instead of |
| 173 | // the required minimum of 64 bytes. |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 174 | : LLVMTargetMachine( |
| 175 | T, "e-m:e-p:32:32:32-a:0-n16:32-" |
| 176 | "i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-" |
| 177 | "v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048", |
| 178 | TT, CPU, FS, Options, getEffectiveRelocModel(RM), CM, |
| 179 | (HexagonNoOpt ? CodeGenOpt::None : OL)), |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 180 | TLOF(make_unique<HexagonTargetObjectFile>()) { |
Krzysztof Parzyszek | 951fb36 | 2016-08-24 22:27:36 +0000 | [diff] [blame] | 181 | initializeHexagonExpandCondsetsPass(*PassRegistry::getPassRegistry()); |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 182 | initAsmInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 185 | const HexagonSubtarget * |
| 186 | HexagonTargetMachine::getSubtargetImpl(const Function &F) const { |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 187 | AttributeList FnAttrs = F.getAttributes(); |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 188 | Attribute CPUAttr = |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 189 | FnAttrs.getAttribute(AttributeList::FunctionIndex, "target-cpu"); |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 190 | Attribute FSAttr = |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 191 | FnAttrs.getAttribute(AttributeList::FunctionIndex, "target-features"); |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 192 | |
| 193 | std::string CPU = !CPUAttr.hasAttribute(Attribute::None) |
| 194 | ? CPUAttr.getValueAsString().str() |
| 195 | : TargetCPU; |
| 196 | std::string FS = !FSAttr.hasAttribute(Attribute::None) |
| 197 | ? FSAttr.getValueAsString().str() |
| 198 | : TargetFS; |
| 199 | |
| 200 | auto &I = SubtargetMap[CPU + FS]; |
| 201 | if (!I) { |
| 202 | // This needs to be done before we create a new subtarget since any |
| 203 | // creation will depend on the TM and the code generation flags on the |
| 204 | // function that reside in TargetOptions. |
| 205 | resetTargetOptions(F); |
| 206 | I = llvm::make_unique<HexagonSubtarget>(TargetTriple, CPU, FS, *this); |
| 207 | } |
| 208 | return I.get(); |
| 209 | } |
| 210 | |
Krzysztof Parzyszek | c8b9438 | 2017-01-26 21:41:10 +0000 | [diff] [blame] | 211 | void HexagonTargetMachine::adjustPassManager(PassManagerBuilder &PMB) { |
| 212 | PMB.addExtension( |
| 213 | PassManagerBuilder::EP_LateLoopOptimizations, |
| 214 | [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) { |
| 215 | PM.add(createHexagonLoopIdiomPass()); |
| 216 | }); |
| 217 | } |
| 218 | |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 219 | TargetIRAnalysis HexagonTargetMachine::getTargetIRAnalysis() { |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 220 | return TargetIRAnalysis([this](const Function &F) { |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 221 | return TargetTransformInfo(HexagonTTIImpl(this, F)); |
| 222 | }); |
| 223 | } |
| 224 | |
| 225 | |
Reid Kleckner | 357600e | 2014-11-20 23:37:18 +0000 | [diff] [blame] | 226 | HexagonTargetMachine::~HexagonTargetMachine() {} |
| 227 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 228 | namespace { |
| 229 | /// Hexagon Code Generator Pass Configuration Options. |
| 230 | class HexagonPassConfig : public TargetPassConfig { |
| 231 | public: |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 232 | HexagonPassConfig(HexagonTargetMachine &TM, PassManagerBase &PM) |
Krzysztof Parzyszek | d0f8e1c | 2016-05-27 20:48:39 +0000 | [diff] [blame] | 233 | : TargetPassConfig(TM, PM) {} |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 234 | |
| 235 | HexagonTargetMachine &getHexagonTargetMachine() const { |
| 236 | return getTM<HexagonTargetMachine>(); |
| 237 | } |
| 238 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 239 | ScheduleDAGInstrs * |
| 240 | createMachineScheduler(MachineSchedContext *C) const override { |
Andrew Trick | 978674b | 2013-09-20 05:14:41 +0000 | [diff] [blame] | 241 | return createVLIWMachineSched(C); |
| 242 | } |
| 243 | |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 244 | void addIRPasses() override; |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 245 | bool addInstSelector() override; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 246 | void addPreRegAlloc() override; |
| 247 | void addPostRegAlloc() override; |
| 248 | void addPreSched2() override; |
| 249 | void addPreEmitPass() override; |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 250 | }; |
| 251 | } // namespace |
| 252 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 253 | TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) { |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 254 | return new HexagonPassConfig(*this, PM); |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 257 | void HexagonPassConfig::addIRPasses() { |
| 258 | TargetPassConfig::addIRPasses(); |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 259 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 260 | |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 261 | addPass(createAtomicExpandPass()); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 262 | if (!NoOpt) { |
Krzysztof Parzyszek | d3d0a4b | 2016-07-22 14:22:43 +0000 | [diff] [blame] | 263 | if (EnableLoopPrefetch) |
| 264 | addPass(createLoopDataPrefetchPass()); |
Krzysztof Parzyszek | a0ecf07 | 2015-07-14 17:07:24 +0000 | [diff] [blame] | 265 | if (EnableCommGEP) |
| 266 | addPass(createHexagonCommonGEP()); |
| 267 | // Replace certain combinations of shifts and ands with extracts. |
| 268 | if (EnableGenExtract) |
| 269 | addPass(createHexagonGenExtract()); |
| 270 | } |
Krzysztof Parzyszek | 79b2433 | 2015-07-08 19:22:28 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 273 | bool HexagonPassConfig::addInstSelector() { |
Bill Wendling | a3cd350 | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 274 | HexagonTargetMachine &TM = getHexagonTargetMachine(); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 275 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 276 | |
Krzysztof Parzyszek | 055c5fd | 2015-10-19 19:10:48 +0000 | [diff] [blame] | 277 | if (!NoOpt) |
| 278 | addPass(createHexagonOptimizeSZextends()); |
| 279 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 280 | addPass(createHexagonISelDag(TM, getOptLevel())); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 281 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 282 | if (!NoOpt) { |
Krzysztof Parzyszek | 7587447 | 2015-07-14 19:30:21 +0000 | [diff] [blame] | 283 | // Create logical operations on predicate registers. |
| 284 | if (EnableGenPred) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 285 | addPass(createHexagonGenPredicate()); |
Krzysztof Parzyszek | ced9941 | 2015-10-20 22:57:13 +0000 | [diff] [blame] | 286 | // Rotate loops to expose bit-simplification opportunities. |
| 287 | if (EnableLoopResched) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 288 | addPass(createHexagonLoopRescheduling()); |
Krzysztof Parzyszek | a7c5f04 | 2015-10-16 20:38:54 +0000 | [diff] [blame] | 289 | // Split double registers. |
| 290 | if (!DisableHSDR) |
| 291 | addPass(createHexagonSplitDoubleRegs()); |
Krzysztof Parzyszek | ced9941 | 2015-10-20 22:57:13 +0000 | [diff] [blame] | 292 | // Bit simplification. |
| 293 | if (EnableBitSimplify) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 294 | addPass(createHexagonBitSimplify()); |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 295 | addPass(createHexagonPeephole()); |
Krzysztof Parzyszek | 167d918 | 2016-07-28 20:01:59 +0000 | [diff] [blame] | 296 | // Constant propagation. |
| 297 | if (!DisableHCP) { |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 298 | addPass(createHexagonConstPropagationPass()); |
| 299 | addPass(&UnreachableMachineBlockElimID); |
Krzysztof Parzyszek | 167d918 | 2016-07-28 20:01:59 +0000 | [diff] [blame] | 300 | } |
Krzysztof Parzyszek | 21b53a5 | 2015-07-08 14:47:34 +0000 | [diff] [blame] | 301 | if (EnableGenInsert) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 302 | addPass(createHexagonGenInsert()); |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 303 | if (EnableEarlyIf) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 304 | addPass(createHexagonEarlyIfConversion()); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 305 | } |
Jyotsna Verma | 653d883 | 2013-03-27 11:14:24 +0000 | [diff] [blame] | 306 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 307 | return false; |
| 308 | } |
| 309 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 310 | void HexagonPassConfig::addPreRegAlloc() { |
Krzysztof Parzyszek | 5b7dd0c | 2015-10-16 19:43:56 +0000 | [diff] [blame] | 311 | if (getOptLevel() != CodeGenOpt::None) { |
Krzysztof Parzyszek | 951fb36 | 2016-08-24 22:27:36 +0000 | [diff] [blame] | 312 | if (EnableExpandCondsets) |
| 313 | insertPass(&RegisterCoalescerID, &HexagonExpandCondsetsID); |
Krzysztof Parzyszek | 5b7dd0c | 2015-10-16 19:43:56 +0000 | [diff] [blame] | 314 | if (!DisableStoreWidening) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 315 | addPass(createHexagonStoreWidening()); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 316 | if (!DisableHardwareLoops) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 317 | addPass(createHexagonHardwareLoops()); |
Krzysztof Parzyszek | 5b7dd0c | 2015-10-16 19:43:56 +0000 | [diff] [blame] | 318 | } |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 319 | if (TM->getOptLevel() >= CodeGenOpt::Default) |
| 320 | addPass(&MachinePipelinerID); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 323 | void HexagonPassConfig::addPostRegAlloc() { |
Krzysztof Parzyszek | 1279881 | 2016-01-12 19:09:01 +0000 | [diff] [blame] | 324 | if (getOptLevel() != CodeGenOpt::None) { |
| 325 | if (EnableRDFOpt) |
| 326 | addPass(createHexagonRDFOpt()); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 327 | if (!DisableHexagonCFGOpt) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 328 | addPass(createHexagonCFGOptimizer()); |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 329 | if (!DisableAModeOpt) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 330 | addPass(createHexagonOptAddrMode()); |
Krzysztof Parzyszek | 1279881 | 2016-01-12 19:09:01 +0000 | [diff] [blame] | 331 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 334 | void HexagonPassConfig::addPreSched2() { |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 335 | addPass(createHexagonCopyToCombine()); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 336 | if (getOptLevel() != CodeGenOpt::None) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 337 | addPass(&IfConverterID); |
Eric Christopher | 01f875e | 2015-02-02 22:11:43 +0000 | [diff] [blame] | 338 | addPass(createHexagonSplitConst32AndConst64()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 341 | void HexagonPassConfig::addPreEmitPass() { |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 342 | bool NoOpt = (getOptLevel() == CodeGenOpt::None); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 343 | |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 344 | if (!NoOpt) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 345 | addPass(createHexagonNewValueJump()); |
Sirish Pande | 4bd20c5 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 346 | |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 347 | addPass(createHexagonBranchRelaxation()); |
Krzysztof Parzyszek | 7b59ae2 | 2016-04-19 18:30:18 +0000 | [diff] [blame] | 348 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 349 | // Create Packets. |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 350 | if (!NoOpt) { |
| 351 | if (!DisableHardwareLoops) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 352 | addPass(createHexagonFixupHwLoops()); |
Krzysztof Parzyszek | 9217220 | 2015-07-20 21:23:25 +0000 | [diff] [blame] | 353 | // Generate MUX from pairs of conditional transfers. |
| 354 | if (EnableGenMux) |
Krzysztof Parzyszek | b1ada4e | 2017-06-08 21:25:36 +0000 | [diff] [blame] | 355 | addPass(createHexagonGenMux()); |
Krzysztof Parzyszek | 9217220 | 2015-07-20 21:23:25 +0000 | [diff] [blame] | 356 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 357 | addPass(createHexagonPacketizer(), false); |
Krzysztof Parzyszek | 59df52c | 2013-05-06 21:25:45 +0000 | [diff] [blame] | 358 | } |
Ron Lieberman | 8123b96 | 2016-08-01 19:36:39 +0000 | [diff] [blame] | 359 | if (EnableVectorPrint) |
| 360 | addPass(createHexagonVectorPrint(), false); |
Krzysztof Parzyszek | db86770 | 2015-10-19 17:46:01 +0000 | [diff] [blame] | 361 | |
| 362 | // Add CFI instructions if necessary. |
| 363 | addPass(createHexagonCallFrameInformation(), false); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 364 | } |