From e63e8ee0ed40d25504ab90934bdca50de9295f59 Mon Sep 17 00:00:00 2001 From: Shen-Ta Hsieh Date: Wed, 1 Nov 2023 09:19:00 +0800 Subject: [PATCH] [AOT] Add invariant attribute for memory and global pointer Signed-off-by: Shen-Ta Hsieh --- lib/aot/compiler.cpp | 6 +++++- lib/aot/llvm.h | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/aot/compiler.cpp b/lib/aot/compiler.cpp index 3c8757f12f32..1f4d9b5db096 100644 --- a/lib/aot/compiler.cpp +++ b/lib/aot/compiler.cpp @@ -453,6 +453,8 @@ struct WasmEdge::AOT::Compiler::CompileContext { auto VPtr = Builder.createLoad( Int8PtrTy, Builder.createInBoundsGEP1(Int8PtrTy, Array, LLContext.getInt64(Index))); + VPtr.setMetadata(LLContext, LLVM::Core::InvariantGroup, + LLVM::Metadata(LLContext, {})); return Builder.createBitCast(VPtr, Int8PtrTy); } std::pair getGlobal(LLVM::Builder &Builder, @@ -463,6 +465,8 @@ struct WasmEdge::AOT::Compiler::CompileContext { auto VPtr = Builder.createLoad( Int128PtrTy, Builder.createInBoundsGEP1(Int8PtrTy, Array, LLContext.getInt64(Index))); + VPtr.setMetadata(LLContext, LLVM::Core::InvariantGroup, + LLVM::Metadata(LLContext, {})); auto Ptr = Builder.createBitCast(VPtr, Ty.getPointerTo()); return {Ty, Ptr}; } @@ -492,7 +496,7 @@ struct WasmEdge::AOT::Compiler::CompileContext { auto PtrTy = Ty.getPointerTo(); auto PtrPtrTy = PtrTy.getPointerTo(); auto IT = Builder.createLoad(IntrinsicsTablePtrTy, IntrinsicsTable); - IT.setMetadata(LLContext, LLVM::Core::InvariantLoad, + IT.setMetadata(LLContext, LLVM::Core::InvariantGroup, LLVM::Metadata(LLContext, {})); auto VPtr = Builder.createInBoundsGEP2(IntrinsicsTableTy, IT, LLContext.getInt64(0), diff --git a/lib/aot/llvm.h b/lib/aot/llvm.h index 52f26e932cd4..c393c45ff627 100644 --- a/lib/aot/llvm.h +++ b/lib/aot/llvm.h @@ -87,7 +87,7 @@ class Core { static inline unsigned int ReadOnly = 0; static inline unsigned int StrictFP = 0; - static inline unsigned int InvariantLoad = 0; + static inline unsigned int InvariantGroup = 0; private: static inline std::once_flag Once; @@ -162,7 +162,7 @@ class Core { ReadOnly = getEnumAttributeKind("readonly"sv); StrictFP = getEnumAttributeKind("strictfp"sv); - InvariantLoad = getMetadataKind("invariant.load"); + InvariantGroup = getMetadataKind("invariant.group"); } template