From b55f83d013eff244f7cf6bfcd06f06f7c894ff28 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Fri, 13 Jan 2023 15:50:38 +0000 Subject: [PATCH] [NFC] Remove Function::getParamAlignment Differential Revision: https://reviews.llvm.org/D141696 --- llvm/include/llvm/IR/Function.h | 9 ----- llvm/lib/IR/Function.cpp | 5 --- .../Target/AMDGPU/AMDGPULowerKernelArguments.cpp | 10 ++--- .../Transforms/Instrumentation/MemorySanitizer.cpp | 2 +- llvm/lib/Transforms/Utils/InlineFunction.cpp | 47 ++++++++++++---------- 5 files changed, 30 insertions(+), 43 deletions(-) diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index 0ffbf90..aee0a9d 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -437,15 +437,6 @@ public: /// attributes for the given arg. void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes); - /// Extract the alignment for a call or parameter (0=unknown). - /// FIXME: Remove this function once transition to Align is over. - /// Use getParamAlign() instead. - uint64_t getParamAlignment(unsigned ArgNo) const { - if (const auto MA = getParamAlign(ArgNo)) - return MA->value(); - return 0; - } - MaybeAlign getParamAlign(unsigned ArgNo) const { return AttributeSets.getParamAlignment(ArgNo); } diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 694e805..677db46 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -188,11 +188,6 @@ Type *Argument::getPointeeInMemoryValueType() const { return getMemoryParamAllocType(ParamAttrs); } -uint64_t Argument::getParamAlignment() const { - assert(getType()->isPointerTy() && "Only pointers have alignments"); - return getParent()->getParamAlignment(getArgNo()); -} - MaybeAlign Argument::getParamAlign() const { assert(getType()->isPointerTy() && "Only pointers have alignments"); return getParent()->getParamAlign(getArgNo()); diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp index bacd12b..f3ff9b7 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp @@ -200,13 +200,11 @@ bool AMDGPULowerKernelArguments::runOnFunction(Function &F) { DerefOrNullBytes)))); } - unsigned ParamAlign = Arg.getParamAlignment(); - if (ParamAlign != 0) { + if (MaybeAlign ParamAlign = Arg.getParamAlign()) { Load->setMetadata( - LLVMContext::MD_align, - MDNode::get(Ctx, - MDB.createConstant(ConstantInt::get(Builder.getInt64Ty(), - ParamAlign)))); + LLVMContext::MD_align, + MDNode::get(Ctx, MDB.createConstant(ConstantInt::get( + Builder.getInt64Ty(), ParamAlign->value())))); } } diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 4dd6afe..178267a 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1899,7 +1899,7 @@ struct MemorySanitizerVisitor : public InstVisitor { // argument shadow to the underlying memory. // Figure out maximal valid memcpy alignment. const Align ArgAlign = DL.getValueOrABITypeAlignment( - MaybeAlign(FArg.getParamAlignment()), FArg.getParamByValType()); + FArg.getParamAlign(), FArg.getParamByValType()); Value *CpShadowPtr, *CpOriginPtr; std::tie(CpShadowPtr, CpOriginPtr) = getShadowOriginPtr(V, EntryIRB, EntryIRB.getInt8Ty(), ArgAlign, diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index ceb2f52..9370c73 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1437,23 +1437,26 @@ 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.hasPassPointeeByValueCopyAttr() && !Arg.hasNUses(0)) { - if (!DTCalculated) { - DT.recalculate(*CB.getCaller()); - DTCalculated = true; - } - - // If we can already prove the asserted alignment in the context of the - // caller, then don't bother inserting the assumption. - Value *ArgVal = CB.getArgOperand(Arg.getArgNo()); - if (getKnownAlignment(ArgVal, DL, &CB, AC, &DT) >= Align) - continue; + if (!Arg.getType()->isPointerTy() || Arg.hasPassPointeeByValueCopyAttr() || + Arg.hasNUses(0)) + continue; + MaybeAlign Alignment = Arg.getParamAlign(); + if (!Alignment) + continue; - CallInst *NewAsmp = - IRBuilder<>(&CB).CreateAlignmentAssumption(DL, ArgVal, Align); - AC->registerAssumption(cast(NewAsmp)); + if (!DTCalculated) { + DT.recalculate(*CB.getCaller()); + DTCalculated = true; } + // If we can already prove the asserted alignment in the context of the + // caller, then don't bother inserting the assumption. + Value *ArgVal = CB.getArgOperand(Arg.getArgNo()); + if (getKnownAlignment(ArgVal, DL, &CB, AC, &DT) >= *Alignment) + continue; + + CallInst *NewAsmp = IRBuilder<>(&CB).CreateAlignmentAssumption( + DL, ArgVal, Alignment->value()); + AC->registerAssumption(cast(NewAsmp)); } } @@ -1553,7 +1556,7 @@ static Value *HandleByValArgument(Type *ByValType, Value *Arg, Instruction *TheCall, const Function *CalledFunc, InlineFunctionInfo &IFI, - unsigned ByValAlignment) { + MaybeAlign ByValAlignment) { assert(cast(Arg->getType()) ->isOpaqueOrPointeeTypeMatches(ByValType)); Function *Caller = TheCall->getFunction(); @@ -1566,7 +1569,7 @@ static Value *HandleByValArgument(Type *ByValType, Value *Arg, // If the byval argument has a specified alignment that is greater than the // passed in pointer, then we either have to round up the input pointer or // give up on this transformation. - if (ByValAlignment <= 1) // 0 = unspecified, 1 = no particular alignment. + if (ByValAlignment.valueOrOne() == 1) return Arg; AssumptionCache *AC = @@ -1574,8 +1577,8 @@ static Value *HandleByValArgument(Type *ByValType, Value *Arg, // If the pointer is already known to be sufficiently aligned, or if we can // round it up to a larger alignment, then we don't need a temporary. - if (getOrEnforceKnownAlignment(Arg, Align(ByValAlignment), DL, TheCall, - AC) >= ByValAlignment) + if (getOrEnforceKnownAlignment(Arg, *ByValAlignment, DL, TheCall, AC) >= + *ByValAlignment) return Arg; // Otherwise, we have to make a memcpy to get a safe alignment. This is bad @@ -1588,8 +1591,8 @@ static Value *HandleByValArgument(Type *ByValType, Value *Arg, // If the byval had an alignment specified, we *must* use at least that // alignment, as it is required by the byval argument (and uses of the // pointer inside the callee). - if (ByValAlignment > 0) - Alignment = std::max(Alignment, Align(ByValAlignment)); + if (ByValAlignment) + Alignment = std::max(Alignment, *ByValAlignment); Value *NewAlloca = new AllocaInst(ByValType, DL.getAllocaAddrSpace(), nullptr, Alignment, @@ -2185,7 +2188,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, if (CB.isByValArgument(ArgNo)) { ActualArg = HandleByValArgument(CB.getParamByValType(ArgNo), ActualArg, &CB, CalledFunc, IFI, - CalledFunc->getParamAlignment(ArgNo)); + CalledFunc->getParamAlign(ArgNo)); if (ActualArg != *AI) ByValInits.push_back( {ActualArg, (Value *)*AI, CB.getParamByValType(ArgNo)}); -- 2.7.4