Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microoptimize the rewriter class #839

Merged
merged 1 commit into from
Aug 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/asm_writing/rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ assembler::XMMRegister RewriterVar::getInXMMReg(Location dest) {
}

bool RewriterVar::isInLocation(Location l) {
return locations.count(l) != 0;
return std::find(locations.begin(), locations.end(), l) != locations.end();
}

RewriterVar* Rewriter::getArg(int argnum) {
Expand Down Expand Up @@ -880,7 +880,7 @@ void Rewriter::_setupCall(bool has_side_effects, const RewriterVar::SmallVector&
addLocationToVar(var, l);
} else {
assembler::Register r2 = var->getInReg(l);
assert(var->locations.count(r2));
assert(var->isInLocation(r2));
assert(r2 == r);
}
}
Expand Down Expand Up @@ -1244,7 +1244,7 @@ void Rewriter::commit() {
}

// silly, but need to make a copy due to the mutations:
for (auto l : std::vector<Location>(var->locations.begin(), var->locations.end())) {
for (auto l : llvm::SmallVector<Location, 8>(var->locations.begin(), var->locations.end())) {
if (l == expected)
continue;
removeLocationFromVar(var, l);
Expand Down Expand Up @@ -1691,7 +1691,7 @@ void Rewriter::addLocationToVar(RewriterVar* var, Location l) {
|| l.type == Location::Stack,
"%d", l.type);

var->locations.insert(l);
var->locations.push_back(l);
vars_by_location[l] = var;

#ifndef NDEBUG
Expand All @@ -1714,7 +1714,12 @@ void Rewriter::removeLocationFromVar(RewriterVar* var, Location l) {
assert(vars_by_location[l] == var);

vars_by_location.erase(l);
var->locations.erase(l);
for (auto it = var->locations.begin(), it_end = var->locations.end(); it != it_end; ++it) {
if (*it == l) {
it = var->locations.erase(it);
break;
}
}
}

RewriterVar* Rewriter::createNewVar() {
Expand Down Expand Up @@ -1751,7 +1756,8 @@ assembler::Register RewriterVar::initializeInReg(Location l) {
var = this;

// Add the location to this
this->locations.insert(l);
assert(!isInLocation(l));
this->locations.push_back(l);

return reg;
}
Expand All @@ -1768,7 +1774,8 @@ assembler::XMMRegister RewriterVar::initializeInXMMReg(Location l) {
var = this;

// Add the location to this
this->locations.insert(l);
assert(!isInLocation(l));
this->locations.push_back(l);

return reg;
}
Expand Down Expand Up @@ -1825,7 +1832,7 @@ Rewriter::Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const s
RewriterVar*& var = vars_by_location[l];
if (!var) {
var = createNewVar();
var->locations.insert(l);
var->locations.push_back(l);
}

this->live_outs.push_back(var);
Expand Down
6 changes: 3 additions & 3 deletions src/asm_writing/rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class RewriterVar {
private:
Rewriter* rewriter;

std::set<Location> locations;
llvm::SmallVector<Location, 4> locations;
bool isInLocation(Location l);

// uses is a vector of the indices into the Rewriter::actions vector
Expand Down Expand Up @@ -320,7 +320,7 @@ class Rewriter : public ICSlotRewrite::CommitHook {
// Loads the constant into any register or if already in a register just return it
assembler::Register loadConst(uint64_t val, Location otherThan = Location::any());

std::vector<std::pair<uint64_t, RewriterVar*>> consts;
llvm::SmallVector<std::pair<uint64_t, RewriterVar*>, 16> consts;
};


Expand Down Expand Up @@ -463,7 +463,7 @@ class Rewriter : public ICSlotRewrite::CommitHook {
}
}
assert(found);
assert(p.second->locations.count(p.first) == 1);
assert(p.second->isInLocation(p.first));
}
}
if (!done_guarding) {
Expand Down