6 #ifndef JLM_LLVM_IR_OPERATORS_STORE_HPP
7 #define JLM_LLVM_IR_OPERATORS_STORE_HPP
29 const std::vector<std::shared_ptr<const rvsdg::Type>> & operandTypes,
30 const std::vector<std::shared_ptr<const rvsdg::Type>> & resultTypes,
31 size_t numMemoryStates,
39 auto & addressType = *operandTypes[0];
42 auto & storedType = *operandTypes[1];
45 JLM_ASSERT(operandTypes.size() == resultTypes.size() + 2);
46 for (
size_t n = 0; n < resultTypes.size(); n++)
48 auto & operandType = *operandTypes[n + 2];
49 auto & resultType = *resultTypes[n];
78 auto & input = *node.input(0);
87 auto & input = *node.input(1);
95 const auto storeOperation = util::assertedCast<const StoreOperation>(&node.GetOperation());
96 if (storeOperation->NumMemoryStates_ == 0)
101 const auto firstMemoryStateOutput =
102 node.output(storeOperation->nresults() - storeOperation->NumMemoryStates_);
103 JLM_ASSERT(is<MemoryStateType>(firstMemoryStateOutput->Type()));
114 auto [storeNode, storeOperation] = rvsdg::TryGetSimpleNodeAndOptionalOp<StoreOperation>(output);
116 JLM_ASSERT(storeNode->ninputs() - 2 == storeNode->noutputs());
117 const auto input = storeNode->input(output.
index() + 2);
118 JLM_ASSERT(is<MemoryStateType>(input->Type()));
138 std::shared_ptr<const rvsdg::Type> storedType,
139 const
size_t numMemoryStates,
140 const
size_t alignment)
149 operator==(
const Operation & other)
const noexcept
override;
151 [[nodiscard]] std::string
154 [[nodiscard]] std::unique_ptr<Operation>
155 copy()
const override;
175 static std::optional<std::vector<rvsdg::Output *>>
178 const std::vector<rvsdg::Output *> &
operands);
194 static std::optional<std::vector<rvsdg::Output *>>
197 const std::vector<rvsdg::Output *> &
operands);
217 static std::optional<std::vector<rvsdg::Output *>>
220 const std::vector<rvsdg::Output *> &
operands);
235 static std::optional<std::vector<rvsdg::Output *>>
238 const std::vector<rvsdg::Output *> &
operands);
258 static std::optional<std::vector<rvsdg::Output *>>
261 const std::vector<rvsdg::Output *> &
operands);
275 static std::optional<std::vector<rvsdg::Output *>>
278 const std::vector<rvsdg::Output *> &
operands);
280 static std::unique_ptr<llvm::ThreeAddressCode>
285 auto op = std::make_unique<StoreNonVolatileOperation>(storedType, 1, alignment);
289 static std::vector<rvsdg::Output *>
293 const std::vector<rvsdg::Output *> & memoryStates,
303 const std::vector<rvsdg::Output *> & memoryStates,
308 std::vector
operands({ &address, &value });
311 auto operation = std::make_unique<StoreNonVolatileOperation>(
312 std::move(storedType),
318 static std::vector<rvsdg::Output *>
321 std::unique_ptr<StoreNonVolatileOperation> storeOperation,
322 const std::vector<rvsdg::Output *> &
operands)
330 std::unique_ptr<StoreNonVolatileOperation> storeOperation,
331 const std::vector<rvsdg::Output *> &
operands)
337 static const std::shared_ptr<const jlm::rvsdg::Type>
348 static std::vector<std::shared_ptr<const rvsdg::Type>>
351 std::vector<std::shared_ptr<const rvsdg::Type>> types(
353 std::vector<std::shared_ptr<const rvsdg::Type>> states(
356 types.insert(types.end(), states.begin(), states.end());
378 std::shared_ptr<const rvsdg::Type> storedType,
379 const
size_t numMemoryStates,
380 const
size_t alignment)
389 operator==(
const Operation & other)
const noexcept
override;
391 [[nodiscard]] std::string
394 [[nodiscard]] std::unique_ptr<Operation>
395 copy()
const override;
401 auto & input = *node.input(2);
410 auto & output = *node.output(0);
415 static std::unique_ptr<llvm::ThreeAddressCode>
425 auto op = std::make_unique<StoreVolatileOperation>(storedType, 1, alignment);
432 std::unique_ptr<StoreVolatileOperation> storeOperation,
433 const std::vector<rvsdg::Output *> &
operands)
443 const std::vector<rvsdg::Output *> & memoryStates,
448 std::vector<rvsdg::Output *>
operands({ &address, &value, &ioState });
452 std::make_unique<StoreVolatileOperation>(storedType, memoryStates.size(), alignment);
456 static std::vector<rvsdg::Output *>
459 std::unique_ptr<StoreVolatileOperation> storeOperation,
460 const std::vector<rvsdg::Output *> &
operands)
466 static std::shared_ptr<const rvsdg::Type>
475 static std::vector<std::shared_ptr<const rvsdg::Type>>
478 std::vector<std::shared_ptr<const rvsdg::Type>> types(
480 std::vector<std::shared_ptr<const rvsdg::Type>> states(
483 types.insert(types.end(), states.begin(), states.end());
487 static std::vector<std::shared_ptr<const rvsdg::Type>>
491 std::vector<std::shared_ptr<const rvsdg::Type>> memoryStates(
494 types.insert(types.end(), memoryStates.begin(), memoryStates.end());
static std::shared_ptr< const IOStateType > Create()
static std::shared_ptr< const MemoryStateType > Create()
static std::shared_ptr< const PointerType > Create()
static rvsdg::SimpleNode & CreateNode(rvsdg::Region ®ion, std::unique_ptr< StoreNonVolatileOperation > storeOperation, const std::vector< rvsdg::Output * > &operands)
static const std::shared_ptr< const jlm::rvsdg::Type > CheckAndExtractStoredType(const std::shared_ptr< const rvsdg::Type > &type)
static std::unique_ptr< llvm::ThreeAddressCode > Create(const Variable *address, const Variable *value, const Variable *state, size_t alignment)
static std::vector< rvsdg::Output * > Create(rvsdg::Output *address, rvsdg::Output *value, const std::vector< rvsdg::Output * > &memoryStates, size_t alignment)
static std::vector< rvsdg::Output * > Create(rvsdg::Region ®ion, std::unique_ptr< StoreNonVolatileOperation > storeOperation, const std::vector< rvsdg::Output * > &operands)
static rvsdg::SimpleNode & CreateNode(rvsdg::Output &address, rvsdg::Output &value, const std::vector< rvsdg::Output * > &memoryStates, size_t alignment)
static std::optional< std::vector< rvsdg::Output * > > NormalizeIOBarrierAllocaAddress(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Redirect the address operand of the StoreNonVolatileOperation from an IOBarrierOperation when it can ...
StoreNonVolatileOperation(std::shared_ptr< const rvsdg::Type > storedType, const size_t numMemoryStates, const size_t alignment)
static std::vector< std::shared_ptr< const rvsdg::Type > > CreateOperandTypes(std::shared_ptr< const rvsdg::Type > storedType, size_t numMemoryStates)
std::string debug_string() const override
bool operator==(const Operation &other) const noexcept override
static std::optional< std::vector< rvsdg::Output * > > NormalizeStoreMux(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Swaps a memory state merge operation and a store operation.
~StoreNonVolatileOperation() noexcept override
static std::optional< std::vector< rvsdg::Output * > > normalizeStoreAllocaSingleUser(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
std::unique_ptr< Operation > copy() const override
static std::optional< std::vector< rvsdg::Output * > > NormalizeStoreAlloca(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Removes unnecessary state from a store node when its address originates directly from an alloca node.
static std::optional< std::vector< rvsdg::Output * > > NormalizeStoreStore(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Removes a duplicated store to the same address.
static std::optional< std::vector< rvsdg::Output * > > NormalizeDuplicateStates(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Remove duplicated state operands.
const rvsdg::Type & GetStoredType() const noexcept
StoreOperation(const std::vector< std::shared_ptr< const rvsdg::Type >> &operandTypes, const std::vector< std::shared_ptr< const rvsdg::Type >> &resultTypes, size_t numMemoryStates, size_t alignment)
static rvsdg::Input & StoredValueInput(const rvsdg::Node &node) noexcept
size_t GetAlignment() const noexcept
static rvsdg::Input & MapMemoryStateOutputToInput(const rvsdg::Output &output)
static rvsdg::Node::OutputIteratorRange MemoryStateOutputs(const rvsdg::SimpleNode &node) noexcept
size_t NumMemoryStates() const noexcept
static rvsdg::Input & AddressInput(const rvsdg::Node &node) noexcept
bool operator==(const Operation &other) const noexcept override
static rvsdg::Output & IOStateOutput(const rvsdg::Node &node) noexcept
static rvsdg::SimpleNode & CreateNode(rvsdg::Region ®ion, std::unique_ptr< StoreVolatileOperation > storeOperation, const std::vector< rvsdg::Output * > &operands)
static std::unique_ptr< llvm::ThreeAddressCode > Create(const Variable *address, const Variable *value, const Variable *ioState, const Variable *memoryState, size_t alignment)
std::string debug_string() const override
static std::vector< std::shared_ptr< const rvsdg::Type > > CreateOperandTypes(std::shared_ptr< const rvsdg::Type > storedType, size_t numMemoryStates)
~StoreVolatileOperation() noexcept override
static std::vector< std::shared_ptr< const rvsdg::Type > > CreateResultTypes(size_t numMemoryStates)
static rvsdg::SimpleNode & CreateNode(rvsdg::Output &address, rvsdg::Output &value, rvsdg::Output &ioState, const std::vector< rvsdg::Output * > &memoryStates, size_t alignment)
static std::shared_ptr< const rvsdg::Type > CheckAndExtractStoredType(const std::shared_ptr< const rvsdg::Type > &type)
std::unique_ptr< Operation > copy() const override
static rvsdg::Input & IOStateInput(const rvsdg::Node &node) noexcept
static std::vector< rvsdg::Output * > Create(rvsdg::Region ®ion, std::unique_ptr< StoreVolatileOperation > storeOperation, const std::vector< rvsdg::Output * > &operands)
static std::unique_ptr< llvm::ThreeAddressCode > create(std::unique_ptr< rvsdg::SimpleOperation > operation, const std::vector< const Variable * > &operands)
const std::shared_ptr< const jlm::rvsdg::Type > Type() const noexcept
rvsdg::Region * region() const noexcept
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
size_t index() const noexcept
Represent acyclic RVSDG subgraphs.
static SimpleNode & Create(Region ®ion, std::unique_ptr< Operation > operation, const std::vector< rvsdg::Output * > &operands)
const std::shared_ptr< const rvsdg::Type > & argument(size_t index) const noexcept
SimpleOperation(std::vector< std::shared_ptr< const jlm::rvsdg::Type >> operands, std::vector< std::shared_ptr< const jlm::rvsdg::Type >> results)
Global memory state passed between functions.
static std::string type(const Node *n)
@ State
Designate a state type.
@ Value
Designate a value type.
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
static std::vector< jlm::rvsdg::Output * > outputs(const Node *node)