Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===// |
Tony Linthicum | b4b5415 | 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 | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 10 | // Implements the info about Hexagon target spec. |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 14 | #include "HexagonTargetMachine.h" |
| 15 | #include "Hexagon.h" |
| 16 | #include "HexagonISelLowering.h" |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 17 | #include "HexagonMachineScheduler.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/Passes.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame^] | 19 | #include "llvm/IR/Module.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 20 | #include "llvm/PassManager.h" |
Benjamin Kramer | f3fd7ee | 2012-02-06 10:19:29 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CommandLine.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 22 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
| 24 | #include "llvm/Transforms/Scalar.h" |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
| 28 | static cl:: |
| 29 | opt<bool> DisableHardwareLoops( |
| 30 | "disable-hexagon-hwloops", cl::Hidden, |
| 31 | cl::desc("Disable Hardware Loops for Hexagon target")); |
| 32 | |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 33 | static cl:: |
| 34 | opt<bool> DisableHexagonMISched("disable-hexagon-misched", |
| 35 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 36 | cl::desc("Disable Hexagon MI Scheduling")); |
| 37 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 38 | /// HexagonTargetMachineModule - Note that this is used on hosts that |
| 39 | /// cannot link in a library unless there are references into the |
| 40 | /// library. In particular, it seems that it is not possible to get |
| 41 | /// things to work on Win32 without this. Though it is unused, do not |
| 42 | /// remove it. |
| 43 | extern "C" int HexagonTargetMachineModule; |
| 44 | int HexagonTargetMachineModule = 0; |
| 45 | |
| 46 | extern "C" void LLVMInitializeHexagonTarget() { |
| 47 | // Register the target. |
| 48 | RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 51 | static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) { |
| 52 | return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler()); |
| 53 | } |
| 54 | |
| 55 | static MachineSchedRegistry |
| 56 | SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler", |
| 57 | createVLIWMachineSched); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 58 | |
| 59 | /// HexagonTargetMachine ctor - Create an ILP32 architecture model. |
| 60 | /// |
| 61 | |
| 62 | /// Hexagon_TODO: Do I need an aggregate alignment? |
| 63 | /// |
| 64 | HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT, |
| 65 | StringRef CPU, StringRef FS, |
Craig Topper | 1e0c9ab | 2012-03-17 09:24:09 +0000 | [diff] [blame] | 66 | const TargetOptions &Options, |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 67 | Reloc::Model RM, |
| 68 | CodeModel::Model CM, |
| 69 | CodeGenOpt::Level OL) |
| 70 | : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 71 | DL("e-p:32:32:32-" |
Sirish Pande | 7517bbc | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 72 | "i64:64:64-i32:32:32-i16:16:16-i1:32:32-" |
| 73 | "f64:64:64-f32:32:32-a0:0-n32") , |
Benjamin Kramer | 9034562 | 2011-12-16 19:08:59 +0000 | [diff] [blame] | 74 | Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this), |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 75 | TSInfo(*this), |
| 76 | FrameLowering(Subtarget), |
Nadav Rotem | cbd9a19 | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 77 | InstrItins(&Subtarget.getInstrItineraryData()), |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 78 | STTI(&TLInfo), VTTI(&TLInfo) { |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 79 | setMCUseCFI(false); |
| 80 | } |
| 81 | |
| 82 | // addPassesForOptimizations - Allow the backend (target) to add Target |
| 83 | // Independent Optimization passes to the Pass Manager. |
| 84 | bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) { |
| 85 | |
| 86 | PM.add(createConstantPropagationPass()); |
| 87 | PM.add(createLoopSimplifyPass()); |
| 88 | PM.add(createDeadCodeEliminationPass()); |
| 89 | PM.add(createConstantPropagationPass()); |
| 90 | PM.add(createLoopUnrollPass()); |
Nadav Rotem | cbd9a19 | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 91 | PM.add(createLoopStrengthReducePass()); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 92 | return true; |
| 93 | } |
| 94 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 95 | namespace { |
| 96 | /// Hexagon Code Generator Pass Configuration Options. |
| 97 | class HexagonPassConfig : public TargetPassConfig { |
| 98 | public: |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 99 | HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM) |
Sergei Larin | 3e59040 | 2012-09-04 14:49:56 +0000 | [diff] [blame] | 100 | : TargetPassConfig(TM, PM) { |
| 101 | // Enable MI scheduler. |
| 102 | if (!DisableHexagonMISched) { |
| 103 | enablePass(&MachineSchedulerID); |
| 104 | MachineSchedRegistry::setDefault(createVLIWMachineSched); |
| 105 | } |
| 106 | } |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 107 | |
| 108 | HexagonTargetMachine &getHexagonTargetMachine() const { |
| 109 | return getTM<HexagonTargetMachine>(); |
| 110 | } |
| 111 | |
| 112 | virtual bool addInstSelector(); |
| 113 | virtual bool addPreRegAlloc(); |
| 114 | virtual bool addPostRegAlloc(); |
| 115 | virtual bool addPreSched2(); |
| 116 | virtual bool addPreEmitPass(); |
| 117 | }; |
| 118 | } // namespace |
| 119 | |
Andrew Trick | 061efcf | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 120 | TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 121 | return new HexagonPassConfig(this, PM); |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | bool HexagonPassConfig::addInstSelector() { |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 125 | addPass(createHexagonRemoveExtendOps(getHexagonTargetMachine())); |
| 126 | addPass(createHexagonISelDag(getHexagonTargetMachine())); |
| 127 | addPass(createHexagonPeephole()); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 128 | return false; |
| 129 | } |
| 130 | |
| 131 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 132 | bool HexagonPassConfig::addPreRegAlloc() { |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 133 | if (!DisableHardwareLoops) { |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 134 | addPass(createHexagonHardwareLoops()); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 135 | } |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 136 | return false; |
| 137 | } |
| 138 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 139 | bool HexagonPassConfig::addPostRegAlloc() { |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 140 | addPass(createHexagonCFGOptimizer(getHexagonTargetMachine())); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 141 | return true; |
| 142 | } |
| 143 | |
| 144 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 145 | bool HexagonPassConfig::addPreSched2() { |
Bob Wilson | 3fb99a7 | 2012-07-02 19:48:37 +0000 | [diff] [blame] | 146 | addPass(&IfConverterID); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 147 | return true; |
| 148 | } |
| 149 | |
Andrew Trick | 843ee2e | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 150 | bool HexagonPassConfig::addPreEmitPass() { |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 151 | |
| 152 | if (!DisableHardwareLoops) { |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 153 | addPass(createHexagonFixupHwLoops()); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 156 | addPass(createHexagonNewValueJump()); |
Sirish Pande | b338570 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 157 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 158 | // Expand Spill code for predicate registers. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 159 | addPass(createHexagonExpandPredSpillCode(getHexagonTargetMachine())); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 160 | |
| 161 | // Split up TFRcondsets into conditional transfers. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 162 | addPass(createHexagonSplitTFRCondSets(getHexagonTargetMachine())); |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 163 | |
Sirish Pande | 26f61a1 | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 164 | // Create Packets. |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 165 | addPass(createHexagonPacketizer()); |
Sirish Pande | 26f61a1 | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 166 | |
Tony Linthicum | b4b5415 | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 167 | return false; |
| 168 | } |