mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-11 13:26:08 +03:00
clang format
This commit is contained in:
parent
b613a53948
commit
91c1b8e69c
8 changed files with 76 additions and 88 deletions
|
@ -9,19 +9,17 @@
|
||||||
|
|
||||||
#include "bind.h"
|
#include "bind.h"
|
||||||
|
|
||||||
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/IR/BasicBlock.h"
|
#include "llvm/IR/BasicBlock.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
|
||||||
#include "llvm/Transforms/Utils/Cloning.h"
|
#include "llvm/Transforms/Utils/Cloning.h"
|
||||||
|
|
||||||
#include "valueparser.h"
|
#include "valueparser.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
enum {
|
enum { SmallParamsCount = 5 };
|
||||||
SmallParamsCount = 5
|
|
||||||
};
|
|
||||||
|
|
||||||
llvm::FunctionType *getDstFuncType(llvm::FunctionType &srcType,
|
llvm::FunctionType *getDstFuncType(llvm::FunctionType &srcType,
|
||||||
const llvm::ArrayRef<ParamSlice> ¶ms) {
|
const llvm::ArrayRef<ParamSlice> ¶ms) {
|
||||||
|
@ -38,14 +36,12 @@ llvm::FunctionType *getDstFuncType(llvm::FunctionType &srcType,
|
||||||
return llvm::FunctionType::get(retType, newParams, /*isVarArg*/ false);
|
return llvm::FunctionType::get(retType, newParams, /*isVarArg*/ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Function *createBindFunc(llvm::Module &module,
|
llvm::Function *createBindFunc(llvm::Module &module, llvm::Function &srcFunc,
|
||||||
llvm::Function &srcFunc,
|
|
||||||
llvm::Function &exampleFunc,
|
llvm::Function &exampleFunc,
|
||||||
llvm::FunctionType &funcType,
|
llvm::FunctionType &funcType,
|
||||||
const llvm::ArrayRef<ParamSlice> ¶ms) {
|
const llvm::ArrayRef<ParamSlice> ¶ms) {
|
||||||
auto newFunc = llvm::Function::Create(
|
auto newFunc = llvm::Function::Create(
|
||||||
&funcType, llvm::GlobalValue::ExternalLinkage, "\1.jit_bind",
|
&funcType, llvm::GlobalValue::ExternalLinkage, "\1.jit_bind", &module);
|
||||||
&module);
|
|
||||||
|
|
||||||
newFunc->setCallingConv(srcFunc.getCallingConv());
|
newFunc->setCallingConv(srcFunc.getCallingConv());
|
||||||
// auto srcAttributes = srcFunc.getAttributes();
|
// auto srcAttributes = srcFunc.getAttributes();
|
||||||
|
@ -67,25 +63,24 @@ llvm::Function *createBindFunc(llvm::Module &module,
|
||||||
return newFunc;
|
return newFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::Value *
|
||||||
llvm::Value *allocParam(
|
allocParam(llvm::IRBuilder<> &builder, llvm::Type &srcType,
|
||||||
llvm::IRBuilder<> &builder, llvm::Type &srcType, const
|
const llvm::DataLayout &layout, const ParamSlice ¶m,
|
||||||
llvm::DataLayout &layout, const ParamSlice& param,
|
|
||||||
llvm::function_ref<void(const std::string &)> errHandler,
|
llvm::function_ref<void(const std::string &)> errHandler,
|
||||||
const BindOverride &override) {
|
const BindOverride &override) {
|
||||||
if (param.type == ParamType::Aggregate && srcType.isPointerTy()) {
|
if (param.type == ParamType::Aggregate && srcType.isPointerTy()) {
|
||||||
auto elemType = llvm::cast<llvm::PointerType>(&srcType)->getElementType();
|
auto elemType = llvm::cast<llvm::PointerType>(&srcType)->getElementType();
|
||||||
auto stackArg = builder.CreateAlloca(elemType);
|
auto stackArg = builder.CreateAlloca(elemType);
|
||||||
stackArg->setAlignment(layout.getABITypeAlignment(elemType));
|
stackArg->setAlignment(layout.getABITypeAlignment(elemType));
|
||||||
auto init = parseInitializer(layout, *elemType, param.data, errHandler,
|
auto init =
|
||||||
override);
|
parseInitializer(layout, *elemType, param.data, errHandler, override);
|
||||||
builder.CreateStore(init, stackArg);
|
builder.CreateStore(init, stackArg);
|
||||||
return stackArg;
|
return stackArg;
|
||||||
}
|
}
|
||||||
auto stackArg = builder.CreateAlloca(&srcType);
|
auto stackArg = builder.CreateAlloca(&srcType);
|
||||||
stackArg->setAlignment(layout.getABITypeAlignment(&srcType));
|
stackArg->setAlignment(layout.getABITypeAlignment(&srcType));
|
||||||
auto init = parseInitializer(layout, srcType, param.data, errHandler,
|
auto init =
|
||||||
override);
|
parseInitializer(layout, srcType, param.data, errHandler, override);
|
||||||
builder.CreateStore(init, stackArg);
|
builder.CreateStore(init, stackArg);
|
||||||
return builder.CreateLoad(stackArg);
|
return builder.CreateLoad(stackArg);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +128,9 @@ void doBind(llvm::Module &module, llvm::Function &dstFunc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Function *bindParamsToFunc(llvm::Module &module, llvm::Function &srcFunc, llvm::Function &exampleFunc,
|
llvm::Function *
|
||||||
|
bindParamsToFunc(llvm::Module &module, llvm::Function &srcFunc,
|
||||||
|
llvm::Function &exampleFunc,
|
||||||
const llvm::ArrayRef<ParamSlice> ¶ms,
|
const llvm::ArrayRef<ParamSlice> ¶ms,
|
||||||
llvm::function_ref<void(const std::string &)> errHandler,
|
llvm::function_ref<void(const std::string &)> errHandler,
|
||||||
const BindOverride &override) {
|
const BindOverride &override) {
|
||||||
|
|
|
@ -28,13 +28,12 @@ class Module;
|
||||||
class Function;
|
class Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
using BindOverride =
|
using BindOverride = llvm::Optional<
|
||||||
llvm::Optional<llvm::function_ref<llvm::Constant*(
|
llvm::function_ref<llvm::Constant *(llvm::Type &, const void *, size_t)>>;
|
||||||
llvm::Type &, const void *, size_t)>>;
|
|
||||||
|
|
||||||
|
llvm::Function *
|
||||||
llvm::Function *bindParamsToFunc(
|
bindParamsToFunc(llvm::Module &module, llvm::Function &srcFunc,
|
||||||
llvm::Module &module, llvm::Function &srcFunc,llvm::Function &exampleFunc,
|
llvm::Function &exampleFunc,
|
||||||
const llvm::ArrayRef<ParamSlice> ¶ms,
|
const llvm::ArrayRef<ParamSlice> ¶ms,
|
||||||
llvm::function_ref<void(const std::string &)> errHandler,
|
llvm::function_ref<void(const std::string &)> errHandler,
|
||||||
const BindOverride &override = BindOverride{});
|
const BindOverride &override = BindOverride{});
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
#include "llvm/Bitcode/BitcodeReader.h"
|
#include "llvm/Bitcode/BitcodeReader.h"
|
||||||
#include "llvm/ExecutionEngine/JITSymbol.h"
|
#include "llvm/ExecutionEngine/JITSymbol.h"
|
||||||
#include "llvm/IR/Constants.h"
|
#include "llvm/IR/Constants.h"
|
||||||
#include "llvm/IR/Mangler.h"
|
|
||||||
#include "llvm/IR/GlobalVariable.h"
|
#include "llvm/IR/GlobalVariable.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"
|
||||||
|
@ -148,9 +148,7 @@ public:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<BindHandle> &getBindHandles() const {
|
const std::vector<BindHandle> &getBindHandles() const { return bindHandles; }
|
||||||
return bindHandles;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addBindHandle(llvm::StringRef name, void *handle) {
|
void addBindHandle(llvm::StringRef name, void *handle) {
|
||||||
assert(!name.empty());
|
assert(!name.empty());
|
||||||
|
@ -194,17 +192,15 @@ void generateBind(const Context &context, JITContext &jitContext,
|
||||||
if (funcToInline != nullptr) {
|
if (funcToInline != nullptr) {
|
||||||
auto exampleIrFunc = getIrFunc(exampleFunc);
|
auto exampleIrFunc = getIrFunc(exampleFunc);
|
||||||
assert(exampleIrFunc != nullptr);
|
assert(exampleIrFunc != nullptr);
|
||||||
auto errhandler = [&](const std::string &str) {
|
auto errhandler = [&](const std::string &str) { fatal(context, str); };
|
||||||
fatal(context, str);
|
auto overrideHandler = [&](llvm::Type &type, const void *data,
|
||||||
};
|
size_t size) -> llvm::Constant * {
|
||||||
auto overrideHandler =
|
|
||||||
[&](llvm::Type &type, const void *data, size_t size)->
|
|
||||||
llvm::Constant *{
|
|
||||||
if (type.isPointerTy()) {
|
if (type.isPointerTy()) {
|
||||||
auto getBindFunc = [&]() {
|
auto getBindFunc = [&]() {
|
||||||
auto handle = *static_cast<void *const *>(data);
|
auto handle = *static_cast<void *const *>(data);
|
||||||
return handle != nullptr && jitContext.hasBindFunction(handle) ?
|
return handle != nullptr && jitContext.hasBindFunction(handle)
|
||||||
handle : nullptr;
|
? handle
|
||||||
|
: nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto ptype = llvm::cast<llvm::PointerType>(&type);
|
auto ptype = llvm::cast<llvm::PointerType>(&type);
|
||||||
|
@ -226,17 +222,16 @@ void generateBind(const Context &context, JITContext &jitContext,
|
||||||
auto bindIrFunc = it->second;
|
auto bindIrFunc = it->second;
|
||||||
auto funcPtrType = bindIrFunc->getType();
|
auto funcPtrType = bindIrFunc->getType();
|
||||||
auto globalVar1 = new llvm::GlobalVariable(
|
auto globalVar1 = new llvm::GlobalVariable(
|
||||||
module, funcPtrType, true,
|
module, funcPtrType, true, llvm::GlobalValue::PrivateLinkage,
|
||||||
llvm::GlobalValue::PrivateLinkage,
|
|
||||||
bindIrFunc, ".jit_bind_handle");
|
bindIrFunc, ".jit_bind_handle");
|
||||||
return llvm::ConstantExpr::getBitCast(globalVar1, &type);
|
return llvm::ConstantExpr::getBitCast(globalVar1, &type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
auto func = bindParamsToFunc(module, *funcToInline, *exampleIrFunc,
|
auto func =
|
||||||
params, errhandler,
|
bindParamsToFunc(module, *funcToInline, *exampleIrFunc, params,
|
||||||
BindOverride(overrideHandler));
|
errhandler, BindOverride(overrideHandler));
|
||||||
moduleInfo.addBindHandle(func->getName(), bindPtr);
|
moduleInfo.addBindHandle(func->getName(), bindPtr);
|
||||||
bindFuncs.insert({bindPtr, func});
|
bindFuncs.insert({bindPtr, func});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,10 +18,7 @@
|
||||||
#include <cstddef> //size_t
|
#include <cstddef> //size_t
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
enum ParamType : uint32_t {
|
enum ParamType : uint32_t { Simple = 0, Aggregate = 1 };
|
||||||
Simple = 0,
|
|
||||||
Aggregate = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ParamSlice {
|
struct ParamSlice {
|
||||||
const void *data;
|
const void *data;
|
||||||
|
|
|
@ -54,8 +54,8 @@ void rtCompileProcessImpl(const Context *context, std::size_t contextSize) {
|
||||||
JIT_API_ENTRYPOINT(dynamiccompile_modules_head, context, contextSize);
|
JIT_API_ENTRYPOINT(dynamiccompile_modules_head, context, contextSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerBindPayload(void *handle, void *originalFunc, const ParamSlice *desc,
|
void registerBindPayload(void *handle, void *originalFunc,
|
||||||
size_t descSize) {
|
const ParamSlice *desc, size_t descSize) {
|
||||||
JIT_REG_BIND_PAYLOAD(handle, originalFunc, desc, descSize);
|
JIT_REG_BIND_PAYLOAD(handle, originalFunc, desc, descSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue