Index: llvm/include/llvm/IR/Attributes.h =================================================================== --- llvm/include/llvm/IR/Attributes.h +++ llvm/include/llvm/IR/Attributes.h @@ -139,6 +139,9 @@ /// Return true if the attribute is a type attribute. bool isTypeAttribute() const; + /// Return true if the attribute is the None AttrKind. + bool isNone() const { return !pImpl; } + /// Return true if the attribute is present. bool hasAttribute(AttrKind Val) const; Index: llvm/lib/CodeGen/XRayInstrumentation.cpp =================================================================== --- llvm/lib/CodeGen/XRayInstrumentation.cpp +++ llvm/lib/CodeGen/XRayInstrumentation.cpp @@ -145,20 +145,20 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) { auto &F = MF.getFunction(); auto InstrAttr = F.getFnAttribute("function-instrument"); - bool AlwaysInstrument = !InstrAttr.hasAttribute(Attribute::None) && + bool AlwaysInstrument = !InstrAttr.isNone() && InstrAttr.isStringAttribute() && InstrAttr.getValueAsString() == "xray-always"; auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold"); auto IgnoreLoopsAttr = F.getFnAttribute("xray-ignore-loops"); unsigned int XRayThreshold = 0; if (!AlwaysInstrument) { - if (ThresholdAttr.hasAttribute(Attribute::None) || + if (ThresholdAttr.isNone() || !ThresholdAttr.isStringAttribute()) return false; // XRay threshold attribute not found. if (ThresholdAttr.getValueAsString().getAsInteger(10, XRayThreshold)) return false; // Invalid value for threshold. - bool IgnoreLoops = !IgnoreLoopsAttr.hasAttribute(Attribute::None); + bool IgnoreLoops = !IgnoreLoopsAttr.isNone(); // Count the number of MachineInstr`s in MachineFunction int64_t MICount = 0; Index: llvm/lib/IR/Attributes.cpp =================================================================== --- llvm/lib/IR/Attributes.cpp +++ llvm/lib/IR/Attributes.cpp @@ -1089,7 +1089,7 @@ "Misordered Attributes list!"); assert(llvm::none_of(Attrs, [](const std::pair &Pair) { - return Pair.second.hasAttribute(Attribute::None); + return Pair.second.isNone(); }) && "Pointless attribute!"); Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp +++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp @@ -331,10 +331,10 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -401,14 +401,14 @@ StringRef AMDGPUTargetMachine::getGPUName(const Function &F) const { Attribute GPUAttr = F.getFnAttribute("target-cpu"); - return GPUAttr.hasAttribute(Attribute::None) ? + return GPUAttr.isNone() ? getTargetCPU() : GPUAttr.getValueAsString(); } StringRef AMDGPUTargetMachine::getFeatureString(const Function &F) const { Attribute FSAttr = F.getFnAttribute("target-features"); - return FSAttr.hasAttribute(Attribute::None) ? + return FSAttr.isNone() ? getTargetFeatureString() : FSAttr.getValueAsString(); } Index: llvm/lib/Target/ARM/ARMTargetMachine.cpp =================================================================== --- llvm/lib/Target/ARM/ARMTargetMachine.cpp +++ llvm/lib/Target/ARM/ARMTargetMachine.cpp @@ -261,10 +261,10 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; Index: llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp +++ llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp @@ -235,10 +235,10 @@ Attribute FSAttr = FnAttrs.getAttribute(AttributeList::FunctionIndex, "target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; // Append the preexisting target features last, so that +mattr overrides Index: llvm/lib/Target/Mips/MipsTargetMachine.cpp =================================================================== --- llvm/lib/Target/Mips/MipsTargetMachine.cpp +++ llvm/lib/Target/Mips/MipsTargetMachine.cpp @@ -163,21 +163,21 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; bool hasMips16Attr = - !F.getFnAttribute("mips16").hasAttribute(Attribute::None); + !F.getFnAttribute("mips16").isNone(); bool hasNoMips16Attr = - !F.getFnAttribute("nomips16").hasAttribute(Attribute::None); + !F.getFnAttribute("nomips16").isNone(); bool HasMicroMipsAttr = - !F.getFnAttribute("micromips").hasAttribute(Attribute::None); + !F.getFnAttribute("micromips").isNone(); bool HasNoMicroMipsAttr = - !F.getFnAttribute("nomicromips").hasAttribute(Attribute::None); + !F.getFnAttribute("nomicromips").isNone(); // FIXME: This is related to the code below to reset the target options, // we need to know whether or not the soft float flag is set on the Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -316,10 +316,10 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; Index: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp +++ llvm/lib/Target/RISCV/RISCVTargetMachine.cpp @@ -77,10 +77,10 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; std::string Key = CPU + FS; Index: llvm/lib/Target/Sparc/SparcTargetMachine.cpp =================================================================== --- llvm/lib/Target/Sparc/SparcTargetMachine.cpp +++ llvm/lib/Target/Sparc/SparcTargetMachine.cpp @@ -111,10 +111,10 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; Index: llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp =================================================================== --- llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp +++ llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp @@ -171,10 +171,10 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -160,10 +160,10 @@ Attribute CPUAttr = F.getFnAttribute("target-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + std::string CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString().str() : TargetCPU; - std::string FS = !FSAttr.hasAttribute(Attribute::None) + std::string FS = !FSAttr.isNone() ? FSAttr.getValueAsString().str() : TargetFS; Index: llvm/lib/Target/X86/X86TargetMachine.cpp =================================================================== --- llvm/lib/Target/X86/X86TargetMachine.cpp +++ llvm/lib/Target/X86/X86TargetMachine.cpp @@ -236,13 +236,13 @@ Attribute TuneAttr = F.getFnAttribute("tune-cpu"); Attribute FSAttr = F.getFnAttribute("target-features"); - StringRef CPU = !CPUAttr.hasAttribute(Attribute::None) + StringRef CPU = !CPUAttr.isNone() ? CPUAttr.getValueAsString() : (StringRef)TargetCPU; - StringRef TuneCPU = !TuneAttr.hasAttribute(Attribute::None) + StringRef TuneCPU = !TuneAttr.isNone() ? TuneAttr.getValueAsString() : (StringRef)CPU; - StringRef FS = !FSAttr.hasAttribute(Attribute::None) + StringRef FS = !FSAttr.isNone() ? FSAttr.getValueAsString() : (StringRef)TargetFS; @@ -255,7 +255,7 @@ // Extract prefer-vector-width attribute. unsigned PreferVectorWidthOverride = 0; Attribute PreferVecWidthAttr = F.getFnAttribute("prefer-vector-width"); - if (!PreferVecWidthAttr.hasAttribute(Attribute::None)) { + if (!PreferVecWidthAttr.isNone()) { StringRef Val = PreferVecWidthAttr.getValueAsString(); unsigned Width; if (!Val.getAsInteger(0, Width)) { @@ -268,7 +268,7 @@ // Extract min-legal-vector-width attribute. unsigned RequiredVectorWidth = UINT32_MAX; Attribute MinLegalVecWidthAttr = F.getFnAttribute("min-legal-vector-width"); - if (!MinLegalVecWidthAttr.hasAttribute(Attribute::None)) { + if (!MinLegalVecWidthAttr.isNone()) { StringRef Val = MinLegalVecWidthAttr.getValueAsString(); unsigned Width; if (!Val.getAsInteger(0, Width)) { Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp =================================================================== --- llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -1326,7 +1326,7 @@ static bool isThumbFunction(Function *F, Triple::ArchType ModuleArch) { Attribute TFAttr = F->getFnAttribute("target-features"); - if (!TFAttr.hasAttribute(Attribute::None)) { + if (!TFAttr.isNone()) { SmallVector Features; TFAttr.getValueAsString().split(Features, ','); for (StringRef Feature : Features) { Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp =================================================================== --- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -1258,8 +1258,7 @@ // Jump tables are only profitable if the retpoline mitigation is enabled. Attribute FSAttr = CB.getCaller()->getFnAttribute("target-features"); - if (FSAttr.hasAttribute(Attribute::None) || - !FSAttr.getValueAsString().contains("+retpoline")) + if (FSAttr.isNone() || !FSAttr.getValueAsString().contains("+retpoline")) continue; if (RemarksEnabled)