Skip to content

Commit

Permalink
Add const to a bunch of call graph functions.
Browse files Browse the repository at this point in the history
Change the declaration of the functions that do not modify the call
graph data structure to const to make it easier to know which ones do
modify the call graph at a glance.

Swift SVN r32930
  • Loading branch information
rudkx committed Oct 28, 2015
1 parent 68fa1c2 commit 0ceb040
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
26 changes: 12 additions & 14 deletions include/swift/SILAnalysis/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ class CallGraphEdge {
explicit Callees(CalleeSet TheCallees) : TheCallees(TheCallees) {}

public:
CalleeFunctionView::iterator begin() {
CalleeFunctionView::iterator begin() const {
return getFunctionView().begin();
}

CalleeFunctionView::iterator end() {
CalleeFunctionView::iterator end() const {
return getFunctionView().end();
}

bool canCallUnknownFunction() {
bool canCallUnknownFunction() const {
if (TheCallees.is<CalleeSet>())
return TheCallees.get<CalleeSet>().getInt();

Expand All @@ -90,7 +90,7 @@ class CallGraphEdge {
}

private:
CalleeFunctionView getFunctionView() {
CalleeFunctionView getFunctionView() const {
// Make a view over the entire callee set.
if (TheCallees.is<CalleeSet>()) {
auto *Set = TheCallees.get<CalleeSet>().getPointer();
Expand Down Expand Up @@ -147,9 +147,7 @@ class CallGraphEdge {
~CallGraphEdge() {
}

const FullApplySite getApply() const { return TheApply; }

FullApplySite getApply() { return TheApply; }
FullApplySite getApply() const { return TheApply; }

/// Return the callee set.
CallGraphNodeSet getCalleeSet() const {
Expand Down Expand Up @@ -203,9 +201,9 @@ class CallGraphEdge {
return Ordinal;
}

void print(llvm::raw_ostream &OS, int Indent);
void dump(int Indent);
void dump();
void print(llvm::raw_ostream &OS, int Indent) const;
void dump(int Indent) const;
void dump() const;
};

class CallGraphNode {
Expand Down Expand Up @@ -283,8 +281,8 @@ class CallGraphNode {
return Ordinal;
}

void print(llvm::raw_ostream &OS);
void dump();
void print(llvm::raw_ostream &OS) const;
void dump() const;

private:
/// Mark a set of callers as known to not be complete.
Expand Down Expand Up @@ -400,7 +398,7 @@ class CallGraph {

// Call graph queries on call sites.

bool canCallUnknownFunction(FullApplySite FAS) {
bool canCallUnknownFunction(FullApplySite FAS) const {
return getCallGraphEdge(FAS)->canCallUnknownFunction();
}

Expand Down Expand Up @@ -452,7 +450,7 @@ class CallGraph {

// Query funtions for getting nodes and edges from the call graph.

CallGraphNode *getCallGraphNode(SILFunction *F) const {
const CallGraphNode *getCallGraphNode(SILFunction *F) const {
return const_cast<CallGraph *>(this)->getCallGraphNode(F);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/SILAnalysis/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ static void printFlag(llvm::raw_ostream &OS,
(Value ? "yes\n" : "no\n");
}

void CallGraphEdge::print(llvm::raw_ostream &OS, int Indent) {
void CallGraphEdge::print(llvm::raw_ostream &OS, int Indent) const {
indent(OS, Indent);
OS << CallGraphFileCheckPrefix << "Call site #" << Ordinal << ": ";
OS << *getApply().getInstruction();
Expand All @@ -490,20 +490,20 @@ void CallGraphEdge::print(llvm::raw_ostream &OS, int Indent) {
}
}

void CallGraphEdge::dump(int Indent) {
void CallGraphEdge::dump(int Indent) const {
#ifndef NDEBUG
print(llvm::errs(), Indent);
#endif
}

void CallGraphEdge::dump() {
void CallGraphEdge::dump() const {
#ifndef NDEBUG
dump(0);
#endif
}


void CallGraphNode::print(llvm::raw_ostream &OS) {
void CallGraphNode::print(llvm::raw_ostream &OS) const {
OS << CallGraphFileCheckPrefix << "Function #" << Ordinal << ": " <<
getFunction()->getName() << "\n";
OS << CallGraphFileCheckPrefix << "Demangled: " <<
Expand Down Expand Up @@ -555,7 +555,7 @@ void CallGraphNode::print(llvm::raw_ostream &OS) {
getFunction()->print(OS);
}

void CallGraphNode::dump() {
void CallGraphNode::dump() const {
#ifndef NDEBUG
print(llvm::errs());
#endif
Expand Down Expand Up @@ -884,7 +884,7 @@ void CallGraph::verify(SILFunction *F) const {
#ifndef NDEBUG
// Collect all full apply sites of the function.

CallGraphNode *Node = getCallGraphNode(F);
auto *Node = getCallGraphNode(F);
unsigned numEdges = 0;

for (auto &BB : *F) {
Expand Down

0 comments on commit 0ceb040

Please sign in to comment.