clang format

This commit is contained in:
Ivan 2018-06-03 02:41:28 +03:00
parent b613a53948
commit 91c1b8e69c
8 changed files with 76 additions and 88 deletions

View file

@ -9,19 +9,17 @@
#include "bind.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "valueparser.h"
namespace {
enum {
SmallParamsCount = 5
};
enum { SmallParamsCount = 5 };
llvm::FunctionType *getDstFuncType(llvm::FunctionType &srcType,
const llvm::ArrayRef<ParamSlice> &params) {
@ -38,14 +36,12 @@ llvm::FunctionType *getDstFuncType(llvm::FunctionType &srcType,
return llvm::FunctionType::get(retType, newParams, /*isVarArg*/ false);
}
llvm::Function *createBindFunc(llvm::Module &module,
llvm::Function &srcFunc,
llvm::Function *createBindFunc(llvm::Module &module, llvm::Function &srcFunc,
llvm::Function &exampleFunc,
llvm::FunctionType &funcType,
const llvm::ArrayRef<ParamSlice> &params) {
auto newFunc = llvm::Function::Create(
&funcType, llvm::GlobalValue::ExternalLinkage, "\1.jit_bind",
&module);
&funcType, llvm::GlobalValue::ExternalLinkage, "\1.jit_bind", &module);
newFunc->setCallingConv(srcFunc.getCallingConv());
// auto srcAttributes = srcFunc.getAttributes();
@ -67,25 +63,24 @@ llvm::Function *createBindFunc(llvm::Module &module,
return newFunc;
}
llvm::Value *allocParam(
llvm::IRBuilder<> &builder, llvm::Type &srcType, const
llvm::DataLayout &layout, const ParamSlice& param,
llvm::Value *
allocParam(llvm::IRBuilder<> &builder, llvm::Type &srcType,
const llvm::DataLayout &layout, const ParamSlice &param,
llvm::function_ref<void(const std::string &)> errHandler,
const BindOverride &override) {
if (param.type == ParamType::Aggregate && srcType.isPointerTy()) {
auto elemType = llvm::cast<llvm::PointerType>(&srcType)->getElementType();
auto stackArg = builder.CreateAlloca(elemType);
stackArg->setAlignment(layout.getABITypeAlignment(elemType));
auto init = parseInitializer(layout, *elemType, param.data, errHandler,
override);
auto init =
parseInitializer(layout, *elemType, param.data, errHandler, override);
builder.CreateStore(init, stackArg);
return stackArg;
}
auto stackArg = builder.CreateAlloca(&srcType);
stackArg->setAlignment(layout.getABITypeAlignment(&srcType));
auto init = parseInitializer(layout, srcType, param.data, errHandler,
override);
auto init =
parseInitializer(layout, srcType, param.data, errHandler, override);
builder.CreateStore(init, 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> &params,
llvm::function_ref<void(const std::string &)> errHandler,
const BindOverride &override) {

View file

@ -28,13 +28,12 @@ class Module;
class Function;
}
using BindOverride =
llvm::Optional<llvm::function_ref<llvm::Constant*(
llvm::Type &, const void *, size_t)>>;
using BindOverride = llvm::Optional<
llvm::function_ref<llvm::Constant *(llvm::Type &, const void *, size_t)>>;
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> &params,
llvm::function_ref<void(const std::string &)> errHandler,
const BindOverride &override = BindOverride{});

View file

@ -30,8 +30,8 @@
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Linker/Linker.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Cloning.h"
@ -148,9 +148,7 @@ public:
return nullptr;
}
const std::vector<BindHandle> &getBindHandles() const {
return bindHandles;
}
const std::vector<BindHandle> &getBindHandles() const { return bindHandles; }
void addBindHandle(llvm::StringRef name, void *handle) {
assert(!name.empty());
@ -194,17 +192,15 @@ void generateBind(const Context &context, JITContext &jitContext,
if (funcToInline != nullptr) {
auto exampleIrFunc = getIrFunc(exampleFunc);
assert(exampleIrFunc != nullptr);
auto errhandler = [&](const std::string &str) {
fatal(context, str);
};
auto overrideHandler =
[&](llvm::Type &type, const void *data, size_t size)->
llvm::Constant *{
auto errhandler = [&](const std::string &str) { fatal(context, str); };
auto overrideHandler = [&](llvm::Type &type, const void *data,
size_t size) -> llvm::Constant * {
if (type.isPointerTy()) {
auto getBindFunc = [&]() {
auto handle = *static_cast<void *const *>(data);
return handle != nullptr && jitContext.hasBindFunction(handle) ?
handle : nullptr;
return handle != nullptr && jitContext.hasBindFunction(handle)
? handle
: nullptr;
};
auto ptype = llvm::cast<llvm::PointerType>(&type);
@ -226,17 +222,16 @@ void generateBind(const Context &context, JITContext &jitContext,
auto bindIrFunc = it->second;
auto funcPtrType = bindIrFunc->getType();
auto globalVar1 = new llvm::GlobalVariable(
module, funcPtrType, true,
llvm::GlobalValue::PrivateLinkage,
module, funcPtrType, true, llvm::GlobalValue::PrivateLinkage,
bindIrFunc, ".jit_bind_handle");
return llvm::ConstantExpr::getBitCast(globalVar1, &type);
}
}
return nullptr;
};
auto func = bindParamsToFunc(module, *funcToInline, *exampleIrFunc,
params, errhandler,
BindOverride(overrideHandler));
auto func =
bindParamsToFunc(module, *funcToInline, *exampleIrFunc, params,
errhandler, BindOverride(overrideHandler));
moduleInfo.addBindHandle(func->getName(), bindPtr);
bindFuncs.insert({bindPtr, func});
} else {

View file

@ -18,10 +18,7 @@
#include <cstddef> //size_t
#include <cstdint>
enum ParamType : uint32_t {
Simple = 0,
Aggregate = 1
};
enum ParamType : uint32_t { Simple = 0, Aggregate = 1 };
struct ParamSlice {
const void *data;

View file

@ -54,8 +54,8 @@ void rtCompileProcessImpl(const Context *context, std::size_t contextSize) {
JIT_API_ENTRYPOINT(dynamiccompile_modules_head, context, contextSize);
}
void registerBindPayload(void *handle, void *originalFunc, const ParamSlice *desc,
size_t descSize) {
void registerBindPayload(void *handle, void *originalFunc,
const ParamSlice *desc, size_t descSize) {
JIT_REG_BIND_PAYLOAD(handle, originalFunc, desc, descSize);
}