Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 1 | //=== HexagonSplitConst32AndConst64.cpp - split CONST32/Const64 into HI/LO ===// |
| 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 | // When the compiler is invoked with no small data, for instance, with the -G0 |
Krzysztof Parzyszek | a338650 | 2016-08-10 16:46:36 +0000 | [diff] [blame] | 11 | // command line option, then all CONST* opcodes should be broken down into |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 12 | // appropriate LO and HI instructions. This splitting is done by this pass. |
| 13 | // The only reason this is not done in the DAG lowering itself is that there |
| 14 | // is no simple way of getting the register allocator to allot the same hard |
| 15 | // register to the result of LO and HI instructions. This pass is always |
| 16 | // scheduled after register allocation. |
| 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
Bill Wendling | 0cb8c0b | 2013-08-21 20:36:42 +0000 | [diff] [blame] | 19 | |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 20 | #include "HexagonSubtarget.h" |
Eric Christopher | 0120db5 | 2014-05-21 22:42:07 +0000 | [diff] [blame] | 21 | #include "HexagonTargetMachine.h" |
| 22 | #include "HexagonTargetObjectFile.h" |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Bill Wendling | 0cb8c0b | 2013-08-21 20:36:42 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | 0cb8c0b | 2013-08-21 20:36:42 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/Passes.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetInstrInfo.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetRegisterInfo.h" |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace llvm; |
| 30 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 31 | #define DEBUG_TYPE "xfer" |
| 32 | |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 33 | namespace llvm { |
| 34 | FunctionPass *createHexagonSplitConst32AndConst64(); |
| 35 | void initializeHexagonSplitConst32AndConst64Pass(PassRegistry&); |
| 36 | } |
| 37 | |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 38 | namespace { |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 39 | class HexagonSplitConst32AndConst64 : public MachineFunctionPass { |
| 40 | public: |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 41 | static char ID; |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 42 | HexagonSplitConst32AndConst64() : MachineFunctionPass(ID) { |
| 43 | PassRegistry &R = *PassRegistry::getPassRegistry(); |
| 44 | initializeHexagonSplitConst32AndConst64Pass(R); |
| 45 | } |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 46 | const char *getPassName() const override { |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 47 | return "Hexagon Split Const32s and Const64s"; |
| 48 | } |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 49 | bool runOnMachineFunction(MachineFunction &Fn) override; |
Derek Schuff | 1dbf7a5 | 2016-04-04 17:09:25 +0000 | [diff] [blame] | 50 | MachineFunctionProperties getRequiredProperties() const override { |
| 51 | return MachineFunctionProperties().set( |
Matthias Braun | 1eb4736 | 2016-08-25 01:27:13 +0000 | [diff] [blame] | 52 | MachineFunctionProperties::Property::NoVRegs); |
Derek Schuff | 1dbf7a5 | 2016-04-04 17:09:25 +0000 | [diff] [blame] | 53 | } |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 54 | }; |
| 55 | } |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 56 | |
| 57 | char HexagonSplitConst32AndConst64::ID = 0; |
| 58 | |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 59 | INITIALIZE_PASS(HexagonSplitConst32AndConst64, "split-const-for-sdata", |
| 60 | "Hexagon Split Const32s and Const64s", false, false) |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 61 | |
| 62 | bool HexagonSplitConst32AndConst64::runOnMachineFunction(MachineFunction &Fn) { |
Eric Christopher | 0120db5 | 2014-05-21 22:42:07 +0000 | [diff] [blame] | 63 | const HexagonTargetObjectFile &TLOF = |
Eric Christopher | 01f875e | 2015-02-02 22:11:43 +0000 | [diff] [blame] | 64 | *static_cast<const HexagonTargetObjectFile *>( |
| 65 | Fn.getTarget().getObjFileLowering()); |
Krzysztof Parzyszek | 5de5910 | 2016-04-21 18:56:45 +0000 | [diff] [blame] | 66 | if (TLOF.isSmallDataEnabled()) |
Eric Christopher | 0120db5 | 2014-05-21 22:42:07 +0000 | [diff] [blame] | 67 | return true; |
| 68 | |
Eric Christopher | 01f875e | 2015-02-02 22:11:43 +0000 | [diff] [blame] | 69 | const TargetInstrInfo *TII = Fn.getSubtarget().getInstrInfo(); |
Colin LeMahieu | 5425109 | 2015-03-09 20:11:02 +0000 | [diff] [blame] | 70 | const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo(); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 71 | |
| 72 | // Loop over all of the basic blocks |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 73 | for (MachineBasicBlock &B : Fn) { |
| 74 | for (auto I = B.begin(), E = B.end(); I != E; ) { |
| 75 | MachineInstr &MI = *I; |
| 76 | ++I; |
| 77 | unsigned Opc = MI.getOpcode(); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 78 | |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 79 | if (Opc == Hexagon::CONST32) { |
| 80 | unsigned DestReg = MI.getOperand(0).getReg(); |
| 81 | uint64_t ImmValue = MI.getOperand(1).getImm(); |
| 82 | const DebugLoc &DL = MI.getDebugLoc(); |
| 83 | BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestReg) |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 84 | .addImm(ImmValue); |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 85 | B.erase(&MI); |
| 86 | } else if (Opc == Hexagon::CONST64) { |
| 87 | unsigned DestReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | a338650 | 2016-08-10 16:46:36 +0000 | [diff] [blame] | 88 | int64_t ImmValue = MI.getOperand(1).getImm(); |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 89 | const DebugLoc &DL = MI.getDebugLoc(); |
Colin LeMahieu | 5425109 | 2015-03-09 20:11:02 +0000 | [diff] [blame] | 90 | unsigned DestLo = TRI->getSubReg(DestReg, Hexagon::subreg_loreg); |
| 91 | unsigned DestHi = TRI->getSubReg(DestReg, Hexagon::subreg_hireg); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 92 | |
| 93 | int32_t LowWord = (ImmValue & 0xFFFFFFFF); |
| 94 | int32_t HighWord = (ImmValue >> 32) & 0xFFFFFFFF; |
| 95 | |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 96 | BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestLo) |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 97 | .addImm(LowWord); |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 98 | BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestHi) |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 99 | .addImm(HighWord); |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 100 | B.erase(&MI); |
Colin LeMahieu | 5425109 | 2015-03-09 20:11:02 +0000 | [diff] [blame] | 101 | } |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 108 | |
| 109 | //===----------------------------------------------------------------------===// |
| 110 | // Public Constructor Functions |
| 111 | //===----------------------------------------------------------------------===// |
| 112 | |
Krzysztof Parzyszek | 0bbad0f | 2016-08-10 18:05:47 +0000 | [diff] [blame] | 113 | FunctionPass *llvm::createHexagonSplitConst32AndConst64() { |
Eric Christopher | 01f875e | 2015-02-02 22:11:43 +0000 | [diff] [blame] | 114 | return new HexagonSplitConst32AndConst64(); |
Jyotsna Verma | 5eb5980 | 2013-05-07 19:53:00 +0000 | [diff] [blame] | 115 | } |