Jlm
Loading...
Searching...
No Matches
IOBarrier.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
8#include <jlm/util/strfmt.hpp>
9
10namespace jlm::llvm
11{
12
14
15bool
16IOBarrierOperation::operator==(const Operation & other) const noexcept
17{
18 const auto ioBarrier = dynamic_cast<const IOBarrierOperation *>(&other);
19 return ioBarrier && ioBarrier->Type() == Type();
20}
21
22std::string
24{
25 return "IOBarrier";
26}
27
28std::unique_ptr<rvsdg::Operation>
30{
31 return std::make_unique<IOBarrierOperation>(*this);
32}
33
35
36bool
37MemoryHoistBarrierOperation::operator==(const Operation & other) const noexcept
38{
39 const auto hoistBarrier = dynamic_cast<const MemoryHoistBarrierOperation *>(&other);
40 return hoistBarrier && hoistBarrier->getDereferenceableSize() == getDereferenceableSize();
41}
42
43std::string
45{
46 return util::strfmt("MemoryHoistBarrier[", getDereferenceableSize(), "]");
47}
48
49std::unique_ptr<rvsdg::Operation>
51{
52 return std::make_unique<MemoryHoistBarrierOperation>(*this);
53}
54
55std::optional<std::vector<rvsdg::Output *>>
57 const MemoryHoistBarrierOperation & lowerMhbOp,
58 const std::vector<rvsdg::Output *> & operands)
59{
60 JLM_ASSERT(operands.size() == 2);
61 auto & lowerMhbAddressOperand = *operands[0];
62 auto & lowerMhbIOStateOperand = *operands[1];
63
64 OutputTracer tracer;
68
69 auto & tracedLowerMhbAddressOperand = tracer.trace(lowerMhbAddressOperand, nullptr);
70 auto [upperMhbNode, upperMhbOp] =
72 tracedLowerMhbAddressOperand);
73 if (!upperMhbOp)
74 {
75 return std::nullopt;
76 }
77
78 if (upperMhbNode->region() != lowerMhbAddressOperand.region())
79 {
80 return std::nullopt;
81 }
82
83 auto & upperMhbAddressOperand = *getAddressInput(*upperMhbNode).origin();
84 auto & upperMhbIOStateOperand = *getIOStateInput(*upperMhbNode).origin();
85
86 const auto & tracedUpperMhbIOStateOperand = tracer.trace(upperMhbIOStateOperand, nullptr);
87 const auto & tracedLowerMhbIOStateOperand = tracer.trace(lowerMhbIOStateOperand, nullptr);
88 if (&tracedLowerMhbIOStateOperand != &tracedUpperMhbIOStateOperand)
89 {
90 return std::nullopt;
91 }
92
93 auto & newMhbNode = createNode(
94 upperMhbAddressOperand,
95 upperMhbIOStateOperand,
96 std::min(lowerMhbOp.getDereferenceableSize(), upperMhbOp->getDereferenceableSize()));
97 return rvsdg::outputs(&newMhbNode);
98}
99
100}
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
Definition IOBarrier.hpp:55
std::string debug_string() const override
Definition IOBarrier.cpp:23
~IOBarrierOperation() noexcept override
std::unique_ptr< Operation > copy() const override
Definition IOBarrier.cpp:29
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 rvsdg::Input & getAddressInput(const rvsdg::Node &node) noexcept
std::unique_ptr< Operation > copy() const override
Definition IOBarrier.cpp:50
~MemoryHoistBarrierOperation() noexcept override
std::size_t getDereferenceableSize() const noexcept
std::string debug_string() const override
Definition IOBarrier.cpp:44
static rvsdg::Input & getIOStateInput(const rvsdg::Node &node) noexcept
void setTracingThroughHoistBarriers(const bool traceThroughHoistBarriers)
Definition Trace.hpp:60
Output * origin() const noexcept
Definition node.hpp:58
void setRegionPredicateCheckingEnabled(bool value) noexcept
Definition Trace.hpp:165
Output & trace(Output &output)
Definition Trace.cpp:21
void setStructuralNodePolicy(StructuralNodePolicy value) noexcept
Definition Trace.hpp:106
#define JLM_ASSERT(x)
Definition common.hpp:16
Global memory state passed between functions.
static std::vector< jlm::rvsdg::Output * > outputs(const Node *node)
Definition node.hpp:1058
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
static std::string strfmt(Args... args)
Definition strfmt.hpp:35