[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
This commit is contained in:
parent
05b0a49832
commit
744a837838
|
@ -28,7 +28,7 @@ public:
|
|||
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);
|
||||
|
|
|
@ -100,7 +100,7 @@ using OffsetAndArgPart = std::pair<int64_t, ArgPart>;
|
|||
|
||||
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 @@ static Function *doPromotion(
|
|||
|
||||
// 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 @@ static Function *doPromotion(
|
|||
|
||||
// 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 @@ static Function *doPromotion(
|
|||
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()) {
|
||||
|
@ -355,13 +355,13 @@ static Function *doPromotion(
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -523,7 +523,7 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
|
|||
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 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
|
|||
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 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
|
|||
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);
|
||||
}
|
||||
|
@ -698,19 +698,19 @@ bool ArgumentPromotionPass::isDenselyPacked(Type *type, const DataLayout &DL) {
|
|||
}
|
||||
|
||||
/// 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)) {
|
||||
|
@ -801,7 +801,7 @@ promoteArguments(Function *F, function_ref<AAResults &(Function &F)> AARGetter,
|
|||
if (CB->isMustTailCall())
|
||||
return nullptr;
|
||||
|
||||
if (CB->getParent()->getParent() == F)
|
||||
if (CB->getFunction() == F)
|
||||
IsRecursive = true;
|
||||
}
|
||||
|
||||
|
@ -840,14 +840,14 @@ promoteArguments(Function *F, function_ref<AAResults &(Function &F)> AARGetter,
|
|||
// 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
|
||||
|
@ -1048,7 +1048,7 @@ bool ArgPromotion::runOnSCC(CallGraphSCC &SCC) {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue