Skip to content

Commit c4a68cc

Browse files
committed
Minor fixes
1 parent 45744cc commit c4a68cc

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ def LLVM_TargetAttr : LLVM_Attr<"Target", "target", [LLVM_TargetAttrInterface]>
2626
TODO
2727
}];
2828
let parameters = (ins "StringAttr":$triple,
29-
"StringAttr":$cpu,
30-
"TargetFeaturesAttr":$target_features);
29+
OptionalParameter<"StringAttr">:$chip,
30+
OptionalParameter<"TargetFeaturesAttr">:$features);
3131

32-
let assemblyFormat = "`<` $triple `,` $cpu `,` qualified($target_features) `>`";
32+
let assemblyFormat = [{`<` `triple` `=` $triple
33+
(`,` `chip` `=` $chip^)?
34+
(`,` qualified($features)^)? `>`}];
3335

3436
let extraClassDeclaration = [{
3537
std::optional<llvm::TargetMachine *> targetMachine = std::nullopt;

mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,15 @@ def LLVM_TargetAttrInterface
585585
/*args=*/(ins)
586586
>,
587587
InterfaceMethod<
588-
/*description=*/"Returns the target cpu identifier.",
588+
/*description=*/"Returns the target chip (i.e. \"cpu\") identifier.",
589589
/*retTy=*/"::llvm::StringRef",
590-
/*methodName=*/"getCpu",
590+
/*methodName=*/"getChip",
591591
/*args=*/(ins)
592592
>,
593593
InterfaceMethod<
594594
/*description=*/"Returns the target features as a string.",
595595
/*retTy=*/"::mlir::LLVM::TargetFeaturesAttr",
596-
/*methodName=*/"getTargetFeatures",
596+
/*methodName=*/"getFeatures",
597597
/*args=*/(ins)
598598
>,
599599
InterfaceMethod<

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ FailureOr<llvm::TargetMachine *> TargetAttr::getTargetMachine() {
433433
std::string error;
434434
const llvm::Target *target =
435435
llvm::TargetRegistry::lookupTarget(getTriple(), error);
436-
if (!error.empty()) {
436+
if (!target || !error.empty()) {
437437
LLVM_DEBUG({
438438
llvm::dbgs() << "Failed to retrieve the target with: `" << error << "`\n";
439439
});
@@ -442,8 +442,8 @@ FailureOr<llvm::TargetMachine *> TargetAttr::getTargetMachine() {
442442
}
443443

444444
targetMachine = {target->createTargetMachine(
445-
llvm::Triple(getTriple().strref()), getCpu().strref(),
446-
getTargetFeatures().getFeaturesString().c_str(), {}, {})};
445+
llvm::Triple(getTriple().strref()), getChip() ? getChip().strref() : "",
446+
getFeatures() ? getFeatures().getFeaturesString() : "", {}, {})};
447447

448448
return {targetMachine.value()};
449449
}
@@ -467,13 +467,14 @@ FailureOr<llvm::DataLayout> TargetAttr::getDataLayout() {
467467
}
468468

469469
FailureOr<::mlir::Attribute> TargetAttr::query(DataLayoutEntryKey key) {
470+
Attribute result;
470471
if (auto stringAttrKey = dyn_cast<StringAttr>(key)) {
471472
if (stringAttrKey.getValue() == "triple")
472473
return getTriple();
473-
if (stringAttrKey.getValue() == "cpu")
474-
return getCpu();
475-
if (stringAttrKey.getValue() == "features")
476-
return getTargetFeatures();
474+
if (stringAttrKey.getValue() == "chip" && (result = getChip()))
475+
return result;
476+
if (stringAttrKey.getValue() == "features" && (result = getFeatures()))
477+
return result;
477478
}
478479

479480
return failure();

mlir/lib/Dialect/LLVMIR/Transforms/DataLayoutFromTarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct DataLayoutFromTargetPass
4040
mod->emitError() << "failed to obtain llvm::DataLayout from "
4141
<< targetAttr;
4242
passFailed = true;
43+
return;
4344
}
4445
auto dataLayoutAttr = DataLayoutAttr::get(
4546
&getContext(), dataLayout->getStringRepresentation());

0 commit comments

Comments
 (0)