diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -1364,7 +1364,7 @@ "__block_literal_global", blockInfo.BlockAlign, /*constant*/ !IsWindows, llvm::GlobalVariable::InternalLinkage, AddrSpace); - literal->addAttribute("objc_arc_inert"); + literal->addAttribute(llvm::ObjcArcInertAttr); // Windows does not allow globals to be initialised to point to globals in // different DLLs. Any such variables must run code to initialise them. diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1758,7 +1758,7 @@ AA->getAssumption().split(Attrs, ","); if (!Attrs.empty()) - FuncAttrs.addAttribute(llvm::AssumptionAttrKey, + FuncAttrs.addAttribute(llvm::LLVMAssumeAttr, llvm::join(Attrs.begin(), Attrs.end(), ",")); } @@ -1788,8 +1788,9 @@ if (CodeGenOpts.DisableRedZone) FuncAttrs.addAttribute(llvm::Attribute::NoRedZone); - if (CodeGenOpts.IndirectTlsSegRefs) - FuncAttrs.addAttribute("indirect-tls-seg-refs"); + if (CodeGenOpts.IndirectTlsSegRefs) { + FuncAttrs.addAttribute(llvm::IndirectTLSSegRefsAttr); + } if (CodeGenOpts.NoImplicitFloat) FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat); @@ -1797,8 +1798,9 @@ // Attributes that should go on the call site only. if (!CodeGenOpts.SimplifyLibCalls || LangOpts.isNoBuiltinFunc(Name)) FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin); - if (!CodeGenOpts.TrapFuncName.empty()) - FuncAttrs.addAttribute("trap-func-name", CodeGenOpts.TrapFuncName); + if (!CodeGenOpts.TrapFuncName.empty()) { + FuncAttrs.addAttribute(llvm::TrapFuncNameAttr, CodeGenOpts.TrapFuncName); + } } else { StringRef FpKind; switch (CodeGenOpts.getFramePointer()) { @@ -1812,65 +1814,79 @@ FpKind = "all"; break; } - FuncAttrs.addAttribute("frame-pointer", FpKind); + FuncAttrs.addAttribute(llvm::FramePointerAttr, FpKind); - if (CodeGenOpts.LessPreciseFPMAD) - FuncAttrs.addAttribute("less-precise-fpmad", "true"); + if (CodeGenOpts.LessPreciseFPMAD) { + FuncAttrs.addAttribute(llvm::LessPreciseFPMADAttr, "true"); + } if (CodeGenOpts.NullPointerIsValid) FuncAttrs.addAttribute(llvm::Attribute::NullPointerIsValid); - if (CodeGenOpts.FPDenormalMode != llvm::DenormalMode::getIEEE()) - FuncAttrs.addAttribute("denormal-fp-math", + if (CodeGenOpts.FPDenormalMode != llvm::DenormalMode::getIEEE()) { + FuncAttrs.addAttribute(llvm::DenormalFPMathAttr, CodeGenOpts.FPDenormalMode.str()); + } if (CodeGenOpts.FP32DenormalMode != CodeGenOpts.FPDenormalMode) { - FuncAttrs.addAttribute( - "denormal-fp-math-f32", - CodeGenOpts.FP32DenormalMode.str()); + FuncAttrs.addAttribute(llvm::DenormalFPMathf32Attr, + CodeGenOpts.FP32DenormalMode.str()); } - if (LangOpts.getFPExceptionMode() == LangOptions::FPE_Ignore) - FuncAttrs.addAttribute("no-trapping-math", "true"); + if (LangOpts.getFPExceptionMode() == LangOptions::FPE_Ignore) { + FuncAttrs.addAttribute(llvm::NoTrappingMathAttr, "true"); + } // Strict (compliant) code is the default, so only add this attribute to // indicate that we are trying to workaround a problem case. - if (!CodeGenOpts.StrictFloatCastOverflow) - FuncAttrs.addAttribute("strict-float-cast-overflow", "false"); + if (!CodeGenOpts.StrictFloatCastOverflow) { + FuncAttrs.addAttribute(llvm::StrictFloatCastOverflowAttr, "false"); + } // TODO: Are these all needed? // unsafe/inf/nan/nsz are handled by instruction-level FastMathFlags. - if (LangOpts.NoHonorInfs) - FuncAttrs.addAttribute("no-infs-fp-math", "true"); - if (LangOpts.NoHonorNaNs) - FuncAttrs.addAttribute("no-nans-fp-math", "true"); - if (LangOpts.ApproxFunc) - FuncAttrs.addAttribute("approx-func-fp-math", "true"); - if (LangOpts.UnsafeFPMath) - FuncAttrs.addAttribute("unsafe-fp-math", "true"); - if (CodeGenOpts.SoftFloat) - FuncAttrs.addAttribute("use-soft-float", "true"); - FuncAttrs.addAttribute("stack-protector-buffer-size", + if (LangOpts.NoHonorInfs) { + FuncAttrs.addAttribute(llvm::NoInfsFPMathAttr, "true"); + } + if (LangOpts.NoHonorNaNs) { + FuncAttrs.addAttribute(llvm::NoNansFPMathAttr, "true"); + } + if (LangOpts.ApproxFunc) { + FuncAttrs.addAttribute(llvm::ApproxFuncFPMathAttr, "true"); + } + if (LangOpts.UnsafeFPMath) { + FuncAttrs.addAttribute(llvm::UnsafeFPMathAttr, "true"); + } + if (CodeGenOpts.SoftFloat) { + FuncAttrs.addAttribute(llvm::UseSoftFloatAttr, "true"); + } + FuncAttrs.addAttribute(llvm::StackProtectorBufferSizeAttr, llvm::utostr(CodeGenOpts.SSPBufferSize)); - if (LangOpts.NoSignedZero) - FuncAttrs.addAttribute("no-signed-zeros-fp-math", "true"); + if (LangOpts.NoSignedZero) { + FuncAttrs.addAttribute(llvm::NoSignedZerosFPMathAttr, "true"); + } // TODO: Reciprocal estimate codegen options should apply to instructions? const std::vector &Recips = CodeGenOpts.Reciprocals; - if (!Recips.empty()) - FuncAttrs.addAttribute("reciprocal-estimates", + if (!Recips.empty()) { + FuncAttrs.addAttribute(llvm::ReciprocalEstimatesAttr, llvm::join(Recips, ",")); + } if (!CodeGenOpts.PreferVectorWidth.empty() && - CodeGenOpts.PreferVectorWidth != "none") - FuncAttrs.addAttribute("prefer-vector-width", + CodeGenOpts.PreferVectorWidth != "none") { + FuncAttrs.addAttribute(llvm::PreferVectorWidthAttr, CodeGenOpts.PreferVectorWidth); + } - if (CodeGenOpts.StackRealignment) - FuncAttrs.addAttribute("stackrealign"); - if (CodeGenOpts.Backchain) - FuncAttrs.addAttribute("backchain"); - if (CodeGenOpts.EnableSegmentedStacks) - FuncAttrs.addAttribute("split-stack"); + if (CodeGenOpts.StackRealignment) { + FuncAttrs.addAttribute(llvm::StackrealignAttr); + } + if (CodeGenOpts.Backchain) { + FuncAttrs.addAttribute(llvm::BackchainAttr); + } + if (CodeGenOpts.EnableSegmentedStacks) { + FuncAttrs.addAttribute(llvm::SplitStackAttr); + } if (CodeGenOpts.SpeculativeLoadHardening) FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening); @@ -1893,7 +1909,7 @@ for (StringRef Attr : CodeGenOpts.DefaultFunctionAttrs) { StringRef Var, Value; std::tie(Var, Value) = Attr.split('='); - FuncAttrs.addAttribute(Var, Value); + FuncAttrs.addAttribute(llvm::AttributeKey::Create(Var), Value); } } @@ -1919,13 +1935,13 @@ SmallString<32> AttributeName; AttributeName += "no-builtin-"; AttributeName += BuiltinName; - FuncAttrs.addAttribute(AttributeName); + FuncAttrs.addAttribute(llvm::AttributeKey::Create(AttributeName)); }; // First, handle the language options passed through -fno-builtin. if (LangOpts.NoBuiltin) { // -fno-builtin disables them all. - FuncAttrs.addAttribute("no-builtins"); + FuncAttrs.addAttribute(llvm::NoBuiltinsAttr); return; } @@ -1940,7 +1956,7 @@ // If there is a wildcard in the builtin names specified through the // attribute, disable them all. if (llvm::is_contained(NBA->builtinNames(), "*")) { - FuncAttrs.addAttribute("no-builtins"); + FuncAttrs.addAttribute(llvm::NoBuiltinsAttr); return; } @@ -2028,8 +2044,9 @@ CallingConv = FI.getEffectiveCallingConvention(); if (FI.isNoReturn()) FuncAttrs.addAttribute(llvm::Attribute::NoReturn); - if (FI.isCmseNSCall()) - FuncAttrs.addAttribute("cmse_nonsecure_call"); + if (FI.isCmseNSCall()) { + FuncAttrs.addAttribute(llvm::CmseNonsecureEntryAttr); + } // Collect function IR attributes from the callee prototype if we have one. AddAttributesFromFunctionProtoType(getContext(), FuncAttrs, @@ -2110,8 +2127,9 @@ if (TargetDecl->hasAttr() && !CodeGenOpts.NullPointerIsValid) RetAttrs.addAttribute(llvm::Attribute::NonNull); - if (TargetDecl->hasAttr()) - FuncAttrs.addAttribute("no_caller_saved_registers"); + if (TargetDecl->hasAttr()) { + FuncAttrs.addAttribute(llvm::NoCallerSavedRegistersAttr); + } if (TargetDecl->hasAttr()) FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck); if (TargetDecl->hasAttr()) @@ -2129,14 +2147,14 @@ if (TargetDecl->hasAttr()) { if (getLangOpts().OpenCLVersion <= 120) { // OpenCL v1.2 Work groups are always uniform - FuncAttrs.addAttribute("uniform-work-group-size", "true"); + FuncAttrs.addAttribute(llvm::UniformWorkGroupSizeAttr, "true"); } else { // OpenCL v2.0 Work groups may be whether uniform or not. // '-cl-uniform-work-group-size' compile option gets a hint // to the compiler that the global work-size be a multiple of // the work-group size specified to clEnqueueNDRangeKernel // (i.e. work groups are uniform). - FuncAttrs.addAttribute("uniform-work-group-size", + FuncAttrs.addAttribute(llvm::UniformWorkGroupSizeAttr, llvm::toStringRef(CodeGenOpts.UniformWGSize)); } } @@ -2160,8 +2178,9 @@ FuncAttrs.removeAttribute(llvm::Attribute::SpeculativeLoadHardening); if (TargetDecl->hasAttr()) FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening); - if (TargetDecl->hasAttr()) - FuncAttrs.removeAttribute("split-stack"); + if (TargetDecl->hasAttr()) { + FuncAttrs.removeAttribute(llvm::SplitStackAttr); + } // Add NonLazyBind attribute to function declarations when -fno-plt // is used. @@ -2181,17 +2200,19 @@ if (TargetDecl && CodeGenOpts.UniqueInternalLinkageNames) { if (isa(TargetDecl)) { if (this->getFunctionLinkage(CalleeInfo.getCalleeDecl()) == - llvm::GlobalValue::InternalLinkage) - FuncAttrs.addAttribute("sample-profile-suffix-elision-policy", + llvm::GlobalValue::InternalLinkage) { + FuncAttrs.addAttribute(llvm::SampleProfileSuffixElisionPolicyAttr, "selected"); + } } } // Collect non-call-site function IR attributes from declaration-specific // information. if (!AttrOnCallSite) { - if (TargetDecl && TargetDecl->hasAttr()) - FuncAttrs.addAttribute("cmse_nonsecure_entry"); + if (TargetDecl && TargetDecl->hasAttr()) { + FuncAttrs.addAttribute(llvm::CmseNonsecureEntryAttr); + } // Whether tail calls are enabled. auto shouldDisableTailCalls = [&] { @@ -2214,8 +2235,9 @@ return false; }; - if (shouldDisableTailCalls()) - FuncAttrs.addAttribute("disable-tail-calls", "true"); + if (shouldDisableTailCalls()) { + FuncAttrs.addAttribute(llvm::DisableTailCallsAttr, "true"); + } // CPU/feature overrides. addDefaultFunctionDefinitionAttributes // handles these separately to set them based on the global defaults. @@ -5263,8 +5285,10 @@ // Control Flow Guard checks should not be added, even if the call is inlined. if (const auto *FD = dyn_cast_or_null(CurFuncDecl)) { if (const auto *A = FD->getAttr()) { - if (A->getGuard() == CFGuardAttr::GuardArg::nocf && !CI->getCalledFunction()) - Attrs = Attrs.addFnAttribute(getLLVMContext(), "guard_nocf"); + if (A->getGuard() == CFGuardAttr::GuardArg::nocf && + !CI->getCalledFunction()) { + Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::GuardNocfAttr); + } } } diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1691,7 +1691,7 @@ return; // Prevent the current stack frame from disappearing from the stack trace. - CGF.CurFn->addFnAttr("disable-tail-calls", "true"); + CGF.CurFn->addFnAttr(llvm::DisableTailCallsAttr, "true"); // Construct pointer to region to begin poisoning, and calculate poison // size, so that only members declared in this class are poisoned. diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -434,14 +434,18 @@ if (D.hasAttr()) CGM.AddGlobalAnnotations(&D, var); - if (auto *SA = D.getAttr()) - var->addAttribute("bss-section", SA->getName()); - if (auto *SA = D.getAttr()) - var->addAttribute("data-section", SA->getName()); - if (auto *SA = D.getAttr()) - var->addAttribute("rodata-section", SA->getName()); - if (auto *SA = D.getAttr()) - var->addAttribute("relro-section", SA->getName()); + if (auto *SA = D.getAttr()) { + var->addAttribute(llvm::BssSectionAttr, SA->getName()); + } + if (auto *SA = D.getAttr()) { + var->addAttribute(llvm::DataSectionAttr, SA->getName()); + } + if (auto *SA = D.getAttr()) { + var->addAttribute(llvm::RodataSectionAttr, SA->getName()); + } + if (auto *SA = D.getAttr()) { + var->addAttribute(llvm::RelroSectionAttr, SA->getName()); + } if (const SectionAttr *SA = D.getAttr()) var->setSection(SA->getName()); diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -712,7 +712,7 @@ getLangOpts().GPUAllowDeviceInit); if (getLangOpts().HIP && getLangOpts().CUDAIsDevice) { Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL); - Fn->addFnAttr("device-init"); + Fn->addFnAttr(llvm::DeviceInitAttr); } CXXGlobalInits.clear(); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3494,7 +3494,7 @@ llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { - auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", + auto A = llvm::Attribute::get(getLLVMContext(), llvm::TrapFuncNameAttr, CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } @@ -3518,7 +3518,7 @@ Builder.CreateCall(CGM.getIntrinsic(IntrID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { - auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", + auto A = llvm::Attribute::get(getLLVMContext(), llvm::TrapFuncNameAttr, CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -6581,13 +6581,13 @@ int32_t DefaultValTeams = -1; getNumTeamsExprForTargetDirective(CGF, D, DefaultValTeams); if (DefaultValTeams > 0) { - OutlinedFn->addFnAttr("omp_target_num_teams", + OutlinedFn->addFnAttr(llvm::OmpTargetNumTeamsAttr, std::to_string(DefaultValTeams)); } int32_t DefaultValThreads = -1; getNumThreadsExprForTargetDirective(CGF, D, DefaultValThreads); if (DefaultValThreads > 0) { - OutlinedFn->addFnAttr("omp_target_thread_limit", + OutlinedFn->addFnAttr(llvm::OmpTargetThreadLimitAttr, std::to_string(DefaultValThreads)); } } @@ -11614,7 +11614,7 @@ Out << 'a' << ParamAttr.Alignment; } Out << '_' << Fn->getName(); - Fn->addFnAttr(Out.str()); + Fn->addFnAttr(llvm::AttributeKey::Create(Out.str())); } } } @@ -11772,7 +11772,7 @@ if (OutputBecomesInput) Out << "v"; Out << ParSeq << "_" << MangledName; - Fn->addFnAttr(Out.str()); + Fn->addFnAttr(llvm::AttributeKey::Create(Out.str())); } // Helper function to generate the Advanced SIMD names depending on diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -562,8 +562,9 @@ // that the return type is meaningless. These thunks can be used to call // functions with differing return types, and the caller is required to cast // the prototype appropriately to extract the correct value. - if (IsUnprototyped) - ThunkFn->addFnAttr("thunk"); + if (IsUnprototyped) { + ThunkFn->addFnAttr(llvm::ThunkAttr); + } CGM.SetLLVMFunctionAttributesForDefinition(GD.getDecl(), ThunkFn); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -162,20 +162,20 @@ NewRoundingBehavior == llvm::RoundingMode::NearestTiesToEven)) && "FPConstrained should be enabled on entire function"); - auto mergeFnAttrValue = [&](StringRef Name, bool Value) { + auto mergeFnAttrValue = [&](llvm::AttributeKey Name, bool Value) { auto OldValue = CGF.CurFn->getFnAttribute(Name).getValueAsBool(); auto NewValue = OldValue & Value; if (OldValue != NewValue) CGF.CurFn->addFnAttr(Name, llvm::toStringRef(NewValue)); }; - mergeFnAttrValue("no-infs-fp-math", FPFeatures.getNoHonorInfs()); - mergeFnAttrValue("no-nans-fp-math", FPFeatures.getNoHonorNaNs()); - mergeFnAttrValue("no-signed-zeros-fp-math", FPFeatures.getNoSignedZero()); - mergeFnAttrValue("unsafe-fp-math", FPFeatures.getAllowFPReassociate() && - FPFeatures.getAllowReciprocal() && - FPFeatures.getAllowApproxFunc() && - FPFeatures.getNoSignedZero()); + mergeFnAttrValue(llvm::NoInfsFPMathAttr, FPFeatures.getNoHonorInfs()); + mergeFnAttrValue(llvm::NoNansFPMathAttr, FPFeatures.getNoHonorNaNs()); + mergeFnAttrValue(llvm::NoSignedZerosFPMathAttr, FPFeatures.getNoSignedZero()); + mergeFnAttrValue( + llvm::UnsafeFPMathAttr, + FPFeatures.getAllowFPReassociate() && FPFeatures.getAllowReciprocal() && + FPFeatures.getAllowApproxFunc() && FPFeatures.getNoSignedZero()); } CodeGenFunction::CGFPOptionsRAII::~CGFPOptionsRAII() { @@ -375,11 +375,14 @@ llvm::DebugLoc Loc = EmitReturnBlock(); if (ShouldInstrumentFunction()) { - if (CGM.getCodeGenOpts().InstrumentFunctions) - CurFn->addFnAttr("instrument-function-exit", "__cyg_profile_func_exit"); - if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining) - CurFn->addFnAttr("instrument-function-exit-inlined", + if (CGM.getCodeGenOpts().InstrumentFunctions) { + CurFn->addFnAttr(llvm::InstrumentFunctionExitAttr, "__cyg_profile_func_exit"); + } + if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining) { + CurFn->addFnAttr(llvm::InstrumentFunctionExitInlinedAttr, + "__cyg_profile_func_exit"); + } } if (ShouldSkipSanitizerInstrumentation()) @@ -494,7 +497,8 @@ // 4. Width of vector arguments and return types for this function. // 5. Width of vector aguments and return types for functions called by this // function. - CurFn->addFnAttr("min-legal-vector-width", llvm::utostr(LargestVectorWidth)); + CurFn->addFnAttr(llvm::MinLegalVectorWidthAttr, + llvm::utostr(LargestVectorWidth)); // Add vscale_range attribute if appropriate. Optional> VScaleRange = @@ -664,7 +668,7 @@ void CodeGenFunction::markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn) { if (SanOpts.has(SanitizerKind::Thread)) { - Fn->addFnAttr("sanitize_thread_no_checking_at_run_time"); + Fn->addFnAttr(llvm::SanitizeThreadNoCheckingAtRunTimeAttr); Fn->removeFnAttr(llvm::Attribute::SanitizeThread); } } @@ -823,34 +827,39 @@ CGM.getCodeGenOpts().XRayInstrumentationBundle.has( XRayInstrKind::FunctionExit)) { if (XRayAttr->alwaysXRayInstrument() && ShouldXRayInstrumentFunction()) { - Fn->addFnAttr("function-instrument", "xray-always"); + Fn->addFnAttr(llvm::FunctionInstrumentAttr, "xray-always"); AlwaysXRayAttr = true; } if (XRayAttr->neverXRayInstrument()) - Fn->addFnAttr("function-instrument", "xray-never"); + Fn->addFnAttr(llvm::FunctionInstrumentAttr, "xray-never"); if (const auto *LogArgs = D->getAttr()) - if (ShouldXRayInstrumentFunction()) - Fn->addFnAttr("xray-log-args", + if (ShouldXRayInstrumentFunction()) { + Fn->addFnAttr(llvm::XrayLogArgsAttr, llvm::utostr(LogArgs->getArgumentCount())); + } } } else { - if (ShouldXRayInstrumentFunction() && !CGM.imbueXRayAttrs(Fn, Loc)) + if (ShouldXRayInstrumentFunction() && !CGM.imbueXRayAttrs(Fn, Loc)) { Fn->addFnAttr( - "xray-instruction-threshold", + llvm::XrayInstructionThresholdAttr, llvm::itostr(CGM.getCodeGenOpts().XRayInstructionThreshold)); + } } if (ShouldXRayInstrumentFunction()) { - if (CGM.getCodeGenOpts().XRayIgnoreLoops) - Fn->addFnAttr("xray-ignore-loops"); + if (CGM.getCodeGenOpts().XRayIgnoreLoops) { + Fn->addFnAttr(llvm::XrayIgnoreLoopsAttr); + } if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has( - XRayInstrKind::FunctionExit)) - Fn->addFnAttr("xray-skip-exit"); + XRayInstrKind::FunctionExit)) { + Fn->addFnAttr(llvm::XraySkipExitAttr); + } if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has( - XRayInstrKind::FunctionEntry)) - Fn->addFnAttr("xray-skip-entry"); + XRayInstrKind::FunctionEntry)) { + Fn->addFnAttr(llvm::XraySkipEntryAttr); + } auto FuncGroups = CGM.getCodeGenOpts().XRayTotalFunctionGroups; if (FuncGroups > 1) { @@ -858,8 +867,9 @@ CurFn->getName().bytes_begin(), CurFn->getName().bytes_end()); auto Group = crc32(FuncName) % FuncGroups; if (Group != CGM.getCodeGenOpts().XRaySelectedFunctionGroup && - !AlwaysXRayAttr) - Fn->addFnAttr("function-instrument", "xray-never"); + !AlwaysXRayAttr) { + Fn->addFnAttr(llvm::FunctionInstrumentAttr, "xray-never"); + } } } @@ -877,28 +887,35 @@ Offset = CGM.getCodeGenOpts().PatchableFunctionEntryOffset; } if (Count && Offset <= Count) { - Fn->addFnAttr("patchable-function-entry", std::to_string(Count - Offset)); - if (Offset) - Fn->addFnAttr("patchable-function-prefix", std::to_string(Offset)); + Fn->addFnAttr(llvm::PatchableFunctionEntryAttr, + std::to_string(Count - Offset)); + if (Offset) { + Fn->addFnAttr(llvm::PatchableFunctionPrefixAttr, std::to_string(Offset)); + } } // Add no-jump-tables value. - if (CGM.getCodeGenOpts().NoUseJumpTables) - Fn->addFnAttr("no-jump-tables", "true"); + if (CGM.getCodeGenOpts().NoUseJumpTables) { + Fn->addFnAttr(llvm::NoJumpTablesAttr, "true"); + } // Add no-inline-line-tables value. - if (CGM.getCodeGenOpts().NoInlineLineTables) - Fn->addFnAttr("no-inline-line-tables"); + if (CGM.getCodeGenOpts().NoInlineLineTables) { + Fn->addFnAttr(llvm::NoInlineLineTablesAttr); + } // Add profile-sample-accurate value. - if (CGM.getCodeGenOpts().ProfileSampleAccurate) - Fn->addFnAttr("profile-sample-accurate"); + if (CGM.getCodeGenOpts().ProfileSampleAccurate) { + Fn->addFnAttr(llvm::ProfileSampleAccurateAttr); + } - if (!CGM.getCodeGenOpts().SampleProfileFile.empty()) - Fn->addFnAttr("use-sample-profile"); + if (!CGM.getCodeGenOpts().SampleProfileFile.empty()) { + Fn->addFnAttr(llvm::UseSampleProfileAttr); + } - if (D && D->hasAttr()) - Fn->addFnAttr("cfi-canonical-jump-table"); + if (D && D->hasAttr()) { + Fn->addFnAttr(llvm::CfiCanonicalJumpTablesAttr); + } if (D && D->hasAttr()) Fn->addFnAttr(llvm::Attribute::NoProfile); @@ -970,8 +987,9 @@ // If a custom alignment is used, force realigning to this alignment on // any main function which certainly will need it. if (FD && ((FD->isMain() || FD->isMSVCRTEntryPoint()) && - CGM.getCodeGenOpts().StackAlignment)) - Fn->addFnAttr("stackrealign"); + CGM.getCodeGenOpts().StackAlignment)) { + Fn->addFnAttr(llvm::StackrealignAttr); + } llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn); @@ -1004,14 +1022,18 @@ } if (ShouldInstrumentFunction()) { - if (CGM.getCodeGenOpts().InstrumentFunctions) - CurFn->addFnAttr("instrument-function-entry", "__cyg_profile_func_enter"); - if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining) - CurFn->addFnAttr("instrument-function-entry-inlined", + if (CGM.getCodeGenOpts().InstrumentFunctions) { + CurFn->addFnAttr(llvm::InstrumentFunctionEntryAttr, "__cyg_profile_func_enter"); - if (CGM.getCodeGenOpts().InstrumentFunctionEntryBare) - CurFn->addFnAttr("instrument-function-entry-inlined", + } + if (CGM.getCodeGenOpts().InstrumentFunctionsAfterInlining) { + CurFn->addFnAttr(llvm::InstrumentFunctionEntryInlinedAttr, + "__cyg_profile_func_enter"); + } + if (CGM.getCodeGenOpts().InstrumentFunctionEntryBare) { + CurFn->addFnAttr(llvm::InstrumentFunctionEntryInlinedAttr, "__cyg_profile_func_enter_bare"); + } } // Since emitting the mcount call here impacts optimizations such as function @@ -1022,24 +1044,25 @@ // Calls to fentry/mcount should not be generated if function has // the no_instrument_function attribute. if (!CurFuncDecl || !CurFuncDecl->hasAttr()) { - if (CGM.getCodeGenOpts().CallFEntry) - Fn->addFnAttr("fentry-call", "true"); - else { - Fn->addFnAttr("instrument-function-entry-inlined", + if (CGM.getCodeGenOpts().CallFEntry) { + Fn->addFnAttr(llvm::FentryCallAttr, "true"); + } else { + Fn->addFnAttr(llvm::InstrumentFunctionEntryInlinedAttr, getTarget().getMCountName()); } + if (CGM.getCodeGenOpts().MNopMCount) { if (!CGM.getCodeGenOpts().CallFEntry) CGM.getDiags().Report(diag::err_opt_not_valid_without_opt) << "-mnop-mcount" << "-mfentry"; - Fn->addFnAttr("mnop-mcount"); + Fn->addFnAttr(llvm::MnopMcountAttr); } if (CGM.getCodeGenOpts().RecordMCount) { if (!CGM.getCodeGenOpts().CallFEntry) CGM.getDiags().Report(diag::err_opt_not_valid_without_opt) << "-mrecord-mcount" << "-mfentry"; - Fn->addFnAttr("mrecord-mcount"); + Fn->addFnAttr(llvm::MrecordMcountAttr); } } } @@ -1049,13 +1072,14 @@ llvm::Triple::systemz) CGM.getDiags().Report(diag::err_opt_not_valid_on_target) << "-mpacked-stack"; - Fn->addFnAttr("packed-stack"); + Fn->addFnAttr(llvm::PackedStackAttr); } if (CGM.getCodeGenOpts().WarnStackSize != UINT_MAX && - !CGM.getDiags().isIgnored(diag::warn_fe_backend_frame_larger_than, Loc)) - Fn->addFnAttr("warn-stack-size", + !CGM.getDiags().isIgnored(diag::warn_fe_backend_frame_larger_than, Loc)) { + Fn->addFnAttr(llvm::WarnStackSizeAttr, std::to_string(CGM.getCodeGenOpts().WarnStackSize)); + } if (RetTy->isVoidType()) { // Void type; nothing to return. diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1786,8 +1786,9 @@ if (CodeGenOpts.UnwindTables) B.addAttribute(llvm::Attribute::UWTable); - if (CodeGenOpts.StackClashProtector) - B.addAttribute("probe-stack", "inline-asm"); + if (CodeGenOpts.StackClashProtector) { + B.addAttribute(llvm::ProbeStackAttr, "inline-asm"); + } if (!hasUnwindExceptions(LangOpts)) B.addAttribute(llvm::Attribute::NoUnwind); @@ -1944,9 +1945,7 @@ void CodeGenModule::setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F) { if (D->hasAttr()) { - llvm::AttrBuilder FuncAttrs; - FuncAttrs.addAttribute("strictfp"); - F->addFnAttrs(FuncAttrs); + F->addFnAttr(llvm::StrictfpAttr); } } @@ -2011,16 +2010,16 @@ } if (!TargetCPU.empty()) { - Attrs.addAttribute("target-cpu", TargetCPU); + Attrs.addAttribute(llvm::TargetCPUAttr, TargetCPU); AddedAttr = true; } if (!TuneCPU.empty()) { - Attrs.addAttribute("tune-cpu", TuneCPU); + Attrs.addAttribute(llvm::TuneCPUAttr, TuneCPU); AddedAttr = true; } if (!Features.empty()) { llvm::sort(Features); - Attrs.addAttribute("target-features", llvm::join(Features, ",")); + Attrs.addAttribute(llvm::TargetFeaturesAttr, llvm::join(Features, ",")); AddedAttr = true; } @@ -2036,22 +2035,27 @@ if (auto *GV = dyn_cast(GO)) { if (D->hasAttr()) addUsedGlobal(GV); - if (auto *SA = D->getAttr()) - GV->addAttribute("bss-section", SA->getName()); - if (auto *SA = D->getAttr()) - GV->addAttribute("data-section", SA->getName()); - if (auto *SA = D->getAttr()) - GV->addAttribute("rodata-section", SA->getName()); - if (auto *SA = D->getAttr()) - GV->addAttribute("relro-section", SA->getName()); + if (auto *SA = D->getAttr()) { + GV->addAttribute(llvm::BssSectionAttr, SA->getName()); + } + if (auto *SA = D->getAttr()) { + GV->addAttribute(llvm::DataSectionAttr, SA->getName()); + } + if (auto *SA = D->getAttr()) { + GV->addAttribute(llvm::RodataSectionAttr, SA->getName()); + } + if (auto *SA = D->getAttr()) { + GV->addAttribute(llvm::RelroSectionAttr, SA->getName()); + } } if (auto *F = dyn_cast(GO)) { if (D->hasAttr()) addUsedGlobal(F); if (auto *SA = D->getAttr()) - if (!D->getAttr()) - F->addFnAttr("implicit-section-name", SA->getName()); + if (!D->getAttr()) { + F->addFnAttr(llvm::ImplicitSectionNameAttr, SA->getName()); + } llvm::AttrBuilder Attrs; if (GetCPUAndFeaturesAttributes(GD, Attrs)) { @@ -2059,9 +2063,9 @@ // newest set, since it has the newest possible FunctionDecl, so the // new ones should replace the old. llvm::AttrBuilder RemoveAttrs; - RemoveAttrs.addAttribute("target-cpu"); - RemoveAttrs.addAttribute("target-features"); - RemoveAttrs.addAttribute("tune-cpu"); + RemoveAttrs.addAttribute(llvm::TargetCPUAttr); + RemoveAttrs.addAttribute(llvm::TargetFeaturesAttr); + RemoveAttrs.addAttribute(llvm::TuneCPUAttr); F->removeFnAttrs(RemoveAttrs); F->addFnAttrs(Attrs); } @@ -2165,10 +2169,11 @@ F->setSection(SA->getName()); if (const auto *EA = FD->getAttr()) { - if (EA->isError()) - F->addFnAttr("dontcall-error", EA->getUserDiagnostic()); - else if (EA->isWarning()) - F->addFnAttr("dontcall-warn", EA->getUserDiagnostic()); + if (EA->isError()) { + F->addFnAttr(llvm::DontcallErrorAttr, EA->getUserDiagnostic()); + } else if (EA->isWarning()) { + F->addFnAttr(llvm::DontcallWarnAttr, EA->getUserDiagnostic()); + } } // If we plan on emitting this inline builtin, we can't treat it as a builtin. @@ -2692,14 +2697,14 @@ case ImbueAttr::NONE: return false; case ImbueAttr::ALWAYS: - Fn->addFnAttr("function-instrument", "xray-always"); + Fn->addFnAttr(llvm::FunctionInstrumentAttr, "xray-always"); break; case ImbueAttr::ALWAYS_ARG1: - Fn->addFnAttr("function-instrument", "xray-always"); - Fn->addFnAttr("xray-log-args", "1"); + Fn->addFnAttr(llvm::FunctionInstrumentAttr, "xray-always"); + Fn->addFnAttr(llvm::XrayLogArgsAttr, "1"); break; case ImbueAttr::NEVER: - Fn->addFnAttr("function-instrument", "xray-never"); + Fn->addFnAttr(llvm::FunctionInstrumentAttr, "xray-never"); break; } return true; @@ -5276,7 +5281,7 @@ GV = Fields.finishAndCreateGlobal("_unnamed_cfstring_", Alignment, /*isConstant=*/false, llvm::GlobalVariable::PrivateLinkage); - GV->addAttribute("objc_arc_inert"); + GV->addAttribute(llvm::ObjcArcInertAttr); switch (Triple.getObjectFormat()) { case llvm::Triple::UnknownObjectFormat: llvm_unreachable("unknown file format"); diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -2058,7 +2058,7 @@ // meaningless. These thunks can be used to call functions with differing // return types, and the caller is required to cast the prototype // appropriately to extract the correct value. - ThunkFn->addFnAttr("thunk"); + ThunkFn->addFnAttr(llvm::ThunkAttr); // These thunks can be compared, so they are not unnamed. ThunkFn->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None); diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -856,27 +856,28 @@ if (const auto *Attr = FD->getAttr()) { llvm::Function *Fn = cast(GV); llvm::AttrBuilder B; - B.addAttribute("wasm-import-module", Attr->getImportModule()); + B.addAttribute(llvm::WasmImportModuleAttr, Attr->getImportModule()); Fn->addFnAttrs(B); } if (const auto *Attr = FD->getAttr()) { llvm::Function *Fn = cast(GV); llvm::AttrBuilder B; - B.addAttribute("wasm-import-name", Attr->getImportName()); + B.addAttribute(llvm::WasmImportNameAttr, Attr->getImportName()); Fn->addFnAttrs(B); } if (const auto *Attr = FD->getAttr()) { llvm::Function *Fn = cast(GV); llvm::AttrBuilder B; - B.addAttribute("wasm-export-name", Attr->getExportName()); + B.addAttribute(llvm::WasmExportNameAttr, Attr->getExportName()); Fn->addFnAttrs(B); } } if (auto *FD = dyn_cast_or_null(D)) { llvm::Function *Fn = cast(GV); - if (!FD->doesThisDeclarationHaveABody() && !FD->hasPrototype()) - Fn->addFnAttr("no-prototype"); + if (!FD->doesThisDeclarationHaveABody() && !FD->hasPrototype()) { + Fn->addFnAttr(llvm::NoPrototypeAttr); + } } } }; @@ -2166,7 +2167,7 @@ if (const FunctionDecl *FD = dyn_cast_or_null(D)) { if (FD->hasAttr()) { llvm::Function *Fn = cast(GV); - Fn->addFnAttr("stackrealign"); + Fn->addFnAttr(llvm::StackrealignAttr); } addX86InterruptAttrs(FD, GV, CGM); @@ -2532,7 +2533,7 @@ if (const FunctionDecl *FD = dyn_cast_or_null(D)) { if (FD->hasAttr()) { llvm::Function *Fn = cast(GV); - Fn->addFnAttr("stackrealign"); + Fn->addFnAttr(llvm::StackrealignAttr); } addX86InterruptAttrs(FD, GV, CGM); @@ -2683,11 +2684,13 @@ CodeGen::CodeGenModule &CGM) { if (llvm::Function *Fn = dyn_cast_or_null(GV)) { - if (CGM.getCodeGenOpts().StackProbeSize != 4096) - Fn->addFnAttr("stack-probe-size", + if (CGM.getCodeGenOpts().StackProbeSize != 4096) { + Fn->addFnAttr(llvm::StackProbeSizeAttr, llvm::utostr(CGM.getCodeGenOpts().StackProbeSize)); - if (CGM.getCodeGenOpts().NoStackArgProbe) - Fn->addFnAttr("no-stack-arg-probe"); + } + if (CGM.getCodeGenOpts().NoStackArgProbe) { + Fn->addFnAttr(llvm::NoStackArgProbeAttr); + } } } @@ -2743,7 +2746,7 @@ if (const FunctionDecl *FD = dyn_cast_or_null(D)) { if (FD->hasAttr()) { llvm::Function *Fn = cast(GV); - Fn->addFnAttr("stackrealign"); + Fn->addFnAttr(llvm::StackrealignAttr); } addX86InterruptAttrs(FD, GV, CGM); @@ -5563,16 +5566,17 @@ auto *Fn = cast(GV); static const char *SignReturnAddrStr[] = {"none", "non-leaf", "all"}; - Fn->addFnAttr("sign-return-address", SignReturnAddrStr[static_cast(BPI.SignReturnAddr)]); + Fn->addFnAttr(llvm::SignReturnAddressAttr, + SignReturnAddrStr[static_cast(BPI.SignReturnAddr)]); if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) { - Fn->addFnAttr("sign-return-address-key", + Fn->addFnAttr(llvm::SignReturnAddressAttr, BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key" : "b_key"); } - Fn->addFnAttr("branch-target-enforcement", + Fn->addFnAttr(llvm::BranchTargetEnforcementAttr, BPI.BranchTargetEnforcement ? "true" : "false"); } @@ -6381,7 +6385,7 @@ llvm::Function *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); + Fn->addFnAttr(llvm::InterruptAttr, Kind); ARMABIInfo::ABIKind ABI = cast(getABIInfo()).getABIKind(); if (ABI == ARMABIInfo::APCS) @@ -7745,8 +7749,8 @@ if (GV->isDeclaration()) return; if (const FunctionDecl *FD = dyn_cast_or_null(D)) { - const auto *InterruptAttr = FD->getAttr(); - if (!InterruptAttr) + const auto *Interrupt_Attr = FD->getAttr(); + if (!Interrupt_Attr) return; // Handle 'interrupt' attribute: @@ -7757,7 +7761,8 @@ // Step 2: Add attributes goodness. F->addFnAttr(llvm::Attribute::NoInline); - F->addFnAttr("interrupt", llvm::utostr(InterruptAttr->getNumber())); + F->addFnAttr(llvm::InterruptAttr, + llvm::utostr(Interrupt_Attr->getNumber())); } } @@ -7805,26 +7810,28 @@ if (!FD) return; llvm::Function *Fn = cast(GV); - if (FD->hasAttr()) - Fn->addFnAttr("long-call"); - else if (FD->hasAttr()) - Fn->addFnAttr("short-call"); + if (FD->hasAttr()) { + Fn->addFnAttr(llvm::LongCallAttr); + } else if (FD->hasAttr()) { + Fn->addFnAttr(llvm::ShortCallAttr); + } // Other attributes do not have a meaning for declarations. if (GV->isDeclaration()) return; if (FD->hasAttr()) { - Fn->addFnAttr("mips16"); + Fn->addFnAttr(llvm::Mips16KAttr); } else if (FD->hasAttr()) { - Fn->addFnAttr("nomips16"); + Fn->addFnAttr(llvm::Nomips16Attr); } - if (FD->hasAttr()) - Fn->addFnAttr("micromips"); - else if (FD->hasAttr()) - Fn->addFnAttr("nomicromips"); + if (FD->hasAttr()) { + Fn->addFnAttr(llvm::MicromipsAttr); + } else if (FD->hasAttr()) { + Fn->addFnAttr(llvm::NoMicromipsAttr); + } const MipsInterruptAttr *Attr = FD->getAttr(); if (!Attr) @@ -7843,8 +7850,7 @@ case MipsInterruptAttr::hw5: Kind = "hw5"; break; } - Fn->addFnAttr("interrupt", Kind); - + Fn->addFnAttr(llvm::InterruptAttr, Kind); } bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, @@ -8277,11 +8283,13 @@ if (!FD) return; auto *Fn = cast(GV); - if (FD->getAttr()) - Fn->addFnAttr("interrupt"); + if (FD->getAttr()) { + Fn->addFnAttr(llvm::InterruptAttr); + } - if (FD->getAttr()) - Fn->addFnAttr("signal"); + if (FD->getAttr()) { + Fn->addFnAttr(llvm::SignalAttr); + } } }; } @@ -9206,12 +9214,13 @@ const bool IsHIPKernel = M.getLangOpts().HIP && FD->hasAttr(); if ((IsOpenCLKernel || IsHIPKernel) && - (M.getTriple().getOS() == llvm::Triple::AMDHSA)) - F->addFnAttr("amdgpu-implicitarg-num-bytes", "56"); - - if (IsHIPKernel) - F->addFnAttr("uniform-work-group-size", "true"); + (M.getTriple().getOS() == llvm::Triple::AMDHSA)) { + F->addFnAttr(llvm::AmdgpuImplicitargNumBytesAttr, "56"); + } + if (IsHIPKernel) { + F->addFnAttr(llvm::UniformWorkGroupSizeAttr, "true"); + } const auto *FlatWGS = FD->getAttr(); if (ReqdWGS || FlatWGS) { @@ -9232,7 +9241,7 @@ assert(Min <= Max && "Min must be less than or equal Max"); std::string AttrVal = llvm::utostr(Min) + "," + llvm::utostr(Max); - F->addFnAttr("amdgpu-flat-work-group-size", AttrVal); + F->addFnAttr(llvm::AmdgpuFlatWorkGroupSizeAttr, AttrVal); } else assert(Max == 0 && "Max must be zero"); } else if (IsOpenCLKernel || IsHIPKernel) { @@ -9244,7 +9253,7 @@ : M.getLangOpts().GPUMaxThreadsPerBlock; std::string AttrVal = std::string("1,") + llvm::utostr(DefaultMaxWorkGroupSize); - F->addFnAttr("amdgpu-flat-work-group-size", AttrVal); + F->addFnAttr(llvm::AmdgpuFlatWorkGroupSizeAttr, AttrVal); } if (const auto *Attr = FD->getAttr()) { @@ -9261,7 +9270,7 @@ std::string AttrVal = llvm::utostr(Min); if (Max != 0) AttrVal = AttrVal + "," + llvm::utostr(Max); - F->addFnAttr("amdgpu-waves-per-eu", AttrVal); + F->addFnAttr(llvm::AmdgpuWavesPerEuAttr, AttrVal); } else assert(Max == 0 && "Max must be zero"); } @@ -9269,22 +9278,26 @@ if (const auto *Attr = FD->getAttr()) { unsigned NumSGPR = Attr->getNumSGPR(); - if (NumSGPR != 0) - F->addFnAttr("amdgpu-num-sgpr", llvm::utostr(NumSGPR)); + if (NumSGPR != 0) { + F->addFnAttr(llvm::AmdgpuNumSgprAttr, llvm::utostr(NumSGPR)); + } } if (const auto *Attr = FD->getAttr()) { uint32_t NumVGPR = Attr->getNumVGPR(); - if (NumVGPR != 0) - F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR)); + if (NumVGPR != 0) { + F->addFnAttr(llvm::AmdgpuNumVgprAttr, llvm::utostr(NumVGPR)); + } } - if (M.getContext().getTargetInfo().allowAMDGPUUnsafeFPAtomics()) - F->addFnAttr("amdgpu-unsafe-fp-atomics", "true"); + if (M.getContext().getTargetInfo().allowAMDGPUUnsafeFPAtomics()) { + F->addFnAttr(llvm::AmdgpuUnsafeFpAtomicsAttr, "true"); + } - if (!getABIInfo().getCodeGenOpts().EmitIEEENaNCompliantInsts) - F->addFnAttr("amdgpu-ieee", "false"); + if (!getABIInfo().getCodeGenOpts().EmitIEEENaNCompliantInsts) { + F->addFnAttr(llvm::AmdgpuIeeeAttr, "false"); + } } unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const { @@ -11016,7 +11029,7 @@ auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); + Fn->addFnAttr(llvm::InterruptAttr, Kind); } }; } // namespace @@ -11367,7 +11380,7 @@ auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false); auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name, &CGF.CGM.getModule()); - F->addFnAttr("enqueued-block"); + F->addFnAttr(llvm::EnqueuedBlockAttr); auto IP = CGF.Builder.saveIP(); auto *BB = llvm::BasicBlock::Create(C, "entry", F); Builder.SetInsertPoint(BB); diff --git a/llvm/include/llvm/Analysis/SyncDependenceAnalysis.h b/llvm/include/llvm/Analysis/SyncDependenceAnalysis.h --- a/llvm/include/llvm/Analysis/SyncDependenceAnalysis.h +++ b/llvm/include/llvm/Analysis/SyncDependenceAnalysis.h @@ -20,6 +20,7 @@ #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Analysis/LoopInfo.h" +#include #include #include diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h --- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h +++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h @@ -235,7 +235,7 @@ : Impl(&Impl), OverrideAsUnavailable(NumLibFuncs) { if (!F) return; - if ((*F)->hasFnAttribute("no-builtins")) + if ((*F)->hasFnAttribute(NoBuiltinsAttr)) disableAllFunctions(); else { // Disable individual libc/libm calls in TargetLibraryInfo. @@ -244,7 +244,7 @@ for (const Attribute &Attr : FnAttrs) { if (!Attr.isStringAttribute()) continue; - auto AttrStr = Attr.getKindAsString(); + auto AttrStr = Attr.getKindAsKey().value(); if (!AttrStr.consume_front("no-builtin-")) continue; if (getLibFunc(AttrStr, LF)) diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -695,19 +695,19 @@ bool areInlineCompatible(const Function *Caller, const Function *Callee) const { - return (Caller->getFnAttribute("target-cpu") == - Callee->getFnAttribute("target-cpu")) && - (Caller->getFnAttribute("target-features") == - Callee->getFnAttribute("target-features")); + return (Caller->getFnAttribute(TargetCPUAttr) == + Callee->getFnAttribute(TargetCPUAttr)) && + (Caller->getFnAttribute(TargetFeaturesAttr) == + Callee->getFnAttribute(TargetFeaturesAttr)); } bool areFunctionArgsABICompatible(const Function *Caller, const Function *Callee, SmallPtrSetImpl &Args) const { - return (Caller->getFnAttribute("target-cpu") == - Callee->getFnAttribute("target-cpu")) && - (Caller->getFnAttribute("target-features") == - Callee->getFnAttribute("target-features")); + return (Caller->getFnAttribute(TargetCPUAttr) == + Callee->getFnAttribute(TargetCPUAttr)) && + (Caller->getFnAttribute(TargetFeaturesAttr) == + Callee->getFnAttribute(TargetFeaturesAttr)); } bool isIndexedLoadLegal(TTI::MemIndexedMode Mode, Type *Ty, diff --git a/llvm/include/llvm/Analysis/VectorUtils.h b/llvm/include/llvm/Analysis/VectorUtils.h --- a/llvm/include/llvm/Analysis/VectorUtils.h +++ b/llvm/include/llvm/Analysis/VectorUtils.h @@ -189,9 +189,6 @@ /// Retrieve the `VFParamKind` from a string token. VFParamKind getVFParamKindFromString(const StringRef Token); -// Name of the attribute where the variant mappings are stored. -static constexpr char const *MappingsAttrName = "vector-function-abi-variant"; - /// Populates a set of strings representing the Vector Function ABI variants /// associated to the CallInst CI. If the CI does not contain the /// vector-function-abi-variant attribute, we return without populating diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -161,7 +161,7 @@ std::vector getFeatureList(); -void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val); +void renderBoolStringAttr(AttrBuilder &B, AttributeKey Name, bool Val); /// Set function attributes of function \p F based on CPU, Features, and command /// line flags. diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -1166,7 +1166,7 @@ /// Return true if lowering to a jump table is allowed. virtual bool areJTsAllowed(const Function *Fn) const { - if (Fn->getFnAttribute("no-jump-tables").getValueAsBool()) + if (Fn->getFnAttribute(NoJumpTablesAttr).getValueAsBool()) return false; return isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) || diff --git a/llvm/include/llvm/IR/Assumptions.h b/llvm/include/llvm/IR/Assumptions.h --- a/llvm/include/llvm/IR/Assumptions.h +++ b/llvm/include/llvm/IR/Assumptions.h @@ -18,15 +18,13 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" +#include "llvm/IR/Attributes.h" namespace llvm { class Function; class CallBase; -/// The key we use for assumption attributes. -constexpr StringRef AssumptionAttrKey = "llvm.assume"; - /// A set of known assumption strings that are accepted without warning and /// which can be recommended as typo correction. extern StringSet<> KnownAssumptionStrings; diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -17,6 +17,7 @@ #include "llvm-c/Types.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" @@ -29,7 +30,58 @@ #include #include #include +#include #include +namespace llvm { +constexpr uint32_t dj2(const char *str) { + uint32_t hash = 5381; + int c = 0; + + while ((c = *str++)) + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + + return hash; +} + +class AttributeKey { + const char *value_; + uint32_t hash_; + uint32_t size_; + + AttributeKey(StringRef s) + : value_(strndup(s.data(), s.size())), hash_(dj2(s.data())), + size_(s.size()) {} + +public: + static AttributeKey Create(StringRef s); + + template + explicit constexpr AttributeKey(const char (&s)[N]) + : value_(s), hash_(dj2(s)), size_(N - 1) { + static_assert(N - 1 < std::numeric_limits::max(), + "large enough size storage"); + } + constexpr AttributeKey() : AttributeKey("") {} + StringRef value() const { return StringRef(value_, size_); } + uint32_t hash() const { return hash_; } + uint32_t size() const { return size_; } + bool operator==(AttributeKey const &other) const { + return size_ == other.size_ && strncmp(value_, other.value_, size_) == 0; + } + bool operator!=(AttributeKey const &other) const { + return !((*this) == other); + } + bool operator<(AttributeKey const &other) const { + return strcmp(value_, other.value_) < 0; + } +}; +} // namespace llvm + +template <> struct std::hash { + std::size_t operator()(llvm::AttributeKey const &s) const noexcept { + return s.hash(); + } +}; namespace llvm { @@ -109,7 +161,7 @@ /// Return a uniquified Attribute object. static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0); - static Attribute get(LLVMContext &Context, StringRef Kind, + static Attribute get(LLVMContext &Context, AttributeKey Kind, StringRef Val = StringRef()); static Attribute get(LLVMContext &Context, AttrKind Kind, Type *Ty); @@ -171,7 +223,7 @@ bool hasAttribute(AttrKind Val) const; /// Return true if the target-dependent attribute is present. - bool hasAttribute(StringRef Val) const; + bool hasAttribute(AttributeKey Val) const; /// Return the attribute's kind as an enum (Attribute::AttrKind). This /// requires the attribute to be an enum, integer, or type attribute. @@ -187,7 +239,7 @@ /// Return the attribute's kind as a string. This requires the /// attribute to be a string attribute. - StringRef getKindAsString() const; + AttributeKey getKindAsKey() const; /// Return the attribute's value as a string. This requires the /// attribute to be a string attribute. @@ -297,7 +349,7 @@ /// Add a target-dependent attribute. Returns a new set because attribute sets /// are immutable. - LLVM_NODISCARD AttributeSet addAttribute(LLVMContext &C, StringRef Kind, + LLVM_NODISCARD AttributeSet addAttribute(LLVMContext &C, AttributeKey Kind, StringRef Value = StringRef()) const; /// Add attributes to the attribute set. Returns a new set because attribute @@ -313,7 +365,7 @@ /// Remove the specified attribute from this set. Returns a new set because /// attribute sets are immutable. LLVM_NODISCARD AttributeSet removeAttribute(LLVMContext &C, - StringRef Kind) const; + AttributeKey Kind) const; /// Remove the specified attributes from this set. Returns a new set because /// attribute sets are immutable. @@ -330,13 +382,13 @@ bool hasAttribute(Attribute::AttrKind Kind) const; /// Return true if the attribute exists in this set. - bool hasAttribute(StringRef Kind) const; + bool hasAttribute(AttributeKey Kind) const; /// Return the attribute object. Attribute getAttribute(Attribute::AttrKind Kind) const; /// Return the target-dependent attribute object. - Attribute getAttribute(StringRef Kind) const; + Attribute getAttribute(AttributeKey Kind) const; MaybeAlign getAlignment() const; MaybeAlign getStackAlignment() const; @@ -451,7 +503,7 @@ ArrayRef Kinds, ArrayRef Values); static AttributeList get(LLVMContext &C, unsigned Index, - ArrayRef Kind); + ArrayRef Kind); static AttributeList get(LLVMContext &C, unsigned Index, const AttrBuilder &B); @@ -464,7 +516,7 @@ /// Add an attribute to the attribute set at the given index. /// Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList - addAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind, + addAttributeAtIndex(LLVMContext &C, unsigned Index, AttributeKey Kind, StringRef Value = StringRef()) const; /// Add an attribute to the attribute set at the given index. @@ -496,7 +548,7 @@ /// Add a function attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList addFnAttribute( - LLVMContext &C, StringRef Kind, StringRef Value = StringRef()) const { + LLVMContext &C, AttributeKey Kind, StringRef Value = StringRef()) const { return addAttributeAtIndex(C, FunctionIndex, Kind, Value); } @@ -538,7 +590,7 @@ /// Add an argument attribute to the list. Returns a new list because /// attribute lists are immutable. LLVM_NODISCARD AttributeList - addParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind, + addParamAttribute(LLVMContext &C, unsigned ArgNo, AttributeKey Kind, StringRef Value = StringRef()) const { return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind, Value); } @@ -566,9 +618,9 @@ /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeAttributeAtIndex(LLVMContext &C, unsigned Index, - StringRef Kind) const; + AttributeKey Kind) const; LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, - StringRef Kind) const { + AttributeKey Kind) const { return removeAttributeAtIndex(C, Index, Kind); } @@ -592,7 +644,7 @@ /// 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 { + AttributeKey Kind) const { return removeAttributeAtIndex(C, FunctionIndex, Kind); } @@ -619,7 +671,7 @@ /// 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 { + AttributeKey Kind) const { return removeAttributeAtIndex(C, ReturnIndex, Kind); } @@ -641,7 +693,7 @@ /// attribute list. Returns a new list because attribute lists are immutable. LLVM_NODISCARD AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, - StringRef Kind) const { + AttributeKey Kind) const { return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind); } @@ -713,7 +765,7 @@ bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const; /// Return true if the attribute exists at the given index. - bool hasAttributeAtIndex(unsigned Index, StringRef Kind) const; + bool hasAttributeAtIndex(unsigned Index, AttributeKey Kind) const; /// Return true if attribute exists at the given index. bool hasAttributesAtIndex(unsigned Index) const; @@ -724,7 +776,7 @@ } /// Return true if the attribute exists for the given argument - bool hasParamAttr(unsigned ArgNo, StringRef Kind) const { + bool hasParamAttr(unsigned ArgNo, AttributeKey Kind) const { return hasAttributeAtIndex(ArgNo + FirstArgIndex, Kind); } @@ -739,7 +791,7 @@ } /// Return true if the attribute exists for the return value. - bool hasRetAttr(StringRef Kind) const { + bool hasRetAttr(AttributeKey Kind) const { return hasAttributeAtIndex(ReturnIndex, Kind); } @@ -750,7 +802,7 @@ bool hasFnAttr(Attribute::AttrKind Kind) const; /// Return true if the attribute exists for the function. - bool hasFnAttr(StringRef Kind) const; + bool hasFnAttr(AttributeKey Kind) const; /// Return true the attributes exist for the function. bool hasFnAttrs() const { return hasAttributesAtIndex(FunctionIndex); } @@ -765,7 +817,7 @@ Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const; /// Return the attribute object that exists at the given index. - Attribute getAttributeAtIndex(unsigned Index, StringRef Kind) const; + Attribute getAttributeAtIndex(unsigned Index, AttributeKey Kind) const; /// Return the attribute object that exists at the arg index. Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const { @@ -773,7 +825,7 @@ } /// Return the attribute object that exists at the given index. - Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const { + Attribute getParamAttr(unsigned ArgNo, AttributeKey Kind) const { return getAttributeAtIndex(ArgNo + FirstArgIndex, Kind); } @@ -783,7 +835,7 @@ } /// Return the attribute object that exists for the function. - Attribute getFnAttr(StringRef Kind) const { + Attribute getFnAttr(AttributeKey Kind) const { return getAttributeAtIndex(FunctionIndex, Kind); } @@ -922,6 +974,164 @@ } }; +constexpr llvm::AttributeKey + AmdgpuFlatWorkGroupSizeAttr("amdgpu-flat-work-group-size"); +constexpr llvm::AttributeKey AmdgpuIeeeAttr("amdgpu-ieee"); +constexpr llvm::AttributeKey + AmdgpuImplicitargNumBytesAttr("amdgpu-implicitarg-num-bytes"); +constexpr llvm::AttributeKey AmdgpuNumSgprAttr("amdgpu-num-sgpr"); +constexpr llvm::AttributeKey AmdgpuNumVgprAttr("amdgpu-num-vgpr"); +constexpr llvm::AttributeKey + AmdgpuUnsafeFpAtomicsAttr("amdgpu-unsafe-fp-atomics"); +constexpr llvm::AttributeKey AmdgpuWavesPerEuAttr("amdgpu-waves-per-eu"); +constexpr llvm::AttributeKey ApproxFuncFPMathAttr("approx-func-fp-math"); +constexpr llvm::AttributeKey BackchainAttr("backchain"); +constexpr llvm::AttributeKey + BranchTargetEnforcementAttr("branch-target-enforcement"); +constexpr llvm::AttributeKey BssSectionAttr("bss-section"); +constexpr llvm::AttributeKey CallThresholdBonus("call-threshold-bonus"); +constexpr llvm::AttributeKey CallInlineCost("call-inline-cost"); +constexpr llvm::AttributeKey + CfiCanonicalJumpTablesAttr("cfi-canonical-jump-table"); +constexpr llvm::AttributeKey CmseNonsecureEntryAttr("cmse_nonsecure_entry"); +constexpr llvm::AttributeKey CoroutinePresplitAttr("coroutine.presplit"); +constexpr llvm::AttributeKey DataSectionAttr("data-section"); +constexpr llvm::AttributeKey DenormalFPMathAttr("denormal-fp-math"); +constexpr llvm::AttributeKey DenormalFPMathf32Attr("denormal-fp-math-f32"); +constexpr llvm::AttributeKey DeoptLoweringAttr("deopt-lowering"); +constexpr llvm::AttributeKey DeviceInitAttr("device-init"); +constexpr llvm::AttributeKey DisableTailCallsAttr("disable-tail-calls"); +constexpr llvm::AttributeKey DontcallErrorAttr("dontcall-error"); +constexpr llvm::AttributeKey DontcallWarnAttr("dontcall-warn"); +constexpr llvm::AttributeKey EnqueuedBlockAttr("enqueued-block"); +constexpr llvm::AttributeKey FentryCallAttr("fentry-call"); +constexpr llvm::AttributeKey FramePointerAttr("frame-pointer"); +constexpr llvm::AttributeKey FunctionInlineCost("function-inline-cost"); +constexpr llvm::AttributeKey + FunctionInlineThreshold("function-inline-threshold"); +constexpr llvm::AttributeKey FunctionInstrumentAttr("function-instrument"); +constexpr llvm::AttributeKey GcLeafFunctionAttr("gc-leaf-function"); +constexpr llvm::AttributeKey GuardNocfAttr("guard_nocf"); +constexpr llvm::AttributeKey ImplicitSectionNameAttr("implicit-section-name"); +constexpr llvm::AttributeKey IndirectTLSSegRefsAttr("indirect-tls-seg-refs"); +constexpr llvm::AttributeKey InlineRemarkAttr("inline-remark"); +constexpr llvm::AttributeKey + InstrumentFunctionEntryAttr("instrument-function-entry"); +constexpr llvm::AttributeKey + InstrumentFunctionEntryInlinedAttr("instrument-function-entry-inlined"); +constexpr llvm::AttributeKey + InstrumentFunctionExitAttr("instrument-function-exit"); +constexpr llvm::AttributeKey + InstrumentFunctionExitInlinedAttr("instrument-function-exit-inlined"); +constexpr llvm::AttributeKey InterruptAttr("interrupt"); +constexpr llvm::AttributeKey LLVMAssumeAttr("llvm.assume"); +constexpr llvm::AttributeKey LessPreciseFPMADAttr("less-precise-fpmad"); +constexpr llvm::AttributeKey LongCallAttr("long-call"); +constexpr llvm::AttributeKey MicromipsAttr("micromips"); +constexpr llvm::AttributeKey MinLegalVectorWidthAttr("min-legal-vector-width"); +constexpr llvm::AttributeKey Mips16KAttr("mips16"); +constexpr llvm::AttributeKey MnopMcountAttr("mnop-mcount"); +constexpr llvm::AttributeKey MrecordMcountAttr("mrecord-mcount"); +constexpr llvm::AttributeKey MustProgressAttr("must-progress"); +constexpr llvm::AttributeKey NoBuiltinsAttr("no-builtins"); +constexpr llvm::AttributeKey + NoCalleeSavedRegistersAttr("no_callee_saved_registers"); +constexpr llvm::AttributeKey + NoCallerSavedRegistersAttr("no_caller_saved_registers"); +constexpr llvm::AttributeKey + NoCaptureMaybeReturned("no-capture-maybe-returned"); +constexpr llvm::AttributeKey NoFramePointerElimAttr("no-frame-pointer-elim"); +constexpr llvm::AttributeKey + NoFramePointerElimNonLeafAttr("no-frame-pointer-elim-non-leaf"); +constexpr llvm::AttributeKey NoImplicitFloatAttr("no-implicit-float"); +constexpr llvm::AttributeKey NoInfsFPMathAttr("no-infs-fp-math"); +constexpr llvm::AttributeKey NoInlineLineTablesAttr("no-inline-line-tables"); +constexpr llvm::AttributeKey NoJumpTablesAttr("no-jump-tables"); +constexpr llvm::AttributeKey NoOpenmp("no_openmp"); +constexpr llvm::AttributeKey NoOpenmpRoutines("no_openmp_routines"); +constexpr llvm::AttributeKey NoMicromipsAttr("no-micromips"); +constexpr llvm::AttributeKey NoNansFPMathAttr("no-nans-fp-math"); +constexpr llvm::AttributeKey NoProfileAttr("no-profile"); +constexpr llvm::AttributeKey NoPrototypeAttr("no-prototype"); +constexpr llvm::AttributeKey NoRealignStack("no-realign-stack"); +constexpr llvm::AttributeKey NoSignedZerosFPMathAttr("no-signed-zeros-fp-math"); +constexpr llvm::AttributeKey NoStackArgProbeAttr("no-stack-arg-probe"); +constexpr llvm::AttributeKey NoTrappingMathAttr("no-trapping-math"); +constexpr llvm::AttributeKey NomicromipsAttr("nomicromips"); +constexpr llvm::AttributeKey Nomips16Attr("nomips16"); +constexpr llvm::AttributeKey NullPointerIsValidAttr("null-pointer-is-valid"); +constexpr llvm::AttributeKey ObjcArcInertAttr("objc_arc_inert"); +constexpr llvm::AttributeKey OmpTargetNumTeamsAttr("omp_target_num_teams"); +constexpr llvm::AttributeKey + OmpTargetThreadLimitAttr("omp_target_thread_limit"); +constexpr llvm::AttributeKey PackedStackAttr("packed-stack"); +constexpr llvm::AttributeKey PatchableFunctionAttr("patchable-function"); +constexpr llvm::AttributeKey + PatchableFunctionEntryAttr("patchable-function-entry"); +constexpr llvm::AttributeKey + PatchableFunctionPrefixAttr("patchable-function-prefix"); +constexpr llvm::AttributeKey PreferVectorWidthAttr("prefer-vector-width"); +constexpr llvm::AttributeKey ProbeStackAttr("probe-stack"); +constexpr llvm::AttributeKey + ProfileSampleAccurateAttr("profile-sample-accurate"); +constexpr llvm::AttributeKey ReciprocalEstimatesAttr("reciprocal-estimates"); +constexpr llvm::AttributeKey RelroSectionAttr("relro-section"); +constexpr llvm::AttributeKey RodataSectionAttr("rodata-section"); +constexpr llvm::AttributeKey SafeStackAttr("safe-stack"); +constexpr llvm::AttributeKey SafesehAttr("safeseh"); +constexpr llvm::AttributeKey SampleProfileSuffixElisionPolicyAttr( + "sample-profile-suffix-elision-policy"); +constexpr llvm::AttributeKey SanitizeAddressAttr("sanitize-address"); +constexpr llvm::AttributeKey SanitizeHWAddressAttr("sanitize-hw-address"); +constexpr llvm::AttributeKey SanitizeMemTagAttr("sanitize-mem-tag"); +constexpr llvm::AttributeKey SanitizeMemoryAttr("sanitize-memory"); +constexpr llvm::AttributeKey SanitizeThreadAttr("sanitize-thread"); +constexpr llvm::AttributeKey SanitizeThreadNoCheckingAtRunTimeAttr( + "sanitize_thread_no_checking_at_run_time"); +constexpr llvm::AttributeKey ShadowCallStackAttr("shadow-call-stack"); +constexpr llvm::AttributeKey ShortCallAttr("short-call"); +constexpr llvm::AttributeKey SignReturnAddressAttr("sign-return-address"); +constexpr llvm::AttributeKey + SignReturnAddressKeyAttr("sign-return-address-key"); +constexpr llvm::AttributeKey SignalAttr("signal"); +constexpr llvm::AttributeKey + SpeculativeLoadHardeningAttr("speculative-load-hardening"); +constexpr llvm::AttributeKey SplitStackAttr("split-stack"); +constexpr llvm::AttributeKey StackProbeSizeAttr("stack-probe-size"); +constexpr llvm::AttributeKey + StackProtectorBufferSizeAttr("stack-protector-buffer-size"); +constexpr llvm::AttributeKey StackrealignAttr("stackrealign"); +constexpr llvm::AttributeKey StatepointIdAttr("statepoint-id"); +constexpr llvm::AttributeKey + StatepointNumPatchBytesAttr("statepoint-num-patch-bytes"); +constexpr llvm::AttributeKey + StrictFloatCastOverflowAttr("strict-float-cast-overflow"); +constexpr llvm::AttributeKey StrictfpAttr("strictfp"); +constexpr llvm::AttributeKey TargetCPUAttr("target-cpu"); +constexpr llvm::AttributeKey TargetFeaturesAttr("target-features"); +constexpr llvm::AttributeKey ThinltoInternalizeAttr("thinlto-internalize"); +constexpr llvm::AttributeKey ThunkAttr("thunk"); +constexpr llvm::AttributeKey TocDataAttr("toc-data"); +constexpr llvm::AttributeKey TrapFuncNameAttr("trap-func-name"); +constexpr llvm::AttributeKey TuneCPUAttr("tune-cpu"); +constexpr llvm::AttributeKey + UniformWorkGroupSizeAttr("uniform-work-group-size"); +constexpr llvm::AttributeKey UnsafeFPMathAttr("unsafe-fp-math"); +constexpr llvm::AttributeKey UseSampleProfileAttr("use-sample-profile"); +constexpr llvm::AttributeKey UseSoftFloatAttr("use-soft-float"); +constexpr llvm::AttributeKey + VectorFunctionAbiVariantAttr("vector-function-abi-variant"); +constexpr llvm::AttributeKey WarnStackSizeAttr("warn-stack-size"); +constexpr llvm::AttributeKey WasmExportNameAttr("wasm-export-name"); +constexpr llvm::AttributeKey WasmImportModuleAttr("wasm-import-module"); +constexpr llvm::AttributeKey WasmImportNameAttr("wasm-import-name"); +constexpr llvm::AttributeKey XrayIgnoreLoopsAttr("xray-ignore-loops"); +constexpr llvm::AttributeKey + XrayInstructionThresholdAttr("xray-instruction-threshold"); +constexpr llvm::AttributeKey XrayLogArgsAttr("xray-log-args"); +constexpr llvm::AttributeKey XraySkipEntryAttr("xray-skip-entry"); +constexpr llvm::AttributeKey XraySkipExitAttr("xray-skip-exit"); + //===----------------------------------------------------------------------===// /// \class /// This class is used in conjunction with the Attribute::get method to @@ -930,7 +1140,7 @@ /// equality, presence of attributes, etc. class AttrBuilder { std::bitset Attrs; - std::map, SmallString<32>, std::less<>> TargetDepAttrs; + std::map> TargetDepAttrs; std::array IntAttrs = {}; std::array TypeAttrs = {}; @@ -963,7 +1173,7 @@ AttrBuilder &addAttribute(Attribute A); /// Add the target-dependent attribute to the builder. - AttrBuilder &addAttribute(StringRef A, StringRef V = StringRef()); + AttrBuilder &addAttribute(AttributeKey A, StringRef V = StringRef()); /// Remove an attribute from the builder. AttrBuilder &removeAttribute(Attribute::AttrKind Val); @@ -972,7 +1182,7 @@ AttrBuilder &removeAttributes(AttributeList A, uint64_t WithoutIndex); /// Remove the target-dependent attribute to the builder. - AttrBuilder &removeAttribute(StringRef A); + AttrBuilder &removeAttribute(AttributeKey A); /// Add the attributes from the builder. AttrBuilder &merge(const AttrBuilder &B); @@ -992,7 +1202,7 @@ /// Return true if the builder has the specified target-dependent /// attribute. - bool contains(StringRef A) const; + bool contains(AttributeKey A) const; /// Return true if the builder has IR-level attributes. bool hasAttributes() const; diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -311,15 +311,15 @@ string CompatFunc = F; } -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; class MergeRule { // The name of the function called to merge the attributes of the caller and @@ -330,18 +330,18 @@ string MergeFunc = F; } -def : MergeRule<"setAND">; -def : MergeRule<"setAND">; -def : MergeRule<"setAND">; -def : MergeRule<"setAND">; -def : MergeRule<"setAND">; -def : MergeRule<"setOR">; -def : MergeRule<"setOR">; -def : MergeRule<"setOR">; -def : MergeRule<"setOR">; +def : MergeRule<"setAND">; +def : MergeRule<"setAND">; +def : MergeRule<"setAND">; +def : MergeRule<"setAND">; +def : MergeRule<"setAND">; +def : MergeRule<"setOR">; +def : MergeRule<"setOR">; +def : MergeRule<"setOR">; +def : MergeRule<"setOR">; def : MergeRule<"adjustCallerSSPLevel">; def : MergeRule<"adjustCallerStackProbes">; def : MergeRule<"adjustCallerStackProbeSize">; def : MergeRule<"adjustMinLegalVectorWidth">; def : MergeRule<"adjustNullPointerValidAttr">; -def : MergeRule<"setAND">; +def : MergeRule<"setAND">; diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -337,7 +337,7 @@ void addFnAttr(Attribute::AttrKind Kind); /// Add function attributes to this function. - void addFnAttr(StringRef Kind, StringRef Val = StringRef()); + void addFnAttr(AttributeKey Kind, StringRef Val = StringRef()); /// Add function attributes to this function. void addFnAttr(Attribute Attr); @@ -367,13 +367,13 @@ void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind); /// removes the attribute from the list of attributes. - void removeAttributeAtIndex(unsigned i, StringRef Kind); + void removeAttributeAtIndex(unsigned i, AttributeKey Kind); /// Remove function attributes from this function. void removeFnAttr(Attribute::AttrKind Kind); /// Remove function attribute from this function. - void removeFnAttr(StringRef Kind); + void removeFnAttr(AttributeKey Kind); void removeFnAttrs(const AttrBuilder &Attrs); @@ -381,7 +381,7 @@ void removeRetAttr(Attribute::AttrKind Kind); /// removes the attribute from the return value list of attributes. - void removeRetAttr(StringRef Kind); + void removeRetAttr(AttributeKey Kind); /// removes the attributes from the return value list of attributes. void removeRetAttrs(const AttrBuilder &Attrs); @@ -390,7 +390,7 @@ void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind); /// removes the attribute from the list of attributes. - void removeParamAttr(unsigned ArgNo, StringRef Kind); + void removeParamAttr(unsigned ArgNo, AttributeKey Kind); /// removes the attribute from the list of attributes. void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs); @@ -399,7 +399,7 @@ bool hasFnAttribute(Attribute::AttrKind Kind) const; /// Return true if the function has the attribute. - bool hasFnAttribute(StringRef Kind) const; + bool hasFnAttribute(AttributeKey Kind) const; /// check if an attribute is in the list of attributes for the return value. bool hasRetAttribute(Attribute::AttrKind Kind) const; @@ -411,13 +411,13 @@ Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const; /// gets the attribute from the list of attributes. - Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const; + Attribute getAttributeAtIndex(unsigned i, AttributeKey Kind) const; /// Return the attribute for the given attribute kind. Attribute getFnAttribute(Attribute::AttrKind Kind) const; /// Return the attribute for the given attribute kind. - Attribute getFnAttribute(StringRef Kind) const; + Attribute getFnAttribute(AttributeKey Kind) const; /// gets the specified attribute from the list of attributes. Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const; @@ -500,7 +500,7 @@ /// A function will have the "coroutine.presplit" attribute if it's /// a coroutine and has not gone through full CoroSplit pass. bool isPresplitCoroutine() const { - return hasFnAttribute("coroutine.presplit"); + return hasFnAttribute(CoroutinePresplitAttr); } /// Determine if the function does not access memory. diff --git a/llvm/include/llvm/IR/GlobalVariable.h b/llvm/include/llvm/IR/GlobalVariable.h --- a/llvm/include/llvm/IR/GlobalVariable.h +++ b/llvm/include/llvm/IR/GlobalVariable.h @@ -190,7 +190,7 @@ } /// Add attribute to this global. - void addAttribute(StringRef Kind, StringRef Val = StringRef()) { + void addAttribute(AttributeKey Kind, StringRef Val = StringRef()) { Attrs = Attrs.addAttribute(getContext(), Kind, Val); } @@ -200,7 +200,7 @@ } /// Return true if the attribute exists. - bool hasAttribute(StringRef Kind) const { + bool hasAttribute(AttributeKey Kind) const { return Attrs.hasAttribute(Kind); } @@ -215,7 +215,7 @@ } /// Return the attribute object. - Attribute getAttribute(StringRef Kind) const { + Attribute getAttribute(AttributeKey Kind) const { return Attrs.getAttribute(Kind); } @@ -241,10 +241,10 @@ /// Check if section name is present bool hasImplicitSection() const { - return getAttributes().hasAttribute("bss-section") || - getAttributes().hasAttribute("data-section") || - getAttributes().hasAttribute("relro-section") || - getAttributes().hasAttribute("rodata-section"); + return getAttributes().hasAttribute(BssSectionAttr) || + getAttributes().hasAttribute(DataSectionAttr) || + getAttributes().hasAttribute(RelroSectionAttr) || + getAttributes().hasAttribute(RodataSectionAttr); } // Methods for support type inquiry through isa, cast, and dyn_cast: diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -1488,7 +1488,7 @@ /// Determine whether this call has the given attribute. If it does not /// then determine if the called function has the attribute, but only if /// the attribute is allowed for the call. - bool hasFnAttr(StringRef Kind) const { return hasFnAttrImpl(Kind); } + bool hasFnAttr(AttributeKey Kind) const { return hasFnAttrImpl(Kind); } // TODO: remove non-AtIndex versions of these methods. /// adds the attribute to the list of attributes. @@ -1539,7 +1539,7 @@ } /// removes the attribute from the list of attributes. - void removeAttributeAtIndex(unsigned i, StringRef Kind) { + void removeAttributeAtIndex(unsigned i, AttributeKey Kind) { Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind); } @@ -1570,7 +1570,7 @@ } /// Removes the attribute from the given argument - void removeParamAttr(unsigned ArgNo, StringRef Kind) { + void removeParamAttr(unsigned ArgNo, AttributeKey Kind) { assert(ArgNo < arg_size() && "Out of bounds"); Attrs = Attrs.removeParamAttribute(getContext(), ArgNo, Kind); } @@ -1595,7 +1595,7 @@ return hasRetAttrImpl(Kind); } /// Determine whether the return value has the given attribute. - bool hasRetAttr(StringRef Kind) const { return hasRetAttrImpl(Kind); } + bool hasRetAttr(AttributeKey Kind) const { return hasRetAttrImpl(Kind); } /// Determine whether the argument or parameter has the given attribute. bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const; @@ -1606,12 +1606,12 @@ } /// Get the attribute of a given kind at a position. - Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const { + Attribute getAttributeAtIndex(unsigned i, AttributeKey Kind) const { return getAttributes().getAttributeAtIndex(i, Kind); } /// Get the attribute of a given kind for the function. - Attribute getFnAttr(StringRef Kind) const { + Attribute getFnAttr(AttributeKey Kind) const { return getAttributes().getFnAttr(Kind); } @@ -1627,7 +1627,7 @@ } /// Get the attribute of a given kind from a given arg - Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const { + Attribute getParamAttr(unsigned ArgNo, AttributeKey Kind) const { assert(ArgNo < arg_size() && "Out of bounds"); return getAttributes().getParamAttr(ArgNo, Kind); } @@ -2086,7 +2086,7 @@ /// Is the function attribute S disallowed by some operand bundle on /// this operand bundle user? - bool isFnAttrDisallowedByOpBundle(StringRef S) const { + bool isFnAttrDisallowedByOpBundle(AttributeKey S) const { // Operand bundles only possibly disallow readnone, readonly and argmemonly // attributes. All String attributes are fine. return false; @@ -2271,7 +2271,7 @@ private: bool hasFnAttrOnCalledFunction(Attribute::AttrKind Kind) const; - bool hasFnAttrOnCalledFunction(StringRef Kind) const; + bool hasFnAttrOnCalledFunction(AttributeKey Kind) const; template bool hasFnAttrImpl(AttrKind Kind) const { if (Attrs.hasFnAttr(Kind)) @@ -2286,7 +2286,7 @@ } /// Determine whether the return value has the given attribute. Supports - /// Attribute::AttrKind and StringRef as \p AttrKind types. + /// Attribute::AttrKind and AttributeKey as \p AttrKind types. template bool hasRetAttrImpl(AttrKind Kind) const { if (Attrs.hasRetAttr(Kind)) return true; diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -942,8 +942,8 @@ /// Return the canonical name for a function, taking into account /// suffix elision policy attributes. static StringRef getCanonicalFnName(const Function &F) { - auto AttrName = "sample-profile-suffix-elision-policy"; - auto Attr = F.getFnAttribute(AttrName).getValueAsString(); + auto Attr = F.getFnAttribute(SampleProfileSuffixElisionPolicyAttr) + .getValueAsString(); return getCanonicalFnName(F.getName(), Attr); } diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -735,10 +735,9 @@ BasicBlock *Header = TheLoop->getHeader(); Function &F = *Header->getParent(); FastMathFlags FMF; - FMF.setNoNaNs( - F.getFnAttribute("no-nans-fp-math").getValueAsBool()); + FMF.setNoNaNs(F.getFnAttribute(NoNansFPMathAttr).getValueAsBool()); FMF.setNoSignedZeros( - F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool()); + F.getFnAttribute(NoSignedZerosFPMathAttr).getValueAsBool()); if (AddReductionVar(Phi, RecurKind::Add, TheLoop, FMF, RedDes, DB, AC, DT)) { LLVM_DEBUG(dbgs() << "Found an ADD reduction PHI." << *Phi << "\n"); diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp --- a/llvm/lib/Analysis/InlineAdvisor.cpp +++ b/llvm/lib/Analysis/InlineAdvisor.cpp @@ -348,7 +348,7 @@ if (!InlineRemarkAttribute) return; - Attribute Attr = Attribute::get(CB.getContext(), "inline-remark", Message); + Attribute Attr = Attribute::get(CB.getContext(), InlineRemarkAttr, Message); CB.addFnAttr(Attr); } diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -138,7 +138,7 @@ /// This function behaves more like CallBase::hasFnAttr: when it looks for the /// requested attribute, it check both the call instruction and the called /// function (if it's available and operand bundles don't prohibit that). -Attribute getFnAttr(CallBase &CB, StringRef AttrKind) { +Attribute getFnAttr(CallBase &CB, AttributeKey AttrKind) { Attribute CallAttr = CB.getFnAttr(AttrKind); if (CallAttr.isValid()) return CallAttr; @@ -152,7 +152,7 @@ return {}; } -Optional getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind) { +Optional getStringFnAttrAsInt(CallBase &CB, AttributeKey AttrKind) { Attribute Attr = getFnAttr(CB, AttrKind); int AttrValue; if (Attr.getValueAsString().getAsInteger(10, AttrValue)) @@ -599,11 +599,11 @@ bool onCallBaseVisitStart(CallBase &Call) override { if (Optional AttrCallThresholdBonus = - getStringFnAttrAsInt(Call, "call-threshold-bonus")) + getStringFnAttrAsInt(Call, CallThresholdBonus)) Threshold += *AttrCallThresholdBonus; if (Optional AttrCallCost = - getStringFnAttrAsInt(Call, "call-inline-cost")) { + getStringFnAttrAsInt(Call, CallInlineCost)) { addCost(*AttrCallCost); // Prevent further processing of the call since we want to override its // inline cost, not just add to it. @@ -902,11 +902,11 @@ Threshold -= VectorBonus / 2; if (Optional AttrCost = - getStringFnAttrAsInt(CandidateCall, "function-inline-cost")) + getStringFnAttrAsInt(CandidateCall, FunctionInlineCost)) Cost = *AttrCost; if (Optional AttrThreshold = - getStringFnAttrAsInt(CandidateCall, "function-inline-threshold")) + getStringFnAttrAsInt(CandidateCall, FunctionInlineThreshold)) Threshold = *AttrThreshold; if (auto Result = costBenefitAnalysis()) { diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -1376,7 +1376,8 @@ void VFABI::getVectorVariantNames( const CallInst &CI, SmallVectorImpl &VariantMappings) { - const StringRef S = CI.getFnAttr(VFABI::MappingsAttrName).getValueAsString(); + const StringRef S = + CI.getFnAttr(VectorFunctionAbiVariantAttr).getValueAsString(); if (S.empty()) return; diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1612,7 +1612,7 @@ std::string Val; if (EatIfPresent(lltok::equal) && parseStringConstant(Val)) return true; - B.addAttribute(Attr, Val); + B.addAttribute(AttributeKey::Create(Attr), Val); return false; } diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1644,7 +1644,7 @@ assert(Record[i] == 0 && "Value string not null terminated"); } - B.addAttribute(KindStr.str(), ValStr.str()); + B.addAttribute(AttributeKey::Create(KindStr), ValStr.str()); } else { assert((Record[i] == 5 || Record[i] == 6) && "Invalid attribute group entry"); diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -799,7 +799,7 @@ Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); Record.push_back(Attr.getValueAsInt()); } else if (Attr.isStringAttribute()) { - StringRef Kind = Attr.getKindAsString(); + StringRef Kind = Attr.getKindAsKey().value(); StringRef Val = Attr.getValueAsString(); Record.push_back(Val.empty() ? 3 : 4); diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -776,10 +776,10 @@ // place prefix data before NOPs. unsigned PatchableFunctionPrefix = 0; unsigned PatchableFunctionEntry = 0; - (void)F.getFnAttribute("patchable-function-prefix") + (void)F.getFnAttribute(PatchableFunctionPrefixAttr) .getValueAsString() .getAsInteger(10, PatchableFunctionPrefix); - (void)F.getFnAttribute("patchable-function-entry") + (void)F.getFnAttribute(PatchableFunctionEntryAttr) .getValueAsString() .getAsInteger(10, PatchableFunctionEntry); if (PatchableFunctionPrefix) { @@ -2002,9 +2002,9 @@ MBBSectionRanges.clear(); MBBSectionExceptionSyms.clear(); bool NeedsLocalForSize = MAI->needsLocalForSize(); - if (F.hasFnAttribute("patchable-function-entry") || - F.hasFnAttribute("function-instrument") || - F.hasFnAttribute("xray-instruction-threshold") || + if (F.hasFnAttribute(PatchableFunctionEntryAttr) || + F.hasFnAttribute(FunctionInstrumentAttr) || + F.hasFnAttribute(XrayInstructionThresholdAttr) || needFuncLabelsForEHOrDebugInfo(MF) || NeedsLocalForSize || MF.getTarget().Options.EmitStackSizeSection || MF.hasBBLabels()) { CurrentFnBegin = createTempSymbol("func_begin"); @@ -3570,8 +3570,8 @@ void AsmPrinter::recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version) { const Function &F = MI.getMF()->getFunction(); - auto Attr = F.getFnAttribute("function-instrument"); - bool LogArgs = F.hasFnAttribute("xray-log-args"); + auto Attr = F.getFnAttribute(FunctionInstrumentAttr); + bool LogArgs = F.hasFnAttribute(XrayLogArgsAttr); bool AlwaysInstrument = Attr.isStringAttribute() && Attr.getValueAsString() == "xray-always"; if (Kind == SledKind::FUNCTION_ENTER && LogArgs) @@ -3583,10 +3583,10 @@ void AsmPrinter::emitPatchableFunctionEntries() { const Function &F = MF->getFunction(); unsigned PatchableFunctionPrefix = 0, PatchableFunctionEntry = 0; - (void)F.getFnAttribute("patchable-function-prefix") + (void)F.getFnAttribute(PatchableFunctionPrefixAttr) .getValueAsString() .getAsInteger(10, PatchableFunctionPrefix); - (void)F.getFnAttribute("patchable-function-entry") + (void)F.getFnAttribute(PatchableFunctionEntryAttr) .getValueAsString() .getAsInteger(10, PatchableFunctionEntry); if (!PatchableFunctionPrefix && !PatchableFunctionEntry) diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp --- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp @@ -54,7 +54,7 @@ auto &OS = *Asm->OutStreamer; const Module *M = MMI->getModule(); for (const Function &F : *M) - if (F.hasFnAttribute("safeseh")) + if (F.hasFnAttribute(SafesehAttr)) OS.EmitCOFFSafeSEH(Asm->getSymbol(&F)); if (M->getModuleFlag("ehcontguard") && !EHContTargets.empty()) { diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp --- a/llvm/lib/CodeGen/CommandFlags.cpp +++ b/llvm/lib/CodeGen/CommandFlags.cpp @@ -599,14 +599,15 @@ return Features.getFeatures(); } -void codegen::renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val) { +void codegen::renderBoolStringAttr(AttrBuilder &B, AttributeKey Name, + bool Val) { B.addAttribute(Name, Val ? "true" : "false"); } -#define HANDLE_BOOL_ATTR(CL, AttrName) \ +#define HANDLE_BOOL_ATTR(CL, Attr) \ do { \ - if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \ - renderBoolStringAttr(NewAttrs, AttrName, *CL); \ + if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(Attr)) \ + renderBoolStringAttr(NewAttrs, Attr, *CL); \ } while (0) /// Set function attributes of function \p F based on CPU, Features, and command @@ -617,58 +618,57 @@ AttributeList Attrs = F.getAttributes(); AttrBuilder NewAttrs; - if (!CPU.empty() && !F.hasFnAttribute("target-cpu")) - NewAttrs.addAttribute("target-cpu", CPU); + if (!CPU.empty() && !F.hasFnAttribute(TargetCPUAttr)) + NewAttrs.addAttribute(TargetCPUAttr, CPU); if (!Features.empty()) { // Append the command line features to any that are already on the function. StringRef OldFeatures = - F.getFnAttribute("target-features").getValueAsString(); + F.getFnAttribute(TargetFeaturesAttr).getValueAsString(); if (OldFeatures.empty()) - NewAttrs.addAttribute("target-features", Features); + NewAttrs.addAttribute(TargetFeaturesAttr, Features); else { SmallString<256> Appended(OldFeatures); Appended.push_back(','); Appended.append(Features); - NewAttrs.addAttribute("target-features", Appended); + NewAttrs.addAttribute(TargetFeaturesAttr, Appended); } } if (FramePointerUsageView->getNumOccurrences() > 0 && - !F.hasFnAttribute("frame-pointer")) { + !F.hasFnAttribute(FramePointerAttr)) { if (getFramePointerUsage() == FramePointerKind::All) - NewAttrs.addAttribute("frame-pointer", "all"); + NewAttrs.addAttribute(FramePointerAttr, "all"); else if (getFramePointerUsage() == FramePointerKind::NonLeaf) - NewAttrs.addAttribute("frame-pointer", "non-leaf"); + NewAttrs.addAttribute(FramePointerAttr, "non-leaf"); else if (getFramePointerUsage() == FramePointerKind::None) - NewAttrs.addAttribute("frame-pointer", "none"); + NewAttrs.addAttribute(FramePointerAttr, "none"); } if (DisableTailCallsView->getNumOccurrences() > 0) - NewAttrs.addAttribute("disable-tail-calls", + NewAttrs.addAttribute(DisableTailCallsAttr, toStringRef(getDisableTailCalls())); if (getStackRealign()) - NewAttrs.addAttribute("stackrealign"); + NewAttrs.addAttribute(StackrealignAttr); - HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math"); - HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math"); - HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math"); - HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math"); + HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, UnsafeFPMathAttr); + HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, NoInfsFPMathAttr); + HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, NoNansFPMathAttr); + HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, NoSignedZerosFPMathAttr); if (DenormalFPMathView->getNumOccurrences() > 0 && - !F.hasFnAttribute("denormal-fp-math")) { + !F.hasFnAttribute(DenormalFPMathAttr)) { DenormalMode::DenormalModeKind DenormKind = getDenormalFPMath(); // FIXME: Command line flag should expose separate input/output modes. - NewAttrs.addAttribute("denormal-fp-math", + NewAttrs.addAttribute(DenormalFPMathAttr, DenormalMode(DenormKind, DenormKind).str()); } if (DenormalFP32MathView->getNumOccurrences() > 0 && - !F.hasFnAttribute("denormal-fp-math-f32")) { + !F.hasFnAttribute(DenormalFPMathf32Attr)) { // FIXME: Command line flag should expose separate input/output modes. DenormalMode::DenormalModeKind DenormKind = getDenormalFP32Math(); - NewAttrs.addAttribute( - "denormal-fp-math-f32", - DenormalMode(DenormKind, DenormKind).str()); + NewAttrs.addAttribute(DenormalFPMathf32Attr, + DenormalMode(DenormKind, DenormKind).str()); } if (TrapFuncNameView->getNumOccurrences() > 0) @@ -679,7 +679,7 @@ if (F->getIntrinsicID() == Intrinsic::debugtrap || F->getIntrinsicID() == Intrinsic::trap) Call->addFnAttr( - Attribute::get(Ctx, "trap-func-name", getTrapFuncName())); + Attribute::get(Ctx, TrapFuncNameAttr, getTrapFuncName())); // Let NewAttrs override Attrs. F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs)); diff --git a/llvm/lib/CodeGen/FEntryInserter.cpp b/llvm/lib/CodeGen/FEntryInserter.cpp --- a/llvm/lib/CodeGen/FEntryInserter.cpp +++ b/llvm/lib/CodeGen/FEntryInserter.cpp @@ -36,7 +36,7 @@ bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) { const std::string FEntryName = std::string( - MF.getFunction().getFnAttribute("fentry-call").getValueAsString()); + MF.getFunction().getFnAttribute(FentryCallAttr).getValueAsString()); if (FEntryName != "true") return false; diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp --- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp @@ -89,7 +89,7 @@ bool CanBeTailCalled = CB.isTailCall() && isInTailCallPosition(CB, MF.getTarget()) && (MF.getFunction() - .getFnAttribute("disable-tail-calls") + .getFnAttribute(DisableTailCallsAttr) .getValueAsString() != "true"); CallingConv::ID CallConv = CB.getCallingConv(); diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -2238,7 +2238,7 @@ case Intrinsic::debugtrap: case Intrinsic::ubsantrap: { StringRef TrapFuncName = - CI.getAttributes().getFnAttr("trap-func-name").getValueAsString(); + CI.getAttributes().getFnAttr(TrapFuncNameAttr).getValueAsString(); if (TrapFuncName.empty()) break; // Use the default handling. CallLowering::CallLoweringInfo Info; diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -166,7 +166,7 @@ // We can realign the stack if the target supports it and the user hasn't // explicitly asked us not to. bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() && - !F.hasFnAttribute("no-realign-stack"); + !F.hasFnAttribute(NoRealignStack); FrameInfo = new (Allocator) MachineFrameInfo( getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP, /*ForcedRealign=*/CanRealignSP && @@ -279,7 +279,7 @@ /// Should we be emitting segmented stack stuff for the function bool MachineFunction::shouldSplitStack() const { - return getFunction().hasFnAttribute("split-stack"); + return getFunction().hasFnAttribute(SplitStackAttr); } LLVM_NODISCARD unsigned diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp --- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp +++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp @@ -102,7 +102,7 @@ // be more beneficial to augment the linker to ensure contiguous layout of // split functions within the same section as specified by the attribute. if (MF.getFunction().hasSection() || - MF.getFunction().hasFnAttribute("implicit-section-name")) + MF.getFunction().hasFnAttribute(ImplicitSectionNameAttr)) return false; // We don't want to proceed further for cold functions diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -623,8 +623,8 @@ // must necessarily support the instructions that are in the outlined region. Candidate &FirstCand = OF.Candidates.front(); const Function &ParentFn = FirstCand.getMF()->getFunction(); - if (ParentFn.hasFnAttribute("target-features")) - F->addFnAttr(ParentFn.getFnAttribute("target-features")); + if (ParentFn.hasFnAttribute(TargetFeaturesAttr)) + F->addFnAttr(ParentFn.getFnAttribute(TargetFeaturesAttr)); // Set nounwind, so we don't generate eh_frame. if (llvm::all_of(OF.Candidates, [](const outliner::Candidate &C) { diff --git a/llvm/lib/CodeGen/PatchableFunction.cpp b/llvm/lib/CodeGen/PatchableFunction.cpp --- a/llvm/lib/CodeGen/PatchableFunction.cpp +++ b/llvm/lib/CodeGen/PatchableFunction.cpp @@ -55,7 +55,7 @@ } bool PatchableFunction::runOnMachineFunction(MachineFunction &MF) { - if (MF.getFunction().hasFnAttribute("patchable-function-entry")) { + if (MF.getFunction().hasFnAttribute(PatchableFunctionEntryAttr)) { MachineBasicBlock &FirstMBB = *MF.begin(); const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo(); // The initial .loc covers PATCHABLE_FUNCTION_ENTER. @@ -64,11 +64,11 @@ return true; } - if (!MF.getFunction().hasFnAttribute("patchable-function")) + if (!MF.getFunction().hasFnAttribute(PatchableFunctionAttr)) return false; #ifndef NDEBUG - Attribute PatchAttr = MF.getFunction().getFnAttribute("patchable-function"); + Attribute PatchAttr = MF.getFunction().getFnAttribute(PatchableFunctionAttr); StringRef PatchType = PatchAttr.getValueAsString(); assert(PatchType == "prologue-short-redirect" && "Only possibility today!"); #endif diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -275,9 +275,9 @@ uint64_t StackSize = MFI.getStackSize(); unsigned Threshold = UINT_MAX; - if (MF.getFunction().hasFnAttribute("warn-stack-size")) { + if (MF.getFunction().hasFnAttribute(WarnStackSizeAttr)) { bool Failed = MF.getFunction() - .getFnAttribute("warn-stack-size") + .getFnAttribute(WarnStackSizeAttr) .getValueAsString() .getAsInteger(10, Threshold); // Verifier should have caught this. diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -14677,7 +14677,7 @@ // unexpected results. Ie, programs may be relying on the platform-specific // undefined behavior when the float-to-int conversion overflows. const Function &F = DAG.getMachineFunction().getFunction(); - Attribute StrictOverflow = F.getFnAttribute("strict-float-cast-overflow"); + Attribute StrictOverflow = F.getFnAttribute(StrictFloatCastOverflowAttr); if (StrictOverflow.getValueAsString().equals("false")) return SDValue(); diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1141,9 +1141,8 @@ bool IsTailCall = CI->isTailCall(); if (IsTailCall && !isInTailCallPosition(*CI, TM)) IsTailCall = false; - if (IsTailCall && MF->getFunction() - .getFnAttribute("disable-tail-calls") - .getValueAsBool()) + if (IsTailCall && + MF->getFunction().getFnAttribute(DisableTailCallsAttr).getValueAsBool()) IsTailCall = false; CallLoweringInfo CLI; @@ -1538,7 +1537,7 @@ // Don't handle Intrinsic::trap if a trap function is specified. if (F && F->getIntrinsicID() == Intrinsic::trap && - Call->hasFnAttr("trap-func-name")) + Call->hasFnAttr(TrapFuncNameAttr)) return false; } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -6705,7 +6705,7 @@ case Intrinsic::debugtrap: case Intrinsic::trap: { StringRef TrapFuncName = - I.getAttributes().getFnAttr("trap-func-name").getValueAsString(); + I.getAttributes().getFnAttr(TrapFuncNameAttr).getValueAsString(); if (TrapFuncName.empty()) { switch (Intrinsic) { case Intrinsic::trap: @@ -7602,8 +7602,9 @@ // Avoid emitting tail calls in functions with the disable-tail-calls // attribute. auto *Caller = CB.getParent()->getParent(); - if (Caller->getFnAttribute("disable-tail-calls").getValueAsString() == - "true" && !isMustTailCall) + if (Caller->getFnAttribute(DisableTailCallsAttr).getValueAsString() == + "true" && + !isMustTailCall) isTailCall = false; // We can't tail call inside a function with a swifterror argument. Lowering diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -54,7 +54,7 @@ const Function &F = DAG.getMachineFunction().getFunction(); // First, check if tail calls have been disabled in this function. - if (F.getFnAttribute("disable-tail-calls").getValueAsBool()) + if (F.getFnAttribute(DisableTailCallsAttr).getValueAsBool()) return false; // Conservatively require the attributes of the call to match those of diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp --- a/llvm/lib/CodeGen/StackProtector.cpp +++ b/llvm/lib/CodeGen/StackProtector.cpp @@ -93,7 +93,7 @@ HasPrologue = false; HasIRCheck = false; - Attribute Attr = Fn.getFnAttribute("stack-protector-buffer-size"); + Attribute Attr = Fn.getFnAttribute(StackProtectorBufferSizeAttr); if (Attr.isStringAttribute() && Attr.getValueAsString().getAsInteger(10, SSPBufferSize)) return false; // Invalid integer string diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp --- a/llvm/lib/CodeGen/TargetLoweringBase.cpp +++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -2044,7 +2044,7 @@ /// override the target defaults. static StringRef getRecipEstimateForFunc(MachineFunction &MF) { const Function &F = MF.getFunction(); - return F.getFnAttribute("reciprocal-estimates").getValueAsString(); + return F.getFnAttribute(ReciprocalEstimatesAttr).getValueAsString(); } /// Construct a string for the given reciprocal operation of the given type. diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -742,19 +742,20 @@ const GlobalVariable *GV = dyn_cast(GO); if (GV && GV->hasImplicitSection()) { auto Attrs = GV->getAttributes(); - if (Attrs.hasAttribute("bss-section") && Kind.isBSS()) { - SectionName = Attrs.getAttribute("bss-section").getValueAsString(); - } else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly()) { - SectionName = Attrs.getAttribute("rodata-section").getValueAsString(); - } else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) { - SectionName = Attrs.getAttribute("relro-section").getValueAsString(); - } else if (Attrs.hasAttribute("data-section") && Kind.isData()) { - SectionName = Attrs.getAttribute("data-section").getValueAsString(); + if (Attrs.hasAttribute(BssSectionAttr) && Kind.isBSS()) { + SectionName = Attrs.getAttribute(BssSectionAttr).getValueAsString(); + } else if (Attrs.hasAttribute(RodataSectionAttr) && Kind.isReadOnly()) { + SectionName = Attrs.getAttribute(RodataSectionAttr).getValueAsString(); + } else if (Attrs.hasAttribute(RelroSectionAttr) && + Kind.isReadOnlyWithRel()) { + SectionName = Attrs.getAttribute(RelroSectionAttr).getValueAsString(); + } else if (Attrs.hasAttribute(DataSectionAttr) && Kind.isData()) { + SectionName = Attrs.getAttribute(DataSectionAttr).getValueAsString(); } } const Function *F = dyn_cast(GO); - if (F && F->hasFnAttribute("implicit-section-name")) { - SectionName = F->getFnAttribute("implicit-section-name").getValueAsString(); + if (F && F->hasFnAttribute(ImplicitSectionNameAttr)) { + SectionName = F->getFnAttribute(ImplicitSectionNameAttr).getValueAsString(); } // Infer section flags from the section name if we can. @@ -896,7 +897,7 @@ unsigned Flags = getELFSectionFlags(Kind); // If the function's section names is pre-determined via pragma or a // section attribute, call selectExplicitSectionGlobal. - if (F.hasSection() || F.hasFnAttribute("implicit-section-name")) + if (F.hasSection() || F.hasFnAttribute(ImplicitSectionNameAttr)) return selectExplicitSectionGlobal( &F, Kind, TM, getContext(), getMangler(), NextUniqueID, Used.count(&F), /* ForceUnique = */true); @@ -1226,8 +1227,8 @@ StringRef SectionName = GO->getSection(); const Function *F = dyn_cast(GO); - if (F && F->hasFnAttribute("implicit-section-name")) { - SectionName = F->getFnAttribute("implicit-section-name").getValueAsString(); + if (F && F->hasFnAttribute(ImplicitSectionNameAttr)) { + SectionName = F->getFnAttribute(ImplicitSectionNameAttr).getValueAsString(); } // Parse the section specifier and create it if valid. @@ -2221,7 +2222,7 @@ // here. if (const GlobalObject *GO = dyn_cast(GV)) { if (const GlobalVariable *GVar = dyn_cast(GV)) - if (GVar->hasAttribute("toc-data")) + if (GVar->hasAttribute(TocDataAttr)) return cast( SectionForGlobal(GVar, SectionKind::getData(), TM)) ->getQualNameSymbol(); @@ -2254,7 +2255,7 @@ // Handle the XCOFF::TD case first, then deal with the rest. if (const GlobalVariable *GVar = dyn_cast(GO)) - if (GVar->hasAttribute("toc-data")) + if (GVar->hasAttribute(TocDataAttr)) return getContext().getXCOFFSection( SectionName, Kind, XCOFF::CsectProperties(/*MappingClass*/ XCOFF::XMC_TD, XCOFF::XTY_SD), @@ -2298,7 +2299,7 @@ const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // Handle the XCOFF::TD case first, then deal with the rest. if (const GlobalVariable *GVar = dyn_cast(GO)) - if (GVar->hasAttribute("toc-data")) { + if (GVar->hasAttribute(TocDataAttr)) { SmallString<128> Name; getNameWithPrefix(Name, GO, TM); return getContext().getXCOFFSection( diff --git a/llvm/lib/CodeGen/TargetOptionsImpl.cpp b/llvm/lib/CodeGen/TargetOptionsImpl.cpp --- a/llvm/lib/CodeGen/TargetOptionsImpl.cpp +++ b/llvm/lib/CodeGen/TargetOptionsImpl.cpp @@ -28,9 +28,9 @@ const Function &F = MF.getFunction(); - if (!F.hasFnAttribute("frame-pointer")) + if (!F.hasFnAttribute(FramePointerAttr)) return false; - StringRef FP = F.getFnAttribute("frame-pointer").getValueAsString(); + StringRef FP = F.getFnAttribute(FramePointerAttr).getValueAsString(); if (FP == "all") return true; if (FP == "non-leaf") diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp --- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp +++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp @@ -476,14 +476,14 @@ } bool TargetRegisterInfo::canRealignStack(const MachineFunction &MF) const { - return !MF.getFunction().hasFnAttribute("no-realign-stack"); + return !MF.getFunction().hasFnAttribute(NoRealignStack); } bool TargetRegisterInfo::shouldRealignStack(const MachineFunction &MF) const { const MachineFrameInfo &MFI = MF.getFrameInfo(); const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); const Function &F = MF.getFunction(); - return F.hasFnAttribute("stackrealign") || + return F.hasFnAttribute(StackrealignAttr) || (MFI.getMaxAlign() > TFI->getStackAlign()) || F.hasFnAttribute(Attribute::StackAlignment); } diff --git a/llvm/lib/CodeGen/XRayInstrumentation.cpp b/llvm/lib/CodeGen/XRayInstrumentation.cpp --- a/llvm/lib/CodeGen/XRayInstrumentation.cpp +++ b/llvm/lib/CodeGen/XRayInstrumentation.cpp @@ -144,15 +144,15 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) { auto &F = MF.getFunction(); - auto InstrAttr = F.getFnAttribute("function-instrument"); + auto InstrAttr = F.getFnAttribute(FunctionInstrumentAttr); bool AlwaysInstrument = InstrAttr.isStringAttribute() && InstrAttr.getValueAsString() == "xray-always"; bool NeverInstrument = InstrAttr.isStringAttribute() && InstrAttr.getValueAsString() == "xray-never"; if (NeverInstrument && !AlwaysInstrument) return false; - auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold"); - auto IgnoreLoopsAttr = F.getFnAttribute("xray-ignore-loops"); + auto ThresholdAttr = F.getFnAttribute(XrayInstructionThresholdAttr); + auto IgnoreLoopsAttr = F.getFnAttribute(XrayIgnoreLoopsAttr); unsigned int XRayThreshold = 0; if (!AlwaysInstrument) { if (!ThresholdAttr.isStringAttribute()) @@ -214,14 +214,14 @@ return false; } - if (!F.hasFnAttribute("xray-skip-entry")) { + if (!F.hasFnAttribute(XraySkipEntryAttr)) { // First, insert an PATCHABLE_FUNCTION_ENTER as the first instruction of the // MachineFunction. BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(), TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER)); } - if (!F.hasFnAttribute("xray-skip-exit")) { + if (!F.hasFnAttribute(XraySkipExitAttr)) { switch (MF.getTarget().getTargetTriple().getArch()) { case Triple::ArchType::arm: case Triple::ArchType::thumb: diff --git a/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp b/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp --- a/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp +++ b/llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp @@ -188,7 +188,7 @@ for (auto &F : *Mod) { auto Attrs = F.getAttributes(); StringRef Value = options.NoFramePointerElim ? "all" : "none"; - Attrs = Attrs.addFnAttribute(F.getContext(), "frame-pointer", Value); + Attrs = Attrs.addFnAttribute(F.getContext(), FramePointerAttr, Value); F.setAttributes(Attrs); } diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -2152,8 +2152,8 @@ createTargetMachine(Function *F, CodeGenOpt::Level OptLevel) { Module *M = F->getParent(); - StringRef CPU = F->getFnAttribute("target-cpu").getValueAsString(); - StringRef Features = F->getFnAttribute("target-features").getValueAsString(); + StringRef CPU = F->getFnAttribute(TargetCPUAttr).getValueAsString(); + StringRef Features = F->getFnAttribute(TargetFeaturesAttr).getValueAsString(); const std::string &Triple = M->getTargetTriple(); std::string Error; diff --git a/llvm/lib/IR/Assumptions.cpp b/llvm/lib/IR/Assumptions.cpp --- a/llvm/lib/IR/Assumptions.cpp +++ b/llvm/lib/IR/Assumptions.cpp @@ -60,7 +60,7 @@ LLVMContext &Ctx = Site.getContext(); Site.addFnAttr(llvm::Attribute::get( - Ctx, llvm::AssumptionAttrKey, + Ctx, llvm::LLVMAssumeAttr, llvm::join(CurAssumptions.begin(), CurAssumptions.end(), ","))); return true; @@ -69,7 +69,7 @@ bool llvm::hasAssumption(const Function &F, const KnownAssumptionString &AssumptionStr) { - const Attribute &A = F.getFnAttribute(AssumptionAttrKey); + const Attribute &A = F.getFnAttribute(LLVMAssumeAttr); return ::hasAssumption(A, AssumptionStr); } @@ -79,17 +79,17 @@ if (hasAssumption(*F, AssumptionStr)) return true; - const Attribute &A = CB.getFnAttr(AssumptionAttrKey); + const Attribute &A = CB.getFnAttr(LLVMAssumeAttr); return ::hasAssumption(A, AssumptionStr); } DenseSet llvm::getAssumptions(const Function &F) { - const Attribute &A = F.getFnAttribute(AssumptionAttrKey); + const Attribute &A = F.getFnAttribute(LLVMAssumeAttr); return ::getAssumptions(A); } DenseSet llvm::getAssumptions(const CallBase &CB) { - const Attribute &A = CB.getFnAttr(AssumptionAttrKey); + const Attribute &A = CB.getFnAttr(LLVMAssumeAttr); return ::getAssumptions(A); } diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h --- a/llvm/lib/IR/AttributeImpl.h +++ b/llvm/lib/IR/AttributeImpl.h @@ -60,13 +60,13 @@ bool isTypeAttribute() const { return KindID == TypeAttrEntry; } bool hasAttribute(Attribute::AttrKind A) const; - bool hasAttribute(StringRef Kind) const; + bool hasAttribute(AttributeKey Kind) const; Attribute::AttrKind getKindAsEnum() const; uint64_t getValueAsInt() const; bool getValueAsBool() const; - StringRef getKindAsString() const; + AttributeKey getKindAsKey() const; StringRef getValueAsString() const; Type *getValueAsType() const; @@ -80,7 +80,7 @@ else if (isIntAttribute()) Profile(ID, getKindAsEnum(), getValueAsInt()); else if (isStringAttribute()) - Profile(ID, getKindAsString(), getValueAsString()); + Profile(ID, getKindAsKey(), getValueAsString()); else Profile(ID, getKindAsEnum(), getValueAsType()); } @@ -91,8 +91,9 @@ if (Val) ID.AddInteger(Val); } - static void Profile(FoldingSetNodeID &ID, StringRef Kind, StringRef Values) { - ID.AddString(Kind); + static void Profile(FoldingSetNodeID &ID, AttributeKey Kind, + StringRef Values) { + ID.AddString(Kind.value()); if (!Values.empty()) ID.AddString(Values); } @@ -148,34 +149,26 @@ private TrailingObjects { friend TrailingObjects; - unsigned KindSize; + AttributeKey Kind; unsigned ValSize; - size_t numTrailingObjects(OverloadToken) const { - return KindSize + 1 + ValSize + 1; - } + size_t numTrailingObjects(OverloadToken) const { return ValSize + 1; } public: - StringAttributeImpl(StringRef Kind, StringRef Val = StringRef()) - : AttributeImpl(StringAttrEntry), KindSize(Kind.size()), - ValSize(Val.size()) { + StringAttributeImpl(AttributeKey Kind, StringRef Val = StringRef()) + : AttributeImpl(StringAttrEntry), Kind(Kind), ValSize(Val.size()) { char *TrailingString = getTrailingObjects(); // Some users rely on zero-termination. - llvm::copy(Kind, TrailingString); - TrailingString[KindSize] = '\0'; - llvm::copy(Val, &TrailingString[KindSize + 1]); - TrailingString[KindSize + 1 + ValSize] = '\0'; + llvm::copy(Val, TrailingString); + TrailingString[ValSize] = '\0'; } - StringRef getStringKind() const { - return StringRef(getTrailingObjects(), KindSize); - } + AttributeKey getStringKind() const { return Kind; } StringRef getStringValue() const { - return StringRef(getTrailingObjects() + KindSize + 1, ValSize); + return StringRef(getTrailingObjects(), ValSize); } - static size_t totalSizeToAlloc(StringRef Kind, StringRef Val) { - return TrailingObjects::totalSizeToAlloc(Kind.size() + 1 + - Val.size() + 1); + static size_t totalSizeToAlloc(StringRef Val) { + return TrailingObjects::totalSizeToAlloc(Val.size() + 1); } }; @@ -217,7 +210,7 @@ unsigned NumAttrs; ///< Number of attributes in this node. AttributeBitSet AvailableAttrs; ///< Available enum attributes. - DenseMap StringAttrs; + std::unordered_map StringAttrs; AttributeSetNode(ArrayRef Attrs); @@ -242,11 +235,11 @@ bool hasAttribute(Attribute::AttrKind Kind) const { return AvailableAttrs.hasAttribute(Kind); } - bool hasAttribute(StringRef Kind) const; + bool hasAttribute(AttributeKey Kind) const; bool hasAttributes() const { return NumAttrs != 0; } Attribute getAttribute(Attribute::AttrKind Kind) const; - Attribute getAttribute(StringRef Kind) const; + Attribute getAttribute(AttributeKey Kind) const; MaybeAlign getAlignment() const; MaybeAlign getStackAlignment() const; diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -118,10 +118,11 @@ return Attribute(PA); } -Attribute Attribute::get(LLVMContext &Context, StringRef Kind, StringRef Val) { +Attribute Attribute::get(LLVMContext &Context, AttributeKey Kind, + StringRef Val) { LLVMContextImpl *pImpl = Context.pImpl; FoldingSetNodeID ID; - ID.AddString(Kind); + ID.AddString(Kind.value()); if (!Val.empty()) ID.AddString(Val); void *InsertPoint; @@ -131,7 +132,7 @@ // If we didn't find any existing attributes of the same shape then create a // new one and insert it. void *Mem = - pImpl->Alloc.Allocate(StringAttributeImpl::totalSizeToAlloc(Kind, Val), + pImpl->Alloc.Allocate(StringAttributeImpl::totalSizeToAlloc(Val), alignof(StringAttributeImpl)); PA = new (Mem) StringAttributeImpl(Kind, Val); pImpl->AttrsSet.InsertNode(PA, InsertPoint); @@ -291,11 +292,11 @@ return pImpl->getValueAsBool(); } -StringRef Attribute::getKindAsString() const { +AttributeKey Attribute::getKindAsKey() const { if (!pImpl) return {}; assert(isStringAttribute() && "Invalid attribute type to get the kind as a string!"); - return pImpl->getKindAsString(); + return pImpl->getKindAsKey(); } StringRef Attribute::getValueAsString() const { @@ -317,7 +318,7 @@ return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None); } -bool Attribute::hasAttribute(StringRef Kind) const { +bool Attribute::hasAttribute(AttributeKey Kind) const { if (!isStringAttribute()) return false; return pImpl && pImpl->hasAttribute(Kind); } @@ -448,7 +449,7 @@ std::string Result; { raw_string_ostream OS(Result); - OS << '"' << getKindAsString() << '"'; + OS << '"' << getKindAsKey().value() << '"'; // Since some attribute strings contain special characters that cannot be // printable, those have to be escaped to make the attribute value @@ -523,9 +524,9 @@ return getKindAsEnum() == A; } -bool AttributeImpl::hasAttribute(StringRef Kind) const { +bool AttributeImpl::hasAttribute(AttributeKey Kind) const { if (!isStringAttribute()) return false; - return getKindAsString() == Kind; + return getKindAsKey() == Kind; } Attribute::AttrKind AttributeImpl::getKindAsEnum() const { @@ -543,7 +544,7 @@ return getValueAsString() == "true"; } -StringRef AttributeImpl::getKindAsString() const { +AttributeKey AttributeImpl::getKindAsKey() const { assert(isStringAttribute()); return static_cast(this)->getStringKind(); } @@ -578,9 +579,9 @@ if (!AI.isStringAttribute()) return false; - if (getKindAsString() == AI.getKindAsString()) + if (getKindAsKey() == AI.getKindAsKey()) return getValueAsString() < AI.getValueAsString(); - return getKindAsString() < AI.getKindAsString(); + return getKindAsKey() < AI.getKindAsKey(); } //===----------------------------------------------------------------------===// @@ -603,7 +604,7 @@ return addAttributes(C, AttributeSet::get(C, B)); } -AttributeSet AttributeSet::addAttribute(LLVMContext &C, StringRef Kind, +AttributeSet AttributeSet::addAttribute(LLVMContext &C, AttributeKey Kind, StringRef Value) const { AttrBuilder B; B.addAttribute(Kind, Value); @@ -634,7 +635,7 @@ } AttributeSet AttributeSet::removeAttribute(LLVMContext &C, - StringRef Kind) const { + AttributeKey Kind) const { if (!hasAttribute(Kind)) return *this; AttrBuilder B(*this); B.removeAttribute(Kind); @@ -660,7 +661,7 @@ return SetNode ? SetNode->hasAttribute(Kind) : false; } -bool AttributeSet::hasAttribute(StringRef Kind) const { +bool AttributeSet::hasAttribute(AttributeKey Kind) const { return SetNode ? SetNode->hasAttribute(Kind) : false; } @@ -668,7 +669,7 @@ return SetNode ? SetNode->getAttribute(Kind) : Attribute(); } -Attribute AttributeSet::getAttribute(StringRef Kind) const { +Attribute AttributeSet::getAttribute(AttributeKey Kind) const { return SetNode ? SetNode->getAttribute(Kind) : Attribute(); } @@ -761,7 +762,7 @@ for (const auto &I : *this) { if (I.isStringAttribute()) - StringAttrs.insert({ I.getKindAsString(), I }); + StringAttrs.insert({I.getKindAsKey(), I}); else AvailableAttrs.addAttribute(I.getKindAsEnum()); } @@ -829,7 +830,7 @@ return getSorted(C, Attrs); } -bool AttributeSetNode::hasAttribute(StringRef Kind) const { +bool AttributeSetNode::hasAttribute(AttributeKey Kind) const { return StringAttrs.count(Kind); } @@ -856,8 +857,9 @@ return {}; } -Attribute AttributeSetNode::getAttribute(StringRef Kind) const { - return StringAttrs.lookup(Kind); +Attribute AttributeSetNode::getAttribute(AttributeKey Kind) const { + auto Where = StringAttrs.find(Kind); + return Where != StringAttrs.end() ? Where->second : Attribute(); } MaybeAlign AttributeSetNode::getAlignment() const { @@ -1147,7 +1149,7 @@ } AttributeList AttributeList::get(LLVMContext &C, unsigned Index, - ArrayRef Kinds) { + ArrayRef Kinds) { SmallVector, 8> Attrs; for (const auto &K : Kinds) Attrs.emplace_back(Index, Attribute::get(C, K)); @@ -1193,7 +1195,7 @@ } AttributeList AttributeList::addAttributeAtIndex(LLVMContext &C, unsigned Index, - StringRef Kind, + AttributeKey Kind, StringRef Value) const { AttrBuilder B; B.addAttribute(Kind, Value); @@ -1278,7 +1280,7 @@ AttributeList AttributeList::removeAttributeAtIndex(LLVMContext &C, unsigned Index, - StringRef Kind) const { + AttributeKey Kind) const { if (!hasAttributeAtIndex(Index, Kind)) return *this; @@ -1368,7 +1370,8 @@ return getAttributes(Index).hasAttribute(Kind); } -bool AttributeList::hasAttributeAtIndex(unsigned Index, StringRef Kind) const { +bool AttributeList::hasAttributeAtIndex(unsigned Index, + AttributeKey Kind) const { return getAttributes(Index).hasAttribute(Kind); } @@ -1380,7 +1383,7 @@ return pImpl && pImpl->hasFnAttribute(Kind); } -bool AttributeList::hasFnAttr(StringRef Kind) const { +bool AttributeList::hasFnAttr(AttributeKey Kind) const { return hasAttributeAtIndex(AttributeList::FunctionIndex, Kind); } @@ -1395,7 +1398,7 @@ } Attribute AttributeList::getAttributeAtIndex(unsigned Index, - StringRef Kind) const { + AttributeKey Kind) const { return getAttributes(Index).getAttribute(Kind); } @@ -1561,7 +1564,7 @@ AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) { if (Attr.isStringAttribute()) { - addAttribute(Attr.getKindAsString(), Attr.getValueAsString()); + addAttribute(Attr.getKindAsKey(), Attr.getValueAsString()); return *this; } @@ -1576,7 +1579,7 @@ return *this; } -AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) { +AttrBuilder &AttrBuilder::addAttribute(AttributeKey A, StringRef V) { TargetDepAttrs[A] = V; return *this; } @@ -1598,7 +1601,7 @@ return *this; } -AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { +AttrBuilder &AttrBuilder::removeAttribute(AttributeKey A) { TargetDepAttrs.erase(A); return *this; } @@ -1764,7 +1767,7 @@ return false; } -bool AttrBuilder::contains(StringRef A) const { +bool AttrBuilder::contains(AttributeKey A) const { return TargetDepAttrs.find(A) != TargetDepAttrs.end(); } @@ -1781,7 +1784,7 @@ return true; } else { assert(Attr.isStringAttribute() && "Invalid attribute kind!"); - return contains(Attr.getKindAsString()); + return contains(Attr.getKindAsKey()); } } @@ -1907,9 +1910,10 @@ /// If the inlined function required stack probes, then ensure that /// the calling function has those too. static void adjustCallerStackProbes(Function &Caller, const Function &Callee) { - if (!Caller.hasFnAttribute("probe-stack") && - Callee.hasFnAttribute("probe-stack")) { - Caller.addFnAttr(Callee.getFnAttribute("probe-stack")); + constexpr AttributeKey ProbeStackAttr("probe-stack"); + if (!Caller.hasFnAttribute(ProbeStackAttr) && + Callee.hasFnAttribute(ProbeStackAttr)) { + Caller.addFnAttr(Callee.getFnAttribute(ProbeStackAttr)); } } @@ -1918,9 +1922,10 @@ /// that is no larger. static void adjustCallerStackProbeSize(Function &Caller, const Function &Callee) { - Attribute CalleeAttr = Callee.getFnAttribute("stack-probe-size"); + constexpr AttributeKey StackProbeSizeAttr("stack-probe-size"); + Attribute CalleeAttr = Callee.getFnAttribute(StackProbeSizeAttr); if (CalleeAttr.isValid()) { - Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size"); + Attribute CallerAttr = Caller.getFnAttribute(StackProbeSizeAttr); if (CallerAttr.isValid()) { uint64_t CallerStackProbeSize, CalleeStackProbeSize; CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize); @@ -1946,9 +1951,10 @@ /// handled as part of inline cost analysis. static void adjustMinLegalVectorWidth(Function &Caller, const Function &Callee) { - Attribute CallerAttr = Caller.getFnAttribute("min-legal-vector-width"); + constexpr AttributeKey AttrK("min-legal-vector-width"); + Attribute CallerAttr = Caller.getFnAttribute(AttrK); if (CallerAttr.isValid()) { - Attribute CalleeAttr = Callee.getFnAttribute("min-legal-vector-width"); + Attribute CalleeAttr = Callee.getFnAttribute(AttrK); if (CalleeAttr.isValid()) { uint64_t CallerVectorWidth, CalleeVectorWidth; CallerAttr.getValueAsString().getAsInteger(0, CallerVectorWidth); @@ -1958,7 +1964,7 @@ } else { // If the callee doesn't have the attribute then we don't know anything // and must drop the attribute from the caller. - Caller.removeFnAttr("min-legal-vector-width"); + Caller.removeFnAttr(AttrK); } } } @@ -1988,28 +1994,26 @@ }; struct StrBoolAttr { - static bool isSet(const Function &Fn, - StringRef Kind) { + static bool isSet(const Function &Fn, AttributeKey Kind) { auto A = Fn.getFnAttribute(Kind); return A.getValueAsString().equals("true"); } - static void set(Function &Fn, - StringRef Kind, bool Val) { + static void set(Function &Fn, AttributeKey Kind, bool Val) { Fn.addFnAttr(Kind, Val ? "true" : "false"); } }; #define GET_ATTR_NAMES #define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \ - struct ENUM_NAME##Attr : EnumAttr { \ + struct ENUM_NAME##_Attr : EnumAttr { \ static enum Attribute::AttrKind getKind() { \ return llvm::Attribute::ENUM_NAME; \ } \ }; #define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \ - struct ENUM_NAME##Attr : StrBoolAttr { \ - static StringRef getKind() { return #DISPLAY_NAME; } \ + struct ENUM_NAME##_Attr : StrBoolAttr { \ + static AttributeKey getKind() { return ENUM_NAME##Attr; } \ }; #include "llvm/IR/Attributes.inc" @@ -2043,3 +2047,18 @@ // that aspect in the merged function. mergeFnAttrs(Base, ToMerge); } + +static DenseMap AttributeKeyPool; + +AttributeKey AttributeKey::Create(StringRef s) { + assert(s.size() < std::numeric_limits::max() && + "large enough size storage"); + auto Where = AttributeKeyPool.find(s); + if (Where == AttributeKeyPool.end()) { + AttributeKey Key(s); + AttributeKeyPool.insert({Key.value(), Key}); + return Key; + } else { + return Where->second; + } +} diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -4467,29 +4467,29 @@ void llvm::UpgradeAttributes(AttrBuilder &B) { StringRef FramePointer; - if (B.contains("no-frame-pointer-elim")) { + if (B.contains(NoFramePointerElimAttr)) { // The value can be "true" or "false". for (const auto &I : B.td_attrs()) - if (I.first == "no-frame-pointer-elim") + if (I.first == NoFramePointerElimAttr) FramePointer = I.second == "true" ? "all" : "none"; - B.removeAttribute("no-frame-pointer-elim"); + B.removeAttribute(NoFramePointerElimAttr); } - if (B.contains("no-frame-pointer-elim-non-leaf")) { + if (B.contains(NoFramePointerElimNonLeafAttr)) { // The value is ignored. "no-frame-pointer-elim"="true" takes priority. if (FramePointer != "all") FramePointer = "non-leaf"; - B.removeAttribute("no-frame-pointer-elim-non-leaf"); + B.removeAttribute(NoFramePointerElimNonLeafAttr); } if (!FramePointer.empty()) - B.addAttribute("frame-pointer", FramePointer); + B.addAttribute(FramePointerAttr, FramePointer); - if (B.contains("null-pointer-is-valid")) { + if (B.contains(NullPointerIsValidAttr)) { // The value can be "true" or "false". bool NullPointerIsValid = false; for (const auto &I : B.td_attrs()) - if (I.first == "null-pointer-is-valid") + if (I.first == NullPointerIsValidAttr) NullPointerIsValid = I.second == "true"; - B.removeAttribute("null-pointer-is-valid"); + B.removeAttribute(NullPointerIsValidAttr); if (NullPointerIsValid) B.addAttribute(Attribute::NullPointerIsValid); } diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -179,13 +179,14 @@ LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C, const char *K, unsigned KLength, const char *V, unsigned VLength) { - return wrap(Attribute::get(*unwrap(C), StringRef(K, KLength), + return wrap(Attribute::get(*unwrap(C), + AttributeKey::Create(StringRef(K, KLength)), StringRef(V, VLength))); } const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length) { - auto S = unwrap(A).getKindAsString(); + auto S = unwrap(A).getKindAsKey().value(); *Length = S.size(); return S.data(); } @@ -2485,8 +2486,8 @@ LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap( - unwrap(F)->getAttributeAtIndex(Idx, StringRef(K, KLen))); + return wrap(unwrap(F)->getAttributeAtIndex( + Idx, AttributeKey::Create(StringRef(K, KLen)))); } void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, @@ -2496,13 +2497,15 @@ void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - unwrap(F)->removeAttributeAtIndex(Idx, StringRef(K, KLen)); + unwrap(F)->removeAttributeAtIndex( + Idx, AttributeKey::Create(StringRef(K, KLen))); } void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, const char *V) { Function *Func = unwrap(Fn); - Attribute Attr = Attribute::get(Func->getContext(), A, V); + Attribute Attr = + Attribute::get(Func->getContext(), AttributeKey::Create(A), V); Func->addFnAttr(Attr); } @@ -2896,8 +2899,8 @@ LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap( - unwrap(C)->getAttributeAtIndex(Idx, StringRef(K, KLen))); + return wrap(unwrap(C)->getAttributeAtIndex( + Idx, AttributeKey::Create(StringRef(K, KLen)))); } void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, @@ -2907,7 +2910,8 @@ void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - unwrap(C)->removeAttributeAtIndex(Idx, StringRef(K, KLen)); + unwrap(C)->removeAttributeAtIndex( + Idx, AttributeKey::Create(StringRef(K, KLen))); } LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) { diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -406,7 +406,7 @@ return; for (int i = 0; i != 2; ++i) { - auto AttrName = i == 0 ? "dontcall-error" : "dontcall-warn"; + AttributeKey AttrName = i == 0 ? DontcallErrorAttr : DontcallWarnAttr; auto Sev = i == 0 ? DS_Error : DS_Warning; if (F->hasFnAttribute(AttrName)) { diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -348,10 +348,10 @@ // 0 ("none") is the default. break; case FramePointerKind::NonLeaf: - B.addAttribute("frame-pointer", "non-leaf"); + B.addAttribute(FramePointerAttr, "non-leaf"); break; case FramePointerKind::All: - B.addAttribute("frame-pointer", "all"); + B.addAttribute(FramePointerAttr, "all"); break; } F->addFnAttrs(B); @@ -537,7 +537,7 @@ AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind); } -void Function::addFnAttr(StringRef Kind, StringRef Val) { +void Function::addFnAttr(AttributeKey Kind, StringRef Val) { AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind, Val); } @@ -577,7 +577,7 @@ AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); } -void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) { +void Function::removeAttributeAtIndex(unsigned i, AttributeKey Kind) { AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); } @@ -585,7 +585,7 @@ AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind); } -void Function::removeFnAttr(StringRef Kind) { +void Function::removeFnAttr(AttributeKey Kind) { AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind); } @@ -597,7 +597,7 @@ AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind); } -void Function::removeRetAttr(StringRef Kind) { +void Function::removeRetAttr(AttributeKey Kind) { AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind); } @@ -609,7 +609,7 @@ AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind); } -void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) { +void Function::removeParamAttr(unsigned ArgNo, AttributeKey Kind) { AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind); } @@ -627,7 +627,7 @@ return AttributeSets.hasFnAttr(Kind); } -bool Function::hasFnAttribute(StringRef Kind) const { +bool Function::hasFnAttribute(AttributeKey Kind) const { return AttributeSets.hasFnAttr(Kind); } @@ -645,7 +645,7 @@ return AttributeSets.getAttributeAtIndex(i, Kind); } -Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const { +Attribute Function::getAttributeAtIndex(unsigned i, AttributeKey Kind) const { return AttributeSets.getAttributeAtIndex(i, Kind); } @@ -653,7 +653,7 @@ return AttributeSets.getFnAttr(Kind); } -Attribute Function::getFnAttribute(StringRef Kind) const { +Attribute Function::getFnAttribute(AttributeKey Kind) const { return AttributeSets.getFnAttr(Kind); } @@ -671,7 +671,7 @@ DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const { if (&FPType == &APFloat::IEEEsingle()) { - Attribute Attr = getFnAttribute("denormal-fp-math-f32"); + Attribute Attr = getFnAttribute(DenormalFPMathf32Attr); StringRef Val = Attr.getValueAsString(); if (!Val.empty()) return parseDenormalFPAttribute(Val); @@ -680,7 +680,7 @@ // generic one. } - Attribute Attr = getFnAttribute("denormal-fp-math"); + Attribute Attr = getFnAttribute(DenormalFPMathAttr); return parseDenormalFPAttribute(Attr.getValueAsString()); } diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -360,7 +360,7 @@ return false; } -bool CallBase::hasFnAttrOnCalledFunction(StringRef Kind) const { +bool CallBase::hasFnAttrOnCalledFunction(AttributeKey Kind) const { Value *V = getCalledOperand(); if (auto *CE = dyn_cast(V)) if (CE->getOpcode() == BitCast) diff --git a/llvm/lib/IR/Statepoint.cpp b/llvm/lib/IR/Statepoint.cpp --- a/llvm/lib/IR/Statepoint.cpp +++ b/llvm/lib/IR/Statepoint.cpp @@ -18,22 +18,22 @@ using namespace llvm; bool llvm::isStatepointDirectiveAttr(Attribute Attr) { - return Attr.hasAttribute("statepoint-id") || - Attr.hasAttribute("statepoint-num-patch-bytes"); + return Attr.hasAttribute(StatepointIdAttr) || + Attr.hasAttribute(StatepointNumPatchBytesAttr); } StatepointDirectives llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) { StatepointDirectives Result; - Attribute AttrID = AS.getFnAttr("statepoint-id"); + Attribute AttrID = AS.getFnAttr(StatepointIdAttr); uint64_t StatepointID; if (AttrID.isStringAttribute()) if (!AttrID.getValueAsString().getAsInteger(10, StatepointID)) Result.StatepointID = StatepointID; uint32_t NumPatchBytes; - Attribute AttrNumPatchBytes = AS.getFnAttr("statepoint-num-patch-bytes"); + Attribute AttrNumPatchBytes = AS.getFnAttr(StatepointNumPatchBytesAttr); if (AttrNumPatchBytes.isStringAttribute()) if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes)) Result.NumPatchBytes = NumPatchBytes; diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -548,7 +548,7 @@ bool verifyAttributeCount(AttributeList Attrs, unsigned Params); void verifyAttributeTypes(AttributeSet Attrs, const Value *V); void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V); - void checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr, + void checkUnsignedBaseTenFuncAttr(AttributeList Attrs, AttributeKey Attr, const Value *V); void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, const Value *V, bool IsIntrinsic); @@ -1706,7 +1706,7 @@ #define GET_ATTR_NAMES #define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) #define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \ - if (A.getKindAsString() == #DISPLAY_NAME) { \ + if (A.getKindAsKey().value() == #DISPLAY_NAME) { \ auto V = A.getValueAsString(); \ if (!(V.empty() || V == "true" || V == "false")) \ CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \ @@ -1868,13 +1868,14 @@ } } -void Verifier::checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr, - const Value *V) { +void Verifier::checkUnsignedBaseTenFuncAttr(AttributeList Attrs, + AttributeKey Attr, const Value *V) { if (Attrs.hasFnAttr(Attr)) { StringRef S = Attrs.getFnAttr(Attr).getValueAsString(); unsigned N; if (S.getAsInteger(10, N)) - CheckFailed("\"" + Attr + "\" takes an unsigned integer: " + S, V); + CheckFailed("\"" + Attr.value() + "\" takes an unsigned integer: " + S, + V); } } @@ -2062,15 +2063,15 @@ CheckFailed("'vscale_range' minimum cannot be greater than maximum", V); } - if (Attrs.hasFnAttr("frame-pointer")) { - StringRef FP = Attrs.getFnAttr("frame-pointer").getValueAsString(); + if (Attrs.hasFnAttr(FramePointerAttr)) { + StringRef FP = Attrs.getFnAttr(FramePointerAttr).getValueAsString(); if (FP != "all" && FP != "non-leaf" && FP != "none") CheckFailed("invalid value for 'frame-pointer' attribute: " + FP, V); } - checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-prefix", V); - checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-entry", V); - checkUnsignedBaseTenFuncAttr(Attrs, "warn-stack-size", V); + checkUnsignedBaseTenFuncAttr(Attrs, PatchableFunctionPrefixAttr, V); + checkUnsignedBaseTenFuncAttr(Attrs, PatchableFunctionEntryAttr, V); + checkUnsignedBaseTenFuncAttr(Attrs, WarnStackSizeAttr, V); } void Verifier::verifyFunctionMetadata( diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -321,16 +321,16 @@ if (auto *GVar = dyn_cast(GO)) { auto Attrs = GVar->getAttributes(); - if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) || - (Attrs.hasAttribute("data-section") && Kind.isData()) || - (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) || - (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) { - return getExplicitSectionGlobal(GO, Kind, TM); + if ((Attrs.hasAttribute(BssSectionAttr) && Kind.isBSS()) || + (Attrs.hasAttribute(DataSectionAttr) && Kind.isData()) || + (Attrs.hasAttribute(RelroSectionAttr) && Kind.isReadOnlyWithRel()) || + (Attrs.hasAttribute(RodataSectionAttr) && Kind.isReadOnly())) { + return getExplicitSectionGlobal(GO, Kind, TM); } } if (auto *F = dyn_cast(GO)) { - if (F->hasFnAttribute("implicit-section-name")) + if (F->hasFnAttribute(ImplicitSectionNameAttr)) return getExplicitSectionGlobal(GO, Kind, TM); } diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -59,10 +59,10 @@ Options.X = F.getFnAttribute(Y).getValueAsBool(); \ } while (0) - RESET_OPTION(UnsafeFPMath, "unsafe-fp-math"); - RESET_OPTION(NoInfsFPMath, "no-infs-fp-math"); - RESET_OPTION(NoNaNsFPMath, "no-nans-fp-math"); - RESET_OPTION(NoSignedZerosFPMath, "no-signed-zeros-fp-math"); + RESET_OPTION(UnsafeFPMath, UnsafeFPMathAttr); + RESET_OPTION(NoInfsFPMath, NoInfsFPMathAttr); + RESET_OPTION(NoNaNsFPMath, NoNansFPMathAttr); + RESET_OPTION(NoSignedZerosFPMath, NoSignedZerosFPMathAttr); } /// Returns the code generation relocation model. The choices are static, PIC, diff --git a/llvm/lib/Target/X86/X86DynAllocaExpander.cpp b/llvm/lib/Target/X86/X86DynAllocaExpander.cpp --- a/llvm/lib/Target/X86/X86DynAllocaExpander.cpp +++ b/llvm/lib/Target/X86/X86DynAllocaExpander.cpp @@ -283,13 +283,13 @@ SlotSize = TRI->getSlotSize(); StackProbeSize = 4096; - if (MF.getFunction().hasFnAttribute("stack-probe-size")) { + if (MF.getFunction().hasFnAttribute(StackProbeSizeAttr)) { MF.getFunction() - .getFnAttribute("stack-probe-size") + .getFnAttribute(StackProbeSizeAttr) .getValueAsString() .getAsInteger(0, StackProbeSize); } - NoStackArgProbe = MF.getFunction().hasFnAttribute("no-stack-arg-probe"); + NoStackArgProbe = MF.getFunction().hasFnAttribute(NoStackArgProbeAttr); if (NoStackArgProbe) StackProbeSize = INT64_MAX; diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp --- a/llvm/lib/Target/X86/X86FastISel.cpp +++ b/llvm/lib/Target/X86/X86FastISel.cpp @@ -3182,11 +3182,11 @@ return false; // Functions with no_caller_saved_registers that need special handling. - if ((CB && isa(CB) && CB->hasFnAttr("no_caller_saved_registers"))) + if ((CB && isa(CB) && CB->hasFnAttr(NoCallerSavedRegistersAttr))) return false; // Functions with no_callee_saved_registers that need special handling. - if ((CB && CB->hasFnAttr("no_callee_saved_registers"))) + if ((CB && CB->hasFnAttr(NoCalleeSavedRegistersAttr))) return false; // Functions using thunks for indirect calls need to use SDISel. diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -1051,7 +1051,7 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); Align MaxAlign = MFI.getMaxAlign(); // Desired stack alignment. Align StackAlign = getStackAlign(); - if (MF.getFunction().hasFnAttribute("stackrealign")) { + if (MF.getFunction().hasFnAttribute(StackrealignAttr)) { if (MFI.hasCalls()) MaxAlign = (StackAlign > MaxAlign) ? StackAlign : MaxAlign; else if (MaxAlign < SlotSize) diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp --- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -182,8 +182,8 @@ bool runOnMachineFunction(MachineFunction &MF) override { // Reset the subtarget each time through. Subtarget = &MF.getSubtarget(); - IndirectTlsSegRefs = MF.getFunction().hasFnAttribute( - "indirect-tls-seg-refs"); + IndirectTlsSegRefs = + MF.getFunction().hasFnAttribute(IndirectTLSSegRefsAttr); // OptFor[Min]Size are used in pattern predicates that isel is matching. OptForMinSize = MF.getFunction().hasMinSize(); diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -2902,7 +2902,7 @@ // For example, when they are used for argument passing. bool ShouldDisableCalleeSavedRegister = CallConv == CallingConv::X86_RegCall || - MF.getFunction().hasFnAttribute("no_caller_saved_registers"); + MF.getFunction().hasFnAttribute(NoCallerSavedRegistersAttr); if (CallConv == CallingConv::X86_INTR && !Outs.empty()) report_fatal_error("X86 interrupts may not return any value"); @@ -4050,7 +4050,7 @@ } if (CallConv == CallingConv::X86_RegCall || - F.hasFnAttribute("no_caller_saved_registers")) { + F.hasFnAttribute(NoCallerSavedRegistersAttr)) { MachineRegisterInfo &MRI = MF.getRegInfo(); for (std::pair Pair : MRI.liveins()) MRI.disableCalleeSavedRegister(Pair.first); @@ -4145,8 +4145,8 @@ CallConv == CallingConv::Tail || CallConv == CallingConv::SwiftTail; bool IsCalleePopSRet = !IsGuaranteeTCO && hasCalleePopSRet(Outs, Subtarget); X86MachineFunctionInfo *X86Info = MF.getInfo(); - bool HasNCSR = (CB && isa(CB) && - CB->hasFnAttr("no_caller_saved_registers")); + bool HasNCSR = + (CB && isa(CB) && CB->hasFnAttr(NoCallerSavedRegistersAttr)); bool HasNoCfCheck = (CB && CB->doesNoCfCheck()); bool IsIndirectCall = (CB && isa(CB) && CB->isIndirectCall()); const Module *M = MF.getMMI().getModule(); @@ -4579,7 +4579,7 @@ AdaptedCC = (CallingConv::ID)CallingConv::X86_INTR; // If NoCalleeSavedRegisters is requested, than use GHC since it happens // to use the CSR_NoRegs_RegMask. - if (CB && CB->hasFnAttr("no_callee_saved_registers")) + if (CB && CB->hasFnAttr(NoCalleeSavedRegistersAttr)) AdaptedCC = (CallingConv::ID)CallingConv::GHC; return RegInfo->getCallPreservedMask(MF, AdaptedCC); }(); @@ -54198,12 +54198,12 @@ // No inline stack probe for Windows, they have their own mechanism. if (Subtarget.isOSWindows() || - MF.getFunction().hasFnAttribute("no-stack-arg-probe")) + MF.getFunction().hasFnAttribute(NoStackArgProbeAttr)) return false; // If the function specifically requests inline stack probes, emit them. - if (MF.getFunction().hasFnAttribute("probe-stack")) - return MF.getFunction().getFnAttribute("probe-stack").getValueAsString() == + if (MF.getFunction().hasFnAttribute(ProbeStackAttr)) + return MF.getFunction().getFnAttribute(ProbeStackAttr).getValueAsString() == "inline-asm"; return false; @@ -54218,13 +54218,13 @@ return ""; // If the function specifically requests stack probes, emit them. - if (MF.getFunction().hasFnAttribute("probe-stack")) - return MF.getFunction().getFnAttribute("probe-stack").getValueAsString(); + if (MF.getFunction().hasFnAttribute(ProbeStackAttr)) + return MF.getFunction().getFnAttribute(ProbeStackAttr).getValueAsString(); // Generally, if we aren't on Windows, the platform ABI does not include // support for stack probes, so don't emit them. if (!Subtarget.isOSWindows() || Subtarget.isTargetMachO() || - MF.getFunction().hasFnAttribute("no-stack-arg-probe")) + MF.getFunction().hasFnAttribute(NoStackArgProbeAttr)) return ""; // We need a stack probe to conform to the Windows ABI. Choose the right @@ -54240,8 +54240,8 @@ // attribute. unsigned StackProbeSize = 4096; const Function &Fn = MF.getFunction(); - if (Fn.hasFnAttribute("stack-probe-size")) - Fn.getFnAttribute("stack-probe-size") + if (Fn.hasFnAttribute(StackProbeSizeAttr)) + Fn.getFnAttribute(StackProbeSizeAttr) .getValueAsString() .getAsInteger(0, StackProbeSize); return StackProbeSize; diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1893,9 +1893,9 @@ NoAutoPaddingScope NoPadScope(*OutStreamer); const Function &F = MF->getFunction(); - if (F.hasFnAttribute("patchable-function-entry")) { + if (F.hasFnAttribute(PatchableFunctionEntryAttr)) { unsigned Num; - if (F.getFnAttribute("patchable-function-entry") + if (F.getFnAttribute(PatchableFunctionEntryAttr) .getValueAsString() .getAsInteger(10, Num)) return; diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -287,12 +287,12 @@ // If attribute NoCallerSavedRegisters exists then we set X86_INTR calling // convention because it has the CSR list. - if (MF->getFunction().hasFnAttribute("no_caller_saved_registers")) + if (MF->getFunction().hasFnAttribute(NoCallerSavedRegistersAttr)) CC = CallingConv::X86_INTR; // If atribute specified, override the CSRs normally specified by the // calling convention and use the empty set instead. - if (MF->getFunction().hasFnAttribute("no_callee_saved_registers")) + if (MF->getFunction().hasFnAttribute(NoCalleeSavedRegistersAttr)) return CSR_NoRegs_SaveList; switch (CC) { diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp --- a/llvm/lib/Target/X86/X86TargetMachine.cpp +++ b/llvm/lib/Target/X86/X86TargetMachine.cpp @@ -237,9 +237,9 @@ const X86Subtarget * X86TargetMachine::getSubtargetImpl(const Function &F) const { - Attribute CPUAttr = F.getFnAttribute("target-cpu"); - Attribute TuneAttr = F.getFnAttribute("tune-cpu"); - Attribute FSAttr = F.getFnAttribute("target-features"); + Attribute CPUAttr = F.getFnAttribute(TargetCPUAttr); + Attribute TuneAttr = F.getFnAttribute(TuneCPUAttr); + Attribute FSAttr = F.getFnAttribute(TargetFeaturesAttr); StringRef CPU = CPUAttr.isValid() ? CPUAttr.getValueAsString() : (StringRef)TargetCPU; @@ -256,7 +256,7 @@ // Extract prefer-vector-width attribute. unsigned PreferVectorWidthOverride = 0; - Attribute PreferVecWidthAttr = F.getFnAttribute("prefer-vector-width"); + Attribute PreferVecWidthAttr = F.getFnAttribute(PreferVectorWidthAttr); if (PreferVecWidthAttr.isValid()) { StringRef Val = PreferVecWidthAttr.getValueAsString(); unsigned Width; @@ -269,7 +269,7 @@ // Extract min-legal-vector-width attribute. unsigned RequiredVectorWidth = UINT32_MAX; - Attribute MinLegalVecWidthAttr = F.getFnAttribute("min-legal-vector-width"); + Attribute MinLegalVecWidthAttr = F.getFnAttribute(MinLegalVectorWidthAttr); if (MinLegalVecWidthAttr.isValid()) { StringRef Val = MinLegalVecWidthAttr.getValueAsString(); unsigned Width; @@ -294,7 +294,7 @@ // function before we can generate a subtarget. We also need to use // it as a key for the subtarget since that can be the only difference // between two functions. - bool SoftFloat = F.getFnAttribute("use-soft-float").getValueAsBool(); + bool SoftFloat = F.getFnAttribute(UseSoftFloatAttr).getValueAsBool(); // If the soft float attribute is set on the function turn on the soft float // subtarget feature. if (SoftFloat) diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp --- a/llvm/lib/Target/X86/X86WinEHState.cpp +++ b/llvm/lib/Target/X86/X86WinEHState.cpp @@ -420,7 +420,7 @@ void WinEHStatePass::linkExceptionRegistration(IRBuilder<> &Builder, Function *Handler) { // Emit the .safeseh directive for this function. - Handler->addFnAttr("safeseh"); + Handler->addFnAttr(SafesehAttr); Type *LinkTy = getEHLinkRegistrationType(); // Handler = Handler diff --git a/llvm/lib/Transforms/CFGuard/CFGuard.cpp b/llvm/lib/Transforms/CFGuard/CFGuard.cpp --- a/llvm/lib/Transforms/CFGuard/CFGuard.cpp +++ b/llvm/lib/Transforms/CFGuard/CFGuard.cpp @@ -262,7 +262,7 @@ for (BasicBlock &BB : F.getBasicBlockList()) { for (Instruction &I : BB.getInstList()) { auto *CB = dyn_cast(&I); - if (CB && CB->isIndirectCall() && !CB->hasFnAttr("guard_nocf")) { + if (CB && CB->isIndirectCall() && !CB->hasFnAttr(GuardNocfAttr)) { IndirectCalls.push_back(CB); CFGuardCounter++; } diff --git a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp --- a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp @@ -180,7 +180,7 @@ // with a coroutine attribute. if (auto *CII = cast(&I)) { if (CII->getInfo().isPreSplit()) { - F.addFnAttr(CORO_PRESPLIT_ATTR, UNPREPARED_FOR_SPLIT); + F.addFnAttr(CoroutinePresplitAttr, UNPREPARED_FOR_SPLIT); setCannotDuplicate(CII); CII->setCoroutineSelf(); CoroId = cast(&I); @@ -190,7 +190,7 @@ case Intrinsic::coro_id_retcon: case Intrinsic::coro_id_retcon_once: case Intrinsic::coro_id_async: - F.addFnAttr(CORO_PRESPLIT_ATTR, PREPARED_FOR_SPLIT); + F.addFnAttr(CoroutinePresplitAttr, PREPARED_FOR_SPLIT); break; case Intrinsic::coro_resume: lowerResumeOrDestroy(*CB, CoroSubFnInst::ResumeIndex); diff --git a/llvm/lib/Transforms/Coroutines/CoroElide.cpp b/llvm/lib/Transforms/Coroutines/CoroElide.cpp --- a/llvm/lib/Transforms/Coroutines/CoroElide.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroElide.cpp @@ -444,7 +444,7 @@ bool Changed = false; - if (F.hasFnAttribute(CORO_PRESPLIT_ATTR)) + if (F.hasFnAttribute(CoroutinePresplitAttr)) Changed = replaceDevirtTrigger(F); L->CoroIds.clear(); diff --git a/llvm/lib/Transforms/Coroutines/CoroInternal.h b/llvm/lib/Transforms/Coroutines/CoroInternal.h --- a/llvm/lib/Transforms/Coroutines/CoroInternal.h +++ b/llvm/lib/Transforms/Coroutines/CoroInternal.h @@ -36,7 +36,6 @@ // adds coroutine subfunctions to the SCC to be processed by IPO pipeline. // Async lowering similarily triggers a restart of the pipeline after it has // split the coroutine. -#define CORO_PRESPLIT_ATTR "coroutine.presplit" #define UNPREPARED_FOR_SPLIT "0" #define PREPARED_FOR_SPLIT "1" #define ASYNC_RESTART_AFTER_SPLIT "2" diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -1912,9 +1912,9 @@ assert(DevirtFn && "coro.devirt.trigger function not found"); #endif - F.addFnAttr(CORO_PRESPLIT_ATTR, MarkForAsyncRestart - ? ASYNC_RESTART_AFTER_SPLIT - : PREPARED_FOR_SPLIT); + F.addFnAttr(CoroutinePresplitAttr, MarkForAsyncRestart + ? ASYNC_RESTART_AFTER_SPLIT + : PREPARED_FOR_SPLIT); // Insert an indirect call sequence that will be devirtualized by CoroElide // pass: @@ -2118,7 +2118,7 @@ // Find coroutines for processing. SmallVector Coroutines; for (LazyCallGraph::Node &N : C) - if (N.getFunction().hasFnAttribute(CORO_PRESPLIT_ATTR)) + if (N.getFunction().hasFnAttribute(CoroutinePresplitAttr)) Coroutines.push_back(&N); if (Coroutines.empty() && PrepareFns.empty()) @@ -2133,11 +2133,12 @@ // Split all the coroutines. for (LazyCallGraph::Node *N : Coroutines) { Function &F = N->getFunction(); - LLVM_DEBUG(dbgs() << "CoroSplit: Processing coroutine '" << F.getName() - << "' state: " - << F.getFnAttribute(CORO_PRESPLIT_ATTR).getValueAsString() - << "\n"); - F.removeFnAttr(CORO_PRESPLIT_ATTR); + LLVM_DEBUG( + dbgs() << "CoroSplit: Processing coroutine '" << F.getName() + << "' state: " + << F.getFnAttribute(CoroutinePresplitAttr).getValueAsString() + << "\n"); + F.removeFnAttr(CoroutinePresplitAttr); SmallVector Clones; const coro::Shape Shape = splitCoroutine(F, Clones, ReuseFrameSlot); @@ -2202,7 +2203,7 @@ SmallVector Coroutines; for (CallGraphNode *CGN : SCC) if (auto *F = CGN->getFunction()) - if (F->hasFnAttribute(CORO_PRESPLIT_ATTR)) + if (F->hasFnAttribute(CoroutinePresplitAttr)) Coroutines.push_back(F); if (Coroutines.empty() && PrepareFns.empty()) @@ -2221,21 +2222,21 @@ // Split all the coroutines. for (Function *F : Coroutines) { - Attribute Attr = F->getFnAttribute(CORO_PRESPLIT_ATTR); + Attribute Attr = F->getFnAttribute(CoroutinePresplitAttr); StringRef Value = Attr.getValueAsString(); LLVM_DEBUG(dbgs() << "CoroSplit: Processing coroutine '" << F->getName() << "' state: " << Value << "\n"); // Async lowering marks coroutines to trigger a restart of the pipeline // after it has split them. if (Value == ASYNC_RESTART_AFTER_SPLIT) { - F->removeFnAttr(CORO_PRESPLIT_ATTR); + F->removeFnAttr(CoroutinePresplitAttr); continue; } if (Value == UNPREPARED_FOR_SPLIT) { prepareForSplit(*F, CG); continue; } - F->removeFnAttr(CORO_PRESPLIT_ATTR); + F->removeFnAttr(CoroutinePresplitAttr); SmallVector Clones; const coro::Shape Shape = splitCoroutine(*F, Clones, ReuseFrameSlot); diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -390,7 +390,7 @@ return true; } if (Attr.isStringAttribute()) { - StringRef Kind = Attr.getKindAsString(); + AttributeKey Kind = Attr.getKindAsKey(); if (Attrs.hasAttributeAtIndex(AttrIdx, Kind)) if (!ForceReplace && isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind))) diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -4673,7 +4673,7 @@ if (isAssumedNoCapture()) Attrs.emplace_back(Attribute::get(Ctx, Attribute::NoCapture)); else if (ManifestInternal) - Attrs.emplace_back(Attribute::get(Ctx, "no-capture-maybe-returned")); + Attrs.emplace_back(Attribute::get(Ctx, NoCaptureMaybeReturned)); } } diff --git a/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp b/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp --- a/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp +++ b/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp @@ -113,7 +113,7 @@ Triple T(M.getTargetTriple()); if (T.isARM() || T.isThumb()) - F->addFnAttr("target-features", "+thumb-mode"); + F->addFnAttr(TargetFeaturesAttr, "+thumb-mode"); auto args = F->arg_begin(); Value &CallSiteTypeId = *(args++); diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1203,7 +1203,7 @@ for (auto &GV : M.globals()) // Skip GVs which have been converted to declarations // by dropDeadSymbols. - if (!GV.isDeclaration() && GV.hasAttribute("thinlto-internalize")) { + if (!GV.isDeclaration() && GV.hasAttribute(ThinltoInternalizeAttr)) { GV.setLinkage(GlobalValue::InternalLinkage); GV.setVisibility(GlobalValue::DefaultVisibility); } diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -68,6 +68,7 @@ #include "llvm/Transforms/Utils/Local.h" #include #include +#include #include #include diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp --- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -243,7 +243,7 @@ F->getParent()->getModuleFlag("CFI Canonical Jump Tables")); if (!CI || CI->getZExtValue() != 0) return true; - return F->hasFnAttribute("cfi-canonical-jump-table"); + return F->hasFnAttribute(CfiCanonicalJumpTablesAttr); } namespace { @@ -1353,7 +1353,7 @@ } static bool isThumbFunction(Function *F, Triple::ArchType ModuleArch) { - Attribute TFAttr = F->getFnAttribute("target-features"); + Attribute TFAttr = F->getFnAttribute(TargetFeaturesAttr); if (TFAttr.isValid()) { SmallVector Features; TFAttr.getValueAsString().split(Features, ','); @@ -1415,16 +1415,16 @@ if (OS != Triple::Win32) F->addFnAttr(Attribute::Naked); if (JumpTableArch == Triple::arm) - F->addFnAttr("target-features", "-thumb-mode"); + F->addFnAttr(TargetFeaturesAttr, "-thumb-mode"); if (JumpTableArch == Triple::thumb) { - F->addFnAttr("target-features", "+thumb-mode"); + F->addFnAttr(TargetFeaturesAttr, "+thumb-mode"); // Thumb jump table assembly needs Thumb2. The following attribute is added // by Clang for -march=armv7. - F->addFnAttr("target-cpu", "cortex-a8"); + F->addFnAttr(TargetCPUAttr, "cortex-a8"); } if (JumpTableArch == Triple::aarch64) { - F->addFnAttr("branch-target-enforcement", "false"); - F->addFnAttr("sign-return-address", "none"); + F->addFnAttr(BranchTargetEnforcementAttr, "false"); + F->addFnAttr(SignReturnAddressAttr, "none"); } // Make sure we don't emit .eh_frame for this function. F->addFnAttr(Attribute::NoUnwind); diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -2202,8 +2202,7 @@ InternalControlVar &ICV) const { const auto *CB = dyn_cast(I); - if (!CB || CB->hasFnAttr("no_openmp") || - CB->hasFnAttr("no_openmp_routines")) + if (!CB || CB->hasFnAttr(NoOpenmp) || CB->hasFnAttr(NoOpenmpRoutines)) return None; auto &OMPInfoCache = static_cast(A.getInfoCache()); @@ -4126,10 +4125,10 @@ Changed |= foldParallelLevel(A); break; case OMPRTL___kmpc_get_hardware_num_threads_in_block: - Changed = Changed | foldKernelFnAttribute(A, "omp_target_thread_limit"); + Changed = Changed | foldKernelFnAttribute(A, OmpTargetThreadLimitAttr); break; case OMPRTL___kmpc_get_hardware_num_blocks: - Changed = Changed | foldKernelFnAttribute(A, "omp_target_num_teams"); + Changed = Changed | foldKernelFnAttribute(A, OmpTargetNumTeamsAttr); break; default: llvm_unreachable("Unhandled OpenMP runtime function!"); @@ -4319,7 +4318,7 @@ : ChangeStatus::CHANGED; } - ChangeStatus foldKernelFnAttribute(Attributor &A, llvm::StringRef Attr) { + ChangeStatus foldKernelFnAttribute(Attributor &A, AttributeKey Attr) { // Specialize only if all the calls agree with the attribute constant value int32_t CurrentAttrValue = -1; Optional SimplifiedValueBefore = SimplifiedValue; diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -932,7 +932,7 @@ // recursive. As llvm does not inline recursive calls, we will // simply ignore it instead of handling it explicitly. if (!R->getValue()->isDeclaration() && R->getValue()->getSubprogram() && - R->getValue()->hasFnAttribute("use-sample-profile") && + R->getValue()->hasFnAttribute(UseSampleProfileAttr) && R->getValue() != &F && isLegalToPromote(CI, R->getValue(), &Reason)) { // For promoted target, set its value with NOMORE_ICP_MAGICNUM count // in the value profile metadata so the target won't be promoted again. @@ -1108,7 +1108,7 @@ // Profile symbol list is ignored when profile-sample-accurate is on. assert((!ProfAccForSymsInList || (!ProfileSampleAccurate && - !F.hasFnAttribute("profile-sample-accurate"))) && + !F.hasFnAttribute(ProfileSampleAccurateAttr))) && "ProfAccForSymsInList should be false when profile-sample-accurate " "is enabled"); @@ -1432,7 +1432,7 @@ // Profile symbol list is ignored when profile-sample-accurate is on. assert((!ProfAccForSymsInList || (!ProfileSampleAccurate && - !F.hasFnAttribute("profile-sample-accurate"))) && + !F.hasFnAttribute(ProfileSampleAccurateAttr))) && "ProfAccForSymsInList should be false when profile-sample-accurate " "is enabled"); @@ -1765,7 +1765,7 @@ // gets a chance to be processed. for (auto &Node : CG) { const auto *F = Node.first; - if (!F || F->isDeclaration() || !F->hasFnAttribute("use-sample-profile")) + if (!F || F->isDeclaration() || !F->hasFnAttribute(UseSampleProfileAttr)) continue; ProfiledCG->addProfiledFunction(FunctionSamples::getCanonicalFnName(*F)); } @@ -1793,7 +1793,7 @@ } for (Function &F : M) - if (!F.isDeclaration() && F.hasFnAttribute("use-sample-profile")) + if (!F.isDeclaration() && F.hasFnAttribute(UseSampleProfileAttr)) FunctionOrderList.push_back(&F); return FunctionOrderList; } @@ -1855,7 +1855,7 @@ while (!CGI.isAtEnd()) { for (ProfiledCallGraphNode *Node : *CGI) { Function *F = SymbolMap.lookup(Node->Name); - if (F && !F->isDeclaration() && F->hasFnAttribute("use-sample-profile")) + if (F && !F->isDeclaration() && F->hasFnAttribute(UseSampleProfileAttr)) FunctionOrderList.push_back(F); } ++CGI; @@ -1865,7 +1865,7 @@ while (!CGI.isAtEnd()) { for (CallGraphNode *Node : *CGI) { auto *F = Node->getFunction(); - if (F && !F->isDeclaration() && F->hasFnAttribute("use-sample-profile")) + if (F && !F->isDeclaration() && F->hasFnAttribute(UseSampleProfileAttr)) FunctionOrderList.push_back(F); } ++CGI; @@ -2056,7 +2056,7 @@ uint64_t initialEntryCount = -1; ProfAccForSymsInList = ProfileAccurateForSymsInList && PSL; - if (ProfileSampleAccurate || F.hasFnAttribute("profile-sample-accurate")) { + if (ProfileSampleAccurate || F.hasFnAttribute(ProfileSampleAccurateAttr)) { // initialize all the function entry counts to 0. It means all the // functions without profile will be regarded as cold. initialEntryCount = 0; diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp --- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -1322,7 +1322,7 @@ CallBase &CB = VCallSite.CB; // Jump tables are only profitable if the retpoline mitigation is enabled. - Attribute FSAttr = CB.getCaller()->getFnAttribute("target-features"); + Attribute FSAttr = CB.getCaller()->getFnAttribute(TargetFeaturesAttr); if (!FSAttr.isValid() || !FSAttr.getValueAsString().contains("+retpoline")) continue; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2891,7 +2891,7 @@ // If this is a call to a thunk function, don't remove the cast. Thunks are // used to transparently forward all incoming parameters and outgoing return // values, so it's important to leave the cast in place. - if (Callee->hasFnAttribute("thunk")) + if (Callee->hasFnAttribute(ThunkAttr)) return false; // If this is a musttail call, the callee's prototype must match the caller's diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -1115,7 +1115,7 @@ BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF); if (F->isVarArg()) { - NewF->removeFnAttrs(AttrBuilder().addAttribute("split-stack")); + NewF->removeFnAttrs(AttrBuilder().addAttribute(SplitStackAttr)); CallInst::Create(DFSanVarargWrapperFn, IRBuilder<>(BB).CreateGlobalStringPtr(F->getName()), "", BB); diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -4196,7 +4196,7 @@ AMD64FpEndOffset = AMD64FpEndOffsetSSE; for (const auto &Attr : F.getAttributes().getFnAttrs()) { if (Attr.isStringAttribute() && - (Attr.getKindAsString() == "target-features")) { + (Attr.getKindAsKey().value() == "target-features")) { if (Attr.getValueAsString().contains("-sse")) AMD64FpEndOffset = AMD64FpEndOffsetNoSSE; break; @@ -5071,7 +5071,7 @@ void visitCallBase(CallBase &CB, IRBuilder<> &IRB) override { bool IsSoftFloatABI = CB.getCalledFunction() - ->getFnAttribute("use-soft-float") + ->getFnAttribute(UseSoftFloatAttr) .getValueAsBool(); unsigned GpOffset = SystemZGpOffset; unsigned FpOffset = SystemZFpOffset; diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -620,7 +620,7 @@ Res |= instrumentMemIntrinsic(Inst); } - if (F.hasFnAttribute("sanitize_thread_no_checking_at_run_time")) { + if (F.hasFnAttribute(SanitizeThreadNoCheckingAtRunTimeAttr)) { assert(!F.hasFnAttribute(Attribute::SanitizeThread)); if (HasCalls) InsertRuntimeIgnores(F); diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -912,7 +912,7 @@ // See if this is a global attribute annotated with an 'objc_arc_inert'. if (auto *GV = dyn_cast(V)) - if (GV->hasAttribute("objc_arc_inert")) + if (GV->hasAttribute(ObjcArcInertAttr)) return true; if (auto PN = dyn_cast(V)) { diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -1528,16 +1528,15 @@ } // end anonymous namespace static StringRef getDeoptLowering(CallBase *Call) { - const char *DeoptLowering = "deopt-lowering"; - if (Call->hasFnAttr(DeoptLowering)) { + if (Call->hasFnAttr(DeoptLoweringAttr)) { // FIXME: Calls have a *really* confusing interface around attributes // with values. const AttributeList &CSAS = Call->getAttributes(); - if (CSAS.hasFnAttr(DeoptLowering)) - return CSAS.getFnAttr(DeoptLowering).getValueAsString(); + if (CSAS.hasFnAttr(DeoptLoweringAttr)) + return CSAS.getFnAttr(DeoptLoweringAttr).getValueAsString(); Function *F = Call->getCalledFunction(); - assert(F && F->hasFnAttribute(DeoptLowering)); - return F->getFnAttribute(DeoptLowering).getValueAsString(); + assert(F && F->hasFnAttribute(DeoptLoweringAttr)); + return F->getFnAttribute(DeoptLoweringAttr).getValueAsString(); } return "live-through"; } diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp --- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -846,7 +846,7 @@ AliasAnalysis *AA, OptimizationRemarkEmitter *ORE, DomTreeUpdater &DTU) { - if (F.getFnAttribute("disable-tail-calls").getValueAsBool()) + if (F.getFnAttribute(DisableTailCallsAttr).getValueAsBool()) return false; bool MadeChange = false; diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -888,7 +888,7 @@ // attribute can not be inherited. for (const auto &Attr : oldFunction->getAttributes().getFnAttrs()) { if (Attr.isStringAttribute()) { - if (Attr.getKindAsString() == "thunk") + if (Attr.getKindAsKey().value() == "thunk") continue; } else switch (Attr.getKindAsEnum()) { diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -67,11 +67,11 @@ } static bool runOnFunction(Function &F, bool PostInlining) { - StringRef EntryAttr = PostInlining ? "instrument-function-entry-inlined" - : "instrument-function-entry"; + AttributeKey EntryAttr = PostInlining ? InstrumentFunctionEntryInlinedAttr + : InstrumentFunctionEntryAttr; - StringRef ExitAttr = PostInlining ? "instrument-function-exit-inlined" - : "instrument-function-exit"; + AttributeKey ExitAttr = PostInlining ? InstrumentFunctionExitInlinedAttr + : InstrumentFunctionExitAttr; StringRef EntryFunc = F.getFnAttribute(EntryAttr).getValueAsString(); StringRef ExitFunc = F.getFnAttribute(ExitAttr).getValueAsString(); diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp --- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -243,7 +243,7 @@ ImportIndex.findSummaryInModule(VI, M.getModuleIdentifier())); if (GVS && (ImportIndex.isReadOnly(GVS) || ImportIndex.isWriteOnly(GVS))) { - V->addAttribute("thinlto-internalize"); + V->addAttribute(ThinltoInternalizeAttr); // Objects referenced by writeonly GV initializer should not be // promoted, because there is no any kind of read access to them // on behalf of this writeonly GV. To avoid promotion we convert diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1506,7 +1506,7 @@ // Check if we are not generating inline line tables and want to use // the call site location instead. - bool NoInlineLineTables = Fn->hasFnAttribute("no-inline-line-tables"); + bool NoInlineLineTables = Fn->hasFnAttribute(NoInlineLineTablesAttr); for (; FI != Fn->end(); ++FI) { for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2732,10 +2732,10 @@ bool llvm::callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI) { // Check if the function is specifically marked as a gc leaf function. - if (Call->hasFnAttr("gc-leaf-function")) + if (Call->hasFnAttr(GcLeafFunctionAttr)) return true; if (const Function *F = Call->getCalledFunction()) { - if (F->hasFnAttribute("gc-leaf-function")) + if (F->hasFnAttribute(GcLeafFunctionAttr)) return true; if (auto IID = F->getIntrinsicID()) { diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -297,6 +297,6 @@ "vector function declaration is missing."); } #endif - CI->addFnAttr( - Attribute::get(M->getContext(), MappingsAttrName, Buffer.str())); + CI->addFnAttr(Attribute::get(M->getContext(), VectorFunctionAbiVariantAttr, + Buffer.str())); } diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -5815,7 +5815,7 @@ // Only build lookup table when we have a target that supports it or the // attribute is not set. if (!TTI.shouldBuildLookupTables() || - (Fn->getFnAttribute("no-jump-tables").getValueAsBool())) + (Fn->getFnAttribute(NoJumpTablesAttr).getValueAsBool())) return false; // FIXME: If the switch is too sparse for a lookup table, perhaps we could diff --git a/llvm/tools/bugpoint-passes/TestPasses.cpp b/llvm/tools/bugpoint-passes/TestPasses.cpp --- a/llvm/tools/bugpoint-passes/TestPasses.cpp +++ b/llvm/tools/bugpoint-passes/TestPasses.cpp @@ -144,7 +144,7 @@ bool runOnFunction(Function &F) override { AttributeSet A = F.getAttributes().getFnAttrs(); - if (A.hasAttribute("bugpoint-crash")) + if (A.hasAttribute(AttributeKey::Create("bugpoint-crash"))) abort(); return false; } diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -97,9 +97,10 @@ Idx++; } - Call->addRetAttr(Attribute::get(Call->getContext(), "test-str-attr")); - EXPECT_TRUE(Call->hasRetAttr("test-str-attr")); - EXPECT_FALSE(Call->hasRetAttr("not-on-call")); + Call->addRetAttr(Attribute::get(Call->getContext(), + AttributeKey::Create("test-str-attr"))); + EXPECT_TRUE(Call->hasRetAttr(AttributeKey::Create("test-str-attr"))); + EXPECT_FALSE(Call->hasRetAttr(AttributeKey::Create("not-on-call"))); } TEST_F(ModuleWithFunctionTest, InvokeInst) { diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp --- a/llvm/unittests/ProfileData/SampleProfTest.cpp +++ b/llvm/unittests/ProfileData/SampleProfTest.cpp @@ -359,7 +359,7 @@ auto Inserted = M->getOrInsertFunction(Fname, FnType); auto Fcn = cast(Inserted.getCallee()); if (Policy != "") - Fcn->addFnAttr("sample-profile-suffix-elision-policy", Policy); + Fcn->addFnAttr(SampleProfileSuffixElisionPolicyAttr, Policy); } void setupModuleForElisionTest(Module *M, StringRef Policy) { diff --git a/llvm/unittests/Transforms/Utils/VFABIUtils.cpp b/llvm/unittests/Transforms/Utils/VFABIUtils.cpp --- a/llvm/unittests/Transforms/Utils/VFABIUtils.cpp +++ b/llvm/unittests/Transforms/Utils/VFABIUtils.cpp @@ -47,6 +47,7 @@ Mappings.push_back("_ZGVnN2v_g(custom_vg)"); VFABI::setVectorVariantNames(CI, Mappings); const StringRef S = - CI->getFnAttr("vector-function-abi-variant").getValueAsString(); + CI->getFnAttr(llvm::AttributeKey::Create("vector-function-abi-variant")) + .getValueAsString(); EXPECT_EQ(S, "_ZGVnN8v_g,_ZGVnN2v_g(custom_vg)"); }