LLVM 22.0.0git
MachineInstrBuilder.h
Go to the documentation of this file.
1//===- CodeGen/MachineInstrBuilder.h - Simplify creation of MIs --*- 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//
9// This file exposes a function named BuildMI, which is useful for dramatically
10// simplifying how MachineInstr's are created. It allows use of code like this:
11//
12// MIMetadata MIMD(MI); // Propagates DebugLoc and other metadata
13// M = BuildMI(MBB, MI, MIMD, TII.get(X86::ADD8rr), Dst)
14// .addReg(argVal1)
15// .addReg(argVal2);
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H
20#define LLVM_CODEGEN_MACHINEINSTRBUILDER_H
21
22#include "llvm/ADT/ArrayRef.h"
30#include "llvm/IR/InstrTypes.h"
31#include "llvm/IR/Intrinsics.h"
34#include <cassert>
35#include <cstdint>
36
37namespace llvm {
38
39class MCInstrDesc;
40class MDNode;
41
42namespace RegState {
43
44// Keep this in sync with the table in MIRLangRef.rst.
45enum {
46 /// Register definition.
47 Define = 0x2,
48 /// Not emitted register (e.g. carry, or temporary result).
49 Implicit = 0x4,
50 /// The last use of a register.
51 Kill = 0x8,
52 /// Unused definition.
53 Dead = 0x10,
54 /// Value of the register doesn't matter.
55 Undef = 0x20,
56 /// Register definition happens before uses.
58 /// Register 'use' is for debugging purpose.
59 Debug = 0x80,
60 /// Register reads a value that is defined inside the same instruction or
61 /// bundle.
62 InternalRead = 0x100,
63 /// Register that may be renamed.
64 Renamable = 0x200,
68};
69
70} // end namespace RegState
71
72/// Set of metadata that should be preserved when using BuildMI(). This provides
73/// a more convenient way of preserving certain data from the original
74/// instruction.
76public:
77 MIMetadata() = default;
78 MIMetadata(DebugLoc DL, MDNode *PCSections = nullptr, MDNode *MMRA = nullptr,
79 Value *DeactivationSymbol = nullptr)
80 : DL(std::move(DL)), PCSections(PCSections), MMRA(MMRA),
81 DeactivationSymbol(DeactivationSymbol) {}
82 MIMetadata(const DILocation *DI, MDNode *PCSections = nullptr,
83 MDNode *MMRA = nullptr)
84 : DL(DI), PCSections(PCSections), MMRA(MMRA) {}
85 explicit MIMetadata(const Instruction &From)
86 : DL(From.getDebugLoc()),
87 PCSections(From.getMetadata(LLVMContext::MD_pcsections)),
88 DeactivationSymbol(getDeactivationSymbol(&From)) {}
89 explicit MIMetadata(const MachineInstr &From)
90 : DL(From.getDebugLoc()), PCSections(From.getPCSections()),
91 DeactivationSymbol(From.getDeactivationSymbol()) {}
92
93 const DebugLoc &getDL() const { return DL; }
94 MDNode *getPCSections() const { return PCSections; }
95 MDNode *getMMRAMetadata() const { return MMRA; }
96 Value *getDeactivationSymbol() const { return DeactivationSymbol; }
97
98private:
100 MDNode *PCSections = nullptr;
101 MDNode *MMRA = nullptr;
102 Value *DeactivationSymbol = nullptr;
103
104 static inline Value *getDeactivationSymbol(const Instruction *I) {
105 if (auto *CB = dyn_cast<CallBase>(I))
106 if (auto Bundle =
107 CB->getOperandBundle(llvm::LLVMContext::OB_deactivation_symbol))
108 return Bundle->Inputs[0].get();
109 return nullptr;
110 }
111};
112
114 MachineFunction *MF = nullptr;
115 MachineInstr *MI = nullptr;
116
117public:
119
120 /// Create a MachineInstrBuilder for manipulating an existing instruction.
121 /// F must be the machine function that was used to allocate I.
125
126 /// Allow automatic conversion to the machine instruction we are working on.
127 operator MachineInstr*() const { return MI; }
128 MachineInstr *operator->() const { return MI; }
129 operator MachineBasicBlock::iterator() const { return MI; }
130
131 /// If conversion operators fail, use this method to get the MachineInstr
132 /// explicitly.
133 MachineInstr *getInstr() const { return MI; }
134
135 /// Get the register for the operand index.
136 /// The operand at the index should be a register (asserted by
137 /// MachineOperand).
138 Register getReg(unsigned Idx) const { return MI->getOperand(Idx).getReg(); }
139
140 /// Add a new virtual register operand.
141 const MachineInstrBuilder &addReg(Register RegNo, unsigned flags = 0,
142 unsigned SubReg = 0) const {
143 assert((flags & 0x1) == 0 &&
144 "Passing in 'true' to addReg is forbidden! Use enums instead.");
145 MI->addOperand(*MF, MachineOperand::CreateReg(RegNo,
146 flags & RegState::Define,
147 flags & RegState::Implicit,
148 flags & RegState::Kill,
149 flags & RegState::Dead,
150 flags & RegState::Undef,
152 SubReg,
153 flags & RegState::Debug,
155 flags & RegState::Renamable));
156 return *this;
157 }
158
159 /// Add a virtual register definition operand.
160 const MachineInstrBuilder &addDef(Register RegNo, unsigned Flags = 0,
161 unsigned SubReg = 0) const {
162 return addReg(RegNo, Flags | RegState::Define, SubReg);
163 }
164
165 /// Add a virtual register use operand. It is an error for Flags to contain
166 /// `RegState::Define` when calling this function.
167 const MachineInstrBuilder &addUse(Register RegNo, unsigned Flags = 0,
168 unsigned SubReg = 0) const {
169 assert(!(Flags & RegState::Define) &&
170 "Misleading addUse defines register, use addReg instead.");
171 return addReg(RegNo, Flags, SubReg);
172 }
173
174 /// Add a new immediate operand.
175 const MachineInstrBuilder &addImm(int64_t Val) const {
177 return *this;
178 }
179
180 const MachineInstrBuilder &addCImm(const ConstantInt *Val) const {
182 return *this;
183 }
184
185 const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
187 return *this;
188 }
189
191 unsigned TargetFlags = 0) const {
192 MI->addOperand(*MF, MachineOperand::CreateMBB(MBB, TargetFlags));
193 return *this;
194 }
195
196 const MachineInstrBuilder &addFrameIndex(int Idx) const {
198 return *this;
199 }
200
201 const MachineInstrBuilder &
202 addConstantPoolIndex(unsigned Idx, int Offset = 0,
203 unsigned TargetFlags = 0) const {
204 MI->addOperand(*MF, MachineOperand::CreateCPI(Idx, Offset, TargetFlags));
205 return *this;
206 }
207
208 const MachineInstrBuilder &addTargetIndex(unsigned Idx, int64_t Offset = 0,
209 unsigned TargetFlags = 0) const {
211 TargetFlags));
212 return *this;
213 }
214
216 unsigned TargetFlags = 0) const {
217 MI->addOperand(*MF, MachineOperand::CreateJTI(Idx, TargetFlags));
218 return *this;
219 }
220
222 int64_t Offset = 0,
223 unsigned TargetFlags = 0) const {
224 MI->addOperand(*MF, MachineOperand::CreateGA(GV, Offset, TargetFlags));
225 return *this;
226 }
227
228 const MachineInstrBuilder &addExternalSymbol(const char *FnName,
229 unsigned TargetFlags = 0) const {
230 MI->addOperand(*MF, MachineOperand::CreateES(FnName, TargetFlags));
231 return *this;
232 }
233
235 int64_t Offset = 0,
236 unsigned TargetFlags = 0) const {
237 MI->addOperand(*MF, MachineOperand::CreateBA(BA, Offset, TargetFlags));
238 return *this;
239 }
240
241 const MachineInstrBuilder &addRegMask(const uint32_t *Mask) const {
243 return *this;
244 }
245
247 MI->addMemOperand(*MF, MMO);
248 return *this;
249 }
250
251 const MachineInstrBuilder &
253 MI->setMemRefs(*MF, MMOs);
254 return *this;
255 }
256
257 const MachineInstrBuilder &cloneMemRefs(const MachineInstr &OtherMI) const {
258 MI->cloneMemRefs(*MF, OtherMI);
259 return *this;
260 }
261
262 const MachineInstrBuilder &
264 MI->cloneMergedMemRefs(*MF, OtherMIs);
265 return *this;
266 }
267
268 const MachineInstrBuilder &add(const MachineOperand &MO) const {
269 MI->addOperand(*MF, MO);
270 return *this;
271 }
272
274 for (const MachineOperand &MO : MOs)
275 MI->addOperand(*MF, MO);
276 return *this;
277 }
278
279 const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
281 assert((MI->isDebugValueLike() ? static_cast<bool>(MI->getDebugVariable())
282 : true) &&
283 "first MDNode argument of a DBG_VALUE not a variable");
284 assert((MI->isDebugLabel() ? static_cast<bool>(MI->getDebugLabel())
285 : true) &&
286 "first MDNode argument of a DBG_LABEL not a label");
287 return *this;
288 }
289
290 const MachineInstrBuilder &addCFIIndex(unsigned CFIIndex) const {
291 MI->addOperand(*MF, MachineOperand::CreateCFIIndex(CFIIndex));
292 return *this;
293 }
294
299
302 return *this;
303 }
304
307 return *this;
308 }
309
311 MI->addOperand(*MF, MachineOperand::CreateLaneMask(LaneMask));
312 return *this;
313 }
314
316 unsigned char TargetFlags = 0) const {
317 MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym, TargetFlags));
318 return *this;
319 }
320
321 const MachineInstrBuilder &setMIFlags(unsigned Flags) const {
322 MI->setFlags(Flags);
323 return *this;
324 }
325
327 MI->setFlag(Flag);
328 return *this;
329 }
330
331 const MachineInstrBuilder &setOperandDead(unsigned OpIdx) const {
333 return *this;
334 }
335
336 // Add a displacement from an existing MachineOperand with an added offset.
337 const MachineInstrBuilder &addDisp(const MachineOperand &Disp, int64_t off,
338 unsigned char TargetFlags = 0) const {
339 // If caller specifies new TargetFlags then use it, otherwise the
340 // default behavior is to copy the target flags from the existing
341 // MachineOperand. This means if the caller wants to clear the
342 // target flags it needs to do so explicitly.
343 if (0 == TargetFlags)
344 TargetFlags = Disp.getTargetFlags();
345
346 switch (Disp.getType()) {
347 default:
348 llvm_unreachable("Unhandled operand type in addDisp()");
350 return addImm(Disp.getImm() + off);
352 return addConstantPoolIndex(Disp.getIndex(), Disp.getOffset() + off,
353 TargetFlags);
355 return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
356 TargetFlags);
358 return addBlockAddress(Disp.getBlockAddress(), Disp.getOffset() + off,
359 TargetFlags);
361 assert(off == 0 && "cannot create offset into jump tables");
362 return addJumpTableIndex(Disp.getIndex(), TargetFlags);
363 }
364 }
365
367 if (MIMD.getPCSections())
368 MI->setPCSections(*MF, MIMD.getPCSections());
369 if (MIMD.getMMRAMetadata())
370 MI->setMMRAMetadata(*MF, MIMD.getMMRAMetadata());
371 if (MIMD.getDeactivationSymbol())
372 MI->setDeactivationSymbol(*MF, MIMD.getDeactivationSymbol());
373 return *this;
374 }
375
376 /// Copy all the implicit operands from OtherMI onto this one.
377 const MachineInstrBuilder &
378 copyImplicitOps(const MachineInstr &OtherMI) const {
379 MI->copyImplicitOps(*MF, OtherMI);
380 return *this;
381 }
382
384 const TargetRegisterInfo &TRI,
385 const RegisterBankInfo &RBI) const {
386 return constrainSelectedInstRegOperands(*MI, TII, TRI, RBI);
387 }
388};
389
390/// Builder interface. Specify how to create the initial instruction itself.
392 const MCInstrDesc &MCID) {
393 return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, MIMD.getDL()))
394 .copyMIMetadata(MIMD);
395}
396
397/// This version of the builder sets up the first operand as a
398/// destination virtual register.
400 const MCInstrDesc &MCID, Register DestReg) {
401 return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, MIMD.getDL()))
402 .copyMIMetadata(MIMD)
403 .addReg(DestReg, RegState::Define);
404}
405
406/// This version of the builder inserts the newly-built instruction before
407/// the given position in the given MachineBasicBlock, and sets up the first
408/// operand as a destination virtual register.
411 const MIMetadata &MIMD,
412 const MCInstrDesc &MCID, Register DestReg) {
413 MachineFunction &MF = *BB.getParent();
414 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
415 BB.insert(I, MI);
417 DestReg, RegState::Define);
418}
419
420/// This version of the builder inserts the newly-built instruction before
421/// the given position in the given MachineBasicBlock, and sets up the first
422/// operand as a destination virtual register.
423///
424/// If \c I is inside a bundle, then the newly inserted \a MachineInstr is
425/// added to the same bundle.
428 const MIMetadata &MIMD,
429 const MCInstrDesc &MCID, Register DestReg) {
430 MachineFunction &MF = *BB.getParent();
431 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
432 BB.insert(I, MI);
434 DestReg, RegState::Define);
435}
436
438 const MIMetadata &MIMD,
439 const MCInstrDesc &MCID, Register DestReg) {
440 // Calling the overload for instr_iterator is always correct. However, the
441 // definition is not available in headers, so inline the check.
442 if (I.isInsideBundle())
444 DestReg);
445 return BuildMI(BB, MachineBasicBlock::iterator(I), MIMD, MCID, DestReg);
446}
447
449 const MIMetadata &MIMD,
450 const MCInstrDesc &MCID, Register DestReg) {
451 return BuildMI(BB, *I, MIMD, MCID, DestReg);
452}
453
454/// This version of the builder inserts the newly-built instruction before the
455/// given position in the given MachineBasicBlock, and does NOT take a
456/// destination register.
459 const MIMetadata &MIMD,
460 const MCInstrDesc &MCID) {
461 MachineFunction &MF = *BB.getParent();
462 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
463 BB.insert(I, MI);
464 return MachineInstrBuilder(MF, MI).copyMIMetadata(MIMD);
465}
466
469 const MIMetadata &MIMD,
470 const MCInstrDesc &MCID) {
471 MachineFunction &MF = *BB.getParent();
472 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
473 BB.insert(I, MI);
474 return MachineInstrBuilder(MF, MI).copyMIMetadata(MIMD);
475}
476
478 const MIMetadata &MIMD,
479 const MCInstrDesc &MCID) {
480 // Calling the overload for instr_iterator is always correct. However, the
481 // definition is not available in headers, so inline the check.
482 if (I.isInsideBundle())
484 return BuildMI(BB, MachineBasicBlock::iterator(I), MIMD, MCID);
485}
486
488 const MIMetadata &MIMD,
489 const MCInstrDesc &MCID) {
490 return BuildMI(BB, *I, MIMD, MCID);
491}
492
493/// This version of the builder inserts the newly-built instruction at the end
494/// of the given MachineBasicBlock, and does NOT take a destination register.
496 const MIMetadata &MIMD,
497 const MCInstrDesc &MCID) {
498 return BuildMI(*BB, BB->end(), MIMD, MCID);
499}
500
501/// This version of the builder inserts the newly-built instruction at the
502/// end of the given MachineBasicBlock, and sets up the first operand as a
503/// destination virtual register.
505 const MIMetadata &MIMD,
506 const MCInstrDesc &MCID, Register DestReg) {
507 return BuildMI(*BB, BB->end(), MIMD, MCID, DestReg);
508}
509
510/// This version of the builder builds a DBG_VALUE intrinsic
511/// for either a value in a register or a register-indirect
512/// address. The convention is that a DBG_VALUE is indirect iff the
513/// second operand is an immediate.
514LLVM_ABI MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
515 const MCInstrDesc &MCID, bool IsIndirect,
516 Register Reg, const MDNode *Variable,
517 const MDNode *Expr);
518
519/// This version of the builder builds a DBG_VALUE or DBG_VALUE_LIST intrinsic
520/// for a MachineOperand.
521LLVM_ABI MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
522 const MCInstrDesc &MCID, bool IsIndirect,
524 const MDNode *Variable,
525 const MDNode *Expr);
526
527/// This version of the builder builds a DBG_VALUE intrinsic
528/// for either a value in a register or a register-indirect
529/// address and inserts it at position I.
530LLVM_ABI MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
532 const DebugLoc &DL,
533 const MCInstrDesc &MCID, bool IsIndirect,
534 Register Reg, const MDNode *Variable,
535 const MDNode *Expr);
536
537/// This version of the builder builds a DBG_VALUE, DBG_INSTR_REF, or
538/// DBG_VALUE_LIST intrinsic for a machine operand and inserts it at position I.
539LLVM_ABI MachineInstrBuilder BuildMI(
540 MachineBasicBlock &BB, MachineBasicBlock::iterator I, const DebugLoc &DL,
541 const MCInstrDesc &MCID, bool IsIndirect, ArrayRef<MachineOperand> MOs,
542 const MDNode *Variable, const MDNode *Expr);
543
544/// Clone a DBG_VALUE whose value has been spilled to FrameIndex.
545LLVM_ABI MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
547 const MachineInstr &Orig,
548 int FrameIndex, Register SpillReg);
549LLVM_ABI MachineInstr *buildDbgValueForSpill(
550 MachineBasicBlock &BB, MachineBasicBlock::iterator I,
551 const MachineInstr &Orig, int FrameIndex,
552 const SmallVectorImpl<const MachineOperand *> &SpilledOperands);
553
554/// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
555/// modifying an instruction in place while iterating over a basic block.
556LLVM_ABI void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex,
557 Register Reg);
558
559inline unsigned getDefRegState(bool B) {
560 return B ? RegState::Define : 0;
561}
562inline unsigned getImplRegState(bool B) {
563 return B ? RegState::Implicit : 0;
564}
565inline unsigned getKillRegState(bool B) {
566 return B ? RegState::Kill : 0;
567}
568inline unsigned getDeadRegState(bool B) {
569 return B ? RegState::Dead : 0;
570}
571inline unsigned getUndefRegState(bool B) {
572 return B ? RegState::Undef : 0;
573}
574inline unsigned getInternalReadRegState(bool B) {
575 return B ? RegState::InternalRead : 0;
576}
577inline unsigned getDebugRegState(bool B) {
578 return B ? RegState::Debug : 0;
579}
580inline unsigned getRenamableRegState(bool B) {
581 return B ? RegState::Renamable : 0;
582}
583
584/// Get all register state flags from machine operand \p RegOp.
585inline unsigned getRegState(const MachineOperand &RegOp) {
586 assert(RegOp.isReg() && "Not a register operand");
587 return getDefRegState(RegOp.isDef()) | getImplRegState(RegOp.isImplicit()) |
588 getKillRegState(RegOp.isKill()) | getDeadRegState(RegOp.isDead()) |
589 getUndefRegState(RegOp.isUndef()) |
591 getDebugRegState(RegOp.isDebug()) |
593 RegOp.isRenamable());
594}
595
596/// Helper class for constructing bundles of MachineInstrs.
597///
598/// MIBundleBuilder can create a bundle from scratch by inserting new
599/// MachineInstrs one at a time, or it can create a bundle from a sequence of
600/// existing MachineInstrs in a basic block.
605
606public:
607 /// Create an MIBundleBuilder that inserts instructions into a new bundle in
608 /// BB above the bundle or instruction at Pos.
610 : MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
611
612 /// Create a bundle from the sequence of instructions between B and E.
615 : MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
616 assert(B != E && "No instructions to bundle");
617 ++B;
618 while (B != E) {
619 MachineInstr &MI = *B;
620 ++B;
621 MI.bundleWithPred();
622 }
623 }
624
625 /// Create an MIBundleBuilder representing an existing instruction or bundle
626 /// that has MI as its head.
628 : MBB(*MI->getParent()), Begin(MI),
629 End(getBundleEnd(MI->getIterator())) {}
630
631 /// Return a reference to the basic block containing this bundle.
632 MachineBasicBlock &getMBB() const { return MBB; }
633
634 /// Return true if no instructions have been inserted in this bundle yet.
635 /// Empty bundles aren't representable in a MachineBasicBlock.
636 bool empty() const { return Begin == End; }
637
638 /// Return an iterator to the first bundled instruction.
639 MachineBasicBlock::instr_iterator begin() const { return Begin; }
640
641 /// Return an iterator beyond the last bundled instruction.
643
644 /// Insert MI into this bundle before I which must point to an instruction in
645 /// the bundle, or end().
647 MachineInstr *MI) {
648 MBB.insert(I, MI);
649 if (I == Begin) {
650 if (!empty())
651 MI->bundleWithSucc();
652 Begin = MI->getIterator();
653 return *this;
654 }
655 if (I == End) {
656 MI->bundleWithPred();
657 return *this;
658 }
659 // MI was inserted in the middle of the bundle, so its neighbors' flags are
660 // already fine. Update MI's bundle flags manually.
663 return *this;
664 }
665
666 /// Insert MI into MBB by prepending it to the instructions in the bundle.
667 /// MI will become the first instruction in the bundle.
671
672 /// Insert MI into MBB by appending it to the instructions in the bundle.
673 /// MI will become the last instruction in the bundle.
675 return insert(end(), MI);
676 }
677};
678
679} // end namespace llvm
680
681#endif // LLVM_CODEGEN_MACHINEINSTRBUILDER_H
unsigned SubReg
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
MachineInstr unsigned OpIdx
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
The address of a basic block.
Definition Constants.h:904
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:282
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A debug info location.
Definition DebugLoc.h:123
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Describe properties that are true of each instruction in the target description file.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Metadata node.
Definition Metadata.h:1078
MachineBasicBlock::instr_iterator end() const
Return an iterator beyond the last bundled instruction.
MachineBasicBlock::instr_iterator begin() const
Return an iterator to the first bundled instruction.
MIBundleBuilder & append(MachineInstr *MI)
Insert MI into MBB by appending it to the instructions in the bundle.
MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator B, MachineBasicBlock::iterator E)
Create a bundle from the sequence of instructions between B and E.
MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator Pos)
Create an MIBundleBuilder that inserts instructions into a new bundle in BB above the bundle or instr...
MIBundleBuilder & insert(MachineBasicBlock::instr_iterator I, MachineInstr *MI)
Insert MI into this bundle before I which must point to an instruction in the bundle,...
MachineBasicBlock & getMBB() const
Return a reference to the basic block containing this bundle.
MIBundleBuilder & prepend(MachineInstr *MI)
Insert MI into MBB by prepending it to the instructions in the bundle.
bool empty() const
Return true if no instructions have been inserted in this bundle yet.
MIBundleBuilder(MachineInstr *MI)
Create an MIBundleBuilder representing an existing instruction or bundle that has MI as its head.
Set of metadata that should be preserved when using BuildMI().
const DebugLoc & getDL() const
MIMetadata()=default
MIMetadata(const DILocation *DI, MDNode *PCSections=nullptr, MDNode *MMRA=nullptr)
MDNode * getMMRAMetadata() const
MIMetadata(const Instruction &From)
MIMetadata(const MachineInstr &From)
Value * getDeactivationSymbol() const
MDNode * getPCSections() const
MIMetadata(DebugLoc DL, MDNode *PCSections=nullptr, MDNode *MMRA=nullptr, Value *DeactivationSymbol=nullptr)
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
Instructions::iterator instr_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
const MachineInstrBuilder & cloneMergedMemRefs(ArrayRef< const MachineInstr * > OtherMIs) const
const MachineInstrBuilder & addTargetIndex(unsigned Idx, int64_t Offset=0, unsigned TargetFlags=0) const
Register getReg(unsigned Idx) const
Get the register for the operand index.
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand * > MMOs) const
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addCImm(const ConstantInt *Val) const
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & setOperandDead(unsigned OpIdx) const
MachineInstrBuilder(MachineFunction &F, MachineInstr *I)
Create a MachineInstrBuilder for manipulating an existing instruction.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
MachineInstr * operator->() const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addPredicate(CmpInst::Predicate Pred) const
const MachineInstrBuilder & addBlockAddress(const BlockAddress *BA, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addIntrinsicID(Intrinsic::ID ID) const
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addShuffleMask(ArrayRef< int > Val) const
MachineInstrBuilder(MachineFunction &F, MachineBasicBlock::iterator I)
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
const MachineInstrBuilder & add(ArrayRef< MachineOperand > MOs) const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDisp(const MachineOperand &Disp, int64_t off, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
bool constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
const MachineInstrBuilder & addJumpTableIndex(unsigned Idx, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
const MachineInstrBuilder & addLaneMask(LaneBitmask LaneMask) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & copyMIMetadata(const MIMetadata &MIMD) const
Representation of each machine instruction.
void setFlags(unsigned flags)
LLVM_ABI void cloneMemRefs(MachineFunction &MF, const MachineInstr &MI)
Clone another MachineInstr's memory reference descriptor list and replace ours with it.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
LLVM_ABI void setMemRefs(MachineFunction &MF, ArrayRef< MachineMemOperand * > MemRefs)
Assign this MachineInstr's memory reference descriptor list.
LLVM_ABI void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
LLVM_ABI void cloneMergedMemRefs(MachineFunction &MF, ArrayRef< const MachineInstr * > MIs)
Clone the merge of multiple MachineInstrs' memory reference descriptors list and replace ours with it...
void setFlag(MIFlag Flag)
Set a MI flag.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI void setPCSections(MachineFunction &MF, MDNode *MD)
LLVM_ABI void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
A description of a memory reference used in the backend.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
const GlobalValue * getGlobal() const
static MachineOperand CreateES(const char *SymName, unsigned TargetFlags=0)
static MachineOperand CreateFPImm(const ConstantFP *CFP)
int64_t getImm() const
static MachineOperand CreateCFIIndex(unsigned CFIIndex)
static MachineOperand CreateRegMask(const uint32_t *Mask)
CreateRegMask - Creates a register mask operand referencing Mask.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static MachineOperand CreateCImm(const ConstantInt *CI)
void setIsDead(bool Val=true)
LLVM_ABI bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
static MachineOperand CreateMetadata(const MDNode *Meta)
const BlockAddress * getBlockAddress() const
static MachineOperand CreatePredicate(unsigned Pred)
unsigned getTargetFlags() const
static MachineOperand CreateImm(int64_t Val)
static MachineOperand CreateShuffleMask(ArrayRef< int > Mask)
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MachineOperand CreateJTI(unsigned Idx, unsigned TargetFlags=0)
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
bool isInternalRead() const
static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateLaneMask(LaneBitmask LaneMask)
static MachineOperand CreateCPI(unsigned Idx, int Offset, unsigned TargetFlags=0)
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0)
int64_t getOffset() const
Return the offset from the symbol in this operand.
static MachineOperand CreateIntrinsicID(Intrinsic::ID ID)
static MachineOperand CreateFI(int Idx)
Holds all the information related to register banks.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Debug
Register 'use' is for debugging purpose.
@ Dead
Unused definition.
@ Renamable
Register that may be renamed.
@ Define
Register definition.
@ InternalRead
Register reads a value that is defined inside the same instruction or bundle.
@ Kill
The last use of a register.
@ Undef
Value of the register doesn't matter.
@ EarlyClobber
Register definition happens before uses.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex, Register Reg)
Update a DBG_VALUE whose value has been spilled to FrameIndex.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
Definition Utils.cpp:155
unsigned getDeadRegState(bool B)
unsigned getImplRegState(bool B)
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
unsigned getInternalReadRegState(bool B)
unsigned getDebugRegState(bool B)
unsigned getUndefRegState(bool B)
unsigned getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
unsigned getDefRegState(bool B)
unsigned getKillRegState(bool B)
unsigned getRenamableRegState(bool B)
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1879
LLVM_ABI MachineInstr * buildDbgValueForSpill(MachineBasicBlock &BB, MachineBasicBlock::iterator I, const MachineInstr &Orig, int FrameIndex, Register SpillReg)
Clone a DBG_VALUE whose value has been spilled to FrameIndex.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867