Commits

ebo committed db56ab4

Changed GenericBinOp to no longer need a stack copy.

  • Participants
  • Parent commits 2abea14

Comments (0)

Files changed (1)

  {
    if (!active_)
      return;
-@@ -189,6 +195,36 @@
+@@ -189,6 +195,46 @@
  
  namespace jit {
  
 +    return v;
 +  }
 +
++  JITValue *
++  JITStack::Second()
++  {
++    JITValue *w = this->Pop();
++    JITValue *v = this->Pop();
++    this->Push(v);
++    this->Push(w);
++    return v;
++  }
++
 +  // *******************************
 +
    JITTraceAnalysis::JITTraceAnalysis()
      : stack_counter_(0)
    {
-@@ -206,37 +242,52 @@
+@@ -206,37 +252,53 @@
      }
    }
  
 -      JITValue *v = stack_.back();
 -      stack_.pop_back();
 -      return v;
-+    JITStack stack_before((stack));
-+
 +    int opcode = entry.opcode;
-+    JITValue *w = stack.Pop();
-+    JITValue *v = stack.Pop();
++    JITValue *w = stack.Top();
++    JITValue *v = stack.Second();
 +    // std::cout << "binop "
 +    //           << (entry.arg0 ? entry.arg0->tp_name : "NULL")
 +    //           << " "
 +    if (impl->inlined()) {
 +      if (!type_v->hasGuard()) {
 +        type_v->setGuard(true);
-+        this->createGuardType(v, BH_NO_BLACKHOLE, entry.pc, stack_before);
++        this->createGuardType(v, BH_NO_BLACKHOLE, entry.pc, stack);
 +      }
 +
 +      if (!type_w->hasGuard()) {
 +        type_w->setGuard(true);
-+        this->createGuardType(w, BH_NO_BLACKHOLE, entry.pc, stack_before);
++        this->createGuardType(w, BH_NO_BLACKHOLE, entry.pc, stack);
 +      }
      }
  
 -    loaded_stack_.push_back(v);
 -    return v;
 -  }
-+    JITValue *x = this->createGenericBinOp(impl, inplace, v, w);
++    stack.Pop();
++    stack.Pop();
  
 -  JITValue *
 -  JITTraceAnalysis::Top()
 -    this->Push(v);
 -    return v;
 -  }
--
++    JITValue *x = this->createGenericBinOp(impl, inplace, v, w);
+ 
 -  void
 -  JITTraceAnalysis::Push(JITValue *value)
 -  {
      for (size_t i = 0; i < trace.size(); ++i) {
        TraceEntry &entry = trace[i];
        int opcode = entry.opcode;
-@@ -249,101 +300,86 @@
+@@ -249,101 +311,86 @@
  
  
        case POP_JUMP_IF_FALSE:
      llvm::Value *v_type =
        builder.CreateLoad(ObjectTy::ob_type(builder, v), "v_type");
      llvm::Value *tp_iternext =
-@@ -351,13 +387,14 @@
+@@ -351,13 +398,14 @@
                           "tp_iternext");
  
      value_ = fbuilder.getState()->CreateCall(tp_iternext, v);
      llvm::Value *localptr = fbuilder.LocalPtr(oparg_);
      llvm::Value *old = builder.CreateLoad(localptr);
      builder.CreateStore(v, localptr);
-@@ -370,6 +407,7 @@
+@@ -370,6 +418,7 @@
      JITFunctionState::BuilderT &builder = fbuilder.builder();
      llvm::Value *localptr = fbuilder.LocalPtr(oparg_);
      value_ = builder.CreateLoad(localptr);
    }
  
    void
-@@ -378,71 +416,34 @@
+@@ -378,71 +427,34 @@
      JITFunctionState::BuilderT &builder = fbuilder.builder();
      llvm::Value *localptr = fbuilder.ConstPtr(oparg_);
      value_ = builder.CreateLoad(localptr);
    }
  
    void
