Skip to content

Commit 5408901

Browse files
committed
[KeyInstr][Clang] Store-like builtin atoms
1 parent 6741ef3 commit 5408901

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,7 +4100,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41004100
Value *SizeVal = EmitScalarExpr(E->getArg(1));
41014101
EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
41024102
E->getArg(0)->getExprLoc(), FD, 0);
4103-
Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
4103+
auto *I = Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
4104+
addInstToNewSourceAtom(I, nullptr);
41044105
return RValue::get(nullptr);
41054106
}
41064107

@@ -4115,7 +4116,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41154116
EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)),
41164117
E->getArg(1)->getType(), E->getArg(1)->getExprLoc(), FD,
41174118
0);
4118-
Builder.CreateMemMove(Dest, Src, SizeVal, false);
4119+
auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
4120+
addInstToNewSourceAtom(I, nullptr);
41194121
return RValue::get(nullptr);
41204122
}
41214123

@@ -4128,7 +4130,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41284130
Value *SizeVal = EmitScalarExpr(E->getArg(2));
41294131
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
41304132
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4131-
Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4133+
auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4134+
addInstToNewSourceAtom(I, nullptr);
41324135
if (BuiltinID == Builtin::BImempcpy ||
41334136
BuiltinID == Builtin::BI__builtin_mempcpy)
41344137
return RValue::get(Builder.CreateInBoundsGEP(
@@ -4144,7 +4147,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41444147
E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
41454148
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
41464149
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4147-
Builder.CreateMemCpyInline(Dest, Src, Size);
4150+
auto *I = Builder.CreateMemCpyInline(Dest, Src, Size);
4151+
addInstToNewSourceAtom(I, nullptr);
41484152
return RValue::get(nullptr);
41494153
}
41504154

@@ -4165,7 +4169,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41654169
Address Dest = EmitPointerWithAlignment(E->getArg(0));
41664170
Address Src = EmitPointerWithAlignment(E->getArg(1));
41674171
Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
4168-
Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4172+
auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
4173+
addInstToNewSourceAtom(I, nullptr);
41694174
return RValue::get(Dest, *this);
41704175
}
41714176

@@ -4191,7 +4196,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41914196
Address Dest = EmitPointerWithAlignment(E->getArg(0));
41924197
Address Src = EmitPointerWithAlignment(E->getArg(1));
41934198
Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
4194-
Builder.CreateMemMove(Dest, Src, SizeVal, false);
4199+
auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
4200+
addInstToNewSourceAtom(I, nullptr);
41954201
return RValue::get(Dest, *this);
41964202
}
41974203

@@ -4202,7 +4208,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
42024208
Value *SizeVal = EmitScalarExpr(E->getArg(2));
42034209
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
42044210
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
4205-
Builder.CreateMemMove(Dest, Src, SizeVal, false);
4211+
auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
4212+
addInstToNewSourceAtom(I, nullptr);
42064213
return RValue::get(Dest, *this);
42074214
}
42084215
case Builtin::BImemset:
@@ -4213,7 +4220,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
42134220
Value *SizeVal = EmitScalarExpr(E->getArg(2));
42144221
EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
42154222
E->getArg(0)->getExprLoc(), FD, 0);
4216-
Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4223+
auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4224+
addInstToNewSourceAtom(I, nullptr);
42174225
return RValue::get(Dest, *this);
42184226
}
42194227
case Builtin::BI__builtin_memset_inline: {
@@ -4225,7 +4233,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
42254233
EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)),
42264234
E->getArg(0)->getType(), E->getArg(0)->getExprLoc(), FD,
42274235
0);
4228-
Builder.CreateMemSetInline(Dest, ByteVal, Size);
4236+
auto *I = Builder.CreateMemSetInline(Dest, ByteVal, Size);
4237+
addInstToNewSourceAtom(I, nullptr);
42294238
return RValue::get(nullptr);
42304239
}
42314240
case Builtin::BI__builtin___memset_chk: {
@@ -4242,7 +4251,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
42424251
Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
42434252
Builder.getInt8Ty());
42444253
Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
4245-
Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4254+
auto *I = Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
4255+
addInstToNewSourceAtom(I, nullptr);
42464256
return RValue::get(Dest, *this);
42474257
}
42484258
case Builtin::BI__builtin_wmemchr: {

clang/test/KeyInstructions/builtin.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
typedef float m2x2 __attribute__((matrix_type(2, 2)));
99
m2x2 mat;
1010
float f4[4];
11+
float f8[8];
1112

1213
void fun() {
1314
// CHECK: %a = alloca ptr, align 8
@@ -23,10 +24,54 @@ void fun() {
2324

2425
// CHECK: call void @llvm.matrix.column.major.store.v4f32{{.*}}, !dbg [[G3R1:!.*]]
2526
__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);
2660
}
2761

2862
// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
2963
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
3064
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
3165
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
3266
// 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)