On Thu, 30 Jul 2026 05:09:51 +0200
Anton Johansson <[email protected]> wrote:

> When producing LLVM IR using clang -O0, a noinline attribute is added.
> Remove this attribute to not inhibit future optimization.  Also try and
> force functions returning struct type to be inlined so they might be
> translated.
> 
> Signed-off-by: Anton Johansson <[email protected]>
> ---
>  .../src/PrepareForOptPass/PrepareForOptPass.cpp    | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git 
> a/subprojects/helper-to-tcg/src/PrepareForOptPass/PrepareForOptPass.cpp 
> b/subprojects/helper-to-tcg/src/PrepareForOptPass/PrepareForOptPass.cpp
> index 157f8cd05e..a7bee53582 100644
> --- a/subprojects/helper-to-tcg/src/PrepareForOptPass/PrepareForOptPass.cpp
> +++ b/subprojects/helper-to-tcg/src/PrepareForOptPass/PrepareForOptPass.cpp
> @@ -32,6 +32,7 @@
>  #include <llvm/IR/Intrinsics.h>
>  #include <llvm/IR/Module.h>
>  #include <llvm/Support/Debug.h>
> +#include <llvm/Transforms/Utils/Local.h>
>  
>  #include <queue>
>  #include <set>
> @@ -293,5 +294,18 @@ PreservedAnalyses PrepareForOptPass::run(Module &M,
>      collectAnnotations(M, ResultAnnotations);
>      cullUnusedFunctions(M, ResultAnnotations);
>      replaceRetaddrWithUndef(M);
> +    // Remove noinline function attributes automatically added by -O0, add
> +    // alwaysinline attribute to functions with a struct return value, these
> +    // can not be translated to TCG currently and we rely on inlining to
> +    // hopefully get rid of them.
> +    for (Function &F : M) {
> +        if (F.hasFnAttribute(Attribute::AttrKind::NoInline)) {
> +            F.removeFnAttr(Attribute::AttrKind::NoInline);
> +        }
> +        if (F.getReturnType()->isStructTy()) {
> +            F.addFnAttr(Attribute::AttrKind::AlwaysInline);
> +        }

I'd add a brief comment about why structs are a problem.

> +    }
> +

Did you consider having dinstinct passes for:

1. demangleFunctionNames
2. collectAnnotations + cullUnusedFunctions
3. replaceRetaddrWithUndef
4. This

>      return PreservedAnalyses::none();
>  }
> -- 
> 2.52.0
> 

Reviewed-by: Alessandro Di Federico <[email protected]>

-- 
Alessandro Di Federico
rev.ng Labs

Reply via email to