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()));
137 auto [storeNode, storeOperation] = rvsdg::TryGetSimpleNodeAndOptionalOp<StoreOperation>(output);
139 JLM_ASSERT(storeNode->ninputs() - 2 == storeNode->noutputs());
140 const auto input = storeNode->input(output.
index() + 2);
141 JLM_ASSERT(is<MemoryStateType>(input->Type()));
161 std::shared_ptr<const rvsdg::Type> storedType,
162 const
size_t numMemoryStates,
163 const
size_t alignment)
172 operator==(
const Operation & other)
const noexcept
override;
174 [[nodiscard]] std::string
177 [[nodiscard]] std::unique_ptr<Operation>
178 copy()
const override;
198 static std::optional<std::vector<rvsdg::Output *>>
201 const std::vector<rvsdg::Output *> &
operands);
217 static std::optional<std::vector<rvsdg::Output *>>
220 const std::vector<rvsdg::Output *> &
operands);
240 static std::optional<std::vector<rvsdg::Output *>>
243 const std::vector<rvsdg::Output *> &
operands);
258 static std::optional<std::vector<rvsdg::Output *>>
261 const std::vector<rvsdg::Output *> &
operands);
281 static std::optional<std::vector<rvsdg::Output *>>
284 const std::vector<rvsdg::Output *> &
operands);
298 static std::optional<std::vector<rvsdg::Output *>>
301 const std::vector<rvsdg::Output *> &
operands);
303 static std::unique_ptr<llvm::ThreeAddressCode>
308 auto op = std::make_unique<StoreNonVolatileOperation>(storedType, 1, alignment);
312 static std::vector<rvsdg::Output *>
316 const std::vector<rvsdg::Output *> & memoryStates,
326 const std::vector<rvsdg::Output *> & memoryStates,
331 std::vector
operands({ &address, &value });
334 auto operation = std::make_unique<StoreNonVolatileOperation>(
335 std::move(storedType),
341 static std::vector<rvsdg::Output *>
344 std::unique_ptr<StoreNonVolatileOperation> storeOperation,
345 const std::vector<rvsdg::Output *> &
operands)
353 std::unique_ptr<StoreNonVolatileOperation> storeOperation,
354 const std::vector<rvsdg::Output *> &
operands)
360 static const std::shared_ptr<const jlm::rvsdg::Type>
371 static std::vector<std::shared_ptr<const rvsdg::Type>>
374 std::vector<std::shared_ptr<const rvsdg::Type>> types(
376 std::vector<std::shared_ptr<const rvsdg::Type>> states(
379 types.insert(types.end(), states.begin(), states.end());
401 std::shared_ptr<const rvsdg::Type> storedType,
402 const
size_t numMemoryStates,
403 const
size_t alignment)
412 operator==(
const Operation & other)
const noexcept
override;
414 [[nodiscard]] std::string
417 [[nodiscard]] std::unique_ptr<Operation>
418 copy()
const override;
424 auto & input = *node.input(2);
433 auto & output = *node.output(0);
438 static std::unique_ptr<llvm::ThreeAddressCode>
448 auto op = std::make_unique<StoreVolatileOperation>(storedType, 1, alignment);
455 std::unique_ptr<StoreVolatileOperation> storeOperation,
456 const std::vector<rvsdg::Output *> &
operands)
466 const std::vector<rvsdg::Output *> & memoryStates,
471 std::vector<rvsdg::Output *>
operands({ &address, &value, &ioState });
475 std::make_unique<StoreVolatileOperation>(storedType, memoryStates.size(), alignment);
479 static std::vector<rvsdg::Output *>
482 std::unique_ptr<StoreVolatileOperation> storeOperation,
483 const std::vector<rvsdg::Output *> &
operands)
489 static std::shared_ptr<const rvsdg::Type>
498 static std::vector<std::shared_ptr<const rvsdg::Type>>
501 std::vector<std::shared_ptr<const rvsdg::Type>> types(
503 std::vector<std::shared_ptr<const rvsdg::Type>> states(
506 types.insert(types.end(), states.begin(), states.end());
510 static std::vector<std::shared_ptr<const rvsdg::Type>>
514 std::vector<std::shared_ptr<const rvsdg::Type>> memoryStates(
517 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::Node::OutputIteratorRange MemoryStateOutputs(const rvsdg::Node &node) noexcept
static rvsdg::Node::InputIteratorRange getMemoryStateInputs(const rvsdg::Node &node) noexcept
static rvsdg::Input & MapMemoryStateOutputToInput(const rvsdg::Output &output)
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.
@ 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)