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;
104 const TargetRegisterClass *UseRC =
nullptr;
105 MVT VT =
Op.getSimpleValueType();
108 if (TLI->isTypeLegal(VT))
109 UseRC = TLI->getRegClassFor(VT,
Op->isDivergent());
111 for (SDNode *User :
Op->users()) {
118 }
else if (DestReg != SrcReg)
121 for (
unsigned i = 0, e =
User->getNumOperands(); i != e; ++i) {
122 if (
User->getOperand(i) !=
Op)
124 if (VT == MVT::Other || VT == MVT::Glue)
127 if (
User->isMachineOpcode()) {
128 const MCInstrDesc &
II = TII->get(
User->getMachineOpcode());
129 const TargetRegisterClass *RC =
nullptr;
130 if (i +
II.getNumDefs() <
II.getNumOperands()) {
131 RC = TRI->getAllocatableClass(
132 TII->getRegClass(
II, i +
II.getNumDefs()));
137 const TargetRegisterClass *ComRC =
138 TRI->getCommonSubClass(UseRC, RC);
152 const TargetRegisterClass *SrcRC =
nullptr, *DstRC =
nullptr;
153 SrcRC = TRI->getMinimalPhysRegClass(SrcReg, VT);
157 DstRC = MRI->getRegClass(VRBase);
159 assert(TRI->isTypeLegalForClass(*UseRC, VT) &&
160 "Incompatible phys register def and uses!");
171 VRBase = MRI->createVirtualRegister(DstRC);
172 BuildMI(*MBB, InsertPos,
Op.getDebugLoc(), TII->get(TargetOpcode::COPY),
179 bool isNew = VRBaseMap.insert(std::make_pair(
Op, VRBase)).second;
181 assert(isNew &&
"Node emitted out of order - early");
184void InstrEmitter::CreateVirtualRegisters(
SDNode *Node,
187 bool IsClone,
bool IsCloned,
188 VRBaseMapType &VRBaseMap) {
189 assert(
Node->getMachineOpcode() != TargetOpcode::IMPLICIT_DEF &&
190 "IMPLICIT_DEF should have been handled as a special case elsewhere!");
193 bool HasVRegVariadicDefs = !MF->getTarget().usesPhysRegsForValues() &&
194 II.isVariadic() &&
II.variadicOpsAreDefs();
195 unsigned NumVRegs = HasVRegVariadicDefs ? NumResults :
II.getNumDefs();
196 if (
Node->getMachineOpcode() == TargetOpcode::STATEPOINT)
197 NumVRegs = NumResults;
198 for (
unsigned i = 0; i < NumVRegs; ++i) {
203 const TargetRegisterClass *RC =
204 TRI->getAllocatableClass(TII->getRegClass(
II, i));
209 if (i < NumResults && TLI->isTypeLegal(
Node->getSimpleValueType(i))) {
210 const TargetRegisterClass *VTRC = TLI->getRegClassFor(
211 Node->getSimpleValueType(i),
212 (
Node->isDivergent() || (RC && TRI->isDivergentRegClass(RC))));
214 VTRC = TRI->getCommonSubClass(RC, VTRC);
219 if (!
II.operands().empty() &&
II.operands()[i].isOptionalDef()) {
226 if (!VRBase && !IsClone && !IsCloned)
227 for (SDNode *User :
Node->users()) {
229 User->getOperand(2).getNode() == Node &&
230 User->getOperand(2).getResNo() == i) {
233 const TargetRegisterClass *RegRC = MRI->getRegClass(
Reg);
246 assert(RC &&
"Isn't a register operand!");
247 VRBase = MRI->createVirtualRegister(RC);
253 if (i < NumResults) {
257 bool isNew = VRBaseMap.insert(std::make_pair(
Op, VRBase)).second;
259 assert(isNew &&
"Node emitted out of order - early");
267 if (
Op.isMachineOpcode() &&
268 Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF) {
272 const TargetRegisterClass *RC = TLI->getRegClassFor(
273 Op.getSimpleValueType(),
Op.getNode()->isDivergent());
274 Register VReg = MRI->createVirtualRegister(RC);
275 BuildMI(*MBB, InsertPos,
Op.getDebugLoc(),
276 TII->get(TargetOpcode::IMPLICIT_DEF), VReg);
281 assert(
I != VRBaseMap.end() &&
"Node emitted out of order - late");
286 if (
Op->isMachineOpcode()) {
287 switch (
Op->getMachineOpcode()) {
288 case TargetOpcode::CONVERGENCECTRL_ANCHOR:
289 case TargetOpcode::CONVERGENCECTRL_ENTRY:
290 case TargetOpcode::CONVERGENCECTRL_LOOP:
291 case TargetOpcode::CONVERGENCECTRL_GLUE:
300 switch (
Op->getOpcode()) {
318 VRBaseMapType &VRBaseMap,
319 bool IsDebug,
bool IsClone,
bool IsCloned) {
320 assert(
Op.getValueType() != MVT::Other &&
321 Op.getValueType() != MVT::Glue &&
322 "Chain and glue operands should occur at end of operand list!");
326 const MCInstrDesc &MCID = MIB->
getDesc();
328 MCID.
operands()[IIOpNum].isOptionalDef();
335 const TargetRegisterClass *OpRC =
nullptr;
336 if (IIOpNum < II->getNumOperands())
337 OpRC = TII->getRegClass(*
II, IIOpNum);
343 if (
Op.isMachineOpcode() &&
344 Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF)
347 const TargetRegisterClass *ConstrainedRC
348 = MRI->constrainRegClass(VReg, OpRC, MinNumRegs);
349 if (!ConstrainedRC) {
350 OpRC = TRI->getAllocatableClass(OpRC);
351 assert(OpRC &&
"Constraints cannot be fulfilled for allocation");
352 Register NewVReg = MRI->createVirtualRegister(OpRC);
354 TII->
get(TargetOpcode::COPY), NewVReg)
359 "Constraining an allocatable VReg produced an unallocatable class?");
377 !(IsClone || IsCloned);
398 VRBaseMapType &VRBaseMap,
bool IsDebug,
399 bool IsClone,
bool IsCloned) {
400 if (
Op.isMachineOpcode()) {
401 AddRegisterOperand(MIB,
Op, IIOpNum,
II, VRBaseMap,
402 IsDebug, IsClone, IsCloned);
404 if (
C->getAPIntValue().getSignificantBits() <= 64) {
408 ConstantInt::get(MF->getFunction().getContext(),
C->getAPIntValue()));
414 MVT OpVT =
Op.getSimpleValueType();
415 const TargetRegisterClass *IIRC =
416 II ? TRI->getAllocatableClass(TII->getRegClass(*
II, IIOpNum)) :
nullptr;
417 const TargetRegisterClass *OpRC =
418 TLI->isTypeLegal(OpVT)
419 ? TLI->getRegClassFor(OpVT,
420 Op.getNode()->isDivergent() ||
421 (IIRC && TRI->isDivergentRegClass(IIRC)))
424 if (OpRC && IIRC && OpRC != IIRC && VReg.
isVirtual()) {
425 Register NewVReg = MRI->createVirtualRegister(IIRC);
426 BuildMI(*MBB, InsertPos,
Op.getNode()->getDebugLoc(),
427 TII->get(TargetOpcode::COPY), NewVReg).
addReg(VReg);
433 bool Imp =
II && (IIOpNum >=
II->getNumOperands() && !
II->isVariadic());
439 TGA->getTargetFlags());
441 MIB.
addMBB(BBNode->getBasicBlock());
447 int Offset = CP->getOffset();
448 Align Alignment = CP->getAlign();
451 MachineConstantPool *MCP = MF->getConstantPool();
452 if (CP->isMachineConstantPoolEntry())
460 MIB.
addSym(SymNode->getMCSymbol());
464 BA->getTargetFlags());
466 MIB.
addTargetIndex(TI->getIndex(), TI->getOffset(), TI->getTargetFlags());
468 assert(
Op.getValueType() != MVT::Other &&
469 Op.getValueType() != MVT::Glue &&
470 "Chain and glue operands should occur at end of operand list!");
471 AddRegisterOperand(MIB,
Op, IIOpNum,
II, VRBaseMap,
472 IsDebug, IsClone, IsCloned);
478 const TargetRegisterClass *VRC = MRI->getRegClass(VReg);
479 const TargetRegisterClass *RC = TRI->getSubClassWithSubReg(VRC, SubIdx);
484 RC = MRI->constrainRegClass(VReg, RC,
MinRCSize);
492 RC = TRI->getSubClassWithSubReg(TLI->getRegClassFor(VT, isDivergent), SubIdx);
493 assert(RC &&
"No legal register class for VT supports that SubIdx");
494 Register NewReg = MRI->createVirtualRegister(RC);
495 BuildMI(*MBB, InsertPos,
DL, TII->get(TargetOpcode::COPY), NewReg)
502void InstrEmitter::EmitSubregNode(
SDNode *Node, VRBaseMapType &VRBaseMap,
503 bool IsClone,
bool IsCloned) {
505 unsigned Opc =
Node->getMachineOpcode();
509 for (SDNode *User :
Node->users()) {
511 User->getOperand(2).getNode() == Node) {
520 if (
Opc == TargetOpcode::EXTRACT_SUBREG) {
524 unsigned SubIdx =
Node->getConstantOperandVal(1);
525 const TargetRegisterClass *TRC =
526 TLI->getRegClassFor(
Node->getSimpleValueType(0),
Node->isDivergent());
531 if (R &&
R->getReg().isPhysical()) {
535 Reg =
R ?
R->getReg() : getVR(
Node->getOperand(0), VRBaseMap);
542 TII->isCoalescableExtInstr(*
DefMI, SrcReg, DstReg, DefSubIdx) &&
543 SubIdx == DefSubIdx &&
544 TRC == MRI->getRegClass(SrcReg)) {
550 VRBase = MRI->createVirtualRegister(TRC);
552 TII->get(TargetOpcode::COPY), VRBase).
addReg(SrcReg);
553 MRI->clearKillFlags(SrcReg);
559 Reg = ConstrainForSubReg(
Reg, SubIdx,
560 Node->getOperand(0).getSimpleValueType(),
561 Node->isDivergent(),
Node->getDebugLoc());
564 VRBase = MRI->createVirtualRegister(TRC);
567 MachineInstrBuilder CopyMI =
569 TII->get(TargetOpcode::COPY), VRBase);
573 CopyMI.
addReg(TRI->getSubReg(
Reg, SubIdx));
575 }
else if (
Opc == TargetOpcode::INSERT_SUBREG ||
576 Opc == TargetOpcode::SUBREG_TO_REG) {
580 if (
Opc == TargetOpcode::INSERT_SUBREG) {
583 SubIdx =
Node->getOperand(2)->getAsZExtVal();
586 SubIdx =
Node->getOperand(1)->getAsZExtVal();
603 const TargetRegisterClass *SRC =
604 TLI->getRegClassFor(
Node->getSimpleValueType(0),
Node->isDivergent());
605 SRC = TRI->getSubClassWithSubReg(SRC, SubIdx);
606 assert(SRC &&
"No register class supports VT and SubIdx for INSERT_SUBREG");
608 if (VRBase == 0 || !SRC->
hasSubClassEq(MRI->getRegClass(VRBase)))
609 VRBase = MRI->createVirtualRegister(SRC);
612 MachineInstrBuilder MIB =
618 AddOperand(MIB,
Reg, 0,
nullptr, VRBaseMap,
false, IsClone,
622 AddOperand(MIB,
SubReg, 0,
nullptr, VRBaseMap,
false, IsClone,
625 MBB->
insert(InsertPos, MIB);
627 llvm_unreachable(
"Node is not insert_subreg, extract_subreg, or subreg_to_reg");
630 bool isNew = VRBaseMap.insert(std::make_pair(
Op, VRBase)).second;
632 assert(isNew &&
"Node emitted out of order - early");
640InstrEmitter::EmitCopyToRegClassNode(
SDNode *Node,
641 VRBaseMapType &VRBaseMap) {
643 unsigned DstRCIdx =
Node->getConstantOperandVal(1);
644 const TargetRegisterClass *DstRC =
645 TRI->getAllocatableClass(TRI->getRegClass(DstRCIdx));
646 Register NewVReg = MRI->createVirtualRegister(DstRC);
647 const MCInstrDesc &
II = TII->get(TargetOpcode::COPY);
648 MachineInstrBuilder MIB =
BuildMI(*MF,
Node->getDebugLoc(),
II, NewVReg);
649 AddOperand(MIB,
Node->getOperand(0), 1, &
II, VRBaseMap,
false,
652 MBB->insert(InsertPos, MIB);
654 bool isNew = VRBaseMap.insert(std::make_pair(
Op, NewVReg)).second;
656 assert(isNew &&
"Node emitted out of order - early");
661void InstrEmitter::EmitRegSequence(
SDNode *Node, VRBaseMapType &VRBaseMap,
662 bool IsClone,
bool IsCloned) {
663 unsigned DstRCIdx =
Node->getConstantOperandVal(0);
664 const TargetRegisterClass *RC = TRI->getRegClass(DstRCIdx);
665 Register NewVReg = MRI->createVirtualRegister(TRI->getAllocatableClass(RC));
666 const MCInstrDesc &
II = TII->get(TargetOpcode::REG_SEQUENCE);
667 MachineInstrBuilder MIB =
BuildMI(*MF,
Node->getDebugLoc(),
II, NewVReg);
676 "REG_SEQUENCE must have an odd number of operands!");
677 for (
unsigned i = 1; i !=
NumOps; ++i) {
683 if (!R || !
R->getReg().isPhysical()) {
684 unsigned SubIdx =
Op->getAsZExtVal();
686 const TargetRegisterClass *TRC = MRI->getRegClass(
SubReg);
687 const TargetRegisterClass *SRC =
688 TRI->getMatchingSuperRegClass(RC, TRC, SubIdx);
689 if (SRC && SRC != RC) {
690 MRI->setRegClass(NewVReg, SRC);
695 AddOperand(MIB,
Op, i+1, &
II, VRBaseMap,
false,
699 MBB->insert(InsertPos, MIB);
701 bool isNew = VRBaseMap.insert(std::make_pair(
Op, NewVReg)).second;
703 assert(isNew &&
"Node emitted out of order - early");
713 ->isValidLocationForIntrinsic(
DL) &&
714 "Expected inlined-at fields to agree");
719 "dbg_value with no location operands?");
725 if (EmitDebugInstrRefs)
740 const Value *V =
Op.getConst();
742 if (CI->getBitWidth() > 64)
744 if (CI->getBitWidth() == 1)
766 switch (
Op.getKind()) {
780 if (VRBaseMap.
count(V) == 0)
783 AddOperand(MIB, V, (*MIB).getNumOperands(), &DbgValDesc, VRBaseMap,
799 const MCInstrDesc &RefII = TII->get(TargetOpcode::DBG_INSTR_REF);
841 auto AddVRegOp = [&](
Register VReg) {
861 if (!MRI->hasOneDef(VReg)) {
866 DefMI = &*MRI->def_instr_begin(VReg);
873 if (
I == VRBaseMap.
end())
877 VReg = getVR(
Op, VRBaseMap);
881 if (!MRI->hasOneDef(VReg)) {
886 DefMI = &*MRI->def_instr_begin(VReg);
896 if (
DefMI->isCopyLike() || TII->isCopyInstr(*
DefMI)) {
902 unsigned OperandIdx = 0;
903 for (
const auto &MO :
DefMI->operands()) {
904 if (MO.isReg() && MO.isDef() && MO.getReg() == VReg)
908 assert(OperandIdx < DefMI->getNumOperands());
911 unsigned InstrNum =
DefMI->getDebugInstrNum();
917 if (MOs.
size() != OpCount)
920 return BuildMI(*MF,
DL, RefII,
false, MOs, Var, Expr);
942 const MCInstrDesc &DbgValDesc = TII->get(TargetOpcode::DBG_VALUE_LIST);
960 "Non variadic dbg_value should have only one location op");
966 const Value *V = LocationOps[0].getConst();
991 "Expected inlined-at fields to agree");
1004EmitMachineNode(
SDNode *
Node,
bool IsClone,
bool IsCloned,
1005 VRBaseMapType &VRBaseMap) {
1006 unsigned Opc =
Node->getMachineOpcode();
1009 if (
Opc == TargetOpcode::EXTRACT_SUBREG ||
1010 Opc == TargetOpcode::INSERT_SUBREG ||
1011 Opc == TargetOpcode::SUBREG_TO_REG) {
1012 EmitSubregNode(
Node, VRBaseMap, IsClone, IsCloned);
1017 if (
Opc == TargetOpcode::COPY_TO_REGCLASS) {
1018 EmitCopyToRegClassNode(
Node, VRBaseMap);
1023 if (
Opc == TargetOpcode::REG_SEQUENCE) {
1024 EmitRegSequence(Node, VRBaseMap, IsClone, IsCloned);
1028 if (
Opc == TargetOpcode::IMPLICIT_DEF)
1032 const MCInstrDesc &
II = TII->get(
Opc);
1034 unsigned NumDefs =
II.getNumDefs();
1038 if (
Opc == TargetOpcode::STACKMAP ||
Opc == TargetOpcode::PATCHPOINT) {
1043 if (
Opc == TargetOpcode::PATCHPOINT) {
1045 NumDefs = NumResults;
1048 }
else if (
Opc == TargetOpcode::STATEPOINT) {
1049 NumDefs = NumResults;
1052 unsigned NumImpUses = 0;
1053 unsigned NodeOperands =
1055 bool HasVRegVariadicDefs = !MF->getTarget().usesPhysRegsForValues() &&
1056 II.isVariadic() &&
II.variadicOpsAreDefs();
1057 bool HasPhysRegOuts = NumResults > NumDefs && !
II.implicit_defs().empty() &&
1058 !HasVRegVariadicDefs;
1060 unsigned NumMIOperands = NodeOperands + NumResults;
1061 if (
II.isVariadic())
1062 assert(NumMIOperands >=
II.getNumOperands() &&
1063 "Too few operands for a variadic node!");
1065 assert(NumMIOperands >=
II.getNumOperands() &&
1067 II.getNumOperands() +
II.implicit_defs().size() + NumImpUses &&
1068 "#operands for dag node doesn't match .td file!");
1072 MachineInstrBuilder MIB =
BuildMI(*MF,
Node->getDebugLoc(),
II);
1076 const SDNodeFlags
Flags =
Node->getFlags();
1077 if (
Flags.hasUnpredictable())
1083 CreateVirtualRegisters(Node, MIB,
II, IsClone, IsCloned, VRBaseMap);
1085 if (
Flags.hasNoSignedZeros())
1088 if (
Flags.hasAllowReciprocal())
1091 if (
Flags.hasNoNaNs())
1094 if (
Flags.hasNoInfs())
1097 if (
Flags.hasAllowContract())
1100 if (
Flags.hasApproximateFuncs())
1103 if (
Flags.hasAllowReassociation())
1106 if (
Flags.hasNoUnsignedWrap())
1109 if (
Flags.hasNoSignedWrap())
1112 if (
Flags.hasExact())
1115 if (
Flags.hasNoFPExcept())
1118 if (
Flags.hasDisjoint())
1121 if (
Flags.hasSameSign())
1124 if (
Flags.hasNoConvergent())
1130 bool HasOptPRefs = NumDefs > NumResults;
1131 assert((!HasOptPRefs || !HasPhysRegOuts) &&
1132 "Unable to cope with optional defs and phys regs defs!");
1133 unsigned NumSkip = HasOptPRefs ? NumDefs - NumResults : 0;
1134 for (
unsigned i = NumSkip; i != NodeOperands; ++i)
1135 AddOperand(MIB,
Node->getOperand(i), i-NumSkip+NumDefs, &
II,
1136 VRBaseMap,
false, IsClone, IsCloned);
1140 for (
unsigned i = 0; ScratchRegs[i]; ++i)
1154 MBB->insert(InsertPos, MIB);
1174 if (HasPhysRegOuts) {
1175 for (
unsigned i = NumDefs; i < NumResults; ++i) {
1177 if (!
Node->hasAnyUseOfValue(i))
1181 EmitCopyFromReg(
SDValue(Node, i), IsClone,
Reg, VRBaseMap);
1186 if (
Node->getValueType(
Node->getNumValues()-1) == MVT::Glue) {
1187 for (SDNode *
F =
Node->getGluedUser();
F;
F =
F->getGluedUser()) {
1198 const MCInstrDesc &MCID = TII->get(
F->getMachineOpcode());
1212 if (
II.isCall() && MF->getFunction().hasFnAttribute(Attribute::StrictFP)) {
1218 if (!UsedRegs.
empty() || !
II.implicit_defs().empty() ||
II.hasOptionalDef())
1223 if (
Opc == TargetOpcode::STATEPOINT && NumDefs > 0) {
1224 assert(!HasPhysRegOuts &&
"STATEPOINT mishandled");
1225 MachineInstr *
MI = MIB;
1227 int First = StatepointOpers(
MI).getFirstGCPtrIdx();
1228 assert(
First > 0 &&
"Statepoint has Defs but no GC ptr list");
1230 while (Def < NumDefs) {
1231 if (
MI->getOperand(Use).isReg())
1232 MI->tieOperands(Def++, Use);
1237 unsigned Op =
Node->getNumOperands();
1238 if (
Op != 0 &&
Node->getOperand(
Op - 1)->getOpcode() ==
1239 ~(
unsigned)TargetOpcode::CONVERGENCECTRL_GLUE) {
1240 Register VReg = getVR(
Node->getOperand(
Op - 1)->getOperand(0), VRBaseMap);
1249 MI->setDeactivationSymbol(
1250 *MF,
const_cast<GlobalValue *
>(
1257 if (
II.hasPostISelHook())
1258 TLI->AdjustInstrPostInstrSelection(*MIB, Node);
1264EmitSpecialNode(
SDNode *Node,
bool IsClone,
bool IsCloned,
1265 VRBaseMapType &VRBaseMap) {
1266 switch (
Node->getOpcode()) {
1271 llvm_unreachable(
"This target-independent node should have been selected!");
1285 TII->get(TargetOpcode::IMPLICIT_DEF), DestReg);
1290 SrcReg =
R->getReg();
1292 SrcReg = getVR(SrcVal, VRBaseMap);
1294 if (SrcReg == DestReg)
1297 BuildMI(*MBB, InsertPos,
Node->getDebugLoc(), TII->get(TargetOpcode::COPY),
1303 EmitCopyFromReg(
SDValue(Node, 0), IsClone, SrcReg, VRBaseMap);
1309 ? TargetOpcode::EH_LABEL
1310 : TargetOpcode::ANNOTATION_LABEL;
1320 ? TargetOpcode::LIFETIME_START
1321 : TargetOpcode::LIFETIME_END;
1323 BuildMI(*MBB, InsertPos,
Node->getDebugLoc(), TII->get(TarOp))
1329 unsigned TarOp = TargetOpcode::PSEUDO_PROBE;
1334 BuildMI(*MBB, InsertPos,
Node->getDebugLoc(), TII->get(TarOp))
1345 if (
Node->getOperand(
NumOps-1).getValueType() == MVT::Glue)
1350 ? TargetOpcode::INLINEASM_BR
1351 : TargetOpcode::INLINEASM;
1352 MachineInstrBuilder MIB =
1353 BuildMI(*MF,
Node->getDebugLoc(), TII->get(TgtOpc));
1368 SmallVector<unsigned, 8> GroupIdx;
1375 unsigned Flags =
Node->getConstantOperandVal(i);
1376 const InlineAsm::Flag
F(Flags);
1377 const unsigned NumVals =
F.getNumOperandRegisters();
1383 switch (
F.getKind()) {
1385 for (
unsigned j = 0;
j != NumVals; ++
j, ++i) {
1395 for (
unsigned j = 0;
j != NumVals; ++
j, ++i) {
1407 for (
unsigned j = 0;
j != NumVals; ++
j, ++i)
1408 AddOperand(MIB,
Node->getOperand(i), 0,
nullptr, VRBaseMap,
1409 false, IsClone, IsCloned);
1412 if (
F.isRegUseKind()) {
1414 if (
F.isUseOperandTiedToDef(DefGroup)) {
1415 unsigned DefIdx = GroupIdx[DefGroup] + 1;
1416 unsigned UseIdx = GroupIdx.
back() + 1;
1417 for (
unsigned j = 0;
j != NumVals; ++
j)
1423 for (
unsigned j = 0;
j != NumVals; ++
j, ++i) {
1425 AddOperand(MIB,
Op, 0,
nullptr, VRBaseMap,
1426 false, IsClone, IsCloned);
1431 MF->getSubtarget().classifyGlobalFunctionReference(
1447 MachineOperand *MO =
1449 assert(MO &&
"No def operand for clobbered register?");
1461 if (MF->getFunction().hasFnAttribute(Attribute::StrictFP)) {
1467 MBB->
insert(InsertPos, MIB);
1477 : MF(mbb->
getParent()), MRI(&MF->getRegInfo()),
1478 TII(MF->getSubtarget().getInstrInfo()),
1479 TRI(MF->getSubtarget().getRegisterInfo()),
1480 TLI(MF->getSubtarget().getTargetLowering()), MBB(mbb),
1481 InsertPos(insertpos) {
1482 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)
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
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
This file describes how to lower LLVM code to machine code.
ArrayRef - 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.
iterator find(const_arg_type_t< KeyT > Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
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)
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,...
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.
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.
bool isAllocatable() const
Return true if this register class may be used to create virtual registers.
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
bool expensiveOrImpossibleToCopy() const
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.
@ C
The default llvm calling convention, compatible with C.
@ 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.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_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)
TODO: Might pack better if we changed this to a Struct of Arrays, since MachineOperand is width 32,...