Jlm
CfgPurgeTests.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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/print.hpp>
12 
13 TEST(ControLFlowGraphPurgeTests, test)
14 {
15  using namespace jlm::llvm;
16 
18 
19  ControlFlowGraph cfg(module);
20  auto bb0 = BasicBlock::create(cfg);
21  auto bb1 = BasicBlock::create(cfg);
22 
23  auto op = std::make_unique<jlm::rvsdg::ControlConstantOperation>(
25  bb0->append_last(ThreeAddressCode::create(std::move(op), {}));
26  bb0->append_last(BranchOperation::create(2, bb0->last()->result(0)));
27 
28  cfg.exit()->divert_inedges(bb0);
29  bb0->add_outedge(bb1);
30  bb0->add_outedge(cfg.exit());
31  bb1->add_outedge(bb1);
32 
33  std::cout << ControlFlowGraph::ToAscii(cfg) << std::flush;
34 
35  purge(cfg);
36 
37  EXPECT_EQ(cfg.nnodes(), 2u);
38 }
TEST(ControLFlowGraphPurgeTests, test)
static BasicBlock * create(ControlFlowGraph &cfg)
Definition: basic-block.cpp:37
static std::unique_ptr< llvm::ThreeAddressCode > create(size_t nalternatives, const Variable *operand)
Definition: operators.hpp:420
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
size_t nnodes() const noexcept
Definition: cfg.hpp:241
static std::unique_ptr< llvm::ThreeAddressCode > create(std::unique_ptr< rvsdg::SimpleOperation > operation, const std::vector< const Variable * > &operands)
Definition: tac.hpp:135
Global memory state passed between functions.
void purge(ControlFlowGraph &cfg)
Remove all basic blocks without instructions.