34#define DEBUG_TYPE "instr-emitter"
46 unsigned N =
Node->getNumValues();
47 while (
N &&
Node->getValueType(
N - 1) == MVT::Glue)
49 if (
N &&
Node->getValueType(
N - 1) == MVT::Other)
62 unsigned &NumImpUses) {
63 unsigned N =
Node->getNumOperands();
64 while (
N &&
Node->getOperand(
N - 1).getValueType() == MVT::Glue)
68 if (
N &&
Node->getOperand(
N - 1).getValueType() == MVT::Other)
72 NumImpUses =
N - NumExpUses;
73 for (
unsigned I =
N;
I > NumExpUses; --
I) {
77 if (RN->getReg().isPhysical())
89 VRBaseMapType &VRBaseMap) {
95 bool isNew = VRBaseMap.insert(std::make_pair(
Op, SrcReg)).second;
97 assert(isNew &&
"Node emitted out of order - early");
103 bool MatchReg =
true;
105 MVT VT =
Op.getSimpleValueType();
110 VT == MVT::Untyped ? nullptr : TLI->getRegClassFor(VT,
Op->isDivergent());
112 for (SDNode *User :
Op->users()) {
119 }
else if (DestReg != SrcReg)
122 for (
unsigned i = 0, e =
User->getNumOperands(); i != e; ++i) {
123 if (
User->getOperand(i) !=
Op)
125 if (VT == MVT::Other || VT == MVT::Glue)
128 if (
User->isMachineOpcode()) {
129 const MCInstrDesc &
II = TII->get(
User->getMachineOpcode());
131 if (i +
II.getNumDefs() <
II.getNumOperands()) {
132 RC = TRI->getAllocatableClass(
133 TII->getRegClass(
II, i +
II.getNumDefs()));
139 TRI->getCommonSubClass(UseRC, RC);
154 SrcRC = TRI->getMinimalPhysRegClass(SrcReg);
158 DstRC = MRI->getRegClass(VRBase);
160 assert(TRI->isTypeLegalForClass(*UseRC, VT) &&
161 "Incompatible phys register def and uses!");
172 VRBase = MRI->createVirtualRegister(DstRC);
173 BuildMI(*MBB, InsertPos,
Op.getDebugLoc(), TII->get(TargetOpcode::COPY),
180 bool isNew = VRBaseMap.insert(std::make_pair(
Op, VRBase)).second;
182 assert(isNew &&
"Node emitted out of order - early");
185void InstrEmitter::CreateVirtualRegisters(
SDNode *Node,
188 bool IsClone,
bool IsCloned,
189 VRBaseMapType &VRBaseMap) {
190 assert(
Node->getMachineOpcode() != TargetOpcode::IMPLICIT_DEF &&
191 "IMPLICIT_DEF should have been handled as a special case elsewhere!");
194 bool HasVRegVariadicDefs = !MF->getTarget().usesPhysRegsForValues() &&
195 II.isVariadic() &&
II.variadicOpsAreDefs();
196 unsigned NumVRegs = HasVRegVariadicDefs ? NumResults :
II.getNumDefs();
197 if (
Node->getMachineOpcode() == TargetOpcode::STATEPOINT)
198 NumVRegs = NumResults;
199 for (
unsigned i = 0; i < NumVRegs; ++i) {
205 TRI->getAllocatableClass(TII->getRegClass(
II, i));
210 if (i < NumResults && TLI->isTypeLegal(
Node->getSimpleValueType(i))) {
212 Node->getSimpleValueType(i),
213 (
Node->isDivergent() || (RC && TRI->isDivergentRegClass(RC))));
215 VTRC = TRI->getCommonSubClass(RC, VTRC);
220 if (!
II.operands().empty() &&
II.operands()[i].isOptionalDef()) {
227 if (!VRBase && !IsClone && !IsCloned)
228 for (SDNode *User :
Node->users()) {
230 User->getOperand(2).getNode() == Node &&
231 User->getOperand(2).getResNo() == i) {
247 assert(RC &&
"Isn't a register operand!");
248 VRBase = MRI->createVirtualRegister(RC);
254 if (i < NumResults) {
258 bool isNew = VRBaseMap.insert(std::make_pair(
Op, VRBase)).second;
260 assert(isNew &&
"Node emitted out of order - early");
268 if (
Op.isMachineOpcode() &&
269 Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF) {
274 Op.getSimpleValueType(),
Op.getNode()->isDivergent());
275 Register VReg = MRI->createVirtualRegister(RC);
276 BuildMI(*MBB, InsertPos,
Op.getDebugLoc(),
277 TII->get(TargetOpcode::IMPLICIT_DEF), VReg);
282 assert(
I != VRBaseMap.end() &&
"Node emitted out of order - late");
287 if (
Op->isMachineOpcode()) {
288 switch (
Op->getMachineOpcode()) {
289 case TargetOpcode::CONVERGENCECTRL_ANCHOR:
290 case TargetOpcode::CONVERGENCECTRL_ENTRY:
291 case TargetOpcode::CONVERGENCECTRL_LOOP:
292 case TargetOpcode::CONVERGENCECTRL_GLUE:
301 switch (
Op->getOpcode()) {
319 VRBaseMapType &VRBaseMap,
320 bool IsDebug,
bool IsClone,
bool IsCloned) {
321 assert(
Op.getValueType() != MVT::Other &&
322 Op.getValueType() != MVT::Glue &&
323 "Chain and glue operands should occur at end of operand list!");
327 const MCInstrDesc &MCID = MIB->
getDesc();
329 MCID.
operands()[IIOpNum].isOptionalDef();
337 if (IIOpNum < II->getNumOperands())
338 OpRC = TII->getRegClass(*
II, IIOpNum);
344 if (
Op.isMachineOpcode() &&
345 Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF)
349 = MRI->constrainRegClass(VReg, OpRC, MinNumRegs);
350 if (!ConstrainedRC) {
351 OpRC = TRI->getAllocatableClass(OpRC);
352 assert(OpRC &&
"Constraints cannot be fulfilled for allocation");
353 Register NewVReg = MRI->createVirtualRegister(OpRC);
355 TII->
get(TargetOpcode::COPY), NewVReg)
360 "Constraining an allocatable VReg produced an unallocatable class?");
378 !(IsClone || IsCloned);
399 VRBaseMapType &VRBaseMap,
bool IsDebug,
400 bool IsClone,
bool IsCloned) {
401 if (
Op.isMachineOpcode()) {
402 AddRegisterOperand(MIB,
Op, IIOpNum,
II, VRBaseMap,
403 IsDebug, IsClone, IsCloned);
405 if (
C->getAPIntValue().getSignificantBits() <= 64) {
409 ConstantInt::get(MF->getFunction().getContext(),
C->getAPIntValue()));
415 MVT OpVT =
Op.getSimpleValueType();
417 II ? TRI->getAllocatableClass(TII->getRegClass(*
II, IIOpNum)) :
nullptr;
419 TLI->isTypeLegal(OpVT)
420 ? TLI->getRegClassFor(OpVT,
421 Op.getNode()->isDivergent() ||
422 (IIRC && TRI->isDivergentRegClass(IIRC)))
425 if (OpRC && IIRC && OpRC != IIRC && VReg.
isVirtual()) {
426 Register NewVReg = MRI->createVirtualRegister(IIRC);
427 BuildMI(*MBB, InsertPos,
Op.getNode()->getDebugLoc(),
428 TII->get(TargetOpcode::COPY), NewVReg).
addReg(VReg);
434 bool Imp =
II && (IIOpNum >=
II->getNumOperands() && !
II->isVariadic());
440 TGA->getTargetFlags());
442 MIB.
addMBB(BBNode->getBasicBlock());
448 int Offset = CP->getOffset();
452 MachineConstantPool *MCP = MF->getConstantPool();
453 if (CP->isMachineConstantPoolEntry())
461 MIB.
addSym(SymNode->getMCSymbol());
465 BA->getTargetFlags());
467 MIB.
addTargetIndex(TI->getIndex(), TI->getOffset(), TI->getTargetFlags());
469 assert(
Op.getValueType() != MVT::Other &&
470 Op.getValueType() != MVT::Glue &&
471 "Chain and glue operands should occur at end of operand list!");
472 AddRegisterOperand(MIB,
Op, IIOpNum,
II, VRBaseMap,
473 IsDebug, IsClone, IsCloned);
485 RC = MRI->constrainRegClass(VReg, RC,
MinRCSize);
493 RC = TRI->getSubClassWithSubReg(TLI->getRegClassFor(VT, isDivergent), SubIdx);
494 assert(RC &&
"No legal register class for VT supports that SubIdx");
495 Register NewReg = MRI->createVirtualRegister(RC);
496 BuildMI(*MBB, InsertPos,
DL, TII->get(TargetOpcode::COPY), NewReg)
503void InstrEmitter::EmitSubregNode(
SDNode *Node, VRBaseMapType &VRBaseMap,
504 bool IsClone,
bool IsCloned) {
506 unsigned Opc =
Node->getMachineOpcode();
510 for (SDNode *User :
Node->users()) {
512 User->getOperand(2).getNode() == Node) {
521 if (
Opc == TargetOpcode::EXTRACT_SUBREG) {
525 unsigned SubIdx =
Node->getConstantOperandVal(1);
527 TLI->getRegClassFor(
Node->getSimpleValueType(0),
Node->isDivergent());
532 if (R &&
R->getReg().isPhysical()) {
536 Reg =
R ?
R->getReg() : getVR(
Node->getOperand(0), VRBaseMap);
543 TII->isCoalescableExtInstr(*
DefMI, SrcReg, DstReg, DefSubIdx) &&
544 SubIdx == DefSubIdx &&
545 TRC == MRI->getRegClass(SrcReg)) {
551 VRBase = MRI->createVirtualRegister(TRC);
553 TII->get(TargetOpcode::COPY), VRBase).
addReg(SrcReg);
554 MRI->clearKillFlags(SrcReg);
560 Reg = ConstrainForSubReg(
Reg, SubIdx,
561 Node->getOperand(0).getSimpleValueType(),
562 Node->isDivergent(),
Node->getDebugLoc());
565 VRBase = MRI->createVirtualRegister(TRC);
568 MachineInstrBuilder CopyMI =
570 TII->get(TargetOpcode::COPY), VRBase);
574 CopyMI.
addReg(TRI->getSubReg(
Reg, SubIdx));
576 }
else if (
Opc == TargetOpcode::INSERT_SUBREG ||
577 Opc == TargetOpcode::SUBREG_TO_REG) {
581 if (
Opc == TargetOpcode::INSERT_SUBREG) {
583 SubReg =
Node->getOperand(1);
584 SubIdx =
Node->getOperand(2)->getAsZExtVal();
586 SubReg =
Node->getOperand(0);
587 SubIdx =
Node->getOperand(1)->getAsZExtVal();
605 TLI->getRegClassFor(
Node->getSimpleValueType(0),
Node->isDivergent());
606 SRC = TRI->getSubClassWithSubReg(SRC, SubIdx);
607 assert(SRC &&
"No register class supports VT and SubIdx for INSERT_SUBREG");
609 if (VRBase == 0 || !SRC->
hasSubClassEq(MRI->getRegClass(VRBase)))
610 VRBase = MRI->createVirtualRegister(SRC);
613 MachineInstrBuilder MIB =
619 AddOperand(MIB,
Reg, 0,
nullptr, VRBaseMap,
false, IsClone,
623 AddOperand(MIB, SubReg, 0,
nullptr, VRBaseMap,
false, IsClone,
626 MBB->
insert(InsertPos, MIB);
628 llvm_unreachable(
"Node is not insert_subreg, extract_subreg, or subreg_to_reg");
631 bool isNew = VRBaseMap.insert(std::make_pair(
Op, VRBase)).second;
633 assert(isNew &&
"Node emitted out of order - early");
641InstrEmitter::EmitCopyToRegClassNode(
SDNode *Node,
642 VRBaseMapType &VRBaseMap) {
644 unsigned DstRCIdx =
Node->getConstantOperandVal(1);
646 TRI->getAllocatableClass(TRI->getRegClass(DstRCIdx));
647 Register NewVReg = MRI->createVirtualRegister(DstRC);
648 const MCInstrDesc &
II = TII->get(TargetOpcode::COPY);
649 MachineInstrBuilder MIB =
BuildMI(*MF,
Node->getDebugLoc(),
II, NewVReg);
650 AddOperand(MIB,
Node->getOperand(0), 1, &
II, VRBaseMap,
false,
653 MBB->insert(InsertPos, MIB);
655 bool isNew = VRBaseMap.insert(std::make_pair(
Op, NewVReg)).second;
657 assert(isNew &&
"Node emitted out of order - early");
662void InstrEmitter::EmitRegSequence(
SDNode *Node, VRBaseMapType &VRBaseMap,
663 bool IsClone,
bool IsCloned) {
664 unsigned DstRCIdx =
Node->getConstantOperandVal(0);
666 Register NewVReg = MRI->createVirtualRegister(TRI->getAllocatableClass(RC));
667 const MCInstrDesc &
II = TII->get(TargetOpcode::REG_SEQUENCE);
668 MachineInstrBuilder MIB =
BuildMI(*MF,
Node->getDebugLoc(),
II, NewVReg);
677 "REG_SEQUENCE must have an odd number of operands!");
678 for (
unsigned i = 1; i !=
NumOps; ++i) {
679 SDValue
Op =
Node->getOperand(i);
684 if (!R || !
R->getReg().isPhysical()) {
685 unsigned SubIdx =
Op->getAsZExtVal();
686 Register SubReg = getVR(
Node->getOperand(i - 1), VRBaseMap);
689 TRI->getMatchingSuperRegClass(RC, TRC, SubIdx);
690 if (SRC && SRC != RC) {
691 MRI->setRegClass(NewVReg, SRC);
696 AddOperand(MIB,
Op, i+1, &
II, VRBaseMap,
false,
700 MBB->insert(InsertPos, MIB);
702 bool isNew = VRBaseMap.insert(std::make_pair(
Op, NewVReg)).second;
704 assert(isNew &&
"Node emitted out of order - early");
712 ->isValidLocationForIntrinsic(SD->
getDebugLoc()) &&
713 "Expected inlined-at fields to agree");
718 "dbg_value with no location operands?");
724 if (EmitDebugInstrRefs)
739 const Value *V =
Op.getConst();
741 if (CI->getBitWidth() > 64)
743 if (CI->getBitWidth() == 1)
765 switch (
Op.getKind()) {
779 if (VRBaseMap.
count(V) == 0)
782 AddOperand(MIB, V, (*MIB).getNumOperands(), &DbgValDesc, VRBaseMap,
801 const MCInstrDesc &RefII = TII->get(TargetOpcode::DBG_INSTR_REF);
844 auto AddVRegOp = [&](
Register VReg) {
852 for (
unsigned OpIdx = 0; OpIdx < OpCount; ++OpIdx) {
864 if (!MRI->hasOneDef(VReg)) {
869 DefMI = &*MRI->def_instr_begin(VReg);
876 if (
I == VRBaseMap.
end())
880 VReg = getVR(
Op, VRBaseMap);
884 if (!MRI->hasOneDef(VReg)) {
889 DefMI = &*MRI->def_instr_begin(VReg);
903 if (
DefMI->isCopyLike() || TII->isCopyInstr(*
DefMI)) {
909 unsigned OperandIdx = 0;
910 for (
const auto &MO :
DefMI->operands()) {
911 if (MO.isReg() && MO.isDef() && MO.getReg() == VReg)
915 assert(OperandIdx < DefMI->getNumOperands());
918 unsigned InstrNum =
DefMI->getDebugInstrNum();
924 if (MOs.
size() != OpCount)
927 return BuildMI(*MF,
DL, RefII,
false, MOs, Var, Expr);
949 const MCInstrDesc &DbgValDesc = TII->get(TargetOpcode::DBG_VALUE_LIST);
967 "Non variadic dbg_value should have only one location op");
973 const Value *V = LocationOps[0].getConst();
998 "Expected inlined-at fields to agree");
1011EmitMachineNode(
SDNode *
Node,
bool IsClone,
bool IsCloned,
1012 VRBaseMapType &VRBaseMap) {
1013 unsigned Opc =
Node->getMachineOpcode();
1016 if (
Opc == TargetOpcode::EXTRACT_SUBREG ||
1017 Opc == TargetOpcode::INSERT_SUBREG ||
1018 Opc == TargetOpcode::SUBREG_TO_REG) {
1019 EmitSubregNode(
Node, VRBaseMap, IsClone, IsCloned);
1024 if (
Opc == TargetOpcode::COPY_TO_REGCLASS) {
1025 EmitCopyToRegClassNode(
Node, VRBaseMap);
1030 if (
Opc == TargetOpcode::REG_SEQUENCE) {
1031 EmitRegSequence(Node, VRBaseMap, IsClone, IsCloned);
1035 if (
Opc == TargetOpcode::IMPLICIT_DEF)
1039 const MCInstrDesc &
II = TII->get(
Opc);
1041 unsigned NumDefs =
II.getNumDefs();
1045 if (
Opc == TargetOpcode::STACKMAP ||
Opc == TargetOpcode::PATCHPOINT) {
1050 if (
Opc == TargetOpcode::PATCHPOINT) {
1052 NumDefs = NumResults;
1055 }
else if (
Opc == TargetOpcode::STATEPOINT) {
1056 NumDefs = NumResults;
1059 unsigned NumImpUses = 0;
1060 unsigned NodeOperands =
1062 bool HasVRegVariadicDefs = !MF->getTarget().usesPhysRegsForValues() &&
1063 II.isVariadic() &&
II.variadicOpsAreDefs();
1064 bool HasPhysRegOuts = NumResults > NumDefs && !
II.implicit_defs().empty() &&
1065 !HasVRegVariadicDefs;
1067 unsigned NumMIOperands = NodeOperands + NumResults;
1068 if (
II.isVariadic())
1069 assert(NumMIOperands >=
II.getNumOperands() &&
1070 "Too few operands for a variadic node!");
1072 assert(NumMIOperands >=
II.getNumOperands() &&
1074 II.getNumOperands() +
II.implicit_defs().size() + NumImpUses &&
1075 "#operands for dag node doesn't match .td file!");
1079 MachineInstrBuilder MIB =
BuildMI(*MF,
Node->getDebugLoc(),
II);
1083 const SDNodeFlags
Flags =
Node->getFlags();
1084 if (
Flags.hasUnpredictable())
1090 CreateVirtualRegisters(Node, MIB,
II, IsClone, IsCloned, VRBaseMap);
1092 if (
Flags.hasNoSignedZeros())
1095 if (
Flags.hasAllowReciprocal())
1098 if (
Flags.hasNoNaNs())
1101 if (
Flags.hasNoInfs())
1104 if (
Flags.hasAllowContract())
1107 if (
Flags.hasApproximateFuncs())
1110 if (
Flags.hasAllowReassociation())
1113 if (
Flags.hasNoUnsignedWrap())
1116 if (
Flags.hasNoSignedWrap())
1119 if (
Flags.hasExact())
1122 if (
Flags.hasNoFPExcept())
1125 if (
Flags.hasDisjoint())
1128 if (
Flags.hasSameSign())
1131 if (
Flags.hasNoConvergent())
1137 bool HasOptPRefs = NumDefs > NumResults;
1138 assert((!HasOptPRefs || !HasPhysRegOuts) &&
1139 "Unable to cope with optional defs and phys regs defs!");
1140 unsigned NumSkip = HasOptPRefs ? NumDefs - NumResults : 0;
1141 for (
unsigned i = NumSkip; i != NodeOperands; ++i)
1142 AddOperand(MIB,
Node->getOperand(i), i-NumSkip+NumDefs, &
II,
1143 VRBaseMap,
false, IsClone, IsCloned);
1147 for (
unsigned i = 0; ScratchRegs[i]; ++i)
1161 MBB->insert(InsertPos, MIB);
1181 if (HasPhysRegOuts) {
1182 for (
unsigned i = NumDefs; i < NumResults; ++i) {
1184 if (!
Node->hasAnyUseOfValue(i))
1188 EmitCopyFromReg(SDValue(Node, i), IsClone,
Reg, VRBaseMap);
1193 if (
Node->getValueType(
Node->getNumValues()-1) == MVT::Glue) {
1194 for (SDNode *
F =
Node->getGluedUser();
F;
F =
F->getGluedUser()) {
1205 const MCInstrDesc &MCID = TII->get(
F->getMachineOpcode());
1209 for (
const SDValue &
Op :
F->op_values())
1219 if (
II.isCall() && MF->getFunction().hasFnAttribute(Attribute::StrictFP)) {
1225 if (!UsedRegs.
empty() || !
II.implicit_defs().empty() ||
II.hasOptionalDef())
1230 if (
Opc == TargetOpcode::STATEPOINT && NumDefs > 0) {
1231 assert(!HasPhysRegOuts &&
"STATEPOINT mishandled");
1232 MachineInstr *
MI = MIB;
1234 int First = StatepointOpers(
MI).getFirstGCPtrIdx();
1235 assert(
First > 0 &&
"Statepoint has Defs but no GC ptr list");
1237 while (Def < NumDefs) {
1238 if (
MI->getOperand(Use).isReg())
1239 MI->tieOperands(Def++, Use);
1244 unsigned Op =
Node->getNumOperands();
1245 if (
Op != 0 &&
Node->getOperand(
Op - 1)->getOpcode() ==
1246 ~(
unsigned)TargetOpcode::CONVERGENCECTRL_GLUE) {
1247 Register VReg = getVR(
Node->getOperand(
Op - 1)->getOperand(0), VRBaseMap);
1256 MI->setDeactivationSymbol(
1257 *MF,
const_cast<GlobalValue *
>(
1264 if (
II.hasPostISelHook())
1265 TLI->AdjustInstrPostInstrSelection(*MIB, Node);
1271EmitSpecialNode(
SDNode *Node,
bool IsClone,
bool IsCloned,
1272 VRBaseMapType &VRBaseMap) {
1273 switch (
Node->getOpcode()) {
1278 llvm_unreachable(
"This target-independent node should have been selected!");
1286 SDValue SrcVal =
Node->getOperand(2);
1292 TII->get(TargetOpcode::IMPLICIT_DEF), DestReg);
1297 SrcReg =
R->getReg();
1299 SrcReg = getVR(SrcVal, VRBaseMap);
1301 if (SrcReg == DestReg)
1304 BuildMI(*MBB, InsertPos,
Node->getDebugLoc(), TII->get(TargetOpcode::COPY),
1310 EmitCopyFromReg(SDValue(Node, 0), IsClone, SrcReg, VRBaseMap);
1316 ? TargetOpcode::EH_LABEL
1317 : TargetOpcode::ANNOTATION_LABEL;
1327 ? TargetOpcode::LIFETIME_START
1328 : TargetOpcode::LIFETIME_END;
1330 BuildMI(*MBB, InsertPos,
Node->getDebugLoc(), TII->get(TarOp))
1336 unsigned TarOp = TargetOpcode::PSEUDO_PROBE;
1341 BuildMI(*MBB, InsertPos,
Node->getDebugLoc(), TII->get(TarOp))
1352 if (
Node->getOperand(
NumOps-1).getValueType() == MVT::Glue)
1357 ? TargetOpcode::INLINEASM_BR
1358 : TargetOpcode::INLINEASM;
1359 MachineInstrBuilder MIB =
1360 BuildMI(*MF,
Node->getDebugLoc(), TII->get(TgtOpc));
1375 SmallVector<unsigned, 8> GroupIdx;
1383 if (
Node->getValueType(
Node->getNumValues() - 1) == MVT::Glue) {
1384 for (SDNode *
G =
Node->getGluedUser();
G;
G =
G->getGluedUser()) {
1395 unsigned Flags =
Node->getConstantOperandVal(i);
1396 const InlineAsm::Flag
F(Flags);
1397 const unsigned NumVals =
F.getNumOperandRegisters();
1403 switch (
F.getKind()) {
1405 for (
unsigned j = 0;
j != NumVals; ++
j, ++i) {
1415 for (
unsigned j = 0;
j != NumVals; ++
j, ++i) {
1419 return TRI->regsOverlap(U,
Reg);
1432 for (
unsigned j = 0;
j != NumVals; ++
j, ++i)
1433 AddOperand(MIB,
Node->getOperand(i), 0,
nullptr, VRBaseMap,
1434 false, IsClone, IsCloned);
1437 if (
F.isRegUseKind()) {
1439 if (
F.isUseOperandTiedToDef(DefGroup)) {
1440 unsigned DefIdx = GroupIdx[DefGroup] + 1;
1441 unsigned UseIdx = GroupIdx.
back() + 1;
1442 for (
unsigned j = 0;
j != NumVals; ++
j)
1448 for (
unsigned j = 0;
j != NumVals; ++
j, ++i) {
1449 SDValue
Op =
Node->getOperand(i);
1450 AddOperand(MIB,
Op, 0,
nullptr, VRBaseMap,
1451 false, IsClone, IsCloned);
1456 MF->getSubtarget().classifyGlobalFunctionReference(
1472 MachineOperand *MO =
1474 assert(MO &&
"No def operand for clobbered register?");
1486 if (MF->getFunction().hasFnAttribute(Attribute::StrictFP)) {
1492 MBB->
insert(InsertPos, MIB);
1502 : MF(mbb->
getParent()), MRI(&MF->getRegInfo()),
1503 TII(MF->getSubtarget().getInstrInfo()),
1504 TRI(MF->getSubtarget().getRegisterInfo()),
1505 TLI(MF->getSubtarget().getTargetLowering()), MBB(mbb),
1506 InsertPos(insertpos) {
1507 EmitDebugInstrRefs = mbb->
getParent()->useDebugInstrRef();
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains constants used for implementing Dwarf debug support.
static bool isConvergenceCtrlMachineOp(SDValue Op)
MachineOperand GetMOForConstDbgOp(const SDDbgOperand &Op)
const unsigned MinRCSize
MinRCSize - Smallest register class we allow when constraining virtual registers.
static unsigned countOperands(SDNode *Node, unsigned NumExpUses, unsigned &NumImpUses)
countOperands - The inputs to target nodes have any actual inputs first, followed by an optional chai...
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Promote Memory to Register
uint64_t IntrinsicInst * II
This file describes how to lower LLVM code to machine code.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
LLVM_ABI std::pair< DIExpression *, const ConstantInt * > constantFold(const ConstantInt *CI)
Try to shorten an expression with an initial constant operand.
static LLVM_ABI const DIExpression * convertToVariadicExpression(const DIExpression *Expr)
If Expr is a non-variadic expression (i.e.
static LLVM_ABI const DIExpression * convertToUndefExpression(const DIExpression *Expr)
Removes all elements from Expr that do not apply to an undef debug value, which includes every operat...
Base class for variables.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
iterator find(const_arg_type_t< KeyT > Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
MachineInstr * EmitDbgValue(SDDbgValue *SD, VRBaseMapType &VRBaseMap)
EmitDbgValue - Generate machine instruction for a dbg_value node.
MachineInstr * EmitDbgInstrRef(SDDbgValue *SD, VRBaseMapType &VRBaseMap)
Emit a dbg_value as a DBG_INSTR_REF.
SmallDenseMap< SDValue, Register, 16 > VRBaseMapType
MachineInstr * EmitDbgLabel(SDDbgLabel *SD)
Generate machine instruction for a dbg_label node.
MachineInstr * EmitDbgNoLocation(SDDbgValue *SD)
Emit a DBG_VALUE $noreg, indicating a variable has no location.
static unsigned CountResults(SDNode *Node)
CountResults - The results of target nodes have register or immediate operands first,...
MachineInstr * EmitDbgValueList(SDDbgValue *SD, VRBaseMapType &VRBaseMap)
Emit a DBG_VALUE_LIST from the operands to SDDbgValue.
InstrEmitter(const TargetMachine &TM, MachineBasicBlock *mbb, MachineBasicBlock::iterator insertpos)
InstrEmitter - Construct an InstrEmitter and set it to start inserting at the given position in the g...
void AddDbgValueLocationOps(MachineInstrBuilder &MIB, const MCInstrDesc &DbgValDesc, ArrayRef< SDDbgOperand > Locations, VRBaseMapType &VRBaseMap)
MachineInstr * EmitDbgValueFromSingleOp(SDDbgValue *SD, VRBaseMapType &VRBaseMap)
Emit a DBG_VALUE from the operands to SDDbgValue.
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
ArrayRef< MCPhysReg > implicit_uses() const
Return a list of registers that are potentially read by any instance of this machine instruction.
bool isAllocatable() const
isAllocatable - Return true if this register class may be used to create virtual registers.
bool expensiveOrImpossibleToCopy() const
bool hasSubClassEq(const MCRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI unsigned getConstantPoolIndex(const Constant *C, Align Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one.
const MachineInstrBuilder & addTargetIndex(unsigned Idx, int64_t Offset=0, unsigned TargetFlags=0) const
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 & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addBlockAddress(const BlockAddress *BA, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
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 & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
const MachineInstrBuilder & addJumpTableIndex(unsigned Idx, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
LLVM_ABI void setCFIType(MachineFunction &MF, uint32_t Type)
Set the CFI type for the instruction.
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
unsigned getNumOperands() const
Retuns the total number of operands.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
LLVM_ABI void insert(mop_iterator InsertBefore, ArrayRef< MachineOperand > Ops)
Inserts Ops BEFORE It. Can untie/retie tied operands.
LLVM_ABI void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void setPhysRegsDeadExcept(ArrayRef< Register > UsedRegs, const TargetRegisterInfo &TRI)
Mark every physreg used by this instruction as dead except those in the UsedRegs list.
const MachineOperand & getOperand(unsigned i) const
MachineOperand * findRegisterDefOperand(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false)
Wrapper for findRegisterDefOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateFPImm(const ConstantFP *CFP)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static MachineOperand CreateCImm(const ConstantInt *CI)
void setIsEarlyClobber(bool Val=true)
static MachineOperand CreateImm(int64_t Val)
static MachineOperand CreateDbgInstrRef(unsigned InstrIdx, unsigned OpIdx)
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
void setTargetFlags(unsigned F)
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)
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Holds the information from a dbg_label node through SDISel.
MDNode * getLabel() const
Returns the MDNode pointer for the label.
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
Holds the information for a single machine location through SDISel; either an SDNode,...
const GlobalValue * getGlobal() const
Returns the GlobalValue whose address describes the variable.
Register getVReg() const
Returns the Virtual Register for a VReg.
unsigned getResNo() const
Returns the ResNo for a register ref.
static SDDbgOperand fromConst(const Value *Const)
SDNode * getSDNode() const
Returns the SDNode* for a register ref.
@ VREG
Value is a virtual register.
@ FRAMEIX
Value is contents of a stack location.
@ SDNODE
Value is the result of an expression.
@ CONST
Value is a constant.
@ GLOBALADDR
Value is the address of a global.
Holds the information from a dbg_value node through SDISel.
const DebugLoc & getDebugLoc() const
Returns the DebugLoc.
DIVariable * getVariable() const
Returns the DIVariable pointer for the variable.
bool isInvalidated() const
ArrayRef< SDDbgOperand > getLocationOps() const
DIExpression * getExpression() const
Returns the DIExpression pointer for the expression.
bool isIndirect() const
Returns whether this is an indirect value.
void setIsEmitted()
setIsEmitted / isEmitted - Getter/Setter for flag indicating that this SDDbgValue has been emitted to...
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
bool isMachineOpcode() const
unsigned getMachineOpcode() const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI unsigned getNextMetaArgIdx(const MachineInstr *MI, unsigned CurIdx)
Get index of next meta operand.
Primary interface to the complete machine description for the target machine.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
@ CONVERGENCECTRL_ANCHOR
The llvm.experimental.convergence.* intrinsics.
@ DEACTIVATION_SYMBOL
Untyped node storing deactivation symbol reference (DeactivationSymbolSDNode).
@ EH_LABEL
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
@ ANNOTATION_LABEL
ANNOTATION_LABEL - Represents a mid basic block label used by annotations.
@ CONVERGENCECTRL_GLUE
This does not correspond to any convergence control intrinsic.
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
@ EntryToken
EntryToken - This is the marker used to indicate the start of a region.
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
@ LIFETIME_START
This corresponds to the llvm.lifetime.
@ INLINEASM_BR
INLINEASM_BR - Branching version of inline asm. Used by asm-goto.
@ PSEUDO_PROBE
Pseudo probe for AutoFDO, as a place holder in a basic block to improve the sample counts quality.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ INLINEASM
INLINEASM - Represents an inline asm block.
@ User
could "use" a pointer
NodeAddr< DefNode * > Def
NodeAddr< UseNode * > Use
NodeAddr< NodeBase * > Node
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ EarlyClobber
Register definition happens before uses.
@ Define
Register definition.
constexpr RegState getImplRegState(bool B)
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
constexpr RegState getDeadRegState(bool B)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
constexpr RegState getDefRegState(bool B)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr RegState getDebugRegState(bool B)
MCRegisterClass TargetRegisterClass
TODO: Might pack better if we changed this to a Struct of Arrays, since MachineOperand is width 32,...