static Value *createByteGEP(IRBuilderBase &IRB, const DataLayout &DL,
Value *Ptr, Type *ResElemTy, int64_t Offset) {
- // For non-opaque pointers, try create a "nice" GEP if possible, otherwise
+ // For non-opaque pointers, try to create a "nice" GEP if possible, otherwise
// fall back to an i8 GEP to a specific offset.
unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace();
APInt OrigOffset(DL.getIndexTypeSizeInBits(Ptr->getType()), Offset);
// The new function will have the !dbg metadata copied from the original
// function. The original function may not be deleted, and dbg metadata need
- // to be unique so we need to drop it.
+ // to be unique, so we need to drop it.
F->setSubprogram(nullptr);
LLVM_DEBUG(dbgs() << "ARG PROMOTION: Promoting to:" << *NF << "\n"
// Loop over the operands, inserting GEP and loads in the caller as
// appropriate.
- auto AI = CB.arg_begin();
+ auto *AI = CB.arg_begin();
ArgNo = 0;
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
++I, ++AI, ++ArgNo)
ConstantInt::get(Type::getInt32Ty(F->getContext()), 0), nullptr};
const StructLayout *SL = DL.getStructLayout(STy);
Align StructAlign = *I->getParamAlign();
- for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
- Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
+ for (unsigned J = 0, Elems = STy->getNumElements(); J != Elems; ++J) {
+ Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), J);
auto *Idx =
- IRB.CreateGEP(STy, *AI, Idxs, (*AI)->getName() + "." + Twine(i));
+ IRB.CreateGEP(STy, *AI, Idxs, (*AI)->getName() + "." + Twine(J));
// TODO: Tell AA about the new values?
Align Alignment =
- commonAlignment(StructAlign, SL->getElementOffset(i));
+ commonAlignment(StructAlign, SL->getElementOffset(J));
Args.push_back(IRB.CreateAlignedLoad(
- STy->getElementType(i), Idx, Alignment, Idx->getName() + ".val"));
+ STy->getElementType(J), Idx, Alignment, Idx->getName() + ".val"));
ArgAttrVec.push_back(AttributeSet());
}
} else if (!I->use_empty()) {
nullptr};
const StructLayout *SL = DL.getStructLayout(STy);
- for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
- Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
+ for (unsigned J = 0, Elems = STy->getNumElements(); J != Elems; ++J) {
+ Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), J);
Value *Idx = GetElementPtrInst::Create(
- AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(i),
+ AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(J),
InsertPt);
- I2->setName(Arg.getName() + "." + Twine(i));
- Align Alignment = commonAlignment(StructAlign, SL->getElementOffset(i));
+ I2->setName(Arg.getName() + "." + Twine(J));
+ Align Alignment = commonAlignment(StructAlign, SL->getElementOffset(J));
new StoreInst(&*I2++, Idx, false, Alignment, InsertPt);
}
return false;
}
- // If this load is not guaranteed to execute and we haven't seen a load at
+ // If this load is not guaranteed to execute, and we haven't seen a load at
// this offset before (or it had lower alignment), then we need to remember
// that requirement.
// Note that skipping loads of previously seen offsets is only correct
Offset = Pair.first + DL.getTypeStoreSize(Pair.second.Ty);
}
- // Okay, now we know that the argument is only used by load instructions and
+ // Okay, now we know that the argument is only used by load instructions, and
// it is safe to unconditionally perform all of them. Use alias analysis to
// check to see if the pointer is guaranteed to not be modified from entry of
// the function to each of the load instructions.
return true;
}
-bool ArgumentPromotionPass::isDenselyPacked(Type *type, const DataLayout &DL) {
+bool ArgumentPromotionPass::isDenselyPacked(Type *Ty, const DataLayout &DL) {
// There is no size information, so be conservative.
- if (!type->isSized())
+ if (!Ty->isSized())
return false;
// If the alloc size is not equal to the storage size, then there are padding
// bytes. For x86_fp80 on x86-64, size: 80 alloc size: 128.
- if (DL.getTypeSizeInBits(type) != DL.getTypeAllocSizeInBits(type))
+ if (DL.getTypeSizeInBits(Ty) != DL.getTypeAllocSizeInBits(Ty))
return false;
// FIXME: This isn't the right way to check for padding in vectors with
// non-byte-size elements.
- if (VectorType *seqTy = dyn_cast<VectorType>(type))
- return isDenselyPacked(seqTy->getElementType(), DL);
+ if (VectorType *SeqTy = dyn_cast<VectorType>(Ty))
+ return isDenselyPacked(SeqTy->getElementType(), DL);
// For array types, check for padding within members.
- if (ArrayType *seqTy = dyn_cast<ArrayType>(type))
- return isDenselyPacked(seqTy->getElementType(), DL);
+ if (ArrayType *SeqTy = dyn_cast<ArrayType>(Ty))
+ return isDenselyPacked(SeqTy->getElementType(), DL);
- if (!isa<StructType>(type))
+ if (!isa<StructType>(Ty))
return true;
// Check for padding within and between elements of a struct.
- StructType *StructTy = cast<StructType>(type);
+ StructType *StructTy = cast<StructType>(Ty);
const StructLayout *Layout = DL.getStructLayout(StructTy);
uint64_t StartPos = 0;
- for (unsigned i = 0, E = StructTy->getNumElements(); i < E; ++i) {
- Type *ElTy = StructTy->getElementType(i);
+ for (unsigned I = 0, E = StructTy->getNumElements(); I < E; ++I) {
+ Type *ElTy = StructTy->getElementType(I);
if (!isDenselyPacked(ElTy, DL))
return false;
- if (StartPos != Layout->getElementOffsetInBits(i))
+ if (StartPos != Layout->getElementOffsetInBits(I))
return false;
StartPos += DL.getTypeAllocSizeInBits(ElTy);
}
}
/// Checks if the padding bytes of an argument could be accessed.
-static bool canPaddingBeAccessed(Argument *arg) {
- assert(arg->hasByValAttr());
+static bool canPaddingBeAccessed(Argument *Arg) {
+ assert(Arg->hasByValAttr());
// Track all the pointers to the argument to make sure they are not captured.
SmallPtrSet<Value *, 16> PtrValues;
- PtrValues.insert(arg);
+ PtrValues.insert(Arg);
// Track all of the stores.
SmallVector<StoreInst *, 16> Stores;
// Scan through the uses recursively to make sure the pointer is always used
// sanely.
- SmallVector<Value *, 16> WorkList(arg->users());
+ SmallVector<Value *, 16> WorkList(Arg->users());
while (!WorkList.empty()) {
Value *V = WorkList.pop_back_val();
if (isa<GetElementPtrInst>(V) || isa<PHINode>(V)) {
if (CB->isMustTailCall())
return nullptr;
- if (CB->getParent()->getParent() == F)
+ if (CB->getFunction() == F)
IsRecursive = true;
}
// Only handle arguments with specified alignment; if it's unspecified, the
// actual alignment of the argument is target-specific.
Type *ByValTy = PtrArg->getParamByValType();
- bool isSafeToPromote =
+ bool IsSafeToPromote =
ByValTy && PtrArg->getParamAlign() &&
(ArgumentPromotionPass::isDenselyPacked(ByValTy, DL) ||
!canPaddingBeAccessed(PtrArg));
- if (isSafeToPromote) {
+ if (IsSafeToPromote) {
if (StructType *STy = dyn_cast<StructType>(ByValTy)) {
if (MaxElements > 0 && STy->getNumElements() > MaxElements) {
- LLVM_DEBUG(dbgs() << "argpromotion disable promoting argument '"
+ LLVM_DEBUG(dbgs() << "ArgPromotion disables promoting argument '"
<< PtrArg->getName()
<< "' because it would require adding more"
<< " than " << MaxElements
else
OldF->setLinkage(Function::ExternalLinkage);
- // And updat ethe SCC we're iterating as well.
+ // And update the SCC we're iterating as well.
SCC.ReplaceNode(OldNode, NewNode);
}
}