Jlm
Loading...
Searching...
No Matches
IOBarrierTests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2026 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#include <gtest/gtest.h>
7
10#include <jlm/rvsdg/gamma.hpp>
11#include <jlm/rvsdg/graph.hpp>
14
15namespace jlm::llvm
16{
17
18TEST(MemoryHoistBarrierTests, normalizeNestedMemoryHoistBarriers)
19{
20 using namespace jlm::rvsdg;
21
22 // Arrange
23 auto ptrType = PointerType::Create();
24 auto ioStateType = IOStateType::Create();
25
26 Graph graph;
27 auto & a1 = GraphImport::Create(graph, ptrType, "a0");
28 auto & a2 = GraphImport::Create(graph, ptrType, "a1");
29 auto & ioState = GraphImport::Create(graph, ioStateType, "ioState");
30
31 auto & mhbNode1 = MemoryHoistBarrierOperation::createNode(a1, ioState, 1);
32 auto & mhbNode2 = MemoryHoistBarrierOperation::createNode(*mhbNode1.output(0), ioState, 4);
33
34 auto & mhbNode3 = MemoryHoistBarrierOperation::createNode(a2, ioState, 2);
35
36 auto testNode = TestOperation::createNode(&graph.GetRootRegion(), { &ioState }, { ioStateType });
37 auto & mhbNode4 =
38 MemoryHoistBarrierOperation::createNode(*mhbNode1.output(0), *testNode->output(0), 3);
39
40 auto & ctlFalse = ControlConstantOperation::createFalse(graph.GetRootRegion());
41 auto gammaNode = GammaNode::create(&ctlFalse, 2);
42 auto ptrEntryVar = gammaNode->AddEntryVar(mhbNode1.output(0));
43 auto ioStateEntryVar = gammaNode->AddEntryVar(&ioState);
44
45 // gammaNode - subregion 0
47 *ptrEntryVar.branchArgument[0],
48 *ioStateEntryVar.branchArgument[0],
49 5);
50
51 // gammaNode - subregion 1
52 // Nothing needs to be done
53
54 // gammaNode - finalize
55 auto ptrExitVar = gammaNode->AddExitVar({ mhbNode5.output(0), ptrEntryVar.branchArgument[1] });
56
57 auto & x1 = GraphExport::Create(*mhbNode1.output(0), "x1");
58 auto & x2 = GraphExport::Create(*mhbNode2.output(0), "x2");
59 auto & x3 = GraphExport::Create(*mhbNode3.output(0), "x3");
60 auto & x4 = GraphExport::Create(*mhbNode4.output(0), "x4");
61 GraphExport::Create(*ptrExitVar.output, "x5");
62
63 // Act
64 ReduceNode<MemoryHoistBarrierOperation>(
66 mhbNode1);
67 ReduceNode<MemoryHoistBarrierOperation>(
69 mhbNode2);
70 ReduceNode<MemoryHoistBarrierOperation>(
72 mhbNode3);
73 ReduceNode<MemoryHoistBarrierOperation>(
75 mhbNode4);
76 ReduceNode<MemoryHoistBarrierOperation>(
78 mhbNode5);
79
80 // Assert
81 {
82 // We expect that nothing happened with mhbNode1
83 EXPECT_EQ(x1.origin(), mhbNode1.output(0));
84 }
85
86 {
87 // We expect that mhbNode2 was replaced
88 auto [mhbNode, mhbOp] =
90 EXPECT_NE(mhbNode, nullptr);
91 EXPECT_EQ(mhbOp->getDereferenceableSize(), 1);
92 EXPECT_EQ(mhbNode->input(0)->origin(), &a1);
93 EXPECT_EQ(mhbNode->input(1)->origin(), &ioState);
94 }
95
96 {
97 // We expect that nothing happened with mhbNode3
98 EXPECT_EQ(x3.origin(), mhbNode3.output(0));
99 }
100
101 {
102 // We expect that nothing happened with mhbNode4
103 EXPECT_EQ(x4.origin(), mhbNode4.output(0));
104 }
105
106 {
107 // We expect that nothing happened with mhbNode5
108 EXPECT_EQ(ptrExitVar.branchResult[0]->origin(), mhbNode5.output(0));
109 }
110}
111
112}
static std::shared_ptr< const IOStateType > Create()
Definition types.cpp:343
static std::optional< std::vector< rvsdg::Output * > > normalizeNestedMemoryHoistBarriers(const MemoryHoistBarrierOperation &lowerMhbOp, const std::vector< rvsdg::Output * > &operands)
Definition IOBarrier.cpp:56
static rvsdg::SimpleNode & createNode(rvsdg::Output &address, rvsdg::Output &ioState, const std::size_t dereferenceableSize)
static std::shared_ptr< const PointerType > Create()
Definition types.cpp:45
Region & GetRootRegion() const noexcept
Definition graph.hpp:99
Global memory state passed between functions.
TEST(ControlOperationsTests, foldConstants)
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872