LLVM  15.0.0git
LegalizerHelper.h
Go to the documentation of this file.
1 //== llvm/CodeGen/GlobalISel/LegalizerHelper.h ---------------- -*- 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 /// \file A pass to convert the target-illegal operations created by IR -> MIR
10 /// translation into ones the target expects to be able to select. This may
11 /// occur in multiple phases, for example G_ADD <2 x i8> -> G_ADD <2 x i16> ->
12 /// G_ADD <4 x i16>.
13 ///
14 /// The LegalizerHelper class is where most of the work happens, and is
15 /// designed to be callable from other passes that find themselves with an
16 /// illegal instruction.
17 //
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLVM_CODEGEN_GLOBALISEL_LEGALIZERHELPER_H
21 #define LLVM_CODEGEN_GLOBALISEL_LEGALIZERHELPER_H
22 
26 
27 namespace llvm {
28 // Forward declarations.
29 class APInt;
30 class GAnyLoad;
31 class GLoadStore;
32 class GStore;
33 class GenericMachineInstr;
34 class MachineFunction;
35 class MachineIRBuilder;
36 class MachineInstr;
37 class MachineInstrBuilder;
38 struct MachinePointerInfo;
39 template <typename T> class SmallVectorImpl;
40 class LegalizerInfo;
41 class MachineRegisterInfo;
42 class GISelChangeObserver;
43 class LostDebugLocObserver;
44 class TargetLowering;
45 
47 public:
48  /// Expose MIRBuilder so clients can set their own RecordInsertInstruction
49  /// functions
51 
52  /// To keep track of changes made by the LegalizerHelper.
54 
55 private:
57  const LegalizerInfo &LI;
58  const TargetLowering &TLI;
59 
60 public:
62  /// Instruction was already legal and no change was made to the
63  /// MachineFunction.
65 
66  /// Instruction has been legalized and the MachineFunction changed.
68 
69  /// Some kind of error has occurred and we could not legalize this
70  /// instruction.
72  };
73 
74  /// Expose LegalizerInfo so the clients can re-use.
75  const LegalizerInfo &getLegalizerInfo() const { return LI; }
76  const TargetLowering &getTargetLowering() const { return TLI; }
77 
82 
83  /// Replace \p MI by a sequence of legal instructions that can implement the
84  /// same operation. Note that this means \p MI may be deleted, so any iterator
85  /// steps should be performed before calling this function. \p Helper should
86  /// be initialized to the MachineFunction containing \p MI.
87  ///
88  /// Considered as an opaque blob, the legal code will use and define the same
89  /// registers as \p MI.
91  LostDebugLocObserver &LocObserver);
92 
93  /// Legalize an instruction by emiting a runtime library call instead.
95 
96  /// Legalize an instruction by reducing the width of the underlying scalar
97  /// type.
98  LegalizeResult narrowScalar(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy);
99 
100  /// Legalize an instruction by performing the operation on a wider scalar type
101  /// (for example a 16-bit addition can be safely performed at 32-bits
102  /// precision, ignoring the unused bits).
103  LegalizeResult widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
104 
105  /// Legalize an instruction by replacing the value type
106  LegalizeResult bitcast(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
107 
108  /// Legalize an instruction by splitting it into simpler parts, hopefully
109  /// understood by the target.
110  LegalizeResult lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
111 
112  /// Legalize a vector instruction by splitting into multiple components, each
113  /// acting on the same scalar type as the original but with fewer elements.
115  LLT NarrowTy);
116 
117  /// Legalize a vector instruction by increasing the number of vector elements
118  /// involved and ignoring the added elements later.
120  LLT MoreTy);
121 
122  /// Cast the given value to an LLT::scalar with an equivalent size. Returns
123  /// the register to use if an instruction was inserted. Returns the original
124  /// register if no coercion was necessary.
125  //
126  // This may also fail and return Register() if there is no legal way to cast.
128 
129  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
130  /// Use by extending the operand's type to \p WideTy using the specified \p
131  /// ExtOpcode for the extension instruction, and replacing the vreg of the
132  /// operand in place.
133  void widenScalarSrc(MachineInstr &MI, LLT WideTy, unsigned OpIdx,
134  unsigned ExtOpcode);
135 
136  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
137  /// Use by truncating the operand's type to \p NarrowTy using G_TRUNC, and
138  /// replacing the vreg of the operand in place.
139  void narrowScalarSrc(MachineInstr &MI, LLT NarrowTy, unsigned OpIdx);
140 
141  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
142  /// Def by extending the operand's type to \p WideTy and truncating it back
143  /// with the \p TruncOpcode, and replacing the vreg of the operand in place.
144  void widenScalarDst(MachineInstr &MI, LLT WideTy, unsigned OpIdx = 0,
145  unsigned TruncOpcode = TargetOpcode::G_TRUNC);
146 
147  // Legalize a single operand \p OpIdx of the machine instruction \p MI as a
148  // Def by truncating the operand's type to \p NarrowTy, replacing in place and
149  // extending back with \p ExtOpcode.
150  void narrowScalarDst(MachineInstr &MI, LLT NarrowTy, unsigned OpIdx,
151  unsigned ExtOpcode);
152  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
153  /// Def by performing it with additional vector elements and extracting the
154  /// result elements, and replacing the vreg of the operand in place.
155  void moreElementsVectorDst(MachineInstr &MI, LLT MoreTy, unsigned OpIdx);
156 
157  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
158  /// Use by producing a vector with undefined high elements, extracting the
159  /// original vector type, and replacing the vreg of the operand in place.
160  void moreElementsVectorSrc(MachineInstr &MI, LLT MoreTy, unsigned OpIdx);
161 
162  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
163  /// use by inserting a G_BITCAST to \p CastTy
164  void bitcastSrc(MachineInstr &MI, LLT CastTy, unsigned OpIdx);
165 
166  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
167  /// def by inserting a G_BITCAST from \p CastTy
168  void bitcastDst(MachineInstr &MI, LLT CastTy, unsigned OpIdx);
169 
170  /// Widen \p OrigReg to \p WideTy by merging to a wider type, padding with
171  /// G_IMPLICIT_DEF, and producing dead results.
172  Register widenWithUnmerge(LLT WideTy, Register OrigReg);
173 
174 private:
176  widenScalarMergeValues(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
178  widenScalarUnmergeValues(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
180  widenScalarExtract(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
182  widenScalarInsert(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
183  LegalizeResult widenScalarAddSubOverflow(MachineInstr &MI, unsigned TypeIdx,
184  LLT WideTy);
185  LegalizeResult widenScalarAddSubShlSat(MachineInstr &MI, unsigned TypeIdx,
186  LLT WideTy);
187  LegalizeResult widenScalarMulo(MachineInstr &MI, unsigned TypeIdx,
188  LLT WideTy);
189 
190  /// Helper function to split a wide generic register into bitwise blocks with
191  /// the given Type (which implies the number of blocks needed). The generic
192  /// registers created are appended to Ops, starting at bit 0 of Reg.
193  void extractParts(Register Reg, LLT Ty, int NumParts,
195 
196  /// Version which handles irregular splits.
197  bool extractParts(Register Reg, LLT RegTy, LLT MainTy,
198  LLT &LeftoverTy,
200  SmallVectorImpl<Register> &LeftoverVRegs);
201 
202  /// Version which handles irregular sub-vector splits.
203  void extractVectorParts(Register Reg, unsigned NumElst,
205 
206  /// Helper function to build a wide generic register \p DstReg of type \p
207  /// RegTy from smaller parts. This will produce a G_MERGE_VALUES,
208  /// G_BUILD_VECTOR, G_CONCAT_VECTORS, or sequence of G_INSERT as appropriate
209  /// for the types.
210  ///
211  /// \p PartRegs must be registers of type \p PartTy.
212  ///
213  /// If \p ResultTy does not evenly break into \p PartTy sized pieces, the
214  /// remainder must be specified with \p LeftoverRegs of type \p LeftoverTy.
215  void insertParts(Register DstReg, LLT ResultTy,
216  LLT PartTy, ArrayRef<Register> PartRegs,
217  LLT LeftoverTy = LLT(), ArrayRef<Register> LeftoverRegs = {});
218 
219  /// Merge \p PartRegs with different types into \p DstReg.
220  void mergeMixedSubvectors(Register DstReg, ArrayRef<Register> PartRegs);
221 
222  void appendVectorElts(SmallVectorImpl<Register> &Elts, Register Reg);
223 
224  /// Unmerge \p SrcReg into smaller sized values, and append them to \p
225  /// Parts. The elements of \p Parts will be the greatest common divisor type
226  /// of \p DstTy, \p NarrowTy and the type of \p SrcReg. This will compute and
227  /// return the GCD type.
228  LLT extractGCDType(SmallVectorImpl<Register> &Parts, LLT DstTy,
229  LLT NarrowTy, Register SrcReg);
230 
231  /// Unmerge \p SrcReg into \p GCDTy typed registers. This will append all of
232  /// the unpacked registers to \p Parts. This version is if the common unmerge
233  /// type is already known.
234  void extractGCDType(SmallVectorImpl<Register> &Parts, LLT GCDTy,
235  Register SrcReg);
236 
237  /// Produce a merge of values in \p VRegs to define \p DstReg. Perform a merge
238  /// from the least common multiple type, and convert as appropriate to \p
239  /// DstReg.
240  ///
241  /// \p VRegs should each have type \p GCDTy. This type should be greatest
242  /// common divisor type of \p DstReg, \p NarrowTy, and an undetermined source
243  /// type.
244  ///
245  /// \p NarrowTy is the desired result merge source type. If the source value
246  /// needs to be widened to evenly cover \p DstReg, inserts high bits
247  /// corresponding to the extension opcode \p PadStrategy.
248  ///
249  /// \p VRegs will be cleared, and the the result \p NarrowTy register pieces
250  /// will replace it. Returns The complete LCMTy that \p VRegs will cover when
251  /// merged.
252  LLT buildLCMMergePieces(LLT DstTy, LLT NarrowTy, LLT GCDTy,
253  SmallVectorImpl<Register> &VRegs,
254  unsigned PadStrategy = TargetOpcode::G_ANYEXT);
255 
256  /// Merge the values in \p RemergeRegs to an \p LCMTy typed value. Extract the
257  /// low bits into \p DstReg. This is intended to use the outputs from
258  /// buildLCMMergePieces after processing.
259  void buildWidenedRemergeToDst(Register DstReg, LLT LCMTy,
260  ArrayRef<Register> RemergeRegs);
261 
262  /// Perform generic multiplication of values held in multiple registers.
263  /// Generated instructions use only types NarrowTy and i1.
264  /// Destination can be same or two times size of the source.
265  void multiplyRegisters(SmallVectorImpl<Register> &DstRegs,
266  ArrayRef<Register> Src1Regs,
267  ArrayRef<Register> Src2Regs, LLT NarrowTy);
268 
269  void changeOpcode(MachineInstr &MI, unsigned NewOpcode);
270 
271  LegalizeResult tryNarrowPow2Reduction(MachineInstr &MI, Register SrcReg,
272  LLT SrcTy, LLT NarrowTy,
273  unsigned ScalarOpc);
274 
275  // Memcpy family legalization helpers.
276  LegalizeResult lowerMemset(MachineInstr &MI, Register Dst, Register Val,
277  uint64_t KnownLen, Align Alignment,
278  bool IsVolatile);
279  LegalizeResult lowerMemcpyInline(MachineInstr &MI, Register Dst, Register Src,
280  uint64_t KnownLen, Align DstAlign,
281  Align SrcAlign, bool IsVolatile);
282  LegalizeResult lowerMemcpy(MachineInstr &MI, Register Dst, Register Src,
283  uint64_t KnownLen, uint64_t Limit, Align DstAlign,
284  Align SrcAlign, bool IsVolatile);
285  LegalizeResult lowerMemmove(MachineInstr &MI, Register Dst, Register Src,
286  uint64_t KnownLen, Align DstAlign, Align SrcAlign,
287  bool IsVolatile);
288 
289 public:
290  /// Return the alignment to use for a stack temporary object with the given
291  /// type.
292  Align getStackTemporaryAlignment(LLT Type, Align MinAlign = Align()) const;
293 
294  /// Create a stack temporary based on the size in bytes and the alignment
295  MachineInstrBuilder createStackTemporary(TypeSize Bytes, Align Alignment,
296  MachinePointerInfo &PtrInfo);
297 
298  /// Get a pointer to vector element \p Index located in memory for a vector of
299  /// type \p VecTy starting at a base address of \p VecPtr. If \p Index is out
300  /// of bounds the returned pointer is unspecified, but will be within the
301  /// vector bounds.
302  Register getVectorElementPointer(Register VecPtr, LLT VecTy, Register Index);
303 
304  /// Handles most opcodes. Split \p MI into same instruction on sub-vectors or
305  /// scalars with \p NumElts elements (1 for scalar). Supports uneven splits:
306  /// there can be leftover sub-vector with fewer then \p NumElts or a leftover
307  /// scalar. To avoid this use moreElements first and set MI number of elements
308  /// to multiple of \p NumElts. Non-vector operands that should be used on all
309  /// sub-instructions without split are listed in \p NonVecOpIndices.
311  GenericMachineInstr &MI, unsigned NumElts,
312  std::initializer_list<unsigned> NonVecOpIndices = {});
313 
314  LegalizeResult fewerElementsVectorPhi(GenericMachineInstr &MI,
315  unsigned NumElts);
316 
317  LegalizeResult moreElementsVectorPhi(MachineInstr &MI, unsigned TypeIdx,
318  LLT MoreTy);
319  LegalizeResult moreElementsVectorShuffle(MachineInstr &MI, unsigned TypeIdx,
320  LLT MoreTy);
321 
323  unsigned TypeIdx,
324  LLT NarrowTy);
325  LegalizeResult fewerElementsVectorMerge(MachineInstr &MI, unsigned TypeIdx,
326  LLT NarrowTy);
328  unsigned TypeIdx,
329  LLT NarrowTy);
330 
331  LegalizeResult reduceLoadStoreWidth(GLoadStore &MI, unsigned TypeIdx,
332  LLT NarrowTy);
333 
334  LegalizeResult fewerElementsVectorSextInReg(MachineInstr &MI, unsigned TypeIdx,
335  LLT NarrowTy);
336 
337  LegalizeResult narrowScalarShiftByConstant(MachineInstr &MI, const APInt &Amt,
338  LLT HalfTy, LLT ShiftAmtTy);
339 
341  unsigned TypeIdx, LLT NarrowTy);
342 
343  LegalizeResult fewerElementsVectorShuffle(MachineInstr &MI, unsigned TypeIdx,
344  LLT NarrowTy);
345 
346  LegalizeResult narrowScalarShift(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
347  LegalizeResult narrowScalarAddSub(MachineInstr &MI, unsigned TypeIdx,
348  LLT NarrowTy);
349  LegalizeResult narrowScalarMul(MachineInstr &MI, LLT Ty);
350  LegalizeResult narrowScalarFPTOI(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
351  LegalizeResult narrowScalarExtract(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
352  LegalizeResult narrowScalarInsert(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
353 
354  LegalizeResult narrowScalarBasic(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
355  LegalizeResult narrowScalarExt(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
356  LegalizeResult narrowScalarSelect(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
357  LegalizeResult narrowScalarCTLZ(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
358  LegalizeResult narrowScalarCTTZ(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
359  LegalizeResult narrowScalarCTPOP(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
360 
361  /// Perform Bitcast legalize action on G_EXTRACT_VECTOR_ELT.
362  LegalizeResult bitcastExtractVectorElt(MachineInstr &MI, unsigned TypeIdx,
363  LLT CastTy);
364 
365  /// Perform Bitcast legalize action on G_INSERT_VECTOR_ELT.
366  LegalizeResult bitcastInsertVectorElt(MachineInstr &MI, unsigned TypeIdx,
367  LLT CastTy);
368 
369  LegalizeResult lowerBitcast(MachineInstr &MI);
370  LegalizeResult lowerLoad(GAnyLoad &MI);
371  LegalizeResult lowerStore(GStore &MI);
372  LegalizeResult lowerBitCount(MachineInstr &MI);
375  LegalizeResult lowerFunnelShift(MachineInstr &MI);
377  LegalizeResult lowerRotate(MachineInstr &MI);
378 
379  LegalizeResult lowerU64ToF32BitOps(MachineInstr &MI);
380  LegalizeResult lowerUITOFP(MachineInstr &MI);
381  LegalizeResult lowerSITOFP(MachineInstr &MI);
382  LegalizeResult lowerFPTOUI(MachineInstr &MI);
383  LegalizeResult lowerFPTOSI(MachineInstr &MI);
384 
386  LegalizeResult lowerFPTRUNC(MachineInstr &MI);
387  LegalizeResult lowerFPOWI(MachineInstr &MI);
388 
389  LegalizeResult lowerMinMax(MachineInstr &MI);
390  LegalizeResult lowerFCopySign(MachineInstr &MI);
391  LegalizeResult lowerFMinNumMaxNum(MachineInstr &MI);
392  LegalizeResult lowerFMad(MachineInstr &MI);
393  LegalizeResult lowerIntrinsicRound(MachineInstr &MI);
394  LegalizeResult lowerFFloor(MachineInstr &MI);
395  LegalizeResult lowerMergeValues(MachineInstr &MI);
396  LegalizeResult lowerUnmergeValues(MachineInstr &MI);
398  LegalizeResult lowerShuffleVector(MachineInstr &MI);
399  LegalizeResult lowerDynStackAlloc(MachineInstr &MI);
400  LegalizeResult lowerExtract(MachineInstr &MI);
401  LegalizeResult lowerInsert(MachineInstr &MI);
402  LegalizeResult lowerSADDO_SSUBO(MachineInstr &MI);
405  LegalizeResult lowerShlSat(MachineInstr &MI);
406  LegalizeResult lowerBswap(MachineInstr &MI);
407  LegalizeResult lowerBitreverse(MachineInstr &MI);
409  LegalizeResult lowerSMULH_UMULH(MachineInstr &MI);
410  LegalizeResult lowerSelect(MachineInstr &MI);
411  LegalizeResult lowerDIVREM(MachineInstr &MI);
412  LegalizeResult lowerAbsToAddXor(MachineInstr &MI);
413  LegalizeResult lowerAbsToMaxNeg(MachineInstr &MI);
414  LegalizeResult lowerVectorReduction(MachineInstr &MI);
415  LegalizeResult lowerMemcpyInline(MachineInstr &MI);
416  LegalizeResult lowerMemCpyFamily(MachineInstr &MI, unsigned MaxLen = 0);
417 };
418 
419 /// Helper function that creates a libcall to the given \p Name using the given
420 /// calling convention \p CC.
422 createLibcall(MachineIRBuilder &MIRBuilder, const char *Name,
423  const CallLowering::ArgInfo &Result,
424  ArrayRef<CallLowering::ArgInfo> Args, CallingConv::ID CC);
425 
426 /// Helper function that creates the given libcall.
428 createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall,
429  const CallLowering::ArgInfo &Result,
430  ArrayRef<CallLowering::ArgInfo> Args);
431 
432 /// Create a libcall to memcpy et al.
434 createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
435  MachineInstr &MI, LostDebugLocObserver &LocObserver);
436 
437 } // End namespace llvm.
438 
439 #endif
llvm::LegalizerHelper::createStackTemporary
MachineInstrBuilder createStackTemporary(TypeSize Bytes, Align Alignment, MachinePointerInfo &PtrInfo)
Create a stack temporary based on the size in bytes and the alignment.
Definition: LegalizerHelper.cpp:3599
llvm::LegalizerHelper::narrowScalarShiftByConstant
LegalizeResult narrowScalarShiftByConstant(MachineInstr &MI, const APInt &Amt, LLT HalfTy, LLT ShiftAmtTy)
Definition: LegalizerHelper.cpp:4615
llvm::LegalizerHelper::narrowScalarBasic
LegalizeResult narrowScalarBasic(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5384
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::LegalizerHelper::moreElementsVectorPhi
LegalizeResult moreElementsVectorPhi(MachineInstr &MI, unsigned TypeIdx, LLT MoreTy)
Definition: LegalizerHelper.cpp:4813
llvm::LostDebugLocObserver
Definition: LostDebugLocObserver.h:19
llvm::LegalizerHelper::lowerFPTOSI
LegalizeResult lowerFPTOSI(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6152
llvm::LegalizerHelper::libcall
LegalizeResult libcall(MachineInstr &MI, LostDebugLocObserver &LocObserver)
Legalize an instruction by emiting a runtime library call instead.
Definition: LegalizerHelper.cpp:790
llvm::LegalizerHelper::lowerFPTRUNC_F64_TO_F16
LegalizeResult lowerFPTRUNC_F64_TO_F16(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6221
CallLowering.h
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:50
llvm::LegalizerHelper::lowerFCopySign
LegalizeResult lowerFCopySign(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6386
llvm::LegalizerHelper::lowerBitreverse
LegalizeResult lowerBitreverse(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7191
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::LegalizerHelper::widenScalarSrc
void widenScalarSrc(MachineInstr &MI, LLT WideTy, unsigned OpIdx, unsigned ExtOpcode)
Legalize a single operand OpIdx of the machine instruction MI as a Use by extending the operand's typ...
Definition: LegalizerHelper.cpp:1433
llvm::LegalizerHelper::lowerBitcast
LegalizeResult lowerBitcast(MachineInstr &MI)
Definition: LegalizerHelper.cpp:2677
llvm::LegalizerHelper::lowerExtract
LegalizeResult lowerExtract(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6780
llvm::LegalizerHelper::lowerFPTOUI
LegalizeResult lowerFPTOUI(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6109
llvm::LegalizerHelper::bitcastSrc
void bitcastSrc(MachineInstr &MI, LLT CastTy, unsigned OpIdx)
Legalize a single operand OpIdx of the machine instruction MI as a use by inserting a G_BITCAST to Ca...
Definition: LegalizerHelper.cpp:1482
llvm::RTLIB::Libcall
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit.
Definition: RuntimeLibcalls.h:30
llvm::LegalizerHelper::lowerFMad
LegalizeResult lowerFMad(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6460
llvm::LegalizerHelper::UnableToLegalize
@ UnableToLegalize
Some kind of error has occurred and we could not legalize this instruction.
Definition: LegalizerHelper.h:71
llvm::LegalizerHelper::lowerShlSat
LegalizeResult lowerShlSat(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7111
llvm::LegalizerHelper::lower
LegalizeResult lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Legalize an instruction by splitting it into simpler parts, hopefully understood by the target.
Definition: LegalizerHelper.cpp:3290
llvm::LegalizerHelper::lowerSelect
LegalizeResult lowerSelect(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7269
llvm::LegalizerHelper::lowerDIVREM
LegalizeResult lowerDIVREM(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7314
llvm::LegalizerHelper
Definition: LegalizerHelper.h:46
llvm::LegalizerHelper::lowerAbsToAddXor
LegalizeResult lowerAbsToAddXor(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7331
llvm::LegalizerHelper::lowerFFloor
LegalizeResult lowerFFloor(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6507
llvm::LegalizerHelper::LegalizerHelper
LegalizerHelper(MachineFunction &MF, GISelChangeObserver &Observer, MachineIRBuilder &B)
Definition: LegalizerHelper.cpp:98
llvm::LegalizerHelper::lowerVectorReduction
LegalizeResult lowerVectorReduction(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7363
llvm::LegalizerHelper::moreElementsVectorSrc
void moreElementsVectorSrc(MachineInstr &MI, LLT MoreTy, unsigned OpIdx)
Legalize a single operand OpIdx of the machine instruction MI as a Use by producing a vector with und...
Definition: LegalizerHelper.cpp:1475
llvm::LegalizerHelper::getStackTemporaryAlignment
Align getStackTemporaryAlignment(LLT Type, Align MinAlign=Align()) const
Return the alignment to use for a stack temporary object with the given type.
Definition: LegalizerHelper.cpp:3588
llvm::MinAlign
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Definition: MathExtras.h:699
llvm::LegalizerHelper::lowerBswap
LegalizeResult lowerBswap(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7145
llvm::LegalizerHelper::lowerFunnelShiftAsShifts
LegalizeResult lowerFunnelShiftAsShifts(MachineInstr &MI)
Definition: LegalizerHelper.cpp:5808
llvm::LegalizerHelper::narrowScalarSelect
LegalizeResult narrowScalarSelect(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5447
llvm::LegalizerHelper::lowerSITOFP
LegalizeResult lowerSITOFP(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6063
llvm::LegalizerHelper::narrowScalarMul
LegalizeResult narrowScalarMul(MachineInstr &MI, LLT Ty)
Definition: LegalizerHelper.cpp:5176
llvm::LegalizerHelper::narrowScalarCTPOP
LegalizeResult narrowScalarCTPOP(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5565
llvm::LegalizerHelper::lowerSADDO_SSUBO
LegalizeResult lowerSADDO_SSUBO(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6930
llvm::LegalizerHelper::lowerShuffleVector
LegalizeResult lowerShuffleVector(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6687
llvm::LegalizerHelper::lowerFPTRUNC
LegalizeResult lowerFPTRUNC(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6326
llvm::LegalizerHelper::narrowScalarCTLZ
LegalizeResult narrowScalarCTLZ(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5493
llvm::LegalizerHelper::moreElementsVectorDst
void moreElementsVectorDst(MachineInstr &MI, LLT MoreTy, unsigned OpIdx)
Legalize a single operand OpIdx of the machine instruction MI as a Def by performing it with addition...
Definition: LegalizerHelper.cpp:1465
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3395
llvm::LegalizerHelper::narrowScalar
LegalizeResult narrowScalar(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Legalize an instruction by reducing the width of the underlying scalar type.
Definition: LegalizerHelper.cpp:899
llvm::LegalizerHelper::bitcast
LegalizeResult bitcast(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Legalize an instruction by replacing the value type.
Definition: LegalizerHelper.cpp:3213
TargetOpcodes.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::LegalizerHelper::lowerU64ToF32BitOps
LegalizeResult lowerU64ToF32BitOps(MachineInstr &MI)
Definition: LegalizerHelper.cpp:5979
llvm::LegalizerHelper::fewerElementsVectorMultiEltType
LegalizeResult fewerElementsVectorMultiEltType(GenericMachineInstr &MI, unsigned NumElts, std::initializer_list< unsigned > NonVecOpIndices={})
Handles most opcodes.
Definition: LegalizerHelper.cpp:3739
llvm::LegalizerHelper::lowerInsert
LegalizeResult lowerInsert(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6838
llvm::LegalizerHelper::lowerAddSubSatToMinMax
LegalizeResult lowerAddSubSatToMinMax(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6966
Align
uint64_t Align
Definition: ELFObjHandler.cpp:81
llvm::LegalizerHelper::lowerUITOFP
LegalizeResult lowerUITOFP(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6035
llvm::LegalizerHelper::narrowScalarCTTZ
LegalizeResult narrowScalarCTTZ(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5529
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::LegalizerHelper::fewerElementsVector
LegalizeResult fewerElementsVector(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Legalize a vector instruction by splitting into multiple components, each acting on the same scalar t...
Definition: LegalizerHelper.cpp:4162
llvm::LegalizerHelper::lowerIntrinsicRound
LegalizeResult lowerIntrinsicRound(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6474
llvm::LegalizerHelper::lowerExtractInsertVectorElt
LegalizeResult lowerExtractInsertVectorElt(MachineInstr &MI)
Lower a vector extract or insert by writing the vector to a stack temporary and reloading the element...
Definition: LegalizerHelper.cpp:6615
llvm::LegalizerHelper::getVectorElementPointer
Register getVectorElementPointer(Register VecPtr, LLT VecTy, Register Index)
Get a pointer to vector element Index located in memory for a vector of type VecTy starting at a base...
Definition: LegalizerHelper.cpp:3629
llvm::LegalizerHelper::lowerAbsToMaxNeg
LegalizeResult lowerAbsToMaxNeg(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7348
llvm::LegalizerHelper::lowerFunnelShift
LegalizeResult lowerFunnelShift(MachineInstr &MI)
Definition: LegalizerHelper.cpp:5866
llvm::LegalizerHelper::lowerReadWriteRegister
LegalizeResult lowerReadWriteRegister(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7222
llvm::LegalizerHelper::lowerFunnelShiftWithInverse
LegalizeResult lowerFunnelShiftWithInverse(MachineInstr &MI)
Definition: LegalizerHelper.cpp:5766
llvm::LegalizerHelper::getLegalizerInfo
const LegalizerInfo & getLegalizerInfo() const
Expose LegalizerInfo so the clients can re-use.
Definition: LegalizerHelper.h:75
llvm::LegalizerHelper::fewerElementsVectorPhi
LegalizeResult fewerElementsVectorPhi(GenericMachineInstr &MI, unsigned NumElts)
Definition: LegalizerHelper.cpp:3809
llvm::MachineIRBuilder
Helper class to build MachineInstr.
Definition: MachineIRBuilder.h:219
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
uint64_t
RuntimeLibcalls.h
llvm::createLibcall
LegalizerHelper::LegalizeResult createLibcall(MachineIRBuilder &MIRBuilder, const char *Name, const CallLowering::ArgInfo &Result, ArrayRef< CallLowering::ArgInfo > Args, CallingConv::ID CC)
Helper function that creates a libcall to the given Name using the given calling convention CC.
Definition: LegalizerHelper.cpp:629
llvm::LegalizerHelper::narrowScalarAddSub
LegalizeResult narrowScalarAddSub(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Definition: LegalizerHelper.cpp:5082
llvm::LegalizerHelper::lowerMergeValues
LegalizeResult lowerMergeValues(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6534
llvm::LegalizerHelper::lowerSMULH_UMULH
LegalizeResult lowerSMULH_UMULH(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7248
llvm::LegalizerHelper::lowerMinMax
LegalizeResult lowerMinMax(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6370
llvm::LegalizerHelper::moreElementsVectorShuffle
LegalizeResult moreElementsVectorShuffle(MachineInstr &MI, unsigned TypeIdx, LLT MoreTy)
Definition: LegalizerHelper.cpp:4976
llvm::LegalizerHelper::fewerElementsVectorShuffle
LegalizeResult fewerElementsVectorShuffle(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Definition: LegalizerHelper.cpp:4303
llvm::LegalizerHelper::narrowScalarDst
void narrowScalarDst(MachineInstr &MI, LLT NarrowTy, unsigned OpIdx, unsigned ExtOpcode)
Definition: LegalizerHelper.cpp:1456
llvm::LegalizerHelper::lowerStore
LegalizeResult lowerStore(GStore &MI)
Definition: LegalizerHelper.cpp:3113
llvm::LegalizerHelper::fewerElementsVectorExtractInsertVectorElt
LegalizeResult fewerElementsVectorExtractInsertVectorElt(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Definition: LegalizerHelper.cpp:3992
llvm::LegalizerHelper::fewerElementsVectorUnmergeValues
LegalizeResult fewerElementsVectorUnmergeValues(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Definition: LegalizerHelper.cpp:3857
llvm::LegalizerHelper::widenScalar
LegalizeResult widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy)
Legalize an instruction by performing the operation on a wider scalar type (for example a 16-bit addi...
Definition: LegalizerHelper.cpp:2058
llvm::LegalizerHelper::narrowScalarExtract
LegalizeResult narrowScalarExtract(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5233
llvm::MachineFunction
Definition: MachineFunction.h:241
llvm::LegalizerHelper::AlreadyLegal
@ AlreadyLegal
Instruction was already legal and no change was made to the MachineFunction.
Definition: LegalizerHelper.h:64
llvm::LegalizerHelper::lowerLoad
LegalizeResult lowerLoad(GAnyLoad &MI)
Definition: LegalizerHelper.cpp:2976
llvm::LegalizerHelper::lowerBitCount
LegalizeResult lowerBitCount(MachineInstr &MI)
Definition: LegalizerHelper.cpp:5590
llvm::LegalizerHelper::narrowScalarExt
LegalizeResult narrowScalarExt(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5425
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::LegalizerHelper::widenWithUnmerge
Register widenWithUnmerge(LLT WideTy, Register OrigReg)
Widen OrigReg to WideTy by merging to a wider type, padding with G_IMPLICIT_DEF, and producing dead r...
Definition: LegalizerHelper.cpp:1617
llvm::LegalizerHelper::fewerElementsVectorSextInReg
LegalizeResult fewerElementsVectorSextInReg(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
llvm::LegalizerHelper::Observer
GISelChangeObserver & Observer
To keep track of changes made by the LegalizerHelper.
Definition: LegalizerHelper.h:53
llvm::LegalizerHelper::narrowScalarSrc
void narrowScalarSrc(MachineInstr &MI, LLT NarrowTy, unsigned OpIdx)
Legalize a single operand OpIdx of the machine instruction MI as a Use by truncating the operand's ty...
Definition: LegalizerHelper.cpp:1440
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::IsVolatile
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
Definition: AMDGPUMetadata.h:199
llvm::LegalizerHelper::lowerUnmergeValues
LegalizeResult lowerUnmergeValues(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6575
llvm::GISelChangeObserver
Abstract class that contains various methods for clients to notify about changes.
Definition: GISelChangeObserver.h:29
llvm::LegalizerHelper::bitcastDst
void bitcastDst(MachineInstr &MI, LLT CastTy, unsigned OpIdx)
Legalize a single operand OpIdx of the machine instruction MI as a def by inserting a G_BITCAST from ...
Definition: LegalizerHelper.cpp:1487
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::LegalizerHelper::getTargetLowering
const TargetLowering & getTargetLowering() const
Definition: LegalizerHelper.h:76
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::LegalizerHelper::widenScalarDst
void widenScalarDst(MachineInstr &MI, LLT WideTy, unsigned OpIdx=0, unsigned TruncOpcode=TargetOpcode::G_TRUNC)
Legalize a single operand OpIdx of the machine instruction MI as a Def by extending the operand's typ...
Definition: LegalizerHelper.cpp:1447
llvm::LegalizerHelper::bitcastInsertVectorElt
LegalizeResult bitcastInsertVectorElt(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
Perform Bitcast legalize action on G_INSERT_VECTOR_ELT.
Definition: LegalizerHelper.cpp:2913
llvm::LegalizerHelper::lowerMemCpyFamily
LegalizeResult lowerMemCpyFamily(MachineInstr &MI, unsigned MaxLen=0)
Definition: LegalizerHelper.cpp:7865
llvm::LegalizerHelper::narrowScalarShift
LegalizeResult narrowScalarShift(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:4704
llvm::LegalizerHelper::lowerAddSubSatToAddoSubo
LegalizeResult lowerAddSubSatToAddoSubo(MachineInstr &MI)
Definition: LegalizerHelper.cpp:7043
llvm::LegalizerHelper::narrowScalarFPTOI
LegalizeResult narrowScalarFPTOI(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5208
llvm::LegalizerHelper::lowerFMinNumMaxNum
LegalizeResult lowerFMinNumMaxNum(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6430
llvm::LegalizerHelper::fewerElementsVectorReductions
LegalizeResult fewerElementsVectorReductions(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Definition: LegalizerHelper.cpp:4493
llvm::LegalizerHelper::narrowScalarInsert
LegalizeResult narrowScalarInsert(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Definition: LegalizerHelper.cpp:5300
llvm::LegalizerHelper::lowerFPOWI
LegalizeResult lowerFPOWI(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6343
llvm::LegalizerHelper::lowerDynStackAlloc
LegalizeResult lowerDynStackAlloc(MachineInstr &MI)
Definition: LegalizerHelper.cpp:6743
llvm::LegalizerHelper::LegalizeResult
LegalizeResult
Definition: LegalizerHelper.h:61
llvm::createMemLibcall
LegalizerHelper::LegalizeResult createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI, MachineInstr &MI, LostDebugLocObserver &LocObserver)
Create a libcall to memcpy et al.
Definition: LegalizerHelper.cpp:671
llvm::LegalizerHelper::lowerRotateWithReverseRotate
LegalizeResult lowerRotateWithReverseRotate(MachineInstr &MI)
Definition: LegalizerHelper.cpp:5890
llvm::LegalizerHelper::MIRBuilder
MachineIRBuilder & MIRBuilder
Expose MIRBuilder so clients can set their own RecordInsertInstruction functions.
Definition: LegalizerHelper.h:50
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::LegalizerHelper::reduceLoadStoreWidth
LegalizeResult reduceLoadStoreWidth(GLoadStore &MI, unsigned TypeIdx, LLT NarrowTy)
Definition: LegalizerHelper.cpp:4067
llvm::LegalizerInfo
Definition: LegalizerInfo.h:1180
llvm::LegalizerHelper::coerceToScalar
Register coerceToScalar(Register Val)
Cast the given value to an LLT::scalar with an equivalent size.
Definition: LegalizerHelper.cpp:1411
llvm::LegalizerHelper::fewerElementsVectorMerge
LegalizeResult fewerElementsVectorMerge(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Definition: LegalizerHelper.cpp:3906
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::LegalizerHelper::moreElementsVector
LegalizeResult moreElementsVector(MachineInstr &MI, unsigned TypeIdx, LLT MoreTy)
Legalize a vector instruction by increasing the number of vector elements involved and ignoring the a...
Definition: LegalizerHelper.cpp:4832
llvm::LegalizerHelper::lowerRotate
LegalizeResult lowerRotate(MachineInstr &MI)
Definition: LegalizerHelper.cpp:5904
llvm::LegalizerHelper::legalizeInstrStep
LegalizeResult legalizeInstrStep(MachineInstr &MI, LostDebugLocObserver &LocObserver)
Replace MI by a sequence of legal instructions that can implement the same operation.
Definition: LegalizerHelper.cpp:112
llvm::LegalizerHelper::Legalized
@ Legalized
Instruction has been legalized and the MachineFunction changed.
Definition: LegalizerHelper.h:67
llvm::LegalizerHelper::bitcastExtractVectorElt
LegalizeResult bitcastExtractVectorElt(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
Perform Bitcast legalize action on G_EXTRACT_VECTOR_ELT.
Definition: LegalizerHelper.cpp:2773
llvm::LLT
Definition: LowLevelTypeImpl.h:39