[unladen-swallow] r943 committed - Remove FunctionRecord objects in favor of the existing PyMethodDef glo...

0 views
Skip to first unread message

unladen...@googlecode.com

unread,
Dec 18, 2009, 1:56:23 PM12/18/09
to unladen...@googlegroups.com
Revision: 943
Author: reid.kleckner
Date: Fri Dec 18 10:55:28 2009
Log: Remove FunctionRecord objects in favor of the existing PyMethodDef
globals.
http://code.google.com/p/unladen-swallow/source/detail?r=943

Modified:
/trunk/Python/llvm_fbuilder.cc
/trunk/Util/RuntimeFeedback.cc
/trunk/Util/RuntimeFeedback.h

=======================================
--- /trunk/Python/llvm_fbuilder.cc Wed Dec 16 13:34:06 2009
+++ /trunk/Python/llvm_fbuilder.cc Fri Dec 18 10:55:28 2009
@@ -2014,7 +2014,7 @@
}

// Only optimize monomorphic callsites.
- llvm::SmallVector<FunctionRecord*, 3> fdo_data;
+ llvm::SmallVector<PyMethodDef*, 3> fdo_data;
feedback->GetSeenFuncsInto(fdo_data);
if (fdo_data.size() != 1) {
#ifdef Py_WITH_INSTRUMENTATION
@@ -2027,13 +2027,13 @@
return;
}

- FunctionRecord *func_record = fdo_data[0];
+ PyMethodDef *func_record = fdo_data[0];

// Only optimize calls to C functions with a known number of
parameters,
// where the number of arguments we have is in that range.
- int flags = func_record->flags;
- int min_arity = func_record->min_arity;
- int max_arity = func_record->max_arity;
+ int flags = func_record->ml_flags;
+ int min_arity = func_record->ml_min_arity;
+ int max_arity = func_record->ml_max_arity;
int num_args = oparg & 0xff;
if (!(flags & METH_ARG_RANGE &&
min_arity <= num_args && num_args <= max_arity)) {
@@ -2043,7 +2043,7 @@
}
assert(num_args <= PY_MAX_ARITY);

- PyCFunction cfunc_ptr = func_record->func;
+ PyCFunction cfunc_ptr = func_record->ml_meth;

// Expose the C function pointer to LLVM. This is what will actually
get
// called.
@@ -2051,7 +2051,7 @@
this->llvm_data_->constant_mirror().GetGlobalForCFunction(
cfunc_ptr,
max_arity,
- func_record->name);
+ func_record->ml_name);

BasicBlock *not_profiling =
this->CreateBasicBlock("CALL_FUNCTION_not_profiling");
=======================================
--- /trunk/Util/RuntimeFeedback.cc Fri Nov 13 17:46:58 2009
+++ /trunk/Util/RuntimeFeedback.cc Fri Dec 18 10:55:28 2009
@@ -12,36 +12,12 @@
using llvm::PointerLikeTypeTraits;
using llvm::SmallPtrSet;
using llvm::SmallVector;
-
-
-FunctionRecord::FunctionRecord(const PyObject *func)
-{
- this->func = PyCFunction_GET_FUNCTION(func);
- this->flags = PyCFunction_GET_FLAGS(func);
- this->name = PyCFunction_GET_METHODDEF(func)->ml_name;
- this->min_arity = -1;
- this->max_arity = -1;
-
- if (this->flags & METH_ARG_RANGE) {
- this->min_arity = PyCFunction_GET_MIN_ARITY(func);
- this->max_arity = PyCFunction_GET_MAX_ARITY(func);
- }
-}
-
-FunctionRecord::FunctionRecord(const FunctionRecord &record)
-{
- this->func = record.func;
- this->flags = record.flags;
- this->name = record.name;
- this->min_arity = record.min_arity;
- this->max_arity = record.max_arity;
-}


