xo-jit: compiler nit: (clang 15)
This commit is contained in:
parent
9439f0f221
commit
855887df71
7 changed files with 2607 additions and 0 deletions
66
include/xo/jit/activation_record.new.hpp
Normal file
66
include/xo/jit/activation_record.new.hpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/** @file activation_record.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LlvmContext.hpp"
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
# include <llvm/IR/IRBuilder.h>
|
||||
# include <llvm/IR/Instructions.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <map>
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace jit {
|
||||
/** scope for a stack frame associated with a user-defined function
|
||||
*
|
||||
* each function needs its own IR builder, to keep track of things like insert point
|
||||
**/
|
||||
class activation_record {
|
||||
public:
|
||||
activation_record(llvm::Function * llvm_fn,
|
||||
llvm::AllocaInst * frame) : frame_{frame} {
|
||||
int i_arg = 0;
|
||||
for (auto & arg : llvm_fn->args()) {
|
||||
std::string arg_name = std::string(arg.getName());
|
||||
|
||||
name2ix_map_[arg_name] = 2 + i_arg;
|
||||
}
|
||||
}
|
||||
|
||||
std::int32_t lookup_var(const std::string & var_name) const;
|
||||
|
||||
#ifdef OBSOLETE
|
||||
llvm::AllocaInst * lookup_var(const std::string & var_name) const;
|
||||
|
||||
llvm::AllocaInst * alloc_var(const std::string & var_name,
|
||||
llvm::AllocaInst * alloca);
|
||||
#endif
|
||||
|
||||
private:
|
||||
/** stack frame for a user-defined function (lambda) **/
|
||||
llvm::AllocaInst * frame_ = nullptr;
|
||||
|
||||
/** for each formal parameter,
|
||||
* reports its position in stack frame.
|
||||
* This is the position to use with getelementptr,
|
||||
* i.e. +2 to skip first two slots, that are reserved
|
||||
* for nextframe pointer (slot 0) + unwind pointer (slot 1)
|
||||
**/
|
||||
std::map<std::string, std::int32_t> name2ix_map_;
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/** maps named slots in a stack frame to logical addresses **/
|
||||
std::map<std::string, llvm::AllocaInst*> frame_; /* <-> kaleidoscope NamedValues */
|
||||
#endif
|
||||
}; /*activation_record*/
|
||||
|
||||
} /*namespace jit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/** end activation_record.hpp **/
|
||||
41
include/xo/jit/activation_record.orig.hpp
Normal file
41
include/xo/jit/activation_record.orig.hpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/** @file activation_record.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LlvmContext.hpp"
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
# include <llvm/IR/IRBuilder.h>
|
||||
# include <llvm/IR/Instructions.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <map>
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace jit {
|
||||
/** scope for a stack frame associated with a user-defined function
|
||||
*
|
||||
* each function needs its own IR builder, to keep track of things like insert point
|
||||
**/
|
||||
class activation_record {
|
||||
public:
|
||||
activation_record() = default;
|
||||
|
||||
llvm::AllocaInst * lookup_var(const std::string & var_name) const;
|
||||
|
||||
llvm::AllocaInst * alloc_var(const std::string & var_name,
|
||||
llvm::AllocaInst * alloca);
|
||||
|
||||
private:
|
||||
/** maps named slots in a stack frame to logical addresses **/
|
||||
std::map<std::string, llvm::AllocaInst*> frame_; /* <-> kaleidoscope NamedValues */
|
||||
}; /*activation_record*/
|
||||
|
||||
} /*namespace jit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/** end activation_record.hpp **/
|
||||
|
|
@ -8,7 +8,10 @@
|
|||
#include "LlvmContext.hpp"
|
||||
#include "xo/expression/Lambda.hpp"
|
||||
#include "xo/reflect/TypeDescr.hpp"
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#include <llvm/IR/DerivedTypes.h>
|
||||
#pragma GCC diagnostic pop
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
1341
src/jit/MachPipeline.new.cpp
Normal file
1341
src/jit/MachPipeline.new.cpp
Normal file
File diff suppressed because it is too large
Load diff
1064
src/jit/MachPipeline.orig.cpp
Normal file
1064
src/jit/MachPipeline.orig.cpp
Normal file
File diff suppressed because it is too large
Load diff
47
src/jit/activation_record.new.cpp
Normal file
47
src/jit/activation_record.new.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* @file activation_record.cpp */
|
||||
|
||||
#include "activation_record.hpp"
|
||||
#include "xo/indentlog/print/tag.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
namespace jit {
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
int32_t
|
||||
activation_record::lookup_var(const std::string & x) const {
|
||||
|
||||
auto ix = name2ix_map_.find(x);
|
||||
|
||||
if (ix == name2ix_map_.end()) {
|
||||
cerr << "activation_record::lookup_var: no binding for variable x"
|
||||
<< xtag("x", x)
|
||||
<< endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ix->second;
|
||||
} /*lookup_var*/
|
||||
|
||||
#ifdef OBSOLETE
|
||||
llvm::AllocaInst *
|
||||
activation_record::alloc_var(const std::string & x,
|
||||
llvm::AllocaInst * alloca)
|
||||
{
|
||||
if (frame_.find(x) != frame_.end()) {
|
||||
cerr << "activation_record::alloc_var: variable x already present in frame"
|
||||
<< xtag("x", x)
|
||||
<< endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
frame_[x] = alloca;
|
||||
return alloca;
|
||||
} /*alloc_var*/
|
||||
#endif
|
||||
} /*namespace jit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end activation_record.cpp */
|
||||
45
src/jit/activation_record.orig.cpp
Normal file
45
src/jit/activation_record.orig.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* @file activation_record.cpp */
|
||||
|
||||
#include "activation_record.hpp"
|
||||
#include "xo/indentlog/print/tag.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
namespace jit {
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
llvm::AllocaInst *
|
||||
activation_record::lookup_var(const std::string & x) const {
|
||||
|
||||
auto ix = frame_.find(x);
|
||||
|
||||
if (ix == frame_.end()) {
|
||||
cerr << "activation_record::lookup_var: no binding for variable x"
|
||||
<< xtag("x", x)
|
||||
<< endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ix->second;
|
||||
} /*lookup_var*/
|
||||
|
||||
llvm::AllocaInst *
|
||||
activation_record::alloc_var(const std::string & x,
|
||||
llvm::AllocaInst * alloca)
|
||||
{
|
||||
if (frame_.find(x) != frame_.end()) {
|
||||
cerr << "activation_record::alloc_var: variable x already present in frame"
|
||||
<< xtag("x", x)
|
||||
<< endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
frame_[x] = alloca;
|
||||
return alloca;
|
||||
} /*alloc_var*/
|
||||
} /*namespace jit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end activation_record.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue