Jlm
Loading...
Searching...
No Matches
OperatorsTests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#include <gtest/gtest.h>
7
14#include <jlm/rvsdg/lambda.hpp>
16
17namespace jlm::llvm
18{
19
20TEST(PtrCmpOperationTests, testNormalizeNullPointerComparison)
21{
22 using namespace jlm::rvsdg;
23
24 // Arrange
25 auto pointerType = PointerType::Create();
26 auto i32Type = BitType::Create(32);
27 auto functionType = FunctionType::Create({}, { pointerType });
28
29 Graph graph;
30
31 auto & i0 = LlvmGraphImport::create(
32 graph,
33 i32Type,
34 pointerType,
35 "i0",
38 true,
39 4);
40
41 auto deltaNode = DeltaNode::Create(
42 &graph.GetRootRegion(),
43 LlvmDeltaOperation::Create(pointerType, "delta", Linkage::externalLinkage, "", true, 4));
44 auto & ptrNullDeltaNode = ConstantPointerNullOperation::createNode(*deltaNode->subregion());
45 auto & deltaOutput = deltaNode->finalize(ptrNullDeltaNode.output(0));
46
47 auto lambdaNode = LambdaNode::Create(
48 graph.GetRootRegion(),
50 functionType,
51 "lambda",
54 {}));
55 auto & ptrNullLambdaNode = ConstantPointerNullOperation::createNode(*lambdaNode->subregion());
56 auto lambdaOutput = lambdaNode->finalize({ ptrNullLambdaNode.output(0) });
57
58 auto & fnToPtrNode = CreateOpNode<FunctionToPointerOperation>({ lambdaOutput }, functionType);
59
60 auto & oneNode = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 1);
61 auto & allocaNode = AllocaOperation::createNode(i32Type, *oneNode.output(0), 4);
62
63 auto & cPtrNullNode = ConstantPointerNullOperation::createNode(graph.GetRootRegion());
64
65 auto & ptrCmpNode1 = PtrCmpOperation::createNode(
68 *cPtrNullNode.output(0));
69
70 auto & ptrCmpNode2 = PtrCmpOperation::createNode(
73 *cPtrNullNode.output(0));
74
75 auto & ptrCmpNode3 = PtrCmpOperation::createNode(ICmpPredicate::Ne, i0, *cPtrNullNode.output(0));
76
77 auto & ptrCmpNode4 =
78 PtrCmpOperation::createNode(ICmpPredicate::Ne, deltaOutput, *cPtrNullNode.output(0));
79
80 auto & ptrCmpNode5 = PtrCmpOperation::createNode(
82 *fnToPtrNode.output(0),
83 *cPtrNullNode.output(0));
84
85 auto & x1 = GraphExport::Create(*ptrCmpNode1.output(0), "x1");
86 auto & x2 = GraphExport::Create(*ptrCmpNode2.output(0), "x2");
87 auto & x3 = GraphExport::Create(*ptrCmpNode3.output(0), "x3");
88 auto & x4 = GraphExport::Create(*ptrCmpNode4.output(0), "x4");
89 auto & x5 = GraphExport::Create(*ptrCmpNode5.output(0), "x5");
90
91 // Act
97
98 // Assert
99 {
100 auto [constantNode, constantOperation] =
102 EXPECT_NE(constantOperation, nullptr);
103 EXPECT_EQ(constantOperation->Representation().nbits(), 1u);
104 EXPECT_EQ(constantOperation->Representation().to_uint(), 0u);
105 }
106
107 {
108 auto [constantNode, constantOperation] =
110 EXPECT_NE(constantOperation, nullptr);
111 EXPECT_EQ(constantOperation->Representation().nbits(), 1u);
112 EXPECT_EQ(constantOperation->Representation().to_uint(), 1u);
113 }
114
115 {
116 auto [constantNode, constantOperation] =
118 EXPECT_NE(constantOperation, nullptr);
119 EXPECT_EQ(constantOperation->Representation().nbits(), 1u);
120 EXPECT_EQ(constantOperation->Representation().to_uint(), 1u);
121 }
122
123 {
124 auto [constantNode, constantOperation] =
126 EXPECT_NE(constantOperation, nullptr);
127 EXPECT_EQ(constantOperation->Representation().nbits(), 1u);
128 EXPECT_EQ(constantOperation->Representation().to_uint(), 1u);
129 }
130
131 {
132 auto [constantNode, constantOperation] =
134 EXPECT_NE(constantOperation, nullptr);
135 EXPECT_EQ(constantOperation->Representation().nbits(), 1u);
136 EXPECT_EQ(constantOperation->Representation().to_uint(), 1u);
137 }
138}
139
140}
static rvsdg::SimpleNode & createNode(std::shared_ptr< const rvsdg::Type > allocatedType, rvsdg::Output &count, const size_t alignment)
Definition alloca.hpp:109
static rvsdg::Output & getPointerOutput(rvsdg::Node &node)
Definition alloca.hpp:74
static rvsdg::Node & createNode(rvsdg::Region &region)
static rvsdg::Node & Create(rvsdg::Region &region, IntegerValueRepresentation representation)
static std::unique_ptr< LlvmDeltaOperation > Create(std::shared_ptr< const rvsdg::Type > type, const std::string &name, const Linkage &linkage, std::string section, bool constant, const size_t alignment)
Definition delta.hpp:82
static LlvmGraphImport & create(rvsdg::Graph &graph, std::shared_ptr< const rvsdg::Type > valueType, std::shared_ptr< const rvsdg::Type > importedType, std::string name, Linkage linkage, CallingConvention callingConvention, const bool isConstant, const size_t alignment)
static std::unique_ptr< LlvmLambdaOperation > Create(std::shared_ptr< const jlm::rvsdg::FunctionType > type, std::string name, const jlm::llvm::Linkage &linkage, jlm::llvm::CallingConvention callingConvention, jlm::llvm::AttributeSet attributes)
Definition lambda.hpp:84
static std::shared_ptr< const PointerType > Create()
Definition types.cpp:45
static rvsdg::SimpleNode & createNode(const ICmpPredicate kind, rvsdg::Output &operand1, rvsdg::Output &operand2)
static std::optional< std::vector< rvsdg::Output * > > normalizeNullPointerComparison(const PtrCmpOperation &ptrCmpOperation, const std::vector< rvsdg::Output * > &operands)
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