LLVM 19.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"
24
25namespace llvm {
26
27// Forward declarations.
28class APInt;
29class BlockAddress;
30class Constant;
31class ConstantFP;
32class ConstantInt;
33class DataLayout;
34class GISelCSEInfo;
35class GlobalValue;
36class TargetRegisterClass;
37class MachineFunction;
38class MachineInstr;
39class TargetInstrInfo;
40class GISelChangeObserver;
41
42/// Class which stores all the state required in a MachineIRBuilder.
43/// Since MachineIRBuilders will only store state in this object, it allows
44/// to transfer BuilderState between different kinds of MachineIRBuilders.
46 /// MachineFunction under construction.
47 MachineFunction *MF = nullptr;
48 /// Information used to access the description of the opcodes.
49 const TargetInstrInfo *TII = nullptr;
50 /// Information used to verify types are consistent and to create virtual registers.
52 /// Debug location to be set to any instruction we create.
54 /// PC sections metadata to be set to any instruction we create.
55 MDNode *PCSections = nullptr;
56
57 /// \name Fields describing the insertion point.
58 /// @{
61 /// @}
62
64
66};
67
68class DstOp {
69 union {
73 };
74
75public:
76 enum class DstType { Ty_LLT, Ty_Reg, Ty_RC };
77 DstOp(unsigned R) : Reg(R), Ty(DstType::Ty_Reg) {}
78 DstOp(Register R) : Reg(R), Ty(DstType::Ty_Reg) {}
80 DstOp(const LLT T) : LLTTy(T), Ty(DstType::Ty_LLT) {}
81 DstOp(const TargetRegisterClass *TRC) : RC(TRC), Ty(DstType::Ty_RC) {}
82
84 switch (Ty) {
85 case DstType::Ty_Reg:
86 MIB.addDef(Reg);
87 break;
88 case DstType::Ty_LLT:
89 MIB.addDef(MRI.createGenericVirtualRegister(LLTTy));
90 break;
91 case DstType::Ty_RC:
92 MIB.addDef(MRI.createVirtualRegister(RC));
93 break;
94 }
95 }
96
98 switch (Ty) {
99 case DstType::Ty_RC:
100 return LLT{};
101 case DstType::Ty_LLT:
102 return LLTTy;
103 case DstType::Ty_Reg:
104 return MRI.getType(Reg);
105 }
106 llvm_unreachable("Unrecognised DstOp::DstType enum");
107 }
108
109 Register getReg() const {
110 assert(Ty == DstType::Ty_Reg && "Not a register");
111 return Reg;
112 }
113
115 switch (Ty) {
116 case DstType::Ty_RC:
117 return RC;
118 default:
119 llvm_unreachable("Not a RC Operand");
120 }
121 }
122
123 DstType getDstOpKind() const { return Ty; }
124
125private:
126 DstType Ty;
127};
128
129class SrcOp {
130 union {
134 int64_t Imm;
135 };
136
137public:
139 SrcOp(Register R) : Reg(R), Ty(SrcType::Ty_Reg) {}
141 SrcOp(const MachineInstrBuilder &MIB) : SrcMIB(MIB), Ty(SrcType::Ty_MIB) {}
143 /// Use of registers held in unsigned integer variables (or more rarely signed
144 /// integers) is no longer permitted to avoid ambiguity with upcoming support
145 /// for immediates.
146 SrcOp(unsigned) = delete;
147 SrcOp(int) = delete;
148 SrcOp(uint64_t V) : Imm(V), Ty(SrcType::Ty_Imm) {}
149 SrcOp(int64_t V) : Imm(V), Ty(SrcType::Ty_Imm) {}
150
152 switch (Ty) {
154 MIB.addPredicate(Pred);
155 break;
156 case SrcType::Ty_Reg:
157 MIB.addUse(Reg);
158 break;
159 case SrcType::Ty_MIB:
160 MIB.addUse(SrcMIB->getOperand(0).getReg());
161 break;
162 case SrcType::Ty_Imm:
163 MIB.addImm(Imm);
164 break;
165 }
166 }
167
169 switch (Ty) {
171 case SrcType::Ty_Imm:
172 llvm_unreachable("Not a register operand");
173 case SrcType::Ty_Reg:
174 return MRI.getType(Reg);
175 case SrcType::Ty_MIB:
176 return MRI.getType(SrcMIB->getOperand(0).getReg());
177 }
178 llvm_unreachable("Unrecognised SrcOp::SrcType enum");
179 }
180
181 Register getReg() const {
182 switch (Ty) {
184 case SrcType::Ty_Imm:
185 llvm_unreachable("Not a register operand");
186 case SrcType::Ty_Reg:
187 return Reg;
188 case SrcType::Ty_MIB:
189 return SrcMIB->getOperand(0).getReg();
190 }
191 llvm_unreachable("Unrecognised SrcOp::SrcType enum");
192 }
193
195 switch (Ty) {
197 return Pred;
198 default:
199 llvm_unreachable("Not a register operand");
200 }
201 }
202
203 int64_t getImm() const {
204 switch (Ty) {
205 case SrcType::Ty_Imm:
206 return Imm;
207 default:
208 llvm_unreachable("Not an immediate");
209 }
210 }
211
212 SrcType getSrcOpKind() const { return Ty; }
213
214private:
215 SrcType Ty;
216};
217
218/// Helper class to build MachineInstr.
219/// It keeps internally the insertion point and debug location for all
220/// the new instructions we want to create.
221/// This information can be modified via the related setters.
223
225
226 unsigned getOpcodeForMerge(const DstOp &DstOp, ArrayRef<SrcOp> SrcOps) const;
227
228protected:
229 void validateTruncExt(const LLT Dst, const LLT Src, bool IsExtend);
230
231 void validateUnaryOp(const LLT Res, const LLT Op0);
232 void validateBinaryOp(const LLT Res, const LLT Op0, const LLT Op1);
233 void validateShiftOp(const LLT Res, const LLT Op0, const LLT Op1);
234
235 void validateSelectOp(const LLT ResTy, const LLT TstTy, const LLT Op0Ty,
236 const LLT Op1Ty);
237
238 void recordInsertion(MachineInstr *InsertedInstr) const {
239 if (State.Observer)
240 State.Observer->createdInstr(*InsertedInstr);
241 }
242
243public:
244 /// Some constructors for easy use.
245 MachineIRBuilder() = default;
247
249 setMF(*MBB.getParent());
250 setInsertPt(MBB, InsPt);
251 }
252
254 MachineIRBuilder(*MI.getParent(), MI.getIterator()) {
255 setInstr(MI);
256 setDebugLoc(MI.getDebugLoc());
257 }
258
261 setChangeObserver(Observer);
262 }
263
264 virtual ~MachineIRBuilder() = default;
265
266 MachineIRBuilder(const MachineIRBuilderState &BState) : State(BState) {}
267
269 assert(State.TII && "TargetInstrInfo is not set");
270 return *State.TII;
271 }
272
273 /// Getter for the function we currently build.
275 assert(State.MF && "MachineFunction is not set");
276 return *State.MF;
277 }
278
279 const MachineFunction &getMF() const {
280 assert(State.MF && "MachineFunction is not set");
281 return *State.MF;
282 }
283
284 const DataLayout &getDataLayout() const {
286 }
287
289 return getMF().getFunction().getContext();
290 }
291
292 /// Getter for DebugLoc
293 const DebugLoc &getDL() { return State.DL; }
294
295 /// Getter for MRI
296 MachineRegisterInfo *getMRI() { return State.MRI; }
297 const MachineRegisterInfo *getMRI() const { return State.MRI; }
298
299 /// Getter for the State
300 MachineIRBuilderState &getState() { return State; }
301
302 /// Setter for the State
303 void setState(const MachineIRBuilderState &NewState) { State = NewState; }
304
305 /// Getter for the basic block we currently build.
306 const MachineBasicBlock &getMBB() const {
307 assert(State.MBB && "MachineBasicBlock is not set");
308 return *State.MBB;
309 }
310
312 return const_cast<MachineBasicBlock &>(
313 const_cast<const MachineIRBuilder *>(this)->getMBB());
314 }
315
316 GISelCSEInfo *getCSEInfo() { return State.CSEInfo; }
317 const GISelCSEInfo *getCSEInfo() const { return State.CSEInfo; }
318
319 /// Current insertion point for new instructions.
321
322 /// Set the insertion point before the specified position.
323 /// \pre MBB must be in getMF().
324 /// \pre II must be a valid iterator in MBB.
326 assert(MBB.getParent() == &getMF() &&
327 "Basic block is in a different function");
328 State.MBB = &MBB;
329 State.II = II;
330 }
331
332 /// @}
333
335
336 /// \name Setters for the insertion point.
337 /// @{
338 /// Set the MachineFunction where to build instructions.
339 void setMF(MachineFunction &MF);
340
341 /// Set the insertion point to the end of \p MBB.
342 /// \pre \p MBB must be contained by getMF().
344 State.MBB = &MBB;
345 State.II = MBB.end();
346 assert(&getMF() == MBB.getParent() &&
347 "Basic block is in a different function");
348 }
349
350 /// Set the insertion point to before MI.
351 /// \pre MI must be in getMF().
353 assert(MI.getParent() && "Instruction is not part of a basic block");
354 setMBB(*MI.getParent());
355 State.II = MI.getIterator();
356 setPCSections(MI.getPCSections());
357 }
358 /// @}
359
360 /// Set the insertion point to before MI, and set the debug loc to MI's loc.
361 /// \pre MI must be in getMF().
363 setInstr(MI);
364 setDebugLoc(MI.getDebugLoc());
365 }
366
368 State.Observer = &Observer;
369 }
370
372
373 void stopObservingChanges() { State.Observer = nullptr; }
374
375 bool isObservingChanges() const { return State.Observer != nullptr; }
376 /// @}
377
378 /// Set the debug location to \p DL for all the next build instructions.
379 void setDebugLoc(const DebugLoc &DL) { this->State.DL = DL; }
380
381 /// Get the current instruction's debug location.
382 const DebugLoc &getDebugLoc() { return State.DL; }
383
384 /// Set the PC sections metadata to \p MD for all the next build instructions.
385 void setPCSections(MDNode *MD) { State.PCSections = MD; }
386
387 /// Get the current instruction's PC sections metadata.
388 MDNode *getPCSections() { return State.PCSections; }
389
390 /// Build and insert <empty> = \p Opcode <empty>.
391 /// The insertion point is the one set by the last call of either
392 /// setBasicBlock or setMI.
393 ///
394 /// \pre setBasicBlock or setMI must have been called.
395 ///
396 /// \return a MachineInstrBuilder for the newly created instruction.
398 return insertInstr(buildInstrNoInsert(Opcode));
399 }
400
401 /// Build but don't insert <empty> = \p Opcode <empty>.
402 ///
403 /// \pre setMF, setBasicBlock or setMI must have been called.
404 ///
405 /// \return a MachineInstrBuilder for the newly created instruction.
407
408 /// Insert an existing instruction at the insertion point.
410
411 /// Build and insert a DBG_VALUE instruction expressing the fact that the
412 /// associated \p Variable lives in \p Reg (suitably modified by \p Expr).
414 const MDNode *Expr);
415
416 /// Build and insert a DBG_VALUE instruction expressing the fact that the
417 /// associated \p Variable lives in memory at \p Reg (suitably modified by \p
418 /// Expr).
420 const MDNode *Variable,
421 const MDNode *Expr);
422
423 /// Build and insert a DBG_VALUE instruction expressing the fact that the
424 /// associated \p Variable lives in the stack slot specified by \p FI
425 /// (suitably modified by \p Expr).
426 MachineInstrBuilder buildFIDbgValue(int FI, const MDNode *Variable,
427 const MDNode *Expr);
428
429 /// Build and insert a DBG_VALUE instructions specifying that \p Variable is
430 /// given by \p C (suitably modified by \p Expr).
432 const MDNode *Variable,
433 const MDNode *Expr);
434
435 /// Build and insert a DBG_LABEL instructions specifying that \p Label is
436 /// given. Convert "llvm.dbg.label Label" to "DBG_LABEL Label".
438
439 /// Build and insert \p Res = G_DYN_STACKALLOC \p Size, \p Align
440 ///
441 /// G_DYN_STACKALLOC does a dynamic stack allocation and writes the address of
442 /// the allocated memory into \p Res.
443 /// \pre setBasicBlock or setMI must have been called.
444 /// \pre \p Res must be a generic virtual register with pointer type.
445 ///
446 /// \return a MachineInstrBuilder for the newly created instruction.
448 Align Alignment);
449
450 /// Build and insert \p Res = G_FRAME_INDEX \p Idx
451 ///
452 /// G_FRAME_INDEX materializes the address of an alloca value or other
453 /// stack-based object.
454 ///
455 /// \pre setBasicBlock or setMI must have been called.
456 /// \pre \p Res must be a generic virtual register with pointer type.
457 ///
458 /// \return a MachineInstrBuilder for the newly created instruction.
460
461 /// Build and insert \p Res = G_GLOBAL_VALUE \p GV
462 ///
463 /// G_GLOBAL_VALUE materializes the address of the specified global
464 /// into \p Res.
465 ///
466 /// \pre setBasicBlock or setMI must have been called.
467 /// \pre \p Res must be a generic virtual register with pointer type
468 /// in the same address space as \p GV.
469 ///
470 /// \return a MachineInstrBuilder for the newly created instruction.
472
473 /// Build and insert \p Res = G_CONSTANT_POOL \p Idx
474 ///
475 /// G_CONSTANT_POOL materializes the address of an object in the constant
476 /// pool.
477 ///
478 /// \pre setBasicBlock or setMI must have been called.
479 /// \pre \p Res must be a generic virtual register with pointer type.
480 ///
481 /// \return a MachineInstrBuilder for the newly created instruction.
482 MachineInstrBuilder buildConstantPool(const DstOp &Res, unsigned Idx);
483
484 /// Build and insert \p Res = G_PTR_ADD \p Op0, \p Op1
485 ///
486 /// G_PTR_ADD adds \p Op1 addressible units to the pointer specified by \p Op0,
487 /// storing the resulting pointer in \p Res. Addressible units are typically
488 /// bytes but this can vary between targets.
489 ///
490 /// \pre setBasicBlock or setMI must have been called.
491 /// \pre \p Res and \p Op0 must be generic virtual registers with pointer
492 /// type.
493 /// \pre \p Op1 must be a generic virtual register with scalar type.
494 ///
495 /// \return a MachineInstrBuilder for the newly created instruction.
496 MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0,
497 const SrcOp &Op1,
498 std::optional<unsigned> Flags = std::nullopt);
499
500 /// Materialize and insert \p Res = G_PTR_ADD \p Op0, (G_CONSTANT \p Value)
501 ///
502 /// G_PTR_ADD adds \p Value bytes to the pointer specified by \p Op0,
503 /// storing the resulting pointer in \p Res. If \p Value is zero then no
504 /// G_PTR_ADD or G_CONSTANT will be created and \pre Op0 will be assigned to
505 /// \p Res.
506 ///
507 /// \pre setBasicBlock or setMI must have been called.
508 /// \pre \p Op0 must be a generic virtual register with pointer type.
509 /// \pre \p ValueTy must be a scalar type.
510 /// \pre \p Res must be 0. This is to detect confusion between
511 /// materializePtrAdd() and buildPtrAdd().
512 /// \post \p Res will either be a new generic virtual register of the same
513 /// type as \p Op0 or \p Op0 itself.
514 ///
515 /// \return a MachineInstrBuilder for the newly created instruction.
516 std::optional<MachineInstrBuilder> materializePtrAdd(Register &Res,
517 Register Op0,
518 const LLT ValueTy,
520
521 /// Build and insert \p Res = G_PTRMASK \p Op0, \p Op1
523 const SrcOp &Op1) {
524 return buildInstr(TargetOpcode::G_PTRMASK, {Res}, {Op0, Op1});
525 }
526
527 /// Build and insert \p Res = G_PTRMASK \p Op0, \p G_CONSTANT (1 << NumBits) - 1
528 ///
529 /// This clears the low bits of a pointer operand without destroying its
530 /// pointer properties. This has the effect of rounding the address *down* to
531 /// a specified alignment in bits.
532 ///
533 /// \pre setBasicBlock or setMI must have been called.
534 /// \pre \p Res and \p Op0 must be generic virtual registers with pointer
535 /// type.
536 /// \pre \p NumBits must be an integer representing the number of low bits to
537 /// be cleared in \p Op0.
538 ///
539 /// \return a MachineInstrBuilder for the newly created instruction.
540 MachineInstrBuilder buildMaskLowPtrBits(const DstOp &Res, const SrcOp &Op0,
541 uint32_t NumBits);
542
543 /// Build and insert
544 /// a, b, ..., x = G_UNMERGE_VALUES \p Op0
545 /// \p Res = G_BUILD_VECTOR a, b, ..., x, undef, ..., undef
546 ///
547 /// Pad \p Op0 with undef elements to match number of elements in \p Res.
548 ///
549 /// \pre setBasicBlock or setMI must have been called.
550 /// \pre \p Res and \p Op0 must be generic virtual registers with vector type,
551 /// same vector element type and Op0 must have fewer elements then Res.
552 ///
553 /// \return a MachineInstrBuilder for the newly created build vector instr.
555 const SrcOp &Op0);
556
557 /// Build and insert
558 /// a, b, ..., x, y, z = G_UNMERGE_VALUES \p Op0
559 /// \p Res = G_BUILD_VECTOR a, b, ..., x
560 ///
561 /// Delete trailing elements in \p Op0 to match number of elements in \p Res.
562 ///
563 /// \pre setBasicBlock or setMI must have been called.
564 /// \pre \p Res and \p Op0 must be generic virtual registers with vector type,
565 /// same vector element type and Op0 must have more elements then Res.
566 ///
567 /// \return a MachineInstrBuilder for the newly created build vector instr.
569 const SrcOp &Op0);
570
571 /// Build and insert \p Res, \p CarryOut = G_UADDO \p Op0, \p Op1
572 ///
573 /// G_UADDO sets \p Res to \p Op0 + \p Op1 (truncated to the bit width) and
574 /// sets \p CarryOut to 1 if the result overflowed in unsigned arithmetic.
575 ///
576 /// \pre setBasicBlock or setMI must have been called.
577 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers with the
578 /// same scalar type.
579 ////\pre \p CarryOut must be generic virtual register with scalar type
580 ///(typically s1)
581 ///
582 /// \return The newly created instruction.
583 MachineInstrBuilder buildUAddo(const DstOp &Res, const DstOp &CarryOut,
584 const SrcOp &Op0, const SrcOp &Op1) {
585 return buildInstr(TargetOpcode::G_UADDO, {Res, CarryOut}, {Op0, Op1});
586 }
587
588 /// Build and insert \p Res, \p CarryOut = G_USUBO \p Op0, \p Op1
589 MachineInstrBuilder buildUSubo(const DstOp &Res, const DstOp &CarryOut,
590 const SrcOp &Op0, const SrcOp &Op1) {
591 return buildInstr(TargetOpcode::G_USUBO, {Res, CarryOut}, {Op0, Op1});
592 }
593
594 /// Build and insert \p Res, \p CarryOut = G_SADDO \p Op0, \p Op1
595 MachineInstrBuilder buildSAddo(const DstOp &Res, const DstOp &CarryOut,
596 const SrcOp &Op0, const SrcOp &Op1) {
597 return buildInstr(TargetOpcode::G_SADDO, {Res, CarryOut}, {Op0, Op1});
598 }
599
600 /// Build and insert \p Res, \p CarryOut = G_SUBO \p Op0, \p Op1
601 MachineInstrBuilder buildSSubo(const DstOp &Res, const DstOp &CarryOut,
602 const SrcOp &Op0, const SrcOp &Op1) {
603 return buildInstr(TargetOpcode::G_SSUBO, {Res, CarryOut}, {Op0, Op1});
604 }
605
606 /// Build and insert \p Res, \p CarryOut = G_UADDE \p Op0,
607 /// \p Op1, \p CarryIn
608 ///
609 /// G_UADDE sets \p Res to \p Op0 + \p Op1 + \p CarryIn (truncated to the bit
610 /// width) and sets \p CarryOut to 1 if the result overflowed in unsigned
611 /// arithmetic.
612 ///
613 /// \pre setBasicBlock or setMI must have been called.
614 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
615 /// with the same scalar type.
616 /// \pre \p CarryOut and \p CarryIn must be generic virtual
617 /// registers with the same scalar type (typically s1)
618 ///
619 /// \return The newly created instruction.
620 MachineInstrBuilder buildUAdde(const DstOp &Res, const DstOp &CarryOut,
621 const SrcOp &Op0, const SrcOp &Op1,
622 const SrcOp &CarryIn) {
623 return buildInstr(TargetOpcode::G_UADDE, {Res, CarryOut},
624 {Op0, Op1, CarryIn});
625 }
626
627 /// Build and insert \p Res, \p CarryOut = G_USUBE \p Op0, \p Op1, \p CarryInp
628 MachineInstrBuilder buildUSube(const DstOp &Res, const DstOp &CarryOut,
629 const SrcOp &Op0, const SrcOp &Op1,
630 const SrcOp &CarryIn) {
631 return buildInstr(TargetOpcode::G_USUBE, {Res, CarryOut},
632 {Op0, Op1, CarryIn});
633 }
634
635 /// Build and insert \p Res, \p CarryOut = G_SADDE \p Op0, \p Op1, \p CarryInp
636 MachineInstrBuilder buildSAdde(const DstOp &Res, const DstOp &CarryOut,
637 const SrcOp &Op0, const SrcOp &Op1,
638 const SrcOp &CarryIn) {
639 return buildInstr(TargetOpcode::G_SADDE, {Res, CarryOut},
640 {Op0, Op1, CarryIn});
641 }
642
643 /// Build and insert \p Res, \p CarryOut = G_SSUBE \p Op0, \p Op1, \p CarryInp
644 MachineInstrBuilder buildSSube(const DstOp &Res, const DstOp &CarryOut,
645 const SrcOp &Op0, const SrcOp &Op1,
646 const SrcOp &CarryIn) {
647 return buildInstr(TargetOpcode::G_SSUBE, {Res, CarryOut},
648 {Op0, Op1, CarryIn});
649 }
650
651 /// Build and insert \p Res = G_ANYEXT \p Op0
652 ///
653 /// G_ANYEXT produces a register of the specified width, with bits 0 to
654 /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are unspecified
655 /// (i.e. this is neither zero nor sign-extension). For a vector register,
656 /// each element is extended individually.
657 ///
658 /// \pre setBasicBlock or setMI must have been called.
659 /// \pre \p Res must be a generic virtual register with scalar or vector type.
660 /// \pre \p Op must be a generic virtual register with scalar or vector type.
661 /// \pre \p Op must be smaller than \p Res
662 ///
663 /// \return The newly created instruction.
664
665 MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op);
666
667 /// Build and insert \p Res = G_SEXT \p Op
668 ///
669 /// G_SEXT produces a register of the specified width, with bits 0 to
670 /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are duplicated from the
671 /// high bit of \p Op (i.e. 2s-complement sign extended).
672 ///
673 /// \pre setBasicBlock or setMI must have been called.
674 /// \pre \p Res must be a generic virtual register with scalar or vector type.
675 /// \pre \p Op must be a generic virtual register with scalar or vector type.
676 /// \pre \p Op must be smaller than \p Res
677 ///
678 /// \return The newly created instruction.
679 MachineInstrBuilder buildSExt(const DstOp &Res, const SrcOp &Op);
680
681 /// Build and insert \p Res = G_SEXT_INREG \p Op, ImmOp
682 MachineInstrBuilder buildSExtInReg(const DstOp &Res, const SrcOp &Op, int64_t ImmOp) {
683 return buildInstr(TargetOpcode::G_SEXT_INREG, {Res}, {Op, SrcOp(ImmOp)});
684 }
685
686 /// Build and insert \p Res = G_FPEXT \p Op
688 std::optional<unsigned> Flags = std::nullopt) {
689 return buildInstr(TargetOpcode::G_FPEXT, {Res}, {Op}, Flags);
690 }
691
692 /// Build and insert a G_PTRTOINT instruction.
694 return buildInstr(TargetOpcode::G_PTRTOINT, {Dst}, {Src});
695 }
696
697 /// Build and insert a G_INTTOPTR instruction.
699 return buildInstr(TargetOpcode::G_INTTOPTR, {Dst}, {Src});
700 }
701
702 /// Build and insert \p Dst = G_BITCAST \p Src
703 MachineInstrBuilder buildBitcast(const DstOp &Dst, const SrcOp &Src) {
704 return buildInstr(TargetOpcode::G_BITCAST, {Dst}, {Src});
705 }
706
707 /// Build and insert \p Dst = G_ADDRSPACE_CAST \p Src
709 return buildInstr(TargetOpcode::G_ADDRSPACE_CAST, {Dst}, {Src});
710 }
711
712 /// \return The opcode of the extension the target wants to use for boolean
713 /// values.
714 unsigned getBoolExtOp(bool IsVec, bool IsFP) const;
715
716 // Build and insert \p Res = G_ANYEXT \p Op, \p Res = G_SEXT \p Op, or \p Res
717 // = G_ZEXT \p Op depending on how the target wants to extend boolean values.
718 MachineInstrBuilder buildBoolExt(const DstOp &Res, const SrcOp &Op,
719 bool IsFP);
720
721 // Build and insert \p Res = G_SEXT_INREG \p Op, 1 or \p Res = G_AND \p Op, 1,
722 // or COPY depending on how the target wants to extend boolean values, using
723 // the original register size.
725 bool IsVector,
726 bool IsFP);
727
728 /// Build and insert \p Res = G_ZEXT \p Op
729 ///
730 /// G_ZEXT produces a register of the specified width, with bits 0 to
731 /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are 0. For a vector
732 /// register, each element is extended individually.
733 ///
734 /// \pre setBasicBlock or setMI must have been called.
735 /// \pre \p Res must be a generic virtual register with scalar or vector type.
736 /// \pre \p Op must be a generic virtual register with scalar or vector type.
737 /// \pre \p Op must be smaller than \p Res
738 ///
739 /// \return The newly created instruction.
740 MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op);
741
742 /// Build and insert \p Res = G_SEXT \p Op, \p Res = G_TRUNC \p Op, or
743 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
744 /// ///
745 /// \pre setBasicBlock or setMI must have been called.
746 /// \pre \p Res must be a generic virtual register with scalar or vector type.
747 /// \pre \p Op must be a generic virtual register with scalar or vector type.
748 ///
749 /// \return The newly created instruction.
751
752 /// Build and insert \p Res = G_ZEXT \p Op, \p Res = G_TRUNC \p Op, or
753 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
754 /// ///
755 /// \pre setBasicBlock or setMI must have been called.
756 /// \pre \p Res must be a generic virtual register with scalar or vector type.
757 /// \pre \p Op must be a generic virtual register with scalar or vector type.
758 ///
759 /// \return The newly created instruction.
761
762 // Build and insert \p Res = G_ANYEXT \p Op, \p Res = G_TRUNC \p Op, or
763 /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op.
764 /// ///
765 /// \pre setBasicBlock or setMI must have been called.
766 /// \pre \p Res must be a generic virtual register with scalar or vector type.
767 /// \pre \p Op must be a generic virtual register with scalar or vector type.
768 ///
769 /// \return The newly created instruction.
771
772 /// Build and insert \p Res = \p ExtOpc, \p Res = G_TRUNC \p
773 /// Op, or \p Res = COPY \p Op depending on the differing sizes of \p Res and
774 /// \p Op.
775 /// ///
776 /// \pre setBasicBlock or setMI must have been called.
777 /// \pre \p Res must be a generic virtual register with scalar or vector type.
778 /// \pre \p Op must be a generic virtual register with scalar or vector type.
779 ///
780 /// \return The newly created instruction.
781 MachineInstrBuilder buildExtOrTrunc(unsigned ExtOpc, const DstOp &Res,
782 const SrcOp &Op);
783
784 /// Build and inserts \p Res = \p G_AND \p Op, \p LowBitsSet(ImmOp)
785 /// Since there is no G_ZEXT_INREG like G_SEXT_INREG, the instruction is
786 /// emulated using G_AND.
788 int64_t ImmOp);
789
790 /// Build and insert an appropriate cast between two registers of equal size.
791 MachineInstrBuilder buildCast(const DstOp &Dst, const SrcOp &Src);
792
793 /// Build and insert G_BR \p Dest
794 ///
795 /// G_BR is an unconditional branch to \p Dest.
796 ///
797 /// \pre setBasicBlock or setMI must have been called.
798 ///
799 /// \return a MachineInstrBuilder for the newly created instruction.
801
802 /// Build and insert G_BRCOND \p Tst, \p Dest
803 ///
804 /// G_BRCOND is a conditional branch to \p Dest.
805 ///
806 /// \pre setBasicBlock or setMI must have been called.
807 /// \pre \p Tst must be a generic virtual register with scalar
808 /// type. At the beginning of legalization, this will be a single
809 /// bit (s1). Targets with interesting flags registers may change
810 /// this. For a wider type, whether the branch is taken must only
811 /// depend on bit 0 (for now).
812 ///
813 /// \return The newly created instruction.
815
816 /// Build and insert G_BRINDIRECT \p Tgt
817 ///
818 /// G_BRINDIRECT is an indirect branch to \p Tgt.
819 ///
820 /// \pre setBasicBlock or setMI must have been called.
821 /// \pre \p Tgt must be a generic virtual register with pointer type.
822 ///
823 /// \return a MachineInstrBuilder for the newly created instruction.
825
826 /// Build and insert G_BRJT \p TablePtr, \p JTI, \p IndexReg
827 ///
828 /// G_BRJT is a jump table branch using a table base pointer \p TablePtr,
829 /// jump table index \p JTI and index \p IndexReg
830 ///
831 /// \pre setBasicBlock or setMI must have been called.
832 /// \pre \p TablePtr must be a generic virtual register with pointer type.
833 /// \pre \p JTI must be a jump table index.
834 /// \pre \p IndexReg must be a generic virtual register with pointer type.
835 ///
836 /// \return a MachineInstrBuilder for the newly created instruction.
837 MachineInstrBuilder buildBrJT(Register TablePtr, unsigned JTI,
838 Register IndexReg);
839
840 /// Build and insert \p Res = G_CONSTANT \p Val
841 ///
842 /// G_CONSTANT is an integer constant with the specified size and value. \p
843 /// Val will be extended or truncated to the size of \p Reg.
844 ///
845 /// \pre setBasicBlock or setMI must have been called.
846 /// \pre \p Res must be a generic virtual register with scalar or pointer
847 /// type.
848 ///
849 /// \return The newly created instruction.
850 virtual MachineInstrBuilder buildConstant(const DstOp &Res,
851 const ConstantInt &Val);
852
853 /// Build and insert \p Res = G_CONSTANT \p Val
854 ///
855 /// G_CONSTANT is an integer constant with the specified size and value.
856 ///
857 /// \pre setBasicBlock or setMI must have been called.
858 /// \pre \p Res must be a generic virtual register with scalar type.
859 ///
860 /// \return The newly created instruction.
861 MachineInstrBuilder buildConstant(const DstOp &Res, int64_t Val);
862 MachineInstrBuilder buildConstant(const DstOp &Res, const APInt &Val);
863
864 /// Build and insert \p Res = G_FCONSTANT \p Val
865 ///
866 /// G_FCONSTANT is a floating-point constant with the specified size and
867 /// value.
868 ///
869 /// \pre setBasicBlock or setMI must have been called.
870 /// \pre \p Res must be a generic virtual register with scalar type.
871 ///
872 /// \return The newly created instruction.
873 virtual MachineInstrBuilder buildFConstant(const DstOp &Res,
874 const ConstantFP &Val);
875
876 MachineInstrBuilder buildFConstant(const DstOp &Res, double Val);
877 MachineInstrBuilder buildFConstant(const DstOp &Res, const APFloat &Val);
878
879 /// Build and insert \p Res = COPY Op
880 ///
881 /// Register-to-register COPY sets \p Res to \p Op.
882 ///
883 /// \pre setBasicBlock or setMI must have been called.
884 ///
885 /// \return a MachineInstrBuilder for the newly created instruction.
886 MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op);
887
888
889 /// Build and insert G_ASSERT_SEXT, G_ASSERT_ZEXT, or G_ASSERT_ALIGN
890 ///
891 /// \return a MachineInstrBuilder for the newly created instruction.
893 const SrcOp &Op, unsigned Val) {
894 return buildInstr(Opc, Res, Op).addImm(Val);
895 }
896
897 /// Build and insert \p Res = G_ASSERT_ZEXT Op, Size
898 ///
899 /// \return a MachineInstrBuilder for the newly created instruction.
901 unsigned Size) {
902 return buildAssertInstr(TargetOpcode::G_ASSERT_ZEXT, Res, Op, Size);
903 }
904
905 /// Build and insert \p Res = G_ASSERT_SEXT Op, Size
906 ///
907 /// \return a MachineInstrBuilder for the newly created instruction.
909 unsigned Size) {
910 return buildAssertInstr(TargetOpcode::G_ASSERT_SEXT, Res, Op, Size);
911 }
912
913 /// Build and insert \p Res = G_ASSERT_ALIGN Op, AlignVal
914 ///
915 /// \return a MachineInstrBuilder for the newly created instruction.
917 Align AlignVal) {
918 return buildAssertInstr(TargetOpcode::G_ASSERT_ALIGN, Res, Op,
919 AlignVal.value());
920 }
921
922 /// Build and insert `Res = G_LOAD Addr, MMO`.
923 ///
924 /// Loads the value stored at \p Addr. Puts the result in \p Res.
925 ///
926 /// \pre setBasicBlock or setMI must have been called.
927 /// \pre \p Res must be a generic virtual register.
928 /// \pre \p Addr must be a generic virtual register with pointer type.
929 ///
930 /// \return a MachineInstrBuilder for the newly created instruction.
932 MachineMemOperand &MMO) {
933 return buildLoadInstr(TargetOpcode::G_LOAD, Res, Addr, MMO);
934 }
935
936 /// Build and insert a G_LOAD instruction, while constructing the
937 /// MachineMemOperand.
939 buildLoad(const DstOp &Res, const SrcOp &Addr, MachinePointerInfo PtrInfo,
940 Align Alignment,
942 const AAMDNodes &AAInfo = AAMDNodes());
943
944 /// Build and insert `Res = <opcode> Addr, MMO`.
945 ///
946 /// Loads the value stored at \p Addr. Puts the result in \p Res.
947 ///
948 /// \pre setBasicBlock or setMI must have been called.
949 /// \pre \p Res must be a generic virtual register.
950 /// \pre \p Addr must be a generic virtual register with pointer type.
951 ///
952 /// \return a MachineInstrBuilder for the newly created instruction.
953 MachineInstrBuilder buildLoadInstr(unsigned Opcode, const DstOp &Res,
954 const SrcOp &Addr, MachineMemOperand &MMO);
955
956 /// Helper to create a load from a constant offset given a base address. Load
957 /// the type of \p Dst from \p Offset from the given base address and memory
958 /// operand.
960 const SrcOp &BasePtr,
961 MachineMemOperand &BaseMMO,
962 int64_t Offset);
963
964 /// Build and insert `G_STORE Val, Addr, MMO`.
965 ///
966 /// Stores the value \p Val to \p Addr.
967 ///
968 /// \pre setBasicBlock or setMI must have been called.
969 /// \pre \p Val must be a generic virtual register.
970 /// \pre \p Addr must be a generic virtual register with pointer type.
971 ///
972 /// \return a MachineInstrBuilder for the newly created instruction.
973 MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr,
974 MachineMemOperand &MMO);
975
976 /// Build and insert a G_STORE instruction, while constructing the
977 /// MachineMemOperand.
979 buildStore(const SrcOp &Val, const SrcOp &Addr, MachinePointerInfo PtrInfo,
980 Align Alignment,
982 const AAMDNodes &AAInfo = AAMDNodes());
983
984 /// Build and insert `Res0, ... = G_EXTRACT Src, Idx0`.
985 ///
986 /// \pre setBasicBlock or setMI must have been called.
987 /// \pre \p Res and \p Src must be generic virtual registers.
988 ///
989 /// \return a MachineInstrBuilder for the newly created instruction.
990 MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index);
991
992 /// Build and insert \p Res = IMPLICIT_DEF.
994
995 /// Build and insert \p Res = G_MERGE_VALUES \p Op0, ...
996 ///
997 /// G_MERGE_VALUES combines the input elements contiguously into a larger
998 /// register. It should only be used when the destination register is not a
999 /// vector.
1000 ///
1001 /// \pre setBasicBlock or setMI must have been called.
1002 /// \pre The entire register \p Res (and no more) must be covered by the input
1003 /// registers.
1004 /// \pre The type of all \p Ops registers must be identical.
1005 ///
1006 /// \return a MachineInstrBuilder for the newly created instruction.
1008 ArrayRef<Register> Ops);
1009
1010 /// Build and insert \p Res = G_MERGE_VALUES \p Op0, ...
1011 /// or \p Res = G_BUILD_VECTOR \p Op0, ...
1012 /// or \p Res = G_CONCAT_VECTORS \p Op0, ...
1013 ///
1014 /// G_MERGE_VALUES combines the input elements contiguously into a larger
1015 /// register. It is used when the destination register is not a vector.
1016 /// G_BUILD_VECTOR combines scalar inputs into a vector register.
1017 /// G_CONCAT_VECTORS combines vector inputs into a vector register.
1018 ///
1019 /// \pre setBasicBlock or setMI must have been called.
1020 /// \pre The entire register \p Res (and no more) must be covered by the input
1021 /// registers.
1022 /// \pre The type of all \p Ops registers must be identical.
1023 ///
1024 /// \return a MachineInstrBuilder for the newly created instruction. The
1025 /// opcode of the new instruction will depend on the types of both
1026 /// the destination and the sources.
1028 ArrayRef<Register> Ops);
1030 std::initializer_list<SrcOp> Ops);
1031
1032 /// Build and insert \p Res0, ... = G_UNMERGE_VALUES \p Op
1033 ///
1034 /// G_UNMERGE_VALUES splits contiguous bits of the input into multiple
1035 ///
1036 /// \pre setBasicBlock or setMI must have been called.
1037 /// \pre The entire register \p Res (and no more) must be covered by the input
1038 /// registers.
1039 /// \pre The type of all \p Res registers must be identical.
1040 ///
1041 /// \return a MachineInstrBuilder for the newly created instruction.
1044
1045 /// Build and insert an unmerge of \p Res sized pieces to cover \p Op
1047
1048 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ...
1049 ///
1050 /// G_BUILD_VECTOR creates a vector value from multiple scalar registers.
1051 /// \pre setBasicBlock or setMI must have been called.
1052 /// \pre The entire register \p Res (and no more) must be covered by the
1053 /// input scalar registers.
1054 /// \pre The type of all \p Ops registers must be identical.
1055 ///
1056 /// \return a MachineInstrBuilder for the newly created instruction.
1058 ArrayRef<Register> Ops);
1059
1060 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ... where each OpN is
1061 /// built with G_CONSTANT.
1063 ArrayRef<APInt> Ops);
1064
1065 /// Build and insert \p Res = G_BUILD_VECTOR with \p Src replicated to fill
1066 /// the number of elements
1067 MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src);
1068
1069 /// Build and insert \p Res = G_BUILD_VECTOR_TRUNC \p Op0, ...
1070 ///
1071 /// G_BUILD_VECTOR_TRUNC creates a vector value from multiple scalar registers
1072 /// which have types larger than the destination vector element type, and
1073 /// truncates the values to fit.
1074 ///
1075 /// If the operands given are already the same size as the vector elt type,
1076 /// then this method will instead create a G_BUILD_VECTOR instruction.
1077 ///
1078 /// \pre setBasicBlock or setMI must have been called.
1079 /// \pre The type of all \p Ops registers must be identical.
1080 ///
1081 /// \return a MachineInstrBuilder for the newly created instruction.
1083 ArrayRef<Register> Ops);
1084
1085 /// Build and insert a vector splat of a scalar \p Src using a
1086 /// G_INSERT_VECTOR_ELT and G_SHUFFLE_VECTOR idiom.
1087 ///
1088 /// \pre setBasicBlock or setMI must have been called.
1089 /// \pre \p Src must have the same type as the element type of \p Dst
1090 ///
1091 /// \return a MachineInstrBuilder for the newly created instruction.
1092 MachineInstrBuilder buildShuffleSplat(const DstOp &Res, const SrcOp &Src);
1093
1094 /// Build and insert \p Res = G_SHUFFLE_VECTOR \p Src1, \p Src2, \p Mask
1095 ///
1096 /// \pre setBasicBlock or setMI must have been called.
1097 ///
1098 /// \return a MachineInstrBuilder for the newly created instruction.
1099 MachineInstrBuilder buildShuffleVector(const DstOp &Res, const SrcOp &Src1,
1100 const SrcOp &Src2, ArrayRef<int> Mask);
1101
1102 /// Build and insert \p Res = G_SPLAT_VECTOR \p Val
1103 ///
1104 /// \pre setBasicBlock or setMI must have been called.
1105 /// \pre \p Res must be a generic virtual register with vector type.
1106 /// \pre \p Val must be a generic virtual register with scalar type.
1107 ///
1108 /// \return a MachineInstrBuilder for the newly created instruction.
1109 MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Val);
1110
1111 /// Build and insert \p Res = G_CONCAT_VECTORS \p Op0, ...
1112 ///
1113 /// G_CONCAT_VECTORS creates a vector from the concatenation of 2 or more
1114 /// vectors.
1115 ///
1116 /// \pre setBasicBlock or setMI must have been called.
1117 /// \pre The entire register \p Res (and no more) must be covered by the input
1118 /// registers.
1119 /// \pre The type of all source operands must be identical.
1120 ///
1121 /// \return a MachineInstrBuilder for the newly created instruction.
1123 ArrayRef<Register> Ops);
1124
1125 /// Build and insert `Res = G_INSERT_SUBVECTOR Src0, Src1, Idx`.
1126 ///
1127 /// \pre setBasicBlock or setMI must have been called.
1128 /// \pre \p Res, \p Src0, and \p Src1 must be generic virtual registers with
1129 /// vector type.
1130 ///
1131 /// \return a MachineInstrBuilder for the newly created instruction.
1132 MachineInstrBuilder buildInsertSubvector(const DstOp &Res, const SrcOp &Src0,
1133 const SrcOp &Src1, unsigned Index);
1134
1135 /// Build and insert `Res = G_EXTRACT_SUBVECTOR Src, Idx0`.
1136 ///
1137 /// \pre setBasicBlock or setMI must have been called.
1138 /// \pre \p Res and \p Src must be generic virtual registers with vector type.
1139 ///
1140 /// \return a MachineInstrBuilder for the newly created instruction.
1142 unsigned Index);
1143
1144 MachineInstrBuilder buildInsert(const DstOp &Res, const SrcOp &Src,
1145 const SrcOp &Op, unsigned Index);
1146
1147 /// Build and insert \p Res = G_VSCALE \p MinElts
1148 ///
1149 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1150 /// into \p Res.
1151 ///
1152 /// \pre setBasicBlock or setMI must have been called.
1153 /// \pre \p Res must be a generic virtual register with scalar type.
1154 ///
1155 /// \return a MachineInstrBuilder for the newly created instruction.
1156 MachineInstrBuilder buildVScale(const DstOp &Res, unsigned MinElts);
1157
1158 /// Build and insert \p Res = G_VSCALE \p MinElts
1159 ///
1160 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1161 /// into \p Res.
1162 ///
1163 /// \pre setBasicBlock or setMI must have been called.
1164 /// \pre \p Res must be a generic virtual register with scalar type.
1165 ///
1166 /// \return a MachineInstrBuilder for the newly created instruction.
1167 MachineInstrBuilder buildVScale(const DstOp &Res, const ConstantInt &MinElts);
1168
1169 /// Build and insert \p Res = G_VSCALE \p MinElts
1170 ///
1171 /// G_VSCALE puts the value of the runtime vscale multiplied by \p MinElts
1172 /// into \p Res.
1173 ///
1174 /// \pre setBasicBlock or setMI must have been called.
1175 /// \pre \p Res must be a generic virtual register with scalar type.
1176 ///
1177 /// \return a MachineInstrBuilder for the newly created instruction.
1178 MachineInstrBuilder buildVScale(const DstOp &Res, const APInt &MinElts);
1179
1180 /// Build and insert a G_INTRINSIC instruction.
1181 ///
1182 /// There are four different opcodes based on combinations of whether the
1183 /// intrinsic has side effects and whether it is convergent. These properties
1184 /// can be specified as explicit parameters, or else they are retrieved from
1185 /// the MCID for the intrinsic.
1186 ///
1187 /// The parameter \p Res provides the Registers or MOs that will be defined by
1188 /// this instruction.
1189 ///
1190 /// \pre setBasicBlock or setMI must have been called.
1191 ///
1192 /// \return a MachineInstrBuilder for the newly created instruction.
1194 bool HasSideEffects, bool isConvergent);
1197 bool HasSideEffects, bool isConvergent);
1199
1200 /// Build and insert \p Res = G_FPTRUNC \p Op
1201 ///
1202 /// G_FPTRUNC converts a floating-point value into one with a smaller type.
1203 ///
1204 /// \pre setBasicBlock or setMI must have been called.
1205 /// \pre \p Res must be a generic virtual register with scalar or vector type.
1206 /// \pre \p Op must be a generic virtual register with scalar or vector type.
1207 /// \pre \p Res must be smaller than \p Op
1208 ///
1209 /// \return The newly created instruction.
1211 buildFPTrunc(const DstOp &Res, const SrcOp &Op,
1212 std::optional<unsigned> Flags = std::nullopt);
1213
1214 /// Build and insert \p Res = G_TRUNC \p Op
1215 ///
1216 /// G_TRUNC extracts the low bits of a type. For a vector type each element is
1217 /// truncated independently before being packed into the destination.
1218 ///
1219 /// \pre setBasicBlock or setMI must have been called.
1220 /// \pre \p Res must be a generic virtual register with scalar or vector type.
1221 /// \pre \p Op must be a generic virtual register with scalar or vector type.
1222 /// \pre \p Res must be smaller than \p Op
1223 ///
1224 /// \return The newly created instruction.
1225 MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op);
1226
1227 /// Build and insert a \p Res = G_ICMP \p Pred, \p Op0, \p Op1
1228 ///
1229 /// \pre setBasicBlock or setMI must have been called.
1230
1231 /// \pre \p Res must be a generic virtual register with scalar or
1232 /// vector type. Typically this starts as s1 or <N x s1>.
1233 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1234 /// same number of elements as \p Res. If \p Res is a scalar,
1235 /// \p Op0 must be either a scalar or pointer.
1236 /// \pre \p Pred must be an integer predicate.
1237 ///
1238 /// \return a MachineInstrBuilder for the newly created instruction.
1240 const SrcOp &Op0, const SrcOp &Op1);
1241
1242 /// Build and insert a \p Res = G_FCMP \p Pred\p Op0, \p Op1
1243 ///
1244 /// \pre setBasicBlock or setMI must have been called.
1245
1246 /// \pre \p Res must be a generic virtual register with scalar or
1247 /// vector type. Typically this starts as s1 or <N x s1>.
1248 /// \pre \p Op0 and Op1 must be generic virtual registers with the
1249 /// same number of elements as \p Res (or scalar, if \p Res is
1250 /// scalar).
1251 /// \pre \p Pred must be a floating-point predicate.
1252 ///
1253 /// \return a MachineInstrBuilder for the newly created instruction.
1255 const SrcOp &Op0, const SrcOp &Op1,
1256 std::optional<unsigned> Flags = std::nullopt);
1257
1258 /// Build and insert a \p Res = G_IS_FPCLASS \p Src, \p Mask
1260 unsigned Mask) {
1261 return buildInstr(TargetOpcode::G_IS_FPCLASS, {Res},
1262 {Src, SrcOp(static_cast<int64_t>(Mask))});
1263 }
1264
1265 /// Build and insert a \p Res = G_SELECT \p Tst, \p Op0, \p Op1
1266 ///
1267 /// \pre setBasicBlock or setMI must have been called.
1268 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1269 /// with the same type.
1270 /// \pre \p Tst must be a generic virtual register with scalar, pointer or
1271 /// vector type. If vector then it must have the same number of
1272 /// elements as the other parameters.
1273 ///
1274 /// \return a MachineInstrBuilder for the newly created instruction.
1275 MachineInstrBuilder buildSelect(const DstOp &Res, const SrcOp &Tst,
1276 const SrcOp &Op0, const SrcOp &Op1,
1277 std::optional<unsigned> Flags = std::nullopt);
1278
1279 /// Build and insert \p Res = G_INSERT_VECTOR_ELT \p Val,
1280 /// \p Elt, \p Idx
1281 ///
1282 /// \pre setBasicBlock or setMI must have been called.
1283 /// \pre \p Res and \p Val must be a generic virtual register
1284 // with the same vector type.
1285 /// \pre \p Elt and \p Idx must be a generic virtual register
1286 /// with scalar type.
1287 ///
1288 /// \return The newly created instruction.
1290 const SrcOp &Val,
1291 const SrcOp &Elt,
1292 const SrcOp &Idx);
1293
1294 /// Build and insert \p Res = G_EXTRACT_VECTOR_ELT \p Val, \p Idx
1295 ///
1296 /// \pre setBasicBlock or setMI must have been called.
1297 /// \pre \p Res must be a generic virtual register with scalar type.
1298 /// \pre \p Val must be a generic virtual register with vector type.
1299 ///
1300 /// \return The newly created instruction.
1302 const SrcOp &Val,
1303 const int Idx) {
1304 auto TLI = getMF().getSubtarget().getTargetLowering();
1305 unsigned VecIdxWidth = TLI->getVectorIdxTy(getDataLayout()).getSizeInBits();
1307 Res, Val, buildConstant(LLT::scalar(VecIdxWidth), Idx));
1308 }
1309
1310 /// Build and insert \p Res = G_EXTRACT_VECTOR_ELT \p Val, \p Idx
1311 ///
1312 /// \pre setBasicBlock or setMI must have been called.
1313 /// \pre \p Res must be a generic virtual register with scalar type.
1314 /// \pre \p Val must be a generic virtual register with vector type.
1315 /// \pre \p Idx must be a generic virtual register with scalar type.
1316 ///
1317 /// \return The newly created instruction.
1319 const SrcOp &Val,
1320 const SrcOp &Idx);
1321
1322 /// Build and insert `OldValRes<def>, SuccessRes<def> =
1323 /// G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr, CmpVal, NewVal, MMO`.
1324 ///
1325 /// Atomically replace the value at \p Addr with \p NewVal if it is currently
1326 /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p
1327 /// Addr in \p Res, along with an s1 indicating whether it was replaced.
1328 ///
1329 /// \pre setBasicBlock or setMI must have been called.
1330 /// \pre \p OldValRes must be a generic virtual register of scalar type.
1331 /// \pre \p SuccessRes must be a generic virtual register of scalar type. It
1332 /// will be assigned 0 on failure and 1 on success.
1333 /// \pre \p Addr must be a generic virtual register with pointer type.
1334 /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual
1335 /// registers of the same type.
1336 ///
1337 /// \return a MachineInstrBuilder for the newly created instruction.
1339 buildAtomicCmpXchgWithSuccess(const DstOp &OldValRes, const DstOp &SuccessRes,
1340 const SrcOp &Addr, const SrcOp &CmpVal,
1341 const SrcOp &NewVal, MachineMemOperand &MMO);
1342
1343 /// Build and insert `OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal,
1344 /// MMO`.
1345 ///
1346 /// Atomically replace the value at \p Addr with \p NewVal if it is currently
1347 /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p
1348 /// Addr in \p Res.
1349 ///
1350 /// \pre setBasicBlock or setMI must have been called.
1351 /// \pre \p OldValRes must be a generic virtual register of scalar type.
1352 /// \pre \p Addr must be a generic virtual register with pointer type.
1353 /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual
1354 /// registers of the same type.
1355 ///
1356 /// \return a MachineInstrBuilder for the newly created instruction.
1358 const SrcOp &Addr, const SrcOp &CmpVal,
1359 const SrcOp &NewVal,
1360 MachineMemOperand &MMO);
1361
1362 /// Build and insert `OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO`.
1363 ///
1364 /// Atomically read-modify-update the value at \p Addr with \p Val. Puts the
1365 /// original value from \p Addr in \p OldValRes. The modification is
1366 /// determined by the opcode.
1367 ///
1368 /// \pre setBasicBlock or setMI must have been called.
1369 /// \pre \p OldValRes must be a generic virtual register.
1370 /// \pre \p Addr must be a generic virtual register with pointer type.
1371 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1372 /// same type.
1373 ///
1374 /// \return a MachineInstrBuilder for the newly created instruction.
1375 MachineInstrBuilder buildAtomicRMW(unsigned Opcode, const DstOp &OldValRes,
1376 const SrcOp &Addr, const SrcOp &Val,
1377 MachineMemOperand &MMO);
1378
1379 /// Build and insert `OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO`.
1380 ///
1381 /// Atomically replace the value at \p Addr with \p Val. Puts the original
1382 /// value from \p Addr in \p OldValRes.
1383 ///
1384 /// \pre setBasicBlock or setMI must have been called.
1385 /// \pre \p OldValRes must be a generic virtual register.
1386 /// \pre \p Addr must be a generic virtual register with pointer type.
1387 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1388 /// same type.
1389 ///
1390 /// \return a MachineInstrBuilder for the newly created instruction.
1392 Register Val, MachineMemOperand &MMO);
1393
1394 /// Build and insert `OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO`.
1395 ///
1396 /// Atomically replace the value at \p Addr with the addition of \p Val and
1397 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1398 ///
1399 /// \pre setBasicBlock or setMI must have been called.
1400 /// \pre \p OldValRes must be a generic virtual register.
1401 /// \pre \p Addr must be a generic virtual register with pointer type.
1402 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1403 /// same type.
1404 ///
1405 /// \return a MachineInstrBuilder for the newly created instruction.
1407 Register Val, MachineMemOperand &MMO);
1408
1409 /// Build and insert `OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO`.
1410 ///
1411 /// Atomically replace the value at \p Addr with the subtraction of \p Val and
1412 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1413 ///
1414 /// \pre setBasicBlock or setMI must have been called.
1415 /// \pre \p OldValRes must be a generic virtual register.
1416 /// \pre \p Addr must be a generic virtual register with pointer type.
1417 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1418 /// same type.
1419 ///
1420 /// \return a MachineInstrBuilder for the newly created instruction.
1422 Register Val, MachineMemOperand &MMO);
1423
1424 /// Build and insert `OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO`.
1425 ///
1426 /// Atomically replace the value at \p Addr with the bitwise and of \p Val and
1427 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1428 ///
1429 /// \pre setBasicBlock or setMI must have been called.
1430 /// \pre \p OldValRes must be a generic virtual register.
1431 /// \pre \p Addr must be a generic virtual register with pointer type.
1432 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1433 /// same type.
1434 ///
1435 /// \return a MachineInstrBuilder for the newly created instruction.
1437 Register Val, MachineMemOperand &MMO);
1438
1439 /// Build and insert `OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO`.
1440 ///
1441 /// Atomically replace the value at \p Addr with the bitwise nand of \p Val
1442 /// and the original value. Puts the original value from \p Addr in \p
1443 /// OldValRes.
1444 ///
1445 /// \pre setBasicBlock or setMI must have been called.
1446 /// \pre \p OldValRes must be a generic virtual register.
1447 /// \pre \p Addr must be a generic virtual register with pointer type.
1448 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1449 /// same type.
1450 ///
1451 /// \return a MachineInstrBuilder for the newly created instruction.
1453 Register Val, MachineMemOperand &MMO);
1454
1455 /// Build and insert `OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO`.
1456 ///
1457 /// Atomically replace the value at \p Addr with the bitwise or of \p Val and
1458 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1459 ///
1460 /// \pre setBasicBlock or setMI must have been called.
1461 /// \pre \p OldValRes must be a generic virtual register.
1462 /// \pre \p Addr must be a generic virtual register with pointer type.
1463 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1464 /// same type.
1465 ///
1466 /// \return a MachineInstrBuilder for the newly created instruction.
1468 Register Val, MachineMemOperand &MMO);
1469
1470 /// Build and insert `OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO`.
1471 ///
1472 /// Atomically replace the value at \p Addr with the bitwise xor of \p Val and
1473 /// the original value. Puts the original value from \p Addr in \p OldValRes.
1474 ///
1475 /// \pre setBasicBlock or setMI must have been called.
1476 /// \pre \p OldValRes must be a generic virtual register.
1477 /// \pre \p Addr must be a generic virtual register with pointer type.
1478 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1479 /// same type.
1480 ///
1481 /// \return a MachineInstrBuilder for the newly created instruction.
1483 Register Val, MachineMemOperand &MMO);
1484
1485 /// Build and insert `OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO`.
1486 ///
1487 /// Atomically replace the value at \p Addr with the signed maximum of \p
1488 /// Val and the original value. Puts the original value from \p Addr in \p
1489 /// OldValRes.
1490 ///
1491 /// \pre setBasicBlock or setMI must have been called.
1492 /// \pre \p OldValRes must be a generic virtual register.
1493 /// \pre \p Addr must be a generic virtual register with pointer type.
1494 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1495 /// same type.
1496 ///
1497 /// \return a MachineInstrBuilder for the newly created instruction.
1499 Register Val, MachineMemOperand &MMO);
1500
1501 /// Build and insert `OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO`.
1502 ///
1503 /// Atomically replace the value at \p Addr with the signed minimum of \p
1504 /// Val and the original value. Puts the original value from \p Addr in \p
1505 /// OldValRes.
1506 ///
1507 /// \pre setBasicBlock or setMI must have been called.
1508 /// \pre \p OldValRes must be a generic virtual register.
1509 /// \pre \p Addr must be a generic virtual register with pointer type.
1510 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1511 /// same type.
1512 ///
1513 /// \return a MachineInstrBuilder for the newly created instruction.
1515 Register Val, MachineMemOperand &MMO);
1516
1517 /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO`.
1518 ///
1519 /// Atomically replace the value at \p Addr with the unsigned maximum of \p
1520 /// Val and the original value. Puts the original value from \p Addr in \p
1521 /// OldValRes.
1522 ///
1523 /// \pre setBasicBlock or setMI must have been called.
1524 /// \pre \p OldValRes must be a generic virtual register.
1525 /// \pre \p Addr must be a generic virtual register with pointer type.
1526 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1527 /// same type.
1528 ///
1529 /// \return a MachineInstrBuilder for the newly created instruction.
1531 Register Val, MachineMemOperand &MMO);
1532
1533 /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO`.
1534 ///
1535 /// Atomically replace the value at \p Addr with the unsigned minimum of \p
1536 /// Val and the original value. Puts the original value from \p Addr in \p
1537 /// OldValRes.
1538 ///
1539 /// \pre setBasicBlock or setMI must have been called.
1540 /// \pre \p OldValRes must be a generic virtual register.
1541 /// \pre \p Addr must be a generic virtual register with pointer type.
1542 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1543 /// same type.
1544 ///
1545 /// \return a MachineInstrBuilder for the newly created instruction.
1547 Register Val, MachineMemOperand &MMO);
1548
1549 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FADD Addr, Val, MMO`.
1551 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1552 MachineMemOperand &MMO);
1553
1554 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FSUB Addr, Val, MMO`.
1556 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1557 MachineMemOperand &MMO);
1558
1559 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMAX Addr, Val, MMO`.
1560 ///
1561 /// Atomically replace the value at \p Addr with the floating point maximum of
1562 /// \p Val and the original value. Puts the original value from \p Addr in \p
1563 /// OldValRes.
1564 ///
1565 /// \pre setBasicBlock or setMI must have been called.
1566 /// \pre \p OldValRes must be a generic virtual register.
1567 /// \pre \p Addr must be a generic virtual register with pointer type.
1568 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1569 /// same type.
1570 ///
1571 /// \return a MachineInstrBuilder for the newly created instruction.
1573 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1574 MachineMemOperand &MMO);
1575
1576 /// Build and insert `OldValRes<def> = G_ATOMICRMW_FMIN Addr, Val, MMO`.
1577 ///
1578 /// Atomically replace the value at \p Addr with the floating point minimum of
1579 /// \p Val and the original value. Puts the original value from \p Addr in \p
1580 /// OldValRes.
1581 ///
1582 /// \pre setBasicBlock or setMI must have been called.
1583 /// \pre \p OldValRes must be a generic virtual register.
1584 /// \pre \p Addr must be a generic virtual register with pointer type.
1585 /// \pre \p OldValRes, and \p Val must be generic virtual registers of the
1586 /// same type.
1587 ///
1588 /// \return a MachineInstrBuilder for the newly created instruction.
1590 const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val,
1591 MachineMemOperand &MMO);
1592
1593 /// Build and insert `G_FENCE Ordering, Scope`.
1594 MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope);
1595
1596 /// Build and insert G_PREFETCH \p Addr, \p RW, \p Locality, \p CacheType
1597 MachineInstrBuilder buildPrefetch(const SrcOp &Addr, unsigned RW,
1598 unsigned Locality, unsigned CacheType,
1599 MachineMemOperand &MMO);
1600
1601 /// Build and insert \p Dst = G_FREEZE \p Src
1602 MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src) {
1603 return buildInstr(TargetOpcode::G_FREEZE, {Dst}, {Src});
1604 }
1605
1606 /// Build and insert \p Res = G_BLOCK_ADDR \p BA
1607 ///
1608 /// G_BLOCK_ADDR computes the address of a basic block.
1609 ///
1610 /// \pre setBasicBlock or setMI must have been called.
1611 /// \pre \p Res must be a generic virtual register of a pointer type.
1612 ///
1613 /// \return The newly created instruction.
1615
1616 /// Build and insert \p Res = G_ADD \p Op0, \p Op1
1617 ///
1618 /// G_ADD sets \p Res to the sum of integer parameters \p Op0 and \p Op1,
1619 /// truncated to their width.
1620 ///
1621 /// \pre setBasicBlock or setMI must have been called.
1622 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1623 /// with the same (scalar or vector) type).
1624 ///
1625 /// \return a MachineInstrBuilder for the newly created instruction.
1626
1627 MachineInstrBuilder buildAdd(const DstOp &Dst, const SrcOp &Src0,
1628 const SrcOp &Src1,
1629 std::optional<unsigned> Flags = std::nullopt) {
1630 return buildInstr(TargetOpcode::G_ADD, {Dst}, {Src0, Src1}, Flags);
1631 }
1632
1633 /// Build and insert \p Res = G_SUB \p Op0, \p Op1
1634 ///
1635 /// G_SUB sets \p Res to the difference of integer parameters \p Op0 and
1636 /// \p Op1, truncated to their width.
1637 ///
1638 /// \pre setBasicBlock or setMI must have been called.
1639 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1640 /// with the same (scalar or vector) type).
1641 ///
1642 /// \return a MachineInstrBuilder for the newly created instruction.
1643
1644 MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0,
1645 const SrcOp &Src1,
1646 std::optional<unsigned> Flags = std::nullopt) {
1647 return buildInstr(TargetOpcode::G_SUB, {Dst}, {Src0, Src1}, Flags);
1648 }
1649
1650 /// Build and insert \p Res = G_MUL \p Op0, \p Op1
1651 ///
1652 /// G_MUL sets \p Res to the product of integer parameters \p Op0 and \p Op1,
1653 /// truncated to their width.
1654 ///
1655 /// \pre setBasicBlock or setMI must have been called.
1656 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1657 /// with the same (scalar or vector) type).
1658 ///
1659 /// \return a MachineInstrBuilder for the newly created instruction.
1660 MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0,
1661 const SrcOp &Src1,
1662 std::optional<unsigned> Flags = std::nullopt) {
1663 return buildInstr(TargetOpcode::G_MUL, {Dst}, {Src0, Src1}, Flags);
1664 }
1665
1667 const SrcOp &Src1,
1668 std::optional<unsigned> Flags = std::nullopt) {
1669 return buildInstr(TargetOpcode::G_UMULH, {Dst}, {Src0, Src1}, Flags);
1670 }
1671
1673 const SrcOp &Src1,
1674 std::optional<unsigned> Flags = std::nullopt) {
1675 return buildInstr(TargetOpcode::G_SMULH, {Dst}, {Src0, Src1}, Flags);
1676 }
1677
1678 /// Build and insert \p Res = G_UREM \p Op0, \p Op1
1679 MachineInstrBuilder buildURem(const DstOp &Dst, const SrcOp &Src0,
1680 const SrcOp &Src1,
1681 std::optional<unsigned> Flags = std::nullopt) {
1682 return buildInstr(TargetOpcode::G_UREM, {Dst}, {Src0, Src1}, Flags);
1683 }
1684
1685 MachineInstrBuilder buildFMul(const DstOp &Dst, const SrcOp &Src0,
1686 const SrcOp &Src1,
1687 std::optional<unsigned> Flags = std::nullopt) {
1688 return buildInstr(TargetOpcode::G_FMUL, {Dst}, {Src0, Src1}, Flags);
1689 }
1690
1692 buildFMinNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1693 std::optional<unsigned> Flags = std::nullopt) {
1694 return buildInstr(TargetOpcode::G_FMINNUM, {Dst}, {Src0, Src1}, Flags);
1695 }
1696
1698 buildFMaxNum(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1699 std::optional<unsigned> Flags = std::nullopt) {
1700 return buildInstr(TargetOpcode::G_FMAXNUM, {Dst}, {Src0, Src1}, Flags);
1701 }
1702
1704 buildFMinNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1705 std::optional<unsigned> Flags = std::nullopt) {
1706 return buildInstr(TargetOpcode::G_FMINNUM_IEEE, {Dst}, {Src0, Src1}, Flags);
1707 }
1708
1710 buildFMaxNumIEEE(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1711 std::optional<unsigned> Flags = std::nullopt) {
1712 return buildInstr(TargetOpcode::G_FMAXNUM_IEEE, {Dst}, {Src0, Src1}, Flags);
1713 }
1714
1715 MachineInstrBuilder buildShl(const DstOp &Dst, const SrcOp &Src0,
1716 const SrcOp &Src1,
1717 std::optional<unsigned> Flags = std::nullopt) {
1718 return buildInstr(TargetOpcode::G_SHL, {Dst}, {Src0, Src1}, Flags);
1719 }
1720
1721 MachineInstrBuilder buildLShr(const DstOp &Dst, const SrcOp &Src0,
1722 const SrcOp &Src1,
1723 std::optional<unsigned> Flags = std::nullopt) {
1724 return buildInstr(TargetOpcode::G_LSHR, {Dst}, {Src0, Src1}, Flags);
1725 }
1726
1727 MachineInstrBuilder buildAShr(const DstOp &Dst, const SrcOp &Src0,
1728 const SrcOp &Src1,
1729 std::optional<unsigned> Flags = std::nullopt) {
1730 return buildInstr(TargetOpcode::G_ASHR, {Dst}, {Src0, Src1}, Flags);
1731 }
1732
1733 /// Build and insert \p Res = G_AND \p Op0, \p Op1
1734 ///
1735 /// G_AND sets \p Res to the bitwise and of integer parameters \p Op0 and \p
1736 /// Op1.
1737 ///
1738 /// \pre setBasicBlock or setMI must have been called.
1739 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1740 /// with the same (scalar or vector) type).
1741 ///
1742 /// \return a MachineInstrBuilder for the newly created instruction.
1743
1744 MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0,
1745 const SrcOp &Src1) {
1746 return buildInstr(TargetOpcode::G_AND, {Dst}, {Src0, Src1});
1747 }
1748
1749 /// Build and insert \p Res = G_OR \p Op0, \p Op1
1750 ///
1751 /// G_OR sets \p Res to the bitwise or of integer parameters \p Op0 and \p
1752 /// Op1.
1753 ///
1754 /// \pre setBasicBlock or setMI must have been called.
1755 /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers
1756 /// with the same (scalar or vector) type).
1757 ///
1758 /// \return a MachineInstrBuilder for the newly created instruction.
1759 MachineInstrBuilder buildOr(const DstOp &Dst, const SrcOp &Src0,
1760 const SrcOp &Src1,
1761 std::optional<unsigned> Flags = std::nullopt) {
1762 return buildInstr(TargetOpcode::G_OR, {Dst}, {Src0, Src1}, Flags);
1763 }
1764
1765 /// Build and insert \p Res = G_XOR \p Op0, \p Op1
1766 MachineInstrBuilder buildXor(const DstOp &Dst, const SrcOp &Src0,
1767 const SrcOp &Src1) {
1768 return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, Src1});
1769 }
1770
1771 /// Build and insert a bitwise not,
1772 /// \p NegOne = G_CONSTANT -1
1773 /// \p Res = G_OR \p Op0, NegOne
1774 MachineInstrBuilder buildNot(const DstOp &Dst, const SrcOp &Src0) {
1775 auto NegOne = buildConstant(Dst.getLLTTy(*getMRI()), -1);
1776 return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, NegOne});
1777 }
1778
1779 /// Build and insert integer negation
1780 /// \p Zero = G_CONSTANT 0
1781 /// \p Res = G_SUB Zero, \p Op0
1782 MachineInstrBuilder buildNeg(const DstOp &Dst, const SrcOp &Src0) {
1783 auto Zero = buildConstant(Dst.getLLTTy(*getMRI()), 0);
1784 return buildInstr(TargetOpcode::G_SUB, {Dst}, {Zero, Src0});
1785 }
1786
1787 /// Build and insert \p Res = G_CTPOP \p Op0, \p Src0
1788 MachineInstrBuilder buildCTPOP(const DstOp &Dst, const SrcOp &Src0) {
1789 return buildInstr(TargetOpcode::G_CTPOP, {Dst}, {Src0});
1790 }
1791
1792 /// Build and insert \p Res = G_CTLZ \p Op0, \p Src0
1793 MachineInstrBuilder buildCTLZ(const DstOp &Dst, const SrcOp &Src0) {
1794 return buildInstr(TargetOpcode::G_CTLZ, {Dst}, {Src0});
1795 }
1796
1797 /// Build and insert \p Res = G_CTLZ_ZERO_UNDEF \p Op0, \p Src0
1799 return buildInstr(TargetOpcode::G_CTLZ_ZERO_UNDEF, {Dst}, {Src0});
1800 }
1801
1802 /// Build and insert \p Res = G_CTTZ \p Op0, \p Src0
1803 MachineInstrBuilder buildCTTZ(const DstOp &Dst, const SrcOp &Src0) {
1804 return buildInstr(TargetOpcode::G_CTTZ, {Dst}, {Src0});
1805 }
1806
1807 /// Build and insert \p Res = G_CTTZ_ZERO_UNDEF \p Op0, \p Src0
1809 return buildInstr(TargetOpcode::G_CTTZ_ZERO_UNDEF, {Dst}, {Src0});
1810 }
1811
1812 /// Build and insert \p Dst = G_BSWAP \p Src0
1813 MachineInstrBuilder buildBSwap(const DstOp &Dst, const SrcOp &Src0) {
1814 return buildInstr(TargetOpcode::G_BSWAP, {Dst}, {Src0});
1815 }
1816
1817 /// Build and insert \p Res = G_FADD \p Op0, \p Op1
1818 MachineInstrBuilder buildFAdd(const DstOp &Dst, const SrcOp &Src0,
1819 const SrcOp &Src1,
1820 std::optional<unsigned> Flags = std::nullopt) {
1821 return buildInstr(TargetOpcode::G_FADD, {Dst}, {Src0, Src1}, Flags);
1822 }
1823
1824 /// Build and insert \p Res = G_STRICT_FADD \p Op0, \p Op1
1826 buildStrictFAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1827 std::optional<unsigned> Flags = std::nullopt) {
1828 return buildInstr(TargetOpcode::G_STRICT_FADD, {Dst}, {Src0, Src1}, Flags);
1829 }
1830
1831 /// Build and insert \p Res = G_FSUB \p Op0, \p Op1
1832 MachineInstrBuilder buildFSub(const DstOp &Dst, const SrcOp &Src0,
1833 const SrcOp &Src1,
1834 std::optional<unsigned> Flags = std::nullopt) {
1835 return buildInstr(TargetOpcode::G_FSUB, {Dst}, {Src0, Src1}, Flags);
1836 }
1837
1838 /// Build and insert \p Res = G_FDIV \p Op0, \p Op1
1839 MachineInstrBuilder buildFDiv(const DstOp &Dst, const SrcOp &Src0,
1840 const SrcOp &Src1,
1841 std::optional<unsigned> Flags = std::nullopt) {
1842 return buildInstr(TargetOpcode::G_FDIV, {Dst}, {Src0, Src1}, Flags);
1843 }
1844
1845 /// Build and insert \p Res = G_FMA \p Op0, \p Op1, \p Op2
1846 MachineInstrBuilder buildFMA(const DstOp &Dst, const SrcOp &Src0,
1847 const SrcOp &Src1, const SrcOp &Src2,
1848 std::optional<unsigned> Flags = std::nullopt) {
1849 return buildInstr(TargetOpcode::G_FMA, {Dst}, {Src0, Src1, Src2}, Flags);
1850 }
1851
1852 /// Build and insert \p Res = G_FMAD \p Op0, \p Op1, \p Op2
1853 MachineInstrBuilder buildFMAD(const DstOp &Dst, const SrcOp &Src0,
1854 const SrcOp &Src1, const SrcOp &Src2,
1855 std::optional<unsigned> Flags = std::nullopt) {
1856 return buildInstr(TargetOpcode::G_FMAD, {Dst}, {Src0, Src1, Src2}, Flags);
1857 }
1858
1859 /// Build and insert \p Res = G_FNEG \p Op0
1860 MachineInstrBuilder buildFNeg(const DstOp &Dst, const SrcOp &Src0,
1861 std::optional<unsigned> Flags = std::nullopt) {
1862 return buildInstr(TargetOpcode::G_FNEG, {Dst}, {Src0}, Flags);
1863 }
1864
1865 /// Build and insert \p Res = G_FABS \p Op0
1866 MachineInstrBuilder buildFAbs(const DstOp &Dst, const SrcOp &Src0,
1867 std::optional<unsigned> Flags = std::nullopt) {
1868 return buildInstr(TargetOpcode::G_FABS, {Dst}, {Src0}, Flags);
1869 }
1870
1871 /// Build and insert \p Dst = G_FCANONICALIZE \p Src0
1873 buildFCanonicalize(const DstOp &Dst, const SrcOp &Src0,
1874 std::optional<unsigned> Flags = std::nullopt) {
1875 return buildInstr(TargetOpcode::G_FCANONICALIZE, {Dst}, {Src0}, Flags);
1876 }
1877
1878 /// Build and insert \p Dst = G_INTRINSIC_TRUNC \p Src0
1880 buildIntrinsicTrunc(const DstOp &Dst, const SrcOp &Src0,
1881 std::optional<unsigned> Flags = std::nullopt) {
1882 return buildInstr(TargetOpcode::G_INTRINSIC_TRUNC, {Dst}, {Src0}, Flags);
1883 }
1884
1885 /// Build and insert \p Res = GFFLOOR \p Op0, \p Op1
1887 buildFFloor(const DstOp &Dst, const SrcOp &Src0,
1888 std::optional<unsigned> Flags = std::nullopt) {
1889 return buildInstr(TargetOpcode::G_FFLOOR, {Dst}, {Src0}, Flags);
1890 }
1891
1892 /// Build and insert \p Dst = G_FLOG \p Src
1894 std::optional<unsigned> Flags = std::nullopt) {
1895 return buildInstr(TargetOpcode::G_FLOG, {Dst}, {Src}, Flags);
1896 }
1897
1898 /// Build and insert \p Dst = G_FLOG2 \p Src
1900 std::optional<unsigned> Flags = std::nullopt) {
1901 return buildInstr(TargetOpcode::G_FLOG2, {Dst}, {Src}, Flags);
1902 }
1903
1904 /// Build and insert \p Dst = G_FEXP2 \p Src
1906 std::optional<unsigned> Flags = std::nullopt) {
1907 return buildInstr(TargetOpcode::G_FEXP2, {Dst}, {Src}, Flags);
1908 }
1909
1910 /// Build and insert \p Dst = G_FPOW \p Src0, \p Src1
1911 MachineInstrBuilder buildFPow(const DstOp &Dst, const SrcOp &Src0,
1912 const SrcOp &Src1,
1913 std::optional<unsigned> Flags = std::nullopt) {
1914 return buildInstr(TargetOpcode::G_FPOW, {Dst}, {Src0, Src1}, Flags);
1915 }
1916
1917 /// Build and insert \p Dst = G_FLDEXP \p Src0, \p Src1
1919 buildFLdexp(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1,
1920 std::optional<unsigned> Flags = std::nullopt) {
1921 return buildInstr(TargetOpcode::G_FLDEXP, {Dst}, {Src0, Src1}, Flags);
1922 }
1923
1924 /// Build and insert \p Fract, \p Exp = G_FFREXP \p Src
1926 buildFFrexp(const DstOp &Fract, const DstOp &Exp, const SrcOp &Src,
1927 std::optional<unsigned> Flags = std::nullopt) {
1928 return buildInstr(TargetOpcode::G_FFREXP, {Fract, Exp}, {Src}, Flags);
1929 }
1930
1931 /// Build and insert \p Res = G_FCOPYSIGN \p Op0, \p Op1
1933 const SrcOp &Src1) {
1934 return buildInstr(TargetOpcode::G_FCOPYSIGN, {Dst}, {Src0, Src1});
1935 }
1936
1937 /// Build and insert \p Res = G_UITOFP \p Src0
1938 MachineInstrBuilder buildUITOFP(const DstOp &Dst, const SrcOp &Src0) {
1939 return buildInstr(TargetOpcode::G_UITOFP, {Dst}, {Src0});
1940 }
1941
1942 /// Build and insert \p Res = G_SITOFP \p Src0
1943 MachineInstrBuilder buildSITOFP(const DstOp &Dst, const SrcOp &Src0) {
1944 return buildInstr(TargetOpcode::G_SITOFP, {Dst}, {Src0});
1945 }
1946
1947 /// Build and insert \p Res = G_FPTOUI \p Src0
1948 MachineInstrBuilder buildFPTOUI(const DstOp &Dst, const SrcOp &Src0) {
1949 return buildInstr(TargetOpcode::G_FPTOUI, {Dst}, {Src0});
1950 }
1951
1952 /// Build and insert \p Res = G_FPTOSI \p Src0
1953 MachineInstrBuilder buildFPTOSI(const DstOp &Dst, const SrcOp &Src0) {
1954 return buildInstr(TargetOpcode::G_FPTOSI, {Dst}, {Src0});
1955 }
1956
1957 /// Build and insert \p Dst = G_INTRINSIC_ROUNDEVEN \p Src0, \p Src1
1959 buildIntrinsicRoundeven(const DstOp &Dst, const SrcOp &Src0,
1960 std::optional<unsigned> Flags = std::nullopt) {
1961 return buildInstr(TargetOpcode::G_INTRINSIC_ROUNDEVEN, {Dst}, {Src0},
1962 Flags);
1963 }
1964
1965 /// Build and insert \p Res = G_SMIN \p Op0, \p Op1
1966 MachineInstrBuilder buildSMin(const DstOp &Dst, const SrcOp &Src0,
1967 const SrcOp &Src1) {
1968 return buildInstr(TargetOpcode::G_SMIN, {Dst}, {Src0, Src1});
1969 }
1970
1971 /// Build and insert \p Res = G_SMAX \p Op0, \p Op1
1972 MachineInstrBuilder buildSMax(const DstOp &Dst, const SrcOp &Src0,
1973 const SrcOp &Src1) {
1974 return buildInstr(TargetOpcode::G_SMAX, {Dst}, {Src0, Src1});
1975 }
1976
1977 /// Build and insert \p Res = G_UMIN \p Op0, \p Op1
1978 MachineInstrBuilder buildUMin(const DstOp &Dst, const SrcOp &Src0,
1979 const SrcOp &Src1) {
1980 return buildInstr(TargetOpcode::G_UMIN, {Dst}, {Src0, Src1});
1981 }
1982
1983 /// Build and insert \p Res = G_UMAX \p Op0, \p Op1
1984 MachineInstrBuilder buildUMax(const DstOp &Dst, const SrcOp &Src0,
1985 const SrcOp &Src1) {
1986 return buildInstr(TargetOpcode::G_UMAX, {Dst}, {Src0, Src1});
1987 }
1988
1989 /// Build and insert \p Dst = G_ABS \p Src
1990 MachineInstrBuilder buildAbs(const DstOp &Dst, const SrcOp &Src) {
1991 return buildInstr(TargetOpcode::G_ABS, {Dst}, {Src});
1992 }
1993
1994 /// Build and insert \p Res = G_JUMP_TABLE \p JTI
1995 ///
1996 /// G_JUMP_TABLE sets \p Res to the address of the jump table specified by
1997 /// the jump table index \p JTI.
1998 ///
1999 /// \return a MachineInstrBuilder for the newly created instruction.
2000 MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI);
2001
2002 /// Build and insert \p Res = G_VECREDUCE_SEQ_FADD \p ScalarIn, \p VecIn
2003 ///
2004 /// \p ScalarIn is the scalar accumulator input to start the sequential
2005 /// reduction operation of \p VecIn.
2007 const SrcOp &ScalarIn,
2008 const SrcOp &VecIn) {
2009 return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FADD, {Dst},
2010 {ScalarIn, {VecIn}});
2011 }
2012
2013 /// Build and insert \p Res = G_VECREDUCE_SEQ_FMUL \p ScalarIn, \p VecIn
2014 ///
2015 /// \p ScalarIn is the scalar accumulator input to start the sequential
2016 /// reduction operation of \p VecIn.
2018 const SrcOp &ScalarIn,
2019 const SrcOp &VecIn) {
2020 return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FMUL, {Dst},
2021 {ScalarIn, {VecIn}});
2022 }
2023
2024 /// Build and insert \p Res = G_VECREDUCE_FADD \p Src
2025 ///
2026 /// \p ScalarIn is the scalar accumulator input to the reduction operation of
2027 /// \p VecIn.
2029 const SrcOp &ScalarIn,
2030 const SrcOp &VecIn) {
2031 return buildInstr(TargetOpcode::G_VECREDUCE_FADD, {Dst}, {ScalarIn, VecIn});
2032 }
2033
2034 /// Build and insert \p Res = G_VECREDUCE_FMUL \p Src
2035 ///
2036 /// \p ScalarIn is the scalar accumulator input to the reduction operation of
2037 /// \p VecIn.
2039 const SrcOp &ScalarIn,
2040 const SrcOp &VecIn) {
2041 return buildInstr(TargetOpcode::G_VECREDUCE_FMUL, {Dst}, {ScalarIn, VecIn});
2042 }
2043
2044 /// Build and insert \p Res = G_VECREDUCE_FMAX \p Src
2046 return buildInstr(TargetOpcode::G_VECREDUCE_FMAX, {Dst}, {Src});
2047 }
2048
2049 /// Build and insert \p Res = G_VECREDUCE_FMIN \p Src
2051 return buildInstr(TargetOpcode::G_VECREDUCE_FMIN, {Dst}, {Src});
2052 }
2053
2054 /// Build and insert \p Res = G_VECREDUCE_FMAXIMUM \p Src
2056 const SrcOp &Src) {
2057 return buildInstr(TargetOpcode::G_VECREDUCE_FMAXIMUM, {Dst}, {Src});
2058 }
2059
2060 /// Build and insert \p Res = G_VECREDUCE_FMINIMUM \p Src
2062 const SrcOp &Src) {
2063 return buildInstr(TargetOpcode::G_VECREDUCE_FMINIMUM, {Dst}, {Src});
2064 }
2065
2066 /// Build and insert \p Res = G_VECREDUCE_ADD \p Src
2068 return buildInstr(TargetOpcode::G_VECREDUCE_ADD, {Dst}, {Src});
2069 }
2070
2071 /// Build and insert \p Res = G_VECREDUCE_MUL \p Src
2073 return buildInstr(TargetOpcode::G_VECREDUCE_MUL, {Dst}, {Src});
2074 }
2075
2076 /// Build and insert \p Res = G_VECREDUCE_AND \p Src
2078 return buildInstr(TargetOpcode::G_VECREDUCE_AND, {Dst}, {Src});
2079 }
2080
2081 /// Build and insert \p Res = G_VECREDUCE_OR \p Src
2083 return buildInstr(TargetOpcode::G_VECREDUCE_OR, {Dst}, {Src});
2084 }
2085
2086 /// Build and insert \p Res = G_VECREDUCE_XOR \p Src
2088 return buildInstr(TargetOpcode::G_VECREDUCE_XOR, {Dst}, {Src});
2089 }
2090
2091 /// Build and insert \p Res = G_VECREDUCE_SMAX \p Src
2093 return buildInstr(TargetOpcode::G_VECREDUCE_SMAX, {Dst}, {Src});
2094 }
2095
2096 /// Build and insert \p Res = G_VECREDUCE_SMIN \p Src
2098 return buildInstr(TargetOpcode::G_VECREDUCE_SMIN, {Dst}, {Src});
2099 }
2100
2101 /// Build and insert \p Res = G_VECREDUCE_UMAX \p Src
2103 return buildInstr(TargetOpcode::G_VECREDUCE_UMAX, {Dst}, {Src});
2104 }
2105
2106 /// Build and insert \p Res = G_VECREDUCE_UMIN \p Src
2108 return buildInstr(TargetOpcode::G_VECREDUCE_UMIN, {Dst}, {Src});
2109 }
2110
2111 /// Build and insert G_MEMCPY or G_MEMMOVE
2112 MachineInstrBuilder buildMemTransferInst(unsigned Opcode, const SrcOp &DstPtr,
2113 const SrcOp &SrcPtr,
2114 const SrcOp &Size,
2115 MachineMemOperand &DstMMO,
2116 MachineMemOperand &SrcMMO) {
2117 auto MIB = buildInstr(
2118 Opcode, {}, {DstPtr, SrcPtr, Size, SrcOp(INT64_C(0) /*isTailCall*/)});
2119 MIB.addMemOperand(&DstMMO);
2120 MIB.addMemOperand(&SrcMMO);
2121 return MIB;
2122 }
2123
2124 MachineInstrBuilder buildMemCpy(const SrcOp &DstPtr, const SrcOp &SrcPtr,
2125 const SrcOp &Size, MachineMemOperand &DstMMO,
2126 MachineMemOperand &SrcMMO) {
2127 return buildMemTransferInst(TargetOpcode::G_MEMCPY, DstPtr, SrcPtr, Size,
2128 DstMMO, SrcMMO);
2129 }
2130
2131 /// Build and insert G_TRAP or G_DEBUGTRAP
2133 return buildInstr(Debug ? TargetOpcode::G_DEBUGTRAP : TargetOpcode::G_TRAP);
2134 }
2135
2136 /// Build and insert \p Dst = G_SBFX \p Src, \p LSB, \p Width.
2138 const SrcOp &LSB, const SrcOp &Width) {
2139 return buildInstr(TargetOpcode::G_SBFX, {Dst}, {Src, LSB, Width});
2140 }
2141
2142 /// Build and insert \p Dst = G_UBFX \p Src, \p LSB, \p Width.
2144 const SrcOp &LSB, const SrcOp &Width) {
2145 return buildInstr(TargetOpcode::G_UBFX, {Dst}, {Src, LSB, Width});
2146 }
2147
2148 /// Build and insert \p Dst = G_ROTR \p Src, \p Amt
2150 const SrcOp &Amt) {
2151 return buildInstr(TargetOpcode::G_ROTR, {Dst}, {Src, Amt});
2152 }
2153
2154 /// Build and insert \p Dst = G_ROTL \p Src, \p Amt
2156 const SrcOp &Amt) {
2157 return buildInstr(TargetOpcode::G_ROTL, {Dst}, {Src, Amt});
2158 }
2159
2160 /// Build and insert \p Dst = G_BITREVERSE \p Src
2162 return buildInstr(TargetOpcode::G_BITREVERSE, {Dst}, {Src});
2163 }
2164
2165 virtual MachineInstrBuilder
2166 buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps, ArrayRef<SrcOp> SrcOps,
2167 std::optional<unsigned> Flags = std::nullopt);
2168};
2169
2170} // End namespace llvm.
2171#endif // LLVM_CODEGEN_GLOBALISEL_MACHINEIRBUILDER_H
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t Addr
uint64_t Size
This contains common code to allow clients to notify changes to machine instr.
IRTranslator LLVM IR MI
unsigned Reg
Module.h This file contains the declarations for the Module class.
#define P(N)
bool Debug
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file describes how to lower LLVM code to machine code.
Class for arbitrary precision integers.
Definition: APInt.h:76
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
The address of a basic block.
Definition: Constants.h:889
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:993
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:268
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
This is an important base class in LLVM.
Definition: Constant.h:41
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
A debug info location.
Definition: DebugLoc.h:33
DstOp(const LLT T)
DstOp(unsigned R)
DstOp(Register R)
void addDefToMIB(MachineRegisterInfo &MRI, MachineInstrBuilder &MIB) const
LLT getLLTTy(const MachineRegisterInfo &MRI) const
DstOp(const MachineOperand &Op)
DstType getDstOpKind() const
const TargetRegisterClass * RC
const TargetRegisterClass * getRegClass() const
DstOp(const TargetRegisterClass *TRC)
Register getReg() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:356
The CSE Analysis object.
Definition: CSEInfo.h:69
Abstract class that contains various methods for clients to notify about changes.
virtual void createdInstr(MachineInstr &MI)=0
An instruction has been created and inserted into the function.
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelType.h:42
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Metadata node.
Definition: Metadata.h:1067
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Helper class to build MachineInstr.
MachineInstrBuilder buildLoadFromOffset(const DstOp &Dst, const SrcOp &BasePtr, MachineMemOperand &BaseMMO, int64_t Offset)
Helper to create a load from a constant offset given a base address.
MachineInstrBuilder buildAtomicRMWFMin(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_FMIN Addr, Val, MMO.
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 buildBoolExtInReg(const DstOp &Res, const SrcOp &Op, bool IsVector, bool IsFP)
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 buildAtomicRMWXor(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO.
MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV)
Build and insert Res = G_GLOBAL_VALUE GV.
MachineInstrBuilder buildBr(MachineBasicBlock &Dest)
Build and insert G_BR Dest.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
const MachineFunction & getMF() const
std::optional< MachineInstrBuilder > materializePtrAdd(Register &Res, Register Op0, const LLT ValueTy, uint64_t Value)
Materialize and insert Res = G_PTR_ADD Op0, (G_CONSTANT Value)
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 buildUndef(const DstOp &Res)
Build and insert Res = IMPLICIT_DEF.
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 buildVecReduceSeqFAdd(const DstOp &Dst, const SrcOp &ScalarIn, const SrcOp &VecIn)
Build and insert Res = G_VECREDUCE_SEQ_FADD ScalarIn, VecIn.
MachineInstrBuilder buildRotateRight(const DstOp &Dst, const SrcOp &Src, const SrcOp &Amt)
Build and insert Dst = G_ROTR Src, Amt.
MachineInstrBuilder buildCTTZ(const DstOp &Dst, const SrcOp &Src0)
Build and insert Res = G_CTTZ Op0, Src0.
virtual ~MachineIRBuilder()=default
MachineInstrBuilder buildVecReduceOr(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_OR Src.
MachineInstrBuilder buildFLog2(const DstOp &Dst, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FLOG2 Src.
MachineInstrBuilder buildAShr(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildConstantPool(const DstOp &Res, unsigned Idx)
Build and insert Res = G_CONSTANT_POOL Idx.
MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI)
Build and insert Res = G_JUMP_TABLE JTI.
MachineInstrBuilder buildBoolExt(const DstOp &Res, const SrcOp &Op, bool IsFP)
MachineInstrBuilder buildUnmerge(ArrayRef< LLT > Res, const SrcOp &Op)
Build and insert Res0, ... = G_UNMERGE_VALUES Op.
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 buildSelect(const DstOp &Res, const SrcOp &Tst, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
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 buildAtomicRMWAnd(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO.
MachineInstrBuilder buildZExtInReg(const DstOp &Res, const SrcOp &Op, int64_t ImmOp)
Build and inserts Res = G_AND Op, LowBitsSet(ImmOp) Since there is no G_ZEXT_INREG like G_SEXT_INREG,...
MachineInstrBuilder buildSMulH(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
GISelCSEInfo * getCSEInfo()
MachineInstrBuilder buildAtomicRMWMin(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO.
MachineInstrBuilder buildVecReduceFMax(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_FMAX Src.
MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index)
Build and insert Res0, ... = G_EXTRACT Src, Idx0.
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 buildInsertSubvector(const DstOp &Res, const SrcOp &Src0, const SrcOp &Src1, unsigned Index)
Build and insert Res = G_INSERT_SUBVECTOR Src0, Src1, Idx.
MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_AND Op0, Op1.
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
MachineInstrBuilder buildCast(const DstOp &Dst, const SrcOp &Src)
Build and insert an appropriate cast between two registers of equal size.
const TargetInstrInfo & getTII()
MachineInstrBuilder buildAtomicRMWFAdd(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_FADD Addr, Val, MMO.
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 buildAtomicRMWNand(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO.
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 buildAnyExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Res = COPY Op depending on the differing sizes of Res and Op.
MachineInstrBuilder buildSExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_SEXT Op.
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 buildSExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
MachineInstrBuilder buildShuffleSplat(const DstOp &Res, const SrcOp &Src)
Build and insert a vector splat of a scalar Src using a G_INSERT_VECTOR_ELT and G_SHUFFLE_VECTOR idio...
MachineInstrBuilder buildConcatVectors(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_CONCAT_VECTORS Op0, ...
MachineInstrBuilder buildAtomicRMW(unsigned Opcode, const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO.
MachineInstrBuilder buildVecReduceSeqFMul(const DstOp &Dst, const SrcOp &ScalarIn, const SrcOp &VecIn)
Build and insert Res = G_VECREDUCE_SEQ_FMUL ScalarIn, VecIn.
MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_SUB Op0, Op1.
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef< Register > Res, bool HasSideEffects, bool isConvergent)
Build and insert a G_INTRINSIC instruction.
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 buildVScale(const DstOp &Res, unsigned MinElts)
Build and insert Res = G_VSCALE MinElts.
MachineInstrBuilder buildAddrSpaceCast(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_ADDRSPACE_CAST Src.
MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src)
Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements.
MachineInstrBuilder buildFExp2(const DstOp &Dst, const SrcOp &Src, std::optional< unsigned > Flags=std::nullopt)
Build and insert Dst = G_FEXP2 Src.
MachineInstrBuilder buildIntToPtr(const DstOp &Dst, const SrcOp &Src)
Build and insert a G_INTTOPTR instruction.
MachineInstrBuilder buildIndirectDbgValue(Register Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in me...
unsigned getBoolExtOp(bool IsVec, bool IsFP) const
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.
MachineInstrBuilder buildAtomicRMWUmax(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO.
MachineInstrBuilder buildBuildVector(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_BUILD_VECTOR Op0, ...
MachineIRBuilder(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsPt)
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 buildConstDbgValue(const Constant &C, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified b...
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 buildBrCond(const SrcOp &Tst, MachineBasicBlock &Dest)
Build and insert G_BRCOND Tst, Dest.
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.
MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ... or Res = G_BUILD_VECTOR Op0, ... or Res = G_CONCAT_VEC...
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.
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_PTR_ADD Op0, Op1.
MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
MachineInstrBuilder buildBuildVectorTrunc(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_BUILD_VECTOR_TRUNC Op0, ...
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.
virtual MachineInstrBuilder buildFConstant(const DstOp &Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
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 buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
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 buildPadVectorWithUndefElements(const DstOp &Res, const SrcOp &Op0)
Build and insert a, b, ..., x = G_UNMERGE_VALUES Op0 Res = G_BUILD_VECTOR a, b, .....
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 buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
MachineInstrBuilder buildVecReduceUMax(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_UMAX Src.
MachineInstrBuilder buildDirectDbgValue(Register Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in Re...
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.
MachineInstrBuilder buildBuildVectorConstant(const DstOp &Res, ArrayRef< APInt > Ops)
Build and insert Res = G_BUILD_VECTOR Op0, ... where each OpN is built with G_CONSTANT.
MachineInstrBuilder buildAtomicRMWUmin(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO.
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)
MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op.
MachineFunction & getMF()
Getter for the function we currently build.
MachineIRBuilder(MachineFunction &MF)
MachineIRBuilder(const MachineIRBuilderState &BState)
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 buildDbgLabel(const MDNode *Label)
Build and insert a DBG_LABEL instructions specifying that Label is given.
MachineInstrBuilder buildBrJT(Register TablePtr, unsigned JTI, Register IndexReg)
Build and insert G_BRJT TablePtr, JTI, IndexReg.
MachineInstrBuilder buildInsert(const DstOp &Res, const SrcOp &Src, const SrcOp &Op, unsigned Index)
MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size, Align Alignment)
Build and insert Res = G_DYN_STACKALLOC Size, Align.
MachineInstrBuilder buildVecReduceUMin(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_UMIN Src.
MachineInstrBuilder buildFIDbgValue(int FI, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in th...
void setInstrAndDebugLoc(MachineInstr &MI)
Set the insertion point to before MI, and set the debug loc to MI's loc.
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.
void setPCSections(MDNode *MD)
Set the PC sections metadata to MD for all the next build instructions.
MachineInstrBuilder buildExtOrTrunc(unsigned ExtOpc, const DstOp &Res, const SrcOp &Op)
Build and insert Res = ExtOpc, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes of...
MachineInstrBuilder buildVecReduceAdd(const DstOp &Dst, const SrcOp &Src)
Build and insert Res = G_VECREDUCE_ADD Src.
MachineInstrBuilder buildAtomicRMWSub(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO.
MachineInstrBuilder buildIsFPClass(const DstOp &Res, const SrcOp &Src, unsigned Mask)
Build and insert a Res = G_IS_FPCLASS Src, Mask.
MachineInstrBuilder buildMergeValues(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ...
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.
MachineInstrBuilder buildAtomicRMWFMax(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_FMAX Addr, Val, MMO.
void setDebugLoc(const DebugLoc &DL)
Set the debug location to DL for all the next build instructions.
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 buildAtomicRMWOr(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO.
bool isObservingChanges() const
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.
MachineInstrBuilder buildInsertVectorElement(const DstOp &Res, const SrcOp &Val, const SrcOp &Elt, const SrcOp &Idx)
Build and insert Res = G_INSERT_VECTOR_ELT Val, Elt, Idx.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
MachineInstrBuilder buildAtomicCmpXchgWithSuccess(const DstOp &OldValRes, const DstOp &SuccessRes, const SrcOp &Addr, const SrcOp &CmpVal, const SrcOp &NewVal, MachineMemOperand &MMO)
Build and insert OldValRes<def>, SuccessRes<def> = G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr,...
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 buildTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC Op.
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.
MachineInstrBuilder buildDeleteTrailingVectorElements(const DstOp &Res, const SrcOp &Op0)
Build and insert a, b, ..., x, y, z = G_UNMERGE_VALUES Op0 Res = G_BUILD_VECTOR a,...
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildAtomicRMWAdd(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO.
MachineInstrBuilder buildFPTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FPTRUNC Op.
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 buildAtomicCmpXchg(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &CmpVal, const SrcOp &NewVal, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal, MMO.
MachineIRBuilderState & getState()
Getter for the State.
MachineInstrBuilder buildShuffleVector(const DstOp &Res, const SrcOp &Src1, const SrcOp &Src2, ArrayRef< int > Mask)
Build and insert Res = G_SHUFFLE_VECTOR Src1, Src2, Mask.
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 buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
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)
MachineInstrBuilder buildBlockAddress(Register Res, const BlockAddress *BA)
Build and insert Res = G_BLOCK_ADDR BA.
MachineInstrBuilder buildAtomicRMWMax(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO.
MachineInstrBuilder buildPrefetch(const SrcOp &Addr, unsigned RW, unsigned Locality, unsigned CacheType, MachineMemOperand &MMO)
Build and insert G_PREFETCH Addr, RW, Locality, CacheType.
MachineInstrBuilder buildExtractSubvector(const DstOp &Res, const SrcOp &Src, unsigned Index)
Build and insert Res = G_EXTRACT_SUBVECTOR Src, Idx0.
const DataLayout & getDataLayout() const
MachineInstrBuilder buildBrIndirect(Register Tgt)
Build and insert G_BRINDIRECT Tgt.
MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Val)
Build and insert Res = G_SPLAT_VECTOR Val.
MachineInstrBuilder buildLoadInstr(unsigned Opcode, const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = <opcode> Addr, MMO.
void setMF(MachineFunction &MF)
MachineInstrBuilder buildAtomicRMWFSub(const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_FSUB Addr, Val, MMO.
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.
MachineInstrBuilder buildAtomicRMWXchg(Register OldValRes, Register Addr, Register Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO.
void setState(const MachineIRBuilderState &NewState)
Setter for the State.
void setChangeObserver(GISelChangeObserver &Observer)
MachineInstrBuilder buildMaskLowPtrBits(const DstOp &Res, const SrcOp &Op0, uint32_t NumBits)
Build and insert Res = G_PTRMASK Op0, G_CONSTANT (1 << NumBits) - 1.
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 buildFCmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert a Res = G_FCMP PredOp0, 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 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 & addMemOperand(MachineMemOperand *MMO) const
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
Definition: MachineInstr.h:69
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:556
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.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:293
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.
virtual MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
virtual const TargetLowering * getTargetLowering() const
LLVM Value Representation.
Definition: Value.h:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ ConstantFP
Definition: ISDOpcodes.h:77
@ BlockAddress
Definition: ISDOpcodes.h:84
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
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.
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,...