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

dpl at FreeBSD.org dpl at FreeBSD.org
Tue Sep 2 15:03:32 UTC 2014


Author: dpl
Date: Tue Sep  2 15:03:31 2014
New Revision: 273487
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273487

Log:
  Corrected LLVM code, now assertions are always right.

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	Tue Sep  2 14:27:12 2014	(r273486)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc	Tue Sep  2 15:03:31 2014	(r273487)
@@ -78,12 +78,12 @@
 	Value *Match;
 	Value *L;
 	Value *Done;
-	Value *F_pos;
+	Value *FPos;
 	Value *Retval;
 	Value *Cmd;
-	Value *Cmdlen;
+	Value *CmdLen;
 	Value *Tablearg;
-	Value *Skip_or;
+	Value *SkipOr;
 	Value *F;
 
 	// Packet matching variables.
@@ -289,17 +289,17 @@
 		Done = Irb.CreateAlloca(Int32Ty);
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Done);
 
-		F_pos = Irb.CreateAlloca(Int32Ty);
-		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), F_pos);
+		FPos = Irb.CreateAlloca(Int32Ty);
+		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), FPos);
 
 		Retval = Irb.CreateAlloca(Int32Ty);
 		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Retval);
 
-		Cmd = Irb.CreateAlloca(Ipfw_insnTy);
+		Cmd = Irb.CreateAlloca(Ipfw_insnPtrTy);
 		Tablearg = Irb.CreateAlloca(Int32Ty);
-		Cmdlen = Irb.CreateAlloca(Int32Ty);
-		Skip_or = Irb.CreateAlloca(Int32Ty);
-		F = Irb.CreateAlloca(Ip_fwTy);
+		CmdLen = Irb.CreateAlloca(Int32Ty);
+		SkipOr = Irb.CreateAlloca(Int32Ty);
+		F = Irb.CreateAlloca(Ip_fwPtrTy);
 
 		// m = args->m (idx: 0)
 		MPtr = Irb.CreateAlloca(MbufPtrTy);
@@ -390,33 +390,11 @@
 		// If it returns one, goto pullup_failed.
 		// Else, goto first rule.
 		Value *Ip = Irb.CreateLoad(IpPtr);
-
-		Args->getType()->dump();
-		Ip->getType()->dump();
-		M->getType()->dump();
-		Src_ip->getType()->dump();
-		Dst_ip->getType()->dump();
-		Src_port->getType()->dump();
-		Dst_port->getType()->dump();
-		Etype->getType()->dump();
-		Ext_hd->getType()->dump();
-		Iplen->getType()->dump();
-		Pktlen->getType()->dump();
-		Is_ipv4->getType()->dump();
-		Is_ipv6->getType()->dump();
-		Hlen->getType()->dump();
-		Proto->getType()->dump();
-		Icmp6_type->getType()->dump();
-		Ip6f_mf->getType()->dump();
-		Offset->getType()->dump();
-		Ulp->getType()->dump();
-
-		InspectPkt->dump();
+		Value *UlpL = Irb.CreateLoad(Ulp);
 
 		Value *InspectPktCall = Irb.CreateCall(InspectPkt, {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});
-		InspectPktCall->dump();
+			Is_ipv6, Hlen, Proto, Icmp6_type, Ip6f_mf, Offset, UlpL});
 
 		Value *Cond = Irb.CreateICmpEQ(InspectPktCall, ConstantInt::get(Int32Ty, 1));
 		Irb.CreateCondBr(Cond, Pullup_failed, Check_tag);
@@ -428,7 +406,7 @@
 		BasicBlock *print = BasicBlock::Create(Con, "print", Func);
 		BasicBlock *ret = BasicBlock::Create(Con, "ret", Func);
 
-		Value *is_verbose, *str, *Comp;
+		Value *Is_verbose, *Str, *Comp;
 
 
 		// VNET_DECLARE(int, fw_verbose);
@@ -440,18 +418,20 @@
 		// 		printf("ipfw: pullup failed\n");
 		// 	return (IP_FW_DENY);
 
