[llvm-commits] [llvm] r58557 - in /llvm/trunk: include/llvm/LinkAllPasses.h include/llvm/Transforms/IPO.h lib/Transforms/IPO/MergeFunctions.cpp test/Transforms/MergeFunc/ test/Transforms/MergeFunc/Output/ test/Transforms/MergeFunc/dg.exp test/Transforms/MergeFunc/phi-speculation1.ll test/Transforms/MergeFunc/phi-speculation2.ll

Duncan Sands duncan.sands at math.u-psud.fr
Sun Nov 2 01:21:51 PDT 2008


Hi,

> +static bool fold(std::vector<Function *> &FnVec, unsigned i, unsigned j) {
> +  if (FnVec[i]->mayBeOverridden() && !FnVec[j]->mayBeOverridden())
> +    std::swap(FnVec[i], FnVec[j]);
> +
> +  Function *F = FnVec[i];
> +  Function *G = FnVec[j];
> +
> +  if (!F->mayBeOverridden()) {

If they can both be overridden, then they could still be merged by creating
a new merged function and two aliases, one for each.  May not be worth it,
in which case it is worth a comment :)

> +    // Make sure we aren't passing U as a parameter to call instead of the
> +    // callee. getOperand(0) is the callee for both CallInst and
> InvokeInst. +    // Check the other operands to see if any of them is F.
> +    for (User::op_iterator OI = I->op_begin() + 1, OE = I->op_end(); OI !=
> OE; +         ++OI) {
> +      if (*OI == U)
> +        return true;
> +    }

CallSite has a hasArgument method that can be used for this.

> +    if (F->hasLinkOnceLinkage() || F->hasCommonLinkage() ||
> +        F->hasDLLImportLinkage() || F->hasDLLExportLinkage())
> +      continue;

Rather than listing linkage types that are not ok, it would be
safer to list linkage types that are ok.  That way, when new
linkage types are added the code will continue to be conservatively
correct.

Ciao,

Duncan.



More information about the llvm-commits mailing list