Commit 25c54f76 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #675 from kmod/perf

rewriter optimization; switch things away from compareInternal
parents 5babbb14 956eb6fe
...@@ -278,7 +278,7 @@ class RewriterAction { ...@@ -278,7 +278,7 @@ class RewriterAction {
public: public:
std::function<void()> action; std::function<void()> action;
RewriterAction(std::function<void()> f) : action(f) {} RewriterAction(std::function<void()> f) : action(std::move(f)) {}
}; };
enum class ActionType { NORMAL, GUARD, MUTATION }; enum class ActionType { NORMAL, GUARD, MUTATION };
...@@ -349,7 +349,7 @@ protected: ...@@ -349,7 +349,7 @@ protected:
Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const std::vector<int>& live_outs); Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const std::vector<int>& live_outs);
std::vector<RewriterAction> actions; std::vector<RewriterAction> actions;
void addAction(const std::function<void()>& action, std::vector<RewriterVar*> const& vars, ActionType type) { void addAction(std::function<void()> action, std::vector<RewriterVar*> const& vars, ActionType type) {
assertPhaseCollecting(); assertPhaseCollecting();
for (RewriterVar* var : vars) { for (RewriterVar* var : vars) {
assert(var != NULL); assert(var != NULL);
...@@ -368,7 +368,7 @@ protected: ...@@ -368,7 +368,7 @@ protected:
assert(!added_changing_action); assert(!added_changing_action);
last_guard_action = (int)actions.size(); last_guard_action = (int)actions.size();
} }
actions.emplace_back(action); actions.emplace_back(std::move(action));
} }
bool added_changing_action; bool added_changing_action;
bool marked_inside_ic; bool marked_inside_ic;
......
...@@ -781,9 +781,11 @@ Box* listContains(BoxedList* self, Box* elt) { ...@@ -781,9 +781,11 @@ Box* listContains(BoxedList* self, Box* elt) {
if (identity_eq) if (identity_eq)
return True; return True;
Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL); int r = PyObject_RichCompareBool(e, elt, Py_EQ);
bool b = nonzero(cmp); if (r == -1)
if (b) throwCAPIException();
if (r)
return True; return True;
} }
return False; return False;
...@@ -797,9 +799,12 @@ Box* listCount(BoxedList* self, Box* elt) { ...@@ -797,9 +799,12 @@ Box* listCount(BoxedList* self, Box* elt) {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Box* e = self->elts->elts[i]; Box* e = self->elts->elts[i];
Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL);
bool b = nonzero(cmp); int r = PyObject_RichCompareBool(e, elt, Py_EQ);
if (b) if (r == -1)
throwCAPIException();
if (r)
count++; count++;
} }
return boxInt(count); return boxInt(count);
...@@ -829,9 +834,12 @@ Box* listIndex(BoxedList* self, Box* elt, BoxedInt* _start, Box** args) { ...@@ -829,9 +834,12 @@ Box* listIndex(BoxedList* self, Box* elt, BoxedInt* _start, Box** args) {
for (int64_t i = start; i < stop; i++) { for (int64_t i = start; i < stop; i++) {
Box* e = self->elts->elts[i]; Box* e = self->elts->elts[i];
Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL);
bool b = nonzero(cmp); int r = PyObject_RichCompareBool(e, elt, Py_EQ);
if (b) if (r == -1)
throwCAPIException();
if (r)
return boxInt(i); return boxInt(i);
} }
...@@ -846,10 +854,12 @@ Box* listRemove(BoxedList* self, Box* elt) { ...@@ -846,10 +854,12 @@ Box* listRemove(BoxedList* self, Box* elt) {
for (int i = 0; i < self->size; i++) { for (int i = 0; i < self->size; i++) {
Box* e = self->elts->elts[i]; Box* e = self->elts->elts[i];
Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL);
bool b = nonzero(cmp);
if (b) { int r = PyObject_RichCompareBool(e, elt, Py_EQ);
if (r == -1)
throwCAPIException();
if (r) {
memmove(self->elts->elts + i, self->elts->elts + i + 1, (self->size - i - 1) * sizeof(Box*)); memmove(self->elts->elts + i, self->elts->elts + i + 1, (self->size - i - 1) * sizeof(Box*));
self->size--; self->size--;
return None; return None;
...@@ -927,10 +937,11 @@ Box* _listCmp(BoxedList* lhs, BoxedList* rhs, AST_TYPE::AST_TYPE op_type) { ...@@ -927,10 +937,11 @@ Box* _listCmp(BoxedList* lhs, BoxedList* rhs, AST_TYPE::AST_TYPE op_type) {
if (identity_eq) if (identity_eq)
continue; continue;
Box* is_eq = compareInternal(lhs->elts->elts[i], rhs->elts->elts[i], AST_TYPE::Eq, NULL); int r = PyObject_RichCompareBool(lhs->elts->elts[i], rhs->elts->elts[i], Py_EQ);
bool bis_eq = nonzero(is_eq); if (r == -1)
throwCAPIException();
if (bis_eq) if (r)
continue; continue;
if (op_type == AST_TYPE::Eq) { if (op_type == AST_TYPE::Eq) {
......
...@@ -683,15 +683,14 @@ Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) { ...@@ -683,15 +683,14 @@ Box* Box::getattr(llvm::StringRef attr, GetattrRewriteArgs* rewrite_args) {
rewrite_args->obj->addAttrGuard(BOX_CLS_OFFSET, (intptr_t)cls); rewrite_args->obj->addAttrGuard(BOX_CLS_OFFSET, (intptr_t)cls);
#if 0 #if 0
if (attr[0] == '_' && attr[1] == '_') { if (attr.data()[0] == '_' && attr.data()[1] == '_') {
// Only do this logging for potentially-avoidable cases: // Only do this logging for potentially-avoidable cases:
if (!rewrite_args && cls != classobj_cls) { if (!rewrite_args && cls != classobj_cls) {
if (attr == "__setattr__") if (attr == "__setattr__")
printf(""); printf("");
std::string per_name_stat_name = "slowpath_box_getattr." + std::string(attr); std::string per_name_stat_name = "slowpath_box_getattr." + std::string(attr);
int id = Stats::getStatId(per_name_stat_name); Stats::log(Stats::getStatCounter(per_name_stat_name));
Stats::log(id);
} }
} }
#endif #endif
......
...@@ -226,9 +226,12 @@ Box* tupleContains(BoxedTuple* self, Box* elt) { ...@@ -226,9 +226,12 @@ Box* tupleContains(BoxedTuple* self, Box* elt) {
int size = self->size(); int size = self->size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Box* e = self->elts[i]; Box* e = self->elts[i];
Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL);
bool b = nonzero(cmp); int r = PyObject_RichCompareBool(e, elt, Py_EQ);
if (b) if (r == -1)
throwCAPIException();
if (r)
return True; return True;
} }
return False; return False;
...@@ -238,9 +241,12 @@ Box* tupleIndex(BoxedTuple* self, Box* elt) { ...@@ -238,9 +241,12 @@ Box* tupleIndex(BoxedTuple* self, Box* elt) {
int size = self->size(); int size = self->size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Box* e = self->elts[i]; Box* e = self->elts[i];
Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL);
bool b = nonzero(cmp); int r = PyObject_RichCompareBool(e, elt, Py_EQ);
if (b) if (r == -1)
throwCAPIException();
if (r)
return boxInt(i); return boxInt(i);
} }
......
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