39 "Basic block is in a different function");
51 "Basic block is in a different function");
92 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
93 assert(cast<DIExpression>(Expr)->isValid() &&
"not an expression");
95 cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(
getDL()) &&
96 "Expected inlined-at fields to agree");
98 getTII().
get(TargetOpcode::DBG_VALUE),
99 false, Reg, Variable, Expr));
104 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
105 assert(cast<DIExpression>(Expr)->isValid() &&
"not an expression");
107 cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(
getDL()) &&
108 "Expected inlined-at fields to agree");
110 getTII().
get(TargetOpcode::DBG_VALUE),
111 true, Reg, Variable, Expr));
117 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
118 assert(cast<DIExpression>(Expr)->isValid() &&
"not an expression");
120 cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(
getDL()) &&
121 "Expected inlined-at fields to agree");
131 assert(isa<DILocalVariable>(Variable) &&
"not a variable");
132 assert(cast<DIExpression>(Expr)->isValid() &&
"not an expression");
134 cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(
getDL()) &&
135 "Expected inlined-at fields to agree");
136 auto MIB =
buildInstr(TargetOpcode::DBG_VALUE);
137 if (
auto *CI = dyn_cast<ConstantInt>(&C)) {
138 if (CI->getBitWidth() > 64)
141 MIB.addImm(CI->getZExtValue());
142 }
else if (
auto *CFP = dyn_cast<ConstantFP>(&C)) {
149 return MIB.addImm(0).addMetadata(Variable).addMetadata(Expr);
155 return buildInstr(TargetOpcode::G_FRAME_INDEX)
165 "address space mismatch");
167 return buildInstr(TargetOpcode::G_GLOBAL_VALUE)
176 "invalid operand type");
195 const LLT &ValueTy, uint64_t
Value) {
196 assert(Res == 0 &&
"Res is a result argument");
314 unsigned Op0,
unsigned Op1,
333 validateTruncExt(Res, Op,
true);
338 validateTruncExt(Res, Op,
true);
343 validateTruncExt(Res, Op,
true);
350 assert((TargetOpcode::G_ANYEXT == ExtOpc || TargetOpcode::G_ZEXT == ExtOpc ||
351 TargetOpcode::G_SEXT == ExtOpc) &&
352 "Expecting Extending Opc");
357 unsigned Opcode = TargetOpcode::COPY;
363 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");
417 assert(Index == 0 &&
"insertion past the end of a register");
431 assert(!Ops.
empty() &&
"invalid trivial sequence");
433 "sequence offsets must be in ascending order");
443 bool MaybeMerge =
true;
444 for (
unsigned i = 0; i < Ops.size(); ++i) {
445 if (
getMRI()->
getType(Ops[i]) != OpTy || Indices[i] != i * OpSize) {
451 if (MaybeMerge && Ops.size() * OpSize == ResTy.
getSizeInBits()) {
459 for (
unsigned i = 0; i < Ops.size(); ++i) {
460 unsigned ResOut = i + 1 == Ops.size()
476 assert(!Ops.
empty() &&
"invalid trivial sequence");
482 "input operands do not cover output register");
490 for (
unsigned i = 0; i < Ops.size(); ++i)
499 assert(!Res.
empty() &&
"invalid trivial sequence");
505 "input operands do not cover output register");
509 for (
unsigned i = 0; i < Res.size(); ++i)
516 unsigned Src,
unsigned Op,
520 "insertion past the end of a register");
536 bool HasSideEffects) {
538 buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS
539 : TargetOpcode::G_INTRINSIC);
542 MIB.addIntrinsicID(ID);
548 validateTruncExt(Res, Op,
false);
554 validateTruncExt(Res, Op,
false);
559 unsigned Res,
unsigned Op0,
581 unsigned Res,
unsigned Op0,
586 "invalid operand type");
612 "invalid operand type");
634 unsigned Elt,
unsigned Idx) {
646 return buildInstr(TargetOpcode::G_INSERT_VECTOR_ELT)
666 return buildInstr(TargetOpcode::G_EXTRACT_VECTOR_ELT)
673 unsigned OldValRes,
unsigned SuccessRes,
unsigned Addr,
unsigned CmpVal,
686 assert(OldValResTy == CmpValTy &&
"type mismatch");
687 assert(OldValResTy == NewValTy &&
"type mismatch");
690 return buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG_WITH_SUCCESS)
701 unsigned CmpVal,
unsigned NewVal,
712 assert(OldValResTy == CmpValTy &&
"type mismatch");
713 assert(OldValResTy == NewValTy &&
"type mismatch");
716 return buildInstr(TargetOpcode::G_ATOMIC_CMPXCHG)
726 unsigned Addr,
unsigned Val,
735 assert(OldValResTy == ValTy &&
"type mismatch");
748 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_XCHG, OldValRes, Addr, Val,
754 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_ADD, OldValRes, Addr, Val,
760 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_SUB, OldValRes, Addr, Val,
766 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_AND, OldValRes, Addr, Val,
772 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_NAND, OldValRes, Addr, Val,
778 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_OR, OldValRes, Addr, Val,
784 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_XOR, OldValRes, Addr, Val,
790 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_MAX, OldValRes, Addr, Val,
796 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_MIN, OldValRes, Addr, Val,
802 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_UMAX, OldValRes, Addr, Val,
808 return buildAtomicRMW(TargetOpcode::G_ATOMICRMW_UMIN, OldValRes, Addr, Val,
821 void MachineIRBuilderBase::validateTruncExt(
unsigned Dst,
unsigned Src,
828 assert(SrcTy.
isVector() &&
"mismatched cast between vector and non-vector");
830 "different number of elements in a trunc/ext");
836 "invalid narrowing extend");
839 "invalid widening trunc");
bool isFPPredicate() const
MachineInstrBuilder buildCopy(unsigned Res, unsigned Op)
Build and insert Res = COPY Op.
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
MachineInstrBuilder buildIndirectDbgValue(unsigned Reg, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instruction expressing the fact that the associated Variable lives in me...
Compute iterated dominance frontiers using a linear time algorithm.
MachineInstrBuilder buildGEP(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res = G_GEP Op0, Op1.
MachineInstrBuilder buildInsertVectorElement(unsigned Res, unsigned Val, unsigned Elt, unsigned Idx)
Build and insert Res = G_INSERT_VECTOR_ELT Val, Elt, Idx.
MachineInstrBuilder buildStore(unsigned Val, unsigned Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
MachineInstrBuilder buildFConstant(DstType &&Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
MachineInstrBuilder buildUndef(DstType &&Res)
Build and insert Res = IMPLICIT_DEF.
MachineInstrBuilder buildSExt(DstType &&Res, ArgType &&Arg)
Build and insert Res = G_SEXT Op.
MachineInstrBuilder buildUnmerge(ArrayRef< unsigned > Res, unsigned Op)
Build and insert Res0, ...
MachineInstrBuilder buildAtomicRMWUmin(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO.
MachineInstrBuilder buildFPTrunc(DstType &&Res, SrcType &&Src)
Build and insert Res = G_FPTRUNC Op.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
const MachineInstrBuilder & addPredicate(CmpInst::Predicate Pred) const
MachineInstrBuilder buildAnyExt(unsigned Res, unsigned Op)
Build and insert Res = G_ANYEXT Op0.
MachineInstrBuilder buildAtomicRMWOr(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MachineInstrBuilder buildBrCond(unsigned Tst, MachineBasicBlock &Dest)
Build and insert G_BRCOND Tst, Dest.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
MachineInstrBuilder buildAtomicCmpXchg(unsigned OldValRes, unsigned Addr, unsigned CmpVal, unsigned NewVal, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal, MMO.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineInstrBuilder buildAtomicRMWXor(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO.
The address of a basic block.
void recordInsertion(MachineInstr *InsertedInstr) const
MachineInstrBuilder buildAtomicRMWMax(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO.
A description of a memory reference used in the backend.
std::function< void(MachineInstr *)> InsertedInstr
void setMF(MachineFunction &)
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
MachineInstrBuilder buildBrIndirect(unsigned Tgt)
Build and insert G_BRINDIRECT Tgt.
MachineBasicBlock::iterator II
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
APFloat getAPFloatFromSize(double Val, unsigned Size)
Returns an APFloat from Val converted to the appropriate size.
MachineInstrBuilder buildConstDbgValue(const Constant &C, const MDNode *Variable, const MDNode *Expr)
Build and insert a DBG_VALUE instructions specifying that Variable is given by C (suitably modified b...
MachineInstrBuilder buildAnyExtOrTrunc(DstTy &&Dst, UseArgTy &&Use)
Res = COPY Op depending on the differing sizes of Res and Op.
MachineInstrBuilder buildPtrMask(unsigned Res, unsigned Op0, uint32_t NumBits)
Build and insert Res = G_PTR_MASK Op0, NumBits.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
MachineInstrBuilder buildAtomicRMWSub(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO.
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
const APInt & getValue() const
Return the constant as an APInt value reference.
virtual const TargetInstrInfo * getInstrInfo() const
MachineInstrBuilder buildZExt(DstType &&Res, ArgType &&Arg)
Build and insert Res = G_ZEXT Op.
static Function * getFunction(Constant *C)
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
MachineInstrBuilder buildGlobalValue(unsigned Res, const GlobalValue *GV)
Build and insert Res = G_GLOBAL_VALUE GV.
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...
void stopRecordingInsertions()
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...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
MachineInstrBundleIterator< MachineInstr > iterator
MachineInstrBuilder buildZExtOrTrunc(DstTy &&Dst, UseArgTy &&Use)
Build and insert Res = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
const MachineInstrBuilder & addBlockAddress(const BlockAddress *BA, int64_t Offset=0, unsigned char TargetFlags=0) const
const TargetInstrInfo * TII
Information used to access the description of the opcodes.
const MachineInstrBuilder & addCImm(const ConstantInt *Val) const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
size_t size() const
size - Get the array size.
This is an important base class in LLVM.
MachineInstrBuilder buildBr(MachineBasicBlock &Dest)
Build and insert G_BR Dest.
MachineInstrBuilder buildAtomicRMWUmax(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO.
ConstantFP - Floating Point Values [float, double].
MachineInstrBuilder buildUAdde(unsigned Res, unsigned CarryOut, unsigned Op0, unsigned Op1, unsigned CarryIn)
Build and insert Res, CarryOut = G_UADDE Op0, Op1, CarryIn.
MachineInstrBuilder buildExtract(unsigned Res, unsigned Src, uint64_t Index)
Build and insert `Res0, ...
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...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
DebugLoc DL
Debug location to be set to any instruction we create.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
MachineInstrBuilder buildExtractVectorElement(unsigned Res, unsigned Val, unsigned Idx)
Build and insert Res = G_EXTRACT_VECTOR_ELT Val, Idx.
const DebugLoc & getDL()
Getter for DebugLoc.
self_iterator getIterator()
const MachineInstrBuilder & addFrameIndex(int Idx) const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
void validateBinaryOp(unsigned Res, unsigned Op0, unsigned Op1)
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
static wasm::ValType getType(const TargetRegisterClass *RC)
unsigned createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
MachineInstrBuilder buildSExtOrTrunc(DstTy &&Dst, UseArgTy &&Use)
Build and insert Res = G_SEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
This is the shared class of boolean and integer constants.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
MachineInstrBuilder buildAtomicRMWXchg(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO.
MachineInstrBuilder buildFrameIndex(unsigned Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
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.
LegalityPredicate isScalar(unsigned TypeIdx)
True iff the specified type index is a scalar.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
MachineInstrBuilder buildSelect(unsigned Res, unsigned Tst, unsigned Op0, unsigned Op1)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
MachineInstrBuilder buildTrunc(unsigned Res, unsigned Op)
Build and insert Res = G_TRUNC Op.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
This file declares the MachineIRBuilder class.
bool isIntPredicate() const
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
void recordInsertions(std::function< void(MachineInstr *)> InsertedInstr)
MachineInstrBuilder buildAtomicRMWMin(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO.
MachineInstrBuilder buildConstant(unsigned Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
MachineInstrBuilder buildAtomicRMW(unsigned Opcode, unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO.
const MachineBasicBlock * getParent() const
MachineInstrBuilder buildAtomicRMWAdd(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO.
MachineInstrBuilder buildMerge(unsigned Res, ArrayRef< unsigned > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ...
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBuilder buildAtomicRMWNand(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineInstrBuilder buildAtomicRMWAnd(unsigned OldValRes, unsigned Addr, unsigned Val, MachineMemOperand &MMO)
Build and insert OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildLoadInstr(unsigned Opcode, unsigned Res, unsigned Addr, MachineMemOperand &MMO)
Build and insert Res = <opcode> Addr, MMO.
MachineInstrBuilder buildLoad(unsigned Res, unsigned Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineFunction & getMF()
Getter for the function we currently build.
Optional< MachineInstrBuilder > materializeGEP(unsigned &Res, unsigned Op0, const LLT &ValueTy, uint64_t Value)
Materialize and insert Res = G_GEP Op0, (G_CONSTANT Value)
MachineInstrBuilder buildCast(DstType &&Res, ArgType &&Arg)
Build and insert an appropriate cast between two registers of equal size.
MachineInstrBuilder buildAtomicCmpXchgWithSuccess(unsigned OldValRes, unsigned SuccessRes, unsigned Addr, unsigned CmpVal, unsigned NewVal, MachineMemOperand &MMO)
Build and insert OldValRes<def>, SuccessRes<def> = G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr, CmpVal, NewVal, MMO.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
MachineBasicBlock & getMBB()
Getter for the basic block we currently build.
print Print MemDeps of function
MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_FCMP PredOp0, Op1.
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
MachineFunction * MF
MachineFunction under construction.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
MachineInstrBuilder buildInsert(unsigned Res, unsigned Src, unsigned Op, unsigned Index)
MachineInstrBuilder buildBlockAddress(unsigned Res, const BlockAddress *BA)
Build and insert Res = G_BLOCK_ADDR BA.
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 buildExtOrTrunc(unsigned ExtOpc, unsigned Res, unsigned Op)
Build and insert Res = ExtOpc, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes of...
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, unsigned Res, unsigned Op0, unsigned Op1)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
PointerType * getType() const
Global values are always pointers.
bool empty() const
empty - Check if the array is empty.
MachineRegisterInfo * MRI
Information used to verify types are consistent and to create virtual registers.