-		is_verbose = mod->getGlobalVariable("fw_verbose");
-		str = Irb.CreateGlobalString("ipfw: pullup failed\n");
+		Is_verbose = mod->getGlobalVariable("fw_verbose");
+		Str = Irb.CreateGlobalString("ipfw: pullup failed\n");
 
 		Irb.SetInsertPoint(Pullup_failed);
 
 		// if (V_fw_verbose)
-		Comp = Irb.CreateICmpEQ(is_verbose, ConstantInt::get(Int32Ty, 0));
+		Value *Is_verboseL = Irb.CreateLoad(Is_verbose); 
+		Comp = Irb.CreateICmpEQ(Is_verboseL, ConstantInt::get(Int32Ty, 0));
 		Irb.CreateCondBr(Comp, ret, print);
 
 		// printf("ipfw: pullup failed\n");
 		Irb.SetInsertPoint(print);
-		Irb.CreateCall(PrintfFunc, str);
+		Value *StrFirstElement = Irb.CreateStructGEP(Str, 0);
+		Irb.CreateCall(PrintfFunc, StrFirstElement);
 		Irb.CreateBr(ret);
 
 		// return (IP_FW_DENY);
@@ -490,27 +470,34 @@
 		// if (args->rule.slot)
 		Value *Rule = Irb.CreateStructGEP(Args, 4);
 		Value *Slot = Irb.CreateStructGEP(Rule, 0);
-		Comp = Irb.CreateICmpEQ(Slot, ConstantInt::get(Int32Ty, 0));
+		Value *SlotValue = Irb.CreateLoad(Slot);
+		Comp = Irb.CreateICmpEQ(SlotValue, ConstantInt::get(Int32Ty, 0));
 		Irb.CreateCondBr(Comp, Nottagged, Tagged);
 
 		Irb.SetInsertPoint(Tagged);
 		// if (args->rule.chain_id == chain->id)
-		Value *Chain_id = Irb.CreateStructGEP(Rule, 3); 
-		Value *Id = Irb.CreateInBoundsGEP(Chain, ConstantInt::get(Int32Ty, 12));
-		Comp = Irb.CreateICmpEQ(Chain_id, Id);
+		Value *ChainId = Irb.CreateStructGEP(Rule, 3); 
+		Value *Id = Irb.CreateStructGEP(Chain, 12);
+		Value *ChainIdL = Irb.CreateLoad(ChainId);
+		Value *IdL = Irb.CreateLoad(Id);
+		Comp = Irb.CreateICmpEQ(ChainIdL, IdL);
 		Irb.CreateCondBr(Comp, Jt, Jf);
 
 		// f_pos = args->rule.slot;
 		Irb.SetInsertPoint(Jt);
-		Irb.CreateStore(Slot, F_pos);
+		Irb.CreateStore(SlotValue, FPos);
 		Irb.CreateBr(Nottagged);
 
 		// else fpos = ipfw_find_rule(chain, args->rule.rulenum, args->rule.rule_id)
 		Irb.SetInsertPoint(Jf);
 		Value *Rulenum = Irb.CreateStructGEP(Rule, 1);
+		Value *RulenumL = Irb.CreateLoad(Rulenum);
+
 		Value *RuleId = Irb.CreateStructGEP(Rule, 2);
-		Value *FindRuleCall = Irb.CreateCall3(Ipfw_find_rule, Chain, Rulenum, RuleId);
-		Irb.CreateStore(FindRuleCall, F_pos);
+		Value *RuleIdL = Irb.CreateLoad(RuleId);
+
+		Value *FindRuleCall = Irb.CreateCall3(Ipfw_find_rule, Chain, RulenumL, RuleIdL);
+		Irb.CreateStore(FindRuleCall, FPos);
 
 		// Branch to Nottagged because it
 		// only finishes the entry BasicBlock.
@@ -529,7 +516,7 @@
 		BasicBlock *jt = BasicBlock::Create(Con, "jt", Func);
 		BasicBlock *jf = BasicBlock::Create(Con, "jf", Func);
 
