LLVM: include/llvm/CodeGen/MachineInstrBuilder.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H
20#define LLVM_CODEGEN_MACHINEINSTRBUILDER_H
21
34#include
35#include
36
37namespace llvm {
38
41
43
44
45enum {
46
48
50
52
54
56
58
60
61
63
68};
69
70}
71
72
73
74
76public:
79 Value *DeactivationSymbol = nullptr)
80 : DL(std::move(DL)), PCSections(PCSections), MMRA(MMRA),
81 DeactivationSymbol(DeactivationSymbol) {}
83 MDNode *MMRA = nullptr)
84 : DL(DI), PCSections(PCSections), MMRA(MMRA) {}
87 PCSections(From.getMetadata(LLVMContext::MD_pcsections)),
92
97
98private:
100 MDNode *PCSections = nullptr;
101 MDNode *MMRA = nullptr;
102 Value *DeactivationSymbol = nullptr;
103
106 if (auto Bundle =
108 return Bundle->Inputs[0].get();
109 return nullptr;
110 }
111};
112
116
117public:
119
120
121
125
126
130
131
132
134
135
136
137
138 Register getReg(unsigned Idx) const { return MI->getOperand(Idx).getReg(); }
139
140
142 unsigned SubReg = 0) const {
143 assert((flags & 0x1) == 0 &&
144 "Passing in 'true' to addReg is forbidden! Use enums instead.");
156 return *this;
157 }
158
159
161 unsigned SubReg = 0) const {
163 }
164
165
166
168 unsigned SubReg = 0) const {
170 "Misleading addUse defines register, use addReg instead.");
172 }
173
174
179
184
189
191 unsigned TargetFlags = 0) const {
193 return *this;
194 }
195
200
203 unsigned TargetFlags = 0) const {
205 return *this;
206 }
207
209 unsigned TargetFlags = 0) const {
211 TargetFlags));
212 return *this;
213 }
214
216 unsigned TargetFlags = 0) const {
218 return *this;
219 }
220
223 unsigned TargetFlags = 0) const {
225 return *this;
226 }
227
229 unsigned TargetFlags = 0) const {
231 return *this;
232 }
233
236 unsigned TargetFlags = 0) const {
238 return *this;
239 }
240
245
250
256
261
267
272
278
281 assert((MI->isDebugValueLike() ? static_cast<bool>(MI->getDebugVariable())
282 : true) &&
283 "first MDNode argument of a DBG_VALUE not a variable");
284 assert((MI->isDebugLabel() ? static_cast<bool>(MI->getDebugLabel())
285 : true) &&
286 "first MDNode argument of a DBG_LABEL not a label");
287 return *this;
288 }
289
294
299
304
309
314
316 unsigned char TargetFlags = 0) const {
318 return *this;
319 }
320
325
330
335
336
338 unsigned char TargetFlags = 0) const {
339
340
341
342
343 if (0 == TargetFlags)
345
346 switch (Disp.getType()) {
347 default:
353 TargetFlags);
356 TargetFlags);
359 TargetFlags);
361 assert(off == 0 && "cannot create offset into jump tables");
363 }
364 }
365
375
376
382
388};
389
390
396
397
398
405
406
407
408
419
420
421
422
423
424
425
436
440
441
442 if (I.isInsideBundle())
444 DestReg);
446}
447
453
454
455
456
466
476
480
481
482 if (I.isInsideBundle())
485}
486
492
493
494
500
501
502
503
509
510
511
512
513
515 const MCInstrDesc &MCID, bool IsIndirect,
517 const MDNode *Expr);
518
519
520
522 const MCInstrDesc &MCID, bool IsIndirect,
524 const MDNode *Variable,
525 const MDNode *Expr);
526
527
528
529
530LLVM_ABI MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
533 const MCInstrDesc &MCID, bool IsIndirect,
535 const MDNode *Expr);
536
537
538
542 const MDNode *Variable, const MDNode *Expr);
543
544
547 const MachineInstr &Orig,
548 int FrameIndex, Register SpillReg);
551 const MachineInstr &Orig, int FrameIndex,
552 const SmallVectorImpl<const MachineOperand *> &SpilledOperands);
553
554
555
558
583
584
586 assert(RegOp.isReg() && "Not a register operand");
594}
595
596
597
598
599
600
605
606public:
607
608
610 : MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
611
612
615 : MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
616 assert(B != E && "No instructions to bundle");
617 ++B;
620 ++B;
621 MI.bundleWithPred();
622 }
623 }
624
625
626
630
631
633
634
635
636 bool empty() const { return Begin == End; }
637
638
640
641
643
644
645
649 if (I == Begin) {
651 MI->bundleWithSucc();
652 Begin = MI->getIterator();
653 return *this;
654 }
655 if (I == End) {
656 MI->bundleWithPred();
657 return *this;
658 }
659
660
663 return *this;
664 }
665
666
667
671
672
673
677};
678
679}
680
681#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
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")
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 const TargetRegisterInfo * TRI
Promote Memory to Register
MachineInstr unsigned OpIdx
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
The address of a basic block.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This is an important class for using LLVM in a threaded context.
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 ...
MachineBasicBlock::instr_iterator end() const
Return an iterator beyond the last bundled instruction.
Definition MachineInstrBuilder.h:642
MachineBasicBlock::instr_iterator begin() const
Return an iterator to the first bundled instruction.
Definition MachineInstrBuilder.h:639
MIBundleBuilder & append(MachineInstr *MI)
Insert MI into MBB by appending it to the instructions in the bundle.
Definition MachineInstrBuilder.h:674
MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator B, MachineBasicBlock::iterator E)
Create a bundle from the sequence of instructions between B and E.
Definition MachineInstrBuilder.h:613
MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator Pos)
Create an MIBundleBuilder that inserts instructions into a new bundle in BB above the bundle or instr...
Definition MachineInstrBuilder.h:609
MIBundleBuilder & insert(MachineBasicBlock::instr_iterator I, MachineInstr *MI)
Insert MI into this bundle before I which must point to an instruction in the bundle,...
Definition MachineInstrBuilder.h:646
MachineBasicBlock & getMBB() const
Return a reference to the basic block containing this bundle.
Definition MachineInstrBuilder.h:632
MIBundleBuilder & prepend(MachineInstr *MI)
Insert MI into MBB by prepending it to the instructions in the bundle.
Definition MachineInstrBuilder.h:668
bool empty() const
Return true if no instructions have been inserted in this bundle yet.
Definition MachineInstrBuilder.h:636
MIBundleBuilder(MachineInstr *MI)
Create an MIBundleBuilder representing an existing instruction or bundle that has MI as its head.
Definition MachineInstrBuilder.h:627
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
Definition MachineInstrBuilder.h:263
const MachineInstrBuilder & addTargetIndex(unsigned Idx, int64_t Offset=0, unsigned TargetFlags=0) const
Definition MachineInstrBuilder.h:208
Register getReg(unsigned Idx) const
Get the register for the operand index.
Definition MachineInstrBuilder.h:138
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand * > MMOs) const
Definition MachineInstrBuilder.h:252
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
Definition MachineInstrBuilder.h:228
const MachineInstrBuilder & addCImm(const ConstantInt *Val) const
Definition MachineInstrBuilder.h:180
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
Definition MachineInstrBuilder.h:290
const MachineInstrBuilder & setOperandDead(unsigned OpIdx) const
Definition MachineInstrBuilder.h:331
MachineInstrBuilder()=default
MachineInstrBuilder(MachineFunction &F, MachineInstr *I)
Create a MachineInstrBuilder for manipulating an existing instruction.
Definition MachineInstrBuilder.h:122
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
Definition MachineInstrBuilder.h:326
MachineInstr * operator->() const
Definition MachineInstrBuilder.h:128
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition MachineInstrBuilder.h:175
const MachineInstrBuilder & addPredicate(CmpInst::Predicate Pred) const
Definition MachineInstrBuilder.h:300
const MachineInstrBuilder & addBlockAddress(const BlockAddress *BA, int64_t Offset=0, unsigned TargetFlags=0) const
Definition MachineInstrBuilder.h:234
const MachineInstrBuilder & add(const MachineOperand &MO) const
Definition MachineInstrBuilder.h:268
const MachineInstrBuilder & addIntrinsicID(Intrinsic::ID ID) const
Definition MachineInstrBuilder.h:295
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
Definition MachineInstrBuilder.h:279
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
Definition MachineInstrBuilder.h:315
const MachineInstrBuilder & addShuffleMask(ArrayRef< int > Val) const
Definition MachineInstrBuilder.h:305
MachineInstrBuilder(MachineFunction &F, MachineBasicBlock::iterator I)
Definition MachineInstrBuilder.h:123
const MachineInstrBuilder & addFrameIndex(int Idx) const
Definition MachineInstrBuilder.h:196
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned TargetFlags=0) const
Definition MachineInstrBuilder.h:202
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
Definition MachineInstrBuilder.h:241
const MachineInstrBuilder & add(ArrayRef< MachineOperand > MOs) const
Definition MachineInstrBuilder.h:273
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
Definition MachineInstrBuilder.h:221
const MachineInstrBuilder & addDisp(const MachineOperand &Disp, int64_t off, unsigned char TargetFlags=0) const
Definition MachineInstrBuilder.h:337
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition MachineInstrBuilder.h:141
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
Definition MachineInstrBuilder.h:185
bool constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Definition MachineInstrBuilder.h:383
const MachineInstrBuilder & addJumpTableIndex(unsigned Idx, unsigned TargetFlags=0) const
Definition MachineInstrBuilder.h:215
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Definition MachineInstrBuilder.h:190
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
Definition MachineInstrBuilder.h:257
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
Definition MachineInstrBuilder.h:167
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
Definition MachineInstrBuilder.h:321
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
Definition MachineInstrBuilder.h:378
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Definition MachineInstrBuilder.h:246
const MachineInstrBuilder & addLaneMask(LaneBitmask LaneMask) const
Definition MachineInstrBuilder.h:310
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Definition MachineInstrBuilder.h:133
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Definition MachineInstrBuilder.h:160
const MachineInstrBuilder & copyMIMetadata(const MIMetadata &MIMD) const
Definition MachineInstrBuilder.h:366
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)
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.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
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.
#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.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
Definition MachineInstrBuilder.h:49
@ Debug
Register 'use' is for debugging purpose.
Definition MachineInstrBuilder.h:59
@ Dead
Unused definition.
Definition MachineInstrBuilder.h:53
@ Renamable
Register that may be renamed.
Definition MachineInstrBuilder.h:64
@ Define
Register definition.
Definition MachineInstrBuilder.h:47
@ InternalRead
Register reads a value that is defined inside the same instruction or bundle.
Definition MachineInstrBuilder.h:62
@ ImplicitDefine
Definition MachineInstrBuilder.h:66
@ Kill
The last use of a register.
Definition MachineInstrBuilder.h:51
@ Undef
Value of the register doesn't matter.
Definition MachineInstrBuilder.h:55
@ EarlyClobber
Register definition happens before uses.
Definition MachineInstrBuilder.h:57
@ ImplicitKill
Definition MachineInstrBuilder.h:67
@ DefineNoRead
Definition MachineInstrBuilder.h:65
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition MachineInstrBuilder.h:391
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 - Return the argument parameter cast to the specified type.
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...
unsigned getDeadRegState(bool B)
Definition MachineInstrBuilder.h:568
unsigned getImplRegState(bool B)
Definition MachineInstrBuilder.h:562
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
unsigned getInternalReadRegState(bool B)
Definition MachineInstrBuilder.h:574
unsigned getDebugRegState(bool B)
Definition MachineInstrBuilder.h:577
unsigned getUndefRegState(bool B)
Definition MachineInstrBuilder.h:571
unsigned getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
Definition MachineInstrBuilder.h:585
unsigned getDefRegState(bool B)
Definition MachineInstrBuilder.h:559
unsigned getKillRegState(bool B)
Definition MachineInstrBuilder.h:565
unsigned getRenamableRegState(bool B)
Definition MachineInstrBuilder.h:580
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.
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.