Transforms: Canonicalize access to function attributes, NFC

Canonicalize access to function attributes to use the simpler API.

getAttributes().getAttribute(AttributeSet::FunctionIndex, Kind)
  => getFnAttribute(Kind)

getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind)
  => hasFnAttribute(Kind)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229202 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-02-14 01:11:29 +00:00
parent ef126cdf56
commit 7520a90c75
6 changed files with 19 additions and 39 deletions

View File

@ -97,25 +97,17 @@ static void AdjustCallerSSPLevel(Function *Caller, Function *Callee) {
AttributeSet OldSSPAttr = AttributeSet::get(Caller->getContext(), AttributeSet OldSSPAttr = AttributeSet::get(Caller->getContext(),
AttributeSet::FunctionIndex, AttributeSet::FunctionIndex,
B); B);
AttributeSet CallerAttr = Caller->getAttributes(),
CalleeAttr = Callee->getAttributes();
if (CalleeAttr.hasAttribute(AttributeSet::FunctionIndex, if (Callee->hasFnAttribute(Attribute::StackProtectReq)) {
Attribute::StackProtectReq)) {
Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr); Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
Caller->addFnAttr(Attribute::StackProtectReq); Caller->addFnAttr(Attribute::StackProtectReq);
} else if (CalleeAttr.hasAttribute(AttributeSet::FunctionIndex, } else if (Callee->hasFnAttribute(Attribute::StackProtectStrong) &&
Attribute::StackProtectStrong) && !Caller->hasFnAttribute(Attribute::StackProtectReq)) {
!CallerAttr.hasAttribute(AttributeSet::FunctionIndex,
Attribute::StackProtectReq)) {
Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr); Caller->removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
Caller->addFnAttr(Attribute::StackProtectStrong); Caller->addFnAttr(Attribute::StackProtectStrong);
} else if (CalleeAttr.hasAttribute(AttributeSet::FunctionIndex, } else if (Callee->hasFnAttribute(Attribute::StackProtect) &&
Attribute::StackProtect) && !Caller->hasFnAttribute(Attribute::StackProtectReq) &&
!CallerAttr.hasAttribute(AttributeSet::FunctionIndex, !Caller->hasFnAttribute(Attribute::StackProtectStrong))
Attribute::StackProtectReq) &&
!CallerAttr.hasAttribute(AttributeSet::FunctionIndex,
Attribute::StackProtectStrong))
Caller->addFnAttr(Attribute::StackProtect); Caller->addFnAttr(Attribute::StackProtect);
} }
@ -273,8 +265,7 @@ unsigned Inliner::getInlineThreshold(CallSite CS) const {
// would decrease the threshold. // would decrease the threshold.
Function *Caller = CS.getCaller(); Function *Caller = CS.getCaller();
bool OptSize = Caller && !Caller->isDeclaration() && bool OptSize = Caller && !Caller->isDeclaration() &&
Caller->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Caller->hasFnAttribute(Attribute::OptimizeForSize);
Attribute::OptimizeForSize);
if (!(InlineLimit.getNumOccurrences() > 0) && OptSize && if (!(InlineLimit.getNumOccurrences() > 0) && OptSize &&
OptSizeThreshold < thres) OptSizeThreshold < thres)
thres = OptSizeThreshold; thres = OptSizeThreshold;
@ -283,17 +274,14 @@ unsigned Inliner::getInlineThreshold(CallSite CS) const {
// and the caller does not need to minimize its size. // and the caller does not need to minimize its size.
Function *Callee = CS.getCalledFunction(); Function *Callee = CS.getCalledFunction();
bool InlineHint = Callee && !Callee->isDeclaration() && bool InlineHint = Callee && !Callee->isDeclaration() &&
Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Callee->hasFnAttribute(Attribute::InlineHint);
Attribute::InlineHint); if (InlineHint && HintThreshold > thres &&
if (InlineHint && HintThreshold > thres !Caller->hasFnAttribute(Attribute::MinSize))
&& !Caller->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
Attribute::MinSize))
thres = HintThreshold; thres = HintThreshold;
// Listen to the cold attribute when it would decrease the threshold. // Listen to the cold attribute when it would decrease the threshold.
bool ColdCallee = Callee && !Callee->isDeclaration() && bool ColdCallee = Callee && !Callee->isDeclaration() &&
Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Callee->hasFnAttribute(Attribute::Cold);
Attribute::Cold);
// Command line argument for InlineLimit will override the default // Command line argument for InlineLimit will override the default
// ColdThreshold. If we have -inline-threshold but no -inlinecold-threshold, // ColdThreshold. If we have -inline-threshold but no -inlinecold-threshold,
// do not use the default cold threshold even if it is smaller. // do not use the default cold threshold even if it is smaller.
@ -659,9 +647,7 @@ bool Inliner::removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly) {
// Handle the case when this function is called and we only want to care // Handle the case when this function is called and we only want to care
// about always-inline functions. This is a bit of a hack to share code // about always-inline functions. This is a bit of a hack to share code
// between here and the InlineAlways pass. // between here and the InlineAlways pass.
if (AlwaysInlineOnly && if (AlwaysInlineOnly && !F->hasFnAttribute(Attribute::AlwaysInline))
!F->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
Attribute::AlwaysInline))
continue; continue;
// If the only remaining users of the function are dead constants, remove // If the only remaining users of the function are dead constants, remove

