[PATCH] D109248: Annotate `llvm.eh.sjlj.setjmp` as `returns_twice`
Tee KOBAYASHI via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 3 10:40:16 PDT 2021
xtkoba created this revision.
xtkoba requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
In LLVM, some optimizations are disabled for functions that return twice. For instance, register coalescing in those functions is disabled by D77767 <https://reviews.llvm.org/D77767>. Currently, this does not apply to `__builtin_setjmp`, because the intrinsic function `llvm.eh.sjlj.setjmp` is not annotated as `returns_twice`.
In the proposed change, we annotate `llvm.eh.sjlj.setjmp` as `returns_twice`. This fixes PR50234.
https://reviews.llvm.org/D109248
Files:
llvm/include/llvm/IR/Intrinsics.td
llvm/utils/TableGen/CodeGenIntrinsics.h
llvm/utils/TableGen/CodeGenTarget.cpp
llvm/utils/TableGen/IntrinsicEmitter.cpp
Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
===================================================================
--- llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -590,6 +590,9 @@
if (L->isNoReturn != R->isNoReturn)
return R->isNoReturn;
+ if (L->isReturnsTwice != R->isReturnsTwice)
+ return R->isReturnsTwice;
+
if (L->isNoSync != R->isNoSync)
return R->isNoSync;
@@ -739,7 +742,8 @@
if (!Intrinsic.canThrow ||
(Intrinsic.ModRef != CodeGenIntrinsic::ReadWriteMem &&
!Intrinsic.hasSideEffects) ||
- Intrinsic.isNoReturn || Intrinsic.isNoSync || Intrinsic.isNoFree ||
+ Intrinsic.isNoReturn || Intrinsic.isReturnsTwice ||
+ Intrinsic.isNoSync || Intrinsic.isNoFree ||
Intrinsic.isWillReturn || Intrinsic.isCold || Intrinsic.isNoDuplicate ||
Intrinsic.isNoMerge || Intrinsic.isConvergent ||
Intrinsic.isSpeculatable) {
@@ -749,6 +753,8 @@
OS << LS << "Attribute::NoUnwind";
if (Intrinsic.isNoReturn)
OS << LS << "Attribute::NoReturn";
+ if (Intrinsic.isReturnsTwice)
+ OS << LS << "Attribute::ReturnsTwice";
if (Intrinsic.isNoSync)
OS << LS << "Attribute::NoSync";
if (Intrinsic.isNoFree)
Index: llvm/utils/TableGen/CodeGenTarget.cpp
===================================================================
--- llvm/utils/TableGen/CodeGenTarget.cpp
+++ llvm/utils/TableGen/CodeGenTarget.cpp
@@ -666,6 +666,7 @@
isCommutative = false;
canThrow = false;
isNoReturn = false;
+ isReturnsTwice = false;
isNoSync = false;
isNoFree = false;
isWillReturn = false;
@@ -867,6 +868,8 @@
isConvergent = true;
else if (R->getName() == "IntrNoReturn")
isNoReturn = true;
+ else if (R->getName() == "IntrReturnsTwice")
+ isReturnsTwice = true;
else if (R->getName() == "IntrNoSync")
isNoSync = true;
else if (R->getName() == "IntrNoFree")
Index: llvm/utils/TableGen/CodeGenIntrinsics.h
===================================================================
--- llvm/utils/TableGen/CodeGenIntrinsics.h
+++ llvm/utils/TableGen/CodeGenIntrinsics.h
@@ -126,6 +126,9 @@
/// True if the intrinsic is no-return.
bool isNoReturn;
+ /// True if the intrinsic is returns-twice.
+ bool isReturnsTwice;
+
/// True if the intrinsic is no-sync.
bool isNoSync;
Index: llvm/include/llvm/IR/Intrinsics.td
===================================================================
--- llvm/include/llvm/IR/Intrinsics.td
+++ llvm/include/llvm/IR/Intrinsics.td
@@ -120,6 +120,8 @@
def IntrNoReturn : IntrinsicProperty;
+def IntrReturnsTwice : IntrinsicProperty;
+
// IntrNoSync - Threads executing the intrinsic will not synchronize using
// memory or other means. Applied by default.
def IntrNoSync : IntrinsicProperty<1>;
@@ -984,7 +986,8 @@
def int_eh_sjlj_callsite : Intrinsic<[], [llvm_i32_ty], [IntrNoMem]>;
def int_eh_sjlj_functioncontext : Intrinsic<[], [llvm_ptr_ty]>;
-def int_eh_sjlj_setjmp : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty]>;
+def int_eh_sjlj_setjmp : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty],
+ [IntrReturnsTwice]>;
def int_eh_sjlj_longjmp : Intrinsic<[], [llvm_ptr_ty], [IntrNoReturn]>;
def int_eh_sjlj_setup_dispatch : Intrinsic<[], []>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109248.370617.patch
Type: text/x-patch
Size: 3380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210903/205e5114/attachment.bin>
More information about the llvm-commits
mailing list