socsvn commit: r273809 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw

dpl at FreeBSD.org dpl at FreeBSD.org
Mon Sep 8 16:54:40 UTC 2014


Author: dpl
Date: Mon Sep  8 16:54:38 2014
New Revision: 273809
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273809

Log:
  Squashed some bugs. It works now.

Modified:
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c
  soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c	Mon Sep  8 15:42:47 2014	(r273808)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_pfil.c	Mon Sep  8 16:54:38 2014	(r273809)
@@ -147,6 +147,7 @@
 		ret = ipfw_chk_jit(args, chain);
 		IPFW_PF_RUNLOCK(chain);
 	}
+	#include <err.h>
 	return (ret);
 }
 

Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc
==============================================================================
--- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Mon Sep  8 15:42:47 2014	(r273808)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Mon Sep  8 16:54:38 2014	(r273809)
@@ -44,10 +44,16 @@
 
 using namespace llvm;
 
+// if (logging) {
+// 	Value *Str = Irb.CreateGlobalString("\nipfw_chk_jit(): firstf\n\n");
+// 	Value *StrFirstElement = Irb.CreateStructGEP(Str, 0);
+// 	Irb.CreateCall(PrintfFunc, StrFirstElement);
+// }
+
 class ipfwJIT {
 	Module *mod;
 	Function *Func;
-	LLVMContext *Con;
+	LLVMContext &Con;
 	IRBuilder<> Irb;
 
 	// We'll store the BasicBlock objects for each rule here.
@@ -135,7 +141,6 @@
 	Function *Set_match;
 	Function *Jump_fast;
 
-	// Not pkg-filtering related funcs.
 	Function *PrintfFunc;
 	Function *Ipfw_find_rule;
 
@@ -175,7 +180,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);
@@ -186,7 +191,7 @@
 	BasicBlock*
 	nextRule()
 	{
-		int nextn = rulenumber+1;
+		int nextn = rulenumber + 1;
 		if (nextn >= rules.size())
 			return (End);
 		else
@@ -209,10 +214,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.
@@ -281,108 +286,98 @@
 	allocaAndInit()
 	{
 		Irb.SetInsertPoint(Entry);
-		// Control flow variables.
-		L = Irb.CreateAlloca(Int32Ty);
 
-		Done = Irb.CreateAlloca(Int32Ty);
+		// Control flow variables.
+		Done = Irb.CreateAlloca(Int32Ty, nullptr, "done");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Done);
 
-		FPos = Irb.CreateAlloca(Int32Ty);
+		FPos = Irb.CreateAlloca(Int32Ty, nullptr, "fpos");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), FPos);
 
-		Retval = Irb.CreateAlloca(Int32Ty);
+		Retval = Irb.CreateAlloca(Int32Ty, nullptr, "retval");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Retval);
 
-		Cmd = Irb.CreateAlloca(Ipfw_insnPtrTy);
-		Tablearg = Irb.CreateAlloca(Int32Ty);
-		CmdLen = Irb.CreateAlloca(Int32Ty);
-		SkipOr = Irb.CreateAlloca(Int32Ty);
-		F = Irb.CreateAlloca(Ip_fwPtrTy);
-
 		// m = args->m (idx: 0)
-		MPtr = Irb.CreateAlloca(MbufPtrTy);
+		MPtr = Irb.CreateAlloca(MbufPtrTy, nullptr, "m");
 		Irb.CreateStore(Irb.CreateLoad(Irb.CreateStructGEP(Args, 0)), MPtr);
 		Value *M = Irb.CreateLoad(MPtr);
 
 		// ip = (struct ip *)((m)->m_data) (idx: 2)
-		IpPtr = Irb.CreateAlloca(IpPtrTy);
+		IpPtr = Irb.CreateAlloca(IpPtrTy, nullptr, "ip");
 		Value *M_data = Irb.CreateStructGEP(M, 2);
 		Value *M_casted = Irb.CreateBitCast(M_data, IpPtrTy);
 		Irb.CreateStore(M_casted, IpPtr);
 
