[unladen-swallow] r1165 committed - Change the opcode files to comply to the this-> policy we have to acce...

1 view
Skip to first unread message

unladen...@googlecode.com

unread,
Jul 29, 2010, 2:51:32 AM7/29/10
to unladen...@googlegroups.com
Revision: 1165
Author: e...@4geeks.de
Date: Wed Jul 28 23:50:04 2010
Log: Change the opcode files to comply to the this-> policy we have to
access member variables in C++.

It also removes all friend-statements from llvm_fbuilder.h

http://code.google.com/p/unladen-swallow/source/detail?r=1165

Modified:
/trunk/JIT/llvm_compile.cc
/trunk/JIT/llvm_fbuilder.cc
/trunk/JIT/llvm_fbuilder.h
/trunk/JIT/opcodes/attributes.cc
/trunk/JIT/opcodes/attributes.h
/trunk/JIT/opcodes/binops.cc
/trunk/JIT/opcodes/block.cc
/trunk/JIT/opcodes/block.h
/trunk/JIT/opcodes/call.cc
/trunk/JIT/opcodes/call.h
/trunk/JIT/opcodes/closure.cc
/trunk/JIT/opcodes/closure.h
/trunk/JIT/opcodes/cmpops.cc
/trunk/JIT/opcodes/cmpops.h
/trunk/JIT/opcodes/container.cc
/trunk/JIT/opcodes/container.h
/trunk/JIT/opcodes/control.cc
/trunk/JIT/opcodes/control.h
/trunk/JIT/opcodes/globals.cc
/trunk/JIT/opcodes/globals.h
/trunk/JIT/opcodes/locals.cc
/trunk/JIT/opcodes/locals.h
/trunk/JIT/opcodes/loop.cc
/trunk/JIT/opcodes/loop.h
/trunk/JIT/opcodes/name.cc
/trunk/JIT/opcodes/slice.cc
/trunk/JIT/opcodes/stack.cc
/trunk/JIT/opcodes/unaryops.cc

=======================================
--- /trunk/JIT/llvm_compile.cc Tue Jun 15 13:27:27 2010
+++ /trunk/JIT/llvm_compile.cc Wed Jul 28 23:50:04 2010
@@ -253,7 +253,7 @@
// doing this check here saves us having to iterate over the
opcodes
// again.
case DELETE_FAST:
- fbuilder.uses_delete_fast = true;
+ fbuilder.uses_delete_fast() = true;
continue;

default:
=======================================
--- /trunk/JIT/llvm_fbuilder.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/llvm_fbuilder.cc Wed Jul 28 23:50:04 2010
@@ -66,8 +66,7 @@

LlvmFunctionBuilder::LlvmFunctionBuilder(
LlvmFunctionState *state, PyCodeObject *code_object)
- : uses_delete_fast(false),
- state_(state),
+ : state_(state),
llvm_data_(state->llvm_data()),
code_object_(code_object),
context_(this->llvm_data_->context()),
@@ -94,7 +93,8 @@
false, // Not local to unit.
true)), // Is definition.
error_(false),
- is_generator_(code_object->co_flags & CO_GENERATOR)
+ is_generator_(code_object->co_flags & CO_GENERATOR),
+ uses_delete_fast_(false)
{
Function::arg_iterator args = this->function_->arg_begin();
this->frame_ = args++;
@@ -1224,6 +1224,34 @@
this->builder_.SetInsertPoint(done);
return this->builder_.CreateLoad(result_addr);
}
+
+void
+LlvmFunctionBuilder::WatchType(PyTypeObject *type)
+{
+ this->types_used_.insert(type);
+}
+
+void
+LlvmFunctionBuilder::WatchDict(int reason)
+{
+ this->uses_watched_dicts_.set(reason);
+}
+
+
+Value *
+LlvmFunctionBuilder::GetUseJitCond()
+{
+ Value *use_jit = this->builder_.CreateLoad(this->use_jit_addr_,
+ "co_use_jit");
+ return this->state()->IsNonZero(use_jit);
+}
+
+void
+LlvmFunctionBuilder::AddYieldResumeBB(llvm::ConstantInt *number,
+ llvm::BasicBlock *block)
+{
+ this->yield_resume_switch_->addCase(number, block);
+}

int
LlvmFunctionBuilder::FinishFunction()
=======================================
--- /trunk/JIT/llvm_fbuilder.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/llvm_fbuilder.h Wed Jul 28 23:50:04 2010
@@ -30,22 +30,6 @@

namespace py {

-class OpcodeAttributes;
-class OpcodeBinops;
-class OpcodeBlock;
-class OpcodeCall;
-class OpcodeClosure;
-class OpcodeCmpops;
-class OpcodeContainer;
-class OpcodeControl;
-class OpcodeGlobals;
-class OpcodeLocals;
-class OpcodeLoop;
-class OpcodeName;
-class OpcodeSlice;
-class OpcodeStack;
-class OpcodeUnaryops;
-
/// Helps the compiler build LLVM functions corresponding to Python
/// functions. This class maintains all Value*s which depend on a
/// single frame/code object. It also contains all functions that
@@ -54,37 +38,63 @@
LlvmFunctionBuilder(const LlvmFunctionBuilder &); // Not implemented.
void operator=(const LlvmFunctionBuilder &); // Not implemented.

- friend class AttributeAccessor;
- friend class OpcodeAttributes;
- friend class OpcodeBinops;
- friend class OpcodeBlock;
- friend class OpcodeCall;
- friend class OpcodeClosure;
- friend class OpcodeCmpops;
- friend class OpcodeContainer;
- friend class OpcodeControl;
- friend class OpcodeGlobals;
- friend class OpcodeLocals;
- friend class OpcodeLoop;
- friend class OpcodeName;
- friend class OpcodeSlice;
- friend class OpcodeStack;
- friend class OpcodeUnaryops;
-
public:
LlvmFunctionBuilder(LlvmFunctionState *state, PyCodeObject *code);

llvm::Function *function() { return function_; }
typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
BuilderT& builder() { return builder_; }
- llvm::BasicBlock *unreachable_block() { return unreachable_block_; }
LlvmFunctionState *state() const { return this->state_; }
+ PyCodeObject *code_object() const { return this->code_object_; }
+ PyGlobalLlvmData *llvm_data() const { return this->llvm_data_; }
+ llvm::LLVMContext& context() { return this->context_; }
+ bool& uses_delete_fast() { return this->uses_delete_fast_; }
+
+ llvm::BasicBlock *unreachable_block() const
+ {
+ return this->unreachable_block_;
+ }
+ llvm::BasicBlock *unwind_block() const { return this->unwind_block_; }
+ llvm::BasicBlock *do_return_block() const { return
this->do_return_block_; }
+
+ llvm::Value *unwind_reason_addr() const
+ {
+ return this->unwind_reason_addr_;
+ }
+ llvm::Value *retval_addr() const
+ {
+ return this->retval_addr_;
+ }
+ llvm::Value *num_blocks_addr() const
+ {
+ return this->num_blocks_addr_;
+ }
+ llvm::Value *blockstack_addr() const
+ {
+ return this->blockstack_addr_;
+ }
+ llvm::Value *stack_pointer_addr() const
+ {
+ return this->stack_pointer_addr_;
+ }
+ llvm::Value *f_lasti_addr() const { return this->f_lasti_addr_; }
+
+ llvm::Value *stack_bottom() const { return this->stack_bottom_; }
+
+ llvm::Value *freevars() const { return this->freevars_; }
+ llvm::Value *frame() const { return this->frame_; }
+ llvm::Value *globals() const { return this->globals_; }
+ llvm::Value *builtins() const { return this->builtins_; }
+ llvm::Value *fastlocals() const { return this->fastlocals_; }
+
+ llvm::Value *GetLocal(int i) const { return this->locals_[i]; }

bool Error() { return this->error_; }

/// Sets the current instruction index. This is only put into the
/// frame object when tracing.
void SetLasti(int current_instruction_index);
+ int GetLasti() const { return this->f_lasti_; }

/// Sets the current line number being executed. This is used to
/// make tracebacks correct and to get tracing to fire in the
@@ -255,7 +265,16 @@
/// exception.
llvm::BasicBlock *GetExceptionBlock() const;

- bool uses_delete_fast;
+ // Add a Type to the watch list.
+ void WatchType(PyTypeObject *type);
+
+ void WatchDict(int reason);
+
+ // Return a i1 which is true when the use_jit field is set in the
+ // code object
+ llvm::Value *GetUseJitCond();
+
+ void AddYieldResumeBB(llvm::ConstantInt *number, llvm::BasicBlock
*block);

private:
LlvmFunctionState *state_;
@@ -271,12 +290,6 @@
llvm::DIFactory &debug_info_;
const llvm::DICompileUnit debug_compile_unit_;
const llvm::DISubprogram debug_subprogram_;
- const bool is_generator_;
-
- // True if something went wrong and we need to stop compilation without
- // aborting the process. If this is true, a Python error has already
- // been set.
- bool error_;

// The most recent index we've started emitting an instruction for.
int f_lasti_;
@@ -340,6 +353,14 @@
llvm::Value *retval_addr_;

llvm::SmallPtrSet<PyTypeObject*, 5> types_used_;
+
+ // True if something went wrong and we need to stop compilation without
+ // aborting the process. If this is true, a Python error has already
+ // been set.
+ bool error_;
+
+ const bool is_generator_;
+ bool uses_delete_fast_;
};

} // namespace py
=======================================
--- /trunk/JIT/opcodes/attributes.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/attributes.cc Wed Jul 28 23:50:04 2010
@@ -86,7 +86,10 @@
namespace py {

OpcodeAttributes::OpcodeAttributes(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder()),
+ llvm_data_(fbuilder->llvm_data())
{
}

@@ -102,23 +105,23 @@
void
OpcodeAttributes::LOAD_ATTR_safe(int names_index)
{
- Value *attr = fbuilder_->LookupName(names_index);
- Value *obj = fbuilder_->Pop();
- Function *pyobj_getattr = state_->GetGlobalFunction<
+ Value *attr = this->fbuilder_->LookupName(names_index);
+ Value *obj = this->fbuilder_->Pop();
+ Function *pyobj_getattr = this->state_->GetGlobalFunction<
PyObject *(PyObject *, PyObject *)>("PyObject_GetAttr");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
pyobj_getattr, obj, attr, "LOAD_ATTR_result");
- state_->DecRef(obj);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->state_->DecRef(obj);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

bool
OpcodeAttributes::LOAD_ATTR_fast(int names_index)
{
PyObject *name =
- PyTuple_GET_ITEM(fbuilder_->code_object_->co_names, names_index);
- AttributeAccessor accessor(fbuilder_, name, ATTR_ACCESS_LOAD);
+ PyTuple_GET_ITEM(this->fbuilder_->code_object()->co_names,
names_index);
+ AttributeAccessor accessor(this->fbuilder_, name, ATTR_ACCESS_LOAD);

// Check that we can optimize this load.
if (!accessor.CanOptimizeAttrAccess()) {
@@ -127,17 +130,17 @@
ACCESS_ATTR_INC_STATS(optimized_loads);

// Emit the appropriate guards.
- Value *obj_v = fbuilder_->Pop();
- BasicBlock *do_load = state_->CreateBasicBlock("LOAD_ATTR_do_load");
+ Value *obj_v = this->fbuilder_->Pop();
+ BasicBlock *do_load =
this->state_->CreateBasicBlock("LOAD_ATTR_do_load");
accessor.GuardAttributeAccess(obj_v, do_load);

// Call the inline function that deals with the lookup. LLVM
propagates
// these constant arguments through the body of the function.
- fbuilder_->builder_.SetInsertPoint(do_load);
- PyConstantMirror &mirror = fbuilder_->llvm_data_->constant_mirror();
+ this->builder_.SetInsertPoint(do_load);
+ PyConstantMirror &mirror = llvm_data_->constant_mirror();
Value *descr_get_v = mirror.GetGlobalForFunctionPointer<descrgetfunc>(
(void*)accessor.descr_get_, "");
- Value *getattr_func = state_->GetGlobalFunction<
+ Value *getattr_func = this->state_->GetGlobalFunction<
PyObject *(PyObject *obj, PyTypeObject *type, PyObject *name,
long dictoffset, PyObject *descr, descrgetfunc
descr_get,
char is_data_descr)>("_PyLlvm_Object_GenericGetAttr");
@@ -150,13 +153,13 @@
descr_get_v,
accessor.is_data_descr_v_
};
- Value *result = state_->CreateCall(getattr_func,
- args, array_endof(args));
+ Value *result = this->state_->CreateCall(getattr_func,
+ args, array_endof(args));

// Put the result on the stack and possibly propagate an exception.
- state_->DecRef(obj_v);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->state_->DecRef(obj_v);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
return true;
}

@@ -172,24 +175,24 @@
void
OpcodeAttributes::STORE_ATTR_safe(int names_index)
{
- Value *attr = fbuilder_->LookupName(names_index);
- Value *obj = fbuilder_->Pop();
- Value *value = fbuilder_->Pop();
- Function *pyobj_setattr = state_->GetGlobalFunction<
+ Value *attr = this->fbuilder_->LookupName(names_index);
+ Value *obj = this->fbuilder_->Pop();
+ Value *value = this->fbuilder_->Pop();
+ Function *pyobj_setattr = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *, PyObject *)>("PyObject_SetAttr");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
pyobj_setattr, obj, attr, value, "STORE_ATTR_result");
- state_->DecRef(obj);
- state_->DecRef(value);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ this->state_->DecRef(obj);
+ this->state_->DecRef(value);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

bool
OpcodeAttributes::STORE_ATTR_fast(int names_index)
{
PyObject *name =
- PyTuple_GET_ITEM(fbuilder_->code_object_->co_names, names_index);
- AttributeAccessor accessor(fbuilder_, name, ATTR_ACCESS_STORE);
+ PyTuple_GET_ITEM(this->fbuilder_->code_object()->co_names,
names_index);
+ AttributeAccessor accessor(this->fbuilder_, name, ATTR_ACCESS_STORE);

// Check that we can optimize this store.
if (!accessor.CanOptimizeAttrAccess()) {
@@ -198,18 +201,19 @@
ACCESS_ATTR_INC_STATS(optimized_stores);

// Emit appropriate guards.
- Value *obj_v = fbuilder_->Pop();
- BasicBlock *do_store = state_->CreateBasicBlock("STORE_ATTR_do_store");
+ Value *obj_v = this->fbuilder_->Pop();
+ BasicBlock *do_store =
+ this->state_->CreateBasicBlock("STORE_ATTR_do_store");
accessor.GuardAttributeAccess(obj_v, do_store);

// Call the inline function that deals with the lookup. LLVM
propagates
// these constant arguments through the body of the function.
- fbuilder_->builder_.SetInsertPoint(do_store);
- Value *val_v = fbuilder_->Pop();
- PyConstantMirror &mirror = fbuilder_->llvm_data_->constant_mirror();
+ this->builder_.SetInsertPoint(do_store);
+ Value *val_v = this->fbuilder_->Pop();
+ PyConstantMirror &mirror = llvm_data_->constant_mirror();
Value *descr_set_v = mirror.GetGlobalForFunctionPointer<descrsetfunc>(
(void*)accessor.descr_set_, "");
- Value *setattr_func = state_->GetGlobalFunction<
+ Value *setattr_func = this->state_->GetGlobalFunction<
int (PyObject *obj, PyObject *val, PyTypeObject *type, PyObject
*name,
long dictoffset, PyObject *descr, descrsetfunc descr_set,
char is_data_descr)>("_PyLlvm_Object_GenericSetAttr");
@@ -223,12 +227,12 @@
descr_set_v,
accessor.is_data_descr_v_
};
- Value *result = state_->CreateCall(setattr_func, args,
- array_endof(args));
-
- state_->DecRef(obj_v);
- state_->DecRef(val_v);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ Value *result = this->state_->CreateCall(setattr_func, args,
+ array_endof(args));
+
+ this->state_->DecRef(obj_v);
+ this->state_->DecRef(val_v);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
return true;
}

@@ -308,7 +312,7 @@
// Now that we know for sure that we are going to optimize this
lookup, add
// the type to the list of types we need to listen for modifications
from
// and make the llvm::Values.
- this->fbuilder_->types_used_.insert(type);
+ this->fbuilder_->WatchType(type);
MakeLlvmValues();

return true;
@@ -339,11 +343,11 @@
state->EmbedPointer<PyTypeObject*>(this->guard_type_);
this->name_v_ = state->EmbedPointer<PyObject*>(this->name_);
this->dictoffset_v_ =
-
ConstantInt::get(PyTypeBuilder<long>::get(this->fbuilder_->context_),
+
ConstantInt::get(PyTypeBuilder<long>::get(this->fbuilder_->context()),
this->dictoffset_);
this->descr_v_ = state->EmbedPointer<PyObject*>(this->descr_);
this->is_data_descr_v_ =
-
ConstantInt::get(PyTypeBuilder<char>::get(this->fbuilder_->context_),
+
ConstantInt::get(PyTypeBuilder<char>::get(this->fbuilder_->context()),
this->is_data_descr_);
}

@@ -361,9 +365,7 @@

// Make sure that the code object is still valid. This may fail if the
// code object is invalidated inside of a call to the code object.
- Value *use_jit = builder.CreateLoad(fbuilder->use_jit_addr_,
- "co_use_jit");
- builder.CreateCondBr(state->IsNonZero(use_jit), guard_type,
bail_block);
+ builder.CreateCondBr(fbuilder->GetUseJitCond(), guard_type,
bail_block);

// Compare ob_type against type and bail if it's the wrong type. Since
// we've subscribed to the type object for modification updates, the
code
@@ -379,7 +381,7 @@
// descriptor type.
builder.SetInsertPoint(guard_descr);
if (this->descr_ != NULL) {
- fbuilder->types_used_.insert(this->guard_descr_type_);
+ fbuilder->WatchType(this->guard_descr_type_);
Value *descr_type_v =
builder.CreateLoad(ObjectTy::ob_type(builder, this->descr_v_));
Value *guard_descr_type_v =
@@ -400,15 +402,15 @@
void
OpcodeAttributes::DELETE_ATTR(int index)
{
- Value *attr = fbuilder_->LookupName(index);
- Value *obj = fbuilder_->Pop();
- Value *value = state_->GetNull<PyObject*>();
- Function *pyobj_setattr = state_->GetGlobalFunction<
+ Value *attr = this->fbuilder_->LookupName(index);
+ Value *obj = this->fbuilder_->Pop();
+ Value *value = this->state_->GetNull<PyObject*>();
+ Function *pyobj_setattr = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *, PyObject *)>("PyObject_SetAttr");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
pyobj_setattr, obj, attr, value, "DELETE_ATTR_result");
- state_->DecRef(obj);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ this->state_->DecRef(obj);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

}
=======================================
--- /trunk/JIT/opcodes/attributes.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/attributes.h Wed Jul 28 23:50:04 2010
@@ -13,6 +13,8 @@
class BasicBlock;
class Value;
}
+
+class PyGlobalLlvmData;

namespace py {

@@ -28,7 +30,6 @@
ATTR_ACCESS_STORE
};

-
// This class encapsulates the common data and code for doing optimized
// attribute access. This object helps perform checks, generate guard
// code, and register invalidation listeners when generating an optimized
@@ -137,8 +138,12 @@
void STORE_ATTR_safe(int names_index);
bool STORE_ATTR_fast(int names_index);

