[llvm] r346885 - Mark @llvm.trap cold
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 14 11:53:41 PST 2018
Author: vedantk
Date: Wed Nov 14 11:53:41 2018
New Revision: 346885
URL: http://llvm.org/viewvc/llvm-project?rev=346885&view=rev
Log:
Mark @llvm.trap cold
A call to @llvm.trap can be expected to be cold (i.e. unlikely to be
reached in a normal program execution).
Outlining paths which unconditionally trap is an important memory
saving. As the hot/cold splitting pass (imho) should not treat all
noreturn calls as cold, explicitly mark @llvm.trap cold so that it can
be outlined.
Split out of https://reviews.llvm.org/D54244.
Differential Revision: https://reviews.llvm.org/D54329
Modified:
llvm/trunk/docs/LangRef.rst
llvm/trunk/include/llvm/IR/Intrinsics.td
llvm/trunk/test/Feature/intrinsics.ll
llvm/trunk/test/Transforms/SimplifyCFG/switch-on-const-select.ll
llvm/trunk/utils/TableGen/CodeGenIntrinsics.h
llvm/trunk/utils/TableGen/CodeGenTarget.cpp
llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp
Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=346885&r1=346884&r2=346885&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Wed Nov 14 11:53:41 2018
@@ -14868,7 +14868,7 @@ Syntax:
::
- declare void @llvm.trap() noreturn nounwind
+ declare void @llvm.trap() cold noreturn nounwind
Overview:
"""""""""
Modified: llvm/trunk/include/llvm/IR/Intrinsics.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Intrinsics.td?rev=346885&r1=346884&r2=346885&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Intrinsics.td (original)
+++ llvm/trunk/include/llvm/IR/Intrinsics.td Wed Nov 14 11:53:41 2018
@@ -90,6 +90,10 @@ class ReadNone<int argNo> : IntrinsicPro
def IntrNoReturn : IntrinsicProperty;
+// IntrCold - Calls to this intrinsic are cold.
+// Parallels the cold attribute on LLVM IR functions.
+def IntrCold : IntrinsicProperty;
+
// IntrNoduplicate - Calls to this intrinsic cannot be duplicated.
// Parallels the noduplicate attribute on LLVM IR functions.
def IntrNoDuplicate : IntrinsicProperty;
@@ -867,7 +871,7 @@ def int_coro_subfn_addr : Intrinsic<[llv
//
def int_flt_rounds : Intrinsic<[llvm_i32_ty]>,
GCCBuiltin<"__builtin_flt_rounds">;
-def int_trap : Intrinsic<[], [], [IntrNoReturn]>,
+def int_trap : Intrinsic<[], [], [IntrNoReturn, IntrCold]>,
GCCBuiltin<"__builtin_trap">;
def int_debugtrap : Intrinsic<[]>,
GCCBuiltin<"__builtin_debugtrap">;
Modified: llvm/trunk/test/Feature/intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Feature/intrinsics.ll?rev=346885&r1=346884&r2=346885&view=diff
==============================================================================
--- llvm/trunk/test/Feature/intrinsics.ll (original)
+++ llvm/trunk/test/Feature/intrinsics.ll Wed Nov 14 11:53:41 2018
@@ -70,4 +70,4 @@ define void @trap() {
}
; CHECK: attributes #0 = { nounwind readnone speculatable }
-; CHECK: attributes #1 = { noreturn nounwind }
+; CHECK: attributes #1 = { cold noreturn nounwind }
Modified: llvm/trunk/test/Transforms/SimplifyCFG/switch-on-const-select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/switch-on-const-select.ll?rev=346885&r1=346884&r2=346885&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/switch-on-const-select.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/switch-on-const-select.ll Wed Nov 14 11:53:41 2018
@@ -138,4 +138,4 @@ declare void @bees.a() nounwind
declare void @bees.b() nounwind
; CHECK: attributes [[$NUW]] = { nounwind }
-; CHECK: attributes #1 = { noreturn nounwind }
+; CHECK: attributes #1 = { cold noreturn nounwind }
Modified: llvm/trunk/utils/TableGen/CodeGenIntrinsics.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenIntrinsics.h?rev=346885&r1=346884&r2=346885&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenIntrinsics.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenIntrinsics.h Wed Nov 14 11:53:41 2018
@@ -124,6 +124,9 @@ struct CodeGenIntrinsic {
/// True if the intrinsic is no-return.
bool isNoReturn;
+ /// True if the intrinsic is cold.
+ bool isCold;
+
/// True if the intrinsic is marked as convergent.
bool isConvergent;
Modified: llvm/trunk/utils/TableGen/CodeGenTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=346885&r1=346884&r2=346885&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenTarget.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenTarget.cpp Wed Nov 14 11:53:41 2018
@@ -536,6 +536,7 @@ CodeGenIntrinsic::CodeGenIntrinsic(Recor
isCommutative = false;
canThrow = false;
isNoReturn = false;
+ isCold = false;
isNoDuplicate = false;
isConvergent = false;
isSpeculatable = false;
@@ -682,6 +683,8 @@ CodeGenIntrinsic::CodeGenIntrinsic(Recor
isConvergent = true;
else if (Property->getName() == "IntrNoReturn")
isNoReturn = true;
+ else if (Property->getName() == "IntrCold")
+ isCold = true;
else if (Property->getName() == "IntrSpeculatable")
isSpeculatable = true;
else if (Property->getName() == "IntrHasSideEffects")
Modified: llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp?rev=346885&r1=346884&r2=346885&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp Wed Nov 14 11:53:41 2018
@@ -489,6 +489,9 @@ struct AttributeComparator {
if (L->isNoReturn != R->isNoReturn)
return R->isNoReturn;
+ if (L->isCold != R->isCold)
+ return R->isCold;
+
if (L->isConvergent != R->isConvergent)
return R->isConvergent;
@@ -622,7 +625,7 @@ void IntrinsicEmitter::EmitAttributes(co
if (!intrinsic.canThrow ||
intrinsic.ModRef != CodeGenIntrinsic::ReadWriteMem ||
- intrinsic.isNoReturn || intrinsic.isNoDuplicate ||
+ intrinsic.isNoReturn || intrinsic.isCold || intrinsic.isNoDuplicate ||
intrinsic.isConvergent || intrinsic.isSpeculatable) {
OS << " const Attribute::AttrKind Atts[] = {";
bool addComma = false;
@@ -636,6 +639,12 @@ void IntrinsicEmitter::EmitAttributes(co
OS << "Attribute::NoReturn";
addComma = true;
}
+ if (intrinsic.isCold) {
+ if (addComma)
+ OS << ",";
+ OS << "Attribute::Cold";
+ addComma = true;
+ }
if (intrinsic.isNoDuplicate) {
if (addComma)
OS << ",";
More information about the llvm-commits
mailing list