Jlm
call.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 
7 #include <jlm/llvm/ir/Trace.hpp>
8 #include <jlm/rvsdg/theta.hpp>
9 
10 namespace jlm::llvm
11 {
12 
13 /*
14  * CallOperation class
15  */
16 
18 
19 bool
20 CallOperation::operator==(const Operation & other) const noexcept
21 {
22  auto callOperation = dynamic_cast<const CallOperation *>(&other);
23  return callOperation && FunctionType_ == callOperation->FunctionType_;
24 }
25 
26 std::string
28 {
29  return "CALL";
30 }
31 
32 std::unique_ptr<rvsdg::Operation>
34 {
35  return std::make_unique<CallOperation>(*this);
36 }
37 
40 {
41  JLM_ASSERT(is<CallOperation>(&callNode));
42  const auto origin = GetFunctionInput(callNode).origin();
43  return llvm::traceOutput(*origin);
44 }
45 
46 std::unique_ptr<CallTypeClassifier>
48 {
49  JLM_ASSERT(is<CallOperation>(&callNode));
50  auto & output = TraceFunctionInput(callNode);
51 
52  if (rvsdg::TryGetOwnerNode<rvsdg::LambdaNode>(output))
53  {
55  }
56 
57  if (auto phi = rvsdg::TryGetRegionParentNode<rvsdg::PhiNode>(output))
58  {
59  if (auto fix = phi->MapArgumentFixVar(output))
60  {
62  }
63  }
64 
65  if (auto argument = dynamic_cast<rvsdg::RegionArgument *>(&output))
66  {
67  if (argument->region() == &argument->region()->graph()->GetRootRegion())
68  {
70  }
71  }
72 
74 }
75 
76 bool
78 {
79  if (!IsExternalCall())
80  return false;
81 
82  if (const auto graphImport = dynamic_cast<const LlvmGraphImport *>(&GetImport()))
83  {
84  // In C and C++, setjmp is a macro to some underlying function. Clang uses _setjmp
85  return graphImport->Name() == "_setjmp";
86  }
87 
88  return false;
89 }
90 
91 bool
93 {
94  if (!IsExternalCall())
95  return false;
96 
97  if (const auto graphImport = dynamic_cast<const LlvmGraphImport *>(&GetImport()))
98  {
99  // LLVM intrinsics can contain extra suffixes like .p0, so check its prefix
100  return graphImport->Name().rfind("llvm.va_start", 0) == 0;
101  }
102 
103  return false;
104 }
105 
106 }
Call operation class.
Definition: call.hpp:249
std::shared_ptr< const rvsdg::FunctionType > FunctionType_
Definition: call.hpp:538
static rvsdg::Input & GetFunctionInput(const rvsdg::Node &node) noexcept
Definition: call.hpp:302
std::unique_ptr< Operation > copy() const override
Definition: call.cpp:33
static std::unique_ptr< CallTypeClassifier > ClassifyCall(const rvsdg::SimpleNode &callNode)
Classifies a call node.
Definition: call.cpp:47
static rvsdg::Output & TraceFunctionInput(const rvsdg::SimpleNode &callNode)
Traces function input of call node.
Definition: call.cpp:39
bool operator==(const Operation &other) const noexcept override
Definition: call.cpp:20
std::string debug_string() const override
Definition: call.cpp:27
bool IsExternalCall() const noexcept
Determines whether call is an external call.
Definition: call.hpp:100
static std::unique_ptr< CallTypeClassifier > CreateExternalCallClassifier(rvsdg::RegionArgument &argument)
Classify callee as external.
Definition: call.hpp:222
static std::unique_ptr< CallTypeClassifier > CreateIndirectCallClassifier(jlm::rvsdg::Output &output)
Classify callee as inderict.
Definition: call.hpp:235
static std::unique_ptr< CallTypeClassifier > CreateNonRecursiveDirectCallClassifier(rvsdg::Output &output)
Classify callee as non-recursive.
Definition: call.hpp:191
rvsdg::RegionArgument & GetImport() const noexcept
Returns the imported function.
Definition: call.hpp:147
static std::unique_ptr< CallTypeClassifier > CreateRecursiveDirectCallClassifier(rvsdg::Output &output)
Classify callee as recursive.
Definition: call.hpp:207
Output * origin() const noexcept
Definition: node.hpp:58
Represents the argument of a region.
Definition: region.hpp:41
const std::shared_ptr< const rvsdg::Type > & argument(size_t index) const noexcept
Definition: operation.cpp:23
#define JLM_ASSERT(x)
Definition: common.hpp:16
Global memory state passed between functions.
rvsdg::Output & traceOutput(rvsdg::Output &output)
Definition: Trace.cpp:39