- LlvmFunctionBuilder *fbuilder_;
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
+ LlvmFunctionBuilder *const fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
+ PyGlobalLlvmData *const llvm_data_;
};

}
=======================================
--- /trunk/JIT/opcodes/binops.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/binops.cc Wed Jul 28 23:50:04 2010
@@ -59,22 +59,22 @@
void
OpcodeBinops::GenericBinOp(const char *apifunc)
{
- Value *rhs = fbuilder_->Pop();
- Value *lhs = fbuilder_->Pop();
- Function *op =
- state_->GetGlobalFunction<PyObject*(PyObject*,
PyObject*)>(apifunc);
- Value *result = state_->CreateCall(op, lhs, rhs, "binop_result");
- state_->DecRef(lhs);
- state_->DecRef(rhs);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ Value *rhs = this->fbuilder_->Pop();
+ Value *lhs = this->fbuilder_->Pop();
+ Function *op = this->state_->GetGlobalFunction<
+ PyObject*(PyObject*, PyObject*)>(apifunc);
+ Value *result = this->state_->CreateCall(op, lhs, rhs, "binop_result");
+ this->state_->DecRef(lhs);
+ this->state_->DecRef(rhs);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

void
OpcodeBinops::OptimizedBinOp(const char *apifunc)
{
- const PyTypeObject *lhs_type = fbuilder_->GetTypeFeedback(0);
- const PyTypeObject *rhs_type = fbuilder_->GetTypeFeedback(1);
+ const PyTypeObject *lhs_type = this->fbuilder_->GetTypeFeedback(0);
+ const PyTypeObject *rhs_type = this->fbuilder_->GetTypeFeedback(1);
if (lhs_type == NULL || rhs_type == NULL) {
BINOP_INC_STATS(unpredictable);
this->GenericBinOp(apifunc);
@@ -83,11 +83,11 @@

// We're always specializing the receiver, so don't check the lhs for
// wildcards.
- const char *name = fbuilder_->llvm_data_->optimized_ops.
+ const char *name = this->fbuilder_->llvm_data()->optimized_ops.
Find(apifunc, lhs_type, rhs_type);

if (name == NULL) {
- name = fbuilder_->llvm_data_->optimized_ops.
+ name = this->fbuilder_->llvm_data()->optimized_ops.
Find(apifunc, lhs_type, Wildcard);
if (name == NULL) {
BINOP_INC_STATS(omitted);
@@ -97,11 +97,11 @@
}

BINOP_INC_STATS(optimized);
- BasicBlock *success = state_->CreateBasicBlock("BINOP_OPT_success");
- BasicBlock *bailpoint = state_->CreateBasicBlock("BINOP_OPT_bail");
-
- Value *rhs = fbuilder_->Pop();
- Value *lhs = fbuilder_->Pop();
+ BasicBlock *success =
this->state_->CreateBasicBlock("BINOP_OPT_success");
+ BasicBlock *bailpoint =
this->state_->CreateBasicBlock("BINOP_OPT_bail");
+
+ Value *rhs = this->fbuilder_->Pop();
+ Value *lhs = this->fbuilder_->Pop();

// This strategy of bailing may duplicate the work (once in the inlined
// version, once again in the eval loop). This is generally (in a
Halting
@@ -109,20 +109,20 @@
// subset of all possible types where we control the semantics of
__add__,
// etc.
Function *op =
- state_->GetGlobalFunction<PyObject*(PyObject*, PyObject*)>(name);
- Value *result = state_->CreateCall(op, lhs, rhs, "binop_result");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(result),
- bailpoint, success);
-
- fbuilder_->builder_.SetInsertPoint(bailpoint);
- fbuilder_->Push(lhs);
- fbuilder_->Push(rhs);
- fbuilder_->CreateGuardBailPoint(_PYGUARD_BINOP);
-
- fbuilder_->builder_.SetInsertPoint(success);
- state_->DecRef(lhs);
- state_->DecRef(rhs);
- fbuilder_->Push(result);
+ this->state_->GetGlobalFunction<PyObject*(PyObject*,
PyObject*)>(name);
+ Value *result = this->state_->CreateCall(op, lhs, rhs, "binop_result");
+ this->fbuilder_->builder().CreateCondBr(this->state_->IsNull(result),
+ bailpoint, success);
+
+ this->fbuilder_->builder().SetInsertPoint(bailpoint);
+ this->fbuilder_->Push(lhs);
+ this->fbuilder_->Push(rhs);
+ this->fbuilder_->CreateGuardBailPoint(_PYGUARD_BINOP);
+
+ this->fbuilder_->builder().SetInsertPoint(success);
+ this->state_->DecRef(lhs);
+ this->state_->DecRef(rhs);
+ this->fbuilder_->Push(result);
}

#define BINOP_METH(OPCODE, APIFUNC) \
@@ -178,17 +178,17 @@
void
OpcodeBinops::GenericPowOp(const char *apifunc)
{
- Value *rhs = fbuilder_->Pop();
- Value *lhs = fbuilder_->Pop();
- Function *op = state_->GetGlobalFunction<PyObject*(PyObject*,
PyObject*,
- PyObject *)>(apifunc);
- Value *pynone = state_->GetGlobalVariableFor(&_Py_NoneStruct);
- Value *result = state_->CreateCall(op, lhs, rhs, pynone,
- "powop_result");
- state_->DecRef(lhs);
- state_->DecRef(rhs);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ Value *rhs = this->fbuilder_->Pop();
+ Value *lhs = this->fbuilder_->Pop();
+ Function *op = this->state_->GetGlobalFunction<
+ PyObject*(PyObject*, PyObject*, PyObject *)>(apifunc);
+ Value *pynone = this->state_->GetGlobalVariableFor(&_Py_NoneStruct);
+ Value *result = this->state_->CreateCall(op, lhs, rhs, pynone,
+ "powop_result");
+ this->state_->DecRef(lhs);
+ this->state_->DecRef(rhs);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

void
=======================================
--- /trunk/JIT/opcodes/block.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/block.cc Wed Jul 28 23:50:04 2010
@@ -23,7 +23,10 @@
namespace py {

OpcodeBlock::OpcodeBlock(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder()),
+ llvm_data_(fbuilder->llvm_data())
{
}

@@ -38,16 +41,16 @@
void
OpcodeBlock::POP_BLOCK()
{
- Value *block_info = state_->CreateCall(
- state_->GetGlobalFunction<PyTryBlock *(PyTryBlock *, char *)>(
+ Value *block_info = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<PyTryBlock *(PyTryBlock *, char
*)>(
"_PyLlvm_Frame_BlockPop"),
- fbuilder_->blockstack_addr_,
- fbuilder_->num_blocks_addr_);
- Value *pop_to_level = fbuilder_->builder_.CreateLoad(
- PyTypeBuilder<PyTryBlock>::b_level(fbuilder_->builder_,
block_info));
+ this->fbuilder_->blockstack_addr(),
+ this->fbuilder_->num_blocks_addr());
+ Value *pop_to_level = this->builder_.CreateLoad(
+ PyTypeBuilder<PyTryBlock>::b_level(this->builder_, block_info));
Value *pop_to_addr =
- fbuilder_->builder_.CreateGEP(fbuilder_->stack_bottom_,
pop_to_level);
- fbuilder_->PopAndDecrefTo(pop_to_addr);
+ this->builder_.CreateGEP(this->fbuilder_->stack_bottom(),
pop_to_level);
+ this->fbuilder_->PopAndDecrefTo(pop_to_addr);
}

void
@@ -70,26 +73,26 @@
OpcodeBlock::CallBlockSetup(int block_type, llvm::BasicBlock *handler,
int handler_opindex)
{
- Value *stack_level = fbuilder_->GetStackLevel();
+ Value *stack_level = this->fbuilder_->GetStackLevel();
Value *unwind_target_index =
- fbuilder_->AddUnwindTarget(handler, handler_opindex);
+ this->fbuilder_->AddUnwindTarget(handler, handler_opindex);
Function *blocksetup =
- state_->GetGlobalFunction<void(PyTryBlock *, char *, int, int,
int)>(
+ this->state_->GetGlobalFunction<void(PyTryBlock *, char *, int,
int, int)>(
"_PyLlvm_Frame_BlockSetup");
Value *args[] = {
- fbuilder_->blockstack_addr_, fbuilder_->num_blocks_addr_,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
+ this->fbuilder_->blockstack_addr(),
this->fbuilder_->num_blocks_addr(),
+
ConstantInt::get(PyTypeBuilder<int>::get(this->fbuilder_->context()),
block_type),
unwind_target_index,
stack_level
};
- state_->CreateCall(blocksetup, args, array_endof(args));
+ this->state_->CreateCall(blocksetup, args, array_endof(args));
}

void
OpcodeBlock::END_FINALLY()
{
- Value *finally_discriminator = fbuilder_->Pop();
+ Value *finally_discriminator = this->fbuilder_->Pop();
// END_FINALLY is fairly complicated. It decides what to do based
// on the top value in the stack. If that value is an int, it's
// interpreted as one of the unwind reasons. If it's an exception
@@ -99,115 +102,116 @@
// flow.

BasicBlock *unwind_code =
- state_->CreateBasicBlock("unwind_code");
+ this->state_->CreateBasicBlock("unwind_code");
BasicBlock *test_exception =
- state_->CreateBasicBlock("test_exception");
+ this->state_->CreateBasicBlock("test_exception");
BasicBlock *reraise_exception =
- state_->CreateBasicBlock("reraise_exception");
- BasicBlock *check_none = state_->CreateBasicBlock("check_none");
- BasicBlock *not_none = state_->CreateBasicBlock("not_none");
+ this->state_->CreateBasicBlock("reraise_exception");
+ BasicBlock *check_none = this->state_->CreateBasicBlock("check_none");
+ BasicBlock *not_none = this->state_->CreateBasicBlock("not_none");
BasicBlock *finally_fallthrough =
- state_->CreateBasicBlock("finally_fallthrough");
-
- fbuilder_->builder_.CreateCondBr(
- state_->IsInstanceOfFlagClass(finally_discriminator,
- Py_TPFLAGS_INT_SUBCLASS),
+ this->state_->CreateBasicBlock("finally_fallthrough");
+
+ this->builder_.CreateCondBr(
+ this->state_->IsInstanceOfFlagClass(finally_discriminator,
+ Py_TPFLAGS_INT_SUBCLASS),
unwind_code, test_exception);

- fbuilder_->builder_.SetInsertPoint(unwind_code);
+ this->builder_.SetInsertPoint(unwind_code);
// The top of the stack was an int, interpreted as an unwind code.
// If we're resuming a return or continue, the return value or
// loop target (respectively) is now on top of the stack and needs
// to be popped off.
- Value *unwind_reason = fbuilder_->builder_.CreateTrunc(
- state_->CreateCall(
- state_->GetGlobalFunction<long(PyObject *)>("PyInt_AsLong"),
+ Value *unwind_reason = this->builder_.CreateTrunc(
+ this->state_->CreateCall(
+ this->state_->GetGlobalFunction<long(PyObject
*)>("PyInt_AsLong"),
finally_discriminator),
- Type::getInt8Ty(fbuilder_->context_),
+ Type::getInt8Ty(this->fbuilder_->context()),
"unwind_reason");
- state_->DecRef(finally_discriminator);
+ this->state_->DecRef(finally_discriminator);
// Save the unwind reason for when we jump to the unwind block.
- fbuilder_->builder_.CreateStore(unwind_reason,
- fbuilder_->unwind_reason_addr_);
+ this->builder_.CreateStore(unwind_reason,
+ this->fbuilder_->unwind_reason_addr());
// Check if we need to pop the return value or loop target.
- BasicBlock *pop_retval = state_->CreateBasicBlock("pop_retval");
+ BasicBlock *pop_retval = this->state_->CreateBasicBlock("pop_retval");
llvm::SwitchInst *should_pop_retval =
- fbuilder_->builder_.CreateSwitch(unwind_reason,
- fbuilder_->unwind_block_, 2);
+ this->builder_.CreateSwitch(unwind_reason,
+ this->fbuilder_->unwind_block(), 2);
should_pop_retval->addCase(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_RETURN),
pop_retval);
should_pop_retval->addCase(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_CONTINUE),
pop_retval);

- fbuilder_->builder_.SetInsertPoint(pop_retval);
+ this->builder_.SetInsertPoint(pop_retval);
// We're continuing a return or continue. Retrieve its argument.
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(),
fbuilder_->retval_addr_);
- fbuilder_->builder_.CreateBr(fbuilder_->unwind_block_);
-
- fbuilder_->builder_.SetInsertPoint(test_exception);
- Value *is_exception_or_string = state_->CreateCall(
- state_->GetGlobalFunction<int(PyObject *)>(
+ this->builder_.CreateStore(this->fbuilder_->Pop(),
+ this->fbuilder_->retval_addr());
+ this->builder_.CreateBr(this->fbuilder_->unwind_block());
+
+ this->builder_.SetInsertPoint(test_exception);
+ Value *is_exception_or_string = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<int(PyObject *)>(
"_PyLlvm_WrapIsExceptionOrString"),
finally_discriminator);
- fbuilder_->builder_.CreateCondBr(
- state_->IsNonZero(is_exception_or_string),
+ this->builder_.CreateCondBr(
+ this->state_->IsNonZero(is_exception_or_string),
reraise_exception, check_none);

- fbuilder_->builder_.SetInsertPoint(reraise_exception);
+ this->builder_.SetInsertPoint(reraise_exception);
Value *err_type = finally_discriminator;
- Value *err_value = fbuilder_->Pop();
- Value *err_traceback = fbuilder_->Pop();
- state_->CreateCall(
- state_->GetGlobalFunction<void(PyObject *, PyObject *, PyObject
*)>(
- "PyErr_Restore"),
+ Value *err_value = this->fbuilder_->Pop();
+ Value *err_traceback = this->fbuilder_->Pop();
+ this->state_->CreateCall(
+ this->state_->GetGlobalFunction<
+ void(PyObject *, PyObject *, PyObject *)>("PyErr_Restore"),
err_type, err_value, err_traceback);
// This is a "re-raise" rather than a new exception, so we don't
// jump to the propagate_exception_block_.
- fbuilder_->builder_.CreateStore(state_->GetNull<PyObject*>(),
- fbuilder_->retval_addr_);
- fbuilder_->builder_.CreateStore(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ this->builder_.CreateStore(this->state_->GetNull<PyObject*>(),
+ this->fbuilder_->retval_addr());
+ this->builder_.CreateStore(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_EXCEPTION),
- fbuilder_->unwind_reason_addr_);
- fbuilder_->builder_.CreateBr(fbuilder_->unwind_block_);
-
- fbuilder_->builder_.SetInsertPoint(check_none);
+ this->fbuilder_->unwind_reason_addr());
+ this->builder_.CreateBr(this->fbuilder_->unwind_block());
+
+ this->builder_.SetInsertPoint(check_none);
// The contents of the try block push None onto the stack just
// before falling through to the finally block. If we didn't get
// an unwind reason or an exception, we expect to fall through,
// but for sanity we also double-check that the None is present.
- Value *is_none = fbuilder_->builder_.CreateICmpEQ(
+ Value *is_none = this->builder_.CreateICmpEQ(
finally_discriminator,
- state_->GetGlobalVariableFor(&_Py_NoneStruct));
- state_->DecRef(finally_discriminator);
- fbuilder_->builder_.CreateCondBr(is_none, finally_fallthrough,
not_none);
-
- fbuilder_->builder_.SetInsertPoint(not_none);
+ this->state_->GetGlobalVariableFor(&_Py_NoneStruct));
+ this->state_->DecRef(finally_discriminator);
+ this->builder_.CreateCondBr(is_none, finally_fallthrough, not_none);
+
+ this->builder_.SetInsertPoint(not_none);
// If we didn't get a None, raise a SystemError.
- Value *system_error = fbuilder_->builder_.CreateLoad(
- state_->GET_GLOBAL_VARIABLE(PyObject *, PyExc_SystemError));
- Value *err_msg = fbuilder_->llvm_data_->GetGlobalStringPtr(
+ Value *system_error = this->builder_.CreateLoad(
+ this->state_->GET_GLOBAL_VARIABLE(PyObject *, PyExc_SystemError));
+ Value *err_msg = llvm_data_->GetGlobalStringPtr(
"'finally' pops bad exception");
- state_->CreateCall(
- state_->GetGlobalFunction<void(PyObject *, const char *)>(
+ this->state_->CreateCall(
+ this->state_->GetGlobalFunction<void(PyObject *, const char *)>(
"PyErr_SetString"),
system_error, err_msg);
- fbuilder_->builder_.CreateStore(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ this->builder_.CreateStore(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_EXCEPTION),
- fbuilder_->unwind_reason_addr_);
- fbuilder_->builder_.CreateBr(fbuilder_->unwind_block_);
+ this->fbuilder_->unwind_reason_addr());
+ this->builder_.CreateBr(this->fbuilder_->unwind_block());

// After falling through into a finally block, we also fall
// through out of the block. This has the nice side-effect of
// avoiding jumps and switch instructions in the common case,
// although returning out of a finally may still be slower than
// ideal.
- fbuilder_->builder_.SetInsertPoint(finally_fallthrough);
+ this->builder_.SetInsertPoint(finally_fallthrough);
}

void
@@ -235,63 +239,64 @@
should still be resumed.)
*/

- Value *exc_type = state_->CreateAllocaInEntryBlock(
- PyTypeBuilder<PyObject*>::get(fbuilder_->context_),
+ Value *exc_type = this->state_->CreateAllocaInEntryBlock(
+ PyTypeBuilder<PyObject*>::get(this->fbuilder_->context()),
NULL, "WITH_CLEANUP_exc_type");
- Value *exc_value = state_->CreateAllocaInEntryBlock(
- PyTypeBuilder<PyObject*>::get(fbuilder_->context_),
+ Value *exc_value = this->state_->CreateAllocaInEntryBlock(
+ PyTypeBuilder<PyObject*>::get(this->fbuilder_->context()),
NULL, "WITH_CLEANUP_exc_value");
- Value *exc_traceback = state_->CreateAllocaInEntryBlock(
- PyTypeBuilder<PyObject*>::get(fbuilder_->context_),
+ Value *exc_traceback = this->state_->CreateAllocaInEntryBlock(
+ PyTypeBuilder<PyObject*>::get(this->fbuilder_->context()),
NULL, "WITH_CLEANUP_exc_traceback");
- Value *exit_func = state_->CreateAllocaInEntryBlock(
- PyTypeBuilder<PyObject*>::get(fbuilder_->context_),
+ Value *exit_func = this->state_->CreateAllocaInEntryBlock(
+ PyTypeBuilder<PyObject*>::get(this->fbuilder_->context()),
NULL, "WITH_CLEANUP_exit_func");

BasicBlock *handle_none =
- state_->CreateBasicBlock("WITH_CLEANUP_handle_none");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_handle_none");
BasicBlock *check_int =
- state_->CreateBasicBlock("WITH_CLEANUP_check_int");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_check_int");
BasicBlock *handle_int =
- state_->CreateBasicBlock("WITH_CLEANUP_handle_int");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_handle_int");
BasicBlock *handle_ret_cont =
- state_->CreateBasicBlock("WITH_CLEANUP_handle_ret_cont");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_handle_ret_cont");
BasicBlock *handle_default =
- state_->CreateBasicBlock("WITH_CLEANUP_handle_default");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_handle_default");
BasicBlock *handle_else =
- state_->CreateBasicBlock("WITH_CLEANUP_handle_else");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_handle_else");
BasicBlock *main_block =
- state_->CreateBasicBlock("WITH_CLEANUP_main_block");
-
- Value *none = state_->GetGlobalVariableFor(&_Py_NoneStruct);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), exc_type);
-
- Value *is_none = fbuilder_->builder_.CreateICmpEQ(
- fbuilder_->builder_.CreateLoad(exc_type), none,
+ this->state_->CreateBasicBlock("WITH_CLEANUP_main_block");
+
+ Value *none = this->state_->GetGlobalVariableFor(&_Py_NoneStruct);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), exc_type);
+
+ Value *is_none = this->builder_.CreateICmpEQ(
+ this->builder_.CreateLoad(exc_type), none,
"reason_is_none");
- fbuilder_->builder_.CreateCondBr(is_none, handle_none, check_int);
-
- fbuilder_->builder_.SetInsertPoint(handle_none);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), exit_func);
- fbuilder_->Push(fbuilder_->builder_.CreateLoad(exc_type));
- fbuilder_->builder_.CreateStore(none, exc_value);
- fbuilder_->builder_.CreateStore(none, exc_traceback);
- fbuilder_->builder_.CreateBr(main_block);
-
- fbuilder_->builder_.SetInsertPoint(check_int);
- Value *is_int = state_->CreateCall(
- state_->GetGlobalFunction<int(PyObject *)>("_PyLlvm_WrapIntCheck"),
- fbuilder_->builder_.CreateLoad(exc_type),
+ this->builder_.CreateCondBr(is_none, handle_none, check_int);
+
+ this->builder_.SetInsertPoint(handle_none);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), exit_func);
+ this->fbuilder_->Push(this->builder_.CreateLoad(exc_type));
+ this->builder_.CreateStore(none, exc_value);
+ this->builder_.CreateStore(none, exc_traceback);
+ this->builder_.CreateBr(main_block);
+
+ this->builder_.SetInsertPoint(check_int);
+ Value *is_int = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<int(PyObject *)>(
+ "_PyLlvm_WrapIntCheck"),
+ this->builder_.CreateLoad(exc_type),
"WITH_CLEANUP_pyint_check");
- fbuilder_->builder_.CreateCondBr(state_->IsNonZero(is_int),
- handle_int, handle_else);
-
- fbuilder_->builder_.SetInsertPoint(handle_int);
- Value *unboxed = fbuilder_->builder_.CreateTrunc(
- state_->CreateCall(
- state_->GetGlobalFunction<long(PyObject *)>("PyInt_AsLong"),
- fbuilder_->builder_.CreateLoad(exc_type)),
- Type::getInt8Ty(fbuilder_->context_),
+ this->builder_.CreateCondBr(this->state_->IsNonZero(is_int),
+ handle_int, handle_else);
+
+ this->builder_.SetInsertPoint(handle_int);
+ Value *unboxed = this->builder_.CreateTrunc(
+ this->state_->CreateCall(
+ this->state_->GetGlobalFunction<long(PyObject
*)>("PyInt_AsLong"),
+ this->builder_.CreateLoad(exc_type)),
+ Type::getInt8Ty(this->fbuilder_->context()),
"unboxed_unwind_reason");
// The LLVM equivalent of
// switch (reason)
@@ -302,96 +307,96 @@
// default:
// break;
llvm::SwitchInst *unwind_kind =
- fbuilder_->builder_.CreateSwitch(unboxed, handle_default, 2);
-
unwind_kind->addCase(ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
- UNWIND_RETURN),
- handle_ret_cont);
-
unwind_kind->addCase(ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
- UNWIND_CONTINUE),
- handle_ret_cont);
-
- fbuilder_->builder_.SetInsertPoint(handle_ret_cont);
- Value *retval = fbuilder_->Pop();
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), exit_func);
- fbuilder_->Push(retval);
- fbuilder_->Push(fbuilder_->builder_.CreateLoad(exc_type));
- fbuilder_->builder_.CreateStore(none, exc_type);
- fbuilder_->builder_.CreateStore(none, exc_value);
- fbuilder_->builder_.CreateStore(none, exc_traceback);
- fbuilder_->builder_.CreateBr(main_block);
-
- fbuilder_->builder_.SetInsertPoint(handle_default);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), exit_func);
- fbuilder_->Push(fbuilder_->builder_.CreateLoad(exc_type));
- fbuilder_->builder_.CreateStore(none, exc_type);
- fbuilder_->builder_.CreateStore(none, exc_value);
- fbuilder_->builder_.CreateStore(none, exc_traceback);
- fbuilder_->builder_.CreateBr(main_block);
+ this->builder_.CreateSwitch(unboxed, handle_default, 2);
+ unwind_kind->addCase(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
+ UNWIND_RETURN), handle_ret_cont);
+ unwind_kind->addCase(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
+ UNWIND_CONTINUE), handle_ret_cont);
+
+ this->builder_.SetInsertPoint(handle_ret_cont);
+ Value *retval = this->fbuilder_->Pop();
+ this->builder_.CreateStore(this->fbuilder_->Pop(), exit_func);
+ this->fbuilder_->Push(retval);
+ this->fbuilder_->Push(this->builder_.CreateLoad(exc_type));
+ this->builder_.CreateStore(none, exc_type);
+ this->builder_.CreateStore(none, exc_value);
+ this->builder_.CreateStore(none, exc_traceback);
+ this->builder_.CreateBr(main_block);
+
+ this->builder_.SetInsertPoint(handle_default);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), exit_func);
+ this->fbuilder_->Push(this->builder_.CreateLoad(exc_type));
+ this->builder_.CreateStore(none, exc_type);
+ this->builder_.CreateStore(none, exc_value);
+ this->builder_.CreateStore(none, exc_traceback);
+ this->builder_.CreateBr(main_block);