-		Value *set_disable = mod->getGlobalVariable("set_disable");
+		Value *SetDisable = mod->getGlobalVariable("set_disable");
 
 		// All this variables are already allocated.
 		// ipfw_insn *cmd;
@@ -548,24 +535,28 @@
 		// 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, F_pos);
-		Irb.CreateStore(MapFPos, F);
+		Value *MapFPos = Irb.CreateInBoundsGEP(Map, FPos);
+		Value *MapFPosL = Irb.CreateLoad(MapFPos);
+		Irb.CreateStore(MapFPosL, F);
 
 		// if (V_set_disable & (1 << f->set) )
-		Value *Set = Irb.CreateStructGEP(F, 5);
-		Value *ShiftedSet = Irb.CreateShl(ConstantInt::get(Int32Ty, 1), Set);
-		Value *AndOp = Irb.CreateAnd(set_disable, ShiftedSet);
+		Value *FL = Irb.CreateLoad(F);
+		Value *Set = Irb.CreateStructGEP(FL, 5);
+		Value *SetL = Irb.CreateLoad(Set); //uint8
+		Value *ShiftedSet = Irb.CreateShl(ConstantInt::get(Int8Ty, 1), SetL);
+		Value *SetDisableL = Irb.CreateLoad(SetDisable);
+		Value *ShiftedSet32 = Irb.CreateZExt(ShiftedSet, Int32Ty);
+		Value *AndOp = Irb.CreateAnd(SetDisableL, ShiftedSet32);
 		Value *Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0));
 		Irb.CreateCondBr(Comp, jt, jf);
 
-
 		Irb.SetInsertPoint(jt);
 		//		continue;
 		Irb.CreateBr(nextRule(rulenumber+1));
 
 		// skip_or = 0;
 		Irb.SetInsertPoint(jf);
-		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Skip_or);
+		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), SkipOr);
 
 		Irb.CreateBr(Inner_for_prologue);
 	}
@@ -595,23 +586,32 @@
 		Irb.SetInsertPoint(Inner_for_prologue);
 
 		// l = f->cmd_len;
-		// XXX - ask David about types. int l; uint16_t cmd_len;
-		Value *CmdLen = Irb.CreateStructGEP(F, 3);
-		Irb.CreateStore(CmdLen, L);
+		Value *FL = Irb.CreateLoad(F);
+		Value *FCmdLen = Irb.CreateStructGEP(FL, 3);
+		Value *FCmdLenL = Irb.CreateLoad(FCmdLen);
+		Value *FCmdLenL32 = Irb.CreateZExt(FCmdLenL, Int32Ty);
+		Irb.CreateStore(FCmdLenL32, L);
 
 		// cmd = f->cmd;
-		Value *FCmd = Irb.CreateStructGEP(F, 11);
-		Irb.CreateStore(FCmd, 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);
 		// int match;
 		Match = Irb.CreateAlloca(Int32Ty);
 
+		// int cmdlen;
 		// cmdlen = ((cmd)->len & F_LEN_MASK);
-		Value *Len = Irb.CreateStructGEP(Cmd, 1);
+		Value *LenPtr = Irb.CreateStructGEP(CmdL, 1);
+		Value *Len = Irb.CreateLoad(LenPtr);
 		AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_LEN_MASK));
-		Irb.CreateStore(AndOp, Cmdlen);
+		Value *AndOp32 = Irb.CreateSExt(AndOp, Int32Ty);
+		Irb.CreateStore(AndOp32, CmdLen);
 
 		// if (skip_or)
-		Comp = Irb.CreateICmpNE(Skip_or, ConstantInt::get(Int32Ty, 0));
+		Value *SkipOrL = Irb.CreateLoad(SkipOr);
+		Comp = Irb.CreateICmpNE(SkipOrL, ConstantInt::get(Int32Ty, 0));
 		Irb.CreateCondBr(Comp, firstt, firstf);
 
 		Irb.SetInsertPoint(firstt);
