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

dpl at FreeBSD.org dpl at FreeBSD.org
Thu Aug 21 18:57:35 UTC 2014


Author: dpl
Date: Thu Aug 21 18:57:34 2014
New Revision: 272789
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272789

Log:
  s/chainptr/chain/g;s/argsptr/args/g, changed the getTypeByName arguments

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	Thu Aug 21 18:56:39 2014	(r272788)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Thu Aug 21 18:57:34 2014	(r272789)
@@ -73,8 +73,8 @@
 
 	// JIT Compiled Vars
 	// These are the function arguments.
-	Value *argsptr;
-	Value *chainptr;
+	Value *args;
+	Value *chain;
 	// Loop control.
 	Value *match;
 	Value *l;
@@ -203,8 +203,8 @@
 		if (arglist.size() != 2)
 			err(1, "Compilation error: no correct parameters\n");
 
-		argsptr = &arglist.front();
-		chainptr = &arglist.back();
+		args = &arglist.front();
+		chain = &arglist.back();
 
 		// Get Type objects
 		int8Ty = Type::getInt8Ty(con);
@@ -214,35 +214,35 @@
 		int8PtrTy = PointerType::getUnqual(int8Ty);
 
 		// Get StrucType from bitcode.
-		ipfw_dyn_ruleTy = mod->getTypeByName("ipfw_dyn_rule");
-		ifnetTy = mod->getTypeByName("ifnet");
-		in_addrTy = mod->getTypeByName("in_addr");
-		ipTy = mod->getTypeByName("ip");
-		ip_fw_argsTy = mod->getTypeByName("ip_fw_args");
-		ip_fw_chainTy = mod->getTypeByName("ip_fw_chain");
-		ip_fwTy = mod->getTypeByName("ip_fw");
-		ipfw_insnTy = mod->getTypeByName("_ipfw_insn");
-		ipfw_insn_ifTy = mod->getTypeByName("_ipfw_insn_if");
-		mbufTy = mod->getTypeByName("mbuf");
+		mbufTy = mod->getTypeByName("struct.mbuf");
+		ifnetTy = mod->getTypeByName("struct.ifnet");
+		in_addrTy = mod->getTypeByName("struct.in_addr");
+		ipTy = mod->getTypeByName("struct.ip");
+		ip_fw_argsTy = mod->getTypeByName("struct.ip_fw_args");
+		ip_fw_chainTy = mod->getTypeByName("struct.ip_fw_chain");
+		ip_fwTy = mod->getTypeByName("struct.ip_fw");
+		ipfw_insnTy = mod->getTypeByName("struct._ipfw_insn");
+		ipfw_insn_ifTy = mod->getTypeByName("struct._ipfw_insn_if");
+		ipfw_dyn_ruleTy = mod->getTypeByName("struct._ipfw_dyn_rule");
 #ifdef __FreeBSD__
-		ucredTy = mod->getTypeByName("ucred");
+		ucredTy = mod->getTypeByName("struct.ucred");
 #else
-		ucredTy = mod->getTypeByName("bsd_ucred");
+		ucredTy = mod->getTypeByName("struct.bsd_ucred");
 #endif /* __FreeBSD__ */
 
 		// Create Pointer to StructType types.
-		ipfw_dyn_rulePtrTy = PointerType::get(ipfw_dyn_ruleTy, 0);
-		ifnetPtrTy = PointerType::get(ifnetTy, 0);
-		in_addrPtrTy = PointerType::get(in_addrTy, 0);
-		ipPtrTy = PointerType::get(ipTy, 0);
-		ip_fw_argsPtrTy = PointerType::get(ip_fw_argsTy, 0);
-		ip_fw_chainPtrTy = PointerType::get(ip_fw_chainTy, 0);
-		ip_fwPtrTy = PointerType::get(ip_fwTy, 0);
-		ipfw_insnPtrTy = PointerType::get(ipfw_insnTy, 0);
-		ipfw_insn_ifPtrTy = PointerType::get(ipfw_insn_ifTy, 0);
-		mbufPtrTy = PointerType::get(mbufTy, 0);
+		mbufPtrTy = PointerType::getUnqual(mbufTy);
+		ifnetPtrTy = PointerType::getUnqual(ifnetTy);
+		in_addrPtrTy = PointerType::getUnqual(in_addrTy);
+		ipPtrTy = PointerType::getUnqual(ipTy);
+		ip_fw_argsPtrTy = PointerType::getUnqual(ip_fw_argsTy);
+		ip_fw_chainPtrTy = PointerType::getUnqual(ip_fw_chainTy);
+		ip_fwPtrTy = PointerType::getUnqual(ip_fwTy);
+		ipfw_insnPtrTy = PointerType::getUnqual(ipfw_insnTy);
+		ipfw_insn_ifPtrTy = PointerType::getUnqual(ipfw_insn_ifTy);
+		ipfw_dyn_rulePtrTy = PointerType::getUnqual(ipfw_dyn_ruleTy);
 #ifdef __FreeBSD__
-		ucredPtrTy = PointerType::get(ucredTy, 0);
+		ucredPtrTy = PointerType::getUnqual(ucredTy);
 #endif
 		// Get Function defs from bitcode.
 		// All of them are auxiliary functions.
@@ -278,7 +278,7 @@
 
 	// Allocate and initialize LLVM vars.
 	void
-	allocaAndInit(struct ip_fw_args *args, struct ip_fw_chain *chain)
+	allocaAndInit()
 	{
 		irb.SetInsertPoint(entry);
 		// Control flow variables.
@@ -298,11 +298,11 @@
 
 		// m = args->m (idx: 0)
 		m = irb.CreateAlloca(mbufPtrTy);
-		irb.CreateStore(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 0)), m);
+		irb.CreateStore(irb.CreateInBoundsGEP(args, ConstantInt::get(int32Ty, 0)), m);
 
 		// ip = (struct ip *)((m)->m_data) (idx: 2)
 		ip = irb.CreateAlloca(ipPtrTy);
-		irb.CreateStore(irb.CreateBitCast(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 2)), ipPtrTy), ip);
+		irb.CreateStore(irb.CreateBitCast(irb.CreateInBoundsGEP(args, ConstantInt::get(int32Ty, 2)), ipPtrTy), ip);
 
 #ifdef __FreeBSD__
 		ucred_cache = irb.CreateAlloca(ucredPtrTy); // Init: NULL if type ucred.
@@ -330,7 +330,7 @@
 		proto = irb.CreateAlloca(int8Ty);
 		irb.CreateStore(ConstantInt::get(int8Ty, 0), proto);
 		// args->f_id.proto = 0 (idx: 6, 5)
-		irb.CreateStore(ConstantInt::get(int8Ty, 0), irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 6), ConstantInt::get(int32Ty, 5)} ));
+		irb.CreateStore(ConstantInt::get(int8Ty, 0), irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 6), ConstantInt::get(int32Ty, 5)} ));
 
 		src_port = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int16Ty, 0), src_port);
@@ -351,7 +351,7 @@
 		// m_pkthdr is the 6th element (idx: 5)
 		// len is the 2nd element (idx: 1)
 		pktlen = irb.CreateAlloca(int32Ty);
-		irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(m, {ConstantInt::get(int32Ty, 5), ConstantInt::get(int32Ty, 1)} ));
+		irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(irb.CreateLoad(m), {ConstantInt::get(int32Ty, 5), ConstantInt::get(int32Ty, 1)} ));
 
 		etype = irb.CreateAlloca(int16Ty);
 		irb.CreateStore(ConstantInt::get(int32Ty, 0), etype);
@@ -435,19 +435,19 @@
 		// }
 
 		// if (args->rule.slot)
-		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), ConstantInt::get(int32Ty, 0)), nottagged, tagged);
+		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), ConstantInt::get(int32Ty, 0)), nottagged, tagged);
 		// if (args->rule.chain_id == chain->id)
 		irb.SetInsertPoint(tagged);
-		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 3)}), irb.CreateInBoundsGEP(chainptr, ConstantInt::get(int32Ty, 12))), jt, jf);
+		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 3)}), irb.CreateInBoundsGEP(chain, ConstantInt::get(int32Ty, 12))), jt, jf);
 
 		// f_pos = args->rule.slot;
 		irb.SetInsertPoint(jt);
-		irb.CreateStore(irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), f_pos);
+		irb.CreateStore(irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), f_pos);
 		irb.CreateBr(nottagged);
 
 		// else fpos = ipfw_find_rule(chain, args->rule.rulenum, args->rule.rule_id)
 		irb.SetInsertPoint(jf);
-		irb.CreateStore(irb.CreateCall3(ipfw_find_rule, chainptr, irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 1)}), irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 2)})), f_pos);
+		irb.CreateStore(irb.CreateCall3(ipfw_find_rule, chain, irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 1)}), irb.CreateInBoundsGEP(args, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 2)})), f_pos);
 
 		// Branch to nottagged because it
 		// only finishes the entry BasicBlock.
@@ -481,7 +481,7 @@
 		irb.CreateStore(ConstantInt::get(int32Ty, 0), tablearg);
 
 		// f = chain->map[f_pos];
-		irb.CreateStore(irb.CreateInBoundsGEP(chainptr, {ConstantInt::get(int32Ty, 5), f_pos}), f);
+		irb.CreateStore(irb.CreateInBoundsGEP(irb.CreateLoad(chain), {ConstantInt::get(int32Ty, 5), f_pos}), f);
 
 		// if (V_set_disable & (1 << f->set) )
 		irb.CreateCondBr(irb.CreateICmpNE(irb.CreateAnd(set_disable, irb.CreateShl(ConstantInt::get(int32Ty, 1), irb.CreateInBoundsGEP(f, ConstantInt::get(int32Ty, 5)))), ConstantInt::get(int32Ty, 0)), jt, jf);
@@ -662,7 +662,7 @@
 		irb.SetInsertPoint(jt);
 		// struct ip_fw *rule = chain->map[f_pos];
 		rule = irb.CreateAlloca(ip_fwPtrTy);
-		irb.CreateStore(irb.CreateInBoundsGEP(chainptr, {ConstantInt::get(int32Ty, 5), f_pos}), rule);
+		irb.CreateStore(irb.CreateInBoundsGEP(chain, {ConstantInt::get(int32Ty, 5), f_pos}), rule);
 
 		// uint64_t pcnt;
 		// (rule)->pcnt++;
@@ -753,7 +753,8 @@
 	void
 	optimize()
 	{
-		return;
+		Function *vf = mod->getFunction("voidfunction");
+		vf->eraseFromParent();
 	}
 
 	// Returns the pointer to the compiled function.
@@ -769,7 +770,7 @@
 	{
 		// If it returns one, goto pullup_failed.
 		// Else, goto starrules.
-		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt, {argsptr, ip, m, src_ip, dst_ip, src_port, dst_port, etype, ext_hd, iplen, pktlen, is_ipv4, is_ipv6, hlen, proto, icmp6_type, ip6f_mf, offset, ulp}), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules);
+		irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt, {args, ip, m, src_ip, dst_ip, src_port, dst_port, etype, ext_hd, iplen, pktlen, is_ipv4, is_ipv6, hlen, proto, icmp6_type, ip6f_mf, offset, ulp}), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules);
 	}
 
 	void


More information about the svn-soc-all mailing list