-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SelectionDAG] Prevent converting a virtual register to an MCRegister. #122857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I believe the goal is that MCRegister is only for physical registers.
@llvm/pr-subscribers-llvm-selectiondag Author: Craig Topper (topperc) ChangesI believe the goal is that MCRegister is only for physical registers. Full diff: https://github.com/llvm/llvm-project/pull/122857.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index d64a90bcaae7da..c918ca3df7cd21 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -705,53 +705,57 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
if (InstrRef)
continue;
- // If Reg is live-in then update debug info to track its copy in a vreg.
- DenseMap<MCRegister, Register>::iterator LDI = LiveInMap.find(Reg);
- if (LDI != LiveInMap.end()) {
- assert(!hasFI && "There's no handling of frame pointer updating here yet "
- "- add if needed");
- MachineInstr *Def = RegInfo->getVRegDef(LDI->second);
- MachineBasicBlock::iterator InsertPos = Def;
- const MDNode *Variable = MI->getDebugVariable();
- const MDNode *Expr = MI->getDebugExpression();
- DebugLoc DL = MI->getDebugLoc();
- bool IsIndirect = MI->isIndirectDebugValue();
- if (IsIndirect)
- assert(MI->getDebugOffset().getImm() == 0 &&
- "DBG_VALUE with nonzero offset");
- assert(cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
- "Expected inlined-at fields to agree");
- assert(MI->getOpcode() != TargetOpcode::DBG_VALUE_LIST &&
- "Didn't expect to see a DBG_VALUE_LIST here");
- // Def is never a terminator here, so it is ok to increment InsertPos.
- BuildMI(*EntryMBB, ++InsertPos, DL, TII->get(TargetOpcode::DBG_VALUE),
- IsIndirect, LDI->second, Variable, Expr);
-
- // If this vreg is directly copied into an exported register then
- // that COPY instructions also need DBG_VALUE, if it is the only
- // user of LDI->second.
- MachineInstr *CopyUseMI = nullptr;
- for (MachineInstr &UseMI : RegInfo->use_instructions(LDI->second)) {
- if (UseMI.isDebugValue())
- continue;
- if (UseMI.isCopy() && !CopyUseMI && UseMI.getParent() == EntryMBB) {
- CopyUseMI = &UseMI;
- continue;
+ if (Reg.isPhysical()) {
+ // If Reg is live-in then update debug info to track its copy in a vreg.
+ DenseMap<MCRegister, Register>::iterator LDI = LiveInMap.find(Reg);
+ if (LDI != LiveInMap.end()) {
+ assert(!hasFI &&
+ "There's no handling of frame pointer updating here yet "
+ "- add if needed");
+ MachineInstr *Def = RegInfo->getVRegDef(LDI->second);
+ MachineBasicBlock::iterator InsertPos = Def;
+ const MDNode *Variable = MI->getDebugVariable();
+ const MDNode *Expr = MI->getDebugExpression();
+ DebugLoc DL = MI->getDebugLoc();
+ bool IsIndirect = MI->isIndirectDebugValue();
+ if (IsIndirect)
+ assert(MI->getDebugOffset().getImm() == 0 &&
+ "DBG_VALUE with nonzero offset");
+ assert(
+ cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
+ "Expected inlined-at fields to agree");
+ assert(MI->getOpcode() != TargetOpcode::DBG_VALUE_LIST &&
+ "Didn't expect to see a DBG_VALUE_LIST here");
+ // Def is never a terminator here, so it is ok to increment InsertPos.
+ BuildMI(*EntryMBB, ++InsertPos, DL, TII->get(TargetOpcode::DBG_VALUE),
+ IsIndirect, LDI->second, Variable, Expr);
+
+ // If this vreg is directly copied into an exported register then
+ // that COPY instructions also need DBG_VALUE, if it is the only
+ // user of LDI->second.
+ MachineInstr *CopyUseMI = nullptr;
+ for (MachineInstr &UseMI : RegInfo->use_instructions(LDI->second)) {
+ if (UseMI.isDebugValue())
+ continue;
+ if (UseMI.isCopy() && !CopyUseMI && UseMI.getParent() == EntryMBB) {
+ CopyUseMI = &UseMI;
+ continue;
+ }
+ // Otherwise this is another use or second copy use.
+ CopyUseMI = nullptr;
+ break;
+ }
+ if (CopyUseMI &&
+ TRI.getRegSizeInBits(LDI->second, MRI) ==
+ TRI.getRegSizeInBits(CopyUseMI->getOperand(0).getReg(), MRI)) {
+ // Use MI's debug location, which describes where Variable was
+ // declared, rather than whatever is attached to CopyUseMI.
+ MachineInstr *NewMI =
+ BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsIndirect,
+ CopyUseMI->getOperand(0).getReg(), Variable, Expr);
+ MachineBasicBlock::iterator Pos = CopyUseMI;
+ EntryMBB->insertAfter(Pos, NewMI);
}
- // Otherwise this is another use or second copy use.
- CopyUseMI = nullptr;
- break;
- }
- if (CopyUseMI &&
- TRI.getRegSizeInBits(LDI->second, MRI) ==
- TRI.getRegSizeInBits(CopyUseMI->getOperand(0).getReg(), MRI)) {
- // Use MI's debug location, which describes where Variable was
- // declared, rather than whatever is attached to CopyUseMI.
- MachineInstr *NewMI =
- BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsIndirect,
- CopyUseMI->getOperand(0).getReg(), Variable, Expr);
- MachineBasicBlock::iterator Pos = CopyUseMI;
- EntryMBB->insertAfter(Pos, NewMI);
}
}
}
|
CopyUseMI = &UseMI; | ||
continue; | ||
if (Reg.isPhysical()) { | ||
// If Reg is live-in then update debug info to track its copy in a vreg. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should extract into its own function at this point
I believe the goal is that MCRegister is only for physical registers.