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