[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
Duncan P. N. Exon Smith via llvm-dev
llvm-dev at lists.llvm.org
Tue Aug 2 13:19:06 PDT 2016
> On 2016-Jul-27, at 11:20, Abe Skolnik via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> Dear all,
>
> In the process of trying to add optimization for better layout of global variables, I have run up against a roadblock: I don`t seem to be able to sort the contents of a "SymbolTableListTraits<GlobalVariable>" -- or even swap two elements in that list -- without causing LLVM to crash.
>
> I have tried writing a comparator class and then using "llvm::iplist< NodeTy, Traits >::sort(Compare comp)" [<http://llvm.org/docs/doxygen/html/classllvm_1_1iplist.html#a81afd2c47bb276cd50c78c74b3f92ec3>], since "llvm::Module::GlobalListType" [<http://llvm.org/docs/doxygen/html/classllvm_1_1Module.html#accd281de11bad056a32f319d7facafe3>] is an alias for "SymbolTableList<GlobalVariable>" and according to the Web-based documentation every instantiation of SymbolTableList [<http://llvm.org/docs/doxygen/html/classllvm_1_1SymbolTableList.html>] is-an instantiation of "iplist" [<http://llvm.org/docs/doxygen/html/classllvm_1_1iplist.html>]. This call to "sort" crashed badly.
Crashed how? Have you turned on ASan? You might file a PR (feel free to CC me). I recommend attaching a minimal reproduction... I assume you can reproduce this in a unit test? That's easiest.
I just had a look at the sort code, and I don't see anything obviously wrong.
> I`ll paste in the code for this attempt below [simplified for clarity], but not the code for the others since they are longer and more "desperate".
>
> All my attempts to write anything that might be the innermost operation in a "sort" I would write myself either would not compile or would compile and crash at run-time. The ones that wouldn`t compile wouldn`t compile because GlobalVariable has an explicitly-deleted copy constructor and no move constructor [so "std::move(...)" was not usable to solve the problem].
>
> BTW: I am [and was] doing this in the context of "OptimizeGlobalVars" which is in "llvm/lib/Transforms/IPO/GlobalOpt.cpp".
>
> If anybody reading this can provide some assistance, I`d be much obliged.
>
> Regards,
>
> Abe
>
>
>
>
>
>
>
>
> struct GV_alignment_comparator {
> bool operator()(const GlobalVariable& L, const GlobalVariable& R) {
> return L.getAlignment() < R.getAlignment();
> }
> };
>
> // 'M' is a "Module &"
>
> /* this crashes BADLY... :-(
> M.getGlobalList().sort( GV_alignment_comparator() );
> Changed = true;
> */
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list