// This is the (TOP, SECOND, THIRD) = exc_info() case above.
- fbuilder_->builder_.SetInsertPoint(handle_else);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), exc_value);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), exc_traceback);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), exit_func);
- fbuilder_->Push(fbuilder_->builder_.CreateLoad(exc_traceback));
- fbuilder_->Push(fbuilder_->builder_.CreateLoad(exc_value));
- fbuilder_->Push(fbuilder_->builder_.CreateLoad(exc_type));
- fbuilder_->builder_.CreateBr(main_block);
-
- fbuilder_->builder_.SetInsertPoint(main_block);
+ this->builder_.SetInsertPoint(handle_else);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), exc_value);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), exc_traceback);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), exit_func);
+ this->fbuilder_->Push(this->builder_.CreateLoad(exc_traceback));
+ this->fbuilder_->Push(this->builder_.CreateLoad(exc_value));
+ this->fbuilder_->Push(this->builder_.CreateLoad(exc_type));
+ this->builder_.CreateBr(main_block);
+
+ this->builder_.SetInsertPoint(main_block);
// Build a vector because there is no CreateCall5().
// This is easier than building the tuple ourselves, but doing so would
// probably be faster.
std::vector<Value*> args;
- args.push_back(fbuilder_->builder_.CreateLoad(exit_func));
- args.push_back(fbuilder_->builder_.CreateLoad(exc_type));
- args.push_back(fbuilder_->builder_.CreateLoad(exc_value));
- args.push_back(fbuilder_->builder_.CreateLoad(exc_traceback));
- args.push_back(state_->GetNull<PyObject*>());
- Value *ret = state_->CreateCall(
- state_->GetGlobalFunction<PyObject *(PyObject *, ...)>(
+ args.push_back(this->builder_.CreateLoad(exit_func));
+ args.push_back(this->builder_.CreateLoad(exc_type));
+ args.push_back(this->builder_.CreateLoad(exc_value));
+ args.push_back(this->builder_.CreateLoad(exc_traceback));
+ args.push_back(this->state_->GetNull<PyObject*>());
+ Value *ret = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<PyObject *(PyObject *, ...)>(
"PyObject_CallFunctionObjArgs"),
args.begin(), args.end());
- state_->DecRef(fbuilder_->builder_.CreateLoad(exit_func));
- fbuilder_->PropagateExceptionOnNull(ret);
+ this->state_->DecRef(this->builder_.CreateLoad(exit_func));
+ this->fbuilder_->PropagateExceptionOnNull(ret);

BasicBlock *check_silence =
- state_->CreateBasicBlock("WITH_CLEANUP_check_silence");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_check_silence");
BasicBlock *no_silence =
- state_->CreateBasicBlock("WITH_CLEANUP_no_silence");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_no_silence");
BasicBlock *cleanup =
- state_->CreateBasicBlock("WITH_CLEANUP_cleanup");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_cleanup");
BasicBlock *next =
- state_->CreateBasicBlock("WITH_CLEANUP_next");
+ this->state_->CreateBasicBlock("WITH_CLEANUP_next");

// Don't bother checking whether to silence the exception if there's
// no exception to silence.
- fbuilder_->builder_.CreateCondBr(
- fbuilder_->builder_.CreateICmpEQ(
- fbuilder_->builder_.CreateLoad(exc_type), none),
+ this->builder_.CreateCondBr(
+ this->builder_.CreateICmpEQ(
+ this->builder_.CreateLoad(exc_type), none),
no_silence, check_silence);

- fbuilder_->builder_.SetInsertPoint(no_silence);
- state_->DecRef(ret);
- fbuilder_->builder_.CreateBr(next);
-
- fbuilder_->builder_.SetInsertPoint(check_silence);
- fbuilder_->builder_.CreateCondBr(fbuilder_->IsPythonTrue(ret),
- cleanup, next);
-
- fbuilder_->builder_.SetInsertPoint(cleanup);
+ this->builder_.SetInsertPoint(no_silence);
+ this->state_->DecRef(ret);
+ this->builder_.CreateBr(next);
+
+ this->builder_.SetInsertPoint(check_silence);
+ this->builder_.CreateCondBr(this->fbuilder_->IsPythonTrue(ret),
+ cleanup, next);
+
+ this->builder_.SetInsertPoint(cleanup);
// There was an exception and a true return. Swallow the exception.
- fbuilder_->Pop();
- fbuilder_->Pop();
- fbuilder_->Pop();
- state_->IncRef(none);
- fbuilder_->Push(none);
- state_->DecRef(fbuilder_->builder_.CreateLoad(exc_type));
- state_->DecRef(fbuilder_->builder_.CreateLoad(exc_value));
- state_->DecRef(fbuilder_->builder_.CreateLoad(exc_traceback));
- fbuilder_->builder_.CreateBr(next);
-
- fbuilder_->builder_.SetInsertPoint(next);
+ this->fbuilder_->Pop();
+ this->fbuilder_->Pop();
+ this->fbuilder_->Pop();
+ this->state_->IncRef(none);
+ this->fbuilder_->Push(none);
+ this->state_->DecRef(this->builder_.CreateLoad(exc_type));
+ this->state_->DecRef(this->builder_.CreateLoad(exc_value));
+ this->state_->DecRef(this->builder_.CreateLoad(exc_traceback));
+ this->builder_.CreateBr(next);
+
+ this->builder_.SetInsertPoint(next);
}

}
=======================================
--- /trunk/JIT/opcodes/block.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/block.h Wed Jul 28 23:50:04 2010
@@ -6,6 +6,9 @@
#error This header expects to be included only in C++ source
#endif

+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"
+
namespace llvm {
class BasicBlock;
}
@@ -34,6 +37,8 @@
void WITH_CLEANUP();

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
// Adds handler to the switch for unwind targets and then sets up
// a call to PyFrame_BlockSetup() with the block type, handler
// index, and current stack level.
@@ -42,6 +47,8 @@

LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
+ PyGlobalLlvmData *const llvm_data_;
};

}
=======================================
--- /trunk/JIT/opcodes/call.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/call.cc Wed Jul 28 23:50:04 2010
@@ -68,7 +68,10 @@
namespace py {

OpcodeCall::OpcodeCall(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder()),
+ llvm_data_(fbuilder->llvm_data())
{
}

@@ -121,85 +124,85 @@
// Expose the C function pointer to LLVM. This is what will actually
get
// called.
Constant *llvm_func =
- fbuilder_->llvm_data_->constant_mirror().GetGlobalForCFunction(
+ llvm_data_->constant_mirror().GetGlobalForCFunction(
cfunc_ptr,
max_arity,
func_record->ml_name);

BasicBlock *not_profiling =
- state_->CreateBasicBlock("CALL_FUNCTION_not_profiling");
+ this->state_->CreateBasicBlock("CALL_FUNCTION_not_profiling");
BasicBlock *check_is_same_func =
- state_->CreateBasicBlock("CALL_FUNCTION_check_is_same_func");
+ this->state_->CreateBasicBlock("CALL_FUNCTION_check_is_same_func");
BasicBlock *invalid_assumptions =
- state_->CreateBasicBlock("CALL_FUNCTION_invalid_assumptions");
+
this->state_->CreateBasicBlock("CALL_FUNCTION_invalid_assumptions");
BasicBlock *all_assumptions_valid =
- state_->CreateBasicBlock("CALL_FUNCTION_all_assumptions_valid");
-
- fbuilder_->BailIfProfiling(not_profiling);
+
this->state_->CreateBasicBlock("CALL_FUNCTION_all_assumptions_valid");
+
+ this->fbuilder_->BailIfProfiling(not_profiling);

// Handle bailing back to the interpreter if the assumptions below
don't
// hold.
- fbuilder_->builder_.SetInsertPoint(invalid_assumptions);
- fbuilder_->CreateGuardBailPoint(_PYGUARD_CFUNC);
-
- fbuilder_->builder_.SetInsertPoint(not_profiling);
+ this->builder_.SetInsertPoint(invalid_assumptions);
+ this->fbuilder_->CreateGuardBailPoint(_PYGUARD_CFUNC);
+
+ this->builder_.SetInsertPoint(not_profiling);
#ifdef WITH_TSC
- state_->LogTscEvent(CALL_START_LLVM);
+ this->state_->LogTscEvent(CALL_START_LLVM);
#endif
// Retrieve the function to call from the Python stack.
Value *stack_pointer =
- fbuilder_->builder_.CreateLoad(fbuilder_->stack_pointer_addr_);
- fbuilder_->llvm_data_->tbaa_stack.MarkInstruction(stack_pointer);
-
- Value *actual_func = fbuilder_->builder_.CreateLoad(
- fbuilder_->builder_.CreateGEP(
+ this->builder_.CreateLoad(this->fbuilder_->stack_pointer_addr());
+ llvm_data_->tbaa_stack.MarkInstruction(stack_pointer);
+
+ Value *actual_func = this->builder_.CreateLoad(
+ this->builder_.CreateGEP(
stack_pointer,
ConstantInt::getSigned(
- Type::getInt64Ty(fbuilder_->context_),
+ Type::getInt64Ty(this->fbuilder_->context()),
-num_args - 1)));

// Make sure it's a PyCFunction; if not, bail.
- Value *is_cfunction = state_->CreateCall(
- state_->GetGlobalFunction<int(PyObject *)>(
+ Value *is_cfunction = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<int(PyObject *)>(
"_PyLlvm_WrapCFunctionCheck"),
actual_func,
"is_cfunction");
- Value *is_cfunction_guard = fbuilder_->builder_.CreateICmpEQ(
+ Value *is_cfunction_guard = this->builder_.CreateICmpEQ(
is_cfunction, ConstantInt::get(is_cfunction->getType(), 1),
"is_cfunction_guard");
- fbuilder_->builder_.CreateCondBr(is_cfunction_guard,
check_is_same_func,
- invalid_assumptions);
+ this->builder_.CreateCondBr(is_cfunction_guard, check_is_same_func,
+ invalid_assumptions);

// Make sure we got the same underlying function pointer; if not, bail.
- fbuilder_->builder_.SetInsertPoint(check_is_same_func);
- Value *actual_as_pycfunc = fbuilder_->builder_.CreateBitCast(
+ this->builder_.SetInsertPoint(check_is_same_func);
+ Value *actual_as_pycfunc = this->builder_.CreateBitCast(
actual_func,
- PyTypeBuilder<PyCFunctionObject *>::get(fbuilder_->context_));
- Value *actual_method_def = fbuilder_->builder_.CreateLoad(
- CFunctionTy::m_ml(fbuilder_->builder_, actual_as_pycfunc),
+ PyTypeBuilder<PyCFunctionObject
*>::get(this->fbuilder_->context()));
+ Value *actual_method_def = this->builder_.CreateLoad(
+ CFunctionTy::m_ml(this->builder_, actual_as_pycfunc),
"CALL_FUNCTION_actual_method_def");
- Value *actual_func_ptr = fbuilder_->builder_.CreateLoad(
- MethodDefTy::ml_meth(fbuilder_->builder_, actual_method_def),
+ Value *actual_func_ptr = this->builder_.CreateLoad(
+ MethodDefTy::ml_meth(this->builder_, actual_method_def),
"CALL_FUNCTION_actual_func_ptr");
- Value *is_same = fbuilder_->builder_.CreateICmpEQ(
+ Value *is_same = this->builder_.CreateICmpEQ(
// TODO(jyasskin): change this to "llvm_func" when
// http://llvm.org/PR5126 is fixed.
- state_->EmbedPointer<PyCFunction>((void*)cfunc_ptr),
+ this->state_->EmbedPointer<PyCFunction>((void*)cfunc_ptr),
actual_func_ptr);
- fbuilder_->builder_.CreateCondBr(is_same,
+ this->builder_.CreateCondBr(is_same,
all_assumptions_valid, invalid_assumptions);

// Once we get to this point, we know we can make some kind of fast
call,
// either, a) a specialized inline version, or b) a direct call to a C
// function, bypassing the CPython function call machinery. We check
them
// in that order.
- fbuilder_->builder_.SetInsertPoint(all_assumptions_valid);
+ this->builder_.SetInsertPoint(all_assumptions_valid);

// Check if we are calling a built-in function that can be specialized.
if (cfunc_ptr == _PyBuiltin_Len) {
// Feedback index 0 is the function itself, index 1 is the first
// argument.
- const PyTypeObject *arg1_type = fbuilder_->GetTypeFeedback(1);
+ const PyTypeObject *arg1_type =
this->fbuilder_->GetTypeFeedback(1);
const char *function_name = NULL;
if (arg1_type == &PyString_Type)
function_name = "_PyLlvm_BuiltinLen_String";
@@ -228,48 +231,49 @@
// functions like len() and C-level methods like list.append(), we
pull the
// invocant (called m_self) from the PyCFunction object we popped
// off the stack. Once the function returns, we patch up the stack
pointer.
- Value *self = fbuilder_->builder_.CreateLoad(
- CFunctionTy::m_self(fbuilder_->builder_, actual_as_pycfunc),
+ Value *self = this->builder_.CreateLoad(
+ CFunctionTy::m_self(this->builder_, actual_as_pycfunc),
"CALL_FUNCTION_actual_self");
llvm::SmallVector<Value*, PY_MAX_ARITY + 1> args; // +1 for self.
args.push_back(self);
if (num_args == 0 && max_arity == 0) {
- args.push_back(state_->GetNull<PyObject *>());
+ args.push_back(this->state_->GetNull<PyObject *>());
}
for (int i = num_args; i >= 1; --i) {
args.push_back(
- fbuilder_->builder_.CreateLoad(
- fbuilder_->builder_.CreateGEP(
+ this->builder_.CreateLoad(
+ this->builder_.CreateGEP(
stack_pointer,
ConstantInt::getSigned(
- Type::getInt64Ty(fbuilder_->context_), -i))));
+ Type::getInt64Ty(this->fbuilder_->context()),
-i))));
}
for(int i = 0; i < (max_arity - num_args); ++i) {
- args.push_back(state_->GetNull<PyObject *>());
+ args.push_back(this->state_->GetNull<PyObject *>());
}

#ifdef WITH_TSC
- state_->LogTscEvent(CALL_ENTER_C);
+ this->state_->LogTscEvent(CALL_ENTER_C);
#endif
- Value *result = state_->CreateCall(llvm_func, args.begin(),
args.end());
-
- state_->DecRef(actual_func);
+ Value *result =
+ this->state_->CreateCall(llvm_func, args.begin(), args.end());
+
+ this->state_->DecRef(actual_func);
// Decrefing args[0] will cause self to be double-decrefed, so avoid
that.
for (int i = 1; i <= num_args; ++i) {
- state_->DecRef(args[i]);
- }
- Value *new_stack_pointer = fbuilder_->builder_.CreateGEP(
+ this->state_->DecRef(args[i]);
+ }
+ Value *new_stack_pointer = this->builder_.CreateGEP(
stack_pointer,
ConstantInt::getSigned(
- Type::getInt64Ty(fbuilder_->context_),
+ Type::getInt64Ty(this->fbuilder_->context()),
-num_args - 1));
- fbuilder_->builder_.CreateStore(new_stack_pointer,
- fbuilder_->stack_pointer_addr_);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->builder_.CreateStore(new_stack_pointer,
+ this->fbuilder_->stack_pointer_addr());
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);

// Check signals and maybe switch threads after each function call.
- fbuilder_->CheckPyTicker();
+ this->fbuilder_->CheckPyTicker();
CF_INC_STATS(direct_calls);
}

@@ -279,74 +283,74 @@
BasicBlock *invalid_assumptions,
const char *function_name)
{
- BasicBlock *success = state_->CreateBasicBlock("BUILTIN_LEN_success");
-
- Value *obj = fbuilder_->Pop();
+ BasicBlock *success =
this->state_->CreateBasicBlock("BUILTIN_LEN_success");
+
+ Value *obj = this->fbuilder_->Pop();
Function *builtin_len =
- state_->GetGlobalFunction<PyObject *(PyObject *)>(function_name);
-
- Value *result = state_->CreateCall(builtin_len, obj,
- "BUILTIN_LEN_result");
- fbuilder_->builder_.CreateCondBr(state_->IsNonZero(result),
- success, invalid_assumptions);
-
- fbuilder_->builder_.SetInsertPoint(success);
- state_->DecRef(actual_func);
- state_->DecRef(obj);
-
- Value *new_stack_pointer = fbuilder_->builder_.CreateGEP(
+ this->state_->GetGlobalFunction<PyObject *(PyObject
*)>(function_name);
+
+ Value *result = this->state_->CreateCall(builtin_len, obj,
+ "BUILTIN_LEN_result");
+ this->builder_.CreateCondBr(this->state_->IsNonZero(result),
+ success, invalid_assumptions);
+
+ this->builder_.SetInsertPoint(success);
+ this->state_->DecRef(actual_func);
+ this->state_->DecRef(obj);
+
+ Value *new_stack_pointer = this->builder_.CreateGEP(
stack_pointer,
ConstantInt::getSigned(
- Type::getInt64Ty(fbuilder_->context_),
+ Type::getInt64Ty(this->fbuilder_->context()),
-2)); // -1 for the function, -1 for the argument.
- fbuilder_->builder_.CreateStore(new_stack_pointer,
- fbuilder_->stack_pointer_addr_);
-
- fbuilder_->Push(result);
+ this->builder_.CreateStore(new_stack_pointer,
+ this->fbuilder_->stack_pointer_addr());
+
+ this->fbuilder_->Push(result);

// Check signals and maybe switch threads after each function call.
- fbuilder_->CheckPyTicker();
+ this->fbuilder_->CheckPyTicker();
}

void
OpcodeCall::CALL_FUNCTION_safe(int oparg)
{
#ifdef WITH_TSC
- state_->LogTscEvent(CALL_START_LLVM);
+ this->state_->LogTscEvent(CALL_START_LLVM);
#endif
Value *stack_pointer =
- fbuilder_->builder_.CreateLoad(fbuilder_->stack_pointer_addr_);
- fbuilder_->llvm_data_->tbaa_stack.MarkInstruction(stack_pointer);
+ this->builder_.CreateLoad(this->fbuilder_->stack_pointer_addr());
+ llvm_data_->tbaa_stack.MarkInstruction(stack_pointer);

int num_args = oparg & 0xff;
int num_kwargs = (oparg>>8) & 0xff;
- Function *call_function = state_->GetGlobalFunction<
+ Function *call_function = this->state_->GetGlobalFunction<
PyObject *(PyObject **, int, int)>("_PyEval_CallFunction");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
call_function,
stack_pointer,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
+
ConstantInt::get(PyTypeBuilder<int>::get(this->fbuilder_->context()),
num_args),
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
+
ConstantInt::get(PyTypeBuilder<int>::get(this->fbuilder_->context()),
num_kwargs),
"CALL_FUNCTION_result");
- Value *new_stack_pointer = fbuilder_->builder_.CreateGEP(
+ Value *new_stack_pointer = this->builder_.CreateGEP(
stack_pointer,
- ConstantInt::getSigned(Type::getInt64Ty(fbuilder_->context_),
+
ConstantInt::getSigned(Type::getInt64Ty(this->fbuilder_->context()),
-num_args - 2*num_kwargs - 1));
- fbuilder_->builder_.CreateStore(new_stack_pointer,
- fbuilder_->stack_pointer_addr_);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->builder_.CreateStore(new_stack_pointer,
+ this->fbuilder_->stack_pointer_addr());
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);

// Check signals and maybe switch threads after each function call.
- fbuilder_->CheckPyTicker();
+ this->fbuilder_->CheckPyTicker();
}

void
OpcodeCall::CALL_FUNCTION(int oparg)
{
- const PyRuntimeFeedback *feedback = fbuilder_->GetFeedback();
+ const PyRuntimeFeedback *feedback = this->fbuilder_->GetFeedback();
if (feedback == NULL || feedback->FuncsOverflowed())
this->CALL_FUNCTION_safe(oparg);
else
@@ -361,24 +365,24 @@
OpcodeCall::CallVarKwFunction(int oparg, int call_flag)
{
#ifdef WITH_TSC
- state_->LogTscEvent(CALL_START_LLVM);
+ this->state_->LogTscEvent(CALL_START_LLVM);
#endif
Value *stack_pointer =
- fbuilder_->builder_.CreateLoad(fbuilder_->stack_pointer_addr_);
- fbuilder_->llvm_data_->tbaa_stack.MarkInstruction(stack_pointer);
+ this->builder_.CreateLoad(this->fbuilder_->stack_pointer_addr());
+ llvm_data_->tbaa_stack.MarkInstruction(stack_pointer);

int num_args = oparg & 0xff;
int num_kwargs = (oparg>>8) & 0xff;
- Function *call_function = state_->GetGlobalFunction<
+ Function *call_function = this->state_->GetGlobalFunction<
PyObject *(PyObject **, int, int,
int)>("_PyEval_CallFunctionVarKw");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
call_function,
stack_pointer,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
+
ConstantInt::get(PyTypeBuilder<int>::get(this->fbuilder_->context()),
num_args),
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
+
ConstantInt::get(PyTypeBuilder<int>::get(this->fbuilder_->context()),
num_kwargs),
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
+
ConstantInt::get(PyTypeBuilder<int>::get(this->fbuilder_->context()),
call_flag),
"CALL_FUNCTION_VAR_KW_result");
int stack_items = num_args + 2 * num_kwargs + 1;
@@ -388,24 +392,24 @@
if (call_flag & CALL_FLAG_KW) {
++stack_items;
}
- Value *new_stack_pointer = fbuilder_->builder_.CreateGEP(
+ Value *new_stack_pointer = this->builder_.CreateGEP(
stack_pointer,
- ConstantInt::getSigned(Type::getInt64Ty(fbuilder_->context_),
+
ConstantInt::getSigned(Type::getInt64Ty(this->fbuilder_->context()),
-stack_items));
- fbuilder_->builder_.CreateStore(new_stack_pointer,
- fbuilder_->stack_pointer_addr_);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->builder_.CreateStore(new_stack_pointer,
+ this->fbuilder_->stack_pointer_addr());
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);

// Check signals and maybe switch threads after each function call.
- fbuilder_->CheckPyTicker();
+ this->fbuilder_->CheckPyTicker();
}

void
OpcodeCall::CALL_FUNCTION_VAR(int oparg)
{
#ifdef WITH_TSC
- state_->LogTscEvent(CALL_START_LLVM);
+ this->state_->LogTscEvent(CALL_START_LLVM);
#endif
this->CallVarKwFunction(oparg, CALL_FLAG_VAR);
}
@@ -414,7 +418,7 @@
OpcodeCall::CALL_FUNCTION_KW(int oparg)
{
#ifdef WITH_TSC
- state_->LogTscEvent(CALL_START_LLVM);
+ this->state_->LogTscEvent(CALL_START_LLVM);
#endif
this->CallVarKwFunction(oparg, CALL_FLAG_KW);
}
@@ -423,7 +427,7 @@
OpcodeCall::CALL_FUNCTION_VAR_KW(int oparg)
{
#ifdef WITH_TSC
- state_->LogTscEvent(CALL_START_LLVM);
+ this->state_->LogTscEvent(CALL_START_LLVM);
#endif
this->CallVarKwFunction(oparg, CALL_FLAG_KW | CALL_FLAG_VAR);
}
=======================================
--- /trunk/JIT/opcodes/call.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/call.h Wed Jul 28 23:50:04 2010
@@ -7,6 +7,8 @@
#endif

#include "JIT/RuntimeFeedback.h"
+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"

namespace py {

@@ -25,6 +27,8 @@
void CALL_FUNCTION_VAR_KW(int num_args);

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
// Helper method for CALL_FUNCTION_(VAR|KW|VAR_KW); calls
// _PyEval_CallFunctionVarKw() with the given flags and the current
// stack pointer.
@@ -44,6 +48,8 @@

LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
+ PyGlobalLlvmData *const llvm_data_;
};

}
=======================================
--- /trunk/JIT/opcodes/closure.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/closure.cc Wed Jul 28 23:50:04 2010
@@ -16,145 +16,150 @@
namespace py {

OpcodeClosure::OpcodeClosure(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder()),
+ llvm_data_(fbuilder->llvm_data())
{
}

void
OpcodeClosure::LOAD_CLOSURE(int freevars_index)
{
- Value *cell = fbuilder_->builder_.CreateLoad(
- fbuilder_->builder_.CreateGEP(
- fbuilder_->freevars_,
- ConstantInt::get(Type::getInt32Ty(fbuilder_->context_),
+ Value *cell = this->builder_.CreateLoad(
+ this->builder_.CreateGEP(
+ this->fbuilder_->freevars(),
+ ConstantInt::get(Type::getInt32Ty(this->fbuilder_->context()),
freevars_index)));
- state_->IncRef(cell);
- fbuilder_->Push(cell);
+ this->state_->IncRef(cell);
+ this->fbuilder_->Push(cell);
}

void
OpcodeClosure::MAKE_CLOSURE(int num_defaults)
{
- Value *code_object = fbuilder_->Pop();
- Function *pyfunction_new = state_->GetGlobalFunction<
+ Value *code_object = this->fbuilder_->Pop();
+ Function *pyfunction_new = this->state_->GetGlobalFunction<
PyObject *(PyObject *, PyObject *)>("PyFunction_New");
- Value *func_object = state_->CreateCall(
- pyfunction_new, code_object, fbuilder_->globals_,
+ Value *func_object = this->state_->CreateCall(
+ pyfunction_new, code_object, this->fbuilder_->globals(),
"MAKE_CLOSURE_result");
- state_->DecRef(code_object);
- fbuilder_->PropagateExceptionOnNull(func_object);
- Value *closure = fbuilder_->Pop();
- Function *pyfunction_setclosure = state_->GetGlobalFunction<
+ this->state_->DecRef(code_object);
+ this->fbuilder_->PropagateExceptionOnNull(func_object);
+ Value *closure = this->fbuilder_->Pop();
+ Function *pyfunction_setclosure = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *)>("PyFunction_SetClosure");
- Value *setclosure_result = state_->CreateCall(
+ Value *setclosure_result = this->state_->CreateCall(
pyfunction_setclosure, func_object, closure,
"MAKE_CLOSURE_setclosure_result");
- state_->DecRef(closure);
- fbuilder_->PropagateExceptionOnNonZero(setclosure_result);
+ this->state_->DecRef(closure);
+ this->fbuilder_->PropagateExceptionOnNonZero(setclosure_result);
if (num_defaults > 0) {
// Effectively inline BuildSequenceLiteral and
// PropagateExceptionOnNull so we can DecRef func_object on error.
BasicBlock *failure =
- state_->CreateBasicBlock("MAKE_CLOSURE_failure");
+ this->state_->CreateBasicBlock("MAKE_CLOSURE_failure");
BasicBlock *success =
- state_->CreateBasicBlock("MAKE_CLOSURE_success");
+ this->state_->CreateBasicBlock("MAKE_CLOSURE_success");

Value *tupsize = ConstantInt::get(
- PyTypeBuilder<Py_ssize_t>::get(fbuilder_->context_),
num_defaults);
- Function *pytuple_new =
- state_->GetGlobalFunction<PyObject
*(Py_ssize_t)>("PyTuple_New");
- Value *defaults = state_->CreateCall(pytuple_new, tupsize,
- "MAKE_CLOSURE_defaults");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(defaults),
- failure, success);
-
- fbuilder_->builder_.SetInsertPoint(failure);
- state_->DecRef(func_object);
- fbuilder_->PropagateException();
-
- fbuilder_->builder_.SetInsertPoint(success);
+ PyTypeBuilder<Py_ssize_t>::get(this->fbuilder_->context()),
+ num_defaults);
+ Function *pytuple_new = this->state_
+ ->GetGlobalFunction<PyObject *(Py_ssize_t)>("PyTuple_New");
+ Value *defaults = this->state_->CreateCall(pytuple_new, tupsize,
+ "MAKE_CLOSURE_defaults");
+ this->builder_.CreateCondBr(this->state_->IsNull(defaults),
+ failure, success);
+
+ this->builder_.SetInsertPoint(failure);
+ this->state_->DecRef(func_object);
+ this->fbuilder_->PropagateException();
+
+ this->builder_.SetInsertPoint(success);
// XXX(twouters): do this with a memcpy?
while (--num_defaults >= 0) {
- Value *itemslot = state_->GetTupleItemSlot(defaults,
- num_defaults);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), itemslot);
+ Value *itemslot = this->state_->GetTupleItemSlot(defaults,
+ num_defaults);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), itemslot);
}
// End of inlining.
- Function *pyfunction_setdefaults = state_->GetGlobalFunction<
+ Function *pyfunction_setdefaults = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *)>("PyFunction_SetDefaults");
- Value *setdefaults_result = state_->CreateCall(
+ Value *setdefaults_result = this->state_->CreateCall(
pyfunction_setdefaults, func_object, defaults,
"MAKE_CLOSURE_setdefaults_result");
- state_->DecRef(defaults);
- fbuilder_->PropagateExceptionOnNonZero(setdefaults_result);
- }
- fbuilder_->Push(func_object);
+ this->state_->DecRef(defaults);
+ this->fbuilder_->PropagateExceptionOnNonZero(setdefaults_result);
+ }
+ this->fbuilder_->Push(func_object);
}

void
OpcodeClosure::LOAD_DEREF(int index)
{
BasicBlock *failed_load =
- state_->CreateBasicBlock("LOAD_DEREF_failed_load");
+ this->state_->CreateBasicBlock("LOAD_DEREF_failed_load");
BasicBlock *unbound_local =
- state_->CreateBasicBlock("LOAD_DEREF_unbound_local");
+ this->state_->CreateBasicBlock("LOAD_DEREF_unbound_local");
BasicBlock *error =
- state_->CreateBasicBlock("LOAD_DEREF_error");
+ this->state_->CreateBasicBlock("LOAD_DEREF_error");
BasicBlock *success =
- state_->CreateBasicBlock("LOAD_DEREF_success");
-
- Value *cell = fbuilder_->builder_.CreateLoad(
- fbuilder_->builder_.CreateGEP(
- fbuilder_->freevars_,
- ConstantInt::get(Type::getInt32Ty(fbuilder_->context_),
+ this->state_->CreateBasicBlock("LOAD_DEREF_success");
+
+ Value *cell = this->builder_.CreateLoad(
+ this->builder_.CreateGEP(
+ this->fbuilder_->freevars(),
+ ConstantInt::get(Type::getInt32Ty(this->fbuilder_->context()),
index)));
- Function *pycell_get = state_->GetGlobalFunction<
+ Function *pycell_get = this->state_->GetGlobalFunction<
PyObject *(PyObject *)>("PyCell_Get");
- Value *value = state_->CreateCall(
+ Value *value = this->state_->CreateCall(
pycell_get, cell, "LOAD_DEREF_cell_contents");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(value),
- failed_load, success);
-
- fbuilder_->builder_.SetInsertPoint(failed_load);
+ this->builder_.CreateCondBr(this->state_->IsNull(value),
+ failed_load, success);
+
+ this->builder_.SetInsertPoint(failed_load);
Function *pyerr_occurred =
- state_->GetGlobalFunction<PyObject *()>("PyErr_Occurred");
+ this->state_->GetGlobalFunction<PyObject *()>("PyErr_Occurred");
Value *was_err =
- state_->CreateCall(pyerr_occurred, "LOAD_DEREF_err_occurred");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(was_err),
- unbound_local, error);
-
- fbuilder_->builder_.SetInsertPoint(unbound_local);
+
this->state_->CreateCall(pyerr_occurred, "LOAD_DEREF_err_occurred");
+ this->builder_.CreateCondBr(this->state_->IsNull(was_err),
+ unbound_local, error);
+
+ this->builder_.SetInsertPoint(unbound_local);
Function *do_raise =
- state_->GetGlobalFunction<void(PyFrameObject*, int)>(
+ this->state_->GetGlobalFunction<void(PyFrameObject*, int)>(
"_PyEval_RaiseForUnboundFreeVar");
- state_->CreateCall(
- do_raise, fbuilder_->frame_,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
index));
-
- fbuilder_->FallThroughTo(error);
- fbuilder_->PropagateException();
-
- fbuilder_->builder_.SetInsertPoint(success);
- fbuilder_->Push(value);
+ this->state_->CreateCall(
+ do_raise, this->fbuilder_->frame(),
+
ConstantInt::get(PyTypeBuilder<int>::get(this->fbuilder_->context()),
+ index));
+
+ this->fbuilder_->FallThroughTo(error);
+ this->fbuilder_->PropagateException();
+
+ this->builder_.SetInsertPoint(success);
+ this->fbuilder_->Push(value);
}

void
OpcodeClosure::STORE_DEREF(int index)
{
- Value *value = fbuilder_->Pop();
- Value *cell = fbuilder_->builder_.CreateLoad(
- fbuilder_->builder_.CreateGEP(
- fbuilder_->freevars_,
- ConstantInt::get(Type::getInt32Ty(fbuilder_->context_),
+ Value *value = this->fbuilder_->Pop();
+ Value *cell = this->builder_.CreateLoad(
+ this->builder_.CreateGEP(
+ this->fbuilder_->freevars(),
+ ConstantInt::get(Type::getInt32Ty(this->fbuilder_->context()),
index)));
- Function *pycell_set = state_->GetGlobalFunction<
+ Function *pycell_set = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *)>("PyCell_Set");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
pycell_set, cell, value, "STORE_DEREF_result");
- state_->DecRef(value);
+ this->state_->DecRef(value);
// eval.cc doesn't actually check the return value of this, I guess
// we are a little more likely to do things wrong.
- fbuilder_->PropagateExceptionOnNonZero(result);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

}
=======================================
--- /trunk/JIT/opcodes/closure.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/closure.h Wed Jul 28 23:50:04 2010
@@ -6,6 +6,9 @@
#error This header expects to be included only in C++ source
#endif

+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"
+
namespace py {

class LlvmFunctionBuilder;
@@ -23,8 +26,12 @@
void STORE_DEREF(int index);

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
+ PyGlobalLlvmData *const llvm_data_;
};

}
=======================================
--- /trunk/JIT/opcodes/cmpops.cc Tue Jun 15 13:27:27 2010
+++ /trunk/JIT/opcodes/cmpops.cc Wed Jul 28 23:50:04 2010
@@ -36,7 +36,9 @@
namespace py {

OpcodeCmpops::OpcodeCmpops(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder())
{
}

@@ -71,7 +73,7 @@
#undef CMPOP_NAME
}

- const char *name = fbuilder_->llvm_data_->optimized_ops.
+ const char *name = this->fbuilder_->llvm_data()->optimized_ops.
Find(api_func, lhs_type, rhs_type);

if (name == NULL) {
@@ -80,27 +82,27 @@

CMPOP_INC_STATS(optimized);

- BasicBlock *success = state_->CreateBasicBlock("CMPOP_OPT_success");
- BasicBlock *bailpoint = state_->CreateBasicBlock("CMPOP_OPT_bail");
-
- Value *rhs = fbuilder_->Pop();
- Value *lhs = fbuilder_->Pop();
+ BasicBlock *success =
this->state_->CreateBasicBlock("CMPOP_OPT_success");
+ BasicBlock *bailpoint =
this->state_->CreateBasicBlock("CMPOP_OPT_bail");
+
+ Value *rhs = this->fbuilder_->Pop();
+ Value *lhs = this->fbuilder_->Pop();

Function *op =
- state_->GetGlobalFunction<PyObject*(PyObject*, PyObject*)>(name);
- Value *result = state_->CreateCall(op, lhs, rhs, "cmpop_result");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(result),
- bailpoint, success);
-
- fbuilder_->builder_.SetInsertPoint(bailpoint);
- fbuilder_->Push(lhs);
- fbuilder_->Push(rhs);
- fbuilder_->CreateBailPoint(_PYFRAME_GUARD_FAIL);
-
- fbuilder_->builder_.SetInsertPoint(success);
- state_->DecRef(lhs);
- state_->DecRef(rhs);
- fbuilder_->Push(result);
+ this->state_->GetGlobalFunction<PyObject*(PyObject*,
PyObject*)>(name);
+ Value *result = this->state_->CreateCall(op, lhs, rhs, "cmpop_result");
+ this->builder_.CreateCondBr(this->state_->IsNull(result),
+ bailpoint, success);
+
+ this->builder_.SetInsertPoint(bailpoint);
+ this->fbuilder_->Push(lhs);
+ this->fbuilder_->Push(rhs);
+ this->fbuilder_->CreateBailPoint(_PYFRAME_GUARD_FAIL);
+
+ this->builder_.SetInsertPoint(success);
+ this->state_->DecRef(lhs);
+ this->state_->DecRef(rhs);
+ this->fbuilder_->Push(result);
return true;
}

@@ -108,8 +110,8 @@
OpcodeCmpops::COMPARE_OP(int cmp_op)
{
CMPOP_INC_STATS(total);
- const PyTypeObject *lhs_type = fbuilder_->GetTypeFeedback(0);
- const PyTypeObject *rhs_type = fbuilder_->GetTypeFeedback(1);
+ const PyTypeObject *lhs_type = this->fbuilder_->GetTypeFeedback(0);
+ const PyTypeObject *rhs_type = this->fbuilder_->GetTypeFeedback(1);
if (lhs_type != NULL && rhs_type != NULL) {
// Returning true means the op was successfully optimized.
if (this->COMPARE_OP_fast(cmp_op, lhs_type, rhs_type)) {
@@ -127,21 +129,20 @@
void
OpcodeCmpops::COMPARE_OP_safe(int cmp_op)
{
- Value *rhs = fbuilder_->Pop();
- Value *lhs = fbuilder_->Pop();
+ Value *rhs = this->fbuilder_->Pop();
+ Value *lhs = this->fbuilder_->Pop();
Value *result;
switch (cmp_op) {
case PyCmp_IS:
- result = fbuilder_->builder_.CreateICmpEQ(lhs, rhs,
- "COMPARE_OP_is_same");
- state_->DecRef(lhs);
- state_->DecRef(rhs);
+ result = this->builder_.CreateICmpEQ(lhs,
rhs, "COMPARE_OP_is_same");
+ this->state_->DecRef(lhs);
+ this->state_->DecRef(rhs);
break;
case PyCmp_IS_NOT:
- result = fbuilder_->builder_.CreateICmpNE(lhs, rhs,
+ result = this->builder_.CreateICmpNE(lhs, rhs,
"COMPARE_OP_is_not_same");
- state_->DecRef(lhs);
- state_->DecRef(rhs);
+ this->state_->DecRef(lhs);
+ this->state_->DecRef(rhs);
break;
case PyCmp_IN:
// item in seq -> ContainerContains(seq, item)
@@ -150,7 +151,7 @@
case PyCmp_NOT_IN:
{
Value *inverted_result = this->ContainerContains(rhs, lhs);
- result = fbuilder_->builder_.CreateICmpEQ(
+ result = this->builder_.CreateICmpEQ(
inverted_result, ConstantInt::get(inverted_result->getType(),
0),
"COMPARE_OP_not_in_result");
break;
@@ -172,56 +173,57 @@
Py_FatalError("unknown COMPARE_OP oparg");
return; // Not reached.
}
- Value *value = fbuilder_->builder_.CreateSelect(
+ Value *value = this->builder_.CreateSelect(
result,
- state_->GetGlobalVariableFor((PyObject*)&_Py_TrueStruct),
- state_->GetGlobalVariableFor((PyObject*)&_Py_ZeroStruct),
+ this->state_->GetGlobalVariableFor((PyObject*)&_Py_TrueStruct),
+ this->state_->GetGlobalVariableFor((PyObject*)&_Py_ZeroStruct),
"COMPARE_OP_result");
- state_->IncRef(value);
- fbuilder_->Push(value);
+ this->state_->IncRef(value);
+ this->fbuilder_->Push(value);
}

void
OpcodeCmpops::RichCompare(Value *lhs, Value *rhs, int cmp_op)
{
- Function *pyobject_richcompare = state_->GetGlobalFunction<
+ Function *pyobject_richcompare = this->state_->GetGlobalFunction<
PyObject *(PyObject *, PyObject *, int)>("PyObject_RichCompare");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
pyobject_richcompare, lhs, rhs,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
cmp_op),
+ ConstantInt::get(
+ PyTypeBuilder<int>::get(this->fbuilder_->context()), cmp_op),
"COMPARE_OP_RichCompare_result");
- state_->DecRef(lhs);
- state_->DecRef(rhs);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->state_->DecRef(lhs);
+ this->state_->DecRef(rhs);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

Value *
OpcodeCmpops::ContainerContains(Value *container, Value *item)
{
Function *contains =
- state_->GetGlobalFunction<int(PyObject *, PyObject *)>(
+ this->state_->GetGlobalFunction<int(PyObject *, PyObject *)>(
"PySequence_Contains");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
contains, container, item, "ContainerContains_result");
- state_->DecRef(item);
- state_->DecRef(container);
- fbuilder_->PropagateExceptionOnNegative(result);
- return state_->IsPositive(result);
+ this->state_->DecRef(item);
+ this->state_->DecRef(container);
+ this->fbuilder_->PropagateExceptionOnNegative(result);
+ return this->state_->IsPositive(result);
}

// TODO(twouters): test this (used in exception handling.)
Value *
OpcodeCmpops::ExceptionMatches(Value *exc, Value *exc_type)
{
- Function *exc_matches = state_->GetGlobalFunction<
+ Function *exc_matches = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *)>("_PyEval_CheckedExceptionMatches");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
exc_matches, exc, exc_type, "ExceptionMatches_result");
- state_->DecRef(exc_type);
- state_->DecRef(exc);
- fbuilder_->PropagateExceptionOnNegative(result);
- return state_->IsPositive(result);
+ this->state_->DecRef(exc_type);
+ this->state_->DecRef(exc);
+ this->fbuilder_->PropagateExceptionOnNegative(result);
+ return this->state_->IsPositive(result);
}

}
=======================================
--- /trunk/JIT/opcodes/cmpops.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/cmpops.h Wed Jul 28 23:50:04 2010
@@ -6,6 +6,9 @@
#error This header expects to be included only in C++ source
#endif

+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"
+
namespace llvm {
class Value;
}
@@ -24,6 +27,8 @@
void COMPARE_OP(int cmp_op);

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
bool COMPARE_OP_fast(int cmp_op,
const PyTypeObject *lhs_type,
const PyTypeObject *rhs_type);
@@ -45,6 +50,7 @@

LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
};

}
=======================================
--- /trunk/JIT/opcodes/container.cc Sun Jul 11 08:07:54 2010
+++ /trunk/JIT/opcodes/container.cc Wed Jul 28 23:50:04 2010
@@ -46,7 +46,9 @@
namespace py {

OpcodeContainer::OpcodeContainer(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder())
{
}

@@ -56,20 +58,20 @@
Value *(LlvmFunctionState::*getitemslot)(Value*, int))
{
const Type *IntSsizeTy =
- PyTypeBuilder<Py_ssize_t>::get(fbuilder_->context_);
+ PyTypeBuilder<Py_ssize_t>::get(this->fbuilder_->context());
Value *seqsize = ConstantInt::getSigned(IntSsizeTy, size);

Function *create =
- state_->GetGlobalFunction<PyObject *(Py_ssize_t)>(createname);
- Value *seq = state_->CreateCall(create, seqsize, "sequence_literal");
- fbuilder_->PropagateExceptionOnNull(seq);
+ this->state_->GetGlobalFunction<PyObject
*(Py_ssize_t)>(createname);
+ Value *seq = this->state_->CreateCall(create,
seqsize, "sequence_literal");
+ this->fbuilder_->PropagateExceptionOnNull(seq);

// XXX(twouters): do this with a memcpy?
while (--size >= 0) {
- Value *itemslot = (state_->*getitemslot)(seq, size);
- fbuilder_->builder_.CreateStore(fbuilder_->Pop(), itemslot);
- }
- fbuilder_->Push(seq);
+ Value *itemslot = (this->state_->*getitemslot)(seq, size);
+ this->builder_.CreateStore(this->fbuilder_->Pop(), itemslot);
+ }
+ this->fbuilder_->Push(seq);
}

void
@@ -90,13 +92,13 @@
OpcodeContainer::BUILD_MAP(int size)
{
Value *sizehint = ConstantInt::getSigned(
- PyTypeBuilder<Py_ssize_t>::get(fbuilder_->context_), size);
- Function *create_dict = state_->GetGlobalFunction<
+ PyTypeBuilder<Py_ssize_t>::get(this->fbuilder_->context()), size);
+ Function *create_dict = this->state_->GetGlobalFunction<
PyObject *(Py_ssize_t)>("_PyDict_NewPresized");
- Value *result = state_->CreateCall(create_dict, sizehint,
- "BULD_MAP_result");
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ Value *result = this->state_->CreateCall(create_dict, sizehint,
+ "BULD_MAP_result");
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

void
@@ -106,30 +108,30 @@
// STORE_* ones that follow into a single block of code circumventing
the
// stack altogether. And omitting the horrible external stack munging
that
// UnpackIterable does.
- Value *iterable = fbuilder_->Pop();
- Function *unpack_iterable = state_->GetGlobalFunction<
+ Value *iterable = this->fbuilder_->Pop();
+ Function *unpack_iterable = this->state_->GetGlobalFunction<
int(PyObject *, int, PyObject **)>("_PyLlvm_FastUnpackIterable");
- Value *new_stack_pointer = fbuilder_->builder_.CreateGEP(
- fbuilder_->builder_.CreateLoad(fbuilder_->stack_pointer_addr_),
+ Value *new_stack_pointer = this->builder_.CreateGEP(
+ this->builder_.CreateLoad(this->fbuilder_->stack_pointer_addr()),
ConstantInt::getSigned(
- PyTypeBuilder<Py_ssize_t>::get(fbuilder_->context_), size));
- fbuilder_->llvm_data_->tbaa_stack.MarkInstruction(new_stack_pointer);
-
- Value *result = state_->CreateCall(
+ PyTypeBuilder<Py_ssize_t>::get(this->fbuilder_->context()),
size));
+
this->fbuilder_->llvm_data()->tbaa_stack.MarkInstruction(new_stack_pointer);
+
+ Value *result = this->state_->CreateCall(
unpack_iterable, iterable,
ConstantInt::get(
- PyTypeBuilder<int>::get(fbuilder_->context_), size, true),
+ PyTypeBuilder<int>::get(this->fbuilder_->context()), size,
true),
// _PyLlvm_FastUnpackIterable really takes the *new* stack pointer
as
// an argument, because it builds the result stack in reverse.
new_stack_pointer);
- state_->DecRef(iterable);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ this->state_->DecRef(iterable);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
// Not setting the new stackpointer on failure does mean that if
// _PyLlvm_FastUnpackIterable failed after pushing some values onto the
// stack, and it didn't clean up after itself, we lose references.
This
// is what eval.cc does as well.
- fbuilder_->builder_.CreateStore(new_stack_pointer,
- fbuilder_->stack_pointer_addr_);
+ this->builder_.CreateStore(new_stack_pointer,
+ this->fbuilder_->stack_pointer_addr());
}

#define INT_OBJ_OBJ_OBJ int(PyObject*, PyObject*, PyObject*)
@@ -137,48 +139,50 @@
void
OpcodeContainer::STORE_SUBSCR_list_int()
{
- BasicBlock *success = state_->CreateBasicBlock("STORE_SUBSCR_success");
- BasicBlock *bailpoint = state_->CreateBasicBlock("STORE_SUBSCR_bail");
-
- Value *key = fbuilder_->Pop();
- Value *obj = fbuilder_->Pop();
- Value *value = fbuilder_->Pop();
+ BasicBlock *success =
+ this->state_->CreateBasicBlock("STORE_SUBSCR_success");
+ BasicBlock *bailpoint =
+ this->state_->CreateBasicBlock("STORE_SUBSCR_bail");
+
+ Value *key = this->fbuilder_->Pop();
+ Value *obj = this->fbuilder_->Pop();
+ Value *value = this->fbuilder_->Pop();
Function *setitem =
- state_->GetGlobalFunction<INT_OBJ_OBJ_OBJ>(
+ this->state_->GetGlobalFunction<INT_OBJ_OBJ_OBJ>(
"_PyLlvm_StoreSubscr_List");

- Value *result = state_->CreateCall(setitem, obj, key, value,
- "STORE_SUBSCR_result");
- fbuilder_->builder_.CreateCondBr(state_->IsNonZero(result),
- bailpoint, success);
-
- fbuilder_->builder_.SetInsertPoint(bailpoint);
- fbuilder_->Push(value);
- fbuilder_->Push(obj);
- fbuilder_->Push(key);
- fbuilder_->CreateGuardBailPoint(_PYGUARD_STORE_SUBSCR);
-
- fbuilder_->builder_.SetInsertPoint(success);
- state_->DecRef(value);
- state_->DecRef(obj);
- state_->DecRef(key);
+ Value *result = this->state_->CreateCall(setitem, obj, key, value,
+ "STORE_SUBSCR_result");
+ this->builder_.CreateCondBr(this->state_->IsNonZero(result),
+ bailpoint, success);
+
+ this->builder_.SetInsertPoint(bailpoint);
+ this->fbuilder_->Push(value);
+ this->fbuilder_->Push(obj);
+ this->fbuilder_->Push(key);
+ this->fbuilder_->CreateGuardBailPoint(_PYGUARD_STORE_SUBSCR);
+
+ this->builder_.SetInsertPoint(success);
+ this->state_->DecRef(value);
+ this->state_->DecRef(obj);
+ this->state_->DecRef(key);
}

void
OpcodeContainer::STORE_SUBSCR_safe()
{
// Performing obj[key] = val
- Value *key = fbuilder_->Pop();
- Value *obj = fbuilder_->Pop();
- Value *value = fbuilder_->Pop();
+ Value *key = this->fbuilder_->Pop();
+ Value *obj = this->fbuilder_->Pop();
+ Value *value = this->fbuilder_->Pop();
Function *setitem =
- state_->GetGlobalFunction<INT_OBJ_OBJ_OBJ>("PyObject_SetItem");
- Value *result = state_->CreateCall(setitem, obj, key, value,
- "STORE_SUBSCR_result");
- state_->DecRef(value);
- state_->DecRef(obj);
- state_->DecRef(key);
- fbuilder_->PropagateExceptionOnNonZero(result);
+
this->state_->GetGlobalFunction<INT_OBJ_OBJ_OBJ>("PyObject_SetItem");
+ Value *result = this->state_->CreateCall(setitem, obj, key, value,
+ "STORE_SUBSCR_result");
+ this->state_->DecRef(value);
+ this->state_->DecRef(obj);
+ this->state_->DecRef(key);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

#undef INT_OBJ_OBJ_OBJ
@@ -188,8 +192,8 @@
{
OpcodeBinops::IncStatsTotal();

- const PyTypeObject *lhs_type = fbuilder_->GetTypeFeedback(0);
- const PyTypeObject *rhs_type = fbuilder_->GetTypeFeedback(1);
+ const PyTypeObject *lhs_type = this->fbuilder_->GetTypeFeedback(0);
+ const PyTypeObject *rhs_type = this->fbuilder_->GetTypeFeedback(1);

if (lhs_type == &PyList_Type && rhs_type == &PyInt_Type) {
OpcodeBinops::IncStatsOptimized();
@@ -206,51 +210,51 @@
void
OpcodeContainer::DELETE_SUBSCR()
{
- Value *key = fbuilder_->Pop();
- Value *obj = fbuilder_->Pop();
- Function *delitem = state_->GetGlobalFunction<
+ Value *key = this->fbuilder_->Pop();
+ Value *obj = this->fbuilder_->Pop();
+ Function *delitem = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *)>("PyObject_DelItem");
- Value *result = state_->CreateCall(delitem, obj, key,
- "DELETE_SUBSCR_result");
- state_->DecRef(obj);
- state_->DecRef(key);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ Value *result = this->state_->CreateCall(delitem, obj, key,
+ "DELETE_SUBSCR_result");
+ this->state_->DecRef(obj);
+ this->state_->DecRef(key);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

void
OpcodeContainer::LIST_APPEND()
{
- Value *item = fbuilder_->Pop();
- Value *listobj = fbuilder_->Pop();
- Function *list_append = state_->GetGlobalFunction<
+ Value *item = this->fbuilder_->Pop();
+ Value *listobj = this->fbuilder_->Pop();
+ Function *list_append = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *)>("PyList_Append");
- Value *result = state_->CreateCall(list_append, listobj, item,
- "LIST_APPEND_result");
- state_->DecRef(listobj);
- state_->DecRef(item);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ Value *result = this->state_->CreateCall(list_append, listobj, item,
+ "LIST_APPEND_result");
+ this->state_->DecRef(listobj);
+ this->state_->DecRef(item);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

void
OpcodeContainer::STORE_MAP()
{
- Value *key = fbuilder_->Pop();
- Value *value = fbuilder_->Pop();
- Value *dict = fbuilder_->Pop();
- fbuilder_->Push(dict);
- Value *dict_type = fbuilder_->builder_.CreateLoad(
- ObjectTy::ob_type(fbuilder_->builder_, dict));
- Value *is_exact_dict = fbuilder_->builder_.CreateICmpEQ(
- dict_type, state_->GetGlobalVariableFor((PyObject*)&PyDict_Type));
- state_->Assert(is_exact_dict,
- "dict argument to STORE_MAP is not exactly a PyDict");
- Function *setitem = state_->GetGlobalFunction<
+ Value *key = this->fbuilder_->Pop();
+ Value *value = this->fbuilder_->Pop();
+ Value *dict = this->fbuilder_->Pop();
+ this->fbuilder_->Push(dict);
+ Value *dict_type = this->builder_.CreateLoad(
+ ObjectTy::ob_type(this->builder_, dict));
+ Value *is_exact_dict = this->builder_.CreateICmpEQ(
+ dict_type,
this->state_->GetGlobalVariableFor((PyObject*)&PyDict_Type));
+ this->state_->Assert(is_exact_dict,
+ "dict argument to STORE_MAP is not exactly a
PyDict");
+ Function *setitem = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *, PyObject *)>("PyDict_SetItem");
- Value *result = state_->CreateCall(setitem, dict, key, value,
- "STORE_MAP_result");
- state_->DecRef(value);
- state_->DecRef(key);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ Value *result = this->state_->CreateCall(setitem, dict, key, value,
+ "STORE_MAP_result");
+ this->state_->DecRef(value);
+ this->state_->DecRef(key);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

#define FUNC_TYPE PyObject *(PyObject *, PyObject *, PyObject *)
@@ -263,18 +267,18 @@
if (this->IMPORT_NAME_fast())
return;

- Value *mod_name = fbuilder_->Pop();
- Value *names = fbuilder_->Pop();
- Value *level = fbuilder_->Pop();
-
- Value *module = state_->CreateCall(
- state_->GetGlobalFunction<FUNC_TYPE>("_PyEval_ImportName"),
+ Value *mod_name = this->fbuilder_->Pop();
+ Value *names = this->fbuilder_->Pop();
+ Value *level = this->fbuilder_->Pop();
+
+ Value *module = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<FUNC_TYPE>("_PyEval_ImportName"),
level, names, mod_name);
- state_->DecRef(level);
- state_->DecRef(names);
- state_->DecRef(mod_name);
- fbuilder_->PropagateExceptionOnNull(module);
- fbuilder_->Push(module);
+ this->state_->DecRef(level);
+ this->state_->DecRef(names);
+ this->state_->DecRef(mod_name);
+ this->fbuilder_->PropagateExceptionOnNull(module);
+ this->fbuilder_->Push(module);
}

#undef FUNC_TYPE
@@ -282,7 +286,7 @@
bool
OpcodeContainer::IMPORT_NAME_fast()
{
- PyCodeObject *code = fbuilder_->code_object_;
+ PyCodeObject *code = fbuilder_->code_object();

// If we're not already monitoring the builtins dict, monitor it.
Normally
// we pick it up from the eval loop, but if it isn't here, then we
make a
@@ -293,7 +297,7 @@
_PyCode_WatchDict(code, WATCHING_BUILTINS, builtins);
}

- const PyRuntimeFeedback *feedback = fbuilder_->GetFeedback();
+ const PyRuntimeFeedback *feedback = this->fbuilder_->GetFeedback();
if (feedback == NULL || feedback->ObjectsOverflowed()) {
return false;
}
@@ -319,35 +323,34 @@
return false;
}

- fbuilder_->uses_watched_dicts_.set(WATCHING_BUILTINS);
- fbuilder_->uses_watched_dicts_.set(WATCHING_SYS_MODULES);
+ fbuilder_->WatchDict(WATCHING_BUILTINS);
+ fbuilder_->WatchDict(WATCHING_SYS_MODULES);
}

BasicBlock *keep_going =
- state_->CreateBasicBlock("IMPORT_NAME_keep_going");
+ this->state_->CreateBasicBlock("IMPORT_NAME_keep_going");
BasicBlock *invalid_assumptions =
- state_->CreateBasicBlock("IMPORT_NAME_invalid_assumptions");
-
- Value *use_jit =
fbuilder_->builder_.CreateLoad(fbuilder_->use_jit_addr_);
- fbuilder_->builder_.CreateCondBr(state_->IsNonZero(use_jit),
- keep_going,
- invalid_assumptions);
+ this->state_->CreateBasicBlock("IMPORT_NAME_invalid_assumptions");
+
+ this->builder_.CreateCondBr(this->fbuilder_->GetUseJitCond(),
+ keep_going,
+ invalid_assumptions);

/* Our assumptions about the state of sys.modules no longer hold;
bail back to the interpreter. */
- fbuilder_->builder_.SetInsertPoint(invalid_assumptions);
- fbuilder_->CreateBailPoint(_PYFRAME_FATAL_GUARD_FAIL);
-
- fbuilder_->builder_.SetInsertPoint(keep_going);
+ this->builder_.SetInsertPoint(invalid_assumptions);
+ this->fbuilder_->CreateBailPoint(_PYFRAME_FATAL_GUARD_FAIL);
+
+ this->builder_.SetInsertPoint(keep_going);
/* TODO(collinwinter): we pop to get rid of the inputs to IMPORT_NAME.
Find a way to omit this work. */
- state_->DecRef(fbuilder_->Pop());
- state_->DecRef(fbuilder_->Pop());
- state_->DecRef(fbuilder_->Pop());
-
- Value *mod = state_->GetGlobalVariableFor(module);
- state_->IncRef(mod);
- fbuilder_->Push(mod);
+ this->state_->DecRef(this->fbuilder_->Pop());
+ this->state_->DecRef(this->fbuilder_->Pop());
+ this->state_->DecRef(this->fbuilder_->Pop());
+
+ Value *mod = this->state_->GetGlobalVariableFor(module);
+ this->state_->IncRef(mod);
+ this->fbuilder_->Push(mod);

IMPORT_NAME_INC_STATS(optimized);
return true;
=======================================
--- /trunk/JIT/opcodes/container.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/container.h Wed Jul 28 23:50:04 2010
@@ -6,9 +6,8 @@
#error This header expects to be included only in C++ source
#endif

-namespace llvm {
- class Value;
-}
+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"

namespace py {

@@ -38,6 +37,8 @@
void IMPORT_NAME();

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
// Helper method for building a new sequence from items on the stack.
// 'size' is the number of items to build, 'createname' the Python/C
API
// function to call to create the sequence, and 'getitemslot' is called
@@ -58,6 +59,7 @@

LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
};

}
=======================================
--- /trunk/JIT/opcodes/control.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/control.cc Wed Jul 28 23:50:04 2010
@@ -53,7 +53,9 @@
namespace py {

OpcodeControl::OpcodeControl(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder())
{
}

@@ -63,71 +65,71 @@
// Accept code after a raise statement, even though it's never
executed.
// Otherwise, CPython's willingness to insert code after block
// terminators causes problems.
- BasicBlock *dead_code = state_->CreateBasicBlock("dead_code");
+ BasicBlock *dead_code = this->state_->CreateBasicBlock("dead_code");

// All raises set 'why' to UNWIND_EXCEPTION and the return value to
NULL.
// This is redundant with the propagate_exception_block_, but mem2reg
will
// remove the redundancy.
- fbuilder_->builder_.CreateStore(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ this->builder_.CreateStore(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_EXCEPTION),
- fbuilder_->unwind_reason_addr_);
- fbuilder_->builder_.CreateStore(state_->GetNull<PyObject*>(),
- fbuilder_->retval_addr_);
+ this->fbuilder_->unwind_reason_addr());
+ this->builder_.CreateStore(this->state_->GetNull<PyObject*>(),
+ this->fbuilder_->retval_addr());

#ifdef WITH_TSC
- state_->LogTscEvent(EXCEPT_RAISE_LLVM);
+ this->state_->LogTscEvent(EXCEPT_RAISE_LLVM);
#endif
- Function *do_raise = state_->GetGlobalFunction<
+ Function *do_raise = this->state_->GetGlobalFunction<
int(PyObject*, PyObject *, PyObject *)>("_PyEval_DoRaise");
// _PyEval_DoRaise eats references.
- Value *is_reraise = state_->CreateCall(
+ Value *is_reraise = this->state_->CreateCall(
do_raise, exc_type, exc_inst, exc_tb, "raise_is_reraise");
// If this is a "re-raise", we jump straight to the unwind block.
// If it's a new raise, we call PyTraceBack_Here from the
// propagate_exception_block_.
- fbuilder_->builder_.CreateCondBr(
- fbuilder_->builder_.CreateICmpEQ(
+ this->builder_.CreateCondBr(
+ this->builder_.CreateICmpEQ(
is_reraise,
ConstantInt::get(is_reraise->getType(), UNWIND_RERAISE)),
- fbuilder_->unwind_block_, fbuilder_->GetExceptionBlock());
-
- fbuilder_->builder_.SetInsertPoint(dead_code);
+ this->fbuilder_->unwind_block(),
this->fbuilder_->GetExceptionBlock());
+
+ this->builder_.SetInsertPoint(dead_code);
}

void
OpcodeControl::RAISE_VARARGS_ZERO()
{
- Value *exc_tb = state_->GetNull<PyObject*>();
- Value *exc_inst = state_->GetNull<PyObject*>();
- Value *exc_type = state_->GetNull<PyObject*>();
+ Value *exc_tb = this->state_->GetNull<PyObject*>();
+ Value *exc_inst = this->state_->GetNull<PyObject*>();
+ Value *exc_type = this->state_->GetNull<PyObject*>();
this->DoRaise(exc_type, exc_inst, exc_tb);
}

void
OpcodeControl::RAISE_VARARGS_ONE()
{
- Value *exc_tb = state_->GetNull<PyObject*>();
- Value *exc_inst = state_->GetNull<PyObject*>();
- Value *exc_type = fbuilder_->Pop();
+ Value *exc_tb = this->state_->GetNull<PyObject*>();
+ Value *exc_inst = this->state_->GetNull<PyObject*>();
+ Value *exc_type = this->fbuilder_->Pop();
this->DoRaise(exc_type, exc_inst, exc_tb);
}

void
OpcodeControl::RAISE_VARARGS_TWO()
{
- Value *exc_tb = state_->GetNull<PyObject*>();
- Value *exc_inst = fbuilder_->Pop();
- Value *exc_type = fbuilder_->Pop();
+ Value *exc_tb = this->state_->GetNull<PyObject*>();
+ Value *exc_inst = this->fbuilder_->Pop();
+ Value *exc_type = this->fbuilder_->Pop();
this->DoRaise(exc_type, exc_inst, exc_tb);
}

void
OpcodeControl::RAISE_VARARGS_THREE()
{
- Value *exc_tb = fbuilder_->Pop();
- Value *exc_inst = fbuilder_->Pop();
- Value *exc_type = fbuilder_->Pop();
+ Value *exc_tb = this->fbuilder_->Pop();
+ Value *exc_inst = this->fbuilder_->Pop();
+ Value *exc_type = this->fbuilder_->Pop();
this->DoRaise(exc_type, exc_inst, exc_tb);
}

@@ -137,64 +139,65 @@
// Accept code after a return statement, even though it's never
executed.
// Otherwise, CPython's willingness to insert code after block
// terminators causes problems.
- BasicBlock *dead_code = state_->CreateBasicBlock("dead_code");
-
- Value *retval = fbuilder_->Pop();
- fbuilder_->Return(retval);
-
- fbuilder_->builder_.SetInsertPoint(dead_code);
+ BasicBlock *dead_code = this->state_->CreateBasicBlock("dead_code");
+
+ Value *retval = this->fbuilder_->Pop();
+ this->fbuilder_->Return(retval);
+
+ this->builder_.SetInsertPoint(dead_code);
}

void
OpcodeControl::YIELD_VALUE()
{
- assert(fbuilder_->is_generator_ && "yield in non-generator!");
+ assert(this->fbuilder_->is_generator() && "yield in non-generator!");
BasicBlock *yield_resume =
- state_->CreateBasicBlock("yield_resume");
+ this->state_->CreateBasicBlock("yield_resume");
// Save the current opcode index into f_lasti when we yield so
// that, if tracing gets turned on while we're outside this
// function we can jump back to the interpreter at the right
// place.
ConstantInt *yield_number =
-
ConstantInt::getSigned(PyTypeBuilder<int>::get(fbuilder_->context_),
- fbuilder_->f_lasti_);
- fbuilder_->yield_resume_switch_->addCase(yield_number, yield_resume);
-
- Value *retval = fbuilder_->Pop();
+ ConstantInt::getSigned(
+ PyTypeBuilder<int>::get(this->fbuilder_->context()),
+ this->fbuilder_->GetLasti());
+ this->fbuilder_->AddYieldResumeBB(yield_number, yield_resume);
+
+ Value *retval = this->fbuilder_->Pop();

// Save everything to the frame object so it'll be there when we
// resume from the yield.
- fbuilder_->CopyToFrameObject();
+ this->fbuilder_->CopyToFrameObject();

// Save the right block to jump back to when we resume this generator.
- fbuilder_->builder_.CreateStore(yield_number,
fbuilder_->f_lasti_addr_);
+ this->builder_.CreateStore(yield_number,
this->fbuilder_->f_lasti_addr());

// Yields return from the current function without unwinding the
// stack. They do trace the return and call _PyEval_ResetExcInfo
// like everything else, so we jump to the common return block
// instead of returning directly.
- fbuilder_->builder_.CreateStore(retval, fbuilder_->retval_addr_);
- fbuilder_->builder_.CreateStore(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ this->builder_.CreateStore(retval, this->fbuilder_->retval_addr());
+ this->builder_.CreateStore(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_YIELD),
- fbuilder_->unwind_reason_addr_);
- fbuilder_->builder_.CreateBr(fbuilder_->do_return_block_);
+ this->fbuilder_->unwind_reason_addr());
+ this->builder_.CreateBr(this->fbuilder_->do_return_block());

// Continue inserting code inside the resume block.
- fbuilder_->builder_.SetInsertPoint(yield_resume);
+ this->builder_.SetInsertPoint(yield_resume);
// Set frame->f_lasti back to negative so that exceptions are
// generated with llvm-provided line numbers.
- fbuilder_->builder_.CreateStore(
+ this->builder_.CreateStore(
ConstantInt::getSigned(
- PyTypeBuilder<int>::get(fbuilder_->context_), -2),
- fbuilder_->f_lasti_addr_);
+ PyTypeBuilder<int>::get(this->fbuilder_->context()), -2),
+ this->fbuilder_->f_lasti_addr());
}

void
OpcodeControl::JUMP_ABSOLUTE(llvm::BasicBlock *target,
llvm::BasicBlock *fallthrough)
{
- fbuilder_->builder_.CreateBr(target);
+ this->builder_.CreateBr(target);
}

enum BranchInput {
@@ -246,15 +249,16 @@
BasicBlock **bail_block)
{
COND_BRANCH_INC_STATS(total);
- BranchInput branch_dir =
predict_branch_input(fbuilder_->GetFeedback());
+ BranchInput branch_dir =
+ predict_branch_input(this->fbuilder_->GetFeedback());

if (branch_dir == BranchInputFalse) {
*bail_idx = false_idx;
- *false_block = *bail_block =
state_->CreateBasicBlock("FALSE_bail");
+ *false_block = *bail_block =
this->state_->CreateBasicBlock("FALSE_bail");
}
else if (branch_dir == BranchInputTrue) {
*bail_idx = true_idx;
- *true_block = *bail_block = state_->CreateBasicBlock("TRUE_bail");
+ *true_block = *bail_block =
this->state_->CreateBasicBlock("TRUE_bail");
}
else {
*bail_idx = 0;
@@ -267,12 +271,12 @@
unsigned bail_idx)
{
COND_BRANCH_INC_STATS(optimized);
- BasicBlock *current = fbuilder_->builder_.GetInsertBlock();
-
- fbuilder_->builder_.SetInsertPoint(bail_to);
- fbuilder_->CreateGuardBailPoint(bail_idx, _PYGUARD_BRANCH);
-
- fbuilder_->builder_.SetInsertPoint(current);
+ BasicBlock *current = this->builder_.GetInsertBlock();
+
+ this->builder_.SetInsertPoint(bail_to);
+ this->fbuilder_->CreateGuardBailPoint(bail_idx, _PYGUARD_BRANCH);
+
+ this->builder_.SetInsertPoint(current);
}

void
@@ -287,9 +291,9 @@
/*on false: */ fallthrough_idx,
&fallthrough,
&bail_idx, &bail_to);

- Value *test_value = fbuilder_->Pop();
- Value *is_true = fbuilder_->IsPythonTrue(test_value);
- fbuilder_->builder_.CreateCondBr(is_true, fallthrough, target);
+ Value *test_value = this->fbuilder_->Pop();
+ Value *is_true = this->fbuilder_->IsPythonTrue(test_value);
+ this->builder_.CreateCondBr(is_true, fallthrough, target);

if (bail_to)
this->FillPyCondBranchBailBlock(bail_to, bail_idx);
@@ -307,9 +311,9 @@
/*on false: */ target_idx, &target,
&bail_idx, &bail_to);

- Value *test_value = fbuilder_->Pop();
- Value *is_true = fbuilder_->IsPythonTrue(test_value);
- fbuilder_->builder_.CreateCondBr(is_true, target, fallthrough);
+ Value *test_value = this->fbuilder_->Pop();
+ Value *is_true = this->fbuilder_->IsPythonTrue(test_value);
+ this->builder_.CreateCondBr(is_true, target, fallthrough);

if (bail_to)
this->FillPyCondBranchBailBlock(bail_to, bail_idx);
@@ -328,18 +332,18 @@
&bail_idx, &bail_to);

BasicBlock *true_path =
- state_->CreateBasicBlock("JUMP_IF_FALSE_OR_POP_pop");
- Value *test_value = fbuilder_->Pop();
- fbuilder_->Push(test_value);
+ this->state_->CreateBasicBlock("JUMP_IF_FALSE_OR_POP_pop");
+ Value *test_value = this->fbuilder_->Pop();
+ this->fbuilder_->Push(test_value);
// IsPythonTrue() will steal the reference to test_value, so make sure
// the stack owns one too.
- state_->IncRef(test_value);
- Value *is_true = fbuilder_->IsPythonTrue(test_value);
- fbuilder_->builder_.CreateCondBr(is_true, true_path, target);
- fbuilder_->builder_.SetInsertPoint(true_path);
- test_value = fbuilder_->Pop();
- state_->DecRef(test_value);
- fbuilder_->builder_.CreateBr(fallthrough);
+ this->state_->IncRef(test_value);
+ Value *is_true = this->fbuilder_->IsPythonTrue(test_value);
+ this->builder_.CreateCondBr(is_true, true_path, target);
+ this->builder_.SetInsertPoint(true_path);
+ test_value = this->fbuilder_->Pop();
+ this->state_->DecRef(test_value);
+ this->builder_.CreateBr(fallthrough);

if (bail_to)
this->FillPyCondBranchBailBlock(bail_to, bail_idx);
@@ -358,18 +362,18 @@
&bail_idx, &bail_to);

BasicBlock *false_path =
- state_->CreateBasicBlock("JUMP_IF_TRUE_OR_POP_pop");
- Value *test_value = fbuilder_->Pop();
- fbuilder_->Push(test_value);
+ this->state_->CreateBasicBlock("JUMP_IF_TRUE_OR_POP_pop");
+ Value *test_value = this->fbuilder_->Pop();
+ this->fbuilder_->Push(test_value);
// IsPythonTrue() will steal the reference to test_value, so make sure
// the stack owns one too.
- state_->IncRef(test_value);
- Value *is_true = fbuilder_->IsPythonTrue(test_value);
- fbuilder_->builder_.CreateCondBr(is_true, target, false_path);
- fbuilder_->builder_.SetInsertPoint(false_path);
- test_value = fbuilder_->Pop();
- state_->DecRef(test_value);
- fbuilder_->builder_.CreateBr(fallthrough);
+ this->state_->IncRef(test_value);
+ Value *is_true = this->fbuilder_->IsPythonTrue(test_value);
+ this->builder_.CreateCondBr(is_true, target, false_path);
+ this->builder_.SetInsertPoint(false_path);
+ test_value = this->fbuilder_->Pop();
+ this->state_->DecRef(test_value);
+ this->builder_.CreateBr(fallthrough);

if (bail_to)
this->FillPyCondBranchBailBlock(bail_to, bail_idx);
=======================================
--- /trunk/JIT/opcodes/control.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/control.h Wed Jul 28 23:50:04 2010
@@ -6,6 +6,9 @@
#error This header expects to be included only in C++ source
#endif

+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"
+
namespace llvm {
class BasicBlock;
class Value;
@@ -54,6 +57,8 @@
llvm::BasicBlock *fallthrough);

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
// Set exception information and jump to exception handling. The
// arguments can be Value*'s representing NULL to implement the
// four forms of the 'raise' statement. Steals all references.
@@ -87,6 +92,7 @@

LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
};

}
=======================================
--- /trunk/JIT/opcodes/globals.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/globals.cc Wed Jul 28 23:50:04 2010
@@ -14,7 +14,9 @@
namespace py {

OpcodeGlobals::OpcodeGlobals(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder())
{
}

@@ -23,7 +25,7 @@
// A code object might not have co_watching set if
// a) it was compiled by setting co_optimization, or
// b) we couldn't watch the globals/builtins dicts.
- PyObject **watching = fbuilder_->code_object_->co_watching;
+ PyObject **watching = this->fbuilder_->code_object()->co_watching;
if (watching && watching[WATCHING_GLOBALS] &&
watching[WATCHING_BUILTINS])
this->LOAD_GLOBAL_fast(index);
else
@@ -32,7 +34,7 @@

void OpcodeGlobals::LOAD_GLOBAL_fast(int index)
{
- PyCodeObject *code = fbuilder_->code_object_;
+ PyCodeObject *code = this->fbuilder_->code_object();
assert(code->co_watching != NULL);
assert(code->co_watching[WATCHING_GLOBALS]);
assert(code->co_watching[WATCHING_BUILTINS]);
@@ -50,124 +52,124 @@
return;
}
}
- fbuilder_->uses_watched_dicts_.set(WATCHING_GLOBALS);
- fbuilder_->uses_watched_dicts_.set(WATCHING_BUILTINS);
+ this->fbuilder_->WatchDict(WATCHING_GLOBALS);
+ this->fbuilder_->WatchDict(WATCHING_BUILTINS);

BasicBlock *keep_going =
- state_->CreateBasicBlock("LOAD_GLOBAL_keep_going");
+ this->state_->CreateBasicBlock("LOAD_GLOBAL_keep_going");
BasicBlock *invalid_assumptions =
- state_->CreateBasicBlock("LOAD_GLOBAL_invalid_assumptions");
+ this->state_->CreateBasicBlock("LOAD_GLOBAL_invalid_assumptions");

#ifdef WITH_TSC
- state_->LogTscEvent(LOAD_GLOBAL_ENTER_LLVM);
+ this->state_->LogTscEvent(LOAD_GLOBAL_ENTER_LLVM);
#endif
- Value *use_jit =
fbuilder_->builder_.CreateLoad(fbuilder_->use_jit_addr_,
- "co_use_jit");
- fbuilder_->builder_.CreateCondBr(state_->IsNonZero(use_jit),
- keep_going,
- invalid_assumptions);
+ this->builder_.CreateCondBr(this->fbuilder_->GetUseJitCond(),
+ keep_going,
+ invalid_assumptions);

/* Our assumptions about the state of the globals/builtins no longer
hold;
bail back to the interpreter. */
- fbuilder_->builder_.SetInsertPoint(invalid_assumptions);
- fbuilder_->CreateBailPoint(_PYFRAME_FATAL_GUARD_FAIL);
+ this->builder_.SetInsertPoint(invalid_assumptions);
+ this->fbuilder_->CreateBailPoint(_PYFRAME_FATAL_GUARD_FAIL);

