LLVM  8.0.1
SystemZInstrInfo.h
Go to the documentation of this file.
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_LIB_TARGET_SYSTEMZ_SYSTEMZINSTRINFO_H
15 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZINSTRINFO_H
16 
17 #include "SystemZ.h"
18 #include "SystemZRegisterInfo.h"
19 #include "llvm/ADT/ArrayRef.h"
24 #include <cstdint>
25 
26 #define GET_INSTRINFO_HEADER
27 #include "SystemZGenInstrInfo.inc"
28 
29 namespace llvm {
30 
31 class SystemZSubtarget;
32 
33 namespace SystemZII {
34 
35 enum {
36  // See comments in SystemZInstrFormats.td.
37  SimpleBDXLoad = (1 << 0),
38  SimpleBDXStore = (1 << 1),
39  Has20BitOffset = (1 << 2),
40  HasIndex = (1 << 3),
41  Is128Bit = (1 << 4),
42  AccessSizeMask = (31 << 5),
44  CCValuesMask = (15 << 10),
46  CompareZeroCCMaskMask = (15 << 14),
48  CCMaskFirst = (1 << 18),
49  CCMaskLast = (1 << 19),
50  IsLogical = (1 << 20)
51 };
52 
53 static inline unsigned getAccessSize(unsigned int Flags) {
54  return (Flags & AccessSizeMask) >> AccessSizeShift;
55 }
56 
57 static inline unsigned getCCValues(unsigned int Flags) {
58  return (Flags & CCValuesMask) >> CCValuesShift;
59 }
60 
61 static inline unsigned getCompareZeroCCMask(unsigned int Flags) {
63 }
64 
65 // SystemZ MachineOperand target flags.
66 enum {
67  // Masks out the bits for the access model.
68  MO_SYMBOL_MODIFIER = (3 << 0),
69 
70  // @GOT (aka @GOTENT)
71  MO_GOT = (1 << 0),
72 
73  // @INDNTPOFF
74  MO_INDNTPOFF = (2 << 0)
75 };
76 
77 // Classifies a branch.
78 enum BranchType {
79  // An instruction that branches on the current value of CC.
81 
82  // An instruction that peforms a 32-bit signed comparison and branches
83  // on the result.
85 
86  // An instruction that peforms a 32-bit unsigned comparison and branches
87  // on the result.
89 
90  // An instruction that peforms a 64-bit signed comparison and branches
91  // on the result.
93 
94  // An instruction that peforms a 64-bit unsigned comparison and branches
95  // on the result.
97 
98  // An instruction that decrements a 32-bit register and branches if
99  // the result is nonzero.
101 
102  // An instruction that decrements a 64-bit register and branches if
103  // the result is nonzero.
105 };
106 
107 // Information about a branch instruction.
108 struct Branch {
109  // The type of the branch.
111 
112  // CCMASK_<N> is set if CC might be equal to N.
113  unsigned CCValid;
114 
115  // CCMASK_<N> is set if the branch should be taken when CC == N.
116  unsigned CCMask;
117 
118  // The target of the branch.
120 
121  Branch(BranchType type, unsigned ccValid, unsigned ccMask,
122  const MachineOperand *target)
123  : Type(type), CCValid(ccValid), CCMask(ccMask), Target(target) {}
124 };
125 
126 // Kinds of fused compares in compare-and-* instructions. Together with type
127 // of the converted compare, this identifies the compare-and-*
128 // instruction.
130  // Relative branch - CRJ etc.
132 
133  // Indirect branch, used for return - CRBReturn etc.
135 
136  // Indirect branch, used for sibcall - CRBCall etc.
138 
139  // Trap
141 };
142 
143 } // end namespace SystemZII
144 
146  const SystemZRegisterInfo RI;
147  SystemZSubtarget &STI;
148 
149  void splitMove(MachineBasicBlock::iterator MI, unsigned NewOpcode) const;
150  void splitAdjDynAlloc(MachineBasicBlock::iterator MI) const;
151  void expandRIPseudo(MachineInstr &MI, unsigned LowOpcode, unsigned HighOpcode,
152  bool ConvertHigh) const;
153  void expandRIEPseudo(MachineInstr &MI, unsigned LowOpcode,
154  unsigned LowOpcodeK, unsigned HighOpcode) const;
155  void expandRXYPseudo(MachineInstr &MI, unsigned LowOpcode,
156  unsigned HighOpcode) const;
157  void expandLOCPseudo(MachineInstr &MI, unsigned LowOpcode,
158  unsigned HighOpcode) const;
159  void expandLOCRPseudo(MachineInstr &MI, unsigned LowOpcode,
160  unsigned HighOpcode) const;
161  void expandZExtPseudo(MachineInstr &MI, unsigned LowOpcode,
162  unsigned Size) const;
163  void expandLoadStackGuard(MachineInstr *MI) const;
164 
166  emitGRX32Move(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
167  const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
168  unsigned LowLowOpcode, unsigned Size, bool KillSrc,
169  bool UndefSrc) const;
170 
171  virtual void anchor();
172 
173 protected:
174  /// Commutes the operands in the given instruction by changing the operands
175  /// order and/or changing the instruction's opcode and/or the immediate value
176  /// operand.
177  ///
178  /// The arguments 'CommuteOpIdx1' and 'CommuteOpIdx2' specify the operands
179  /// to be commuted.
180  ///
181  /// Do not call this method for a non-commutable instruction or
182  /// non-commutable operands.
183  /// Even though the instruction is commutable, the method may still
184  /// fail to commute the operands, null pointer is returned in such cases.
185  MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI,
186  unsigned CommuteOpIdx1,
187  unsigned CommuteOpIdx2) const override;
188 
189 public:
190  explicit SystemZInstrInfo(SystemZSubtarget &STI);
191 
192  // Override TargetInstrInfo.
193  unsigned isLoadFromStackSlot(const MachineInstr &MI,
194  int &FrameIndex) const override;
195  unsigned isStoreToStackSlot(const MachineInstr &MI,
196  int &FrameIndex) const override;
197  bool isStackSlotCopy(const MachineInstr &MI, int &DestFrameIndex,
198  int &SrcFrameIndex) const override;
199  bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
200  MachineBasicBlock *&FBB,
202  bool AllowModify) const override;
203  unsigned removeBranch(MachineBasicBlock &MBB,
204  int *BytesRemoved = nullptr) const override;
205  unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
207  const DebugLoc &DL,
208  int *BytesAdded = nullptr) const override;
209  bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
210  unsigned &SrcReg2, int &Mask, int &Value) const override;
211  bool canInsertSelect(const MachineBasicBlock&, ArrayRef<MachineOperand> Cond,
212  unsigned, unsigned, int&, int&, int&) const override;
213  void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
214  const DebugLoc &DL, unsigned DstReg,
215  ArrayRef<MachineOperand> Cond, unsigned TrueReg,
216  unsigned FalseReg) const override;
217  bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, unsigned Reg,
218  MachineRegisterInfo *MRI) const override;
219  bool isPredicable(const MachineInstr &MI) const override;
220  bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
221  unsigned ExtraPredCycles,
222  BranchProbability Probability) const override;
223  bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
224  unsigned NumCyclesT, unsigned ExtraPredCyclesT,
225  MachineBasicBlock &FMBB,
226  unsigned NumCyclesF, unsigned ExtraPredCyclesF,
227  BranchProbability Probability) const override;
228  bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
229  BranchProbability Probability) const override;
230  bool PredicateInstruction(MachineInstr &MI,
231  ArrayRef<MachineOperand> Pred) const override;
232  void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
233  const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
234  bool KillSrc) const override;
235  void storeRegToStackSlot(MachineBasicBlock &MBB,
237  unsigned SrcReg, bool isKill, int FrameIndex,
238  const TargetRegisterClass *RC,
239  const TargetRegisterInfo *TRI) const override;
240  void loadRegFromStackSlot(MachineBasicBlock &MBB,
242  unsigned DestReg, int FrameIdx,
243  const TargetRegisterClass *RC,
244  const TargetRegisterInfo *TRI) const override;
245  MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
246  MachineInstr &MI,
247  LiveVariables *LV) const override;
248  MachineInstr *
249  foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI,
250  ArrayRef<unsigned> Ops,
251  MachineBasicBlock::iterator InsertPt, int FrameIndex,
252  LiveIntervals *LIS = nullptr) const override;
253  MachineInstr *foldMemoryOperandImpl(
255  MachineBasicBlock::iterator InsertPt, MachineInstr &LoadMI,
256  LiveIntervals *LIS = nullptr) const override;
257  bool expandPostRAPseudo(MachineInstr &MBBI) const override;
258  bool reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const
259  override;
260 
261  // Return the SystemZRegisterInfo, which this class owns.
262  const SystemZRegisterInfo &getRegisterInfo() const { return RI; }
263 
264  // Return the size in bytes of MI.
265  unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
266 
267  // Return true if MI is a conditional or unconditional branch.
268  // When returning true, set Cond to the mask of condition-code
269  // values on which the instruction will branch, and set Target
270  // to the operand that contains the branch target. This target
271  // can be a register or a basic block.
272  SystemZII::Branch getBranchInfo(const MachineInstr &MI) const;
273 
274  // Get the load and store opcodes for a given register class.
275  void getLoadStoreOpcodes(const TargetRegisterClass *RC,
276  unsigned &LoadOpcode, unsigned &StoreOpcode) const;
277 
278  // Opcode is the opcode of an instruction that has an address operand,
279  // and the caller wants to perform that instruction's operation on an
280  // address that has displacement Offset. Return the opcode of a suitable
281  // instruction (which might be Opcode itself) or 0 if no such instruction
282  // exists.
283  unsigned getOpcodeForOffset(unsigned Opcode, int64_t Offset) const;
284 
285  // If Opcode is a load instruction that has a LOAD AND TEST form,
286  // return the opcode for the testing form, otherwise return 0.
287  unsigned getLoadAndTest(unsigned Opcode) const;
288 
289  // Return true if ROTATE AND ... SELECTED BITS can be used to select bits
290  // Mask of the R2 operand, given that only the low BitSize bits of Mask are
291  // significant. Set Start and End to the I3 and I4 operands if so.
292  bool isRxSBGMask(uint64_t Mask, unsigned BitSize,
293  unsigned &Start, unsigned &End) const;
294 
295  // If Opcode is a COMPARE opcode for which an associated fused COMPARE AND *
296  // operation exists, return the opcode for the latter, otherwise return 0.
297  // MI, if nonnull, is the compare instruction.
298  unsigned getFusedCompare(unsigned Opcode,
300  const MachineInstr *MI = nullptr) const;
301 
302  // If Opcode is a LOAD opcode for with an associated LOAD AND TRAP
303  // operation exists, returh the opcode for the latter, otherwise return 0.
304  unsigned getLoadAndTrap(unsigned Opcode) const;
305 
306  // Emit code before MBBI in MI to move immediate value Value into
307  // physical register Reg.
308  void loadImmediate(MachineBasicBlock &MBB,
310  unsigned Reg, uint64_t Value) const;
311 
312  // Sometimes, it is possible for the target to tell, even without
313  // aliasing information, that two MIs access different memory
314  // addresses. This function returns true if two MIs access different
315  // memory addresses and false otherwise.
316  bool
317  areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,
318  AliasAnalysis *AA = nullptr) const override;
319 };
320 
321 } // end namespace llvm
322 
323 #endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZINSTRINFO_H
const SystemZRegisterInfo & getRegisterInfo() const
This class represents lattice values for constants.
Definition: AllocatorList.h:24
unsigned Reg
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:34
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
Branch(BranchType type, unsigned ccValid, unsigned ccMask, const MachineOperand *target)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
const MachineOperand * Target
BasicBlockListType::iterator iterator
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static unsigned getAccessSize(unsigned int Flags)
MachineInstrBuilder & UseMI
static void expandLoadStackGuard(MachineInstrBuilder &MIB, const TargetInstrInfo &TII)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static unsigned getCompareZeroCCMask(unsigned int Flags)
MachineOperand class - Representation of each machine instruction operand.
MachineInstrBuilder MachineInstrBuilder & DefMI
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:64
static unsigned getCCValues(unsigned int Flags)
uint32_t Size
Definition: Profile.cpp:47
LLVM Value Representation.
Definition: Value.h:73
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
IRTranslator LLVM IR MI