LLVM 24.0.0git
MachineIRBuilder.h
Go to the documentation of this file.
1//===-- llvm/CodeGen/GlobalISel/MachineIRBuilder.h - MIBuilder --*- 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/// \file
9/// This file declares the MachineIRBuilder class.
10/// This is a helper class to build MachineInstr.
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_GLOBALISEL_MACHINEIRBUILDER_H
14#define LLVM_CODEGEN_GLOBALISEL_MACHINEIRBUILDER_H
15
22#include "llvm/IR/DebugLoc.h"
23#include "llvm/IR/Module.h"
25
26namespace llvm {
27
28// Forward declarations.
29class APInt;
30class BlockAddress;
31class Constant;
32class ConstantFP;
33class ConstantInt;
34class DataLayout;
35class GISelCSEInfo;
36class GlobalValue;
37class MCRegisterClass;
39class MachineFunction;
40class MachineInstr;
41class TargetInstrInfo;
43
44/// Class which stores all the state required in a MachineIRBuilder.
45/// Since MachineIRBuilders will only store state in this object, it allows
46/// to transfer BuilderState between different kinds of MachineIRBuilders.
48 /// MachineFunction under construction.
49 MachineFunction *MF = nullptr;
50 /// Information used to access the description of the opcodes.
51 const TargetInstrInfo *TII = nullptr;
52 /// Information used to verify types are consistent and to create virtual registers.
54 /// Debug location to be set to any instruction we create.
56 /// PC sections metadata to be set to any instruction we create.
57 MDNode *PCSections = nullptr;
58 /// MMRA Metadata to be set on any instruction we create.
59 MDNode *MMRA = nullptr;
60 Value *DS = nullptr;
61
62 /// \name Fields describing the insertion point.
63 /// @{
66 /// @}
67
69
71};
72
73class DstOp {
74 union {
79 };
80
81public:
83 DstOp(unsigned R) : Reg(R), Ty(DstType::Ty_Reg) {}
84 DstOp(Register R) : Reg(R), Ty(DstType::Ty_Reg) {}
86 DstOp(const LLT T) : LLTTy(T), Ty(DstType::Ty_LLT) {}
87 DstOp(const TargetRegisterClass *TRC) : RC(TRC), Ty(DstType::Ty_RC) {}
91 : Attrs({RCOrRB, Ty}), Ty(DstType::Ty_VRegAttrs) {}
92
94 switch (Ty) {
95 case DstType::Ty_Reg:
96 MIB.addDef(Reg);
97 break;
98 case DstType::Ty_LLT:
99 MIB.addDef(MRI.createGenericVirtualRegister(LLTTy));
100 break;
101 case DstType::Ty_RC:
102 MIB.addDef(MRI.createVirtualRegister(RC));
103 break;
105 MIB.addDef(MRI.createVirtualRegister(Attrs));
106 break;
107 }
108 }
109
111 switch (Ty) {
112 case DstType::Ty_RC:
113 return LLT{};
114 case DstType::Ty_LLT:
115 return LLTTy;
116 case DstType::Ty_Reg:
117 return MRI.getType(Reg);
119 return Attrs.Ty;
120 }
121 llvm_unreachable("Unrecognised DstOp::DstType enum");
122 }
123
124 Register getReg() const {
125 assert(Ty == DstType::Ty_Reg && "Not a register");
126 return Reg;
127 }
128
130 assert(Ty == DstType::Ty_RC && "Not a RC Operand");
131 return RC;
132 }
133
135 assert(Ty == DstType::Ty_VRegAttrs && "Not a VRegAttrs Operand");
136 return Attrs;
137 }
138
139 DstType getDstOpKind() const { return Ty; }
140
141private:
142 DstType Ty;
143};
144
145class SrcOp {
146 union {
150 int64_t Imm;
151 };
152
153public:
155 SrcOp(Register R) : Reg(R), Ty(SrcType::Ty_Reg) {}
157 SrcOp(const MachineInstrBuilder &MIB) : SrcMIB(MIB), Ty(SrcType::Ty_MIB) {}
159 /// Use of registers held in unsigned integer variables (or more rarely signed
160 /// integers) is no longer permitted to avoid ambiguity with upcoming support
161 /// for immediates.
162 SrcOp(unsigned) = delete;
163 SrcOp(int) = delete;
165 SrcOp(int64_t V) : Imm(V), Ty(SrcType::Ty_Imm) {}
166
168 switch (Ty) {
170 MIB.addPredicate(Pred);
171 break;
172 case SrcType::Ty_Reg:
173 MIB.addUse(Reg);
174 break;
175 case SrcType::Ty_MIB:
176 MIB.addUse(SrcMIB->getOperand(0).getReg());
177 break;
178 case SrcType::Ty_Imm:
179 MIB.addImm(Imm);
180 break;
181 }
182 }
183
185 switch (Ty) {
187 case SrcType::Ty_Imm:
188 llvm_unreachable("Not a register operand");
189 case SrcType::Ty_Reg:
190 return MRI.getType(Reg);
191 case SrcType::Ty_MIB:
192 return MRI.getType(SrcMIB->getOperand(0).getReg());
193 }
194 llvm_unreachable("Unrecognised SrcOp::SrcType enum");
195 }
196
197 Register getReg() const {
198 switch (Ty) {
200 case SrcType::Ty_Imm:
201 llvm_unreachable("Not a register operand");
202 case SrcType::Ty_Reg:
203 return Reg;
204 case SrcType::Ty_MIB:
205 return SrcMIB->getOperand(0).getReg();
206 }
207 llvm_unreachable("Unrecognised SrcOp::SrcType enum");
208 }
209
211 switch (Ty) {
213 return Pred;
214 default:
215 llvm_unreachable("Not a register operand");
216 }
217 }
218
219 int64_t getImm() const {
220 switch (Ty) {
221 case SrcType::Ty_Imm:
222 return Imm;
223 default:
224 llvm_unreachable("Not an immediate");
225 }
226 }
227
228 SrcType getSrcOpKind() const { return Ty; }
229
230private:
231 SrcType Ty;
232};
233
234/// Helper class to build MachineInstr.
235/// It keeps internally the insertion point and debug location for all
236/// the new instructions we want to create.
237/// This information can be modified via the related setters.
239
241
242 unsigned getOpcodeForMerge(const DstOp &DstOp, ArrayRef<SrcOp> SrcOps) const;
243
244protected:
245 void validateTruncExt(const LLT Dst, const LLT Src, bool IsExtend);
246
247 void validateUnaryOp(const LLT Res, const LLT Op0);
248 void validateBinaryOp(const LLT Res, const LLT Op0, const LLT Op1);
249 void validateShiftOp(const LLT Res, const LLT Op0, const LLT Op1);
250
251 void validateSelectOp(const LLT ResTy, const LLT TstTy, const LLT Op0Ty,
252 const LLT Op1Ty);
253
254 void recordInsertion(MachineInstr *InsertedInstr) const {
255 if (State.Observer)
256 State.Observer->createdInstr(*InsertedInstr);
257 }
258
259public:
260 /// Some constructors for easy use.
261 MachineIRBuilder() = default;
263
268
270 MachineIRBuilder(*MI.getParent(), MI.getIterator()) {
271 setInstr(MI);
272 setDebugLoc(MI.getDebugLoc());
273 }
274
279
280 virtual ~MachineIRBuilder() = default;
281
282 MachineIRBuilder(const MachineIRBuilderState &BState) : State(BState) {}
283
285 assert(State.TII && "TargetInstrInfo is not set");
286 return *State.TII;
287 }
288
289 /// Getter for the function we currently build.
291 assert(State.MF && "MachineFunction is not set");
292 return *State.MF;
293 }
294
295 const MachineFunction &getMF() const {
296 assert(State.MF && "MachineFunction is not set");
297 return *State.MF;
298 }
299
300 const DataLayout &getDataLayout() const {
301 return getMF().getFunction().getDataLayout();
302 }
303
305 return getMF().getFunction().getContext();
306 }
307
308 /// Getter for DebugLoc
309 const DebugLoc &getDL() { return State.DL; }
310
311 /// Getter for MRI
312 MachineRegisterInfo *getMRI() { return State.MRI; }
313 const MachineRegisterInfo *getMRI() const { return State.MRI; }
314
315 /// Getter for the State
316 MachineIRBuilderState &getState() { return State; }
317
318 /// Setter for the State
319 void setState(const MachineIRBuilderState &NewState) { State = NewState; }
320
321 /// Getter for the basic block we currently build.
322 const MachineBasicBlock &getMBB() const {
323 assert(State.MBB && "MachineBasicBlock is not set");
324 return *State.MBB;
325 }
326
328 return const_cast<MachineBasicBlock &>(
329 const_cast<const MachineIRBuilder *>(this)->getMBB());
330 }
331
332 GISelCSEInfo *getCSEInfo() { return State.CSEInfo; }
333 const GISelCSEInfo *getCSEInfo() const { return State.CSEInfo; }
334
335 /// Current insertion point for new instructions.
337
338 /// Set the insertion point before the specified position.
339 /// \pre MBB must be in getMF().
340 /// \pre II must be a valid iterator in MBB.
342 assert(MBB.getParent() == &getMF() &&
343 "Basic block is in a different function");
344 State.MBB = &MBB;
345 State.II = II;
346 }
347
348 /// @}
349
350 void setCSEInfo(GISelCSEInfo *Info) { State.CSEInfo = Info; }
351
352 /// \name Setters for the insertion point.
353 /// @{
354 /// Set the MachineFunction where to build instructions.
355 void setMF(MachineFunction &MF);
356
357 /// Set the insertion point to the end of \p MBB.
358 /// \pre \p MBB must be contained by getMF().
360 State.MBB = &MBB;
361 State.II = MBB.end();
362 assert(&getMF() == MBB.getParent() &&
363 "Basic block is in a different function");
364 }
365
366 /// Set the insertion point to before MI.
367 /// \pre MI must be in getMF().
369 assert(MI.getParent() && "Instruction is not part of a basic block");
370 setMBB(*MI.getParent());
371 State.II = MI.getIterator();
372 setPCSections(MI.getPCSections());
373 setMMRAMetadata(MI.getMMRAMetadata());
374 setDeactivationSymbol(MI.getDeactivationSymbol());
375 }
376 /// @}
377
378 /// Set the insertion point to before MI, and set the debug loc to MI's loc.
379 /// \pre MI must be in getMF().
381 setInstr(MI);
382 setDebugLoc(MI.getDebugLoc());
383 }
384
386 State.Observer = &Observer;
387 }
388
389 GISelChangeObserver *getObserver() { return State.Observer; }
390
391 void stopObservingChanges() { State.Observer = nullptr; }
392
393 bool isObservingChanges() const { return State.Observer != nullptr; }
394 /// @}
395
396 /// Set the debug location to \p DL for all the next build instructions.
397 void setDebugLoc(const DebugLoc &DL) { this->State.DL = DL; }
398
399 /// Get the current instruction's debug location.
400 const DebugLoc &getDebugLoc() { return State.DL; }
401
402 /// Set the PC sections metadata to \p MD for all the next build instructions.
403 void setPCSections(MDNode *MD) { State.PCSections = MD; }
404
405 /// Get the current instruction's PC sections metadata.
406 MDNode *getPCSections() { return State.PCSections; }
407
408 /// Set the PC sections metadata to \p MD for all the next build instructions.
409 void setMMRAMetadata(MDNode *MMRA) { State.MMRA = MMRA; }
410
411 Value *getDeactivationSymbol() { return State.DS; }
412 void setDeactivationSymbol(Value *DS) { State.DS = DS; }
413
414 /// Get the current instruction's MMRA metadata.
415 MDNode *getMMRAMetadata() { return State.MMRA; }
416
417 /// Build and insert <empty> = \p Opcode <empty>.
418 /// The insertion point is the one set by the last call of either
419 /// setBasicBlock or setMI.
420 ///
421 /// \pre setBasicBlock or setMI must have been called.
422 ///
423 /// \return a MachineInstrBuilder for the newly created instruction.
425 return insertInstr(buildInstrNoInsert(Opcode));
426 }
427
428 /// Build but don't insert <empty> = \p Opcode <empty>.
429 ///
430 /// \pre setMF, setBasicBlock or setMI must have been called.
431 ///
432 /// \return a MachineInstrBuilder for the newly created instruction.
433 MachineInstrBuilder buildInstrNoInsert(unsigned Opcode);
434
435 /// Insert an existing instruction at the insertion point.
437
438 /// Build and insert a DBG_VALUE instruction expressing the fact that the
439 /// associated \p Variable lives in \p Reg (suitably modified by \p Expr).
440 MachineInstrBuilder buildDirectDbgValue(Register Reg, const MDNode *Variable,
441 const MDNode *Expr);
442
443 /// Build and insert a DBG_VALUE instruction expressing the fact that the
444 /// associated \p Variable lives in memory at \p Reg (suitably modified by \p
445 /// Expr).
446 MachineInstrBuilder buildIndirectDbgValue(Register Reg,
447 const MDNode *Variable,
448 const MDNode *Expr);
449
450 /// Build and insert a DBG_VALUE instruction expressing the fact that the
451 /// associated \p Variable lives in the stack slot specified by \p FI
452 /// (suitably modified by \p Expr).
453 MachineInstrBuilder buildFIDbgValue(int FI, const MDNode *Variable,
454 const MDNode *Expr);
455
456 /// Build and insert a DBG_VALUE instructions specifying that \p Variable is
457 /// given by \p C (suitably modified by \p Expr).
458 MachineInstrBuilder buildConstDbgValue(const Constant &C,
459 const MDNode *Variable,
460 const MDNode *Expr);
461
462 /// Build and insert a DBG_LABEL instructions specifying that \p Label is
463 /// given. Convert "llvm.dbg.label Label" to "DBG_LABEL Label".
464 MachineInstrBuilder buildDbgLabel(const MDNode *Label);
465
466 /// Build and insert \p Res = G_DYN_STACKALLOC \p Size, \p Align
467 ///
468 /// G_DYN_STACKALLOC does a dynamic stack allocation and writes the address of
469 /// the allocated memory into \p Res.
470 /// \pre setBasicBlock or setMI must have been called.
471 /// \pre \p Res must be a generic virtual register with pointer type.
472 ///
473 /// \return a MachineInstrBuilder for the newly created instruction.
474 MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size,
475 Align Alignment);
476
477 /// Build and insert \p Res = G_FRAME_INDEX \p Idx
478 ///
479 /// G_FRAME_INDEX materializes the address of an alloca value or other
480 /// stack-based object.
481 ///
482 /// \pre setBasicBlock or setMI must have been called.
483 /// \pre \p Res must be a generic virtual register with pointer type.
484 ///
485 /// \return a MachineInstrBuilder for the newly created instruction.
486 MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx);
487
488 /// Build and insert \p Res = G_GLOBAL_VALUE \p GV
489 ///
490 /// G_GLOBAL_VALUE materializes the address of the specified global
491 /// into \p Res.
492 ///
493 /// \pre setBasicBlock or setMI must have been called.
494 /// \pre \p Res must be a generic virtual register with pointer type
495 /// in the same address space as \p GV.
496 ///
497 /// \return a MachineInstrBuilder for the newly created instruction.
498 MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV);
499
500 /// Build and insert \p Res = G_CONSTANT_POOL \p Idx
501 ///
502 /// G_CONSTANT_POOL materializes the address of an object in the constant
503 /// pool.
504 ///
505 /// \pre setBasicBlock or setMI must have been called.
506 /// \pre \p Res must be a generic virtual register with pointer type.
507 ///
508 /// \return a MachineInstrBuilder for the newly created instruction.
509 MachineInstrBuilder buildConstantPool(const DstOp &Res, unsigned Idx);
510
511 /// Build and insert \p Res = G_PTR_ADD \p Op0, \p Op1
512 ///
513 /// G_PTR_ADD adds \p Op1 addressible units to the pointer specified by \p Op0,
514 /// storing the resulting pointer in \p Res. Addressible units are typically
515 /// bytes but this can vary between targets.
516 ///
517 /// \pre setBasicBlock or setMI must have been called.
518 /// \pre \p Res and \p Op0 must be generic virtual registers with pointer
519 /// type.
520 /// \pre \p Op1 must be a generic virtual register with scalar type.
521 ///
522 /// \return a MachineInstrBuilder for the newly created instruction.
523 MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0,
524 const SrcOp &Op1,
525 std::optional<unsigned> Flags = std::nullopt);
526
527 /// Build and insert an instruction with appropriate flags for addressing some
528 /// offset of an object, i.e.: \p Res = nuw inbounds G_PTR_ADD \p Op0, \p Op1
529 /// The value of \p Op0 must be a pointer into or just after an object, adding
530 /// the value of \p Op1 to it must yield to a pointer into or just after the
531 /// same object.
532 ///
533 /// \pre setBasicBlock or setMI must have been called.
534 /// \pre \p Res and \p Op0 must be generic virtual registers with pointer
535 /// type.
536 /// \pre \p Op1 must be a generic virtual register with scalar type.
537 ///
538 /// \return a MachineInstrBuilder for the newly created instruction.
539 MachineInstrBuilder buildObjectPtrOffset(const DstOp &Res, const SrcOp &Op0,
540 const SrcOp &Op1);
541
542 /// Materialize and insert \p Res = G_PTR_ADD \p Op0, (G_CONSTANT \p Value)
543 ///
544 /// G_PTR_ADD adds \p Value bytes to the pointer specified by \p Op0,
545 /// storing the resulting pointer in \p Res. If \p Value is zero then no
546 /// G_PTR_ADD or G_CONSTANT will be created and \pre Op0 will be assigned to
547 /// \p Res.
548 ///
549 /// \pre setBasicBlock or setMI must have been called.
550 /// \pre \p Op0 must be a generic virtual register with pointer type.
551 /// \pre \p ValueTy must be a scalar type.
552 /// \pre \p Res must be 0. This is to detect confusion between
553 /// materializePtrAdd() and buildPtrAdd().
554 /// \post \p Res will either be a new generic virtual register of the same
555 /// type as \p Op0 or \p Op0 itself.
556 ///
557 /// \return a MachineInstrBuilder for the newly created instruction.
558 std::optional<MachineInstrBuilder>
559 materializePtrAdd(Register &Res, Register Op0, const LLT ValueTy,
561 std::optional<unsigned> Flags = std::nullopt);
562
563 /// Materialize and insert an instruction with appropriate flags for
564 /// addressing some offset of an object, i.e.:
565 /// \p Res = nuw inbounds G_PTR_ADD \p Op0, (G_CONSTANT \p Value)
566 /// The value of \p Op0 must be a pointer into or just after an object, adding
567 /// \p Value to it must yield to a pointer into or just after the same object.
568 ///
569 /// \pre setBasicBlock or setMI must have been called.
570 /// \pre \p Op0 must be a generic virtual register with pointer type.
571 /// \pre \p ValueTy must be a scalar type.
572 /// \pre \p Res must be 0. This is to detect confusion between
573 /// materializeObjectPtrOffset() and buildObjectPtrOffset().
574 /// \post \p Res will either be a new generic virtual register of the same
575 /// type as \p Op0 or \p Op0 itself.
576 ///
577 /// \return a MachineInstrBuilder for the newly created instruction.
578 std::optional<MachineInstrBuilder>
579 materializeObjectPtrOffset(Register &Res, Register Op0, const LLT ValueTy,
581
582 /// Build and insert \p Res = G_PTRMASK \p Op0, \p Op1
584 const SrcOp &Op1) {
585 return buildInstr(TargetOpcode::G_PTRMASK, {Res}, {Op0, Op1});
586 }
587
588 /// Build and insert \p Res = G_PTRMASK \p Op0, \p G_CONSTANT (1 << NumBits) - 1
589 ///
590 /// This clears the low bits of a pointer operand without destroying its
591 /// pointer properties. This has the effect of rounding the address *down* to
592 /// a specified alignment in bits.
593 ///
594 /// \pre setBasicBlock or setMI must have been called.
595 /// \pre \p Res and \p Op0 must be generic virtual registers with pointer
596 /// type.
597 /// \pre \p NumBits must be an integer representing the number of low bits to
598 /// be cleared in \p Op0.
599 ///
600 /// \return a MachineInstrBuilder for the newly created instruction.
601 MachineInstrBuilder buildMaskLowPtrBits(const DstOp &Res, const SrcOp &Op0,
602 uint32_t NumBits);
603
604 /// Build and insert
605 /// a, b, ..., x = G_UNMERGE_VALUES \p Op0
606 /// \p Res = G_BUILD_VECTOR a, b, ..., x, undef, ..., undef
607 ///
608 /// Pad \p Op0 with undef elements to match number of elements in \p Res.
609 ///
610 /// \pre setBasicBlock or setMI must have been called.
611 /// \pre \p Res and \p Op0 must be generic virtual registers with vector type,
612 /// same vector element type and Op0 must have fewer elements then Res.
613 ///
614 /// \return a MachineInstrBuilder for the newly created build vector instr.
615 MachineInstrBuilder buildPadVectorWithUndefElements(const DstOp &Res,
616 const SrcOp &Op0);
617
618 /// Build and insert
619 /// a, b, ..., x, y, z = G_UNMERGE_VALUES \p Op0
620 /// \p Res = G_BUILD_VECTOR a, b, ..., x
621 ///
622 /// Delete trailing elements in \p Op0 to match number of elements in \p Res.
623 ///
624 /// \pre setBasicBlock or setMI must have been called.
625 /// \pre \p Res and \p Op0 must be generic virtual registers with vector type,
626 /// same vector element type and Op0 must have more elements then Res.
627 ///
628 /// \return a MachineInstrBuilder for the newly created build vector instr.
629 MachineInstrBuilder buildDeleteTrailingVectorElements(const DstOp &Res,
630 const SrcOp &Op0);
631
632 /// Build and insert \p Res, \p CarryOut = G_UADDO \p Op0, \p Op1
633 ///
634 /// G_UADDO sets \p Res to \p Op0 + \p Op1 (truncated to the bit width) and
635 /// sets \p CarryOut to 1 if the result overflowed in unsigned arithmetic.
636 ///
637 /// \pre setBasicBlock or setMI must have been called.
638 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers with the
639 /// same scalar type.
640 ////\pre \p CarryOut must be generic virtual register with scalar type
641 ///(typically s1)
642 ///
643 /// \return The newly created instruction.
644 MachineInstrBuilder buildUAddo(const DstOp &Res, const DstOp &CarryOut,
645 const SrcOp &Op0, const SrcOp &Op1) {
646 return buildInstr(TargetOpcode::G_UADDO, {Res, CarryOut}, {Op0, Op1});
647 }
648
649 /// Build and insert \p Res, \p CarryOut = G_USUBO \p Op0, \p Op1
650 MachineInstrBuilder buildUSubo(const DstOp &Res, const DstOp &CarryOut,
651 const SrcOp &Op0, const SrcOp &Op1) {
652 return buildInstr(TargetOpcode::G_USUBO, {Res, CarryOut}, {Op0, Op1});
653 }
654
655 /// Build and insert \p Res, \p CarryOut = G_SADDO \p Op0, \p Op1
656 MachineInstrBuilder buildSAddo(const DstOp &Res, const DstOp &CarryOut,
657 const SrcOp &Op0, const SrcOp &Op1) {
658 return buildInstr(TargetOpcode::G_SADDO, {Res, CarryOut}, {Op0, Op1});
659 }
660
661 /// Build and insert \p Res, \p CarryOut = G_SUBO \p Op0, \p Op1
662 MachineInstrBuilder buildSSubo(const DstOp &Res, const DstOp &CarryOut,
663 const SrcOp &Op0, const SrcOp &Op1) {
664 return buildInstr(TargetOpcode::G_SSUBO, {Res, CarryOut}, {Op0, Op1});
665 }
666
667 /// Build and insert \p Res, \p CarryOut = G_UADDE \p Op0,
668 /// \p Op1, \p CarryIn
669 ///
670 /// G_UADDE sets \p Res to \p Op0 + \p Op1 + \p CarryIn (truncated to the bit
671 /// width) and sets \p CarryOut to 1 if the result overflowed in unsigned
672 /// arithmetic.
673 ///
674 /// \pre setBasicBlock or setMI must have been called.
675 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
676 /// with the same scalar type.
677 /// \pre \p CarryOut and \p CarryIn must be generic virtual
678 /// registers with the same scalar type (typically s1)
679 ///
680 /// \return The newly created instruction.
681 MachineInstrBuilder buildUAdde(const DstOp &Res, const DstOp &CarryOut,
682 const SrcOp &Op0, const SrcOp &Op1,
683 const SrcOp &CarryIn) {
684 return buildInstr(TargetOpcode::G_UADDE, {Res, CarryOut},
685 {Op0, Op1, CarryIn});
686 }
687
688 /// Build and insert \p Res, \p CarryOut = G_USUBE \p Op0, \p Op1, \p CarryInp
689 MachineInstrBuilder buildUSube(const DstOp &Res, const DstOp &CarryOut,
690 const SrcOp &Op0, const SrcOp &Op1,
691 const SrcOp &CarryIn) {
692 return buildInstr(TargetOpcode::G_USUBE, {Res, CarryOut},
693 {Op0, Op1, CarryIn});
694 }
695
696 /// Build and insert \p Res, \p CarryOut = G_SADDE \p Op0, \p Op1, \p CarryInp
697 MachineInstrBuilder buildSAdde(const DstOp &Res, const DstOp &CarryOut,
698 const SrcOp &Op0, const SrcOp &Op1,
699 const SrcOp &CarryIn) {
700 return buildInstr(TargetOpcode::G_SADDE, {Res, CarryOut},
701 {Op0, Op1, CarryIn});
702 }
703
704 /// Build and insert \p Res, \p CarryOut = G_SSUBE \p Op0, \p Op1, \p CarryInp
705 MachineInstrBuilder buildSSube(const DstOp &Res, const DstOp &CarryOut,
706 const SrcOp &Op0, const SrcOp &Op1,
707 const SrcOp &CarryIn) {
708 return buildInstr(TargetOpcode::G_SSUBE, {Res, CarryOut},
709 {Op0, Op1, CarryIn});
710 }
711
712 /// Build and insert \p Res = G_ANYEXT \p Op0
713 ///
714 /// G_ANYEXT produces a register of the specified width, with bits 0 to
715 /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are unspecified
716 /// (i.e. this is neither zero nor sign-extension). For a vector register,
717 /// each element is extended individually.
718 ///
719 /// \pre setBasicBlock or setMI must have been called.
720 /// \pre \p Res must be a generic virtual register with scalar or vector type.
721 /// \pre \p Op must be a generic virtual register with scalar or vector type.
722 /// \pre \p Op must be smaller than \p Res
723 ///
724 /// \return The newly created instruction.
725
726 MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op);
727
728 /// Build and insert \p Res = G_SEXT \p Op
729 ///
730 /// G_SEXT produces a register of the specified width, with bits 0 to
731 /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are duplicated from the
732 /// high bit of \p Op (i.e. 2s-complement sign extended).
733 ///
734 /// \pre setBasicBlock or setMI must have been called.
735 /// \pre \p Res must be a generic virtual register with scalar or vector type.
736 /// \pre \p Op must be a generic virtual register with scalar or vector type.
737 /// \pre \p Op must be smaller than \p Res
738 ///
739 /// \return The newly created instruction.
740 MachineInstrBuilder buildSExt(const DstOp &Res, const SrcOp &Op);
741
742 /// Build and insert \p Res = G_SEXT_INREG \p Op, ImmOp
743 MachineInstrBuilder buildSExtInReg(const DstOp &Res, const SrcOp &Op, int64_t ImmOp) {
744 return buildInstr(TargetOpcode::G_SEXT_INREG, {Res}, {Op, SrcOp(ImmOp)});
745 }
746
747 /// Build and insert \p Res = G_FPEXT \p Op
749 std::optional<unsigned> Flags = std::nullopt) {
750 return buildInstr(TargetOpcode::G_FPEXT, {Res}, {Op}, Flags);
751 }
752
753 /// Build and insert a G_PTRTOINT instruction.
755 return buildInstr(TargetOpcode::G_PTRTOINT, {Dst}, {Src});
756 }
757
758 /// Build and insert a G_INTTOPTR instruction.
760 return buildInstr(TargetOpcode::G_INTTOPTR, {Dst}, {Src});
761 }
762
763 /// Build and insert \p Dst = G_BITCAST \p Src
764 MachineInstrBuilder buildBitcast(const DstOp &Dst, const SrcOp &Src) {
765 return buildInstr(TargetOpcode::G_BITCAST, {Dst}, {Src});
766 }
767
768 /// Build and insert \p Dst = G_ADDRSPACE_CAST \p Src
770 return buildInstr(TargetOpcode::G_ADDRSPACE_CAST, {Dst}, {Src});
771 }
772
773 /// \return The opcode of the extension the target wants to use for boolean
774 /// values.
775 unsigned getBoolExtOp(bool IsVec, bool IsFP) const;
776
777 // Build and insert \p Res = G_ANYEXT \p Op, \p Res = G_SEXT \p Op, or \p Res
778 // = G_ZEXT \p Op depending on how the target wants to extend boolean values.
779 MachineInstrBuilder buildBoolExt(const DstOp &Res, const SrcOp &Op,
780 bool IsFP);
781
782 // Build and insert \p Res = G_SEXT_INREG \p Op, 1 or \p Res = G_AND \p Op, 1,
783 // or COPY depending on how the target wants to extend boolean values, using
784 // the original register size.
785 MachineInstrBuilder buildBoolExtInReg(const DstOp &Res, const SrcOp &Op,
786 bool IsVector,
787 bool IsFP);
788
789 /// Build and insert \p Res = G_ZEXT \p Op
790 ///
791 /// G_ZEXT produces a register of the specified width, with bits 0 to
792 /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are 0. For a vector
793 /// register, each element is extended individually.
794 ///
795 /// \pre setBasicBlock or setMI must have been called.
796 /// \pre \p Res must be a generic virtual register with scalar or vector type.
797 /// \pre \p Op must be a generic virtual register with scalar or vector type.
798 /// \pre \p Op must be smaller than \p Res
799 ///
800 /// \return The newly created instruction.
801 MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op,
802 std::optional<unsigned> Flags = std::nullopt);
803
804 /// Build and insert \p Res = G_SEXT \p Op, \p Res = G_TRUNC \p Op, or
805 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
806 ///
807 /// \pre setBasicBlock or setMI must have been called.
808 /// \pre \p Res must be a generic virtual register with scalar or vector type.
809 /// \pre \p Op must be a generic virtual register with scalar or vector type.
810 ///
811 /// \return The newly created instruction.
812 MachineInstrBuilder buildSExtOrTrunc(const DstOp &Res, const SrcOp &Op);
813
814 /// Build and insert \p Res = G_ZEXT \p Op, \p Res = G_TRUNC \p Op, or
815 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
816 ///
817 /// \pre setBasicBlock or setMI must have been called.
818 /// \pre \p Res must be a generic virtual register with scalar or vector type.
819 /// \pre \p Op must be a generic virtual register with scalar or vector type.
820 ///
821 /// \return The newly created instruction.
822 MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op);
823
824 // Build and insert \p Res = G_ANYEXT \p Op, \p Res = G_TRUNC \p Op, or
825 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
826 ///
827 /// \pre setBasicBlock or setMI must have been called.
828 /// \pre \p Res must be a generic virtual register with scalar or vector type.
829 /// \pre \p Op must be a generic virtual register with scalar or vector type.
830 ///
831 /// \return The newly created instruction.
832 MachineInstrBuilder buildAnyExtOrTrunc(const DstOp &Res, const SrcOp &Op);
833
834 /// Build and insert \p Res = \p ExtOpc, \p Res = G_TRUNC \p
835 /// Op, or \p Res = COPY \p Op depending on the differing sizes of \p Res and
836 /// \p Op.
837 ///
838 /// \pre setBasicBlock or setMI must have been called.
839 /// \pre \p Res must be a generic virtual register with scalar or vector type.
840 /// \pre \p Op must be a generic virtual register with scalar or vector type.
841 ///
842 /// \return The newly created instruction.
843 MachineInstrBuilder buildExtOrTrunc(unsigned ExtOpc, const DstOp &Res,
844 const SrcOp &Op);
845
846 /// Build and inserts \p Res = \p G_AND \p Op, \p LowBitsSet(ImmOp)
847 /// Since there is no G_ZEXT_INREG like G_SEXT_INREG, the instruction is
848 /// emulated using G_AND.
849 MachineInstrBuilder buildZExtInReg(const DstOp &Res, const SrcOp &Op,
850 int64_t ImmOp);
851
852 /// Build and insert \p Res = \p G_TRUNC_SSAT_S \p Op
853 ///
854 /// G_TRUNC_SSAT_S truncates the signed input, \p Op, to a signed result with
855 /// saturation.
856 ///
857 /// \pre setBasicBlock or setMI must have been called.
858 /// \pre \p Res must be a generic virtual register with scalar or vector type.
859 /// \pre \p Op must be a generic virtual register with scalar or vector type.
860 ///
861 /// \return The newly created instruction.
863 return buildInstr(TargetOpcode::G_TRUNC_SSAT_S, {Res}, {Op});
864 }
865
866 /// Build and insert \p Res = \p G_TRUNC_SSAT_U \p Op
867 ///
868 /// G_TRUNC_SSAT_U truncates the signed input, \p Op, to an unsigned result
869 /// with saturation.
870 ///
871 /// \pre setBasicBlock or setMI must have been called.
872 /// \pre \p Res must be a generic virtual register with scalar or vector type.
873 /// \pre \p Op must be a generic virtual register with scalar or vector type.
874 ///
875 /// \return The newly created instruction.
877 return buildInstr(TargetOpcode::G_TRUNC_SSAT_U, {Res}, {Op});
878 }
879
880 /// Build and insert \p Res = \p G_TRUNC_USAT_U \p Op
881 ///
882 /// G_TRUNC_USAT_U truncates the unsigned input, \p Op, to an unsigned result
883 /// with saturation.
884 ///
885 /// \pre setBasicBlock or setMI must have been called.
886 /// \pre \p Res must be a generic virtual register with scalar or vector type.
887 /// \pre \p Op must be a generic virtual register with scalar or vector type.
888 ///
889 /// \return The newly created instruction.
891 return buildInstr(TargetOpcode::G_TRUNC_USAT_U, {Res}, {Op});
892 }
893
894 /// Build and insert an appropriate cast between two registers of equal size.
895 MachineInstrBuilder buildCast(const DstOp &Dst, const SrcOp &Src);
896
897 /// Build and insert G_BR \p Dest
898 ///
899 /// G_BR is an unconditional branch to \p Dest.
900 ///
901 /// \pre setBasicBlock or setMI must have been called.
902 ///
903 /// \return a MachineInstrBuilder for the newly created instruction.
905
906 /// Build and insert G_BRCOND \p Tst, \p Dest
907 ///
908 /// G_BRCOND is a conditional branch to \p Dest.
909 ///
910 /// \pre setBasicBlock or setMI must have been called.
911 /// \pre \p Tst must be a generic virtual register with scalar
912 /// type. At the beginning of legalization, this will be a single
913 /// bit (s1). Targets with interesting flags registers may change
914 /// this. For a wider type, whether the branch is taken must only
915 /// depend on bit 0 (for now).
916 ///
917 /// \return The newly created instruction.
918 MachineInstrBuilder buildBrCond(const SrcOp &Tst, MachineBasicBlock &Dest);
919
920 /// Build and insert G_BRINDIRECT \p Tgt
921 ///
922 /// G_BRINDIRECT is an indirect branch to \p Tgt.
923 ///
924 /// \pre setBasicBlock or setMI must have been called.
925 /// \pre \p Tgt must be a generic virtual register with pointer type.
926 ///
927 /// \return a MachineInstrBuilder for the newly created instruction.
928 MachineInstrBuilder buildBrIndirect(Register Tgt);
929
930 /// Build and insert G_BRJT \p TablePtr, \p JTI, \p IndexReg
931 ///
932 /// G_BRJT is a jump table branch using a table base pointer \p TablePtr,
933 /// jump table index \p JTI and index \p IndexReg
934 ///
935 /// \pre setBasicBlock or setMI must have been called.
936 /// \pre \p TablePtr must be a generic virtual register with pointer type.
937 /// \pre \p JTI must be a jump table index.
938 /// \pre \p IndexReg must be a generic virtual register with pointer type.
939 ///
940 /// \return a MachineInstrBuilder for the newly created instruction.
941 MachineInstrBuilder buildBrJT(Register TablePtr, unsigned JTI,
942 Register IndexReg);
943
944 /// Build and insert \p Res = G_CONSTANT \p Val
945 ///
946 /// G_CONSTANT is an integer constant with the specified size and value. \p
947 /// Val will be extended or truncated to the size of \p Reg.
948 ///
949 /// \pre setBasicBlock or setMI must have been called.
950 /// \pre \p Res must be a generic virtual register with scalar or pointer
951 /// type.
952 ///
953 /// \return The newly created instruction.
954 virtual MachineInstrBuilder buildConstant(const DstOp &Res,
955 const ConstantInt &Val);
956
957 /// Build and insert \p Res = G_CONSTANT \p Val
958 ///
959 /// G_CONSTANT is an integer constant with the specified size and value.
960 ///
961 /// \pre setBasicBlock or setMI must have been called.
962 /// \pre \p Res must be a generic virtual register with scalar type.
963 ///
964 /// \return The newly created instruction.
965 MachineInstrBuilder buildConstant(const DstOp &Res, int64_t Val);
966 MachineInstrBuilder buildConstant(const DstOp &Res, const APInt &Val);
967
968 /// Build and insert \p Res = G_FCONSTANT \p Val
969 ///
970 /// G_FCONSTANT is a floating-point constant with the specified size and
971 /// value.
972 ///
973 /// \pre setBasicBlock or setMI must have been called.
974 /// \pre \p Res must be a generic virtual register with scalar type.
975 ///
976 /// \return The newly created instruction.
977 virtual MachineInstrBuilder buildFConstant(const DstOp &Res,
978 const ConstantFP &Val);
979
980 MachineInstrBuilder buildFConstant(const DstOp &Res, double Val);
981 MachineInstrBuilder buildFConstant(const DstOp &Res, const APFloat &Val);
982
983 /// Build and insert G_PTRAUTH_GLOBAL_VALUE
984 ///
985 /// \return a MachineInstrBuilder for the newly created instruction.
986 MachineInstrBuilder buildConstantPtrAuth(const DstOp &Res,
987 const ConstantPtrAuth *CPA,
988 Register Addr, Register AddrDisc);
989
990 /// Build and insert \p Res = COPY Op
991 ///
992 /// Register-to-register COPY sets \p Res to \p Op.
993 ///
994 /// \pre setBasicBlock or setMI must have been called.
995 ///
996 /// \return a MachineInstrBuilder for the newly created instruction.
997 MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op);
998
999
1000 /// Build and insert G_ASSERT_SEXT, G_ASSERT_ZEXT, or G_ASSERT_ALIGN
1001 ///
1002 /// \return a MachineInstrBuilder for the newly created instruction.
1004 const SrcOp &Op, unsigned Val) {
1005 return buildInstr(Opc, Res, Op).addImm(Val);
1006 }
1007
1008 /// Build and insert \p Res = G_ASSERT_ZEXT Op, Size
1009 ///
1010 /// \return a MachineInstrBuilder for the newly created instruction.
1012 unsigned Size) {
1013 return buildAssertInstr(TargetOpcode::G_ASSERT_ZEXT, Res, Op, Size);
1014 }
1015
1016 /// Build and insert \p Res = G_ASSERT_SEXT Op, Size
1017 ///
1018 /// \return a MachineInstrBuilder for the newly created instruction.
1020 unsigned Size) {
1021 return buildAssertInstr(TargetOpcode::G_ASSERT_SEXT, Res, Op, Size);
1022 }
1023
1024 /// Build and insert \p Res = G_ASSERT_ALIGN Op, AlignVal
1025 ///
1026 /// \return a MachineInstrBuilder for the newly created instruction.
1028 Align AlignVal) {
1029 return buildAssertInstr(TargetOpcode::G_ASSERT_ALIGN, Res, Op,
1030 AlignVal.value());
1031 }
1032
1033 /// Build and insert `Res = G_LOAD Addr, MMO`.
1034 ///
1035 /// Loads the value stored at \p Addr. Puts the result in \p Res.
1036 ///
1037 /// \pre setBasicBlock or setMI must have been called.
1038 /// \pre \p Res must be a generic virtual register.
1039 /// \pre \p Addr must be a generic virtual register with pointer type.
1040 ///
1041 /// \return a MachineInstrBuilder for the newly created instruction.
1042 MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr,
1043 MachineMemOperand &MMO) {
1044 return buildLoadInstr(TargetOpcode::G_LOAD, Res, Addr, MMO);
1045 }
1046
1047 /// Build and insert a G_LOAD instruction, while constructing the
1048 /// MachineMemOperand.
1050 buildLoad(const DstOp &Res, const SrcOp &Addr, MachinePointerInfo PtrInfo,
1051 Align Alignment,
1053 const AAMDNodes &AAInfo = AAMDNodes());
1054
1055 /// Build and insert `Res = <opcode> Addr, MMO`.
1056 ///
1057 /// Loads the value stored at \p Addr. Puts the result in \p Res.
1058 ///
1059 /// \pre setBasicBlock or setMI must have been called.
1060 /// \pre \p Res must be a generic virtual register.
1061 /// \pre \p Addr must be a generic virtual register with pointer type.
1062 ///
1063 /// \return a MachineInstrBuilder for the newly created instruction.
1064 MachineInstrBuilder buildLoadInstr(unsigned Opcode, const DstOp &Res,
1065 const SrcOp &Addr, MachineMemOperand &MMO);
1066
1067 /// Helper to create a load from a constant offset given a base address. Load
1068 /// the type of \p Dst from \p Offset from the given base address and memory
1069 /// operand.
1070 MachineInstrBuilder buildLoadFromOffset(const DstOp &Dst,
1071 const SrcOp &BasePtr,
1072 MachineMemOperand &BaseMMO,
1073 int64_t Offset);
1074
1075 /// Build and insert `G_STORE Val, Addr, MMO`.
1076 ///
1077 /// Stores the value \p Val to \p Addr.
1078 ///
1079 /// \pre setBasicBlock or setMI must have been called.
1080 /// \pre \p Val must be a generic virtual register.
1081 /// \pre \p Addr must be a generic virtual register with pointer type.
1082 ///
1083 /// \return a MachineInstrBuilder for the newly created instruction.
1084 MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr,
1085 MachineMemOperand &MMO);
1086
1087 /// Build and insert `<opcode> Val, Addr, MMO`.
1088 ///
1089 /// Stores the value \p Val to \p Addr.
1090 ///
1091 /// \pre setBasicBlock or setMI must have been called.
1092 /// \pre \p Val must be a generic virtual register.
1093 /// \pre \p Addr must be a generic virtual register with pointer type.
1094 ///
1095 /// \return a MachineInstrBuilder for the newly created instruction.
1096 MachineInstrBuilder buildStoreInstr(unsigned Opcode, const SrcOp &Val,
1097 const SrcOp &Addr,
1098 MachineMemOperand &MMO);
1099
1100 /// Build and insert a G_STORE instruction, while constructing the
1101 /// MachineMemOperand.
1103 buildStore(const SrcOp &Val, const SrcOp &Addr, MachinePointerInfo PtrInfo,
1104 Align Alignment,
1106 const AAMDNodes &AAInfo = AAMDNodes());
1107
1108 /// Build and insert `Res0, ... = G_EXTRACT Src, Idx0`.
1109 ///
1110 /// \pre setBasicBlock or setMI must have been called.
1111 /// \pre \p Res and \p Src must be generic virtual registers.
1112 ///
1113 /// \return a MachineInstrBuilder for the newly created instruction.
1114 MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index);
1115
1116 /// Build and insert \p Res = IMPLICIT_DEF.
1117 MachineInstrBuilder buildUndef(const DstOp &Res);
1118
1119 /// Build and insert \p Res = G_MERGE_VALUES \p Op0, ...
1120 ///
1121 /// G_MERGE_VALUES combines the input elements contiguously into a larger
1122 /// register. It should only be used when the destination register is not a
1123 /// vector.
1124 ///
1125 /// \pre setBasicBlock or setMI must have been called.
1126 /// \pre The entire register \p Res (and no more) must be covered by the input
1127 /// registers.
1128 /// \pre The type of all \p Ops registers must be identical.
1129 ///
1130 /// \return a MachineInstrBuilder for the newly created instruction.
1131 MachineInstrBuilder buildMergeValues(const DstOp &Res,
1133
1134 /// Build and insert \p Res = G_MERGE_VALUES \p Op0, ...
1135 /// or \p Res = G_BUILD_VECTOR \p Op0, ...
1136 /// or \p Res = G_CONCAT_VECTORS \p Op0, ...
1137 ///
1138 /// G_MERGE_VALUES combines the input elements contiguously into a larger
1139 /// register. It is used when the destination register is not a vector.
1140 /// G_BUILD_VECTOR combines scalar inputs into a vector register.
1141 /// G_CONCAT_VECTORS combines vector inputs into a vector register.
1142 ///
1143 /// \pre setBasicBlock or setMI must have been called.
1144 /// \pre The entire register \p Res (and no more) must be covered by the input
1145 /// registers.
1146 /// \pre The type of all \p Ops registers must be identical.
1147 ///
1148 /// \return a MachineInstrBuilder for the newly created instruction. The
1149 /// opcode of the new instruction will depend on the types of both
1150 /// the destination and the sources.
1151 MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res,
1153 MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res,
1154 std::initializer_list<SrcOp> Ops);
1155
1156 /// Build and insert \p Res0, ... = G_UNMERGE_VALUES \p Op
1157 ///
1158 /// G_UNMERGE_VALUES splits contiguous bits of the input into multiple
1159 ///
1160 /// \pre setBasicBlock or setMI must have been called.
1161 /// \pre The entire register \p Res (and no more) must be covered by the input
1162 /// registers.
1163 /// \pre The type of all \p Res registers must be identical.
1164 ///
1165 /// \return a MachineInstrBuilder for the newly created instruction.
1166 MachineInstrBuilder buildUnmerge(ArrayRef<LLT> Res, const SrcOp &Op);
1167 MachineInstrBuilder buildUnmerge(ArrayRef<Register> Res, const SrcOp &Op);
1168
1169 /// Build and insert an unmerge of \p Res sized pieces to cover \p Op
1170 MachineInstrBuilder buildUnmerge(LLT Res, const SrcOp &Op);
1171
1172 /// Build and insert an unmerge of pieces with \p Attrs register attributes to
1173 /// cover \p Op
1175 const SrcOp &Op);
1176
1177 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ...
1178 ///
1179 /// G_BUILD_VECTOR creates a vector value from multiple scalar registers.
1180 /// \pre setBasicBlock or setMI must have been called.
1181 /// \pre The entire register \p Res (and no more) must be covered by the
1182 /// input scalar registers.
1183 /// \pre The type of all \p Ops registers must be identical.
1184 ///
1185 /// \return a MachineInstrBuilder for the newly created instruction.
1186 MachineInstrBuilder buildBuildVector(const DstOp &Res,
1188
1189 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ... where each OpN is
1190 /// built with G_CONSTANT.
1191 MachineInstrBuilder buildBuildVectorConstant(const DstOp &Res,
1193
1194 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ... where each OpN is
1195 /// built with G_FCONSTANT.
1196 MachineInstrBuilder buildBuildVectorFConstant(const DstOp &Res,
1198
1199 /// Build and insert \p Res = G_BUILD_VECTOR with \p Src replicated to fill
1200 /// the number of elements
1201 MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src);
1202
1203 /// Build and insert \p Res = G_BUILD_VECTOR_TRUNC \p Op0, ...
1204 ///
1205 /// G_BUILD_VECTOR_TRUNC creates a vector value from multiple scalar registers
1206 /// which have types larger than the destination vector element type, and
1207 /// truncates the values to fit.
1208 ///
1209 /// If the operands given are already the same size as the vector elt type,
1210 /// then this method will instead create a G_BUILD_VECTOR instruction.
1211 ///
1212 /// \pre setBasicBlock or setMI must have been called.
1213 /// \pre The type of all \p Ops registers must be identical.
1214 ///
1215 /// \return a MachineInstrBuilder for the newly created instruction.
1216 MachineInstrBuilder buildBuildVectorTrunc(const DstOp &Res,
1218
1219 /// Build and insert a vector splat of a scalar \p Src using a
1220 /// G_INSERT_VECTOR_ELT and G_SHUFFLE_VECTOR idiom.
1221 ///
1222 /// \pre setBasicBlock or setMI must have been called.
1223 /// \pre \p Src must have the same type as the element type of \p Dst
1224 ///
1225 /// \return a MachineInstrBuilder for the newly created instruction.
1226 MachineInstrBuilder buildShuffleSplat(const DstOp &Res, const SrcOp &Src);
1227
1228 /// Build and insert \p Res = G_SHUFFLE_VECTOR \p Src1, \p Src2, \p Mask
1229 ///
1230 /// \pre setBasicBlock or setMI must have been called.
1231 ///
1232 /// \return a MachineInstrBuilder for the newly created instruction.
1233 MachineInstrBuilder buildShuffleVector(const DstOp &Res, const SrcOp &Src1,
1234 const SrcOp &Src2, ArrayRef<int> Mask);
1235
1236 /// Build and insert \p Res = G_SPLAT_VECTOR \p Val
1237 ///
1238 /// \pre setBasicBlock or setMI must have been called.
1239 /// \pre \p Res must be a generic virtual register with vector type.
1240 /// \pre \p Val must be a generic virtual register with scalar type.
1241 ///
1242 /// \return a MachineInstrBuilder for the newly created instruction.
1243 MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Val);
1244
1245 /// Build and insert \p Res = G_CONCAT_VECTORS \p Op0, ...
1246 ///
1247 /// G_CONCAT_VECTORS creates a vector from the concatenation of 2 or more
1248 /// vectors.
1249 ///
1250 /// \pre setBasicBlock or setMI must have been called.
1251 /// \pre The entire register \p Res (and no more) must be covered by the input
1252 /// registers.
1253 /// \pre The type of all source operands must be identical.
1254 ///
1255 /// \return a MachineInstrBuilder for the newly created instruction.
1256 MachineInstrBuilder buildConcatVectors(const DstOp &Res,
1258
1259 /// Build and insert `Res = G_INSERT_SUBVECTOR Src0, Src1, Idx`.
1260 ///
1261 /// \pre setBasicBlock or setMI must have been called.
1262 /// \pre \p Res, \p Src0, and \p Src1 must be generic virtual registers with
1263 /// vector type.
1264 ///
1265 /// \return a MachineInstrBuilder for the newly created instruction.
1266 MachineInstrBuilder buildInsertSubvector(const DstOp &Res, const SrcOp &Src0,
1267 const SrcOp &Src1, unsigned Index);
1268
1269 /// Build and insert `Res = G_EXTRACT_SUBVECTOR Src, Idx0`.
1270 ///
1271 /// \pre setBasicBlock or setMI must have been called.
1272 /// \pre \p Res and \p Src must be generic virtual registers with vector type.
1273 ///
1274 /// \return a MachineInstrBuilder for the newly created instruction.
1275 MachineInstrBuilder buildExtractSubvector(const DstOp &Res, const SrcOp &Src,
1276 unsigned Index);
1277
1278 MachineInstrBuilder buildInsert(const DstOp &Res, const SrcOp &Src,
1279 const SrcOp &Op, unsigned Index);
1280
1281 /// Build and insert \p Res = G_STEP_VECTOR \p Step
1282 ///
1283 /// G_STEP_VECTOR returns a scalable vector of linear sequence of step \p Step
1284 /// into \p Res.
1285 ///
1286 /// \pre setBasicBlock or setMI must have been called.
1287 /// \pre \p Res must be a generic virtual register with scalable vector type.
1288 ///
1289 /// \return a MachineInstrBuilder for the newly created instruction.
1290 MachineInstrBuilder buildStepVector(const DstOp &Res, unsigned Step);
1291
1292 /// Build and insert \p Res = G_VSCALE \p MinElts
1293 ///
1294 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1295 /// into \p Res.
1296 ///
1297 /// \pre setBasicBlock or setMI must have been called.
1298 /// \pre \p Res must be a generic virtual register with scalar type.
1299 ///
1300 /// \return a MachineInstrBuilder for the newly created instruction.
1301 MachineInstrBuilder buildVScale(const DstOp &Res, unsigned MinElts);
1302
1303 /// Build and insert \p Res = G_VSCALE \p MinElts
1304 ///
1305 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1306 /// into \p Res.
1307 ///
1308 /// \pre setBasicBlock or setMI must have been called.
1309 /// \pre \p Res must be a generic virtual register with scalar type.
1310 ///
1311 /// \return a MachineInstrBuilder for the newly created instruction.
1312 MachineInstrBuilder buildVScale(const DstOp &Res, const ConstantInt &MinElts);
1313
1314 /// Build and insert \p Res = G_VSCALE \p MinElts
1315 ///
1316 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1317 /// into \p Res.
1318 ///
1319 /// \pre setBasicBlock or setMI must have been called.
1320 /// \pre \p Res must be a generic virtual register with scalar type.
1321 ///
1322 /// \return a MachineInstrBuilder for the newly created instruction.
1323 MachineInstrBuilder buildVScale(const DstOp &Res, const APInt &MinElts);
1324
1325 /// Build and insert a G_INTRINSIC instruction.
1326 ///
1327 /// There are four different opcodes based on combinations of whether the
1328 /// intrinsic has side effects and whether it is convergent. These properties
1329 /// can be specified as explicit parameters, or else they are retrieved from
1330 /// the MCID for the intrinsic.
1331 ///
1332 /// The parameter \p Res provides the Registers or MOs that will be defined by
1333 /// this instruction.
1334 ///
1335 /// \pre setBasicBlock or setMI must have been called.
1336 ///
1337 /// \return a MachineInstrBuilder for the newly created instruction.
1339 bool HasSideEffects, bool isConvergent);
1341 MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<DstOp> Res,
1342 bool HasSideEffects, bool isConvergent);
1343 MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<DstOp> Res);
1344
1345 /// Build and insert \p Res = G_FPTRUNC \p Op
1346 ///
1347 /// G_FPTRUNC converts a floating-point value into one with a smaller type.
1348 ///
1349 /// \pre setBasicBlock or setMI must have been called.
1350 /// \pre \p Res must be a generic virtual register with scalar or vector type.
1351 /// \pre \p Op must be a generic virtual register with scalar or vector type.
1352 /// \pre \p Res must be smaller than \p Op
1353 ///
1354 /// \return The newly created instruction.
1356 buildFPTrunc(const DstOp &Res, const SrcOp &Op,
1357 std::optional<unsigned> Flags = std::nullopt);
1358
1359 /// Build and insert \p Res = G_TRUNC \p Op
1360 ///
1361 /// G_TRUNC extracts the low bits of a type. For a vector type each element is
1362 /// truncated independently before being packed into the destination.
1363 ///
1364 /// \pre setBasicBlock or setMI must have been called.
1365 /// \pre \p Res must be a generic virtual register with scalar or vector type.
1366 /// \pre \p Op must be a generic virtual register with scalar or vector type.
1367 /// \pre \p Res must be smaller than \p Op
1368 ///
1369 /// \return The newly created instruction.
1370 MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op,
1371 std::optional<unsigned> Flags = std::nullopt);
1372
1373 /// Build and insert a \p Res = G_ICMP \p Pred, \p Op0, \p Op1
1374 ///
1375 /// \pre setBasicBlock or setMI must have been called.
1376
1377 /// \pre \p Res must be a generic virtual register with scalar or
1378 /// vector type. Typically this starts as s1 or <N x s1>.
1379 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1380 /// same number of elements as \p Res. If \p Res is a scalar,
1381 /// \p Op0 must be either a scalar or pointer.
1382 /// \pre \p Pred must be an integer predicate.
1383 ///
1384 /// \return a MachineInstrBuilder for the newly created instruction.
1385 MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res,
1386 const SrcOp &Op0, const SrcOp &Op1,
1387 std::optional<unsigned> Flags = std::nullopt);
1388
1389 /// Build and insert a \p Res = G_FCMP \p Pred\p Op0, \p Op1
1390 ///
1391 /// \pre setBasicBlock or setMI must have been called.
1392
1393 /// \pre \p Res must be a generic virtual register with scalar or
1394 /// vector type. Typically this starts as s1 or <N x s1>.
1395 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1396 /// same number of elements as \p Res (or scalar, if \p Res is
1397 /// scalar).
1398 /// \pre \p Pred must be a floating-point predicate.
1399 ///
1400 /// \return a MachineInstrBuilder for the newly created instruction.
1401 MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, const DstOp &Res,
1402 const SrcOp &Op0, const SrcOp &Op1,
1403 std::optional<unsigned> Flags = std::nullopt);
1404
1405 /// Build and insert a \p Res = G_SCMP \p Op0, \p Op1
1406 ///
1407 /// \pre setBasicBlock or setMI must have been called.
1408
1409 /// \pre \p Res must be a generic virtual register with scalar or
1410 /// vector type. Typically this starts as s2 or <N x s2>.
1411 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1412 /// same number of elements as \p Res. If \p Res is a scalar,
1413 /// \p Op0 must be a scalar.
1414 ///
1415 /// \return a MachineInstrBuilder for the newly created instruction.
1416 MachineInstrBuilder buildSCmp(const DstOp &Res, const SrcOp &Op0,
1417 const SrcOp &Op1);
1418
1419 /// Build and insert a \p Res = G_UCMP \p Op0, \p Op1
1420 ///
1421 /// \pre setBasicBlock or setMI must have been called.
1422
1423 /// \pre \p Res must be a generic virtual register with scalar or
1424 /// vector type. Typically this starts as s2 or <N x s2>.
1425 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1426 /// same number of elements as \p Res. If \p Res is a scalar,
1427 /// \p Op0 must be a scalar.
1428 ///
1429 /// \return a MachineInstrBuilder for the newly created instruction.
1430 MachineInstrBuilder buildUCmp(const DstOp &Res, const SrcOp &Op0,
1431 const SrcOp &Op1);
1432
1433 /// Build and insert a \p Res = G_IS_FPCLASS \p Src, \p Mask
1435 unsigned Mask) {
1436 return buildInstr(TargetOpcode::G_IS_FPCLASS, {Res},
1437 {Src, SrcOp(static_cast<int64_t>(Mask))});
1438 }
1439
1440 /// Build and insert a \p Res = G_SELECT \p Tst, \p Op0, \p Op1
1441 ///
1442 /// \pre setBasicBlock or setMI must have been called.
1443 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1444 /// with the same type.
1445 /// \pre \p Tst must be a generic virtual register with scalar, pointer or
1446 /// vector type. If vector then it must have the same number of
1447 /// elements as the other parameters.
1448 ///
1449 /// \return a MachineInstrBuilder for the newly created instruction.
1450 MachineInstrBuilder buildSelect(const DstOp &Res, const SrcOp &Tst,
1451 const SrcOp &Op0, const SrcOp &Op1,
1452 std::optional<unsigned> Flags = std::nullopt);
1453
1454 /// Build and insert \p Res = G_INSERT_VECTOR_ELT \p Val,
1455 /// \p Elt, \p Idx
1456 ///
1457 /// \pre setBasicBlock or setMI must have been called.
1458 /// \pre \p Res and \p Val must be a generic virtual register
1459 // with the same vector type.
1460 /// \pre \p Elt and \p Idx must be a generic virtual register
1461 /// with scalar type.
1462 ///
1463 /// \return The newly created instruction.
1464 MachineInstrBuilder buildInsertVectorElement(const DstOp &Res,
1465 const SrcOp &Val,
1466 const SrcOp &Elt,
1467 const SrcOp &Idx);
1468
1469 /// Build and insert \p Res = G_EXTRACT_VECTOR_ELT \p Val, \p Idx
1470 ///
1471 /// \pre setBasicBlock or setMI must have been called.
1472 /// \pre \p Res must be a generic virtual register with scalar type.
1473 /// \pre \p Val must be a generic virtual register with vector type.
1474 ///
1475 /// \return The newly created instruction.
1477 const SrcOp &Val,
1478 const int Idx) {
1479 const TargetLowering *TLI = getMF().getSubtarget().getTargetLowering();
1480 LLT IdxTy = TLI->getVectorIdxLLT(getDataLayout());
1481 return buildExtractVectorElement(Res, Val, buildConstant(IdxTy, Idx));
1482 }
1483
1484 /// Build and insert \p Res = G_EXTRACT_VECTOR_ELT \p Val, \p Idx
1485 ///
1486 /// \pre setBasicBlock or setMI must have been called.
1487 /// \pre \p Res must be a generic virtual register with scalar type.
1488 /// \pre \p Val must be a generic virtual register with vector type.
1489 /// \pre \p Idx must be a generic virtual register with scalar type.
1490 ///
1491 /// \return The newly created instruction.
1492 MachineInstrBuilder buildExtractVectorElement(const DstOp &Res,
1493 const SrcOp &Val,
1494 const SrcOp &Idx);
1495
1496 /// Build and insert `OldValRes<def>, SuccessRes<def> =
1497 /// G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr, CmpVal, NewVal, MMO`.
1498 ///
1499 /// Atomically replace the value at \p Addr with \p NewVal if it is currently
1500 /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p
1501 /// Addr in \p Res, along with an s1 indicating whether it was replaced.
1502 ///
1503 /// \pre setBasicBlock or setMI must have been called.
1504 /// \pre \p OldValRes must be a generic virtual register of scalar type.
1505 /// \pre \p SuccessRes must be a generic virtual register of scalar type. It
1506 /// will be assigned 0 on failure and 1 on success.
1507 /// \pre \p Addr must be a generic virtual register with pointer type.
1508 /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual
1509 /// registers of the same type.
1510 ///
1511 /// \return a MachineInstrBuilder for the newly created instruction.
1513 buildAtomicCmpXchgWithSuccess(const DstOp &OldValRes, const DstOp &SuccessRes,
1514 const SrcOp &Addr, const SrcOp &CmpVal,
1515 const SrcOp &NewVal, MachineMemOperand &MMO);
1516
1517 /// Build and insert `OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal,
1518 /// MMO`.
1519 ///
1520 /// Atomically replace the value at \p Addr with \p NewVal if it is currently
1521 /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p
1522 /// Addr in \p Res.
1523 ///
1524 /// \pre setBasicBlock or setMI must have been called.
1525 /// \pre \p OldValRes must be a generic virtual register of scalar type.
1526 /// \pre \p Addr must be a generic virtual register with pointer type.
1527 /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual
1528 /// registers of the same type.
1529 ///
1530 /// \return a MachineInstrBuilder for the newly created instruction.
1531 MachineInstrBuilder buildAtomicCmpXchg(const DstOp &OldValRes,
1532 const SrcOp &Addr, const SrcOp &CmpVal,
1533 const SrcOp &NewVal,
1534 MachineMemOperand &MMO);
1535
1536 /// Build and insert `OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO`.
1537 ///
1538 /// Atomically read-modify-update the value at \p Addr with \p Val. Puts the
1539 /// original value from \p Addr in \p OldValRes. The modification is
1540 /// determined by the opcode.
1541 ///
1542 /// \pre setBasicBlock or setMI must have been called.
1543 /// \pre \p OldValRes must be a generic virtual register.
1544 /// \pre \p Addr must be a generic virtual register with pointer type.
1545 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1546 /// same type.
1547 ///
1548 /// \return a MachineInstrBuilder for the newly created instruction.
1549 MachineInstrBuilder buildAtomicRMW(unsigned Opcode, const DstOp &OldValRes,
1550 const SrcOp &Addr, const SrcOp &Val,
1551 MachineMemOperand &MMO);
1552
1553 /// Build and insert `OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO`.
1554 ///
1555 /// Atomically replace the value at \p Addr with \p Val. Puts the original
1556 /// value from \p Addr in \p OldValRes.
1557 ///
1558 /// \pre setBasicBlock or setMI must have been called.
1559 /// \pre \p OldValRes must be a generic virtual register.
1560 /// \pre \p Addr must be a generic virtual register with pointer type.
1561 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1562 /// same type.
1563 ///
1564 /// \return a MachineInstrBuilder for the newly created instruction.
1565 MachineInstrBuilder buildAtomicRMWXchg(Register OldValRes, Register Addr,
1566 Register Val, MachineMemOperand &MMO);
1567
1568 /// Build and insert `OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO`.
1569 ///
1570 /// Atomically replace the value at \p Addr with the addition of \p Val and
1571 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1572 ///
1573 /// \pre setBasicBlock or setMI must have been called.
1574 /// \pre \p OldValRes must be a generic virtual register.
1575 /// \pre \p Addr must be a generic virtual register with pointer type.
1576 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1577 /// same type.
1578 ///
1579 /// \return a MachineInstrBuilder for the newly created instruction.
1580 MachineInstrBuilder buildAtomicRMWAdd(Register OldValRes, Register Addr,
1581 Register Val, MachineMemOperand &MMO);
1582
1583 /// Build and insert `OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO`.
1584 ///
1585 /// Atomically replace the value at \p Addr with the subtraction of \p Val and
1586 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1587 ///
1588 /// \pre setBasicBlock or setMI must have been called.
1589 /// \pre \p OldValRes must be a generic virtual register.
1590 /// \pre \p Addr must be a generic virtual register with pointer type.
1591 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1592 /// same type.
1593 ///
1594 /// \return a MachineInstrBuilder for the newly created instruction.
1595 MachineInstrBuilder buildAtomicRMWSub(Register OldValRes, Register Addr,
1596 Register Val, MachineMemOperand &MMO);
1597
1598 /// Build and insert `OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO`.
1599 ///
1600 /// Atomically replace the value at \p Addr with the bitwise and of \p Val and
1601 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1602 ///
1603 /// \pre setBasicBlock or setMI must have been called.
1604 /// \pre \p OldValRes must be a generic virtual register.
1605 /// \pre \p Addr must be a generic virtual register with pointer type.
1606 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1607 /// same type.
1608 ///
1609 /// \return a MachineInstrBuilder for the newly created instruction.
1610 MachineInstrBuilder buildAtomicRMWAnd(Register OldValRes, Register Addr,
1611 Register Val, MachineMemOperand &MMO);
1612
1613 /// Build and insert `OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO`.
1614 ///
1615 /// Atomically replace the value at \p Addr with the bitwise nand of \p Val
1616 /// and the original value. Puts the original value from \p Addr in \p
1617 /// OldValRes.
1618 ///
1619 /// \pre setBasicBlock or setMI must have been called.
1620 /// \pre \p OldValRes must be a generic virtual register.
1621 /// \pre \p Addr must be a generic virtual register with pointer type.
1622 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1623 /// same type.
1624 ///
1625 /// \return a MachineInstrBuilder for the newly created instruction.
1626 MachineInstrBuilder buildAtomicRMWNand(Register OldValRes, Register Addr,
1627 Register Val, MachineMemOperand &MMO);
1628
1629 /// Build and insert `OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO`.
1630 ///
1631 /// Atomically replace the value at \p Addr with the bitwise or of \p Val and
1632 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1633 ///
1634 /// \pre setBasicBlock or setMI must have been called.
1635 /// \pre \p OldValRes must be a generic virtual register.
1636 /// \pre \p Addr must be a generic virtual register with pointer type.
1637 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1638 /// same type.
1639 ///
1640 /// \return a MachineInstrBuilder for the newly created instruction.
1641 MachineInstrBuilder buildAtomicRMWOr(Register OldValRes, Register Addr,
1642 Register Val, MachineMemOperand &MMO);
1643
1644 /// Build and insert `OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO`.
1645 ///
1646 /// Atomically replace the value at \p Addr with the bitwise xor of \p Val and
1647 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1648 ///
1649 /// \pre setBasicBlock or setMI must have been called.
1650 /// \pre \p OldValRes must be a generic virtual register.
1651 /// \pre \p Addr must be a generic virtual register with pointer type.
1652 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1653 /// same type.
1654 ///
1655 /// \return a MachineInstrBuilder for the newly created instruction.
1656 MachineInstrBuilder buildAtomicRMWXor(Register OldValRes, Register Addr,
1657 Register Val, MachineMemOperand &MMO);
1658
1659 /// Build and insert `OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO`.
1660 ///
1661 /// Atomically replace the value at \p Addr with the signed maximum of \p
1662 /// Val and the original value. Puts the original value from \p Addr in \p
1663 /// OldValRes.
1664 ///
1665 /// \pre setBasicBlock or setMI must have been called.
1666 /// \pre \p OldValRes must be a generic virtual register.
1667 /// \pre \p Addr must be a generic virtual register with pointer type.
1668 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1669 /// same type.
1670 ///
1671 /// \return a MachineInstrBuilder for the newly created instruction.
1672 MachineInstrBuilder buildAtomicRMWMax(Register OldValRes, Register Addr,
1673 Register Val, MachineMemOperand &MMO);
1674
1675 /// Build and insert `OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO`.
1676 ///
1677 /// Atomically replace the value at \p Addr with the signed minimum of \p
1678 /// Val and the original value. Puts the original value from \p Addr in \p
1679 /// OldValRes.
1680 ///
1681 /// \pre setBasicBlock or setMI must have been called.
1682 /// \pre \p OldValRes must be a generic virtual register.
1683 /// \pre \p Addr must be a generic virtual register with pointer type.
1684 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1685 /// same type.
1686 ///
1687 /// \return a MachineInstrBuilder for the newly created instruction.
1688 MachineInstrBuilder buildAtomicRMWMin(Register OldValRes, Register Addr,
1689 Register Val, MachineMemOperand &MMO);
1690
1691 /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO`.
1692 ///
1693 /// Atomically replace the value at \p Addr with the unsigned maximum of \p
1694 /// Val and the original value. Puts the original value from \p Addr in \p
1695 /// OldValRes.
1696 ///
1697 /// \pre setBasicBlock or setMI must have been called.
1698 /// \pre \p OldValRes must be a generic virtual register.
1699 /// \pre \p Addr must be a generic virtual register with pointer type.
1700 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1701 /// same type.
1702 ///
1703 /// \return a MachineInstrBuilder for the newly created instruction.
1704 MachineInstrBuilder buildAtomicRMWUmax(Register OldValRes, Register Addr,
1705 Register Val, MachineMemOperand &MMO);
1706
1707 /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO`.
1708 ///
1709 /// Atomically replace the value at \p Addr with the unsigned minimum of \p
1710 /// Val and the original value. Puts the original value from \p Addr in \p
1711 /// OldValRes.
1712 ///
1713 /// \pre setBasicBlock or setMI must have been called.
1714 /// \pre \p OldValRes must be a generic virtual register.
1715 /// \pre \p Addr must be a generic virtual register with pointer type.
1716 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1717 /// same type.
1718 ///
1719 /// \return a MachineInstrBuilder for the newly created instruction.
1720 MachineInstrBuilder buildAtomicRMWUmin(Register OldValRes, Register Addr,
1721 Register Val, MachineMemOperand &MMO);
1722
1723 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FADD Addr, Val, MMO`.
1724 MachineInstrBuilder buildAtomicRMWFAdd(
1725 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1726 MachineMemOperand &MMO);
1727
1728 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FSUB Addr, Val, MMO`.
1729 MachineInstrBuilder buildAtomicRMWFSub(
1730 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1731 MachineMemOperand &MMO);
1732
1733 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMAX Addr, Val, MMO`.
1734 ///
1735 /// Atomically replace the value at \p Addr with the floating point maximum of
1736 /// \p Val and the original value. Puts the original value from \p Addr in \p
1737 /// OldValRes.
1738 ///
1739 /// \pre setBasicBlock or setMI must have been called.
1740 /// \pre \p OldValRes must be a generic virtual register.
1741 /// \pre \p Addr must be a generic virtual register with pointer type.
1742 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1743 /// same type.
1744 ///
1745 /// \return a MachineInstrBuilder for the newly created instruction.
1746 MachineInstrBuilder buildAtomicRMWFMax(
1747 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1748 MachineMemOperand &MMO);
1749
1750 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMIN Addr, Val, MMO`.
1751 ///
1752 /// Atomically replace the value at \p Addr with the floating point minimum of
1753 /// \p Val and the original value. Puts the original value from \p Addr in \p
1754 /// OldValRes.
1755 ///
1756 /// \pre setBasicBlock or setMI must have been called.
1757 /// \pre \p OldValRes must be a generic virtual register.
1758 /// \pre \p Addr must be a generic virtual register with pointer type.
1759 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1760 /// same type.
1761 ///
1762 /// \return a MachineInstrBuilder for the newly created instruction.
1763 MachineInstrBuilder buildAtomicRMWFMin(
1764 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1765 MachineMemOperand &MMO);
1766
1767 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMAXIMUM Addr, Val, MMO`.
1768 ///
1769 /// Atomically replace the value at \p Addr with the floating point maximum of
1770 /// \p Val and the original value. Puts the original value from \p Addr in \p
1771 /// OldValRes.
1772 ///
1773 /// \pre setBasicBlock or setMI must have been called.
1774 /// \pre \p OldValRes must be a generic virtual register.
1775 /// \pre \p Addr must be a generic virtual register with pointer type.
1776 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1777 /// same type.
1778 ///
1779 /// \return a MachineInstrBuilder for the newly created instruction.
1780 MachineInstrBuilder buildAtomicRMWFMaximum(const DstOp &OldValRes,
1781 const SrcOp &Addr,
1782 const SrcOp &Val,
1783 MachineMemOperand &MMO);
1784
1785 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMINIMUM Addr, Val, MMO`.
1786 ///
1787 /// Atomically replace the value at \p Addr with the floating point minimum of
1788 /// \p Val and the original value. Puts the original value from \p Addr in \p
1789 /// OldValRes.
1790 ///
1791 /// \pre setBasicBlock or setMI must have been called.
1792 /// \pre \p OldValRes must be a generic virtual register.
1793 /// \pre \p Addr must be a generic virtual register with pointer type.
1794 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1795 /// same type.
1796 ///
1797 /// \return a MachineInstrBuilder for the newly created instruction.
1798 MachineInstrBuilder buildAtomicRMWFMinimum(const DstOp &OldValRes,
1799 const SrcOp &Addr,
1800 const SrcOp &Val,
1801 MachineMemOperand &MMO);
1802
1803 /// Build and insert `G_FENCE Ordering, Scope`.
1804 MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope);
1805
1806 /// Build and insert G_PREFETCH \p Addr, \p RW, \p Locality, \p CacheType
1807 MachineInstrBuilder buildPrefetch(const SrcOp &Addr, unsigned RW,
1808 unsigned Locality, unsigned CacheType,
1809 MachineMemOperand &MMO);
1810
1811 /// Build and insert \p Dst = G_FREEZE \p Src
1812 MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src) {
1813 return buildInstr(TargetOpcode::G_FREEZE, {Dst}, {Src});
1814 }
1815
1816 /// Build and insert \p Res = G_BLOCK_ADDR \p BA
1817 ///
1818 /// G_BLOCK_ADDR computes the address of a basic block.
1819 ///
1820 /// \pre setBasicBlock or setMI must have been called.
1821 /// \pre \p Res must be a generic virtual register of a pointer type.
1822 ///
1823 /// \return The newly created instruction.
1824 MachineInstrBuilder buildBlockAddress(Register Res, const BlockAddress *BA);
1825
1826 /// Build and insert \p Res = G_ADD \p Op0, \p Op1
1827 ///
1828 /// G_ADD sets \p Res to the sum of integer parameters \p Op0 and \p Op1,
1829 /// truncated to their width.
1830 ///
1831 /// \pre setBasicBlock or setMI must have been called.
1832 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1833 /// with the same (scalar or vector) type).
1834 ///
1835 /// \return a MachineInstrBuilder for the newly created instruction.
1836
1837 MachineInstrBuilder buildAdd(const DstOp &Dst, const SrcOp &Src0,
1838 const SrcOp &Src1,
1839 std::optional<unsigned> Flags = std::nullopt) {
1840 return buildInstr(TargetOpcode::G_ADD, {Dst}, {Src0, Src1}, Flags);
1841 }
1842
1843 /// Build and insert \p Res = G_SUB \p Op0, \p Op1
1844 ///
1845 /// G_SUB sets \p Res to the difference of integer parameters \p Op0 and
1846 /// \p Op1, truncated to their width.
1847 ///
1848 /// \pre setBasicBlock or setMI must have been called.
1849 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1850 /// with the same (scalar or vector) type).
1851 ///
1852 /// \return a MachineInstrBuilder for the newly created instruction.
1853
1854 MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0,
1855 const SrcOp &Src1,
1856 std::optional<unsigned> Flags = std::nullopt) {
1857 return buildInstr(TargetOpcode::G_SUB, {Dst}, {Src0, Src1}, Flags);
1858 }
1859
1860 /// Build and insert \p Res = G_MUL \p Op0, \p Op1
1861 ///
1862 /// G_MUL sets \p Res to the product of integer parameters \p Op0 and \p Op1,
1863 /// truncated to their width.
1864 ///
1865 /// \pre setBasicBlock or setMI must have been called.
1866 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1867 /// with the same (scalar or vector) type).
1868 ///
1869 /// \return a MachineInstrBuilder for the newly created instruction.
1870 MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0,
1871 const SrcOp &Src1,
1872 std::optional<unsigned> Flags = std::nullopt) {
1873 return buildInstr(TargetOpcode::G_MUL, {Dst}, {Src0, Src1}, Flags);
1874 }
1875
1876 /// Build and insert \p Res = G_ABDS \p Op0, \p Op1
1877 ///
1878 /// G_ABDS return the signed absolute difference of \p Op0 and \p Op1.
1879 ///
1880 /// \pre setBasicBlock or setMI must have been called.
1881 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1882 /// with the same (scalar or vector) type).
1883 ///
1884 /// \return a MachineInstrBuilder for the newly created instruction.
1885 MachineInstrBuilder buildAbds(const DstOp &Dst, const SrcOp &Src0,
1886 const SrcOp &Src1) {
1887 return buildInstr(TargetOpcode::G_ABDS, {Dst}, {Src0, Src1});
1888 }
1889
1890 /// Build and insert \p Res = G_ABDU \p Op0, \p Op1
1891 ///
1892 /// G_ABDU return the unsigned absolute difference of \p Op0 and \p Op1.
1893 ///
1894 /// \pre setBasicBlock or setMI must have been called.
1895 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1896 /// with the same (scalar or vector) type).
1897 ///
1898 /// \return a MachineInstrBuilder for the newly created instruction.
1899 MachineInstrBuilder buildAbdu(const DstOp &Dst, const SrcOp &Src0,
1900 const SrcOp &Src1) {
1901 return buildInstr(TargetOpcode::G_ABDU, {Dst}, {Src0, Src1});
1902 }
1903
1905 const SrcOp &Src1,
1906 std::optional<unsigned> Flags = std::nullopt) {
1907 return buildInstr(TargetOpcode::G_UMULH, {Dst}, {Src0, Src1}, Flags);
1908 }
1909
1911 const SrcOp &Src1,
1912 std::optional<unsigned> Flags = std::nullopt) {
1913 return buildInstr(TargetOpcode::G_SMULH, {Dst}, {Src0, Src1}, Flags);
1914 }
1915
1916 /// Build and insert \p Res = G_UREM \p Op0, \p Op1
1917 MachineInstrBuilder buildURem(const DstOp &Dst, const SrcOp &Src0,
1918 const SrcOp &Src1,
1919 std::optional<unsigned> Flags = std::nullopt) {
1920 return buildInstr(TargetOpcode::G_UREM, {Dst}, {Src0, Src1}, Flags);
1921 }
1922
1923 MachineInstrBuilder buildFMul(const DstOp &Dst, const SrcOp &Src0,
1924 const SrcOp &Src1,
1925 std::optional<unsigned> Flags = std::nullopt) {
1926 return buildInstr(TargetOpcode::G_FMUL, {Dst}, {Src0, Src1}, Flags);
1927 }
1928
1930 buildFMinNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1931 std::optional<unsigned> Flags = std::nullopt) {
1932 return buildInstr(TargetOpcode::G_FMINNUM, {Dst}, {Src0, Src1}, Flags);
1933 }
1934
1936 buildFMaxNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1937 std::optional<unsigned> Flags = std::nullopt) {
1938 return buildInstr(TargetOpcode::G_FMAXNUM, {Dst}, {Src0, Src1}, Flags);
1939 }
1940
1942 buildFMinNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1943 std::optional<unsigned> Flags = std::nullopt) {
1944 return buildInstr(TargetOpcode::G_FMINNUM_IEEE, {Dst}, {Src0, Src1}, Flags);
1945 }
1946
1948 buildFMaxNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1949 std::optional<unsigned> Flags = std::nullopt) {
1950 return buildInstr(TargetOpcode::G_FMAXNUM_IEEE, {Dst}, {Src0, Src1}, Flags);
1951 }
1952
1953 MachineInstrBuilder buildShl(const DstOp &Dst, const SrcOp &Src0,
1954 const SrcOp &Src1,
1955 std::optional<unsigned> Flags = std::nullopt) {
1956 return buildInstr(TargetOpcode::G_SHL, {Dst}, {Src0, Src1}, Flags);
1957 }
1958
1959 MachineInstrBuilder buildLShr(const DstOp &Dst, const SrcOp &Src0,
1960 const SrcOp &Src1,
1961 std::optional<unsigned> Flags = std::nullopt) {
1962 return buildInstr(TargetOpcode::G_LSHR, {Dst}, {Src0, Src1}, Flags);
1963 }
1964
1965 MachineInstrBuilder buildAShr(const DstOp &Dst, const SrcOp &Src0,
1966 const SrcOp &Src1,
1967 std::optional<unsigned> Flags = std::nullopt) {
1968 return buildInstr(TargetOpcode::G_ASHR, {Dst}, {Src0, Src1}, Flags);
1969 }
1970
1971 /// Build and insert \p Res = G_AND \p Op0, \p Op1
1972 ///
1973 /// G_AND sets \p Res to the bitwise and of integer parameters \p Op0 and \p
1974 /// Op1.
1975 ///
1976 /// \pre setBasicBlock or setMI must have been called.
1977 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1978 /// with the same (scalar or vector) type).
1979 ///
1980 /// \return a MachineInstrBuilder for the newly created instruction.
1981
1982 MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0,
1983 const SrcOp &Src1) {
1984 return buildInstr(TargetOpcode::G_AND, {Dst}, {Src0, Src1});
1985 }
1986
1987 /// Build and insert \p Res = G_OR \p Op0, \p Op1
1988 ///
1989 /// G_OR sets \p Res to the bitwise or of integer parameters \p Op0 and \p
1990 /// Op1.
1991 ///
1992 /// \pre setBasicBlock or setMI must have been called.
1993 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1994 /// with the same (scalar or vector) type).
1995 ///
1996 /// \return a MachineInstrBuilder for the newly created instruction.
1997 MachineInstrBuilder buildOr(const DstOp &Dst, const SrcOp &Src0,
1998 const SrcOp &Src1,
1999 std::optional<unsigned> Flags = std::nullopt) {
2000 return buildInstr(TargetOpcode::G_OR, {Dst}, {Src0, Src1}, Flags);
2001 }
2002
2003 /// Build and insert \p Res = G_XOR \p Op0, \p Op1
2004 MachineInstrBuilder buildXor(const DstOp &Dst, const SrcOp &Src0,
2005 const SrcOp &Src1) {
2006 return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, Src1});
2007 }
2008
2009 /// Build and insert a bitwise not,
2010 /// \p NegOne = G_CONSTANT -1
2011 /// \p Res = G_OR \p Op0, NegOne
2012 MachineInstrBuilder buildNot(const DstOp &Dst, const SrcOp &Src0) {
2013 auto NegOne = buildConstant(Dst.getLLTTy(*getMRI()), -1);
2014 return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, NegOne});
2015 }
2016
2017 /// Build and insert integer negation
2018 /// \p Zero = G_CONSTANT 0
2019 /// \p Res = G_SUB Zero, \p Op0
2020 MachineInstrBuilder buildNeg(const DstOp &Dst, const SrcOp &Src0) {
2021 auto Zero = buildConstant(Dst.getLLTTy(*getMRI()), 0);
2022 return buildInstr(TargetOpcode::G_SUB, {Dst}, {Zero, Src0});
2023 }
2024
2025 /// Build and insert \p Res = G_CTPOP \p Op0, \p Src0
2026 MachineInstrBuilder buildCTPOP(const DstOp &Dst, const SrcOp &Src0) {
2027 return buildInstr(TargetOpcode::G_CTPOP, {Dst}, {Src0});
2028 }
2029
2030 /// Build and insert \p Res = G_CTLZ \p Op0, \p Src0
2031 MachineInstrBuilder buildCTLZ(const DstOp &Dst, const SrcOp &Src0) {
2032 return buildInstr(TargetOpcode::G_CTLZ, {Dst}, {Src0});
2033 }
2034
2035 /// Build and insert \p Res = G_CTLZ_ZERO_POISON \p Op0, \p Src0
2037 const SrcOp &Src0) {
2038 return buildInstr(TargetOpcode::G_CTLZ_ZERO_POISON, {Dst}, {Src0});
2039 }
2040
2041 /// Build and insert \p Res = G_CTTZ \p Op0, \p Src0
2042 MachineInstrBuilder buildCTTZ(const DstOp &Dst, const SrcOp &Src0) {
2043 return buildInstr(TargetOpcode::G_CTTZ, {Dst}, {Src0});
2044 }
2045
2046 /// Build and insert \p Res = G_CTTZ_ZERO_POISON \p Op0, \p Src0
2048 const SrcOp &Src0) {
2049 return buildInstr(TargetOpcode::G_CTTZ_ZERO_POISON, {Dst}, {Src0});
2050 }
2051
2052 /// Build and insert \p Res = G_CTLS \p Op0, \p Src0
2053 MachineInstrBuilder buildCTLS(const DstOp &Dst, const SrcOp &Src0) {
2054 return buildInstr(TargetOpcode::G_CTLS, {Dst}, {Src0});
2055 }
2056
2057 /// Build and insert \p Dst = G_BSWAP \p Src0
2058 MachineInstrBuilder buildBSwap(const DstOp &Dst, const SrcOp &Src0) {
2059 return buildInstr(TargetOpcode::G_BSWAP, {Dst}, {Src0});
2060 }
2061
2062 /// Build and insert \p Res = G_FADD \p Op0, \p Op1
2063 MachineInstrBuilder buildFAdd(const DstOp &Dst, const SrcOp &Src0,
2064 const SrcOp &Src1,
2065 std::optional<unsigned> Flags = std::nullopt) {
2066 return buildInstr(TargetOpcode::G_FADD, {Dst}, {Src0, Src1}, Flags);
2067 }
2068
2069 /// Build and insert \p Res = G_STRICT_FADD \p Op0, \p Op1
2071 buildStrictFAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
2072 std::optional<unsigned> Flags = std::nullopt) {
2073 return buildInstr(TargetOpcode::G_STRICT_FADD, {Dst}, {Src0, Src1}, Flags);
2074 }
2075
2076 /// Build and insert \p Res = G_FSUB \p Op0, \p Op1
2077 MachineInstrBuilder buildFSub(const DstOp &Dst, const SrcOp &Src0,
2078 const SrcOp &Src1,
2079 std::optional<unsigned> Flags = std::nullopt) {
2080 return buildInstr(TargetOpcode::G_FSUB, {Dst}, {Src0, Src1}, Flags);
2081 }
2082
2083 /// Build and insert \p Res = G_FDIV \p Op0, \p Op1
2084 MachineInstrBuilder buildFDiv(const DstOp &Dst, const SrcOp &Src0,
2085 const SrcOp &Src1,
2086 std::optional<unsigned> Flags = std::nullopt) {
2087 return buildInstr(TargetOpcode::G_FDIV, {Dst}, {Src0, Src1}, Flags);
2088 }
2089
2090 /// Build and insert \p Res = G_FMA \p Op0, \p Op1, \p Op2
2091 MachineInstrBuilder buildFMA(const DstOp &Dst, const SrcOp &Src0,
2092 const SrcOp &Src1, const SrcOp &Src2,
2093 std::optional<unsigned> Flags = std::nullopt) {
2094 return buildInstr(TargetOpcode::G_FMA, {Dst}, {Src0, Src1, Src2}, Flags);
2095 }
2096
2097 /// Build and insert \p Res = G_FMAD \p Op0, \p Op1, \p Op2
2098 MachineInstrBuilder buildFMAD(const DstOp &Dst, const SrcOp &Src0,
2099 const SrcOp &Src1, const SrcOp &Src2,
2100 std::optional<unsigned> Flags = std::nullopt) {
2101 return buildInstr(TargetOpcode::G_FMAD, {Dst}, {Src0, Src1, Src2}, Flags);
2102 }
2103
2104 /// Build and insert \p Res = G_FNEG \p Op0
2105 MachineInstrBuilder buildFNeg(const DstOp &Dst, const SrcOp &Src0,
2106 std::optional<unsigned> Flags = std::nullopt) {
2107 return buildInstr(TargetOpcode::G_FNEG, {Dst}, {Src0}, Flags);
2108 }
2109
2110 /// Build and insert \p Res = G_FABS \p Op0
2111 MachineInstrBuilder buildFAbs(const DstOp &Dst, const SrcOp &Src0,
2112 std::optional<unsigned> Flags = std::nullopt) {
2113 return buildInstr(TargetOpcode::G_FABS, {Dst}, {Src0}, Flags);
2114 }
2115
2116 /// Build and insert \p Dst = G_FCANONICALIZE \p Src0
2118 buildFCanonicalize(const DstOp &Dst, const SrcOp &Src0,
2119 std::optional<unsigned> Flags = std::nullopt) {
2120 return buildInstr(TargetOpcode::G_FCANONICALIZE, {Dst}, {Src0}, Flags);
2121 }
2122
2123 /// Build and insert \p Dst = G_INTRINSIC_TRUNC \p Src0
2125 buildIntrinsicTrunc(const DstOp &Dst, const SrcOp &Src0,
2126 std::optional<unsigned> Flags = std::nullopt) {
2127 return buildInstr(TargetOpcode::G_INTRINSIC_TRUNC, {Dst}, {Src0}, Flags);
2128 }
2129
2130 /// Build and insert \p Res = GFFLOOR \p Op0, \p Op1
2132 buildFFloor(const DstOp &Dst, const SrcOp &Src0,
2133 std::optional<unsigned> Flags = std::nullopt) {
2134 return buildInstr(TargetOpcode::G_FFLOOR, {Dst}, {Src0}, Flags);
2135 }
2136
2137 /// Build and insert \p Dst = G_FLOG \p Src
2139 std::optional<unsigned> Flags = std::nullopt) {
2140 return buildInstr(TargetOpcode::G_FLOG, {Dst}, {Src}, Flags);
2141 }
2142
2143 /// Build and insert \p Dst = G_FLOG2 \p Src
2145 std::optional<unsigned> Flags = std::nullopt) {
2146 return buildInstr(TargetOpcode::G_FLOG2, {Dst}, {Src}, Flags);
2147 }
2148
2149 /// Build and insert \p Dst = G_FEXP2 \p Src
2151 std::optional<unsigned> Flags = std::nullopt) {
2152 return buildInstr(TargetOpcode::G_FEXP2, {Dst}, {Src}, Flags);
2153 }
2154
2155 /// Build and insert \p Dst = G_FPOW \p Src0, \p Src1
2156 MachineInstrBuilder buildFPow(const DstOp &Dst, const SrcOp &Src0,
2157 const SrcOp &Src1,
2158 std::optional<unsigned> Flags = std::nullopt) {
2159 return buildInstr(TargetOpcode::G_FPOW, {Dst}, {Src0, Src1}, Flags);
2160 }
2161
2162 /// Build and insert \p Dst = G_FLDEXP \p Src0, \p Src1
2164 buildFLdexp(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
2165 std::optional<unsigned> Flags = std::nullopt) {
2166 return buildInstr(TargetOpcode::G_FLDEXP, {Dst}, {Src0, Src1}, Flags);
2167 }
2168
2169 /// Build and insert \p Fract, \p Exp = G_FFREXP \p Src
2171 buildFFrexp(const DstOp &Fract, const DstOp &Exp, const SrcOp &Src,
2172 std::optional<unsigned> Flags = std::nullopt) {
2173 return buildInstr(TargetOpcode::G_FFREXP, {Fract, Exp}, {Src}, Flags);
2174 }
2175
2176 /// Build and insert \p Sin, \p Cos = G_FSINCOS \p Src
2178 buildFSincos(const DstOp &Sin, const DstOp &Cos, const SrcOp &Src,
2179 std::optional<unsigned> Flags = std::nullopt) {
2180 return buildInstr(TargetOpcode::G_FSINCOS, {Sin, Cos}, {Src}, Flags);
2181 }
2182
2183 /// Build and insert \p Fract, \p Int = G_FMODF \p Src
2185 const SrcOp &Src,
2186 std::optional<unsigned> Flags = std::nullopt) {
2187 return buildInstr(TargetOpcode::G_FMODF, {Fract, Int}, {Src}, Flags);
2188 }
2189
2190 /// Build and insert \p Res = G_FCOPYSIGN \p Op0, \p Op1
2192 buildFCopysign(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
2193 std::optional<unsigned> Flags = std::nullopt) {
2194 return buildInstr(TargetOpcode::G_FCOPYSIGN, {Dst}, {Src0, Src1}, Flags);
2195 }
2196
2197 /// Build and insert \p Res = G_UITOFP \p Src0
2198 MachineInstrBuilder buildUITOFP(const DstOp &Dst, const SrcOp &Src0) {
2199 return buildInstr(TargetOpcode::G_UITOFP, {Dst}, {Src0});
2200 }
2201
2202 /// Build and insert \p Res = G_SITOFP \p Src0
2203 MachineInstrBuilder buildSITOFP(const DstOp &Dst, const SrcOp &Src0) {
2204 return buildInstr(TargetOpcode::G_SITOFP, {Dst}, {Src0});
2205 }
2206
2207 /// Build and insert \p Res = G_FPTOUI \p Src0
2208 MachineInstrBuilder buildFPTOUI(const DstOp &Dst, const SrcOp &Src0) {
2209 return buildInstr(TargetOpcode::G_FPTOUI, {Dst}, {Src0});
2210 }
2211
2212 /// Build and insert \p Res = G_FPTOSI \p Src0
2213 MachineInstrBuilder buildFPTOSI(const DstOp &Dst, const SrcOp &Src0) {
2214 return buildInstr(TargetOpcode::G_FPTOSI, {Dst}, {Src0});
2215 }
2216
2217 /// Build and insert \p Res = G_FPTOUI_SAT \p Src0
2219 return buildInstr(TargetOpcode::G_FPTOUI_SAT, {Dst}, {Src0});
2220 }
2221
2222 /// Build and insert \p Res = G_FPTOSI_SAT \p Src0
2224 return buildInstr(TargetOpcode::G_FPTOSI_SAT, {Dst}, {Src0});
2225 }
2226
2227 /// Build and insert \p Dst = G_FRINT \p Src0
2229 std::optional<unsigned> Flags = std::nullopt) {
2230 return buildInstr(TargetOpcode::G_FRINT, {Dst}, {Src0}, Flags);
2231 }
2232
2233 /// Build and insert \p Dst = G_INTRINSIC_ROUNDEVEN \p Src0, \p Src1
2235 buildIntrinsicRoundeven(const DstOp &Dst, const SrcOp &Src0,
2236 std::optional<unsigned> Flags = std::nullopt) {
2237 return buildInstr(TargetOpcode::G_INTRINSIC_ROUNDEVEN, {Dst}, {Src0},
2238 Flags);
2239 }
2240
2241 /// Build and insert \p Res = G_SMIN \p Op0, \p Op1
2242 MachineInstrBuilder buildSMin(const DstOp &Dst, const SrcOp &Src0,
2243 const SrcOp &Src1) {
2244 return buildInstr(TargetOpcode::G_SMIN, {Dst}, {Src0, Src1});
2245 }
2246
2247 /// Build and insert \p Res = G_SMAX \p Op0, \p Op1
2248 MachineInstrBuilder buildSMax(const DstOp &Dst, const SrcOp &Src0,
2249 const SrcOp &Src1) {
2250 return buildInstr(TargetOpcode::G_SMAX, {Dst}, {Src0, Src1});
2251 }
2252
2253 /// Build and insert \p Res = G_UMIN \p Op0, \p Op1
2254 MachineInstrBuilder buildUMin(const DstOp &Dst, const SrcOp &Src0,
2255 const SrcOp &Src1) {
2256 return buildInstr(TargetOpcode::G_UMIN, {Dst}, {Src0, Src1});
2257 }
2258
2259 /// Build and insert \p Res = G_UMAX \p Op0, \p Op1
2260 MachineInstrBuilder buildUMax(const DstOp &Dst, const SrcOp &Src0,
2261 const SrcOp &Src1) {
2262 return buildInstr(TargetOpcode::G_UMAX, {Dst}, {Src0, Src1});
2263 }
2264
2265 /// Build and insert \p Dst = G_ABS \p Src
2266 MachineInstrBuilder buildAbs(const DstOp &Dst, const SrcOp &Src) {
2267 return buildInstr(TargetOpcode::G_ABS, {Dst}, {Src});
2268 }
2269
2270 /// Build and insert \p Res = G_JUMP_TABLE \p JTI
2271 ///
2272 /// G_JUMP_TABLE sets \p Res to the address of the jump table specified by
2273 /// the jump table index \p JTI.
2274 ///
2275 /// \return a MachineInstrBuilder for the newly created instruction.
2276 MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI);
2277
2278 /// Build and insert \p Res = G_VECREDUCE_SEQ_FADD \p ScalarIn, \p VecIn
2279 ///
2280 /// \p ScalarIn is the scalar accumulator input to start the sequential
2281 /// reduction operation of \p VecIn.
2283 const SrcOp &ScalarIn,
2284 const SrcOp &VecIn) {
2285 return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FADD, {Dst},
2286 {ScalarIn, {VecIn}});
2287 }
2288
2289 /// Build and insert \p Res = G_VECREDUCE_SEQ_FMUL \p ScalarIn, \p VecIn
2290 ///
2291 /// \p ScalarIn is the scalar accumulator input to start the sequential
2292 /// reduction operation of \p VecIn.
2294 const SrcOp &ScalarIn,
2295 const SrcOp &VecIn) {
2296 return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FMUL, {Dst},
2297 {ScalarIn, {VecIn}});
2298 }
2299
2300 /// Build and insert \p Res = G_VECREDUCE_FADD \p Src
2301 ///
2302 /// \p ScalarIn is the scalar accumulator input to the reduction operation of
2303 /// \p VecIn.
2305 const SrcOp &ScalarIn,
2306 const SrcOp &VecIn) {
2307 return buildInstr(TargetOpcode::G_VECREDUCE_FADD, {Dst}, {ScalarIn, VecIn});
2308 }
2309
2310 /// Build and insert \p Res = G_VECREDUCE_FMUL \p Src
2311 ///
2312 /// \p ScalarIn is the scalar accumulator input to the reduction operation of
2313 /// \p VecIn.
2315 const SrcOp &ScalarIn,
2316 const SrcOp &VecIn) {
2317 return buildInstr(TargetOpcode::G_VECREDUCE_FMUL, {Dst}, {ScalarIn, VecIn});
2318 }
2319
2320 /// Build and insert \p Res = G_VECREDUCE_FMAX \p Src
2322 return buildInstr(TargetOpcode::G_VECREDUCE_FMAX, {Dst}, {Src});
2323 }
2324
2325 /// Build and insert \p Res = G_VECREDUCE_FMIN \p Src
2327 return buildInstr(TargetOpcode::G_VECREDUCE_FMIN, {Dst}, {Src});
2328 }
2329
2330 /// Build and insert \p Res = G_VECREDUCE_FMAXIMUM \p Src
2332 const SrcOp &Src) {
2333 return buildInstr(TargetOpcode::G_VECREDUCE_FMAXIMUM, {Dst}, {Src});
2334 }
2335
2336 /// Build and insert \p Res = G_VECREDUCE_FMINIMUM \p Src
2338 const SrcOp &Src) {
2339 return buildInstr(TargetOpcode::G_VECREDUCE_FMINIMUM, {Dst}, {Src});
2340 }
2341
2342 /// Build and insert \p Res = G_VECREDUCE_ADD \p Src
2344 return buildInstr(TargetOpcode::G_VECREDUCE_ADD, {Dst}, {Src});
2345 }
2346
2347 /// Build and insert \p Res = G_VECREDUCE_MUL \p Src
2349 return buildInstr(TargetOpcode::G_VECREDUCE_MUL, {Dst}, {Src});
2350 }
2351
2352 /// Build and insert \p Res = G_VECREDUCE_AND \p Src
2354 return buildInstr(TargetOpcode::G_VECREDUCE_AND, {Dst}, {Src});
2355 }
2356
2357 /// Build and insert \p Res = G_VECREDUCE_OR \p Src
2359 return buildInstr(TargetOpcode::G_VECREDUCE_OR, {Dst}, {Src});
2360 }
2361
2362 /// Build and insert \p Res = G_VECREDUCE_XOR \p Src
2364 return buildInstr(TargetOpcode::G_VECREDUCE_XOR, {Dst}, {Src});
2365 }
2366
2367 /// Build and insert \p Res = G_VECREDUCE_SMAX \p Src
2369 return buildInstr(TargetOpcode::G_VECREDUCE_SMAX, {Dst}, {Src});
2370 }
2371
2372 /// Build and insert \p Res = G_VECREDUCE_SMIN \p Src
2374 return buildInstr(TargetOpcode::G_VECREDUCE_SMIN, {Dst}, {Src});
2375 }
2376
2377 /// Build and insert \p Res = G_VECREDUCE_UMAX \p Src
2379 return buildInstr(TargetOpcode::G_VECREDUCE_UMAX, {Dst}, {Src});
2380 }
2381
2382 /// Build and insert \p Res = G_VECREDUCE_UMIN \p Src
2384 return buildInstr(TargetOpcode::G_VECREDUCE_UMIN, {Dst}, {Src});
2385 }
2386
2387 /// Build and insert G_MEMCPY or G_MEMMOVE
2388 MachineInstrBuilder buildMemTransferInst(unsigned Opcode, const SrcOp &DstPtr,
2389 const SrcOp &SrcPtr,
2390 const SrcOp &Size,
2391 MachineMemOperand &DstMMO,
2392 MachineMemOperand &SrcMMO) {
2393 auto MIB = buildInstr(
2394 Opcode, {}, {DstPtr, SrcPtr, Size, SrcOp(INT64_C(0) /*isTailCall*/)});
2395 MIB.addMemOperand(&DstMMO);
2396 MIB.addMemOperand(&SrcMMO);
2397 return MIB;
2398 }
2399
2400 MachineInstrBuilder buildMemCpy(const SrcOp &DstPtr, const SrcOp &SrcPtr,
2401 const SrcOp &Size, MachineMemOperand &DstMMO,
2402 MachineMemOperand &SrcMMO) {
2403 return buildMemTransferInst(TargetOpcode::G_MEMCPY, DstPtr, SrcPtr, Size,
2404 DstMMO, SrcMMO);
2405 }
2406
2407 /// Build and insert G_TRAP or G_DEBUGTRAP
2409 return buildInstr(Debug ? TargetOpcode::G_DEBUGTRAP : TargetOpcode::G_TRAP);
2410 }
2411
2412 /// Build and insert \p Dst = G_SBFX \p Src, \p LSB, \p Width.
2414 const SrcOp &LSB, const SrcOp &Width) {
2415 return buildInstr(TargetOpcode::G_SBFX, {Dst}, {Src, LSB, Width});
2416 }
2417
2418 /// Build and insert \p Dst = G_UBFX \p Src, \p LSB, \p Width.
2420 const SrcOp &LSB, const SrcOp &Width) {
2421 return buildInstr(TargetOpcode::G_UBFX, {Dst}, {Src, LSB, Width});
2422 }
2423
2424 /// Build and insert \p Dst = G_ROTR \p Src, \p Amt
2426 const SrcOp &Amt) {
2427 return buildInstr(TargetOpcode::G_ROTR, {Dst}, {Src, Amt});
2428 }
2429
2430 /// Build and insert \p Dst = G_ROTL \p Src, \p Amt
2432 const SrcOp &Amt) {
2433 return buildInstr(TargetOpcode::G_ROTL, {Dst}, {Src, Amt});
2434 }
2435
2436 /// Build and insert \p Dst = G_BITREVERSE \p Src
2438 return buildInstr(TargetOpcode::G_BITREVERSE, {Dst}, {Src});
2439 }
2440
2441 /// Build and insert \p Dst = G_GET_FPENV
2443 return buildInstr(TargetOpcode::G_GET_FPENV, {Dst}, {});
2444 }
2445
2446 /// Build and insert G_SET_FPENV \p Src
2448 return buildInstr(TargetOpcode::G_SET_FPENV, {}, {Src});
2449 }
2450
2451 /// Build and insert G_RESET_FPENV
2453 return buildInstr(TargetOpcode::G_RESET_FPENV, {}, {});
2454 }
2455
2456 /// Build and insert \p Dst = G_GET_FPMODE
2458 return buildInstr(TargetOpcode::G_GET_FPMODE, {Dst}, {});
2459 }
2460
2461 /// Build and insert G_SET_FPMODE \p Src
2463 return buildInstr(TargetOpcode::G_SET_FPMODE, {}, {Src});
2464 }
2465
2466 /// Build and insert G_RESET_FPMODE
2468 return buildInstr(TargetOpcode::G_RESET_FPMODE, {}, {});
2469 }
2470
2471 /// Build and insert \p Dst = G_GET_ROUNDING
2473 return buildInstr(TargetOpcode::G_GET_ROUNDING, {Dst}, {});
2474 }
2475
2476 /// Build and insert G_SET_ROUNDING
2478 return buildInstr(TargetOpcode::G_SET_ROUNDING, {}, {Src});
2479 }
2480
2481 virtual MachineInstrBuilder
2482 buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps, ArrayRef<SrcOp> SrcOps,
2483 std::optional<unsigned> Flags = std::nullopt);
2484};
2485
2486} // End namespace llvm.
2487#endif // LLVM_CODEGEN_GLOBALISEL_MACHINEIRBUILDER_H
const TargetLowering & TLI
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
This contains common code to allow clients to notify changes to machine instr.
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Register Reg
#define T
uint64_t IntrinsicInst * II
#define P(N)
MachineRegisterInfo & MRI
This file describes how to lower LLVM code to machine code.
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
The address of a basic block.
Definition Constants.h:1088
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A signed pointer, in the ptrauth sense.
Definition Constants.h:1223
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A debug info location.
Definition DebugLoc.h:126
DstOp(const LLT T)
DstOp(unsigned R)
DstOp(Register R)
void addDefToMIB(MachineRegisterInfo &MRI, MachineInstrBuilder &MIB) const
LLT getLLTTy(const MachineRegisterInfo &MRI) const
MachineRegisterInfo::VRegAttrs Attrs
DstOp(MachineRegisterInfo::VRegAttrs Attrs)
DstOp(const MachineOperand &Op)
MachineRegisterInfo::VRegAttrs getVRegAttrs() const
DstType getDstOpKind() const
const TargetRegisterClass * RC
const TargetRegisterClass * getRegClass() const
DstOp(const TargetRegisterClass *TRC)
DstOp(RegClassOrRegBank RCOrRB, LLT Ty)
Register getReg() const
The CSE Analysis object.
Definition CSEInfo.h:72
Abstract class that contains various methods for clients to notify about changes.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
MCRegisterClass - Base class of TargetRegisterClass.
Metadata node.
Definition Metadata.h:1081
MachineInstrBundleIterator< MachineInstr > iterator
MachineInstrBuilder buildFPTOUI_SAT(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_FPTOUI_SAT Src0.
MachineInstrBuilder buildFSub(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FSUB Op0, Op1.
MachineInstrBuilder buildFPTOSI(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_FPTOSI Src0.
GISelChangeObserver * getObserver()
MachineInstrBuilder buildFMul(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
MachineInstrBuilder buildFLdexp(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FLDEXP Src0, Src1.
MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_FREEZE Src.
MachineInstrBuilder buildTruncUSatU(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC_USAT_U Op.
MachineInstrBuilder buildModf(const DstOp &Fract, const DstOp &Int, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Fract, Int = G_FMODF Src.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
const MachineFunction & getMF() const
LLVMContext & getContext() const
MachineInstrBuilder buildAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_ADD Op0, Op1.
MachineInstrBuilder buildResetFPMode()
Build and insert G_RESET_FPMODE.
MachineInstrBuilder buildFPExt(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FPEXT Op.
MachineInstrBuilder buildNot(const DstOp &Dst, const SrcOp &Src0)
Build and insert a bitwise not, NegOne = G_CONSTANT -1 Res = G_OR Op0, NegOne.
MachineInstrBuilder buildFPTOSI_SAT(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_FPTOSI_SAT Src0.
MachineInstrBuilder buildVecReduceSeqFAdd(const DstOp &Dst, const SrcOp &ScalarIn, const SrcOp &VecIn)
Build and insert Res = G_VECREDUCE_SEQ_FADD ScalarIn, VecIn.
MachineInstrBuilder buildRotateRight(const DstOp &Dst, const SrcOp &Src, const SrcOp &Amt)
Build and insert Dst = G_ROTR Src, Amt.
MachineInstrBuilder buildCTTZ(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_CTTZ Op0, Src0.
virtual ~MachineIRBuilder()=default
MachineInstrBuilder buildVecReduceOr(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_OR Src.
MachineInstrBuilder buildFLog2(const DstOp &Dst, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FLOG2 Src.
MachineInstrBuilder buildAShr(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildGetRounding(const DstOp &Dst)
Build and insert Dst = G_GET_ROUNDING.
MachineInstrBuilder buildFAbs(const DstOp &Dst, const SrcOp &Src0, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FABS Op0.
MachineInstrBuilder buildFMinNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildFMA(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, const SrcOp &Src2, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FMA Op0, Op1, Op2.
MachineInstrBuilder buildGetFPMode(const DstOp &Dst)
Build and insert Dst = G_GET_FPMODE.
MachineInstrBuilder buildSMulH(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
GISelCSEInfo * getCSEInfo()
MachineInstrBuilder buildVecReduceFMax(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_FMAX Src.
MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_MUL Op0, Op1.
MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_AND Op0, Op1.
const TargetInstrInfo & getTII()
MachineInstrBuilder buildSAdde(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1, const SrcOp &CarryIn)
Build and insert Res, CarryOut = G_SADDE Op0, Op1, CarryInp.
MachineInstrBuilder buildTruncSSatU(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC_SSAT_U Op.
MachineInstrBuilder buildURem(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_UREM Op0, Op1.
MachineInstrBuilder buildSAddo(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res, CarryOut = G_SADDO Op0, Op1.
MachineInstrBuilder buildFPTOUI(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_FPTOUI Src0.
MachineInstrBuilder buildLShr(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildFPow(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FPOW Src0, Src1.
MachineInstrBuilder buildIntrinsicTrunc(const DstOp &Dst, const SrcOp &Src0, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_INTRINSIC_TRUNC Src0.
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
MachineInstrBuilder buildVecReduceSeqFMul(const DstOp &Dst, const SrcOp &ScalarIn, const SrcOp &VecIn)
Build and insert Res = G_VECREDUCE_SEQ_FMUL ScalarIn, VecIn.
MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_SUB Op0, Op1.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
MDNode * getPCSections()
Get the current instruction's PC sections metadata.
MachineInstrBuilder buildBSwap(const DstOp &Dst, const SrcOp &Src0)
Build and insert Dst = G_BSWAP Src0.
MachineInstrBuilder buildVecReduceFMul(const DstOp &Dst, const SrcOp &ScalarIn, const SrcOp &VecIn)
Build and insert Res = G_VECREDUCE_FMUL Src.
MachineInstrBuilder buildCTLZ_ZERO_POISON(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_CTLZ_ZERO_POISON Op0, Src0.
MachineInstrBuilder buildAddrSpaceCast(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_ADDRSPACE_CAST Src.
MachineInstrBuilder buildFExp2(const DstOp &Dst, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FEXP2 Src.
MachineInstrBuilder buildSetFPMode(const SrcOp &Src)
Build and insert G_SET_FPMODE Src.
MachineInstrBuilder buildIntToPtr(const DstOp &Dst, const SrcOp &Src)
Build and insert a G_INTTOPTR instruction.
MachineInstrBuilder buildUSubo(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res, CarryOut = G_USUBO Op0, Op1.
MachineInstrBuilder buildVecReduceFAdd(const DstOp &Dst, const SrcOp &ScalarIn, const SrcOp &VecIn)
Build and insert Res = G_VECREDUCE_FADD Src.
MachineIRBuilder(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsPt)
MachineInstrBuilder buildAbdu(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_ABDU Op0, Op1.
MachineInstrBuilder buildVecReduceFMinimum(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_FMINIMUM Src.
MachineInstrBuilder buildNeg(const DstOp &Dst, const SrcOp &Src0)
Build and insert integer negation Zero = G_CONSTANT 0 Res = G_SUB Zero, Op0.
MachineInstrBuilder buildVecReduceSMin(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_SMIN Src.
MachineInstrBuilder buildCTLZ(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_CTLZ Op0, Src0.
MachineInstrBuilder buildSMax(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_SMAX Op0, Op1.
MachineInstrBuilder buildAssertZExt(const DstOp &Res, const SrcOp &Op, unsigned Size)
Build and insert Res = G_ASSERT_ZEXT Op, Size.
void recordInsertion(MachineInstr *InsertedInstr) const
MachineInstrBuilder buildUMulH(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildStrictFAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_STRICT_FADD Op0, Op1.
MachineInstrBuilder buildVecReduceXor(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_XOR Src.
MachineInstrBuilder buildVecReduceFMin(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_FMIN Src.
MachineInstrBuilder buildFDiv(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FDIV Op0, Op1.
const GISelCSEInfo * getCSEInfo() const
MachineInstrBuilder buildSetRounding(const SrcOp &Src)
Build and insert G_SET_ROUNDING.
MachineInstrBuilder buildExtractVectorElement(const DstOp &Res, const SrcOp &Val, const SrcOp &Idx)
Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx.
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineBasicBlock & getMBB()
MachineIRBuilder(MachineInstr &MI)
MachineInstrBuilder buildExtractVectorElementConstant(const DstOp &Res, const SrcOp &Val, const int Idx)
Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx.
MachineInstrBuilder buildBitReverse(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_BITREVERSE Src.
MachineInstrBuilder buildShl(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildUITOFP(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_UITOFP Src0.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineInstrBuilder buildSITOFP(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_SITOFP Src0.
MachineIRBuilder(MachineInstr &MI, GISelChangeObserver &Observer)
MachineInstrBuilder buildFMAD(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, const SrcOp &Src2, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FMAD Op0, Op1, Op2.
MachineInstrBuilder buildAbds(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_ABDS Op0, Op1.
MachineInstrBuilder buildFLog(const DstOp &Dst, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FLOG Src.
void validateSelectOp(const LLT ResTy, const LLT TstTy, const LLT Op0Ty, const LLT Op1Ty)
MachineInstrBuilder buildVecReduceUMax(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_UMAX Src.
const DebugLoc & getDL()
Getter for DebugLoc.
MachineInstrBuilder buildUbfx(const DstOp &Dst, const SrcOp &Src, const SrcOp &LSB, const SrcOp &Width)
Build and insert Dst = G_UBFX Src, LSB, Width.
const MachineRegisterInfo * getMRI() const
MachineInstrBuilder buildCTLS(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_CTLS Op0, Src0.
MachineInstrBuilder buildCTPOP(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_CTPOP Op0, Src0.
MachineInstrBuilder buildAbs(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_ABS Src.
void validateBinaryOp(const LLT Res, const LLT Op0, const LLT Op1)
MachineInstrBuilder buildVecReduceAnd(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_AND Src.
MachineInstrBuilder buildVecReduceFMaximum(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_FMAXIMUM Src.
void validateShiftOp(const LLT Res, const LLT Op0, const LLT Op1)
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildFCopysign(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FCOPYSIGN Op0, Op1.
MachineIRBuilder(MachineFunction &MF)
MachineIRBuilder(const MachineIRBuilderState &BState)
MachineInstrBuilder buildTruncSSatS(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC_SSAT_S Op.
MachineInstrBuilder buildMemCpy(const SrcOp &DstPtr, const SrcOp &SrcPtr, const SrcOp &Size, MachineMemOperand &DstMMO, MachineMemOperand &SrcMMO)
MachineInstrBuilder buildAssertAlign(const DstOp &Res, const SrcOp &Op, Align AlignVal)
Build and insert Res = G_ASSERT_ALIGN Op, AlignVal.
MachineInstrBuilder buildFRint(const DstOp &Dst, const SrcOp &Src0, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FRINT Src0.
MachineInstrBuilder buildSbfx(const DstOp &Dst, const SrcOp &Src, const SrcOp &LSB, const SrcOp &Width)
Build and insert Dst = G_SBFX Src, LSB, Width.
MachineInstrBuilder buildFMaxNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildSMin(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_SMIN Op0, Op1.
MachineInstrBuilder buildFMinNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildVecReduceUMin(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_UMIN Src.
void setInstrAndDebugLoc(MachineInstr &MI)
Set the insertion point to before MI, and set the debug loc to MI's loc.
void setMMRAMetadata(MDNode *MMRA)
Set the PC sections metadata to MD for all the next build instructions.
MachineInstrBuilder buildSSube(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1, const SrcOp &CarryIn)
Build and insert Res, CarryOut = G_SSUBE Op0, Op1, CarryInp.
void setDeactivationSymbol(Value *DS)
MachineInstrBuilder buildIntrinsicRoundeven(const DstOp &Dst, const SrcOp &Src0, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_INTRINSIC_ROUNDEVEN Src0, Src1.
MachineInstrBuilder buildResetFPEnv()
Build and insert G_RESET_FPENV.
void setPCSections(MDNode *MD)
Set the PC sections metadata to MD for all the next build instructions.
MachineInstrBuilder buildVecReduceAdd(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_ADD Src.
MachineInstrBuilder buildIsFPClass(const DstOp &Res, const SrcOp &Src, unsigned Mask)
Build and insert a Res = G_IS_FPCLASS Src, Mask.
MachineInstrBuilder buildUAdde(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1, const SrcOp &CarryIn)
Build and insert Res, CarryOut = G_UADDE Op0, Op1, CarryIn.
void setDebugLoc(const DebugLoc &DL)
Set the debug location to DL for all the next build instructions.
MachineInstrBuilder buildGetFPEnv(const DstOp &Dst)
Build and insert Dst = G_GET_FPENV.
MachineInstrBuilder buildSSubo(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res, CarryOut = G_SUBO Op0, Op1.
MachineInstrBuilder buildUSube(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1, const SrcOp &CarryIn)
Build and insert Res, CarryOut = G_USUBE Op0, Op1, CarryInp.
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
MachineInstrBuilder buildFNeg(const DstOp &Dst, const SrcOp &Src0, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FNEG Op0.
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MachineInstrBuilder buildBitcast(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_BITCAST Src.
const DebugLoc & getDebugLoc()
Get the current instruction's debug location.
MachineInstrBuilder buildUAddo(const DstOp &Res, const DstOp &CarryOut, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res, CarryOut = G_UADDO Op0, Op1.
void setCSEInfo(GISelCSEInfo *Info)
MachineInstrBuilder buildFMaxNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildTrap(bool Debug=false)
Build and insert G_TRAP or G_DEBUGTRAP.
MachineInstrBuilder buildFFloor(const DstOp &Dst, const SrcOp &Src0, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = GFFLOOR Op0, Op1.
MachineInstrBuilder buildFFrexp(const DstOp &Fract, const DstOp &Exp, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Fract, Exp = G_FFREXP Src.
MachineIRBuilder()=default
Some constructors for easy use.
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildOr(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_OR Op0, Op1.
MachineInstrBuilder buildFSincos(const DstOp &Sin, const DstOp &Cos, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Sin, Cos = G_FSINCOS Src.
MachineIRBuilderState & getState()
Getter for the State.
MachineInstrBuilder buildAssertInstr(unsigned Opc, const DstOp &Res, const SrcOp &Op, unsigned Val)
Build and insert G_ASSERT_SEXT, G_ASSERT_ZEXT, or G_ASSERT_ALIGN.
void validateTruncExt(const LLT Dst, const LLT Src, bool IsExtend)
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineInstrBuilder buildPtrMask(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res = G_PTRMASK Op0, Op1.
MachineInstrBuilder buildVecReduceSMax(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_SMAX Src.
MachineInstrBuilder buildMemTransferInst(unsigned Opcode, const SrcOp &DstPtr, const SrcOp &SrcPtr, const SrcOp &Size, MachineMemOperand &DstMMO, MachineMemOperand &SrcMMO)
Build and insert G_MEMCPY or G_MEMMOVE.
void validateUnaryOp(const LLT Res, const LLT Op0)
MDNode * getMMRAMetadata()
Get the current instruction's MMRA metadata.
const DataLayout & getDataLayout() const
MachineInstrBuilder buildLoadInstr(unsigned Opcode, const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = <opcode> Addr, MMO.
MachineInstrBuilder buildCTTZ_ZERO_POISON(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_CTTZ_ZERO_POISON Op0, Src0.
void setMF(MachineFunction &MF)
MachineInstrBuilder buildAssertSExt(const DstOp &Res, const SrcOp &Op, unsigned Size)
Build and insert Res = G_ASSERT_SEXT Op, Size.
MachineInstrBuilder buildXor(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_XOR Op0, Op1.
void setState(const MachineIRBuilderState &NewState)
Setter for the State.
void setChangeObserver(GISelChangeObserver &Observer)
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
MachineInstrBuilder buildVecReduceMul(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_MUL Src.
MachineInstrBuilder buildUMin(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_UMIN Op0, Op1.
MachineInstrBuilder buildUMax(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_UMAX Op0, Op1.
MachineInstrBuilder buildFAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FADD Op0, Op1.
MachineInstrBuilder buildSetFPEnv(const SrcOp &Src)
Build and insert G_SET_FPENV Src.
MachineInstrBuilder buildPtrToInt(const DstOp &Dst, const SrcOp &Src)
Build and insert a G_PTRTOINT instruction.
MachineInstrBuilder buildFCanonicalize(const DstOp &Dst, const SrcOp &Src0, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FCANONICALIZE Src0.
MachineInstrBuilder buildSExtInReg(const DstOp &Res, const SrcOp &Op, int64_t ImmOp)
Build and insert Res = G_SEXT_INREG Op, ImmOp.
MachineInstrBuilder buildRotateLeft(const DstOp &Dst, const SrcOp &Src, const SrcOp &Amt)
Build and insert Dst = G_ROTL Src, Amt.
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addPredicate(CmpInst::Predicate Pred) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
SrcOp(const MachineInstrBuilder &MIB)
SrcOp(int64_t V)
SrcOp(const CmpInst::Predicate P)
SrcOp(uint64_t V)
SrcOp(int)=delete
MachineInstrBuilder SrcMIB
CmpInst::Predicate getPredicate() const
SrcType getSrcOpKind() const
CmpInst::Predicate Pred
int64_t getImm() const
LLT getLLTTy(const MachineRegisterInfo &MRI) const
SrcOp(const MachineOperand &Op)
void addSrcToMIB(MachineInstrBuilder &MIB) const
SrcOp(unsigned)=delete
Use of registers held in unsigned integer variables (or more rarely signed integers) is no longer per...
Register getReg() const
SrcOp(Register R)
TargetInstrInfo - Interface to description of machine instruction set.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
PointerUnion< const TargetRegisterClass *, const RegisterBank * > RegClassOrRegBank
Convenient type to represent either a register class or a register bank.
@ Debug
Register 'use' is for debugging purpose.
DWARFExpression::Operation Op
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:774
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:82
Class which stores all the state required in a MachineIRBuilder.
MachineFunction * MF
MachineFunction under construction.
MDNode * MMRA
MMRA Metadata to be set on any instruction we create.
DebugLoc DL
Debug location to be set to any instruction we create.
const TargetInstrInfo * TII
Information used to access the description of the opcodes.
MDNode * PCSections
PC sections metadata to be set to any instruction we create.
MachineBasicBlock::iterator II
MachineRegisterInfo * MRI
Information used to verify types are consistent and to create virtual registers.
GISelChangeObserver * Observer
This class contains a discriminated union of information about pointers in memory operands,...
All attributes(register class or bank and low-level type) a virtual register can have.