socsvn commit: r271868 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw
dpl at FreeBSD.org
dpl at FreeBSD.org
Mon Aug 4 19:31:00 UTC 2014
Author: dpl
Date: Mon Aug 4 19:30:59 2014
New Revision: 271868
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271868
Log:
Added the basic starting 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 Mon Aug 4 19:30:13 2014 (r271867)
+++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Mon Aug 4 19:30:59 2014 (r271868)
@@ -32,106 +32,135 @@
using namespace llvm;
-class jitCompiler {
+class ipfwJIT {
private:
- Module *mod;
- LLVMContext con;
- LLVMContext &c = con;
- OwningPtr<MemoryBuffer> buffer;
- //IRBuilder<> irb;
- public:
- Module *loadbc(std::string name)
- {
- /* We load the bc for JIT compilation */
- error_code ec = MemoryBuffer::getFile(name, buffer);
- if (ec) {
- std::cerr << "Failed to open bitcode: " << ec.message() << "\n";
- return (NULL);
- }
-
- ErrorOr<Module*> ptr = parseBitcodeFile(buffer.get(), con);
- if ((ec = ptr.getError()))
- {
- std::cerr << "Failed to parse bitcode: " << ec.message() << "\n";
- return (NULL);
- }
- return (ptr.get());
+ Module *mod;
+ Function *func;
+ LLVMContext con;
+ OwningPtr<MemoryBuffer> buffer;
+ IRBuilder<> irb;
+ std::vector<BasicBlock> BBs;
+
+ Module *loadbc(std::string name)
+ {
+ /* We load the bc for JIT compilation */
+ error_code ec = MemoryBuffer::getFile(name, buffer);
+ if (ec) {
+ std::cerr << "Failed to open bitcode: " << ec.message() << "\n";
+ return (NULL);
}
- int
- emit_nop(Type *match)
+ ErrorOr<Module*> ptr = parseBitcodeFile(buffer.get(), con);
+ if ((ec = ptr.getError()))
{
- /*
- static IPFW_RULES_INLINE void
- rule_nop(int *match)
- {
- *match = 1;
- }
- // Get the stub (prototype) for the cell function
- F = Mod->getFunction("cell");
- // Set it to have private linkage, so that it can be removed after being
- // inlined.
- F->setLinkage(GlobalValue::PrivateLinkage);
-
- // Add an entry basic block to this function and set it
- BasicBlock *entry = BasicBlock::Create(C, "entry", F);
- B.SetInsertPoint(entry);
- // Cache the type of registers
- regTy = Type::getInt16Ty(C);
-
- // Collect the function parameters
- auto args = F->arg_begin();
- oldGrid = args++;
- newGrid = args++;
- width = args++;
- height = args++;
- x = args++;
- y = args++;
+ std::cerr << "Failed to parse bitcode: " << ec.message() << "\n";
+ return (NULL);
+ }
+ mod = ptr.get();
+ return (mod);
+ }
- // Create space on the stack for the local registers
- for (int i=0 ; i<10 ; i++)
- {
- a[i] = B.CreateAlloca(regTy);
- }
+ /* Set the needed variables to perform pkt filtering. */
+ int
+ setVars()
+ {
+ //We need the match var.
+ Value *match;
+ Value *f_pos;
+ return (0);
+ }
- // Create a space on the stack for the current value. This can be
- // assigned to, and will be returned at the end. Store the value passed
- // as a parameter in this.
- v = B.CreateAlloca(regTy);
- B.CreateStore(args++, v);
- // Create a load of pointers to the global registers.
- Value *gArg = args;
- for (int i=0 ; i<10 ; i++)
+ public:
+ ipfwJIT(): irb(con)
+ {
+ //Create the module and load the code.
+ mod = loadbc("ip_fw_rules.bc");
+ setVars();
+ //Create Function, and start its first BasicBlock.
+ //int ipfw_chk_jitted(ip_fw_args *);
+ // XXX Do we have to define ip_fw_args using this?
+ StructType ipfwargsTy = StructType::get(/*TYPE1, TYPE2, TYPE3...*/);
+ Type *argsTy[] = { PointerType::getUnqual(ipfwargsTy) };
+ FunctionType *ipfwchkTy = FunctionType::get(Int32Ty, argsTy, false);
+ func = Function::Create(ipfwchkTy, GlobalValue::PrivateLinkage, "ipfw_chk", mod);
+
+ // XXX Create basic block, and add it to BBs
+
+ }
+ ~ipfwJIT()
+ {
+ if (mod)
+ delete mod;
+ }
+
+ int
+ emit_nop(int *match)
+ {
+ /*
+ static IPFW_RULES_INLINE void
+ rule_nop(int *match)
{
- B.CreateStore(ConstantInt::get(regTy, 0), a[i]);
- g[i] = B.CreateConstGEP1_32(gArg, i);
+ *match = 1;
}
- */
- return (0);
- }
+ // Get the stub (prototype) for the cell function
+ F = Mod->getFunction("cell");
+ // Set it to have private linkage, so that it can be removed after being
+ // inlined.
+ F->setLinkage(GlobalValue::PrivateLinkage);
+
+ // Add an entry basic block to this function and set it
+ BasicBlock *entry = BasicBlock::Create(C, "entry", F);
+ B.SetInsertPoint(entry);
+ // Cache the type of registers
+ regTy = Type::getInt16Ty(C);
+
+ // Collect the function parameters
+ auto args = F->arg_begin();
+ oldGrid = args++;
+ newGrid = args++;
+ width = args++;
+ height = args++;
+ x = args++;
+ y = args++;
- int
- emit_forward_mac()
+ // Create space on the stack for the local registers
+ for (int i=0 ; i<10 ; i++)
{
- return (0);
+ a[i] = B.CreateAlloca(regTy);
}
- /* Set the needed variables to perform pkt filtering. */
- int
- setVars()
+ // Create a space on the stack for the current value. This can be
+ // assigned to, and will be returned at the end. Store the value passed
+ // as a parameter in this.
+ v = B.CreateAlloca(regTy);
+ B.CreateStore(args++, v);
+ // Create a load of pointers to the global registers.
+ Value *gArg = args;
+ for (int i=0 ; i<10 ; i++)
{
- return (0);
+ B.CreateStore(ConstantInt::get(regTy, 0), a[i]);
+ g[i] = B.CreateConstGEP1_32(gArg, i);
}
+ */
+ return (0);
+ }
+
+ int
+ emit_forward_mac()
+ {
+ return (0);
+ }
};
extern "C" funcptr
compile_code(struct ip_fw_args *args, struct ip_fw_chain *chain)
{
- int f_pos, res;
- Module *bc;
- jitCompiler comp;
+ int res;
+ ipfwJIT comp;
+ Module *mod;
- bc = comp.loadbc("ip_fw_rules.bc");
+ int f_pos = 0;
+ int retval = 0;
// Now I have to load the stubs of the loaded rules.
// Iterate through the rules.
@@ -192,7 +221,7 @@
switch (cmd->opcode) {
case O_NOP:
- comp.emit_nop(*match);
+ comp.emit_nop(&match);
break;
case O_FORWARD_MAC:
@@ -608,3 +637,4 @@
return (0);
}
+}
More information about the svn-soc-all
mailing list