-		Ucred_cache = Irb.CreateAlloca(UcredTy); // Init: NULL if type ucred.
-
-		Ucred_lookup = Irb.CreateAlloca(Int32Ty);
+		Ucred_lookup = Irb.CreateAlloca(Int32Ty, nullptr, "ucred_lookup");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Ucred_lookup);
 
-		Oif = Irb.CreateAlloca(IfnetTy); // Init: args->oif
+		Oif = Irb.CreateAlloca(IfnetTy, nullptr, "oif"); // Init: args->oif
 		Irb.CreateLoad(Irb.CreateStructGEP(Args, 1), Oif);
 
-		Hlen = Irb.CreateAlloca(Int32Ty);
+		Hlen = Irb.CreateAlloca(Int32Ty, nullptr, "hlen");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Hlen);
 
-		Offset = Irb.CreateAlloca(Int16Ty);
+		Offset = Irb.CreateAlloca(Int16Ty, nullptr, "offset");
 		Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Offset);
 
-		Ip6f_mf = Irb.CreateAlloca(Int16Ty);
+		Ip6f_mf = Irb.CreateAlloca(Int16Ty, nullptr, "ip6f_mf");
 		Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Ip6f_mf);
 
-		// proto = args->f_id.proto = 0
-		// proto = 0;
-		Proto = Irb.CreateAlloca(Int8Ty);
+		// proto = 0
+		Proto = Irb.CreateAlloca(Int8Ty, nullptr, "proto");
 		Irb.CreateStore(ConstantInt::get(Int8Ty, 0), Proto);
 		// args->f_id.proto = 0 (idx: 6, 5)
 		Value *F_id = Irb.CreateStructGEP(Args, 6);
-		Value *Proto = Irb.CreateStructGEP(F_id, 5);
-		Irb.CreateStore(ConstantInt::get(Int8Ty, 0), Proto);
+		Value *FProto = Irb.CreateStructGEP(F_id, 5);
+		Irb.CreateStore(ConstantInt::get(Int8Ty, 0), FProto);
 
-		Src_port = Irb.CreateAlloca(Int16Ty);
+		Src_port = Irb.CreateAlloca(Int16Ty, nullptr, "src_port");
 		Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Src_port);
-		Dst_port = Irb.CreateAlloca(Int16Ty);
+		Dst_port = Irb.CreateAlloca(Int16Ty, nullptr, "dst_port");
 		Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Dst_port);
 
 		//src_ip.s_addr = 0;
-		Src_ip = Irb.CreateAlloca(In_addrTy);
+		Src_ip = Irb.CreateAlloca(In_addrTy, nullptr, "src_ip");
 		Value *Src_s_addr = Irb.CreateStructGEP(Src_ip, 0);
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Src_s_addr);
 		//dst_ip.s_addr = 0;
-		Dst_ip = Irb.CreateAlloca(In_addrTy);
+		Dst_ip = Irb.CreateAlloca(In_addrTy, nullptr, "dst_ip");
 		Value *Dst_s_addr = Irb.CreateStructGEP(Dst_ip, 0);
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Dst_s_addr);
 
 		//iplen = 0;
-		Iplen = Irb.CreateAlloca(Int16Ty);
+		Iplen = Irb.CreateAlloca(Int16Ty, nullptr, "iplen");
 		Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Iplen);
 
 		// pktlen = m->m_pkthdr.len;
 		// m_pkthdr is the 6th element (idx: 5)
 		// len is the 2nd element (idx: 1)
-		Pktlen = Irb.CreateAlloca(Int32Ty);
+		Pktlen = Irb.CreateAlloca(Int32Ty, nullptr, "pktlen");
 		Value *Header = Irb.CreateStructGEP(M, 5);
 		Value *LengthPtr = Irb.CreateStructGEP(Header, 1);
 		Value *Length = Irb.CreateLoad(LengthPtr);
 		Irb.CreateStore(Length, Pktlen);
 
-		Etype = Irb.CreateAlloca(Int16Ty);
+		Etype = Irb.CreateAlloca(Int16Ty, nullptr, "etype");
 		Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Etype);
 
-		Dyn_dir = Irb.CreateAlloca(Int32Ty);
+		Dyn_dir = Irb.CreateAlloca(Int32Ty, nullptr, "dyn_dir");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, MATCH_UNKNOWN), Dyn_dir);
 
