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