Skip to content

Commit 744a837

Browse files
samolisovnikic
authored andcommitted
[ArgPromotion] Rename variables according to the code style. NFC
Some loop counters ('i', 'e') and variables ('type') were named not in accordance with the code style and clang-tidy issues warnings about the using of such variables. This patch renames the variables and fixes some typos in the comments within the source file. Differential Revision: https://reviews.llvm.org/D123662
1 parent 05b0a49 commit 744a837

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ArgumentPromotionPass : public PassInfoMixin<ArgumentPromotionPass> {
2828
ArgumentPromotionPass(unsigned MaxElements = 3u) : MaxElements(MaxElements) {}
2929

3030
/// Checks if a type could have padding bytes.
31-
static bool isDenselyPacked(Type *type, const DataLayout &DL);
31+
static bool isDenselyPacked(Type *Ty, const DataLayout &DL);
3232

3333
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
3434
LazyCallGraph &CG, CGSCCUpdateResult &UR);

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ using OffsetAndArgPart = std::pair<int64_t, ArgPart>;
100100

101101
static Value *createByteGEP(IRBuilderBase &IRB, const DataLayout &DL,
102102
Value *Ptr, Type *ResElemTy, int64_t Offset) {
103-
// For non-opaque pointers, try create a "nice" GEP if possible, otherwise
103+
// For non-opaque pointers, try to create a "nice" GEP if possible, otherwise
104104
// fall back to an i8 GEP to a specific offset.
105105
unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace();
106106
APInt OrigOffset(DL.getIndexTypeSizeInBits(Ptr->getType()), Offset);
@@ -207,7 +207,7 @@ static Function *doPromotion(
207207

208208
// The new function will have the !dbg metadata copied from the original
209209
// function. The original function may not be deleted, and dbg metadata need
210-
// to be unique so we need to drop it.
210+
// to be unique, so we need to drop it.
211211
F->setSubprogram(nullptr);
212212

213213
LLVM_DEBUG(dbgs() << "ARG PROMOTION: Promoting to:" << *NF << "\n"
@@ -235,7 +235,7 @@ static Function *doPromotion(
235235

236236
// Loop over the operands, inserting GEP and loads in the caller as
237237
// appropriate.
238-
auto AI = CB.arg_begin();
238+
auto *AI = CB.arg_begin();
239239
ArgNo = 0;
240240
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
241241
++I, ++AI, ++ArgNo)
@@ -250,15 +250,15 @@ static Function *doPromotion(
250250
ConstantInt::get(Type::getInt32Ty(F->getContext()), 0), nullptr};
251251
const StructLayout *SL = DL.getStructLayout(STy);
252252
Align StructAlign = *I->getParamAlign();
253-
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
254-
Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
253+
for (unsigned J = 0, Elems = STy->getNumElements(); J != Elems; ++J) {
254+
Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), J);
255255
auto *Idx =
256-
IRB.CreateGEP(STy, *AI, Idxs, (*AI)->getName() + "." + Twine(i));
256+
IRB.CreateGEP(STy, *AI, Idxs, (*AI)->getName() + "." + Twine(J));
257257
// TODO: Tell AA about the new values?
258258
Align Alignment =
259-
commonAlignment(StructAlign, SL->getElementOffset(i));
259+
commonAlignment(StructAlign, SL->getElementOffset(J));
260260
Args.push_back(IRB.CreateAlignedLoad(
261-
STy->getElementType(i), Idx, Alignment, Idx->getName() + ".val"));
261+
STy->getElementType(J), Idx, Alignment, Idx->getName() + ".val"));
262262
ArgAttrVec.push_back(AttributeSet());
263263
}
264264
} else if (!I->use_empty()) {
@@ -355,13 +355,13 @@ static Function *doPromotion(
355355
nullptr};
356356
const StructLayout *SL = DL.getStructLayout(STy);
357357

358-
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
359-
Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
358+
for (unsigned J = 0, Elems = STy->getNumElements(); J != Elems; ++J) {
359+
Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), J);
360360
Value *Idx = GetElementPtrInst::Create(
361-
AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(i),
361+
AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(J),
362362
InsertPt);
363-
I2->setName(Arg.getName() + "." + Twine(i));
364-
Align Alignment = commonAlignment(StructAlign, SL->getElementOffset(i));
363+
I2->setName(Arg.getName() + "." + Twine(J));
364+
Align Alignment = commonAlignment(StructAlign, SL->getElementOffset(J));
365365
new StoreInst(&*I2++, Idx, false, Alignment, InsertPt);
366366
}
367367

@@ -523,7 +523,7 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
523523
return false;
524524
}
525525

526-
// If this load is not guaranteed to execute and we haven't seen a load at
526+
// If this load is not guaranteed to execute, and we haven't seen a load at
527527
// this offset before (or it had lower alignment), then we need to remember
528528
// that requirement.
529529
// Note that skipping loads of previously seen offsets is only correct
@@ -625,7 +625,7 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
625625
Offset = Pair.first + DL.getTypeStoreSize(Pair.second.Ty);
626626
}
627627

628-
// Okay, now we know that the argument is only used by load instructions and
628+
// Okay, now we know that the argument is only used by load instructions, and
629629
// it is safe to unconditionally perform all of them. Use alias analysis to
630630
// check to see if the pointer is guaranteed to not be modified from entry of
631631
// the function to each of the load instructions.
@@ -659,37 +659,37 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
659659
return true;
660660
}
661661

662-
bool ArgumentPromotionPass::isDenselyPacked(Type *type, const DataLayout &DL) {
662+
bool ArgumentPromotionPass::isDenselyPacked(Type *Ty, const DataLayout &DL) {
663663
// There is no size information, so be conservative.
664-
if (!type->isSized())
664+
if (!Ty->isSized())
665665
return false;
666666

667667
// If the alloc size is not equal to the storage size, then there are padding
668668
// bytes. For x86_fp80 on x86-64, size: 80 alloc size: 128.
669-
if (DL.getTypeSizeInBits(type) != DL.getTypeAllocSizeInBits(type))
669+
if (DL.getTypeSizeInBits(Ty) != DL.getTypeAllocSizeInBits(Ty))
670670
return false;
671671

672672
// FIXME: This isn't the right way to check for padding in vectors with
673673
// non-byte-size elements.
674-
if (VectorType *seqTy = dyn_cast<VectorType>(type))
675-
return isDenselyPacked(seqTy->getElementType(), DL);
674+
if (VectorType *SeqTy = dyn_cast<VectorType>(Ty))
675+
return isDenselyPacked(SeqTy->getElementType(), DL);
676676

677677
// For array types, check for padding within members.
678-
if (ArrayType *seqTy = dyn_cast<ArrayType>(type))
679-
return isDenselyPacked(seqTy->getElementType(), DL);
678+
if (ArrayType *SeqTy = dyn_cast<ArrayType>(Ty))
679+
return isDenselyPacked(SeqTy->getElementType(), DL);
680680

681-
if (!isa<StructType>(type))
681+
if (!isa<StructType>(Ty))
682682
return true;
683683

684684
// Check for padding within and between elements of a struct.
685-
StructType *StructTy = cast<StructType>(type);
685+
StructType *StructTy = cast<StructType>(Ty);
686686
const StructLayout *Layout = DL.getStructLayout(StructTy);
687687
uint64_t StartPos = 0;
688-
for (unsigned i = 0, E = StructTy->getNumElements(); i < E; ++i) {
689-
Type *ElTy = StructTy->getElementType(i);
688+
for (unsigned I = 0, E = StructTy->getNumElements(); I < E; ++I) {
689+
Type *ElTy = StructTy->getElementType(I);
690690
if (!isDenselyPacked(ElTy, DL))
691691
return false;
692-
if (StartPos != Layout->getElementOffsetInBits(i))
692+
if (StartPos != Layout->getElementOffsetInBits(I))
693693
return false;
694694
StartPos += DL.getTypeAllocSizeInBits(ElTy);
695695
}
@@ -698,19 +698,19 @@ bool ArgumentPromotionPass::isDenselyPacked(Type *type, const DataLayout &DL) {
698698
}
699699

700700
/// Checks if the padding bytes of an argument could be accessed.
701-
static bool canPaddingBeAccessed(Argument *arg) {
702-
assert(arg->hasByValAttr());
701+
static bool canPaddingBeAccessed(Argument *Arg) {
702+
assert(Arg->hasByValAttr());
703703

704704
// Track all the pointers to the argument to make sure they are not captured.
705705
SmallPtrSet<Value *, 16> PtrValues;
706-
PtrValues.insert(arg);
706+
PtrValues.insert(Arg);
707707

708708
// Track all of the stores.
709709
SmallVector<StoreInst *, 16> Stores;
710710

711711
// Scan through the uses recursively to make sure the pointer is always used
712712
// sanely.
713-
SmallVector<Value *, 16> WorkList(arg->users());
713+
SmallVector<Value *, 16> WorkList(Arg->users());
714714
while (!WorkList.empty()) {
715715
Value *V = WorkList.pop_back_val();
716716
if (isa<GetElementPtrInst>(V) || isa<PHINode>(V)) {
@@ -801,7 +801,7 @@ promoteArguments(Function *F, function_ref<AAResults &(Function &F)> AARGetter,
801801
if (CB->isMustTailCall())
802802
return nullptr;
803803

804-
if (CB->getParent()->getParent() == F)
804+
if (CB->getFunction() == F)
805805
IsRecursive = true;
806806
}
807807

@@ -840,14 +840,14 @@ promoteArguments(Function *F, function_ref<AAResults &(Function &F)> AARGetter,
840840
// Only handle arguments with specified alignment; if it's unspecified, the
841841
// actual alignment of the argument is target-specific.
842842
Type *ByValTy = PtrArg->getParamByValType();
843-
bool isSafeToPromote =
843+
bool IsSafeToPromote =
844844
ByValTy && PtrArg->getParamAlign() &&
845845
(ArgumentPromotionPass::isDenselyPacked(ByValTy, DL) ||
846846
!canPaddingBeAccessed(PtrArg));
847-
if (isSafeToPromote) {
847+
if (IsSafeToPromote) {
848848
if (StructType *STy = dyn_cast<StructType>(ByValTy)) {
849849
if (MaxElements > 0 && STy->getNumElements() > MaxElements) {
850-
LLVM_DEBUG(dbgs() << "argpromotion disable promoting argument '"
850+
LLVM_DEBUG(dbgs() << "ArgPromotion disables promoting argument '"
851851
<< PtrArg->getName()
852852
<< "' because it would require adding more"
853853
<< " than " << MaxElements
@@ -1048,7 +1048,7 @@ bool ArgPromotion::runOnSCC(CallGraphSCC &SCC) {
10481048
else
10491049
OldF->setLinkage(Function::ExternalLinkage);
10501050

1051-
// And updat ethe SCC we're iterating as well.
1051+
// And update the SCC we're iterating as well.
10521052
SCC.ReplaceNode(OldNode, NewNode);
10531053
}
10541054
}

0 commit comments

Comments
 (0)