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