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