6 #include <gtest/gtest.h>
16 TEST(AnnotationTests, TestBasicBlockAnnotation)
26 auto v0 = module.create_variable(
vt,
"v0");
37 return std::make_tuple(std::move(root), v0, v1, v2);
41 auto [aggregationTreeRoot, v0, v1, v2] = SetupAggregationTree(module);
46 auto demandMap =
Annotate(*aggregationTreeRoot);
47 print(*aggregationTreeRoot, *demandMap, stdout);
57 TEST(AnnotationTests, TestLinearSubgraphAnnotation)
89 return std::make_tuple(std::move(root), v1, v2);
94 auto [aggregationTreeRoot, v1, v2] = SetupAggregationTree(module, argument);
99 auto demandMap =
Annotate(*aggregationTreeRoot);
100 print(*aggregationTreeRoot, *demandMap, stdout);
109 auto linearNode1 = aggregationTreeRoot->child(0);
114 auto entryNode = linearNode1->child(0);
119 auto basicBlockNode1 = linearNode1->child(1);
125 auto linearNode2 = aggregationTreeRoot->child(1);
130 auto basicBlockNode2 = linearNode2->child(0);
135 auto exitNode = linearNode2->child(1);
141 TEST(AnnotationTests, TestBranchAnnotation)
154 auto argument = module.create_variable(
vt,
"arg");
155 auto v3 = module.create_variable(
vt,
"v3");
175 branch->add_child(std::move(basicBlock1));
176 branch->add_child(std::move(basicBlock2));
180 return std::make_tuple(std::move(root), argument, v1, v2, v3, v4);
187 auto [aggregationTreeRoot, argument, v1, v2, v3, v4] = SetupAggregationTree(module);
192 auto demandMap =
Annotate(*aggregationTreeRoot);
193 print(*aggregationTreeRoot, *demandMap, stdout);
202 auto splitNode = aggregationTreeRoot->child(0);
207 auto branchNode = aggregationTreeRoot->child(1);
212 auto basicBlockNode1 = branchNode->child(0);
217 auto basicBlockNode2 = branchNode->child(1);
225 TEST(AnnotationTests, TestLoopAnnotation)
235 auto v1 = module.create_variable(
vt,
"v1");
236 auto v4 = module.create_variable(
vt,
"v4");
251 return std::make_tuple(std::move(root), v1, v2, v3, v4);
255 auto [aggregationTreeRoot, v1, v2, v3, v4] = SetupAggregationTree(module);
260 auto demandMap =
Annotate(*aggregationTreeRoot);
261 print(*aggregationTreeRoot, *demandMap, stdout);
270 auto loopNode = aggregationTreeRoot->child(0);
275 auto basicBlockNode = loopNode->child(0);
281 auto exitNode = aggregationTreeRoot->child(1);
288 TEST(AnnotationTests, TestBranchInLoopAnnotation)
298 auto v1 = module.create_variable(
vt,
"v1");
299 auto v3 = module.create_variable(
vt,
"v3");
318 branchNode->add_child(std::move(basicBlock1));
319 branchNode->add_child(std::move(basicBlock2));
325 return std::make_tuple(std::move(root), v1, v2, v3, v4);
329 auto [aggregationTreeRoot, v1, v2, v3, v4] = SetupAggregationTree(module);
334 auto demandMap =
Annotate(*aggregationTreeRoot);
335 print(*aggregationTreeRoot, *demandMap, stdout);
344 auto loopNode = aggregationTreeRoot->child(0);
349 auto branchNode = loopNode->child(0);
352 BranchAnnotationSet({ v1, v4 }, { v2, v3, v4 }, { v3 }, { v1, v2, v4 }, { v2, v3, v4 }));
354 auto basicBlockNode1 = branchNode->child(0);
359 auto basicBlockNode2 = branchNode->child(1);
366 auto exitNode = aggregationTreeRoot->child(1);
373 TEST(AnnotationTests, TestAssignmentAnnotation)
382 auto v1 = module.create_variable(
vt,
"v1");
383 auto v2 = module.create_variable(
vt,
"v2");
390 return std::make_tuple(std::move(root), v1, v2);
394 auto [aggregationTreeRoot, v1, v2] = SetupAggregationTree(module);
399 auto demandMap =
Annotate(*aggregationTreeRoot);
400 print(*aggregationTreeRoot, *demandMap, stdout);
410 TEST(AnnotationTests, TestBranchPassByAnnotation)
420 auto v3 = module.create_variable(
vt,
"v3");
439 branchNode->add_child(std::move(basicBlockNode1));
440 branchNode->add_child(std::move(basicBlockNode2));
447 root->add_child(std::move(joinNode));
448 root->add_child(std::move(exitNode));
450 return std::make_tuple(std::move(root), v1, v2, v3);
454 auto [aggregationTreeRoot, v1, v2, v3] = SetupAggregationTree(module);
459 auto demandMap =
Annotate(*aggregationTreeRoot);
460 print(*aggregationTreeRoot, *demandMap, stdout);
469 auto splitNode = aggregationTreeRoot->child(0);
474 auto branchNode = aggregationTreeRoot->child(1);
479 auto basicBlockNode1 = branchNode->child(0);
484 auto basicBlockNode2 = branchNode->child(1);
490 auto joinNode = aggregationTreeRoot->child(2);
495 auto exitNode = aggregationTreeRoot->child(3);
TEST(AnnotationTests, TestBasicBlockAnnotation)
static std::unique_ptr< llvm::ThreeAddressCode > create(const Variable *rhs, const Variable *lhs)
static std::unique_ptr< AggregationNode > create()
static std::unique_ptr< AggregationNode > create()
static std::unique_ptr< AggregationNode > create(const std::vector< llvm::Argument * > &arguments)
static std::unique_ptr< AggregationNode > create(const std::vector< const Variable * > &results)
static std::unique_ptr< AggregationNode > create(std::unique_ptr< AggregationNode > n1, std::unique_ptr< AggregationNode > n2)
static std::unique_ptr< AggregationNode > create(std::unique_ptr< AggregationNode > body)
ThreeAddressCode * last() const noexcept
void append_last(std::unique_ptr< llvm::ThreeAddressCode > tac)
const ThreeAddressCodeVariable * result(size_t index) const noexcept
static std::unique_ptr< llvm::ThreeAddressCode > create(std::unique_ptr< rvsdg::SimpleOperation > operation, const std::vector< const Variable * > &operands)
static std::shared_ptr< const TestType > createValueType()
Global memory state passed between functions.
void print(const AggregationNode &n, const AnnotationMap &dm, FILE *out)
std::unique_ptr< AnnotationMap > Annotate(const AggregationNode &aggregationTreeRoot)