static bool
-is_duplicate_method(PyObject *a, FunctionRecord *b)
-{
- return PyCFunction_Check(a) && PyCFunction_GET_FUNCTION(a) == b->func;
+is_duplicate_method(PyObject *a, PyMethodDef *b)
+{
+ return PyCFunction_Check(a) && PyCFunction_GET_FUNCTION(a) ==
b->ml_meth;
}

PyLimitedFeedback::PyLimitedFeedback()
@@ -56,13 +32,6 @@
Py_XINCREF(value);
this->data_[i] = src.data_[i];
}
- else if (src.InFuncMode() && src.data_[i].getPointer() != NULL) {
- FunctionRecord *src_record =
- (FunctionRecord *)src.data_[i].getPointer();
- FunctionRecord *new_record = new FunctionRecord(*src_record);
- this->data_[i].setInt(src.data_[i].getInt());
- this->data_[i].setPointer(new_record);
- }
else {
this->data_[i] = src.data_[i];
}
@@ -141,13 +110,10 @@
PyLimitedFeedback::Clear()
{
bool object_mode = this->InObjectMode();
- bool func_mode = this->InFuncMode();

for (int i = 0; i < PyLimitedFeedback::NUM_POINTERS; ++i) {
if (object_mode)
Py_XDECREF((PyObject *)this->data_[i].getPointer());
- else if (func_mode)
- delete (FunctionRecord *)this->data_[i].getPointer();
this->data_[i].setPointer(NULL);
this->data_[i].setInt(0);
}
@@ -211,10 +177,9 @@
return;

for (int i = 0; i < PyLimitedFeedback::NUM_POINTERS; ++i) {
- FunctionRecord *value = (FunctionRecord
*)this->data_[i].getPointer();
+ PyMethodDef *value = (PyMethodDef *)this->data_[i].getPointer();
if (value == NULL) {
- FunctionRecord *record = new FunctionRecord(obj);
- this->data_[i].setPointer((void *)record);
+ this->data_[i].setPointer((void
*)PyCFunction_GET_METHODDEF(obj));
return;
}
// Deal with the fact that "for x in y: l.append(x)" results in
@@ -228,7 +193,7 @@

void
PyLimitedFeedback::GetSeenFuncsInto(
- SmallVector<FunctionRecord*, 3> &result) const
+ SmallVector<PyMethodDef*, 3> &result) const
{
assert(this->InFuncMode());

@@ -238,7 +203,7 @@
result.push_back(NULL);
}
for (int i = 0; i < PyLimitedFeedback::NUM_POINTERS; ++i) {
- FunctionRecord *value = (FunctionRecord
*)this->data_[i].getPointer();
+ PyMethodDef *value = (PyMethodDef *)this->data_[i].getPointer();
if (value == NULL)
return;
result.push_back(value);
@@ -263,9 +228,6 @@
if (src.usage_ == ObjectMode) {
Py_XINCREF((PyObject *)obj);
}
- else if (src.usage_ == FuncMode) {
- obj = new FunctionRecord(*static_cast<const
FunctionRecord*>(*it));
- }
this->data_.insert(obj);
}
}
@@ -299,9 +261,6 @@
if (this->usage_ == ObjectMode) {
Py_XDECREF((PyObject *)*it);
}
- else if (this->usage_ == FuncMode) {
- delete (FunctionRecord *)*it;
- }
}
this->data_.clear();
for (unsigned i = 0; i < llvm::array_lengthof(this->counters_); ++i)
@@ -355,25 +314,24 @@
// multiple method objects for l.append.
for (ObjSet::const_iterator it = this->data_.begin(),
end = this->data_.end(); it != end; ++it) {
- if (is_duplicate_method(obj, (FunctionRecord *)*it))
+ if (is_duplicate_method(obj, (PyMethodDef *)*it))
return;
}

- FunctionRecord *record = new FunctionRecord(obj);
- this->data_.insert((void *)record);
+ this->data_.insert((void *)PyCFunction_GET_METHODDEF(obj));
}
}

void
PyFullFeedback::GetSeenFuncsInto(
- SmallVector<FunctionRecord*, /*in-object elems=*/3> &result) const
+ SmallVector<PyMethodDef*, /*in-object elems=*/3> &result) const
{
assert(this->InFuncMode());

result.clear();
for (ObjSet::const_iterator it = this->data_.begin(),
end = this->data_.end(); it != end; ++it) {
- result.push_back((FunctionRecord *)*it);
+ result.push_back((PyMethodDef *)*it);
}
}

=======================================
--- /trunk/Util/RuntimeFeedback.h Fri Nov 13 17:46:58 2009
+++ /trunk/Util/RuntimeFeedback.h Fri Dec 18 10:55:28 2009
@@ -39,22 +39,6 @@
// PY_FDO_JUMP_FALSE - PY_FDO_JUMP_NON_BOOLEAN).
enum { PY_FDO_JUMP_TRUE = 0, PY_FDO_JUMP_FALSE, PY_FDO_JUMP_NON_BOOLEAN };

-// We copy data out of PyCFunctionObjects, rather than INCREFing them like
we do
-// objects. We do this to avoid inflating the refcounts for bound methods,
which
-// may result in delaying or preventing the deallocation of the bound
invocant;
-// this is especially problematic for files.
-class FunctionRecord {
-public:
- FunctionRecord(const PyObject *func);
- FunctionRecord(const FunctionRecord &record);
-
- PyCFunction func;
- int flags;
- short min_arity;
- short max_arity;
- std::string name;
-};
-
class PyLimitedFeedback {
public:
PyLimitedFeedback();
@@ -71,8 +55,8 @@

// Record that a given function was called.
void AddFuncSeen(PyObject *obj);
- // Clears result and fills it with the set of observed FunctionRecords.
- void GetSeenFuncsInto(llvm::SmallVector<FunctionRecord*, 3> &result)
const;
+ // Clears result and fills it with the set of observed PyMethodDefs.
+ void GetSeenFuncsInto(llvm::SmallVector<PyMethodDef*, 3> &result)
const;
bool FuncsOverflowed() const {
return GetFlagBit(SAW_MORE_THAN_THREE_OBJS_BIT);
}
@@ -117,7 +101,7 @@
//
// The pointers in this array start out NULL and are filled from
// the lowest index as we see new objects. We store either PyObject *s
(when
- // operating in object mode) or FunctionRecord *s (in function mode).
+ // operating in object mode) or PyMethodDef *s (in function mode).
llvm::PointerIntPair<void*, /*bits used from bottom of pointer=*/2>
data_[NUM_POINTERS];

@@ -150,7 +134,7 @@
// Record that a given function was called.
void AddFuncSeen(PyObject *obj);
// Clears result and fills it with the set of seen function objects.
- void GetSeenFuncsInto(llvm::SmallVector<FunctionRecord*, 3> &result)
const;
+ void GetSeenFuncsInto(llvm::SmallVector<PyMethodDef*, 3> &result)
const;
bool FuncsOverflowed() const { return false; }

void IncCounter(unsigned counter_id);
@@ -164,7 +148,7 @@

private:
// Assume three pointers in the set to start with. We store either
- // PyObject *s (when in object mode) or FunctionRecord *s (when in
function
+ // PyObject *s (when in object mode) or PyMethodDef *s (when in
function
// mode).
typedef llvm::SmallPtrSet<void*, 3> ObjSet;

Reply all
Reply to author
Forward
0 new messages