Jlm
SsaDestructionTests.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #include <gtest/gtest.h>
7 
11 #include <jlm/llvm/ir/ssa.hpp>
13 #include <jlm/rvsdg/TestType.hpp>
14 
15 TEST(StaticSingleAssignmentDestructionTests, test_two_phis)
16 {
17  using namespace jlm::llvm;
18  using namespace jlm::rvsdg;
19 
22 
23  ControlFlowGraph cfg(module);
24  auto bb1 = BasicBlock::create(cfg);
25  auto bb2 = BasicBlock::create(cfg);
26  auto bb3 = BasicBlock::create(cfg);
27  auto bb4 = BasicBlock::create(cfg);
28 
29  cfg.exit()->divert_inedges(bb1);
30  bb1->add_outedge(bb2);
31  bb1->add_outedge(bb3);
32  bb2->add_outedge(bb4);
33  bb3->add_outedge(bb4);
34  bb4->add_outedge(cfg.exit());
35 
36  bb2->append_last(ThreeAddressCode::create(TestOperation::create({}, { vt }), {}));
37  auto v1 = bb2->last()->result(0);
38 
39  bb2->append_last(ThreeAddressCode::create(TestOperation::create({}, { vt }), {}));
40  auto v3 = bb2->last()->result(0);
41 
42  bb3->append_last(ThreeAddressCode::create(TestOperation::create({}, { vt }), {}));
43  auto v2 = bb3->last()->result(0);
44 
45  bb3->append_last(ThreeAddressCode::create(TestOperation::create({}, { vt }), {}));
46  auto v4 = bb3->last()->result(0);
47 
48  bb4->append_last(SsaPhiOperation::create({ { v1, bb2 }, { v2, bb3 } }, vt));
49  bb4->append_last(SsaPhiOperation::create({ { v3, bb2 }, { v4, bb3 } }, vt));
50 
51  std::cout << ControlFlowGraph::ToAscii(cfg) << std::flush;
52 
53  destruct_ssa(cfg);
54 
55  std::cout << ControlFlowGraph::ToAscii(cfg) << std::flush;
56 }
static const auto vt
Definition: PullTests.cpp:16
TEST(StaticSingleAssignmentDestructionTests, test_two_phis)
static BasicBlock * create(ControlFlowGraph &cfg)
Definition: basic-block.cpp:37
void divert_inedges(llvm::ControlFlowGraphNode *new_successor)
Definition: cfg-node.hpp:171
static std::string ToAscii(const ControlFlowGraph &controlFlowGraph)
Definition: cfg.cpp:151
ExitNode * exit() const noexcept
Definition: cfg.hpp:212
static std::unique_ptr< llvm::ThreeAddressCode > create(const std::vector< std::pair< const Variable *, ControlFlowGraphNode * >> &arguments, std::shared_ptr< const jlm::rvsdg::Type > type)
Definition: operators.hpp:76
static std::unique_ptr< llvm::ThreeAddressCode > create(std::unique_ptr< rvsdg::SimpleOperation > operation, const std::vector< const Variable * > &operands)
Definition: tac.hpp:135
static std::shared_ptr< const TestType > createValueType()
Definition: TestType.cpp:67
Global memory state passed between functions.
void destruct_ssa(ControlFlowGraph &cfg)
Definition: ssa.cpp:18