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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346885
91177308-0d34-0410-b5e6-
96231b3b80d8
::
- declare void @llvm.trap() noreturn nounwind
+ declare void @llvm.trap() cold noreturn nounwind
Overview:
"""""""""
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;
//
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">;
}
; CHECK: attributes #0 = { nounwind readnone speculatable }
-; CHECK: attributes #1 = { noreturn nounwind }
+; CHECK: attributes #1 = { cold noreturn nounwind }
declare void @bees.b() nounwind
; CHECK: attributes [[$NUW]] = { nounwind }
-; CHECK: attributes #1 = { noreturn nounwind }
+; CHECK: attributes #1 = { cold noreturn nounwind }
/// 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;
isCommutative = false;
canThrow = false;
isNoReturn = false;
+ isCold = false;
isNoDuplicate = false;
isConvergent = false;
isSpeculatable = false;
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")
if (L->isNoReturn != R->isNoReturn)
return R->isNoReturn;
+ if (L->isCold != R->isCold)
+ return R->isCold;
+
if (L->isConvergent != R->isConvergent)
return R->isConvergent;
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;
OS << "Attribute::NoReturn";
addComma = true;
}
+ if (intrinsic.isCold) {
+ if (addComma)
+ OS << ",";
+ OS << "Attribute::Cold";
+ addComma = true;
+ }
if (intrinsic.isNoDuplicate) {
if (addComma)
OS << ",";