6#include <gtest/gtest.h>
20static std::unique_ptr<jlm::llvm::ControlFlowGraph>
27 auto cfg = ControlFlowGraph::create(ipgModule);
29 std::vector<const Variable *> operands;
30 for (
size_t n = 0; n < operation.
narguments(); n++)
32 auto & operandType = operation.
argument(n);
33 auto operand = cfg->entry()->append_argument(Argument::create(
"", operandType));
34 operands.emplace_back(operand);
37 auto basicBlock = BasicBlock::create(*cfg);
38 auto threeAddressCode = basicBlock->append_last(ThreeAddressCode::create(
39 std::unique_ptr<jlm::rvsdg::SimpleOperation>(
40 jlm::util::assertedCast<jlm::rvsdg::SimpleOperation>(operation.
copy().release())),
43 for (
size_t n = 0; n < threeAddressCode->nresults(); n++)
45 auto result = threeAddressCode->result(n);
46 cfg->exit()->append_result(result);
49 cfg->exit()->divert_inedges(basicBlock);
50 basicBlock->add_outedge(cfg->exit());
55static std::unique_ptr<jlm::llvm::InterProceduralGraphModule>
61 auto & ipgraph = ipgModule->ipgraph();
63 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> operandTypes;
64 for (
size_t n = 0; n < operation.
narguments(); n++)
66 operandTypes.emplace_back(operation.
argument(n));
69 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> resultTypes;
70 for (
size_t n = 0; n < operation.
nresults(); n++)
72 resultTypes.emplace_back(operation.
result(n));
77 auto functionNode = FunctionNode::create(ipgraph,
"test", functionType, Linkage::externalLinkage);
79 functionNode->add_cfg(std::move(cfg));
80 ipgModule->create_variable(functionNode);
85TEST(ThreeAddressCodeConversionTests, LoadVolatileConversion)
97 std::cout <<
jlm::rvsdg::view(&rvsdgModule->Rvsdg().GetRootRegion()) << std::flush;
100 auto lambdaOutput = rvsdgModule->Rvsdg().GetRootRegion().result(0)->origin();
103 auto loadVolatileNode = lambda->subregion()->Nodes().begin().ptr();
104 EXPECT_TRUE(is<LoadVolatileOperation>(loadVolatileNode));
107TEST(ThreeAddressCodeConversionTests, StoreVolatileConversion)
119 std::cout <<
jlm::rvsdg::view(&rvsdgModule->Rvsdg().GetRootRegion()) << std::flush;
122 auto lambdaOutput = rvsdgModule->Rvsdg().GetRootRegion().result(0)->origin();
125 auto storeVolatileNode = lambda->subregion()->Nodes().begin().ptr();
126 EXPECT_TRUE(is<StoreVolatileOperation>(storeVolatileNode));
static jlm::util::StatisticsCollector statisticsCollector
static std::unique_ptr< jlm::llvm::ControlFlowGraph > SetupControlFlowGraph(jlm::llvm::InterProceduralGraphModule &ipgModule, const jlm::rvsdg::SimpleOperation &operation)
TEST(ThreeAddressCodeConversionTests, LoadVolatileConversion)
static std::unique_ptr< jlm::llvm::InterProceduralGraphModule > SetupFunctionWithThreeAddressCode(const jlm::rvsdg::SimpleOperation &operation)
static std::shared_ptr< const FunctionType > Create(std::vector< std::shared_ptr< const jlm::rvsdg::Type > > argumentTypes, std::vector< std::shared_ptr< const jlm::rvsdg::Type > > resultTypes)
virtual std::unique_ptr< Operation > copy() const =0
const std::shared_ptr< const rvsdg::Type > & argument(size_t index) const noexcept
const std::shared_ptr< const rvsdg::Type > & result(size_t index) const noexcept
size_t nresults() const noexcept
size_t narguments() const noexcept
static std::shared_ptr< const TestType > createValueType()
Global memory state passed between functions.
std::string view(const rvsdg::Region *region)
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.