summaryrefslogtreecommitdiffstats
path: root/compiler/sea_ir
diff options
context:
space:
mode:
authorDragos Sbirlea <dragoss@google.com>2013-08-07 18:15:44 -0700
committerDragos Sbirlea <dragoss@google.com>2013-08-08 08:42:14 -0700
commit597e46bf300244a45d1e214c618e89250b39912b (patch)
tree51eca501960cf8c28940c6cc807a1fbeeca42338 /compiler/sea_ir
parentf91bdf9c194381a3d346bd6420afcabd863f134c (diff)
downloadart-597e46bf300244a45d1e214c618e89250b39912b.zip
art-597e46bf300244a45d1e214c618e89250b39912b.tar.gz
art-597e46bf300244a45d1e214c618e89250b39912b.tar.bz2
Added tests for SEA IR intermediate representation.
Change-Id: Ibc55fc3d1f6f753381a9d508d250944c2c45531d
Diffstat (limited to 'compiler/sea_ir')
-rw-r--r--compiler/sea_ir/ir/regions_test.cc59
-rw-r--r--compiler/sea_ir/ir/sea.h13
2 files changed, 66 insertions, 6 deletions
diff --git a/compiler/sea_ir/ir/regions_test.cc b/compiler/sea_ir/ir/regions_test.cc
new file mode 100644
index 0000000..9813465
--- /dev/null
+++ b/compiler/sea_ir/ir/regions_test.cc
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common_test.h"
+#include "sea_ir/ir/sea.h"
+
+using utils::ScopedHashtable;
+
+namespace sea_ir {
+
+class RegionsTest : public art::CommonTest {
+};
+
+TEST_F(RegionsTest, Basics) {
+ sea_ir::SeaGraph sg(*java_lang_dex_file_);
+ sea_ir::Region* root = sg.GetNewRegion();
+ sea_ir::Region* then_region = sg.GetNewRegion();
+ sea_ir::Region* else_region = sg.GetNewRegion();
+ std::vector<sea_ir::Region*>* regions = sg.GetRegions();
+ // Test that regions have been registered correctly as children of the graph.
+ EXPECT_TRUE(std::find(regions->begin(), regions->end(), root) != regions->end());
+ EXPECT_TRUE(std::find(regions->begin(), regions->end(), then_region) != regions->end());
+ EXPECT_TRUE(std::find(regions->begin(), regions->end(), else_region) != regions->end());
+ // Check that an edge recorded correctly in both the head and the tail.
+ sg.AddEdge(root, then_region);
+ std::vector<sea_ir::Region*>* succs = root->GetSuccessors();
+ EXPECT_EQ(1U, succs->size());
+ EXPECT_EQ(then_region, succs->at(0));
+ std::vector<sea_ir::Region*>* preds = then_region->GetPredecessors();
+ EXPECT_EQ(1U, preds->size());
+ EXPECT_EQ(root, preds->at(0));
+ // Check that two edges are recorded properly for both head and tail.
+ sg.AddEdge(root, else_region);
+ succs = root->GetSuccessors();
+ EXPECT_EQ(2U, succs->size());
+ EXPECT_TRUE(std::find(succs->begin(), succs->end(), then_region) != succs->end());
+ EXPECT_TRUE(std::find(succs->begin(), succs->end(), else_region) != succs->end());
+ preds = then_region->GetPredecessors();
+ EXPECT_EQ(1U, preds->size());
+ EXPECT_EQ(root, preds->at(0));
+ preds = else_region->GetPredecessors();
+ EXPECT_EQ(1U, preds->size());
+ EXPECT_EQ(root, preds->at(0));
+}
+
+} // namespace art
diff --git a/compiler/sea_ir/ir/sea.h b/compiler/sea_ir/ir/sea.h
index 7746a60..0b20ed7 100644
--- a/compiler/sea_ir/ir/sea.h
+++ b/compiler/sea_ir/ir/sea.h
@@ -21,11 +21,12 @@
#include <set>
#include <map>
+#include "utils/scoped_hashtable.h"
+#include "gtest/gtest_prod.h"
#include "dex_file.h"
#include "dex_instruction.h"
#include "sea_ir/ir/instruction_tools.h"
#include "sea_ir/ir/instruction_nodes.h"
-#include "utils/scoped_hashtable.h"
namespace sea_ir {
@@ -289,8 +290,12 @@ class SeaGraph: IVisitable {
uint32_t method_idx_;
uint32_t method_access_flags_;
- private:
+ protected:
explicit SeaGraph(const art::DexFile& df);
+ virtual ~SeaGraph() { }
+
+ private:
+ FRIEND_TEST(RegionsTest, Basics);
// Registers @childReg as a region belonging to the SeaGraph instance.
void AddRegion(Region* childReg);
// Returns new region and registers it with the SeaGraph instance.
@@ -330,10 +335,6 @@ class SeaGraph: IVisitable {
// Identifies the definitions corresponding to uses for region @node
// by using the scoped hashtable of names @ scoped_table.
void RenameAsSSA(Region* node, utils::ScopedHashtable<int, InstructionNode*>* scoped_table);
-
-
-
- virtual ~SeaGraph() {}
// Generate LLVM IR for the method.
// Precondition: ConvertToSSA().
void GenerateLLVM();