@@ -622,7 +622,7 @@
 
 		Irb.SetInsertPoint(secondt);
 		// skip_or = 0;
-		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), Skip_or);
+		Irb.CreateStore(ConstantInt::get(Int32Ty, 0), SkipOr);
 		Irb.CreateBr(secondf);
 
 		Irb.SetInsertPoint(secondf);
@@ -652,8 +652,18 @@
 
 		// This are the increments of the for loop.
 		// l -= cmdlen, cmd += cmdlen;
-		Irb.CreateStore(Irb.CreateNSWSub(L, Cmdlen), L);
-		Irb.CreateStore(Irb.CreateAdd(Cmd, Cmdlen), Cmd);
+		Value *LL = Irb.CreateLoad(L);
+		Value *CmdLenL = Irb.CreateLoad(CmdLen);
+		Value *Sub = Irb.CreateNSWSub(LL, CmdLenL);
+		Irb.CreateStore(Sub, L);
+
+		// TODO -- Should ensure correctness of code.
+		// ipfw_insn *cmd; Add to pointer.
+		// Note: Since LLVM can't add to a ptr, we can use GEP with casted Ptr.
+		// cmd += cmdlen;
+		Value *CmdL = Irb.CreateLoad(Cmd);
+		Value *Add = Irb.CreateInBoundsGEP(CmdL, CmdLenL);
+		Irb.CreateStore(Add, Cmd);
 
 		// if (cmd->len & F_NOT)
 		// 	match = !match;
@@ -669,15 +679,17 @@
 		Irb.SetInsertPoint(Inner_for_epilogue);
 
 		// if (cmd->len & F_NOT)
-		Value *Len = Irb.CreateStructGEP(Cmd, 1);
-		AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_NOT));
-		Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0));
+		Value *Len = Irb.CreateStructGEP(CmdL, 1);
+		Value *LenL = Irb.CreateLoad(Len);
+		AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_NOT));
+		Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int8Ty, 0));
 		Irb.CreateCondBr(Comp, jt, sec_cond);
 
 		Irb.SetInsertPoint(jt);
 		// match = !match;
 		// match = ((match)?0:1);
-		Comp = Irb.CreateICmpNE(Match, ConstantInt::get(Int32Ty, 0));
+		Value *MatchL = Irb.CreateLoad(Match);
+		Comp = Irb.CreateICmpNE(MatchL, ConstantInt::get(Int32Ty, 0));
 		Irb.CreateCondBr(Comp, matchnz, matchz);
 
 		Irb.SetInsertPoint(matchnz);
@@ -690,25 +702,25 @@
 
 		Irb.SetInsertPoint(sec_cond);
 		// if (match)
-		Comp = Irb.CreateICmpNE(Match, ConstantInt::get(Int32Ty, 0));
+		Comp = Irb.CreateICmpNE(MatchL, ConstantInt::get(Int32Ty, 0));
 		Irb.CreateCondBr(Comp, matchnotzero, matchzero);
 
 		Irb.SetInsertPoint(matchnotzero);
 		// if (cmd->len & F_OR)
-		AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_OR));
-		Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int32Ty, 0));
+		AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR));
+		Comp = Irb.CreateICmpNE(AndOp, ConstantInt::get(Int8Ty, 0));
 		Irb.CreateCondBr(Comp, is_or, Outer_for_epilogue);
 
 		Irb.SetInsertPoint(is_or);
 		// skip_or = 1;
-		Irb.CreateStore(ConstantInt::get(Int32Ty, 1), Skip_or);
+		Irb.CreateStore(ConstantInt::get(Int32Ty, 1), SkipOr);
 		Irb.CreateBr(Outer_for_epilogue);
 
 		Irb.SetInsertPoint(matchzero);
 		// if (!(cmd->len & F_OR)) /* not an OR block, */
 		//     break;