-		Q = Irb.CreateAlloca(Ipfw_dyn_rulePtrTy);
+		Q = Irb.CreateAlloca(Ipfw_dyn_rulePtrTy, nullptr, "q");
 		Irb.CreateStore(ConstantPointerNull::get(Ipfw_dyn_rulePtrTy), Q);
 
 		// There are no (void *), we use i8*
-		Ulp = Irb.CreateAlloca(Int8PtrTy);
+		Ulp = Irb.CreateAlloca(Int8PtrTy, nullptr, "ulp");
 		Irb.CreateStore(ConstantPointerNull::get(Int8PtrTy), Ulp);
 
-		Is_ipv4 = Irb.CreateAlloca(Int32Ty);
+		Is_ipv4 = Irb.CreateAlloca(Int32Ty, nullptr, "is_ipv4");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Is_ipv4);
-		Is_ipv6 = Irb.CreateAlloca(Int32Ty);
+		Is_ipv6 = Irb.CreateAlloca(Int32Ty, nullptr, "is_ipv6");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Is_ipv6);
-		Icmp6_type = Irb.CreateAlloca(Int8Ty);
+		Icmp6_type = Irb.CreateAlloca(Int8Ty, nullptr, "icmp6_type");
 		Irb.CreateStore(ConstantInt::get(Int8Ty, 0), Icmp6_type);
-		Ext_hd = Irb.CreateAlloca(Int16Ty);
+		Ext_hd = Irb.CreateAlloca(Int16Ty, nullptr, "ext_hd");
 		Irb.CreateStore(ConstantInt::get(Int16Ty, 0), Ext_hd);
 
 		// If it returns one, goto pullup_failed.
@@ -402,12 +397,11 @@
 	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;
 
-
 		// VNET_DECLARE(int, fw_verbose);
 		// #define	V_fw_verbose		VNET(fw_verbose)
 		// We should be fine getting that from the Module.
@@ -441,10 +435,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;
 
@@ -471,6 +465,11 @@
 		Value *Slot = Irb.CreateStructGEP(Rule, 0);
 		Value *SlotValue = Irb.CreateLoad(Slot);
 		Comp = Irb.CreateICmpEQ(SlotValue, ConstantInt::get(Int32Ty, 0));
+		// if (1) {
+		// 	Value *Str = Irb.CreateGlobalString("args->rule.slot: %d\n");
+		// 	Value *StrFirstElement = Irb.CreateStructGEP(Str, 0);
+		// 	Irb.CreateCall(PrintfFunc, {StrFirstElement});
+		// }
 		Irb.CreateCondBr(Comp, Nottagged, Tagged);
 
 		Irb.SetInsertPoint(Tagged);
@@ -491,10 +490,8 @@
 		Irb.SetInsertPoint(Jf);
 		Value *Rulenum = Irb.CreateStructGEP(Rule, 1);
 		Value *RulenumL = Irb.CreateLoad(Rulenum);
-
 		Value *RuleId = Irb.CreateStructGEP(Rule, 2);
 		Value *RuleIdL = Irb.CreateLoad(RuleId);
-
 		Value *FindRuleCall = Irb.CreateCall3(Ipfw_find_rule, Chain, RulenumL, RuleIdL);
 		Irb.CreateStore(FindRuleCall, FPos);
 
@@ -505,12 +502,18 @@
 		// else f_pos = 0;
 		// Since f_pos is initialized by default as 0, we only br.
 		Irb.SetInsertPoint(Nottagged);
+		// XXX Fpos
+		// if (1) {
+		// 	Value *Str = Irb.CreateGlobalString("f_pos: %d\n&fpos: %p\n");
+		// 	Value *StrFirstElement = Irb.CreateStructGEP(Str, 0);
+		// 	Irb.CreateCall(PrintfFunc, {StrFirstElement, FPos, FPos});
+		// }
 		// Jump to first rule.
 		Irb.CreateBr(rules.front());
 	}
 
 	public:
