diff options
| author | Vedant Kumar <vsk@apple.com> | 2018-11-14 19:53:41 +0000 | 
|---|---|---|
| committer | Vedant Kumar <vsk@apple.com> | 2018-11-14 19:53:41 +0000 | 
| commit | 808e157356234ecc865c0baecb2e22df5e4d54a8 (patch) | |
| tree | 709d3fcfa3a621d154b82f49755bfb053498ed18 | |
| parent | c0830f55779adf07809f6b1af4351c3a2f293dfc (diff) | |
| download | bcm5719-llvm-808e157356234ecc865c0baecb2e22df5e4d54a8.tar.gz bcm5719-llvm-808e157356234ecc865c0baecb2e22df5e4d54a8.zip  | |
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
llvm-svn: 346885
| -rw-r--r-- | llvm/docs/LangRef.rst | 2 | ||||
| -rw-r--r-- | llvm/include/llvm/IR/Intrinsics.td | 6 | ||||
| -rw-r--r-- | llvm/test/Feature/intrinsics.ll | 2 | ||||
| -rw-r--r-- | llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll | 2 | ||||
| -rw-r--r-- | llvm/utils/TableGen/CodeGenIntrinsics.h | 3 | ||||
| -rw-r--r-- | llvm/utils/TableGen/CodeGenTarget.cpp | 3 | ||||
| -rw-r--r-- | llvm/utils/TableGen/IntrinsicEmitter.cpp | 11 | 
7 files changed, 24 insertions, 5 deletions
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 06e092fb9fc..739267c8f58 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -14868,7 +14868,7 @@ Syntax:  :: -      declare void @llvm.trap() noreturn nounwind +      declare void @llvm.trap() cold noreturn nounwind  Overview:  """"""""" diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td index 04de1ca63a2..4213d750b3f 100644 --- a/llvm/include/llvm/IR/Intrinsics.td +++ b/llvm/include/llvm/IR/Intrinsics.td @@ -90,6 +90,10 @@ class ReadNone<int argNo> : IntrinsicProperty {  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<[llvm_ptr_ty], [llvm_ptr_ty, llvm_i8_ty],  //  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">; diff --git a/llvm/test/Feature/intrinsics.ll b/llvm/test/Feature/intrinsics.ll index bbf30d3cc23..71bb73cde18 100644 --- a/llvm/test/Feature/intrinsics.ll +++ b/llvm/test/Feature/intrinsics.ll @@ -70,4 +70,4 @@ define void @trap() {  }  ; CHECK: attributes #0 = { nounwind readnone speculatable } -; CHECK: attributes #1 = { noreturn nounwind } +; CHECK: attributes #1 = { cold noreturn nounwind } diff --git a/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll b/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll index c33030fa5d1..165e5b264ae 100644 --- a/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll +++ b/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll @@ -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 } diff --git a/llvm/utils/TableGen/CodeGenIntrinsics.h b/llvm/utils/TableGen/CodeGenIntrinsics.h index 5d071595912..9487a79c143 100644 --- a/llvm/utils/TableGen/CodeGenIntrinsics.h +++ b/llvm/utils/TableGen/CodeGenIntrinsics.h @@ -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; diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp index 305d2d19ff4..bcb65313555 100644 --- a/llvm/utils/TableGen/CodeGenTarget.cpp +++ b/llvm/utils/TableGen/CodeGenTarget.cpp @@ -536,6 +536,7 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {    isCommutative = false;    canThrow = false;    isNoReturn = false; +  isCold = false;    isNoDuplicate = false;    isConvergent = false;    isSpeculatable = false; @@ -682,6 +683,8 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {        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") diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp index 06e44e3b57c..049282e5ebf 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -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(const CodeGenIntrinsicTable &Ints,      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(const CodeGenIntrinsicTable &Ints,          OS << "Attribute::NoReturn";          addComma = true;        } +      if (intrinsic.isCold) { +        if (addComma) +          OS << ","; +        OS << "Attribute::Cold"; +        addComma = true; +      }        if (intrinsic.isNoDuplicate) {          if (addComma)            OS << ",";  | 

