Jlm
Loading...
Searching...
No Matches
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
8#include <jlm/rvsdg/theta.hpp>
9
10namespace jlm::llvm
11{
12
13/*
14 * CallOperation class
15 */
16
18
19bool
20CallOperation::operator==(const Operation & other) const noexcept
21{
22 const auto callOperation = dynamic_cast<const CallOperation *>(&other);
23 return callOperation && FunctionType_ == callOperation->FunctionType_
24 && callingConvention_ == callOperation->callingConvention_
25 && attributes_ == callOperation->attributes_;
26}
27
28std::string
30{
31 return "CALL";
32}
33
34std::unique_ptr<rvsdg::Operation>
36{
37 return std::make_unique<CallOperation>(*this);
38}
39
42{
43 JLM_ASSERT(is<CallOperation>(&callNode));
44 const auto origin = GetFunctionInput(callNode).origin();
45 return llvm::traceOutput(*origin);
46}
47
48std::unique_ptr<CallTypeClassifier>
50{
51 JLM_ASSERT(is<CallOperation>(&callNode));
52 auto & output = TraceFunctionInput(callNode);
53
55 {
57 }
58
60 {
61 if (auto fix = phi->MapArgumentFixVar(output))
62 {
64 }
65 }
66
67 if (auto argument = dynamic_cast<rvsdg::RegionArgument *>(&output))
68 {
69 if (argument->region() == &argument->region()->graph()->GetRootRegion())
70 {
72 }
73 }
74
76}
77
78bool
80{
81 if (!IsExternalCall())
82 return false;
83
84 if (const auto graphImport = dynamic_cast<const LlvmGraphImport *>(&GetImport()))
85 {
86 // In C and C++, setjmp is a macro to some underlying function. Clang uses _setjmp
87 return graphImport->Name() == "_setjmp";
88 }
89
90 return false;
91}
92
93bool
95{
96 if (!IsExternalCall())
97 return false;
98
99 if (const auto graphImport = dynamic_cast<const LlvmGraphImport *>(&GetImport()))
100 {
101 // LLVM intrinsics can contain extra suffixes like .p0, so check its prefix
102 return graphImport->Name().rfind("llvm.va_start", 0) == 0;
103 }
104
105 return false;
106}
107
108}
Call operation class.
Definition call.hpp:251
std::shared_ptr< const rvsdg::FunctionType > FunctionType_
Definition call.hpp:593
std::unique_ptr< Operation > copy() const override
Definition call.cpp:35
static std::unique_ptr< CallTypeClassifier > ClassifyCall(const rvsdg::SimpleNode &callNode)
Classifies a call node.
Definition call.cpp:49
static rvsdg::Output & TraceFunctionInput(const rvsdg::SimpleNode &callNode)
Traces function input of call node.
Definition call.cpp:41
static rvsdg::Input & GetFunctionInput(const rvsdg::Node &node) noexcept
Definition call.hpp:321
bool operator==(const Operation &other) const noexcept override
Definition call.cpp:20
std::string debug_string() const override
Definition call.cpp:29
bool IsExternalCall() const noexcept
Determines whether call is an external call.
Definition call.hpp:102
rvsdg::RegionArgument & GetImport() const noexcept
Returns the imported function.
Definition call.hpp:149
static std::unique_ptr< CallTypeClassifier > CreateExternalCallClassifier(rvsdg::RegionArgument &argument)
Classify callee as external.
Definition call.hpp:224
static std::unique_ptr< CallTypeClassifier > CreateIndirectCallClassifier(jlm::rvsdg::Output &output)
Classify callee as inderict.
Definition call.hpp:237
static std::unique_ptr< CallTypeClassifier > CreateNonRecursiveDirectCallClassifier(rvsdg::Output &output)
Classify callee as non-recursive.
Definition call.hpp:193
static std::unique_ptr< CallTypeClassifier > CreateRecursiveDirectCallClassifier(rvsdg::Output &output)
Classify callee as recursive.
Definition call.hpp:209
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, const rvsdg::Region *withinRegion)
Definition Trace.cpp:62
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872