@@ -3263,33 +3263,28 @@ def Target : InheritableAttr {
32633263 let Subjects = SubjectList<[Function], ErrorDiag>;
32643264 let Documentation = [TargetDocs];
32653265 let AdditionalMembers = [{
3266- StringRef getArchitecture () const {
3266+ std::optional< StringRef> getX86Architecture () const {
32673267 StringRef Features = getFeaturesStr();
3268- if (Features == "default") return {};
3269-
3270- SmallVector<StringRef, 1> AttrFeatures;
3271- Features.split(AttrFeatures, ",");
3272-
3273- for (auto &Feature : AttrFeatures) {
3268+ SmallVector<StringRef, 4> AttrFeatures;
3269+ Features.split(AttrFeatures, ',');
3270+ for (StringRef Feature : AttrFeatures) {
32743271 Feature = Feature.trim();
32753272 if (Feature.starts_with("arch="))
32763273 return Feature.drop_front(sizeof("arch=") - 1);
32773274 }
3278- return "" ;
3275+ return std::nullopt ;
32793276 }
32803277
32813278 // Gets the list of features as simple string-refs with no +/- or 'no-'.
32823279 // Only adds the items to 'Out' that are additions.
3283- void getAddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
3280+ void getX86AddedFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
3281+ if (isDefaultVersion())
3282+ return;
32843283 StringRef Features = getFeaturesStr();
3285- if (Features == "default") return;
3286-
3287- SmallVector<StringRef, 1> AttrFeatures;
3288- Features.split(AttrFeatures, ",");
3289-
3284+ SmallVector<StringRef, 4> AttrFeatures;
3285+ Features.split(AttrFeatures, ',');
32903286 for (auto &Feature : AttrFeatures) {
32913287 Feature = Feature.trim();
3292-
32933288 if (!Feature.starts_with("no-") && !Feature.starts_with("arch=") &&
32943289 !Feature.starts_with("fpmath=") && !Feature.starts_with("tune="))
32953290 Out.push_back(Feature);
@@ -3307,17 +3302,17 @@ def TargetVersion : InheritableAttr, TargetSpecificAttr<TargetArch<!listconcat(T
33073302 let Documentation = [TargetVersionDocs];
33083303 let AdditionalMembers = [{
33093304 StringRef getName() const { return getNamesStr().trim(); }
3310- bool isDefaultVersion() const {
3311- return getName() == "default";
3312- }
3313- void getFeatures(llvm::SmallVectorImpl<StringRef> &Out) const {
3314- if (isDefaultVersion()) return;
3315- StringRef Features = getName();
33163305
3317- SmallVector<StringRef, 8> AttrFeatures;
3318- Features.split(AttrFeatures, "+");
3306+ bool isDefaultVersion() const { return getName() == "default"; }
33193307
3320- for (auto &Feature : AttrFeatures) {
3308+ void getFeatures(llvm::SmallVectorImpl<StringRef> &Out,
3309+ char Delim = '+') const {
3310+ if (isDefaultVersion())
3311+ return;
3312+ StringRef Features = getName();
3313+ SmallVector<StringRef, 4> AttrFeatures;
3314+ Features.split(AttrFeatures, Delim);
3315+ for (StringRef Feature : AttrFeatures) {
33213316 Feature = Feature.trim();
33223317 Out.push_back(Feature);
33233318 }
@@ -3334,20 +3329,40 @@ def TargetClones : InheritableAttr {
33343329 StringRef getFeatureStr(unsigned Index) const {
33353330 return *(featuresStrs_begin() + Index);
33363331 }
3332+
33373333 bool isDefaultVersion(unsigned Index) const {
33383334 return getFeatureStr(Index) == "default";
33393335 }
3336+
33403337 void getFeatures(llvm::SmallVectorImpl<StringRef> &Out,
3341- unsigned Index) const {
3342- if (isDefaultVersion(Index)) return;
3338+ unsigned Index, char Delim = '+') const {
3339+ if (isDefaultVersion(Index))
3340+ return;
33433341 StringRef Features = getFeatureStr(Index);
3344- SmallVector<StringRef, 8 > AttrFeatures;
3345- Features.split(AttrFeatures, "+" );
3346- for (auto & Feature : AttrFeatures) {
3342+ SmallVector<StringRef, 4 > AttrFeatures;
3343+ Features.split(AttrFeatures, Delim );
3344+ for (StringRef Feature : AttrFeatures) {
33473345 Feature = Feature.trim();
33483346 Out.push_back(Feature);
33493347 }
33503348 }
3349+
3350+ std::optional<StringRef> getX86Architecture(unsigned Index) const {
3351+ StringRef Feature = getFeatureStr(Index);
3352+ if (Feature.starts_with("arch="))
3353+ return Feature.drop_front(sizeof("arch=") - 1);
3354+ return std::nullopt;
3355+ }
3356+
3357+ void getX86Feature(llvm::SmallVectorImpl<StringRef> &Out,
3358+ unsigned Index) const {
3359+ if (isDefaultVersion(Index))
3360+ return;
3361+ if (getX86Architecture(Index))
3362+ return;
3363+ Out.push_back(getFeatureStr(Index));
3364+ }
3365+
33513366 // Given an index into the 'featuresStrs' sequence, compute a unique
33523367 // ID to be used with function name mangling for the associated variant.
33533368 // This mapping is necessary due to a requirement that the mangling ID
0 commit comments