mirror of
https://github.com/intel/llvm.git
synced 2026-02-08 00:50:03 +08:00
[WebAssembly] locals can now be indirect in DWARF
This for example to indicate that byval args are represented by a pointer to a struct. Followup to https://reviews.llvm.org/D94140 Differential Revision: https://reviews.llvm.org/D94347
This commit is contained in:
@@ -2501,8 +2501,8 @@ void DwarfDebug::emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
|
||||
// encoding is supported.
|
||||
assert(AP.TM.getTargetTriple().isWasm());
|
||||
DwarfExpr.addWasmLocation(Loc.Index, static_cast<uint64_t>(Loc.Offset));
|
||||
DwarfExpr.addExpression(std::move(ExprCursor));
|
||||
return;
|
||||
DwarfExpr.addExpression(std::move(ExprCursor));
|
||||
return;
|
||||
} else if (Value.isConstantFP()) {
|
||||
if (AP.getDwarfVersion() >= 4 && !AP.getDwarfDebug()->tuneForSCE() &&
|
||||
!ExprCursor) {
|
||||
|
||||
@@ -664,9 +664,14 @@ void DwarfExpression::emitLegacyZExt(unsigned FromBits) {
|
||||
}
|
||||
|
||||
void DwarfExpression::addWasmLocation(unsigned Index, uint64_t Offset) {
|
||||
assert(LocationKind == Implicit || LocationKind == Unknown);
|
||||
LocationKind = Implicit;
|
||||
emitOp(dwarf::DW_OP_WASM_location);
|
||||
emitUnsigned(Index);
|
||||
emitUnsigned(Index == 4/*TI_LOCAL_INDIRECT*/ ? 0/*TI_LOCAL*/ : Index);
|
||||
emitUnsigned(Offset);
|
||||
if (Index == 4 /*TI_LOCAL_INDIRECT*/) {
|
||||
assert(LocationKind == Unknown);
|
||||
LocationKind = Memory;
|
||||
} else {
|
||||
assert(LocationKind == Implicit || LocationKind == Unknown);
|
||||
LocationKind = Implicit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,10 @@ bool DWARFExpression::Operation::extract(DataExtractor Data,
|
||||
case Operation::WasmLocationArg:
|
||||
assert(Operand == 1);
|
||||
switch (Operands[0]) {
|
||||
case 0: case 1: case 2:
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 4:
|
||||
Operands[Operand] = Data.getULEB128(&Offset);
|
||||
break;
|
||||
case 3: // global as uint32
|
||||
@@ -294,8 +297,11 @@ bool DWARFExpression::Operation::print(raw_ostream &OS, DIDumpOptions DumpOpts,
|
||||
} else if (Size == Operation::WasmLocationArg) {
|
||||
assert(Operand == 1);
|
||||
switch (Operands[0]) {
|
||||
case 0: case 1: case 2:
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3: // global as uint32
|
||||
case 4:
|
||||
OS << format(" 0x%" PRIx64, Operands[Operand]);
|
||||
break;
|
||||
default: assert(false);
|
||||
|
||||
@@ -87,10 +87,14 @@ enum TargetIndex {
|
||||
TI_LOCAL,
|
||||
// Followed by an absolute global index (ULEB). DEPRECATED.
|
||||
TI_GLOBAL_FIXED,
|
||||
// Followed by the index from the bottom of the Wasm stack.
|
||||
TI_OPERAND_STACK,
|
||||
// Followed by a compilation unit relative global index (uint32_t)
|
||||
// that will have an associated relocation.
|
||||
TI_GLOBAL_RELOC
|
||||
TI_GLOBAL_RELOC,
|
||||
// Like TI_LOCAL, but indicates an indirect value (e.g. byval arg
|
||||
// passed by pointer).
|
||||
TI_LOCAL_INDIRECT
|
||||
};
|
||||
} // end namespace WebAssembly
|
||||
|
||||
|
||||
@@ -59,7 +59,11 @@ void WebAssemblyDebugValueManager::clone(MachineInstr *Insert,
|
||||
|
||||
void WebAssemblyDebugValueManager::replaceWithLocal(unsigned LocalId) {
|
||||
for (auto *DBI : DbgValues) {
|
||||
MachineOperand &Op = DBI->getDebugOperand(0);
|
||||
Op.ChangeToTargetIndex(llvm::WebAssembly::TI_LOCAL, LocalId);
|
||||
MachineOperand &Op0 = DBI->getDebugOperand(0);
|
||||
MachineOperand &Op1 = DBI->getOperand(1);
|
||||
bool Indirect = Op1.isImm() && Op1.getImm() == 0;
|
||||
Op0.ChangeToTargetIndex(Indirect ? llvm::WebAssembly::TI_LOCAL_INDIRECT
|
||||
: llvm::WebAssembly::TI_LOCAL,
|
||||
LocalId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +210,7 @@ WebAssemblyInstrInfo::getSerializableTargetIndices() const {
|
||||
{WebAssembly::TI_LOCAL, "wasm-local"},
|
||||
{WebAssembly::TI_GLOBAL_FIXED, "wasm-global-fixed"},
|
||||
{WebAssembly::TI_OPERAND_STACK, "wasm-operand-stack"},
|
||||
{WebAssembly::TI_GLOBAL_RELOC, "wasm-global-reloc"}};
|
||||
{WebAssembly::TI_GLOBAL_RELOC, "wasm-global-reloc"},
|
||||
{WebAssembly::TI_LOCAL_INDIRECT, "wasm-local-indirect"}};
|
||||
return makeArrayRef(TargetIndices);
|
||||
}
|
||||
|
||||
@@ -103,11 +103,11 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
|
||||
; CHECK-NEXT: DW_AT_name ("x")
|
||||
|
||||
; CHECK-LABEL: DW_TAG_formal_parameter
|
||||
; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x1, DW_OP_stack_value)
|
||||
; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x1)
|
||||
; CHECK-NEXT: DW_AT_name ("some_union")
|
||||
|
||||
; CHECK-LABEL: DW_TAG_formal_parameter
|
||||
; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x2, DW_OP_stack_value)
|
||||
; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x2)
|
||||
; CHECK-NEXT: DW_AT_name ("some_struct")
|
||||
|
||||
; CHECK-LABEL: DW_TAG_formal_parameter
|
||||
|
||||
Reference in New Issue
Block a user