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