-		AndOp = Irb.CreateAnd(Len, ConstantInt::get(Int8Ty, F_OR));
-		Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int32Ty, 0));
+		AndOp = Irb.CreateAnd(LenL, ConstantInt::get(Int8Ty, F_OR));
+		Comp = Irb.CreateICmpEQ(AndOp, ConstantInt::get(Int8Ty, 0));
 		Irb.CreateCondBr(Comp, nextRule(rulenumber+1) /* break */, Outer_for_epilogue);
 	}
 
@@ -720,23 +732,25 @@
 		Irb.SetInsertPoint(Outer_for_epilogue);
 
 		// f_pos++, increment of the for loop.
-		Value *AddOp = Irb.CreateAdd(F_pos, ConstantInt::get(Int32Ty, 1));
-		Irb.CreateStore(AddOp, F_pos);
+		Value *FPosL = Irb.CreateLoad(FPos);
+		Value *AddOp = Irb.CreateAdd(FPosL, ConstantInt::get(Int32Ty, 1));
+		Irb.CreateStore(AddOp, FPos);
 
 		// if (done)
 		//		break;
-		Value *Comp = Irb.CreateICmpNE(Done, ConstantInt::get(Int32Ty, 0));
+		Value *DoneL = Irb.CreateLoad(Done);
+		Value *Comp = Irb.CreateICmpNE(DoneL, ConstantInt::get(Int32Ty, 0));
 		Irb.CreateCondBr(Comp, End, nextRule(rulenumber+1));
 	}
 
 	void
 	emit_end()
 	{
-		Value *rule, *time_uptime, *str;
+		Value *Rule, *TimeUptime, *Str;
 
-		BasicBlock *jt = BasicBlock::Create(Con, "jt", Func);
-		BasicBlock *jf = BasicBlock::Create(Con, "jf", Func);
-		BasicBlock *ret = BasicBlock::Create(Con, "ret", Func);
+		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) {
@@ -759,47 +773,56 @@
 
 		Irb.SetInsertPoint(End);
 		// We need to get the timestamp variable.
-		time_uptime = mod->getGlobalVariable("time_uptime");
-		str = Irb.CreateGlobalString("ipfw: ouch!, skip past end of rules, denying packet\n");
+		TimeUptime = mod->getGlobalVariable("time_uptime");
+		Str = Irb.CreateGlobalString("ipfw: ouch!, skip past end of rules, denying packet\n");
 
 		// if (done)
-		Comp = Irb.CreateICmpNE(Done, ConstantInt::get(Int32Ty, 0));
-		Irb.CreateCondBr(Comp, jt, jf);
+		Value *DoneL = Irb.CreateLoad(Done);
+		Comp = Irb.CreateICmpNE(DoneL, ConstantInt::get(Int32Ty, 0));
+		Irb.CreateCondBr(Comp, Jt, Jf);
 
-		Irb.SetInsertPoint(jt);
+		Irb.SetInsertPoint(Jt);
 		// struct ip_fw *rule = chain->map[f_pos];
-		rule = Irb.CreateAlloca(Ip_fwPtrTy);
+		Rule = Irb.CreateAlloca(Ip_fwPtrTy);
 		Value *MapPtr = Irb.CreateStructGEP(Chain, 5);
 		Value *Map = Irb.CreateLoad(MapPtr);
-		Value *MapFPos = Irb.CreateInBoundsGEP(Map, F_pos);
-		Irb.CreateStore(MapFPos, rule);
+		Value *MapFPos = Irb.CreateInBoundsGEP(Map, FPos);
+		Value *MapFPosL = Irb.CreateLoad(MapFPos);
+		Irb.CreateStore(MapFPosL, Rule);
 
 		// uint64_t pcnt;
 		// (rule)->pcnt++;
-		Value *RuleL = Irb.CreateLoad(rule);
+		Value *RuleL = Irb.CreateLoad(Rule);
 		Value *Pcnt = Irb.CreateStructGEP(RuleL, 8);
-		AddOp = Irb.CreateAdd(Pcnt, ConstantInt::get(Pcnt->getType(), 1));
+		Value *PcntL = Irb.CreateLoad(Pcnt);
+		AddOp = Irb.CreateAdd(PcntL, ConstantInt::get(PcntL->getType(), 1));
 		Irb.CreateStore(AddOp, Pcnt);
 
 		// uint64_t bnct;
+		// int32_t pktlen
 		// (rule)->bcnt += pktlen;
-		// XXX pktlen->getType(): Int32Ty
-		Value *bcnt = Irb.CreateStructGEP(RuleL, 9);
-		AddOp = Irb.CreateAdd(bcnt, Pktlen);
-		Irb.CreateStore(AddOp, bcnt);
+		Value *Bcnt = Irb.CreateStructGEP(RuleL, 9);
+		Value *BcntL = Irb.CreateLoad(Bcnt);
+		Value *PktlenL = Irb.CreateLoad(Pktlen);
+		Value *PktlenL64 = Irb.CreateZExt(PktlenL, Int64Ty);
+		AddOp = Irb.CreateAdd(BcntL, PktlenL64);
+		Irb.CreateStore(AddOp, Bcnt);
 
+		// We have to fit 64 bits into 32
 		// (rule)->timestamp = time_uptime;
 		// uInt32_t timestamp;
-		// XXX timestamp->getType(): Int32Ty
-		// XXX time_uptime: int64Ty
-		Value *timestamp = Irb.CreateStructGEP(RuleL, 10);
-		Irb.CreateStore(time_uptime, timestamp);
+		// int64_t time_uptime;
+		Value *TimeUptimeL = Irb.CreateLoad(TimeUptime);
+		Value *TimeUptimeL32 = Irb.CreateTrunc(TimeUptimeL, Int32Ty);
+		Value *Timestamp = Irb.CreateStructGEP(RuleL, 10);
+		Irb.CreateStore(TimeUptimeL32, Timestamp);
 
-		Irb.SetInsertPoint(jf);
+		Irb.SetInsertPoint(Jf);
 		//	retval = IP_FW_DENY;
 		//	printf("ipfw: ouch!, skip past end of rules, denying packet\n");
 		Irb.CreateStore(ConstantInt::get(Int32Ty, IP_FW_DENY), Retval);
-		Irb.CreateCall(PrintfFunc, str);
+		Value *StrFirstElement = Irb.CreateStructGEP(Str, 0);
+		Irb.CreateCall(PrintfFunc, StrFirstElement);
 #ifndef __FreeBSD__
 		Irb.CreateBr(ret);
 #endif
@@ -807,17 +830,18 @@
 #ifdef __FreeBSD__
 		{
 			Irb.SetInsertPoint(End);
-			BasicBlock *cache_nnull;
+			BasicBlock *CacheNN = BasicBlock::Create(Con, "cachennull", Func);
 			// 	if (ucred_cache != NULL)
-			Comp = Irb.CreateICmpNE(Ucred_cache, ConstantPointerNull::get(UcredPtrTy));
-			Irb.CreateCondBr(Comp, cache_nnull, ret);
+			Comp = Irb.CreateICmpNE(Ucred_cache, 
+				ConstantPointerNull::get(UcredPtrTy));
+			Irb.CreateCondBr(Comp, CacheNN, Ret);
 
-			Irb.SetInsertPoint(cache_nnull);
-			Irb.CreateBr(ret);
+			Irb.SetInsertPoint(CacheNN);
+			Irb.CreateBr(Ret);
 		}
 #endif
 
-		Irb.SetInsertPoint(ret);
+		Irb.SetInsertPoint(Ret);
 		Irb.CreateRet(Retval);
 	}
 
