diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -278,7 +278,7 @@ bool IsSwiftSelf : 1; bool IsSwiftError : 1; bool IsCFGuardTarget : 1; - uint16_t Alignment = 0; + MaybeAlign Alignment = None; Type *ByValType = nullptr; ArgListEntry() diff --git a/llvm/include/llvm/IR/CallSite.h b/llvm/include/llvm/IR/CallSite.h --- a/llvm/include/llvm/IR/CallSite.h +++ b/llvm/include/llvm/IR/CallSite.h @@ -413,13 +413,27 @@ } /// Extract the alignment of the return value. + /// FIXME: Remove when the transition to Align is over. unsigned getRetAlignment() const { - CALLSITE_DELEGATE_GETTER(getRetAlignment()); + if (auto MA = getRetAlign()) + return MA->value(); + return 0; } + /// Extract the alignment of the return value. + MaybeAlign getRetAlign() const { CALLSITE_DELEGATE_GETTER(getRetAlign()); } + /// Extract the alignment for a call or parameter (0=unknown). + /// FIXME: Remove when the transition to Align is over. unsigned getParamAlignment(unsigned ArgNo) const { - CALLSITE_DELEGATE_GETTER(getParamAlignment(ArgNo)); + if (auto MA = getParamAlign(ArgNo)) + return MA->value(); + return 0; + } + + /// Extract the alignment for a call or parameter (0=unknown). + MaybeAlign getParamAlign(unsigned ArgNo) const { + CALLSITE_DELEGATE_GETTER(getParamAlign(ArgNo)); } /// Extract the byval type for a call or parameter (nullptr=unknown). diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -1577,10 +1577,8 @@ dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone); } - /// Extract the alignment of the return value. - /// FIXME: Remove this function once transition to Align is over. - /// Use getRetAlign() instead. - unsigned getRetAlignment() const { + LLVM_ATTRIBUTE_DEPRECATED(unsigned getRetAlignment() const, + "Use getRetAlign() instead") { if (const auto MA = Attrs.getRetAlignment()) return MA->value(); return 0; @@ -1592,7 +1590,8 @@ /// Extract the alignment for a call or parameter (0=unknown). /// FIXME: Remove this function once transition to Align is over. /// Use getParamAlign() instead. - unsigned getParamAlignment(unsigned ArgNo) const { + LLVM_ATTRIBUTE_DEPRECATED(unsigned getParamAlignment(unsigned ArgNo) const, + "Use getParamAlign() instead") { if (const auto MA = Attrs.getParamAlignment(ArgNo)) return MA->value(); return 0; diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h --- a/llvm/include/llvm/IR/IntrinsicInst.h +++ b/llvm/include/llvm/IR/IntrinsicInst.h @@ -392,7 +392,11 @@ /// FIXME: Remove this function once transition to Align is over. /// Use getDestAlign() instead. - unsigned getDestAlignment() const { return getParamAlignment(ARG_DEST); } + unsigned getDestAlignment() const { + if (auto MA = getParamAlign(ARG_DEST)) + return MA->value(); + return 0; + } MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); } /// Set the specified arguments of the instruction. @@ -454,7 +458,9 @@ /// FIXME: Remove this function once transition to Align is over. /// Use getSourceAlign() instead. unsigned getSourceAlignment() const { - return BaseCL::getParamAlignment(ARG_SOURCE); + if (auto MA = BaseCL::getParamAlign(ARG_SOURCE)) + return MA->value(); + return 0; } MaybeAlign getSourceAlign() const { diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp --- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp @@ -108,12 +108,12 @@ // For ByVal, alignment should be passed from FE. BE will guess if // this info is not there but there are cases it cannot get right. - unsigned FrameAlign; - if (FuncInfo.getParamAlignment(OpIdx - 2)) - FrameAlign = FuncInfo.getParamAlignment(OpIdx - 2); + Align FrameAlign; + if (auto ParamAlign = FuncInfo.getParamAlign(OpIdx - 2)) + FrameAlign = *ParamAlign; else - FrameAlign = getTLI()->getByValTypeAlignment(ElementTy, DL); - Flags.setByValAlign(Align(FrameAlign)); + FrameAlign = Align(getTLI()->getByValTypeAlignment(ElementTy, DL)); + Flags.setByValAlign(FrameAlign); } if (Attrs.hasAttribute(OpIdx, Attribute::Nest)) Flags.setNest(); diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1226,17 +1226,17 @@ // For ByVal, alignment should come from FE. BE will guess if this info // is not there, but there are cases it cannot get right. - unsigned FrameAlign = Arg.Alignment; + MaybeAlign FrameAlign = Arg.Alignment; if (!FrameAlign) - FrameAlign = TLI.getByValTypeAlignment(ElementTy, DL); + FrameAlign = Align(TLI.getByValTypeAlignment(ElementTy, DL)); Flags.setByValSize(FrameSize); - Flags.setByValAlign(Align(FrameAlign)); + Flags.setByValAlign(*FrameAlign); } if (Arg.IsNest) Flags.setNest(); if (NeedsRegBlock) Flags.setInConsecutiveRegs(); - Flags.setOrigAlign(Align(DL.getABITypeAlignment(Arg.Ty))); + Flags.setOrigAlign(DL.getABITypeAlign(Arg.Ty)); CLI.OutVals.push_back(Arg.Val); CLI.OutFlags.push_back(Flags); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -8979,9 +8979,10 @@ // assert(!CS.hasInAllocaArgument() && // "sret demotion is incompatible with inalloca"); uint64_t TySize = DL.getTypeAllocSize(CLI.RetTy); - unsigned Align = DL.getPrefTypeAlignment(CLI.RetTy); + Align Alignment = DL.getPrefTypeAlign(CLI.RetTy); MachineFunction &MF = CLI.DAG.getMachineFunction(); - DemoteStackIdx = MF.getFrameInfo().CreateStackObject(TySize, Align, false); + DemoteStackIdx = + MF.getFrameInfo().CreateStackObject(TySize, Alignment, false); Type *StackSlotPtrType = PointerType::get(CLI.RetTy, DL.getAllocaAddrSpace()); @@ -8999,7 +9000,7 @@ Entry.IsSwiftSelf = false; Entry.IsSwiftError = false; Entry.IsCFGuardTarget = false; - Entry.Alignment = Align; + Entry.Alignment = Alignment; CLI.getArgs().insert(CLI.getArgs().begin(), Entry); CLI.NumFixedArgs += 1; CLI.RetTy = Type::getVoidTy(CLI.RetTy->getContext()); @@ -9133,12 +9134,12 @@ Flags.setByValSize(FrameSize); // info is not there but there are cases it cannot get right. - unsigned FrameAlign; - if (Args[i].Alignment) - FrameAlign = Args[i].Alignment; + Align FrameAlign; + if (auto MA = Args[i].Alignment) + FrameAlign = *MA; else - FrameAlign = getByValTypeAlignment(ElementTy, DL); - Flags.setByValAlign(Align(FrameAlign)); + FrameAlign = Align(getByValTypeAlignment(ElementTy, DL)); + Flags.setByValAlign(FrameAlign); } if (Args[i].IsNest) Flags.setNest(); diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -114,7 +114,7 @@ IsReturned = Call->paramHasAttr(ArgIdx, Attribute::Returned); IsSwiftSelf = Call->paramHasAttr(ArgIdx, Attribute::SwiftSelf); IsSwiftError = Call->paramHasAttr(ArgIdx, Attribute::SwiftError); - Alignment = Call->getParamAlignment(ArgIdx); + Alignment = Call->getParamAlign(ArgIdx); ByValType = nullptr; if (Call->paramHasAttr(ArgIdx, Attribute::ByVal)) ByValType = Call->getParamByValType(ArgIdx); diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -746,22 +746,22 @@ if (GVar->isStrongDefinitionForLinker()) return MaybeAlign(DL.getPreferredAlignment(GVar)); else - return Align(DL.getABITypeAlignment(ObjectType)); + return DL.getABITypeAlign(ObjectType); } } } return Alignment; } else if (const Argument *A = dyn_cast(this)) { - const MaybeAlign Alignment(A->getParamAlignment()); + const MaybeAlign Alignment = A->getParamAlign(); if (!Alignment && A->hasStructRetAttr()) { // An sret parameter has at least the ABI alignment of the return type. Type *EltTy = cast(A->getType())->getElementType(); if (EltTy->isSized()) - return Align(DL.getABITypeAlignment(EltTy)); + return DL.getABITypeAlign(EltTy); } return Alignment; } else if (const AllocaInst *AI = dyn_cast(this)) { - const MaybeAlign Alignment(AI->getAlignment()); + const MaybeAlign Alignment = AI->getAlign(); if (!Alignment) { Type *AllocatedType = AI->getAllocatedType(); if (AllocatedType->isSized()) @@ -769,7 +769,7 @@ } return Alignment; } else if (const auto *Call = dyn_cast(this)) { - const MaybeAlign Alignment(Call->getRetAlignment()); + const MaybeAlign Alignment = Call->getRetAlign(); if (!Alignment && Call->getCalledFunction()) return MaybeAlign( Call->getCalledFunction()->getAttributes().getRetAlignment());