1 //===-- SystemZInstrInfo.h - SystemZ instruction information ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the SystemZ implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_SYSTEMZINSTRINFO_H
15 #define LLVM_TARGET_SYSTEMZINSTRINFO_H
18 #include "SystemZRegisterInfo.h"
19 #include "llvm/Target/TargetInstrInfo.h"
21 #define GET_INSTRINFO_HEADER
22 #include "SystemZGenInstrInfo.inc"
26 class SystemZTargetMachine;
30 // See comments in SystemZInstrFormats.td.
31 SimpleBDXLoad = (1 << 0),
32 SimpleBDXStore = (1 << 1),
33 Has20BitOffset = (1 << 2),
36 AccessSizeMask = (31 << 5),
38 CCValuesMask = (15 << 10),
40 CCHasZero = (1 << 14),
41 CCHasOrder = (1 << 15),
42 CCMaskFirst = (1 << 16),
43 CCMaskLast = (1 << 17),
46 static inline unsigned getAccessSize(unsigned int Flags) {
47 return (Flags & AccessSizeMask) >> AccessSizeShift;
49 static inline unsigned getCCValues(unsigned int Flags) {
50 return (Flags & CCValuesMask) >> CCValuesShift;
53 // SystemZ MachineOperand target flags.
55 // Masks out the bits for the access model.
56 MO_SYMBOL_MODIFIER = (1 << 0),
61 // Classifies a branch.
63 // An instruction that branches on the current value of CC.
66 // An instruction that peforms a 32-bit signed comparison and branches
70 // An instruction that peforms a 64-bit signed comparison and branches
74 // An instruction that decrements a 32-bit register and branches if
75 // the result is nonzero.
78 // An instruction that decrements a 64-bit register and branches if
79 // the result is nonzero.
82 // Information about a branch instruction.
84 // The type of the branch.
87 // CCMASK_<N> is set if CC might be equal to N.
90 // CCMASK_<N> is set if the branch should be taken when CC == N.
93 // The target of the branch.
94 const MachineOperand *Target;
96 Branch(BranchType type, unsigned ccValid, unsigned ccMask,
97 const MachineOperand *target)
98 : Type(type), CCValid(ccValid), CCMask(ccMask), Target(target) {}
102 class SystemZInstrInfo : public SystemZGenInstrInfo {
103 const SystemZRegisterInfo RI;
104 SystemZTargetMachine &TM;
106 void splitMove(MachineBasicBlock::iterator MI, unsigned NewOpcode) const;
107 void splitAdjDynAlloc(MachineBasicBlock::iterator MI) const;
110 explicit SystemZInstrInfo(SystemZTargetMachine &TM);
112 // Override TargetInstrInfo.
113 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
114 int &FrameIndex) const LLVM_OVERRIDE;
115 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
116 int &FrameIndex) const LLVM_OVERRIDE;
117 virtual bool isStackSlotCopy(const MachineInstr *MI, int &DestFrameIndex,
118 int &SrcFrameIndex) const LLVM_OVERRIDE;
119 virtual bool AnalyzeBranch(MachineBasicBlock &MBB,
120 MachineBasicBlock *&TBB,
121 MachineBasicBlock *&FBB,
122 SmallVectorImpl<MachineOperand> &Cond,
123 bool AllowModify) const LLVM_OVERRIDE;
124 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const LLVM_OVERRIDE;
125 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
126 MachineBasicBlock *FBB,
127 const SmallVectorImpl<MachineOperand> &Cond,
128 DebugLoc DL) const LLVM_OVERRIDE;
129 virtual bool isPredicable(MachineInstr *MI) const LLVM_OVERRIDE;
130 virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
131 unsigned ExtraPredCycles,
132 const BranchProbability &Probability) const
134 virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
136 unsigned ExtraPredCyclesT,
137 MachineBasicBlock &FMBB,
139 unsigned ExtraPredCyclesF,
140 const BranchProbability &Probability) const
143 PredicateInstruction(MachineInstr *MI,
144 const SmallVectorImpl<MachineOperand> &Pred) const
146 virtual void copyPhysReg(MachineBasicBlock &MBB,
147 MachineBasicBlock::iterator MBBI, DebugLoc DL,
148 unsigned DestReg, unsigned SrcReg,
149 bool KillSrc) const LLVM_OVERRIDE;
151 storeRegToStackSlot(MachineBasicBlock &MBB,
152 MachineBasicBlock::iterator MBBI,
153 unsigned SrcReg, bool isKill, int FrameIndex,
154 const TargetRegisterClass *RC,
155 const TargetRegisterInfo *TRI) const LLVM_OVERRIDE;
157 loadRegFromStackSlot(MachineBasicBlock &MBB,
158 MachineBasicBlock::iterator MBBI,
159 unsigned DestReg, int FrameIdx,
160 const TargetRegisterClass *RC,
161 const TargetRegisterInfo *TRI) const LLVM_OVERRIDE;
162 virtual MachineInstr *
163 convertToThreeAddress(MachineFunction::iterator &MFI,
164 MachineBasicBlock::iterator &MBBI,
165 LiveVariables *LV) const;
166 virtual MachineInstr *
167 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
168 const SmallVectorImpl<unsigned> &Ops,
169 int FrameIndex) const;
170 virtual MachineInstr *
171 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr* MI,
172 const SmallVectorImpl<unsigned> &Ops,
173 MachineInstr* LoadMI) const;
175 expandPostRAPseudo(MachineBasicBlock::iterator MBBI) const LLVM_OVERRIDE;
177 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const
180 // Return the SystemZRegisterInfo, which this class owns.
181 const SystemZRegisterInfo &getRegisterInfo() const { return RI; }
183 // Return the size in bytes of MI.
184 uint64_t getInstSizeInBytes(const MachineInstr *MI) const;
186 // Return true if MI is a conditional or unconditional branch.
187 // When returning true, set Cond to the mask of condition-code
188 // values on which the instruction will branch, and set Target
189 // to the operand that contains the branch target. This target
190 // can be a register or a basic block.
191 SystemZII::Branch getBranchInfo(const MachineInstr *MI) const;
193 // Get the load and store opcodes for a given register class.
194 void getLoadStoreOpcodes(const TargetRegisterClass *RC,
195 unsigned &LoadOpcode, unsigned &StoreOpcode) const;
197 // Opcode is the opcode of an instruction that has an address operand,
198 // and the caller wants to perform that instruction's operation on an
199 // address that has displacement Offset. Return the opcode of a suitable
200 // instruction (which might be Opcode itself) or 0 if no such instruction
202 unsigned getOpcodeForOffset(unsigned Opcode, int64_t Offset) const;
204 // If Opcode is a load instruction that has a LOAD AND TEST form,
205 // return the opcode for the testing form, otherwise return 0.
206 unsigned getLoadAndTest(unsigned Opcode) const;
208 // Return true if ROTATE AND ... SELECTED BITS can be used to select bits
209 // Mask of the R2 operand, given that only the low BitSize bits of Mask are
210 // significant. Set Start and End to the I3 and I4 operands if so.
211 bool isRxSBGMask(uint64_t Mask, unsigned BitSize,
212 unsigned &Start, unsigned &End) const;
214 // If Opcode is a COMPARE opcode for which an associated COMPARE AND
215 // BRANCH exists, return the opcode for the latter, otherwise return 0.
216 // MI, if nonnull, is the compare instruction.
217 unsigned getCompareAndBranch(unsigned Opcode,
218 const MachineInstr *MI = 0) const;
220 // Emit code before MBBI in MI to move immediate value Value into
221 // physical register Reg.
222 void loadImmediate(MachineBasicBlock &MBB,
223 MachineBasicBlock::iterator MBBI,
224 unsigned Reg, uint64_t Value) const;
226 } // end namespace llvm