Skip to content

Commit

Permalink
[AOT] Add invariant attribute for memory and global pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Shen-Ta Hsieh <beststeve@secondstate.io>
  • Loading branch information
ibmibmibm authored and hydai committed Nov 1, 2023
1 parent a3a3474 commit e63e8ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/aot/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LLVM::Type, LLVM::Value> getGlobal(LLVM::Builder &Builder,
Expand All @@ -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};
}
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions lib/aot/llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,7 +162,7 @@ class Core {
ReadOnly = getEnumAttributeKind("readonly"sv);
StrictFP = getEnumAttributeKind("strictfp"sv);

InvariantLoad = getMetadataKind("invariant.load");
InvariantGroup = getMetadataKind("invariant.group");
}

template <typename... ArgsT>
Expand Down

0 comments on commit e63e8ee

Please sign in to comment.