| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1 | //===-- SystemZInstrInfo.h - SystemZ instruction information ----*- C++ -*-===// |
| 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 | |
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZINSTRINFO_H |
| 15 | #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZINSTRINFO_H |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 16 | |
| 17 | #include "SystemZ.h" |
| 18 | #include "SystemZRegisterInfo.h" |
| 19 | #include "llvm/Target/TargetInstrInfo.h" |
| 20 | |
| 21 | #define GET_INSTRINFO_HEADER |
| 22 | #include "SystemZGenInstrInfo.inc" |
| 23 | |
| 24 | namespace llvm { |
| 25 | |
| 26 | class SystemZTargetMachine; |
| 27 | |
| 28 | namespace SystemZII { |
| Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 29 | enum { |
| 30 | // See comments in SystemZInstrFormats.td. |
| 31 | SimpleBDXLoad = (1 << 0), |
| 32 | SimpleBDXStore = (1 << 1), |
| 33 | Has20BitOffset = (1 << 2), |
| 34 | HasIndex = (1 << 3), |
| 35 | Is128Bit = (1 << 4), |
| 36 | AccessSizeMask = (31 << 5), |
| 37 | AccessSizeShift = 5, |
| 38 | CCValuesMask = (15 << 10), |
| 39 | CCValuesShift = 10, |
| 40 | CompareZeroCCMaskMask = (15 << 14), |
| 41 | CompareZeroCCMaskShift = 14, |
| 42 | CCMaskFirst = (1 << 18), |
| 43 | CCMaskLast = (1 << 19), |
| 44 | IsLogical = (1 << 20) |
| 45 | }; |
| 46 | static inline unsigned getAccessSize(unsigned int Flags) { |
| 47 | return (Flags & AccessSizeMask) >> AccessSizeShift; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 48 | } |
| Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 49 | static inline unsigned getCCValues(unsigned int Flags) { |
| 50 | return (Flags & CCValuesMask) >> CCValuesShift; |
| 51 | } |
| 52 | static inline unsigned getCompareZeroCCMask(unsigned int Flags) { |
| 53 | return (Flags & CompareZeroCCMaskMask) >> CompareZeroCCMaskShift; |
| 54 | } |
| 55 | |
| 56 | // SystemZ MachineOperand target flags. |
| 57 | enum { |
| 58 | // Masks out the bits for the access model. |
| Ulrich Weigand | 7db6918 | 2015-02-18 09:13:27 +0000 | [diff] [blame] | 59 | MO_SYMBOL_MODIFIER = (3 << 0), |
| Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 60 | |
| 61 | // @GOT (aka @GOTENT) |
| Ulrich Weigand | 7db6918 | 2015-02-18 09:13:27 +0000 | [diff] [blame] | 62 | MO_GOT = (1 << 0), |
| 63 | |
| 64 | // @INDNTPOFF |
| 65 | MO_INDNTPOFF = (2 << 0) |
| Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 66 | }; |
| 67 | // Classifies a branch. |
| 68 | enum BranchType { |
| 69 | // An instruction that branches on the current value of CC. |
| 70 | BranchNormal, |
| 71 | |
| 72 | // An instruction that peforms a 32-bit signed comparison and branches |
| 73 | // on the result. |
| 74 | BranchC, |
| 75 | |
| 76 | // An instruction that peforms a 32-bit unsigned comparison and branches |
| 77 | // on the result. |
| 78 | BranchCL, |
| 79 | |
| 80 | // An instruction that peforms a 64-bit signed comparison and branches |
| 81 | // on the result. |
| 82 | BranchCG, |
| 83 | |
| 84 | // An instruction that peforms a 64-bit unsigned comparison and branches |
| 85 | // on the result. |
| 86 | BranchCLG, |
| 87 | |
| 88 | // An instruction that decrements a 32-bit register and branches if |
| 89 | // the result is nonzero. |
| 90 | BranchCT, |
| 91 | |
| 92 | // An instruction that decrements a 64-bit register and branches if |
| 93 | // the result is nonzero. |
| 94 | BranchCTG |
| 95 | }; |
| 96 | // Information about a branch instruction. |
| 97 | struct Branch { |
| 98 | // The type of the branch. |
| 99 | BranchType Type; |
| 100 | |
| 101 | // CCMASK_<N> is set if CC might be equal to N. |
| 102 | unsigned CCValid; |
| 103 | |
| 104 | // CCMASK_<N> is set if the branch should be taken when CC == N. |
| 105 | unsigned CCMask; |
| 106 | |
| 107 | // The target of the branch. |
| 108 | const MachineOperand *Target; |
| 109 | |
| 110 | Branch(BranchType type, unsigned ccValid, unsigned ccMask, |
| 111 | const MachineOperand *target) |
| 112 | : Type(type), CCValid(ccValid), CCMask(ccMask), Target(target) {} |
| 113 | }; |
| Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 114 | // Kinds of fused compares in compare-and-* instructions. Together with type |
| 115 | // of the converted compare, this identifies the compare-and-* |
| Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 116 | // instruction. |
| Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 117 | enum FusedCompareType { |
| Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 118 | // Relative branch - CRJ etc. |
| 119 | CompareAndBranch, |
| 120 | |
| 121 | // Indirect branch, used for return - CRBReturn etc. |
| Ulrich Weigand | 848a513 | 2016-04-11 12:12:32 +0000 | [diff] [blame] | 122 | CompareAndReturn, |
| 123 | |
| 124 | // Indirect branch, used for sibcall - CRBCall etc. |
| Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 125 | CompareAndSibcall, |
| 126 | |
| 127 | // Trap |
| 128 | CompareAndTrap |
| Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 129 | }; |
| Richard Sandiford | c231269 | 2014-03-06 10:38:30 +0000 | [diff] [blame] | 130 | } // end namespace SystemZII |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 131 | |
| Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 132 | class SystemZSubtarget; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 133 | class SystemZInstrInfo : public SystemZGenInstrInfo { |
| 134 | const SystemZRegisterInfo RI; |
| Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 135 | SystemZSubtarget &STI; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 136 | |
| 137 | void splitMove(MachineBasicBlock::iterator MI, unsigned NewOpcode) const; |
| 138 | void splitAdjDynAlloc(MachineBasicBlock::iterator MI) const; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 139 | void expandRIPseudo(MachineInstr &MI, unsigned LowOpcode, unsigned HighOpcode, |
| 140 | bool ConvertHigh) const; |
| 141 | void expandRIEPseudo(MachineInstr &MI, unsigned LowOpcode, |
| Richard Sandiford | 42a694f | 2013-10-01 14:53:46 +0000 | [diff] [blame] | 142 | unsigned LowOpcodeK, unsigned HighOpcode) const; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 143 | void expandRXYPseudo(MachineInstr &MI, unsigned LowOpcode, |
| Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 144 | unsigned HighOpcode) const; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 145 | void expandZExtPseudo(MachineInstr &MI, unsigned LowOpcode, |
| Richard Sandiford | 21235a2 | 2013-10-01 12:49:07 +0000 | [diff] [blame] | 146 | unsigned Size) const; |
| Marcin Koscielnicki | aef3b5b | 2016-04-24 13:57:49 +0000 | [diff] [blame] | 147 | void expandLoadStackGuard(MachineInstr *MI) const; |
| Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 148 | void emitGRX32Move(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 149 | const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, |
| Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 150 | unsigned LowLowOpcode, unsigned Size, bool KillSrc) const; |
| Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 151 | virtual void anchor(); |
| Richard Sandiford | 0755c93 | 2013-10-01 11:26:28 +0000 | [diff] [blame] | 152 | |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 153 | public: |
| Eric Christopher | 673b3af | 2014-06-27 07:01:17 +0000 | [diff] [blame] | 154 | explicit SystemZInstrInfo(SystemZSubtarget &STI); |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 155 | |
| 156 | // Override TargetInstrInfo. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 157 | unsigned isLoadFromStackSlot(const MachineInstr &MI, |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 158 | int &FrameIndex) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 159 | unsigned isStoreToStackSlot(const MachineInstr &MI, |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 160 | int &FrameIndex) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 161 | bool isStackSlotCopy(const MachineInstr &MI, int &DestFrameIndex, |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 162 | int &SrcFrameIndex) const override; |
| Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame^] | 163 | bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 164 | MachineBasicBlock *&FBB, |
| 165 | SmallVectorImpl<MachineOperand> &Cond, |
| 166 | bool AllowModify) const override; |
| 167 | unsigned RemoveBranch(MachineBasicBlock &MBB) const override; |
| 168 | unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 169 | MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 170 | const DebugLoc &DL) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 171 | bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg, |
| Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 172 | unsigned &SrcReg2, int &Mask, int &Value) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 173 | bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg, |
| Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 174 | unsigned SrcReg2, int Mask, int Value, |
| Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 175 | const MachineRegisterInfo *MRI) const override; |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 176 | bool isPredicable(MachineInstr &MI) const override; |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 177 | bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| 178 | unsigned ExtraPredCycles, |
| Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 179 | BranchProbability Probability) const override; |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 180 | bool isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 181 | unsigned NumCyclesT, unsigned ExtraPredCyclesT, |
| 182 | MachineBasicBlock &FMBB, |
| 183 | unsigned NumCyclesF, unsigned ExtraPredCyclesF, |
| Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 184 | BranchProbability Probability) const override; |
| Ulrich Weigand | 2eb027d | 2016-04-07 16:11:44 +0000 | [diff] [blame] | 185 | bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| 186 | BranchProbability Probability) const override; |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 187 | bool PredicateInstruction(MachineInstr &MI, |
| Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 188 | ArrayRef<MachineOperand> Pred) const override; |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 189 | void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 190 | const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 191 | bool KillSrc) const override; |
| 192 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 193 | MachineBasicBlock::iterator MBBI, |
| 194 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 195 | const TargetRegisterClass *RC, |
| 196 | const TargetRegisterInfo *TRI) const override; |
| 197 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 198 | MachineBasicBlock::iterator MBBI, |
| 199 | unsigned DestReg, int FrameIdx, |
| 200 | const TargetRegisterClass *RC, |
| 201 | const TargetRegisterInfo *TRI) const override; |
| 202 | MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 203 | MachineInstr &MI, |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 204 | LiveVariables *LV) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 205 | MachineInstr * |
| 206 | foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, |
| 207 | ArrayRef<unsigned> Ops, |
| 208 | MachineBasicBlock::iterator InsertPt, int FrameIndex, |
| 209 | LiveIntervals *LIS = nullptr) const override; |
| 210 | MachineInstr *foldMemoryOperandImpl( |
| 211 | MachineFunction &MF, MachineInstr &MI, ArrayRef<unsigned> Ops, |
| 212 | MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI, |
| 213 | LiveIntervals *LIS = nullptr) const override; |
| 214 | bool expandPostRAPseudo(MachineInstr &MBBI) const override; |
| Richard Sandiford | b4d67b5 | 2014-03-06 12:03:36 +0000 | [diff] [blame] | 215 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const |
| 216 | override; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 217 | |
| 218 | // Return the SystemZRegisterInfo, which this class owns. |
| 219 | const SystemZRegisterInfo &getRegisterInfo() const { return RI; } |
| 220 | |
| Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 221 | // Return the size in bytes of MI. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 222 | uint64_t getInstSizeInBytes(const MachineInstr &MI) const; |
| Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 223 | |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 224 | // Return true if MI is a conditional or unconditional branch. |
| 225 | // When returning true, set Cond to the mask of condition-code |
| 226 | // values on which the instruction will branch, and set Target |
| 227 | // to the operand that contains the branch target. This target |
| 228 | // can be a register or a basic block. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 229 | SystemZII::Branch getBranchInfo(const MachineInstr &MI) const; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 230 | |
| 231 | // Get the load and store opcodes for a given register class. |
| 232 | void getLoadStoreOpcodes(const TargetRegisterClass *RC, |
| 233 | unsigned &LoadOpcode, unsigned &StoreOpcode) const; |
| 234 | |
| 235 | // Opcode is the opcode of an instruction that has an address operand, |
| 236 | // and the caller wants to perform that instruction's operation on an |
| 237 | // address that has displacement Offset. Return the opcode of a suitable |
| 238 | // instruction (which might be Opcode itself) or 0 if no such instruction |
| 239 | // exists. |
| 240 | unsigned getOpcodeForOffset(unsigned Opcode, int64_t Offset) const; |
| 241 | |
| Richard Sandiford | b49a3ab | 2013-08-05 11:03:20 +0000 | [diff] [blame] | 242 | // If Opcode is a load instruction that has a LOAD AND TEST form, |
| 243 | // return the opcode for the testing form, otherwise return 0. |
| 244 | unsigned getLoadAndTest(unsigned Opcode) const; |
| 245 | |
| Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 246 | // Return true if ROTATE AND ... SELECTED BITS can be used to select bits |
| 247 | // Mask of the R2 operand, given that only the low BitSize bits of Mask are |
| 248 | // significant. Set Start and End to the I3 and I4 operands if so. |
| 249 | bool isRxSBGMask(uint64_t Mask, unsigned BitSize, |
| 250 | unsigned &Start, unsigned &End) const; |
| 251 | |
| Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 252 | // If Opcode is a COMPARE opcode for which an associated fused COMPARE AND * |
| 253 | // operation exists, return the opcode for the latter, otherwise return 0. |
| Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 254 | // MI, if nonnull, is the compare instruction. |
| Zhan Jun Liau | ab42cbc | 2016-06-10 19:58:10 +0000 | [diff] [blame] | 255 | unsigned getFusedCompare(unsigned Opcode, |
| 256 | SystemZII::FusedCompareType Type, |
| 257 | const MachineInstr *MI = nullptr) const; |
| Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 258 | |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 259 | // Emit code before MBBI in MI to move immediate value Value into |
| 260 | // physical register Reg. |
| 261 | void loadImmediate(MachineBasicBlock &MBB, |
| 262 | MachineBasicBlock::iterator MBBI, |
| 263 | unsigned Reg, uint64_t Value) const; |
| 264 | }; |
| 265 | } // end namespace llvm |
| 266 | |
| 267 | #endif |