[InstrRef][AArch64][1/4] Accept constant physreg variable locations
Late in SelectionDAG we join up instruction numbers with their defining
instructions, if it couldn't be done during the main part of SelectionDAG.
One exception is function arguments, where we have to point a DBG_PHI
instruction at the incoming live register, as they don't have a defining
instruction. This patch adds another exception, for constant physregs, like
aarch64 has.
It may seem wasteful to use two instructions where we could use a single
DBG_VALUE, however the whole point of instruction referencing is to
decouple the identification of values from the specification of where
variable location ranges start.
(Part of my aarch64 work to ease adoption of instruction referencing, as
in the meta comment on D104520)
Differential Revision: https://reviews.llvm.org/D104520
GitOrigin-RevId: f86694cb808f22253e00742ccd279760ef0c688d
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index 72e5870..dc4b1a6 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -1131,15 +1131,24 @@
}
}
+ MachineBasicBlock &InsertBB = *CurInst->getParent();
+
// We reached the start of the block before finding a defining instruction.
- // It must be an argument: assert that this is the entry block, and produce
- // a DBG_PHI.
- assert(!State.first.isVirtual());
- MachineBasicBlock &TargetBB = *CurInst->getParent();
- assert(&*TargetBB.getParent()->begin() == &TargetBB);
+ // It could be from a constant register, otherwise it must be an argument.
+ if (TRI.isConstantPhysReg(State.first)) {
+ // We can produce a DBG_PHI that identifies the constant physreg. Doesn't
+ // matter where we put it, as it's constant valued.
+ assert(CurInst->isCopy());
+ } else {
+ // Assert that this is the entry block. If it isn't, then there is some
+ // code construct we don't recognise that deals with physregs across
+ // blocks.
+ assert(!State.first.isVirtual());
+ assert(&*InsertBB.getParent()->begin() == &InsertBB);
+ }
// Create DBG_PHI for specified physreg.
- auto Builder = BuildMI(TargetBB, TargetBB.getFirstNonPHI(), DebugLoc(),
+ auto Builder = BuildMI(InsertBB, InsertBB.getFirstNonPHI(), DebugLoc(),
TII.get(TargetOpcode::DBG_PHI));
Builder.addReg(State.first, RegState::Debug);
unsigned NewNum = getNewDebugInstrNum();