Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1 | //===-- SystemZInstrInfo.cpp - SystemZ instruction information ------------===// |
| 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 | // This file contains the SystemZ implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 14 | #include "MCTargetDesc/SystemZMCTargetDesc.h" |
| 15 | #include "SystemZ.h" |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 16 | #include "SystemZInstrBuilder.h" |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 17 | #include "SystemZInstrInfo.h" |
| 18 | #include "SystemZSubtarget.h" |
| 19 | #include "llvm/CodeGen/LiveInterval.h" |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/LiveVariables.h" |
| 22 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 23 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 24 | #include "llvm/CodeGen/MachineFunction.h" |
| 25 | #include "llvm/CodeGen/MachineInstr.h" |
| 26 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 27 | #include "llvm/CodeGen/MachineMemOperand.h" |
| 28 | #include "llvm/CodeGen/MachineOperand.h" |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/SlotIndexes.h" |
| 31 | #include "llvm/MC/MCInstrDesc.h" |
| 32 | #include "llvm/MC/MCRegisterInfo.h" |
| 33 | #include "llvm/Support/BranchProbability.h" |
| 34 | #include "llvm/Support/ErrorHandling.h" |
| 35 | #include "llvm/Support/MathExtras.h" |
| 36 | #include "llvm/Target/TargetInstrInfo.h" |
| 37 | #include "llvm/Target/TargetMachine.h" |
| 38 | #include "llvm/Target/TargetSubtargetInfo.h" |
| 39 | #include <cassert> |
| 40 | #include <cstdint> |
| 41 | #include <iterator> |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 42 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 43 | using namespace llvm; |
| 44 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 45 | #define GET_INSTRINFO_CTOR_DTOR |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 46 | #define GET_INSTRMAP_INFO |
| 47 | #include "SystemZGenInstrInfo.inc" |
| 48 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 49 | // Return a mask with Count low bits set. |
| 50 | static uint64_t allOnes(unsigned int Count) { |
| 51 | return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1; |
| 52 | } |
| 53 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 54 | // Reg should be a 32-bit GPR. Return true if it is a high register rather |
| 55 | // than a low register. |
| 56 | static bool isHighReg(unsigned int Reg) { |
| 57 | if (SystemZ::GRH32BitRegClass.contains(Reg)) |
| 58 | return true; |
| 59 | assert(SystemZ::GR32BitRegClass.contains(Reg) && "Invalid GRX32"); |
| 60 | return false; |
| 61 | } |
| 62 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 63 | // Pin the vtable to this file. |
| 64 | void SystemZInstrInfo::anchor() {} |
| 65 | |
Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 66 | SystemZInstrInfo::SystemZInstrInfo(SystemZSubtarget &sti) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 67 | : SystemZGenInstrInfo(SystemZ::ADJCALLSTACKDOWN, SystemZ::ADJCALLSTACKUP), |
Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 68 | RI(), STI(sti) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | // MI is a 128-bit load or store. Split it into two 64-bit loads or stores, |
| 72 | // each having the opcode given by NewOpcode. |
| 73 | void SystemZInstrInfo::splitMove(MachineBasicBlock::iterator MI, |
| 74 | unsigned NewOpcode) const { |
| 75 | MachineBasicBlock *MBB = MI->getParent(); |
| 76 | MachineFunction &MF = *MBB->getParent(); |
| 77 | |
| 78 | // Get two load or store instructions. Use the original instruction for one |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 79 | // of them (arbitrarily the second here) and create a clone for the other. |
Duncan P. N. Exon Smith | 4565ec0 | 2016-07-12 01:39:01 +0000 | [diff] [blame] | 80 | MachineInstr *EarlierMI = MF.CloneMachineInstr(&*MI); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 81 | MBB->insert(MI, EarlierMI); |
| 82 | |
| 83 | // Set up the two 64-bit registers. |
| 84 | MachineOperand &HighRegOp = EarlierMI->getOperand(0); |
| 85 | MachineOperand &LowRegOp = MI->getOperand(0); |
Richard Sandiford | 87a4436 | 2013-09-30 10:28:35 +0000 | [diff] [blame] | 86 | HighRegOp.setReg(RI.getSubReg(HighRegOp.getReg(), SystemZ::subreg_h64)); |
| 87 | LowRegOp.setReg(RI.getSubReg(LowRegOp.getReg(), SystemZ::subreg_l64)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 88 | |
| 89 | // The address in the first (high) instruction is already correct. |
| 90 | // Adjust the offset in the second (low) instruction. |
| 91 | MachineOperand &HighOffsetOp = EarlierMI->getOperand(2); |
| 92 | MachineOperand &LowOffsetOp = MI->getOperand(2); |
| 93 | LowOffsetOp.setImm(LowOffsetOp.getImm() + 8); |
| 94 | |
Jonas Paulsson | 2ba3152 | 2016-03-31 08:00:14 +0000 | [diff] [blame] | 95 | // Clear the kill flags for the base and index registers in the first |
| 96 | // instruction. |
Jonas Paulsson | 63a2b68 | 2015-10-10 07:14:24 +0000 | [diff] [blame] | 97 | EarlierMI->getOperand(1).setIsKill(false); |
Jonas Paulsson | 7da3820 | 2015-10-26 15:03:41 +0000 | [diff] [blame] | 98 | EarlierMI->getOperand(3).setIsKill(false); |
Jonas Paulsson | 63a2b68 | 2015-10-10 07:14:24 +0000 | [diff] [blame] | 99 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 100 | // Set the opcodes. |
| 101 | unsigned HighOpcode = getOpcodeForOffset(NewOpcode, HighOffsetOp.getImm()); |
| 102 | unsigned LowOpcode = getOpcodeForOffset(NewOpcode, LowOffsetOp.getImm()); |
| 103 | assert(HighOpcode && LowOpcode && "Both offsets should be in range"); |
| 104 | |
| 105 | EarlierMI->setDesc(get(HighOpcode)); |
| 106 | MI->setDesc(get(LowOpcode)); |
| 107 | } |
| 108 | |
| 109 | // Split ADJDYNALLOC instruction MI. |
| 110 | void SystemZInstrInfo::splitAdjDynAlloc(MachineBasicBlock::iterator MI) const { |
| 111 | MachineBasicBlock *MBB = MI->getParent(); |
| 112 | MachineFunction &MF = *MBB->getParent(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 113 | MachineFrameInfo &MFFrame = MF.getFrameInfo(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 114 | MachineOperand &OffsetMO = MI->getOperand(2); |
| 115 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 116 | uint64_t Offset = (MFFrame.getMaxCallFrameSize() + |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 117 | SystemZMC::CallFrameSize + |
| 118 | OffsetMO.getImm()); |
| 119 | unsigned NewOpcode = getOpcodeForOffset(SystemZ::LA, Offset); |
| 120 | assert(NewOpcode && "No support for huge argument lists yet"); |
| 121 | MI->setDesc(get(NewOpcode)); |
| 122 | OffsetMO.setImm(Offset); |
| 123 | } |
| 124 | |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 125 | // MI is an RI-style pseudo instruction. Replace it with LowOpcode |
| 126 | // if the first operand is a low GR32 and HighOpcode if the first operand |
| 127 | // is a high GR32. ConvertHigh is true if LowOpcode takes a signed operand |
| 128 | // and HighOpcode takes an unsigned 32-bit operand. In those cases, |
| 129 | // MI has the same kind of operand as LowOpcode, so needs to be converted |
| 130 | // if HighOpcode is used. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 131 | void SystemZInstrInfo::expandRIPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 132 | unsigned HighOpcode, |
| 133 | bool ConvertHigh) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 134 | unsigned Reg = MI.getOperand(0).getReg(); |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 135 | bool IsHigh = isHighReg(Reg); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 136 | MI.setDesc(get(IsHigh ? HighOpcode : LowOpcode)); |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 137 | if (IsHigh && ConvertHigh) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 138 | MI.getOperand(1).setImm(uint32_t(MI.getOperand(1).getImm())); |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 141 | // MI is a three-operand RIE-style pseudo instruction. Replace it with |
Jonas Paulsson | 18d877f | 2015-10-09 07:19:16 +0000 | [diff] [blame] | 142 | // LowOpcodeK if the registers are both low GR32s, otherwise use a move |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 143 | // followed by HighOpcode or LowOpcode, depending on whether the target |
| 144 | // is a high or low GR32. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 145 | void SystemZInstrInfo::expandRIEPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 146 | unsigned LowOpcodeK, |
| 147 | unsigned HighOpcode) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 148 | unsigned DestReg = MI.getOperand(0).getReg(); |
| 149 | unsigned SrcReg = MI.getOperand(1).getReg(); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 150 | bool DestIsHigh = isHighReg(DestReg); |
| 151 | bool SrcIsHigh = isHighReg(SrcReg); |
| 152 | if (!DestIsHigh && !SrcIsHigh) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 153 | MI.setDesc(get(LowOpcodeK)); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 154 | else { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 155 | emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(), DestReg, SrcReg, |
Jonas Paulsson | a9bb00d | 2017-01-18 08:32:54 +0000 | [diff] [blame] | 156 | SystemZ::LR, 32, MI.getOperand(1).isKill(), |
| 157 | MI.getOperand(1).isUndef()); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 158 | MI.setDesc(get(DestIsHigh ? HighOpcode : LowOpcode)); |
| 159 | MI.getOperand(1).setReg(DestReg); |
| 160 | MI.tieOperands(0, 1); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 164 | // MI is an RXY-style pseudo instruction. Replace it with LowOpcode |
| 165 | // if the first operand is a low GR32 and HighOpcode if the first operand |
| 166 | // is a high GR32. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 167 | void SystemZInstrInfo::expandRXYPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 168 | unsigned HighOpcode) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 169 | unsigned Reg = MI.getOperand(0).getReg(); |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 170 | unsigned Opcode = getOpcodeForOffset(isHighReg(Reg) ? HighOpcode : LowOpcode, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 171 | MI.getOperand(2).getImm()); |
| 172 | MI.setDesc(get(Opcode)); |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 175 | // MI is a load-on-condition pseudo instruction with a single register |
| 176 | // (source or destination) operand. Replace it with LowOpcode if the |
| 177 | // register is a low GR32 and HighOpcode if the register is a high GR32. |
| 178 | void SystemZInstrInfo::expandLOCPseudo(MachineInstr &MI, unsigned LowOpcode, |
| 179 | unsigned HighOpcode) const { |
| 180 | unsigned Reg = MI.getOperand(0).getReg(); |
| 181 | unsigned Opcode = isHighReg(Reg) ? HighOpcode : LowOpcode; |
| 182 | MI.setDesc(get(Opcode)); |
| 183 | } |
| 184 | |
| 185 | // MI is a load-register-on-condition pseudo instruction. Replace it with |
| 186 | // LowOpcode if source and destination are both low GR32s and HighOpcode if |
| 187 | // source and destination are both high GR32s. |
| 188 | void SystemZInstrInfo::expandLOCRPseudo(MachineInstr &MI, unsigned LowOpcode, |
| 189 | unsigned HighOpcode) const { |
| 190 | unsigned DestReg = MI.getOperand(0).getReg(); |
| 191 | unsigned SrcReg = MI.getOperand(2).getReg(); |
| 192 | bool DestIsHigh = isHighReg(DestReg); |
| 193 | bool SrcIsHigh = isHighReg(SrcReg); |
| 194 | |
| 195 | if (!DestIsHigh && !SrcIsHigh) |
| 196 | MI.setDesc(get(LowOpcode)); |
| 197 | else if (DestIsHigh && SrcIsHigh) |
| 198 | MI.setDesc(get(HighOpcode)); |
| 199 | |
| 200 | // If we were unable to implement the pseudo with a single instruction, we |
| 201 | // need to convert it back into a branch sequence. This cannot be done here |
| 202 | // since the caller of expandPostRAPseudo does not handle changes to the CFG |
| 203 | // correctly. This change is defered to the SystemZExpandPseudo pass. |
| 204 | } |
| 205 | |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 206 | // MI is an RR-style pseudo instruction that zero-extends the low Size bits |
| 207 | // of one GRX32 into another. Replace it with LowOpcode if both operands |
| 208 | // are low registers, otherwise use RISB[LH]G. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 209 | void SystemZInstrInfo::expandZExtPseudo(MachineInstr &MI, unsigned LowOpcode, |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 210 | unsigned Size) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 211 | emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(), |
| 212 | MI.getOperand(0).getReg(), MI.getOperand(1).getReg(), LowOpcode, |
Jonas Paulsson | a9bb00d | 2017-01-18 08:32:54 +0000 | [diff] [blame] | 213 | Size, MI.getOperand(1).isKill(), MI.getOperand(1).isUndef()); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 214 | MI.eraseFromParent(); |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 217 | void SystemZInstrInfo::expandLoadStackGuard(MachineInstr *MI) const { |
| 218 | MachineBasicBlock *MBB = MI->getParent(); |
| 219 | MachineFunction &MF = *MBB->getParent(); |
| 220 | const unsigned Reg = MI->getOperand(0).getReg(); |
| 221 | |
| 222 | // Conveniently, all 4 instructions are cloned from LOAD_STACK_GUARD, |
| 223 | // so they already have operand 0 set to reg. |
| 224 | |
| 225 | // ear <reg>, %a0 |
| 226 | MachineInstr *Ear1MI = MF.CloneMachineInstr(MI); |
| 227 | MBB->insert(MI, Ear1MI); |
| 228 | Ear1MI->setDesc(get(SystemZ::EAR)); |
Ulrich Weigand | fffc711 | 2016-11-08 20:15:26 +0000 | [diff] [blame] | 229 | MachineInstrBuilder(MF, Ear1MI).addReg(SystemZ::A0); |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 230 | |
| 231 | // sllg <reg>, <reg>, 32 |
| 232 | MachineInstr *SllgMI = MF.CloneMachineInstr(MI); |
| 233 | MBB->insert(MI, SllgMI); |
| 234 | SllgMI->setDesc(get(SystemZ::SLLG)); |
| 235 | MachineInstrBuilder(MF, SllgMI).addReg(Reg).addReg(0).addImm(32); |
| 236 | |
| 237 | // ear <reg>, %a1 |
| 238 | MachineInstr *Ear2MI = MF.CloneMachineInstr(MI); |
| 239 | MBB->insert(MI, Ear2MI); |
| 240 | Ear2MI->setDesc(get(SystemZ::EAR)); |
Ulrich Weigand | fffc711 | 2016-11-08 20:15:26 +0000 | [diff] [blame] | 241 | MachineInstrBuilder(MF, Ear2MI).addReg(SystemZ::A1); |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 242 | |
| 243 | // lg <reg>, 40(<reg>) |
| 244 | MI->setDesc(get(SystemZ::LG)); |
| 245 | MachineInstrBuilder(MF, MI).addReg(Reg).addImm(40).addReg(0); |
| 246 | } |
| 247 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 248 | // Emit a zero-extending move from 32-bit GPR SrcReg to 32-bit GPR |
| 249 | // DestReg before MBBI in MBB. Use LowLowOpcode when both DestReg and SrcReg |
| 250 | // are low registers, otherwise use RISB[LH]G. Size is the number of bits |
| 251 | // taken from the low end of SrcReg (8 for LLCR, 16 for LLHR and 32 for LR). |
| 252 | // KillSrc is true if this move is the last use of SrcReg. |
| 253 | void SystemZInstrInfo::emitGRX32Move(MachineBasicBlock &MBB, |
| 254 | MachineBasicBlock::iterator MBBI, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 255 | const DebugLoc &DL, unsigned DestReg, |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 256 | unsigned SrcReg, unsigned LowLowOpcode, |
Jonas Paulsson | a9bb00d | 2017-01-18 08:32:54 +0000 | [diff] [blame] | 257 | unsigned Size, bool KillSrc, |
| 258 | bool UndefSrc) const { |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 259 | unsigned Opcode; |
| 260 | bool DestIsHigh = isHighReg(DestReg); |
| 261 | bool SrcIsHigh = isHighReg(SrcReg); |
| 262 | if (DestIsHigh && SrcIsHigh) |
| 263 | Opcode = SystemZ::RISBHH; |
| 264 | else if (DestIsHigh && !SrcIsHigh) |
| 265 | Opcode = SystemZ::RISBHL; |
| 266 | else if (!DestIsHigh && SrcIsHigh) |
| 267 | Opcode = SystemZ::RISBLH; |
| 268 | else { |
| 269 | BuildMI(MBB, MBBI, DL, get(LowLowOpcode), DestReg) |
Jonas Paulsson | a9bb00d | 2017-01-18 08:32:54 +0000 | [diff] [blame] | 270 | .addReg(SrcReg, getKillRegState(KillSrc) | getUndefRegState(UndefSrc)); |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | unsigned Rotate = (DestIsHigh != SrcIsHigh ? 32 : 0); |
| 274 | BuildMI(MBB, MBBI, DL, get(Opcode), DestReg) |
| 275 | .addReg(DestReg, RegState::Undef) |
Jonas Paulsson | a9bb00d | 2017-01-18 08:32:54 +0000 | [diff] [blame] | 276 | .addReg(SrcReg, getKillRegState(KillSrc) | getUndefRegState(UndefSrc)) |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 277 | .addImm(32 - Size).addImm(128 + 31).addImm(Rotate); |
| 278 | } |
| 279 | |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 280 | MachineInstr *SystemZInstrInfo::commuteInstructionImpl(MachineInstr &MI, |
| 281 | bool NewMI, |
| 282 | unsigned OpIdx1, |
| 283 | unsigned OpIdx2) const { |
| 284 | auto cloneIfNew = [NewMI](MachineInstr &MI) -> MachineInstr & { |
| 285 | if (NewMI) |
| 286 | return *MI.getParent()->getParent()->CloneMachineInstr(&MI); |
| 287 | return MI; |
| 288 | }; |
| 289 | |
| 290 | switch (MI.getOpcode()) { |
| 291 | case SystemZ::LOCRMux: |
| 292 | case SystemZ::LOCFHR: |
| 293 | case SystemZ::LOCR: |
| 294 | case SystemZ::LOCGR: { |
| 295 | auto &WorkingMI = cloneIfNew(MI); |
| 296 | // Invert condition. |
| 297 | unsigned CCValid = WorkingMI.getOperand(3).getImm(); |
| 298 | unsigned CCMask = WorkingMI.getOperand(4).getImm(); |
| 299 | WorkingMI.getOperand(4).setImm(CCMask ^ CCValid); |
| 300 | return TargetInstrInfo::commuteInstructionImpl(WorkingMI, /*NewMI=*/false, |
| 301 | OpIdx1, OpIdx2); |
| 302 | } |
| 303 | default: |
| 304 | return TargetInstrInfo::commuteInstructionImpl(MI, NewMI, OpIdx1, OpIdx2); |
| 305 | } |
| 306 | } |
| 307 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 308 | // If MI is a simple load or store for a frame object, return the register |
| 309 | // it loads or stores and set FrameIndex to the index of the frame object. |
| 310 | // Return 0 otherwise. |
| 311 | // |
| 312 | // Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 313 | static int isSimpleMove(const MachineInstr &MI, int &FrameIndex, |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 314 | unsigned Flag) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 315 | const MCInstrDesc &MCID = MI.getDesc(); |
| 316 | if ((MCID.TSFlags & Flag) && MI.getOperand(1).isFI() && |
| 317 | MI.getOperand(2).getImm() == 0 && MI.getOperand(3).getReg() == 0) { |
| 318 | FrameIndex = MI.getOperand(1).getIndex(); |
| 319 | return MI.getOperand(0).getReg(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 320 | } |
| 321 | return 0; |
| 322 | } |
| 323 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 324 | unsigned SystemZInstrInfo::isLoadFromStackSlot(const MachineInstr &MI, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 325 | int &FrameIndex) const { |
| 326 | return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXLoad); |
| 327 | } |
| 328 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 329 | unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr &MI, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 330 | int &FrameIndex) const { |
| 331 | return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXStore); |
| 332 | } |
| 333 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 334 | bool SystemZInstrInfo::isStackSlotCopy(const MachineInstr &MI, |
Richard Sandiford | c40f27b | 2013-07-05 14:38:48 +0000 | [diff] [blame] | 335 | int &DestFrameIndex, |
| 336 | int &SrcFrameIndex) const { |
| 337 | // Check for MVC 0(Length,FI1),0(FI2) |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 338 | const MachineFrameInfo &MFI = MI.getParent()->getParent()->getFrameInfo(); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 339 | if (MI.getOpcode() != SystemZ::MVC || !MI.getOperand(0).isFI() || |
| 340 | MI.getOperand(1).getImm() != 0 || !MI.getOperand(3).isFI() || |
| 341 | MI.getOperand(4).getImm() != 0) |
Richard Sandiford | c40f27b | 2013-07-05 14:38:48 +0000 | [diff] [blame] | 342 | return false; |
| 343 | |
| 344 | // Check that Length covers the full slots. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 345 | int64_t Length = MI.getOperand(2).getImm(); |
| 346 | unsigned FI1 = MI.getOperand(0).getIndex(); |
| 347 | unsigned FI2 = MI.getOperand(3).getIndex(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 348 | if (MFI.getObjectSize(FI1) != Length || |
| 349 | MFI.getObjectSize(FI2) != Length) |
Richard Sandiford | c40f27b | 2013-07-05 14:38:48 +0000 | [diff] [blame] | 350 | return false; |
| 351 | |
| 352 | DestFrameIndex = FI1; |
| 353 | SrcFrameIndex = FI2; |
| 354 | return true; |
| 355 | } |
| 356 | |
Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 357 | bool SystemZInstrInfo::analyzeBranch(MachineBasicBlock &MBB, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 358 | MachineBasicBlock *&TBB, |
| 359 | MachineBasicBlock *&FBB, |
| 360 | SmallVectorImpl<MachineOperand> &Cond, |
| 361 | bool AllowModify) const { |
| 362 | // Most of the code and comments here are boilerplate. |
| 363 | |
| 364 | // Start from the bottom of the block and work up, examining the |
| 365 | // terminator instructions. |
| 366 | MachineBasicBlock::iterator I = MBB.end(); |
| 367 | while (I != MBB.begin()) { |
| 368 | --I; |
| 369 | if (I->isDebugValue()) |
| 370 | continue; |
| 371 | |
| 372 | // Working from the bottom, when we see a non-terminator instruction, we're |
| 373 | // done. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 374 | if (!isUnpredicatedTerminator(*I)) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 375 | break; |
| 376 | |
| 377 | // A terminator that isn't a branch can't easily be handled by this |
| 378 | // analysis. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 379 | if (!I->isBranch()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 380 | return true; |
| 381 | |
| 382 | // Can't handle indirect branches. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 383 | SystemZII::Branch Branch(getBranchInfo(*I)); |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 384 | if (!Branch.Target->isMBB()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 385 | return true; |
| 386 | |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 387 | // Punt on compound branches. |
| 388 | if (Branch.Type != SystemZII::BranchNormal) |
| 389 | return true; |
| 390 | |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 391 | if (Branch.CCMask == SystemZ::CCMASK_ANY) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 392 | // Handle unconditional branches. |
| 393 | if (!AllowModify) { |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 394 | TBB = Branch.Target->getMBB(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 395 | continue; |
| 396 | } |
| 397 | |
| 398 | // If the block has any instructions after a JMP, delete them. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 399 | while (std::next(I) != MBB.end()) |
| 400 | std::next(I)->eraseFromParent(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 401 | |
| 402 | Cond.clear(); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 403 | FBB = nullptr; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 404 | |
| 405 | // Delete the JMP if it's equivalent to a fall-through. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 406 | if (MBB.isLayoutSuccessor(Branch.Target->getMBB())) { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 407 | TBB = nullptr; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 408 | I->eraseFromParent(); |
| 409 | I = MBB.end(); |
| 410 | continue; |
| 411 | } |
| 412 | |
| 413 | // TBB is used to indicate the unconditinal destination. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 414 | TBB = Branch.Target->getMBB(); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 415 | continue; |
| 416 | } |
| 417 | |
| 418 | // Working from the bottom, handle the first conditional branch. |
| 419 | if (Cond.empty()) { |
| 420 | // FIXME: add X86-style branch swap |
| 421 | FBB = TBB; |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 422 | TBB = Branch.Target->getMBB(); |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 423 | Cond.push_back(MachineOperand::CreateImm(Branch.CCValid)); |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 424 | Cond.push_back(MachineOperand::CreateImm(Branch.CCMask)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 425 | continue; |
| 426 | } |
| 427 | |
| 428 | // Handle subsequent conditional branches. |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 429 | assert(Cond.size() == 2 && TBB && "Should have seen a conditional branch"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 430 | |
| 431 | // Only handle the case where all conditional branches branch to the same |
| 432 | // destination. |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 433 | if (TBB != Branch.Target->getMBB()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 434 | return true; |
| 435 | |
| 436 | // If the conditions are the same, we can leave them alone. |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 437 | unsigned OldCCValid = Cond[0].getImm(); |
| 438 | unsigned OldCCMask = Cond[1].getImm(); |
| 439 | if (OldCCValid == Branch.CCValid && OldCCMask == Branch.CCMask) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 440 | continue; |
| 441 | |
| 442 | // FIXME: Try combining conditions like X86 does. Should be easy on Z! |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 443 | return false; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | return false; |
| 447 | } |
| 448 | |
Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 449 | unsigned SystemZInstrInfo::removeBranch(MachineBasicBlock &MBB, |
Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 450 | int *BytesRemoved) const { |
| 451 | assert(!BytesRemoved && "code size not handled"); |
| 452 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 453 | // Most of the code and comments here are boilerplate. |
| 454 | MachineBasicBlock::iterator I = MBB.end(); |
| 455 | unsigned Count = 0; |
| 456 | |
| 457 | while (I != MBB.begin()) { |
| 458 | --I; |
| 459 | if (I->isDebugValue()) |
| 460 | continue; |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 461 | if (!I->isBranch()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 462 | break; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 463 | if (!getBranchInfo(*I).Target->isMBB()) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 464 | break; |
| 465 | // Remove the branch. |
| 466 | I->eraseFromParent(); |
| 467 | I = MBB.end(); |
| 468 | ++Count; |
| 469 | } |
| 470 | |
| 471 | return Count; |
| 472 | } |
| 473 | |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 474 | bool SystemZInstrInfo:: |
Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 475 | reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 476 | assert(Cond.size() == 2 && "Invalid condition"); |
| 477 | Cond[1].setImm(Cond[1].getImm() ^ Cond[0].getImm()); |
| 478 | return false; |
| 479 | } |
| 480 | |
Matt Arsenault | e8e0f5c | 2016-09-14 17:24:15 +0000 | [diff] [blame] | 481 | unsigned SystemZInstrInfo::insertBranch(MachineBasicBlock &MBB, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 482 | MachineBasicBlock *TBB, |
| 483 | MachineBasicBlock *FBB, |
| 484 | ArrayRef<MachineOperand> Cond, |
Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 485 | const DebugLoc &DL, |
| 486 | int *BytesAdded) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 487 | // In this function we output 32-bit branches, which should always |
| 488 | // have enough range. They can be shortened and relaxed by later code |
| 489 | // in the pipeline, if desired. |
| 490 | |
| 491 | // Shouldn't be a fall through. |
Matt Arsenault | e8e0f5c | 2016-09-14 17:24:15 +0000 | [diff] [blame] | 492 | assert(TBB && "insertBranch must not be told to insert a fallthrough"); |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 493 | assert((Cond.size() == 2 || Cond.size() == 0) && |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 494 | "SystemZ branch conditions have one component!"); |
Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 495 | assert(!BytesAdded && "code size not handled"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 496 | |
| 497 | if (Cond.empty()) { |
| 498 | // Unconditional branch? |
| 499 | assert(!FBB && "Unconditional branch with multiple successors!"); |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 500 | BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(TBB); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 501 | return 1; |
| 502 | } |
| 503 | |
| 504 | // Conditional branch. |
| 505 | unsigned Count = 0; |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 506 | unsigned CCValid = Cond[0].getImm(); |
| 507 | unsigned CCMask = Cond[1].getImm(); |
| 508 | BuildMI(&MBB, DL, get(SystemZ::BRC)) |
| 509 | .addImm(CCValid).addImm(CCMask).addMBB(TBB); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 510 | ++Count; |
| 511 | |
| 512 | if (FBB) { |
| 513 | // Two-way Conditional branch. Insert the second branch. |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 514 | BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(FBB); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 515 | ++Count; |
| 516 | } |
| 517 | return Count; |
| 518 | } |
| 519 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 520 | bool SystemZInstrInfo::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg, |
| 521 | unsigned &SrcReg2, int &Mask, |
| 522 | int &Value) const { |
| 523 | assert(MI.isCompare() && "Caller should have checked for a comparison"); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 524 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 525 | if (MI.getNumExplicitOperands() == 2 && MI.getOperand(0).isReg() && |
| 526 | MI.getOperand(1).isImm()) { |
| 527 | SrcReg = MI.getOperand(0).getReg(); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 528 | SrcReg2 = 0; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 529 | Value = MI.getOperand(1).getImm(); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 530 | Mask = ~0; |
| 531 | return true; |
| 532 | } |
| 533 | |
| 534 | return false; |
| 535 | } |
| 536 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 537 | // If Reg is a virtual register, return its definition, otherwise return null. |
| 538 | static MachineInstr *getDef(unsigned Reg, |
| 539 | const MachineRegisterInfo *MRI) { |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 540 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 541 | return nullptr; |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 542 | return MRI->getUniqueVRegDef(Reg); |
| 543 | } |
| 544 | |
| 545 | // Return true if MI is a shift of type Opcode by Imm bits. |
Matthias Braun | fa3872e | 2015-05-18 20:27:55 +0000 | [diff] [blame] | 546 | static bool isShift(MachineInstr *MI, unsigned Opcode, int64_t Imm) { |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 547 | return (MI->getOpcode() == Opcode && |
| 548 | !MI->getOperand(2).getReg() && |
| 549 | MI->getOperand(3).getImm() == Imm); |
| 550 | } |
| 551 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 552 | // If the destination of MI has no uses, delete it as dead. |
| 553 | static void eraseIfDead(MachineInstr *MI, const MachineRegisterInfo *MRI) { |
| 554 | if (MRI->use_nodbg_empty(MI->getOperand(0).getReg())) |
| 555 | MI->eraseFromParent(); |
| 556 | } |
| 557 | |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 558 | // Compare compares SrcReg against zero. Check whether SrcReg contains |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 559 | // the result of an IPM sequence whose input CC survives until Compare, |
| 560 | // and whether Compare is therefore redundant. Delete it and return |
| 561 | // true if so. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 562 | static bool removeIPMBasedCompare(MachineInstr &Compare, unsigned SrcReg, |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 563 | const MachineRegisterInfo *MRI, |
| 564 | const TargetRegisterInfo *TRI) { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 565 | MachineInstr *LGFR = nullptr; |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 566 | MachineInstr *RLL = getDef(SrcReg, MRI); |
Richard Sandiford | e382775 | 2013-08-16 10:55:47 +0000 | [diff] [blame] | 567 | if (RLL && RLL->getOpcode() == SystemZ::LGFR) { |
| 568 | LGFR = RLL; |
| 569 | RLL = getDef(LGFR->getOperand(1).getReg(), MRI); |
| 570 | } |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 571 | if (!RLL || !isShift(RLL, SystemZ::RLL, 31)) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 572 | return false; |
| 573 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 574 | MachineInstr *SRL = getDef(RLL->getOperand(1).getReg(), MRI); |
Richard Sandiford | f722a8e30 | 2013-10-16 11:10:55 +0000 | [diff] [blame] | 575 | if (!SRL || !isShift(SRL, SystemZ::SRL, SystemZ::IPM_CC)) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 576 | return false; |
| 577 | |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 578 | MachineInstr *IPM = getDef(SRL->getOperand(1).getReg(), MRI); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 579 | if (!IPM || IPM->getOpcode() != SystemZ::IPM) |
| 580 | return false; |
| 581 | |
| 582 | // Check that there are no assignments to CC between the IPM and Compare, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 583 | if (IPM->getParent() != Compare.getParent()) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 584 | return false; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 585 | MachineBasicBlock::iterator MBBI = IPM, MBBE = Compare.getIterator(); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 586 | for (++MBBI; MBBI != MBBE; ++MBBI) { |
Duncan P. N. Exon Smith | 4565ec0 | 2016-07-12 01:39:01 +0000 | [diff] [blame] | 587 | MachineInstr &MI = *MBBI; |
| 588 | if (MI.modifiesRegister(SystemZ::CC, TRI)) |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 589 | return false; |
| 590 | } |
| 591 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 592 | Compare.eraseFromParent(); |
Richard Sandiford | e382775 | 2013-08-16 10:55:47 +0000 | [diff] [blame] | 593 | if (LGFR) |
| 594 | eraseIfDead(LGFR, MRI); |
Richard Sandiford | a590125 | 2013-08-16 10:22:54 +0000 | [diff] [blame] | 595 | eraseIfDead(RLL, MRI); |
| 596 | eraseIfDead(SRL, MRI); |
| 597 | eraseIfDead(IPM, MRI); |
| 598 | |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 599 | return true; |
| 600 | } |
| 601 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 602 | bool SystemZInstrInfo::optimizeCompareInstr( |
| 603 | MachineInstr &Compare, unsigned SrcReg, unsigned SrcReg2, int Mask, |
| 604 | int Value, const MachineRegisterInfo *MRI) const { |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 605 | assert(!SrcReg2 && "Only optimizing constant comparisons so far"); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 606 | bool IsLogical = (Compare.getDesc().TSFlags & SystemZII::IsLogical) != 0; |
Ulrich Weigand | 19d24d2 | 2015-11-13 13:00:27 +0000 | [diff] [blame] | 607 | return Value == 0 && !IsLogical && |
| 608 | removeIPMBasedCompare(Compare, SrcReg, MRI, &RI); |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 611 | bool SystemZInstrInfo::canInsertSelect(const MachineBasicBlock &MBB, |
| 612 | ArrayRef<MachineOperand> Pred, |
| 613 | unsigned TrueReg, unsigned FalseReg, |
| 614 | int &CondCycles, int &TrueCycles, |
| 615 | int &FalseCycles) const { |
| 616 | // Not all subtargets have LOCR instructions. |
| 617 | if (!STI.hasLoadStoreOnCond()) |
| 618 | return false; |
| 619 | if (Pred.size() != 2) |
| 620 | return false; |
| 621 | |
| 622 | // Check register classes. |
| 623 | const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); |
| 624 | const TargetRegisterClass *RC = |
| 625 | RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg)); |
| 626 | if (!RC) |
| 627 | return false; |
| 628 | |
| 629 | // We have LOCR instructions for 32 and 64 bit general purpose registers. |
| 630 | if ((STI.hasLoadStoreOnCond2() && |
| 631 | SystemZ::GRX32BitRegClass.hasSubClassEq(RC)) || |
| 632 | SystemZ::GR32BitRegClass.hasSubClassEq(RC) || |
| 633 | SystemZ::GR64BitRegClass.hasSubClassEq(RC)) { |
| 634 | CondCycles = 2; |
| 635 | TrueCycles = 2; |
| 636 | FalseCycles = 2; |
| 637 | return true; |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 638 | } |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 639 | |
| 640 | // Can't do anything else. |
| 641 | return false; |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 644 | void SystemZInstrInfo::insertSelect(MachineBasicBlock &MBB, |
| 645 | MachineBasicBlock::iterator I, |
| 646 | const DebugLoc &DL, unsigned DstReg, |
| 647 | ArrayRef<MachineOperand> Pred, |
| 648 | unsigned TrueReg, |
| 649 | unsigned FalseReg) const { |
| 650 | MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); |
| 651 | const TargetRegisterClass *RC = MRI.getRegClass(DstReg); |
| 652 | |
| 653 | assert(Pred.size() == 2 && "Invalid condition"); |
| 654 | unsigned CCValid = Pred[0].getImm(); |
| 655 | unsigned CCMask = Pred[1].getImm(); |
| 656 | |
| 657 | unsigned Opc; |
| 658 | if (SystemZ::GRX32BitRegClass.hasSubClassEq(RC)) { |
| 659 | if (STI.hasLoadStoreOnCond2()) |
| 660 | Opc = SystemZ::LOCRMux; |
| 661 | else { |
| 662 | Opc = SystemZ::LOCR; |
| 663 | MRI.constrainRegClass(DstReg, &SystemZ::GR32BitRegClass); |
| 664 | } |
| 665 | } else if (SystemZ::GR64BitRegClass.hasSubClassEq(RC)) |
| 666 | Opc = SystemZ::LOCGR; |
| 667 | else |
| 668 | llvm_unreachable("Invalid register class"); |
| 669 | |
| 670 | BuildMI(MBB, I, DL, get(Opc), DstReg) |
| 671 | .addReg(FalseReg).addReg(TrueReg) |
| 672 | .addImm(CCValid).addImm(CCMask); |
| 673 | } |
| 674 | |
| 675 | bool SystemZInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, |
| 676 | unsigned Reg, |
| 677 | MachineRegisterInfo *MRI) const { |
| 678 | unsigned DefOpc = DefMI.getOpcode(); |
| 679 | if (DefOpc != SystemZ::LHIMux && DefOpc != SystemZ::LHI && |
| 680 | DefOpc != SystemZ::LGHI) |
| 681 | return false; |
| 682 | if (DefMI.getOperand(0).getReg() != Reg) |
| 683 | return false; |
| 684 | int32_t ImmVal = (int32_t)DefMI.getOperand(1).getImm(); |
| 685 | |
| 686 | unsigned UseOpc = UseMI.getOpcode(); |
| 687 | unsigned NewUseOpc; |
| 688 | unsigned UseIdx; |
| 689 | int CommuteIdx = -1; |
| 690 | switch (UseOpc) { |
| 691 | case SystemZ::LOCRMux: |
| 692 | if (!STI.hasLoadStoreOnCond2()) |
| 693 | return false; |
| 694 | NewUseOpc = SystemZ::LOCHIMux; |
| 695 | if (UseMI.getOperand(2).getReg() == Reg) |
| 696 | UseIdx = 2; |
| 697 | else if (UseMI.getOperand(1).getReg() == Reg) |
| 698 | UseIdx = 2, CommuteIdx = 1; |
| 699 | else |
| 700 | return false; |
| 701 | break; |
| 702 | case SystemZ::LOCGR: |
| 703 | if (!STI.hasLoadStoreOnCond2()) |
| 704 | return false; |
| 705 | NewUseOpc = SystemZ::LOCGHI; |
| 706 | if (UseMI.getOperand(2).getReg() == Reg) |
| 707 | UseIdx = 2; |
| 708 | else if (UseMI.getOperand(1).getReg() == Reg) |
| 709 | UseIdx = 2, CommuteIdx = 1; |
| 710 | else |
| 711 | return false; |
| 712 | break; |
| 713 | default: |
| 714 | return false; |
Zhan Jun Liau | def708a | 2016-07-11 18:45:03 +0000 | [diff] [blame] | 715 | } |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 716 | |
| 717 | if (CommuteIdx != -1) |
| 718 | if (!commuteInstruction(UseMI, false, CommuteIdx, UseIdx)) |
| 719 | return false; |
| 720 | |
| 721 | bool DeleteDef = MRI->hasOneNonDBGUse(Reg); |
| 722 | UseMI.setDesc(get(NewUseOpc)); |
| 723 | UseMI.getOperand(UseIdx).ChangeToImmediate(ImmVal); |
| 724 | if (DeleteDef) |
| 725 | DefMI.eraseFromParent(); |
| 726 | |
| 727 | return true; |
Zhan Jun Liau | def708a | 2016-07-11 18:45:03 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Krzysztof Parzyszek | cc31871 | 2017-03-03 18:30:54 +0000 | [diff] [blame^] | 730 | bool SystemZInstrInfo::isPredicable(const MachineInstr &MI) const { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 731 | unsigned Opcode = MI.getOpcode(); |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 732 | if (Opcode == SystemZ::Return || |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 733 | Opcode == SystemZ::Trap || |
Ulrich Weigand | 848a513 | 2016-04-11 12:12:32 +0000 | [diff] [blame] | 734 | Opcode == SystemZ::CallJG || |
| 735 | Opcode == SystemZ::CallBR) |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 736 | return true; |
| 737 | return false; |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | bool SystemZInstrInfo:: |
| 741 | isProfitableToIfCvt(MachineBasicBlock &MBB, |
| 742 | unsigned NumCycles, unsigned ExtraPredCycles, |
Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 743 | BranchProbability Probability) const { |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 744 | // Avoid using conditional returns at the end of a loop (since then |
| 745 | // we'd need to emit an unconditional branch to the beginning anyway, |
| 746 | // making the loop body longer). This doesn't apply for low-probability |
| 747 | // loops (eg. compare-and-swap retry), so just decide based on branch |
| 748 | // probability instead of looping structure. |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 749 | // However, since Compare and Trap instructions cost the same as a regular |
| 750 | // Compare instruction, we should allow the if conversion to convert this |
| 751 | // into a Conditional Compare regardless of the branch probability. |
| 752 | if (MBB.getLastNonDebugInstr()->getOpcode() != SystemZ::Trap && |
| 753 | MBB.succ_empty() && Probability < BranchProbability(1, 8)) |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 754 | return false; |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 755 | // For now only convert single instructions. |
| 756 | return NumCycles == 1; |
| 757 | } |
| 758 | |
| 759 | bool SystemZInstrInfo:: |
| 760 | isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 761 | unsigned NumCyclesT, unsigned ExtraPredCyclesT, |
| 762 | MachineBasicBlock &FMBB, |
| 763 | unsigned NumCyclesF, unsigned ExtraPredCyclesF, |
Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 764 | BranchProbability Probability) const { |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 765 | // For now avoid converting mutually-exclusive cases. |
| 766 | return false; |
| 767 | } |
| 768 | |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 769 | bool SystemZInstrInfo:: |
| 770 | isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| 771 | BranchProbability Probability) const { |
| 772 | // For now only duplicate single instructions. |
| 773 | return NumCycles == 1; |
| 774 | } |
| 775 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 776 | bool SystemZInstrInfo::PredicateInstruction( |
| 777 | MachineInstr &MI, ArrayRef<MachineOperand> Pred) const { |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 778 | assert(Pred.size() == 2 && "Invalid condition"); |
| 779 | unsigned CCValid = Pred[0].getImm(); |
| 780 | unsigned CCMask = Pred[1].getImm(); |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 781 | assert(CCMask > 0 && CCMask < 15 && "Invalid predicate"); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 782 | unsigned Opcode = MI.getOpcode(); |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 783 | if (Opcode == SystemZ::Trap) { |
| 784 | MI.setDesc(get(SystemZ::CondTrap)); |
| 785 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 786 | .addImm(CCValid).addImm(CCMask) |
| 787 | .addReg(SystemZ::CC, RegState::Implicit); |
| 788 | return true; |
| 789 | } |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 790 | if (Opcode == SystemZ::Return) { |
| 791 | MI.setDesc(get(SystemZ::CondReturn)); |
| 792 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 793 | .addImm(CCValid).addImm(CCMask) |
| 794 | .addReg(SystemZ::CC, RegState::Implicit); |
| 795 | return true; |
| 796 | } |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 797 | if (Opcode == SystemZ::CallJG) { |
Zhan Jun Liau | a5d60af | 2016-07-07 15:34:46 +0000 | [diff] [blame] | 798 | MachineOperand FirstOp = MI.getOperand(0); |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 799 | const uint32_t *RegMask = MI.getOperand(1).getRegMask(); |
| 800 | MI.RemoveOperand(1); |
| 801 | MI.RemoveOperand(0); |
| 802 | MI.setDesc(get(SystemZ::CallBRCL)); |
| 803 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 804 | .addImm(CCValid) |
| 805 | .addImm(CCMask) |
| 806 | .add(FirstOp) |
| 807 | .addRegMask(RegMask) |
| 808 | .addReg(SystemZ::CC, RegState::Implicit); |
Ulrich Weigand | fa2dffb | 2016-04-08 17:22:19 +0000 | [diff] [blame] | 809 | return true; |
| 810 | } |
Ulrich Weigand | 848a513 | 2016-04-11 12:12:32 +0000 | [diff] [blame] | 811 | if (Opcode == SystemZ::CallBR) { |
| 812 | const uint32_t *RegMask = MI.getOperand(0).getRegMask(); |
| 813 | MI.RemoveOperand(0); |
| 814 | MI.setDesc(get(SystemZ::CallBCR)); |
| 815 | MachineInstrBuilder(*MI.getParent()->getParent(), MI) |
| 816 | .addImm(CCValid).addImm(CCMask) |
| 817 | .addRegMask(RegMask) |
| 818 | .addReg(SystemZ::CC, RegState::Implicit); |
| 819 | return true; |
| 820 | } |
Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 821 | return false; |
| 822 | } |
| 823 | |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 824 | void SystemZInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 825 | MachineBasicBlock::iterator MBBI, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 826 | const DebugLoc &DL, unsigned DestReg, |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 827 | unsigned SrcReg, bool KillSrc) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 828 | // Split 128-bit GPR moves into two 64-bit moves. This handles ADDR128 too. |
| 829 | if (SystemZ::GR128BitRegClass.contains(DestReg, SrcReg)) { |
Richard Sandiford | 87a4436 | 2013-09-30 10:28:35 +0000 | [diff] [blame] | 830 | copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_h64), |
| 831 | RI.getSubReg(SrcReg, SystemZ::subreg_h64), KillSrc); |
| 832 | copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_l64), |
| 833 | RI.getSubReg(SrcReg, SystemZ::subreg_l64), KillSrc); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 834 | return; |
| 835 | } |
| 836 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 837 | if (SystemZ::GRX32BitRegClass.contains(DestReg, SrcReg)) { |
Jonas Paulsson | a9bb00d | 2017-01-18 08:32:54 +0000 | [diff] [blame] | 838 | emitGRX32Move(MBB, MBBI, DL, DestReg, SrcReg, SystemZ::LR, 32, KillSrc, |
| 839 | false); |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 840 | return; |
| 841 | } |
| 842 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 843 | // Everything else needs only one instruction. |
| 844 | unsigned Opcode; |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 845 | if (SystemZ::GR64BitRegClass.contains(DestReg, SrcReg)) |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 846 | Opcode = SystemZ::LGR; |
| 847 | else if (SystemZ::FP32BitRegClass.contains(DestReg, SrcReg)) |
Ulrich Weigand | cdce026 | 2016-03-14 13:50:03 +0000 | [diff] [blame] | 848 | // For z13 we prefer LDR over LER to avoid partial register dependencies. |
| 849 | Opcode = STI.hasVector() ? SystemZ::LDR32 : SystemZ::LER; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 850 | else if (SystemZ::FP64BitRegClass.contains(DestReg, SrcReg)) |
| 851 | Opcode = SystemZ::LDR; |
| 852 | else if (SystemZ::FP128BitRegClass.contains(DestReg, SrcReg)) |
| 853 | Opcode = SystemZ::LXR; |
Ulrich Weigand | 49506d7 | 2015-05-05 19:28:34 +0000 | [diff] [blame] | 854 | else if (SystemZ::VR32BitRegClass.contains(DestReg, SrcReg)) |
| 855 | Opcode = SystemZ::VLR32; |
| 856 | else if (SystemZ::VR64BitRegClass.contains(DestReg, SrcReg)) |
| 857 | Opcode = SystemZ::VLR64; |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame] | 858 | else if (SystemZ::VR128BitRegClass.contains(DestReg, SrcReg)) |
| 859 | Opcode = SystemZ::VLR; |
Ulrich Weigand | fffc711 | 2016-11-08 20:15:26 +0000 | [diff] [blame] | 860 | else if (SystemZ::AR32BitRegClass.contains(DestReg, SrcReg)) |
| 861 | Opcode = SystemZ::CPYA; |
| 862 | else if (SystemZ::AR32BitRegClass.contains(DestReg) && |
| 863 | SystemZ::GR32BitRegClass.contains(SrcReg)) |
| 864 | Opcode = SystemZ::SAR; |
| 865 | else if (SystemZ::GR32BitRegClass.contains(DestReg) && |
| 866 | SystemZ::AR32BitRegClass.contains(SrcReg)) |
| 867 | Opcode = SystemZ::EAR; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 868 | else |
| 869 | llvm_unreachable("Impossible reg-to-reg copy"); |
| 870 | |
| 871 | BuildMI(MBB, MBBI, DL, get(Opcode), DestReg) |
| 872 | .addReg(SrcReg, getKillRegState(KillSrc)); |
| 873 | } |
| 874 | |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 875 | void SystemZInstrInfo::storeRegToStackSlot( |
| 876 | MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, |
| 877 | bool isKill, int FrameIdx, const TargetRegisterClass *RC, |
| 878 | const TargetRegisterInfo *TRI) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 879 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); |
| 880 | |
| 881 | // Callers may expect a single instruction, so keep 128-bit moves |
| 882 | // together for now and lower them after register allocation. |
| 883 | unsigned LoadOpcode, StoreOpcode; |
| 884 | getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode); |
| 885 | addFrameReference(BuildMI(MBB, MBBI, DL, get(StoreOpcode)) |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 886 | .addReg(SrcReg, getKillRegState(isKill)), |
| 887 | FrameIdx); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 888 | } |
| 889 | |
NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 890 | void SystemZInstrInfo::loadRegFromStackSlot( |
| 891 | MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, |
| 892 | int FrameIdx, const TargetRegisterClass *RC, |
| 893 | const TargetRegisterInfo *TRI) const { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 894 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); |
| 895 | |
| 896 | // Callers may expect a single instruction, so keep 128-bit moves |
| 897 | // together for now and lower them after register allocation. |
| 898 | unsigned LoadOpcode, StoreOpcode; |
| 899 | getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode); |
| 900 | addFrameReference(BuildMI(MBB, MBBI, DL, get(LoadOpcode), DestReg), |
| 901 | FrameIdx); |
| 902 | } |
| 903 | |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 904 | // Return true if MI is a simple load or store with a 12-bit displacement |
| 905 | // and no index. Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores. |
| 906 | static bool isSimpleBD12Move(const MachineInstr *MI, unsigned Flag) { |
| 907 | const MCInstrDesc &MCID = MI->getDesc(); |
| 908 | return ((MCID.TSFlags & Flag) && |
| 909 | isUInt<12>(MI->getOperand(2).getImm()) && |
| 910 | MI->getOperand(3).getReg() == 0); |
| 911 | } |
| 912 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 913 | namespace { |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 914 | |
Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 915 | struct LogicOp { |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 916 | LogicOp() = default; |
Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 917 | LogicOp(unsigned regSize, unsigned immLSB, unsigned immSize) |
| 918 | : RegSize(regSize), ImmLSB(immLSB), ImmSize(immSize) {} |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 919 | |
Aaron Ballman | b46962f | 2015-02-15 22:00:20 +0000 | [diff] [blame] | 920 | explicit operator bool() const { return RegSize; } |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 921 | |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 922 | unsigned RegSize = 0; |
| 923 | unsigned ImmLSB = 0; |
| 924 | unsigned ImmSize = 0; |
Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 925 | }; |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 926 | |
Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 927 | } // end anonymous namespace |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 928 | |
| 929 | static LogicOp interpretAndImmediate(unsigned Opcode) { |
| 930 | switch (Opcode) { |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 931 | case SystemZ::NILMux: return LogicOp(32, 0, 16); |
| 932 | case SystemZ::NIHMux: return LogicOp(32, 16, 16); |
Richard Sandiford | 652784e | 2013-09-25 11:11:53 +0000 | [diff] [blame] | 933 | case SystemZ::NILL64: return LogicOp(64, 0, 16); |
| 934 | case SystemZ::NILH64: return LogicOp(64, 16, 16); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 935 | case SystemZ::NIHL64: return LogicOp(64, 32, 16); |
| 936 | case SystemZ::NIHH64: return LogicOp(64, 48, 16); |
| 937 | case SystemZ::NIFMux: return LogicOp(32, 0, 32); |
Richard Sandiford | 652784e | 2013-09-25 11:11:53 +0000 | [diff] [blame] | 938 | case SystemZ::NILF64: return LogicOp(64, 0, 32); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 939 | case SystemZ::NIHF64: return LogicOp(64, 32, 32); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 940 | default: return LogicOp(); |
| 941 | } |
| 942 | } |
| 943 | |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 944 | static void transferDeadCC(MachineInstr *OldMI, MachineInstr *NewMI) { |
| 945 | if (OldMI->registerDefIsDead(SystemZ::CC)) { |
| 946 | MachineOperand *CCDef = NewMI->findRegisterDefOperand(SystemZ::CC); |
| 947 | if (CCDef != nullptr) |
| 948 | CCDef->setIsDead(true); |
| 949 | } |
| 950 | } |
| 951 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 952 | // Used to return from convertToThreeAddress after replacing two-address |
| 953 | // instruction OldMI with three-address instruction NewMI. |
| 954 | static MachineInstr *finishConvertToThreeAddress(MachineInstr *OldMI, |
| 955 | MachineInstr *NewMI, |
| 956 | LiveVariables *LV) { |
| 957 | if (LV) { |
| 958 | unsigned NumOps = OldMI->getNumOperands(); |
| 959 | for (unsigned I = 1; I < NumOps; ++I) { |
| 960 | MachineOperand &Op = OldMI->getOperand(I); |
| 961 | if (Op.isReg() && Op.isKill()) |
Duncan P. N. Exon Smith | d26fdc8 | 2016-07-01 01:51:32 +0000 | [diff] [blame] | 962 | LV->replaceKillInstruction(Op.getReg(), *OldMI, *NewMI); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 963 | } |
| 964 | } |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 965 | transferDeadCC(OldMI, NewMI); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 966 | return NewMI; |
| 967 | } |
| 968 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 969 | MachineInstr *SystemZInstrInfo::convertToThreeAddress( |
| 970 | MachineFunction::iterator &MFI, MachineInstr &MI, LiveVariables *LV) const { |
| 971 | MachineBasicBlock *MBB = MI.getParent(); |
Jonas Paulsson | 7fa69cd | 2015-12-04 12:48:51 +0000 | [diff] [blame] | 972 | MachineFunction *MF = MBB->getParent(); |
| 973 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 974 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 975 | unsigned Opcode = MI.getOpcode(); |
| 976 | unsigned NumOps = MI.getNumOperands(); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 977 | |
| 978 | // Try to convert something like SLL into SLLK, if supported. |
| 979 | // We prefer to keep the two-operand form where possible both |
| 980 | // because it tends to be shorter and because some instructions |
| 981 | // have memory forms that can be used during spilling. |
Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 982 | if (STI.hasDistinctOps()) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 983 | MachineOperand &Dest = MI.getOperand(0); |
| 984 | MachineOperand &Src = MI.getOperand(1); |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 985 | unsigned DestReg = Dest.getReg(); |
| 986 | unsigned SrcReg = Src.getReg(); |
| 987 | // AHIMux is only really a three-operand instruction when both operands |
| 988 | // are low registers. Try to constrain both operands to be low if |
| 989 | // possible. |
| 990 | if (Opcode == SystemZ::AHIMux && |
| 991 | TargetRegisterInfo::isVirtualRegister(DestReg) && |
| 992 | TargetRegisterInfo::isVirtualRegister(SrcReg) && |
| 993 | MRI.getRegClass(DestReg)->contains(SystemZ::R1L) && |
| 994 | MRI.getRegClass(SrcReg)->contains(SystemZ::R1L)) { |
| 995 | MRI.constrainRegClass(DestReg, &SystemZ::GR32BitRegClass); |
| 996 | MRI.constrainRegClass(SrcReg, &SystemZ::GR32BitRegClass); |
| 997 | } |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 998 | int ThreeOperandOpcode = SystemZ::getThreeOperandOpcode(Opcode); |
| 999 | if (ThreeOperandOpcode >= 0) { |
Jonas Paulsson | 7fa69cd | 2015-12-04 12:48:51 +0000 | [diff] [blame] | 1000 | // Create three address instruction without adding the implicit |
| 1001 | // operands. Those will instead be copied over from the original |
| 1002 | // instruction by the loop below. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1003 | MachineInstrBuilder MIB( |
| 1004 | *MF, MF->CreateMachineInstr(get(ThreeOperandOpcode), MI.getDebugLoc(), |
| 1005 | /*NoImplicit=*/true)); |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 1006 | MIB.add(Dest); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 1007 | // Keep the kill state, but drop the tied flag. |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 1008 | MIB.addReg(Src.getReg(), getKillRegState(Src.isKill()), Src.getSubReg()); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 1009 | // Keep the remaining operands as-is. |
| 1010 | for (unsigned I = 2; I < NumOps; ++I) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 1011 | MIB.add(MI.getOperand(I)); |
Jonas Paulsson | 7fa69cd | 2015-12-04 12:48:51 +0000 | [diff] [blame] | 1012 | MBB->insert(MI, MIB); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1013 | return finishConvertToThreeAddress(&MI, MIB, LV); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 1014 | } |
| 1015 | } |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 1016 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 1017 | // Try to convert an AND into an RISBG-type instruction. |
| 1018 | if (LogicOp And = interpretAndImmediate(Opcode)) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1019 | uint64_t Imm = MI.getOperand(2).getImm() << And.ImmLSB; |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1020 | // AND IMMEDIATE leaves the other bits of the register unchanged. |
| 1021 | Imm |= allOnes(And.RegSize) & ~(allOnes(And.ImmSize) << And.ImmLSB); |
| 1022 | unsigned Start, End; |
| 1023 | if (isRxSBGMask(Imm, And.RegSize, Start, End)) { |
| 1024 | unsigned NewOpcode; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 1025 | if (And.RegSize == 64) { |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1026 | NewOpcode = SystemZ::RISBG; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 1027 | // Prefer RISBGN if available, since it does not clobber CC. |
| 1028 | if (STI.hasMiscellaneousExtensions()) |
| 1029 | NewOpcode = SystemZ::RISBGN; |
| 1030 | } else { |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1031 | NewOpcode = SystemZ::RISBMux; |
| 1032 | Start &= 31; |
| 1033 | End &= 31; |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 1034 | } |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1035 | MachineOperand &Dest = MI.getOperand(0); |
| 1036 | MachineOperand &Src = MI.getOperand(1); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1037 | MachineInstrBuilder MIB = |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1038 | BuildMI(*MBB, MI, MI.getDebugLoc(), get(NewOpcode)) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 1039 | .add(Dest) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1040 | .addReg(0) |
| 1041 | .addReg(Src.getReg(), getKillRegState(Src.isKill()), |
| 1042 | Src.getSubReg()) |
| 1043 | .addImm(Start) |
| 1044 | .addImm(End + 128) |
| 1045 | .addImm(0); |
| 1046 | return finishConvertToThreeAddress(&MI, MIB, LV); |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 1047 | } |
| 1048 | } |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1049 | return nullptr; |
Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1052 | MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl( |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1053 | MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops, |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 1054 | MachineBasicBlock::iterator InsertPt, int FrameIndex, |
| 1055 | LiveIntervals *LIS) const { |
| 1056 | const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1057 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 1058 | unsigned Size = MFI.getObjectSize(FrameIndex); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1059 | unsigned Opcode = MI.getOpcode(); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1060 | |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 1061 | if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1062 | if (LIS != nullptr && (Opcode == SystemZ::LA || Opcode == SystemZ::LAY) && |
| 1063 | isInt<8>(MI.getOperand(2).getImm()) && !MI.getOperand(3).getReg()) { |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 1064 | |
| 1065 | // Check CC liveness, since new instruction introduces a dead |
| 1066 | // def of CC. |
| 1067 | MCRegUnitIterator CCUnit(SystemZ::CC, TRI); |
| 1068 | LiveRange &CCLiveRange = LIS->getRegUnit(*CCUnit); |
| 1069 | ++CCUnit; |
Eugene Zelenko | 3943d2b | 2017-01-24 22:10:43 +0000 | [diff] [blame] | 1070 | assert(!CCUnit.isValid() && "CC only has one reg unit."); |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 1071 | SlotIndex MISlot = |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1072 | LIS->getSlotIndexes()->getInstructionIndex(MI).getRegSlot(); |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 1073 | if (!CCLiveRange.liveAt(MISlot)) { |
| 1074 | // LA(Y) %reg, CONST(%reg) -> AGSI %mem, CONST |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1075 | MachineInstr *BuiltMI = BuildMI(*InsertPt->getParent(), InsertPt, |
| 1076 | MI.getDebugLoc(), get(SystemZ::AGSI)) |
| 1077 | .addFrameIndex(FrameIndex) |
| 1078 | .addImm(0) |
| 1079 | .addImm(MI.getOperand(2).getImm()); |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 1080 | BuiltMI->findRegisterDefOperand(SystemZ::CC)->setIsDead(true); |
| 1081 | CCLiveRange.createDeadDef(MISlot, LIS->getVNInfoAllocator()); |
| 1082 | return BuiltMI; |
| 1083 | } |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 1084 | } |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1085 | return nullptr; |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | // All other cases require a single operand. |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1089 | if (Ops.size() != 1) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1090 | return nullptr; |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1091 | |
| 1092 | unsigned OpNum = Ops[0]; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1093 | assert(Size == |
| 1094 | MF.getRegInfo() |
| 1095 | .getRegClass(MI.getOperand(OpNum).getReg()) |
| 1096 | ->getSize() && |
Benjamin Kramer | 421c8fb | 2013-07-02 21:17:31 +0000 | [diff] [blame] | 1097 | "Invalid size combination"); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1098 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1099 | if ((Opcode == SystemZ::AHI || Opcode == SystemZ::AGHI) && OpNum == 0 && |
| 1100 | isInt<8>(MI.getOperand(2).getImm())) { |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 1101 | // A(G)HI %reg, CONST -> A(G)SI %mem, CONST |
| 1102 | Opcode = (Opcode == SystemZ::AHI ? SystemZ::ASI : SystemZ::AGSI); |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 1103 | MachineInstr *BuiltMI = |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1104 | BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode)) |
| 1105 | .addFrameIndex(FrameIndex) |
| 1106 | .addImm(0) |
| 1107 | .addImm(MI.getOperand(2).getImm()); |
| 1108 | transferDeadCC(&MI, BuiltMI); |
Jonas Paulsson | 9028acf | 2016-05-02 09:37:40 +0000 | [diff] [blame] | 1109 | return BuiltMI; |
Richard Sandiford | 6af6ff1 | 2013-10-15 08:42:59 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 1112 | if (Opcode == SystemZ::LGDR || Opcode == SystemZ::LDGR) { |
| 1113 | bool Op0IsGPR = (Opcode == SystemZ::LGDR); |
| 1114 | bool Op1IsGPR = (Opcode == SystemZ::LDGR); |
| 1115 | // If we're spilling the destination of an LDGR or LGDR, store the |
| 1116 | // source register instead. |
| 1117 | if (OpNum == 0) { |
| 1118 | unsigned StoreOpcode = Op1IsGPR ? SystemZ::STG : SystemZ::STD; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1119 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1120 | get(StoreOpcode)) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 1121 | .add(MI.getOperand(1)) |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1122 | .addFrameIndex(FrameIndex) |
| 1123 | .addImm(0) |
| 1124 | .addReg(0); |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 1125 | } |
| 1126 | // If we're spilling the source of an LDGR or LGDR, load the |
| 1127 | // destination register instead. |
| 1128 | if (OpNum == 1) { |
| 1129 | unsigned LoadOpcode = Op0IsGPR ? SystemZ::LG : SystemZ::LD; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1130 | unsigned Dest = MI.getOperand(0).getReg(); |
| 1131 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1132 | get(LoadOpcode), Dest) |
| 1133 | .addFrameIndex(FrameIndex) |
| 1134 | .addImm(0) |
| 1135 | .addReg(0); |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1139 | // Look for cases where the source of a simple store or the destination |
| 1140 | // of a simple load is being spilled. Try to use MVC instead. |
| 1141 | // |
| 1142 | // Although MVC is in practice a fast choice in these cases, it is still |
| 1143 | // logically a bytewise copy. This means that we cannot use it if the |
Richard Sandiford | 067817e | 2013-09-27 15:29:20 +0000 | [diff] [blame] | 1144 | // load or store is volatile. We also wouldn't be able to use MVC if |
| 1145 | // the two memories partially overlap, but that case cannot occur here, |
| 1146 | // because we know that one of the memories is a full frame index. |
| 1147 | // |
| 1148 | // For performance reasons, we also want to avoid using MVC if the addresses |
| 1149 | // might be equal. We don't worry about that case here, because spill slot |
| 1150 | // coloring happens later, and because we have special code to remove |
| 1151 | // MVCs that turn out to be redundant. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1152 | if (OpNum == 0 && MI.hasOneMemOperand()) { |
| 1153 | MachineMemOperand *MMO = *MI.memoperands_begin(); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1154 | if (MMO->getSize() == Size && !MMO->isVolatile()) { |
| 1155 | // Handle conversion of loads. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1156 | if (isSimpleBD12Move(&MI, SystemZII::SimpleBDXLoad)) { |
| 1157 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1158 | get(SystemZ::MVC)) |
| 1159 | .addFrameIndex(FrameIndex) |
| 1160 | .addImm(0) |
| 1161 | .addImm(Size) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 1162 | .add(MI.getOperand(1)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1163 | .addImm(MI.getOperand(2).getImm()) |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1164 | .addMemOperand(MMO); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1165 | } |
| 1166 | // Handle conversion of stores. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1167 | if (isSimpleBD12Move(&MI, SystemZII::SimpleBDXStore)) { |
| 1168 | return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1169 | get(SystemZ::MVC)) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 1170 | .add(MI.getOperand(1)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1171 | .addImm(MI.getOperand(2).getImm()) |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1172 | .addImm(Size) |
| 1173 | .addFrameIndex(FrameIndex) |
| 1174 | .addImm(0) |
| 1175 | .addMemOperand(MMO); |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1180 | // If the spilled operand is the final one, try to change <INSN>R |
| 1181 | // into <INSN>. |
Richard Sandiford | 3f0edc2 | 2013-07-12 08:37:17 +0000 | [diff] [blame] | 1182 | int MemOpcode = SystemZ::getMemOpcode(Opcode); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1183 | if (MemOpcode >= 0) { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1184 | unsigned NumOps = MI.getNumExplicitOperands(); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1185 | if (OpNum == NumOps - 1) { |
| 1186 | const MCInstrDesc &MemDesc = get(MemOpcode); |
| 1187 | uint64_t AccessBytes = SystemZII::getAccessSize(MemDesc.TSFlags); |
| 1188 | assert(AccessBytes != 0 && "Size of access should be known"); |
| 1189 | assert(AccessBytes <= Size && "Access outside the frame index"); |
| 1190 | uint64_t Offset = Size - AccessBytes; |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1191 | MachineInstrBuilder MIB = BuildMI(*InsertPt->getParent(), InsertPt, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1192 | MI.getDebugLoc(), get(MemOpcode)); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1193 | for (unsigned I = 0; I < OpNum; ++I) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 1194 | MIB.add(MI.getOperand(I)); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1195 | MIB.addFrameIndex(FrameIndex).addImm(Offset); |
| 1196 | if (MemDesc.TSFlags & SystemZII::HasIndex) |
| 1197 | MIB.addReg(0); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1198 | transferDeadCC(&MI, MIB); |
Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 1199 | return MIB; |
| 1200 | } |
| 1201 | } |
| 1202 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1203 | return nullptr; |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Keno Fischer | e70b31f | 2015-06-08 20:09:58 +0000 | [diff] [blame] | 1206 | MachineInstr *SystemZInstrInfo::foldMemoryOperandImpl( |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1207 | MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops, |
| 1208 | MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI, |
Jonas Paulsson | 8e5b0c6 | 2016-05-10 08:09:37 +0000 | [diff] [blame] | 1209 | LiveIntervals *LIS) const { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1210 | return nullptr; |
Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1213 | bool SystemZInstrInfo::expandPostRAPseudo(MachineInstr &MI) const { |
| 1214 | switch (MI.getOpcode()) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1215 | case SystemZ::L128: |
| 1216 | splitMove(MI, SystemZ::LG); |
| 1217 | return true; |
| 1218 | |
| 1219 | case SystemZ::ST128: |
| 1220 | splitMove(MI, SystemZ::STG); |
| 1221 | return true; |
| 1222 | |
| 1223 | case SystemZ::LX: |
| 1224 | splitMove(MI, SystemZ::LD); |
| 1225 | return true; |
| 1226 | |
| 1227 | case SystemZ::STX: |
| 1228 | splitMove(MI, SystemZ::STD); |
| 1229 | return true; |
| 1230 | |
Richard Sandiford | 89e160d | 2013-10-01 12:11:47 +0000 | [diff] [blame] | 1231 | case SystemZ::LBMux: |
| 1232 | expandRXYPseudo(MI, SystemZ::LB, SystemZ::LBH); |
| 1233 | return true; |
| 1234 | |
| 1235 | case SystemZ::LHMux: |
| 1236 | expandRXYPseudo(MI, SystemZ::LH, SystemZ::LHH); |
| 1237 | return true; |
| 1238 | |
Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 1239 | case SystemZ::LLCRMux: |
| 1240 | expandZExtPseudo(MI, SystemZ::LLCR, 8); |
| 1241 | return true; |
| 1242 | |
| 1243 | case SystemZ::LLHRMux: |
| 1244 | expandZExtPseudo(MI, SystemZ::LLHR, 16); |
| 1245 | return true; |
| 1246 | |
Richard Sandiford | 0d46b1a | 2013-10-01 12:19:08 +0000 | [diff] [blame] | 1247 | case SystemZ::LLCMux: |
| 1248 | expandRXYPseudo(MI, SystemZ::LLC, SystemZ::LLCH); |
| 1249 | return true; |
| 1250 | |
| 1251 | case SystemZ::LLHMux: |
| 1252 | expandRXYPseudo(MI, SystemZ::LLH, SystemZ::LLHH); |
| 1253 | return true; |
| 1254 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 1255 | case SystemZ::LMux: |
| 1256 | expandRXYPseudo(MI, SystemZ::L, SystemZ::LFH); |
| 1257 | return true; |
| 1258 | |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 1259 | case SystemZ::LOCMux: |
| 1260 | expandLOCPseudo(MI, SystemZ::LOC, SystemZ::LOCFH); |
| 1261 | return true; |
| 1262 | |
| 1263 | case SystemZ::LOCHIMux: |
| 1264 | expandLOCPseudo(MI, SystemZ::LOCHI, SystemZ::LOCHHI); |
| 1265 | return true; |
| 1266 | |
| 1267 | case SystemZ::LOCRMux: |
| 1268 | expandLOCRPseudo(MI, SystemZ::LOCR, SystemZ::LOCFHR); |
| 1269 | return true; |
| 1270 | |
Richard Sandiford | 5469c39 | 2013-10-01 12:22:49 +0000 | [diff] [blame] | 1271 | case SystemZ::STCMux: |
| 1272 | expandRXYPseudo(MI, SystemZ::STC, SystemZ::STCH); |
| 1273 | return true; |
| 1274 | |
| 1275 | case SystemZ::STHMux: |
| 1276 | expandRXYPseudo(MI, SystemZ::STH, SystemZ::STHH); |
| 1277 | return true; |
| 1278 | |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 1279 | case SystemZ::STMux: |
| 1280 | expandRXYPseudo(MI, SystemZ::ST, SystemZ::STFH); |
| 1281 | return true; |
| 1282 | |
Ulrich Weigand | 524f276 | 2016-11-28 13:34:08 +0000 | [diff] [blame] | 1283 | case SystemZ::STOCMux: |
| 1284 | expandLOCPseudo(MI, SystemZ::STOC, SystemZ::STOCFH); |
| 1285 | return true; |
| 1286 | |
Richard Sandiford | 0124023 | 2013-10-01 13:02:28 +0000 | [diff] [blame] | 1287 | case SystemZ::LHIMux: |
| 1288 | expandRIPseudo(MI, SystemZ::LHI, SystemZ::IIHF, true); |
| 1289 | return true; |
| 1290 | |
| 1291 | case SystemZ::IIFMux: |
| 1292 | expandRIPseudo(MI, SystemZ::IILF, SystemZ::IIHF, false); |
| 1293 | return true; |
| 1294 | |
Richard Sandiford | 1a56931 | 2013-10-01 13:18:56 +0000 | [diff] [blame] | 1295 | case SystemZ::IILMux: |
| 1296 | expandRIPseudo(MI, SystemZ::IILL, SystemZ::IIHL, false); |
| 1297 | return true; |
| 1298 | |
| 1299 | case SystemZ::IIHMux: |
| 1300 | expandRIPseudo(MI, SystemZ::IILH, SystemZ::IIHH, false); |
| 1301 | return true; |
| 1302 | |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1303 | case SystemZ::NIFMux: |
| 1304 | expandRIPseudo(MI, SystemZ::NILF, SystemZ::NIHF, false); |
| 1305 | return true; |
| 1306 | |
| 1307 | case SystemZ::NILMux: |
| 1308 | expandRIPseudo(MI, SystemZ::NILL, SystemZ::NIHL, false); |
| 1309 | return true; |
| 1310 | |
| 1311 | case SystemZ::NIHMux: |
| 1312 | expandRIPseudo(MI, SystemZ::NILH, SystemZ::NIHH, false); |
| 1313 | return true; |
| 1314 | |
Richard Sandiford | 6e96ac6 | 2013-10-01 13:22:41 +0000 | [diff] [blame] | 1315 | case SystemZ::OIFMux: |
| 1316 | expandRIPseudo(MI, SystemZ::OILF, SystemZ::OIHF, false); |
| 1317 | return true; |
| 1318 | |
| 1319 | case SystemZ::OILMux: |
| 1320 | expandRIPseudo(MI, SystemZ::OILL, SystemZ::OIHL, false); |
| 1321 | return true; |
| 1322 | |
| 1323 | case SystemZ::OIHMux: |
| 1324 | expandRIPseudo(MI, SystemZ::OILH, SystemZ::OIHH, false); |
| 1325 | return true; |
| 1326 | |
Richard Sandiford | 5718dac | 2013-10-01 14:08:44 +0000 | [diff] [blame] | 1327 | case SystemZ::XIFMux: |
| 1328 | expandRIPseudo(MI, SystemZ::XILF, SystemZ::XIHF, false); |
| 1329 | return true; |
| 1330 | |
Richard Sandiford | 2cac763 | 2013-10-01 14:41:52 +0000 | [diff] [blame] | 1331 | case SystemZ::TMLMux: |
| 1332 | expandRIPseudo(MI, SystemZ::TMLL, SystemZ::TMHL, false); |
| 1333 | return true; |
| 1334 | |
| 1335 | case SystemZ::TMHMux: |
| 1336 | expandRIPseudo(MI, SystemZ::TMLH, SystemZ::TMHH, false); |
| 1337 | return true; |
| 1338 | |
Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 1339 | case SystemZ::AHIMux: |
| 1340 | expandRIPseudo(MI, SystemZ::AHI, SystemZ::AIH, false); |
| 1341 | return true; |
| 1342 | |
| 1343 | case SystemZ::AHIMuxK: |
| 1344 | expandRIEPseudo(MI, SystemZ::AHI, SystemZ::AHIK, SystemZ::AIH); |
| 1345 | return true; |
| 1346 | |
| 1347 | case SystemZ::AFIMux: |
| 1348 | expandRIPseudo(MI, SystemZ::AFI, SystemZ::AIH, false); |
| 1349 | return true; |
| 1350 | |
Ulrich Weigand | 7583991 | 2016-11-28 13:40:08 +0000 | [diff] [blame] | 1351 | case SystemZ::CHIMux: |
| 1352 | expandRIPseudo(MI, SystemZ::CHI, SystemZ::CIH, false); |
| 1353 | return true; |
| 1354 | |
Richard Sandiford | a9ac0e0 | 2013-10-01 14:56:23 +0000 | [diff] [blame] | 1355 | case SystemZ::CFIMux: |
| 1356 | expandRIPseudo(MI, SystemZ::CFI, SystemZ::CIH, false); |
| 1357 | return true; |
| 1358 | |
| 1359 | case SystemZ::CLFIMux: |
| 1360 | expandRIPseudo(MI, SystemZ::CLFI, SystemZ::CLIH, false); |
| 1361 | return true; |
| 1362 | |
Richard Sandiford | b63e300 | 2013-10-01 15:00:44 +0000 | [diff] [blame] | 1363 | case SystemZ::CMux: |
| 1364 | expandRXYPseudo(MI, SystemZ::C, SystemZ::CHF); |
| 1365 | return true; |
| 1366 | |
| 1367 | case SystemZ::CLMux: |
| 1368 | expandRXYPseudo(MI, SystemZ::CL, SystemZ::CLHF); |
| 1369 | return true; |
| 1370 | |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1371 | case SystemZ::RISBMux: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1372 | bool DestIsHigh = isHighReg(MI.getOperand(0).getReg()); |
| 1373 | bool SrcIsHigh = isHighReg(MI.getOperand(2).getReg()); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1374 | if (SrcIsHigh == DestIsHigh) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1375 | MI.setDesc(get(DestIsHigh ? SystemZ::RISBHH : SystemZ::RISBLL)); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1376 | else { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1377 | MI.setDesc(get(DestIsHigh ? SystemZ::RISBHL : SystemZ::RISBLH)); |
| 1378 | MI.getOperand(5).setImm(MI.getOperand(5).getImm() ^ 32); |
Richard Sandiford | 7028428 | 2013-10-01 14:20:41 +0000 | [diff] [blame] | 1379 | } |
| 1380 | return true; |
| 1381 | } |
| 1382 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1383 | case SystemZ::ADJDYNALLOC: |
| 1384 | splitAdjDynAlloc(MI); |
| 1385 | return true; |
| 1386 | |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 1387 | case TargetOpcode::LOAD_STACK_GUARD: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1388 | expandLoadStackGuard(&MI); |
Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 1389 | return true; |
| 1390 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1391 | default: |
| 1392 | return false; |
| 1393 | } |
| 1394 | } |
| 1395 | |
Sjoerd Meijer | 0eb96ed | 2016-07-29 08:16:16 +0000 | [diff] [blame] | 1396 | unsigned SystemZInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1397 | if (MI.getOpcode() == TargetOpcode::INLINEASM) { |
| 1398 | const MachineFunction *MF = MI.getParent()->getParent(); |
| 1399 | const char *AsmStr = MI.getOperand(0).getSymbolName(); |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 1400 | return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo()); |
| 1401 | } |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1402 | return MI.getDesc().getSize(); |
Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 1405 | SystemZII::Branch |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1406 | SystemZInstrInfo::getBranchInfo(const MachineInstr &MI) const { |
| 1407 | switch (MI.getOpcode()) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1408 | case SystemZ::BR: |
| 1409 | case SystemZ::J: |
| 1410 | case SystemZ::JG: |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1411 | return SystemZII::Branch(SystemZII::BranchNormal, SystemZ::CCMASK_ANY, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1412 | SystemZ::CCMASK_ANY, &MI.getOperand(0)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1413 | |
| 1414 | case SystemZ::BRC: |
| 1415 | case SystemZ::BRCL: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1416 | return SystemZII::Branch(SystemZII::BranchNormal, MI.getOperand(0).getImm(), |
| 1417 | MI.getOperand(1).getImm(), &MI.getOperand(2)); |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1418 | |
Richard Sandiford | c212125 | 2013-08-05 11:23:46 +0000 | [diff] [blame] | 1419 | case SystemZ::BRCT: |
Ulrich Weigand | 7583991 | 2016-11-28 13:40:08 +0000 | [diff] [blame] | 1420 | case SystemZ::BRCTH: |
Richard Sandiford | c212125 | 2013-08-05 11:23:46 +0000 | [diff] [blame] | 1421 | return SystemZII::Branch(SystemZII::BranchCT, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1422 | SystemZ::CCMASK_CMP_NE, &MI.getOperand(2)); |
Richard Sandiford | c212125 | 2013-08-05 11:23:46 +0000 | [diff] [blame] | 1423 | |
| 1424 | case SystemZ::BRCTG: |
| 1425 | return SystemZII::Branch(SystemZII::BranchCTG, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1426 | SystemZ::CCMASK_CMP_NE, &MI.getOperand(2)); |
Richard Sandiford | c212125 | 2013-08-05 11:23:46 +0000 | [diff] [blame] | 1427 | |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1428 | case SystemZ::CIJ: |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1429 | case SystemZ::CRJ: |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 1430 | return SystemZII::Branch(SystemZII::BranchC, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1431 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1432 | |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1433 | case SystemZ::CLIJ: |
| 1434 | case SystemZ::CLRJ: |
| 1435 | return SystemZII::Branch(SystemZII::BranchCL, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1436 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1437 | |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1438 | case SystemZ::CGIJ: |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1439 | case SystemZ::CGRJ: |
Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame] | 1440 | return SystemZII::Branch(SystemZII::BranchCG, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1441 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1442 | |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1443 | case SystemZ::CLGIJ: |
| 1444 | case SystemZ::CLGRJ: |
| 1445 | return SystemZII::Branch(SystemZII::BranchCLG, SystemZ::CCMASK_ICMP, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1446 | MI.getOperand(2).getImm(), &MI.getOperand(3)); |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1447 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1448 | default: |
Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 1449 | llvm_unreachable("Unrecognized branch opcode"); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | void SystemZInstrInfo::getLoadStoreOpcodes(const TargetRegisterClass *RC, |
| 1454 | unsigned &LoadOpcode, |
| 1455 | unsigned &StoreOpcode) const { |
| 1456 | if (RC == &SystemZ::GR32BitRegClass || RC == &SystemZ::ADDR32BitRegClass) { |
| 1457 | LoadOpcode = SystemZ::L; |
Richard Sandiford | 6cbd7f0 | 2013-09-25 10:29:47 +0000 | [diff] [blame] | 1458 | StoreOpcode = SystemZ::ST; |
Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 1459 | } else if (RC == &SystemZ::GRH32BitRegClass) { |
| 1460 | LoadOpcode = SystemZ::LFH; |
| 1461 | StoreOpcode = SystemZ::STFH; |
| 1462 | } else if (RC == &SystemZ::GRX32BitRegClass) { |
| 1463 | LoadOpcode = SystemZ::LMux; |
| 1464 | StoreOpcode = SystemZ::STMux; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1465 | } else if (RC == &SystemZ::GR64BitRegClass || |
| 1466 | RC == &SystemZ::ADDR64BitRegClass) { |
| 1467 | LoadOpcode = SystemZ::LG; |
| 1468 | StoreOpcode = SystemZ::STG; |
| 1469 | } else if (RC == &SystemZ::GR128BitRegClass || |
| 1470 | RC == &SystemZ::ADDR128BitRegClass) { |
| 1471 | LoadOpcode = SystemZ::L128; |
| 1472 | StoreOpcode = SystemZ::ST128; |
| 1473 | } else if (RC == &SystemZ::FP32BitRegClass) { |
| 1474 | LoadOpcode = SystemZ::LE; |
| 1475 | StoreOpcode = SystemZ::STE; |
| 1476 | } else if (RC == &SystemZ::FP64BitRegClass) { |
| 1477 | LoadOpcode = SystemZ::LD; |
| 1478 | StoreOpcode = SystemZ::STD; |
| 1479 | } else if (RC == &SystemZ::FP128BitRegClass) { |
| 1480 | LoadOpcode = SystemZ::LX; |
| 1481 | StoreOpcode = SystemZ::STX; |
Ulrich Weigand | 49506d7 | 2015-05-05 19:28:34 +0000 | [diff] [blame] | 1482 | } else if (RC == &SystemZ::VR32BitRegClass) { |
| 1483 | LoadOpcode = SystemZ::VL32; |
| 1484 | StoreOpcode = SystemZ::VST32; |
| 1485 | } else if (RC == &SystemZ::VR64BitRegClass) { |
| 1486 | LoadOpcode = SystemZ::VL64; |
| 1487 | StoreOpcode = SystemZ::VST64; |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame] | 1488 | } else if (RC == &SystemZ::VF128BitRegClass || |
| 1489 | RC == &SystemZ::VR128BitRegClass) { |
| 1490 | LoadOpcode = SystemZ::VL; |
| 1491 | StoreOpcode = SystemZ::VST; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1492 | } else |
| 1493 | llvm_unreachable("Unsupported regclass to load or store"); |
| 1494 | } |
| 1495 | |
| 1496 | unsigned SystemZInstrInfo::getOpcodeForOffset(unsigned Opcode, |
| 1497 | int64_t Offset) const { |
| 1498 | const MCInstrDesc &MCID = get(Opcode); |
| 1499 | int64_t Offset2 = (MCID.TSFlags & SystemZII::Is128Bit ? Offset + 8 : Offset); |
| 1500 | if (isUInt<12>(Offset) && isUInt<12>(Offset2)) { |
| 1501 | // Get the instruction to use for unsigned 12-bit displacements. |
| 1502 | int Disp12Opcode = SystemZ::getDisp12Opcode(Opcode); |
| 1503 | if (Disp12Opcode >= 0) |
| 1504 | return Disp12Opcode; |
| 1505 | |
| 1506 | // All address-related instructions can use unsigned 12-bit |
| 1507 | // displacements. |
| 1508 | return Opcode; |
| 1509 | } |
| 1510 | if (isInt<20>(Offset) && isInt<20>(Offset2)) { |
| 1511 | // Get the instruction to use for signed 20-bit displacements. |
| 1512 | int Disp20Opcode = SystemZ::getDisp20Opcode(Opcode); |
| 1513 | if (Disp20Opcode >= 0) |
| 1514 | return Disp20Opcode; |
| 1515 | |
| 1516 | // Check whether Opcode allows signed 20-bit displacements. |
| 1517 | if (MCID.TSFlags & SystemZII::Has20BitOffset) |
| 1518 | return Opcode; |
| 1519 | } |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
Richard Sandiford | b49a3ab | 2013-08-05 11:03:20 +0000 | [diff] [blame] | 1523 | unsigned SystemZInstrInfo::getLoadAndTest(unsigned Opcode) const { |
| 1524 | switch (Opcode) { |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 1525 | case SystemZ::L: return SystemZ::LT; |
| 1526 | case SystemZ::LY: return SystemZ::LT; |
| 1527 | case SystemZ::LG: return SystemZ::LTG; |
| 1528 | case SystemZ::LGF: return SystemZ::LTGF; |
| 1529 | case SystemZ::LR: return SystemZ::LTR; |
| 1530 | case SystemZ::LGFR: return SystemZ::LTGFR; |
| 1531 | case SystemZ::LGR: return SystemZ::LTGR; |
| 1532 | case SystemZ::LER: return SystemZ::LTEBR; |
| 1533 | case SystemZ::LDR: return SystemZ::LTDBR; |
| 1534 | case SystemZ::LXR: return SystemZ::LTXBR; |
Jonas Paulsson | 1262932 | 2015-10-01 18:12:28 +0000 | [diff] [blame] | 1535 | case SystemZ::LCDFR: return SystemZ::LCDBR; |
| 1536 | case SystemZ::LPDFR: return SystemZ::LPDBR; |
| 1537 | case SystemZ::LNDFR: return SystemZ::LNDBR; |
| 1538 | case SystemZ::LCDFR_32: return SystemZ::LCEBR; |
| 1539 | case SystemZ::LPDFR_32: return SystemZ::LPEBR; |
| 1540 | case SystemZ::LNDFR_32: return SystemZ::LNEBR; |
Ulrich Weigand | 371d10a | 2015-03-31 12:58:17 +0000 | [diff] [blame] | 1541 | // On zEC12 we prefer to use RISBGN. But if there is a chance to |
| 1542 | // actually use the condition code, we may turn it back into RISGB. |
| 1543 | // Note that RISBG is not really a "load-and-test" instruction, |
| 1544 | // but sets the same condition code values, so is OK to use here. |
| 1545 | case SystemZ::RISBGN: return SystemZ::RISBG; |
| 1546 | default: return 0; |
Richard Sandiford | b49a3ab | 2013-08-05 11:03:20 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 1550 | // Return true if Mask matches the regexp 0*1+0*, given that zero masks |
| 1551 | // have already been filtered out. Store the first set bit in LSB and |
| 1552 | // the number of set bits in Length if so. |
| 1553 | static bool isStringOfOnes(uint64_t Mask, unsigned &LSB, unsigned &Length) { |
| 1554 | unsigned First = findFirstSet(Mask); |
| 1555 | uint64_t Top = (Mask >> First) + 1; |
| 1556 | if ((Top & -Top) == Top) { |
| 1557 | LSB = First; |
| 1558 | Length = findFirstSet(Top); |
| 1559 | return true; |
| 1560 | } |
| 1561 | return false; |
| 1562 | } |
| 1563 | |
| 1564 | bool SystemZInstrInfo::isRxSBGMask(uint64_t Mask, unsigned BitSize, |
| 1565 | unsigned &Start, unsigned &End) const { |
| 1566 | // Reject trivial all-zero masks. |
Ulrich Weigand | ce4c109 | 2015-05-05 19:25:42 +0000 | [diff] [blame] | 1567 | Mask &= allOnes(BitSize); |
Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 1568 | if (Mask == 0) |
| 1569 | return false; |
| 1570 | |
| 1571 | // Handle the 1+0+ or 0+1+0* cases. Start then specifies the index of |
| 1572 | // the msb and End specifies the index of the lsb. |
| 1573 | unsigned LSB, Length; |
| 1574 | if (isStringOfOnes(Mask, LSB, Length)) { |
| 1575 | Start = 63 - (LSB + Length - 1); |
| 1576 | End = 63 - LSB; |
| 1577 | return true; |
| 1578 | } |
| 1579 | |
| 1580 | // Handle the wrap-around 1+0+1+ cases. Start then specifies the msb |
| 1581 | // of the low 1s and End specifies the lsb of the high 1s. |
| 1582 | if (isStringOfOnes(Mask ^ allOnes(BitSize), LSB, Length)) { |
| 1583 | assert(LSB > 0 && "Bottom bit must be set"); |
| 1584 | assert(LSB + Length < BitSize && "Top bit must be set"); |
| 1585 | Start = 63 - (LSB - 1); |
| 1586 | End = 63 - (LSB + Length); |
| 1587 | return true; |
| 1588 | } |
| 1589 | |
| 1590 | return false; |
| 1591 | } |
| 1592 | |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 1593 | unsigned SystemZInstrInfo::getFusedCompare(unsigned Opcode, |
| 1594 | SystemZII::FusedCompareType Type, |
| 1595 | const MachineInstr *MI) const { |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1596 | switch (Opcode) { |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1597 | case SystemZ::CHI: |
Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 1598 | case SystemZ::CGHI: |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 1599 | if (!(MI && isInt<8>(MI->getOperand(1).getImm()))) |
| 1600 | return 0; |
| 1601 | break; |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1602 | case SystemZ::CLFI: |
Richard Sandiford | 93183ee | 2013-09-18 09:56:40 +0000 | [diff] [blame] | 1603 | case SystemZ::CLGFI: |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 1604 | if (!(MI && isUInt<8>(MI->getOperand(1).getImm()))) |
| 1605 | return 0; |
Ulrich Weigand | a0e7325 | 2016-11-11 12:48:26 +0000 | [diff] [blame] | 1606 | break; |
| 1607 | case SystemZ::CL: |
| 1608 | case SystemZ::CLG: |
| 1609 | if (!STI.hasMiscellaneousExtensions()) |
| 1610 | return 0; |
| 1611 | if (!(MI && MI->getOperand(3).getReg() == 0)) |
| 1612 | return 0; |
| 1613 | break; |
Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 1614 | } |
| 1615 | switch (Type) { |
| 1616 | case SystemZII::CompareAndBranch: |
| 1617 | switch (Opcode) { |
| 1618 | case SystemZ::CR: |
| 1619 | return SystemZ::CRJ; |
| 1620 | case SystemZ::CGR: |
| 1621 | return SystemZ::CGRJ; |
| 1622 | case SystemZ::CHI: |
| 1623 | return SystemZ::CIJ; |
| 1624 | case SystemZ::CGHI: |
| 1625 | return SystemZ::CGIJ; |
| 1626 | case SystemZ::CLR: |
| 1627 | return SystemZ::CLRJ; |
| 1628 | case SystemZ::CLGR: |
| 1629 | return SystemZ::CLGRJ; |
| 1630 | case SystemZ::CLFI: |
| 1631 | return SystemZ::CLIJ; |
| 1632 | case SystemZ::CLGFI: |
| 1633 | return SystemZ::CLGIJ; |
| 1634 | default: |
| 1635 | return 0; |
| 1636 | } |
| 1637 | case SystemZII::CompareAndReturn: |
| 1638 | switch (Opcode) { |
| 1639 | case SystemZ::CR: |
| 1640 | return SystemZ::CRBReturn; |
| 1641 | case SystemZ::CGR: |
| 1642 | return SystemZ::CGRBReturn; |
| 1643 | case SystemZ::CHI: |
| 1644 | return SystemZ::CIBReturn; |
| 1645 | case SystemZ::CGHI: |
| 1646 | return SystemZ::CGIBReturn; |
| 1647 | case SystemZ::CLR: |
| 1648 | return SystemZ::CLRBReturn; |
| 1649 | case SystemZ::CLGR: |
| 1650 | return SystemZ::CLGRBReturn; |
| 1651 | case SystemZ::CLFI: |
| 1652 | return SystemZ::CLIBReturn; |
| 1653 | case SystemZ::CLGFI: |
| 1654 | return SystemZ::CLGIBReturn; |
| 1655 | default: |
| 1656 | return 0; |
| 1657 | } |
Ulrich Weigand | 848a513 | 2016-04-11 12:12:32 +0000 | [diff] [blame] | 1658 | case SystemZII::CompareAndSibcall: |
| 1659 | switch (Opcode) { |
| 1660 | case SystemZ::CR: |
| 1661 | return SystemZ::CRBCall; |
| 1662 | case SystemZ::CGR: |
| 1663 | return SystemZ::CGRBCall; |
| 1664 | case SystemZ::CHI: |
| 1665 | return SystemZ::CIBCall; |
| 1666 | case SystemZ::CGHI: |
| 1667 | return SystemZ::CGIBCall; |
| 1668 | case SystemZ::CLR: |
| 1669 | return SystemZ::CLRBCall; |
| 1670 | case SystemZ::CLGR: |
| 1671 | return SystemZ::CLGRBCall; |
| 1672 | case SystemZ::CLFI: |
| 1673 | return SystemZ::CLIBCall; |
| 1674 | case SystemZ::CLGFI: |
| 1675 | return SystemZ::CLGIBCall; |
| 1676 | default: |
| 1677 | return 0; |
| 1678 | } |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 1679 | case SystemZII::CompareAndTrap: |
| 1680 | switch (Opcode) { |
| 1681 | case SystemZ::CR: |
| 1682 | return SystemZ::CRT; |
| 1683 | case SystemZ::CGR: |
| 1684 | return SystemZ::CGRT; |
| 1685 | case SystemZ::CHI: |
| 1686 | return SystemZ::CIT; |
| 1687 | case SystemZ::CGHI: |
| 1688 | return SystemZ::CGIT; |
| 1689 | case SystemZ::CLR: |
| 1690 | return SystemZ::CLRT; |
| 1691 | case SystemZ::CLGR: |
| 1692 | return SystemZ::CLGRT; |
| 1693 | case SystemZ::CLFI: |
| 1694 | return SystemZ::CLFIT; |
| 1695 | case SystemZ::CLGFI: |
| 1696 | return SystemZ::CLGIT; |
Ulrich Weigand | a0e7325 | 2016-11-11 12:48:26 +0000 | [diff] [blame] | 1697 | case SystemZ::CL: |
| 1698 | return SystemZ::CLT; |
| 1699 | case SystemZ::CLG: |
| 1700 | return SystemZ::CLGT; |
Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 1701 | default: |
| 1702 | return 0; |
| 1703 | } |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1704 | } |
Ulrich Weigand | 79391ee | 2016-04-07 16:33:25 +0000 | [diff] [blame] | 1705 | return 0; |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
Ulrich Weigand | 2d9e3d9 | 2016-11-28 13:59:22 +0000 | [diff] [blame] | 1708 | unsigned SystemZInstrInfo::getLoadAndTrap(unsigned Opcode) const { |
| 1709 | if (!STI.hasLoadAndTrap()) |
| 1710 | return 0; |
| 1711 | switch (Opcode) { |
| 1712 | case SystemZ::L: |
| 1713 | case SystemZ::LY: |
| 1714 | return SystemZ::LAT; |
| 1715 | case SystemZ::LG: |
| 1716 | return SystemZ::LGAT; |
| 1717 | case SystemZ::LFH: |
| 1718 | return SystemZ::LFHAT; |
| 1719 | case SystemZ::LLGF: |
| 1720 | return SystemZ::LLGFAT; |
| 1721 | case SystemZ::LLGT: |
| 1722 | return SystemZ::LLGTAT; |
| 1723 | } |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1727 | void SystemZInstrInfo::loadImmediate(MachineBasicBlock &MBB, |
| 1728 | MachineBasicBlock::iterator MBBI, |
| 1729 | unsigned Reg, uint64_t Value) const { |
| 1730 | DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); |
| 1731 | unsigned Opcode; |
| 1732 | if (isInt<16>(Value)) |
| 1733 | Opcode = SystemZ::LGHI; |
| 1734 | else if (SystemZ::isImmLL(Value)) |
| 1735 | Opcode = SystemZ::LLILL; |
| 1736 | else if (SystemZ::isImmLH(Value)) { |
| 1737 | Opcode = SystemZ::LLILH; |
| 1738 | Value >>= 16; |
| 1739 | } else { |
| 1740 | assert(isInt<32>(Value) && "Huge values not handled yet"); |
| 1741 | Opcode = SystemZ::LGFI; |
| 1742 | } |
| 1743 | BuildMI(MBB, MBBI, DL, get(Opcode), Reg).addImm(Value); |
| 1744 | } |
Jonas Paulsson | 8010b63 | 2016-10-20 08:27:16 +0000 | [diff] [blame] | 1745 | |
| 1746 | bool SystemZInstrInfo:: |
| 1747 | areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb, |
| 1748 | AliasAnalysis *AA) const { |
| 1749 | |
| 1750 | if (!MIa.hasOneMemOperand() || !MIb.hasOneMemOperand()) |
| 1751 | return false; |
| 1752 | |
| 1753 | // If mem-operands show that the same address Value is used by both |
| 1754 | // instructions, check for non-overlapping offsets and widths. Not |
| 1755 | // sure if a register based analysis would be an improvement... |
| 1756 | |
| 1757 | MachineMemOperand *MMOa = *MIa.memoperands_begin(); |
| 1758 | MachineMemOperand *MMOb = *MIb.memoperands_begin(); |
| 1759 | const Value *VALa = MMOa->getValue(); |
| 1760 | const Value *VALb = MMOb->getValue(); |
| 1761 | bool SameVal = (VALa && VALb && (VALa == VALb)); |
| 1762 | if (!SameVal) { |
| 1763 | const PseudoSourceValue *PSVa = MMOa->getPseudoValue(); |
| 1764 | const PseudoSourceValue *PSVb = MMOb->getPseudoValue(); |
| 1765 | if (PSVa && PSVb && (PSVa == PSVb)) |
| 1766 | SameVal = true; |
| 1767 | } |
| 1768 | if (SameVal) { |
| 1769 | int OffsetA = MMOa->getOffset(), OffsetB = MMOb->getOffset(); |
| 1770 | int WidthA = MMOa->getSize(), WidthB = MMOb->getSize(); |
| 1771 | int LowOffset = OffsetA < OffsetB ? OffsetA : OffsetB; |
| 1772 | int HighOffset = OffsetA < OffsetB ? OffsetB : OffsetA; |
| 1773 | int LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB; |
| 1774 | if (LowOffset + LowWidth <= HighOffset) |
| 1775 | return true; |
| 1776 | } |
| 1777 | |
| 1778 | return false; |
| 1779 | } |