[PATCH v2 17/50] helper-to-tcg: PrepareForOptPass, fixup inline attributes
Anton Johansson via qemu development <[email protected]>
| Newsgroups | gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
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); + } + } + return PreservedAnalyses::none(); } -- 2.52.0