[llvm-commits] [poolalloc] r110368 - /poolalloc/trunk/lib/AssistDS/IndCloner.cpp
John Criswell
criswell at uiuc.edu
Thu Aug 5 12:42:08 PDT 2010
Author: criswell
Date: Thu Aug 5 14:42:07 2010
New Revision: 110368
URL: http://llvm.org/viewvc/llvm-project?rev=110368&view=rev
Log:
When a call or invoke instruction is found in a function's def-use chain,
ensure that the function isn't passed as an argument in the call.
That would make it usable as an indirect function call.
Modified:
poolalloc/trunk/lib/AssistDS/IndCloner.cpp
Modified: poolalloc/trunk/lib/AssistDS/IndCloner.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/IndCloner.cpp?rev=110368&r1=110367&r2=110368&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/IndCloner.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/IndCloner.cpp Thu Aug 5 14:42:07 2010
@@ -63,6 +63,9 @@
// clone.
//
for (Module::iterator I = M.begin(); I != M.end(); ++I) {
+ // Flag whether the function should be cloned
+ bool pleaseCloneTheFunction = false;
+
//
// Only clone functions which are defined and cannot be replaced by another
// function by the linker.
@@ -70,11 +73,32 @@
if (!I->isDeclaration() && !I->mayBeOverridden()) {
for (Value::use_iterator ui = I->use_begin(), ue = I->use_end();
ui != ue; ++ui) {
+ if (!isa<CallInst>(ui) && !isa<InvokeInst>(ui)) {
+ //
+ // If this function is used for anything other than a direct function
+ // call, then we want to clone it.
+ //
+ pleaseCloneTheFunction = true;
+ } else {
+ //
+ // This is a call instruction, but hold up ranger! We need to make
+ // sure that the function isn't passed as an argument to *another*
+ // function. That would make the function usable in an indirect
+ // function call.
+ //
+ for (unsigned index = 1; index < ui->getNumOperands(); ++index) {
+ if (ui->getOperand(index)->stripPointerCasts() == I) {
+ pleaseCloneTheFunction = true;
+ break;
+ }
+ }
+ }
+
//
- // If this function is used for anything other than a direct function
- // call, then we want to clone it.
+ // If we've discovered that the function could be used by an indirect
+ // call site, schedule it for cloning.
//
- if (!isa<CallInst>(ui) && !isa<InvokeInst>(ui)) {
+ if (pleaseCloneTheFunction) {
toClone.push_back(I);
break;
}
@@ -84,8 +108,12 @@
//
// Update the statistics on the number of functions we'll be cloning.
+ // We only update the statistic if we want to clone one or more functions;
+ // due to the magic of how statistics work, avoiding assignment prevents it
+ // from needlessly showing up.
//
- numCloned += toClone.size();
+ if (toClone.size())
+ numCloned += toClone.size();
//
// Go through the worklist and clone each function. After cloning a
More information about the llvm-commits
mailing list