diff options
author | David Stenberg <david.stenberg@ericsson.com> | 2019-12-09 10:46:16 +0100 |
---|---|---|
committer | David Stenberg <david.stenberg@ericsson.com> | 2019-12-09 10:47:49 +0100 |
commit | 6965f835b476f8e8eb55916cac39be7ffe639866 (patch) | |
tree | 4d982f6f2f4958baa3208df55db8c447cfa6aa80 /llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | |
parent | d0fb7a478df19b78b58bf8778e9f046903115035 (diff) | |
download | bcm5719-llvm-6965f835b476f8e8eb55916cac39be7ffe639866.tar.gz bcm5719-llvm-6965f835b476f8e8eb55916cac39be7ffe639866.zip |
[DebugInfo] Make describeLoadedValue() reg aware
Summary:
Currently the describeLoadedValue() hook is assumed to describe the
value of the instruction's first explicit define. The hook will not be
called for instructions with more than one explicit define.
This commit adds a register parameter to the describeLoadedValue() hook,
and invokes the hook for all registers in the worklist.
This will allow us to for example describe instructions which produce
more than two parameters' values; e.g. Hexagon's various combine
instructions.
This also fixes situations in our downstream target where we may pass
smaller parameters in the high part of a register. If such a parameter's
value is produced by a larger copy instruction, we can't describe the
call site value using the super-register, and we instead need to know
which sub-register that should be used.
This also allows us to handle cases like this:
$ebx = [...]
$rdi = MOVSX64rr32 $ebx
$esi = MOV32rr $edi
CALL64pcrel32 @call
The hook will first be invoked for the MOV32rr instruction, which will
say that @call's second parameter (passed in $esi) is described by $edi.
As $edi is not preserved it will be added to the worklist. When we get
to the MOVSX64rr32 instruction, we need to describe two values; the
sign-extended value of $ebx -> $rdi for the first parameter, and $ebx ->
$edi for the second parameter, which is now possible.
This commit modifies the dbgcall-site-lea-interpretation.mir test case.
In the test case, the values of some 32-bit parameters were produced
with LEA64r. Perhaps we can in general cases handle such by emitting
expressions that AND out the lower 32-bits, but I have not been able to
land in a case where a LEA64r is used for a 32-bit parameter instead of
LEA64_32 from C code.
I have not found a case where it would be useful to describe parameters
using implicit defines, so in this patch the hook is still only invoked
for explicit defines of forwarding registers.
Reviewers: djtodoro, NikolaPrica, aprantl, vsk
Reviewed By: djtodoro, vsk
Subscribers: ormris, hiraditya, llvm-commits
Tags: #debug-info, #llvm
Differential Revision: https://reviews.llvm.org/D70431
Diffstat (limited to 'llvm/lib/Target/AArch64/AArch64InstrInfo.cpp')
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp index 15d908d0797..f952a2f62ba 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -30,6 +30,7 @@ #include "llvm/CodeGen/StackMaps.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/GlobalValue.h" #include "llvm/MC/MCAsmInfo.h" @@ -6447,10 +6448,16 @@ AArch64InstrInfo::isCopyInstrImpl(const MachineInstr &MI) const { return None; } -Optional<DestSourcePair> -AArch64InstrInfo::isAddImmediate(const MachineInstr &MI, - int64_t &Offset) const { +Optional<RegImmPair> AArch64InstrInfo::isAddImmediate(const MachineInstr &MI, + Register Reg) const { int Sign = 1; + int64_t Offset = 0; + + // TODO: Handle cases where Reg is a super- or sub-register of the + // destination register. + if (Reg != MI.getOperand(0).getReg()) + return None; + switch (MI.getOpcode()) { default: return None; @@ -6474,14 +6481,60 @@ AArch64InstrInfo::isAddImmediate(const MachineInstr &MI, Offset = Offset << Shift; } } - return DestSourcePair{MI.getOperand(0), MI.getOperand(1)}; + return RegImmPair{MI.getOperand(1).getReg(), Offset}; +} + +/// If the given ORR instruction is a copy, and \p DescribedReg overlaps with +/// the destination register then, if possible, describe the value in terms of +/// the source register. +static Optional<ParamLoadedValue> +describeORRLoadedValue(const MachineInstr &MI, Register DescribedReg, + const TargetInstrInfo *TII, + const TargetRegisterInfo *TRI) { + auto DestSrc = TII->isCopyInstr(MI); + if (!DestSrc) + return None; + + Register DestReg = DestSrc->Destination->getReg(); + Register SrcReg = DestSrc->Source->getReg(); + + auto Expr = DIExpression::get(MI.getMF()->getFunction().getContext(), {}); + + // If the described register is the destination, just return the source. + if (DestReg == DescribedReg) + return ParamLoadedValue(MachineOperand::CreateReg(SrcReg, false), Expr); + + // ORRWrs zero-extends to 64-bits, so we need to consider such cases. + if (MI.getOpcode() == AArch64::ORRWrs && + TRI->isSuperRegister(DestReg, DescribedReg)) + return ParamLoadedValue(MachineOperand::CreateReg(SrcReg, false), Expr); + + // We may need to describe the lower part of a ORRXrs move. + if (MI.getOpcode() == AArch64::ORRXrs && + TRI->isSubRegister(DestReg, DescribedReg)) { + Register SrcSubReg = TRI->getSubReg(SrcReg, AArch64::sub_32); + return ParamLoadedValue(MachineOperand::CreateReg(SrcSubReg, false), Expr); + } + + assert(!TRI->isSuperOrSubRegisterEq(DestReg, DescribedReg) && + "Unhandled ORR[XW]rs copy case"); + + return None; } Optional<ParamLoadedValue> -AArch64InstrInfo::describeLoadedValue(const MachineInstr &MI) const { +AArch64InstrInfo::describeLoadedValue(const MachineInstr &MI, + Register Reg) const { + const MachineFunction *MF = MI.getMF(); + const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); switch (MI.getOpcode()) { case AArch64::MOVZWi: - case AArch64::MOVZXi: + case AArch64::MOVZXi: { + // MOVZWi may be used for producing zero-extended 32-bit immediates in + // 64-bit parameters, so we need to consider super-registers. + if (!TRI->isSuperRegisterEq(MI.getOperand(0).getReg(), Reg)) + return None; + if (!MI.getOperand(1).isImm()) return None; int64_t Immediate = MI.getOperand(1).getImm(); @@ -6489,7 +6542,12 @@ AArch64InstrInfo::describeLoadedValue(const MachineInstr &MI) const { return ParamLoadedValue(MachineOperand::CreateImm(Immediate << Shift), nullptr); } - return TargetInstrInfo::describeLoadedValue(MI); + case AArch64::ORRWrs: + case AArch64::ORRXrs: + return describeORRLoadedValue(MI, Reg, this, TRI); + } + + return TargetInstrInfo::describeLoadedValue(MI, Reg); } #define GET_INSTRINFO_HELPERS |