Index: lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp +++ lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp @@ -31,7 +31,7 @@ assert(MI.isDebugValue()); assert(MI.getNumOperands() == 4); // If location of variable is described using a register (directly or - // indirecltly), this register is always a first operand. + // indirectly), this register is always a first operand. return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; } @@ -164,7 +164,8 @@ // Look for register defs and register masks. Register masks are // typically on calls and they clobber everything not in the mask. for (const MachineOperand &MO : MI.operands()) { - if (MO.isReg() && MO.isDef() && MO.getReg()) { + if (MO.isReg() && MO.isDef() && MO.getReg() && + !TRI->isVirtualRegister(MO.getReg())) { for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid(); ++AI) Regs.set(*AI); @@ -191,7 +192,8 @@ // Not a DBG_VALUE instruction. It may clobber registers which describe // some variables. for (const MachineOperand &MO : MI.operands()) { - if (MO.isReg() && MO.isDef() && MO.getReg()) { + if (MO.isReg() && MO.isDef() && MO.getReg() && + !TRI->isVirtualRegister(MO.getReg())) { // If this is a register def operand, it may end a debug value // range. for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid(); @@ -238,7 +240,8 @@ if (!MBB.empty() && &MBB != &MF->back()) { for (auto I = RegVars.begin(), E = RegVars.end(); I != E;) { auto CurElem = I++; // CurElem can be erased below. - if (ChangingRegs.test(CurElem->first)) + if (!TRI->isVirtualRegister(CurElem->first) && + ChangingRegs.test(CurElem->first)) clobberRegisterUses(RegVars, CurElem, Result, MBB.back()); } } Index: lib/Target/WebAssembly/WebAssemblyRegStackify.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -258,6 +258,8 @@ LIS.getInstructionIndex(*Def).getRegSlot()); assert(DefVNI); for (auto I : MRI.use_nodbg_operands(Reg)) { + if (I.getParent()->isDebugValue()) + continue; const auto &Result = LI.Query(LIS.getInstructionIndex(*I.getParent())); if (Result.valueIn() == DefVNI) { if (!Result.isKill()) @@ -305,7 +307,7 @@ // Ask LiveIntervals whether moving this virtual register use or def to // Insert will change which value numbers are seen. - // + // // If the operand is a use of a register that is also defined in the same // instruction, test that the newly defined value reaches the insert point, // since the operand will be moving along with the def. @@ -367,7 +369,10 @@ continue; const MachineInstr *UseInst = Use.getParent(); - VNInfo *UseVNI = LI.getVNInfoBefore(LIS.getInstructionIndex(*UseInst)); + if (UseInst->isDebugValue()) + continue; + SlotIndex Idx = LIS.getInstructionIndex(*UseInst); + VNInfo *UseVNI = LI.getVNInfoBefore(Idx); if (UseVNI != OneUseVNI) continue; @@ -386,7 +391,7 @@ // // This is needed as a consequence of using implicit get_locals for // uses and implicit set_locals for defs. - if (UseInst->getDesc().getNumDefs() == 0) + if (UseInst->getDesc().getNumDefs() == 0) return false; const MachineOperand &MO = UseInst->getOperand(0); if (!MO.isReg()) Index: lib/Target/WebAssembly/WebAssemblyReplacePhysRegs.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyReplacePhysRegs.cpp +++ lib/Target/WebAssembly/WebAssemblyReplacePhysRegs.cpp @@ -88,6 +88,8 @@ if (VReg == WebAssembly::NoRegister) VReg = MRI.createVirtualRegister(RC); MO.setReg(VReg); + if (MO.getParent()->isDebugValue()) + MO.setIsDebug(); Changed = true; } } Index: lib/Target/WebAssembly/WebAssemblyStoreResults.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyStoreResults.cpp +++ lib/Target/WebAssembly/WebAssemblyStoreResults.cpp @@ -99,7 +99,11 @@ continue; // If this use gets a different value, skip it. - SlotIndex WhereIdx = LIS.getInstructionIndex(*Where); + SlotIndex WhereIdx; + if (Where->isDebugValue()) + WhereIdx = LIS.getSlotIndexes()->getIndexBefore(*Where); + else + WhereIdx = LIS.getInstructionIndex(*Where); VNInfo *WhereVNI = FromLI->getVNInfoAt(WhereIdx); if (WhereVNI && WhereVNI != FromVNI) continue; @@ -118,7 +122,8 @@ if (!O.isUndef()) { MI.getOperand(0).setIsDead(false); - Indices.push_back(WhereIdx.getRegSlot()); + if (!Where->isDebugValue()) + Indices.push_back(WhereIdx.getRegSlot()); } } Index: test/DebugInfo/WebAssembly/live-intervals.ll =================================================================== --- /dev/null +++ test/DebugInfo/WebAssembly/live-intervals.ll @@ -0,0 +1,70 @@ +; RUN: llc < %s -verify-machineinstrs -mtriple=wasm32-unknown-unknown | FileCheck %s +; CHECK: #DEBUG_VALUE: decode:i <- [%vreg25+12] +; CHECK: #DEBUG_VALUE: decode:v <- [%vreg25+11] +; CHECK: DW_TAG_variable +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +%0 = type opaque + +@key = external global [15 x i8], align 1 + +; Function Attrs: nounwind +define internal zeroext i8 @0(i32, i8 zeroext) !dbg !14 !type !19 { + %3 = alloca i32, align 4 + %4 = alloca i8, align 1 + store i32 %0, i32* %3, align 4 + call void @llvm.dbg.declare(metadata i32* %3, metadata !20, metadata !21), !dbg !22 + store i8 %1, i8* %4, align 1 + call void @llvm.dbg.declare(metadata i8* %4, metadata !23, metadata !21), !dbg !24 + %5 = load i8, i8* %4, align 1, !dbg !25 + %6 = zext i8 %5 to i32, !dbg !25 + %7 = load i32, i32* %3, align 4, !dbg !26 + %8 = urem i32 %7, 15, !dbg !27 + %9 = getelementptr inbounds [15 x i8], [15 x i8]* @key, i32 0, i32 %8, !dbg !28 + %10 = load i8, i8* %9, align 1, !dbg !28 + %11 = zext i8 %10 to i32, !dbg !28 + %12 = xor i32 %6, %11, !dbg !29 + %13 = trunc i32 %12 to i8, !dbg !30 + ret i8 %13, !dbg !31 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!11, !12} +!llvm.ident = !{!13} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3) +!1 = !DIFile(filename: "crash.c", directory: "wasm/tests") +!2 = !{} +!3 = !{!4} +!4 = distinct !DIGlobalVariable(name: "key", scope: !0, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, variable: [15 x i8]* @key) +!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 120, align: 8, elements: !9) +!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8_t", file: !7, line: 185, baseType: !8) +!7 = !DIFile(filename: "wasm/emscripten/system/include/libc/bits/alltypes.h", directory: "wasm/tests") +!8 = !DIBasicType(name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char) +!9 = !{!10} +!10 = !DISubrange(count: 15) +!11 = !{i32 2, !"Dwarf Version", i32 4} +!12 = !{i32 2, !"Debug Info Version", i32 3} +!13 = !{!"clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)"} +!14 = distinct !DISubprogram(name: "decode", scope: !1, file: !1, line: 11, type: !15, isLocal: false, isDefinition: true, scopeLine: 11, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) +!15 = !DISubroutineType(types: !16) +!16 = !{!6, !17, !6} +!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !7, line: 124, baseType: !18) +!18 = !DIBasicType(name: "long unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned) +!19 = !{i64 0, !"_ZTSFhmhE"} +!20 = !DILocalVariable(name: "i", arg: 1, scope: !14, file: !1, line: 11, type: !17) +!21 = !DIExpression() +!22 = !DILocation(line: 11, column: 23, scope: !14) +!23 = !DILocalVariable(name: "v", arg: 2, scope: !14, file: !1, line: 11, type: !6) +!24 = !DILocation(line: 11, column: 34, scope: !14) +!25 = !DILocation(line: 12, column: 11, scope: !14) +!26 = !DILocation(line: 12, column: 19, scope: !14) +!27 = !DILocation(line: 12, column: 21, scope: !14) +!28 = !DILocation(line: 12, column: 15, scope: !14) +!29 = !DILocation(line: 12, column: 13, scope: !14) +!30 = !DILocation(line: 12, column: 10, scope: !14) +!31 = !DILocation(line: 12, column: 3, scope: !14) Index: test/DebugInfo/WebAssembly/variable.ll =================================================================== --- /dev/null +++ test/DebugInfo/WebAssembly/variable.ll @@ -0,0 +1,55 @@ +; RUN: llc < %s -verify-machineinstrs -mtriple=wasm32-unknown-unknown | FileCheck %s +; CHECK: #DEBUG_VALUE: usage:self <- %vreg0 +; CHECK: DW_TAG_variable +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +%0 = type opaque + +@key = external local_unnamed_addr global [15 x i8], align 1 +@.str = external unnamed_addr constant [33 x i8], align 1 + +; Function Attrs: nounwind +define internal i32 @0(i8*) local_unnamed_addr !dbg !14 !type !22 { + tail call void @llvm.dbg.value(metadata i8* %0, i64 0, metadata !21, metadata !23), !dbg !24 + %2 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i32 0, i32 0), i8* %0), !dbg !25 + ret i32 1, !dbg !26 +} + +; Function Attrs: nounwind +declare i32 @printf(i8* nocapture readonly, ...) local_unnamed_addr + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!11, !12} +!llvm.ident = !{!13} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3) +!1 = !DIFile(filename: "crash.c", directory: "wasm/tests") +!2 = !{} +!3 = !{!4} +!4 = distinct !DIGlobalVariable(name: "key", scope: !0, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, variable: [15 x i8]* @key) +!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 120, align: 8, elements: !9) +!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8_t", file: !7, line: 185, baseType: !8) +!7 = !DIFile(filename: "wasm/emscripten/system/include/libc/bits/alltypes.h", directory: "wasm/tests") +!8 = !DIBasicType(name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char) +!9 = !{!10} +!10 = !DISubrange(count: 15) +!11 = !{i32 2, !"Dwarf Version", i32 4} +!12 = !{i32 2, !"Debug Info Version", i32 3} +!13 = !{!"clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)"} +!14 = distinct !DISubprogram(name: "usage", scope: !1, file: !1, line: 15, type: !15, isLocal: false, isDefinition: true, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !20) +!15 = !DISubroutineType(types: !16) +!16 = !{!17, !18} +!17 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 32, align: 32) +!19 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) +!20 = !{!21} +!21 = !DILocalVariable(name: "self", arg: 1, scope: !14, file: !1, line: 15, type: !18) +!22 = !{i64 0, !"_ZTSFiPcE"} +!23 = !DIExpression() +!24 = !DILocation(line: 15, column: 17, scope: !14) +!25 = !DILocation(line: 16, column: 3, scope: !14) +!26 = !DILocation(line: 17, column: 3, scope: !14) Index: test/DebugInfo/WebAssembly/wasm-reg-stackify.ll =================================================================== --- /dev/null +++ test/DebugInfo/WebAssembly/wasm-reg-stackify.ll @@ -0,0 +1,345 @@ +; RUN: llc < %s -verify-machineinstrs -mtriple=wasm32-unknown-unknown | FileCheck %s +; CHECK: #DEBUG_VALUE: main:argv <- %vreg175 +; CHECK: #DEBUG_VALUE: main:argc <- %vreg11 +; CHECK: #DEBUG_VALUE: main:c <- %vreg175 +; CHECK: #DEBUG_VALUE: main:op <- %vreg175 +; CHECK: #DEBUG_VALUE: main:ip <- %vreg175 +; CHECK: #DEBUG_VALUE: main:buf_size <- %vreg175 +; CHECK: #DEBUG_VALUE: main:buf <- %vreg175 +; CHECK: #DEBUG_VALUE: main:pos <- %vreg175 +; CHECK: __stack_pointer +; CHECK: DW_TAG_variable +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +%0 = type opaque + +@key = external local_unnamed_addr global [15 x i8], align 1 +@.str = external unnamed_addr constant [33 x i8], align 1 +@.str.1 = external unnamed_addr constant [2 x i8], align 1 +@optind = external local_unnamed_addr global i32, align 4 +@.str.2 = external unnamed_addr constant [3 x i8], align 1 +@.str.3 = external unnamed_addr constant [24 x i8], align 1 +@.str.4 = external unnamed_addr constant [50 x i8], align 1 +@.str.5 = external unnamed_addr constant [31 x i8], align 1 +@str = external unnamed_addr constant [36 x i8] + +; Function Attrs: nounwind readonly +declare zeroext i8 @decode(i32, i8 zeroext) local_unnamed_addr + +; Function Attrs: nounwind +declare i32 @usage(i8*) local_unnamed_addr + +; Function Attrs: nounwind +declare i32 @printf(i8* nocapture readonly, ...) local_unnamed_addr + +; Function Attrs: nounwind +define hidden i32 @main(i32, i8**) local_unnamed_addr !dbg !14 !type !36 { + tail call void @llvm.dbg.value(metadata i32 %0, i64 0, metadata !22, metadata !37), !dbg !38 + tail call void @llvm.dbg.value(metadata i8** %1, i64 0, metadata !23, metadata !37), !dbg !39 + tail call void @llvm.dbg.value(metadata %0* null, i64 0, metadata !24, metadata !37), !dbg !40 + tail call void @llvm.dbg.value(metadata %0* null, i64 0, metadata !28, metadata !37), !dbg !41 + %3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0)) , !dbg !42 + tail call void @llvm.dbg.value(metadata i32 %3, i64 0, metadata !29, metadata !37), !dbg !44 + switch i32 %3, label %71 [ + i32 -1, label %7 + i32 104, label %4 + i32 63, label %4 + ], !dbg !45 + +;