//
// This pass promotes "by reference" arguments to be "by value" arguments. In
// practice, this means looking for internal functions that have pointer
-// arguments. If we can prove, through the use of alias analysis, that an
-// argument is *only* loaded, then we can pass the value into the function
+// arguments. If it can prove, through the use of alias analysis, that an
+// argument is *only* loaded, then it can pass the value into the function
// instead of the address of the value. This can cause recursive simplification
// of code and lead to the elimination of allocas (especially in C++ template
// code like the STL).
//
// This pass also handles aggregate arguments that are passed into a function,
// scalarizing them if the elements of the aggregate are only loaded. Note that
-// we refuse to scalarize aggregates which would require passing in more than
-// three operands to the function, because we don't want to pass thousands of
-// operands for a large array or structure!
+// it refuses to scalarize aggregates which would require passing in more than
+// three operands to the function, because passing thousands of operands for a
+// large array or structure is unprofitable!
//
// Note that this transformation could also be done for arguments that are only
-// stored to (returning the value instead), but we do not currently handle that
-// case. This case would be best handled when and if we start supporting
-// multiple return values from functions.
+// stored to (returning the value instead), but does not currently. This case
+// would be best handled when and if LLVM begins supporting multiple return
+// values from functions.
//
//===----------------------------------------------------------------------===//
}
virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC);
- static const char ID; // Pass identifcation, replacement for typeid
+ static char ID; // Pass identification, replacement for typeid
ArgPromotion() : CallGraphSCCPass((intptr_t)&ID) {}
private:
Function *DoPromotion(Function *F, std::vector<Argument*> &ArgsToPromote);
};
- const char ArgPromotion::ID = 0;
+ char ArgPromotion::ID = 0;
RegisterPass<ArgPromotion> X("argpromotion",
"Promote 'by reference' arguments to scalars");
}
const PointerType *LoadTy =
cast<PointerType>(Load->getOperand(0)->getType());
- unsigned LoadSize = (unsigned)TD.getTypeSize(LoadTy->getElementType());
+ unsigned LoadSize = (unsigned)TD.getTypeStoreSize(LoadTy->getElementType());
if (AA.canInstructionRangeModify(BB->front(), *Load, Arg, LoadSize))
return false; // Pointer is invalidated!
for (ScalarizeTable::iterator SI = ArgIndices.begin(),
E = ArgIndices.end(); SI != E; ++SI)
Params.push_back(GetElementPtrInst::getIndexedType(I->getType(),
- &(*SI)[0],
- SI->size()));
+ SI->begin(),
+ SI->end()));
if (ArgIndices.size() == 1 && ArgIndices.begin()->empty())
++NumArgumentsPromoted;
Value *V = *AI;
LoadInst *OrigLoad = OriginalLoads[*SI];
if (!SI->empty()) {
- V = new GetElementPtrInst(V, &(*SI)[0], SI->size(),
+ V = new GetElementPtrInst(V, SI->begin(), SI->end(),
V->getName()+".idx", Call);
AA.copyValue(OrigLoad->getOperand(0), V);
}
Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
- &Args[0], Args.size(), "", Call);
+ Args.begin(), Args.end(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else {
- New = new CallInst(NF, &Args[0], Args.size(), "", Call);
+ New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
std::string NewName = I->getName();
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
if (ConstantInt *CI = dyn_cast<ConstantInt>(Operands[i]))
- NewName += "." + CI->getValue().toString(10);
+ NewName += "." + CI->getValue().toStringUnsigned(10);
else
NewName += ".x";
TheArg->setName(NewName+".val");