@@ -840,16 +864,16 @@
 		// 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);
-		Check_tag = BasicBlock::Create(Con, "check_tag", Func);
-		End = BasicBlock::Create(Con, "end", Func);
+		Entry = BasicBlock::Create(Con, "Entry", Func);
+		End = BasicBlock::Create(Con, "End", Func);
+		Check_tag = BasicBlock::Create(Con, "CheckTag", Func);
 		// This is equivalent to the pullup_failed tag.
-		Pullup_failed = BasicBlock::Create(Con, "pullup_failed", Func);
+		Pullup_failed = BasicBlock::Create(Con, "PullupFailed", Func);
 		//Snippets of code to be executed when iterating through the rules.
-		Outer_for_prologue = BasicBlock::Create(Con, "outer_for_prologue", Func);
-		Inner_for_prologue = BasicBlock::Create(Con, "inner_for_prologue", Func);
-		Inner_for_epilogue = BasicBlock::Create(Con, "inner_for_epilogue", Func);
-		Outer_for_epilogue = BasicBlock::Create(Con, "outer_for_epilogue", Func);
+		Outer_for_prologue = BasicBlock::Create(Con, "OuterForPrologue", Func);
+		Inner_for_prologue = BasicBlock::Create(Con, "InnerForPrologue", Func);
+		Inner_for_epilogue = BasicBlock::Create(Con, "InnerForEpilogue", Func);
+		Outer_for_epilogue = BasicBlock::Create(Con, "OuterForEpilogue", Func);
 
 		// Get struct types, and store vars
 		setEnv();
