llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Orlando Cazalet-Hyams (OCHyams) <details> <summary>Changes</summary> [KeyInstr][Clang] Agg init atom This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. The Key Instructions project is introduced, including a "quick summary" section at the top which adds context for this PR, here: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed. The Clang-side work is demoed here: https://github.com/llvm/llvm-project/pull/130943 shouldUseBZeroPlusStoresToInitialize [KeyInstr] init-agg pattern [KeyInstr][Clang] Init pattern atom --- Full diff: https://github.com/llvm/llvm-project/pull/134635.diff 2 Files Affected: - (modified) clang/lib/CodeGen/CGDecl.cpp (+7) - (added) clang/test/KeyInstructions/init-agg.cpp (+39) ``````````diff diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 6aa9f3fa27c87..9860ab0b033bb 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -938,6 +938,7 @@ void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init, isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) || isa<llvm::ConstantExpr>(Init)) { auto *I = Builder.CreateStore(Init, Loc, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); if (IsAutoInit) I->addAnnotationMetadata("auto-init"); return; @@ -1181,6 +1182,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy(); if (canDoSingleStore) { auto *I = Builder.CreateStore(constant, Loc, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); if (IsAutoInit) I->addAnnotationMetadata("auto-init"); return; @@ -1193,6 +1195,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) { auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); + if (IsAutoInit) I->addAnnotationMetadata("auto-init"); @@ -1217,6 +1221,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, } auto *I = Builder.CreateMemSet( Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); if (IsAutoInit) I->addAnnotationMetadata("auto-init"); return; @@ -1263,6 +1268,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, createUnnamedGlobalForMemcpyFrom( CGM, D, Builder, constant, Loc.getAlignment()), SizeVal, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); + if (IsAutoInit) I->addAnnotationMetadata("auto-init"); } diff --git a/clang/test/KeyInstructions/init-agg.cpp b/clang/test/KeyInstructions/init-agg.cpp new file mode 100644 index 0000000000000..f0cc67e659d95 --- /dev/null +++ b/clang/test/KeyInstructions/init-agg.cpp @@ -0,0 +1,39 @@ + +// RUN: %clang -gkey-instructions %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=pattern \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// The implicit-check-not is important; we don't want the GEPs created for the +// store locations to be included in the atom group. + +int g; +void a() { +// CHECK: _Z1av() +// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]] + int A[] = { 1, 2, 3 }; + +// CHECK: store i32 1, ptr %{{.*}}, !dbg [[G2R1:!.*]] +// CHECK: store i32 2, ptr %{{.*}}, !dbg [[G2R1]] +// CHECK: %0 = load i32, ptr @g{{.*}}, !dbg [[G2R2:!.*]] +// CHECK: store i32 %0, ptr %{{.*}}, !dbg [[G2R1]] + int B[] = { 1, 2, g }; + +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G3R1:!.*]] +// CHECK: store i8 97{{.*}}, !dbg [[G3R1]] +// CHECK: store i8 98{{.*}}, !dbg [[G3R1]] +// CHECK: store i8 99{{.*}}, !dbg [[G3R1]] +// CHECK: store i8 100{{.*}}, !dbg [[G3R1]] + char big[65536] = { 'a', 'b', 'c', 'd' }; + +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G4R1:!.*]] + char arr[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, }; + +// CHECK: store i8 -86, ptr %uninit{{.*}}, !dbg [[G5R1:!.*]], !annotation + char uninit; // -ftrivial-auto-var-init=pattern +} + +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) +// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) +// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) `````````` </details> https://github.com/llvm/llvm-project/pull/134635 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits