Skip to content

Commit f3ee614

Browse files
committed
[KeyInstr][Clang] Store-like builtin atoms
1 parent 1fec430 commit f3ee614

File tree

2 files changed

+97
-10
lines changed

2 files changed

+97
-10
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,7 +4351,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43514351
Value *SizeVal = EmitScalarExpr(E->getArg(1));
43524352
EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
43534353
E->getArg(0)->getExprLoc(), FD, 0);
4354-
Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
4354+
auto *I = Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
4355+
addInstToNewSourceAtom(I, nullptr);
43554356
return RValue::get(nullptr);
43564357
}
43574358

@@ -4366,7 +4367,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43664367
EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)),
43674368
E->getArg(1)->getType(), E->getArg(1)->getExprLoc(), FD,
43684369
0);
4369-
Builder.CreateMemMove(Dest, Src, SizeVal, false);
4370+
auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
4371+
addInstToNewSourceAtom(I, nullptr);
43704372
return RValue::get(nullptr);
43714373
}
43724374

@@ -4379,7 +4381,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43794381
Value *SizeVal = EmitScalarExpr(E->getArg(2));
43804382
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
43814383
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4382-
Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4384+
auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4385+
addInstToNewSourceAtom(I, nullptr);
43834386
if (BuiltinID == Builtin::BImempcpy ||
43844387
BuiltinID == Builtin::BI__builtin_mempcpy)
43854388
return RValue::get(Builder.CreateInBoundsGEP(
@@ -4395,7 +4398,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43954398
E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
43964399
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
43974400
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4398-
Builder.CreateMemCpyInline(Dest, Src, Size);
4401+
auto *I = Builder.CreateMemCpyInline(Dest, Src, Size);
4402+
addInstToNewSourceAtom(I, nullptr);
43994403
return RValue::get(nullptr);
44004404
}
44014405

@@ -4416,7 +4420,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44164420
Address Dest = EmitPointerWithAlignment(E->getArg(0));
44174421
Address Src = EmitPointerWithAlignment(E->getArg(1));
44184422
Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
4419-
Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4423+
auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4424+
addInstToNewSourceAtom(I, nullptr);
44204425
return RValue::get(Dest, *this);
44214426
}
44224427

@@ -4442,7 +4447,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44424447
Address Dest = EmitPointerWithAlignment(E->getArg(0));
44434448
Address Src = EmitPointerWithAlignment(E->getArg(1));
44444449
Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
4445-
Builder.CreateMemMove(Dest, Src, SizeVal, false);
4450+
auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
4451+
addInstToNewSourceAtom(I, nullptr);
44464452
return RValue::get(Dest, *this);
44474453
}
44484454

