| 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 | |
| 14 | #ifndef LLVM_TARGET_SYSTEMZINSTRINFO_H |
| 15 | #define LLVM_TARGET_SYSTEMZINSTRINFO_H |
| 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 { |
| 29 | enum { |
| 30 | // See comments in SystemZInstrFormats.td. |
| 31 | SimpleBDXLoad = (1 << 0), |
| 32 | SimpleBDXStore = (1 << 1), |
| 33 | Has20BitOffset = (1 << 2), |
| 34 | HasIndex = (1 << 3), |
| Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 35 | Is128Bit = (1 << 4), |
| 36 | AccessSizeMask = (31 << 5), |
| 37 | AccessSizeShift = 5 |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 38 | }; |
| Richard Sandiford | ed1fab6 | 2013-07-03 10:10:02 +0000 | [diff] [blame] | 39 | static inline unsigned getAccessSize(unsigned int Flags) { |
| 40 | return (Flags & AccessSizeMask) >> AccessSizeShift; |
| 41 | } |
| 42 | |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 43 | // SystemZ MachineOperand target flags. |
| 44 | enum { |
| 45 | // Masks out the bits for the access model. |
| 46 | MO_SYMBOL_MODIFIER = (1 << 0), |
| 47 | |
| 48 | // @GOT (aka @GOTENT) |
| 49 | MO_GOT = (1 << 0) |
| 50 | }; |
| Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 51 | // Classifies a branch. |
| 52 | enum BranchType { |
| 53 | // An instruction that branches on the current value of CC. |
| 54 | BranchNormal, |
| 55 | |
| 56 | // An instruction that peforms a 32-bit signed comparison and branches |
| 57 | // on the result. |
| 58 | BranchC, |
| 59 | |
| 60 | // An instruction that peforms a 64-bit signed comparison and branches |
| 61 | // on the result. |
| 62 | BranchCG |
| 63 | }; |
| Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 64 | // Information about a branch instruction. |
| 65 | struct Branch { |
| Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 66 | // The type of the branch. |
| 67 | BranchType Type; |
| 68 | |
| Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame^] | 69 | // CCMASK_<N> is set if CC might be equal to N. |
| 70 | unsigned CCValid; |
| 71 | |
| Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 72 | // CCMASK_<N> is set if the branch should be taken when CC == N. |
| 73 | unsigned CCMask; |
| 74 | |
| 75 | // The target of the branch. |
| 76 | const MachineOperand *Target; |
| 77 | |
| Richard Sandiford | 3d768e3 | 2013-07-31 12:30:20 +0000 | [diff] [blame^] | 78 | Branch(BranchType type, unsigned ccValid, unsigned ccMask, |
| 79 | const MachineOperand *target) |
| 80 | : Type(type), CCValid(ccValid), CCMask(ccMask), Target(target) {} |
| Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 81 | }; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | class SystemZInstrInfo : public SystemZGenInstrInfo { |
| 85 | const SystemZRegisterInfo RI; |
| Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 86 | SystemZTargetMachine &TM; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 87 | |
| 88 | void splitMove(MachineBasicBlock::iterator MI, unsigned NewOpcode) const; |
| 89 | void splitAdjDynAlloc(MachineBasicBlock::iterator MI) const; |
| 90 | |
| 91 | public: |
| 92 | explicit SystemZInstrInfo(SystemZTargetMachine &TM); |
| 93 | |
| 94 | // Override TargetInstrInfo. |
| 95 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 96 | int &FrameIndex) const LLVM_OVERRIDE; |
| 97 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 98 | int &FrameIndex) const LLVM_OVERRIDE; |
| Richard Sandiford | c40f27b | 2013-07-05 14:38:48 +0000 | [diff] [blame] | 99 | virtual bool isStackSlotCopy(const MachineInstr *MI, int &DestFrameIndex, |
| 100 | int &SrcFrameIndex) const LLVM_OVERRIDE; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 101 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, |
| 102 | MachineBasicBlock *&TBB, |
| 103 | MachineBasicBlock *&FBB, |
| 104 | SmallVectorImpl<MachineOperand> &Cond, |
| 105 | bool AllowModify) const LLVM_OVERRIDE; |
| 106 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const LLVM_OVERRIDE; |
| 107 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 108 | MachineBasicBlock *FBB, |
| 109 | const SmallVectorImpl<MachineOperand> &Cond, |
| 110 | DebugLoc DL) const LLVM_OVERRIDE; |
| Richard Sandiford | f240416 | 2013-07-25 09:11:15 +0000 | [diff] [blame] | 111 | virtual bool isPredicable(MachineInstr *MI) const LLVM_OVERRIDE; |
| 112 | virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| 113 | unsigned ExtraPredCycles, |
| 114 | const BranchProbability &Probability) const |
| 115 | LLVM_OVERRIDE; |
| 116 | virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 117 | unsigned NumCyclesT, |
| 118 | unsigned ExtraPredCyclesT, |
| 119 | MachineBasicBlock &FMBB, |
| 120 | unsigned NumCyclesF, |
| 121 | unsigned ExtraPredCyclesF, |
| 122 | const BranchProbability &Probability) const |
| 123 | LLVM_OVERRIDE; |
| 124 | virtual bool |
| 125 | PredicateInstruction(MachineInstr *MI, |
| 126 | const SmallVectorImpl<MachineOperand> &Pred) const |
| 127 | LLVM_OVERRIDE; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 128 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 129 | MachineBasicBlock::iterator MBBI, DebugLoc DL, |
| 130 | unsigned DestReg, unsigned SrcReg, |
| 131 | bool KillSrc) const LLVM_OVERRIDE; |
| 132 | virtual void |
| 133 | storeRegToStackSlot(MachineBasicBlock &MBB, |
| 134 | MachineBasicBlock::iterator MBBI, |
| 135 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 136 | const TargetRegisterClass *RC, |
| 137 | const TargetRegisterInfo *TRI) const LLVM_OVERRIDE; |
| 138 | virtual void |
| 139 | loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 140 | MachineBasicBlock::iterator MBBI, |
| 141 | unsigned DestReg, int FrameIdx, |
| 142 | const TargetRegisterClass *RC, |
| 143 | const TargetRegisterInfo *TRI) const LLVM_OVERRIDE; |
| Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 144 | virtual MachineInstr * |
| Richard Sandiford | ff6c5a5 | 2013-07-19 16:12:08 +0000 | [diff] [blame] | 145 | convertToThreeAddress(MachineFunction::iterator &MFI, |
| 146 | MachineBasicBlock::iterator &MBBI, |
| 147 | LiveVariables *LV) const; |
| 148 | virtual MachineInstr * |
| Richard Sandiford | f6bae1e | 2013-07-02 15:28:56 +0000 | [diff] [blame] | 149 | foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI, |
| 150 | const SmallVectorImpl<unsigned> &Ops, |
| 151 | int FrameIndex) const; |
| 152 | virtual MachineInstr * |
| 153 | foldMemoryOperandImpl(MachineFunction &MF, MachineInstr* MI, |
| 154 | const SmallVectorImpl<unsigned> &Ops, |
| 155 | MachineInstr* LoadMI) const; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 156 | virtual bool |
| 157 | expandPostRAPseudo(MachineBasicBlock::iterator MBBI) const LLVM_OVERRIDE; |
| 158 | virtual bool |
| 159 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const |
| 160 | LLVM_OVERRIDE; |
| 161 | |
| 162 | // Return the SystemZRegisterInfo, which this class owns. |
| 163 | const SystemZRegisterInfo &getRegisterInfo() const { return RI; } |
| 164 | |
| Richard Sandiford | 312425f | 2013-05-20 14:23:08 +0000 | [diff] [blame] | 165 | // Return the size in bytes of MI. |
| 166 | uint64_t getInstSizeInBytes(const MachineInstr *MI) const; |
| 167 | |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 168 | // Return true if MI is a conditional or unconditional branch. |
| 169 | // When returning true, set Cond to the mask of condition-code |
| 170 | // values on which the instruction will branch, and set Target |
| 171 | // to the operand that contains the branch target. This target |
| 172 | // can be a register or a basic block. |
| Richard Sandiford | 53c9efd | 2013-05-28 10:13:54 +0000 | [diff] [blame] | 173 | SystemZII::Branch getBranchInfo(const MachineInstr *MI) const; |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 174 | |
| 175 | // Get the load and store opcodes for a given register class. |
| 176 | void getLoadStoreOpcodes(const TargetRegisterClass *RC, |
| 177 | unsigned &LoadOpcode, unsigned &StoreOpcode) const; |
| 178 | |
| 179 | // Opcode is the opcode of an instruction that has an address operand, |
| 180 | // and the caller wants to perform that instruction's operation on an |
| 181 | // address that has displacement Offset. Return the opcode of a suitable |
| 182 | // instruction (which might be Opcode itself) or 0 if no such instruction |
| 183 | // exists. |
| 184 | unsigned getOpcodeForOffset(unsigned Opcode, int64_t Offset) const; |
| 185 | |
| Richard Sandiford | 6a06ba3 | 2013-07-31 11:36:35 +0000 | [diff] [blame] | 186 | // Return true if ROTATE AND ... SELECTED BITS can be used to select bits |
| 187 | // Mask of the R2 operand, given that only the low BitSize bits of Mask are |
| 188 | // significant. Set Start and End to the I3 and I4 operands if so. |
| 189 | bool isRxSBGMask(uint64_t Mask, unsigned BitSize, |
| 190 | unsigned &Start, unsigned &End) const; |
| 191 | |
| Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 192 | // If Opcode is a COMPARE opcode for which an associated COMPARE AND |
| 193 | // BRANCH exists, return the opcode for the latter, otherwise return 0. |
| Richard Sandiford | e1d9f00 | 2013-05-29 11:58:52 +0000 | [diff] [blame] | 194 | // MI, if nonnull, is the compare instruction. |
| 195 | unsigned getCompareAndBranch(unsigned Opcode, |
| 196 | const MachineInstr *MI = 0) const; |
| Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 197 | |
| Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 198 | // Emit code before MBBI in MI to move immediate value Value into |
| 199 | // physical register Reg. |
| 200 | void loadImmediate(MachineBasicBlock &MBB, |
| 201 | MachineBasicBlock::iterator MBBI, |
| 202 | unsigned Reg, uint64_t Value) const; |
| 203 | }; |
| 204 | } // end namespace llvm |
| 205 | |
| 206 | #endif |