Use new functions appendToGlobalCtors() and appendToGlobalDtors.

This simplifies the code in module.cpp a bit. But it is also the base to implement a pragma to place an arbitrary function in llvm.global_ctors and llvm.global_dtors.
This commit is contained in:
kai 2012-09-09 20:41:51 +02:00
parent e78ff5a131
commit d57eaa49ae
5 changed files with 144 additions and 91 deletions

View file

@ -10,6 +10,9 @@
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Target/TargetMachine.h"
#if LDC_LLVM_VER >= 301
#include "llvm/Transforms/Utils/ModuleUtils.h"
#endif
#include "gen/tollvm.h"
#include "gen/irstate.h"
@ -24,6 +27,7 @@
#include "gen/todebug.h"
#include "gen/nested.h"
#include "ir/irmodule.h"
#include "gen/llvmcompat.h"
#include <stack>
@ -1837,3 +1841,15 @@ void printLabelName(std::ostream& target, const char* func_mangle, const char* l
target << gTargetMachine->getMCAsmInfo()->getPrivateGlobalPrefix() <<
func_mangle << "_" << label_name;
}
//////////////////////////////////////////////////////////////////////////////////////////
// CTOR and DTOR
//////////////////////////////////////////////////////////////////////////////////////////
void AppendFunctionToLLVMGlobalCtorsDtors(llvm::Function* func, const uint32_t priority, const bool isCtor)
{
if (isCtor)
llvm::appendToGlobalCtors(*gIR->module, func, priority);
else
llvm::appendToGlobalDtors(*gIR->module, func, priority);
}