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