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()));
118 const auto storeOperation = util::assertedCast<const StoreOperation>(&node.GetOperation());
119 if (storeOperation->NumMemoryStates_ == 0)
124 const auto firstMemoryStateInput =
125 node.input(storeOperation->narguments() - storeOperation->NumMemoryStates_);
126 JLM_ASSERT(is<MemoryStateType>(firstMemoryStateInput->Type()));
138 [[nodiscard]]
static std::vector<rvsdg::Output *>
141 std::vector<rvsdg::Output *> operands;
143 operands.push_back(input.origin());
157 JLM_ASSERT(storeNode->ninputs() - 2 == storeNode->noutputs());
158 const auto input = storeNode->input(output.
index() + 2);
159 JLM_ASSERT(is<MemoryStateType>(input->Type()));
179 std::shared_ptr<const rvsdg::Type> storedType,
180 const
size_t numMemoryStates,
181 const
size_t alignment)
190 operator==(
const Operation & other)
const noexcept override;
192 [[nodiscard]] std::string
195 [[nodiscard]] std::unique_ptr<Operation>
196 copy()
const override;
216 static std::optional<std::vector<rvsdg::Output *>>
218 const StoreNonVolatileOperation & operation,
219 const std::vector<rvsdg::Output *> & operands);
235 static std::optional<std::vector<rvsdg::Output *>>
237 const StoreNonVolatileOperation & store2Op,
238 const std::vector<rvsdg::Output *> & operands);
258 static std::optional<std::vector<rvsdg::Output *>>
260 const StoreNonVolatileOperation & operation,
261 const std::vector<rvsdg::Output *> & operands);
276 static std::optional<std::vector<rvsdg::Output *>>
278 const StoreNonVolatileOperation & operation,
279 const std::vector<rvsdg::Output *> & operands);
302 static std::optional<std::vector<rvsdg::Output *>>
304 const StoreNonVolatileOperation & storeOperation,
305 const std::vector<rvsdg::Output *> & operands);
319 static std::optional<std::vector<rvsdg::Output *>>
321 const StoreNonVolatileOperation & operation,
322 const std::vector<rvsdg::Output *> & operands);
324 static std::unique_ptr<llvm::ThreeAddressCode>
329 auto op = std::make_unique<StoreNonVolatileOperation>(storedType, 1, alignment);
333 static std::vector<rvsdg::Output *>
337 const std::vector<rvsdg::Output *> & memoryStates,
340 return outputs(&
CreateNode(*address, *value, memoryStates, alignment));
347 const std::vector<rvsdg::Output *> & memoryStates,
352 std::vector operands({ &address, &value });
353 operands.insert(operands.end(), memoryStates.begin(), memoryStates.end());
355 auto operation = std::make_unique<StoreNonVolatileOperation>(
356 std::move(storedType),
362 static std::vector<rvsdg::Output *>
365 std::unique_ptr<StoreNonVolatileOperation> storeOperation,
366 const std::vector<rvsdg::Output *> & operands)
368 return outputs(&
CreateNode(region, std::move(storeOperation), operands));
374 std::unique_ptr<StoreNonVolatileOperation> storeOperation,
375 const std::vector<rvsdg::Output *> & operands)
381 static const std::shared_ptr<const jlm::rvsdg::Type>
392 static std::vector<std::shared_ptr<const rvsdg::Type>>
395 std::vector<std::shared_ptr<const rvsdg::Type>> types(
397 std::vector<std::shared_ptr<const rvsdg::Type>> states(
400 types.insert(types.end(), states.begin(), states.end());
422 std::shared_ptr<const rvsdg::Type> storedType,
423 const
size_t numMemoryStates,
424 const
size_t alignment)
433 operator==(
const Operation & other)
const noexcept override;
435 [[nodiscard]] std::string
438 [[nodiscard]] std::unique_ptr<Operation>
439 copy()
const override;
445 auto & input = *node.input(2);
454 auto & output = *node.output(0);
459 static std::unique_ptr<llvm::ThreeAddressCode>
469 auto op = std::make_unique<StoreVolatileOperation>(storedType, 1, alignment);
476 std::unique_ptr<StoreVolatileOperation> storeOperation,
477 const std::vector<rvsdg::Output *> & operands)
487 const std::vector<rvsdg::Output *> & memoryStates,
492 std::vector<rvsdg::Output *> operands({ &address, &value, &ioState });
493 operands.insert(operands.end(), memoryStates.begin(), memoryStates.end());
496 std::make_unique<StoreVolatileOperation>(storedType, memoryStates.size(), alignment);
500 static std::vector<rvsdg::Output *>
503 std::unique_ptr<StoreVolatileOperation> storeOperation,
504 const std::vector<rvsdg::Output *> & operands)
510 static std::shared_ptr<const rvsdg::Type>
519 static std::vector<std::shared_ptr<const rvsdg::Type>>
522 std::vector<std::shared_ptr<const rvsdg::Type>> types(
524 std::vector<std::shared_ptr<const rvsdg::Type>> states(
527 types.insert(types.end(), states.begin(), states.end());
531 static std::vector<std::shared_ptr<const rvsdg::Type>>
535 std::vector<std::shared_ptr<const rvsdg::Type>> memoryStates(
538 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 std::optional< std::vector< rvsdg::Output * > > normalizeStoreStore(const StoreNonVolatileOperation &store2Op, const std::vector< rvsdg::Output * > &operands)
Removes a duplicated store to the same address.
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::optional< std::vector< rvsdg::Output * > > normalizeIOBarrierAddress(const StoreNonVolatileOperation &storeOperation, const std::vector< rvsdg::Output * > &operands)
Redirect the address operand of the StoreNonVolatileOperation node from an IOBarrierOperation node wh...
static std::unique_ptr< llvm::ThreeAddressCode > Create(const Variable *address, const Variable *value, const Variable *state, size_t alignment)
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::vector< rvsdg::Output * > Create(rvsdg::Output *address, rvsdg::Output *value, const std::vector< rvsdg::Output * > &memoryStates, size_t alignment)
static std::vector< std::shared_ptr< const rvsdg::Type > > CreateOperandTypes(std::shared_ptr< const rvsdg::Type > storedType, size_t numMemoryStates)
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::vector< rvsdg::Output * > Create(rvsdg::Region ®ion, std::unique_ptr< StoreNonVolatileOperation > storeOperation, const std::vector< rvsdg::Output * > &operands)
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 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 * > > NormalizeDuplicateStates(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Remove duplicated state operands.
static std::vector< rvsdg::Output * > getMemoryStateOperands(const rvsdg::Node &node) noexcept
static rvsdg::Input & StoredValueInput(const rvsdg::Node &node) noexcept
static rvsdg::Input & MapMemoryStateOutputToInput(const rvsdg::Output &output)
size_t GetAlignment() const noexcept
static rvsdg::Input & AddressInput(const rvsdg::Node &node) 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::Node::OutputIteratorRange MemoryStateOutputs(const rvsdg::Node &node) noexcept
static rvsdg::Node::InputIteratorRange getMemoryStateInputs(const rvsdg::Node &node) noexcept
const rvsdg::Type & GetStoredType() const noexcept
size_t NumMemoryStates() const noexcept
bool operator==(const Operation &other) const noexcept override
std::string debug_string() const override
~StoreVolatileOperation() noexcept override
static rvsdg::Output & IOStateOutput(const rvsdg::Node &node) noexcept
static std::vector< std::shared_ptr< const rvsdg::Type > > CreateResultTypes(size_t numMemoryStates)
std::unique_ptr< Operation > copy() const override
static std::vector< std::shared_ptr< const rvsdg::Type > > CreateOperandTypes(std::shared_ptr< const rvsdg::Type > storedType, size_t numMemoryStates)
static std::vector< rvsdg::Output * > Create(rvsdg::Region ®ion, std::unique_ptr< StoreVolatileOperation > storeOperation, const std::vector< rvsdg::Output * > &operands)
static rvsdg::Input & IOStateInput(const rvsdg::Node &node) noexcept
static std::unique_ptr< llvm::ThreeAddressCode > Create(const Variable *address, const Variable *value, const Variable *ioState, const Variable *memoryState, size_t alignment)
static std::shared_ptr< const rvsdg::Type > CheckAndExtractStoredType(const std::shared_ptr< const rvsdg::Type > &type)
static rvsdg::SimpleNode & CreateNode(rvsdg::Output &address, rvsdg::Output &value, rvsdg::Output &ioState, const std::vector< rvsdg::Output * > &memoryStates, size_t alignment)
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(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
size_t index() const noexcept
const std::shared_ptr< const rvsdg::Type > & Type() 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::vector< jlm::rvsdg::Output * > outputs(const Node *node)
@ State
Designate a state type.
@ Value
Designate a value type.
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.