[llvm] r323813 - Teach ValueMapper to use ODR uniqued types when available

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 31 01:04:20 PST 2018


Merged to 6.0 in r323854.

On Tue, Jan 30, 2018 at 9:16 PM, Teresa Johnson via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: tejohnson
> Date: Tue Jan 30 12:16:32 2018
> New Revision: 323813
>
> URL: http://llvm.org/viewvc/llvm-project?rev=323813&view=rev
> Log:
> Teach ValueMapper to use ODR uniqued types when available
>
> Summary:
> This is exposed during ThinLTO compilation, when we import an alias by
> creating a clone of the aliasee. Without this fix the debug type is
> unnecessarily cloned and we get a duplicate, undoing the uniquing.
>
> Fixes PR36089.
>
> Reviewers: mehdi_amini, pcc
>
> Subscribers: eraman, JDevlieghere, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D41669
>
> Added:
>     llvm/trunk/test/ThinLTO/X86/Inputs/dicompositetype-unique-alias.ll
>     llvm/trunk/test/ThinLTO/X86/dicompositetype-unique-alias.ll
> Modified:
>     llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
>
> Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
> Transforms/Utils/ValueMapper.cpp?rev=323813&r1=323812&r2=323813&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Tue Jan 30 12:16:32
> 2018
> @@ -25,6 +25,7 @@
>  #include "llvm/IR/CallSite.h"
>  #include "llvm/IR/Constant.h"
>  #include "llvm/IR/Constants.h"
> +#include "llvm/IR/DebugInfoMetadata.h"
>  #include "llvm/IR/DerivedTypes.h"
>  #include "llvm/IR/Function.h"
>  #include "llvm/IR/GlobalAlias.h"
> @@ -536,13 +537,23 @@ Optional<Metadata *> MDNodeMapper::tryTo
>    return None;
>  }
>
> +static Metadata *cloneOrBuildODR(const MDNode &N) {
> +  auto *CT = dyn_cast<DICompositeType>(&N);
> +  // If ODR type uniquing is enabled, we would have uniqued composite
> types
> +  // with identifiers during bitcode reading, so we can just use CT.
> +  if (CT && CT->getContext().isODRUniquingDebugTypes() &&
> +      CT->getIdentifier() != "")
> +    return const_cast<DICompositeType *>(CT);
> +  return MDNode::replaceWithDistinct(N.clone());
> +}
> +
>  MDNode *MDNodeMapper::mapDistinctNode(const MDNode &N) {
>    assert(N.isDistinct() && "Expected a distinct node");
>    assert(!M.getVM().getMappedMD(&N) && "Expected an unmapped node");
> -  DistinctWorklist.push_back(cast<MDNode>(
> -      (M.Flags & RF_MoveDistinctMDs)
> -          ? M.mapToSelf(&N)
> -          : M.mapToMetadata(&N, MDNode::replaceWithDistinct(N.
> clone()))));
> +  DistinctWorklist.push_back(
> +      cast<MDNode>((M.Flags & RF_MoveDistinctMDs)
> +                       ? M.mapToSelf(&N)
> +                       : M.mapToMetadata(&N, cloneOrBuildODR(N))));
>    return DistinctWorklist.back();
>  }
>
>
> Added: llvm/trunk/test/ThinLTO/X86/Inputs/dicompositetype-unique-alias.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/
> ThinLTO/X86/Inputs/dicompositetype-unique-alias.ll?rev=323813&view=auto
> ============================================================
> ==================
> --- llvm/trunk/test/ThinLTO/X86/Inputs/dicompositetype-unique-alias.ll
> (added)
> +++ llvm/trunk/test/ThinLTO/X86/Inputs/dicompositetype-unique-alias.ll
> Tue Jan 30 12:16:32 2018
> @@ -0,0 +1,39 @@
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-scei-ps4"
> +
> +%struct.CFVS = type { %struct.Vec }
> +%struct.Vec = type { i8 }
> +%struct.S = type { i8 }
> +
> + at _ZN4CFVSD1Ev = alias void (%struct.CFVS*), void (%struct.CFVS*)*
> @_ZN4CFVSD2Ev
> +
> +define void @_ZN4CFVSD2Ev(%struct.CFVS* %this) unnamed_addr align 2 !dbg
> !8 {
> +entry:
> +  %this.addr = alloca %struct.CFVS*, align 8
> +  store %struct.CFVS* %this, %struct.CFVS** %this.addr, align 8
> +  %this1 = load %struct.CFVS*, %struct.CFVS** %this.addr, align 8
> +  %m_val = getelementptr inbounds %struct.CFVS, %struct.CFVS* %this1, i32
> 0, i32 0
> +  ret void
> +}
> +
> +declare dereferenceable(1) %struct.S* @_Z3Getv()
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!3, !4, !5, !6}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
> producer: "clang version 6.0.0 (trunk 321360) (llvm/trunk 321359)",
> isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
> +!1 = !DIFile(filename: "bz188598-b.cpp", directory: "")
> +!2 = !{}
> +!3 = !{i32 2, !"Dwarf Version", i32 4}
> +!4 = !{i32 2, !"Debug Info Version", i32 3}
> +!5 = !{i32 1, !"wchar_size", i32 2}
> +!6 = !{i32 7, !"PIC Level", i32 2}
> +!8 = distinct !DISubprogram(name: "~CFVS", linkageName: "_ZN4CFVSD2Ev",
> scope: !9, file: !1, line: 2, type: !28, isLocal: false, isDefinition:
> true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0,
> declaration: !27, variables: !2)
> +!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "CFVS",
> file: !10, line: 7, size: 8, elements: !11, identifier: "_ZTS4CFVS")
> +!10 = !DIFile(filename: "./bz188598.h", directory: "")
> +!11 = !{!35}
> +!27 = !DISubprogram(name: "~CFVS", scope: !9, file: !10, line: 8, type:
> !28, isLocal: false, isDefinition: false, scopeLine: 8, flags:
> DIFlagPrototyped, isOptimized: false)
> +!28 = !DISubroutineType(types: !29)
> +!29 = !{null, !30}
> +!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64,
> flags: DIFlagArtificial | DIFlagObjectPointer)
> +!35 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
>
> Added: llvm/trunk/test/ThinLTO/X86/dicompositetype-unique-alias.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/
> ThinLTO/X86/dicompositetype-unique-alias.ll?rev=323813&view=auto
> ============================================================
> ==================
> --- llvm/trunk/test/ThinLTO/X86/dicompositetype-unique-alias.ll (added)
> +++ llvm/trunk/test/ThinLTO/X86/dicompositetype-unique-alias.ll Tue Jan
> 30 12:16:32 2018
> @@ -0,0 +1,62 @@
> +; RUN: opt -module-summary -o %t1.bc %s
> +; RUN: opt -module-summary -o %t2.bc %S/Inputs/dicompositetype-
> unique-alias.ll
> +; RUN: llvm-lto --thinlto-action=run %t1.bc %t2.bc
> -thinlto-save-temps=%t3.
> +; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s
> +; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t --save-temps \
> +; RUN: -r %t1.bc,_ZN1CD2Ev,pl \
> +; RUN: -r %t1.bc,_ZN4CFVSD1Ev,l \
> +; RUN: -r %t1.bc,_ZN4CFVSD2Ev,l \
> +; RUN: -r %t1.bc,_Z3Getv,l \
> +; RUN: -r %t2.bc,_ZN4CFVSD1Ev,pl \
> +; RUN: -r %t2.bc,_ZN4CFVSD2Ev,pl \
> +; RUN: -r %t2.bc,_Z3Getv,l
> +; RUN: llvm-dis %t.1.3.import.bc -o - | FileCheck %s
> +
> +; Only llvm-lto2 adds the dso_local keyword, hence the {{.*}}
> +; CHECK: define available_externally{{.*}} void @_ZN4CFVSD1Ev
> +
> +; Confirm that we only have a single DICompositeType after importing
> +; both an alias and its aliasee, since ODR Type Uniquing is enabled.
> +; CHECK: DICompositeType
> +; CHECK-NOT: DICompositeType
> +
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-scei-ps4"
> +
> +%class.C = type <{ i32 (...)**, %class.A, %struct.CFVS, [6 x i8] }>
> +%class.A = type { %struct.Vec }
> +%struct.Vec = type { i8 }
> +%struct.CFVS = type { %struct.Vec }
> +%struct.S = type { i8 }
> +
> +define void @_ZN1CD2Ev(%class.C* %this) unnamed_addr align 2 {
> +entry:
> +  %this.addr = alloca %class.C*, align 8
> +  %this1 = load %class.C*, %class.C** %this.addr, align 8
> +  %m = getelementptr inbounds %class.C, %class.C* %this1, i32 0, i32 2
> +  call void @_ZN4CFVSD1Ev(%struct.CFVS* %m), !dbg !50
> +  call void @_ZN4CFVSD2Ev(%struct.CFVS* %m), !dbg !50
> +  ret void
> +}
> +
> +declare void @_ZN4CFVSD1Ev(%struct.CFVS*) unnamed_addr
> +declare void @_ZN4CFVSD2Ev(%struct.CFVS*) unnamed_addr
> +
> +declare dereferenceable(1) %struct.S* @_Z3Getv()
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!3, !4, !5, !6}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
> producer: "clang version 6.0.0 (trunk 321360) (llvm/trunk 321359)",
> isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
> +!1 = !DIFile(filename: "bz188598-a.cpp", directory: ".")
> +!2 = !{}
> +!3 = !{i32 2, !"Dwarf Version", i32 4}
> +!4 = !{i32 2, !"Debug Info Version", i32 3}
> +!5 = !{i32 1, !"wchar_size", i32 2}
> +!6 = !{i32 7, !"PIC Level", i32 2}
> +!8 = distinct !DISubprogram(name: "~C", linkageName: "_ZN1CD2Ev", scope:
> !1, file: !1, line: 9, type: !47, isLocal: false, isDefinition: true,
> scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0,
> variables: !2)
> +!47 = !DISubroutineType(types: !48)
> +!48 = !{!55}
> +!50 = !DILocation(line: 9, scope: !51)
> +!51 = distinct !DILexicalBlock(scope: !8, file: !1, line: 9)
> +!55 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180131/39336d15/attachment.html>


More information about the llvm-commits mailing list