llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Nikita Popov (nikic) <details> <summary>Changes</summary> Set target features in StartFunction(), which is in particular used by generateAwaitSuspendWrapper(). This ensures that inlining works without having to rely on target-specific feature compatibility logic (after https://github.com/llvm/llvm-project/pull/205113). TBH I'm very confused by Clang's attribute assignment logic for functions -- there are *so many* different APIs for setting attributes, and it feels like the attribute assignment is split randomly across them. I don't understand what the layering here is supposed to be. I initially wanted to move this case from ConstructAttributeList() to StartFunction() entirely, as target-features should only be assigned to definitions, not declarations (as we currently do), but then it turns out that some places only use SetLLVMFunctionAttributes() but not StartFunction(), so that doesn't work. Or maybe the right fix is to not change StartFunction() at all and instead call SetLLVMFunctionAttributes() from the coro code? --- Full diff: https://github.com/llvm/llvm-project/pull/207691.diff 5 Files Affected: - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+4) - (modified) clang/lib/CodeGen/CodeGenModule.h (+2) - (modified) clang/test/CodeGenCoroutines/coro-elide.cpp (-3) - (modified) clang/test/CodeGenCoroutines/coro-halo.cpp (-3) - (modified) clang/test/CodeGenCoroutines/pr65018.cpp (-3) ``````````diff diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index b920266b59808..7fcbcbed8efeb 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1124,6 +1124,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, getLLVMContext(), VScaleRange->first, VScaleRange->second)); } + llvm::AttrBuilder Attrs(getLLVMContext()); + CGM.GetCPUAndFeaturesAttributes(GD, Attrs); + Fn->addFnAttrs(Attrs); + llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn); // Create a marker to make it easy to insert allocas into the entryblock diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index b1e70a7c347db..b1137d900dccf 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1992,9 +1992,11 @@ class CodeGenModule : public CodeGenTypeCache { void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD, StringRef &CurName); +public: bool GetCPUAndFeaturesAttributes(GlobalDecl GD, llvm::AttrBuilder &AttrBuilder, bool SetTargetFeatures = true); +private: void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO); /// Set function attributes for a function declaration. diff --git a/clang/test/CodeGenCoroutines/coro-elide.cpp b/clang/test/CodeGenCoroutines/coro-elide.cpp index 3bff2a29c6e07..1902dd64b5e5a 100644 --- a/clang/test/CodeGenCoroutines/coro-elide.cpp +++ b/clang/test/CodeGenCoroutines/coro-elide.cpp @@ -1,8 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -O2 -emit-llvm %s -o - | FileCheck %s -// FIXME: Generate wrappers with correct target features. -// REQUIRES: x86-registered-target - #include "Inputs/coroutine.h" namespace { diff --git a/clang/test/CodeGenCoroutines/coro-halo.cpp b/clang/test/CodeGenCoroutines/coro-halo.cpp index 6dd785f5c1f8e..e75bedaf81fa2 100644 --- a/clang/test/CodeGenCoroutines/coro-halo.cpp +++ b/clang/test/CodeGenCoroutines/coro-halo.cpp @@ -3,9 +3,6 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -O2 -emit-llvm %s \ // RUN: -fcxx-exceptions -fexceptions -o - | FileCheck %s -// FIXME: Generate wrappers with correct target features. -// REQUIRES: x86-registered-target - #include "Inputs/coroutine.h" #include "Inputs/numeric.h" diff --git a/clang/test/CodeGenCoroutines/pr65018.cpp b/clang/test/CodeGenCoroutines/pr65018.cpp index f3b903dc0b396..f1cde461cabc2 100644 --- a/clang/test/CodeGenCoroutines/pr65018.cpp +++ b/clang/test/CodeGenCoroutines/pr65018.cpp @@ -1,9 +1,6 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \ // RUN: -O1 -emit-llvm %s -o - | FileCheck %s -// FIXME: Generate wrappers with correct target features. -// REQUIRES: x86-registered-target - #include "Inputs/coroutine.h" // A simple awaiter type with an await_suspend method that can't be `````````` </details> https://github.com/llvm/llvm-project/pull/207691 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
