Skip to content

Commit bf3a37d

Browse files
committed
[KeyInstr][Clang] Store-like builtin atoms
1 parent 123bf5f commit bf3a37d

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
@@ -4352,7 +4352,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43524352
Value *SizeVal = EmitScalarExpr(E->getArg(1));
43534353
EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
43544354
E->getArg(0)->getExprLoc(), FD, 0);
4355-
Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
4355+
auto *I = Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
4356+
addInstToNewSourceAtom(I, nullptr);
43564357
return RValue::get(nullptr);
43574358
}
43584359

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

@@ -4380,7 +4382,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43804382
Value *SizeVal = EmitScalarExpr(E->getArg(2));
43814383
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
43824384
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4383-
Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4385+
auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4386+
addInstToNewSourceAtom(I, nullptr);
43844387
if (BuiltinID == Builtin::BImempcpy ||
43854388
BuiltinID == Builtin::BI__builtin_mempcpy)
43864389
return RValue::get(Builder.CreateInBoundsGEP(
@@ -4396,7 +4399,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43964399
E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
43974400
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
43984401
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4399-
Builder.CreateMemCpyInline(Dest, Src, Size);
4402+
auto *I = Builder.CreateMemCpyInline(Dest, Src, Size);
4403+
addInstToNewSourceAtom(I, nullptr);
44004404
return RValue::get(nullptr);
44014405
}
44024406

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

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

@@ -4455,7 +4461,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44554461
Value *SizeVal = EmitScalarExpr(E->getArg(2));
44564462
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
44574463
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4458-
Builder.CreateMemMove(Dest, Src, SizeVal, false);
4464+
auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
4465+
addInstToNewSourceAtom(I, nullptr);
44594466
return RValue::get(Dest, *this);
44604467
}
44614468
case Builtin::BImemset:
@@ -4466,7 +4473,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44664473
Value *SizeVal = EmitScalarExpr(E->getArg(2));
44674474
EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
44684475
E->getArg(0)->getExprLoc(), FD, 0);
4469-
Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4476+
auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4477+
addInstToNewSourceAtom(I, nullptr);
44704478
return RValue::get(Dest, *this);
44714479
}
44724480
case Builtin::BI__builtin_memset_inline: {
@@ -4478,7 +4486,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44784486
EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)),
44794487
E->getArg(0)->getType(), E->getArg(0)->getExprLoc(), FD,
44804488
0);
4481-
Builder.CreateMemSetInline(Dest, ByteVal, Size);
4489+
auto *I = Builder.CreateMemSetInline(Dest, ByteVal, Size);
4490+
addInstToNewSourceAtom(I, nullptr);
44824491
return RValue::get(nullptr);
44834492
}
44844493
case Builtin::BI__builtin___memset_chk: {
@@ -4495,7 +4504,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
44954504
Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
44964505
Builder.getInt8Ty());
44974506
Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
4498-
Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4507+
auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4508+
addInstToNewSourceAtom(I, nullptr);
44994509
return RValue::get(Dest, *this);
45004510
}
45014511
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)