Given a flag (-mllvm -reverse-iterate) this patch will enable iteration of SmallPtrSet in reverse order.
The idea is to compile the same source with and without this flag and expect the code to not change.
If there is a difference in codegen then it would mean that the codegen is sensitive to the iteration order of SmallPtrSet.
This is enabled only with LLVM_ENABLE_ABI_BREAKING_CHECKS.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Based on discussions on the associated email thread:
I have based this patch on LLVM_ENABLE_ABI_BREAKING_CHECKS. I have also turned it ON by default so that this is enabled in buildbot by default.
The user can toggle the behavior with the -mllvm -reverse-iterate flag.
Note: There are no associated tests with this patch as it is very difficult (not possible?) to detect "reverse" iteration since the relative order of elements in the SmallPtrSet is always undefined.
I would be happy to write tests for this if someone can suggest a good way of testing it. Otherwise the biggest test for this is to enable it in the buildbot and let the unit tests fail due to non-deterministic codegen.
Thanks @mehdi_amini for suggesting the unit test to check forward and reverse iteration.
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
30 ↗ | (On Diff #79466) | This introduces a dependency from ADT to Support, I'm not sure it is OK. |
unittests/ADT/ReverseIterationTest.cpp | ||
37 ↗ | (On Diff #79466) | The test cannot link without LLVM_ENABLE_ABI_BREAKING_CHECKS I believe. |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
30 ↗ | (On Diff #79466) | @mehdi_amini Yes, I will move ReverseIterate to LLVM namespace. Initially I was skeptical about defining ReverseIterate in Support. But then I did not know of a better place to do this, Could you please suggest what would be a preferable place to define this? |
unittests/ADT/ReverseIterationTest.cpp | ||
37 ↗ | (On Diff #79466) | Will guard this test for LLVM_ENABLE_ABI_BREAKING_CHECKS. |
- Moved ReverseIterate under LLVM namespace.
- Guarded unit test for LLVM_ENABLE_ABI_BREAKING_CHECKS.
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
30 ↗ | (On Diff #79466) | @mehdi_amini Could you please take a look at my updated patch and comment when you get a chance? |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
30 ↗ | (On Diff #79466) | I don't have a good suggestion. This is quite annoying. Maybe making them weak definition in a header (possibly using template)? |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
30 ↗ | (On Diff #79466) | @mehdi_amini Thanks for the suggestion. Variable templates are a C++14 feature and the compiler will output this warning: Would we need to silence these? By passing -Wno-c++14-extensions in the CMake flags? |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
30 ↗ | (On Diff #79466) | No this is not OK, LLVM builds in C++11 mode. |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
30 ↗ | (On Diff #79466) | Ah got it. Thanks! Will push a patch. |
Changed ReverseIterate to static member of a template class (it has weak definition). This breaks the dependency between ADT and Support.
unittests/ADT/CMakeLists.txt | ||
---|---|---|
67 ↗ | (On Diff #81148) | Without explicitly passing LLVM_ENABLE_ABI_BREAKING_CHECKS to the compilation line of ReverseIteration.cpp, it always complains about undefined variable "ReverseIterate". |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
31 ↗ | (On Diff #81148) | Wasn't it the goal of this to have it enabled by default in assert builds? |
lib/Support/CommandLine.cpp | ||
55 ↗ | (On Diff #81148) | You don't need the redefinition here I think (unless libSupport never imports SmallPtrSet?) |
unittests/ADT/CMakeLists.txt | ||
67 ↗ | (On Diff #81148) | That's not great, but I don't see a better way right now, can you at least document it in file here? |
unittests/ADT/CMakeLists.txt | ||
---|---|---|
67 ↗ | (On Diff #81148) | Didn't realize we needed to include llvm/Config/abi-breaking.h in the header for LLVM_ABI_BREAKING_CHECKS to be used. After including this in the header we no longer need an explicit add_definitions. |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
290 ↗ | (On Diff #81265) | I'd write this: #if LLVM_ENABLE_ABI_BREAKING_CHECKS if (ReverseIterate<bool>::value) { RetreatIfNotValid(); return *this; } #endif ++Bucket; AdvanceIfNotValid(); return *this; |
301 ↗ | (On Diff #81265) | Similar as a above, that makes the LLVM_ENABLE_ABI_BREAKING_CHECKS path more self-contained. |
unittests/ADT/CMakeLists.txt | ||
67 ↗ | (On Diff #81148) | Even if you build in Release mode? |
include/llvm/ADT/SmallPtrSet.h | ||
---|---|---|
290 ↗ | (On Diff #81265) | Done |
unittests/ADT/CMakeLists.txt | ||
67 ↗ | (On Diff #81148) | No, this test will only be enabled when LLVM_ENABLE_ABI_BREAKING_CHECKS is defined. However, conditionally including this test file only when LLVM_ENABLE_ABI_BREAKING_CHECKS is defined produces an error in Release mode: "unknown file ReverseIteration.cpp" |
I think we reached the point of good enough!
So LGTM.
unittests/ADT/CMakeLists.txt | ||
---|---|---|
67 ↗ | (On Diff #81148) | I was trying to make the test work in release mode, and expecting the add_definitions(-DLLVM_ENABLE_ABI_BREAKING_CHECKS) to enable it even in release mode. However that wouldn't work because the include of abi-breaking.h will override the command line definition. May not worth being fixed there. |
Thanks @mehdi_amini and @dexonsmith for all your help with this patch.
I will commit this.
I know this was turned in a while ago. But should the command line option have a description or be marked hidden or both. I believe it shows up in -help on a debug build, but has no description.