LLVM 23.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"
31#include "llvm/IR/InstrTypes.h"
32#include "llvm/IR/Intrinsics.h"
35#include <cassert>
36#include <cstdint>
37
38namespace llvm {
39
40class MCInstrDesc;
41class MDNode;
42
43/// Flags to represent properties of register accesses.
44///
45/// These used to be represented with `unsigned`, but the underlying type of
46/// this enum class is `uint16_t` because these flags are serialized into 2-byte
47/// fields in the GlobalISel table emitters.
48///
49/// Keep this in sync with the table in MIRLangReg.rst
50enum class RegState : uint16_t {
51 /// No Specific Flags
52 NoFlags = 0x0,
53 // Reserved value, to detect if someone is passing `true` rather than this
54 // enum.
55 _Reserved = 0x1,
56 /// Register definition.
57 Define = 0x2,
58 /// Not emitted register (e.g. carry, or temporary result).
59 Implicit = 0x4,
60 /// The last use of a register.
61 Kill = 0x8,
62 /// Unused definition.
63 Dead = 0x10,
64 /// Value of the register doesn't matter.
65 Undef = 0x20,
66 /// Register definition happens before uses.
68 /// Register 'use' is for debugging purpose.
69 Debug = 0x80,
70 /// Register reads a value that is defined inside the same instruction or
71 /// bundle.
72 InternalRead = 0x100,
73 /// Register that may be renamed.
74 Renamable = 0x200,
75
77
78 // Combinations of above flags
82};
83
84constexpr RegState getDefRegState(bool B) {
86}
87constexpr RegState getImplRegState(bool B) {
89}
90constexpr RegState getKillRegState(bool B) {
92}
93constexpr RegState getDeadRegState(bool B) {
95}
96constexpr RegState getUndefRegState(bool B) {
98}
102constexpr RegState getDebugRegState(bool B) {
104}
111
113 return (Value & Test) == Test;
114}
115
116/// Get all register state flags from machine operand \p RegOp.
117inline RegState getRegState(const MachineOperand &RegOp) {
118 assert(RegOp.isReg() && "Not a register operand");
119 return getDefRegState(RegOp.isDef()) | getImplRegState(RegOp.isImplicit()) |
120 getKillRegState(RegOp.isKill()) | getDeadRegState(RegOp.isDead()) |
121 getUndefRegState(RegOp.isUndef()) |
122 // FIXME: why is this not included
123 // getEarlyClobberRegState(RegOp.isEarlyClobber()) |
125 getDebugRegState(RegOp.isDebug()) |
127 RegOp.isRenamable());
128}
129
130/// Set of metadata that should be preserved when using BuildMI(). This provides
131/// a more convenient way of preserving certain data from the original
132/// instruction.
134public:
135 MIMetadata() = default;
136 MIMetadata(DebugLoc DL, MDNode *PCSections = nullptr, MDNode *MMRA = nullptr,
137 Value *DeactivationSymbol = nullptr)
138 : DL(std::move(DL)), PCSections(PCSections), MMRA(MMRA),
139 DeactivationSymbol(DeactivationSymbol) {}
140 MIMetadata(const DILocation *DI, MDNode *PCSections = nullptr,
141 MDNode *MMRA = nullptr)
142 : DL(DI), PCSections(PCSections), MMRA(MMRA) {}
143 explicit MIMetadata(const Instruction &From)
144 : DL(From.getDebugLoc()),
145 PCSections(From.getMetadata(LLVMContext::MD_pcsections)),
146 DeactivationSymbol(getDeactivationSymbol(&From)) {}
147 explicit MIMetadata(const MachineInstr &From)
148 : DL(From.getDebugLoc()), PCSections(From.getPCSections()),
149 DeactivationSymbol(From.getDeactivationSymbol()) {}
150
151 const DebugLoc &getDL() const { return DL; }
152 MDNode *getPCSections() const { return PCSections; }
153 MDNode *getMMRAMetadata() const { return MMRA; }
154 Value *getDeactivationSymbol() const { return DeactivationSymbol; }
155
156private:
157 DebugLoc DL;
158 MDNode *PCSections = nullptr;
159 MDNode *MMRA = nullptr;
160 Value *DeactivationSymbol = nullptr;
161
162 static inline Value *getDeactivationSymbol(const Instruction *I) {
163 if (auto *CB = dyn_cast<CallBase>(I))
164 if (auto Bundle =
165 CB->getOperandBundle(llvm::LLVMContext::OB_deactivation_symbol))
166 return Bundle->Inputs[0].get();
167 return nullptr;
168 }
169};
170
172 MachineFunction *MF = nullptr;
173 MachineInstr *MI = nullptr;
174
175public:
177
178 /// Create a MachineInstrBuilder for manipulating an existing instruction.
179 /// F must be the machine function that was used to allocate I.
183
184 /// Allow automatic conversion to the machine instruction we are working on.
185 operator MachineInstr*() const { return MI; }
186 MachineInstr *operator->() const { return MI; }
187 operator MachineBasicBlock::iterator() const { return MI; }
188
189 /// If conversion operators fail, use this method to get the MachineInstr
190 /// explicitly.
191 MachineInstr *getInstr() const { return MI; }
192
193 /// Get the register for the operand index.
194 /// The operand at the index should be a register (asserted by
195 /// MachineOperand).
196 Register getReg(unsigned Idx) const { return MI->getOperand(Idx).getReg(); }
197
198 /// Add a new virtual register operand.
199 const MachineInstrBuilder &addReg(Register RegNo, RegState Flags = {},
200 unsigned SubReg = 0) const {
202 "Passing in 'true' to addReg is forbidden! Use enums instead.");
203 MI->addOperand(*MF, MachineOperand::CreateReg(
204 RegNo, hasRegState(Flags, RegState::Define),
213
214 return *this;
215 }
216
217 /// Add a virtual register definition operand.
218 const MachineInstrBuilder &addDef(Register RegNo, RegState Flags = {},
219 unsigned SubReg = 0) const {
220 return addReg(RegNo, Flags | RegState::Define, SubReg);
221 }
222
223 /// Add a virtual register use operand. It is an error for Flags to contain
224 /// `RegState::Define` when calling this function.
225 const MachineInstrBuilder &addUse(Register RegNo, RegState Flags = {},
226 unsigned SubReg = 0) const {
228 "Misleading addUse defines register, use addReg instead.");
229 return addReg(RegNo, Flags, SubReg);
230 }
231
232 /// Add a new immediate operand.
233 const MachineInstrBuilder &addImm(int64_t Val) const {
235 return *this;
236 }
237
238 const MachineInstrBuilder &addCImm(const ConstantInt *Val) const {
240 return *this;
241 }
242
243 const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
245 return *this;
246 }
247
249 unsigned TargetFlags = 0) const {
250 MI->addOperand(*MF, MachineOperand::CreateMBB(MBB, TargetFlags));
251 return *this;
252 }
253
254 const MachineInstrBuilder &addFrameIndex(int Idx) const {
256 return *this;
257 }
258
259 const MachineInstrBuilder &
260 addConstantPoolIndex(unsigned Idx, int Offset = 0,
261 unsigned TargetFlags = 0) const {
262 MI->addOperand(*MF, MachineOperand::CreateCPI(Idx, Offset, TargetFlags));
263 return *this;
264 }
265
266 const MachineInstrBuilder &addTargetIndex(unsigned Idx, int64_t Offset = 0,
267 unsigned TargetFlags = 0) const {
269 TargetFlags));
270 return *this;
271 }
272
274 unsigned TargetFlags = 0) const {
275 MI->addOperand(*MF, MachineOperand::CreateJTI(Idx, TargetFlags));
276 return *this;
277 }
278
280 int64_t Offset = 0,
281 unsigned TargetFlags = 0) const {
282 MI->addOperand(*MF, MachineOperand::CreateGA(GV, Offset, TargetFlags));
283 return *this;
284 }
285
286 const MachineInstrBuilder &addExternalSymbol(const char *FnName,
287 unsigned TargetFlags = 0) const {
288 MI->addOperand(*MF, MachineOperand::CreateES(FnName, TargetFlags));
289 return *this;
290 }
291
293 int64_t Offset = 0,
294 unsigned TargetFlags = 0) const {
295 MI->addOperand(*MF, MachineOperand::CreateBA(BA, Offset, TargetFlags));
296 return *this;
297 }
298
299 const MachineInstrBuilder &addRegMask(const uint32_t *Mask) const {
301 return *this;
302 }
303
305 MI->addMemOperand(*MF, MMO);
306 return *this;
307 }
308
309 const MachineInstrBuilder &
311 MI->setMemRefs(*MF, MMOs);
312 return *this;
313 }
314
315 const MachineInstrBuilder &cloneMemRefs(const MachineInstr &OtherMI) const {
316 MI->cloneMemRefs(*MF, OtherMI);
317 return *this;
318 }
319
320 const MachineInstrBuilder &
322 MI->cloneMergedMemRefs(*MF, OtherMIs);
323 return *this;
324 }
325
326 const MachineInstrBuilder &add(const MachineOperand &MO) const {
327 MI->addOperand(*MF, MO);
328 return *this;
329 }
330
332 for (const MachineOperand &MO : MOs)
333 MI->addOperand(*MF, MO);
334 return *this;
335 }
336
337 const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
339 assert((MI->isDebugValueLike() ? static_cast<bool>(MI->getDebugVariable())
340 : true) &&
341 "first MDNode argument of a DBG_VALUE not a variable");
342 assert((MI->isDebugLabel() ? static_cast<bool>(MI->getDebugLabel())
343 : true) &&
344 "first MDNode argument of a DBG_LABEL not a label");
345 return *this;
346 }
347
348 const MachineInstrBuilder &addCFIIndex(unsigned CFIIndex) const {
349 MI->addOperand(*MF, MachineOperand::CreateCFIIndex(CFIIndex));
350 return *this;
351 }
352
357
360 return *this;
361 }
362
365 return *this;
366 }
367
369 MI->addOperand(*MF, MachineOperand::CreateLaneMask(LaneMask));
370 return *this;
371 }
372
374 unsigned char TargetFlags = 0) const {
375 MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym, TargetFlags));
376 return *this;
377 }
378
379 const MachineInstrBuilder &setMIFlags(unsigned Flags) const {
380 MI->setFlags(Flags);
381 return *this;
382 }
383
385 MI->setFlag(Flag);
386 return *this;
387 }
388
389 const MachineInstrBuilder &setOperandDead(unsigned OpIdx) const {
391 return *this;
392 }
393
394 // Add a displacement from an existing MachineOperand with an added offset.
395 const MachineInstrBuilder &addDisp(const MachineOperand &Disp, int64_t off,
396 unsigned char TargetFlags = 0) const {
397 // If caller specifies new TargetFlags then use it, otherwise the
398 // default behavior is to copy the target flags from the existing
399 // MachineOperand. This means if the caller wants to clear the
400 // target flags it needs to do so explicitly.
401 if (0 == TargetFlags)
402 TargetFlags = Disp.getTargetFlags();
403
404 switch (Disp.getType()) {
405 default:
406 llvm_unreachable("Unhandled operand type in addDisp()");
408 return addImm(Disp.getImm() + off);
410 return addConstantPoolIndex(Disp.getIndex(), Disp.getOffset() + off,
411 TargetFlags);
413 return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
414 TargetFlags);
416 return addBlockAddress(Disp.getBlockAddress(), Disp.getOffset() + off,
417 TargetFlags);
419 assert(off == 0 && "cannot create offset into jump tables");
420 return addJumpTableIndex(Disp.getIndex(), TargetFlags);
421 }
422 }
423
425 if (MIMD.getPCSections())
426 MI->setPCSections(*MF, MIMD.getPCSections());
427 if (MIMD.getMMRAMetadata())
428 MI->setMMRAMetadata(*MF, MIMD.getMMRAMetadata());
429 if (MIMD.getDeactivationSymbol())
430 MI->setDeactivationSymbol(*MF, MIMD.getDeactivationSymbol());
431 return *this;
432 }
433
434 /// Copy all the implicit operands from OtherMI onto this one.
435 const MachineInstrBuilder &
436 copyImplicitOps(const MachineInstr &OtherMI) const {
437 MI->copyImplicitOps(*MF, OtherMI);
438 return *this;
439 }
440
442 const TargetRegisterInfo &TRI,
443 const RegisterBankInfo &RBI) const {
444 return constrainSelectedInstRegOperands(*MI, TII, TRI, RBI);
445 }
446};
447
448/// Builder interface. Specify how to create the initial instruction itself.
450 const MCInstrDesc &MCID) {
451 return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, MIMD.getDL()))
452 .copyMIMetadata(MIMD);
453}
454
455/// This version of the builder sets up the first operand as a
456/// destination virtual register.
458 const MCInstrDesc &MCID, Register DestReg) {
459 return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, MIMD.getDL()))
460 .copyMIMetadata(MIMD)
461 .addReg(DestReg, RegState::Define);
462}
463
464/// This version of the builder inserts the newly-built instruction before
465/// the given position in the given MachineBasicBlock, and sets up the first
466/// operand as a destination virtual register.
469 const MIMetadata &MIMD,
470 const MCInstrDesc &MCID, Register DestReg) {
471 MachineFunction &MF = *BB.getParent();
472 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
473 BB.insert(I, MI);
475 DestReg, RegState::Define);
476}
477
478/// This version of the builder inserts the newly-built instruction before
479/// the given position in the given MachineBasicBlock, and sets up the first
480/// operand as a destination virtual register.
481///
482/// If \c I is inside a bundle, then the newly inserted \a MachineInstr is
483/// added to the same bundle.
486 const MIMetadata &MIMD,
487 const MCInstrDesc &MCID, Register DestReg) {
488 MachineFunction &MF = *BB.getParent();
489 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
490 BB.insert(I, MI);
492 DestReg, RegState::Define);
493}
494
496 const MIMetadata &MIMD,
497 const MCInstrDesc &MCID, Register DestReg) {
498 // Calling the overload for instr_iterator is always correct. However, the
499 // definition is not available in headers, so inline the check.
500 if (I.isInsideBundle())
502 DestReg);
503 return BuildMI(BB, MachineBasicBlock::iterator(I), MIMD, MCID, DestReg);
504}
505
507 const MIMetadata &MIMD,
508 const MCInstrDesc &MCID, Register DestReg) {
509 return BuildMI(BB, *I, MIMD, MCID, DestReg);
510}
511
512/// This version of the builder inserts the newly-built instruction before the
513/// given position in the given MachineBasicBlock, and does NOT take a
514/// destination register.
517 const MIMetadata &MIMD,
518 const MCInstrDesc &MCID) {
519 MachineFunction &MF = *BB.getParent();
520 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
521 BB.insert(I, MI);
522 return MachineInstrBuilder(MF, MI).copyMIMetadata(MIMD);
523}
524
527 const MIMetadata &MIMD,
528 const MCInstrDesc &MCID) {
529 MachineFunction &MF = *BB.getParent();
530 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
531 BB.insert(I, MI);
532 return MachineInstrBuilder(MF, MI).copyMIMetadata(MIMD);
533}
534
536 const MIMetadata &MIMD,
537 const MCInstrDesc &MCID) {
538 // Calling the overload for instr_iterator is always correct. However, the
539 // definition is not available in headers, so inline the check.
540 if (I.isInsideBundle())
542 return BuildMI(BB, MachineBasicBlock::iterator(I), MIMD, MCID);
543}
544
546 const MIMetadata &MIMD,
547 const MCInstrDesc &MCID) {
548 return BuildMI(BB, *I, MIMD, MCID);
549}
550
551/// This version of the builder inserts the newly-built instruction at the end
552/// of the given MachineBasicBlock, and does NOT take a destination register.
554 const MIMetadata &MIMD,
555 const MCInstrDesc &MCID) {
556 return BuildMI(*BB, BB->end(), MIMD, MCID);
557}
558
559/// This version of the builder inserts the newly-built instruction at the
560/// end of the given MachineBasicBlock, and sets up the first operand as a
561/// destination virtual register.
563 const MIMetadata &MIMD,
564 const MCInstrDesc &MCID, Register DestReg) {
565 return BuildMI(*BB, BB->end(), MIMD, MCID, DestReg);
566}
567
568/// This version of the builder builds a DBG_VALUE intrinsic
569/// for either a value in a register or a register-indirect
570/// address. The convention is that a DBG_VALUE is indirect iff the
571/// second operand is an immediate.
572LLVM_ABI MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
573 const MCInstrDesc &MCID, bool IsIndirect,
574 Register Reg, const MDNode *Variable,
575 const MDNode *Expr);
576
577/// This version of the builder builds a DBG_VALUE or DBG_VALUE_LIST intrinsic
578/// for a MachineOperand.
579LLVM_ABI MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
580 const MCInstrDesc &MCID, bool IsIndirect,
582 const MDNode *Variable,
583 const MDNode *Expr);
584
585/// This version of the builder builds a DBG_VALUE intrinsic
586/// for either a value in a register or a register-indirect
587/// address and inserts it at position I.
588LLVM_ABI MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
590 const DebugLoc &DL,
591 const MCInstrDesc &MCID, bool IsIndirect,
592 Register Reg, const MDNode *Variable,
593 const MDNode *Expr);
594
595/// This version of the builder builds a DBG_VALUE, DBG_INSTR_REF, or
596/// DBG_VALUE_LIST intrinsic for a machine operand and inserts it at position I.
597LLVM_ABI MachineInstrBuilder BuildMI(
598 MachineBasicBlock &BB, MachineBasicBlock::iterator I, const DebugLoc &DL,
599 const MCInstrDesc &MCID, bool IsIndirect, ArrayRef<MachineOperand> MOs,
600 const MDNode *Variable, const MDNode *Expr);
601
602/// Clone a DBG_VALUE whose value has been spilled to FrameIndex.
603LLVM_ABI MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
605 const MachineInstr &Orig,
606 int FrameIndex, Register SpillReg);
607LLVM_ABI MachineInstr *buildDbgValueForSpill(
608 MachineBasicBlock &BB, MachineBasicBlock::iterator I,
609 const MachineInstr &Orig, int FrameIndex,
610 const SmallVectorImpl<const MachineOperand *> &SpilledOperands);
611
612/// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
613/// modifying an instruction in place while iterating over a basic block.
614LLVM_ABI void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex,
615 Register Reg);
616
617/// Helper class for constructing bundles of MachineInstrs.
618///
619/// MIBundleBuilder can create a bundle from scratch by inserting new
620/// MachineInstrs one at a time, or it can create a bundle from a sequence of
621/// existing MachineInstrs in a basic block.
626
627public:
628 /// Create an MIBundleBuilder that inserts instructions into a new bundle in
629 /// BB above the bundle or instruction at Pos.
631 : MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
632
633 /// Create a bundle from the sequence of instructions between B and E.
636 : MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
637 assert(B != E && "No instructions to bundle");
638 ++B;
639 while (B != E) {
640 MachineInstr &MI = *B;
641 ++B;
642 MI.bundleWithPred();
643 }
644 }
645
646 /// Create an MIBundleBuilder representing an existing instruction or bundle
647 /// that has MI as its head.
649 : MBB(*MI->getParent()), Begin(MI),
650 End(getBundleEnd(MI->getIterator())) {}
651
652 /// Return a reference to the basic block containing this bundle.
653 MachineBasicBlock &getMBB() const { return MBB; }
654
655 /// Return true if no instructions have been inserted in this bundle yet.
656 /// Empty bundles aren't representable in a MachineBasicBlock.
657 bool empty() const { return Begin == End; }
658
659 /// Return an iterator to the first bundled instruction.
660 MachineBasicBlock::instr_iterator begin() const { return Begin; }
661
662 /// Return an iterator beyond the last bundled instruction.
664
665 /// Insert MI into this bundle before I which must point to an instruction in
666 /// the bundle, or end().
668 MachineInstr *MI) {
669 MBB.insert(I, MI);
670 if (I == Begin) {
671 if (!empty())
672 MI->bundleWithSucc();
673 Begin = MI->getIterator();
674 return *this;
675 }
676 if (I == End) {
677 MI->bundleWithPred();
678 return *this;
679 }
680 // MI was inserted in the middle of the bundle, so its neighbors' flags are
681 // already fine. Update MI's bundle flags manually.
684 return *this;
685 }
686
687 /// Insert MI into MBB by prepending it to the instructions in the bundle.
688 /// MI will become the first instruction in the bundle.
692
693 /// Insert MI into MBB by appending it to the instructions in the bundle.
694 /// MI will become the last instruction in the bundle.
696 return insert(end(), MI);
697 }
698};
699
700} // end namespace llvm
701
702#endif // LLVM_CODEGEN_MACHINEINSTRBUILDER_H
unsigned SubReg
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
const HexagonInstrInfo * TII
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:1080
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 & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
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 & 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 & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
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 & 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
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ 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.
RegState
Flags to represent properties of register accesses.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Dead
Unused definition.
@ Kill
The last use of a register.
@ InternalRead
Register reads a value that is defined inside the same instruction or bundle.
@ Undef
Value of the register doesn't matter.
@ EarlyClobber
Register definition happens before uses.
@ Define
Register definition.
@ Renamable
Register that may be renamed.
@ Debug
Register 'use' is for debugging purpose.
@ NoFlags
No Specific Flags.
constexpr RegState getImplRegState(bool B)
LLVM_ABI void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex, Register Reg)
Update a DBG_VALUE whose value has been spilled to FrameIndex.
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr RegState getInternalReadRegState(bool B)
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
constexpr RegState getDeadRegState(bool B)
constexpr RegState getRenamableRegState(bool B)
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
constexpr RegState getDefRegState(bool B)
RegState getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
constexpr bool hasRegState(RegState Value, RegState Test)
constexpr RegState getEarlyClobberRegState(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:1915
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.
constexpr RegState getDebugRegState(bool B)
constexpr RegState getUndefRegState(bool B)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870