@@ -875,10 +899,16 @@
 	funcptr
 	compile()
 	{
+		std::string errstr;
+		std::string comperr = "Compilation error\n";
+
 		// Check correctness.
 		verifyFunction(*Func);
 		verifyModule(*mod);
 
+		InitializeNativeTarget();
+		LLVMLinkInJIT();
+
 		//Optimise
 		PassManagerBuilder PMBuilder;
 		PMBuilder.OptLevel = 0;
@@ -891,13 +921,10 @@
 		PerFunctionPasses->doFinalization();
 		delete PerFunctionPasses;
 
-		//printf("\n\n\n\n");
-		//mod->getFunction("ipfw_chk_jit")->dump();
-
 		// Module passes
 		PassManager *PerModulePasses = new PassManager();
 		PMBuilder.populateModulePassManager(*PerModulePasses);
-		PerModulePasses->run(*mod);
+		//PerModulePasses->run(*mod);
 		delete PerModulePasses;
 
 		// We don't need it anymore.
@@ -905,11 +932,7 @@
 		vf->eraseFromParent();
 
 		//Compile
-		std::string errstr;
-		std::string comperr = "Compilation error\n";
-
 		EngineBuilder EB = EngineBuilder(std::unique_ptr<Module>(mod));
-		EB.setEngineKind(EngineKind::Kind::JIT);
 		EB.setErrorStr(&comperr);
 
 		ExecutionEngine *EE = EB.create();
@@ -918,7 +941,7 @@
 			exit(1);
 		}
 
-		printf("Function ptr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit"));
+		printf("FuncPtr: %p\n", (void *)EE->getFunctionAddress("ipfw_chk_jit"));
 		err(1,"null");
 		return (funcptr)EE->getFunctionAddress("ipfw_chk_jit");
 	}
@@ -991,12 +1014,17 @@
 		// 	proto == IPPROTO_UDP)
 		//		*match = 0;
 
+		// if (offset != 0)
+		//		return;
+
+		// if (proto == IPPROTO_TCP ||
+		// 	proto == IPPROTO_UDP)
+		//		*match = 0;
 	}
 
 	void
 	emit_recv()
 	{
-		// XXX Check correctness.
 		//*match = iface_match(m->m_pkthdr.rcvif, (ipfw_insn_if *)cmd, chain, tablearg);
 		Value *rcvif = Irb.CreateStructGEP(Irb.CreateStructGEP(Irb.CreateLoad(MPtr), 5), 0);
 		Value *cmdc = Irb.CreateBitCast(Cmd, Ipfw_insn_ifPtrTy);
@@ -1012,7 +1040,6 @@
 		Value *IfaceMatchCall = Irb.CreateCall4(Iface_match, Oif, Cmdc, Chain, Tablearg);
 		Irb.CreateStore(IfaceMatchCall, Match);
 	}
-
 };
 
 extern "C" funcptr


More information about the svn-soc-all mailing list