mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-10 04:45:56 +03:00
jit: use llvm::Mangler instead of hand-written routine (#2742)
This commit is contained in:
parent
9c048c635c
commit
86265da6b0
2 changed files with 12 additions and 18 deletions
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include "llvm/Bitcode/BitcodeReader.h"
|
#include "llvm/Bitcode/BitcodeReader.h"
|
||||||
#include "llvm/ExecutionEngine/JITSymbol.h"
|
#include "llvm/ExecutionEngine/JITSymbol.h"
|
||||||
|
#include "llvm/IR/Mangler.h"
|
||||||
#include "llvm/Linker/Linker.h"
|
#include "llvm/Linker/Linker.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Transforms/Utils/Cloning.h"
|
#include "llvm/Transforms/Utils/Cloning.h"
|
||||||
|
@ -65,21 +66,12 @@ struct RtCompileModuleList {
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
std::string decorate(const std::string &name) {
|
std::string decorate(const std::string &name,
|
||||||
#if __APPLE__
|
const llvm::DataLayout &datalayout) {
|
||||||
return "_" + name;
|
llvm::SmallVector<char, 64> ret;
|
||||||
#elif _WIN32
|
llvm::Mangler::getNameWithPrefix(ret, name, datalayout);
|
||||||
assert(!name.empty());
|
assert(!ret.empty());
|
||||||
if (name[0] == 0x1)
|
return std::string(ret.data(), ret.size());
|
||||||
return name.substr(1);
|
|
||||||
#if _M_IX86
|
|
||||||
return "_" + name;
|
|
||||||
#else
|
|
||||||
return name;
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
return name;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JITContext &getJit() {
|
JITContext &getJit() {
|
||||||
|
@ -122,7 +114,7 @@ void dumpModule(const Context &context, const llvm::Module &module,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFunctionsTarget(llvm::Module &module, llvm::TargetMachine &TM) {
|
void setFunctionsTarget(llvm::Module &module, const llvm::TargetMachine &TM) {
|
||||||
// Set function target cpu to host if it wasn't set explicitly
|
// Set function target cpu to host if it wasn't set explicitly
|
||||||
for (auto &&func : module.functions()) {
|
for (auto &&func : module.functions()) {
|
||||||
if (!func.hasFnAttribute("target-cpu")) {
|
if (!func.hasFnAttribute("target-cpu")) {
|
||||||
|
@ -178,6 +170,7 @@ void rtCompileProcessImplSoInternal(const RtCompileModuleList *modlist_head,
|
||||||
std::unique_ptr<llvm::Module> finalModule;
|
std::unique_ptr<llvm::Module> finalModule;
|
||||||
auto &symMap = myJit.getSymMap();
|
auto &symMap = myJit.getSymMap();
|
||||||
symMap.clear();
|
symMap.clear();
|
||||||
|
auto &layout = myJit.getDataLayout();
|
||||||
OptimizerSettings settings;
|
OptimizerSettings settings;
|
||||||
settings.optLevel = context.optLevel;
|
settings.optLevel = context.optLevel;
|
||||||
settings.sizeLevel = context.sizeLevel;
|
settings.sizeLevel = context.sizeLevel;
|
||||||
|
@ -222,7 +215,7 @@ void rtCompileProcessImplSoInternal(const RtCompileModuleList *modlist_head,
|
||||||
|
|
||||||
for (auto &&sym : toArray(current.symList, static_cast<std::size_t>(
|
for (auto &&sym : toArray(current.symList, static_cast<std::size_t>(
|
||||||
current.symListSize))) {
|
current.symListSize))) {
|
||||||
symMap.insert(std::make_pair(decorate(sym.name), sym.sym));
|
symMap.insert(std::make_pair(decorate(sym.name, layout), sym.sym));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -257,7 +250,7 @@ void rtCompileProcessImplSoInternal(const RtCompileModuleList *modlist_head,
|
||||||
JitFinaliser jitFinalizer(myJit);
|
JitFinaliser jitFinalizer(myJit);
|
||||||
interruptPoint(context, "Resolve functions");
|
interruptPoint(context, "Resolve functions");
|
||||||
for (auto &&fun : functions) {
|
for (auto &&fun : functions) {
|
||||||
auto decorated = decorate(fun.first);
|
auto decorated = decorate(fun.first, layout);
|
||||||
auto symbol = myJit.findSymbol(decorated);
|
auto symbol = myJit.findSymbol(decorated);
|
||||||
auto addr = resolveSymbol(symbol);
|
auto addr = resolveSymbol(symbol);
|
||||||
if (nullptr == addr) {
|
if (nullptr == addr) {
|
||||||
|
|
|
@ -98,6 +98,7 @@ public:
|
||||||
~JITContext();
|
~JITContext();
|
||||||
|
|
||||||
llvm::TargetMachine &getTargetMachine() { return *targetmachine; }
|
llvm::TargetMachine &getTargetMachine() { return *targetmachine; }
|
||||||
|
const llvm::DataLayout &getDataLayout() const { return dataLayout; }
|
||||||
|
|
||||||
bool addModule(std::unique_ptr<llvm::Module> module,
|
bool addModule(std::unique_ptr<llvm::Module> module,
|
||||||
llvm::raw_ostream *asmListener);
|
llvm::raw_ostream *asmListener);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue