diff --git a/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h b/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h --- a/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h +++ b/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h @@ -28,7 +28,7 @@ ArgumentPromotionPass(unsigned MaxElements = 3u) : MaxElements(MaxElements) {} /// Checks if a type could have padding bytes. - static bool isDenselyPacked(Type *type, const DataLayout &DL); + static bool isDenselyPacked(Type *Ty, const DataLayout &DL); PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR); diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -100,7 +100,7 @@ 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); @@ -207,7 +207,7 @@ // 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" @@ -235,7 +235,7 @@ // 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) @@ -250,15 +250,15 @@ 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 N = 0, Elems = STy->getNumElements(); N != Elems; ++N) { + Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), N); auto *Idx = - IRB.CreateGEP(STy, *AI, Idxs, (*AI)->getName() + "." + Twine(i)); + IRB.CreateGEP(STy, *AI, Idxs, (*AI)->getName() + "." + Twine(N)); // TODO: Tell AA about the new values? Align Alignment = - commonAlignment(StructAlign, SL->getElementOffset(i)); + commonAlignment(StructAlign, SL->getElementOffset(N)); Args.push_back(IRB.CreateAlignedLoad( - STy->getElementType(i), Idx, Alignment, Idx->getName() + ".val")); + STy->getElementType(N), Idx, Alignment, Idx->getName() + ".val")); ArgAttrVec.push_back(AttributeSet()); } } else if (!I->use_empty()) { @@ -355,13 +355,13 @@ 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 N = 0, Elems = STy->getNumElements(); N != Elems; ++N) { + Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), N); Value *Idx = GetElementPtrInst::Create( - AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(i), + AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(N), InsertPt); - I2->setName(Arg.getName() + "." + Twine(i)); - Align Alignment = commonAlignment(StructAlign, SL->getElementOffset(i)); + I2->setName(Arg.getName() + "." + Twine(N)); + Align Alignment = commonAlignment(StructAlign, SL->getElementOffset(N)); new StoreInst(&*I2++, Idx, false, Alignment, InsertPt); } @@ -523,7 +523,7 @@ 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 @@ -625,7 +625,7 @@ 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. @@ -659,37 +659,37 @@ 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(type)) - return isDenselyPacked(seqTy->getElementType(), DL); + if (VectorType *SeqTy = dyn_cast(Ty)) + return isDenselyPacked(SeqTy->getElementType(), DL); // For array types, check for padding within members. - if (ArrayType *seqTy = dyn_cast(type)) - return isDenselyPacked(seqTy->getElementType(), DL); + if (ArrayType *SeqTy = dyn_cast(Ty)) + return isDenselyPacked(SeqTy->getElementType(), DL); - if (!isa(type)) + if (!isa(Ty)) return true; // Check for padding within and between elements of a struct. - StructType *StructTy = cast(type); + StructType *StructTy = cast(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); } @@ -698,19 +698,19 @@ } /// 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 PtrValues; - PtrValues.insert(arg); + PtrValues.insert(Arg); // Track all of the stores. SmallVector Stores; // Scan through the uses recursively to make sure the pointer is always used // sanely. - SmallVector WorkList(arg->users()); + SmallVector WorkList(Arg->users()); while (!WorkList.empty()) { Value *V = WorkList.pop_back_val(); if (isa(V) || isa(V)) { @@ -801,7 +801,7 @@ if (CB->isMustTailCall()) return nullptr; - if (CB->getParent()->getParent() == F) + if (CB->getFunction() == F) IsRecursive = true; } @@ -840,14 +840,14 @@ // 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(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 @@ -1048,7 +1048,7 @@ 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); } }