LLVM 23.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
29
30namespace llvm {
31// Forward declarations.
32class APInt;
33class GAnyLoad;
34class GLoadStore;
35class GStore;
37class MachineFunction;
39class MachineInstr;
42template <typename T> class SmallVectorImpl;
43class LegalizerInfo;
47class TargetLowering;
48
50public:
51 /// Expose MIRBuilder so clients can set their own RecordInsertInstruction
52 /// functions
54
55 /// To keep track of changes made by the LegalizerHelper.
57
58private:
60 const LegalizerInfo &LI;
61 const TargetLowering &TLI;
62
63 const LibcallLoweringInfo *Libcalls = nullptr;
64 GISelValueTracking *VT = nullptr;
65
66public:
68 /// Instruction was already legal and no change was made to the
69 /// MachineFunction.
71
72 /// Instruction has been legalized and the MachineFunction changed.
74
75 /// Some kind of error has occurred and we could not legalize this
76 /// instruction.
78 };
79
80 /// Expose LegalizerInfo so the clients can re-use.
81 const LegalizerInfo &getLegalizerInfo() const { return LI; }
82 const TargetLowering &getTargetLowering() const { return TLI; }
83 const LibcallLoweringInfo *getLibcallLoweringInfo() { return Libcalls; }
84 GISelValueTracking *getValueTracking() const { return VT; }
85
86 // FIXME: Should probably make Libcalls mandatory
89 const LibcallLoweringInfo *Libcalls = nullptr);
92 const LibcallLoweringInfo *Libcalls = nullptr,
93 GISelValueTracking *VT = nullptr);
94
95 /// Replace \p MI by a sequence of legal instructions that can implement the
96 /// same operation. Note that this means \p MI may be deleted, so any iterator
97 /// steps should be performed before calling this function. \p Helper should
98 /// be initialized to the MachineFunction containing \p MI.
99 ///
100 /// Considered as an opaque blob, the legal code will use and define the same
101 /// registers as \p MI.
103 LostDebugLocObserver &LocObserver);
104
105 /// Legalize an instruction by emiting a runtime library call instead.
107 LostDebugLocObserver &LocObserver);
108
109 /// Legalize an instruction by reducing the width of the underlying scalar
110 /// type.
112 LLT NarrowTy);
113
114 /// Legalize an instruction by performing the operation on a wider scalar type
115 /// (for example a 16-bit addition can be safely performed at 32-bits
116 /// precision, ignoring the unused bits).
118 LLT WideTy);
119
120 /// Legalize an instruction by replacing the value type
121 LLVM_ABI LegalizeResult bitcast(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
122
123 /// Legalize an instruction by splitting it into simpler parts, hopefully
124 /// understood by the target.
125 LLVM_ABI LegalizeResult lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
126
127 /// Legalize a vector instruction by splitting into multiple components, each
128 /// acting on the same scalar type as the original but with fewer elements.
130 unsigned TypeIdx, LLT NarrowTy);
131
132 /// Legalize a vector instruction by increasing the number of vector elements
133 /// involved and ignoring the added elements later.
135 LLT MoreTy);
136
137 /// Cast the given value to an LLT::scalar with an equivalent size. Returns
138 /// the register to use if an instruction was inserted. Returns the original
139 /// register if no coercion was necessary.
140 //
141 // This may also fail and return Register() if there is no legal way to cast.
143
144 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
145 /// Use by extending the operand's type to \p WideTy using the specified \p
146 /// ExtOpcode for the extension instruction, and replacing the vreg of the
147 /// operand in place.
148 LLVM_ABI void widenScalarSrc(MachineInstr &MI, LLT WideTy, unsigned OpIdx,
149 unsigned ExtOpcode);
150
151 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
152 /// Use by extending the operand's type to \p WideTy using the G_FPEXT for the
153 /// extension instruction, and replacing the vreg of the operand in place.
154 /// Flags are copied from MI to the new extend.
156 unsigned OpIdx);
157
158 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
159 /// Use by truncating the operand's type to \p NarrowTy using G_TRUNC, and
160 /// replacing the vreg of the operand in place.
161 LLVM_ABI void narrowScalarSrc(MachineInstr &MI, LLT NarrowTy, unsigned OpIdx);
162
163 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
164 /// Def by extending the operand's type to \p WideTy and truncating it back
165 /// with the \p TruncOpcode, and replacing the vreg of the operand in place.
166 LLVM_ABI void widenScalarDst(MachineInstr &MI, LLT WideTy, unsigned OpIdx = 0,
167 unsigned TruncOpcode = TargetOpcode::G_TRUNC);
168
169 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
170 /// Def by extending the operand's type to \p WideTy and truncating it back
171 /// with G_FPTRUNC, and replacing the vreg of the operand in place. Flags are
172 /// copied from MI to the new trunc.
174 unsigned OpIdx = 0);
175
176 // Legalize a single operand \p OpIdx of the machine instruction \p MI as a
177 // Def by truncating the operand's type to \p NarrowTy, replacing in place and
178 // extending back with \p ExtOpcode.
179 LLVM_ABI void narrowScalarDst(MachineInstr &MI, LLT NarrowTy, unsigned OpIdx,
180 unsigned ExtOpcode);
181 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
182 /// Def by performing it with additional vector elements and extracting the
183 /// result elements, and replacing the vreg of the operand in place.
185 unsigned OpIdx);
186
187 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
188 /// Use by producing a vector with undefined high elements, extracting the
189 /// original vector type, and replacing the vreg of the operand in place.
191 unsigned OpIdx);
192
193 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
194 /// use by inserting a G_BITCAST to \p CastTy
195 LLVM_ABI void bitcastSrc(MachineInstr &MI, LLT CastTy, unsigned OpIdx);
196
197 /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
198 /// def by inserting a G_BITCAST from \p CastTy
199 LLVM_ABI void bitcastDst(MachineInstr &MI, LLT CastTy, unsigned OpIdx);
200
201 // Useful for libcalls where all operands have the same type.
204 Type *OpType, LostDebugLocObserver &LocObserver) const;
205
206 /// Helper function that creates a libcall to the given \p Name using the
207 /// given calling convention \p CC.
208 LLVM_ABI LegalizeResult createLibcall(const char *Name,
209 const CallLowering::ArgInfo &Result,
212 LostDebugLocObserver &LocObserver,
213 MachineInstr *MI = nullptr) const;
214
215 /// Helper function that creates the given libcall.
216 LLVM_ABI LegalizeResult createLibcall(RTLIB::Libcall Libcall,
217 const CallLowering::ArgInfo &Result,
219 LostDebugLocObserver &LocObserver,
220 MachineInstr *MI = nullptr) const;
221
223 Type *FromType,
224 LostDebugLocObserver &LocObserver,
225 bool IsSigned = false) const;
228
229 /// Create a libcall to memcpy et al.
232 LostDebugLocObserver &LocObserver) const;
233
234private:
236 widenScalarMergeValues(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
238 widenScalarUnmergeValues(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
240 widenScalarExtract(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
242 widenScalarInsert(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
243 LegalizeResult widenScalarAddSubOverflow(MachineInstr &MI, unsigned TypeIdx,
244 LLT WideTy);
245 LegalizeResult widenScalarAddSubShlSat(MachineInstr &MI, unsigned TypeIdx,
246 LLT WideTy);
247 LegalizeResult widenScalarMulo(MachineInstr &MI, unsigned TypeIdx,
248 LLT WideTy);
249
250 /// Helper function to build a wide generic register \p DstReg of type \p
251 /// RegTy from smaller parts. This will produce a G_MERGE_VALUES,
252 /// G_BUILD_VECTOR, G_CONCAT_VECTORS, or sequence of G_INSERT as appropriate
253 /// for the types.
254 ///
255 /// \p PartRegs must be registers of type \p PartTy.
256 ///
257 /// If \p ResultTy does not evenly break into \p PartTy sized pieces, the
258 /// remainder must be specified with \p LeftoverRegs of type \p LeftoverTy.
259 void insertParts(Register DstReg, LLT ResultTy,
260 LLT PartTy, ArrayRef<Register> PartRegs,
261 LLT LeftoverTy = LLT(), ArrayRef<Register> LeftoverRegs = {});
262
263 /// Merge \p PartRegs with different types into \p DstReg.
264 void mergeMixedSubvectors(Register DstReg, ArrayRef<Register> PartRegs);
265
266 void appendVectorElts(SmallVectorImpl<Register> &Elts, Register Reg);
267
268 /// Unmerge \p SrcReg into smaller sized values, and append them to \p
269 /// Parts. The elements of \p Parts will be the greatest common divisor type
270 /// of \p DstTy, \p NarrowTy and the type of \p SrcReg. This will compute and
271 /// return the GCD type.
272 LLT extractGCDType(SmallVectorImpl<Register> &Parts, LLT DstTy,
273 LLT NarrowTy, Register SrcReg);
274
275 /// Unmerge \p SrcReg into \p GCDTy typed registers. This will append all of
276 /// the unpacked registers to \p Parts. This version is if the common unmerge
277 /// type is already known.
278 void extractGCDType(SmallVectorImpl<Register> &Parts, LLT GCDTy,
279 Register SrcReg);
280
281 /// Produce a merge of values in \p VRegs to define \p DstReg. Perform a merge
282 /// from the least common multiple type, and convert as appropriate to \p
283 /// DstReg.
284 ///
285 /// \p VRegs should each have type \p GCDTy. This type should be greatest
286 /// common divisor type of \p DstReg, \p NarrowTy, and an undetermined source
287 /// type.
288 ///
289 /// \p NarrowTy is the desired result merge source type. If the source value
290 /// needs to be widened to evenly cover \p DstReg, inserts high bits
291 /// corresponding to the extension opcode \p PadStrategy.
292 ///
293 /// \p VRegs will be cleared, and the result \p NarrowTy register pieces
294 /// will replace it. Returns The complete LCMTy that \p VRegs will cover when
295 /// merged.
296 LLT buildLCMMergePieces(LLT DstTy, LLT NarrowTy, LLT GCDTy,
297 SmallVectorImpl<Register> &VRegs,
298 unsigned PadStrategy = TargetOpcode::G_ANYEXT);
299
300 /// Merge the values in \p RemergeRegs to an \p LCMTy typed value. Extract the
301 /// low bits into \p DstReg. This is intended to use the outputs from
302 /// buildLCMMergePieces after processing.
303 void buildWidenedRemergeToDst(Register DstReg, LLT LCMTy,
304 ArrayRef<Register> RemergeRegs);
305
306 /// Perform generic multiplication of values held in multiple registers.
307 /// Generated instructions use only types NarrowTy and i1.
308 /// Destination can be same or two times size of the source.
309 void multiplyRegisters(SmallVectorImpl<Register> &DstRegs,
310 ArrayRef<Register> Src1Regs,
311 ArrayRef<Register> Src2Regs, LLT NarrowTy);
312
313 void changeOpcode(MachineInstr &MI, unsigned NewOpcode);
314
315 LegalizeResult tryNarrowPow2Reduction(MachineInstr &MI, Register SrcReg,
316 LLT SrcTy, LLT NarrowTy,
317 unsigned ScalarOpc);
318
319 // Memcpy family legalization helpers.
320 LegalizeResult lowerMemset(MachineInstr &MI, Register Dst, Register Val,
321 uint64_t KnownLen, Align Alignment,
322 bool DstAlignCanChange, ArrayRef<LLT> MemOps);
323 LegalizeResult lowerMemcpy(MachineInstr &MI, Register Dst, Register Src,
324 uint64_t KnownLen, Align Alignment,
325 bool DstAlignCanChange, ArrayRef<LLT> MemOps);
326 LegalizeResult lowerMemmove(MachineInstr &MI, Register Dst, Register Src,
327 uint64_t KnownLen, Align Alignment,
328 bool DstAlignCanChange, ArrayRef<LLT> MemOps);
329
330 // Implements floating-point environment read/write via library function call.
331 LegalizeResult createGetStateLibcall(MachineInstr &MI,
332 LostDebugLocObserver &LocObserver);
333 LegalizeResult createSetStateLibcall(MachineInstr &MI,
334 LostDebugLocObserver &LocObserver);
335 LegalizeResult createResetStateLibcall(MachineInstr &MI,
336 LostDebugLocObserver &LocObserver);
337 LegalizeResult createFCMPLibcall(MachineInstr &MI,
338 LostDebugLocObserver &LocObserver);
339
340 MachineInstrBuilder
341 getNeutralElementForVecReduce(unsigned Opcode, MachineIRBuilder &MIRBuilder,
342 LLT Ty);
343
344 LegalizeResult emitSincosLibcall(MachineInstr &MI,
345 MachineIRBuilder &MIRBuilder, unsigned Size,
346 Type *OpType,
347 LostDebugLocObserver &LocObserver);
348
349 LegalizeResult emitModfLibcall(MachineInstr &MI, MachineIRBuilder &MIRBuilder,
350 unsigned Size, Type *OpType,
351 LostDebugLocObserver &LocObserver);
352
353public:
354 /// Return the alignment to use for a stack temporary object with the given
355 /// type.
357 Align MinAlign = Align()) const;
358
359 /// Create a stack temporary based on the size in bytes and the alignment
360 LLVM_ABI MachineInstrBuilder createStackTemporary(
361 TypeSize Bytes, Align Alignment, MachinePointerInfo &PtrInfo);
362
363 /// Create a store of \p Val to a stack temporary and return a load as the
364 /// same type as \p Res.
365 LLVM_ABI MachineInstrBuilder createStackStoreLoad(const DstOp &Res,
366 const SrcOp &Val);
367
368 /// Given a store of a boolean vector, scalarize it.
370
371 /// Get a pointer to vector element \p Index located in memory for a vector of
372 /// type \p VecTy starting at a base address of \p VecPtr. If \p Index is out
373 /// of bounds the returned pointer is unspecified, but will be within the
374 /// vector bounds.
376 Register Index);
377
378 /// Handles most opcodes. Split \p MI into same instruction on sub-vectors or
379 /// scalars with \p NumElts elements (1 for scalar). Supports uneven splits:
380 /// there can be leftover sub-vector with fewer then \p NumElts or a leftover
381 /// scalar. To avoid this use moreElements first and set MI number of elements
382 /// to multiple of \p NumElts. Non-vector operands that should be used on all
383 /// sub-instructions without split are listed in \p NonVecOpIndices.
385 GenericMachineInstr &MI, unsigned NumElts,
386 std::initializer_list<unsigned> NonVecOpIndices = {});
387
389 unsigned NumElts);
390
392 unsigned TypeIdx, LLT MoreTy);
394 unsigned TypeIdx,
395 LLT MoreTy);
396
398 unsigned TypeIdx,
399 LLT NarrowTy);
401 unsigned TypeIdx,
402 LLT NarrowTy);
404 MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy);
405
406 /// Equalize source and destination vector sizes of G_SHUFFLE_VECTOR.
408
409 LLVM_ABI LegalizeResult reduceLoadStoreWidth(GLoadStore &MI, unsigned TypeIdx,
410 LLT NarrowTy);
411
413 const APInt &Amt,
414 LLT HalfTy,
415 LLT ShiftAmtTy);
416
417 /// Multi-way shift legalization: directly split wide shifts into target-sized
418 /// parts in a single step, avoiding recursive binary splitting.
420 LLT TargetTy);
421
422 /// Optimized path for constant shift amounts using static indexing.
423 /// Directly calculates which source parts contribute to each output part
424 /// without generating runtime select chains.
426 const APInt &Amt,
427 LLT TargetTy,
428 LLT ShiftAmtTy);
429
430 struct ShiftParams {
431 Register WordShift; // Number of complete words to shift
432 Register BitShift; // Number of bits to shift within words
433 Register InvBitShift; // Complement bit shift (TargetBits - BitShift)
434 Register Zero; // Zero constant for SHL/LSHR fill
435 Register SignBit; // Sign extension value for ASHR fill
436 };
437
438 /// Generates a single output part for constant shifts using direct indexing.
439 /// Calculates which source parts contribute and how they're combined.
440 LLVM_ABI Register buildConstantShiftPart(unsigned Opcode, unsigned PartIdx,
441 unsigned NumParts,
442 ArrayRef<Register> SrcParts,
443 const ShiftParams &Params,
444 LLT TargetTy, LLT ShiftAmtTy);
445
446 /// Generates a shift part with carry for variable shifts.
447 /// Combines main operand shifted by BitShift with carry bits from adjacent
448 /// operand.
450 Register MainOperand,
451 Register ShiftAmt, LLT TargetTy,
452 Register CarryOperand = Register());
453
455 unsigned TypeIdx,
456 LLT NarrowTy);
458 unsigned TypeIdx,
459 LLT NarrowTy);
460
461 // Fewer Elements for bitcast, ensuring that the size of the Src and Dst
462 // registers will be the same
464 unsigned TypeIdx, LLT NarrowTy);
465
467 unsigned TypeIdx,
468 LLT NarrowTy);
469
471 LLT Ty);
473 LLT NarrowTy);
476 LLT Ty);
478 unsigned TypeIdx, LLT Ty);
480 LLT Ty);
481
483 LLT Ty);
485 LLT Ty);
487 LLT Ty);
489 LLT Ty);
491 LLT Ty);
493 LLT Ty);
495 LLT Ty);
497 LLT Ty);
498
499 /// Perform Bitcast legalize action on G_EXTRACT_VECTOR_ELT.
501 unsigned TypeIdx, LLT CastTy);
502
503 /// Perform Bitcast legalize action on G_INSERT_VECTOR_ELT.
505 unsigned TypeIdx, LLT CastTy);
507 unsigned TypeIdx, LLT CastTy);
509 unsigned TypeIdx, LLT CastTy);
511 unsigned TypeIdx, LLT CastTy);
513 unsigned TypeIdx, LLT CastTy);
514
528
537
544
546
561 Register AllocSize,
562 Align Alignment, LLT PtrTy);
588 Register Src, uint64_t KnownLen,
589 Align Alignment,
590 bool DstAlignCanChange,
591 ArrayRef<LLT> MemOps);
593 unsigned MaxLen = 0);
596};
597
598} // End namespace llvm.
599
600#endif
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file describes how to lower LLVM calls to machine code calls.
#define LLVM_ABI
Definition Compiler.h:215
Provides analysis for querying information about KnownBits during GISel passes.
IRTranslator LLVM IR MI
This file declares the MachineIRBuilder class.
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
MachineInstr unsigned OpIdx
static constexpr MCPhysReg SPReg
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Represents any generic load, including sign/zero extending variants.
Abstract class that contains various methods for clients to notify about changes.
Represents any type of generic load or store.
Represents a G_STORE.
A base class for all GenericMachineInstrs.
LLVM_ABI LegalizeResult lowerShlSat(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarCTPOP(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult lowerThreewayCompare(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFPTRUNC_F64_TO_F16(MachineInstr &MI)
LLVM_ABI LegalizeResult equalizeVectorShuffleLengths(MachineInstr &MI)
Equalize source and destination vector sizes of G_SHUFFLE_VECTOR.
LLVM_ABI LegalizeResult bitcastInsertVectorElt(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
Perform Bitcast legalize action on G_INSERT_VECTOR_ELT.
LLVM_ABI LegalizeResult lowerSITOFP(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerDynStackAlloc(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerBitCount(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarMul(MachineInstr &MI, LLT Ty)
LLVM_ABI LegalizeResult lowerFMinNumMaxNum(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerU64ToF64BitFloatOps(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerSSUBE(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerIntrinsicRound(MachineInstr &MI)
LLVM_ABI 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...
LLVM_ABI LegalizeResult moreElementsVectorShuffle(MachineInstr &MI, unsigned TypeIdx, LLT MoreTy)
LLVM_ABI LegalizeResult lowerSMULH_UMULH(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerLoad(GAnyLoad &MI)
LLVM_ABI LegalizeResult fewerElementsVectorShuffle(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI LegalizeResult lowerAbsToAddXor(MachineInstr &MI)
LLVM_ABI 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...
LLVM_ABI LegalizerHelper::LegalizeResult createAtomicLibcall(MachineInstr &MI) const
LLVM_ABI LegalizeResult lowerFConstant(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarCTTZ(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult lowerBitreverse(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarShift(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult lowerExtractInsertVectorElt(MachineInstr &MI)
Lower a vector extract or insert by writing the vector to a stack temporary and reloading the element...
LLVM_ABI LegalizeResult moreElementsVector(MachineInstr &MI, unsigned TypeIdx, LLT MoreTy)
Legalize a vector instruction by increasing the number of vector elements involved and ignoring the a...
LLVM_ABI LegalizeResult lowerFunnelShiftWithInverse(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerAbsToMaxNeg(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFPTOINT_SAT(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarCTLS(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult lowerEXT(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerStore(GStore &MI)
LLVM_ABI LegalizeResult lowerAbsToCNeg(MachineInstr &MI)
LLVM_ABI LegalizeResult bitcastExtractSubvector(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
This attempts to bitcast G_EXTRACT_SUBVECTOR to CastTy.
LLVM_ABI LegalizeResult narrowScalarShiftMultiway(MachineInstr &MI, LLT TargetTy)
Multi-way shift legalization: directly split wide shifts into target-sized parts in a single step,...
LLVM_ABI LegalizeResult lowerSADDO_SSUBO(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerMemCpyFamily(MachineInstr &MI, Register Dst, Register Src, uint64_t KnownLen, Align Alignment, bool DstAlignCanChange, ArrayRef< LLT > MemOps)
LLVM_ABI MachineInstrBuilder createStackTemporary(TypeSize Bytes, Align Alignment, MachinePointerInfo &PtrInfo)
Create a stack temporary based on the size in bytes and the alignment.
LLVM_ABI Register buildConstantShiftPart(unsigned Opcode, unsigned PartIdx, unsigned NumParts, ArrayRef< Register > SrcParts, const ShiftParams &Params, LLT TargetTy, LLT ShiftAmtTy)
Generates a single output part for constant shifts using direct indexing.
LLVM_ABI 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...
LLVM_ABI LegalizeResult fewerElementsVectorPhi(GenericMachineInstr &MI, unsigned NumElts)
LLVM_ABI LegalizeResult lowerFPTOUI(MachineInstr &MI)
const TargetLowering & getTargetLowering() const
LLVM_ABI LegalizeResult narrowScalar(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Legalize an instruction by reducing the width of the underlying scalar type.
LLVM_ABI LegalizeResult narrowScalarFPTOI(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult bitcastInsertSubvector(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
This attempts to bitcast G_INSERT_SUBVECTOR to CastTy.
LLVM_ABI LegalizerHelper(MachineFunction &MF, GISelChangeObserver &Observer, MachineIRBuilder &B, const LibcallLoweringInfo *Libcalls=nullptr)
LLVM_ABI LegalizeResult lowerUnmergeValues(MachineInstr &MI)
LLVM_ABI LegalizeResult bitcast(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Legalize an instruction by replacing the value type.
LLVM_ABI LegalizeResult scalarizeVectorBooleanStore(GStore &MI)
Given a store of a boolean vector, scalarize it.
LLVM_ABI LegalizeResult lowerBitcast(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerMinMax(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFunnelShiftAsShifts(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerInsert(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerReadWriteRegister(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerExtract(MachineInstr &MI)
LLVM_ABI LegalizeResult fewerElementsBitcast(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI LegalizeResult narrowScalarShiftByConstant(MachineInstr &MI, const APInt &Amt, LLT HalfTy, LLT ShiftAmtTy)
LLVM_ABI LegalizeResult lowerISFPCLASS(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerAbsDiffToSelect(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerAddSubSatToMinMax(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFPOWI(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFPExtAndTruncMem(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFAbs(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarBasic(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
GISelValueTracking * getValueTracking() const
LLVM_ABI LegalizeResult lowerVectorReduction(MachineInstr &MI)
const LegalizerInfo & getLegalizerInfo() const
Expose LegalizerInfo so the clients can re-use.
LLVM_ABI LegalizeResult reduceLoadStoreWidth(GLoadStore &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI LegalizeResult fewerElementsVectorMultiEltType(GenericMachineInstr &MI, unsigned NumElts, std::initializer_list< unsigned > NonVecOpIndices={})
Handles most opcodes.
LLVM_ABI LegalizeResult narrowScalarSelect(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult narrowScalarShiftByConstantMultiway(MachineInstr &MI, const APInt &Amt, LLT TargetTy, LLT ShiftAmtTy)
Optimized path for constant shift amounts using static indexing.
LLVM_ABI void widenScalarSrcUsingFPExt(MachineInstr &MI, LLT WideTy, unsigned OpIdx)
Legalize a single operand OpIdx of the machine instruction MI as a Use by extending the operand's typ...
LLVM_ABI MachineInstrBuilder createStackStoreLoad(const DstOp &Res, const SrcOp &Val)
Create a store of Val to a stack temporary and return a load as the same type as Res.
LLVM_ABI LegalizeResult lowerVAArg(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFMODF(MachineInstr &MI)
@ Legalized
Instruction has been legalized and the MachineFunction changed.
@ AlreadyLegal
Instruction was already legal and no change was made to the MachineFunction.
@ UnableToLegalize
Some kind of error has occurred and we could not legalize this instruction.
LLVM_ABI LegalizeResult moreElementsVectorPhi(MachineInstr &MI, unsigned TypeIdx, LLT MoreTy)
LLVM_ABI LegalizeResult lowerU64ToF32BitOps(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFCopySign(MachineInstr &MI)
LLVM_ABI LegalizeResult bitcastConcatVector(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
LLVM_ABI LegalizeResult lowerRotateWithReverseRotate(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerSADDE(MachineInstr &MI)
LLVM_ABI LegalizeResult lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Legalize an instruction by splitting it into simpler parts, hopefully understood by the target.
LLVM_ABI LegalizeResult lowerFunnelShift(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFPTRUNC_F32_TO_BF16(MachineInstr &MI)
LLVM_ABI LegalizeResult fewerElementsVector(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Legalize a vector instruction by splitting into multiple components, each acting on the same scalar t...
GISelChangeObserver & Observer
To keep track of changes made by the LegalizerHelper.
LLVM_ABI LegalizeResult conversionLibcall(MachineInstr &MI, Type *ToType, Type *FromType, LostDebugLocObserver &LocObserver, bool IsSigned=false) const
LLVM_ABI 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 ...
LLVM_ABI LegalizeResult lowerFPTRUNC(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerFMad(MachineInstr &MI)
LLVM_ABI 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...
LLVM_ABI LegalizeResult lowerAddSubSatToAddoSubo(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarExtract(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult lowerFFloor(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerAbsDiffToMinMax(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarExt(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult fewerElementsVectorSeqReductions(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI Register getDynStackAllocTargetPtr(Register SPReg, Register AllocSize, Align Alignment, LLT PtrTy)
LLVM_ABI LegalizeResult lowerFPTOSI(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerUITOFP(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerShuffleVector(MachineInstr &MI)
LLVM_ABI LegalizeResult fewerElementsVectorMerge(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI LegalizeResult lowerMergeValues(MachineInstr &MI)
LLVM_ABI LegalizeResult fewerElementsVectorUnmergeValues(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI LegalizeResult createMemLibcall(MachineRegisterInfo &MRI, MachineInstr &MI, LostDebugLocObserver &LocObserver) const
Create a libcall to memcpy et al.
LLVM_ABI LegalizeResult lowerVECTOR_COMPRESS(MachineInstr &MI)
const LibcallLoweringInfo * getLibcallLoweringInfo()
LLVM_ABI LegalizeResult lowerMulfix(MachineInstr &MI)
LLVM_ABI 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...
LLVM_ABI LegalizeResult bitcastExtractVectorElt(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
Perform Bitcast legalize action on G_EXTRACT_VECTOR_ELT.
LLVM_ABI LegalizeResult lowerRotate(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerU64ToF32WithSITOFP(MachineInstr &MI)
LLVM_ABI LegalizeResult createLibcall(const char *Name, const CallLowering::ArgInfo &Result, ArrayRef< CallLowering::ArgInfo > Args, CallingConv::ID CC, LostDebugLocObserver &LocObserver, MachineInstr *MI=nullptr) const
Helper function that creates a libcall to the given Name using the given calling convention CC.
LLVM_ABI Register coerceToScalar(Register Val)
Cast the given value to an LLT::scalar with an equivalent size.
LLVM_ABI LegalizeResult bitcastShuffleVector(MachineInstr &MI, unsigned TypeIdx, LLT CastTy)
LLVM_ABI LegalizeResult lowerDIVREM(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerSelect(MachineInstr &MI)
LLVM_ABI LegalizeResult narrowScalarInsert(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI LegalizeResult narrowScalarFLDEXP(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI Register buildVariableShiftPart(unsigned Opcode, Register MainOperand, Register ShiftAmt, LLT TargetTy, Register CarryOperand=Register())
Generates a shift part with carry for variable shifts.
LLVM_ABI 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...
LLVM_ABI void narrowScalarDst(MachineInstr &MI, LLT NarrowTy, unsigned OpIdx, unsigned ExtOpcode)
LLVM_ABI LegalizeResult lowerStackRestore(MachineInstr &MI)
LLVM_ABI LegalizeResult fewerElementsVectorReductions(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI LegalizeResult lowerStackSave(MachineInstr &MI)
LLVM_ABI LegalizeResult fewerElementsVectorExtractInsertVectorElt(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI LegalizeResult narrowScalarCTLZ(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
LLVM_ABI void widenScalarDstUsingFPTrunc(MachineInstr &MI, LLT WideTy, unsigned OpIdx=0)
Legalize a single operand OpIdx of the machine instruction MI as a Def by extending the operand's typ...
MachineIRBuilder & MIRBuilder
Expose MIRBuilder so clients can set their own RecordInsertInstruction functions.
LLVM_ABI LegalizeResult lowerTRUNC(MachineInstr &MI)
LLVM_ABI LegalizeResult lowerBswap(MachineInstr &MI)
LLVM_ABI 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...
LLVM_ABI LegalizeResult narrowScalarAddSub(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
LLVM_ABI Align getStackTemporaryAlignment(LLT Type, Align MinAlign=Align()) const
Return the alignment to use for a stack temporary object with the given type.
LLVM_ABI LegalizeResult lowerConstant(MachineInstr &MI)
LLVM_ABI 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...
LLVM_ABI LegalizeResult simpleLibcall(MachineInstr &MI, MachineIRBuilder &MIRBuilder, unsigned Size, Type *OpType, LostDebugLocObserver &LocObserver) const
LLVM_ABI LegalizeResult legalizeInstrStep(MachineInstr &MI, LostDebugLocObserver &LocObserver)
Replace MI by a sequence of legal instructions that can implement the same operation.
LLVM_ABI LegalizeResult lowerFMinimumMaximum(MachineInstr &MI)
Tracks which library functions to use for a particular subtarget.
Helper class to build MachineInstr.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
Definition MathExtras.h:357
ArrayRef(const T &OneElt) -> ArrayRef< T >
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This class contains a discriminated union of information about pointers in memory operands,...