Commit 760925b9 authored by Marius Wachtler's avatar Marius Wachtler

Microoptimize rewriter

parent 31f72898
...@@ -691,7 +691,7 @@ assembler::XMMRegister RewriterVar::getInXMMReg(Location dest) { ...@@ -691,7 +691,7 @@ assembler::XMMRegister RewriterVar::getInXMMReg(Location dest) {
} }
bool RewriterVar::isInLocation(Location l) { 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) { RewriterVar* Rewriter::getArg(int argnum) {
...@@ -880,7 +880,7 @@ void Rewriter::_setupCall(bool has_side_effects, const RewriterVar::SmallVector& ...@@ -880,7 +880,7 @@ void Rewriter::_setupCall(bool has_side_effects, const RewriterVar::SmallVector&
addLocationToVar(var, l); addLocationToVar(var, l);
} else { } else {
assembler::Register r2 = var->getInReg(l); assembler::Register r2 = var->getInReg(l);
assert(var->locations.count(r2)); assert(var->isInLocation(r2));
assert(r2 == r); assert(r2 == r);
} }
} }
...@@ -1244,7 +1244,7 @@ void Rewriter::commit() { ...@@ -1244,7 +1244,7 @@ void Rewriter::commit() {
} }
// silly, but need to make a copy due to the mutations: // 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) if (l == expected)
continue; continue;
removeLocationFromVar(var, l); removeLocationFromVar(var, l);
...@@ -1691,7 +1691,7 @@ void Rewriter::addLocationToVar(RewriterVar* var, Location l) { ...@@ -1691,7 +1691,7 @@ void Rewriter::addLocationToVar(RewriterVar* var, Location l) {
|| l.type == Location::Stack, || l.type == Location::Stack,
"%d", l.type); "%d", l.type);
var->locations.insert(l); var->locations.push_back(l);
vars_by_location[l] = var; vars_by_location[l] = var;
#ifndef NDEBUG #ifndef NDEBUG
...@@ -1714,7 +1714,12 @@ void Rewriter::removeLocationFromVar(RewriterVar* var, Location l) { ...@@ -1714,7 +1714,12 @@ void Rewriter::removeLocationFromVar(RewriterVar* var, Location l) {
assert(vars_by_location[l] == var); assert(vars_by_location[l] == var);
vars_by_location.erase(l); 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() { RewriterVar* Rewriter::createNewVar() {
...@@ -1751,7 +1756,8 @@ assembler::Register RewriterVar::initializeInReg(Location l) { ...@@ -1751,7 +1756,8 @@ assembler::Register RewriterVar::initializeInReg(Location l) {
var = this; var = this;
// Add the location to this // Add the location to this
this->locations.insert(l); assert(!isInLocation(l));
this->locations.push_back(l);
return reg; return reg;
} }
...@@ -1768,7 +1774,8 @@ assembler::XMMRegister RewriterVar::initializeInXMMReg(Location l) { ...@@ -1768,7 +1774,8 @@ assembler::XMMRegister RewriterVar::initializeInXMMReg(Location l) {
var = this; var = this;
// Add the location to this // Add the location to this
this->locations.insert(l); assert(!isInLocation(l));
this->locations.push_back(l);
return reg; return reg;
} }
...@@ -1825,7 +1832,7 @@ Rewriter::Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const s ...@@ -1825,7 +1832,7 @@ Rewriter::Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const s
RewriterVar*& var = vars_by_location[l]; RewriterVar*& var = vars_by_location[l];
if (!var) { if (!var) {
var = createNewVar(); var = createNewVar();
var->locations.insert(l); var->locations.push_back(l);
} }
this->live_outs.push_back(var); this->live_outs.push_back(var);
......
...@@ -227,7 +227,7 @@ public: ...@@ -227,7 +227,7 @@ public:
private: private:
Rewriter* rewriter; Rewriter* rewriter;
std::set<Location> locations; llvm::SmallVector<Location, 4> locations;
bool isInLocation(Location l); bool isInLocation(Location l);
// uses is a vector of the indices into the Rewriter::actions vector // uses is a vector of the indices into the Rewriter::actions vector
...@@ -320,7 +320,7 @@ protected: ...@@ -320,7 +320,7 @@ protected:
// Loads the constant into any register or if already in a register just return it // 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()); 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;
}; };
...@@ -463,7 +463,7 @@ protected: ...@@ -463,7 +463,7 @@ protected:
} }
} }
assert(found); assert(found);
assert(p.second->locations.count(p.first) == 1); assert(p.second->isInLocation(p.first));
} }
} }
if (!done_guarding) { if (!done_guarding) {
......
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