diff options
author | Thurston Dang <thurston@google.com> | 2024-09-17 22:54:52 +0000 |
---|---|---|
committer | Thurston Dang <thurston@google.com> | 2024-09-17 22:54:52 +0000 |
commit | b89bb7775d155fc787ab3170f3fa38449069ecb3 (patch) | |
tree | 035d19e245eb38e891592b0a264eb3433efec535 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 4a0bf8377e1038d6cf9454c7c6740bd759729938 (diff) | |
download | llvm-b89bb7775d155fc787ab3170f3fa38449069ecb3.zip llvm-b89bb7775d155fc787ab3170f3fa38449069ecb3.tar.gz llvm-b89bb7775d155fc787ab3170f3fa38449069ecb3.tar.bz2 |
Reapply "[HLSL] set alwaysinline on HLSL functions (#106588)"
This reverts commit 4a63f4d301c0e044073e1b1f8f110015ec1778a1.
It was reverted because of a buildbot breakage, but the fix-forward has
landed (https://github.com/llvm/llvm-project/pull/109023).
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ba2d658..17b82b2 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2473,11 +2473,14 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::StackProtectReq); if (!D) { + // Non-entry HLSL functions must always be inlined. + if (getLangOpts().HLSL && !F->hasFnAttribute(llvm::Attribute::NoInline)) + B.addAttribute(llvm::Attribute::AlwaysInline); // If we don't have a declaration to control inlining, the function isn't // explicitly marked as alwaysinline for semantic reasons, and inlining is // disabled, mark the function as noinline. - if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline) && - CodeGenOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining) + else if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline) && + CodeGenOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining) B.addAttribute(llvm::Attribute::NoInline); F->addFnAttrs(B); @@ -2504,9 +2507,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, ShouldAddOptNone &= !D->hasAttr<MinSizeAttr>(); ShouldAddOptNone &= !D->hasAttr<AlwaysInlineAttr>(); - // Add optnone, but do so only if the function isn't always_inline. - if ((ShouldAddOptNone || D->hasAttr<OptimizeNoneAttr>()) && - !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) { + // Non-entry HLSL functions must always be inlined. + if (getLangOpts().HLSL && !F->hasFnAttribute(llvm::Attribute::NoInline) && + !D->hasAttr<NoInlineAttr>()) { + B.addAttribute(llvm::Attribute::AlwaysInline); + } else if ((ShouldAddOptNone || D->hasAttr<OptimizeNoneAttr>()) && + !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) { + // Add optnone, but do so only if the function isn't always_inline. B.addAttribute(llvm::Attribute::OptimizeNone); // OptimizeNone implies noinline; we should not be inlining such functions. @@ -2526,7 +2533,8 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, B.addAttribute(llvm::Attribute::NoInline); } else if (D->hasAttr<NoDuplicateAttr>()) { B.addAttribute(llvm::Attribute::NoDuplicate); - } else if (D->hasAttr<NoInlineAttr>() && !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) { + } else if (D->hasAttr<NoInlineAttr>() && + !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) { // Add noinline if the function isn't always_inline. B.addAttribute(llvm::Attribute::NoInline); } else if (D->hasAttr<AlwaysInlineAttr>() && |