xo-jit: setup analsysis pipeline (most of kaleidoscope4)
This commit is contained in:
parent
f7dfd67770
commit
f7db84972f
2 changed files with 48 additions and 3 deletions
|
|
@ -79,7 +79,10 @@ namespace xo {
|
|||
|
||||
/** target triple = string describing target host for codegen **/
|
||||
const std::string & target_triple() const;
|
||||
/** append function names defined in attached module to *p_v **/
|
||||
/** append function names defined in attached module to *p_v
|
||||
*
|
||||
* (RC 15jun2024 - this part is working)
|
||||
**/
|
||||
std::vector<std::string> get_function_name_v();
|
||||
|
||||
/** write state of execution session (all the associated dynamic libraries) **/
|
||||
|
|
@ -148,8 +151,27 @@ namespace xo {
|
|||
std::map<std::string, xo::ref::rp<Expression>> global_env_;
|
||||
/** map variable names (formal parameters) to
|
||||
* corresponding llvm interactor
|
||||
*
|
||||
* only supports one level atm (i.e. only top-level functions)
|
||||
**/
|
||||
std::map<std::string, llvm::Value*> nested_env_;
|
||||
|
||||
// ----- transforms (also adapted from kaleidescope.cpp) ------
|
||||
|
||||
/** manages all the passes+analaysis (?) **/
|
||||
std::unique_ptr<llvm::FunctionPassManager> llvm_fpmgr_;
|
||||
/** loop analysis (?) **/
|
||||
std::unique_ptr<llvm::LoopAnalysisManager> llvm_lamgr_;
|
||||
/** function-level analysis (?) **/
|
||||
std::unique_ptr<llvm::FunctionAnalysisManager> llvm_famgr_;
|
||||
/** cgscc (?) analysis **/
|
||||
std::unique_ptr<llvm::CGSCCAnalysisManager> llvm_cgamgr_;
|
||||
/** module analsyis (?) **/
|
||||
std::unique_ptr<llvm::ModuleAnalysisManager> llvm_mamgr_;
|
||||
/** pass instrumentation **/
|
||||
std::unique_ptr<llvm::PassInstrumentationCallbacks> llvm_pic_;
|
||||
/** standard instrumentation **/
|
||||
std::unique_ptr<llvm::StandardInstrumentations> llvm_si_;
|
||||
}; /*Jit*/
|
||||
|
||||
inline std::ostream &
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ namespace xo {
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
static llvm::ExitOnError llvm_exit_on_err;
|
||||
|
||||
std::unique_ptr<KaleidoscopeJIT> kal_jit = llvm_exit_on_err(KaleidoscopeJIT::Create());
|
||||
|
|
@ -139,6 +140,28 @@ namespace xo {
|
|||
if (!llvm_module_.get()) {
|
||||
throw std::runtime_error("Jit::ctor: expected non-empty llvm module");
|
||||
}
|
||||
|
||||
this->llvm_fpmgr_ = std::make_unique<llvm::FunctionPassManager>();
|
||||
this->llvm_lamgr_ = std::make_unique<llvm::LoopAnalysisManager>();
|
||||
this->llvm_famgr_ = std::make_unique<llvm::FunctionAnalysisManager>();
|
||||
this->llvm_cgamgr_ = std::make_unique<llvm::CGSCCAnalysisManager>();
|
||||
this->llvm_mamgr_ = std::make_unique<llvm::ModuleAnalysisManager>();
|
||||
this->llvm_pic_ = std::make_unique<llvm::PassInstrumentationCallbacks>();
|
||||
this->llvm_si_ = std::make_unique<llvm::StandardInstrumentations>(*llvm_cx_,
|
||||
/*DebugLogging*/ true);
|
||||
|
||||
this->llvm_si_->registerCallbacks(*llvm_pic_, llvm_mamgr_.get());
|
||||
|
||||
// TODO: llvm_fpmgr_->addPass(InstCombinePass()) etc.
|
||||
// TODO: llvm_fpmgr_->addPass(ReassociatePass()) etc.
|
||||
// TODO: llvm_fpmgr_->addPass(GVNPasss()) etc.
|
||||
// TODO: llvm_fpmgr_->addPass(SimplifyCFGPass()) etc.
|
||||
|
||||
/** tracking for analysis passes that share info? **/
|
||||
llvm::PassBuilder llvm_pass_builder;
|
||||
llvm_pass_builder.registerModuleAnalyses(*llvm_mamgr_);
|
||||
llvm_pass_builder.registerFunctionAnalyses(*llvm_famgr_);
|
||||
llvm_pass_builder.crossRegisterProxies(*llvm_lamgr_, *llvm_famgr_, *llvm_cgamgr_, *llvm_mamgr_);
|
||||
}
|
||||
|
||||
const std::string &
|
||||
|
|
@ -389,8 +412,8 @@ namespace xo {
|
|||
/* validate! always validate! */
|
||||
llvm::verifyFunction(*fn);
|
||||
|
||||
/* optimize! */
|
||||
// thefpm->run(*fn, *thefam);
|
||||
/* optimize! does this generate code? */
|
||||
llvm_fpmgr_->run(*fn, *llvm_famgr_);
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue