-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC] Optimize OCLUtil::toString usage in checkError function #1229
Conversation
`toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid.
Tagging @AlexeySachkov @MrSidims, please take a look |
lib/SPIRV/SPIRVWriter.cpp
Outdated
@@ -1877,7 +1872,7 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB, | |||
if (!BM->getErrorLog().checkError( | |||
!AtomicRMWInst::isFPOperation(Op) && Op != AtomicRMWInst::Nand, | |||
SPIRVEC_InvalidInstruction, | |||
OCLUtil::toString(V) + "\nAtomic " + | |||
toString(V) + "\nAtomic " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString(V) + "\nAtomic " + | |
V + "\nAtomic " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean such change? It'll not work now as checkError
accepts an Instruction
, not Value
.
toString(V) + "\nAtomic " + | |
V, "\nAtomic " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change checkError
to accept Value
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied in ff6cabe.
There is a little hotspot involving
to this
You can also include this improvement to your patch. Otherwise I'll commit it separately. |
@Fznamznon thanks for the nice suggestion! I'll apply this change too. |
Co-authored-by: Alexey Sotkin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/SPIRV/libSPIRV/SPIRVUtil.h
Outdated
@@ -422,6 +424,15 @@ getOrInsert(MapTy &Map, typename MapTy::key_type Key, FuncTy Func) { | |||
return NF; | |||
} | |||
|
|||
template <typename T> std::string toString(const T *Object) { | |||
assert(Object != nullptr && "Expected non-null object"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes passing Value
to checkError()
mandatory. I'm not sure which way is better: this assert or return an empty string in this case. @vmaksimo what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, now it seems like it'd be enough to return an empty string - toString
is a utility function and I would not expect it to fail often. I'll rewrite this a bit.
…sGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid.
…ronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]>
…lvm-spirv perf.. '"xmain"' -> '"xmain-cand"' (1 commits) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]>
…o improve llvm-spirv perf.. '"xmain"' -> '"xmain-cand"' (1 commits) (KhronosGroup#48) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]> Co-authored-by: iclsrc <[email protected]> Co-authored-by: Artem Gindinson <[email protected]>
…commits to improve llvm-spirv perf.. '"xmain"' -> '"xmain-cand"' (1 commits) (KhronosGroup#48) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]> Co-authored-by: iclsrc <[email protected]> Co-authored-by: Artem Gindinson <[email protected]>
…lvm-spirv perf.. '"xmain"' -> '"xmain-web"' (7 commits) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]>
…o improve llvm-spirv perf.. '"xmain"' -> '"xmain-web"' (7 commits) (KhronosGroup#49) * Resolve of merge (conflict) 7b7a193 Cherry pick a couple of commits to improve llvm-spirv perf.. '"xmain"' -> '"xmain-web"' (7 commits) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]> * Resolve of merge (conflict) 7b7a193 Cherry pick a couple of commits to improve llvm-spirv perf.. '"xmain"' -> '"xmain-web"' (7 commits) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]> Co-authored-by: iclsrc <[email protected]>
…commits to improve llvm-spirv perf.. '"xmain"' -> '"xmain-web"' (7 commits) (KhronosGroup#49) * Resolve of merge (conflict) 7b7a193 Cherry pick a couple of commits to improve llvm-spirv perf.. '"xmain"' -> '"xmain-web"' (7 commits) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]> * Resolve of merge (conflict) 7b7a193 Cherry pick a couple of commits to improve llvm-spirv perf.. '"xmain"' -> '"xmain-web"' (7 commits) CONFLICT (content): Merge conflict in test/transcoding/annotate_attribute.ll CONFLICT (content): Merge conflict in test/transcoding/NoSignedUnsignedWrap.ll commit 7b7a193 Author: Alexey Sotkin <[email protected]> Date: Tue Oct 26 11:12:43 2021 +0300 Cherry pick a couple of commits to improve llvm-spirv performance (KhronosGroup#46) * [NFC] Optimize adding of decorations (KhronosGroup#1233) Use std::undordered_set instead of std::multiset with custom comparator. It is a bit unclear why std::multiset was required since there is no order requirement for OpDecorate instructions in SPIR-V spec, in addition old data structure was highly inefficient. * [NFC] Optimize OCLUtil::toString usage in checkError function (KhronosGroup#1229) `toString` function is called to convert an LLVM IR instruction to a string, mostly in order to include it into an error message in case LLVM IR is invalid. The problem is that this function is called even when IR is valid which significantly slows translator's work. This patch reworks `toString` usage in `checkError` method to generate a string only in case when LLVM IR is invalid. Co-authored-by: Mariya Podchishchaeva <[email protected]> Co-authored-by: Viktoria Maximova <[email protected]> Co-authored-by: iclsrc <[email protected]>
toString
function is called to convert an LLVM IR instruction to a string,mostly in order to include it into an error message in case LLVM IR is invalid.
The problem is that this function is called even when IR is valid which
significantly slows translator's work.
This patch reworks
toString
usage incheckError
method to generate a stringonly in case when LLVM IR is invalid.