6 #include <gtest/gtest.h>
14 TEST(DeltaTests, TestDeltaCreation)
20 auto valueType = TestType::createValueType();
35 auto dep = delta1->AddContextVar(*imp).inner;
36 auto d1 = &delta1->finalize(
37 TestOperation::createNode(delta1->subregion(), { dep }, { valueType })->output(0));
48 auto d2 = &delta2->finalize(
49 TestOperation::createNode(delta2->subregion(), {}, { valueType })->output(0));
51 GraphExport::Create(*d1,
"");
52 GraphExport::Create(*d2,
"");
59 EXPECT_TRUE(delta1->constant());
60 EXPECT_EQ(*delta1->Type(), *valueType);
62 EXPECT_FALSE(delta2->constant());
63 EXPECT_EQ(*delta2->Type(), *valueType);
66 TEST(DeltaTests, TestRemoveDeltaInputsWhere)
72 auto valueType = TestType::createValueType();
80 auto deltaInput0 = deltaNode->AddContextVar(*x).input;
81 auto deltaInput1 = deltaNode->AddContextVar(*x).input;
82 deltaNode->AddContextVar(*x);
84 auto result = jlm::rvsdg::CreateOpNode<TestOperation>(
85 { deltaNode->MapInputContextVar(*deltaInput1).inner },
86 std::vector<std::shared_ptr<const Type>>{ valueType },
87 std::vector<std::shared_ptr<const Type>>{ valueType })
90 deltaNode->finalize(result);
94 auto numRemovedInputs = deltaNode->RemoveDeltaInputsWhere(
97 return input.
index() == deltaInput1->index();
99 EXPECT_EQ(numRemovedInputs, 0u);
100 EXPECT_EQ(deltaNode->ninputs(), 3u);
101 EXPECT_EQ(deltaNode->GetContextVars().size(), 3u);
104 numRemovedInputs = deltaNode->RemoveDeltaInputsWhere(
107 return input.
index() == 2;
109 EXPECT_EQ(numRemovedInputs, 1u);
110 EXPECT_EQ(deltaNode->ninputs(), 2u);
111 EXPECT_EQ(deltaNode->GetContextVars().size(), 2u);
112 EXPECT_EQ(deltaNode->input(0), deltaInput0);
113 EXPECT_EQ(deltaNode->input(1), deltaInput1);
116 numRemovedInputs = deltaNode->RemoveDeltaInputsWhere(
119 return input.
index() == 0;
121 EXPECT_EQ(numRemovedInputs, 1u);
122 EXPECT_EQ(deltaNode->ninputs(), 1u);
123 EXPECT_EQ(deltaNode->GetContextVars().size(), 1u);
124 EXPECT_EQ(deltaNode->input(0), deltaInput1);
125 EXPECT_EQ(deltaInput1->index(), 0u);
126 EXPECT_EQ(deltaNode->MapInputContextVar(*deltaInput1).inner->index(), 0u);
129 TEST(DeltaTests, TestPruneDeltaInputs)
135 auto valueType = TestType::createValueType();
144 deltaNode->AddContextVar(*x);
145 auto deltaInput1 = deltaNode->AddContextVar(*x).input;
146 deltaNode->AddContextVar(*x);
148 auto result = jlm::rvsdg::CreateOpNode<TestOperation>(
149 { deltaNode->MapInputContextVar(*deltaInput1).inner },
150 std::vector<std::shared_ptr<const Type>>{ valueType },
151 std::vector<std::shared_ptr<const Type>>{ valueType })
154 deltaNode->finalize(result);
157 auto numRemovedInputs = deltaNode->PruneDeltaInputs();
160 EXPECT_EQ(numRemovedInputs, 2u);
161 EXPECT_EQ(deltaNode->ninputs(), 1u);
162 EXPECT_EQ(deltaNode->GetContextVars().size(), 1u);
163 EXPECT_EQ(deltaNode->input(0), deltaInput1);
164 EXPECT_EQ(deltaNode->subregion()->argument(0), deltaNode->MapInputContextVar(*deltaInput1).inner);
165 EXPECT_EQ(deltaInput1->index(), 0u);
166 EXPECT_EQ(deltaNode->MapInputContextVar(*deltaInput1).inner->index(), 0u);
TEST(DeltaTests, TestDeltaCreation)
static std::unique_ptr< DeltaOperation > Create(std::shared_ptr< const rvsdg::Type > type, const std::string &name, const Linkage &linkage, std::string section, bool constant, const size_t alignment)
static std::shared_ptr< const PointerType > Create()
static DeltaNode * Create(rvsdg::Region *parent, std::unique_ptr< DeltaOperation > op)
static GraphImport & Create(Graph &graph, std::shared_ptr< const rvsdg::Type > type, std::string name)
Region & GetRootRegion() const noexcept
size_t numNodes() const noexcept
Global memory state passed between functions.
std::string view(const rvsdg::Region *region)