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 DebugLoc, PCSections and MMRA.
75public:
76 MIMetadata() = default;
77 MIMetadata(DebugLoc DL, MDNode *PCSections = nullptr, MDNode *MMRA = nullptr)
78 : DL(std::move(DL)), PCSections(PCSections), MMRA(MMRA) {}
79 MIMetadata(const DILocation *DI, MDNode *PCSections = nullptr,
80 MDNode *MMRA = nullptr)
81 : DL(DI), PCSections(PCSections), MMRA(MMRA) {}
82 explicit MIMetadata(const Instruction &From)
83 : DL(From.getDebugLoc()),
84 PCSections(From.getMetadata(LLVMContext::MD_pcsections)) {}
85 explicit MIMetadata(const MachineInstr &From)
86 : DL(From.getDebugLoc()), PCSections(From.getPCSections()) {}
87
88 const DebugLoc &getDL() const { return DL; }
89 MDNode *getPCSections() const { return PCSections; }
90 MDNode *getMMRAMetadata() const { return MMRA; }
91
92private:
93 DebugLoc DL;
94 MDNode *PCSections = nullptr;
95 MDNode *MMRA = nullptr;
96};
97
99 MachineFunction *MF = nullptr;
100 MachineInstr *MI = nullptr;
101
102public:
104
105 /// Create a MachineInstrBuilder for manipulating an existing instruction.
106 /// F must be the machine function that was used to allocate I.
109 : MF(&F), MI(&*I) {}
110
111 /// Allow automatic conversion to the machine instruction we are working on.
112 operator MachineInstr*() const { return MI; }
113 MachineInstr *operator->() const { return MI; }
114 operator MachineBasicBlock::iterator() const { return MI; }
115
116 /// If conversion operators fail, use this method to get the MachineInstr
117 /// explicitly.
118 MachineInstr *getInstr() const { return MI; }
119
120 /// Get the register for the operand index.
121 /// The operand at the index should be a register (asserted by
122 /// MachineOperand).
123 Register getReg(unsigned Idx) const { return MI->getOperand(Idx).getReg(); }
124
125 /// Add a new virtual register operand.
126 const MachineInstrBuilder &addReg(Register RegNo, unsigned flags = 0,
127 unsigned SubReg = 0) const {
128 assert((flags & 0x1) == 0 &&
129 "Passing in 'true' to addReg is forbidden! Use enums instead.");
130 MI->addOperand(*MF, MachineOperand::CreateReg(RegNo,
131 flags & RegState::Define,
132 flags & RegState::Implicit,
133 flags & RegState::Kill,
134 flags & RegState::Dead,
135 flags & RegState::Undef,
137 SubReg,
138 flags & RegState::Debug,
140 flags & RegState::Renamable));
141 return *this;
142 }
143
144 /// Add a virtual register definition operand.
145 const MachineInstrBuilder &addDef(Register RegNo, unsigned Flags = 0,
146 unsigned SubReg = 0) const {
147 return addReg(RegNo, Flags | RegState::Define, SubReg);
148 }
149
150 /// Add a virtual register use operand. It is an error for Flags to contain
151 /// `RegState::Define` when calling this function.
152 const MachineInstrBuilder &addUse(Register RegNo, unsigned Flags = 0,
153 unsigned SubReg = 0) const {
154 assert(!(Flags & RegState::Define) &&
155 "Misleading addUse defines register, use addReg instead.");
156 return addReg(RegNo, Flags, SubReg);
157 }
158
159 /// Add a new immediate operand.
160 const MachineInstrBuilder &addImm(int64_t Val) const {
161 MI->addOperand(*MF, MachineOperand::CreateImm(Val));
162 return *this;
163 }
164
165 const MachineInstrBuilder &addCImm(const ConstantInt *Val) const {
166 MI->addOperand(*MF, MachineOperand::CreateCImm(Val));
167 return *this;
168 }
169
170 const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
171 MI->addOperand(*MF, MachineOperand::CreateFPImm(Val));
172 return *this;
173 }
174
176 unsigned TargetFlags = 0) const {
177 MI->addOperand(*MF, MachineOperand::CreateMBB(MBB, TargetFlags));
178 return *this;
179 }
180
182 MI->addOperand(*MF, MachineOperand::CreateFI(Idx));
183 return *this;
184 }
185
186 const MachineInstrBuilder &
187 addConstantPoolIndex(unsigned Idx, int Offset = 0,
188 unsigned TargetFlags = 0) const {
189 MI->addOperand(*MF, MachineOperand::CreateCPI(Idx, Offset, TargetFlags));
190 return *this;
191 }
192
193 const MachineInstrBuilder &addTargetIndex(unsigned Idx, int64_t Offset = 0,
194 unsigned TargetFlags = 0) const {
196 TargetFlags));
197 return *this;
198 }
199
201 unsigned TargetFlags = 0) const {
202 MI->addOperand(*MF, MachineOperand::CreateJTI(Idx, TargetFlags));
203 return *this;
204 }
205
207 int64_t Offset = 0,
208 unsigned TargetFlags = 0) const {
209 MI->addOperand(*MF, MachineOperand::CreateGA(GV, Offset, TargetFlags));
210 return *this;
211 }
212
213 const MachineInstrBuilder &addExternalSymbol(const char *FnName,
214 unsigned TargetFlags = 0) const {
215 MI->addOperand(*MF, MachineOperand::CreateES(FnName, TargetFlags));
216 return *this;
217 }
218
220 int64_t Offset = 0,
221 unsigned TargetFlags = 0) const {
222 MI->addOperand(*MF, MachineOperand::CreateBA(BA, Offset, TargetFlags));
223 return *this;
224 }
225
226 const MachineInstrBuilder &addRegMask(const uint32_t *Mask) const {
227 MI->addOperand(*MF, MachineOperand::CreateRegMask(Mask));
228 return *this;
229 }
230
232 MI->addMemOperand(*MF, MMO);
233 return *this;
234 }
235
236 const MachineInstrBuilder &
238 MI->setMemRefs(*MF, MMOs);
239 return *this;
240 }
241
242 const MachineInstrBuilder &cloneMemRefs(const MachineInstr &OtherMI) const {
243 MI->cloneMemRefs(*MF, OtherMI);
244 return *this;
245 }
246
247 const MachineInstrBuilder &
249 MI->cloneMergedMemRefs(*MF, OtherMIs);
250 return *this;
251 }
252
253 const MachineInstrBuilder &add(const MachineOperand &MO) const {
254 MI->addOperand(*MF, MO);
255 return *this;
256 }
257
259 for (const MachineOperand &MO : MOs)
260 MI->addOperand(*MF, MO);
261 return *this;
262 }
263
264 const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
265 MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
266 assert((MI->isDebugValueLike() ? static_cast<bool>(MI->getDebugVariable())
267 : true) &&
268 "first MDNode argument of a DBG_VALUE not a variable");
269 assert((MI->isDebugLabel() ? static_cast<bool>(MI->getDebugLabel())
270 : true) &&
271 "first MDNode argument of a DBG_LABEL not a label");
272 return *this;
273 }
274
275 const MachineInstrBuilder &addCFIIndex(unsigned CFIIndex) const {
276 MI->addOperand(*MF, MachineOperand::CreateCFIIndex(CFIIndex));
277 return *this;
278 }
279
281 MI->addOperand(*MF, MachineOperand::CreateIntrinsicID(ID));
282 return *this;
283 }
284
286 MI->addOperand(*MF, MachineOperand::CreatePredicate(Pred));
287 return *this;
288 }
289
291 MI->addOperand(*MF, MachineOperand::CreateShuffleMask(Val));
292 return *this;
293 }
294
296 unsigned char TargetFlags = 0) const {
297 MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym, TargetFlags));
298 return *this;
299 }
300
301 const MachineInstrBuilder &setMIFlags(unsigned Flags) const {
302 MI->setFlags(Flags);
303 return *this;
304 }
305
307 MI->setFlag(Flag);
308 return *this;
309 }
310
311 const MachineInstrBuilder &setOperandDead(unsigned OpIdx) const {
312 MI->getOperand(OpIdx).setIsDead();
313 return *this;
314 }
315
316 // Add a displacement from an existing MachineOperand with an added offset.
317 const MachineInstrBuilder &addDisp(const MachineOperand &Disp, int64_t off,
318 unsigned char TargetFlags = 0) const {
319 // If caller specifies new TargetFlags then use it, otherwise the
320 // default behavior is to copy the target flags from the existing
321 // MachineOperand. This means if the caller wants to clear the
322 // target flags it needs to do so explicitly.
323 if (0 == TargetFlags)
324 TargetFlags = Disp.getTargetFlags();
325
326 switch (Disp.getType()) {
327 default:
328 llvm_unreachable("Unhandled operand type in addDisp()");
330 return addImm(Disp.getImm() + off);
332 return addConstantPoolIndex(Disp.getIndex(), Disp.getOffset() + off,
333 TargetFlags);
335 return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
336 TargetFlags);
338 return addBlockAddress(Disp.getBlockAddress(), Disp.getOffset() + off,
339 TargetFlags);
341 assert(off == 0 && "cannot create offset into jump tables");
342 return addJumpTableIndex(Disp.getIndex(), TargetFlags);
343 }
344 }
345
347 if (MIMD.getPCSections())
348 MI->setPCSections(*MF, MIMD.getPCSections());
349 if (MIMD.getMMRAMetadata())
350 MI->setMMRAMetadata(*MF, MIMD.getMMRAMetadata());
351 return *this;
352 }
353
354 /// Copy all the implicit operands from OtherMI onto this one.
355 const MachineInstrBuilder &
356 copyImplicitOps(const MachineInstr &OtherMI) const {
357 MI->copyImplicitOps(*MF, OtherMI);
358 return *this;
359 }
360
362 const TargetRegisterInfo &TRI,
363 const RegisterBankInfo &RBI) const {
365 }
366};
367
368/// Builder interface. Specify how to create the initial instruction itself.
370 const MCInstrDesc &MCID) {
371 return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, MIMD.getDL()))
372 .copyMIMetadata(MIMD);
373}
374
375/// This version of the builder sets up the first operand as a
376/// destination virtual register.
378 const MCInstrDesc &MCID, Register DestReg) {
379 return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, MIMD.getDL()))
380 .copyMIMetadata(MIMD)
381 .addReg(DestReg, RegState::Define);
382}
383
384/// This version of the builder inserts the newly-built instruction before
385/// the given position in the given MachineBasicBlock, and sets up the first
386/// operand as a destination virtual register.
389 const MIMetadata &MIMD,
390 const MCInstrDesc &MCID, Register DestReg) {
391 MachineFunction &MF = *BB.getParent();
392 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
393 BB.insert(I, MI);
395 DestReg, RegState::Define);
396}
397
398/// This version of the builder inserts the newly-built instruction before
399/// the given position in the given MachineBasicBlock, and sets up the first
400/// operand as a destination virtual register.
401///
402/// If \c I is inside a bundle, then the newly inserted \a MachineInstr is
403/// added to the same bundle.
406 const MIMetadata &MIMD,
407 const MCInstrDesc &MCID, Register DestReg) {
408 MachineFunction &MF = *BB.getParent();
409 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
410 BB.insert(I, MI);
412 DestReg, RegState::Define);
413}
414
416 const MIMetadata &MIMD,
417 const MCInstrDesc &MCID, Register DestReg) {
418 // Calling the overload for instr_iterator is always correct. However, the
419 // definition is not available in headers, so inline the check.
420 if (I.isInsideBundle())
421 return BuildMI(BB, MachineBasicBlock::instr_iterator(I), MIMD, MCID,
422 DestReg);
423 return BuildMI(BB, MachineBasicBlock::iterator(I), MIMD, MCID, DestReg);
424}
425
427 const MIMetadata &MIMD,
428 const MCInstrDesc &MCID, Register DestReg) {
429 return BuildMI(BB, *I, MIMD, MCID, DestReg);
430}
431
432/// This version of the builder inserts the newly-built instruction before the
433/// given position in the given MachineBasicBlock, and does NOT take a
434/// destination register.
437 const MIMetadata &MIMD,
438 const MCInstrDesc &MCID) {
439 MachineFunction &MF = *BB.getParent();
440 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
441 BB.insert(I, MI);
442 return MachineInstrBuilder(MF, MI).copyMIMetadata(MIMD);
443}
444
447 const MIMetadata &MIMD,
448 const MCInstrDesc &MCID) {
449 MachineFunction &MF = *BB.getParent();
450 MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
451 BB.insert(I, MI);
452 return MachineInstrBuilder(MF, MI).copyMIMetadata(MIMD);
453}
454
456 const MIMetadata &MIMD,
457 const MCInstrDesc &MCID) {
458 // Calling the overload for instr_iterator is always correct. However, the
459 // definition is not available in headers, so inline the check.
460 if (I.isInsideBundle())
461 return BuildMI(BB, MachineBasicBlock::instr_iterator(I), MIMD, MCID);
462 return BuildMI(BB, MachineBasicBlock::iterator(I), MIMD, MCID);
463}
464
466 const MIMetadata &MIMD,
467 const MCInstrDesc &MCID) {
468 return BuildMI(BB, *I, MIMD, MCID);
469}
470
471/// This version of the builder inserts the newly-built instruction at the end
472/// of the given MachineBasicBlock, and does NOT take a destination register.
474 const MIMetadata &MIMD,
475 const MCInstrDesc &MCID) {
476 return BuildMI(*BB, BB->end(), MIMD, MCID);
477}
478
479/// This version of the builder inserts the newly-built instruction at the
480/// end of the given MachineBasicBlock, and sets up the first operand as a
481/// destination virtual register.
483 const MIMetadata &MIMD,
484 const MCInstrDesc &MCID, Register DestReg) {
485 return BuildMI(*BB, BB->end(), MIMD, MCID, DestReg);
486}
487
488/// This version of the builder builds a DBG_VALUE intrinsic
489/// for either a value in a register or a register-indirect
490/// address. The convention is that a DBG_VALUE is indirect iff the
491/// second operand is an immediate.
492LLVM_ABI MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
493 const MCInstrDesc &MCID, bool IsIndirect,
494 Register Reg, const MDNode *Variable,
495 const MDNode *Expr);
496
497/// This version of the builder builds a DBG_VALUE or DBG_VALUE_LIST intrinsic
498/// for a MachineOperand.
499LLVM_ABI MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
500 const MCInstrDesc &MCID, bool IsIndirect,
501 ArrayRef<MachineOperand> MOs,
502 const MDNode *Variable,
503 const MDNode *Expr);
504
505/// This version of the builder builds a DBG_VALUE intrinsic
506/// for either a value in a register or a register-indirect
507/// address and inserts it at position I.
508LLVM_ABI MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
510 const DebugLoc &DL,
511 const MCInstrDesc &MCID, bool IsIndirect,
512 Register Reg, const MDNode *Variable,
513 const MDNode *Expr);
514
515/// This version of the builder builds a DBG_VALUE, DBG_INSTR_REF, or
516/// DBG_VALUE_LIST intrinsic for a machine operand and inserts it at position I.
517LLVM_ABI MachineInstrBuilder BuildMI(
518 MachineBasicBlock &BB, MachineBasicBlock::iterator I, const DebugLoc &DL,
519 const MCInstrDesc &MCID, bool IsIndirect, ArrayRef<MachineOperand> MOs,
520 const MDNode *Variable, const MDNode *Expr);
521
522/// Clone a DBG_VALUE whose value has been spilled to FrameIndex.
523LLVM_ABI MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
525 const MachineInstr &Orig,
526 int FrameIndex, Register SpillReg);
527LLVM_ABI MachineInstr *buildDbgValueForSpill(
528 MachineBasicBlock &BB, MachineBasicBlock::iterator I,
529 const MachineInstr &Orig, int FrameIndex,
530 const SmallVectorImpl<const MachineOperand *> &SpilledOperands);
531
532/// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
533/// modifying an instruction in place while iterating over a basic block.
534LLVM_ABI void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex,
535 Register Reg);
536
537inline unsigned getDefRegState(bool B) {
538 return B ? RegState::Define : 0;
539}
540inline unsigned getImplRegState(bool B) {
541 return B ? RegState::Implicit : 0;
542}
543inline unsigned getKillRegState(bool B) {
544 return B ? RegState::Kill : 0;
545}
546inline unsigned getDeadRegState(bool B) {
547 return B ? RegState::Dead : 0;
548}
549inline unsigned getUndefRegState(bool B) {
550 return B ? RegState::Undef : 0;
551}
552inline unsigned getInternalReadRegState(bool B) {
553 return B ? RegState::InternalRead : 0;
554}
555inline unsigned getDebugRegState(bool B) {
556 return B ? RegState::Debug : 0;
557}
558inline unsigned getRenamableRegState(bool B) {
559 return B ? RegState::Renamable : 0;
560}
561
562/// Get all register state flags from machine operand \p RegOp.
563inline unsigned getRegState(const MachineOperand &RegOp) {
564 assert(RegOp.isReg() && "Not a register operand");
565 return getDefRegState(RegOp.isDef()) | getImplRegState(RegOp.isImplicit()) |
566 getKillRegState(RegOp.isKill()) | getDeadRegState(RegOp.isDead()) |
567 getUndefRegState(RegOp.isUndef()) |
569 getDebugRegState(RegOp.isDebug()) |
571 RegOp.isRenamable());
572}
573
574/// Helper class for constructing bundles of MachineInstrs.
575///
576/// MIBundleBuilder can create a bundle from scratch by inserting new
577/// MachineInstrs one at a time, or it can create a bundle from a sequence of
578/// existing MachineInstrs in a basic block.
583
584public:
585 /// Create an MIBundleBuilder that inserts instructions into a new bundle in
586 /// BB above the bundle or instruction at Pos.
588 : MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
589
590 /// Create a bundle from the sequence of instructions between B and E.
593 : MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
594 assert(B != E && "No instructions to bundle");
595 ++B;
596 while (B != E) {
597 MachineInstr &MI = *B;
598 ++B;
599 MI.bundleWithPred();
600 }
601 }
602
603 /// Create an MIBundleBuilder representing an existing instruction or bundle
604 /// that has MI as its head.
606 : MBB(*MI->getParent()), Begin(MI),
607 End(getBundleEnd(MI->getIterator())) {}
608
609 /// Return a reference to the basic block containing this bundle.
610 MachineBasicBlock &getMBB() const { return MBB; }
611
612 /// Return true if no instructions have been inserted in this bundle yet.
613 /// Empty bundles aren't representable in a MachineBasicBlock.
614 bool empty() const { return Begin == End; }
615
616 /// Return an iterator to the first bundled instruction.
617 MachineBasicBlock::instr_iterator begin() const { return Begin; }
618
619 /// Return an iterator beyond the last bundled instruction.
621
622 /// Insert MI into this bundle before I which must point to an instruction in
623 /// the bundle, or end().
625 MachineInstr *MI) {
626 MBB.insert(I, MI);
627 if (I == Begin) {
628 if (!empty())
629 MI->bundleWithSucc();
630 Begin = MI->getIterator();
631 return *this;
632 }
633 if (I == End) {
634 MI->bundleWithPred();
635 return *this;
636 }
637 // MI was inserted in the middle of the bundle, so its neighbors' flags are
638 // already fine. Update MI's bundle flags manually.
641 return *this;
642 }
643
644 /// Insert MI into MBB by prepending it to the instructions in the bundle.
645 /// MI will become the first instruction in the bundle.
647 return insert(begin(), MI);
648 }
649
650 /// Insert MI into MBB by appending it to the instructions in the bundle.
651 /// MI will become the last instruction in the bundle.
653 return insert(end(), MI);
654 }
655};
656
657} // end namespace llvm
658
659#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)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
bool End
Definition: ELF_riscv.cpp:480
Symbol * Sym
Definition: ELF_riscv.cpp:479
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
Register Reg
Register const TargetRegisterInfo * TRI
MachineInstr unsigned OpIdx
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
The address of a basic block.
Definition: Constants.h:899
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:678
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:277
This is the shared class of boolean and integer constants.
Definition: Constants.h:87
Debug location.
A debug info location.
Definition: DebugLoc.h:124
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.
Definition: MCInstrDesc.h:199
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:1077
Helper class for constructing bundles of MachineInstrs.
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(DebugLoc DL, MDNode *PCSections=nullptr, MDNode *MMRA=nullptr)
MIMetadata(const Instruction &From)
MIMetadata(const MachineInstr &From)
MDNode * getPCSections() const
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
MachineInstr * CreateMachineInstr(const MCInstrDesc &MCID, DebugLoc DL, bool NoImplicit=false)
CreateMachineInstr - Allocate a new MachineInstr.
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
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.
Definition: MachineInstr.h:72
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
bool isImplicit() 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)
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 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:19
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:78
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ 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.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
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.
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)
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:1886
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:856