[Alignment][NFC] Deprecate InstrTypes getRetAlignment/getParamAlignment

Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77312
This commit is contained in:
Guillaume Chatelet 2020-04-02 15:10:30 +00:00
parent 5e426363ba
commit 9068bccbae
9 changed files with 54 additions and 34 deletions

View File

@ -278,7 +278,7 @@ public:
bool IsSwiftSelf : 1;
bool IsSwiftError : 1;
bool IsCFGuardTarget : 1;
uint16_t Alignment = 0;
MaybeAlign Alignment = None;
Type *ByValType = nullptr;
ArgListEntry()

View File

@ -413,13 +413,27 @@ public:
}
/// 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 {
if (auto MA = getParamAlign(ArgNo))
return MA->value();
return 0;
}
/// Extract the alignment for a call or parameter (0=unknown).
unsigned getParamAlignment(unsigned ArgNo) const {
CALLSITE_DELEGATE_GETTER(getParamAlignment(ArgNo));
MaybeAlign getParamAlign(unsigned ArgNo) const {
CALLSITE_DELEGATE_GETTER(getParamAlign(ArgNo));
}
/// Extract the byval type for a call or parameter (nullptr=unknown).

View File

@ -1577,10 +1577,8 @@ public:
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 @@ public:
/// 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;

View File

@ -392,7 +392,11 @@ namespace llvm {
/// 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 @@ namespace llvm {
/// 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 {

View File

@ -108,12 +108,12 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
// 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();

View File

@ -1226,17 +1226,17 @@ bool FastISel::lowerCallTo(CallLoweringInfo &CLI) {
// 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);

View File

@ -8979,9 +8979,10 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
// 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 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
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 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
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();

View File

@ -114,7 +114,7 @@ void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,
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);

View File

@ -746,22 +746,22 @@ MaybeAlign Value::getPointerAlignment(const DataLayout &DL) const {
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<Argument>(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<PointerType>(A->getType())->getElementType();
if (EltTy->isSized())
return Align(DL.getABITypeAlignment(EltTy));
return DL.getABITypeAlign(EltTy);
}
return Alignment;
} else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
const MaybeAlign Alignment(AI->getAlignment());
const MaybeAlign Alignment = AI->getAlign();
if (!Alignment) {
Type *AllocatedType = AI->getAllocatedType();
if (AllocatedType->isSized())
@ -769,7 +769,7 @@ MaybeAlign Value::getPointerAlignment(const DataLayout &DL) const {
}
return Alignment;
} else if (const auto *Call = dyn_cast<CallBase>(this)) {
const MaybeAlign Alignment(Call->getRetAlignment());
const MaybeAlign Alignment = Call->getRetAlign();
if (!Alignment && Call->getCalledFunction())
return MaybeAlign(
Call->getCalledFunction()->getAttributes().getRetAlignment());