blob: 7fc0ca9a7a6e6ed22a6798f47bad06b783b4265f [file] [log] [blame]
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001//===-- 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
24namespace llvm {
25
26class SystemZTargetMachine;
27
28namespace 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 Sandiforded1fab62013-07-03 10:10:02 +000035 Is128Bit = (1 << 4),
36 AccessSizeMask = (31 << 5),
37 AccessSizeShift = 5
Ulrich Weigand5f613df2013-05-06 16:15:19 +000038 };
Richard Sandiforded1fab62013-07-03 10:10:02 +000039 static inline unsigned getAccessSize(unsigned int Flags) {
40 return (Flags & AccessSizeMask) >> AccessSizeShift;
41 }
42
Ulrich Weigand5f613df2013-05-06 16:15:19 +000043 // 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 Sandiford0fb90ab2013-05-28 10:41:11 +000051 // 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 Sandiford53c9efd2013-05-28 10:13:54 +000064 // Information about a branch instruction.
65 struct Branch {
Richard Sandiford0fb90ab2013-05-28 10:41:11 +000066 // The type of the branch.
67 BranchType Type;
68
Richard Sandiford53c9efd2013-05-28 10:13:54 +000069 // CCMASK_<N> is set if the branch should be taken when CC == N.
70 unsigned CCMask;
71
72 // The target of the branch.
73 const MachineOperand *Target;
74
Richard Sandiford0fb90ab2013-05-28 10:41:11 +000075 Branch(BranchType type, unsigned ccMask, const MachineOperand *target)
76 : Type(type), CCMask(ccMask), Target(target) {}
Richard Sandiford53c9efd2013-05-28 10:13:54 +000077 };
Ulrich Weigand5f613df2013-05-06 16:15:19 +000078}
79
80class SystemZInstrInfo : public SystemZGenInstrInfo {
81 const SystemZRegisterInfo RI;
Richard Sandifordff6c5a52013-07-19 16:12:08 +000082 SystemZTargetMachine &TM;
Ulrich Weigand5f613df2013-05-06 16:15:19 +000083
84 void splitMove(MachineBasicBlock::iterator MI, unsigned NewOpcode) const;
85 void splitAdjDynAlloc(MachineBasicBlock::iterator MI) const;
86
87public:
88 explicit SystemZInstrInfo(SystemZTargetMachine &TM);
89
90 // Override TargetInstrInfo.
91 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
92 int &FrameIndex) const LLVM_OVERRIDE;
93 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
94 int &FrameIndex) const LLVM_OVERRIDE;
Richard Sandifordc40f27b2013-07-05 14:38:48 +000095 virtual bool isStackSlotCopy(const MachineInstr *MI, int &DestFrameIndex,
96 int &SrcFrameIndex) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +000097 virtual bool AnalyzeBranch(MachineBasicBlock &MBB,
98 MachineBasicBlock *&TBB,
99 MachineBasicBlock *&FBB,
100 SmallVectorImpl<MachineOperand> &Cond,
101 bool AllowModify) const LLVM_OVERRIDE;
102 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const LLVM_OVERRIDE;
103 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
104 MachineBasicBlock *FBB,
105 const SmallVectorImpl<MachineOperand> &Cond,
106 DebugLoc DL) const LLVM_OVERRIDE;
Richard Sandifordc3f85d72013-07-25 09:34:38 +0000107 virtual bool analyzeCompare(const MachineInstr *MI,
108 unsigned &SrcReg, unsigned &SrcReg2,
109 int &Mask, int &Value) const LLVM_OVERRIDE;
110 virtual bool optimizeCompareInstr(MachineInstr *CmpInstr,
111 unsigned SrcReg, unsigned SrcReg2,
112 int Mask, int Value,
113 const MachineRegisterInfo *MRI) const
114 LLVM_OVERRIDE;
Richard Sandifordf2404162013-07-25 09:11:15 +0000115 virtual bool isPredicable(MachineInstr *MI) const LLVM_OVERRIDE;
116 virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
117 unsigned ExtraPredCycles,
118 const BranchProbability &Probability) const
119 LLVM_OVERRIDE;
120 virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
121 unsigned NumCyclesT,
122 unsigned ExtraPredCyclesT,
123 MachineBasicBlock &FMBB,
124 unsigned NumCyclesF,
125 unsigned ExtraPredCyclesF,
126 const BranchProbability &Probability) const
127 LLVM_OVERRIDE;
128 virtual bool
129 PredicateInstruction(MachineInstr *MI,
130 const SmallVectorImpl<MachineOperand> &Pred) const
131 LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000132 virtual void copyPhysReg(MachineBasicBlock &MBB,
133 MachineBasicBlock::iterator MBBI, DebugLoc DL,
134 unsigned DestReg, unsigned SrcReg,
135 bool KillSrc) const LLVM_OVERRIDE;
136 virtual void
137 storeRegToStackSlot(MachineBasicBlock &MBB,
138 MachineBasicBlock::iterator MBBI,
139 unsigned SrcReg, bool isKill, int FrameIndex,
140 const TargetRegisterClass *RC,
141 const TargetRegisterInfo *TRI) const LLVM_OVERRIDE;
142 virtual void
143 loadRegFromStackSlot(MachineBasicBlock &MBB,
144 MachineBasicBlock::iterator MBBI,
145 unsigned DestReg, int FrameIdx,
146 const TargetRegisterClass *RC,
147 const TargetRegisterInfo *TRI) const LLVM_OVERRIDE;
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000148 virtual MachineInstr *
Richard Sandifordff6c5a52013-07-19 16:12:08 +0000149 convertToThreeAddress(MachineFunction::iterator &MFI,
150 MachineBasicBlock::iterator &MBBI,
151 LiveVariables *LV) const;
152 virtual MachineInstr *
Richard Sandifordf6bae1e2013-07-02 15:28:56 +0000153 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
154 const SmallVectorImpl<unsigned> &Ops,
155 int FrameIndex) const;
156 virtual MachineInstr *
157 foldMemoryOperandImpl(MachineFunction &MF, MachineInstr* MI,
158 const SmallVectorImpl<unsigned> &Ops,
159 MachineInstr* LoadMI) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000160 virtual bool
161 expandPostRAPseudo(MachineBasicBlock::iterator MBBI) const LLVM_OVERRIDE;
162 virtual bool
163 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const
164 LLVM_OVERRIDE;
165
166 // Return the SystemZRegisterInfo, which this class owns.
167 const SystemZRegisterInfo &getRegisterInfo() const { return RI; }
168
Richard Sandiford312425f2013-05-20 14:23:08 +0000169 // Return the size in bytes of MI.
170 uint64_t getInstSizeInBytes(const MachineInstr *MI) const;
171
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000172 // Return true if MI is a conditional or unconditional branch.
173 // When returning true, set Cond to the mask of condition-code
174 // values on which the instruction will branch, and set Target
175 // to the operand that contains the branch target. This target
176 // can be a register or a basic block.
Richard Sandiford53c9efd2013-05-28 10:13:54 +0000177 SystemZII::Branch getBranchInfo(const MachineInstr *MI) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000178
179 // Get the load and store opcodes for a given register class.
180 void getLoadStoreOpcodes(const TargetRegisterClass *RC,
181 unsigned &LoadOpcode, unsigned &StoreOpcode) const;
182
183 // Opcode is the opcode of an instruction that has an address operand,
184 // and the caller wants to perform that instruction's operation on an
185 // address that has displacement Offset. Return the opcode of a suitable
186 // instruction (which might be Opcode itself) or 0 if no such instruction
187 // exists.
188 unsigned getOpcodeForOffset(unsigned Opcode, int64_t Offset) const;
189
Richard Sandiford6a06ba32013-07-31 11:36:35 +0000190 // Return true if ROTATE AND ... SELECTED BITS can be used to select bits
191 // Mask of the R2 operand, given that only the low BitSize bits of Mask are
192 // significant. Set Start and End to the I3 and I4 operands if so.
193 bool isRxSBGMask(uint64_t Mask, unsigned BitSize,
194 unsigned &Start, unsigned &End) const;
195
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000196 // If Opcode is a COMPARE opcode for which an associated COMPARE AND
197 // BRANCH exists, return the opcode for the latter, otherwise return 0.
Richard Sandiforde1d9f002013-05-29 11:58:52 +0000198 // MI, if nonnull, is the compare instruction.
199 unsigned getCompareAndBranch(unsigned Opcode,
200 const MachineInstr *MI = 0) const;
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000201
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000202 // Emit code before MBBI in MI to move immediate value Value into
203 // physical register Reg.
204 void loadImmediate(MachineBasicBlock &MBB,
205 MachineBasicBlock::iterator MBBI,
206 unsigned Reg, uint64_t Value) const;
207};
208} // end namespace llvm
209
210#endif