Commit 22087499 authored by Marius Wachtler's avatar Marius Wachtler

VRegSet: use a llvm bitvector as representation

parent ef007829
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <vector> #include <vector>
#include "llvm/ADT/BitVector.h"
#include "core/ast.h" #include "core/ast.h"
#include "core/common.h" #include "core/common.h"
#include "core/stringpool.h" #include "core/stringpool.h"
...@@ -203,8 +205,7 @@ public: ...@@ -203,8 +205,7 @@ public:
class VRegSet { class VRegSet {
private: private:
// TODO: switch just to a bool*? llvm::BitVector v;
std::vector<bool> v;
public: public:
VRegSet(int num_vregs) : v(num_vregs, false) {} VRegSet(int num_vregs) : v(num_vregs, false) {}
...@@ -219,13 +220,7 @@ public: ...@@ -219,13 +220,7 @@ public:
v[vreg] = true; v[vreg] = true;
} }
int numSet() const { int numSet() const { return v.count(); }
int r = 0;
for (auto b : v)
if (b)
r++;
return r;
}
class iterator { class iterator {
public: public:
...@@ -234,9 +229,7 @@ public: ...@@ -234,9 +229,7 @@ public:
iterator(const VRegSet& set, int i) : set(set), i(i) {} iterator(const VRegSet& set, int i) : set(set), i(i) {}
iterator& operator++() { iterator& operator++() {
do { i = set.v.find_next(i);
i++;
} while (i < set.v.size() && !set.v[i]);
return *this; return *this;
} }
...@@ -246,15 +239,8 @@ public: ...@@ -246,15 +239,8 @@ public:
int operator*() { return i; } int operator*() { return i; }
}; };
iterator begin() const { iterator begin() const { return iterator(*this, v.find_first()); }
for (int i = 0; i < v.size(); i++) { iterator end() const { return iterator(*this, -1); }
if (v[i])
return iterator(*this, i);
}
return iterator(*this, this->v.size());
}
iterator end() const { return iterator(*this, this->v.size()); }
}; };
// VRegMap: A compact way of representing a value per vreg. // VRegMap: A compact way of representing a value per vreg.
......
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