- // If this SCC calls an external function, we can't say anything about it, so
- // remove all SCC functions from the FunctionInfo map.
- if (CallsExternal) {
- for (unsigned i = 0, e = SCC.size(); i != e; ++i)
- FunctionInfo.erase(SCC[i]->getFunction());
- return;
- }
+ if (F->isDeclaration()) {
+ // Try to get mod/ref behaviour from function attributes.
+ if (F->onlyReadsMemory()) {
+ FunctionEffect |= Ref;
+ // This function might call back into the module and read a global, so
+ // mark all globals read somewhere as being read by this function.
+ for (std::set<GlobalValue*>::iterator GI = ReadGlobals.begin(),
+ E = ReadGlobals.end(); GI != E; ++GI)
+ FR.GlobalInfo[*GI] |= Ref;
+ } else if (!F->doesNotAccessMemory()) {
+ // Can't say anything useful.
+ KnowNothing = true;
+ }
+ continue;
+ }
+
+ for (CallGraphNode::iterator CI = SCC[i]->begin(), E = SCC[i]->end();
+ CI != E; ++CI)
+ if (Function *Callee = CI->second->getFunction()) {
+ if (FunctionRecord *CalleeFR = getFunctionInfo(Callee)) {
+ // Propagate function effect up.
+ FunctionEffect |= CalleeFR->FunctionEffect;
+
+ // Incorporate callee's effects on globals into our info.
+ for (std::map<GlobalValue*, unsigned>::iterator GI =
+ CalleeFR->GlobalInfo.begin(), E = CalleeFR->GlobalInfo.end();
+ GI != E; ++GI)
+ FR.GlobalInfo[GI->first] |= GI->second;
+ } else {
+ // Can't say anything about it. However, if it is inside our SCC,
+ // then nothing needs to be done.
+ CallGraphNode *CalleeNode = CG[Callee];
+ if (std::find(SCC.begin(), SCC.end(), CalleeNode) == SCC.end())
+ KnowNothing = true;
+ }
+ } else {
+ KnowNothing = true;
+ }
+ }
+
+ // If we can't say anything useful about this SCC, remove all SCC functions
+ // from the FunctionInfo map.
+ if (KnowNothing) {
+ for (unsigned i = 0, e = SCC.size(); i != e; ++i)
+ FunctionInfo.erase(SCC[i]->getFunction());
+ return;
+ }