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