aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4ssa.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2014-07-23 12:04:07 +0200
committerErik Verbruggen <erik.verbruggen@digia.com>2014-08-08 10:45:41 +0200
commit24581b838a5cc1dd5bd0f99cc02ed1aac9771de0 (patch)
tree53c3c823530632d16378d7d24117a04963f84663 /src/qml/compiler/qv4ssa.cpp
parentead3da17e7a91a5e6adf7b03e651950378d1326c (diff)
V4 IR: extend BasicBlockSet functionality.
To be used in later patches. Change-Id: I379addaea225482bcbfd7a0b03dbdbaa254dd579 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/compiler/qv4ssa.cpp')
-rw-r--r--src/qml/compiler/qv4ssa.cpp76
1 files changed, 72 insertions, 4 deletions
diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp
index 662b7054e9..5e9401afc3 100644
--- a/src/qml/compiler/qv4ssa.cpp
+++ b/src/qml/compiler/qv4ssa.cpp
@@ -118,8 +118,6 @@ class BasicBlockSet
IR::Function *function;
enum { MaxVectorCapacity = 8 };
- // Q_DISABLE_COPY(BasicBlockSet); disabled because MSVC wants assignment operator for std::vector
-
public:
class const_iterator
{
@@ -205,7 +203,12 @@ public:
friend class const_iterator;
public:
- BasicBlockSet(): blockNumbers(0), blockFlags(0), function(0) {}
+ BasicBlockSet(IR::Function *f = 0): blockNumbers(0), blockFlags(0), function(0)
+ {
+ if (f)
+ init(f);
+ }
+
#ifdef Q_COMPILER_RVALUE_REFS
BasicBlockSet(BasicBlockSet &&other): blockNumbers(0), blockFlags(0)
{
@@ -213,8 +216,36 @@ public:
std::swap(blockFlags, other.blockFlags);
std::swap(function, other.function);
}
-
#endif // Q_COMPILER_RVALUE_REFS
+
+ BasicBlockSet(const BasicBlockSet &other)
+ : blockNumbers(0)
+ , blockFlags(0)
+ , function(other.function)
+ {
+ if (other.blockFlags)
+ blockFlags = new Flags(*other.blockFlags);
+ else if (other.blockNumbers)
+ blockNumbers = new Numbers(*other.blockNumbers);
+ }
+
+ BasicBlockSet &operator=(const BasicBlockSet &other)
+ {
+ if (blockFlags) {
+ delete blockFlags;
+ blockFlags = 0;
+ } else {
+ delete blockNumbers;
+ blockNumbers = 0;
+ }
+ function = other.function;
+ if (other.blockFlags)
+ blockFlags = new Flags(*other.blockFlags);
+ else if (other.blockNumbers)
+ blockNumbers = new Numbers(*other.blockNumbers);
+ return *this;
+ }
+
~BasicBlockSet() { delete blockNumbers; delete blockFlags; }
void init(IR::Function *f)
@@ -226,6 +257,11 @@ public:
blockNumbers->reserve(MaxVectorCapacity);
}
+ bool empty() const
+ {
+ return begin() == end();
+ }
+
void insert(BasicBlock *bb)
{
Q_ASSERT(function);
@@ -253,6 +289,23 @@ public:
}
}
+ void remove(BasicBlock *bb)
+ {
+ Q_ASSERT(function);
+
+ if (blockFlags) {
+ (*blockFlags)[bb->index()] = false;
+ return;
+ }
+
+ for (std::vector<int>::iterator i = blockNumbers->begin(), ei = blockNumbers->end(); i != ei; ++i) {
+ if (*i == bb->index()) {
+ blockNumbers->erase(i);
+ return;
+ }
+ }
+ }
+
const_iterator begin() const { return const_iterator(*this, false); }
const_iterator end() const { return const_iterator(*this, true); }
@@ -263,6 +316,21 @@ public:
for (const_iterator it = begin(), eit = end(); it != eit; ++it)
bbs.push_back(*it);
}
+
+ bool contains(BasicBlock *bb) const
+ {
+ Q_ASSERT(function);
+
+ if (blockFlags)
+ return (*blockFlags)[bb->index()];
+
+ for (std::vector<int>::const_iterator i = blockNumbers->begin(), ei = blockNumbers->end(); i != ei; ++i) {
+ if (*i == bb->index())
+ return true;
+ }
+
+ return false;
+ }
};
class DominatorTree