Jlm
lambda.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
8 #include <jlm/rvsdg/gamma.hpp>
9 #include <jlm/rvsdg/theta.hpp>
10 
11 namespace jlm::llvm
12 {
13 
15 
17  std::shared_ptr<const jlm::rvsdg::FunctionType> type,
18  std::string name,
19  const jlm::llvm::Linkage & linkage,
20  jlm::llvm::AttributeSet attributes)
21  : rvsdg::LambdaOperation(std::move(type)),
22  name_(std::move(name)),
23  linkage_(linkage),
24  attributes_(std::move(attributes))
25 {
26  ArgumentAttributes_.resize(Type()->NumArguments());
27 }
28 
29 std::string
31 {
32  return util::strfmt("LAMBDA[", name(), "]");
33 }
34 
35 bool
36 LlvmLambdaOperation::operator==(const Operation & other) const noexcept
37 {
38  auto op = dynamic_cast<const LlvmLambdaOperation *>(&other);
39  return op && op->type() == type() && op->name() == name() && op->linkage() == linkage()
40  && op->attributes() == attributes();
41 }
42 
43 std::unique_ptr<rvsdg::Operation>
45 {
46  return std::make_unique<LlvmLambdaOperation>(*this);
47 }
48 
49 [[nodiscard]] const jlm::llvm::AttributeSet &
50 LlvmLambdaOperation::GetArgumentAttributes(std::size_t index) const noexcept
51 {
52  JLM_ASSERT(index < ArgumentAttributes_.size());
53  return ArgumentAttributes_[index];
54 }
55 
56 void
58  std::size_t index,
59  const jlm::llvm::AttributeSet & attributes)
60 {
61  JLM_ASSERT(index < ArgumentAttributes_.size());
63 }
64 
67 {
68  JLM_ASSERT(is<LlvmLambdaOperation>(&lambdaNode));
69  const auto functionArguments = lambdaNode.GetFunctionArguments();
70  const auto ioStateArgument = functionArguments[functionArguments.size() - 2];
71  JLM_ASSERT(is<IOStateType>(ioStateArgument->Type()));
72  return *ioStateArgument;
73 }
74 
75 }
Lambda operation.
Definition: lambda.hpp:30
LlvmLambdaOperation(std::shared_ptr< const jlm::rvsdg::FunctionType > type, std::string name, const jlm::llvm::Linkage &linkage, jlm::llvm::AttributeSet attributes)
Definition: lambda.cpp:16
std::unique_ptr< Operation > copy() const override
Definition: lambda.cpp:44
std::vector< jlm::llvm::AttributeSet > ArgumentAttributes_
Definition: lambda.hpp:107
static rvsdg::Output & getIOStateArgument(const rvsdg::LambdaNode &lambdaNode) noexcept
Definition: lambda.cpp:66
std::string debug_string() const override
Definition: lambda.cpp:30
void SetArgumentAttributes(std::size_t index, const jlm::llvm::AttributeSet &attributes)
Definition: lambda.cpp:57
bool operator==(const Operation &other) const noexcept override
Definition: lambda.cpp:36
const std::string & name() const noexcept
Definition: lambda.hpp:41
const jlm::llvm::AttributeSet & GetArgumentAttributes(std::size_t index) const noexcept
Definition: lambda.cpp:50
const jlm::llvm::AttributeSet & attributes() const noexcept
Definition: lambda.hpp:53
Lambda node.
Definition: lambda.hpp:83
const FunctionType & type() const noexcept
Definition: lambda.hpp:36
const std::shared_ptr< const FunctionType > & Type() const noexcept
Definition: lambda.hpp:42
#define JLM_ASSERT(x)
Definition: common.hpp:16
Global memory state passed between functions.
static std::string type(const Node *n)
Definition: view.cpp:255
static std::string strfmt(Args... args)
Definition: strfmt.hpp:35