[flang-commits] [flang] [mlir] [MLIR][LLVMIR][DLTI] Add #llvm.target, #llvm.data_layout and TargetAttrInterface (PR #145899)
Rolf Morel via flang-commits
flang-commits at lists.llvm.org
Thu Jun 26 12:50:12 PDT 2025
================
@@ -404,3 +408,73 @@ ModuleFlagAttr::verify(function_ref<InFlightDiagnostic()> emitError,
"supported for unknown key '"
<< key << "'";
}
+
+FailureOr<Attribute> TargetFeaturesAttr::query(DataLayoutEntryKey key) {
+ if (auto stringKey = dyn_cast<StringAttr>(key))
+ if (contains(stringKey))
+ return UnitAttr::get(getContext());
+ return failure();
+}
+
+//===----------------------------------------------------------------------===//
+// LLVM_TargetAttr
+//===----------------------------------------------------------------------===//
+
+FailureOr<llvm::TargetMachine *> TargetAttr::getTargetMachine() {
+ if (targetMachine.has_value()) {
+ llvm::TargetMachine *tm = targetMachine.value();
+ if (tm != nullptr)
+ return {tm};
+ return failure();
+ }
+ llvm::InitializeAllTargets();
+ llvm::InitializeAllTargetMCs();
+
+ std::string error;
+ const llvm::Target *target =
+ llvm::TargetRegistry::lookupTarget(getTriple(), error);
+ if (!error.empty()) {
+ LLVM_DEBUG({
+ llvm::dbgs() << "Failed to retrieve the target with: `" << error << "`\n";
+ });
+ targetMachine = {nullptr};
+ return failure();
+ }
+
+ targetMachine = {target->createTargetMachine(
----------------
rolfmorel wrote:
Hopefully someone could help explain what the right way is to hang owned pointers off of an attribute.
Any and all pointers welcome!
https://github.com/llvm/llvm-project/pull/145899
More information about the flang-commits
mailing list