Jlm
Loading...
Searching...
No Matches
CfgPruneTests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#include <gtest/gtest.h>
7
9#include <jlm/llvm/ir/cfg.hpp>
14
15TEST(ControlFlowGraphPruneTests, test)
16{
17 using namespace jlm::llvm;
18 using namespace jlm::rvsdg;
19
21
22 // Arrange
24
25 ControlFlowGraph cfg(im);
26 auto arg = cfg.entry()->append_argument(Argument::create("arg", vt));
27 auto bb0 = BasicBlock::create(cfg);
28 auto bb1 = BasicBlock::create(cfg);
29
30 bb0->append_last(ThreeAddressCode::create(TestOperation::create({}, { vt }), {}));
31 bb1->append_last(
32 SsaPhiOperation::create({ { bb0->last()->result(0), bb0 }, { arg, cfg.entry() } }, vt));
33
34 cfg.exit()->divert_inedges(bb1);
35 bb0->add_outedge(bb1);
36 bb1->add_outedge(cfg.exit());
37 cfg.exit()->append_result(bb1->last()->result(0));
38
39 std::cout << ControlFlowGraph::ToAscii(cfg) << std::flush;
40
41 /* verify pruning */
42
43 prune(cfg);
44 std::cout << ControlFlowGraph::ToAscii(cfg) << std::flush;
45
46 EXPECT_EQ(cfg.nnodes(), 1u);
47}
TEST(ControlFlowGraphPruneTests, test)
static const auto vt
Definition PullTests.cpp:16
void divert_inedges(llvm::ControlFlowGraphNode *new_successor)
Definition cfg-node.hpp:171
ExitNode * exit() const noexcept
Definition cfg.hpp:212
EntryNode * entry() const noexcept
Definition cfg.hpp:206
size_t nnodes() const noexcept
Definition cfg.hpp:241
llvm::Argument * append_argument(std::unique_ptr< llvm::Argument > arg)
Definition cfg.hpp:100
void append_result(const Variable *v)
Definition cfg.hpp:143
static std::shared_ptr< const TestType > createValueType()
Definition TestType.cpp:67
Global memory state passed between functions.