19TEST(ConversionOperationsTests, SExtConstantFolding)
34 auto & x1 = GraphExport::Create(*node1.output(0),
"x1");
35 auto & x2 = GraphExport::Create(*node2.output(0),
"x2");
49 auto [_, op] = TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*x1.origin());
51 EXPECT_EQ(op->Representation().to_uint(), 0u);
52 EXPECT_EQ(op->Representation().nbits(), 32u);
56 auto [_, op] = TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*x2.origin());
58 EXPECT_EQ(op->Representation().to_int(), -1);
59 EXPECT_EQ(op->Representation().nbits(), 32u);
63TEST(ConversionOperationsTests, ZExtConstantFolding)
78 auto & x1 = GraphExport::Create(*node1.output(0),
"x1");
79 auto & x2 = GraphExport::Create(*node2.output(0),
"x2");
93 auto [_, op] = TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*x1.origin());
95 EXPECT_EQ(op->Representation().to_uint(), 0u);
96 EXPECT_EQ(op->Representation().nbits(), 32u);
100 auto [_, op] = TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*x2.origin());
102 EXPECT_EQ(op->Representation().to_int(), 1);
103 EXPECT_EQ(op->Representation().nbits(), 32u);
107TEST(ConversionOperationsTests, TruncConstantFolding)
112 auto i1Type = BitType::Create(1);
124 auto & x1 = GraphExport::Create(*node1.output(0),
"x1");
125 auto & x2 = GraphExport::Create(*node2.output(0),
"x2");
139 auto [_, op] = TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*x1.origin());
141 EXPECT_EQ(op->Representation().to_uint(), 0u);
142 EXPECT_EQ(op->Representation().nbits(), 1u);
146 auto [_, op] = TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*x2.origin());
148 EXPECT_EQ(op->Representation().to_uint(), 1u);
149 EXPECT_EQ(op->Representation().nbits(), 1u);
153TEST(ConversionOperationsTests, FunctionToPointerInversion)
158 auto valueType = TestType::createValueType();
160 auto functionType = FunctionType::Create({ valueType }, { valueType });
164 auto & i0 = GraphImport::Create(graph, pointerType,
"i0");
165 auto & i1 = GraphImport::Create(graph, functionType,
"i1");
169 auto & fnToPtrNode1 =
174 auto & x1 = GraphExport::Create(*fnToPtrNode1.output(0),
"x1");
175 auto & x2 = GraphExport::Create(*fnToPtrNode2.output(0),
"x2");
180 ReduceNode<FunctionToPointerOperation>(
184 ReduceNode<FunctionToPointerOperation>(
195 EXPECT_EQ(x1.origin(), &i0);
200 auto [_, op] = TryGetSimpleNodeAndOptionalOp<FunctionToPointerOperation>(*x2.origin());
201 EXPECT_NE(op,
nullptr);
205TEST(ConversionOperationsTests, PointerToFunctionInversion)
210 auto stateType = TestType::createStateType();
211 auto valueType = TestType::createValueType();
213 auto functionType1 = FunctionType::Create({ valueType }, { valueType });
214 auto functionType2 = FunctionType::Create({ stateType }, { stateType });
218 auto & i0 = GraphImport::Create(graph, functionType1,
"i0");
222 auto & ptrToFnNode1 =
225 auto & ptrToFnNode2 =
228 auto & x1 = GraphExport::Create(*ptrToFnNode1.output(0),
"x1");
229 auto & x2 = GraphExport::Create(*ptrToFnNode2.output(0),
"x2");
234 ReduceNode<PointerToFunctionOperation>(
238 ReduceNode<PointerToFunctionOperation>(
249 EXPECT_EQ(x1.origin(), &i0);
255 auto [_, op] = TryGetSimpleNodeAndOptionalOp<PointerToFunctionOperation>(*x2.origin());
256 EXPECT_NE(op,
nullptr);