ebo avatar ebo committed cf5d8aa

Various cleanups

Comments (0)

Files changed (1)

 +
 +private:
 +  void do_trace(PyCodeObject *code, size_t start);
-+
++  bool verify_trace(std::vector<TraceEntry> &trace);
 +
 +private:
 +  bool active_;
 new file mode 100644
 --- /dev/null
 +++ b/JIT/jit_tracer.cc
-@@ -0,0 +1,904 @@
+@@ -0,0 +1,889 @@
 +#include "Python.h"
 +#include "opcode.h"
 +
 +{
 +}
 +
-+#define JIT_COMPILE_TIME
-+void
-+PyJITTracer::do_trace(PyCodeObject *code, size_t start)
++bool
++PyJITTracer::verify_trace(std::vector<TraceEntry> &trace)
 +{
-+#ifdef JIT_COMPILE_TIME
-+  _PyTime_timeval t;
-+  _PyTime_gettimeofday(&t);
-+  double t0 = (double)t.tv_sec + t.tv_usec * 1e-6;
-+#endif
-+
-+  std::vector<TraceEntry> cut_trace(trace_.begin() + start, trace_.end());
-+  bool verified = true;
-+  for (size_t i = 0; i < cut_trace.size(); ++i) {
-+    int pc = cut_trace[i].pc;
-+    int opcode = cut_trace[i].opcode;
-+    int oparg = cut_trace[i].oparg;
-+    int flag = cut_trace[i].flag;
++  for (size_t i = 0; i < trace.size(); ++i) {
++    int pc = trace[i].pc;
++    int opcode = trace[i].opcode;
++    int oparg = trace[i].oparg;
++    int flag = trace[i].flag;
 +    switch (opcode) {
 +    case POP_JUMP_IF_FALSE:
 +      if (flag != TR_STANDARD) {
-+      // if (flag != TR_STANDARD && flag != TR_JUMP_TAKEN) {
-+        verified = false;
++        // if (flag != TR_STANDARD && flag != TR_JUMP_TAKEN) {
++        return false;
 +      }
 +      break;
 +
 +
 +    case BINARY_SUBSCR:
 +      if (flag != TR_STANDARD) {
-+        verified = false;
++        return false;
 +      }
 +      break;
 +
 +        break;
 +      default:
 +        std::cout << opcode << "/" << oparg << " ";
-+        verified = false;
++        std::cout << "(" << pc << " " << opcode << ")";
++        return false;
 +        break;
 +      }
 +      if (flag != TR_STANDARD) {
-+        verified = false;
++        return false;
 +      }
 +      break;
 +
 +    default:
-+      std::cout << "(" << pc << " " << opcode << ") ";
-+      verified = false;
++      std::cout << "(" << pc << " " << opcode << ")";
++      return false;
 +      break;
 +    }
 +  }
-+  if (!verified) {
++  return true;
++}
++
++#define JIT_COMPILE_TIME
++void
++PyJITTracer::do_trace(PyCodeObject *code, size_t start)
++{
++#ifdef JIT_COMPILE_TIME
++  _PyTime_timeval t;
++  _PyTime_gettimeofday(&t);
++  double t0 = (double)t.tv_sec + t.tv_usec * 1e-6;
++#endif
++
++  std::vector<TraceEntry> cut_trace(trace_.begin() + start, trace_.end());
++  if (!this->verify_trace(cut_trace)) {
 +    std::cout << "Trace contains unkown opcodes\n";
 +    unsuspend();
 +    return;
 +  }
 +
-+  verified = true;
-+  for (size_t i = 0; i < cut_trace.size(); ++i) {
-+    // int pc = trace_[i].pc;
-+    // int opcode = trace_[i].opcode;
-+    // int oparg = trace_[i].oparg;
-+
-+    bool can_inline = false;
-+    // switch (opcode) {
-+    // default:
-+    //   verified = false;
-+    // }
-+    if (!can_inline && i < cut_trace.size() - 1) {
-+      if (cut_trace[i].code != cut_trace[i + 1].code) {
-+        verified = false;
-+      }
-+    }
-+  }
-+  if (!verified) {
-+    std::cout << "Code-Object changed after no-inline opcode\n";
-+    return;
-+  }
-+
-+
 +  jit::JITTraceAnalysis analysis;
 +  analysis.analyseTrace(cut_trace);
 +  // std::cout << "-------------------------------\n";
 +
 +  // state.function()->dump();
 +  PyGlobalJITData::Get()->optimize(state.function());
-+  state.function()->dump();
++  // state.function()->dump();
 +
 +  if (code->co_jit == NULL) {
 +    int codesize = PyBytes_GET_SIZE(code->co_code);
 +
 +    builder.SetInsertPoint(trace_cont);
 +
-+    Value *as_tuple = builder.CreateBitCast(args, PyTypeBuilder<PyTupleObject*>::get(state->context()));
-+    Value *items = TupleTy::ob_item(builder, as_tuple);
-+    items = builder.CreateBitCast(items, PyTypeBuilder<PyObject**>::get(state->context()));
++    Value *as_tuple =
++      builder.CreateBitCast(args,
++                            PyTypeBuilder<PyTupleObject*>::get(state->context()));
++    Value *items =
++      builder.CreateBitCast(TupleTy::ob_item(builder, as_tuple),
++                            PyTypeBuilder<PyObject**>::get(state->context()));
 +    for (size_t i = 0; i < args_.size(); ++i) {
-+      Value *gep = builder.CreateGEP(items,
-+                                     ConstantInt::getSigned(Type::getInt32Ty(state->context()), i));
-+      gep->dump();
-+      gep->getType()->dump();
++      Value *gep =
++        builder.CreateGEP(items,
++                          ConstantInt::getSigned(Type::getInt32Ty(state->context()), i));
 +      builder.CreateStore(args_[i]->getValue(fbuilder),
 +                          gep);
 +    }
 new file mode 100644
 --- /dev/null
 +++ b/dotests.py
-@@ -0,0 +1,224 @@
+@@ -0,0 +1,235 @@
 +import unittest
 +import _jit
 +
 +        self.analyse(doit, self.seq_float)
 +        self.analyse(doit, self.seq_int)
 +
++    def testCallSimple(self):
++        def doit(seq):
++            acc = 0.0
++            for i in seq:
++                i = float(i)
++                acc += i
++            return acc
++
++        self.analyse(doit, self.seq_float)
++        self.analyse(doit, self.seq_int)
++
 +
 +class TestCompares(Utilities, unittest.TestCase):
 +    def testComparesSimple(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.