[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
SLTozer wrote: > looks good - a few bits should be committed separately from this change, so > please do those first and then commit this change Separate review opened up at: https://github.com/llvm/llvm-project/pull/68967 For simplicity's sake I'll keep this patch as-is, and rebase it when the other patch lands. https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/66632 >From eccff5693ebcaac45a7ddf56cbb33a48de281041 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Mon, 18 Sep 2023 09:59:11 +0100 Subject: [PATCH 1/3] [LLVM] Add new attribute `optdebug` to optimize for debugging This patch adds a new fn attribute, `optdebug`, that specifies that optimizations should make decisions that prioritize debug info quality, potentially at the cost of runtime performance. This patch does not add any functional changes triggered by this attribute, only the attribute itself. --- clang/lib/CodeGen/CodeGenModule.cpp | 1 + llvm/docs/BitCodeFormat.rst | 1 + llvm/docs/LangRef.rst | 4 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 + llvm/include/llvm/IR/Attributes.td | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 + llvm/test/Bitcode/attributes.ll | 7 +++ llvm/utils/emacs/llvm-mode.el | 2 +- llvm/utils/kate/llvm.xml| 1 + llvm/utils/vim/syntax/llvm.vim | 1 + 12 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b1a6683a66bd052..875952232e24b86 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2347,6 +2347,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); F->removeFnAttr(llvm::Attribute::OptimizeForSize); F->removeFnAttr(llvm::Attribute::MinSize); } else if (D->hasAttr()) { diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index db913f59d691d71..5742f8594e99908 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -1093,6 +1093,7 @@ The integer codes are mapped to well-known attributes as follows. * code 85: ``skipprofile`` * code 86: ``memory`` * code 87: ``nofpclass`` +* code 88: ``optdebug`` .. note:: The ``allocsize`` attribute has a special encoding for its arguments. Its two diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 798b0ab6c593ab4..b74c61d8a9aed9c 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2025,6 +2025,10 @@ example: Note: Comparing address of a global variable to ``null`` may still evaluate to false because of a limitation in querying this attribute inside constant expressions. +``optdebug`` +This attribute suggests that optimization passes and code generator passes +should make choices that try to preserve debug info without significantly +degrading runtime performance. ``optforfuzzing`` This attribute indicates that this function should be optimized for maximum fuzzing signal. diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 52e76356a892e45..5d7be5ca936ad37 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -713,6 +713,7 @@ enum AttributeKindCodes { ATTR_KIND_SKIP_PROFILE = 85, ATTR_KIND_MEMORY = 86, ATTR_KIND_NOFPCLASS = 87, + ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88, }; enum ComdatSelectionKindCodes { diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index aba1d718f7f72f9..fda79f5f24495fb 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>; /// Null pointer in address space zero is valid. def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>; +/// Select optimizations that give decent debug info. +def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>; + /// Select optimizations for best fuzzing signal. def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d1ec988a93d847..16eafa6e18f5d59 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::NoSanitizeCoverage; case bitc::ATTR_KIND_NULL_POINTER_IS_VALID: return Attribute::NullPointerIsValid; + case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING: +return Attribute::OptimizeForDebugging; case bitc::ATTR_KIND_OPT_FOR_FUZZING: return Attribute::OptForFuzzing; case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE: diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index e991d055f33474b..c427459508ecfc8 100644 --- a/llv
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
https://github.com/SLTozer closed https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
@@ -1872,7 +1872,8 @@ example: passes make choices that keep the code size of this function as small as possible and perform optimizations that may sacrifice runtime performance in order to minimize the size of the generated code. -This attribute is incompatible with the ``optnone`` attribute. +This attribute is incompatible with the ``optdebug`` and ``optnone`` +attributes. joker-eph wrote: It seems that you're missing the Verifier change to enforce this? https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/66632 This patch adds a new fn attribute, `optdebug`, that specifies that optimizations should make decisions that prioritize debug info quality, potentially at the cost of runtime performance. This patch does not add any functional changes triggered by this attribute, only the attribute itself. A subsequent patch will use this flag to disable the post-RA scheduler. I've added the reviewers of the original patch (D157615), i.e. debug info codeowners and the others who left comments; as far as I'm aware there isn't a codeowner for "attributes", but if there's some owned category that applies then lmk and I'll add the relevant reviewer. >From 18f494a4006b4c21b364a91107d4a07ceaf88213 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Mon, 18 Sep 2023 09:59:11 +0100 Subject: [PATCH] [LLVM] Add new attribute `optdebug` to optimize for debugging This patch adds a new fn attribute, `optdebug`, that specifies that optimizations should make decisions that prioritize debug info quality, potentially at the cost of runtime performance. This patch does not add any functional changes triggered by this attribute, only the attribute itself. --- clang/lib/CodeGen/CodeGenModule.cpp | 1 + llvm/docs/BitCodeFormat.rst | 1 + llvm/docs/LangRef.rst | 4 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 + llvm/include/llvm/IR/Attributes.td | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 + llvm/test/Bitcode/attributes.ll | 7 +++ llvm/utils/emacs/llvm-mode.el | 2 +- llvm/utils/kate/llvm.xml| 1 + llvm/utils/vim/syntax/llvm.vim | 1 + 12 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8b0c9340775cbe9..96d053a6aa8f9e5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2325,6 +2325,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); F->removeFnAttr(llvm::Attribute::OptimizeForSize); F->removeFnAttr(llvm::Attribute::MinSize); } else if (D->hasAttr()) { diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 70be73abef19d6d..ce0e29fb6b928a7 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as follows. * code 77: ``elementtype`` * code 78: ``disable_sanitizer_instrumentation`` * code 79: ``nosanitize_bounds`` +* code 88: ``optdebug`` .. note:: The ``allocsize`` attribute has a special encoding for its arguments. Its two diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index f542e70bcfee810..fa274fdb66a5047 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2024,6 +2024,10 @@ example: Note: Comparing address of a global variable to ``null`` may still evaluate to false because of a limitation in querying this attribute inside constant expressions. +``optdebug`` +This attribute suggests that optimization passes and code generator passes +should make choices that try to preserve debug info without significantly +degrading runtime performance. ``optforfuzzing`` This attribute indicates that this function should be optimized for maximum fuzzing signal. diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 52e76356a892e45..5d7be5ca936ad37 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -713,6 +713,7 @@ enum AttributeKindCodes { ATTR_KIND_SKIP_PROFILE = 85, ATTR_KIND_MEMORY = 86, ATTR_KIND_NOFPCLASS = 87, + ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88, }; enum ComdatSelectionKindCodes { diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index aba1d718f7f72f9..fda79f5f24495fb 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>; /// Null pointer in address space zero is valid. def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>; +/// Select optimizations that give decent debug info. +def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>; + /// Select optimizations for best fuzzing signal. def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d1ec988a93d847..16eafa6e18f5d59 100644 --- a
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
llvmbot wrote: @llvm/pr-subscribers-debuginfo Changes This patch adds a new fn attribute, `optdebug`, that specifies that optimizations should make decisions that prioritize debug info quality, potentially at the cost of runtime performance. This patch does not add any functional changes triggered by this attribute, only the attribute itself. A subsequent patch will use this flag to disable the post-RA scheduler. I've added the reviewers of the original patch (D157615), i.e. debug info codeowners and the others who left comments; as far as I'm aware there isn't a codeowner for "attributes", but if there's some owned category that applies then lmk and I'll add the relevant reviewer. --- Full diff: https://github.com/llvm/llvm-project/pull/66632.diff 12 Files Affected: - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1) - (modified) llvm/docs/BitCodeFormat.rst (+1) - (modified) llvm/docs/LangRef.rst (+4) - (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (+1) - (modified) llvm/include/llvm/IR/Attributes.td (+3) - (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+2) - (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+2) - (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+1) - (modified) llvm/test/Bitcode/attributes.ll (+7) - (modified) llvm/utils/emacs/llvm-mode.el (+1-1) - (modified) llvm/utils/kate/llvm.xml (+1) - (modified) llvm/utils/vim/syntax/llvm.vim (+1) ``diff diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8b0c9340775cbe9..96d053a6aa8f9e5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2325,6 +2325,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); F->removeFnAttr(llvm::Attribute::OptimizeForSize); F->removeFnAttr(llvm::Attribute::MinSize); } else if (D->hasAttr()) { diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 70be73abef19d6d..ce0e29fb6b928a7 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as follows. * code 77: ``elementtype`` * code 78: ``disable_sanitizer_instrumentation`` * code 79: ``nosanitize_bounds`` +* code 88: ``optdebug`` .. note:: The ``allocsize`` attribute has a special encoding for its arguments. Its two diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index f542e70bcfee810..fa274fdb66a5047 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2024,6 +2024,10 @@ example: Note: Comparing address of a global variable to ``null`` may still evaluate to false because of a limitation in querying this attribute inside constant expressions. +``optdebug`` +This attribute suggests that optimization passes and code generator passes +should make choices that try to preserve debug info without significantly +degrading runtime performance. ``optforfuzzing`` This attribute indicates that this function should be optimized for maximum fuzzing signal. diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 52e76356a892e45..5d7be5ca936ad37 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -713,6 +713,7 @@ enum AttributeKindCodes { ATTR_KIND_SKIP_PROFILE = 85, ATTR_KIND_MEMORY = 86, ATTR_KIND_NOFPCLASS = 87, + ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88, }; enum ComdatSelectionKindCodes { diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index aba1d718f7f72f9..fda79f5f24495fb 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>; /// Null pointer in address space zero is valid. def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>; +/// Select optimizations that give decent debug info. +def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>; + /// Select optimizations for best fuzzing signal. def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d1ec988a93d847..16eafa6e18f5d59 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::NoSanitizeCoverage; case bitc::ATTR_KIND_NULL_POINTER_IS_VALID: return Attribute::NullPointerIsValid; + case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING: +return Attribute::OptimizeForDebugging; case bitc::ATTR_KIND_OPT_FOR_FUZZING: return Attribute::O
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
@@ -2325,6 +2325,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); pogo59 wrote: Given that this patch doesn't have any other clang changes, this one can be deferred to a later patch where clang actually applies the attribute. https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
@@ -2325,6 +2325,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); dwblaikie wrote: +1, and otherwise the change makes sense to me. Could you post about this on Discourse, pointing to this pull request - just to make sure folks are aware we're adding a new IR attribute here? Be good to ensure there's consensus. https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
@@ -2325,6 +2325,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); SLTozer wrote: Topic posted: https://discourse.llvm.org/t/rfc-new-function-attribute-optdebug-for-prioritizing-debuggability-in-llvm-passes/73552 https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
pogo59 wrote: Are there interactions between `optdebug` and other attributes that should be enforced by the verifier? Like, can't be mixed with `optnone`? https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
aeubanks wrote: > Are there interactions between `optdebug` and other attributes that should be > enforced by the verifier? Like, can't be mixed with `optnone`? +1, this is basically "I want `-O1`" vs "I want `-O0`" so they must conflict https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
aeubanks wrote: And same with `optsize`/`minsize` since those explicitly want as many simplifications as possible which conflicts with `optdebug` https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
SLTozer wrote: Making this attribute mutually exclusive with `optdebug` and `optsize` is fine with me - as a question for the esteemed reviewers of this patch, would it be preferred to add this exclusivity and associated verifier checks in a separate patch, or as part of this patch? https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
aeubanks wrote: I think typically the verifier changes are done in the same change since they match the LangRef change, but it doesn't matter too much as long as it gets sdone. The LangRef change should also mention the attributes this is incompatible with (like `optnone`'s description) https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
@@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as follows. * code 77: ``elementtype`` * code 78: ``disable_sanitizer_instrumentation`` * code 79: ``nosanitize_bounds`` +* code 88: ``optdebug`` aeubanks wrote: if you're going to update this, can you first add the attributes in between? https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/66632 >From 18f494a4006b4c21b364a91107d4a07ceaf88213 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Mon, 18 Sep 2023 09:59:11 +0100 Subject: [PATCH 1/2] [LLVM] Add new attribute `optdebug` to optimize for debugging This patch adds a new fn attribute, `optdebug`, that specifies that optimizations should make decisions that prioritize debug info quality, potentially at the cost of runtime performance. This patch does not add any functional changes triggered by this attribute, only the attribute itself. --- clang/lib/CodeGen/CodeGenModule.cpp | 1 + llvm/docs/BitCodeFormat.rst | 1 + llvm/docs/LangRef.rst | 4 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 + llvm/include/llvm/IR/Attributes.td | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 + llvm/test/Bitcode/attributes.ll | 7 +++ llvm/utils/emacs/llvm-mode.el | 2 +- llvm/utils/kate/llvm.xml| 1 + llvm/utils/vim/syntax/llvm.vim | 1 + 12 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8b0c9340775cbe9..96d053a6aa8f9e5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2325,6 +2325,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); F->removeFnAttr(llvm::Attribute::OptimizeForSize); F->removeFnAttr(llvm::Attribute::MinSize); } else if (D->hasAttr()) { diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 70be73abef19d6d..ce0e29fb6b928a7 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as follows. * code 77: ``elementtype`` * code 78: ``disable_sanitizer_instrumentation`` * code 79: ``nosanitize_bounds`` +* code 88: ``optdebug`` .. note:: The ``allocsize`` attribute has a special encoding for its arguments. Its two diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index f542e70bcfee810..fa274fdb66a5047 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2024,6 +2024,10 @@ example: Note: Comparing address of a global variable to ``null`` may still evaluate to false because of a limitation in querying this attribute inside constant expressions. +``optdebug`` +This attribute suggests that optimization passes and code generator passes +should make choices that try to preserve debug info without significantly +degrading runtime performance. ``optforfuzzing`` This attribute indicates that this function should be optimized for maximum fuzzing signal. diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 52e76356a892e45..5d7be5ca936ad37 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -713,6 +713,7 @@ enum AttributeKindCodes { ATTR_KIND_SKIP_PROFILE = 85, ATTR_KIND_MEMORY = 86, ATTR_KIND_NOFPCLASS = 87, + ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88, }; enum ComdatSelectionKindCodes { diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index aba1d718f7f72f9..fda79f5f24495fb 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>; /// Null pointer in address space zero is valid. def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>; +/// Select optimizations that give decent debug info. +def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>; + /// Select optimizations for best fuzzing signal. def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d1ec988a93d847..16eafa6e18f5d59 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::NoSanitizeCoverage; case bitc::ATTR_KIND_NULL_POINTER_IS_VALID: return Attribute::NullPointerIsValid; + case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING: +return Attribute::OptimizeForDebugging; case bitc::ATTR_KIND_OPT_FOR_FUZZING: return Attribute::OptForFuzzing; case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE: diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index f53fbd73667762
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/66632 >From 18f494a4006b4c21b364a91107d4a07ceaf88213 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Mon, 18 Sep 2023 09:59:11 +0100 Subject: [PATCH 1/3] [LLVM] Add new attribute `optdebug` to optimize for debugging This patch adds a new fn attribute, `optdebug`, that specifies that optimizations should make decisions that prioritize debug info quality, potentially at the cost of runtime performance. This patch does not add any functional changes triggered by this attribute, only the attribute itself. --- clang/lib/CodeGen/CodeGenModule.cpp | 1 + llvm/docs/BitCodeFormat.rst | 1 + llvm/docs/LangRef.rst | 4 llvm/include/llvm/Bitcode/LLVMBitCodes.h| 1 + llvm/include/llvm/IR/Attributes.td | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ llvm/lib/Transforms/Utils/CodeExtractor.cpp | 1 + llvm/test/Bitcode/attributes.ll | 7 +++ llvm/utils/emacs/llvm-mode.el | 2 +- llvm/utils/kate/llvm.xml| 1 + llvm/utils/vim/syntax/llvm.vim | 1 + 12 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8b0c9340775cbe9..96d053a6aa8f9e5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2325,6 +2325,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::Naked); // OptimizeNone wins over OptimizeForSize and MinSize. +F->removeFnAttr(llvm::Attribute::OptimizeForDebugging); F->removeFnAttr(llvm::Attribute::OptimizeForSize); F->removeFnAttr(llvm::Attribute::MinSize); } else if (D->hasAttr()) { diff --git a/llvm/docs/BitCodeFormat.rst b/llvm/docs/BitCodeFormat.rst index 70be73abef19d6d..ce0e29fb6b928a7 100644 --- a/llvm/docs/BitCodeFormat.rst +++ b/llvm/docs/BitCodeFormat.rst @@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as follows. * code 77: ``elementtype`` * code 78: ``disable_sanitizer_instrumentation`` * code 79: ``nosanitize_bounds`` +* code 88: ``optdebug`` .. note:: The ``allocsize`` attribute has a special encoding for its arguments. Its two diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index f542e70bcfee810..fa274fdb66a5047 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2024,6 +2024,10 @@ example: Note: Comparing address of a global variable to ``null`` may still evaluate to false because of a limitation in querying this attribute inside constant expressions. +``optdebug`` +This attribute suggests that optimization passes and code generator passes +should make choices that try to preserve debug info without significantly +degrading runtime performance. ``optforfuzzing`` This attribute indicates that this function should be optimized for maximum fuzzing signal. diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 52e76356a892e45..5d7be5ca936ad37 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -713,6 +713,7 @@ enum AttributeKindCodes { ATTR_KIND_SKIP_PROFILE = 85, ATTR_KIND_MEMORY = 86, ATTR_KIND_NOFPCLASS = 87, + ATTR_KIND_OPTIMIZE_FOR_DEBUGGING = 88, }; enum ComdatSelectionKindCodes { diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index aba1d718f7f72f9..fda79f5f24495fb 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -200,6 +200,9 @@ def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>; /// Null pointer in address space zero is valid. def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>; +/// Select optimizations that give decent debug info. +def OptimizeForDebugging : EnumAttr<"optdebug", [FnAttr]>; + /// Select optimizations for best fuzzing signal. def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d1ec988a93d847..16eafa6e18f5d59 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1980,6 +1980,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::NoSanitizeCoverage; case bitc::ATTR_KIND_NULL_POINTER_IS_VALID: return Attribute::NullPointerIsValid; + case bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING: +return Attribute::OptimizeForDebugging; case bitc::ATTR_KIND_OPT_FOR_FUZZING: return Attribute::OptForFuzzing; case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE: diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index f53fbd73667762
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
SLTozer wrote: Small ping - all comments have now been addressed now I think. https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
https://github.com/dwblaikie edited https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
https://github.com/dwblaikie approved this pull request. looks good - a few bits should be committed separately from this change, so please do those first and then commit this change https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
@@ -1085,6 +1085,7 @@ The integer codes are mapped to well-known attributes as follows. * code 77: ``elementtype`` * code 78: ``disable_sanitizer_instrumentation`` * code 79: ``nosanitize_bounds`` +* code 88: ``optdebug`` dwblaikie wrote: This could/should be committed separately/before this change - since it's fixing an existing documentation problem, not directly related to the patch adding optdebug (eg: if we need to revert the optdebug patch for any reason, we wouldn't want to lose this work) https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LLVM] Add new attribute `optdebug` to optimize for debugging (PR #66632)
@@ -2028,6 +2030,8 @@ example: This attribute suggests that optimization passes and code generator passes should make choices that try to preserve debug info without significantly degrading runtime performance. +This attribute is incompatible with the ``minsize``, ``optsize``, and +``optnone`` attributes. dwblaikie wrote: Looks like this could be committed separately. https://github.com/llvm/llvm-project/pull/66632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits