https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/134651
>From bf3a37df3a82797227e476485f6cf4c0c9a7c912 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Fri, 4 Apr 2025 14:36:43 +0100 Subject: [PATCH 1/5] [KeyInstr][Clang] Store-like builtin atoms --- clang/lib/CodeGen/CGBuiltin.cpp | 30 +++++++---- clang/test/KeyInstructions/builtin.c | 77 ++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 clang/test/KeyInstructions/builtin.c diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 809ffe549be88..fd46b6c40ccd9 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4352,7 +4352,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *SizeVal = EmitScalarExpr(E->getArg(1)); EmitNonNullArgCheck(Dest, E->getArg(0)->getType(), E->getArg(0)->getExprLoc(), FD, 0); - Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false); + auto *I = Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false); + addInstToNewSourceAtom(I, nullptr); return RValue::get(nullptr); } @@ -4367,7 +4368,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)), E->getArg(1)->getType(), E->getArg(1)->getExprLoc(), FD, 0); - Builder.CreateMemMove(Dest, Src, SizeVal, false); + auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false); + addInstToNewSourceAtom(I, nullptr); return RValue::get(nullptr); } @@ -4380,7 +4382,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *SizeVal = EmitScalarExpr(E->getArg(2)); EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0); EmitArgCheck(TCK_Load, Src, E->getArg(1), 1); - Builder.CreateMemCpy(Dest, Src, SizeVal, false); + auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false); + addInstToNewSourceAtom(I, nullptr); if (BuiltinID == Builtin::BImempcpy || BuiltinID == Builtin::BI__builtin_mempcpy) return RValue::get(Builder.CreateInBoundsGEP( @@ -4396,7 +4399,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue(); EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0); EmitArgCheck(TCK_Load, Src, E->getArg(1), 1); - Builder.CreateMemCpyInline(Dest, Src, Size); + auto *I = Builder.CreateMemCpyInline(Dest, Src, Size); + addInstToNewSourceAtom(I, nullptr); return RValue::get(nullptr); } @@ -4417,7 +4421,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Address Dest = EmitPointerWithAlignment(E->getArg(0)); Address Src = EmitPointerWithAlignment(E->getArg(1)); Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); - Builder.CreateMemCpy(Dest, Src, SizeVal, false); + auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false); + addInstToNewSourceAtom(I, nullptr); return RValue::get(Dest, *this); } @@ -4443,7 +4448,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Address Dest = EmitPointerWithAlignment(E->getArg(0)); Address Src = EmitPointerWithAlignment(E->getArg(1)); Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); - Builder.CreateMemMove(Dest, Src, SizeVal, false); + auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false); + addInstToNewSourceAtom(I, nullptr); return RValue::get(Dest, *this); } @@ -4455,7 +4461,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *SizeVal = EmitScalarExpr(E->getArg(2)); EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0); EmitArgCheck(TCK_Load, Src, E->getArg(1), 1); - Builder.CreateMemMove(Dest, Src, SizeVal, false); + auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false); + addInstToNewSourceAtom(I, nullptr); return RValue::get(Dest, *this); } case Builtin::BImemset: @@ -4466,7 +4473,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *SizeVal = EmitScalarExpr(E->getArg(2)); EmitNonNullArgCheck(Dest, E->getArg(0)->getType(), E->getArg(0)->getExprLoc(), FD, 0); - Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); + auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); + addInstToNewSourceAtom(I, nullptr); return RValue::get(Dest, *this); } case Builtin::BI__builtin_memset_inline: { @@ -4478,7 +4486,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)), E->getArg(0)->getType(), E->getArg(0)->getExprLoc(), FD, 0); - Builder.CreateMemSetInline(Dest, ByteVal, Size); + auto *I = Builder.CreateMemSetInline(Dest, ByteVal, Size); + addInstToNewSourceAtom(I, nullptr); return RValue::get(nullptr); } case Builtin::BI__builtin___memset_chk: { @@ -4495,7 +4504,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), Builder.getInt8Ty()); Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); - Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); + auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); + addInstToNewSourceAtom(I, nullptr); return RValue::get(Dest, *this); } case Builtin::BI__builtin_wmemchr: { diff --git a/clang/test/KeyInstructions/builtin.c b/clang/test/KeyInstructions/builtin.c new file mode 100644 index 0000000000000..5129a4ac2c482 --- /dev/null +++ b/clang/test/KeyInstructions/builtin.c @@ -0,0 +1,77 @@ + +// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=zero -fenable-matrix -Xclang -disable-llvm-passes \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// RUN: %clang -gkey-instructions -x c %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=zero -fenable-matrix -Xclang -disable-llvm-passes \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +typedef float m2x2 __attribute__((matrix_type(2, 2))); +m2x2 mat; +float f4[4]; +float f8[8]; + +void fun() { +// CHECK: %a = alloca ptr, align 8 +// CHECK: %0 = alloca i8, i64 4{{.*}}, !dbg [[G1R2:!.*]] +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G1R1:!.*]], !annotation +// CHECK: store ptr %0, ptr %a{{.*}}, !dbg [[G1R1:!.*]] + void *a = __builtin_alloca(4); + +// CHECK: %1 = alloca i8, i64 4{{.*}}, !dbg [[G2R2:!.*]] +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G2R1:!.*]], !annotation +// CHECK: store ptr %1, ptr %b{{.*}}, !dbg [[G2R1:!.*]] + void *b = __builtin_alloca_with_align(4, 8); + +// CHECK: call void @llvm.matrix.column.major.store.v4f32{{.*}}, !dbg [[G3R1:!.*]] + __builtin_matrix_column_major_store(mat, f4, sizeof(float) * 2); + +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G4R1:!.*]] + __builtin_bzero(f4, sizeof(float) * 2); + +// CHECK: call void @llvm.memmove{{.*}}, !dbg [[G5R1:!.*]] + __builtin_bcopy(f4, f8, sizeof(float) * 4); + +// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G6R1:!.*]] + __builtin_memcpy(f4, f8, sizeof(float) * 4); + +// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G7R1:!.*]] + __builtin_mempcpy(f4, f8, sizeof(float) * 4); + +// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G8R1:!.*]] + __builtin_memcpy_inline(f4, f8, sizeof(float) * 4); + +// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G9R1:!.*]] + __builtin___memcpy_chk(f4, f8, sizeof(float) * 4, -1); + +// CHECK: call void @llvm.memmove{{.*}}, !dbg [[G10R1:!.*]] + __builtin___memmove_chk(f4, f8, sizeof(float) * 4, -1); + +// CHECK: call void @llvm.memmove{{.*}}, !dbg [[G11R1:!.*]] + __builtin_memmove(f4, f8, sizeof(float) * 4); + +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G12R1:!.*]] + __builtin_memset(f4, 0, sizeof(float) * 4); + +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G13R1:!.*]] + __builtin_memset_inline(f4, 0, sizeof(float) * 4); + +// CHECK: call void @llvm.memset{{.*}}, !dbg [[G14R1:!.*]] + __builtin___memset_chk(f4, 0, sizeof(float), -1); +} + +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) +// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) +// CHECK: [[G6R1]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 1) +// CHECK: [[G7R1]] = !DILocation({{.*}}, atomGroup: 7, atomRank: 1) +// CHECK: [[G8R1]] = !DILocation({{.*}}, atomGroup: 8, atomRank: 1) +// CHECK: [[G9R1]] = !DILocation({{.*}}, atomGroup: 9, atomRank: 1) +// CHECK: [[G10R1]] = !DILocation({{.*}}, atomGroup: 10, atomRank: 1) +// CHECK: [[G11R1]] = !DILocation({{.*}}, atomGroup: 11, atomRank: 1) +// CHECK: [[G12R1]] = !DILocation({{.*}}, atomGroup: 12, atomRank: 1) +// CHECK: [[G13R1]] = !DILocation({{.*}}, atomGroup: 13, atomRank: 1) +// CHECK: [[G14R1]] = !DILocation({{.*}}, atomGroup: 14, atomRank: 1) >From 56a6cf66bfa0f663d291e1c42f18b3415d8028a5 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 21 May 2025 16:04:43 +0100 Subject: [PATCH 2/5] cc1 --- clang/test/KeyInstructions/builtin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/KeyInstructions/builtin.c b/clang/test/KeyInstructions/builtin.c index 5129a4ac2c482..67a8017eeb236 100644 --- a/clang/test/KeyInstructions/builtin.c +++ b/clang/test/KeyInstructions/builtin.c @@ -1,8 +1,8 @@ -// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=zero -fenable-matrix -Xclang -disable-llvm-passes \ +// RUN: %clang_cc1 -gkey-instructions -x c++ %s -debug-info-kind=line-tables-only -gno-column-info -emit-llvm -o - -ftrivial-auto-var-init=zero -fenable-matrix -disable-llvm-passes \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang -gkey-instructions -x c %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=zero -fenable-matrix -Xclang -disable-llvm-passes \ +// RUN: %clang_cc1 -gkey-instructions -x c %s -debug-info-kind=line-tables-only -gno-column-info -emit-llvm -o - -ftrivial-auto-var-init=zero -fenable-matrix -disable-llvm-passes \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef float m2x2 __attribute__((matrix_type(2, 2))); >From 9f8f2effb0a4b7eab26e02651dd9f8d707ed1922 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 28 May 2025 11:10:55 +0100 Subject: [PATCH 3/5] move test --- clang/test/{ => DebugInfo}/KeyInstructions/builtin.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename clang/test/{ => DebugInfo}/KeyInstructions/builtin.c (100%) diff --git a/clang/test/KeyInstructions/builtin.c b/clang/test/DebugInfo/KeyInstructions/builtin.c similarity index 100% rename from clang/test/KeyInstructions/builtin.c rename to clang/test/DebugInfo/KeyInstructions/builtin.c >From ed66898111b959363476ff9407d0348ab600f577 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 28 May 2025 11:19:54 +0100 Subject: [PATCH 4/5] add missing addInstToNewSourceAtom call (... lost in rebase?) --- clang/lib/CodeGen/CGBuiltin.cpp | 2 ++ clang/test/DebugInfo/KeyInstructions/builtin.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index fd46b6c40ccd9..8ffa9c93cd03c 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -31,6 +31,7 @@ #include "clang/Basic/TargetOptions.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/IR/InlineAsm.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/IntrinsicsX86.h" #include "llvm/IR/MatrixBuilder.h" @@ -4192,6 +4193,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Matrix, Dst.emitRawPointer(*this), Align(Dst.getAlignment().getQuantity()), Stride, IsVolatile, MatrixTy->getNumRows(), MatrixTy->getNumColumns()); + addInstToNewSourceAtom(cast<Instruction>(Result), Matrix); return RValue::get(Result); } diff --git a/clang/test/DebugInfo/KeyInstructions/builtin.c b/clang/test/DebugInfo/KeyInstructions/builtin.c index 67a8017eeb236..f7d4b6f3b2561 100644 --- a/clang/test/DebugInfo/KeyInstructions/builtin.c +++ b/clang/test/DebugInfo/KeyInstructions/builtin.c @@ -22,6 +22,7 @@ void fun() { // CHECK: store ptr %1, ptr %b{{.*}}, !dbg [[G2R1:!.*]] void *b = __builtin_alloca_with_align(4, 8); +// CHECK: %2 = load <4 x float>, ptr @mat{{.*}}, !dbg [[G3R2:!.*]] // CHECK: call void @llvm.matrix.column.major.store.v4f32{{.*}}, !dbg [[G3R1:!.*]] __builtin_matrix_column_major_store(mat, f4, sizeof(float) * 2); @@ -63,6 +64,7 @@ void fun() { // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) >From bfb1a80b3bda0f5dcae8d16d6ad9cd4f0135020d Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 28 May 2025 11:24:04 +0100 Subject: [PATCH 5/5] memset val as backup --- clang/lib/CodeGen/CGBuiltin.cpp | 2 +- clang/test/DebugInfo/KeyInstructions/builtin.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 8ffa9c93cd03c..98b5984d0f9bc 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4476,7 +4476,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, EmitNonNullArgCheck(Dest, E->getArg(0)->getType(), E->getArg(0)->getExprLoc(), FD, 0); auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); - addInstToNewSourceAtom(I, nullptr); + addInstToNewSourceAtom(I, ByteVal); return RValue::get(Dest, *this); } case Builtin::BI__builtin_memset_inline: { diff --git a/clang/test/DebugInfo/KeyInstructions/builtin.c b/clang/test/DebugInfo/KeyInstructions/builtin.c index f7d4b6f3b2561..4c4c9883173f1 100644 --- a/clang/test/DebugInfo/KeyInstructions/builtin.c +++ b/clang/test/DebugInfo/KeyInstructions/builtin.c @@ -9,6 +9,7 @@ typedef float m2x2 __attribute__((matrix_type(2, 2))); m2x2 mat; float f4[4]; float f8[8]; +int v = 3; void fun() { // CHECK: %a = alloca ptr, align 8 @@ -58,6 +59,11 @@ void fun() { // CHECK: call void @llvm.memset{{.*}}, !dbg [[G14R1:!.*]] __builtin___memset_chk(f4, 0, sizeof(float), -1); + +// CHECK: %3 = load i32, ptr @v{{.*}}, !dbg [[G15R3:!.*]] +// CHECK-NEXT: %4 = trunc i32 %3 to i8, !dbg [[G15R2:!.*]] +// CHECK-NEXT: call void @llvm.memset{{.*}}, !dbg [[G15R1:!.*]] + __builtin_memset(f4, v, sizeof(float) * 4); } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) @@ -77,3 +83,6 @@ void fun() { // CHECK: [[G12R1]] = !DILocation({{.*}}, atomGroup: 12, atomRank: 1) // CHECK: [[G13R1]] = !DILocation({{.*}}, atomGroup: 13, atomRank: 1) // CHECK: [[G14R1]] = !DILocation({{.*}}, atomGroup: 14, atomRank: 1) +// CHECK: [[G15R3]] = !DILocation({{.*}}, atomGroup: 15, atomRank: 3) +// CHECK: [[G15R2]] = !DILocation({{.*}}, atomGroup: 15, atomRank: 2) +// CHECK: [[G15R1]] = !DILocation({{.*}}, atomGroup: 15, atomRank: 1) \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits