LLVM 19.0.0git
Utils.h
Go to the documentation of this file.
1//==-- llvm/CodeGen/GlobalISel/Utils.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 This file declares the API of helper functions used throughout the
10/// GlobalISel pipeline.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_GLOBALISEL_UTILS_H
15#define LLVM_CODEGEN_GLOBALISEL_UTILS_H
16
17#include "GISelWorkList.h"
18#include "llvm/ADT/APFloat.h"
19#include "llvm/ADT/StringRef.h"
22#include "llvm/IR/DebugLoc.h"
25#include <cstdint>
26
27namespace llvm {
28
29class AnalysisUsage;
30class LostDebugLocObserver;
31class MachineBasicBlock;
32class BlockFrequencyInfo;
33class GISelKnownBits;
34class MachineFunction;
35class MachineInstr;
36class MachineIRBuilder;
37class MachineOperand;
38class MachineOptimizationRemarkEmitter;
39class MachineOptimizationRemarkMissed;
40struct MachinePointerInfo;
41class MachineRegisterInfo;
42class MCInstrDesc;
43class ProfileSummaryInfo;
44class RegisterBankInfo;
45class TargetInstrInfo;
46class TargetLowering;
47class TargetPassConfig;
48class TargetRegisterInfo;
49class TargetRegisterClass;
50class ConstantFP;
51class APFloat;
52
53// Convenience macros for dealing with vector reduction opcodes.
54#define GISEL_VECREDUCE_CASES_ALL \
55 case TargetOpcode::G_VECREDUCE_SEQ_FADD: \
56 case TargetOpcode::G_VECREDUCE_SEQ_FMUL: \
57 case TargetOpcode::G_VECREDUCE_FADD: \
58 case TargetOpcode::G_VECREDUCE_FMUL: \
59 case TargetOpcode::G_VECREDUCE_FMAX: \
60 case TargetOpcode::G_VECREDUCE_FMIN: \
61 case TargetOpcode::G_VECREDUCE_FMAXIMUM: \
62 case TargetOpcode::G_VECREDUCE_FMINIMUM: \
63 case TargetOpcode::G_VECREDUCE_ADD: \
64 case TargetOpcode::G_VECREDUCE_MUL: \
65 case TargetOpcode::G_VECREDUCE_AND: \
66 case TargetOpcode::G_VECREDUCE_OR: \
67 case TargetOpcode::G_VECREDUCE_XOR: \
68 case TargetOpcode::G_VECREDUCE_SMAX: \
69 case TargetOpcode::G_VECREDUCE_SMIN: \
70 case TargetOpcode::G_VECREDUCE_UMAX: \
71 case TargetOpcode::G_VECREDUCE_UMIN:
72
73#define GISEL_VECREDUCE_CASES_NONSEQ \
74 case TargetOpcode::G_VECREDUCE_FADD: \
75 case TargetOpcode::G_VECREDUCE_FMUL: \
76 case TargetOpcode::G_VECREDUCE_FMAX: \
77 case TargetOpcode::G_VECREDUCE_FMIN: \
78 case TargetOpcode::G_VECREDUCE_FMAXIMUM: \
79 case TargetOpcode::G_VECREDUCE_FMINIMUM: \
80 case TargetOpcode::G_VECREDUCE_ADD: \
81 case TargetOpcode::G_VECREDUCE_MUL: \
82 case TargetOpcode::G_VECREDUCE_AND: \
83 case TargetOpcode::G_VECREDUCE_OR: \
84 case TargetOpcode::G_VECREDUCE_XOR: \
85 case TargetOpcode::G_VECREDUCE_SMAX: \
86 case TargetOpcode::G_VECREDUCE_SMIN: \
87 case TargetOpcode::G_VECREDUCE_UMAX: \
88 case TargetOpcode::G_VECREDUCE_UMIN:
89
90/// Try to constrain Reg to the specified register class. If this fails,
91/// create a new virtual register in the correct class.
92///
93/// \return The virtual register constrained to the right register class.
94Register constrainRegToClass(MachineRegisterInfo &MRI,
95 const TargetInstrInfo &TII,
96 const RegisterBankInfo &RBI, Register Reg,
97 const TargetRegisterClass &RegClass);
98
99/// Constrain the Register operand OpIdx, so that it is now constrained to the
100/// TargetRegisterClass passed as an argument (RegClass).
101/// If this fails, create a new virtual register in the correct class and insert
102/// a COPY before \p InsertPt if it is a use or after if it is a definition.
103/// In both cases, the function also updates the register of RegMo. The debug
104/// location of \p InsertPt is used for the new copy.
105///
106/// \return The virtual register constrained to the right register class.
107Register constrainOperandRegClass(const MachineFunction &MF,
108 const TargetRegisterInfo &TRI,
109 MachineRegisterInfo &MRI,
110 const TargetInstrInfo &TII,
111 const RegisterBankInfo &RBI,
112 MachineInstr &InsertPt,
113 const TargetRegisterClass &RegClass,
114 MachineOperand &RegMO);
115
116/// Try to constrain Reg so that it is usable by argument OpIdx of the provided
117/// MCInstrDesc \p II. If this fails, create a new virtual register in the
118/// correct class and insert a COPY before \p InsertPt if it is a use or after
119/// if it is a definition. In both cases, the function also updates the register
120/// of RegMo.
121/// This is equivalent to constrainOperandRegClass(..., RegClass, ...)
122/// with RegClass obtained from the MCInstrDesc. The debug location of \p
123/// InsertPt is used for the new copy.
124///
125/// \return The virtual register constrained to the right register class.
126Register constrainOperandRegClass(const MachineFunction &MF,
127 const TargetRegisterInfo &TRI,
128 MachineRegisterInfo &MRI,
129 const TargetInstrInfo &TII,
130 const RegisterBankInfo &RBI,
131 MachineInstr &InsertPt, const MCInstrDesc &II,
132 MachineOperand &RegMO, unsigned OpIdx);
133
134/// Mutate the newly-selected instruction \p I to constrain its (possibly
135/// generic) virtual register operands to the instruction's register class.
136/// This could involve inserting COPYs before (for uses) or after (for defs).
137/// This requires the number of operands to match the instruction description.
138/// \returns whether operand regclass constraining succeeded.
139///
140// FIXME: Not all instructions have the same number of operands. We should
141// probably expose a constrain helper per operand and let the target selector
142// constrain individual registers, like fast-isel.
143bool constrainSelectedInstRegOperands(MachineInstr &I,
144 const TargetInstrInfo &TII,
145 const TargetRegisterInfo &TRI,
146 const RegisterBankInfo &RBI);
147
148/// Check if DstReg can be replaced with SrcReg depending on the register
149/// constraints.
150bool canReplaceReg(Register DstReg, Register SrcReg, MachineRegisterInfo &MRI);
151
152/// Check whether an instruction \p MI is dead: it only defines dead virtual
153/// registers, and doesn't have other side effects.
154bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI);
155
156/// Report an ISel error as a missed optimization remark to the LLVMContext's
157/// diagnostic stream. Set the FailedISel MachineFunction property.
158void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
159 MachineOptimizationRemarkEmitter &MORE,
160 MachineOptimizationRemarkMissed &R);
161
162void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
163 MachineOptimizationRemarkEmitter &MORE,
164 const char *PassName, StringRef Msg,
165 const MachineInstr &MI);
166
167/// Report an ISel warning as a missed optimization remark to the LLVMContext's
168/// diagnostic stream.
169void reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC,
170 MachineOptimizationRemarkEmitter &MORE,
171 MachineOptimizationRemarkMissed &R);
172
173/// If \p VReg is defined by a G_CONSTANT, return the corresponding value.
174std::optional<APInt> getIConstantVRegVal(Register VReg,
175 const MachineRegisterInfo &MRI);
176
177/// If \p VReg is defined by a G_CONSTANT fits in int64_t returns it.
178std::optional<int64_t> getIConstantVRegSExtVal(Register VReg,
179 const MachineRegisterInfo &MRI);
180
181/// Simple struct used to hold a constant integer value and a virtual
182/// register.
186};
187
188/// If \p VReg is defined by a statically evaluable chain of instructions rooted
189/// on a G_CONSTANT returns its APInt value and def register.
190std::optional<ValueAndVReg>
193 bool LookThroughInstrs = true);
194
195/// If \p VReg is defined by a statically evaluable chain of instructions rooted
196/// on a G_CONSTANT or G_FCONSTANT returns its value as APInt and def register.
197std::optional<ValueAndVReg> getAnyConstantVRegValWithLookThrough(
198 Register VReg, const MachineRegisterInfo &MRI,
199 bool LookThroughInstrs = true, bool LookThroughAnyExt = false);
200
204};
205
206/// If \p VReg is defined by a statically evaluable chain of instructions rooted
207/// on a G_FCONSTANT returns its APFloat value and def register.
208std::optional<FPValueAndVReg>
211 bool LookThroughInstrs = true);
212
214 const MachineRegisterInfo &MRI);
215
216/// See if Reg is defined by an single def instruction that is
217/// Opcode. Also try to do trivial folding if it's a COPY with
218/// same types. Returns null otherwise.
219MachineInstr *getOpcodeDef(unsigned Opcode, Register Reg,
220 const MachineRegisterInfo &MRI);
221
222/// Simple struct used to hold a Register value and the instruction which
223/// defines it.
227};
228
229/// Find the def instruction for \p Reg, and underlying value Register folding
230/// away any copies.
231///
232/// Also walks through hints such as G_ASSERT_ZEXT.
233std::optional<DefinitionAndSourceRegister>
235
236/// Find the def instruction for \p Reg, folding away any trivial copies. May
237/// return nullptr if \p Reg is not a generic virtual register.
238///
239/// Also walks through hints such as G_ASSERT_ZEXT.
241 const MachineRegisterInfo &MRI);
242
243/// Find the source register for \p Reg, folding away any trivial copies. It
244/// will be an output register of the instruction that getDefIgnoringCopies
245/// returns. May return an invalid register if \p Reg is not a generic virtual
246/// register.
247///
248/// Also walks through hints such as G_ASSERT_ZEXT.
250
251/// Helper function to split a wide generic register into bitwise blocks with
252/// the given Type (which implies the number of blocks needed). The generic
253/// registers created are appended to Ops, starting at bit 0 of Reg.
254void extractParts(Register Reg, LLT Ty, int NumParts,
257
258/// Version which handles irregular splits.
259bool extractParts(Register Reg, LLT RegTy, LLT MainTy, LLT &LeftoverTy,
261 SmallVectorImpl<Register> &LeftoverVRegs,
263
264/// Version which handles irregular sub-vector splits.
265void extractVectorParts(Register Reg, unsigned NumElts,
268
269// Templated variant of getOpcodeDef returning a MachineInstr derived T.
270/// See if Reg is defined by an single def instruction of type T
271/// Also try to do trivial folding if it's a COPY with
272/// same types. Returns null otherwise.
273template <class T>
276 return dyn_cast_or_null<T>(DefMI);
277}
278
279/// Returns an APFloat from Val converted to the appropriate size.
280APFloat getAPFloatFromSize(double Val, unsigned Size);
281
282/// Modify analysis usage so it preserves passes required for the SelectionDAG
283/// fallback.
284void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU);
285
286std::optional<APInt> ConstantFoldBinOp(unsigned Opcode, const Register Op1,
287 const Register Op2,
288 const MachineRegisterInfo &MRI);
289std::optional<APFloat> ConstantFoldFPBinOp(unsigned Opcode, const Register Op1,
290 const Register Op2,
291 const MachineRegisterInfo &MRI);
292
293/// Tries to constant fold a vector binop with sources \p Op1 and \p Op2.
294/// Returns an empty vector on failure.
295SmallVector<APInt> ConstantFoldVectorBinop(unsigned Opcode, const Register Op1,
296 const Register Op2,
297 const MachineRegisterInfo &MRI);
298
299std::optional<APInt> ConstantFoldCastOp(unsigned Opcode, LLT DstTy,
300 const Register Op0,
301 const MachineRegisterInfo &MRI);
302
303std::optional<APInt> ConstantFoldExtOp(unsigned Opcode, const Register Op1,
304 uint64_t Imm,
305 const MachineRegisterInfo &MRI);
306
307std::optional<APFloat> ConstantFoldIntToFloat(unsigned Opcode, LLT DstTy,
308 Register Src,
309 const MachineRegisterInfo &MRI);
310
311/// Tries to constant fold a counting-zero operation (G_CTLZ or G_CTTZ) on \p
312/// Src. If \p Src is a vector then it tries to do an element-wise constant
313/// fold.
314std::optional<SmallVector<unsigned>>
315ConstantFoldCountZeros(Register Src, const MachineRegisterInfo &MRI,
316 std::function<unsigned(APInt)> CB);
317
318/// Test if the given value is known to have exactly one bit set. This differs
319/// from computeKnownBits in that it doesn't necessarily determine which bit is
320/// set.
321bool isKnownToBeAPowerOfTwo(Register Val, const MachineRegisterInfo &MRI,
322 GISelKnownBits *KnownBits = nullptr);
323
324/// Returns true if \p Val can be assumed to never be a NaN. If \p SNaN is true,
325/// this returns if \p Val can be assumed to never be a signaling NaN.
326bool isKnownNeverNaN(Register Val, const MachineRegisterInfo &MRI,
327 bool SNaN = false);
328
329/// Returns true if \p Val can be assumed to never be a signaling NaN.
331 return isKnownNeverNaN(Val, MRI, true);
332}
333
334Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO);
335
336/// Return a virtual register corresponding to the incoming argument register \p
337/// PhysReg. This register is expected to have class \p RC, and optional type \p
338/// RegTy. This assumes all references to the register will use the same type.
339///
340/// If there is an existing live-in argument register, it will be returned.
341/// This will also ensure there is a valid copy
342Register getFunctionLiveInPhysReg(MachineFunction &MF,
343 const TargetInstrInfo &TII,
344 MCRegister PhysReg,
345 const TargetRegisterClass &RC,
346 const DebugLoc &DL, LLT RegTy = LLT());
347
348/// Return the least common multiple type of \p OrigTy and \p TargetTy, by
349/// changing the number of vector elements or scalar bitwidth. The intent is a
350/// G_MERGE_VALUES, G_BUILD_VECTOR, or G_CONCAT_VECTORS can be constructed from
351/// \p OrigTy elements, and unmerged into \p TargetTy. It is an error to call
352/// this function where one argument is a fixed vector and the other is a
353/// scalable vector, since it is illegal to build a G_{MERGE|UNMERGE}_VALUES
354/// between fixed and scalable vectors.
356LLT getLCMType(LLT OrigTy, LLT TargetTy);
357
359/// Return smallest type that covers both \p OrigTy and \p TargetTy and is
360/// multiple of TargetTy.
361LLT getCoverTy(LLT OrigTy, LLT TargetTy);
362
363/// Return a type where the total size is the greatest common divisor of \p
364/// OrigTy and \p TargetTy. This will try to either change the number of vector
365/// elements, or bitwidth of scalars. The intent is the result type can be used
366/// as the result of a G_UNMERGE_VALUES from \p OrigTy, and then some
367/// combination of G_MERGE_VALUES, G_BUILD_VECTOR and G_CONCAT_VECTORS (possibly
368/// with intermediate casts) can re-form \p TargetTy.
369///
370/// If these are vectors with different element types, this will try to produce
371/// a vector with a compatible total size, but the element type of \p OrigTy. If
372/// this can't be satisfied, this will produce a scalar smaller than the
373/// original vector elements. It is an error to call this function where
374/// one argument is a fixed vector and the other is a scalable vector, since it
375/// is illegal to build a G_{MERGE|UNMERGE}_VALUES between fixed and scalable
376/// vectors.
377///
378/// In the worst case, this returns LLT::scalar(1)
380LLT getGCDType(LLT OrigTy, LLT TargetTy);
381
382/// Represents a value which can be a Register or a constant.
383///
384/// This is useful in situations where an instruction may have an interesting
385/// register operand or interesting constant operand. For a concrete example,
386/// \see getVectorSplat.
388 int64_t Cst;
389 Register Reg;
390 bool IsReg;
391
392public:
393 explicit RegOrConstant(Register Reg) : Reg(Reg), IsReg(true) {}
394 explicit RegOrConstant(int64_t Cst) : Cst(Cst), IsReg(false) {}
395 bool isReg() const { return IsReg; }
396 bool isCst() const { return !IsReg; }
397 Register getReg() const {
398 assert(isReg() && "Expected a register!");
399 return Reg;
400 }
401 int64_t getCst() const {
402 assert(isCst() && "Expected a constant!");
403 return Cst;
404 }
405};
406
407/// \returns The splat index of a G_SHUFFLE_VECTOR \p MI when \p MI is a splat.
408/// If \p MI is not a splat, returns std::nullopt.
409std::optional<int> getSplatIndex(MachineInstr &MI);
410
411/// \returns the scalar integral splat value of \p Reg if possible.
412std::optional<APInt> getIConstantSplatVal(const Register Reg,
413 const MachineRegisterInfo &MRI);
414
415/// \returns the scalar integral splat value defined by \p MI if possible.
416std::optional<APInt> getIConstantSplatVal(const MachineInstr &MI,
417 const MachineRegisterInfo &MRI);
418
419/// \returns the scalar sign extended integral splat value of \p Reg if
420/// possible.
421std::optional<int64_t> getIConstantSplatSExtVal(const Register Reg,
422 const MachineRegisterInfo &MRI);
423
424/// \returns the scalar sign extended integral splat value defined by \p MI if
425/// possible.
426std::optional<int64_t> getIConstantSplatSExtVal(const MachineInstr &MI,
427 const MachineRegisterInfo &MRI);
428
429/// Returns a floating point scalar constant of a build vector splat if it
430/// exists. When \p AllowUndef == true some elements can be undef but not all.
431std::optional<FPValueAndVReg> getFConstantSplat(Register VReg,
432 const MachineRegisterInfo &MRI,
433 bool AllowUndef = true);
434
435/// Return true if the specified register is defined by G_BUILD_VECTOR or
436/// G_BUILD_VECTOR_TRUNC where all of the elements are \p SplatValue or undef.
437bool isBuildVectorConstantSplat(const Register Reg,
438 const MachineRegisterInfo &MRI,
439 int64_t SplatValue, bool AllowUndef);
440
441/// Return true if the specified instruction is a G_BUILD_VECTOR or
442/// G_BUILD_VECTOR_TRUNC where all of the elements are \p SplatValue or undef.
443bool isBuildVectorConstantSplat(const MachineInstr &MI,
444 const MachineRegisterInfo &MRI,
445 int64_t SplatValue, bool AllowUndef);
446
447/// Return true if the specified instruction is a G_BUILD_VECTOR or
448/// G_BUILD_VECTOR_TRUNC where all of the elements are 0 or undef.
449bool isBuildVectorAllZeros(const MachineInstr &MI,
450 const MachineRegisterInfo &MRI,
451 bool AllowUndef = false);
452
453/// Return true if the specified instruction is a G_BUILD_VECTOR or
454/// G_BUILD_VECTOR_TRUNC where all of the elements are ~0 or undef.
455bool isBuildVectorAllOnes(const MachineInstr &MI,
456 const MachineRegisterInfo &MRI,
457 bool AllowUndef = false);
458
459/// Return true if the specified instruction is known to be a constant, or a
460/// vector of constants.
461///
462/// If \p AllowFP is true, this will consider G_FCONSTANT in addition to
463/// G_CONSTANT. If \p AllowOpaqueConstants is true, constant-like instructions
464/// such as G_GLOBAL_VALUE will also be considered.
465bool isConstantOrConstantVector(const MachineInstr &MI,
466 const MachineRegisterInfo &MRI,
467 bool AllowFP = true,
468 bool AllowOpaqueConstants = true);
469
470/// Return true if the value is a constant 0 integer or a splatted vector of a
471/// constant 0 integer (with no undefs if \p AllowUndefs is false). This will
472/// handle G_BUILD_VECTOR and G_BUILD_VECTOR_TRUNC as truncation is not an issue
473/// for null values.
474bool isNullOrNullSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI,
475 bool AllowUndefs = false);
476
477/// Return true if the value is a constant -1 integer or a splatted vector of a
478/// constant -1 integer (with no undefs if \p AllowUndefs is false).
479bool isAllOnesOrAllOnesSplat(const MachineInstr &MI,
480 const MachineRegisterInfo &MRI,
481 bool AllowUndefs = false);
482
483/// \returns a value when \p MI is a vector splat. The splat can be either a
484/// Register or a constant.
485///
486/// Examples:
487///
488/// \code
489/// %reg = COPY $physreg
490/// %reg_splat = G_BUILD_VECTOR %reg, %reg, ..., %reg
491/// \endcode
492///
493/// If called on the G_BUILD_VECTOR above, this will return a RegOrConstant
494/// containing %reg.
495///
496/// \code
497/// %cst = G_CONSTANT iN 4
498/// %constant_splat = G_BUILD_VECTOR %cst, %cst, ..., %cst
499/// \endcode
500///
501/// In the above case, this will return a RegOrConstant containing 4.
502std::optional<RegOrConstant> getVectorSplat(const MachineInstr &MI,
503 const MachineRegisterInfo &MRI);
504
505/// Determines if \p MI defines a constant integer or a build vector of
506/// constant integers. Treats undef values as constants.
507bool isConstantOrConstantVector(MachineInstr &MI,
508 const MachineRegisterInfo &MRI);
509
510/// Determines if \p MI defines a constant integer or a splat vector of
511/// constant integers.
512/// \returns the scalar constant or std::nullopt.
513std::optional<APInt>
515 const MachineRegisterInfo &MRI);
516
517/// Attempt to match a unary predicate against a scalar/splat constant or every
518/// element of a constant G_BUILD_VECTOR. If \p ConstVal is null, the source
519/// value was undef.
520bool matchUnaryPredicate(const MachineRegisterInfo &MRI, Register Reg,
521 std::function<bool(const Constant *ConstVal)> Match,
522 bool AllowUndefs = false);
523
524/// Returns true if given the TargetLowering's boolean contents information,
525/// the value \p Val contains a true value.
526bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
527 bool IsFP);
528/// \returns true if given the TargetLowering's boolean contents information,
529/// the value \p Val contains a false value.
530bool isConstFalseVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
531 bool IsFP);
532
533/// Returns an integer representing true, as defined by the
534/// TargetBooleanContents.
535int64_t getICmpTrueVal(const TargetLowering &TLI, bool IsVector, bool IsFP);
536
537/// Returns true if the given block should be optimized for size.
538bool shouldOptForSize(const MachineBasicBlock &MBB, ProfileSummaryInfo *PSI,
539 BlockFrequencyInfo *BFI);
540
543 LostDebugLocObserver *LocObserver,
544 SmallInstListTy &DeadInstChain);
546 LostDebugLocObserver *LocObserver = nullptr);
548 LostDebugLocObserver *LocObserver = nullptr);
549
550/// Assuming the instruction \p MI is going to be deleted, attempt to salvage
551/// debug users of \p MI by writing the effect of \p MI in a DIExpression.
553
554} // End namespace llvm.
555#endif
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file declares a class to represent arbitrary precision floating point values and provide a varie...
basic Basic Alias true
#define LLVM_READNONE
Definition: Compiler.h:220
uint64_t Size
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Implement a low-level type suitable for MachineInstr level instruction selection.
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
unsigned Reg
Promote Memory to Register
Definition: Mem2Reg.cpp:110
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char PassName[]
Class for arbitrary precision integers.
Definition: APInt.h:76
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:268
Helper class to build MachineInstr.
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Represents a value which can be a Register or a constant.
Definition: Utils.h:387
RegOrConstant(Register Reg)
Definition: Utils.h:393
Register getReg() const
Definition: Utils.h:397
bool isCst() const
Definition: Utils.h:396
int64_t getCst() const
Definition: Utils.h:401
RegOrConstant(int64_t Cst)
Definition: Utils.h:394
bool isReg() const
Definition: Utils.h:395
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
@ ConstantFP
Definition: ISDOpcodes.h:77
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Register getFunctionLiveInPhysReg(MachineFunction &MF, const TargetInstrInfo &TII, MCRegister PhysReg, const TargetRegisterClass &RC, const DebugLoc &DL, LLT RegTy=LLT())
Return a virtual register corresponding to the incoming argument register PhysReg.
Definition: Utils.cpp:882
bool isBuildVectorAllZeros(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndef=false)
Return true if the specified instruction is a G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all of the...
Definition: Utils.cpp:1344
Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
Definition: Utils.cpp:54
MachineInstr * getOpcodeDef(unsigned Opcode, Register Reg, const MachineRegisterInfo &MRI)
See if Reg is defined by an single def instruction that is Opcode.
Definition: Utils.cpp:625
const ConstantFP * getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:438
std::optional< APInt > getIConstantVRegVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT, return the corresponding value.
Definition: Utils.cpp:293
std::optional< APFloat > ConstantFoldIntToFloat(unsigned Opcode, LLT DstTy, Register Src, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:956
std::optional< APInt > getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:1304
bool isAllOnesOrAllOnesSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant -1 integer or a splatted vector of a constant -1 integer (with...
Definition: Utils.cpp:1457
std::optional< APFloat > ConstantFoldFPBinOp(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:713
void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
Definition: Utils.cpp:1582
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
Definition: Utils.cpp:153
std::optional< SmallVector< unsigned > > ConstantFoldCountZeros(Register Src, const MachineRegisterInfo &MRI, std::function< unsigned(APInt)> CB)
Tries to constant fold a counting-zero operation (G_CTLZ or G_CTTZ) on Src.
Definition: Utils.cpp:969
std::optional< APInt > ConstantFoldExtOp(unsigned Opcode, const Register Op1, uint64_t Imm, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:915
std::optional< RegOrConstant > getVectorSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:1357
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to have exactly one bit set when defined.
std::optional< APInt > isConstantOrConstantSplatVector(MachineInstr &MI, const MachineRegisterInfo &MRI)
Determines if MI defines a constant integer or a splat vector of constant integers.
Definition: Utils.cpp:1427
bool isNullOrNullSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant 0 integer or a splatted vector of a constant 0 integer (with n...
Definition: Utils.cpp:1439
MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
Definition: Utils.cpp:465
bool matchUnaryPredicate(const MachineRegisterInfo &MRI, Register Reg, std::function< bool(const Constant *ConstVal)> Match, bool AllowUndefs=false)
Attempt to match a unary predicate against a scalar/splat constant or every element of a constant G_B...
Definition: Utils.cpp:1472
bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
Returns true if given the TargetLowering's boolean contents information, the value Val contains a tru...
Definition: Utils.cpp:1504
LLVM_READNONE LLT getLCMType(LLT OrigTy, LLT TargetTy)
Return the least common multiple type of OrigTy and TargetTy, by changing the number of vector elemen...
Definition: Utils.cpp:1076
std::optional< int64_t > getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
Definition: Utils.cpp:305
std::optional< APInt > ConstantFoldBinOp(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:644
bool shouldOptForSize(const MachineBasicBlock &MBB, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI)
Returns true if the given block should be optimized for size.
Definition: Utils.cpp:1541
bool isConstantOrConstantVector(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowFP=true, bool AllowOpaqueConstants=true)
Return true if the specified instruction is known to be a constant, or a vector of constants.
Definition: Utils.cpp:1407
bool canReplaceReg(Register DstReg, Register SrcReg, MachineRegisterInfo &MRI)
Check if DstReg can be replaced with SrcReg depending on the register constraints.
Definition: Utils.cpp:199
void saveUsesAndErase(MachineInstr &MI, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver, SmallInstListTy &DeadInstChain)
Definition: Utils.cpp:1548
void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel error as a missed optimization remark to the LLVMContext's diagnostic stream.
Definition: Utils.cpp:273
std::optional< ValueAndVReg > getAnyConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true, bool LookThroughAnyExt=false)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT or G_FCONST...
Definition: Utils.cpp:419
bool isBuildVectorAllOnes(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndef=false)
Return true if the specified instruction is a G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all of the...
Definition: Utils.cpp:1350
SmallVector< APInt > ConstantFoldVectorBinop(unsigned Opcode, const Register Op1, const Register Op2, const MachineRegisterInfo &MRI)
Tries to constant fold a vector binop with sources Op1 and Op2.
Definition: Utils.cpp:767
std::optional< FPValueAndVReg > getFConstantSplat(Register VReg, const MachineRegisterInfo &MRI, bool AllowUndef=true)
Returns a floating point scalar constant of a build vector splat if it exists.
Definition: Utils.cpp:1337
std::optional< APInt > ConstantFoldCastOp(unsigned Opcode, LLT DstTy, const Register Op0, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:932
void extractParts(Register Reg, LLT Ty, int NumParts, SmallVectorImpl< Register > &VRegs, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Helper function to split a wide generic register into bitwise blocks with the given Type (which impli...
Definition: Utils.cpp:479
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:1072
LLVM_READNONE LLT getCoverTy(LLT OrigTy, LLT TargetTy)
Return smallest type that covers both OrigTy and TargetTy and is multiple of TargetTy.
Definition: Utils.cpp:1143
std::optional< FPValueAndVReg > getFConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_FCONSTANT returns it...
Definition: Utils.cpp:427
bool isConstFalseVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
Definition: Utils.cpp:1517
APFloat getAPFloatFromSize(double Val, unsigned Size)
Returns an APFloat from Val converted to the appropriate size.
Definition: Utils.cpp:631
bool isBuildVectorConstantSplat(const Register Reg, const MachineRegisterInfo &MRI, int64_t SplatValue, bool AllowUndef)
Return true if the specified register is defined by G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all ...
Definition: Utils.cpp:1288
void eraseInstr(MachineInstr &MI, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver=nullptr)
Definition: Utils.cpp:1577
Register constrainRegToClass(MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, Register Reg, const TargetRegisterClass &RegClass)
Try to constrain Reg to the specified register class.
Definition: Utils.cpp:44
int64_t getICmpTrueVal(const TargetLowering &TLI, bool IsVector, bool IsFP)
Returns an integer representing true, as defined by the TargetBooleanContents.
Definition: Utils.cpp:1529
std::optional< ValueAndVReg > getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT returns its...
Definition: Utils.cpp:413
bool isKnownNeverSNaN(Register Val, const MachineRegisterInfo &MRI)
Returns true if Val can be assumed to never be a signaling NaN.
Definition: Utils.h:330
std::optional< DefinitionAndSourceRegister > getDefSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, and underlying value Register folding away any copies.
Definition: Utils.cpp:446
void eraseInstrs(ArrayRef< MachineInstr * > DeadInstrs, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver=nullptr)
Definition: Utils.cpp:1562
bool isKnownNeverNaN(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
Register getSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the source register for Reg, folding away any trivial copies.
Definition: Utils.cpp:472
LLVM_READNONE LLT getGCDType(LLT OrigTy, LLT TargetTy)
Return a type where the total size is the greatest common divisor of OrigTy and TargetTy.
Definition: Utils.cpp:1164
std::optional< int64_t > getIConstantSplatSExtVal(const Register Reg, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:1322
void extractVectorParts(Register Reg, unsigned NumElts, SmallVectorImpl< Register > &VRegs, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Version which handles irregular sub-vector splits.
Definition: Utils.cpp:583
int getSplatIndex(ArrayRef< int > Mask)
If all non-negative Mask elements are the same value, return that value.
bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Check whether an instruction MI is dead: it only defines dead virtual registers, and doesn't have oth...
Definition: Utils.cpp:220
Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
Definition: Utils.cpp:865
void reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel warning as a missed optimization remark to the LLVMContext's diagnostic stream.
Definition: Utils.cpp:267
#define MORE()
Definition: regcomp.c:252
Simple struct used to hold a Register value and the instruction which defines it.
Definition: Utils.h:224
Register VReg
Definition: Utils.h:203
Simple struct used to hold a constant integer value and a virtual register.
Definition: Utils.h:183
Register VReg
Definition: Utils.h:185