llvm.org GIT mirror llvm / dac7487
Re-land r301697 "[IR] Make add/remove Attributes use AttrBuilder instead of AttributeList" This time, I fixed, built, and tested clang. This reverts r301712. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301981 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 3 years ago
12 changed file(s) with 51 addition(s) and 93 deletion(s). Raw diff Collapse all Expand all
345345 Module &M) {
346346 for (auto &F : M) {
347347 auto &Ctx = F.getContext();
348 AttributeList Attrs = F.getAttributes(), NewAttrs;
348 AttributeList Attrs = F.getAttributes();
349 AttrBuilder NewAttrs;
349350
350351 if (!CPU.empty())
351 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
352 "target-cpu", CPU);
353
352 NewAttrs.addAttribute("target-cpu", CPU);
354353 if (!Features.empty())
355 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
356 "target-features", Features);
357
354 NewAttrs.addAttribute("target-features", Features);
358355 if (DisableFPElim.getNumOccurrences() > 0)
359 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
360 "no-frame-pointer-elim",
361 DisableFPElim ? "true" : "false");
362
356 NewAttrs.addAttribute("no-frame-pointer-elim",
357 DisableFPElim ? "true" : "false");
363358 if (DisableTailCalls.getNumOccurrences() > 0)
364 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
365 "disable-tail-calls",
366 toStringRef(DisableTailCalls));
367
359 NewAttrs.addAttribute("disable-tail-calls",
360 toStringRef(DisableTailCalls));
368361 if (StackRealign)
369 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
370 "stackrealign");
362 NewAttrs.addAttribute("stackrealign");
371363
372364 if (TrapFuncName.getNumOccurrences() > 0)
373365 for (auto &B : F)
381373 Attribute::get(Ctx, "trap-func-name", TrapFuncName));
382374
383375 // Let NewAttrs override Attrs.
384 NewAttrs = Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs);
385 F.setAttributes(NewAttrs);
376 F.setAttributes(
377 Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
386378 }
387379 }
388380
353353 /// \brief Add attributes to the attribute set at the given index. Because
354354 /// attribute sets are immutable, this returns a new set.
355355 AttributeList addAttributes(LLVMContext &C, unsigned Index,
356 AttributeList Attrs) const;
357
358 AttributeList addAttributes(LLVMContext &C, unsigned Index,
359356 const AttrBuilder &B) const;
360357
361358 /// \brief Remove the specified attribute at the specified index from this
374371 /// attribute list. Because attribute lists are immutable, this returns the
375372 /// new list.
376373 AttributeList removeAttributes(LLVMContext &C, unsigned Index,
377 AttributeList Attrs) const;
378
379 /// \brief Remove the specified attributes at the specified index from this
380 /// attribute list. Because attribute lists are immutable, this returns the
381 /// new list.
382 AttributeList removeAttributes(LLVMContext &C, unsigned Index,
383 const AttrBuilder &Attrs) const;
374 const AttrBuilder &AttrsToRemove) const;
384375
385376 /// \brief Remove all attributes at the specified index from this
386377 /// attribute list. Because attribute lists are immutable, this returns the
278278 void addAttribute(unsigned i, Attribute Attr);
279279
280280 /// @brief adds the attributes to the list of attributes.
281 void addAttributes(unsigned i, AttributeList Attrs);
281 void addAttributes(unsigned i, const AttrBuilder &Attrs);
282282
283283 /// @brief removes the attribute from the list of attributes.
284284 void removeAttribute(unsigned i, Attribute::AttrKind Kind);
287287 void removeAttribute(unsigned i, StringRef Kind);
288288
289289 /// @brief removes the attributes from the list of attributes.
290 void removeAttributes(unsigned i, AttributeList Attrs);
290 void removeAttributes(unsigned i, const AttrBuilder &Attrs);
291291
292292 /// @brief check if an attributes is in the list of attributes.
293293 bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const {
8282 // For ByVal, alignment should be passed from FE. BE will guess if
8383 // this info is not there but there are cases it cannot get right.
8484 unsigned FrameAlign;
85 if (FuncInfo.getParamAlignment(OpIdx - 1))
86 FrameAlign = FuncInfo.getParamAlignment(OpIdx - 1);
85 if (FuncInfo.getParamAlignment(OpIdx - 2))
86 FrameAlign = FuncInfo.getParamAlignment(OpIdx - 2);
8787 else
8888 FrameAlign = getTLI()->getByValTypeAlignment(ElementTy, DL);
8989 Arg.Flags.setByValAlign(FrameAlign);
935935 AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index,
936936 Attribute::AttrKind Kind) const {
937937 if (hasAttribute(Index, Kind)) return *this;
938 return addAttributes(C, Index, AttributeList::get(C, Index, Kind));
938 AttrBuilder B;
939 B.addAttribute(Kind);
940 return addAttributes(C, Index, B);
939941 }
940942
941943 AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index,
943945 StringRef Value) const {
944946 AttrBuilder B;
945947 B.addAttribute(Kind, Value);
946 return addAttributes(C, Index, AttributeList::get(C, Index, B));
948 return addAttributes(C, Index, B);
947949 }
948950
949951 AttributeList AttributeList::addAttribute(LLVMContext &C,
977979 }
978980
979981 AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
980 AttributeList Attrs) const {
981 if (!pImpl) return Attrs;
982 if (!Attrs.pImpl) return *this;
983
984 return addAttributes(C, Index, Attrs.getAttributes(Index));
985 }
986
987 AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
988982 const AttrBuilder &B) const {
989983 if (!B.hasAttributes())
990984 return *this;
10331027 AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index,
10341028 Attribute::AttrKind Kind) const {
10351029 if (!hasAttribute(Index, Kind)) return *this;
1036 return removeAttributes(C, Index, AttributeList::get(C, Index, Kind));
1030 AttrBuilder B;
1031 B.addAttribute(Kind);
1032 return removeAttributes(C, Index, B);
10371033 }
10381034
10391035 AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index,
10401036 StringRef Kind) const {
10411037 if (!hasAttribute(Index, Kind)) return *this;
1042 return removeAttributes(C, Index, AttributeList::get(C, Index, Kind));
1043 }
1044
1045 AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned Index,
1046 AttributeList Attrs) const {
1047 return removeAttributes(C, Index, AttrBuilder(Attrs.getAttributes(Index)));
1038 AttrBuilder B;
1039 B.addAttribute(Kind);
1040 return removeAttributes(C, Index, B);
10481041 }
10491042
10501043 AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned Index,
11021095 uint64_t Bytes) const {
11031096 AttrBuilder B;
11041097 B.addDereferenceableAttr(Bytes);
1105 return addAttributes(C, Index, AttributeList::get(C, Index, B));
1098 return addAttributes(C, Index, B);
11061099 }
11071100
11081101 AttributeList
11101103 uint64_t Bytes) const {
11111104 AttrBuilder B;
11121105 B.addDereferenceableOrNullAttr(Bytes);
1113 return addAttributes(C, Index, AttributeList::get(C, Index, B));
1106 return addAttributes(C, Index, B);
11141107 }
11151108
11161109 AttributeList
11191112 const Optional &NumElemsArg) {
11201113 AttrBuilder B;
11211114 B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1122 return addAttributes(C, Index, AttributeList::get(C, Index, B));
1115 return addAttributes(C, Index, B);
11231116 }
11241117
11251118 //===----------------------------------------------------------------------===//
16091602 // If upgrading the SSP attribute, clear out the old SSP Attributes first.
16101603 // Having multiple SSP attributes doesn't actually hurt, but it adds useless
16111604 // clutter to the IR.
1612 AttrBuilder B;
1613 B.addAttribute(Attribute::StackProtect)
1614 .addAttribute(Attribute::StackProtectStrong)
1615 .addAttribute(Attribute::StackProtectReq);
1616 AttributeList OldSSPAttr =
1617 AttributeList::get(Caller.getContext(), AttributeList::FunctionIndex, B);
1605 AttrBuilder OldSSPAttr;
1606 OldSSPAttr.addAttribute(Attribute::StackProtect)
1607 .addAttribute(Attribute::StackProtectStrong)
1608 .addAttribute(Attribute::StackProtectReq);
16181609
16191610 if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
16201611 Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
327327 setAttributes(PAL);
328328 }
329329
330 void Function::addAttributes(unsigned i, AttributeList Attrs) {
330 void Function::addAttributes(unsigned i, const AttrBuilder &Attrs) {
331331 AttributeList PAL = getAttributes();
332332 PAL = PAL.addAttributes(getContext(), i, Attrs);
333333 setAttributes(PAL);
345345 setAttributes(PAL);
346346 }
347347
348 void Function::removeAttributes(unsigned i, AttributeList Attrs) {
348 void Function::removeAttributes(unsigned i, const AttrBuilder &Attrs) {
349349 AttributeList PAL = getAttributes();
350350 PAL = PAL.removeAttributes(getContext(), i, Attrs);
351351 setAttributes(PAL);
489489 // remove the use-soft-float attribute
490490 //
491491 static void removeUseSoftFloat(Function &F) {
492 AttributeList A;
492 AttrBuilder B;
493493 DEBUG(errs() << "removing -use-soft-float\n");
494 A = A.addAttribute(F.getContext(), AttributeList::FunctionIndex,
495 "use-soft-float", "false");
496 F.removeAttributes(AttributeList::FunctionIndex, A);
494 B.addAttribute("use-soft-float", "false");
495 F.removeAttributes(AttributeList::FunctionIndex, B);
497496 if (F.hasFnAttribute("use-soft-float")) {
498497 DEBUG(errs() << "still has -use-soft-float\n");
499498 }
500 F.addAttributes(AttributeList::FunctionIndex, A);
499 F.addAttributes(AttributeList::FunctionIndex, B);
501500 }
502501
503502
244244 // Remove old return attributes.
245245 NewF->removeAttributes(
246246 AttributeList::ReturnIndex,
247 AttributeList::get(
248 NewF->getContext(), AttributeList::ReturnIndex,
249 AttributeFuncs::typeIncompatible(NewF->getReturnType())));
247 AttributeFuncs::typeIncompatible(NewF->getReturnType()));
250248
251249 // Make AllocaSpillBlock the new entry block.
252250 auto *SwitchBB = cast(VMap[ResumeEntry]);
253253 MDNode *ColdCallWeights;
254254 DFSanABIList ABIList;
255255 DenseMap UnwrappedFnMap;
256 AttributeList ReadOnlyNoneAttrs;
256 AttrBuilder ReadOnlyNoneAttrs;
257257 bool DFSanRuntimeShadowMask;
258258
259259 Value *getShadowAddress(Value *Addr, Instruction *Pos);
543543 NewF->copyAttributesFrom(F);
544544 NewF->removeAttributes(
545545 AttributeList::ReturnIndex,
546 AttributeList::get(
547 F->getContext(), AttributeList::ReturnIndex,
548 AttributeFuncs::typeIncompatible(NewFT->getReturnType())));
546 AttributeFuncs::typeIncompatible(NewFT->getReturnType()));
549547
550548 BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF);
551549 if (F->isVarArg()) {
552 NewF->removeAttributes(
553 AttributeList::FunctionIndex,
554 AttributeList().addAttribute(*Ctx, AttributeList::FunctionIndex,
555 "split-stack"));
550 NewF->removeAttributes(AttributeList::FunctionIndex,
551 AttrBuilder().addAttribute("split-stack"));
556552 CallInst::Create(DFSanVarargWrapperFn,
557553 IRBuilder<>(BB).CreateGlobalStringPtr(F->getName()), "",
558554 BB);
697693 }
698694 }
699695
700 AttrBuilder B;
701 B.addAttribute(Attribute::ReadOnly).addAttribute(Attribute::ReadNone);
702 ReadOnlyNoneAttrs = AttributeList::get(*Ctx, AttributeList::FunctionIndex, B);
696 ReadOnlyNoneAttrs.addAttribute(Attribute::ReadOnly)
697 .addAttribute(Attribute::ReadNone);
703698
704699 // First, change the ABI of every function in the module. ABI-listed
705700 // functions keep their original ABI and get a wrapper function.
721716 NewF->copyAttributesFrom(&F);
722717 NewF->removeAttributes(
723718 AttributeList::ReturnIndex,
724 AttributeList::get(
725 NewF->getContext(), AttributeList::ReturnIndex,
726 AttributeFuncs::typeIncompatible(NewFT->getReturnType())));
719 AttributeFuncs::typeIncompatible(NewFT->getReturnType()));
727720 for (Function::arg_iterator FArg = F.arg_begin(),
728721 NewFArg = NewF->arg_begin(),
729722 FArgEnd = F.arg_end();
26062606 AttrBuilder B;
26072607 B.addAttribute(Attribute::ReadOnly)
26082608 .addAttribute(Attribute::ReadNone);
2609 Func->removeAttributes(AttributeList::FunctionIndex,
2610 AttributeList::get(Func->getContext(),
2611 AttributeList::FunctionIndex,
2612 B));
2609 Func->removeAttributes(AttributeList::FunctionIndex, B);
26132610 }
26142611
26152612 maybeMarkSanitizerLibraryCallNoBuiltin(Call, TLI);
36583655 AttrBuilder B;
36593656 B.addAttribute(Attribute::ReadOnly)
36603657 .addAttribute(Attribute::ReadNone);
3661 F.removeAttributes(
3662 AttributeList::FunctionIndex,
3663 AttributeList::get(F.getContext(), AttributeList::FunctionIndex, B));
3658 F.removeAttributes(AttributeList::FunctionIndex, B);
36643659
36653660 return Visitor.runOnFunction();
36663661 }
22892289 R.addAttribute(Attribute::NoAlias);
22902290
22912291 if (!R.empty())
2292 AH.setAttributes(AH.getAttributes().removeAttributes(
2293 Ctx, Index, AttributeList::get(Ctx, Index, R)));
2292 AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R));
22942293 }
22952294
22962295 void
4444 AttributeList::get(C, 1, Attribute::SExt)};
4545
4646 AttributeList SetA = AttributeList::get(C, ASs);
47 AttributeList SetB = SetA.removeAttributes(C, 1, ASs[1]);
47 AttributeList SetB = SetA.removeAttributes(C, 1, ASs[1].getAttributes(1));
4848 EXPECT_NE(SetA, SetB);
4949 }
5050