Skip to content

Commit

Permalink
Fix for UserAddrSpaceMD in retry
Browse files Browse the repository at this point in the history
Fixed the UserAddrSpaceMD in retry-compilation. During retry we are recreating the llvm context and the class UserAddrSpaceMD
had pointers to invalid MDNodes. This fix recreates the user_as_* MDNodes after changing the llvm context.
  • Loading branch information
lwesiers authored and igcbot committed Sep 22, 2023
1 parent f18050b commit 65d0f03
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion IGC/Compiler/CodeGenPublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 36 additions & 7 deletions IGC/Compiler/UserAddrSpaceMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,54 @@ SPDX-License-Identifier: MIT

#include "UserAddrSpaceMD.hpp"
#include "IGC/Probe/Assertion.h"
#include <CodeGenPublic.h>

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<llvm::StringRef, 8> 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;
Expand Down
10 changes: 8 additions & 2 deletions IGC/Compiler/UserAddrSpaceMD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ SPDX-License-Identifier: MIT

namespace IGC
{
class CodeGenContext;

typedef uint user_addrspace;

class UserAddrSpaceMD
Expand All @@ -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);
Expand Down

0 comments on commit 65d0f03

Please sign in to comment.