Add 'xo-jit/' from commit '855887df71'
git-subtree-dir: xo-jit git-subtree-mainline:35555df976git-subtree-split:855887df71
This commit is contained in:
commit
757dfed99c
49 changed files with 7305 additions and 0 deletions
4
xo-jit/example/CMakeLists.txt
Normal file
4
xo-jit/example/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
add_subdirectory(ex1)
|
||||
add_subdirectory(ex2_jit)
|
||||
add_subdirectory(ex3_fptr)
|
||||
add_subdirectory(ex_kaleidoscope4)
|
||||
12
xo-jit/example/ex1/CMakeLists.txt
Normal file
12
xo-jit/example/ex1/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# xo-jit/example/ex1/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_jit_ex1)
|
||||
set(SELF_SRCS ex1.cpp)
|
||||
|
||||
if (XO_ENABLE_EXAMPLES)
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
xo_self_dependency(${SELF_EXE} xo_jit)
|
||||
#xo_dependency(${SELF_EXE} xo_expression)
|
||||
endif()
|
||||
|
||||
# end CMakeLists.txt
|
||||
173
xo-jit/example/ex1/ex1.cpp
Normal file
173
xo-jit/example/ex1/ex1.cpp
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/** @file ex1.cpp **/
|
||||
|
||||
#include "xo/jit/MachPipeline.hpp"
|
||||
#include "xo/expression/Constant.hpp"
|
||||
#include "xo/expression/Primitive.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
#include "xo/expression/Lambda.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/IR/BasicBlock.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/Passes/PassBuilder.h"
|
||||
#include "llvm/Passes/StandardInstrumentations.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Scalar/GVN.h"
|
||||
#include "llvm/Transforms/Scalar/Reassociate.h"
|
||||
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
|
||||
|
||||
//double foo(double x) { return x; }
|
||||
|
||||
int
|
||||
main() {
|
||||
using xo::scope;
|
||||
using xo::jit::MachPipeline;
|
||||
using xo::ast::make_constant;
|
||||
using xo::ast::make_primitive;
|
||||
using xo::ast::llvmintrinsic;
|
||||
using xo::ast::make_apply;
|
||||
using xo::ast::make_var;
|
||||
using xo::ast::make_lambda;
|
||||
using xo::reflect::Reflect;
|
||||
using xo::xtag;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
//using xo::ast::make_constant;
|
||||
|
||||
static llvm::ExitOnError llvm_exit_on_err;
|
||||
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
llvm::InitializeNativeTargetAsmParser();
|
||||
|
||||
//auto jit = llvm_exit_on_err(Jit::make_aux());
|
||||
auto jit = MachPipeline::make();
|
||||
|
||||
//static_assert(std::is_function_v<decltype(&foo)>);
|
||||
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
{
|
||||
auto expr = make_constant(7.0);
|
||||
|
||||
log && log(xtag("expr", expr));
|
||||
|
||||
auto llvm_ircode = jit->codegen_toplevel(expr);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", expr)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto expr = make_primitive("sqrt", &sqrt,
|
||||
false /*!explicit_symbol_def*/,
|
||||
llvmintrinsic::fp_sqrt);
|
||||
|
||||
log && log(xtag("expr", expr));
|
||||
|
||||
auto llvm_ircode = jit->codegen_toplevel(expr);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", expr)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* (sqrt 2) */
|
||||
|
||||
auto fn = make_primitive("sqrt", &sqrt,
|
||||
false /*!explicit_symbol_def*/,
|
||||
llvmintrinsic::fp_sqrt);
|
||||
auto arg = make_constant(2.0);
|
||||
|
||||
auto call = make_apply(fn, {arg});
|
||||
|
||||
log && log(xtag("expr", call));
|
||||
|
||||
auto llvm_ircode = jit->codegen_toplevel(call);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", call)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* (lambda (x) (sin (cos x))) */
|
||||
|
||||
auto sin = make_primitive("sin",
|
||||
::sin,
|
||||
false /*!explicit_symbol_def*/,
|
||||
llvmintrinsic::fp_sin);
|
||||
auto cos = make_primitive("cos",
|
||||
::cos,
|
||||
false /*!explicit_symbol_def*/,
|
||||
llvmintrinsic::fp_cos);
|
||||
|
||||
auto x_var = make_var("x", Reflect::require<double>());
|
||||
auto call1 = make_apply(cos, {x_var}); /* (cos x) */
|
||||
auto call2 = make_apply(sin, {call1}); /* (sin (cos x)) */
|
||||
|
||||
/* (define (lm_1 x) (sin (cos x))) */
|
||||
auto lambda = make_lambda("lm_1",
|
||||
{x_var},
|
||||
call2);
|
||||
|
||||
log && log(xtag("expr", lambda));
|
||||
|
||||
auto llvm_ircode = jit->codegen_toplevel(lambda);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", lambda)
|
||||
<< endl;
|
||||
}
|
||||
|
||||
/* is this in module? */
|
||||
cerr << "ex1: jit execution session" << endl;
|
||||
jit->dump_execution_session();
|
||||
}
|
||||
}
|
||||
|
||||
/** end ex1.cpp **/
|
||||
12
xo-jit/example/ex2_jit/CMakeLists.txt
Normal file
12
xo-jit/example/ex2_jit/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# xo-jit/example/ex2_jit/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_jit_ex2)
|
||||
set(SELF_SRCS ex2_jit.cpp)
|
||||
|
||||
if (XO_ENABLE_EXAMPLES)
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
xo_self_dependency(${SELF_EXE} xo_jit)
|
||||
#xo_dependency(${SELF_EXE} xo_expression)
|
||||
endif()
|
||||
|
||||
# end CMakeLists.txt
|
||||
170
xo-jit/example/ex2_jit/ex2_jit.cpp
Normal file
170
xo-jit/example/ex2_jit/ex2_jit.cpp
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/** @file ex2_jit.cpp **/
|
||||
|
||||
#include "xo/jit/MachPipeline.hpp"
|
||||
#include "xo/jit/activation_record.hpp"
|
||||
#include "xo/expression/Constant.hpp"
|
||||
#include "xo/expression/Primitive.hpp"
|
||||
#include "xo/expression/Apply.hpp"
|
||||
#include "xo/expression/Lambda.hpp"
|
||||
#include "xo/expression/Variable.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/IR/BasicBlock.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/Passes/PassBuilder.h"
|
||||
#include "llvm/Passes/StandardInstrumentations.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Scalar/GVN.h"
|
||||
#include "llvm/Transforms/Scalar/Reassociate.h"
|
||||
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
|
||||
|
||||
//double foo(double x) { return x; }
|
||||
|
||||
int
|
||||
main() {
|
||||
using xo::scope;
|
||||
using xo::jit::MachPipeline;
|
||||
using xo::jit::activation_record;
|
||||
using xo::ast::make_constant;
|
||||
using xo::ast::make_primitive;
|
||||
using xo::ast::llvmintrinsic;
|
||||
using xo::ast::make_apply;
|
||||
using xo::ast::make_var;
|
||||
using xo::ast::make_lambda;
|
||||
using xo::reflect::Reflect;
|
||||
using xo::xtag;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
//using xo::ast::make_constant;
|
||||
|
||||
static llvm::ExitOnError llvm_exit_on_err;
|
||||
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
llvm::InitializeNativeTargetAsmParser();
|
||||
|
||||
//auto jit = llvm_exit_on_err(Jit::make_aux());
|
||||
auto jit = MachPipeline::make();
|
||||
|
||||
//static_assert(std::is_function_v<decltype(&foo)>);
|
||||
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
/* try spelling everything out */
|
||||
|
||||
{
|
||||
auto sqrt = make_primitive("sqrt",
|
||||
::sqrt,
|
||||
false /*!explicit_symbol_def*/,
|
||||
llvmintrinsic::fp_sqrt);
|
||||
|
||||
{
|
||||
auto llvm_ircode = jit->codegen_toplevel(sqrt);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", sqrt)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
#define CHOICE 2
|
||||
|
||||
#if CHOICE == 0
|
||||
#define FUNCTION_SYMBOL "callit"
|
||||
/* def callit(f :: double->double, x :: double) { f(x); } */
|
||||
|
||||
auto f_var = make_var("f", Reflect::require<double (*)(double)>());
|
||||
auto x_var = make_var("x", Reflect::require<double>());
|
||||
auto call1 = make_apply(f_var, {x_var}); /* (f x) */
|
||||
//auto call2 = make_apply(f_var, {call1}); /* (f (f x)) */
|
||||
|
||||
auto lambda = make_lambda("callit",
|
||||
{f_var, x_var},
|
||||
call1);
|
||||
#elif CHOICE == 1
|
||||
#define FUNCTION_SYMBOL "root4"
|
||||
/* def root4(x : double) { sqrt(sqrt(x)) } */
|
||||
|
||||
auto x_var = make_var("x", Reflect::require<double>());
|
||||
auto call1 = make_apply(sqrt, {x_var});
|
||||
auto call2 = make_apply(sqrt, {call1});
|
||||
|
||||
auto lambda = make_lambda("root4",
|
||||
{x_var},
|
||||
call2);
|
||||
#elif CHOICE == 2
|
||||
#define FUNCTION_SYMBOL "twice"
|
||||
auto root = make_primitive("sqrt",
|
||||
::sqrt,
|
||||
false /*!explicit_symbol_def*/,
|
||||
llvmintrinsic::fp_sqrt);
|
||||
|
||||
/* def twice(f :: int->int, x :: int) { f(f(x)) } */
|
||||
auto f_var = make_var("f", Reflect::require<int (*)(int)>());
|
||||
auto x_var = make_var("x", Reflect::require<int>());
|
||||
auto call1 = make_apply(f_var, {x_var}); /* (f x) */
|
||||
auto call2 = make_apply(f_var, {call1}); /* (f (f x)) */
|
||||
|
||||
/* (define (twice f ::int->int x ::int) (f (f x))) */
|
||||
auto lambda = make_lambda("twice",
|
||||
{f_var, x_var},
|
||||
call2);
|
||||
#endif
|
||||
|
||||
log && log(xtag("lambda", lambda));
|
||||
|
||||
auto llvm_ircode = jit->codegen_toplevel(lambda);
|
||||
|
||||
if (llvm_ircode) {
|
||||
/* note: llvm:errs() is 'raw stderr stream' */
|
||||
cerr << "ex1 llvm_ircode:" << endl;
|
||||
llvm_ircode->print(llvm::errs());
|
||||
cerr << endl;
|
||||
} else {
|
||||
cerr << "ex1: code generation failed"
|
||||
<< xtag("expr", lambda)
|
||||
<< endl;
|
||||
}
|
||||
|
||||
jit->machgen_current_module();
|
||||
|
||||
/* is this in module? */
|
||||
cerr << "ex2: jit execution session" << endl;
|
||||
jit->dump_execution_session();
|
||||
|
||||
auto fn = jit->lookup_symbol(FUNCTION_SYMBOL);
|
||||
|
||||
if (!fn) {
|
||||
cerr << "ex2: lookup: symbol not found"
|
||||
<< xtag("symbol", FUNCTION_SYMBOL)
|
||||
<< endl;
|
||||
} else {
|
||||
cerr << "ex2: lookup: symbol found"
|
||||
<< xtag("fn", fn.get().getValue())
|
||||
<< xtag("symbol", FUNCTION_SYMBOL)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** end ex2_jit.cpp **/
|
||||
12
xo-jit/example/ex3_fptr/CMakeLists.txt
Normal file
12
xo-jit/example/ex3_fptr/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# xo-jit/example/ex3_fptr/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_fptr_ex3)
|
||||
set(SELF_SRCS ex3_fptr.cpp)
|
||||
|
||||
if (XO_ENABLE_EXAMPLES)
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
xo_self_dependency(${SELF_EXE} xo_jit)
|
||||
#xo_dependency(${SELF_EXE} xo_expression)
|
||||
endif()
|
||||
|
||||
# end CMakeLists.txt
|
||||
45
xo-jit/example/ex3_fptr/ex3_fptr.cpp
Normal file
45
xo-jit/example/ex3_fptr/ex3_fptr.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
int main() {
|
||||
llvm::LLVMContext context;
|
||||
llvm::IRBuilder<> builder(context);
|
||||
llvm::Module *module = new llvm::Module("top", context);
|
||||
|
||||
// Create main function and basic block
|
||||
llvm::FunctionType *functionType = llvm::FunctionType::get(builder.getInt32Ty(), false);
|
||||
llvm::Function *mainFunction = llvm::Function::Create(functionType, llvm::Function::ExternalLinkage, "main", module);
|
||||
llvm::BasicBlock *entry = llvm::BasicBlock::Create(context, "entrypoint", mainFunction);
|
||||
builder.SetInsertPoint(entry);
|
||||
|
||||
// Create a global string pointer
|
||||
llvm::Value *helloWorld = builder.CreateGlobalStringPtr("hello world\n");
|
||||
|
||||
// Create function pointer for puts
|
||||
std::vector<llvm::Type *> putArgs;
|
||||
putArgs.push_back(builder.getInt8Ty()->getPointerTo());
|
||||
llvm::ArrayRef<llvm::Type *> argsRef(putArgs);
|
||||
llvm::FunctionType *putsType = llvm::FunctionType::get(builder.getInt32Ty(), argsRef, false);
|
||||
/* = FunctionType + Callee-pointer */
|
||||
llvm::FunctionCallee putFunction_callee = module->getOrInsertFunction("puts", putsType);
|
||||
|
||||
#ifdef NOT_YET
|
||||
llvm::Constant * putFunction = llvm::Constant
|
||||
|
||||
// Allocate memory for the function pointer
|
||||
llvm::Value *p = builder.CreateAlloca(putFunction->getType(), nullptr, "p");
|
||||
builder.CreateStore(putFunction, p, false);
|
||||
|
||||
// Load the function pointer and call it
|
||||
llvm::Value *temp = builder.CreateLoad(p);
|
||||
builder.CreateCall(temp, helloWorld);
|
||||
|
||||
// Return 0 to complete the main function
|
||||
builder.CreateRet(llvm::ConstantInt::get(builder.getInt32Ty(), 0));
|
||||
|
||||
// Print the module (IR code)
|
||||
module->print(llvm::errs(), nullptr);
|
||||
#endif
|
||||
}
|
||||
6
xo-jit/example/ex_cpp/README
Normal file
6
xo-jit/example/ex_cpp/README
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Not including this in build for now.
|
||||
Instead, use to manually generate .ll output:
|
||||
|
||||
$ clang -cc1 ex_cpp.cpp -emit-llvm
|
||||
|
||||
and inspect ex_cpp.ll
|
||||
40
xo-jit/example/ex_cpp/ex_cpp.cpp
Normal file
40
xo-jit/example/ex_cpp/ex_cpp.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
struct env_type;
|
||||
|
||||
struct closure_type {
|
||||
double (*fnptr)(env_type * env, double x);
|
||||
env_type * envptr;
|
||||
};
|
||||
|
||||
double
|
||||
sqrt(double x) {
|
||||
return x/100;
|
||||
}
|
||||
|
||||
double
|
||||
wrap_sqrt(env_type * env, double x) {
|
||||
return ::sqrt(x);
|
||||
}
|
||||
|
||||
double twice(env_type * env, closure_type fnclosure, double x) {
|
||||
double tmp1 = (*fnclosure.fnptr)(fnclosure.envptr, x);
|
||||
double tmp2 = (*fnclosure.fnptr)(fnclosure.envptr, tmp1);
|
||||
|
||||
return tmp2;
|
||||
}
|
||||
|
||||
closure_type make_some_closure()
|
||||
{
|
||||
closure_type closure;
|
||||
closure.fnptr = &wrap_sqrt;
|
||||
closure.envptr = nullptr;
|
||||
|
||||
return closure;
|
||||
}
|
||||
|
||||
int main() {
|
||||
closure_type closure = make_some_closure();
|
||||
|
||||
double y = twice(nullptr, closure, 4.0);
|
||||
|
||||
//std::cout << "y=" << y << std::endl;
|
||||
}
|
||||
108
xo-jit/example/ex_cpp/ex_cpp.ll
Normal file
108
xo-jit/example/ex_cpp/ex_cpp.ll
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
; ModuleID = 'ex_cpp.cpp'
|
||||
source_filename = "ex_cpp.cpp"
|
||||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
%struct.closure_type = type { ptr, ptr }
|
||||
|
||||
; Function Attrs: mustprogress noinline nounwind optnone
|
||||
define dso_local noundef double @_Z4sqrtd(double noundef %x) #0 {
|
||||
entry:
|
||||
%x.addr = alloca double, align 8
|
||||
store double %x, ptr %x.addr, align 8
|
||||
%0 = load double, ptr %x.addr, align 8
|
||||
%div = fdiv double %0, 1.000000e+02
|
||||
ret double %div
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress noinline nounwind optnone
|
||||
define dso_local noundef double @_Z9wrap_sqrtP8env_typed(ptr noundef %env, double noundef %x) #0 {
|
||||
entry:
|
||||
%env.addr = alloca ptr, align 8
|
||||
%x.addr = alloca double, align 8
|
||||
store ptr %env, ptr %env.addr, align 8
|
||||
store double %x, ptr %x.addr, align 8
|
||||
%0 = load double, ptr %x.addr, align 8
|
||||
%call = call noundef double @_Z4sqrtd(double noundef %0)
|
||||
ret double %call
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress noinline nounwind optnone
|
||||
define dso_local noundef double @_Z5twiceP8env_type12closure_typed(ptr noundef %env, ptr %fnclosure.coerce0, ptr %fnclosure.coerce1, double noundef %x) #0 {
|
||||
entry:
|
||||
%fnclosure = alloca %struct.closure_type, align 8
|
||||
%env.addr = alloca ptr, align 8
|
||||
%x.addr = alloca double, align 8
|
||||
%tmp1 = alloca double, align 8
|
||||
%tmp2 = alloca double, align 8
|
||||
%0 = getelementptr inbounds { ptr, ptr }, ptr %fnclosure, i32 0, i32 0
|
||||
store ptr %fnclosure.coerce0, ptr %0, align 8
|
||||
%1 = getelementptr inbounds { ptr, ptr }, ptr %fnclosure, i32 0, i32 1
|
||||
store ptr %fnclosure.coerce1, ptr %1, align 8
|
||||
store ptr %env, ptr %env.addr, align 8
|
||||
store double %x, ptr %x.addr, align 8
|
||||
%fnptr = getelementptr inbounds %struct.closure_type, ptr %fnclosure, i32 0, i32 0
|
||||
%2 = load ptr, ptr %fnptr, align 8
|
||||
%envptr = getelementptr inbounds %struct.closure_type, ptr %fnclosure, i32 0, i32 1
|
||||
%3 = load ptr, ptr %envptr, align 8
|
||||
%4 = load double, ptr %x.addr, align 8
|
||||
%call = call noundef double %2(ptr noundef %3, double noundef %4)
|
||||
store double %call, ptr %tmp1, align 8
|
||||
%fnptr1 = getelementptr inbounds %struct.closure_type, ptr %fnclosure, i32 0, i32 0
|
||||
%5 = load ptr, ptr %fnptr1, align 8
|
||||
%envptr2 = getelementptr inbounds %struct.closure_type, ptr %fnclosure, i32 0, i32 1
|
||||
%6 = load ptr, ptr %envptr2, align 8
|
||||
%7 = load double, ptr %tmp1, align 8
|
||||
%call3 = call noundef double %5(ptr noundef %6, double noundef %7)
|
||||
store double %call3, ptr %tmp2, align 8
|
||||
%8 = load double, ptr %tmp2, align 8
|
||||
ret double %8
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress noinline nounwind optnone
|
||||
define dso_local { ptr, ptr } @_Z17make_some_closurev() #0 {
|
||||
entry:
|
||||
%retval = alloca %struct.closure_type, align 8
|
||||
%fnptr = getelementptr inbounds %struct.closure_type, ptr %retval, i32 0, i32 0
|
||||
store ptr @_Z9wrap_sqrtP8env_typed, ptr %fnptr, align 8
|
||||
%envptr = getelementptr inbounds %struct.closure_type, ptr %retval, i32 0, i32 1
|
||||
store ptr null, ptr %envptr, align 8
|
||||
%0 = load { ptr, ptr }, ptr %retval, align 8
|
||||
ret { ptr, ptr } %0
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress noinline norecurse nounwind optnone
|
||||
define dso_local noundef i32 @main() #1 {
|
||||
entry:
|
||||
%closure = alloca %struct.closure_type, align 8
|
||||
%y = alloca double, align 8
|
||||
%agg.tmp = alloca %struct.closure_type, align 8
|
||||
%call = call { ptr, ptr } @_Z17make_some_closurev()
|
||||
%0 = getelementptr inbounds { ptr, ptr }, ptr %closure, i32 0, i32 0
|
||||
%1 = extractvalue { ptr, ptr } %call, 0
|
||||
store ptr %1, ptr %0, align 8
|
||||
%2 = getelementptr inbounds { ptr, ptr }, ptr %closure, i32 0, i32 1
|
||||
%3 = extractvalue { ptr, ptr } %call, 1
|
||||
store ptr %3, ptr %2, align 8
|
||||
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %agg.tmp, ptr align 8 %closure, i64 16, i1 false)
|
||||
%4 = getelementptr inbounds { ptr, ptr }, ptr %agg.tmp, i32 0, i32 0
|
||||
%5 = load ptr, ptr %4, align 8
|
||||
%6 = getelementptr inbounds { ptr, ptr }, ptr %agg.tmp, i32 0, i32 1
|
||||
%7 = load ptr, ptr %6, align 8
|
||||
%call1 = call noundef double @_Z5twiceP8env_type12closure_typed(ptr noundef null, ptr %5, ptr %7, double noundef 4.000000e+00)
|
||||
store double %call1, ptr %y, align 8
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
|
||||
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2
|
||||
|
||||
attributes #0 = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
|
||||
attributes #1 = { mustprogress noinline norecurse nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
|
||||
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
||||
|
||||
!llvm.module.flags = !{!0}
|
||||
!llvm.ident = !{!1}
|
||||
|
||||
!0 = !{i32 1, !"wchar_size", i32 4}
|
||||
!1 = !{!"clang version 18.1.5"}
|
||||
58
xo-jit/example/ex_cpp/tmp.ll
Normal file
58
xo-jit/example/ex_cpp/tmp.ll
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
define double @root4(ptr %.env, double %x) {
|
||||
entry:
|
||||
%x1 = alloca double, align 8
|
||||
store double %x, ptr %x1, align 8
|
||||
%x2 = load double, ptr %x1, align 8
|
||||
%calltmp = call double @w.sqrt(ptr null, double %x2)
|
||||
%calltmp3 = call double @w.sqrt(ptr null, double %calltmp)
|
||||
ret double %calltmp3
|
||||
}
|
||||
|
||||
; ----------------------------------------------------------------
|
||||
|
||||
define double @twice(ptr %.env, { ptr, ptr } %f, double %x) {
|
||||
entry:
|
||||
%f1 = alloca { ptr, ptr }, align 8
|
||||
store { ptr, ptr } %f, ptr %f1, align 8
|
||||
%x2 = alloca double, align 8
|
||||
store double %x, ptr %x2, align 8
|
||||
%f3 = load { ptr, ptr }, ptr %f1, align 8
|
||||
%fnptr = extractvalue { ptr, ptr } %f3, 0
|
||||
%envptr = extractvalue { ptr, ptr } %f3, 1
|
||||
%f4 = load { ptr, ptr }, ptr %f1, align 8
|
||||
%fnptr5 = extractvalue { ptr, ptr } %f4, 0
|
||||
%envptr6 = extractvalue { ptr, ptr } %f4, 1
|
||||
%x7 = load double, ptr %x2, align 8
|
||||
%calltmp = call double %fnptr5(ptr %envptr6, double %x7)
|
||||
%calltmp8 = call double %fnptr(ptr %envptr, double %calltmp)
|
||||
ret double %calltmp8
|
||||
}
|
||||
|
||||
|
||||
define double @twice(ptr %.env, { ptr, ptr } %f, double %x) {
|
||||
entry:
|
||||
%f1 = alloca { ptr, ptr }, align 8
|
||||
%f.elt = extractvalue { ptr, ptr } %f, 0
|
||||
store ptr %f.elt, ptr %f1, align 8
|
||||
%f1.repack9 = getelementptr inbounds { ptr, ptr }, ptr %f1, i64 0, i32 1
|
||||
%f.elt10 = extractvalue { ptr, ptr } %f, 1
|
||||
store ptr %f.elt10, ptr %f1.repack9, align 8
|
||||
%calltmp = call double %f.elt(ptr %f.elt10, double %x)
|
||||
%calltmp8 = call double %f.elt(ptr %f.elt10, double %calltmp)
|
||||
ret double %calltmp8
|
||||
}
|
||||
|
||||
|
||||
;; ----------------------------------------------------------------
|
||||
|
||||
define double @root_2x(ptr %.env, double %x2) {
|
||||
entry:
|
||||
%x21 = alloca double, align 8
|
||||
store double %x2, ptr %x21, align 8
|
||||
%envptr = insertvalue { ptr, ptr } { ptr @twice, ptr undef }, ptr %.env, 1
|
||||
%fnptr = extractvalue { ptr, ptr } %envptr, 0
|
||||
%envptr2 = extractvalue { ptr, ptr } %envptr, 1
|
||||
%x23 = load double, ptr %x21, align 8
|
||||
%calltmp = call double %fnptr(ptr %envptr2, { ptr, ptr } { ptr @w.sqrt, ptr null }, double %x23)
|
||||
ret double %calltmp
|
||||
}
|
||||
12
xo-jit/example/ex_kaleidoscope4/CMakeLists.txt
Normal file
12
xo-jit/example/ex_kaleidoscope4/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# xo-jit/example/ex1/CMakeLists.txt
|
||||
|
||||
set(SELF_EXE xo_kaleidoscope4)
|
||||
set(SELF_SRCS ex_kaleidoscope4.cpp)
|
||||
|
||||
if (XO_ENABLE_EXAMPLES)
|
||||
xo_add_executable(${SELF_EXE} ${SELF_SRCS})
|
||||
xo_self_dependency(${SELF_EXE} xo_jit)
|
||||
#xo_dependency(${SELF_EXE} xo_expression)
|
||||
endif()
|
||||
|
||||
# end CMakeLists.txt
|
||||
16
xo-jit/example/ex_kaleidoscope4/ex_kaleidoscope4.cpp
Normal file
16
xo-jit/example/ex_kaleidoscope4/ex_kaleidoscope4.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/** ex_kaleidoscop4.cpp **/
|
||||
|
||||
#include "xo/jit/Jit.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main() {
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
//auto jit = xo::jit::KaleidoscopeJIT::Create();
|
||||
|
||||
//cerr << "created kaleidoscope jit successfully" << endl;
|
||||
}
|
||||
|
||||
/** end ex_kaleidoscope4.cpp **/
|
||||
Loading…
Add table
Add a link
Reference in a new issue