-	ipfwJIT(int rulesnumber) : Con(&getGlobalContext()), Irb(*Con)
+	ipfwJIT(int rulesnumber) : Con(getGlobalContext()), Irb(Con)
 	{
 		// Create the module and load the code.
 		mod = loadBitcode("rules.bc");
@@ -521,11 +524,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
 		setEnv();
@@ -536,7 +538,7 @@
 		// 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();
@@ -552,7 +554,7 @@
 		// Optimise
 		PassManagerBuilder PMBuilder;
 		PMBuilder.OptLevel = 3;
-		PMBuilder.Inliner = createFunctionInliningPass(275);
+		//PMBuilder.Inliner = createFunctionInliningPass(275);
 
 		// Function passes
 		FunctionPassManager *PerFunctionPasses = new FunctionPassManager(mod);
@@ -561,12 +563,6 @@
 		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();
@@ -575,7 +571,7 @@
 		std::string errstr;
 
 		EngineBuilder EB = EngineBuilder(std::unique_ptr<Module>(mod));
-		EB.setEngineKind(EngineKind::Kind::JIT);
+		//EB.setEngineKind(EngineKind::Kind::JIT);
 		EB.setErrorStr(&errstr);
 		EB.setOptLevel(CodeGenOpt::Level::Aggressive);
 		EB.setUseMCJIT(true);
@@ -587,10 +583,9 @@
 			exit(1);
 		}
 
-		// 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");
+		// mod->dump();
+		
+		// XXX We should use a NON deperecated function.
 		return (funcptr)EE->getPointerToFunction(mod->getFunction("ipfw_chk_jit"));
 	}
 
@@ -603,12 +598,11 @@
 	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");
 
-		// All this variables are already allocated.
 		// ipfw_insn *cmd;
 		// uInt32_t tablearg = 0;
 		// int l, cmdlen, skip_or; /* skip rest of OR block */
@@ -618,16 +612,28 @@
 		// 	continue;
 		// skip_or = 0;
 
-		// Write at the rule.
+		// Write at the current rule.
 		Irb.SetInsertPoint(rules[rulenumber]);
 
+		// ipfw_insn *cmd;
+		// uInt32_t tablearg = 0;
+		// int l, cmdlen, skip_or; /* skip rest of OR block */
+		Cmd = Irb.CreateAlloca(Ipfw_insnPtrTy, nullptr, "cmd");
+		Tablearg = Irb.CreateAlloca(Int32Ty, nullptr, "tablearg");
+		L = Irb.CreateAlloca(Int32Ty, nullptr, "l");
+		CmdLen = Irb.CreateAlloca(Int32Ty, nullptr, "cmdlen");
+		SkipOr = Irb.CreateAlloca(Int32Ty, nullptr, "skipor");
+		F = Irb.CreateAlloca(Ip_fwPtrTy, nullptr, "f");
+
 		// uInt32_t tablearg = 0;
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Tablearg);
 
 		// f = chain->map[f_pos]; idxs: 5, f_pos
-		Value *MapPtr = Irb.CreateStructGEP(Chain, 5);
-		Value *Map = Irb.CreateLoad(MapPtr);
-		Value *MapFPos = Irb.CreateInBoundsGEP(Map, FPos);
+		Value *FPosL = Irb.CreateLoad(FPos);
+		Value *ExtFPos = Irb.CreateSExt(FPosL, Int64Ty);
+		Value *Map = Irb.CreateStructGEP(Chain, 5);
+		Value *MapL = Irb.CreateLoad(Map);
+		Value *MapFPos = Irb.CreateInBoundsGEP(MapL, ExtFPos);
 		Value *MapFPosL = Irb.CreateLoad(MapFPos);
 		Irb.CreateStore(MapFPosL, F);
 
@@ -654,14 +660,14 @@
 	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;
 
-		// The first to are the intializers of the for loop.
+		// The first two are initializers of the outer for.
 		//	l = f->cmd_len;
 		//	cmd = f->cmd;
 		//
@@ -683,15 +689,15 @@
 
 		// cmd = f->cmd;
 		Value *FCmd = Irb.CreateStructGEP(FL, 11);
