Commit adf7a0a5 authored by Yury Delendik's avatar Yury Delendik Committed by Derek Schuff
Browse files

[WebAssembly] Use TargetIndex operands in DbgValue to track WebAssembly operands locations

Extends DWARF expression language to express locals/globals locations. (via
target-index operands atm) (possible variants are: non-virtual registers
or address spaces)

The WebAssemblyExplicitLocals can replace virtual registers to targertindex
operand type at the time when WebAssembly backend introduces
{get,set,tee}_local instead of corresponding virtual registers.

Reviewed By: aprantl, dschuff

Tags: #debug-info, #llvm

Differential Revision: https://reviews.llvm.org/D52634
parent 538b485c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -648,6 +648,8 @@ HANDLE_DW_OP(0xa9, reinterpret, 5, DWARF)
// Vendor extensions:
// Extensions for GNU-style thread-local storage.
HANDLE_DW_OP(0xe0, GNU_push_tls_address, 0, GNU)
// Extensions for WebAssembly.
HANDLE_DW_OP(0xed, WASM_location, 0, WASM)
// The GNU entry value extension.
HANDLE_DW_OP(0xf3, GNU_entry_value, 0, GNU)
// Extensions for Fission proposal.
+2 −1
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ enum LLVMConstants : uint32_t {
  DWARF_VENDOR_GNU = 3,
  DWARF_VENDOR_GOOGLE = 4,
  DWARF_VENDOR_LLVM = 5,
  DWARF_VENDOR_MIPS = 6
  DWARF_VENDOR_MIPS = 6,
  DWARF_VENDOR_WASM = 7
};

/// Constants that define the DWARF format as 32 or 64 bit.
+4 −0
Original line number Diff line number Diff line
@@ -879,6 +879,10 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
    OS << MI->getOperand(0).getImm();
  } else if (MI->getOperand(0).isCImm()) {
    MI->getOperand(0).getCImm()->getValue().print(OS, false /*isSigned*/);
  } else if (MI->getOperand(0).isTargetIndex()) {
    auto Op = MI->getOperand(0);
    OS << "!target-index(" << Op.getIndex() << "," << Op.getOffset() << ")";
    return true;
  } else {
    unsigned Reg;
    if (MI->getOperand(0).isReg()) {
+35 −3
Original line number Diff line number Diff line
@@ -20,13 +20,33 @@
namespace llvm {
class AsmPrinter;

/// This struct describes target specific location.
struct TargetIndexLocation {
  int Index;
  int Offset;

  TargetIndexLocation() = default;
  TargetIndexLocation(unsigned Idx, int64_t Offset)
      : Index(Idx), Offset(Offset) {}

  bool operator==(const TargetIndexLocation &Other) const {
    return Index == Other.Index && Offset == Other.Offset;
  }
};

/// A single location or constant.
class DbgValueLoc {
  /// Any complex address location expression for this DbgValueLoc.
  const DIExpression *Expression;

  /// Type of entry that this represents.
  enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
  enum EntryType {
    E_Location,
    E_Integer,
    E_ConstantFP,
    E_ConstantInt,
    E_TargetIndexLocation
  };
  enum EntryType EntryKind;

  /// Either a constant,
@@ -36,8 +56,12 @@ class DbgValueLoc {
    const ConstantInt *CIP;
  } Constant;

  union {
    /// Or a location in the machine frame.
    MachineLocation Loc;
    /// Or a location from target specific location.
    TargetIndexLocation TIL;
  };

public:
  DbgValueLoc(const DIExpression *Expr, int64_t i)
@@ -56,8 +80,13 @@ public:
      : Expression(Expr), EntryKind(E_Location), Loc(Loc) {
    assert(cast<DIExpression>(Expr)->isValid());
  }
  DbgValueLoc(const DIExpression *Expr, TargetIndexLocation Loc)
      : Expression(Expr), EntryKind(E_TargetIndexLocation), TIL(Loc) {}

  bool isLocation() const { return EntryKind == E_Location; }
  bool isTargetIndexLocation() const {
    return EntryKind == E_TargetIndexLocation;
  }
  bool isInt() const { return EntryKind == E_Integer; }
  bool isConstantFP() const { return EntryKind == E_ConstantFP; }
  bool isConstantInt() const { return EntryKind == E_ConstantInt; }
@@ -65,6 +94,7 @@ public:
  const ConstantFP *getConstantFP() const { return Constant.CFP; }
  const ConstantInt *getConstantInt() const { return Constant.CIP; }
  MachineLocation getLoc() const { return Loc; }
  TargetIndexLocation getTargetIndexLocation() const { return TIL; }
  bool isFragment() const { return getExpression()->isFragment(); }
  bool isEntryVal() const { return getExpression()->isEntryValue(); }
  const DIExpression *getExpression() const { return Expression; }
@@ -162,6 +192,8 @@ inline bool operator==(const DbgValueLoc &A,
  switch (A.EntryKind) {
  case DbgValueLoc::E_Location:
    return A.Loc == B.Loc;
  case DbgValueLoc::E_TargetIndexLocation:
    return A.TIL == B.TIL;
  case DbgValueLoc::E_Integer:
    return A.Constant.Int == B.Constant.Int;
  case DbgValueLoc::E_ConstantFP:
+10 −0
Original line number Diff line number Diff line
@@ -241,6 +241,11 @@ static DbgValueLoc getDebugLocValue(const MachineInstr *MI) {
    MachineLocation MLoc(RegOp.getReg(), Op1.isImm());
    return DbgValueLoc(Expr, MLoc);
  }
  if (MI->getOperand(0).isTargetIndex()) {
    auto Op = MI->getOperand(0);
    return DbgValueLoc(Expr,
                       TargetIndexLocation(Op.getIndex(), Op.getOffset()));
  }
  if (MI->getOperand(0).isImm())
    return DbgValueLoc(Expr, MI->getOperand(0).getImm());
  if (MI->getOperand(0).isFPImm())
@@ -2241,6 +2246,11 @@ void DwarfDebug::emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
    if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
      return;
    return DwarfExpr.addExpression(std::move(Cursor));
  } else if (Value.isTargetIndexLocation()) {
    TargetIndexLocation Loc = Value.getTargetIndexLocation();
    // TODO TargetIndexLocation is a target-independent. Currently only the WebAssembly-specific
    // encoding is supported.
    DwarfExpr.addWasmLocation(Loc.Index, Loc.Offset);
  } else if (Value.isConstantFP()) {
    APInt RawBytes = Value.getConstantFP()->getValueAPF().bitcastToAPInt();
    DwarfExpr.addUnsignedConstant(RawBytes);
Loading