Commit aada26f8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #562 from kmod/stringref

Convert runtime functions to take llvm::StringRef
parents 925c13d5 7a45efac
...@@ -412,6 +412,8 @@ float_str(PyFloatObject *v) ...@@ -412,6 +412,8 @@ float_str(PyFloatObject *v)
* coercion to double. So this part is painful too. * coercion to double. So this part is painful too.
*/ */
// Pyston change: don't need this for now
#if 0
static PyObject* static PyObject*
float_richcompare(PyObject *v, PyObject *w, int op) float_richcompare(PyObject *v, PyObject *w, int op)
{ {
...@@ -625,6 +627,7 @@ float_richcompare(PyObject *v, PyObject *w, int op) ...@@ -625,6 +627,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
Py_INCREF(Py_NotImplemented); Py_INCREF(Py_NotImplemented);
return Py_NotImplemented; return Py_NotImplemented;
} }
#endif
static long static long
float_hash(PyFloatObject *v) float_hash(PyFloatObject *v)
...@@ -687,6 +690,8 @@ float_div(PyObject *v, PyObject *w) ...@@ -687,6 +690,8 @@ float_div(PyObject *v, PyObject *w)
return PyFloat_FromDouble(a); return PyFloat_FromDouble(a);
} }
// Pyston change: don't need this for now
#if 0
static PyObject * static PyObject *
float_classic_div(PyObject *v, PyObject *w) float_classic_div(PyObject *v, PyObject *w)
{ {
...@@ -708,6 +713,7 @@ float_classic_div(PyObject *v, PyObject *w) ...@@ -708,6 +713,7 @@ float_classic_div(PyObject *v, PyObject *w)
PyFPE_END_PROTECT(a) PyFPE_END_PROTECT(a)
return PyFloat_FromDouble(a); return PyFloat_FromDouble(a);
} }
#endif
static PyObject * static PyObject *
float_rem(PyObject *v, PyObject *w) float_rem(PyObject *v, PyObject *w)
...@@ -2081,6 +2087,8 @@ PyDoc_STRVAR(float_doc, ...@@ -2081,6 +2087,8 @@ PyDoc_STRVAR(float_doc,
Convert a string or number to a floating point number, if possible."); Convert a string or number to a floating point number, if possible.");
// Pyston change: don't need this for now
#if 0
static PyNumberMethods float_as_number = { static PyNumberMethods float_as_number = {
float_add, /*nb_add*/ float_add, /*nb_add*/
float_sub, /*nb_subtract*/ float_sub, /*nb_subtract*/
...@@ -2121,6 +2129,7 @@ static PyNumberMethods float_as_number = { ...@@ -2121,6 +2129,7 @@ static PyNumberMethods float_as_number = {
0, /* nb_inplace_floor_divide */ 0, /* nb_inplace_floor_divide */
0, /* nb_inplace_true_divide */ 0, /* nb_inplace_true_divide */
}; };
#endif
// pyston change: don't need this // pyston change: don't need this
#if 0 #if 0
......
...@@ -959,15 +959,15 @@ Value ASTInterpreter::visit_print(AST_Print* node) { ...@@ -959,15 +959,15 @@ Value ASTInterpreter::visit_print(AST_Print* node) {
// begin code for handling of softspace // begin code for handling of softspace
bool new_softspace = (i < nvals - 1) || (!node->nl); bool new_softspace = (i < nvals - 1) || (!node->nl);
if (softspace(dest, new_softspace)) { if (softspace(dest, new_softspace)) {
callattrInternal(dest, &write_str, CLASS_OR_INST, 0, ArgPassSpec(1), boxString(space_str), 0, 0, 0, 0); callattrInternal(dest, write_str, CLASS_OR_INST, 0, ArgPassSpec(1), boxString(space_str), 0, 0, 0, 0);
} }
Box* str_or_unicode_var = (var->cls == unicode_cls) ? var : str(var); Box* str_or_unicode_var = (var->cls == unicode_cls) ? var : str(var);
callattrInternal(dest, &write_str, CLASS_OR_INST, 0, ArgPassSpec(1), str_or_unicode_var, 0, 0, 0, 0); callattrInternal(dest, write_str, CLASS_OR_INST, 0, ArgPassSpec(1), str_or_unicode_var, 0, 0, 0, 0);
} }
if (node->nl) { if (node->nl) {
callattrInternal(dest, &write_str, CLASS_OR_INST, 0, ArgPassSpec(1), boxString(newline_str), 0, 0, 0, 0); callattrInternal(dest, write_str, CLASS_OR_INST, 0, ArgPassSpec(1), boxString(newline_str), 0, 0, 0, 0);
if (nvals == 0) { if (nvals == 0) {
softspace(dest, false); softspace(dest, false);
} }
......
...@@ -480,18 +480,18 @@ public: ...@@ -480,18 +480,18 @@ public:
BoxedDict* getDict(); BoxedDict* getDict();
void setattr(const std::string& attr, Box* val, SetattrRewriteArgs* rewrite_args); void setattr(llvm::StringRef attr, Box* val, SetattrRewriteArgs* rewrite_args);
void giveAttr(const std::string& attr, Box* val) { void giveAttr(llvm::StringRef attr, Box* val) {
assert(!this->hasattr(attr)); assert(!this->hasattr(attr));
this->setattr(attr, val, NULL); this->setattr(attr, val, NULL);
} }
// getattr() does the equivalent of PyDict_GetItem(obj->dict, attr): it looks up the attribute's value on the // getattr() does the equivalent of PyDict_GetItem(obj->dict, attr): it looks up the attribute's value on the
// object's attribute storage. it doesn't look at other objects or do any descriptor logic. // object's attribute storage. it doesn't look at other objects or do any descriptor logic.
Box* getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args); Box* getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args);
Box* getattr(const std::string& attr) { return getattr(attr, NULL); } Box* getattr(llvm::StringRef attr) { return getattr(attr, NULL); }
bool hasattr(const std::string& attr) { return getattr(attr) != NULL; } bool hasattr(llvm::StringRef attr) { return getattr(attr) != NULL; }
void delattr(const std::string& attr, DelattrRewriteArgs* rewrite_args); void delattr(llvm::StringRef attr, DelattrRewriteArgs* rewrite_args);
// Only valid for hc-backed instances: // Only valid for hc-backed instances:
Box* getAttrWrapper(); Box* getAttrWrapper();
......
This diff is collapsed.
...@@ -53,7 +53,7 @@ extern "C" void my_assert(bool b); ...@@ -53,7 +53,7 @@ extern "C" void my_assert(bool b);
extern "C" Box* getattr(Box* obj, const char* attr); extern "C" Box* getattr(Box* obj, const char* attr);
extern "C" void setattr(Box* obj, const char* attr, Box* attr_val); extern "C" void setattr(Box* obj, const char* attr, Box* attr_val);
extern "C" void delattr(Box* obj, const char* attr); extern "C" void delattr(Box* obj, const char* attr);
extern "C" void delattrGeneric(Box* obj, const std::string& attr, DelattrRewriteArgs* rewrite_args); extern "C" void delattrGeneric(Box* obj, llvm::StringRef attr, DelattrRewriteArgs* rewrite_args);
extern "C" bool nonzero(Box* obj); extern "C" bool nonzero(Box* obj);
extern "C" Box* runtimeCall(Box*, ArgPassSpec, Box*, Box*, Box*, Box**, const std::vector<const std::string*>*); extern "C" Box* runtimeCall(Box*, ArgPassSpec, Box*, Box*, Box*, Box**, const std::vector<const std::string*>*);
extern "C" Box* callattr(Box*, const std::string*, CallattrFlags, ArgPassSpec, Box*, Box*, Box*, Box**, extern "C" Box* callattr(Box*, const std::string*, CallattrFlags, ArgPassSpec, Box*, Box*, Box*, Box**,
...@@ -97,7 +97,7 @@ extern "C" void dump(void* p); ...@@ -97,7 +97,7 @@ extern "C" void dump(void* p);
extern "C" void dumpEx(void* p, int levels = 0); extern "C" void dumpEx(void* p, int levels = 0);
struct SetattrRewriteArgs; struct SetattrRewriteArgs;
void setattrGeneric(Box* obj, const std::string& attr, Box* val, SetattrRewriteArgs* rewrite_args); void setattrGeneric(Box* obj, llvm::StringRef attr, Box* val, SetattrRewriteArgs* rewrite_args);
struct BinopRewriteArgs; struct BinopRewriteArgs;
extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteArgs* rewrite_args); extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteArgs* rewrite_args);
...@@ -119,27 +119,26 @@ enum LookupScope { ...@@ -119,27 +119,26 @@ enum LookupScope {
INST_ONLY = 2, INST_ONLY = 2,
CLASS_OR_INST = 3, CLASS_OR_INST = 3,
}; };
extern "C" Box* callattrInternal(Box* obj, const std::string* attr, LookupScope, CallRewriteArgs* rewrite_args, extern "C" Box* callattrInternal(Box* obj, llvm::StringRef attr, LookupScope, CallRewriteArgs* rewrite_args,
ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3, Box** args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3, Box** args,
const std::vector<const std::string*>* keyword_names); const std::vector<const std::string*>* keyword_names);
extern "C" void delattr_internal(Box* obj, const std::string& attr, bool allow_custom, extern "C" void delattr_internal(Box* obj, llvm::StringRef attr, bool allow_custom, DelattrRewriteArgs* rewrite_args);
DelattrRewriteArgs* rewrite_args);
struct CompareRewriteArgs; struct CompareRewriteArgs;
Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrite_args); Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrite_args);
// This is the equivalent of PyObject_GetAttr. Unlike getattrInternalGeneric, it checks for custom __getattr__ or // This is the equivalent of PyObject_GetAttr. Unlike getattrInternalGeneric, it checks for custom __getattr__ or
// __getattribute__ methods. // __getattribute__ methods.
Box* getattrInternal(Box* obj, const std::string& attr, GetattrRewriteArgs* rewrite_args); Box* getattrInternal(Box* obj, llvm::StringRef attr, GetattrRewriteArgs* rewrite_args);
// This is the equivalent of PyObject_GenericGetAttr, which performs the default lookup rules for getattr() (check for // This is the equivalent of PyObject_GenericGetAttr, which performs the default lookup rules for getattr() (check for
// data descriptor, check for instance attribute, check for non-data descriptor). It does not check for __getattr__ or // data descriptor, check for instance attribute, check for non-data descriptor). It does not check for __getattr__ or
// __getattribute__. // __getattribute__.
Box* getattrInternalGeneric(Box* obj, const std::string& attr, GetattrRewriteArgs* rewrite_args, bool cls_only, Box* getattrInternalGeneric(Box* obj, llvm::StringRef attr, GetattrRewriteArgs* rewrite_args, bool cls_only,
bool for_call, Box** bind_obj_out, RewriterVar** r_bind_obj_out); bool for_call, Box** bind_obj_out, RewriterVar** r_bind_obj_out);
// This is the equivalent of _PyType_Lookup(), which calls Box::getattr() on each item in the object's MRO in the // This is the equivalent of _PyType_Lookup(), which calls Box::getattr() on each item in the object's MRO in the
// appropriate order. It does not do any descriptor logic. // appropriate order. It does not do any descriptor logic.
Box* typeLookup(BoxedClass* cls, const std::string& attr, GetattrRewriteArgs* rewrite_args); Box* typeLookup(BoxedClass* cls, llvm::StringRef attr, GetattrRewriteArgs* rewrite_args);
extern "C" void raiseAttributeErrorStr(const char* typeName, const char* attr) __attribute__((__noreturn__)); extern "C" void raiseAttributeErrorStr(const char* typeName, const char* attr) __attribute__((__noreturn__));
extern "C" void raiseAttributeError(Box* obj, const char* attr) __attribute__((__noreturn__)); extern "C" void raiseAttributeError(Box* obj, const char* attr) __attribute__((__noreturn__));
......
...@@ -1653,7 +1653,7 @@ public: ...@@ -1653,7 +1653,7 @@ public:
BoxedDict* dict = (BoxedDict*)AttrWrapper::copy(_self); BoxedDict* dict = (BoxedDict*)AttrWrapper::copy(_self);
assert(dict->cls == dict_cls); assert(dict->cls == dict_cls);
const std::string eq_str = "__eq__"; const std::string eq_str = "__eq__";
return callattrInternal(dict, &eq_str, LookupScope::CLASS_ONLY, NULL, ArgPassSpec(1), _other, NULL, NULL, NULL, return callattrInternal(dict, eq_str, LookupScope::CLASS_ONLY, NULL, ArgPassSpec(1), _other, NULL, NULL, NULL,
NULL); NULL);
} }
......
...@@ -239,8 +239,7 @@ public: ...@@ -239,8 +239,7 @@ public:
int weaklist_offset, int instance_size, bool is_user_defined, BoxedString* name, int weaklist_offset, int instance_size, bool is_user_defined, BoxedString* name,
BoxedTuple* bases, size_t nslots); BoxedTuple* bases, size_t nslots);
static BoxedHeapClass* create(BoxedClass* metatype, BoxedClass* base, gcvisit_func gc_visit, int attrs_offset, static BoxedHeapClass* create(BoxedClass* metatype, BoxedClass* base, gcvisit_func gc_visit, int attrs_offset,
int weaklist_offset, int instance_size, bool is_user_defined, int weaklist_offset, int instance_size, bool is_user_defined, llvm::StringRef name);
const std::string& name);
private: private:
// These functions are not meant for external callers and will mostly just be called // These functions are not meant for external callers and will mostly just be called
...@@ -354,10 +353,10 @@ public: ...@@ -354,10 +353,10 @@ public:
} }
// Only valid for NORMAL hidden classes: // Only valid for NORMAL hidden classes:
HiddenClass* getOrMakeChild(const std::string& attr); HiddenClass* getOrMakeChild(llvm::StringRef attr);
// Only valid for NORMAL or SINGLETON hidden classes: // Only valid for NORMAL or SINGLETON hidden classes:
int getOffset(const std::string& attr) { int getOffset(llvm::StringRef attr) {
assert(type == NORMAL || type == SINGLETON); assert(type == NORMAL || type == SINGLETON);
auto it = attr_offsets.find(attr); auto it = attr_offsets.find(attr);
if (it == attr_offsets.end()) if (it == attr_offsets.end())
...@@ -380,7 +379,7 @@ public: ...@@ -380,7 +379,7 @@ public:
HiddenClass* getAttrwrapperChild(); HiddenClass* getAttrwrapperChild();
// Only valid for NORMAL hidden classes: // Only valid for NORMAL hidden classes:
HiddenClass* delAttrToMakeHC(const std::string& attr); HiddenClass* delAttrToMakeHC(llvm::StringRef attr);
}; };
class BoxedInt : public Box { class BoxedInt : public Box {
......
...@@ -7,14 +7,13 @@ def doStuff(): ...@@ -7,14 +7,13 @@ def doStuff():
wr = weakref.ref(meth) wr = weakref.ref(meth)
return wr return wr
def fact(n): def recurse(f, n):
if n <= 1: if n:
return n return recurse(f, n-1)
return n * fact(n-1) return f()
w = doStuff() w = recurse(doStuff, 100)
print fact(10) # try to clear some memory
# Try creating a large object to make sure we can handle them: # Try creating a large object to make sure we can handle them:
def f(): def f():
...@@ -24,7 +23,7 @@ def f(): ...@@ -24,7 +23,7 @@ def f():
return weakref.ref(C) return weakref.ref(C)
r = f() r = recurse(f, 100)
import gc import gc
gc.collect() gc.collect()
......
#!/bin/sh
set -e
if [ "$#" -eq 0 ] ; then
echo "Usage: perf_collect.sh [commands to run benchmark]"
exit 1
fi
perf record -o $1.data -g -- $@
perf report -i $1.data -n --no-call-graph | bash tools/cumulate.sh > $1.txt
echo "Report saved in $1.txt (raw perf data saved in $1.data)"
...@@ -6,7 +6,7 @@ def tally(fn): ...@@ -6,7 +6,7 @@ def tally(fn):
for l in open(fn): for l in open(fn):
samples = int(l.split()[3]) samples = int(l.split()[3])
func = l.split()[-1] func = l.split()[-1]
counts[func] = samples counts[func] = counts.get(func, 0) + samples
return counts return counts
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment