[Assignment Tracking] Skip scalable vectors in declare-to-assign pass

Do not convert dbg.declares to dbg.assigns for variables backed by scalable
vector allocas as this isn't yet supported.

Reviewed By: jmorse

Differential Revision: https://reviews.llvm.org/D149959
This commit is contained in:
OCHyams 2023-05-05 18:05:24 +01:00
parent 839469436a
commit f9dba933c6
2 changed files with 45 additions and 1 deletions

View File

@ -2104,6 +2104,7 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
return /*Changed*/ false;
bool Changed = false;
auto *DL = &F.getParent()->getDataLayout();
// Collect a map of {backing storage : dbg.declares} (currently "backing
// storage" is limited to Allocas). We'll use this to find dbg.declares to
// delete after running `trackAssignments`.
@ -2128,13 +2129,15 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
// FIXME: Skip VLAs for now (let these variables use dbg.declares).
if (!Alloca->isStaticAlloca())
continue;
// Similarly, skip scalable vectors (use dbg.declares instead).
if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
continue;
DbgDeclares[Alloca].insert(DDI);
Vars[Alloca].insert(VarRecord(DDI));
}
}
}
auto DL = std::make_unique<DataLayout>(F.getParent());
// FIXME: Locals can be backed by caller allocas (sret, byval).
// Note: trackAssignments doesn't respect dbg.declare's IR positions (as it
// doesn't "understand" dbg.declares). However, this doesn't appear to break

View File

@ -0,0 +1,41 @@
; RUN: opt -passes=declare-to-assign %s -S | FileCheck %s
;; Check declare-to-assign skips scalable vectors for now. i.e. do not replace
;; the dbg.declare with a dbg.assign intrinsic.
; CHECK: call void @llvm.dbg.declare(metadata ptr %c
define dso_local void @b() !dbg !9 {
entry:
%c = alloca <vscale x 8 x i32>, align 4
call void @llvm.dbg.declare(metadata ptr %c, metadata !13, metadata !DIExpression()), !dbg !21
ret void
}
declare void @llvm.dbg.declare(metadata, metadata, metadata)
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !5, !7}
!llvm.ident = !{!8}
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "test.c", directory: "/")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"target-abi", !"lp64"}
!7 = !{i32 8, !"SmallDataLimit", i32 8}
!8 = !{!"clang version 17.0.0"}
!9 = distinct !DISubprogram(name: "b", scope: !1, file: !1, line: 2, type: !10, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)
!10 = !DISubroutineType(types: !11)
!11 = !{null}
!12 = !{}
!13 = !DILocalVariable(name: "c", scope: !9, file: !1, line: 2, type: !14)
!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "a", file: !1, line: 1, baseType: !15)
!15 = !DIDerivedType(tag: DW_TAG_typedef, name: "__rvv_uint32m4_t", file: !16, baseType: !17)
!16 = !DIFile(filename: "test.c", directory: "/")
!17 = !DICompositeType(tag: DW_TAG_array_type, baseType: !18, flags: DIFlagVector, elements: !19)
!18 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
!19 = !{!20}
!20 = !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_constu, 4, DW_OP_div, DW_OP_constu, 4, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus))
!21 = !DILocation(line: 2, column: 14, scope: !9)