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) 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
781 // Build and insert \p Res = G_SEXT_INREG \p Op, 1 or \p Res = G_AND \p Op, 1,
782 // or COPY depending on how the target wants to extend boolean values, using
783 // the original register size.
784 MachineInstrBuilder buildBoolExtInReg(const DstOp &Res, const SrcOp &Op,
785 bool IsVector);
786
787 /// Build and insert \p Res = G_ZEXT \p Op
788 ///
789 /// G_ZEXT produces a register of the specified width, with bits 0 to
790 /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are 0. For a vector
791 /// register, each element is extended individually.
792 ///
793 /// \pre setBasicBlock or setMI must have been called.
794 /// \pre \p Res must be a generic virtual register with scalar or vector type.
795 /// \pre \p Op must be a generic virtual register with scalar or vector type.
796 /// \pre \p Op must be smaller than \p Res
797 ///
798 /// \return The newly created instruction.
799 MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op,
800 std::optional<unsigned> Flags = std::nullopt);
801
802 /// Build and insert \p Res = G_SEXT \p Op, \p Res = G_TRUNC \p Op, or
803 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
804 ///
805 /// \pre setBasicBlock or setMI must have been called.
806 /// \pre \p Res must be a generic virtual register with scalar or vector type.
807 /// \pre \p Op must be a generic virtual register with scalar or vector type.
808 ///
809 /// \return The newly created instruction.
810 MachineInstrBuilder buildSExtOrTrunc(const DstOp &Res, const SrcOp &Op);
811
812 /// Build and insert \p Res = G_ZEXT \p Op, \p Res = G_TRUNC \p Op, or
813 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
814 ///
815 /// \pre setBasicBlock or setMI must have been called.
816 /// \pre \p Res must be a generic virtual register with scalar or vector type.
817 /// \pre \p Op must be a generic virtual register with scalar or vector type.
818 ///
819 /// \return The newly created instruction.
820 MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op);
821
822 // Build and insert \p Res = G_ANYEXT \p Op, \p Res = G_TRUNC \p Op, or
823 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
824 ///
825 /// \pre setBasicBlock or setMI must have been called.
826 /// \pre \p Res must be a generic virtual register with scalar or vector type.
827 /// \pre \p Op must be a generic virtual register with scalar or vector type.
828 ///
829 /// \return The newly created instruction.
830 MachineInstrBuilder buildAnyExtOrTrunc(const DstOp &Res, const SrcOp &Op);
831
832 /// Build and insert \p Res = \p ExtOpc, \p Res = G_TRUNC \p
833 /// Op, or \p Res = COPY \p Op depending on the differing sizes of \p Res and
834 /// \p Op.
835 ///
836 /// \pre setBasicBlock or setMI must have been called.
837 /// \pre \p Res must be a generic virtual register with scalar or vector type.
838 /// \pre \p Op must be a generic virtual register with scalar or vector type.
839 ///
840 /// \return The newly created instruction.
841 MachineInstrBuilder buildExtOrTrunc(unsigned ExtOpc, const DstOp &Res,
842 const SrcOp &Op);
843
844 /// Build and inserts \p Res = \p G_AND \p Op, \p LowBitsSet(ImmOp)
845 /// Since there is no G_ZEXT_INREG like G_SEXT_INREG, the instruction is
846 /// emulated using G_AND.
847 MachineInstrBuilder buildZExtInReg(const DstOp &Res, const SrcOp &Op,
848 int64_t ImmOp);
849
850 /// Build and insert \p Res = \p G_TRUNC_SSAT_S \p Op
851 ///
852 /// G_TRUNC_SSAT_S truncates the signed input, \p Op, to a signed result with
853 /// saturation.
854 ///
855 /// \pre setBasicBlock or setMI must have been called.
856 /// \pre \p Res must be a generic virtual register with scalar or vector type.
857 /// \pre \p Op must be a generic virtual register with scalar or vector type.
858 ///
859 /// \return The newly created instruction.
861 return buildInstr(TargetOpcode::G_TRUNC_SSAT_S, {Res}, {Op});
862 }
863
864 /// Build and insert \p Res = \p G_TRUNC_SSAT_U \p Op
865 ///
866 /// G_TRUNC_SSAT_U truncates the signed input, \p Op, to an unsigned result
867 /// with saturation.
868 ///
869 /// \pre setBasicBlock or setMI must have been called.
870 /// \pre \p Res must be a generic virtual register with scalar or vector type.
871 /// \pre \p Op must be a generic virtual register with scalar or vector type.
872 ///
873 /// \return The newly created instruction.
875 return buildInstr(TargetOpcode::G_TRUNC_SSAT_U, {Res}, {Op});
876 }
877
878 /// Build and insert \p Res = \p G_TRUNC_USAT_U \p Op
879 ///
880 /// G_TRUNC_USAT_U truncates the unsigned input, \p Op, to an unsigned result
881 /// with saturation.
882 ///
883 /// \pre setBasicBlock or setMI must have been called.
884 /// \pre \p Res must be a generic virtual register with scalar or vector type.
885 /// \pre \p Op must be a generic virtual register with scalar or vector type.
886 ///
887 /// \return The newly created instruction.
889 return buildInstr(TargetOpcode::G_TRUNC_USAT_U, {Res}, {Op});
890 }
891
892 /// Build and insert an appropriate cast between two registers of equal size.
893 MachineInstrBuilder buildCast(const DstOp &Dst, const SrcOp &Src);
894
895 /// Build and insert G_BR \p Dest
896 ///
897 /// G_BR is an unconditional branch to \p Dest.
898 ///
899 /// \pre setBasicBlock or setMI must have been called.
900 ///
901 /// \return a MachineInstrBuilder for the newly created instruction.
903
904 /// Build and insert G_BRCOND \p Tst, \p Dest
905 ///
906 /// G_BRCOND is a conditional branch to \p Dest.
907 ///
908 /// \pre setBasicBlock or setMI must have been called.
909 /// \pre \p Tst must be a generic virtual register with scalar
910 /// type. At the beginning of legalization, this will be a single
911 /// bit (s1). Targets with interesting flags registers may change
912 /// this. For a wider type, whether the branch is taken must only
913 /// depend on bit 0 (for now).
914 ///
915 /// \return The newly created instruction.
916 MachineInstrBuilder buildBrCond(const SrcOp &Tst, MachineBasicBlock &Dest);
917
918 /// Build and insert G_BRINDIRECT \p Tgt
919 ///
920 /// G_BRINDIRECT is an indirect branch to \p Tgt.
921 ///
922 /// \pre setBasicBlock or setMI must have been called.
923 /// \pre \p Tgt must be a generic virtual register with pointer type.
924 ///
925 /// \return a MachineInstrBuilder for the newly created instruction.
926 MachineInstrBuilder buildBrIndirect(Register Tgt);
927
928 /// Build and insert G_BRJT \p TablePtr, \p JTI, \p IndexReg
929 ///
930 /// G_BRJT is a jump table branch using a table base pointer \p TablePtr,
931 /// jump table index \p JTI and index \p IndexReg
932 ///
933 /// \pre setBasicBlock or setMI must have been called.
934 /// \pre \p TablePtr must be a generic virtual register with pointer type.
935 /// \pre \p JTI must be a jump table index.
936 /// \pre \p IndexReg must be a generic virtual register with pointer type.
937 ///
938 /// \return a MachineInstrBuilder for the newly created instruction.
939 MachineInstrBuilder buildBrJT(Register TablePtr, unsigned JTI,
940 Register IndexReg);
941
942 /// Build and insert \p Res = G_CONSTANT \p Val
943 ///
944 /// G_CONSTANT is an integer constant with the specified size and value. \p
945 /// Val will be extended or truncated to the size of \p Reg.
946 ///
947 /// \pre setBasicBlock or setMI must have been called.
948 /// \pre \p Res must be a generic virtual register with scalar or pointer
949 /// type.
950 ///
951 /// \return The newly created instruction.
952 virtual MachineInstrBuilder buildConstant(const DstOp &Res,
953 const ConstantInt &Val);
954
955 /// Build and insert \p Res = G_CONSTANT \p Val
956 ///
957 /// G_CONSTANT is an integer constant with the specified size and value.
958 ///
959 /// \pre setBasicBlock or setMI must have been called.
960 /// \pre \p Res must be a generic virtual register with scalar type.
961 ///
962 /// \return The newly created instruction.
963 MachineInstrBuilder buildConstant(const DstOp &Res, int64_t Val);
964 MachineInstrBuilder buildConstant(const DstOp &Res, const APInt &Val);
965
966 /// Build and insert \p Res = G_FCONSTANT \p Val
967 ///
968 /// G_FCONSTANT is a floating-point constant with the specified size and
969 /// value.
970 ///
971 /// \pre setBasicBlock or setMI must have been called.
972 /// \pre \p Res must be a generic virtual register with scalar type.
973 ///
974 /// \return The newly created instruction.
975 virtual MachineInstrBuilder buildFConstant(const DstOp &Res,
976 const ConstantFP &Val);
977
978 MachineInstrBuilder buildFConstant(const DstOp &Res, double Val);
979 MachineInstrBuilder buildFConstant(const DstOp &Res, const APFloat &Val);
980
981 /// Build and insert G_PTRAUTH_GLOBAL_VALUE
982 ///
983 /// \return a MachineInstrBuilder for the newly created instruction.
984 MachineInstrBuilder buildConstantPtrAuth(const DstOp &Res,
985 const ConstantPtrAuth *CPA,
986 Register Addr, Register AddrDisc);
987
988 /// Build and insert \p Res = COPY Op
989 ///
990 /// Register-to-register COPY sets \p Res to \p Op.
991 ///
992 /// \pre setBasicBlock or setMI must have been called.
993 ///
994 /// \return a MachineInstrBuilder for the newly created instruction.
995 MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op);
996
997
998 /// Build and insert G_ASSERT_SEXT, G_ASSERT_ZEXT, or G_ASSERT_ALIGN
999 ///
1000 /// \return a MachineInstrBuilder for the newly created instruction.
1002 const SrcOp &Op, unsigned Val) {
1003 return buildInstr(Opc, Res, Op).addImm(Val);
1004 }
1005
1006 /// Build and insert \p Res = G_ASSERT_ZEXT Op, Size
1007 ///
1008 /// \return a MachineInstrBuilder for the newly created instruction.
1010 unsigned Size) {
1011 return buildAssertInstr(TargetOpcode::G_ASSERT_ZEXT, Res, Op, Size);
1012 }
1013
1014 /// Build and insert \p Res = G_ASSERT_SEXT Op, Size
1015 ///
1016 /// \return a MachineInstrBuilder for the newly created instruction.
1018 unsigned Size) {
1019 return buildAssertInstr(TargetOpcode::G_ASSERT_SEXT, Res, Op, Size);
1020 }
1021
1022 /// Build and insert \p Res = G_ASSERT_ALIGN Op, AlignVal
1023 ///
1024 /// \return a MachineInstrBuilder for the newly created instruction.
1026 Align AlignVal) {
1027 return buildAssertInstr(TargetOpcode::G_ASSERT_ALIGN, Res, Op,
1028 AlignVal.value());
1029 }
1030
1031 /// Build and insert `Res = G_LOAD Addr, MMO`.
1032 ///
1033 /// Loads the value stored at \p Addr. Puts the result in \p Res.
1034 ///
1035 /// \pre setBasicBlock or setMI must have been called.
1036 /// \pre \p Res must be a generic virtual register.
1037 /// \pre \p Addr must be a generic virtual register with pointer type.
1038 ///
1039 /// \return a MachineInstrBuilder for the newly created instruction.
1040 MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr,
1041 MachineMemOperand &MMO) {
1042 return buildLoadInstr(TargetOpcode::G_LOAD, Res, Addr, MMO);
1043 }
1044
1045 /// Build and insert a G_LOAD instruction, while constructing the
1046 /// MachineMemOperand.
1048 buildLoad(const DstOp &Res, const SrcOp &Addr, MachinePointerInfo PtrInfo,
1049 Align Alignment,
1051 const AAMDNodes &AAInfo = AAMDNodes());
1052
1053 /// Build and insert `Res = <opcode> Addr, MMO`.
1054 ///
1055 /// Loads the value stored at \p Addr. Puts the result in \p Res.
1056 ///
1057 /// \pre setBasicBlock or setMI must have been called.
1058 /// \pre \p Res must be a generic virtual register.
1059 /// \pre \p Addr must be a generic virtual register with pointer type.
1060 ///
1061 /// \return a MachineInstrBuilder for the newly created instruction.
1062 MachineInstrBuilder buildLoadInstr(unsigned Opcode, const DstOp &Res,
1063 const SrcOp &Addr, MachineMemOperand &MMO);
1064
1065 /// Helper to create a load from a constant offset given a base address. Load
1066 /// the type of \p Dst from \p Offset from the given base address and memory
1067 /// operand.
1068 MachineInstrBuilder buildLoadFromOffset(const DstOp &Dst,
1069 const SrcOp &BasePtr,
1070 MachineMemOperand &BaseMMO,
1071 int64_t Offset);
1072
1073 /// Build and insert `G_STORE Val, Addr, MMO`.
1074 ///
1075 /// Stores the value \p Val to \p Addr.
1076 ///
1077 /// \pre setBasicBlock or setMI must have been called.
1078 /// \pre \p Val must be a generic virtual register.
1079 /// \pre \p Addr must be a generic virtual register with pointer type.
1080 ///
1081 /// \return a MachineInstrBuilder for the newly created instruction.
1082 MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr,
1083 MachineMemOperand &MMO);
1084
1085 /// Build and insert `<opcode> Val, Addr, MMO`.
1086 ///
1087 /// Stores the value \p Val to \p Addr.
1088 ///
1089 /// \pre setBasicBlock or setMI must have been called.
1090 /// \pre \p Val must be a generic virtual register.
1091 /// \pre \p Addr must be a generic virtual register with pointer type.
1092 ///
1093 /// \return a MachineInstrBuilder for the newly created instruction.
1094 MachineInstrBuilder buildStoreInstr(unsigned Opcode, const SrcOp &Val,
1095 const SrcOp &Addr,
1096 MachineMemOperand &MMO);
1097
1098 /// Build and insert a G_STORE instruction, while constructing the
1099 /// MachineMemOperand.
1101 buildStore(const SrcOp &Val, const SrcOp &Addr, MachinePointerInfo PtrInfo,
1102 Align Alignment,
1104 const AAMDNodes &AAInfo = AAMDNodes());
1105
1106 /// Build and insert `Res0, ... = G_EXTRACT Src, Idx0`.
1107 ///
1108 /// \pre setBasicBlock or setMI must have been called.
1109 /// \pre \p Res and \p Src must be generic virtual registers.
1110 ///
1111 /// \return a MachineInstrBuilder for the newly created instruction.
1112 MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index);
1113
1114 /// Build and insert \p Res = IMPLICIT_DEF.
1115 MachineInstrBuilder buildUndef(const DstOp &Res);
1116
1117 /// Build and insert \p Res = G_MERGE_VALUES \p Op0, ...
1118 ///
1119 /// G_MERGE_VALUES combines the input elements contiguously into a larger
1120 /// register. It should only be used when the destination register is not a
1121 /// vector.
1122 ///
1123 /// \pre setBasicBlock or setMI must have been called.
1124 /// \pre The entire register \p Res (and no more) must be covered by the input
1125 /// registers.
1126 /// \pre The type of all \p Ops registers must be identical.
1127 ///
1128 /// \return a MachineInstrBuilder for the newly created instruction.
1129 MachineInstrBuilder buildMergeValues(const DstOp &Res,
1131
1132 /// Build and insert \p Res = G_MERGE_VALUES \p Op0, ...
1133 /// or \p Res = G_BUILD_VECTOR \p Op0, ...
1134 /// or \p Res = G_CONCAT_VECTORS \p Op0, ...
1135 ///
1136 /// G_MERGE_VALUES combines the input elements contiguously into a larger
1137 /// register. It is used when the destination register is not a vector.
1138 /// G_BUILD_VECTOR combines scalar inputs into a vector register.
1139 /// G_CONCAT_VECTORS combines vector inputs into a vector register.
1140 ///
1141 /// \pre setBasicBlock or setMI must have been called.
1142 /// \pre The entire register \p Res (and no more) must be covered by the input
1143 /// registers.
1144 /// \pre The type of all \p Ops registers must be identical.
1145 ///
1146 /// \return a MachineInstrBuilder for the newly created instruction. The
1147 /// opcode of the new instruction will depend on the types of both
1148 /// the destination and the sources.
1149 MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res,
1151 MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res,
1152 std::initializer_list<SrcOp> Ops);
1153
1154 /// Build and insert \p Res0, ... = G_UNMERGE_VALUES \p Op
1155 ///
1156 /// G_UNMERGE_VALUES splits contiguous bits of the input into multiple
1157 ///
1158 /// \pre setBasicBlock or setMI must have been called.
1159 /// \pre The entire register \p Res (and no more) must be covered by the input
1160 /// registers.
1161 /// \pre The type of all \p Res registers must be identical.
1162 ///
1163 /// \return a MachineInstrBuilder for the newly created instruction.
1164 MachineInstrBuilder buildUnmerge(ArrayRef<LLT> Res, const SrcOp &Op);
1165 MachineInstrBuilder buildUnmerge(ArrayRef<Register> Res, const SrcOp &Op);
1166
1167 /// Build and insert an unmerge of \p Res sized pieces to cover \p Op
1168 MachineInstrBuilder buildUnmerge(LLT Res, const SrcOp &Op);
1169
1170 /// Build and insert an unmerge of pieces with \p Attrs register attributes to
1171 /// cover \p Op
1173 const SrcOp &Op);
1174
1175 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ...
1176 ///
1177 /// G_BUILD_VECTOR creates a vector value from multiple scalar registers.
1178 /// \pre setBasicBlock or setMI must have been called.
1179 /// \pre The entire register \p Res (and no more) must be covered by the
1180 /// input scalar registers.
1181 /// \pre The type of all \p Ops registers must be identical.
1182 ///
1183 /// \return a MachineInstrBuilder for the newly created instruction.
1184 MachineInstrBuilder buildBuildVector(const DstOp &Res,
1186
1187 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ... where each OpN is
1188 /// built with G_CONSTANT.
1189 MachineInstrBuilder buildBuildVectorConstant(const DstOp &Res,
1191
1192 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ... where each OpN is
1193 /// built with G_FCONSTANT.
1194 MachineInstrBuilder buildBuildVectorFConstant(const DstOp &Res,
1196
1197 /// Build and insert \p Res = G_BUILD_VECTOR with \p Src replicated to fill
1198 /// the number of elements
1199 MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src);
1200
1201 /// Build and insert \p Res = G_BUILD_VECTOR_TRUNC \p Op0, ...
1202 ///
1203 /// G_BUILD_VECTOR_TRUNC creates a vector value from multiple scalar registers
1204 /// which have types larger than the destination vector element type, and
1205 /// truncates the values to fit.
1206 ///
1207 /// If the operands given are already the same size as the vector elt type,
1208 /// then this method will instead create a G_BUILD_VECTOR instruction.
1209 ///
1210 /// \pre setBasicBlock or setMI must have been called.
1211 /// \pre The type of all \p Ops registers must be identical.
1212 ///
1213 /// \return a MachineInstrBuilder for the newly created instruction.
1214 MachineInstrBuilder buildBuildVectorTrunc(const DstOp &Res,
1216
1217 /// Build and insert a vector splat of a scalar \p Src using a
1218 /// G_INSERT_VECTOR_ELT and G_SHUFFLE_VECTOR idiom.
1219 ///
1220 /// \pre setBasicBlock or setMI must have been called.
1221 /// \pre \p Src must have the same type as the element type of \p Dst
1222 ///
1223 /// \return a MachineInstrBuilder for the newly created instruction.
1224 MachineInstrBuilder buildShuffleSplat(const DstOp &Res, const SrcOp &Src);
1225
1226 /// Build and insert \p Res = G_SHUFFLE_VECTOR \p Src1, \p Src2, \p Mask
1227 ///
1228 /// \pre setBasicBlock or setMI must have been called.
1229 ///
1230 /// \return a MachineInstrBuilder for the newly created instruction.
1231 MachineInstrBuilder buildShuffleVector(const DstOp &Res, const SrcOp &Src1,
1232 const SrcOp &Src2, ArrayRef<int> Mask);
1233
1234 /// Build and insert \p Res = G_SPLAT_VECTOR \p Val
1235 ///
1236 /// \pre setBasicBlock or setMI must have been called.
1237 /// \pre \p Res must be a generic virtual register with vector type.
1238 /// \pre \p Val must be a generic virtual register with scalar type.
1239 ///
1240 /// \return a MachineInstrBuilder for the newly created instruction.
1241 MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Val);
1242
1243 /// Build and insert \p Res = G_CONCAT_VECTORS \p Op0, ...
1244 ///
1245 /// G_CONCAT_VECTORS creates a vector from the concatenation of 2 or more
1246 /// vectors.
1247 ///
1248 /// \pre setBasicBlock or setMI must have been called.
1249 /// \pre The entire register \p Res (and no more) must be covered by the input
1250 /// registers.
1251 /// \pre The type of all source operands must be identical.
1252 ///
1253 /// \return a MachineInstrBuilder for the newly created instruction.
1254 MachineInstrBuilder buildConcatVectors(const DstOp &Res,
1256
1257 /// Build and insert `Res = G_INSERT_SUBVECTOR Src0, Src1, Idx`.
1258 ///
1259 /// \pre setBasicBlock or setMI must have been called.
1260 /// \pre \p Res, \p Src0, and \p Src1 must be generic virtual registers with
1261 /// vector type.
1262 ///
1263 /// \return a MachineInstrBuilder for the newly created instruction.
1264 MachineInstrBuilder buildInsertSubvector(const DstOp &Res, const SrcOp &Src0,
1265 const SrcOp &Src1, unsigned Index);
1266
1267 /// Build and insert `Res = G_EXTRACT_SUBVECTOR Src, Idx0`.
1268 ///
1269 /// \pre setBasicBlock or setMI must have been called.
1270 /// \pre \p Res and \p Src must be generic virtual registers with vector type.
1271 ///
1272 /// \return a MachineInstrBuilder for the newly created instruction.
1273 MachineInstrBuilder buildExtractSubvector(const DstOp &Res, const SrcOp &Src,
1274 unsigned Index);
1275
1276 MachineInstrBuilder buildInsert(const DstOp &Res, const SrcOp &Src,
1277 const SrcOp &Op, unsigned Index);
1278
1279 /// Build and insert \p Res = G_STEP_VECTOR \p Step
1280 ///
1281 /// G_STEP_VECTOR returns a scalable vector of linear sequence of step \p Step
1282 /// into \p Res.
1283 ///
1284 /// \pre setBasicBlock or setMI must have been called.
1285 /// \pre \p Res must be a generic virtual register with scalable vector type.
1286 ///
1287 /// \return a MachineInstrBuilder for the newly created instruction.
1288 MachineInstrBuilder buildStepVector(const DstOp &Res, unsigned Step);
1289
1290 /// Build and insert \p Res = G_VSCALE \p MinElts
1291 ///
1292 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1293 /// into \p Res.
1294 ///
1295 /// \pre setBasicBlock or setMI must have been called.
1296 /// \pre \p Res must be a generic virtual register with scalar type.
1297 ///
1298 /// \return a MachineInstrBuilder for the newly created instruction.
1299 MachineInstrBuilder buildVScale(const DstOp &Res, unsigned MinElts);
1300
1301 /// Build and insert \p Res = G_VSCALE \p MinElts
1302 ///
1303 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1304 /// into \p Res.
1305 ///
1306 /// \pre setBasicBlock or setMI must have been called.
1307 /// \pre \p Res must be a generic virtual register with scalar type.
1308 ///
1309 /// \return a MachineInstrBuilder for the newly created instruction.
1310 MachineInstrBuilder buildVScale(const DstOp &Res, const ConstantInt &MinElts);
1311
1312 /// Build and insert \p Res = G_VSCALE \p MinElts
1313 ///
1314 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1315 /// into \p Res.
1316 ///
1317 /// \pre setBasicBlock or setMI must have been called.
1318 /// \pre \p Res must be a generic virtual register with scalar type.
1319 ///
1320 /// \return a MachineInstrBuilder for the newly created instruction.
1321 MachineInstrBuilder buildVScale(const DstOp &Res, const APInt &MinElts);
1322
1323 /// Build and insert a G_INTRINSIC instruction.
1324 ///
1325 /// There are four different opcodes based on combinations of whether the
1326 /// intrinsic has side effects and whether it is convergent. These properties
1327 /// can be specified as explicit parameters, or else they are retrieved from
1328 /// the MCID for the intrinsic.
1329 ///
1330 /// The parameter \p Res provides the Registers or MOs that will be defined by
1331 /// this instruction.
1332 ///
1333 /// \pre setBasicBlock or setMI must have been called.
1334 ///
1335 /// \return a MachineInstrBuilder for the newly created instruction.
1337 bool HasSideEffects, bool isConvergent);
1339 MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<DstOp> Res,
1340 bool HasSideEffects, bool isConvergent);
1341 MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<DstOp> Res);
1342
1343 /// Build and insert \p Res = G_FPTRUNC \p Op
1344 ///
1345 /// G_FPTRUNC converts a floating-point value into one with a smaller type.
1346 ///
1347 /// \pre setBasicBlock or setMI must have been called.
1348 /// \pre \p Res must be a generic virtual register with scalar or vector type.
1349 /// \pre \p Op must be a generic virtual register with scalar or vector type.
1350 /// \pre \p Res must be smaller than \p Op
1351 ///
1352 /// \return The newly created instruction.
1354 buildFPTrunc(const DstOp &Res, const SrcOp &Op,
1355 std::optional<unsigned> Flags = std::nullopt);
1356
1357 /// Build and insert \p Res = G_TRUNC \p Op
1358 ///
1359 /// G_TRUNC extracts the low bits of a type. For a vector type each element is
1360 /// truncated independently before being packed into the destination.
1361 ///
1362 /// \pre setBasicBlock or setMI must have been called.
1363 /// \pre \p Res must be a generic virtual register with scalar or vector type.
1364 /// \pre \p Op must be a generic virtual register with scalar or vector type.
1365 /// \pre \p Res must be smaller than \p Op
1366 ///
1367 /// \return The newly created instruction.
1368 MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op,
1369 std::optional<unsigned> Flags = std::nullopt);
1370
1371 /// Build and insert a \p Res = G_ICMP \p Pred, \p Op0, \p Op1
1372 ///
1373 /// \pre setBasicBlock or setMI must have been called.
1374
1375 /// \pre \p Res must be a generic virtual register with scalar or
1376 /// vector type. Typically this starts as s1 or <N x s1>.
1377 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1378 /// same number of elements as \p Res. If \p Res is a scalar,
1379 /// \p Op0 must be either a scalar or pointer.
1380 /// \pre \p Pred must be an integer predicate.
1381 ///
1382 /// \return a MachineInstrBuilder for the newly created instruction.
1383 MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res,
1384 const SrcOp &Op0, const SrcOp &Op1,
1385 std::optional<unsigned> Flags = std::nullopt);
1386
1387 /// Build and insert a \p Res = G_FCMP \p Pred\p Op0, \p Op1
1388 ///
1389 /// \pre setBasicBlock or setMI must have been called.
1390
1391 /// \pre \p Res must be a generic virtual register with scalar or
1392 /// vector type. Typically this starts as s1 or <N x s1>.
1393 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1394 /// same number of elements as \p Res (or scalar, if \p Res is
1395 /// scalar).
1396 /// \pre \p Pred must be a floating-point predicate.
1397 ///
1398 /// \return a MachineInstrBuilder for the newly created instruction.
1399 MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, const DstOp &Res,
1400 const SrcOp &Op0, const SrcOp &Op1,
1401 std::optional<unsigned> Flags = std::nullopt);
1402
1403 /// Build and insert a \p Res = G_SCMP \p Op0, \p Op1
1404 ///
1405 /// \pre setBasicBlock or setMI must have been called.
1406
1407 /// \pre \p Res must be a generic virtual register with scalar or
1408 /// vector type. Typically this starts as s2 or <N x s2>.
1409 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1410 /// same number of elements as \p Res. If \p Res is a scalar,
1411 /// \p Op0 must be a scalar.
1412 ///
1413 /// \return a MachineInstrBuilder for the newly created instruction.
1414 MachineInstrBuilder buildSCmp(const DstOp &Res, const SrcOp &Op0,
1415 const SrcOp &Op1);
1416
1417 /// Build and insert a \p Res = G_UCMP \p Op0, \p Op1
1418 ///
1419 /// \pre setBasicBlock or setMI must have been called.
1420
1421 /// \pre \p Res must be a generic virtual register with scalar or
1422 /// vector type. Typically this starts as s2 or <N x s2>.
1423 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1424 /// same number of elements as \p Res. If \p Res is a scalar,
1425 /// \p Op0 must be a scalar.
1426 ///
1427 /// \return a MachineInstrBuilder for the newly created instruction.
1428 MachineInstrBuilder buildUCmp(const DstOp &Res, const SrcOp &Op0,
1429 const SrcOp &Op1);
1430
1431 /// Build and insert a \p Res = G_IS_FPCLASS \p Src, \p Mask
1433 unsigned Mask) {
1434 return buildInstr(TargetOpcode::G_IS_FPCLASS, {Res},
1435 {Src, SrcOp(static_cast<int64_t>(Mask))});
1436 }
1437
1438 /// Build and insert a \p Res = G_SELECT \p Tst, \p Op0, \p Op1
1439 ///
1440 /// \pre setBasicBlock or setMI must have been called.
1441 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1442 /// with the same type.
1443 /// \pre \p Tst must be a generic virtual register with scalar, pointer or
1444 /// vector type. If vector then it must have the same number of
1445 /// elements as the other parameters.
1446 ///
1447 /// \return a MachineInstrBuilder for the newly created instruction.
1448 MachineInstrBuilder buildSelect(const DstOp &Res, const SrcOp &Tst,
1449 const SrcOp &Op0, const SrcOp &Op1,
1450 std::optional<unsigned> Flags = std::nullopt);
1451
1452 /// Build and insert \p Res = G_INSERT_VECTOR_ELT \p Val,
1453 /// \p Elt, \p Idx
1454 ///
1455 /// \pre setBasicBlock or setMI must have been called.
1456 /// \pre \p Res and \p Val must be a generic virtual register
1457 // with the same vector type.
1458 /// \pre \p Elt and \p Idx must be a generic virtual register
1459 /// with scalar type.
1460 ///
1461 /// \return The newly created instruction.
1462 MachineInstrBuilder buildInsertVectorElement(const DstOp &Res,
1463 const SrcOp &Val,
1464 const SrcOp &Elt,
1465 const SrcOp &Idx);
1466
1467 /// Build and insert \p Res = G_EXTRACT_VECTOR_ELT \p Val, \p Idx
1468 ///
1469 /// \pre setBasicBlock or setMI must have been called.
1470 /// \pre \p Res must be a generic virtual register with scalar type.
1471 /// \pre \p Val must be a generic virtual register with vector type.
1472 ///
1473 /// \return The newly created instruction.
1475 const SrcOp &Val,
1476 const int Idx) {
1477 const TargetLowering *TLI = getMF().getSubtarget().getTargetLowering();
1478 LLT IdxTy = TLI->getVectorIdxLLT(getDataLayout());
1479 return buildExtractVectorElement(Res, Val, buildConstant(IdxTy, Idx));
1480 }
1481
1482 /// Build and insert \p Res = G_EXTRACT_VECTOR_ELT \p Val, \p Idx
1483 ///
1484 /// \pre setBasicBlock or setMI must have been called.
1485 /// \pre \p Res must be a generic virtual register with scalar type.
1486 /// \pre \p Val must be a generic virtual register with vector type.
1487 /// \pre \p Idx must be a generic virtual register with scalar type.
1488 ///
1489 /// \return The newly created instruction.
1490 MachineInstrBuilder buildExtractVectorElement(const DstOp &Res,
1491 const SrcOp &Val,
1492 const SrcOp &Idx);
1493
1494 /// Build and insert `OldValRes<def>, SuccessRes<def> =
1495 /// G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr, CmpVal, NewVal, MMO`.
1496 ///
1497 /// Atomically replace the value at \p Addr with \p NewVal if it is currently
1498 /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p
1499 /// Addr in \p Res, along with an s1 indicating whether it was replaced.
1500 ///
1501 /// \pre setBasicBlock or setMI must have been called.
1502 /// \pre \p OldValRes must be a generic virtual register of scalar type.
1503 /// \pre \p SuccessRes must be a generic virtual register of scalar type. It
1504 /// will be assigned 0 on failure and 1 on success.
1505 /// \pre \p Addr must be a generic virtual register with pointer type.
1506 /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual
1507 /// registers of the same type.
1508 ///
1509 /// \return a MachineInstrBuilder for the newly created instruction.
1511 buildAtomicCmpXchgWithSuccess(const DstOp &OldValRes, const DstOp &SuccessRes,
1512 const SrcOp &Addr, const SrcOp &CmpVal,
1513 const SrcOp &NewVal, MachineMemOperand &MMO);
1514
1515 /// Build and insert `OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal,
1516 /// MMO`.
1517 ///
1518 /// Atomically replace the value at \p Addr with \p NewVal if it is currently
1519 /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p
1520 /// Addr in \p Res.
1521 ///
1522 /// \pre setBasicBlock or setMI must have been called.
1523 /// \pre \p OldValRes must be a generic virtual register of scalar type.
1524 /// \pre \p Addr must be a generic virtual register with pointer type.
1525 /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual
1526 /// registers of the same type.
1527 ///
1528 /// \return a MachineInstrBuilder for the newly created instruction.
1529 MachineInstrBuilder buildAtomicCmpXchg(const DstOp &OldValRes,
1530 const SrcOp &Addr, const SrcOp &CmpVal,
1531 const SrcOp &NewVal,
1532 MachineMemOperand &MMO);
1533
1534 /// Build and insert `OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO`.
1535 ///
1536 /// Atomically read-modify-update the value at \p Addr with \p Val. Puts the
1537 /// original value from \p Addr in \p OldValRes. The modification is
1538 /// determined by the opcode.
1539 ///
1540 /// \pre setBasicBlock or setMI must have been called.
1541 /// \pre \p OldValRes must be a generic virtual register.
1542 /// \pre \p Addr must be a generic virtual register with pointer type.
1543 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1544 /// same type.
1545 ///
1546 /// \return a MachineInstrBuilder for the newly created instruction.
1547 MachineInstrBuilder buildAtomicRMW(unsigned Opcode, const DstOp &OldValRes,
1548 const SrcOp &Addr, const SrcOp &Val,
1549 MachineMemOperand &MMO);
1550
1551 /// Build and insert `OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO`.
1552 ///
1553 /// Atomically replace the value at \p Addr with \p Val. Puts the original
1554 /// value from \p Addr in \p OldValRes.
1555 ///
1556 /// \pre setBasicBlock or setMI must have been called.
1557 /// \pre \p OldValRes must be a generic virtual register.
1558 /// \pre \p Addr must be a generic virtual register with pointer type.
1559 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1560 /// same type.
1561 ///
1562 /// \return a MachineInstrBuilder for the newly created instruction.
1563 MachineInstrBuilder buildAtomicRMWXchg(Register OldValRes, Register Addr,
1564 Register Val, MachineMemOperand &MMO);
1565
1566 /// Build and insert `OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO`.
1567 ///
1568 /// Atomically replace the value at \p Addr with the addition of \p Val and
1569 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1570 ///
1571 /// \pre setBasicBlock or setMI must have been called.
1572 /// \pre \p OldValRes must be a generic virtual register.
1573 /// \pre \p Addr must be a generic virtual register with pointer type.
1574 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1575 /// same type.
1576 ///
1577 /// \return a MachineInstrBuilder for the newly created instruction.
1578 MachineInstrBuilder buildAtomicRMWAdd(Register OldValRes, Register Addr,
1579 Register Val, MachineMemOperand &MMO);
1580
1581 /// Build and insert `OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO`.
1582 ///
1583 /// Atomically replace the value at \p Addr with the subtraction of \p Val and
1584 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1585 ///
1586 /// \pre setBasicBlock or setMI must have been called.
1587 /// \pre \p OldValRes must be a generic virtual register.
1588 /// \pre \p Addr must be a generic virtual register with pointer type.
1589 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1590 /// same type.
1591 ///
1592 /// \return a MachineInstrBuilder for the newly created instruction.
1593 MachineInstrBuilder buildAtomicRMWSub(Register OldValRes, Register Addr,
1594 Register Val, MachineMemOperand &MMO);
1595
1596 /// Build and insert `OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO`.
1597 ///
1598 /// Atomically replace the value at \p Addr with the bitwise and of \p Val and
1599 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1600 ///
1601 /// \pre setBasicBlock or setMI must have been called.
1602 /// \pre \p OldValRes must be a generic virtual register.
1603 /// \pre \p Addr must be a generic virtual register with pointer type.
1604 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1605 /// same type.
1606 ///
1607 /// \return a MachineInstrBuilder for the newly created instruction.
1608 MachineInstrBuilder buildAtomicRMWAnd(Register OldValRes, Register Addr,
1609 Register Val, MachineMemOperand &MMO);
1610
1611 /// Build and insert `OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO`.
1612 ///
1613 /// Atomically replace the value at \p Addr with the bitwise nand of \p Val
1614 /// and the original value. Puts the original value from \p Addr in \p
1615 /// OldValRes.
1616 ///
1617 /// \pre setBasicBlock or setMI must have been called.
1618 /// \pre \p OldValRes must be a generic virtual register.
1619 /// \pre \p Addr must be a generic virtual register with pointer type.
1620 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1621 /// same type.
1622 ///
1623 /// \return a MachineInstrBuilder for the newly created instruction.
1624 MachineInstrBuilder buildAtomicRMWNand(Register OldValRes, Register Addr,
1625 Register Val, MachineMemOperand &MMO);
1626
1627 /// Build and insert `OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO`.
1628 ///
1629 /// Atomically replace the value at \p Addr with the bitwise or of \p Val and
1630 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1631 ///
1632 /// \pre setBasicBlock or setMI must have been called.
1633 /// \pre \p OldValRes must be a generic virtual register.
1634 /// \pre \p Addr must be a generic virtual register with pointer type.
1635 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1636 /// same type.
1637 ///
1638 /// \return a MachineInstrBuilder for the newly created instruction.
1639 MachineInstrBuilder buildAtomicRMWOr(Register OldValRes, Register Addr,
1640 Register Val, MachineMemOperand &MMO);
1641
1642 /// Build and insert `OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO`.
1643 ///
1644 /// Atomically replace the value at \p Addr with the bitwise xor of \p Val and
1645 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1646 ///
1647 /// \pre setBasicBlock or setMI must have been called.
1648 /// \pre \p OldValRes must be a generic virtual register.
1649 /// \pre \p Addr must be a generic virtual register with pointer type.
1650 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1651 /// same type.
1652 ///
1653 /// \return a MachineInstrBuilder for the newly created instruction.
1654 MachineInstrBuilder buildAtomicRMWXor(Register OldValRes, Register Addr,
1655 Register Val, MachineMemOperand &MMO);
1656
1657 /// Build and insert `OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO`.
1658 ///
1659 /// Atomically replace the value at \p Addr with the signed maximum of \p
1660 /// Val and the original value. Puts the original value from \p Addr in \p
1661 /// OldValRes.
1662 ///
1663 /// \pre setBasicBlock or setMI must have been called.
1664 /// \pre \p OldValRes must be a generic virtual register.
1665 /// \pre \p Addr must be a generic virtual register with pointer type.
1666 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1667 /// same type.
1668 ///
1669 /// \return a MachineInstrBuilder for the newly created instruction.
1670 MachineInstrBuilder buildAtomicRMWMax(Register OldValRes, Register Addr,
1671 Register Val, MachineMemOperand &MMO);
1672
1673 /// Build and insert `OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO`.
1674 ///
1675 /// Atomically replace the value at \p Addr with the signed minimum of \p
1676 /// Val and the original value. Puts the original value from \p Addr in \p
1677 /// OldValRes.
1678 ///
1679 /// \pre setBasicBlock or setMI must have been called.
1680 /// \pre \p OldValRes must be a generic virtual register.
1681 /// \pre \p Addr must be a generic virtual register with pointer type.
1682 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1683 /// same type.
1684 ///
1685 /// \return a MachineInstrBuilder for the newly created instruction.
1686 MachineInstrBuilder buildAtomicRMWMin(Register OldValRes, Register Addr,
1687 Register Val, MachineMemOperand &MMO);
1688
1689 /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO`.
1690 ///
1691 /// Atomically replace the value at \p Addr with the unsigned maximum of \p
1692 /// Val and the original value. Puts the original value from \p Addr in \p
1693 /// OldValRes.
1694 ///
1695 /// \pre setBasicBlock or setMI must have been called.
1696 /// \pre \p OldValRes must be a generic virtual register.
1697 /// \pre \p Addr must be a generic virtual register with pointer type.
1698 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1699 /// same type.
1700 ///
1701 /// \return a MachineInstrBuilder for the newly created instruction.
1702 MachineInstrBuilder buildAtomicRMWUmax(Register OldValRes, Register Addr,
1703 Register Val, MachineMemOperand &MMO);
1704
1705 /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO`.
1706 ///
1707 /// Atomically replace the value at \p Addr with the unsigned minimum of \p
1708 /// Val and the original value. Puts the original value from \p Addr in \p
1709 /// OldValRes.
1710 ///
1711 /// \pre setBasicBlock or setMI must have been called.
1712 /// \pre \p OldValRes must be a generic virtual register.
1713 /// \pre \p Addr must be a generic virtual register with pointer type.
1714 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1715 /// same type.
1716 ///
1717 /// \return a MachineInstrBuilder for the newly created instruction.
1718 MachineInstrBuilder buildAtomicRMWUmin(Register OldValRes, Register Addr,
1719 Register Val, MachineMemOperand &MMO);
1720
1721 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FADD Addr, Val, MMO`.
1722 MachineInstrBuilder buildAtomicRMWFAdd(
1723 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1724 MachineMemOperand &MMO);
1725
1726 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FSUB Addr, Val, MMO`.
1727 MachineInstrBuilder buildAtomicRMWFSub(
1728 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1729 MachineMemOperand &MMO);
1730
1731 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMAX Addr, Val, MMO`.
1732 ///
1733 /// Atomically replace the value at \p Addr with the floating point maximum of
1734 /// \p Val and the original value. Puts the original value from \p Addr in \p
1735 /// OldValRes.
1736 ///
1737 /// \pre setBasicBlock or setMI must have been called.
1738 /// \pre \p OldValRes must be a generic virtual register.
1739 /// \pre \p Addr must be a generic virtual register with pointer type.
1740 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1741 /// same type.
1742 ///
1743 /// \return a MachineInstrBuilder for the newly created instruction.
1744 MachineInstrBuilder buildAtomicRMWFMax(
1745 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1746 MachineMemOperand &MMO);
1747
1748 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMIN Addr, Val, MMO`.
1749 ///
1750 /// Atomically replace the value at \p Addr with the floating point minimum of
1751 /// \p Val and the original value. Puts the original value from \p Addr in \p
1752 /// OldValRes.
1753 ///
1754 /// \pre setBasicBlock or setMI must have been called.
1755 /// \pre \p OldValRes must be a generic virtual register.
1756 /// \pre \p Addr must be a generic virtual register with pointer type.
1757 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1758 /// same type.
1759 ///
1760 /// \return a MachineInstrBuilder for the newly created instruction.
1761 MachineInstrBuilder buildAtomicRMWFMin(
1762 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1763 MachineMemOperand &MMO);
1764
1765 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMAXIMUM Addr, Val, MMO`.
1766 ///
1767 /// Atomically replace the value at \p Addr with the floating point maximum of
1768 /// \p Val and the original value. Puts the original value from \p Addr in \p
1769 /// OldValRes.
1770 ///
1771 /// \pre setBasicBlock or setMI must have been called.
1772 /// \pre \p OldValRes must be a generic virtual register.
1773 /// \pre \p Addr must be a generic virtual register with pointer type.
1774 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1775 /// same type.
1776 ///
1777 /// \return a MachineInstrBuilder for the newly created instruction.
1778 MachineInstrBuilder buildAtomicRMWFMaximum(const DstOp &OldValRes,
1779 const SrcOp &Addr,
1780 const SrcOp &Val,
1781 MachineMemOperand &MMO);
1782
1783 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMINIMUM Addr, Val, MMO`.
1784 ///
1785 /// Atomically replace the value at \p Addr with the floating point minimum of
1786 /// \p Val and the original value. Puts the original value from \p Addr in \p
1787 /// OldValRes.
1788 ///
1789 /// \pre setBasicBlock or setMI must have been called.
1790 /// \pre \p OldValRes must be a generic virtual register.
1791 /// \pre \p Addr must be a generic virtual register with pointer type.
1792 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1793 /// same type.
1794 ///
1795 /// \return a MachineInstrBuilder for the newly created instruction.
1796 MachineInstrBuilder buildAtomicRMWFMinimum(const DstOp &OldValRes,
1797 const SrcOp &Addr,
1798 const SrcOp &Val,
1799 MachineMemOperand &MMO);
1800
1801 /// Build and insert `G_FENCE Ordering, Scope`.
1802 MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope);
1803
1804 /// Build and insert G_PREFETCH \p Addr, \p RW, \p Locality, \p CacheType
1805 MachineInstrBuilder buildPrefetch(const SrcOp &Addr, unsigned RW,
1806 unsigned Locality, unsigned CacheType,
1807 MachineMemOperand &MMO);
1808
1809 /// Build and insert \p Dst = G_FREEZE \p Src
1810 MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src) {
1811 return buildInstr(TargetOpcode::G_FREEZE, {Dst}, {Src});
1812 }
1813
1814 /// Build and insert \p Res = G_BLOCK_ADDR \p BA
1815 ///
1816 /// G_BLOCK_ADDR computes the address of a basic block.
1817 ///
1818 /// \pre setBasicBlock or setMI must have been called.
1819 /// \pre \p Res must be a generic virtual register of a pointer type.
1820 ///
1821 /// \return The newly created instruction.
1822 MachineInstrBuilder buildBlockAddress(Register Res, const BlockAddress *BA);
1823
1824 /// Build and insert \p Res = G_ADD \p Op0, \p Op1
1825 ///
1826 /// G_ADD sets \p Res to the sum of integer parameters \p Op0 and \p Op1,
1827 /// truncated to their width.
1828 ///
1829 /// \pre setBasicBlock or setMI must have been called.
1830 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1831 /// with the same (scalar or vector) type).
1832 ///
1833 /// \return a MachineInstrBuilder for the newly created instruction.
1834
1835 MachineInstrBuilder buildAdd(const DstOp &Dst, const SrcOp &Src0,
1836 const SrcOp &Src1,
1837 std::optional<unsigned> Flags = std::nullopt) {
1838 return buildInstr(TargetOpcode::G_ADD, {Dst}, {Src0, Src1}, Flags);
1839 }
1840
1841 /// Build and insert \p Res = G_SUB \p Op0, \p Op1
1842 ///
1843 /// G_SUB sets \p Res to the difference of integer parameters \p Op0 and
1844 /// \p Op1, truncated to their width.
1845 ///
1846 /// \pre setBasicBlock or setMI must have been called.
1847 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1848 /// with the same (scalar or vector) type).
1849 ///
1850 /// \return a MachineInstrBuilder for the newly created instruction.
1851
1852 MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0,
1853 const SrcOp &Src1,
1854 std::optional<unsigned> Flags = std::nullopt) {
1855 return buildInstr(TargetOpcode::G_SUB, {Dst}, {Src0, Src1}, Flags);
1856 }
1857
1858 /// Build and insert \p Res = G_MUL \p Op0, \p Op1
1859 ///
1860 /// G_MUL sets \p Res to the product of integer parameters \p Op0 and \p Op1,
1861 /// truncated to their width.
1862 ///
1863 /// \pre setBasicBlock or setMI must have been called.
1864 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1865 /// with the same (scalar or vector) type).
1866 ///
1867 /// \return a MachineInstrBuilder for the newly created instruction.
1868 MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0,
1869 const SrcOp &Src1,
1870 std::optional<unsigned> Flags = std::nullopt) {
1871 return buildInstr(TargetOpcode::G_MUL, {Dst}, {Src0, Src1}, Flags);
1872 }
1873
1874 /// Build and insert \p Res = G_ABDS \p Op0, \p Op1
1875 ///
1876 /// G_ABDS return the signed absolute difference of \p Op0 and \p Op1.
1877 ///
1878 /// \pre setBasicBlock or setMI must have been called.
1879 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1880 /// with the same (scalar or vector) type).
1881 ///
1882 /// \return a MachineInstrBuilder for the newly created instruction.
1883 MachineInstrBuilder buildAbds(const DstOp &Dst, const SrcOp &Src0,
1884 const SrcOp &Src1) {
1885 return buildInstr(TargetOpcode::G_ABDS, {Dst}, {Src0, Src1});
1886 }
1887
1888 /// Build and insert \p Res = G_ABDU \p Op0, \p Op1
1889 ///
1890 /// G_ABDU return the unsigned absolute difference of \p Op0 and \p Op1.
1891 ///
1892 /// \pre setBasicBlock or setMI must have been called.
1893 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1894 /// with the same (scalar or vector) type).
1895 ///
1896 /// \return a MachineInstrBuilder for the newly created instruction.
1897 MachineInstrBuilder buildAbdu(const DstOp &Dst, const SrcOp &Src0,
1898 const SrcOp &Src1) {
1899 return buildInstr(TargetOpcode::G_ABDU, {Dst}, {Src0, Src1});
1900 }
1901
1903 const SrcOp &Src1,
1904 std::optional<unsigned> Flags = std::nullopt) {
1905 return buildInstr(TargetOpcode::G_UMULH, {Dst}, {Src0, Src1}, Flags);
1906 }
1907
1909 const SrcOp &Src1,
1910 std::optional<unsigned> Flags = std::nullopt) {
1911 return buildInstr(TargetOpcode::G_SMULH, {Dst}, {Src0, Src1}, Flags);
1912 }
1913
1914 /// Build and insert \p Res = G_UREM \p Op0, \p Op1
1915 MachineInstrBuilder buildURem(const DstOp &Dst, const SrcOp &Src0,
1916 const SrcOp &Src1,
1917 std::optional<unsigned> Flags = std::nullopt) {
1918 return buildInstr(TargetOpcode::G_UREM, {Dst}, {Src0, Src1}, Flags);
1919 }
1920
1921 MachineInstrBuilder buildFMul(const DstOp &Dst, const SrcOp &Src0,
1922 const SrcOp &Src1,
1923 std::optional<unsigned> Flags = std::nullopt) {
1924 return buildInstr(TargetOpcode::G_FMUL, {Dst}, {Src0, Src1}, Flags);
1925 }
1926
1928 buildFMinNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1929 std::optional<unsigned> Flags = std::nullopt) {
1930 return buildInstr(TargetOpcode::G_FMINNUM, {Dst}, {Src0, Src1}, Flags);
1931 }
1932
1934 buildFMaxNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1935 std::optional<unsigned> Flags = std::nullopt) {
1936 return buildInstr(TargetOpcode::G_FMAXNUM, {Dst}, {Src0, Src1}, Flags);
1937 }
1938
1940 buildFMinNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1941 std::optional<unsigned> Flags = std::nullopt) {
1942 return buildInstr(TargetOpcode::G_FMINNUM_IEEE, {Dst}, {Src0, Src1}, Flags);
1943 }
1944
1946 buildFMaxNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1947 std::optional<unsigned> Flags = std::nullopt) {
1948 return buildInstr(TargetOpcode::G_FMAXNUM_IEEE, {Dst}, {Src0, Src1}, Flags);
1949 }
1950
1951 MachineInstrBuilder buildShl(const DstOp &Dst, const SrcOp &Src0,
1952 const SrcOp &Src1,
1953 std::optional<unsigned> Flags = std::nullopt) {
1954 return buildInstr(TargetOpcode::G_SHL, {Dst}, {Src0, Src1}, Flags);
1955 }
1956
1957 MachineInstrBuilder buildLShr(const DstOp &Dst, const SrcOp &Src0,
1958 const SrcOp &Src1,
1959 std::optional<unsigned> Flags = std::nullopt) {
1960 return buildInstr(TargetOpcode::G_LSHR, {Dst}, {Src0, Src1}, Flags);
1961 }
1962
1963 MachineInstrBuilder buildAShr(const DstOp &Dst, const SrcOp &Src0,
1964 const SrcOp &Src1,
1965 std::optional<unsigned> Flags = std::nullopt) {
1966 return buildInstr(TargetOpcode::G_ASHR, {Dst}, {Src0, Src1}, Flags);
1967 }
1968
1969 /// Build and insert \p Res = G_AND \p Op0, \p Op1
1970 ///
1971 /// G_AND sets \p Res to the bitwise and of integer parameters \p Op0 and \p
1972 /// Op1.
1973 ///
1974 /// \pre setBasicBlock or setMI must have been called.
1975 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1976 /// with the same (scalar or vector) type).
1977 ///
1978 /// \return a MachineInstrBuilder for the newly created instruction.
1979
1980 MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0,
1981 const SrcOp &Src1) {
1982 return buildInstr(TargetOpcode::G_AND, {Dst}, {Src0, Src1});
1983 }
1984
1985 /// Build and insert \p Res = G_OR \p Op0, \p Op1
1986 ///
1987 /// G_OR sets \p Res to the bitwise or of integer parameters \p Op0 and \p
1988 /// Op1.
1989 ///
1990 /// \pre setBasicBlock or setMI must have been called.
1991 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1992 /// with the same (scalar or vector) type).
1993 ///
1994 /// \return a MachineInstrBuilder for the newly created instruction.
1995 MachineInstrBuilder buildOr(const DstOp &Dst, const SrcOp &Src0,
1996 const SrcOp &Src1,
1997 std::optional<unsigned> Flags = std::nullopt) {
1998 return buildInstr(TargetOpcode::G_OR, {Dst}, {Src0, Src1}, Flags);
1999 }
2000
2001 /// Build and insert \p Res = G_XOR \p Op0, \p Op1
2002 MachineInstrBuilder buildXor(const DstOp &Dst, const SrcOp &Src0,
2003 const SrcOp &Src1) {
2004 return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, Src1});
2005 }
2006
2007 /// Build and insert a bitwise not,
2008 /// \p NegOne = G_CONSTANT -1
2009 /// \p Res = G_OR \p Op0, NegOne
2010 MachineInstrBuilder buildNot(const DstOp &Dst, const SrcOp &Src0) {
2011 auto NegOne = buildConstant(Dst.getLLTTy(*getMRI()), -1);
2012 return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, NegOne});
2013 }
2014
2015 /// Build and insert integer negation
2016 /// \p Zero = G_CONSTANT 0
2017 /// \p Res = G_SUB Zero, \p Op0
2018 MachineInstrBuilder buildNeg(const DstOp &Dst, const SrcOp &Src0) {
2019 auto Zero = buildConstant(Dst.getLLTTy(*getMRI()), 0);
2020 return buildInstr(TargetOpcode::G_SUB, {Dst}, {Zero, Src0});
2021 }
2022
2023 /// Build and insert \p Res = G_CTPOP \p Op0, \p Src0
2024 MachineInstrBuilder buildCTPOP(const DstOp &Dst, const SrcOp &Src0) {
2025 return buildInstr(TargetOpcode::G_CTPOP, {Dst}, {Src0});
2026 }
2027
2028 /// Build and insert \p Res = G_CTLZ \p Op0, \p Src0
2029 MachineInstrBuilder buildCTLZ(const DstOp &Dst, const SrcOp &Src0) {
2030 return buildInstr(TargetOpcode::G_CTLZ, {Dst}, {Src0});
2031 }
2032
2033 /// Build and insert \p Res = G_CTLZ_ZERO_POISON \p Op0, \p Src0
2035 const SrcOp &Src0) {
2036 return buildInstr(TargetOpcode::G_CTLZ_ZERO_POISON, {Dst}, {Src0});
2037 }
2038
2039 /// Build and insert \p Res = G_CTTZ \p Op0, \p Src0
2040 MachineInstrBuilder buildCTTZ(const DstOp &Dst, const SrcOp &Src0) {
2041 return buildInstr(TargetOpcode::G_CTTZ, {Dst}, {Src0});
2042 }
2043
2044 /// Build and insert \p Res = G_CTTZ_ZERO_POISON \p Op0, \p Src0
2046 const SrcOp &Src0) {
2047 return buildInstr(TargetOpcode::G_CTTZ_ZERO_POISON, {Dst}, {Src0});
2048 }
2049
2050 /// Build and insert \p Res = G_CTLS \p Op0, \p Src0
2051 MachineInstrBuilder buildCTLS(const DstOp &Dst, const SrcOp &Src0) {
2052 return buildInstr(TargetOpcode::G_CTLS, {Dst}, {Src0});
2053 }
2054
2055 /// Build and insert \p Dst = G_BSWAP \p Src0
2056 MachineInstrBuilder buildBSwap(const DstOp &Dst, const SrcOp &Src0) {
2057 return buildInstr(TargetOpcode::G_BSWAP, {Dst}, {Src0});
2058 }
2059
2060 /// Build and insert \p Res = G_FADD \p Op0, \p Op1
2061 MachineInstrBuilder buildFAdd(const DstOp &Dst, const SrcOp &Src0,
2062 const SrcOp &Src1,
2063 std::optional<unsigned> Flags = std::nullopt) {
2064 return buildInstr(TargetOpcode::G_FADD, {Dst}, {Src0, Src1}, Flags);
2065 }
2066
2067 /// Build and insert \p Res = G_STRICT_FADD \p Op0, \p Op1
2069 buildStrictFAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
2070 std::optional<unsigned> Flags = std::nullopt) {
2071 return buildInstr(TargetOpcode::G_STRICT_FADD, {Dst}, {Src0, Src1}, Flags);
2072 }
2073
2074 /// Build and insert \p Res = G_FSUB \p Op0, \p Op1
2075 MachineInstrBuilder buildFSub(const DstOp &Dst, const SrcOp &Src0,
2076 const SrcOp &Src1,
2077 std::optional<unsigned> Flags = std::nullopt) {
2078 return buildInstr(TargetOpcode::G_FSUB, {Dst}, {Src0, Src1}, Flags);
2079 }
2080
2081 /// Build and insert \p Res = G_FDIV \p Op0, \p Op1
2082 MachineInstrBuilder buildFDiv(const DstOp &Dst, const SrcOp &Src0,
2083 const SrcOp &Src1,
2084 std::optional<unsigned> Flags = std::nullopt) {
2085 return buildInstr(TargetOpcode::G_FDIV, {Dst}, {Src0, Src1}, Flags);
2086 }
2087
2088 /// Build and insert \p Res = G_FMA \p Op0, \p Op1, \p Op2
2089 MachineInstrBuilder buildFMA(const DstOp &Dst, const SrcOp &Src0,
2090 const SrcOp &Src1, const SrcOp &Src2,
2091 std::optional<unsigned> Flags = std::nullopt) {
2092 return buildInstr(TargetOpcode::G_FMA, {Dst}, {Src0, Src1, Src2}, Flags);
2093 }
2094
2095 /// Build and insert \p Res = G_FMAD \p Op0, \p Op1, \p Op2
2096 MachineInstrBuilder buildFMAD(const DstOp &Dst, const SrcOp &Src0,
2097 const SrcOp &Src1, const SrcOp &Src2,
2098 std::optional<unsigned> Flags = std::nullopt) {
2099 return buildInstr(TargetOpcode::G_FMAD, {Dst}, {Src0, Src1, Src2}, Flags);
2100 }
2101
2102 /// Build and insert \p Res = G_FNEG \p Op0
2103 MachineInstrBuilder buildFNeg(const DstOp &Dst, const SrcOp &Src0,
2104 std::optional<unsigned> Flags = std::nullopt) {
2105 return buildInstr(TargetOpcode::G_FNEG, {Dst}, {Src0}, Flags);
2106 }
2107
2108 /// Build and insert \p Res = G_FABS \p Op0
2109 MachineInstrBuilder buildFAbs(const DstOp &Dst, const SrcOp &Src0,
2110 std::optional<unsigned> Flags = std::nullopt) {
2111 return buildInstr(TargetOpcode::G_FABS, {Dst}, {Src0}, Flags);
2112 }
2113
2114 /// Build and insert \p Dst = G_FCANONICALIZE \p Src0
2116 buildFCanonicalize(const DstOp &Dst, const SrcOp &Src0,
2117 std::optional<unsigned> Flags = std::nullopt) {
2118 return buildInstr(TargetOpcode::G_FCANONICALIZE, {Dst}, {Src0}, Flags);
2119 }
2120
2121 /// Build and insert \p Dst = G_INTRINSIC_TRUNC \p Src0
2123 buildIntrinsicTrunc(const DstOp &Dst, const SrcOp &Src0,
2124 std::optional<unsigned> Flags = std::nullopt) {
2125 return buildInstr(TargetOpcode::G_INTRINSIC_TRUNC, {Dst}, {Src0}, Flags);
2126 }
2127
2128 /// Build and insert \p Res = GFFLOOR \p Op0, \p Op1
2130 buildFFloor(const DstOp &Dst, const SrcOp &Src0,
2131 std::optional<unsigned> Flags = std::nullopt) {
2132 return buildInstr(TargetOpcode::G_FFLOOR, {Dst}, {Src0}, Flags);
2133 }
2134
2135 /// Build and insert \p Dst = G_FLOG \p Src
2137 std::optional<unsigned> Flags = std::nullopt) {
2138 return buildInstr(TargetOpcode::G_FLOG, {Dst}, {Src}, Flags);
2139 }
2140
2141 /// Build and insert \p Dst = G_FLOG2 \p Src
2143 std::optional<unsigned> Flags = std::nullopt) {
2144 return buildInstr(TargetOpcode::G_FLOG2, {Dst}, {Src}, Flags);
2145 }
2146
2147 /// Build and insert \p Dst = G_FEXP2 \p Src
2149 std::optional<unsigned> Flags = std::nullopt) {
2150 return buildInstr(TargetOpcode::G_FEXP2, {Dst}, {Src}, Flags);
2151 }
2152
2153 /// Build and insert \p Dst = G_FPOW \p Src0, \p Src1
2154 MachineInstrBuilder buildFPow(const DstOp &Dst, const SrcOp &Src0,
2155 const SrcOp &Src1,
2156 std::optional<unsigned> Flags = std::nullopt) {
2157 return buildInstr(TargetOpcode::G_FPOW, {Dst}, {Src0, Src1}, Flags);
2158 }
2159
2160 /// Build and insert \p Dst = G_FLDEXP \p Src0, \p Src1
2162 buildFLdexp(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
2163 std::optional<unsigned> Flags = std::nullopt) {
2164 return buildInstr(TargetOpcode::G_FLDEXP, {Dst}, {Src0, Src1}, Flags);
2165 }
2166
2167 /// Build and insert \p Fract, \p Exp = G_FFREXP \p Src
2169 buildFFrexp(const DstOp &Fract, const DstOp &Exp, const SrcOp &Src,
2170 std::optional<unsigned> Flags = std::nullopt) {
2171 return buildInstr(TargetOpcode::G_FFREXP, {Fract, Exp}, {Src}, Flags);
2172 }
2173
2174 /// Build and insert \p Sin, \p Cos = G_FSINCOS \p Src
2176 buildFSincos(const DstOp &Sin, const DstOp &Cos, const SrcOp &Src,
2177 std::optional<unsigned> Flags = std::nullopt) {
2178 return buildInstr(TargetOpcode::G_FSINCOS, {Sin, Cos}, {Src}, Flags);
2179 }
2180
2181 /// Build and insert \p Fract, \p Int = G_FMODF \p Src
2183 const SrcOp &Src,
2184 std::optional<unsigned> Flags = std::nullopt) {
2185 return buildInstr(TargetOpcode::G_FMODF, {Fract, Int}, {Src}, Flags);
2186 }
2187
2188 /// Build and insert \p Res = G_FCOPYSIGN \p Op0, \p Op1
2190 buildFCopysign(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
2191 std::optional<unsigned> Flags = std::nullopt) {
2192 return buildInstr(TargetOpcode::G_FCOPYSIGN, {Dst}, {Src0, Src1}, Flags);
2193 }
2194
2195 /// Build and insert \p Res = G_UITOFP \p Src0
2196 MachineInstrBuilder buildUITOFP(const DstOp &Dst, const SrcOp &Src0) {
2197 return buildInstr(TargetOpcode::G_UITOFP, {Dst}, {Src0});
2198 }
2199
2200 /// Build and insert \p Res = G_SITOFP \p Src0
2201 MachineInstrBuilder buildSITOFP(const DstOp &Dst, const SrcOp &Src0) {
2202 return buildInstr(TargetOpcode::G_SITOFP, {Dst}, {Src0});
2203 }
2204
2205 /// Build and insert \p Res = G_FPTOUI \p Src0
2206 MachineInstrBuilder buildFPTOUI(const DstOp &Dst, const SrcOp &Src0) {
2207 return buildInstr(TargetOpcode::G_FPTOUI, {Dst}, {Src0});
2208 }
2209
2210 /// Build and insert \p Res = G_FPTOSI \p Src0
2211 MachineInstrBuilder buildFPTOSI(const DstOp &Dst, const SrcOp &Src0) {
2212 return buildInstr(TargetOpcode::G_FPTOSI, {Dst}, {Src0});
2213 }
2214
2215 /// Build and insert \p Res = G_FPTOUI_SAT \p Src0
2217 return buildInstr(TargetOpcode::G_FPTOUI_SAT, {Dst}, {Src0});
2218 }
2219
2220 /// Build and insert \p Res = G_FPTOSI_SAT \p Src0
2222 return buildInstr(TargetOpcode::G_FPTOSI_SAT, {Dst}, {Src0});
2223 }
2224
2225 /// Build and insert \p Dst = G_FRINT \p Src0
2227 std::optional<unsigned> Flags = std::nullopt) {
2228 return buildInstr(TargetOpcode::G_FRINT, {Dst}, {Src0}, Flags);
2229 }
2230
2231 /// Build and insert \p Dst = G_INTRINSIC_ROUNDEVEN \p Src0, \p Src1
2233 buildIntrinsicRoundeven(const DstOp &Dst, const SrcOp &Src0,
2234 std::optional<unsigned> Flags = std::nullopt) {
2235 return buildInstr(TargetOpcode::G_INTRINSIC_ROUNDEVEN, {Dst}, {Src0},
2236 Flags);
2237 }
2238
2239 /// Build and insert \p Res = G_SMIN \p Op0, \p Op1
2240 MachineInstrBuilder buildSMin(const DstOp &Dst, const SrcOp &Src0,
2241 const SrcOp &Src1) {
2242 return buildInstr(TargetOpcode::G_SMIN, {Dst}, {Src0, Src1});
2243 }
2244
2245 /// Build and insert \p Res = G_SMAX \p Op0, \p Op1
2246 MachineInstrBuilder buildSMax(const DstOp &Dst, const SrcOp &Src0,
2247 const SrcOp &Src1) {
2248 return buildInstr(TargetOpcode::G_SMAX, {Dst}, {Src0, Src1});
2249 }
2250
2251 /// Build and insert \p Res = G_UMIN \p Op0, \p Op1
2252 MachineInstrBuilder buildUMin(const DstOp &Dst, const SrcOp &Src0,
2253 const SrcOp &Src1) {
2254 return buildInstr(TargetOpcode::G_UMIN, {Dst}, {Src0, Src1});
2255 }
2256
2257 /// Build and insert \p Res = G_UMAX \p Op0, \p Op1
2258 MachineInstrBuilder buildUMax(const DstOp &Dst, const SrcOp &Src0,
2259 const SrcOp &Src1) {
2260 return buildInstr(TargetOpcode::G_UMAX, {Dst}, {Src0, Src1});
2261 }
2262
2263 /// Build and insert \p Dst = G_ABS \p Src
2264 MachineInstrBuilder buildAbs(const DstOp &Dst, const SrcOp &Src) {
2265 return buildInstr(TargetOpcode::G_ABS, {Dst}, {Src});
2266 }
2267
2268 /// Build and insert \p Res = G_JUMP_TABLE \p JTI
2269 ///
2270 /// G_JUMP_TABLE sets \p Res to the address of the jump table specified by
2271 /// the jump table index \p JTI.
2272 ///
2273 /// \return a MachineInstrBuilder for the newly created instruction.
2274 MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI);
2275
2276 /// Build and insert \p Res = G_VECREDUCE_SEQ_FADD \p ScalarIn, \p VecIn
2277 ///
2278 /// \p ScalarIn is the scalar accumulator input to start the sequential
2279 /// reduction operation of \p VecIn.
2281 const SrcOp &ScalarIn,
2282 const SrcOp &VecIn) {
2283 return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FADD, {Dst},
2284 {ScalarIn, {VecIn}});
2285 }
2286
2287 /// Build and insert \p Res = G_VECREDUCE_SEQ_FMUL \p ScalarIn, \p VecIn
2288 ///
2289 /// \p ScalarIn is the scalar accumulator input to start the sequential
2290 /// reduction operation of \p VecIn.
2292 const SrcOp &ScalarIn,
2293 const SrcOp &VecIn) {
2294 return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FMUL, {Dst},
2295 {ScalarIn, {VecIn}});
2296 }
2297
2298 /// Build and insert \p Res = G_VECREDUCE_FADD \p Src
2299 ///
2300 /// \p ScalarIn is the scalar accumulator input to the reduction operation of
2301 /// \p VecIn.
2303 const SrcOp &ScalarIn,
2304 const SrcOp &VecIn) {
2305 return buildInstr(TargetOpcode::G_VECREDUCE_FADD, {Dst}, {ScalarIn, VecIn});
2306 }
2307
2308 /// Build and insert \p Res = G_VECREDUCE_FMUL \p Src
2309 ///
2310 /// \p ScalarIn is the scalar accumulator input to the reduction operation of
2311 /// \p VecIn.
2313 const SrcOp &ScalarIn,
2314 const SrcOp &VecIn) {
2315 return buildInstr(TargetOpcode::G_VECREDUCE_FMUL, {Dst}, {ScalarIn, VecIn});
2316 }
2317
2318 /// Build and insert \p Res = G_VECREDUCE_FMAX \p Src
2320 return buildInstr(TargetOpcode::G_VECREDUCE_FMAX, {Dst}, {Src});
2321 }
2322
2323 /// Build and insert \p Res = G_VECREDUCE_FMIN \p Src
2325 return buildInstr(TargetOpcode::G_VECREDUCE_FMIN, {Dst}, {Src});
2326 }
2327
2328 /// Build and insert \p Res = G_VECREDUCE_FMAXIMUM \p Src
2330 const SrcOp &Src) {
2331 return buildInstr(TargetOpcode::G_VECREDUCE_FMAXIMUM, {Dst}, {Src});
2332 }
2333
2334 /// Build and insert \p Res = G_VECREDUCE_FMINIMUM \p Src
2336 const SrcOp &Src) {
2337 return buildInstr(TargetOpcode::G_VECREDUCE_FMINIMUM, {Dst}, {Src});
2338 }
2339
2340 /// Build and insert \p Res = G_VECREDUCE_ADD \p Src
2342 return buildInstr(TargetOpcode::G_VECREDUCE_ADD, {Dst}, {Src});
2343 }
2344
2345 /// Build and insert \p Res = G_VECREDUCE_MUL \p Src
2347 return buildInstr(TargetOpcode::G_VECREDUCE_MUL, {Dst}, {Src});
2348 }
2349
2350 /// Build and insert \p Res = G_VECREDUCE_AND \p Src
2352 return buildInstr(TargetOpcode::G_VECREDUCE_AND, {Dst}, {Src});
2353 }
2354
2355 /// Build and insert \p Res = G_VECREDUCE_OR \p Src
2357 return buildInstr(TargetOpcode::G_VECREDUCE_OR, {Dst}, {Src});
2358 }
2359
2360 /// Build and insert \p Res = G_VECREDUCE_XOR \p Src
2362 return buildInstr(TargetOpcode::G_VECREDUCE_XOR, {Dst}, {Src});
2363 }
2364
2365 /// Build and insert \p Res = G_VECREDUCE_SMAX \p Src
2367 return buildInstr(TargetOpcode::G_VECREDUCE_SMAX, {Dst}, {Src});
2368 }
2369
2370 /// Build and insert \p Res = G_VECREDUCE_SMIN \p Src
2372 return buildInstr(TargetOpcode::G_VECREDUCE_SMIN, {Dst}, {Src});
2373 }
2374
2375 /// Build and insert \p Res = G_VECREDUCE_UMAX \p Src
2377 return buildInstr(TargetOpcode::G_VECREDUCE_UMAX, {Dst}, {Src});
2378 }
2379
2380 /// Build and insert \p Res = G_VECREDUCE_UMIN \p Src
2382 return buildInstr(TargetOpcode::G_VECREDUCE_UMIN, {Dst}, {Src});
2383 }
2384
2385 /// Build and insert G_MEMCPY or G_MEMMOVE
2386 MachineInstrBuilder buildMemTransferInst(unsigned Opcode, const SrcOp &DstPtr,
2387 const SrcOp &SrcPtr,
2388 const SrcOp &Size,
2389 MachineMemOperand &DstMMO,
2390 MachineMemOperand &SrcMMO) {
2391 auto MIB = buildInstr(
2392 Opcode, {}, {DstPtr, SrcPtr, Size, SrcOp(INT64_C(0) /*isTailCall*/)});
2393 MIB.addMemOperand(&DstMMO);
2394 MIB.addMemOperand(&SrcMMO);
2395 return MIB;
2396 }
2397
2398 MachineInstrBuilder buildMemCpy(const SrcOp &DstPtr, const SrcOp &SrcPtr,
2399 const SrcOp &Size, MachineMemOperand &DstMMO,
2400 MachineMemOperand &SrcMMO) {
2401 return buildMemTransferInst(TargetOpcode::G_MEMCPY, DstPtr, SrcPtr, Size,
2402 DstMMO, SrcMMO);
2403 }
2404
2405 /// Build and insert G_TRAP or G_DEBUGTRAP
2407 return buildInstr(Debug ? TargetOpcode::G_DEBUGTRAP : TargetOpcode::G_TRAP);
2408 }
2409
2410 /// Build and insert \p Dst = G_SBFX \p Src, \p LSB, \p Width.
2412 const SrcOp &LSB, const SrcOp &Width) {
2413 return buildInstr(TargetOpcode::G_SBFX, {Dst}, {Src, LSB, Width});
2414 }
2415
2416 /// Build and insert \p Dst = G_UBFX \p Src, \p LSB, \p Width.
2418 const SrcOp &LSB, const SrcOp &Width) {
2419 return buildInstr(TargetOpcode::G_UBFX, {Dst}, {Src, LSB, Width});
2420 }
2421
2422 /// Build and insert \p Dst = G_ROTR \p Src, \p Amt
2424 const SrcOp &Amt) {
2425 return buildInstr(TargetOpcode::G_ROTR, {Dst}, {Src, Amt});
2426 }
2427
2428 /// Build and insert \p Dst = G_ROTL \p Src, \p Amt
2430 const SrcOp &Amt) {
2431 return buildInstr(TargetOpcode::G_ROTL, {Dst}, {Src, Amt});
2432 }
2433
2434 /// Build and insert \p Dst = G_BITREVERSE \p Src
2436 return buildInstr(TargetOpcode::G_BITREVERSE, {Dst}, {Src});
2437 }
2438
2439 /// Build and insert \p Dst = G_GET_FPENV
2441 return buildInstr(TargetOpcode::G_GET_FPENV, {Dst}, {});
2442 }
2443
2444 /// Build and insert G_SET_FPENV \p Src
2446 return buildInstr(TargetOpcode::G_SET_FPENV, {}, {Src});
2447 }
2448
2449 /// Build and insert G_RESET_FPENV
2451 return buildInstr(TargetOpcode::G_RESET_FPENV, {}, {});
2452 }
2453
2454 /// Build and insert \p Dst = G_GET_FPMODE
2456 return buildInstr(TargetOpcode::G_GET_FPMODE, {Dst}, {});
2457 }
2458
2459 /// Build and insert G_SET_FPMODE \p Src
2461 return buildInstr(TargetOpcode::G_SET_FPMODE, {}, {Src});
2462 }
2463
2464 /// Build and insert G_RESET_FPMODE
2466 return buildInstr(TargetOpcode::G_RESET_FPMODE, {}, {});
2467 }
2468
2469 /// Build and insert \p Dst = G_GET_ROUNDING
2471 return buildInstr(TargetOpcode::G_GET_ROUNDING, {Dst}, {});
2472 }
2473
2474 /// Build and insert G_SET_ROUNDING
2476 return buildInstr(TargetOpcode::G_SET_ROUNDING, {}, {Src});
2477 }
2478
2479 virtual MachineInstrBuilder
2480 buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps, ArrayRef<SrcOp> SrcOps,
2481 std::optional<unsigned> Flags = std::nullopt);
2482};
2483
2484} // End namespace llvm.
2485#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:127
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:1087
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:775
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.