[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
Abe Skolnik via llvm-dev
llvm-dev at lists.llvm.org
Wed Jul 27 11:20:31 PDT 2016
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. 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;
*/
More information about the llvm-dev
mailing list