Skip to content

Commit 74bdcb3

Browse files
jaladreipsigcbot
authored andcommitted
CodeGenContext changes wrt LLVMContext
Do not leak LLVMContext in InitLLVMContextWrapper Recreate LLVMContext in resetOnRetry
1 parent ef6c200 commit 74bdcb3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

IGC/Compiler/CodeGenContext.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ LLVMContextWrapper::LLVMContextWrapper(bool createResourceDimTypes) : m_UserAddr
321321
if (WA_OpaquePointersCL && WA_OpaquePointersCL->getNumOccurrences() > 0) {
322322
IGC_IsPointerModeAlreadySet = true;
323323
}
324-
324+
325325
if (IGC::canOverwriteLLVMCtxPtrMode(basePtr, IGC_IsPointerModeAlreadySet)) {
326326
bool enableOpaquePointers = AreOpaquePointersEnabled();
327327
IGCLLVM::setOpaquePointers(basePtr, enableOpaquePointers);
@@ -389,6 +389,9 @@ void CodeGenContext::print(llvm::raw_ostream &stream) const {
389389
}
390390

391391
void CodeGenContext::initLLVMContextWrapper(bool createResourceDimTypes) {
392+
if (llvmCtxWrapper)
393+
llvmCtxWrapper->Release();
394+
392395
llvmCtxWrapper = new LLVMContextWrapper(createResourceDimTypes);
393396
llvmCtxWrapper->AddRef();
394397
}
@@ -704,7 +707,16 @@ void CodeGenContext::EmitWarning(const char *warningstr, const llvm::Value *cont
704707

705708
CompOptions &CodeGenContext::getCompilerOption() { return getModuleMetaData()->compOpt; }
706709

707-
void CodeGenContext::resetOnRetry() { m_tempCount = 0; }
710+
void CodeGenContext::resetOnRetry(bool isSubmodule) {
711+
712+
m_tempCount = 0;
713+
714+
if (isSubmodule)
715+
return;
716+
717+
clear();
718+
initLLVMContextWrapper();
719+
}
708720

709721
int32_t CodeGenContext::getNumThreadsPerEU() const { return -1; }
710722

IGC/Compiler/CodeGenPublic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ class CodeGenContext {
10211021
inline const std::string GetErrorAndWarning() { return GetWarning() + GetError(); }
10221022

10231023
CompOptions &getCompilerOption();
1024-
virtual void resetOnRetry();
1024+
virtual void resetOnRetry(bool isSubmodule = false);
10251025
virtual int32_t getNumThreadsPerEU() const;
10261026
virtual uint32_t getExpGRFSize() const;
10271027
virtual uint32_t getNumGRFPerThread(bool returnDefault = true);

0 commit comments

Comments
 (0)