-		Value *FCmdL = Irb.CreateLoad(FCmd);
-		FCmd = Irb.CreateExtractValue(FCmdL, 0);
-		Value *CmdL = Irb.CreateLoad(Cmd);
-		Irb.CreateStore(FCmd, CmdL);
+		Value *Addr = Irb.CreateBitCast(FCmd, Ipfw_insnPtrTy);
+		Irb.CreateStore(Addr, Cmd);
+
 		// int match;
-		Match = Irb.CreateAlloca(Int32Ty);
+		Match = Irb.CreateAlloca(Int32Ty, nullptr, "match");
 
 		// int cmdlen;
 		// cmdlen = ((cmd)->len & F_LEN_MASK);
+		Value *CmdL = Irb.CreateLoad(Cmd);
 		Value *LenPtr = Irb.CreateStructGEP(CmdL, 1);
 		Value *Len = Irb.CreateLoad(LenPtr);
 		AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_LEN_MASK));
@@ -728,14 +734,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;
 
@@ -838,13 +844,9 @@
 	{
 		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);
-	#ifdef __FreeBSD__
-		BasicBlock *CacheNN = BasicBlock::Create(*Con, "cachennull", Func);
-	#endif
+		BasicBlock *Jt = BasicBlock::Create(Con, "jt", Func);
+		BasicBlock *Jf = BasicBlock::Create(Con, "jf", Func);
+		BasicBlock *Ret = BasicBlock::Create(Con, "ret", Func);
 		Value *Comp, *AddOp;
 
 		// if (done) {
@@ -858,14 +860,10 @@
 		//		printf("ipfw: ouch!, skip past end of rules, denying packet\n");
 		// }
 		//
-		// #ifdef __FreeBSD__
-		// 	if (ucred_cache != NULL)
-		// 		crfree(ucred_cache);
-		// #endif
-		//
 		// return (retval);
 
 		Irb.SetInsertPoint(End);
+
 		// We need to get the timestamp variable.
 		TimeUptime = mod->getGlobalVariable("time_uptime");
 		Str = Irb.CreateGlobalString("ipfw: ouch!, skip past end of rules, denying packet\n");
@@ -877,10 +875,12 @@
 
 		Irb.SetInsertPoint(Jt);
 		// struct ip_fw *rule = chain->map[f_pos];
-		Rule = Irb.CreateAlloca(Ip_fwPtrTy);
-		Value *MapPtr = Irb.CreateStructGEP(Chain, 5);
-		Value *Map = Irb.CreateLoad(MapPtr);
-		Value *MapFPos = Irb.CreateInBoundsGEP(Map, FPos);
+		Rule = Irb.CreateAlloca(Ip_fwPtrTy, nullptr, "rule");
+		Value *FPosL = Irb.CreateLoad(FPos);
+		Value *ExtFPos = Irb.CreateSExt(FPosL, Int64Ty);
+		Value *Map = Irb.CreateStructGEP(Chain, 5);
+		Value *MapL = Irb.CreateLoad(Map);
+		Value *MapFPos = Irb.CreateInBoundsGEP(MapL, ExtFPos);
 		Value *MapFPosL = Irb.CreateLoad(MapFPos);
 		Irb.CreateStore(MapFPosL, Rule);
 
@@ -910,7 +910,7 @@
 		Value *TimeUptimeL32 = Irb.CreateTrunc(TimeUptimeL, Int32Ty);
 		Value *Timestamp = Irb.CreateStructGEP(RuleL, 10);
 		Irb.CreateStore(TimeUptimeL32, Timestamp);
-		Irb.CreateBr(DoCache);
+		Irb.CreateBr(Ret);
 
 		Irb.SetInsertPoint(Jf);
 		//	retval = IP_FW_DENY;
@@ -918,22 +918,7 @@
 		Irb.CreateStore(ConstantInt::get(Int32Ty, IP_FW_DENY), Retval);
 		Value *StrFirstElement = Irb.CreateStructGEP(Str, 0);
 		Irb.CreateCall(PrintfFunc, StrFirstElement);
-		Irb.CreateBr(DoCache);
-
-		Irb.SetInsertPoint(DoCache);
-#ifndef __FreeBSD__
 		Irb.CreateBr(Ret);