/* Our assumptions are still valid; encode the result of the lookups
as an
immediate in the IR. */
- fbuilder_->builder_.SetInsertPoint(keep_going);
- Value *global = state_->EmbedPointer<PyObject*>(obj);
- state_->IncRef(global);
- fbuilder_->Push(global);
+ this->builder_.SetInsertPoint(keep_going);
+ Value *global = this->state_->EmbedPointer<PyObject*>(obj);
+ this->state_->IncRef(global);
+ this->fbuilder_->Push(global);

#ifdef WITH_TSC
- state_->LogTscEvent(LOAD_GLOBAL_EXIT_LLVM);
+ this->state_->LogTscEvent(LOAD_GLOBAL_EXIT_LLVM);
#endif
}

void OpcodeGlobals::LOAD_GLOBAL_safe(int index)
{
BasicBlock *global_missing =
- state_->CreateBasicBlock("LOAD_GLOBAL_global_missing");
+ this->state_->CreateBasicBlock("LOAD_GLOBAL_global_missing");
BasicBlock *global_success =
- state_->CreateBasicBlock("LOAD_GLOBAL_global_success");
+ this->state_->CreateBasicBlock("LOAD_GLOBAL_global_success");
BasicBlock *builtin_missing =
- state_->CreateBasicBlock("LOAD_GLOBAL_builtin_missing");
+ this->state_->CreateBasicBlock("LOAD_GLOBAL_builtin_missing");
BasicBlock *builtin_success =
- state_->CreateBasicBlock("LOAD_GLOBAL_builtin_success");
- BasicBlock *done = state_->CreateBasicBlock("LOAD_GLOBAL_done");
+ this->state_->CreateBasicBlock("LOAD_GLOBAL_builtin_success");
+ BasicBlock *done = this->state_->CreateBasicBlock("LOAD_GLOBAL_done");
#ifdef WITH_TSC
- state_->LogTscEvent(LOAD_GLOBAL_ENTER_LLVM);
+ this->state_->LogTscEvent(LOAD_GLOBAL_ENTER_LLVM);
#endif
- Value *name = fbuilder_->LookupName(index);
- Function *pydict_getitem = state_->GetGlobalFunction<
+ Value *name = this->fbuilder_->LookupName(index);
+ Function *pydict_getitem = this->state_->GetGlobalFunction<
PyObject *(PyObject *, PyObject *)>("PyDict_GetItem");
- Value *global = state_->CreateCall(
- pydict_getitem, fbuilder_->globals_, name, "global_variable");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(global),
- global_missing, global_success);
-
- fbuilder_->builder_.SetInsertPoint(global_success);
- state_->IncRef(global);
- fbuilder_->Push(global);
- fbuilder_->builder_.CreateBr(done);
-
- fbuilder_->builder_.SetInsertPoint(global_missing);
+ Value *global = this->state_->CreateCall(
+ pydict_getitem, this->fbuilder_->globals(),
name, "global_variable");
+ this->builder_.CreateCondBr(this->state_->IsNull(global),
+ global_missing, global_success);
+
+ this->builder_.SetInsertPoint(global_success);
+ this->state_->IncRef(global);
+ this->fbuilder_->Push(global);
+ this->builder_.CreateBr(done);
+
+ this->builder_.SetInsertPoint(global_missing);
// This ignores any exception set by PyDict_GetItem (and similarly
// for the builtins dict below,) but this is what ceval does too.
- Value *builtin = state_->CreateCall(
- pydict_getitem, fbuilder_->builtins_, name, "builtin_variable");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(builtin),
- builtin_missing, builtin_success);
-
- fbuilder_->builder_.SetInsertPoint(builtin_missing);
- Function *do_raise = state_->GetGlobalFunction<
+ Value *builtin = this->state_->CreateCall(
+ pydict_getitem, this->fbuilder_->builtins(),
name, "builtin_variable");
+ this->builder_.CreateCondBr(this->state_->IsNull(builtin),
+ builtin_missing, builtin_success);
+
+ this->builder_.SetInsertPoint(builtin_missing);
+ Function *do_raise = this->state_->GetGlobalFunction<
void(PyObject *)>("_PyEval_RaiseForGlobalNameError");
- state_->CreateCall(do_raise, name);
- fbuilder_->PropagateException();
-
- fbuilder_->builder_.SetInsertPoint(builtin_success);
- state_->IncRef(builtin);
- fbuilder_->Push(builtin);
- fbuilder_->builder_.CreateBr(done);
-
- fbuilder_->builder_.SetInsertPoint(done);
+ this->state_->CreateCall(do_raise, name);
+ this->fbuilder_->PropagateException();
+
+ this->builder_.SetInsertPoint(builtin_success);
+ this->state_->IncRef(builtin);
+ this->fbuilder_->Push(builtin);
+ this->builder_.CreateBr(done);
+
+ this->builder_.SetInsertPoint(done);
#ifdef WITH_TSC
- state_->LogTscEvent(LOAD_GLOBAL_EXIT_LLVM);
+ this->state_->LogTscEvent(LOAD_GLOBAL_EXIT_LLVM);
#endif
}

