<div dir="ltr">Thank you Johannes, I looked it up and it seems that we're creating one LLVMContext per compilation "unit", not sure if that matters. i.e. there's no single globally shared LLVMContext object.<div><br></div><div>Is LLVMContext *the* concurrency isolation (or unit) here?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 3, 2019 at 6:34 PM Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov">jdoerfert@anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
Do you use one llvm context or one per thread that interacts with llvm? I'm not an expert but the former might not be supported.
<br>
<br>
</div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
Cheers, <br>
</div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
Johannes <br>
<br>
</div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
Get <a href="https://aka.ms/ghei36" target="_blank">Outlook for Android</a></div>
<br>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-5850426149885951265divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> on behalf of pongba via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Sent:</b> Wednesday, April 3, 2019 7:24:25 PM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [llvm-dev] single-threaded code-gen and how to make it support multi-thread</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div class="gmail-m_-5850426149885951265gmail_signature">Hi llvm-dev,</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">Our code base has a ancient copy of llvm (ver 3.5.1), and it uses the LLVM code gen for some domain-specific language.</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">The previous dev left a global lock around the usage of LLVM code gen stating that because LLVM code gen can only be accessed single-threaded it needs to be protected with this global lock.</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">But now this lock has caused some perf issues as we pretty much lose concurrency when having to compile a large number of source files.</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">I've tried to remove the global lock and what I have observed in crashing stack is something like below:</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">(I did make sure LLVM_ENABLE_THREADS is defined to be 1, apparently it didn't seem to help)</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">The document around this seems vague, I have not found a clear instruction as to how to solve this, hence this post. Can anyone help with some pointers?</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">Any guidance is appreciated:)</div>
<div class="gmail-m_-5850426149885951265gmail_signature"><br>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>ntdll.dll!RtlReportCriticalFailure(long StatusCode, void * FailureInfo, unsigned long BreakIfDbgPresent) Line 201<span style="white-space:pre-wrap">
</span>C</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>ntdll.dll!RtlpHeapHandleError(long ErrorLevel) Line 344<span style="white-space:pre-wrap">
</span>C</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>ntdll.dll!RtlpHpHeapHandleError(_HEAP_FAILURE_TYPE FailureType, unsigned __int64 HeapAddress, unsigned __int64 Address) Line 670<span style="white-space:pre-wrap">
</span>C</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>ntdll.dll!RtlpLogHeapFailure(_HEAP_FAILURE_TYPE FailureType, void * HeapAddress, void * Address, void * Param1, void * Param2, void * Param3) Line 158<span style="white-space:pre-wrap">
</span>C</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>ntdll.dll!RtlFreeHeap(void * HeapHandle, unsigned long Flags, void * BaseAddress) Line 352<span style="white-space:pre-wrap">
</span>C</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>ucrtbase.dll!_free_base(void * block) Line 105<span style="white-space:pre-wrap">
</span>C++</div>
</div>
<div class="gmail-m_-5850426149885951265gmail_signature">
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>XXXTest.exe!llvm::StringMapImpl::RehashTable(unsigned int BucketNo) Line 238<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>XXXTest.exe!llvm::StringMap<llvm::ConstantDataSequential * __ptr64,llvm::MallocAllocator>::insert(std::pair<llvm::StringRef,llvm::ConstantDataSequential *> KV) Line 344<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>[Inline Frame] XXXTest.exe!llvm::StringMap<llvm::Value *,llvm::MallocAllocator>::GetOrCreateValue(llvm::StringRef) Line 371<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>[Inline Frame] XXXTest.exe!llvm::StringMap<llvm::Value *,llvm::MallocAllocator>::GetOrCreateValue(llvm::StringRef) Line 375<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>XXXTest.exe!llvm::ValueSymbolTable::createValueName(llvm::StringRef Name, llvm::Value * V) Line 98<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>XXXTest.exe!llvm::Value::setName(const llvm::Twine & NewName) Line 236<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>XXXTest.exe!llvm::IRBuilder<1,llvm::ConstantFolder,llvm::IRBuilderDefaultInserter<1> >::Insert<llvm::GetElementPtrInst>(llvm::GetElementPtrInst * I, const llvm::Twine & Name) Line 497<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>XXXTest.exe!llvm::IRBuilder<1,llvm::ConstantFolder,llvm::IRBuilderDefaultInserter<1> >::CreateConstInBoundsGEP1_32(llvm::Value * Ptr, unsigned int Idx0, const llvm::Twine & Name) Line 1014<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature">><span style="white-space:pre-wrap"> </span>XXXTest.exe!XXX::LlvmCodeGenerator::Visit(const XXX::FeatureRefExpression & p_expr) Line 953<span style="white-space:pre-wrap">
</span>C++</div>
<div class="gmail-m_-5850426149885951265gmail_signature"> <span style="white-space:pre-wrap"> </span>XXXTest.exe!XXX::FeatureRefExpression::Accept(XXX::Visitor & p_visitor) Line 46<span style="white-space:pre-wrap">
</span>C++</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">刘未鹏(pongba)<br><a href="http://mindhacks.cn" target="_blank">http://mindhacks.cn</a><br></div>