socsvn commit: r273573 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw
dpl at FreeBSD.org
dpl at FreeBSD.org
Wed Sep 3 18:05:05 UTC 2014
Author: dpl
Date: Wed Sep 3 18:05:04 2014
New Revision: 273573
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273573
Log:
Now deletion of the ipfwJIT object is safe for compiled code.
Modified:
soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc
Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Sep 3 18:04:11 2014 (r273572)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Sep 3 18:05:04 2014 (r273573)
@@ -47,7 +47,7 @@
class ipfwJIT {
Module *mod;
Function *Func;
- LLVMContext Con;
+ LLVMContext *Con;
IRBuilder<> Irb;
// We'll store the BasicBlock objects for each rule here.
@@ -175,7 +175,7 @@
return (NULL);
}
- auto modptr = parseBitcodeFile(buff.get().get(), Con);
+ auto modptr = parseBitcodeFile(buff.get().get(), *Con);
if ((modptr.getError())){
std::cerr << "Failed to parse bitcode: " << buff.getError() << "\n";
return (NULL);
@@ -208,10 +208,10 @@
Chain = &arglist.back();
// Get Type objects
- Int8Ty = Type::getInt8Ty(Con);
- Int16Ty = Type::getInt16Ty(Con);
- Int32Ty = Type::getInt32Ty(Con);
- Int64Ty = Type::getInt64Ty(Con);
+ Int8Ty = Type::getInt8Ty(*Con);
+ Int16Ty = Type::getInt16Ty(*Con);
+ Int32Ty = Type::getInt32Ty(*Con);
+ Int64Ty = Type::getInt64Ty(*Con);
Int8PtrTy = PointerType::getUnqual(Int8Ty);
// Get StrucType from bitcode.
@@ -401,8 +401,8 @@
void
emit_pullup_failed()
{
- BasicBlock *print = BasicBlock::Create(Con, "print", Func);
- BasicBlock *ret = BasicBlock::Create(Con, "ret", Func);
+ BasicBlock *print = BasicBlock::Create(*Con, "print", Func);
+ BasicBlock *ret = BasicBlock::Create(*Con, "ret", Func);
Value *Is_verbose, *Str, *Comp;
@@ -440,10 +440,10 @@
void
emit_check_tag()
{
- BasicBlock *Tagged = BasicBlock::Create(Con, "tagged", Func);
- BasicBlock *Nottagged = BasicBlock::Create(Con, "nottagged", Func);
- BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func);
- BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func);
+ BasicBlock *Tagged = BasicBlock::Create(*Con, "tagged", Func);
+ BasicBlock *Nottagged = BasicBlock::Create(*Con, "nottagged", Func);
+ BasicBlock *Jt = BasicBlock::Create(*Con, "jt", Func);
+ BasicBlock *Jf = BasicBlock::Create(*Con, "jf", Func);
Value *Comp;
@@ -509,7 +509,7 @@
}
public:
- ipfwJIT(int rulesnumber): Irb(Con)
+ ipfwJIT(int rulesnumber) : Con(&getGlobalContext()), Irb(*Con)
{
// Create the module and load the code.
mod = loadBitcode("rules.bc");
@@ -520,10 +520,10 @@
// The entry basic block contains all the initialization
// and allocation of resources, and a basic check done
// before start emmiting the rules code.
- Entry = BasicBlock::Create(Con, "Entry", Func);
- End = BasicBlock::Create(Con, "End", Func);
- CheckTag = BasicBlock::Create(Con, "CheckTag", Func);
- PullupFailed = BasicBlock::Create(Con, "PullupFailed", Func);
+ Entry = BasicBlock::Create(*Con, "Entry", Func);
+ End = BasicBlock::Create(*Con, "End", Func);
+ CheckTag = BasicBlock::Create(*Con, "CheckTag", Func);
+ PullupFailed = BasicBlock::Create(*Con, "PullupFailed", Func);
// Get struct types, and store vars
@@ -535,17 +535,12 @@
// Initialize the vector.
rules = std::vector<BasicBlock *>(rulesnumber);
for (auto &i: rules){
- i = BasicBlock::Create(Con, "rule", Func);
+ i = BasicBlock::Create(*Con, "rule", Func);
}
emit_check_tag();
emit_pullup_failed();
}
- ~ipfwJIT()
- {
- if (mod)
- delete mod;
- }
funcptr
compile()
@@ -553,58 +548,49 @@
InitializeNativeTarget();
LLVMLinkInJIT();
-// //Optimise
-// PassManagerBuilder PMBuilder;
-// PMBuilder.OptLevel = 1;
-// PMBuilder.Inliner = createFunctionInliningPass(275);
-
-// // Function passes
-// FunctionPassManager *PerFunctionPasses = new FunctionPassManager(mod);
-// PMBuilder.populateFunctionPassManager(*PerFunctionPasses);
-// PerFunctionPasses->run(*Func);
-// PerFunctionPasses->doFinalization();
-// delete PerFunctionPasses;
-
-// printf("Done optimizing Function\n");
-
-// // Module passes
-// PassManager *PerModulePasses = new PassManager();
-// PMBuilder.populateModulePassManager(*PerModulePasses);
-// PerModulePasses->run(*mod);
-// delete PerModulePasses;
-
-// printf("Done optimizing Module\n");
-
- // // We don't need it anymore.
- // Function *vf = mod->getFunction("voidfunction");
- // vf->eraseFromParent();
- // printf("Done erasing voidfunction\n");
+ // Optimise
+ PassManagerBuilder PMBuilder;
+ PMBuilder.OptLevel = 3;
+ PMBuilder.Inliner = createFunctionInliningPass(275);
+
+ // Function passes
+ FunctionPassManager *PerFunctionPasses = new FunctionPassManager(mod);
+ PMBuilder.populateFunctionPassManager(*PerFunctionPasses);
+ PerFunctionPasses->run(*Func);
+ PerFunctionPasses->doFinalization();
+ delete PerFunctionPasses;
+
+ // Module passes
+ PassManager *PerModulePasses = new PassManager();
+ PMBuilder.populateModulePassManager(*PerModulePasses);
+ PerModulePasses->run(*mod);
+ delete PerModulePasses;
+
+ // We don't need it anymore.
+ Function *vf = mod->getFunction("voidfunction");
+ vf->eraseFromParent();
//Compile
- std::string comperr = "Compilation error\n";
std::string errstr;
EngineBuilder EB = EngineBuilder(std::unique_ptr<Module>(mod));
EB.setEngineKind(EngineKind::Kind::JIT);
+ EB.setErrorStr(&errstr);
+ EB.setOptLevel(CodeGenOpt::Level::Aggressive);
EB.setUseMCJIT(true);
- EB.setErrorStr(&comperr);
EB.setVerifyModules(true);
- EB.setOptLevel(CodeGenOpt::Level::None);
ExecutionEngine *EE = EB.create();
if (!EE) {
- fprintf(stderr, "Error: %s\n", errstr.c_str());
+ fprintf(stderr, "Compilation error: %s\n", errstr.c_str());
exit(1);
}
- //mod->dump();
- //InspectPkt->dump();
- mod->getFunction("m_freem")->dump();
-
- printf("FuncPtr: %p\n", (void *)EE->getPointerToFunction(Func));
- //printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit"));
- err(1,"null");
- return (funcptr)EE->getFunctionAddress("ipfw_chk_jit");
+ // printf("FuncPtr: %p\n", (void *)EE->getPointerToFunction(Func));
+ // printf("FuncPtr: %p\n", (void *)EE->getPointerToNamedFunction("ipfw_chk_jit"));
+ // printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit"));
+ // return (funcptr)EE->getFunctionAddress("ipfw_chk_jit");
+ return (funcptr)EE->getPointerToFunction(mod->getFunction("ipfw_chk_jit"));
}
void
@@ -616,8 +602,8 @@
void
emit_outer_for_prologue()
{
- BasicBlock *jt = BasicBlock::Create(Con, "jt", Func);
- BasicBlock *jf = BasicBlock::Create(Con, "jf", Func);
+ BasicBlock *jt = BasicBlock::Create(*Con, "jt", Func);
+ BasicBlock *jf = BasicBlock::Create(*Con, "jf", Func);
Value *SetDisable = mod->getGlobalVariable("set_disable");
@@ -667,10 +653,10 @@
void
emit_inner_for_prologue()
{
- BasicBlock *firstt = BasicBlock::Create(Con, "firstt", Func);
- BasicBlock *firstf = BasicBlock::Create(Con, "firstf", Func);
- BasicBlock *secondt = BasicBlock::Create(Con, "secondt", Func);
- BasicBlock *secondf = BasicBlock::Create(Con, "secondf", Func);
+ BasicBlock *firstt = BasicBlock::Create(*Con, "firstt", Func);
+ BasicBlock *firstf = BasicBlock::Create(*Con, "firstf", Func);
+ BasicBlock *secondt = BasicBlock::Create(*Con, "secondt", Func);
+ BasicBlock *secondf = BasicBlock::Create(*Con, "secondf", Func);
Value *Comp, *AndOp;
@@ -741,14 +727,14 @@
void
emit_inner_for_epilogue()
{
- BasicBlock *matchnz = BasicBlock::Create(Con, "matchnz", Func);
- BasicBlock *matchz = BasicBlock::Create(Con, "matchz", Func);
- BasicBlock *jt = BasicBlock::Create(Con, "jt", Func);
- BasicBlock *sec_cond = BasicBlock::Create(Con, "sec_cond", Func);
- BasicBlock *matchzero = BasicBlock::Create(Con, "matchzero", Func);
- BasicBlock *matchnotzero = BasicBlock::Create(Con, "matchnotzero", Func);
- BasicBlock *is_or = BasicBlock::Create(Con, "is_or", Func);
- BasicBlock *Continue = BasicBlock::Create(Con, "Continue", Func);
+ BasicBlock *matchnz = BasicBlock::Create(*Con, "matchnz", Func);
+ BasicBlock *matchz = BasicBlock::Create(*Con, "matchz", Func);
+ BasicBlock *jt = BasicBlock::Create(*Con, "jt", Func);
+ BasicBlock *sec_cond = BasicBlock::Create(*Con, "sec_cond", Func);
+ BasicBlock *matchzero = BasicBlock::Create(*Con, "matchzero", Func);
+ BasicBlock *matchnotzero = BasicBlock::Create(*Con, "matchnotzero", Func);
+ BasicBlock *is_or = BasicBlock::Create(*Con, "is_or", Func);
+ BasicBlock *Continue = BasicBlock::Create(*Con, "Continue", Func);
Value *Comp, *AndOp;
@@ -851,12 +837,12 @@
{
Value *Rule, *TimeUptime, *Str;
- BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func);
- BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func);
- BasicBlock *DoCache = BasicBlock::Create(Con, "cache", Func);
- BasicBlock *Ret = BasicBlock::Create(Con, "ret", Func);
+ BasicBlock *Jt = BasicBlock::Create(*Con, "jt", Func);
+ BasicBlock *Jf = BasicBlock::Create(*Con, "jf", Func);
+ BasicBlock *DoCache = BasicBlock::Create(*Con, "cache", Func);
+ BasicBlock *Ret = BasicBlock::Create(*Con, "ret", Func);
#ifdef __FreeBSD__
- BasicBlock *CacheNN = BasicBlock::Create(Con, "cachennull", Func);
+ BasicBlock *CacheNN = BasicBlock::Create(*Con, "cachennull", Func);
#endif
Value *Comp, *AddOp;
@@ -1019,9 +1005,6 @@
int res;
int f_pos = 0;
- InitializeNativeTarget();
- LLVMLinkInJIT();
-
if (chain->n_rules == 0)
return (NULL);
More information about the svn-soc-all
mailing list