-@@ -452,11 +453,43 @@
+@@ -452,11 +464,43 @@
  
      Value *func = state->GetGlobalFunction<PyObject*(PyObject*, PyObject*, int)>("PyObject_RichCompare");
      value_ = state->CreateCall(func,
    }
  
    void
-@@ -468,13 +501,13 @@
+@@ -468,13 +512,13 @@
      llvm::BasicBlock *trace_cont = state->CreateBasicBlock("trace_cont");
      llvm::BasicBlock *bail = state->CreateBasicBlock("bail");
  
      }
      fbuilder.SetLastI(lasti_);
      fbuilder.SetBailReason(reason_);
-@@ -497,7 +530,7 @@
+@@ -497,7 +541,7 @@
      llvm::BasicBlock *bail_exc = state->CreateBasicBlock("bail_exc");
      llvm::BasicBlock *bail_cont = state->CreateBasicBlock("bail_cont");
  
      Value *py_true = state->EmbedPointer<PyObject*>(&_Py_TrueStruct);
      Value *py_false = state->EmbedPointer<PyObject*>(&_Py_FalseStruct);
  
-@@ -541,7 +574,7 @@
+@@ -541,7 +585,7 @@
  
      state->DecRef(v);
      for (size_t i = 0; i < stack_.size(); ++i) {
      }
      fbuilder.SetLastI(lasti_);
      fbuilder.CreateBailBr();
-@@ -554,7 +587,7 @@
+@@ -554,7 +598,7 @@
    JITTraceEnd::emit(JITFunctionBuilder &fbuilder)
    {
      for (size_t i = 0; i < stack_.size(); ++i) {
      }
      fbuilder.CreateEntryBr();
    }
-@@ -563,7 +596,22 @@
+@@ -563,7 +607,22 @@
    JITIncRef::emit(JITFunctionBuilder &fbuilder)
    {
      JITFunctionState *state = fbuilder.getState();
      {}
  
      virtual void dump()
-@@ -357,24 +588,39 @@
+@@ -357,24 +588,41 @@
  
      virtual void emit(JITFunctionBuilder &builder);
  
    private:
      std::vector<JITValue *> stack_;
 -    llvm::Value *value_;
-   };
- 
--  struct JITTraceAnalysis {
--    JITTraceAnalysis();
--
--    void analyseTrace(std::vector<TraceEntry> &trace);
++  };
++
 +  class JITStack {
 +  public:
 +    JITStack()
 +    {}
 +    ~JITStack()
 +    {}
- 
-     void Push(JITValue *value);
-     JITValue *Pop();
-     JITValue *Top();
- 
++
++    void Push(JITValue *value);
++    JITValue *Pop();
++
++    JITValue *Top();
++    JITValue *Second();
++
 +    std::vector<JITValue *> stack;
 +    std::vector<JITStackValue *> loaded_stack;
 +    int stack_counter;
-+  };
-+
-+  struct JITTraceAnalysis {
+   };
+ 
+   struct JITTraceAnalysis {
 +    typedef std::vector<JITValue *> stack_t;
 +
-+    JITTraceAnalysis();
-+
-+    void analyseTrace(std::vector<TraceEntry> &trace);
-+
+     JITTraceAnalysis();
+ 
+     void analyseTrace(std::vector<TraceEntry> &trace);
+ 
+-    void Push(JITValue *value);
+-    JITValue *Pop();
+-    JITValue *Top();
+-
      void dump()
      {
        for (size_t i = 0; i < loaded_stack_.size(); ++i) {
-@@ -387,6 +633,15 @@
+@@ -387,6 +635,15 @@
  
      void emit(JITFunctionState &state);
  
      JITForIter *createForIter(JITValue *v)
      {
        JITForIter *r = new JITForIter(v);
-@@ -394,37 +649,9 @@
+@@ -394,37 +651,9 @@
        return r;
      }
  
        trace_.push_back(r);
        return r;
      }
-@@ -436,16 +663,23 @@
+@@ -436,16 +665,23 @@
        return r;
      }
  
        trace_.push_back(r);
        return r;
      }
-@@ -478,19 +712,18 @@
+@@ -478,19 +714,18 @@
        return r;
      }