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