View File

@ -2915,8 +2915,7 @@ static bool combineInstructionsOverFunction(
TargetLibraryInfo &TLI, DominatorTree &DT, const DataLayout *DL = nullptr, TargetLibraryInfo &TLI, DominatorTree &DT, const DataLayout *DL = nullptr,
LoopInfo *LI = nullptr) { LoopInfo *LI = nullptr) {
// Minimizing size? // Minimizing size?
bool MinimizeSize = F.getAttributes().hasAttribute( bool MinimizeSize = F.hasFnAttribute(Attribute::MinSize);
AttributeSet::FunctionIndex, Attribute::MinSize);
/// Builder - This is an IRBuilder that automatically inserts new /// Builder - This is an IRBuilder that automatically inserts new
/// instructions into the worklist when they are created. /// instructions into the worklist when they are created.

View File

@ -583,8 +583,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
MemorySanitizerVisitor(Function &F, MemorySanitizer &MS) MemorySanitizerVisitor(Function &F, MemorySanitizer &MS)
: F(F), MS(MS), VAHelper(CreateVarArgHelper(F, MS, *this)) { : F(F), MS(MS), VAHelper(CreateVarArgHelper(F, MS, *this)) {
bool SanitizeFunction = F.getAttributes().hasAttribute( bool SanitizeFunction = F.hasFnAttribute(Attribute::SanitizeMemory);
AttributeSet::FunctionIndex, Attribute::SanitizeMemory);
InsertChecks = SanitizeFunction; InsertChecks = SanitizeFunction;
PropagateShadow = SanitizeFunction; PropagateShadow = SanitizeFunction;
PoisonStack = SanitizeFunction && ClPoisonStack; PoisonStack = SanitizeFunction && ClPoisonStack;

View File

@ -213,8 +213,7 @@ namespace {
PartialThreshold = UserThreshold ? CurrentThreshold : UP.PartialThreshold; PartialThreshold = UserThreshold ? CurrentThreshold : UP.PartialThreshold;
if (!UserThreshold && if (!UserThreshold &&
L->getHeader()->getParent()->getAttributes(). L->getHeader()->getParent()->hasFnAttribute(
hasAttribute(AttributeSet::FunctionIndex,
Attribute::OptimizeForSize)) { Attribute::OptimizeForSize)) {
Threshold = UP.OptSizeThreshold; Threshold = UP.OptSizeThreshold;
PartialThreshold = UP.PartialOptSizeThreshold; PartialThreshold = UP.PartialOptSizeThreshold;

View File

@ -657,9 +657,7 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val) {
// Check to see if it would be profitable to unswitch current loop. // Check to see if it would be profitable to unswitch current loop.
// Do not do non-trivial unswitch while optimizing for size. // Do not do non-trivial unswitch while optimizing for size.
if (OptimizeForSize || if (OptimizeForSize || F->hasFnAttribute(Attribute::OptimizeForSize))
F->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
Attribute::OptimizeForSize))
return false; return false;
UnswitchNontrivialCondition(LoopCond, Val, currentLoop); UnswitchNontrivialCondition(LoopCond, Val, currentLoop);

View File

@ -3454,9 +3454,8 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
// Look for the attribute signaling the absence of NaNs. // Look for the attribute signaling the absence of NaNs.
Function &F = *Header->getParent(); Function &F = *Header->getParent();
if (F.hasFnAttribute("no-nans-fp-math")) if (F.hasFnAttribute("no-nans-fp-math"))
HasFunNoNaNAttr = F.getAttributes().getAttribute( HasFunNoNaNAttr =
AttributeSet::FunctionIndex, F.getFnAttribute("no-nans-fp-math").getValueAsString() == "true";
"no-nans-fp-math").getValueAsString() == "true";
// For each block in the loop. // For each block in the loop.
for (Loop::block_iterator bb = TheLoop->block_begin(), for (Loop::block_iterator bb = TheLoop->block_begin(),