@@ -4454,7 +4460,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44544460
Value *SizeVal = EmitScalarExpr(E->getArg(2));
44554461
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
44564462
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4457-
Builder.CreateMemMove(Dest, Src, SizeVal, false);
4463+
auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
4464+
addInstToNewSourceAtom(I, nullptr);
44584465
return RValue::get(Dest, *this);
44594466
}
44604467
case Builtin::BImemset:
@@ -4465,7 +4472,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44654472
Value *SizeVal = EmitScalarExpr(E->getArg(2));
44664473
EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
44674474
E->getArg(0)->getExprLoc(), FD, 0);
4468-
Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4475+
auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4476+
addInstToNewSourceAtom(I, nullptr);
44694477
return RValue::get(Dest, *this);
44704478
}
44714479
case Builtin::BI__builtin_memset_inline: {
@@ -4477,7 +4485,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44774485
EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)),
44784486
E->getArg(0)->getType(), E->getArg(0)->getExprLoc(), FD,
44794487
0);
4480-
Builder.CreateMemSetInline(Dest, ByteVal, Size);
4488+
auto *I = Builder.CreateMemSetInline(Dest, ByteVal, Size);
4489+
addInstToNewSourceAtom(I, nullptr);
44814490
return RValue::get(nullptr);
44824491
}
44834492
case Builtin::BI__builtin___memset_chk: {
@@ -4494,7 +4503,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44944503
Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
44954504
Builder.getInt8Ty());
44964505
Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
4497-
Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4506+
auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4507+
addInstToNewSourceAtom(I, nullptr);
44984508
return RValue::get(Dest, *this);
44994509
}
45004510
case Builtin::BI__builtin_wmemchr: {

clang/test/KeyInstructions/builtin.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
// 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 \
3+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
4+
5+
// 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 \
6+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
7+
8+
typedef float m2x2 __attribute__((matrix_type(2, 2)));
9+
m2x2 mat;
10+
float f4[4];
11+
float f8[8];
12+
13+
void fun() {
14+
// CHECK: %a = alloca ptr, align 8
15+
// CHECK: %0 = alloca i8, i64 4{{.*}}, !dbg [[G1R2:!.*]]
16+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G1R1:!.*]], !annotation
17+
// CHECK: store ptr %0, ptr %a{{.*}}, !dbg [[G1R1:!.*]]
18+
void *a = __builtin_alloca(4);
19+
20+
// CHECK: %1 = alloca i8, i64 4{{.*}}, !dbg [[G2R2:!.*]]
21+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G2R1:!.*]], !annotation
22+
// CHECK: store ptr %1, ptr %b{{.*}}, !dbg [[G2R1:!.*]]
23+
void *b = __builtin_alloca_with_align(4, 8);
24+
25+
// CHECK: call void @llvm.matrix.column.major.store.v4f32{{.*}}, !dbg [[G3R1:!.*]]
26+
__builtin_matrix_column_major_store(mat, f4, sizeof(float) * 2);
27+
28+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G4R1:!.*]]
29+
__builtin_bzero(f4, sizeof(float) * 2);
30+
31+
// CHECK: call void @llvm.memmove{{.*}}, !dbg [[G5R1:!.*]]
32+
__builtin_bcopy(f4, f8, sizeof(float) * 4);
33+
34+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G6R1:!.*]]
35+
__builtin_memcpy(f4, f8, sizeof(float) * 4);
36+
37+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G7R1:!.*]]
38+
__builtin_mempcpy(f4, f8, sizeof(float) * 4);
39+
40+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G8R1:!.*]]
41+
__builtin_memcpy_inline(f4, f8, sizeof(float) * 4);
42+
43+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G9R1:!.*]]
44+
__builtin___memcpy_chk(f4, f8, sizeof(float) * 4, -1);
45+
46+
// CHECK: call void @llvm.memmove{{.*}}, !dbg [[G10R1:!.*]]
47+
__builtin___memmove_chk(f4, f8, sizeof(float) * 4, -1);
48+
49+
// CHECK: call void @llvm.memmove{{.*}}, !dbg [[G11R1:!.*]]
50+
__builtin_memmove(f4, f8, sizeof(float) * 4);
51+
52+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G12R1:!.*]]
53+
__builtin_memset(f4, 0, sizeof(float) * 4);
54+
55+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G13R1:!.*]]
56+
__builtin_memset_inline(f4, 0, sizeof(float) * 4);
57+
58+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G14R1:!.*]]
59+
__builtin___memset_chk(f4, 0, sizeof(float), -1);
60+
}
61+
62+
// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
63+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
64+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
65+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
66+
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
67+
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
68+
// CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)
69+
// CHECK: [[G6R1]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 1)
70+
// CHECK: [[G7R1]] = !DILocation({{.*}}, atomGroup: 7, atomRank: 1)
71+
// CHECK: [[G8R1]] = !DILocation({{.*}}, atomGroup: 8, atomRank: 1)
72+
// CHECK: [[G9R1]] = !DILocation({{.*}}, atomGroup: 9, atomRank: 1)
73+
// CHECK: [[G10R1]] = !DILocation({{.*}}, atomGroup: 10, atomRank: 1)
74+
// CHECK: [[G11R1]] = !DILocation({{.*}}, atomGroup: 11, atomRank: 1)
75+
// CHECK: [[G12R1]] = !DILocation({{.*}}, atomGroup: 12, atomRank: 1)
76+
// CHECK: [[G13R1]] = !DILocation({{.*}}, atomGroup: 13, atomRank: 1)
77+
// CHECK: [[G14R1]] = !DILocation({{.*}}, atomGroup: 14, atomRank: 1)

0 commit comments

Comments
 (0)