These methods can be confusing.
getDefaultFunctionAttributes(F.getName(), F.hasOptNone(),
/* AttrOnCallSite = */ false, FuncAttrs);
// TODO: call GetCPUAndFeaturesAttributes?
- F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
+ F.addFnAttrs(FuncAttrs);
}
void CodeGenModule::addDefaultFunctionDefinitionAttributes(
if (CurAlign >= NewAlign)
return Attrs;
llvm::Attribute AlignAttr = llvm::Attribute::getWithAlignment(Ctx, NewAlign);
- return Attrs
- .removeAttribute(Ctx, llvm::AttributeList::ReturnIndex,
- llvm::Attribute::AttrKind::Alignment)
+ return Attrs.removeRetAttribute(Ctx, llvm::Attribute::AttrKind::Alignment)
.addAttribute(Ctx, llvm::AttributeList::ReturnIndex, AlignAttr);
}
CodeGenOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining)
B.addAttribute(llvm::Attribute::NoInline);
- F->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ F->addFnAttrs(B);
return;
}
B.addAttribute(llvm::Attribute::MinSize);
}
- F->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ F->addFnAttrs(B);
unsigned alignment = D->getMaxAlignment() / Context.getCharWidth();
if (alignment)
if (D->hasAttr<StrictFPAttr>()) {
llvm::AttrBuilder FuncAttrs;
FuncAttrs.addAttribute("strictfp");
- F->addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
+ F->addFnAttrs(FuncAttrs);
}
}
RemoveAttrs.addAttribute("target-cpu");
RemoveAttrs.addAttribute("target-features");
RemoveAttrs.addAttribute("tune-cpu");
- F->removeAttributes(llvm::AttributeList::FunctionIndex, RemoveAttrs);
- F->addAttributes(llvm::AttributeList::FunctionIndex, Attrs);
+ F->removeFnAttrs(RemoveAttrs);
+ F->addFnAttrs(Attrs);
}
}
SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
if (ExtraAttrs.hasFnAttrs()) {
llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex);
- F->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ F->addFnAttrs(B);
}
if (!DontDefer) {
llvm::Function *Fn = cast<llvm::Function>(GV);
llvm::AttrBuilder B;
B.addAttribute("wasm-import-module", Attr->getImportModule());
- Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ Fn->addFnAttrs(B);
}
if (const auto *Attr = FD->getAttr<WebAssemblyImportNameAttr>()) {
llvm::Function *Fn = cast<llvm::Function>(GV);
llvm::AttrBuilder B;
B.addAttribute("wasm-import-name", Attr->getImportName());
- Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ Fn->addFnAttrs(B);
}
if (const auto *Attr = FD->getAttr<WebAssemblyExportNameAttr>()) {
llvm::Function *Fn = cast<llvm::Function>(GV);
llvm::AttrBuilder B;
B.addAttribute("wasm-export-name", Attr->getExportName());
- Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ Fn->addFnAttrs(B);
}
}
// the backend to perform a realignment as part of the function prologue.
llvm::AttrBuilder B;
B.addStackAlignmentAttr(8);
- Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ Fn->addFnAttrs(B);
}
};
AttrBuilder B;
B.addAttribute(llvm::Attribute::NoUnwind);
B.addAttribute(llvm::Attribute::Naked);
- F->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ F->addFnAttrs(B);
// Populate our function a bit so that we can verify.
BasicBlock *Entry = BasicBlock::Create(Ctx, "entry", F);
LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C,
unsigned Index) const;
+ /// Remove the specified attribute at the function index from this
+ /// attribute list. Returns a new list because attribute lists are immutable.
+ LLVM_NODISCARD AttributeList
+ removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const {
+ return removeAttribute(C, FunctionIndex, Kind);
+ }
+
+ /// Remove the specified attribute at the function index from this
+ /// attribute list. Returns a new list because attribute lists are immutable.
+ LLVM_NODISCARD AttributeList removeFnAttribute(LLVMContext &C,
+ StringRef Kind) const {
+ return removeAttribute(C, FunctionIndex, Kind);
+ }
+
+ /// Remove the specified attribute at the function index from this
+ /// attribute list. Returns a new list because attribute lists are immutable.
+ LLVM_NODISCARD AttributeList
+ removeFnAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const {
+ return removeAttributes(C, FunctionIndex, AttrsToRemove);
+ }
+
+ /// Remove the specified attribute at the return value index from this
+ /// attribute list. Returns a new list because attribute lists are immutable.
+ LLVM_NODISCARD AttributeList
+ removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const {
+ return removeAttribute(C, ReturnIndex, Kind);
+ }
+
+ /// Remove the specified attribute at the return value index from this
+ /// attribute list. Returns a new list because attribute lists are immutable.
+ LLVM_NODISCARD AttributeList removeRetAttribute(LLVMContext &C,
+ StringRef Kind) const {
+ return removeAttribute(C, ReturnIndex, Kind);
+ }
+
+ /// Remove the specified attribute at the return value index from this
+ /// attribute list. Returns a new list because attribute lists are immutable.
+ LLVM_NODISCARD AttributeList
+ removeRetAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const {
+ return removeAttributes(C, ReturnIndex, AttrsToRemove);
+ }
+
/// Remove the specified attribute at the specified arg index from this
/// attribute list. Returns a new list because attribute lists are immutable.
LLVM_NODISCARD AttributeList removeParamAttribute(
addAttribute(AttributeList::FunctionIndex, Attr);
}
+ /// Add function attributes to this function.
+ void addFnAttrs(const AttrBuilder &Attrs) {
+ addAttributes(AttributeList::FunctionIndex, Attrs);
+ }
+
+ /// removes the attributes from the list of attributes.
+ void removeAttributes(unsigned i, const AttrBuilder &Attrs);
+
/// Remove function attributes from this function.
void removeFnAttr(Attribute::AttrKind Kind) {
- removeAttribute(AttributeList::FunctionIndex, Kind);
+ setAttributes(getAttributes().removeFnAttribute(getContext(), Kind));
}
/// Remove function attribute from this function.
void removeFnAttr(StringRef Kind) {
- setAttributes(getAttributes().removeAttribute(
- getContext(), AttributeList::FunctionIndex, Kind));
+ setAttributes(getAttributes().removeFnAttribute(getContext(), Kind));
+ }
+
+ void removeFnAttrs(const AttrBuilder &Attrs) {
+ setAttributes(getAttributes().removeFnAttributes(getContext(), Attrs));
}
/// A function will have the "coroutine.presplit" attribute if it's
/// removes the attribute from the list of attributes.
void removeAttribute(unsigned i, StringRef Kind);
- /// removes the attributes from the list of attributes.
- void removeAttributes(unsigned i, const AttrBuilder &Attrs);
+ /// removes the attribute from the return value list of attributes.
+ void removeRetAttr(Attribute::AttrKind Kind);
+
+ /// removes the attribute from the return value list of attributes.
+ void removeRetAttr(StringRef Kind);
+
+ void removeRetAttrs(const AttrBuilder &Attrs);
/// removes the attribute from the list of attributes.
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
.addAttribute(Attribute::StackProtectReq);
if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
- Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
+ Caller.removeFnAttrs(OldSSPAttr);
Caller.addFnAttr(Attribute::StackProtectReq);
} else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
!Caller.hasFnAttribute(Attribute::StackProtectReq)) {
- Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
+ Caller.removeFnAttrs(OldSSPAttr);
Caller.addFnAttr(Attribute::StackProtectStrong);
} else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
!Caller.hasFnAttribute(Attribute::StackProtectReq) &&
}
// Remove all incompatibile attributes from function.
- F.removeAttributes(AttributeList::ReturnIndex,
- AttributeFuncs::typeIncompatible(F.getReturnType()));
+ F.removeRetAttrs(AttributeFuncs::typeIncompatible(F.getReturnType()));
for (auto &Arg : F.args())
Arg.removeAttrs(AttributeFuncs::typeIncompatible(Arg.getType()));
}
B.addAttribute("frame-pointer", "all");
break;
}
- F->addAttributes(AttributeList::FunctionIndex, B);
+ F->addFnAttrs(B);
return F;
}
setAttributes(PAL);
}
-void Function::removeAttributes(unsigned i, const AttrBuilder &Attrs) {
+void Function::removeRetAttr(Attribute::AttrKind Kind) {
AttributeList PAL = getAttributes();
- PAL = PAL.removeAttributes(getContext(), i, Attrs);
+ PAL = PAL.removeRetAttribute(getContext(), Kind);
+ setAttributes(PAL);
+}
+
+void Function::removeRetAttr(StringRef Kind) {
+ AttributeList PAL = getAttributes();
+ PAL = PAL.removeRetAttribute(getContext(), Kind);
+ setAttributes(PAL);
+}
+
+void Function::removeRetAttrs(const AttrBuilder &Attrs) {
+ AttributeList PAL = getAttributes();
+ PAL = PAL.removeRetAttributes(getContext(), Attrs);
setAttributes(PAL);
}
RetAttrs.addAttribute(Attribute::SExt);
RetAttrs.addAttribute(Attribute::ZExt);
RetAttrs.addAttribute(Attribute::NoAlias);
- NewFunc->removeAttributes(AttributeList::ReturnIndex, RetAttrs);
+ NewFunc->removeRetAttrs(RetAttrs);
// TODO: How to preserve metadata?
// Move the body of the function into the new rewritten function, and replace
AttrBuilder B;
LLVM_DEBUG(errs() << "removing -use-soft-float\n");
B.addAttribute("use-soft-float", "false");
- F.removeAttributes(AttributeList::FunctionIndex, B);
+ F.removeFnAttrs(B);
if (F.hasFnAttribute("use-soft-float")) {
LLVM_DEBUG(errs() << "still has -use-soft-float\n");
}
- F.addAttributes(AttributeList::FunctionIndex, B);
+ F.addFnAttrs(B);
}
// This pass only makes sense when the underlying chip has floating point but
if (!F->hasFnAttribute("wasm-import-module")) {
llvm::AttrBuilder B;
B.addAttribute("wasm-import-module", "env");
- F->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ F->addFnAttrs(B);
}
if (!F->hasFnAttribute("wasm-import-name")) {
llvm::AttrBuilder B;
B.addAttribute("wasm-import-name", F->getName());
- F->addAttributes(llvm::AttributeList::FunctionIndex, B);
+ F->addFnAttrs(B);
}
return F;
}
// Reset various things that the optimizer might have decided it
// "knows" about the coroutine function due to not seeing a return.
F.removeFnAttr(Attribute::NoReturn);
- F.removeAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
- F.removeAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
+ F.removeRetAttr(Attribute::NoAlias);
+ F.removeRetAttr(Attribute::NonNull);
auto &Context = F.getContext();
auto *Int8PtrTy = Type::getInt8PtrTy(Context);
// Reset various things that the optimizer might have decided it
// "knows" about the coroutine function due to not seeing a return.
F.removeFnAttr(Attribute::NoReturn);
- F.removeAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
- F.removeAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
+ F.removeRetAttr(Attribute::NoAlias);
+ F.removeRetAttr(Attribute::NonNull);
// Allocate the frame.
auto *Id = cast<AnyCoroIdRetconInst>(Shape.CoroBegin->getId());
AttrsToRemove.addAttribute(Attribute::InaccessibleMemOnly);
AttrsToRemove.addAttribute(Attribute::InaccessibleMemOrArgMemOnly);
}
- F->removeAttributes(AttributeList::FunctionIndex, AttrsToRemove);
+ F->removeFnAttrs(AttrsToRemove);
// Add in the new attribute.
if (WritesMemory && !ReadsMemory)
Function *NewF = Function::Create(NewFT, NewFLink, F->getAddressSpace(),
NewFName, F->getParent());
NewF->copyAttributesFrom(F);
- NewF->removeAttributes(
- AttributeList::ReturnIndex,
+ NewF->removeRetAttrs(
AttributeFuncs::typeIncompatible(NewFT->getReturnType()));
BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF);
if (F->isVarArg()) {
- NewF->removeAttributes(AttributeList::FunctionIndex,
- AttrBuilder().addAttribute("split-stack"));
+ NewF->removeFnAttrs(AttrBuilder().addAttribute("split-stack"));
CallInst::Create(DFSanVarargWrapperFn,
IRBuilder<>(BB).CreateGlobalStringPtr(F->getName()), "",
BB);
Function *NewF = Function::Create(NewFT, F.getLinkage(),
F.getAddressSpace(), "", &M);
NewF->copyAttributesFrom(&F);
- NewF->removeAttributes(
- AttributeList::ReturnIndex,
+ NewF->removeRetAttrs(
AttributeFuncs::typeIncompatible(NewFT->getReturnType()));
for (Function::arg_iterator FArg = F.arg_begin(),
NewFArg = NewF->arg_begin(),
std::string(F.getName()),
WrapperLinkage, NewFT);
if (getInstrumentedABI() == IA_TLS)
- NewF->removeAttributes(AttributeList::FunctionIndex, ReadOnlyNoneAttrs);
+ NewF->removeFnAttrs(ReadOnlyNoneAttrs);
Value *WrappedFnCst =
ConstantExpr::getBitCast(NewF, PointerType::getUnqual(FT));
// Custom functions returning non-void will write to the return label.
if (!FT->getReturnType()->isVoidTy()) {
- CustomFn->removeAttributes(AttributeList::FunctionIndex,
- DFSF.DFS.ReadOnlyNoneAttrs);
+ CustomFn->removeFnAttrs(DFSF.DFS.ReadOnlyNoneAttrs);
}
}
NewCB = IRB.CreateCall(NewFT, Func, Args);
}
NewCB->setCallingConv(CB.getCallingConv());
- NewCB->setAttributes(CB.getAttributes().removeAttributes(
- *DFSF.DFS.Ctx, AttributeList::ReturnIndex,
- AttributeFuncs::typeIncompatible(NewCB->getType())));
+ NewCB->setAttributes(CB.getAttributes().removeRetAttributes(
+ *DFSF.DFS.Ctx, AttributeFuncs::typeIncompatible(NewCB->getType())));
if (Next) {
ExtractValueInst *ExVal = ExtractValueInst::Create(NewCB, 0, "", Next);
Call->removeAttributes(AttributeList::FunctionIndex, B);
if (Function *Func = Call->getCalledFunction()) {
- Func->removeAttributes(AttributeList::FunctionIndex, B);
+ Func->removeFnAttrs(B);
}
maybeMarkSanitizerLibraryCallNoBuiltin(Call, TLI);
.addAttribute(Attribute::WriteOnly)
.addAttribute(Attribute::ArgMemOnly)
.addAttribute(Attribute::Speculatable);
- F.removeAttributes(AttributeList::FunctionIndex, B);
+ F.removeFnAttrs(B);
return Visitor.runOnFunction();
}
AttrBuilder AttributesToRemove;
AttributesToRemove.addAttribute(Attribute::ArgMemOnly);
AttributesToRemove.addAttribute(Attribute::InaccessibleMemOrArgMemOnly);
- F.removeAttributes(AttributeList::FunctionIndex, AttributesToRemove);
+ F.removeFnAttrs(AttributesToRemove);
for (User *U : F.users()) {
auto *CB = dyn_cast<CallBase>(U);
insertCall(F, EntryFunc, &*F.begin()->getFirstInsertionPt(), DL);
Changed = true;
- F.removeAttribute(AttributeList::FunctionIndex, EntryAttr);
+ F.removeFnAttr(EntryAttr);
}
if (!ExitFunc.empty()) {
insertCall(F, ExitFunc, T, DL);
Changed = true;
}
- F.removeAttribute(AttributeList::FunctionIndex, ExitAttr);
+ F.removeFnAttr(ExitAttr);
}
return Changed;
AttributeList::get(C, 1, Attribute::SExt)};
AttributeList SetA = AttributeList::get(C, ASs);
- AttributeList SetB = SetA.removeAttributes(C, 1, ASs[1].getParamAttrs(0));
+ AttributeList SetB =
+ SetA.removeParamAttributes(C, 0, ASs[1].getParamAttrs(0));
EXPECT_NE(SetA, SetB);
}
EXPECT_TRUE(AL.hasRetAttr(Attribute::OptimizeNone));
EXPECT_TRUE(AL.getStackAlignment(0) == 32);
- AL = AL.removeAttribute(C, 0, Attribute::StackAlignment);
+ AL = AL.removeRetAttribute(C, Attribute::StackAlignment);
EXPECT_FALSE(AL.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::ReadOnly));
EXPECT_FALSE(AL.hasRetAttr(Attribute::StackAlignment));
EXPECT_TRUE(AL2.hasRetAttr(Attribute::OptimizeNone));
EXPECT_TRUE(AL2.getStackAlignment(0) == 32);
- AL2 = AL2.removeAttributes(C, 0, B_stackalign);
+ AL2 = AL2.removeRetAttributes(C, B_stackalign);
EXPECT_FALSE(AL2.hasParamAttr(0, Attribute::Alignment));
EXPECT_TRUE(AL2.hasParamAttr(0, Attribute::ReadOnly));
EXPECT_FALSE(AL2.hasRetAttr(Attribute::StackAlignment));