Skip to content

Commit b0a46cb

Browse files
committed
Fixups
1 parent ae5834a commit b0a46cb

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,11 @@ def LLVM_TargetFeaturesAttr : LLVM_Attr<"TargetFeatures", "target_features"> {
960960
}];
961961

962962
let parameters = (ins
963-
ArrayRefOfSelfAllocationParameter<"TargetFeature", "">: $features);
963+
ArrayRefOfSelfAllocationParameter<"TargetFeature", "">:$features);
964964

965965
let builders = [
966-
TypeBuilder<(ins "::llvm::ArrayRef<TargetFeature>": $features)>,
967-
TypeBuilder<(ins "StringRef": $features)>
966+
TypeBuilder<(ins "::llvm::ArrayRef<TargetFeature>":$features)>,
967+
TypeBuilder<(ins "::llvm::StringRef":$features)>
968968
];
969969

970970
let extraClassDeclaration = [{
@@ -980,6 +980,11 @@ def LLVM_TargetFeaturesAttr : LLVM_Attr<"TargetFeatures", "target_features"> {
980980
/// Finds the target features on the parent FunctionOpInterface.
981981
/// Note: This assumes the attribute is called "target_features".
982982
static TargetFeaturesAttr featuresAt(Operation* op);
983+
984+
/// Canonical name for this attribute within MLIR.
985+
static constexpr StringLiteral attributeName() {
986+
return StringLiteral("target_features");
987+
}
983988
}];
984989

985990
let hasCustomAssemblyFormat = 1;

mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ TargetFeaturesAttr::get(MLIRContext *context,
218218
TargetFeaturesAttr TargetFeaturesAttr::get(MLIRContext *context,
219219
StringRef targetFeatures) {
220220
SmallVector<StringRef> features;
221-
StringRef{targetFeatures}.split(features, ',', /*MaxSplit=*/-1,
222-
/*KeepEmpty=*/false);
221+
targetFeatures.split(features, ',', /*MaxSplit=*/-1,
222+
/*KeepEmpty=*/false);
223223
return get(context, llvm::map_to_vector(features, [](StringRef feature) {
224224
return TargetFeature{feature};
225225
}));
@@ -234,21 +234,17 @@ bool TargetFeaturesAttr::contains(TargetFeature feature) const {
234234
}
235235

236236
std::string TargetFeaturesAttr::getFeaturesString() const {
237-
std::string features;
238-
bool first = true;
239-
for (TargetFeature feature : getFeatures()) {
240-
if (!first)
241-
features += ",";
242-
features += StringRef(feature);
243-
first = false;
244-
}
245-
return features;
237+
std::string featuresString;
238+
llvm::raw_string_ostream ss(featuresString);
239+
llvm::interleave(
240+
getFeatures(), ss, [&](auto &feature) { ss << StringRef(feature); }, ",");
241+
return ss.str();
246242
}
247243

248244
TargetFeaturesAttr TargetFeaturesAttr::featuresAt(Operation *op) {
249245
auto parentFunction = op->getParentOfType<FunctionOpInterface>();
250246
if (!parentFunction)
251247
return {};
252248
return parentFunction.getOperation()->getAttrOfType<TargetFeaturesAttr>(
253-
"target_features");
249+
attributeName());
254250
}

0 commit comments

Comments
 (0)