From 023883a8346076b2869516c7c0c2fd9e1f139acb Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 29 Jun 2020 15:13:32 -0400 Subject: [PATCH] IR: Rename Argument::hasPassPointeeByValueAttr to prepare for byref When the byref attribute is added, there will need to be two similar functions for the existing cases which have an associate value copy, and byref which does not. Most, but not all of the existing uses will use the existing version. The associated size function added by D82679 also needs to contextually differ, and will help eliminate a few places still relying on pointee element types. --- llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h | 2 +- llvm/include/llvm/IR/Argument.h | 5 +++-- llvm/lib/Analysis/MemoryBuiltins.cpp | 2 +- llvm/lib/Analysis/ValueTracking.cpp | 2 +- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 2 +- llvm/lib/IR/Function.cpp | 2 +- llvm/lib/IR/Mangler.cpp | 2 +- llvm/lib/Target/ARM/ARMCallLowering.cpp | 2 +- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp | 2 +- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 4 ++-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 2 +- 11 files changed, 14 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h index cad1c52f7f87..945d41c37677 100644 --- a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h +++ b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h @@ -146,7 +146,7 @@ inline bool IsPotentialRetainableObjPtr(const Value *Op) { return false; // Special arguments can not be a valid retainable object pointer. if (const Argument *Arg = dyn_cast(Op)) - if (Arg->hasPassPointeeByValueAttr() || Arg->hasNestAttr() || + if (Arg->hasPassPointeeByValueCopyAttr() || Arg->hasNestAttr() || Arg->hasStructRetAttr()) return false; // Only consider values with pointer types. diff --git a/llvm/include/llvm/IR/Argument.h b/llvm/include/llvm/IR/Argument.h index af469e8a5d1a..2ca18c610349 100644 --- a/llvm/include/llvm/IR/Argument.h +++ b/llvm/include/llvm/IR/Argument.h @@ -72,8 +72,9 @@ public: bool hasSwiftErrorAttr() const; /// Return true if this argument has the byval, inalloca, or preallocated - /// attribute. These attributes represent arguments being passed by value. - bool hasPassPointeeByValueAttr() const; + /// attribute. These attributes represent arguments being passed by value, + /// with an associated copy between the caller and callee + bool hasPassPointeeByValueCopyAttr() const; /// If this argument satisfies has hasPassPointeeByValueAttr, return the /// in-memory ABI size copied to the stack for the call. Otherwise, return 0. diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 0b61b1c0eabd..204f855d28b3 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -677,7 +677,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitAllocaInst(AllocaInst &I) { SizeOffsetType ObjectSizeOffsetVisitor::visitArgument(Argument &A) { // No interprocedural analysis is done at the moment. - if (!A.hasPassPointeeByValueAttr()) { + if (!A.hasPassPointeeByValueCopyAttr()) { ++ObjectVisitorArgument; return unknown(); } diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 306f6a4a35ca..bc8f02972de8 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2362,7 +2362,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth, // A byval, inalloca may not be null in a non-default addres space. A // nonnull argument is assumed never 0. if (const Argument *A = dyn_cast(V)) { - if (((A->hasPassPointeeByValueAttr() && + if (((A->hasPassPointeeByValueCopyAttr() && !NullPointerIsDefined(A->getParent(), PtrTy->getAddressSpace())) || A->hasNonNullAttr())) return true; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 1d596c89c911..c0f84055cfce 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -9571,7 +9571,7 @@ findArgumentCopyElisionCandidates(const DataLayout &DL, // initializes the alloca. Don't elide copies from the same argument twice. const Value *Val = SI->getValueOperand()->stripPointerCasts(); const auto *Arg = dyn_cast(Val); - if (!Arg || Arg->hasPassPointeeByValueAttr() || + if (!Arg || Arg->hasPassPointeeByValueCopyAttr() || Arg->getType()->isEmptyTy() || DL.getTypeStoreSize(Arg->getType()) != DL.getTypeAllocSize(AI->getAllocatedType()) || diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 10d535e3ab11..8db2389ef542 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -121,7 +121,7 @@ bool Argument::hasPreallocatedAttr() const { return hasAttribute(Attribute::Preallocated); } -bool Argument::hasPassPointeeByValueAttr() const { +bool Argument::hasPassPointeeByValueCopyAttr() const { if (!getType()->isPointerTy()) return false; AttributeList Attrs = getParent()->getAttributes(); return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) || diff --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp index 0d66e321c396..218c12ba433f 100644 --- a/llvm/lib/IR/Mangler.cpp +++ b/llvm/lib/IR/Mangler.cpp @@ -100,7 +100,7 @@ static void addByteCountSuffix(raw_ostream &OS, const Function *F, for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end(); AI != AE; ++AI) { // 'Dereference' type in case of byval or inalloca parameter attribute. - uint64_t AllocSize = AI->hasPassPointeeByValueAttr() ? + uint64_t AllocSize = AI->hasPassPointeeByValueCopyAttr() ? AI->getPassPointeeByValueCopySize(DL) : DL.getTypeAllocSize(AI->getType()); diff --git a/llvm/lib/Target/ARM/ARMCallLowering.cpp b/llvm/lib/Target/ARM/ARMCallLowering.cpp index d860473011e7..4f1410eecff4 100644 --- a/llvm/lib/Target/ARM/ARMCallLowering.cpp +++ b/llvm/lib/Target/ARM/ARMCallLowering.cpp @@ -435,7 +435,7 @@ bool ARMCallLowering::lowerFormalArguments( for (auto &Arg : F.args()) { if (!isSupportedType(DL, TLI, Arg.getType())) return false; - if (Arg.hasPassPointeeByValueAttr()) + if (Arg.hasPassPointeeByValueCopyAttr()) return false; } diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp index 54c51b6e7161..af5f72f6b636 100644 --- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -289,7 +289,7 @@ bool DeadArgumentEliminationPass::RemoveDeadArgumentsFromCallers(Function &Fn) { for (Argument &Arg : Fn.args()) { if (!Arg.hasSwiftErrorAttr() && Arg.use_empty() && - !Arg.hasPassPointeeByValueAttr()) { + !Arg.hasPassPointeeByValueCopyAttr()) { if (Arg.isUsedByMetadata()) { Arg.replaceAllUsesWith(UndefValue::get(Arg.getType())); Changed = true; diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 8c044ed0b981..258fd5b9454f 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -848,7 +848,7 @@ static bool handleEndBlock(BasicBlock &BB, AliasAnalysis *AA, // Treat byval or inalloca arguments the same, stores to them are dead at the // end of the function. for (Argument &AI : BB.getParent()->args()) - if (AI.hasPassPointeeByValueAttr()) + if (AI.hasPassPointeeByValueCopyAttr()) DeadStackObjects.insert(&AI); const DataLayout &DL = BB.getModule()->getDataLayout(); @@ -1563,7 +1563,7 @@ struct DSEState { // Treat byval or inalloca arguments the same as Allocas, stores to them are // dead at the end of the function. for (Argument &AI : F.args()) - if (AI.hasPassPointeeByValueAttr()) { + if (AI.hasPassPointeeByValueCopyAttr()) { // For byval, the caller doesn't know the address of the allocation. if (AI.hasByValAttr()) State.InvisibleToCallerBeforeRet.insert(&AI); diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index b0b7ca484798..5c9cb1245d01 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1245,7 +1245,7 @@ static void AddAlignmentAssumptions(CallBase &CB, InlineFunctionInfo &IFI) { Function *CalledFunc = CB.getCalledFunction(); for (Argument &Arg : CalledFunc->args()) { unsigned Align = Arg.getType()->isPointerTy() ? Arg.getParamAlignment() : 0; - if (Align && !Arg.hasPassPointeeByValueAttr() && !Arg.hasNUses(0)) { + if (Align && !Arg.hasPassPointeeByValueCopyAttr() && !Arg.hasNUses(0)) { if (!DTCalculated) { DT.recalculate(*CB.getCaller()); DTCalculated = true;