2002-10-03 20:38:41 +00:00
|
|
|
//===- BottomUpClosure.cpp - Compute bottom-up interprocedural closure ----===//
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-18 00:12:30 +00:00
|
|
|
//
|
|
|
|
// This file implements the BUDataStructures class, which represents the
|
|
|
|
// Bottom-Up Interprocedural closure of the data structure graph over the
|
|
|
|
// program. This is useful for applications like pool allocation, but **not**
|
2002-10-03 20:38:41 +00:00
|
|
|
// applications like alias analysis.
|
2002-07-18 00:12:30 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-07-07 06:35:22 +00:00
|
|
|
#include "llvm/Analysis/DataStructure/DataStructure.h"
|
2005-03-20 02:42:07 +00:00
|
|
|
#include "llvm/Analysis/DataStructure/DSGraph.h"
|
2002-07-18 00:12:30 +00:00
|
|
|
#include "llvm/Module.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2005-04-21 16:09:43 +00:00
|
|
|
#include "llvm/Support/Timer.h"
|
2006-01-22 23:19:18 +00:00
|
|
|
#include <iostream>
|
2003-11-12 23:11:14 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-11-17 22:16:28 +00:00
|
|
|
namespace {
|
|
|
|
Statistic<> MaxSCC("budatastructure", "Maximum SCC Size in Call Graph");
|
2003-07-02 20:24:42 +00:00
|
|
|
Statistic<> NumBUInlines("budatastructures", "Number of graphs inlined");
|
2003-07-02 23:42:48 +00:00
|
|
|
Statistic<> NumCallEdges("budatastructures", "Number of 'actual' call edges");
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2002-11-17 22:16:28 +00:00
|
|
|
RegisterAnalysis<BUDataStructures>
|
2003-06-28 22:14:55 +00:00
|
|
|
X("budatastructure", "Bottom-up Data Structure Analysis");
|
2002-11-17 22:16:28 +00:00
|
|
|
}
|
2002-07-18 00:12:30 +00:00
|
|
|
|
2005-03-25 16:45:43 +00:00
|
|
|
/// BuildGlobalECs - Look at all of the nodes in the globals graph. If any node
|
|
|
|
/// contains multiple globals, DSA will never, ever, be able to tell the globals
|
|
|
|
/// apart. Instead of maintaining this information in all of the graphs
|
|
|
|
/// throughout the entire program, store only a single global (the "leader") in
|
|
|
|
/// the graphs, and build equivalence classes for the rest of the globals.
|
|
|
|
static void BuildGlobalECs(DSGraph &GG, std::set<GlobalValue*> &ECGlobals) {
|
|
|
|
DSScalarMap &SM = GG.getScalarMap();
|
|
|
|
EquivalenceClasses<GlobalValue*> &GlobalECs = SM.getGlobalECs();
|
|
|
|
for (DSGraph::node_iterator I = GG.node_begin(), E = GG.node_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I->getGlobalsList().size() <= 1) continue;
|
|
|
|
|
|
|
|
// First, build up the equivalence set for this block of globals.
|
|
|
|
const std::vector<GlobalValue*> &GVs = I->getGlobalsList();
|
|
|
|
GlobalValue *First = GVs[0];
|
|
|
|
for (unsigned i = 1, e = GVs.size(); i != e; ++i)
|
|
|
|
GlobalECs.unionSets(First, GVs[i]);
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-03-25 16:45:43 +00:00
|
|
|
// Next, get the leader element.
|
|
|
|
assert(First == GlobalECs.getLeaderValue(First) &&
|
|
|
|
"First did not end up being the leader?");
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-03-25 16:45:43 +00:00
|
|
|
// Next, remove all globals from the scalar map that are not the leader.
|
|
|
|
assert(GVs[0] == First && "First had to be at the front!");
|
|
|
|
for (unsigned i = 1, e = GVs.size(); i != e; ++i) {
|
|
|
|
ECGlobals.insert(GVs[i]);
|
|
|
|
SM.erase(SM.find(GVs[i]));
|
|
|
|
}
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-03-25 16:45:43 +00:00
|
|
|
// Finally, change the global node to only contain the leader.
|
|
|
|
I->clearGlobals();
|
|
|
|
I->addGlobal(First);
|
|
|
|
}
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-03-25 16:45:43 +00:00
|
|
|
DEBUG(GG.AssertGraphOK());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EliminateUsesOfECGlobals - Once we have determined that some globals are in
|
|
|
|
/// really just equivalent to some other globals, remove the globals from the
|
|
|
|
/// specified DSGraph (if present), and merge any nodes with their leader nodes.
|
|
|
|
static void EliminateUsesOfECGlobals(DSGraph &G,
|
|
|
|
const std::set<GlobalValue*> &ECGlobals) {
|
|
|
|
DSScalarMap &SM = G.getScalarMap();
|
|
|
|
EquivalenceClasses<GlobalValue*> &GlobalECs = SM.getGlobalECs();
|
|
|
|
|
|
|
|
bool MadeChange = false;
|
|
|
|
for (DSScalarMap::global_iterator GI = SM.global_begin(), E = SM.global_end();
|
|
|
|
GI != E; ) {
|
|
|
|
GlobalValue *GV = *GI++;
|
|
|
|
if (!ECGlobals.count(GV)) continue;
|
|
|
|
|
|
|
|
const DSNodeHandle &GVNH = SM[GV];
|
|
|
|
assert(!GVNH.isNull() && "Global has null NH!?");
|
|
|
|
|
|
|
|
// Okay, this global is in some equivalence class. Start by finding the
|
|
|
|
// leader of the class.
|
|
|
|
GlobalValue *Leader = GlobalECs.getLeaderValue(GV);
|
|
|
|
|
|
|
|
// If the leader isn't already in the graph, insert it into the node
|
|
|
|
// corresponding to GV.
|
|
|
|
if (!SM.global_count(Leader)) {
|
|
|
|
GVNH.getNode()->addGlobal(Leader);
|
|
|
|
SM[Leader] = GVNH;
|
|
|
|
} else {
|
|
|
|
// Otherwise, the leader is in the graph, make sure the nodes are the
|
|
|
|
// merged in the specified graph.
|
|
|
|
const DSNodeHandle &LNH = SM[Leader];
|
|
|
|
if (LNH.getNode() != GVNH.getNode())
|
|
|
|
LNH.mergeWith(GVNH);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next step, remove the global from the DSNode.
|
|
|
|
GVNH.getNode()->removeGlobal(GV);
|
|
|
|
|
|
|
|
// Finally, remove the global from the ScalarMap.
|
|
|
|
SM.erase(GV);
|
|
|
|
MadeChange = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG(if(MadeChange) G.AssertGraphOK());
|
|
|
|
}
|
|
|
|
|
2002-11-09 21:12:07 +00:00
|
|
|
// run - Calculate the bottom up data structure graphs for each function in the
|
|
|
|
// program.
|
|
|
|
//
|
2004-09-20 04:48:05 +00:00
|
|
|
bool BUDataStructures::runOnModule(Module &M) {
|
2003-06-28 22:14:55 +00:00
|
|
|
LocalDataStructures &LocalDSA = getAnalysis<LocalDataStructures>();
|
Create an equivalence class of global variables that DSA will never be able
to tell apart anyway, and only track the leader for of these equivalence
classes in our graphs.
This dramatically reduces the number of GlobalValue*'s that appear in scalar
maps, which A) reduces memory usage, by eliminating many many scalarmap entries
and B) reduces time for operations that need to execute an operation for each
global in the scalar map.
As an example, this reduces the memory used to analyze 176.gcc from 1GB to
511MB, which (while it's still way too much) is better because it doesn't hit
swap anymore. On eon, this shrinks the local graphs from 14MB to 6.8MB,
shrinks the bu+td graphs of povray from 50M to 40M, shrinks the TD graphs of
130.li from 8.8M to 3.6M, etc.
This change also speeds up DSA on large programs where this makes a big
difference. For example, 130.li goes from 1.17s -> 0.56s, 134.perl goes
from 2.14 -> 0.93s, povray goes from 15.63s->7.99s (!!!).
This also apparently either fixes the problem that caused DSA to crash on
perlbmk and gcc, or it hides it, because DSA now works on these. These
both take entirely too much time in the TD pass (147s for perl, 538s for
gcc, vs 7.67/5.9s in the bu pass for either one), but this is a known
problem that I'll deal with later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20696 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-19 22:23:45 +00:00
|
|
|
GlobalECs = LocalDSA.getGlobalECs();
|
|
|
|
|
|
|
|
GlobalsGraph = new DSGraph(LocalDSA.getGlobalsGraph(), GlobalECs);
|
2003-02-03 19:11:38 +00:00
|
|
|
GlobalsGraph->setPrintAuxCalls();
|
2002-11-09 21:12:07 +00:00
|
|
|
|
2005-02-07 16:09:15 +00:00
|
|
|
IndCallGraphMap = new std::map<std::vector<Function*>,
|
|
|
|
std::pair<DSGraph*, std::vector<DSNodeHandle> > >();
|
|
|
|
|
2005-02-01 17:35:52 +00:00
|
|
|
std::vector<Function*> Stack;
|
|
|
|
hash_map<Function*, unsigned> ValMap;
|
|
|
|
unsigned NextID = 1;
|
|
|
|
|
2002-11-11 21:35:13 +00:00
|
|
|
Function *MainFunc = M.getMainFunction();
|
|
|
|
if (MainFunc)
|
2005-02-01 17:35:52 +00:00
|
|
|
calculateGraphs(MainFunc, Stack, NextID, ValMap);
|
2002-11-11 21:35:13 +00:00
|
|
|
|
|
|
|
// Calculate the graphs for any functions that are unreachable from main...
|
2002-11-09 21:12:07 +00:00
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
2003-07-01 16:04:18 +00:00
|
|
|
if (!I->isExternal() && !DSInfo.count(I)) {
|
2002-11-17 22:16:28 +00:00
|
|
|
#ifndef NDEBUG
|
2002-11-11 21:35:13 +00:00
|
|
|
if (MainFunc)
|
|
|
|
std::cerr << "*** Function unreachable from main: "
|
|
|
|
<< I->getName() << "\n";
|
2002-11-17 22:16:28 +00:00
|
|
|
#endif
|
2005-02-01 17:35:52 +00:00
|
|
|
calculateGraphs(I, Stack, NextID, ValMap); // Calculate all graphs.
|
2002-11-11 21:35:13 +00:00
|
|
|
}
|
2003-07-02 23:42:48 +00:00
|
|
|
|
|
|
|
NumCallEdges += ActualCallees.size();
|
2003-09-20 23:27:05 +00:00
|
|
|
|
2005-02-04 19:59:49 +00:00
|
|
|
// If we computed any temporary indcallgraphs, free them now.
|
|
|
|
for (std::map<std::vector<Function*>,
|
|
|
|
std::pair<DSGraph*, std::vector<DSNodeHandle> > >::iterator I =
|
2005-02-07 16:09:15 +00:00
|
|
|
IndCallGraphMap->begin(), E = IndCallGraphMap->end(); I != E; ++I) {
|
2005-02-04 19:59:49 +00:00
|
|
|
I->second.second.clear(); // Drop arg refs into the graph.
|
|
|
|
delete I->second.first;
|
|
|
|
}
|
2005-02-07 16:09:15 +00:00
|
|
|
delete IndCallGraphMap;
|
2005-02-04 19:59:49 +00:00
|
|
|
|
2003-09-20 23:27:05 +00:00
|
|
|
// At the end of the bottom-up pass, the globals graph becomes complete.
|
|
|
|
// FIXME: This is not the right way to do this, but it is sorta better than
|
2003-09-20 23:58:33 +00:00
|
|
|
// nothing! In particular, externally visible globals and unresolvable call
|
|
|
|
// nodes at the end of the BU phase should make things that they point to
|
|
|
|
// incomplete in the globals graph.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2004-02-08 01:51:48 +00:00
|
|
|
GlobalsGraph->removeTriviallyDeadNodes();
|
2003-09-20 23:27:05 +00:00
|
|
|
GlobalsGraph->maskIncompleteMarkers();
|
2005-03-13 20:15:06 +00:00
|
|
|
|
2005-03-22 22:10:22 +00:00
|
|
|
// Mark external globals incomplete.
|
|
|
|
GlobalsGraph->markIncompleteNodes(DSGraph::IgnoreGlobals);
|
|
|
|
|
2005-03-25 16:45:43 +00:00
|
|
|
// Grow the equivalence classes for the globals to include anything that we
|
|
|
|
// now know to be aliased.
|
|
|
|
std::set<GlobalValue*> ECGlobals;
|
|
|
|
BuildGlobalECs(*GlobalsGraph, ECGlobals);
|
|
|
|
if (!ECGlobals.empty()) {
|
2005-04-21 16:09:43 +00:00
|
|
|
NamedRegionTimer X("Bottom-UP EC Cleanup");
|
|
|
|
std::cerr << "Eliminating " << ECGlobals.size() << " EC Globals!\n";
|
2005-03-25 16:45:43 +00:00
|
|
|
for (hash_map<Function*, DSGraph*>::iterator I = DSInfo.begin(),
|
|
|
|
E = DSInfo.end(); I != E; ++I)
|
|
|
|
EliminateUsesOfECGlobals(*I->second, ECGlobals);
|
|
|
|
}
|
|
|
|
|
2005-03-13 20:15:06 +00:00
|
|
|
// Merge the globals variables (not the calls) from the globals graph back
|
|
|
|
// into the main function's graph so that the main function contains all of
|
|
|
|
// the information about global pools and GV usage in the program.
|
2005-03-15 22:10:04 +00:00
|
|
|
if (MainFunc && !MainFunc->isExternal()) {
|
2005-03-13 20:15:06 +00:00
|
|
|
DSGraph &MainGraph = getOrCreateGraph(MainFunc);
|
|
|
|
const DSGraph &GG = *MainGraph.getGlobalsGraph();
|
2005-04-21 21:13:18 +00:00
|
|
|
ReachabilityCloner RC(MainGraph, GG,
|
2005-03-13 20:15:06 +00:00
|
|
|
DSGraph::DontCloneCallNodes |
|
|
|
|
DSGraph::DontCloneAuxCallNodes);
|
|
|
|
|
|
|
|
// Clone the global nodes into this graph.
|
|
|
|
for (DSScalarMap::global_iterator I = GG.getScalarMap().global_begin(),
|
|
|
|
E = GG.getScalarMap().global_end(); I != E; ++I)
|
|
|
|
if (isa<GlobalVariable>(*I))
|
|
|
|
RC.getClonedNH(GG.getNodeForValue(*I));
|
|
|
|
|
2005-03-13 20:32:26 +00:00
|
|
|
MainGraph.maskIncompleteMarkers();
|
2005-04-21 21:13:18 +00:00
|
|
|
MainGraph.markIncompleteNodes(DSGraph::MarkFormalArgs |
|
2005-03-13 20:15:06 +00:00
|
|
|
DSGraph::IgnoreGlobals);
|
|
|
|
}
|
|
|
|
|
2002-11-09 21:12:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-10-03 20:38:41 +00:00
|
|
|
|
2002-11-11 21:35:13 +00:00
|
|
|
DSGraph &BUDataStructures::getOrCreateGraph(Function *F) {
|
|
|
|
// Has the graph already been created?
|
|
|
|
DSGraph *&Graph = DSInfo[F];
|
|
|
|
if (Graph) return *Graph;
|
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
DSGraph &LocGraph = getAnalysis<LocalDataStructures>().getDSGraph(*F);
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
// Steal the local graph.
|
|
|
|
Graph = new DSGraph(GlobalECs, LocGraph.getTargetData());
|
|
|
|
Graph->spliceFrom(LocGraph);
|
2002-11-11 21:35:13 +00:00
|
|
|
|
|
|
|
Graph->setGlobalsGraph(GlobalsGraph);
|
|
|
|
Graph->setPrintAuxCalls();
|
|
|
|
|
|
|
|
// Start with a copy of the original call sites...
|
|
|
|
Graph->getAuxFunctionCalls() = Graph->getFunctionCalls();
|
|
|
|
return *Graph;
|
|
|
|
}
|
|
|
|
|
2005-03-20 02:42:07 +00:00
|
|
|
static bool isVAHackFn(const Function *F) {
|
|
|
|
return F->getName() == "printf" || F->getName() == "sscanf" ||
|
|
|
|
F->getName() == "fprintf" || F->getName() == "open" ||
|
|
|
|
F->getName() == "sprintf" || F->getName() == "fputs" ||
|
2005-04-21 16:09:43 +00:00
|
|
|
F->getName() == "fscanf" || F->getName() == "malloc" ||
|
|
|
|
F->getName() == "free";
|
2005-03-20 02:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isResolvableFunc(const Function* callee) {
|
|
|
|
return !callee->isExternal() || isVAHackFn(callee);
|
|
|
|
}
|
|
|
|
|
2005-04-21 21:13:18 +00:00
|
|
|
static void GetAllCallees(const DSCallSite &CS,
|
2005-03-20 02:42:07 +00:00
|
|
|
std::vector<Function*> &Callees) {
|
|
|
|
if (CS.isDirectCall()) {
|
|
|
|
if (isResolvableFunc(CS.getCalleeFunc()))
|
|
|
|
Callees.push_back(CS.getCalleeFunc());
|
|
|
|
} else if (!CS.getCalleeNode()->isIncomplete()) {
|
|
|
|
// Get all callees.
|
|
|
|
unsigned OldSize = Callees.size();
|
|
|
|
CS.getCalleeNode()->addFullFunctionList(Callees);
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-03-20 02:42:07 +00:00
|
|
|
// If any of the callees are unresolvable, remove the whole batch!
|
|
|
|
for (unsigned i = OldSize, e = Callees.size(); i != e; ++i)
|
|
|
|
if (!isResolvableFunc(Callees[i])) {
|
|
|
|
Callees.erase(Callees.begin()+OldSize, Callees.end());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// GetAllAuxCallees - Return a list containing all of the resolvable callees in
|
|
|
|
/// the aux list for the specified graph in the Callees vector.
|
|
|
|
static void GetAllAuxCallees(DSGraph &G, std::vector<Function*> &Callees) {
|
|
|
|
Callees.clear();
|
|
|
|
for (DSGraph::afc_iterator I = G.afc_begin(), E = G.afc_end(); I != E; ++I)
|
|
|
|
GetAllCallees(*I, Callees);
|
|
|
|
}
|
|
|
|
|
2002-11-11 21:35:13 +00:00
|
|
|
unsigned BUDataStructures::calculateGraphs(Function *F,
|
|
|
|
std::vector<Function*> &Stack,
|
2005-04-21 21:13:18 +00:00
|
|
|
unsigned &NextID,
|
2003-02-01 04:52:08 +00:00
|
|
|
hash_map<Function*, unsigned> &ValMap) {
|
2003-11-13 05:04:19 +00:00
|
|
|
assert(!ValMap.count(F) && "Shouldn't revisit functions!");
|
2002-11-11 21:35:13 +00:00
|
|
|
unsigned Min = NextID++, MyID = Min;
|
|
|
|
ValMap[F] = Min;
|
|
|
|
Stack.push_back(F);
|
|
|
|
|
2004-03-04 17:05:28 +00:00
|
|
|
// FIXME! This test should be generalized to be any function that we have
|
|
|
|
// already processed, in the case when there isn't a main or there are
|
|
|
|
// unreachable functions!
|
2002-11-11 21:35:13 +00:00
|
|
|
if (F->isExternal()) { // sprintf, fprintf, sscanf, etc...
|
|
|
|
// No callees!
|
|
|
|
Stack.pop_back();
|
|
|
|
ValMap[F] = ~0;
|
|
|
|
return Min;
|
|
|
|
}
|
|
|
|
|
|
|
|
DSGraph &Graph = getOrCreateGraph(F);
|
|
|
|
|
2005-03-20 02:42:07 +00:00
|
|
|
// Find all callee functions.
|
|
|
|
std::vector<Function*> CalleeFunctions;
|
|
|
|
GetAllAuxCallees(Graph, CalleeFunctions);
|
|
|
|
|
2002-11-11 21:35:13 +00:00
|
|
|
// The edges out of the current node are the call site targets...
|
2005-03-20 02:42:07 +00:00
|
|
|
for (unsigned i = 0, e = CalleeFunctions.size(); i != e; ++i) {
|
|
|
|
Function *Callee = CalleeFunctions[i];
|
2002-11-11 21:35:13 +00:00
|
|
|
unsigned M;
|
|
|
|
// Have we visited the destination function yet?
|
2003-02-01 04:52:08 +00:00
|
|
|
hash_map<Function*, unsigned>::iterator It = ValMap.find(Callee);
|
2002-11-11 21:35:13 +00:00
|
|
|
if (It == ValMap.end()) // No, visit it now.
|
|
|
|
M = calculateGraphs(Callee, Stack, NextID, ValMap);
|
|
|
|
else // Yes, get it's number.
|
|
|
|
M = It->second;
|
|
|
|
if (M < Min) Min = M;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(ValMap[F] == MyID && "SCC construction assumption wrong!");
|
|
|
|
if (Min != MyID)
|
|
|
|
return Min; // This is part of a larger SCC!
|
|
|
|
|
|
|
|
// If this is a new SCC, process it now.
|
|
|
|
if (Stack.back() == F) { // Special case the single "SCC" case here.
|
|
|
|
DEBUG(std::cerr << "Visiting single node SCC #: " << MyID << " fn: "
|
|
|
|
<< F->getName() << "\n");
|
|
|
|
Stack.pop_back();
|
2003-06-30 05:09:58 +00:00
|
|
|
DSGraph &G = getDSGraph(*F);
|
|
|
|
DEBUG(std::cerr << " [BU] Calculating graph for: " << F->getName()<< "\n");
|
|
|
|
calculateGraph(G);
|
|
|
|
DEBUG(std::cerr << " [BU] Done inlining: " << F->getName() << " ["
|
|
|
|
<< G.getGraphSize() << "+" << G.getAuxFunctionCalls().size()
|
|
|
|
<< "]\n");
|
2002-11-11 21:35:13 +00:00
|
|
|
|
2002-11-17 22:16:28 +00:00
|
|
|
if (MaxSCC < 1) MaxSCC = 1;
|
|
|
|
|
2005-03-20 02:42:07 +00:00
|
|
|
// Should we revisit the graph? Only do it if there are now new resolvable
|
|
|
|
// callees.
|
|
|
|
GetAllAuxCallees(Graph, CalleeFunctions);
|
|
|
|
if (!CalleeFunctions.empty()) {
|
2002-11-11 21:35:13 +00:00
|
|
|
ValMap.erase(F);
|
|
|
|
return calculateGraphs(F, Stack, NextID, ValMap);
|
|
|
|
} else {
|
|
|
|
ValMap[F] = ~0U;
|
|
|
|
}
|
|
|
|
return MyID;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// SCCFunctions - Keep track of the functions in the current SCC
|
|
|
|
//
|
2005-03-25 00:05:04 +00:00
|
|
|
std::vector<DSGraph*> SCCGraphs;
|
|
|
|
|
|
|
|
unsigned SCCSize = 1;
|
|
|
|
Function *NF = Stack.back();
|
|
|
|
ValMap[NF] = ~0U;
|
|
|
|
DSGraph &SCCGraph = getDSGraph(*NF);
|
2002-11-11 21:35:13 +00:00
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
// First thing first, collapse all of the DSGraphs into a single graph for
|
|
|
|
// the entire SCC. Splice all of the graphs into one and discard all of the
|
|
|
|
// old graphs.
|
|
|
|
//
|
|
|
|
while (NF != F) {
|
|
|
|
Stack.pop_back();
|
|
|
|
NF = Stack.back();
|
2002-11-11 21:35:13 +00:00
|
|
|
ValMap[NF] = ~0U;
|
2003-06-30 05:09:58 +00:00
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
DSGraph &NFG = getDSGraph(*NF);
|
2002-11-11 21:35:13 +00:00
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
// Update the Function -> DSG map.
|
|
|
|
for (DSGraph::retnodes_iterator I = NFG.retnodes_begin(),
|
|
|
|
E = NFG.retnodes_end(); I != E; ++I)
|
|
|
|
DSInfo[I->first] = &SCCGraph;
|
2002-11-11 21:35:13 +00:00
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
SCCGraph.spliceFrom(NFG);
|
|
|
|
delete &NFG;
|
2002-11-12 15:58:08 +00:00
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
++SCCSize;
|
|
|
|
}
|
|
|
|
Stack.pop_back();
|
2005-03-25 00:06:09 +00:00
|
|
|
|
2005-03-25 00:05:04 +00:00
|
|
|
std::cerr << "Calculating graph for SCC #: " << MyID << " of size: "
|
|
|
|
<< SCCSize << "\n";
|
|
|
|
|
|
|
|
// Compute the Max SCC Size.
|
|
|
|
if (MaxSCC < SCCSize)
|
|
|
|
MaxSCC = SCCSize;
|
2002-11-11 21:35:13 +00:00
|
|
|
|
2003-07-02 04:37:48 +00:00
|
|
|
// Clean up the graph before we start inlining a bunch again...
|
2005-03-25 00:05:04 +00:00
|
|
|
SCCGraph.removeDeadNodes(DSGraph::KeepUnreachableGlobals);
|
2003-07-02 04:37:48 +00:00
|
|
|
|
2003-06-30 05:09:58 +00:00
|
|
|
// Now that we have one big happy family, resolve all of the call sites in
|
|
|
|
// the graph...
|
2005-03-25 00:05:04 +00:00
|
|
|
calculateGraph(SCCGraph);
|
|
|
|
DEBUG(std::cerr << " [BU] Done inlining SCC [" << SCCGraph.getGraphSize()
|
|
|
|
<< "+" << SCCGraph.getAuxFunctionCalls().size() << "]\n");
|
2002-11-11 21:35:13 +00:00
|
|
|
|
|
|
|
std::cerr << "DONE with SCC #: " << MyID << "\n";
|
|
|
|
|
|
|
|
// We never have to revisit "SCC" processed functions...
|
|
|
|
return MyID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MyID; // == Min
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-18 00:12:30 +00:00
|
|
|
// releaseMemory - If the pass pipeline is done with this pass, we can release
|
|
|
|
// our memory... here...
|
|
|
|
//
|
2005-03-23 21:59:34 +00:00
|
|
|
void BUDataStructures::releaseMyMemory() {
|
2003-06-30 05:09:58 +00:00
|
|
|
for (hash_map<Function*, DSGraph*>::iterator I = DSInfo.begin(),
|
|
|
|
E = DSInfo.end(); I != E; ++I) {
|
|
|
|
I->second->getReturnNodes().erase(I->first);
|
|
|
|
if (I->second->getReturnNodes().empty())
|
|
|
|
delete I->second;
|
|
|
|
}
|
2002-07-18 00:12:30 +00:00
|
|
|
|
|
|
|
// Empty map so next time memory is released, data structures are not
|
|
|
|
// re-deleted.
|
|
|
|
DSInfo.clear();
|
2002-11-09 21:12:07 +00:00
|
|
|
delete GlobalsGraph;
|
|
|
|
GlobalsGraph = 0;
|
2002-07-18 00:12:30 +00:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:09:43 +00:00
|
|
|
DSGraph &BUDataStructures::CreateGraphForExternalFunction(const Function &Fn) {
|
|
|
|
Function *F = const_cast<Function*>(&Fn);
|
|
|
|
DSGraph *DSG = new DSGraph(GlobalECs, GlobalsGraph->getTargetData());
|
|
|
|
DSInfo[F] = DSG;
|
|
|
|
DSG->setGlobalsGraph(GlobalsGraph);
|
|
|
|
DSG->setPrintAuxCalls();
|
|
|
|
|
|
|
|
// Add function to the graph.
|
|
|
|
DSG->getReturnNodes().insert(std::make_pair(F, DSNodeHandle()));
|
|
|
|
|
|
|
|
if (F->getName() == "free") { // Taking the address of free.
|
2005-07-27 06:12:32 +00:00
|
|
|
|
2005-04-21 16:09:43 +00:00
|
|
|
// Free should take a single pointer argument, mark it as heap memory.
|
|
|
|
DSNode *N = new DSNode(0, DSG);
|
|
|
|
N->setHeapNodeMarker();
|
|
|
|
DSG->getNodeForValue(F->arg_begin()).mergeWith(N);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
std::cerr << "Unrecognized external function: " << F->getName() << "\n";
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return *DSG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-30 05:09:58 +00:00
|
|
|
void BUDataStructures::calculateGraph(DSGraph &Graph) {
|
2005-04-25 19:16:31 +00:00
|
|
|
// If this graph contains the main function, clone the globals graph into this
|
|
|
|
// graph before we inline callees and other fun stuff.
|
|
|
|
bool ContainsMain = false;
|
|
|
|
DSGraph::ReturnNodesTy &ReturnNodes = Graph.getReturnNodes();
|
|
|
|
|
|
|
|
for (DSGraph::ReturnNodesTy::iterator I = ReturnNodes.begin(),
|
|
|
|
E = ReturnNodes.end(); I != E; ++I)
|
|
|
|
if (I->first->hasExternalLinkage() && I->first->getName() == "main") {
|
|
|
|
ContainsMain = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this graph contains main, copy the contents of the globals graph over.
|
|
|
|
// Note that this is *required* for correctness. If a callee contains a use
|
|
|
|
// of a global, we have to make sure to link up nodes due to global-argument
|
|
|
|
// bindings.
|
|
|
|
if (ContainsMain) {
|
|
|
|
const DSGraph &GG = *Graph.getGlobalsGraph();
|
|
|
|
ReachabilityCloner RC(Graph, GG,
|
|
|
|
DSGraph::DontCloneCallNodes |
|
|
|
|
DSGraph::DontCloneAuxCallNodes);
|
|
|
|
|
|
|
|
// Clone the global nodes into this graph.
|
|
|
|
for (DSScalarMap::global_iterator I = GG.getScalarMap().global_begin(),
|
|
|
|
E = GG.getScalarMap().global_end(); I != E; ++I)
|
|
|
|
if (isa<GlobalVariable>(*I))
|
|
|
|
RC.getClonedNH(GG.getNodeForValue(*I));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-11 21:35:13 +00:00
|
|
|
// Move our call site list into TempFCs so that inline call sites go into the
|
|
|
|
// new call site list and doesn't invalidate our iterators!
|
2005-01-30 23:51:02 +00:00
|
|
|
std::list<DSCallSite> TempFCs;
|
|
|
|
std::list<DSCallSite> &AuxCallsList = Graph.getAuxFunctionCalls();
|
2002-11-11 21:35:13 +00:00
|
|
|
TempFCs.swap(AuxCallsList);
|
|
|
|
|
2005-02-01 17:35:52 +00:00
|
|
|
bool Printed = false;
|
2005-02-04 19:59:49 +00:00
|
|
|
std::vector<Function*> CalledFuncs;
|
2005-02-01 21:37:27 +00:00
|
|
|
while (!TempFCs.empty()) {
|
|
|
|
DSCallSite &CS = *TempFCs.begin();
|
2005-02-01 17:35:52 +00:00
|
|
|
|
2005-02-04 19:59:49 +00:00
|
|
|
CalledFuncs.clear();
|
2002-11-11 00:01:34 +00:00
|
|
|
|
2005-03-18 23:19:47 +00:00
|
|
|
// Fast path for noop calls. Note that we don't care about merging globals
|
|
|
|
// in the callee with nodes in the caller here.
|
|
|
|
if (CS.getRetVal().isNull() && CS.getNumPtrArgs() == 0) {
|
|
|
|
TempFCs.erase(TempFCs.begin());
|
|
|
|
continue;
|
2005-03-20 02:42:07 +00:00
|
|
|
} else if (CS.isDirectCall() && isVAHackFn(CS.getCalleeFunc())) {
|
|
|
|
TempFCs.erase(TempFCs.begin());
|
|
|
|
continue;
|
2005-03-18 23:19:47 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 02:42:07 +00:00
|
|
|
GetAllCallees(CS, CalledFuncs);
|
2002-11-11 00:01:34 +00:00
|
|
|
|
2005-02-01 21:37:27 +00:00
|
|
|
if (CalledFuncs.empty()) {
|
|
|
|
// Remember that we could not resolve this yet!
|
|
|
|
AuxCallsList.splice(AuxCallsList.end(), TempFCs, TempFCs.begin());
|
2005-02-01 21:49:43 +00:00
|
|
|
continue;
|
2005-02-01 21:37:27 +00:00
|
|
|
} else {
|
2005-02-04 19:59:49 +00:00
|
|
|
DSGraph *GI;
|
2005-03-21 20:20:49 +00:00
|
|
|
Instruction *TheCall = CS.getCallSite().getInstruction();
|
2005-02-04 19:59:49 +00:00
|
|
|
|
|
|
|
if (CalledFuncs.size() == 1) {
|
|
|
|
Function *Callee = CalledFuncs[0];
|
2005-03-21 20:20:49 +00:00
|
|
|
ActualCallees.insert(std::make_pair(TheCall, Callee));
|
2005-02-04 19:59:49 +00:00
|
|
|
|
2005-02-01 21:49:43 +00:00
|
|
|
// Get the data structure graph for the called function.
|
2005-02-04 19:59:49 +00:00
|
|
|
GI = &getDSGraph(*Callee); // Graph to inline
|
|
|
|
DEBUG(std::cerr << " Inlining graph for " << Callee->getName());
|
|
|
|
|
|
|
|
DEBUG(std::cerr << "[" << GI->getGraphSize() << "+"
|
|
|
|
<< GI->getAuxFunctionCalls().size() << "] into '"
|
2005-02-01 21:49:43 +00:00
|
|
|
<< Graph.getFunctionNames() << "' [" << Graph.getGraphSize() <<"+"
|
|
|
|
<< Graph.getAuxFunctionCalls().size() << "]\n");
|
2005-02-04 19:59:49 +00:00
|
|
|
Graph.mergeInGraph(CS, *Callee, *GI,
|
2005-02-01 21:49:43 +00:00
|
|
|
DSGraph::StripAllocaBit|DSGraph::DontCloneCallNodes);
|
|
|
|
++NumBUInlines;
|
2005-02-04 19:59:49 +00:00
|
|
|
} else {
|
|
|
|
if (!Printed)
|
|
|
|
std::cerr << "In Fns: " << Graph.getFunctionNames() << "\n";
|
|
|
|
std::cerr << " calls " << CalledFuncs.size()
|
2005-04-21 21:13:18 +00:00
|
|
|
<< " fns from site: " << CS.getCallSite().getInstruction()
|
2005-02-04 19:59:49 +00:00
|
|
|
<< " " << *CS.getCallSite().getInstruction();
|
|
|
|
std::cerr << " Fns =";
|
2005-03-21 20:20:49 +00:00
|
|
|
unsigned NumPrinted = 0;
|
|
|
|
|
2005-02-04 19:59:49 +00:00
|
|
|
for (std::vector<Function*>::iterator I = CalledFuncs.begin(),
|
2005-03-21 20:20:49 +00:00
|
|
|
E = CalledFuncs.end(); I != E; ++I) {
|
|
|
|
if (NumPrinted++ < 8) std::cerr << " " << (*I)->getName();
|
|
|
|
|
|
|
|
// Add the call edges to the call graph.
|
|
|
|
ActualCallees.insert(std::make_pair(TheCall, *I));
|
|
|
|
}
|
2005-02-04 19:59:49 +00:00
|
|
|
std::cerr << "\n";
|
|
|
|
|
|
|
|
// See if we already computed a graph for this set of callees.
|
|
|
|
std::sort(CalledFuncs.begin(), CalledFuncs.end());
|
|
|
|
std::pair<DSGraph*, std::vector<DSNodeHandle> > &IndCallGraph =
|
2005-02-07 16:09:15 +00:00
|
|
|
(*IndCallGraphMap)[CalledFuncs];
|
2005-02-04 19:59:49 +00:00
|
|
|
|
|
|
|
if (IndCallGraph.first == 0) {
|
|
|
|
std::vector<Function*>::iterator I = CalledFuncs.begin(),
|
|
|
|
E = CalledFuncs.end();
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-02-04 19:59:49 +00:00
|
|
|
// Start with a copy of the first graph.
|
Create an equivalence class of global variables that DSA will never be able
to tell apart anyway, and only track the leader for of these equivalence
classes in our graphs.
This dramatically reduces the number of GlobalValue*'s that appear in scalar
maps, which A) reduces memory usage, by eliminating many many scalarmap entries
and B) reduces time for operations that need to execute an operation for each
global in the scalar map.
As an example, this reduces the memory used to analyze 176.gcc from 1GB to
511MB, which (while it's still way too much) is better because it doesn't hit
swap anymore. On eon, this shrinks the local graphs from 14MB to 6.8MB,
shrinks the bu+td graphs of povray from 50M to 40M, shrinks the TD graphs of
130.li from 8.8M to 3.6M, etc.
This change also speeds up DSA on large programs where this makes a big
difference. For example, 130.li goes from 1.17s -> 0.56s, 134.perl goes
from 2.14 -> 0.93s, povray goes from 15.63s->7.99s (!!!).
This also apparently either fixes the problem that caused DSA to crash on
perlbmk and gcc, or it hides it, because DSA now works on these. These
both take entirely too much time in the TD pass (147s for perl, 538s for
gcc, vs 7.67/5.9s in the bu pass for either one), but this is a known
problem that I'll deal with later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20696 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-19 22:23:45 +00:00
|
|
|
GI = IndCallGraph.first = new DSGraph(getDSGraph(**I), GlobalECs);
|
2005-02-04 19:59:49 +00:00
|
|
|
GI->setGlobalsGraph(Graph.getGlobalsGraph());
|
|
|
|
std::vector<DSNodeHandle> &Args = IndCallGraph.second;
|
|
|
|
|
|
|
|
// Get the argument nodes for the first callee. The return value is
|
|
|
|
// the 0th index in the vector.
|
|
|
|
GI->getFunctionArgumentsForCall(*I, Args);
|
|
|
|
|
|
|
|
// Merge all of the other callees into this graph.
|
|
|
|
for (++I; I != E; ++I) {
|
|
|
|
// If the graph already contains the nodes for the function, don't
|
|
|
|
// bother merging it in again.
|
|
|
|
if (!GI->containsFunction(*I)) {
|
2005-03-22 00:36:51 +00:00
|
|
|
GI->cloneInto(getDSGraph(**I));
|
2005-02-04 19:59:49 +00:00
|
|
|
++NumBUInlines;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<DSNodeHandle> NextArgs;
|
|
|
|
GI->getFunctionArgumentsForCall(*I, NextArgs);
|
|
|
|
unsigned i = 0, e = Args.size();
|
|
|
|
for (; i != e; ++i) {
|
|
|
|
if (i == NextArgs.size()) break;
|
|
|
|
Args[i].mergeWith(NextArgs[i]);
|
|
|
|
}
|
|
|
|
for (e = NextArgs.size(); i != e; ++i)
|
|
|
|
Args.push_back(NextArgs[i]);
|
|
|
|
}
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2005-02-04 19:59:49 +00:00
|
|
|
// Clean up the final graph!
|
|
|
|
GI->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
|
|
|
|
} else {
|
|
|
|
std::cerr << "***\n*** RECYCLED GRAPH ***\n***\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
GI = IndCallGraph.first;
|
|
|
|
|
|
|
|
// Merge the unified graph into this graph now.
|
|
|
|
DEBUG(std::cerr << " Inlining multi callee graph "
|
|
|
|
<< "[" << GI->getGraphSize() << "+"
|
|
|
|
<< GI->getAuxFunctionCalls().size() << "] into '"
|
|
|
|
<< Graph.getFunctionNames() << "' [" << Graph.getGraphSize() <<"+"
|
|
|
|
<< Graph.getAuxFunctionCalls().size() << "]\n");
|
|
|
|
|
|
|
|
Graph.mergeInGraph(CS, IndCallGraph.second, *GI,
|
|
|
|
DSGraph::StripAllocaBit |
|
|
|
|
DSGraph::DontCloneCallNodes);
|
|
|
|
++NumBUInlines;
|
2005-02-01 21:37:27 +00:00
|
|
|
}
|
2005-01-30 23:51:02 +00:00
|
|
|
}
|
2005-02-01 21:49:43 +00:00
|
|
|
TempFCs.erase(TempFCs.begin());
|
2005-01-30 23:51:02 +00:00
|
|
|
}
|
2002-11-11 00:01:34 +00:00
|
|
|
|
2003-07-16 21:42:03 +00:00
|
|
|
// Recompute the Incomplete markers
|
2002-11-11 21:35:13 +00:00
|
|
|
Graph.maskIncompleteMarkers();
|
2003-01-23 22:05:33 +00:00
|
|
|
Graph.markIncompleteNodes(DSGraph::MarkFormalArgs);
|
2003-07-16 21:42:03 +00:00
|
|
|
|
|
|
|
// Delete dead nodes. Treat globals that are unreachable but that can
|
|
|
|
// reach live nodes as live.
|
2003-01-23 22:05:33 +00:00
|
|
|
Graph.removeDeadNodes(DSGraph::KeepUnreachableGlobals);
|
2002-11-11 00:01:34 +00:00
|
|
|
|
2004-02-21 00:30:28 +00:00
|
|
|
// When this graph is finalized, clone the globals in the graph into the
|
|
|
|
// globals graph to make sure it has everything, from all graphs.
|
|
|
|
DSScalarMap &MainSM = Graph.getScalarMap();
|
|
|
|
ReachabilityCloner RC(*GlobalsGraph, Graph, DSGraph::StripAllocaBit);
|
|
|
|
|
2004-10-31 21:54:51 +00:00
|
|
|
// Clone everything reachable from globals in the function graph into the
|
2004-02-21 00:30:28 +00:00
|
|
|
// globals graph.
|
|
|
|
for (DSScalarMap::global_iterator I = MainSM.global_begin(),
|
2005-04-21 21:13:18 +00:00
|
|
|
E = MainSM.global_end(); I != E; ++I)
|
2004-02-21 00:30:28 +00:00
|
|
|
RC.getClonedNH(MainSM[*I]);
|
|
|
|
|
2002-11-11 21:35:13 +00:00
|
|
|
//Graph.writeGraphToFile(std::cerr, "bu_" + F.getName());
|
2002-11-12 15:58:08 +00:00
|
|
|
}
|
2005-01-24 20:00:14 +00:00
|
|
|
|
|
|
|
static const Function *getFnForValue(const Value *V) {
|
|
|
|
if (const Instruction *I = dyn_cast<Instruction>(V))
|
|
|
|
return I->getParent()->getParent();
|
|
|
|
else if (const Argument *A = dyn_cast<Argument>(V))
|
|
|
|
return A->getParent();
|
|
|
|
else if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
|
|
|
|
return BB->getParent();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// deleteValue/copyValue - Interfaces to update the DSGraphs in the program.
|
|
|
|
/// These correspond to the interfaces defined in the AliasAnalysis class.
|
|
|
|
void BUDataStructures::deleteValue(Value *V) {
|
|
|
|
if (const Function *F = getFnForValue(V)) { // Function local value?
|
|
|
|
// If this is a function local value, just delete it from the scalar map!
|
|
|
|
getDSGraph(*F).getScalarMap().eraseIfExists(V);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-01-31 00:10:45 +00:00
|
|
|
if (Function *F = dyn_cast<Function>(V)) {
|
2005-01-24 20:00:14 +00:00
|
|
|
assert(getDSGraph(*F).getReturnNodes().size() == 1 &&
|
|
|
|
"cannot handle scc's");
|
|
|
|
delete DSInfo[F];
|
|
|
|
DSInfo.erase(F);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!isa<GlobalVariable>(V) && "Do not know how to delete GV's yet!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void BUDataStructures::copyValue(Value *From, Value *To) {
|
|
|
|
if (From == To) return;
|
|
|
|
if (const Function *F = getFnForValue(From)) { // Function local value?
|
|
|
|
// If this is a function local value, just delete it from the scalar map!
|
|
|
|
getDSGraph(*F).getScalarMap().copyScalarIfExists(From, To);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Function *FromF = dyn_cast<Function>(From)) {
|
|
|
|
Function *ToF = cast<Function>(To);
|
|
|
|
assert(!DSInfo.count(ToF) && "New Function already exists!");
|
Create an equivalence class of global variables that DSA will never be able
to tell apart anyway, and only track the leader for of these equivalence
classes in our graphs.
This dramatically reduces the number of GlobalValue*'s that appear in scalar
maps, which A) reduces memory usage, by eliminating many many scalarmap entries
and B) reduces time for operations that need to execute an operation for each
global in the scalar map.
As an example, this reduces the memory used to analyze 176.gcc from 1GB to
511MB, which (while it's still way too much) is better because it doesn't hit
swap anymore. On eon, this shrinks the local graphs from 14MB to 6.8MB,
shrinks the bu+td graphs of povray from 50M to 40M, shrinks the TD graphs of
130.li from 8.8M to 3.6M, etc.
This change also speeds up DSA on large programs where this makes a big
difference. For example, 130.li goes from 1.17s -> 0.56s, 134.perl goes
from 2.14 -> 0.93s, povray goes from 15.63s->7.99s (!!!).
This also apparently either fixes the problem that caused DSA to crash on
perlbmk and gcc, or it hides it, because DSA now works on these. These
both take entirely too much time in the TD pass (147s for perl, 538s for
gcc, vs 7.67/5.9s in the bu pass for either one), but this is a known
problem that I'll deal with later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20696 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-19 22:23:45 +00:00
|
|
|
DSGraph *NG = new DSGraph(getDSGraph(*FromF), GlobalECs);
|
2005-01-24 20:00:14 +00:00
|
|
|
DSInfo[ToF] = NG;
|
|
|
|
assert(NG->getReturnNodes().size() == 1 && "Cannot copy SCC's yet!");
|
|
|
|
|
|
|
|
// Change the Function* is the returnnodes map to the ToF.
|
2005-03-15 16:55:04 +00:00
|
|
|
DSNodeHandle Ret = NG->retnodes_begin()->second;
|
2005-01-24 20:00:14 +00:00
|
|
|
NG->getReturnNodes().clear();
|
|
|
|
NG->getReturnNodes()[ToF] = Ret;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-24 04:22:04 +00:00
|
|
|
if (const Function *F = getFnForValue(To)) {
|
|
|
|
DSGraph &G = getDSGraph(*F);
|
|
|
|
G.getScalarMap().copyScalarIfExists(From, To);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << *From;
|
|
|
|
std::cerr << *To;
|
|
|
|
assert(0 && "Do not know how to copy this yet!");
|
|
|
|
abort();
|
2005-01-24 20:00:14 +00:00
|
|
|
}
|