-#endif
-
-#ifdef __FreeBSD__
-		// 	if (ucred_cache != NULL)
-		Comp = Irb.CreateICmpNE(Ucred_cache, 
-			ConstantPointerNull::get(UcredPtrTy));
-		Irb.CreateCondBr(Comp, CacheNN, Ret);
-
-		Irb.SetInsertPoint(CacheNN);
-		Irb.CreateBr(Ret);
-#endif
 
 		//Return retval
 		Irb.SetInsertPoint(Ret);
@@ -943,32 +928,30 @@
 
 
 	// Rules
+	// XXX Not tested.
 	void
 	emit_nop()
 	{
-			//break;
-			Irb.CreateBr(nextRule());
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 1), Match);
 	}
 
+	// XXX Not tested.
 	void
 	emit_forward_mac(u_int8_t opcode)
 	{
 		printf("Compilation error:\n");
 		printf("ipfwjitter: opcode %d unimplemented\n", opcode);
 		printf("Compilation continues.\n");
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
-	// check_uidgid() returns 0 on userspace.
+	// XXX Not tested.
 	void
 	emit_jail()
 	{
-		BasicBlock *OffsetNZ = BasicBlock::Create(*Con, "offsetnotzero", Func);
-		BasicBlock *OffsetZE = BasicBlock::Create(*Con, "offsetiszero", Func);
-		BasicBlock *TCPorUDP = BasicBlock::Create(*Con, "setmatchzero", Func);
-		BasicBlock *Continue = BasicBlock::Create(*Con, "Continue", Func);
+		BasicBlock *OffsetNZ = BasicBlock::Create(Con, "offsetnotzero", Func);
+		BasicBlock *OffsetZE = BasicBlock::Create(Con, "offsetiszero", Func);
+		BasicBlock *TCPorUDP = BasicBlock::Create(Con, "setmatchzero", Func);
+		BasicBlock *Continue = BasicBlock::Create(Con, "Continue", Func);
 		Value *Comp;
 
 		// if (offset != 0)
@@ -1003,10 +986,9 @@
 
 		// Keep on with the for epilogue.
 		Irb.SetInsertPoint(Continue);
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_recv()
 	{
@@ -1015,10 +997,9 @@
 		Value *cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy);
 		Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, rcvif, cmdc, Chain, Tablearg);
 		Irb.CreateStore(IfaceMatchCall, Match);
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_xmit()
 	{
@@ -1026,416 +1007,323 @@
 		Value *Cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy);
 		Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, Oif, Cmdc, Chain, Tablearg);
 		Irb.CreateStore(IfaceMatchCall, Match);
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_via()
 	{
+		BasicBlock *OifNZ = BasicBlock::Create(Con, "OifNotZero", Func);
+		BasicBlock *OifZE = BasicBlock::Create(Con, "OifIsZero", Func);
+
+		// if (oif)
+		// 	match = iface_match(oif, (ipfw_insn_if *)cmd, chain, &tablearg);
+		// else
+		// 	match = iface_match(m->m_pkthdr.rcvif, (ipfw_insn_if *)cmd,
+		// 		chain, &tablearg);
+		// break;
+		//Value *Comp = Irb.CreateICmp(Oif, ConstantPointerNull::get(IfnetPtrTy));
 
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_macaddr2()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_mac_type()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_frag()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_in()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_layer2()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_diverted()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_proto()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_src()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_dst_lookup()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_dst_mask()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_src_me()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip6_src_me()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_src_set()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_dst()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_dst_me()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip6_dst_me()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip_dstport()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_icmptype()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_icmp6type()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ipopt()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ipver()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ipttl()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ipprecedence()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_iptos()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_dscp()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_tcpdatalen()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_tcpflags()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_tcpopts()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_tcpseq()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_tcpack()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_tcpwin()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_estab()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_altq()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_log()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_prob()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_verrevpath()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_versrcreach()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_antispoof()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ipsec()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip6_src()
 	{
-
-		//break;
-		Irb.CreateBr(nextRule());
 	}
 
+	// XXX Not tested.
 	void
 	emit_ip6_dst()

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-soc-all mailing list