利用ESL pass出现的问题
程序员文章站
2023-12-25 16:52:51
...
1、没有ESL_pass中的hw_flow.cc没有inline,修改后的代码为:
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil -*- */
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 expandtab: */
//============================================================================
// Copyright (c) 2011, All Right Reserved, Nimbus Automation Technologies
//
// file: hw_flow.cc
// author: Zuowei Li
// purpose: pure hardware flow
// revision history:
//============================================================================
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Linker/Linker.h"
#include "tcl/commands.h"
//#include "tools/arm_cross_compiler.h"
#include "tools/compiler.h"
#include "tools/link.h"
#include "tools/optimizer.h"
#include "utility/viv_hls_util.h"
using namespace llvm;
namespace esl {
const bool always_inline = true;
// Any input is generated by clang
// clang-3.5 ${name}_labeled.c -emit-llvm -c -fno-builtin -I ../lib/include/
// -m32 -I /usr/include/i386-linux-gnu -O0 -mllvm -inline-threshold=-100
// -fno-inline -fno-vectorize -fno-slp-vectorize
// -o ${name}.prelto.1.bc
bool runHW(Module& module, const std::string& output) {
#if 0
// opt -mem2reg -loops -loop-simplify < ${name}.prelto.cv.bc > ${name}.prelto.2.bc
Optimizer opt;
std::vector<std::string> pass_names = {"mem2reg", "loops", "loop-simplify"};
opt.addPass(pass_names);
opt.optimize(module);
// added by zhgu
// opt -gvn < in.bc > out.bc
opt.reset();
opt.addPass("gvn");
// opt.setOutputFileName("hw.bc");
// opt.setNoOutput(false);
opt.optimize(module);
// opt -disable-inlining -disable-opt -std-link-opts < ${name}.prelto.linked.bc -o ${name}.prelto.linked.1.bc
opt.reset();
opt.setDisableInline(true);
opt.setDisableOptimizations(true);
opt.setStandardLinkOpts(true);
opt.optimize(module);
// // opt -disable-inlining -disable-opt -legup-prelto < ${name}.prelto.linked.1.bc > ${name}.prelto.6.bc
// opt.reset();
// opt.setDisableInline(true);
// opt.setDisableOptimizations(true);
// opt.addPass("legup-prelto");
// opt.optimize(module);
//
// opt -disable-inlining -disable-opt -std-link-opts < ${name}.prelto.6.bc -o ${name}.prelto.bc
opt.reset();
opt.setDisableInline(true);
opt.setDisableOptimizations(true);
opt.setStandardLinkOpts(true);
opt.optimize(module);
// FIXME : How to link
// llvm-link ${name}.prelto.bc ../lib/llvm/liblegup.bc ../lib/llvm/libm.bc -o ${name}.postlto.6.bc
// Link link;
// std::vector<std::string> libbcs = {"liblegup.bc", "libm.bc"};
// link.doLink(module, libbcs);
// Do Not do link for now
// opt -internalize-public-api-list=main -internalize -globaldce ${name}.postlto.6.bc -o ${name}.postlto.8.bc
opt.reset();
const char * argv[] = {"opt","-internalize-public-api-list=main"};
cl::ParseCommandLineOptions(2, argv, "parser internalize-public-api\n");
pass_names.clear();
pass_names = { "internalize", "globaldce"};
opt.addPass(pass_names);
opt.optimize(module);
argv[1] = "-internalize-public-api-list=";
cl::ParseCommandLineOptions(2, argv, "");
// opt -disable-inlining -disable-opt -instcombine -std-link-opts < ${name}.postlto.8.bc -o ${name}.postlto.bc
opt.reset();
opt.setDisableInline(true);
opt.setDisableOptimizations(true);
opt.setStandardLinkOpts(true);
opt.addPass("instcombine");
// opt.setOutputFileName("postlto.bc");
// opt.setNoOutput(false);
opt.optimize(module);
// TODO indvars2
// opt -disable-inlining -disable-opt -basicaa -loop-simplify -indvars2 -loop-pipeline ${name}.postlto.bc -o ${name}.1.bc
opt.reset();
opt.setDisableInline(true);
opt.setDisableOptimizations(true);
pass_names.clear();
// pass_names = { "basicaa", "loop-simplify","loop-pipeline"};
pass_names = { "basicaa", "loop-simplify"};
opt.addPass(pass_names);
opt.optimize(module);
// opt -disable-inlining -disable-opt -instcombine ${name}.1.bc -o ${name}.bc
opt.reset();
opt.setDisableInline(true);
opt.setDisableOptimizations(true);
opt.addPass("instcombine");
opt.setOutputFileName("hw.bc");
opt.setNoOutput(false);
opt.optimize(module);
#endif
#if 1
Optimizer opt;
const char * argv[] = {"opt","-internalize-public-api-list=main"};
cl::ParseCommandLineOptions(2, argv, "parser internalize-public-api\n");
const std::vector<std::string> pass_names = { "internalize", "globaldce"};
opt.addPass(pass_names);
opt.setOutputFileName("hw.bc");
opt.setNoOutput(false);
opt.optimize(module);
#endif
// llc -march=v ${name}.bc -o ${name}.v
Compiler llc;
llc.set_march("v");
llc.set_output_file_name(output);
bool success = llc.compile(module);
return success;
}
//extern void DiagnosticHandler(const DiagnosticInfo&, void*);
std::string constrain_file_name;
int RunHW(ClientData /* data */, Tcl_Interp* interp,
int objc, Tcl_Obj* const objv[]) {
char* cmd = Tcl_GetString(objv[0]);
if (objc < 2) {
errs() << cmd << " : no input specified!\n";
return TCL_ERROR;
}
std::string input_file_name = Tcl_GetString(objv[1]);
std::string output_file_name;
if (Commands::isOptionUsed(objc, objv, "-o")) {
Commands::getStringOption(objc, objv, "-o", output_file_name);
} else {
output_file_name = "output.v";
}
constrain_file_name = "";
if (Commands::isOptionUsed(objc, objv, "-c")) {
Commands::getStringOption(objc, objv, "-c", constrain_file_name);
}
LLVMContext context;
//TODO : Set a diagnostic handler that doesn't exit on the first error
bool has_error = false;
context.setDiagnosticHandler(llvm::make_unique<CommonDiagnosticHandler>(&has_error));
// compile module
SMDiagnostic err;
std::unique_ptr<Module> m = parseIRFile(input_file_name, err, context);
if (m == NULL) {
err.print(cmd, errs());
return TCL_ERROR;
}
if (always_inline) {
// XXX
// Before runHW add always inline to each function
Module &module = *m;
for (auto i = module.begin(); i != module.end(); ++i) {
Function &func = *i;
// added by zhgu at 190225
if (func.isIntrinsic()) continue;
if (isSsdmOpFunc(&func)) continue;
func.addFnAttr(Attribute::AlwaysInline);
}
// Then run always-inline pass to inline all functions
Optimizer opt;
opt.addPass("always-inline");
opt.setOutputFileName("inline.bc");
opt.setNoOutput(false);
opt.optimize(module);
}
bool run_success = runHW(*m, output_file_name);
//if (!run_success || has_error) {
if (!run_success) {
errs() << " Run hardware flow failed !\n";
return TCL_ERROR;
}
return TCL_OK;
}
}
2、
推荐阅读
-
利用ESL pass出现的问题
-
记一次使用JAVA上转型对象出现的问题
-
C语言打印16进制出现0xffffff现象的问题剖析!
-
浏览器解析js生成的html出现样式问题的解决方法_javascript技巧
-
如何利用php实现禁用IE和火狐的缓存问题
-
PHP递归返回值时出现的问题解决办法_PHP
-
使用VueAwesomeSwiper容易出现的问题?
-
IE8下jQuery改变png图片透明度时出现的黑边问题_html/css_WEB-ITnose
-
解决idea 拉取代码出现的 “ Сannot Run Git Cannot identify version of git executable: no response“的问题
-
PHP 中 DOMDocument保存xml时中文出现乱码问题的解决方案