Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
llvm-pass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
llvm-pass
Commits
e750dafe
Commit
e750dafe
authored
6 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
transgender complete
parent
7e7934d9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
callgirl/CallGraph.cpp
+36
-36
36 additions, 36 deletions
callgirl/CallGraph.cpp
callgirl/CallGraph.h
+96
-96
96 additions, 96 deletions
callgirl/CallGraph.h
with
132 additions
and
132 deletions
callgirl/CallGraph.cpp
+
36
−
36
View file @
e750dafe
...
...
@@ -29,16 +29,16 @@ using namespace llvm;
// Implementations of the CallGraph class methods.
//
CallGraph
::
CallGraph
(
Module
&
M
)
CallG
irlG
raph
::
CallG
irlG
raph
(
Module
&
M
)
:
M
(
M
),
ExternalCallingNode
(
getOrInsertFunction
(
nullptr
)),
CallsExternalNode
(
llvm
::
make_unique
<
CallGraphNode
>
(
nullptr
))
CallsExternalNode
(
llvm
::
make_unique
<
CallG
irlG
raphNode
>
(
nullptr
))
{
// Add every function to the call graph.
for
(
Function
&
F
:
M
)
addToCallGraph
(
&
F
);
addToCallG
irlG
raph
(
&
F
);
}
CallGraph
::
CallGraph
(
CallGraph
&&
Arg
)
CallG
irlG
raph
::
CallG
irlG
raph
(
CallG
irlG
raph
&&
Arg
)
:
M
(
Arg
.
M
),
FunctionMap
(
std
::
move
(
Arg
.
FunctionMap
)),
ExternalCallingNode
(
Arg
.
ExternalCallingNode
),
CallsExternalNode
(
std
::
move
(
Arg
.
CallsExternalNode
))
...
...
@@ -47,7 +47,7 @@ CallGraph::CallGraph(CallGraph &&Arg)
Arg
.
ExternalCallingNode
=
nullptr
;
}
CallGraph
::~
CallGraph
()
CallG
irlG
raph
::~
CallG
irlG
raph
()
{
// CallsExternalNode is not in the function map, delete it explicitly.
if
(
CallsExternalNode
)
...
...
@@ -61,9 +61,9 @@ CallGraph::~CallGraph()
#endif
}
void
CallGraph
::
addToCallGraph
(
Function
*
F
)
void
CallG
irlG
raph
::
addToCallG
irlG
raph
(
Function
*
F
)
{
CallGraphNode
*
Node
=
getOrInsertFunction
(
F
);
CallG
irlG
raphNode
*
Node
=
getOrInsertFunction
(
F
);
// If this function has external linkage or has its address taken, anything
// could call it.
...
...
@@ -93,19 +93,19 @@ void CallGraph::addToCallGraph(Function *F)
}
}
void
CallGraph
::
print
(
raw_ostream
&
OS
)
const
void
CallG
irlG
raph
::
print
(
raw_ostream
&
OS
)
const
{
// Print in a deterministic order by sorting CallGraphNodes by name. We do
// Print in a deterministic order by sorting CallG
irlG
raphNodes by name. We do
// this here to avoid slowing down the non-printing fast path.
SmallVector
<
CallGraphNode
*
,
16
>
Nodes
;
SmallVector
<
CallG
irlG
raphNode
*
,
16
>
Nodes
;
Nodes
.
reserve
(
FunctionMap
.
size
());
for
(
const
auto
&
I
:
*
this
)
Nodes
.
push_back
(
I
.
second
.
get
());
llvm
::
sort
(
Nodes
.
begin
(),
Nodes
.
end
(),
[](
CallGraphNode
*
LHS
,
CallGraphNode
*
RHS
)
{
[](
CallG
irlG
raphNode
*
LHS
,
CallG
irlG
raphNode
*
RHS
)
{
if
(
Function
*
LF
=
LHS
->
getFunction
())
if
(
Function
*
RF
=
RHS
->
getFunction
())
return
LF
->
getName
()
<
RF
->
getName
();
...
...
@@ -113,12 +113,12 @@ void CallGraph::print(raw_ostream &OS) const
return
RHS
->
getFunction
()
!=
nullptr
;
});
for
(
CallGraphNode
*
CN
:
Nodes
)
for
(
CallG
irlG
raphNode
*
CN
:
Nodes
)
CN
->
print
(
OS
);
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD
void
CallGraph
::
dump
()
const
LLVM_DUMP_METHOD
void
CallG
irlG
raph
::
dump
()
const
{
print
(
dbgs
());
}
...
...
@@ -130,7 +130,7 @@ LLVM_DUMP_METHOD void CallGraph::dump() const
// functions (ie, there are no edges in it's CGN). The easiest way to do this
// is to dropAllReferences before calling this.
//
Function
*
CallGraph
::
removeFunctionFromModule
(
CallGraphNode
*
CGN
)
Function
*
CallG
irlG
raph
::
removeFunctionFromModule
(
CallG
irlG
raphNode
*
CGN
)
{
assert
(
CGN
->
empty
()
&&
"Cannot remove function from call "
"graph if it references other functions!"
);
...
...
@@ -145,11 +145,11 @@ Function *CallGraph::removeFunctionFromModule(CallGraphNode *CGN)
/// This does not rescan the body of the function, so it is suitable when
/// splicing the body of the old function to the new while also updating all
/// callers from old to new.
void
CallGraph
::
spliceFunction
(
const
Function
*
From
,
const
Function
*
To
)
void
CallG
irlG
raph
::
spliceFunction
(
const
Function
*
From
,
const
Function
*
To
)
{
assert
(
FunctionMap
.
count
(
From
)
&&
"No CallGraphNode for function!"
);
assert
(
FunctionMap
.
count
(
From
)
&&
"No CallG
irlG
raphNode for function!"
);
assert
(
!
FunctionMap
.
count
(
To
)
&&
"Pointing CallGraphNode at a function that already exists"
);
"Pointing CallG
irlG
raphNode at a function that already exists"
);
FunctionMapTy
::
iterator
I
=
FunctionMap
.
find
(
From
);
I
->
second
->
F
=
const_cast
<
Function
*>
(
To
);
FunctionMap
[
To
]
=
std
::
move
(
I
->
second
);
...
...
@@ -157,24 +157,24 @@ void CallGraph::spliceFunction(const Function *From, const Function *To)
}
// getOrInsertFunction - This method is identical to calling operator[], but
// it will insert a new CallGraphNode for the specified function if one does
// it will insert a new CallG
irlG
raphNode for the specified function if one does
// not already exist.
CallGraphNode
*
CallGraph
::
getOrInsertFunction
(
const
Function
*
F
)
CallG
irlG
raphNode
*
CallG
irlG
raph
::
getOrInsertFunction
(
const
Function
*
F
)
{
auto
&
CGN
=
FunctionMap
[
F
];
if
(
CGN
)
return
CGN
.
get
();
assert
((
!
F
||
F
->
getParent
()
==
&
M
)
&&
"Function not in current module!"
);
CGN
=
llvm
::
make_unique
<
CallGraphNode
>
(
const_cast
<
Function
*>
(
F
));
CGN
=
llvm
::
make_unique
<
CallG
irlG
raphNode
>
(
const_cast
<
Function
*>
(
F
));
return
CGN
.
get
();
}
//===----------------------------------------------------------------------===//
// Implementations of the CallGraphNode class methods.
// Implementations of the CallG
irlG
raphNode class methods.
//
void
CallGraphNode
::
print
(
raw_ostream
&
OS
)
const
void
CallG
irlG
raphNode
::
print
(
raw_ostream
&
OS
)
const
{
if
(
Function
*
F
=
getFunction
())
OS
<<
"Call graph node for function: '"
<<
F
->
getName
()
<<
"'"
;
...
...
@@ -195,7 +195,7 @@ void CallGraphNode::print(raw_ostream &OS) const
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD
void
CallGraphNode
::
dump
()
const
LLVM_DUMP_METHOD
void
CallG
irlG
raphNode
::
dump
()
const
{
print
(
dbgs
());
}
...
...
@@ -204,7 +204,7 @@ LLVM_DUMP_METHOD void CallGraphNode::dump() const
/// removeCallEdgeFor - This method removes the edge in the node for the
/// specified call site. Note that this method takes linear time, so it
/// should be used sparingly.
void
CallGraphNode
::
removeCallEdgeFor
(
CallSite
CS
)
void
CallG
irlG
raphNode
::
removeCallEdgeFor
(
CallSite
CS
)
{
for
(
CalledFunctionsVector
::
iterator
I
=
CalledFunctions
.
begin
();;
++
I
)
{
...
...
@@ -222,7 +222,7 @@ void CallGraphNode::removeCallEdgeFor(CallSite CS)
// removeAnyCallEdgeTo - This method removes any call edges from this node to
// the specified callee function. This takes more time to execute than
// removeCallEdgeTo, so it should not be used unless necessary.
void
CallGraphNode
::
removeAnyCallEdgeTo
(
CallGraphNode
*
Callee
)
void
CallG
irlG
raphNode
::
removeAnyCallEdgeTo
(
CallG
irlG
raphNode
*
Callee
)
{
for
(
unsigned
i
=
0
,
e
=
CalledFunctions
.
size
();
i
!=
e
;
++
i
)
if
(
CalledFunctions
[
i
].
second
==
Callee
)
...
...
@@ -237,7 +237,7 @@ void CallGraphNode::removeAnyCallEdgeTo(CallGraphNode *Callee)
/// removeOneAbstractEdgeTo - Remove one edge associated with a null callsite
/// from this node to the specified callee function.
void
CallGraphNode
::
removeOneAbstractEdgeTo
(
CallGraphNode
*
Callee
)
void
CallG
irlG
raphNode
::
removeOneAbstractEdgeTo
(
CallG
irlG
raphNode
*
Callee
)
{
for
(
CalledFunctionsVector
::
iterator
I
=
CalledFunctions
.
begin
();;
++
I
)
{
...
...
@@ -256,8 +256,8 @@ void CallGraphNode::removeOneAbstractEdgeTo(CallGraphNode *Callee)
/// replaceCallEdge - This method replaces the edge in the node for the
/// specified call site with a new one. Note that this method takes linear
/// time, so it should be used sparingly.
void
CallGraphNode
::
replaceCallEdge
(
CallSite
CS
,
CallSite
NewCS
,
CallGraphNode
*
NewNode
)
void
CallG
irlG
raphNode
::
replaceCallEdge
(
CallSite
CS
,
CallSite
NewCS
,
CallG
irlG
raphNode
*
NewNode
)
{
for
(
CalledFunctionsVector
::
iterator
I
=
CalledFunctions
.
begin
();;
++
I
)
{
...
...
@@ -274,17 +274,17 @@ void CallGraphNode::replaceCallEdge(CallSite CS,
}
// Provide an explicit template instantiation for the static ID.
AnalysisKey
CallGraphAnalysis
::
Key
;
AnalysisKey
CallG
irlG
raphAnalysis
::
Key
;
PreservedAnalyses
CallGraphPrinterPass
::
run
(
Module
&
M
,
PreservedAnalyses
CallG
irlG
raphPrinterPass
::
run
(
Module
&
M
,
ModuleAnalysisManager
&
AM
)
{
AM
.
getResult
<
CallGraphAnalysis
>
(
M
).
print
(
OS
);
AM
.
getResult
<
CallG
irlG
raphAnalysis
>
(
M
).
print
(
OS
);
return
PreservedAnalyses
::
all
();
}
//===----------------------------------------------------------------------===//
// Out-of-line definitions of CallGraphAnalysis class members.
// Out-of-line definitions of CallG
irlG
raphAnalysis class members.
//
//===----------------------------------------------------------------------===//
...
...
@@ -305,12 +305,12 @@ void CallGirlGraphWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const
bool
CallGirlGraphWrapperPass
::
runOnModule
(
Module
&
M
)
{
// All the real work is done in the constructor for the CallGraph.
G
.
reset
(
new
CallGraph
(
M
));
// All the real work is done in the constructor for the CallG
irlG
raph.
G
.
reset
(
new
CallG
irlG
raph
(
M
));
return
false
;
}
static
RegisterPass
<
CallGirlGraphWrapperPass
>
X
(
"bbasiccg"
,
"CallGraph Construction"
,
static
RegisterPass
<
CallGirlGraphWrapperPass
>
X
(
"bbasiccg"
,
"CallG
irlG
raph Construction"
,
false
,
true
);
char
CallGirlGraphWrapperPass
::
ID
=
0
;
...
...
This diff is collapsed.
Click to expand it.
callgirl/CallGraph.h
+
96
−
96
View file @
e750dafe
...
...
@@ -63,7 +63,7 @@
namespace
llvm
{
class
CallGraphNode
;
class
CallG
irlG
raphNode
;
class
Module
;
class
raw_ostream
;
...
...
@@ -72,23 +72,23 @@ class raw_ostream;
/// This class exposes both the interface to the call graph for a module of IR.
///
/// The core call graph itself can also be updated to reflect changes to the IR.
class
CallGraph
class
CallG
irlG
raph
{
Module
&
M
;
using
FunctionMapTy
=
std
::
map
<
const
Function
*
,
std
::
unique_ptr
<
CallGraphNode
>>
;
std
::
map
<
const
Function
*
,
std
::
unique_ptr
<
CallG
irlG
raphNode
>>
;
/// A map from \c Function* to \c CallGraphNode*.
/// A map from \c Function* to \c CallG
irlG
raphNode*.
FunctionMapTy
FunctionMap
;
/// This node has edges to all external functions and those internal
/// functions that have their address taken.
CallGraphNode
*
ExternalCallingNode
;
CallG
irlG
raphNode
*
ExternalCallingNode
;
/// This node has edges to it from all functions making indirect calls
/// or calling an external function.
std
::
unique_ptr
<
CallGraphNode
>
CallsExternalNode
;
std
::
unique_ptr
<
CallG
irlG
raphNode
>
CallsExternalNode
;
/// Replace the function represented by this node by another.
///
...
...
@@ -99,12 +99,12 @@ class CallGraph
/// Add a function to the call graph, and link the node to all of the
/// functions that it calls.
void
addToCallGraph
(
Function
*
F
);
void
addToCallG
irlG
raph
(
Function
*
F
);
public:
explicit
CallGraph
(
Module
&
M
);
CallGraph
(
CallGraph
&&
Arg
);
~
CallGraph
();
explicit
CallG
irlG
raph
(
Module
&
M
);
CallG
irlG
raph
(
CallG
irlG
raph
&&
Arg
);
~
CallG
irlG
raph
();
void
print
(
raw_ostream
&
OS
)
const
;
void
dump
()
const
;
...
...
@@ -121,26 +121,26 @@ public:
inline
const_iterator
end
()
const
{
return
FunctionMap
.
end
();
}
/// Returns the call graph node for the provided function.
inline
const
CallGraphNode
*
operator
[](
const
Function
*
F
)
const
inline
const
CallG
irlG
raphNode
*
operator
[](
const
Function
*
F
)
const
{
const_iterator
I
=
FunctionMap
.
find
(
F
);
assert
(
I
!=
FunctionMap
.
end
()
&&
"Function not in
c
all
g
raph!"
);
assert
(
I
!=
FunctionMap
.
end
()
&&
"Function not in
C
all
GirlG
raph!"
);
return
I
->
second
.
get
();
}
/// Returns the call graph node for the provided function.
inline
CallGraphNode
*
operator
[](
const
Function
*
F
)
inline
CallG
irlG
raphNode
*
operator
[](
const
Function
*
F
)
{
const_iterator
I
=
FunctionMap
.
find
(
F
);
assert
(
I
!=
FunctionMap
.
end
()
&&
"Function not in
c
all
g
raph!"
);
assert
(
I
!=
FunctionMap
.
end
()
&&
"Function not in
C
all
GirlG
raph!"
);
return
I
->
second
.
get
();
}
/// Returns the \c CallGraphNode which is used to represent
/// undetermined calls into the
c
all
g
raph.
CallGraphNode
*
getExternalCallingNode
()
const
{
return
ExternalCallingNode
;
}
/// Returns the \c CallG
irlG
raphNode which is used to represent
/// undetermined calls into the
C
all
GirlG
raph.
CallG
irlG
raphNode
*
getExternalCallingNode
()
const
{
return
ExternalCallingNode
;
}
CallGraphNode
*
getCallsExternalNode
()
const
CallG
irlG
raphNode
*
getCallsExternalNode
()
const
{
return
CallsExternalNode
.
get
();
}
...
...
@@ -156,34 +156,34 @@ public:
/// destroyed. This is only valid if the function does not call any other
/// functions (ie, there are no edges in it's CGN). The easiest way to do
/// this is to dropAllReferences before calling this.
Function
*
removeFunctionFromModule
(
CallGraphNode
*
CGN
);
Function
*
removeFunctionFromModule
(
CallG
irlG
raphNode
*
CGN
);
/// Similar to operator[], but this will insert a new CallGraphNode for
/// Similar to operator[], but this will insert a new CallG
irlG
raphNode for
/// \c F if one does not already exist.
CallGraphNode
*
getOrInsertFunction
(
const
Function
*
F
);
CallG
irlG
raphNode
*
getOrInsertFunction
(
const
Function
*
F
);
};
/// A node in the call graph for a module.
///
/// Typically represents a function in the call graph. There are also special
/// "null" nodes used to represent theoretical entries in the call graph.
class
CallGraphNode
class
CallG
irlG
raphNode
{
public:
/// A pair of the calling instruction (a call or invoke)
/// and the call graph node being called.
using
CallRecord
=
std
::
pair
<
WeakTrackingVH
,
CallGraphNode
*>
;
using
CallRecord
=
std
::
pair
<
WeakTrackingVH
,
CallG
irlG
raphNode
*>
;
public:
using
CalledFunctionsVector
=
std
::
vector
<
CallRecord
>
;
/// Creates a node for the specified function.
inline
CallGraphNode
(
Function
*
F
)
:
F
(
F
)
{}
inline
CallG
irlG
raphNode
(
Function
*
F
)
:
F
(
F
)
{}
CallGraphNode
(
const
CallGraphNode
&
)
=
delete
;
CallGraphNode
&
operator
=
(
const
CallGraphNode
&
)
=
delete
;
CallG
irlG
raphNode
(
const
CallG
irlG
raphNode
&
)
=
delete
;
CallG
irlG
raphNode
&
operator
=
(
const
CallG
irlG
raphNode
&
)
=
delete
;
~
CallGraphNode
()
~
CallG
irlG
raphNode
()
{
assert
(
NumReferences
==
0
&&
"Node deleted while references remain"
);
}
...
...
@@ -201,12 +201,12 @@ public:
inline
bool
empty
()
const
{
return
CalledFunctions
.
empty
();
}
inline
unsigned
size
()
const
{
return
(
unsigned
)
CalledFunctions
.
size
();
}
/// Returns the number of other CallGraphNodes in this CallGraph that
/// Returns the number of other CallG
irlG
raphNodes in this CallG
irlG
raph that
/// reference this node in their callee list.
unsigned
getNumReferences
()
const
{
return
NumReferences
;
}
/// Returns the i'th called function.
CallGraphNode
*
operator
[](
unsigned
i
)
const
CallG
irlG
raphNode
*
operator
[](
unsigned
i
)
const
{
assert
(
i
<
CalledFunctions
.
size
()
&&
"Invalid index"
);
return
CalledFunctions
[
i
].
second
;
...
...
@@ -221,7 +221,7 @@ public:
// modified
//
/// Removes all edges from this CallGraphNode to any functions it
/// Removes all edges from this CallG
irlG
raphNode to any functions it
/// calls.
void
removeAllCalledFunctions
()
{
...
...
@@ -233,7 +233,7 @@ public:
}
/// Moves all the callee information from N to this node.
void
stealCalledFunctionsFrom
(
CallGraphNode
*
N
)
void
stealCalledFunctionsFrom
(
CallG
irlG
raphNode
*
N
)
{
assert
(
CalledFunctions
.
empty
()
&&
"Cannot steal callsite information if I already have some"
);
...
...
@@ -241,7 +241,7 @@ public:
}
/// Adds a function to the list of functions called by this one.
void
addCalledFunction
(
CallSite
CS
,
CallGraphNode
*
M
)
void
addCalledFunction
(
CallSite
CS
,
CallG
irlG
raphNode
*
M
)
{
assert
(
!
CS
.
getInstruction
()
||
!
CS
.
getCalledFunction
()
||
!
CS
.
getCalledFunction
()
->
isIntrinsic
()
||
...
...
@@ -267,78 +267,78 @@ public:
///
/// This takes more time to execute than removeCallEdgeTo, so it should not
/// be used unless necessary.
void
removeAnyCallEdgeTo
(
CallGraphNode
*
Callee
);
void
removeAnyCallEdgeTo
(
CallG
irlG
raphNode
*
Callee
);
/// Removes one edge associated with a null callsite from this node to
/// the specified callee function.
void
removeOneAbstractEdgeTo
(
CallGraphNode
*
Callee
);
void
removeOneAbstractEdgeTo
(
CallG
irlG
raphNode
*
Callee
);
/// Replaces the edge in the node for the specified call site with a
/// new one.
///
/// Note that this method takes linear time, so it should be used sparingly.
void
replaceCallEdge
(
CallSite
CS
,
CallSite
NewCS
,
CallGraphNode
*
NewNode
);
void
replaceCallEdge
(
CallSite
CS
,
CallSite
NewCS
,
CallG
irlG
raphNode
*
NewNode
);
private
:
friend
class
CallGraph
;
friend
class
CallG
irlG
raph
;
Function
*
F
;
std
::
vector
<
CallRecord
>
CalledFunctions
;
/// The number of times that this CallGraphNode occurs in the
/// CalledFunctions array of this or other CallGraphNodes.
/// The number of times that this CallG
irlG
raphNode occurs in the
/// CalledFunctions array of this or other CallG
irlG
raphNodes.
unsigned
NumReferences
=
0
;
void
DropRef
()
{
--
NumReferences
;
}
void
AddRef
()
{
++
NumReferences
;
}
/// A special function that should only be used by the CallGraph class.
/// A special function that should only be used by the CallG
irlG
raph class.
void
allReferencesDropped
()
{
NumReferences
=
0
;
}
};
/// An analysis pass to compute the \c CallGraph for a \c Module.
/// An analysis pass to compute the \c CallG
irlG
raph for a \c Module.
///
/// This class implements the concept of an analysis pass used by the \c
/// ModuleAnalysisManager to run an analysis over a module and cache the
/// resulting data.
class
CallGraphAnalysis
:
public
AnalysisInfoMixin
<
CallGraphAnalysis
>
class
CallG
irlG
raphAnalysis
:
public
AnalysisInfoMixin
<
CallG
irlG
raphAnalysis
>
{
friend
AnalysisInfoMixin
<
CallGraphAnalysis
>
;
friend
AnalysisInfoMixin
<
CallG
irlG
raphAnalysis
>
;
static
AnalysisKey
Key
;
public:
/// A formulaic type to inform clients of the result type.
using
Result
=
CallGraph
;
using
Result
=
CallG
irlG
raph
;
/// Compute the \c CallGraph for the module \c M.
/// Compute the \c CallG
irlG
raph for the module \c M.
///
/// The real work here is done in the \c CallGraph constructor.
CallGraph
run
(
Module
&
M
,
ModuleAnalysisManager
&
)
{
return
CallGraph
(
M
);
}
/// The real work here is done in the \c CallG
irlG
raph constructor.
CallG
irlG
raph
run
(
Module
&
M
,
ModuleAnalysisManager
&
)
{
return
CallG
irlG
raph
(
M
);
}
};
/// Printer pass for the \c CallGraphAnalysis results.
class
CallGraphPrinterPass
:
public
PassInfoMixin
<
CallGraphPrinterPass
>
/// Printer pass for the \c CallG
irlG
raphAnalysis results.
class
CallG
irlG
raphPrinterPass
:
public
PassInfoMixin
<
CallG
irlG
raphPrinterPass
>
{
raw_ostream
&
OS
;
public:
explicit
CallGraphPrinterPass
(
raw_ostream
&
OS
)
:
OS
(
OS
)
{}
explicit
CallG
irlG
raphPrinterPass
(
raw_ostream
&
OS
)
:
OS
(
OS
)
{}
PreservedAnalyses
run
(
Module
&
M
,
ModuleAnalysisManager
&
AM
);
};
/// The \c ModulePass which wraps up a \c CallGraph and the logic to
/// The \c ModulePass which wraps up a \c CallG
irlG
raph and the logic to
/// build it.
///
/// This class exposes both the interface to the call graph container and the
/// module pass which runs over a module of IR and produces the call graph. The
/// call graph interface is entirelly a wrapper around a \c CallGraph object
/// call graph interface is entirelly a wrapper around a \c CallG
irlG
raph object
/// which is stored internally for each module.
class
CallGirlGraphWrapperPass
:
public
ModulePass
{
std
::
unique_ptr
<
CallGraph
>
G
;
std
::
unique_ptr
<
CallG
irlG
raph
>
G
;
public:
static
char
ID
;
// Class identification, replacement for typeinfo
...
...
@@ -346,13 +346,13 @@ public:
CallGirlGraphWrapperPass
();
~
CallGirlGraphWrapperPass
()
override
;
/// The internal \c CallGraph around which the rest of this interface
/// The internal \c CallG
irlG
raph around which the rest of this interface
/// is wrapped.
const
CallGraph
&
getCallGraph
()
const
{
return
*
G
;
}
CallGraph
&
getCallGraph
()
{
return
*
G
;
}
const
CallG
irlG
raph
&
getCallG
irlG
raph
()
const
{
return
*
G
;
}
CallG
irlG
raph
&
getCallG
irlG
raph
()
{
return
*
G
;
}
using
iterator
=
CallGraph
::
iterator
;
using
const_iterator
=
CallGraph
::
const_iterator
;
using
iterator
=
CallG
irlG
raph
::
iterator
;
using
const_iterator
=
CallG
irlG
raph
::
const_iterator
;
/// Returns the module the call graph corresponds to.
Module
&
getModule
()
const
{
return
G
->
getModule
();
}
...
...
@@ -363,22 +363,22 @@ public:
inline
const_iterator
end
()
const
{
return
G
->
end
();
}
/// Returns the call graph node for the provided function.
inline
const
CallGraphNode
*
operator
[](
const
Function
*
F
)
const
inline
const
CallG
irlG
raphNode
*
operator
[](
const
Function
*
F
)
const
{
return
(
*
G
)[
F
];
}
/// Returns the call graph node for the provided function.
inline
CallGraphNode
*
operator
[](
const
Function
*
F
)
{
return
(
*
G
)[
F
];
}
inline
CallG
irlG
raphNode
*
operator
[](
const
Function
*
F
)
{
return
(
*
G
)[
F
];
}
/// Returns the \c CallGraphNode which is used to represent
/// undetermined calls into the
c
all
g
raph.
CallGraphNode
*
getExternalCallingNode
()
const
/// Returns the \c CallG
irlG
raphNode which is used to represent
/// undetermined calls into the
C
all
GirlG
raph.
CallG
irlG
raphNode
*
getExternalCallingNode
()
const
{
return
G
->
getExternalCallingNode
();
}
CallGraphNode
*
getCallsExternalNode
()
const
CallG
irlG
raphNode
*
getCallsExternalNode
()
const
{
return
G
->
getCallsExternalNode
();
}
...
...
@@ -394,14 +394,14 @@ public:
/// destroyed. This is only valid if the function does not call any other
/// functions (ie, there are no edges in it's CGN). The easiest way to do
/// this is to dropAllReferences before calling this.
Function
*
removeFunctionFromModule
(
CallGraphNode
*
CGN
)
Function
*
removeFunctionFromModule
(
CallG
irlG
raphNode
*
CGN
)
{
return
G
->
removeFunctionFromModule
(
CGN
);
}
/// Similar to operator[], but this will insert a new CallGraphNode for
/// Similar to operator[], but this will insert a new CallG
irlG
raphNode for
/// \c F if one does not already exist.
CallGraphNode
*
getOrInsertFunction
(
const
Function
*
F
)
CallG
irlG
raphNode
*
getOrInsertFunction
(
const
Function
*
F
)
{
return
G
->
getOrInsertFunction
(
F
);
}
...
...
@@ -426,16 +426,16 @@ public:
// Provide graph traits for tranversing call graphs using standard graph
// traversals.
template
<
>
struct
GraphTraits
<
CallGraphNode
*>
struct
GraphTraits
<
CallG
irlG
raphNode
*>
{
using
NodeRef
=
CallGraphNode
*
;
using
CGNPairTy
=
CallGraphNode
::
CallRecord
;
using
NodeRef
=
CallG
irlG
raphNode
*
;
using
CGNPairTy
=
CallG
irlG
raphNode
::
CallRecord
;
static
NodeRef
getEntryNode
(
CallGraphNode
*
CGN
)
{
return
CGN
;
}
static
CallGraphNode
*
CGNGetValue
(
CGNPairTy
P
)
{
return
P
.
second
;
}
static
NodeRef
getEntryNode
(
CallG
irlG
raphNode
*
CGN
)
{
return
CGN
;
}
static
CallG
irlG
raphNode
*
CGNGetValue
(
CGNPairTy
P
)
{
return
P
.
second
;
}
using
ChildIteratorType
=
mapped_iterator
<
CallGraphNode
::
iterator
,
decltype
(
&
CGNGetValue
)
>
;
mapped_iterator
<
CallG
irlG
raphNode
::
iterator
,
decltype
(
&
CGNGetValue
)
>
;
static
ChildIteratorType
child_begin
(
NodeRef
N
)
{
...
...
@@ -449,18 +449,18 @@ struct GraphTraits<CallGraphNode *>
};
template
<
>
struct
GraphTraits
<
const
CallGraphNode
*>
struct
GraphTraits
<
const
CallG
irlG
raphNode
*>
{
using
NodeRef
=
const
CallGraphNode
*
;
using
CGNPairTy
=
CallGraphNode
::
CallRecord
;
using
EdgeRef
=
const
CallGraphNode
::
CallRecord
&
;
using
NodeRef
=
const
CallG
irlG
raphNode
*
;
using
CGNPairTy
=
CallG
irlG
raphNode
::
CallRecord
;
using
EdgeRef
=
const
CallG
irlG
raphNode
::
CallRecord
&
;
static
NodeRef
getEntryNode
(
const
CallGraphNode
*
CGN
)
{
return
CGN
;
}
static
const
CallGraphNode
*
CGNGetValue
(
CGNPairTy
P
)
{
return
P
.
second
;
}
static
NodeRef
getEntryNode
(
const
CallG
irlG
raphNode
*
CGN
)
{
return
CGN
;
}
static
const
CallG
irlG
raphNode
*
CGNGetValue
(
CGNPairTy
P
)
{
return
P
.
second
;
}
using
ChildIteratorType
=
mapped_iterator
<
CallGraphNode
::
const_iterator
,
decltype
(
&
CGNGetValue
)
>
;
using
ChildEdgeIteratorType
=
CallGraphNode
::
const_iterator
;
mapped_iterator
<
CallG
irlG
raphNode
::
const_iterator
,
decltype
(
&
CGNGetValue
)
>
;
using
ChildEdgeIteratorType
=
CallG
irlG
raphNode
::
const_iterator
;
static
ChildIteratorType
child_begin
(
NodeRef
N
)
{
...
...
@@ -482,68 +482,68 @@ struct GraphTraits<const CallGraphNode *>
};
template
<
>
struct
GraphTraits
<
CallGraph
*>
:
public
GraphTraits
<
CallGraphNode
*>
struct
GraphTraits
<
CallG
irlG
raph
*>
:
public
GraphTraits
<
CallG
irlG
raphNode
*>
{
using
PairTy
=
std
::
pair
<
const
Function
*
const
,
std
::
unique_ptr
<
CallGraphNode
>>
;
std
::
pair
<
const
Function
*
const
,
std
::
unique_ptr
<
CallG
irlG
raphNode
>>
;
static
NodeRef
getEntryNode
(
CallGraph
*
CGN
)
static
NodeRef
getEntryNode
(
CallG
irlG
raph
*
CGN
)
{
return
CGN
->
getExternalCallingNode
();
// Start at the external node!
}
static
CallGraphNode
*
CGGetValuePtr
(
const
PairTy
&
P
)
static
CallG
irlG
raphNode
*
CGGetValuePtr
(
const
PairTy
&
P
)
{
return
P
.
second
.
get
();
}
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
using
nodes_iterator
=
mapped_iterator
<
CallGraph
::
iterator
,
decltype
(
&
CGGetValuePtr
)
>
;
mapped_iterator
<
CallG
irlG
raph
::
iterator
,
decltype
(
&
CGGetValuePtr
)
>
;
static
nodes_iterator
nodes_begin
(
CallGraph
*
CG
)
static
nodes_iterator
nodes_begin
(
CallG
irlG
raph
*
CG
)
{
return
nodes_iterator
(
CG
->
begin
(),
&
CGGetValuePtr
);
}
static
nodes_iterator
nodes_end
(
CallGraph
*
CG
)
static
nodes_iterator
nodes_end
(
CallG
irlG
raph
*
CG
)
{
return
nodes_iterator
(
CG
->
end
(),
&
CGGetValuePtr
);
}
};
template
<
>
struct
GraphTraits
<
const
CallGraph
*>
:
public
GraphTraits
<
const
CallGraphNode
*>
struct
GraphTraits
<
const
CallG
irlG
raph
*>
:
public
GraphTraits
<
const
CallG
irlG
raphNode
*>
{
using
PairTy
=
std
::
pair
<
const
Function
*
const
,
std
::
unique_ptr
<
CallGraphNode
>>
;
std
::
pair
<
const
Function
*
const
,
std
::
unique_ptr
<
CallG
irlG
raphNode
>>
;
static
NodeRef
getEntryNode
(
const
CallGraph
*
CGN
)
static
NodeRef
getEntryNode
(
const
CallG
irlG
raph
*
CGN
)
{
return
CGN
->
getExternalCallingNode
();
// Start at the external node!
}
static
const
CallGraphNode
*
CGGetValuePtr
(
const
PairTy
&
P
)
static
const
CallG
irlG
raphNode
*
CGGetValuePtr
(
const
PairTy
&
P
)
{
return
P
.
second
.
get
();
}
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
using
nodes_iterator
=
mapped_iterator
<
CallGraph
::
const_iterator
,
decltype
(
&
CGGetValuePtr
)
>
;
mapped_iterator
<
CallG
irlG
raph
::
const_iterator
,
decltype
(
&
CGGetValuePtr
)
>
;
static
nodes_iterator
nodes_begin
(
const
CallGraph
*
CG
)
static
nodes_iterator
nodes_begin
(
const
CallG
irlG
raph
*
CG
)
{
return
nodes_iterator
(
CG
->
begin
(),
&
CGGetValuePtr
);
}
static
nodes_iterator
nodes_end
(
const
CallGraph
*
CG
)
static
nodes_iterator
nodes_end
(
const
CallG
irlG
raph
*
CG
)
{
return
nodes_iterator
(
CG
->
end
(),
&
CGGetValuePtr
);
}
};
}
//
end
namespace llvm
}
// namespace llvm
#endif // LLVM_ANALYSIS_CALLGRAPH_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment