From owner-svn-soc-all@FreeBSD.ORG Wed Sep 3 18:05:05 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 57167899 for ; Wed, 3 Sep 2014 18:05:05 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 428A91DF1 for ; Wed, 3 Sep 2014 18:05:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s83I55v5072455 for ; Wed, 3 Sep 2014 18:05:05 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s83I54su072326 for svn-soc-all@FreeBSD.org; Wed, 3 Sep 2014 18:05:04 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 3 Sep 2014 18:05:04 GMT Message-Id: <201409031805.s83I54su072326@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r273573 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2014 18:05:05 -0000 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(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(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);