32 this->InsertedInstr =
nullptr;
39 "Basic block is in a different function");
51 "Basic block is in a different function");
58 InsertedInstr = std::move(Inserted);
62 InsertedInstr =
nullptr;
88 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
89 assert(cast<DIExpression>(Expr)->
isValid() &&
"not an expression");
90 assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
91 "Expected inlined-at fields to agree");
101 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
102 assert(cast<DIExpression>(Expr)->
isValid() &&
"not an expression");
103 assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
104 "Expected inlined-at fields to agree");
115 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
116 assert(cast<DIExpression>(Expr)->
isValid() &&
"not an expression");
117 assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
118 "Expected inlined-at fields to agree");
130 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
131 assert(cast<DIExpression>(Expr)->
isValid() &&
"not an expression");
132 assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
133 "Expected inlined-at fields to agree");
134 auto MIB =
buildInstr(TargetOpcode::DBG_VALUE);
135 if (
auto *CI = dyn_cast<ConstantInt>(&C)) {
136 if (CI->getBitWidth() > 64)
139 MIB.addImm(CI->getZExtValue());
140 }
else if (
auto *CFP = dyn_cast<ConstantFP>(&C)) {
147 return MIB.addImm(Offset).addMetadata(Variable).addMetadata(Expr);
152 return buildInstr(TargetOpcode::G_FRAME_INDEX)
162 "address space mismatch");
164 return buildInstr(TargetOpcode::G_GLOBAL_VALUE)
169 MachineInstrBuilder MachineIRBuilder::buildBinaryOp(
unsigned Opcode,
unsigned Res,
unsigned Op0,
172 "invalid operand type");
184 return buildBinaryOp(TargetOpcode::G_ADD, Res, Op0, Op1);
201 const LLT &ValueTy, uint64_t
Value) {
202 assert(Res == 0 &&
"Res is a result argument");
230 return buildBinaryOp(TargetOpcode::G_SUB, Res, Op0, Op1);
235 return buildBinaryOp(TargetOpcode::G_MUL, Res, Op0, Op1);
240 return buildBinaryOp(TargetOpcode::G_AND, Res, Op0, Op1);
245 return buildBinaryOp(TargetOpcode::G_OR, Res, Op0, Op1);
323 unsigned Op0,
unsigned Op1,
340 validateTruncExt(Res, Op,
true);
345 validateTruncExt(Res, Op,
true);
350 validateTruncExt(Res, Op,
true);
359 unsigned Opcode = TargetOpcode::COPY;
361 Opcode = TargetOpcode::G_SEXT;
363 Opcode = TargetOpcode::G_TRUNC;
375 unsigned Opcode = TargetOpcode::COPY;
377 Opcode = TargetOpcode::G_ZEXT;
379 Opcode = TargetOpcode::G_TRUNC;
394 Opcode = TargetOpcode::G_PTRTOINT;
396 Opcode = TargetOpcode::G_INTTOPTR;
399 Opcode = TargetOpcode::G_BITCAST;
412 "extracting off end of register");
416 assert(Index == 0 &&
"insertion past the end of a register");
430 assert(!Ops.
empty() &&
"invalid trivial sequence");
432 "sequence offsets must be in ascending order");
442 bool MaybeMerge =
true;
443 for (
unsigned i = 0; i < Ops.size(); ++i) {
444 if (MRI->
getType(Ops[i]) != OpTy || Indices[i] != i * OpSize) {
450 if (MaybeMerge && Ops.size() * OpSize == ResTy.getSizeInBits()) {
458 for (
unsigned i = 0; i < Ops.size(); ++i) {
474 assert(!Ops.
empty() &&
"invalid trivial sequence");
480 "input operands do not cover output register");
488 for (
unsigned i = 0; i < Ops.size(); ++i)
497 assert(!Res.
empty() &&
"invalid trivial sequence");
503 "input operands do not cover output register");
507 for (
unsigned i = 0; i < Res.size(); ++i)
514 unsigned Op,
unsigned Index) {
517 "insertion past the end of a register");
532 bool HasSideEffects) {
534 buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS
535 : TargetOpcode::G_INTRINSIC);
538 MIB.addIntrinsicID(ID);
543 validateTruncExt(Res, Op,
false);
548 validateTruncExt(Res, Op,
false);
553 unsigned Res,
unsigned Op0,
575 unsigned Res,
unsigned Op0,
579 "invalid operand type");
599 unsigned Op0,
unsigned Op1) {
603 "invalid operand type");
638 return buildInstr(TargetOpcode::G_INSERT_VECTOR_ELT)
658 return buildInstr(TargetOpcode::G_EXTRACT_VECTOR_ELT)
664 void MachineIRBuilder::validateTruncExt(
unsigned Dst,
unsigned Src,
671 assert(SrcTy.
isVector() &&
"mismatched cast between vecot and non-vector");
673 "different number of elements in a trunc/ext");
679 "invalid narrowing extend");
682 "invalid widening trunc");
MachineBasicBlock & getMBB()
Getter for the basic block we currently build.
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
MachineInstrBuilder buildGEP(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_GEP Op0, Op1.
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
MachineInstrBuilder buildZExtOrTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing ...
MachineInstrBuilder buildZExt(unsigned Res, unsigned Op)
Build and insert Res<def> = G_ZEXT Op.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
MachineInstrBuilder buildTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_TRUNC Op.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
MachineInstrBuilder buildSub(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_SUB Op0, Op1.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
MachineInstrBuilder buildAnyExt(unsigned Res, unsigned Op)
Build and insert Res<def> = G_ANYEXT Op0.
unsigned createGenericVirtualRegister(LLT Ty)
Create and return a new generic virtual register with low-level type Ty.
MachineInstrBuilder buildExtract(unsigned Res, unsigned Src, uint64_t Index)
Build and insert `Res0<def>, ...
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
MachineInstrBuilder buildFPTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_FPTRUNC Op.
MachineInstrBuilder buildSelect(unsigned Res, unsigned Tst, unsigned Op0, unsigned Op1)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_FCMP PredOp0, Op1.
MachineInstrBuilder buildStore(unsigned Val, unsigned Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
A description of a memory reference used in the backend.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned getAddressSpace() const
const APInt & getValue() const
Return the constant as an APInt value reference.
MachineInstrBuilder buildFConstant(unsigned Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
Reg
All possible values of the reg field in the ModR/M byte.
MachineInstrBuilder buildExtractVectorElement(unsigned Res, unsigned Val, unsigned Idx)
Build and insert Res<def> = G_EXTRACT_VECTOR_ELT Val, Idx.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineInstrBuilder buildInsertVectorElement(unsigned Res, unsigned Val, unsigned Elt, unsigned Idx)
Build and insert Res<def> = G_INSERT_VECTOR_ELT Val, Elt, Idx.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
void recordInsertions(std::function< void(MachineInstr *)> InsertedInstr)
MachineInstrBuilder buildConstDbgValue(const Constant &C, unsigned Offset, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified b...
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
size_t size() const
size - Get the array size.
const MachineBasicBlock * getParent() const
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
MachineInstrBuilder buildBr(MachineBasicBlock &BB)
Build and insert G_BR Dest.
MachineInstrBundleIterator< MachineInstr > iterator
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
This is an important base class in LLVM.
MachineInstrBuilder buildPtrMask(unsigned Res, unsigned Op0, uint32_t NumBits)
Build and insert Res<def> = G_PTR_MASK Op0, NumBits.
ConstantFP - Floating Point Values [float, double].
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, unsigned Res, bool HasSideEffects)
Build and insert either a G_INTRINSIC (if HasSideEffects is false) or G_INTRINSIC_W_SIDE_EFFECTS inst...
bool isIntPredicate() const
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
const MachineInstrBuilder & addPredicate(CmpInst::Predicate Pred) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
MachineInstrBuilder buildInsert(unsigned Res, unsigned Src, unsigned Op, unsigned Index)
MachineInstrBuilder buildFIDbgValue(int FI, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in th...
MachineInstrBuilder buildIndirectDbgValue(unsigned Reg, unsigned Offset, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in me...
self_iterator getIterator()
void setMF(MachineFunction &)
bool empty() const
empty - Check if the array is empty.
MachineInstrBuilder buildOr(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_OR Op0, Op1.
MachineInstrBuilder buildBrIndirect(unsigned Tgt)
Build and insert G_BRINDIRECT Tgt.
MachineInstrBuilder buildSExtOrTrunc(unsigned Res, unsigned Op)
Build and insert Res<def> = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing ...
MachineInstrBuilder buildUAdde(unsigned Res, unsigned CarryOut, unsigned Op0, unsigned Op1, unsigned CarryIn)
Build and insert Res<def>, CarryOut<def> = G_UADDE Op0, Op1, CarryIn.
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
void stopRecordingInsertions()
MachineInstrBuilder buildFrameIndex(unsigned Res, int Idx)
Build and insert Res<def> = G_FRAME_INDEX Idx.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is the shared class of boolean and integer constants.
void buildSequence(unsigned Res, ArrayRef< unsigned > Ops, ArrayRef< uint64_t > Indices)
Build and insert instructions to put Ops together at the specified p Indices to form a larger registe...
MachineInstrBuilder buildCopy(unsigned Res, unsigned Op)
Build and insert Res<def> = COPY Op.
const MachineInstrBuilder & addCImm(const ConstantInt *Val) const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
const MachineInstrBuilder & addFrameIndex(int Idx) const
This file declares the MachineIRBuilder class.
MachineInstrBuilder buildSExt(unsigned Res, unsigned Op)
Build and insert Res<def> = G_SEXT Op.
MachineInstrBuilder buildAnd(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_AND Op0, Op1.
bool isFPPredicate() const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
Representation of each machine instruction.
PointerType * getType() const
Global values are always pointers.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
MachineInstrBuilder buildUndef(unsigned Dst)
Build and insert Res = IMPLICIT_DEF.
MachineInstrBuilder buildDirectDbgValue(unsigned Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in Re...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineInstrBuilder buildAdd(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_ADD Op0, Op1.
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MachineInstrBuilder buildConstant(unsigned Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
MachineInstrBuilder buildMul(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res<def> = G_MUL Op0, Op1.
INITIALIZE_PASS(HexagonGenMux,"hexagon-gen-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
Optional< MachineInstrBuilder > materializeGEP(unsigned &Res, unsigned Op0, const LLT &ValueTy, uint64_t Value)
Materialize and insert Res<def> = G_GEP Op0, (G_CONSTANT Value)
MachineInstrBuilder buildUnmerge(ArrayRef< unsigned > Res, unsigned Op)
Build and insert Res0<def>, ...
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineInstrBuilder buildCast(unsigned Dst, unsigned Src)
Build and insert an appropriate cast between two registers of equal size.
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
virtual const TargetInstrInfo * getInstrInfo() const
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
LLVM Value Representation.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
MachineInstrBuilder buildLoad(unsigned Res, unsigned Addr, MachineMemOperand &MMO)
Build and insert Res<def> = G_LOAD Addr, MMO.
print Print MemDeps of function
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
MachineInstrBuilder buildGlobalValue(unsigned Res, const GlobalValue *GV)
Build and insert Res<def> = G_GLOBAL_VALUE GV.
MachineInstrBuilder buildMerge(unsigned Res, ArrayRef< unsigned > Ops)
Build and insert Res<def> = G_MERGE_VALUES Op0, ...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
MachineInstrBuilder buildBrCond(unsigned Tst, MachineBasicBlock &BB)
Build and insert G_BRCOND Tst, Dest.