[PATCH] D147021: [Builtins] Add __builtin_implicit_object_fence.
David Goldblatt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 28 10:32:38 PDT 2023
davidtgoldblatt created this revision.
Herald added subscribers: jeroen.dobbelaere, kosarev.
Herald added a project: All.
davidtgoldblatt updated this revision to Diff 509069.
davidtgoldblatt added a comment.
davidtgoldblatt added a reviewer: rsmith.
davidtgoldblatt published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Update
davidtgoldblatt added a comment.
Adding @zygoloid as a p2590 author for review
This is a builtin that allows the easy implementation of C++23's
start_lifetime_as. It takes a pointer, and returns a pointer allowing
implicit object creation at the given region of storage that will keep
the same object representation.
For now this just means forwarding llvm.tbaa.fence, which I believe is the only
place that C++-level type information makes it into LLVM IR in a
semantics-affecting way.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147021
Files:
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtin-implicit-object-fence.c
Index: clang/test/CodeGen/builtin-implicit-object-fence.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/builtin-implicit-object-fence.c
@@ -0,0 +1,19 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: @test1(
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT: [[B:%.*]] = alloca ptr, align 8
+// CHECK-NEXT: store ptr [[A:%.*]], ptr [[A_ADDR]], align 8
+// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8
+// CHECK-NEXT: [[TMP1:%.*]] = call ptr @llvm.tbaa.fence(ptr [[TMP0]])
+// CHECK-NEXT: store ptr [[TMP1]], ptr [[B]], align 8
+// CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[B]], align 8
+// CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[TMP2]], align 4
+// CHECK-NEXT: ret float [[TMP3]]
+//
+float test1(int *a) {
+ float *b = __builtin_implicit_object_fence(a);
+ return *b;
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -2472,7 +2472,7 @@
return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(*this, E,
Intrinsic::roundeven,
Intrinsic::experimental_constrained_roundeven));
-
+
case Builtin::BIsin:
case Builtin::BIsinf:
case Builtin::BIsinl:
@@ -3904,6 +3904,14 @@
return RValue::get(Ptr);
}
+ case Builtin::BI__builtin_implicit_object_fence: {
+ const Expr *Arg = E->getArg(0);
+ Value *Ptr = EmitScalarExpr(Arg);
+ Function *F =
+ Intrinsic::getDeclaration(&CGM.getModule(), Intrinsic::tbaa_fence);
+ Value *Result = Builder.CreateCall(F, {Ptr});
+ return RValue::get(Result);
+ }
case Builtin::BI__sync_fetch_and_add:
case Builtin::BI__sync_fetch_and_sub:
case Builtin::BI__sync_fetch_and_or:
Index: clang/include/clang/Basic/Builtins.def
===================================================================
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -662,6 +662,7 @@
BUILTIN(__builtin_alloca_with_align_uninitialized, "v*zIz", "Fn")
BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
BUILTIN(__builtin_nondeterministic_value, "v.", "nt")
+BUILTIN(__builtin_implicit_object_fence, "v*v*", "n")
BUILTIN(__builtin_elementwise_abs, "v.", "nct")
BUILTIN(__builtin_elementwise_max, "v.", "nct")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147021.509069.patch
Type: text/x-patch
Size: 2644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230328/d3516ead/attachment.bin>
More information about the cfe-commits
mailing list