mirror of
https://github.com/intel/llvm.git
synced 2026-01-25 19:44:38 +08:00
Use less temporary AttributeLists NFC
llvm-svn: 300628
This commit is contained in:
@@ -1762,7 +1762,7 @@ void CodeGenModule::AddDefaultFnAttrs(llvm::Function &F) {
|
||||
|
||||
void CodeGenModule::ConstructAttributeList(
|
||||
StringRef Name, const CGFunctionInfo &FI, CGCalleeInfo CalleeInfo,
|
||||
AttributeListType &PAL, unsigned &CallingConv, bool AttrOnCallSite) {
|
||||
llvm::AttributeList &AttrList, unsigned &CallingConv, bool AttrOnCallSite) {
|
||||
llvm::AttrBuilder FuncAttrs;
|
||||
llvm::AttrBuilder RetAttrs;
|
||||
|
||||
@@ -1931,13 +1931,8 @@ void CodeGenModule::ConstructAttributeList(
|
||||
RetAttrs.addAttribute(llvm::Attribute::NonNull);
|
||||
}
|
||||
|
||||
// Attach return attributes.
|
||||
if (RetAttrs.hasAttributes()) {
|
||||
PAL.push_back(llvm::AttributeList::get(
|
||||
getLLVMContext(), llvm::AttributeList::ReturnIndex, RetAttrs));
|
||||
}
|
||||
|
||||
bool hasUsedSRet = false;
|
||||
SmallVector<llvm::AttributeSet, 4> ArgAttrs(IRFunctionArgs.totalIRArgs());
|
||||
|
||||
// Attach attributes to sret.
|
||||
if (IRFunctionArgs.hasSRetArg()) {
|
||||
@@ -1946,16 +1941,16 @@ void CodeGenModule::ConstructAttributeList(
|
||||
hasUsedSRet = true;
|
||||
if (RetAI.getInReg())
|
||||
SRETAttrs.addAttribute(llvm::Attribute::InReg);
|
||||
PAL.push_back(llvm::AttributeList::get(
|
||||
getLLVMContext(), IRFunctionArgs.getSRetArgNo() + 1, SRETAttrs));
|
||||
ArgAttrs[IRFunctionArgs.getSRetArgNo()] =
|
||||
llvm::AttributeSet::get(getLLVMContext(), SRETAttrs);
|
||||
}
|
||||
|
||||
// Attach attributes to inalloca argument.
|
||||
if (IRFunctionArgs.hasInallocaArg()) {
|
||||
llvm::AttrBuilder Attrs;
|
||||
Attrs.addAttribute(llvm::Attribute::InAlloca);
|
||||
PAL.push_back(llvm::AttributeList::get(
|
||||
getLLVMContext(), IRFunctionArgs.getInallocaArgNo() + 1, Attrs));
|
||||
ArgAttrs[IRFunctionArgs.getInallocaArgNo()] =
|
||||
llvm::AttributeSet::get(getLLVMContext(), Attrs);
|
||||
}
|
||||
|
||||
unsigned ArgNo = 0;
|
||||
@@ -1968,10 +1963,12 @@ void CodeGenModule::ConstructAttributeList(
|
||||
|
||||
// Add attribute for padding argument, if necessary.
|
||||
if (IRFunctionArgs.hasPaddingArg(ArgNo)) {
|
||||
if (AI.getPaddingInReg())
|
||||
PAL.push_back(llvm::AttributeList::get(
|
||||
getLLVMContext(), IRFunctionArgs.getPaddingArgNo(ArgNo) + 1,
|
||||
llvm::Attribute::InReg));
|
||||
if (AI.getPaddingInReg()) {
|
||||
ArgAttrs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
|
||||
llvm::AttributeSet::get(
|
||||
getLLVMContext(),
|
||||
llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
|
||||
}
|
||||
}
|
||||
|
||||
// 'restrict' -> 'noalias' is done in EmitFunctionProlog when we
|
||||
@@ -2086,15 +2083,15 @@ void CodeGenModule::ConstructAttributeList(
|
||||
unsigned FirstIRArg, NumIRArgs;
|
||||
std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
|
||||
for (unsigned i = 0; i < NumIRArgs; i++)
|
||||
PAL.push_back(llvm::AttributeList::get(getLLVMContext(),
|
||||
FirstIRArg + i + 1, Attrs));
|
||||
ArgAttrs[FirstIRArg + i] =
|
||||
llvm::AttributeSet::get(getLLVMContext(), Attrs);
|
||||
}
|
||||
}
|
||||
assert(ArgNo == FI.arg_size());
|
||||
|
||||
if (FuncAttrs.hasAttributes())
|
||||
PAL.push_back(llvm::AttributeList::get(
|
||||
getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs));
|
||||
AttrList = llvm::AttributeList::get(
|
||||
getLLVMContext(), llvm::AttributeSet::get(getLLVMContext(), FuncAttrs),
|
||||
llvm::AttributeSet::get(getLLVMContext(), RetAttrs), ArgAttrs);
|
||||
}
|
||||
|
||||
/// An argument came in as a promoted argument; demote it back to its
|
||||
@@ -2205,8 +2202,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
|
||||
if (IRFunctionArgs.hasSRetArg()) {
|
||||
auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);
|
||||
AI->setName("agg.result");
|
||||
AI->addAttr(llvm::AttributeList::get(getLLVMContext(), AI->getArgNo() + 1,
|
||||
llvm::Attribute::NoAlias));
|
||||
AI->addAttr(llvm::Attribute::NoAlias);
|
||||
}
|
||||
|
||||
// Track if we received the parameter as a pointer (indirect, byval, or
|
||||
@@ -2297,9 +2293,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
|
||||
if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
|
||||
if (getNonNullAttr(CurCodeDecl, PVD, PVD->getType(),
|
||||
PVD->getFunctionScopeIndex()))
|
||||
AI->addAttr(llvm::AttributeList::get(getLLVMContext(),
|
||||
AI->getArgNo() + 1,
|
||||
llvm::Attribute::NonNull));
|
||||
AI->addAttr(llvm::Attribute::NonNull);
|
||||
|
||||
QualType OTy = PVD->getOriginalType();
|
||||
if (const auto *ArrTy =
|
||||
@@ -2319,9 +2313,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
|
||||
AI->addAttr(llvm::AttributeList::get(
|
||||
getLLVMContext(), AI->getArgNo() + 1, Attrs));
|
||||
} else if (getContext().getTargetAddressSpace(ETy) == 0) {
|
||||
AI->addAttr(llvm::AttributeList::get(getLLVMContext(),
|
||||
AI->getArgNo() + 1,
|
||||
llvm::Attribute::NonNull));
|
||||
AI->addAttr(llvm::Attribute::NonNull);
|
||||
}
|
||||
}
|
||||
} else if (const auto *ArrTy =
|
||||
@@ -2331,9 +2323,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
|
||||
// we know that it must be nonnull.
|
||||
if (ArrTy->getSizeModifier() == VariableArrayType::Static &&
|
||||
!getContext().getTargetAddressSpace(ArrTy->getElementType()))
|
||||
AI->addAttr(llvm::AttributeList::get(getLLVMContext(),
|
||||
AI->getArgNo() + 1,
|
||||
llvm::Attribute::NonNull));
|
||||
AI->addAttr(llvm::Attribute::NonNull);
|
||||
}
|
||||
|
||||
const auto *AVAttr = PVD->getAttr<AlignValueAttr>();
|
||||
@@ -2357,8 +2347,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
|
||||
}
|
||||
|
||||
if (Arg->getType().isRestrictQualified())
|
||||
AI->addAttr(llvm::AttributeList::get(
|
||||
getLLVMContext(), AI->getArgNo() + 1, llvm::Attribute::NoAlias));
|
||||
AI->addAttr(llvm::Attribute::NoAlias);
|
||||
|
||||
// LLVM expects swifterror parameters to be used in very restricted
|
||||
// ways. Copy the value into a less-restricted temporary.
|
||||
@@ -4114,13 +4103,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
|
||||
|
||||
// Compute the calling convention and attributes.
|
||||
unsigned CallingConv;
|
||||
CodeGen::AttributeListType AttributeList;
|
||||
llvm::AttributeList Attrs;
|
||||
CGM.ConstructAttributeList(CalleePtr->getName(), CallInfo,
|
||||
Callee.getAbstractInfo(),
|
||||
AttributeList, CallingConv,
|
||||
Callee.getAbstractInfo(), Attrs, CallingConv,
|
||||
/*AttrOnCallSite=*/true);
|
||||
llvm::AttributeList Attrs =
|
||||
llvm::AttributeList::get(getLLVMContext(), AttributeList);
|
||||
|
||||
// Apply some call-site-specific attributes.
|
||||
// TODO: work this into building the attribute set.
|
||||
|
||||
@@ -39,7 +39,6 @@ namespace clang {
|
||||
class VarDecl;
|
||||
|
||||
namespace CodeGen {
|
||||
typedef SmallVector<llvm::AttributeList, 8> AttributeListType;
|
||||
|
||||
/// Abstract information about a function or function prototype.
|
||||
class CGCalleeInfo {
|
||||
|
||||
@@ -379,12 +379,9 @@ void CodeGenFunction::EmitMustTailThunk(const CXXMethodDecl *MD,
|
||||
|
||||
// Apply the standard set of call attributes.
|
||||
unsigned CallingConv;
|
||||
CodeGen::AttributeListType AttributeList;
|
||||
CGM.ConstructAttributeList(CalleePtr->getName(),
|
||||
*CurFnInfo, MD, AttributeList,
|
||||
llvm::AttributeList Attrs;
|
||||
CGM.ConstructAttributeList(CalleePtr->getName(), *CurFnInfo, MD, Attrs,
|
||||
CallingConv, /*AttrOnCallSite=*/true);
|
||||
llvm::AttributeList Attrs =
|
||||
llvm::AttributeList::get(getLLVMContext(), AttributeList);
|
||||
Call->setAttributes(Attrs);
|
||||
Call->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
|
||||
|
||||
|
||||
@@ -841,10 +841,9 @@ void CodeGenModule::SetLLVMFunctionAttributes(const Decl *D,
|
||||
const CGFunctionInfo &Info,
|
||||
llvm::Function *F) {
|
||||
unsigned CallingConv;
|
||||
AttributeListType AttributeList;
|
||||
ConstructAttributeList(F->getName(), Info, D, AttributeList, CallingConv,
|
||||
false);
|
||||
F->setAttributes(llvm::AttributeList::get(getLLVMContext(), AttributeList));
|
||||
llvm::AttributeList PAL;
|
||||
ConstructAttributeList(F->getName(), Info, D, PAL, CallingConv, false);
|
||||
F->setAttributes(PAL);
|
||||
F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
|
||||
}
|
||||
|
||||
|
||||
@@ -1020,11 +1020,12 @@ public:
|
||||
/// \param CalleeInfo - The callee information these attributes are being
|
||||
/// constructed for. If valid, the attributes applied to this decl may
|
||||
/// contribute to the function attributes and calling convention.
|
||||
/// \param PAL [out] - On return, the attribute list to use.
|
||||
/// \param Attrs [out] - On return, the attribute list to use.
|
||||
/// \param CallingConv [out] - On return, the LLVM calling convention to use.
|
||||
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
|
||||
CGCalleeInfo CalleeInfo, AttributeListType &PAL,
|
||||
unsigned &CallingConv, bool AttrOnCallSite);
|
||||
CGCalleeInfo CalleeInfo,
|
||||
llvm::AttributeList &Attrs, unsigned &CallingConv,
|
||||
bool AttrOnCallSite);
|
||||
|
||||
/// Adds attributes to F according to our CodeGenOptions and LangOptions, as
|
||||
/// though we had emitted it ourselves. We remove any attributes on F that
|
||||
|
||||
Reference in New Issue
Block a user