void OpcodeGlobals::STORE_GLOBAL(int index)
{
- Value *name = fbuilder_->LookupName(index);
- Value *value = fbuilder_->Pop();
- Function *pydict_setitem = state_->GetGlobalFunction<
+ Value *name = this->fbuilder_->LookupName(index);
+ Value *value = this->fbuilder_->Pop();
+ Function *pydict_setitem = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *, PyObject *)>("PyDict_SetItem");
- Value *result = state_->CreateCall(
- pydict_setitem, fbuilder_->globals_, name, value,
+ Value *result = this->state_->CreateCall(
+ pydict_setitem, this->fbuilder_->globals(), name, value,
"STORE_GLOBAL_result");
- state_->DecRef(value);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ this->state_->DecRef(value);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

void OpcodeGlobals::DELETE_GLOBAL(int index)
{
- BasicBlock *failure =
state_->CreateBasicBlock("DELETE_GLOBAL_failure");
- BasicBlock *success =
state_->CreateBasicBlock("DELETE_GLOBAL_success");
- Value *name = fbuilder_->LookupName(index);
- Function *pydict_setitem = state_->GetGlobalFunction<
+ BasicBlock *failure =
+ this->state_->CreateBasicBlock("DELETE_GLOBAL_failure");
+ BasicBlock *success =
+ this->state_->CreateBasicBlock("DELETE_GLOBAL_success");
+ Value *name = this->fbuilder_->LookupName(index);
+ Function *pydict_setitem = this->state_->GetGlobalFunction<
int(PyObject *, PyObject *)>("PyDict_DelItem");
- Value *result = state_->CreateCall(
- pydict_setitem, fbuilder_->globals_, name, "STORE_GLOBAL_result");
- fbuilder_->builder_.CreateCondBr(state_->IsNonZero(result),
- failure, success);
-
- fbuilder_->builder_.SetInsertPoint(failure);
- Function *do_raise = state_->GetGlobalFunction<
+ Value *result = this->state_->CreateCall(
+ pydict_setitem, this->fbuilder_->globals(),
name, "STORE_GLOBAL_result");
+ this->builder_.CreateCondBr(this->state_->IsNonZero(result),
+ failure, success);
+
+ this->builder_.SetInsertPoint(failure);
+ Function *do_raise = this->state_->GetGlobalFunction<
void(PyObject *)>("_PyEval_RaiseForGlobalNameError");
- state_->CreateCall(do_raise, name);
- fbuilder_->PropagateException();
-
- fbuilder_->builder_.SetInsertPoint(success);
+ this->state_->CreateCall(do_raise, name);
+ this->fbuilder_->PropagateException();
+
+ this->builder_.SetInsertPoint(success);
}

}
=======================================
--- /trunk/JIT/opcodes/globals.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/globals.h Wed Jul 28 23:50:04 2010
@@ -6,6 +6,9 @@
#error This header expects to be included only in C++ source
#endif

