Jlm
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>
13 #include <jlm/rvsdg/TestType.hpp>
14 
15 TEST(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
static std::unique_ptr< Argument > create(const std::string &name, std::shared_ptr< const jlm::rvsdg::Type > type, const AttributeSet &attributes)
Definition: cfg.hpp:59
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
EntryNode * entry() const noexcept
Definition: cfg.hpp:206
ExitNode * exit() const noexcept
Definition: cfg.hpp:212
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::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 prune(ControlFlowGraph &cfg)