diff --git a/IGC/Compiler/CodeGenPublic.h b/IGC/Compiler/CodeGenPublic.h index 49b8d9ef0a19..43d886c3274d 100644 --- a/IGC/Compiler/CodeGenPublic.h +++ b/IGC/Compiler/CodeGenPublic.h @@ -1045,7 +1045,7 @@ namespace IGC // Set retry behavor for Disable() m_retryManager.perKernel = (type == ShaderType::OPENCL_SHADER); - m_UserAddrSpaceMD = UserAddrSpaceMD(llvmCtxWrapper); + m_UserAddrSpaceMD = UserAddrSpaceMD(this); } CodeGenContext(CodeGenContext&) = delete; diff --git a/IGC/Compiler/UserAddrSpaceMD.cpp b/IGC/Compiler/UserAddrSpaceMD.cpp index 504f223df4b3..69fcc9ded793 100644 --- a/IGC/Compiler/UserAddrSpaceMD.cpp +++ b/IGC/Compiler/UserAddrSpaceMD.cpp @@ -8,25 +8,54 @@ SPDX-License-Identifier: MIT #include "UserAddrSpaceMD.hpp" #include "IGC/Probe/Assertion.h" +#include using namespace IGC; -UserAddrSpaceMD::UserAddrSpaceMD(llvm::LLVMContext* ctx) +UserAddrSpaceMD::UserAddrSpaceMD(CodeGenContext* ctx) { this->ctx = ctx; - user_addrspace_priv = ctx->getMDKindID("user_as_priv"); - user_addrspace_global = ctx->getMDKindID("user_as_global"); - user_addrspace_local = ctx->getMDKindID("user_as_local"); - user_addrspace_generic = ctx->getMDKindID("user_as_generic"); - user_addrspace_raystack = ctx->getMDKindID("user_as_raystack"); +} + + +bool UserAddrSpaceMD::needUpdateMarks() +{ + llvm::SmallVector mdkinds; + ctx->getLLVMContext()->getMDKindNames(mdkinds); - dummyNode = llvm::MDNode::get(*ctx, llvm::MDString::get(*ctx, "")); + for (auto iter = mdkinds.begin(); + iter != mdkinds.end(); + ++iter) + { + if (iter->equals("user_as_priv")) + { + return false; + } + } + return true; +} + +void UserAddrSpaceMD::updateMarks() +{ + if (needUpdateMarks()) + { + user_addrspace_priv = ctx->getLLVMContext()->getMDKindID("user_as_priv"); + user_addrspace_global = ctx->getLLVMContext()->getMDKindID("user_as_global"); + user_addrspace_local = ctx->getLLVMContext()->getMDKindID("user_as_local"); + user_addrspace_generic = ctx->getLLVMContext()->getMDKindID("user_as_generic"); + user_addrspace_raystack = ctx->getLLVMContext()->getMDKindID("user_as_raystack"); + + dummyNode = llvm::MDNode::get(*ctx->getLLVMContext(), + llvm::MDString::get(*ctx->getLLVMContext(), "")); + } } void UserAddrSpaceMD::Set(llvm::Instruction* inst, LSC_DOC_ADDR_SPACE type, llvm::MDNode* node) { if (inst) { + updateMarks(); + llvm::MDNode* chosen_node = node != nullptr ? node : dummyNode; diff --git a/IGC/Compiler/UserAddrSpaceMD.hpp b/IGC/Compiler/UserAddrSpaceMD.hpp index b146ad27aee3..82d70b047ca0 100644 --- a/IGC/Compiler/UserAddrSpaceMD.hpp +++ b/IGC/Compiler/UserAddrSpaceMD.hpp @@ -18,6 +18,8 @@ SPDX-License-Identifier: MIT namespace IGC { + class CodeGenContext; + typedef uint user_addrspace; class UserAddrSpaceMD @@ -28,12 +30,16 @@ namespace IGC user_addrspace user_addrspace_local; user_addrspace user_addrspace_generic; user_addrspace user_addrspace_raystack; - llvm::LLVMContext* ctx; llvm::MDNode* dummyNode; + CodeGenContext* ctx; + + bool needUpdateMarks(); + void updateMarks(); + public: UserAddrSpaceMD() {}; - UserAddrSpaceMD(llvm::LLVMContext* ctx); + UserAddrSpaceMD(CodeGenContext* ctx); void Set(llvm::Instruction* inst, LSC_DOC_ADDR_SPACE type, llvm::MDNode* node = nullptr); LSC_DOC_ADDR_SPACE Get(llvm::Instruction* inst);