+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"
+
namespace py {

class LlvmFunctionBuilder;
@@ -22,6 +25,8 @@
void DELETE_GLOBAL(int index);

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
/* LOAD_GLOBAL comes in two flavors: the safe version (a port of the
eval
loop that's guaranteed to work) and a fast version, which uses dict
versioning to cache pointers as immediates in the generated IR. */
@@ -30,6 +35,7 @@

LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
};

}
=======================================
--- /trunk/JIT/opcodes/locals.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/locals.cc Wed Jul 28 23:50:04 2010
@@ -16,19 +16,21 @@
namespace py {

OpcodeLocals::OpcodeLocals(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder())
{
}

void
OpcodeLocals::LOAD_CONST(int index)
{
- PyObject *co_consts = fbuilder_->code_object_->co_consts;
- Value *const_ = fbuilder_->builder_.CreateBitCast(
- state_->GetGlobalVariableFor(PyTuple_GET_ITEM(co_consts, index)),
- PyTypeBuilder<PyObject*>::get(fbuilder_->context_));
- state_->IncRef(const_);
- fbuilder_->Push(const_);
+ PyObject *co_consts = this->fbuilder_->code_object()->co_consts;
+ Value *const_ = this->builder_.CreateBitCast(
+ this->state_->GetGlobalVariableFor(PyTuple_GET_ITEM(co_consts,
index)),
+ PyTypeBuilder<PyObject*>::get(this->fbuilder_->context()));
+ this->state_->IncRef(const_);
+ this->fbuilder_->Push(const_);
}

// TODO(collinwinter): we'd like to implement this by simply marking the
load
@@ -40,7 +42,8 @@
{
// Simple check: if DELETE_FAST is never used, function parameters
cannot
// be NULL.
- if (!fbuilder_->uses_delete_fast && index < fbuilder_->GetParamCount())
+ if (!this->fbuilder_->uses_delete_fast() &&
+ index < this->fbuilder_->GetParamCount())
this->LOAD_FAST_fast(index);
else
this->LOAD_FAST_safe(index);
@@ -49,60 +52,61 @@
void
OpcodeLocals::LOAD_FAST_fast(int index)
{
- Value *local = fbuilder_->builder_.CreateLoad(
- fbuilder_->locals_[index], "FAST_loaded");
+ Value *local = this->builder_.CreateLoad(
+ this->fbuilder_->GetLocal(index), "FAST_loaded");
#ifndef NDEBUG
- Value *frame_local_slot = fbuilder_->builder_.CreateGEP(
- fbuilder_->fastlocals_,
- ConstantInt::get(Type::getInt32Ty(fbuilder_->context_),
+ Value *frame_local_slot = this->builder_.CreateGEP(
+ this->fbuilder_->fastlocals(),
+ ConstantInt::get(Type::getInt32Ty(this->fbuilder_->context()),
index));
- Value *frame_local = fbuilder_->builder_.CreateLoad(frame_local_slot);
- Value *sane_locals = fbuilder_->builder_.CreateICmpEQ(frame_local,
local);
- state_->Assert(sane_locals, "alloca locals do not match frame
locals!");
+ Value *frame_local = this->builder_.CreateLoad(frame_local_slot);
+ Value *sane_locals = this->builder_.CreateICmpEQ(frame_local, local);
+ this->state_->Assert(sane_locals, "alloca locals do not match frame
locals!");
#endif /* NDEBUG */
- state_->IncRef(local);
- fbuilder_->Push(local);
+ this->state_->IncRef(local);
+ this->fbuilder_->Push(local);
}

void
OpcodeLocals::LOAD_FAST_safe(int index)
{
BasicBlock *unbound_local =
- state_->CreateBasicBlock("LOAD_FAST_unbound");
+ this->state_->CreateBasicBlock("LOAD_FAST_unbound");
BasicBlock *success =
- state_->CreateBasicBlock("LOAD_FAST_success");
-
- Value *local = fbuilder_->builder_.CreateLoad(
- fbuilder_->locals_[index], "FAST_loaded");
+ this->state_->CreateBasicBlock("LOAD_FAST_success");
+
+ Value *local = this->builder_.CreateLoad(
+ this->fbuilder_->GetLocal(index), "FAST_loaded");
#ifndef NDEBUG
- Value *frame_local_slot = fbuilder_->builder_.CreateGEP(
- fbuilder_->fastlocals_,
- ConstantInt::get(Type::getInt32Ty(fbuilder_->context_),
+ Value *frame_local_slot = this->builder_.CreateGEP(
+ this->fbuilder_->fastlocals(),
+ ConstantInt::get(Type::getInt32Ty(this->fbuilder_->context()),
index));
- Value *frame_local = fbuilder_->builder_.CreateLoad(frame_local_slot);
- Value *sane_locals = fbuilder_->builder_.CreateICmpEQ(frame_local,
local);
- state_->Assert(sane_locals, "alloca locals do not match frame
locals!");
+ Value *frame_local = this->builder_.CreateLoad(frame_local_slot);
+ Value *sane_locals = this->builder_.CreateICmpEQ(frame_local, local);
+ this->state_->Assert(sane_locals,
+ "alloca locals do not match frame locals!");
#endif /* NDEBUG */
- fbuilder_->builder_.CreateCondBr(state_->IsNull(local),
- unbound_local, success);
-
- fbuilder_->builder_.SetInsertPoint(unbound_local);
+ this->builder_.CreateCondBr(this->state_->IsNull(local),
+ unbound_local, success);
+
+ this->builder_.SetInsertPoint(unbound_local);
Function *do_raise =
- state_->GetGlobalFunction<void(PyFrameObject*, int)>(
+ this->state_->GetGlobalFunction<void(PyFrameObject*, int)>(
"_PyEval_RaiseForUnboundLocal");
- state_->CreateCall(do_raise, fbuilder_->frame_,
- state_->GetSigned<int>(index));
- fbuilder_->PropagateException();
-
- fbuilder_->builder_.SetInsertPoint(success);
- state_->IncRef(local);
- fbuilder_->Push(local);
+ this->state_->CreateCall(do_raise, this->fbuilder_->frame(),
+ this->state_->GetSigned<int>(index));
+ this->fbuilder_->PropagateException();
+
+ this->builder_.SetInsertPoint(success);
+ this->state_->IncRef(local);
+ this->fbuilder_->Push(local);
}

void
OpcodeLocals::STORE_FAST(int index)
{
- this->SetLocal(index, fbuilder_->Pop());
+ this->SetLocal(index, this->fbuilder_->Pop());
}

void
@@ -110,55 +114,55 @@
{
// We write changes twice: once to our LLVM-visible locals, and again
to the
// PyFrameObject. This makes vars(), locals() and dir() happy.
- Value *frame_local_slot = fbuilder_->builder_.CreateGEP(
- fbuilder_->fastlocals_,
- ConstantInt::get(Type::getInt32Ty(fbuilder_->context_),
+ Value *frame_local_slot = this->builder_.CreateGEP(
+ this->fbuilder_->fastlocals(),
+ ConstantInt::get(Type::getInt32Ty(this->fbuilder_->context()),
locals_index));
- fbuilder_->llvm_data_->tbaa_locals.MarkInstruction(frame_local_slot);
- fbuilder_->builder_.CreateStore(new_value, frame_local_slot);
-
- Value *llvm_local_slot = fbuilder_->locals_[locals_index];
+
this->fbuilder_->llvm_data()->tbaa_locals.MarkInstruction(frame_local_slot);
+ this->builder_.CreateStore(new_value, frame_local_slot);
+
+ Value *llvm_local_slot = this->fbuilder_->GetLocal(locals_index);
Value *orig_value =
- fbuilder_->builder_.CreateLoad(llvm_local_slot,
- "llvm_local_overwritten");
- fbuilder_->builder_.CreateStore(new_value, llvm_local_slot);
- state_->XDecRef(orig_value);
+ this->builder_.CreateLoad(llvm_local_slot,
+ "llvm_local_overwritten");
+ this->builder_.CreateStore(new_value, llvm_local_slot);
+ this->state_->XDecRef(orig_value);
}

void
OpcodeLocals::DELETE_FAST(int index)
{
BasicBlock *failure =
- state_->CreateBasicBlock("DELETE_FAST_failure");
+ this->state_->CreateBasicBlock("DELETE_FAST_failure");
BasicBlock *success =
- state_->CreateBasicBlock("DELETE_FAST_success");
- Value *local_slot = fbuilder_->locals_[index];
- Value *orig_value = fbuilder_->builder_.CreateLoad(
+ this->state_->CreateBasicBlock("DELETE_FAST_success");
+ Value *local_slot = this->fbuilder_->GetLocal(index);
+ Value *orig_value = this->builder_.CreateLoad(
local_slot, "DELETE_FAST_old_reference");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(orig_value),
- failure, success);
-
- fbuilder_->builder_.SetInsertPoint(failure);
- Function *do_raise = state_->GetGlobalFunction<
+ this->builder_.CreateCondBr(this->state_->IsNull(orig_value),
+ failure, success);
+
+ this->builder_.SetInsertPoint(failure);
+ Function *do_raise = this->state_->GetGlobalFunction<
void(PyFrameObject *, int)>("_PyEval_RaiseForUnboundLocal");
- state_->CreateCall(
- do_raise, fbuilder_->frame_,
+ this->state_->CreateCall(
+ do_raise, this->fbuilder_->frame(),
ConstantInt::getSigned(
- PyTypeBuilder<int>::get(fbuilder_->context_), index));
- fbuilder_->PropagateException();
+ PyTypeBuilder<int>::get(this->fbuilder_->context()), index));
+ this->fbuilder_->PropagateException();

/* We clear both the LLVM-visible locals and the PyFrameObject's
locals to
make vars(), dir() and locals() happy. */
- fbuilder_->builder_.SetInsertPoint(success);
- Value *frame_local_slot = fbuilder_->builder_.CreateGEP(
- fbuilder_->fastlocals_,
- ConstantInt::get(Type::getInt32Ty(fbuilder_->context_),
+ this->builder_.SetInsertPoint(success);
+ Value *frame_local_slot = this->builder_.CreateGEP(
+ this->fbuilder_->fastlocals(),
+ ConstantInt::get(Type::getInt32Ty(this->fbuilder_->context()),
index));
- fbuilder_->builder_.CreateStore(state_->GetNull<PyObject*>(),
- frame_local_slot);
- fbuilder_->builder_.CreateStore(state_->GetNull<PyObject*>(),
- local_slot);
- state_->DecRef(orig_value);
+ this->builder_.CreateStore(this->state_->GetNull<PyObject*>(),
+ frame_local_slot);
+ this->builder_.CreateStore(this->state_->GetNull<PyObject*>(),
+ local_slot);
+ this->state_->DecRef(orig_value);
}

}
=======================================
--- /trunk/JIT/opcodes/locals.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/locals.h Wed Jul 28 23:50:04 2010
@@ -6,6 +6,9 @@
#error This header expects to be included only in C++ source
#endif

+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"
+
namespace llvm {
class Value;
}
@@ -27,6 +30,8 @@
void DELETE_FAST(int index);

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
// A safe version that always works, and a fast version that omits NULL
// checks where we know the local cannot be NULL.
void LOAD_FAST_fast(int index);
@@ -39,6 +44,7 @@

LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
};

}
=======================================
--- /trunk/JIT/opcodes/loop.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/loop.cc Wed Jul 28 23:50:04 2010
@@ -20,76 +20,78 @@
namespace py {

OpcodeLoop::OpcodeLoop(LlvmFunctionBuilder *fbuilder) :
- fbuilder_(fbuilder), state_(fbuilder->state())
+ fbuilder_(fbuilder),
+ state_(fbuilder->state()),
+ builder_(fbuilder->builder())
{
}

void
OpcodeLoop::GET_ITER()
{
- Value *obj = fbuilder_->Pop();
+ Value *obj = this->fbuilder_->Pop();
Function *pyobject_getiter =
- state_->GetGlobalFunction<PyObject*(PyObject*)>(
+ this->state_->GetGlobalFunction<PyObject*(PyObject*)>(
"PyObject_GetIter");
- Value *iter = state_->CreateCall(pyobject_getiter, obj);
- state_->DecRef(obj);
- fbuilder_->PropagateExceptionOnNull(iter);
- fbuilder_->Push(iter);
+ Value *iter = this->state_->CreateCall(pyobject_getiter, obj);
+ this->state_->DecRef(obj);
+ this->fbuilder_->PropagateExceptionOnNull(iter);
+ this->fbuilder_->Push(iter);
}

void
OpcodeLoop::FOR_ITER(llvm::BasicBlock *target,
llvm::BasicBlock *fallthrough)
{
- Value *iter = fbuilder_->Pop();
- Value *iter_tp = fbuilder_->builder_.CreateBitCast(
- fbuilder_->builder_.CreateLoad(
- ObjectTy::ob_type(fbuilder_->builder_, iter)),
- PyTypeBuilder<PyTypeObject *>::get(fbuilder_->context_),
+ Value *iter = this->fbuilder_->Pop();
+ Value *iter_tp = this->builder_.CreateBitCast(
+ this->builder_.CreateLoad(
+ ObjectTy::ob_type(this->builder_, iter)),
+ PyTypeBuilder<PyTypeObject *>::get(this->fbuilder_->context()),
"iter_type");
- Value *iternext = fbuilder_->builder_.CreateLoad(
- TypeTy::tp_iternext(fbuilder_->builder_, iter_tp),
+ Value *iternext = this->builder_.CreateLoad(
+ TypeTy::tp_iternext(this->builder_, iter_tp),
"iternext");
- Value *next = state_->CreateCall(iternext, iter, "next");
- BasicBlock *got_next = state_->CreateBasicBlock("got_next");
- BasicBlock *next_null = state_->CreateBasicBlock("next_null");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(next),
- next_null, got_next);
-
- fbuilder_->builder_.SetInsertPoint(next_null);
- Value *err_occurred = state_->CreateCall(
- state_->GetGlobalFunction<PyObject*()>("PyErr_Occurred"));
- BasicBlock *iter_ended = state_->CreateBasicBlock("iter_ended");
- BasicBlock *exception = state_->CreateBasicBlock("exception");
- fbuilder_->builder_.CreateCondBr(state_->IsNull(err_occurred),
- iter_ended, exception);
-
- fbuilder_->builder_.SetInsertPoint(exception);
- Value *exc_stopiteration = fbuilder_->builder_.CreateLoad(
- state_->GET_GLOBAL_VARIABLE(PyObject*, PyExc_StopIteration));
- Value *was_stopiteration = state_->CreateCall(
- state_->GetGlobalFunction<int(PyObject
*)>("PyErr_ExceptionMatches"),
+ Value *next = this->state_->CreateCall(iternext, iter, "next");
+ BasicBlock *got_next = this->state_->CreateBasicBlock("got_next");
+ BasicBlock *next_null = this->state_->CreateBasicBlock("next_null");
+ this->builder_.CreateCondBr(this->state_->IsNull(next),
+ next_null, got_next);
+
+ this->builder_.SetInsertPoint(next_null);
+ Value *err_occurred = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<PyObject*()>("PyErr_Occurred"));
+ BasicBlock *iter_ended = this->state_->CreateBasicBlock("iter_ended");
+ BasicBlock *exception = this->state_->CreateBasicBlock("exception");
+ this->builder_.CreateCondBr(this->state_->IsNull(err_occurred),
+ iter_ended, exception);
+
+ this->builder_.SetInsertPoint(exception);
+ Value *exc_stopiteration = this->builder_.CreateLoad(
+ this->state_->GET_GLOBAL_VARIABLE(PyObject*, PyExc_StopIteration));
+ Value *was_stopiteration = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<int(PyObject
*)>("PyErr_ExceptionMatches"),
exc_stopiteration);
- BasicBlock *clear_err = state_->CreateBasicBlock("clear_err");
- BasicBlock *propagate = state_->CreateBasicBlock("propagate");
- fbuilder_->builder_.CreateCondBr(state_->IsNonZero(was_stopiteration),
- clear_err, propagate);
-
- fbuilder_->builder_.SetInsertPoint(propagate);
- state_->DecRef(iter);
- fbuilder_->PropagateException();
-
- fbuilder_->builder_.SetInsertPoint(clear_err);
- state_->CreateCall(state_->GetGlobalFunction<void()>("PyErr_Clear"));
- fbuilder_->builder_.CreateBr(iter_ended);
-
- fbuilder_->builder_.SetInsertPoint(iter_ended);
- state_->DecRef(iter);
- fbuilder_->builder_.CreateBr(target);
-
- fbuilder_->builder_.SetInsertPoint(got_next);
- fbuilder_->Push(iter);
- fbuilder_->Push(next);
+ BasicBlock *clear_err = this->state_->CreateBasicBlock("clear_err");
+ BasicBlock *propagate = this->state_->CreateBasicBlock("propagate");
+ this->builder_.CreateCondBr(this->state_->IsNonZero(was_stopiteration),
+ clear_err, propagate);
+
+ this->builder_.SetInsertPoint(propagate);
+ this->state_->DecRef(iter);
+ this->fbuilder_->PropagateException();
+
+ this->builder_.SetInsertPoint(clear_err);
+
this->state_->CreateCall(this->state_->GetGlobalFunction<void()>("PyErr_Clear"));
+ this->builder_.CreateBr(iter_ended);
+
+ this->builder_.SetInsertPoint(iter_ended);
+ this->state_->DecRef(iter);
+ this->builder_.CreateBr(target);
+
+ this->builder_.SetInsertPoint(got_next);
+ this->fbuilder_->Push(iter);
+ this->fbuilder_->Push(next);
}

void
@@ -100,24 +102,27 @@
// Accept code after a continue statement, even though it's never
executed.
// Otherwise, CPython's willingness to insert code after block
// terminators causes problems.
- BasicBlock *dead_code = state_->CreateBasicBlock("dead_code");
- fbuilder_->builder_.CreateStore(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ BasicBlock *dead_code = this->state_->CreateBasicBlock("dead_code");
+ this->builder_.CreateStore(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_CONTINUE),
- fbuilder_->unwind_reason_addr_);
- Value *unwind_target = fbuilder_->AddUnwindTarget(target,
target_opindex);
+ this->fbuilder_->unwind_reason_addr());
+ Value *unwind_target =
+ this->fbuilder_->AddUnwindTarget(target, target_opindex);
// Yes, store the unwind target in the return value slot. This is to
// keep the translation from eval.cc as close as possible; deviation
will
// only introduce bugs. The UNWIND_CONTINUE cases in the unwind block
// (see FillUnwindBlock()) will pick this up and deal with it.
- const Type *long_type = PyTypeBuilder<long>::get(fbuilder_->context_);
- Value *pytarget = state_->CreateCall(
- state_->GetGlobalFunction<PyObject *(long)>("PyInt_FromLong"),
- fbuilder_->builder_.CreateZExt(unwind_target, long_type));
- fbuilder_->builder_.CreateStore(pytarget, fbuilder_->retval_addr_);
- fbuilder_->builder_.CreateBr(fbuilder_->unwind_block_);
-
- fbuilder_->builder_.SetInsertPoint(dead_code);
+ const Type *long_type =
+ PyTypeBuilder<long>::get(this->fbuilder_->context());
+ Value *pytarget = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<PyObject *(long)>(
+ "PyInt_FromLong"),
+ this->builder_.CreateZExt(unwind_target, long_type));
+ this->builder_.CreateStore(pytarget, this->fbuilder_->retval_addr());
+ this->builder_.CreateBr(this->fbuilder_->unwind_block());
+
+ this->builder_.SetInsertPoint(dead_code);
}

void
@@ -126,14 +131,14 @@
// Accept code after a break statement, even though it's never
executed.
// Otherwise, CPython's willingness to insert code after block
// terminators causes problems.
- BasicBlock *dead_code = state_->CreateBasicBlock("dead_code");
- fbuilder_->builder_.CreateStore(
- ConstantInt::get(Type::getInt8Ty(fbuilder_->context_),
+ BasicBlock *dead_code = this->state_->CreateBasicBlock("dead_code");
+ this->builder_.CreateStore(
+ ConstantInt::get(Type::getInt8Ty(this->fbuilder_->context()),
UNWIND_BREAK),
- fbuilder_->unwind_reason_addr_);
- fbuilder_->builder_.CreateBr(fbuilder_->unwind_block_);
-
- fbuilder_->builder_.SetInsertPoint(dead_code);
+ this->fbuilder_->unwind_reason_addr());
+ this->builder_.CreateBr(this->fbuilder_->unwind_block());
+
+ this->builder_.SetInsertPoint(dead_code);
}

}
=======================================
--- /trunk/JIT/opcodes/loop.h Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/loop.h Wed Jul 28 23:50:04 2010
@@ -6,6 +6,9 @@
#error This header expects to be included only in C++ source
#endif

+#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetFolder.h"
+
namespace llvm {
class BasicBlock;
}
@@ -33,8 +36,11 @@
void BREAK_LOOP();

private:
+ typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
+
LlvmFunctionBuilder *fbuilder_;
LlvmFunctionState *state_;
+ BuilderT &builder_;
};

}
=======================================
--- /trunk/JIT/opcodes/name.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/name.cc Wed Jul 28 23:50:04 2010
@@ -23,37 +23,40 @@
void
OpcodeName::LOAD_NAME(int index)
{
- Value *result = state_->CreateCall(
- state_->GetGlobalFunction<PyObject *(PyFrameObject*, int)>(
+ Value *result = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<PyObject *(PyFrameObject*, int)>(
"_PyEval_LoadName"),
- fbuilder_->frame_,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
index));
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->fbuilder_->frame(),
+ ConstantInt::get(
+ PyTypeBuilder<int>::get(this->fbuilder_->context()), index));
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

void
OpcodeName::STORE_NAME(int index)
{
- Value *to_store = fbuilder_->Pop();
- Value *err = state_->CreateCall(
- state_->GetGlobalFunction<int(PyFrameObject*, int, PyObject*)>(
+ Value *to_store = this->fbuilder_->Pop();
+ Value *err = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<int(PyFrameObject*, int,
PyObject*)>(
"_PyEval_StoreName"),
- fbuilder_->frame_,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
index),
+ this->fbuilder_->frame(),
+ ConstantInt::get(
+ PyTypeBuilder<int>::get(this->fbuilder_->context()), index),
to_store);
- fbuilder_->PropagateExceptionOnNonZero(err);
+ this->fbuilder_->PropagateExceptionOnNonZero(err);
}

void
OpcodeName::DELETE_NAME(int index)
{
- Value *err = state_->CreateCall(
- state_->GetGlobalFunction<int(PyFrameObject*, int)>(
+ Value *err = this->state_->CreateCall(
+ this->state_->GetGlobalFunction<int(PyFrameObject*, int)>(
"_PyEval_DeleteName"),
- fbuilder_->frame_,
- ConstantInt::get(PyTypeBuilder<int>::get(fbuilder_->context_),
index));
- fbuilder_->PropagateExceptionOnNonZero(err);
+ this->fbuilder_->frame(),
+ ConstantInt::get(
+ PyTypeBuilder<int>::get(this->fbuilder_->context()), index));
+ this->fbuilder_->PropagateExceptionOnNonZero(err);
}

}
=======================================
--- /trunk/JIT/opcodes/slice.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/slice.cc Wed Jul 28 23:50:04 2010
@@ -24,179 +24,179 @@
OpcodeSlice::AssignSlice(Value *seq, Value *start, Value *stop,
Value *source)
{
- Function *assign_slice = state_->GetGlobalFunction<
+ Function *assign_slice = this->state_->GetGlobalFunction<
int (PyObject *, PyObject *, PyObject *, PyObject *)>(
"_PyEval_AssignSlice");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
assign_slice, seq, start, stop, source, "ApplySlice_result");
- state_->XDecRef(source);
- state_->XDecRef(stop);
- state_->XDecRef(start);
- state_->DecRef(seq);
- fbuilder_->PropagateExceptionOnNonZero(result);
+ this->state_->XDecRef(source);
+ this->state_->XDecRef(stop);
+ this->state_->XDecRef(start);
+ this->state_->DecRef(seq);
+ this->fbuilder_->PropagateExceptionOnNonZero(result);
}

void
OpcodeSlice::ApplySlice(Value *seq, Value *start, Value *stop)
{
- Function *build_slice = state_->GetGlobalFunction<
+ Function *build_slice = this->state_->GetGlobalFunction<
PyObject *(PyObject *, PyObject *, PyObject
*)>("_PyEval_ApplySlice");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
build_slice, seq, start, stop, "ApplySlice_result");
- state_->XDecRef(stop);
- state_->XDecRef(start);
- state_->DecRef(seq);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->state_->XDecRef(stop);
+ this->state_->XDecRef(start);
+ this->state_->DecRef(seq);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

void
OpcodeSlice::SLICE_BOTH()
{
- Value *stop = fbuilder_->Pop();
- Value *start = fbuilder_->Pop();
- Value *seq = fbuilder_->Pop();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->fbuilder_->Pop();
+ Value *seq = this->fbuilder_->Pop();
this->ApplySlice(seq, start, stop);
}

void
OpcodeSlice::SLICE_LEFT()
{
- Value *stop = state_->GetNull<PyObject*>();
- Value *start = fbuilder_->Pop();
- Value *seq = fbuilder_->Pop();
+ Value *stop = this->state_->GetNull<PyObject*>();
+ Value *start = this->fbuilder_->Pop();
+ Value *seq = this->fbuilder_->Pop();
this->ApplySlice(seq, start, stop);
}

void
OpcodeSlice::SLICE_RIGHT()
{
- Value *stop = fbuilder_->Pop();
- Value *start = state_->GetNull<PyObject*>();
- Value *seq = fbuilder_->Pop();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->state_->GetNull<PyObject*>();
+ Value *seq = this->fbuilder_->Pop();
this->ApplySlice(seq, start, stop);
}

void
OpcodeSlice::SLICE_NONE()
{
- Value *stop = state_->GetNull<PyObject*>();
- Value *start = state_->GetNull<PyObject*>();
- Value *seq = fbuilder_->Pop();
+ Value *stop = this->state_->GetNull<PyObject*>();
+ Value *start = this->state_->GetNull<PyObject*>();
+ Value *seq = this->fbuilder_->Pop();
this->ApplySlice(seq, start, stop);
}

void
OpcodeSlice::STORE_SLICE_BOTH()
{
- Value *stop = fbuilder_->Pop();
- Value *start = fbuilder_->Pop();
- Value *seq = fbuilder_->Pop();
- Value *source = fbuilder_->Pop();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->fbuilder_->Pop();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->fbuilder_->Pop();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::STORE_SLICE_LEFT()
{
- Value *stop = state_->GetNull<PyObject*>();
- Value *start = fbuilder_->Pop();
- Value *seq = fbuilder_->Pop();
- Value *source = fbuilder_->Pop();
+ Value *stop = this->state_->GetNull<PyObject*>();
+ Value *start = this->fbuilder_->Pop();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->fbuilder_->Pop();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::STORE_SLICE_RIGHT()
{
- Value *stop = fbuilder_->Pop();
- Value *start = state_->GetNull<PyObject*>();
- Value *seq = fbuilder_->Pop();
- Value *source = fbuilder_->Pop();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->state_->GetNull<PyObject*>();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->fbuilder_->Pop();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::STORE_SLICE_NONE()
{
- Value *stop = state_->GetNull<PyObject*>();
- Value *start = state_->GetNull<PyObject*>();
- Value *seq = fbuilder_->Pop();
- Value *source = fbuilder_->Pop();
+ Value *stop = this->state_->GetNull<PyObject*>();
+ Value *start = this->state_->GetNull<PyObject*>();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->fbuilder_->Pop();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::DELETE_SLICE_BOTH()
{
- Value *stop = fbuilder_->Pop();
- Value *start = fbuilder_->Pop();
- Value *seq = fbuilder_->Pop();
- Value *source = state_->GetNull<PyObject*>();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->fbuilder_->Pop();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->state_->GetNull<PyObject*>();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::DELETE_SLICE_LEFT()
{
- Value *stop = state_->GetNull<PyObject*>();
- Value *start = fbuilder_->Pop();
- Value *seq = fbuilder_->Pop();
- Value *source = state_->GetNull<PyObject*>();
+ Value *stop = this->state_->GetNull<PyObject*>();
+ Value *start = this->fbuilder_->Pop();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->state_->GetNull<PyObject*>();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::DELETE_SLICE_RIGHT()
{
- Value *stop = fbuilder_->Pop();
- Value *start = state_->GetNull<PyObject*>();
- Value *seq = fbuilder_->Pop();
- Value *source = state_->GetNull<PyObject*>();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->state_->GetNull<PyObject*>();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->state_->GetNull<PyObject*>();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::DELETE_SLICE_NONE()
{
- Value *stop = state_->GetNull<PyObject*>();
- Value *start = state_->GetNull<PyObject*>();
- Value *seq = fbuilder_->Pop();
- Value *source = state_->GetNull<PyObject*>();
+ Value *stop = this->state_->GetNull<PyObject*>();
+ Value *start = this->state_->GetNull<PyObject*>();
+ Value *seq = this->fbuilder_->Pop();
+ Value *source = this->state_->GetNull<PyObject*>();
this->AssignSlice(seq, start, stop, source);
}

void
OpcodeSlice::BUILD_SLICE_TWO()
{
- Value *step = state_->GetNull<PyObject*>();
- Value *stop = fbuilder_->Pop();
- Value *start = fbuilder_->Pop();
- Function *build_slice = state_->GetGlobalFunction<
+ Value *step = this->state_->GetNull<PyObject*>();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->fbuilder_->Pop();
+ Function *build_slice = this->state_->GetGlobalFunction<
PyObject *(PyObject *, PyObject *, PyObject *)>("PySlice_New");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
build_slice, start, stop, step, "BUILD_SLICE_result");
- state_->DecRef(start);
- state_->DecRef(stop);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->state_->DecRef(start);
+ this->state_->DecRef(stop);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

void
OpcodeSlice::BUILD_SLICE_THREE()
{
- Value *step = fbuilder_->Pop();
- Value *stop = fbuilder_->Pop();
- Value *start = fbuilder_->Pop();
- Function *build_slice = state_->GetGlobalFunction<
+ Value *step = this->fbuilder_->Pop();
+ Value *stop = this->fbuilder_->Pop();
+ Value *start = this->fbuilder_->Pop();
+ Function *build_slice = this->state_->GetGlobalFunction<
PyObject *(PyObject *, PyObject *, PyObject *)>("PySlice_New");
- Value *result = state_->CreateCall(
+ Value *result = this->state_->CreateCall(
build_slice, start, stop, step, "BUILD_SLICE_result");
- state_->DecRef(start);
- state_->DecRef(stop);
- state_->DecRef(step);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ this->state_->DecRef(start);
+ this->state_->DecRef(stop);
+ this->state_->DecRef(step);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

}
=======================================
--- /trunk/JIT/opcodes/stack.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/stack.cc Wed Jul 28 23:50:04 2010
@@ -23,79 +23,79 @@
void
OpcodeStack::POP_TOP()
{
- state_->DecRef(fbuilder_->Pop());
+ this->state_->DecRef(this->fbuilder_->Pop());
}

void
OpcodeStack::DUP_TOP()
{
- Value *first = fbuilder_->Pop();
- state_->IncRef(first);
- fbuilder_->Push(first);
- fbuilder_->Push(first);
+ Value *first = this->fbuilder_->Pop();
+ this->state_->IncRef(first);
+ this->fbuilder_->Push(first);
+ this->fbuilder_->Push(first);
}

void
OpcodeStack::DUP_TOP_TWO()
{
- Value *first = fbuilder_->Pop();
- Value *second = fbuilder_->Pop();
- state_->IncRef(first);
- state_->IncRef(second);
- fbuilder_->Push(second);
- fbuilder_->Push(first);
- fbuilder_->Push(second);
- fbuilder_->Push(first);
+ Value *first = this->fbuilder_->Pop();
+ Value *second = this->fbuilder_->Pop();
+ this->state_->IncRef(first);
+ this->state_->IncRef(second);
+ this->fbuilder_->Push(second);
+ this->fbuilder_->Push(first);
+ this->fbuilder_->Push(second);
+ this->fbuilder_->Push(first);
}

void
OpcodeStack::DUP_TOP_THREE()
{
- Value *first = fbuilder_->Pop();
- Value *second = fbuilder_->Pop();
- Value *third = fbuilder_->Pop();
- state_->IncRef(first);
- state_->IncRef(second);
- state_->IncRef(third);
- fbuilder_->Push(third);
- fbuilder_->Push(second);
- fbuilder_->Push(first);
- fbuilder_->Push(third);
- fbuilder_->Push(second);
- fbuilder_->Push(first);
+ Value *first = this->fbuilder_->Pop();
+ Value *second = this->fbuilder_->Pop();
+ Value *third = this->fbuilder_->Pop();
+ this->state_->IncRef(first);
+ this->state_->IncRef(second);
+ this->state_->IncRef(third);
+ this->fbuilder_->Push(third);
+ this->fbuilder_->Push(second);
+ this->fbuilder_->Push(first);
+ this->fbuilder_->Push(third);
+ this->fbuilder_->Push(second);
+ this->fbuilder_->Push(first);
}

void
OpcodeStack::ROT_TWO()
{
- Value *first = fbuilder_->Pop();
- Value *second = fbuilder_->Pop();
- fbuilder_->Push(first);
- fbuilder_->Push(second);
+ Value *first = this->fbuilder_->Pop();
+ Value *second = this->fbuilder_->Pop();
+ this->fbuilder_->Push(first);
+ this->fbuilder_->Push(second);
}

void
OpcodeStack::ROT_THREE()
{
- Value *first = fbuilder_->Pop();
- Value *second = fbuilder_->Pop();
- Value *third = fbuilder_->Pop();
- fbuilder_->Push(first);
- fbuilder_->Push(third);
- fbuilder_->Push(second);
+ Value *first = this->fbuilder_->Pop();
+ Value *second = this->fbuilder_->Pop();
+ Value *third = this->fbuilder_->Pop();
+ this->fbuilder_->Push(first);
+ this->fbuilder_->Push(third);
+ this->fbuilder_->Push(second);
}

void
OpcodeStack::ROT_FOUR()
{
- Value *first = fbuilder_->Pop();
- Value *second = fbuilder_->Pop();
- Value *third = fbuilder_->Pop();
- Value *fourth = fbuilder_->Pop();
- fbuilder_->Push(first);
- fbuilder_->Push(fourth);
- fbuilder_->Push(third);
- fbuilder_->Push(second);
+ Value *first = this->fbuilder_->Pop();
+ Value *second = this->fbuilder_->Pop();
+ Value *third = this->fbuilder_->Pop();
+ Value *fourth = this->fbuilder_->Pop();
+ this->fbuilder_->Push(first);
+ this->fbuilder_->Push(fourth);
+ this->fbuilder_->Push(third);
+ this->fbuilder_->Push(second);
}

}
=======================================
--- /trunk/JIT/opcodes/unaryops.cc Mon May 24 13:49:39 2010
+++ /trunk/JIT/opcodes/unaryops.cc Wed Jul 28 23:50:04 2010
@@ -22,12 +22,13 @@
void
OpcodeUnaryops::GenericUnaryOp(const char *apifunc)
{
- Value *value = fbuilder_->Pop();
- Function *op =
state_->GetGlobalFunction<PyObject*(PyObject*)>(apifunc);
- Value *result = state_->CreateCall(op, value, "unaryop_result");
- state_->DecRef(value);
- fbuilder_->PropagateExceptionOnNull(result);
- fbuilder_->Push(result);
+ Value *value = this->fbuilder_->Pop();
+ Function *op =
+ this->state_->GetGlobalFunction<PyObject*(PyObject*)>(apifunc);
+ Value *result = this->state_->CreateCall(op, value, "unaryop_result");
+ this->state_->DecRef(value);
+ this->fbuilder_->PropagateExceptionOnNull(result);
+ this->fbuilder_->Push(result);
}

#define UNARYOP_METH(NAME, APIFUNC) \
@@ -47,14 +48,14 @@
void
OpcodeUnaryops::UNARY_NOT()
{
- Value *value = fbuilder_->Pop();
- Value *retval = fbuilder_->builder_.CreateSelect(
- fbuilder_->IsPythonTrue(value),
- state_->GetGlobalVariableFor((PyObject*)&_Py_ZeroStruct),
- state_->GetGlobalVariableFor((PyObject*)&_Py_TrueStruct),
+ Value *value = this->fbuilder_->Pop();
+ Value *retval = this->fbuilder_->builder().CreateSelect(
+ this->fbuilder_->IsPythonTrue(value),
+ this->state_->GetGlobalVariableFor((PyObject*)&_Py_ZeroStruct),
+ this->state_->GetGlobalVariableFor((PyObject*)&_Py_TrueStruct),
"UNARY_NOT_result");
- state_->IncRef(retval);
- fbuilder_->Push(retval);
+ this->state_->IncRef(retval);
+ this->fbuilder_->Push(retval);
}

}

Reply all
Reply to author
Forward
0 new messages