[Mlir-commits] [flang] [mlir] [MLIR][LLVMIR][DLTI] Add #llvm.target, #llvm.data_layout and TargetAttrInterface (PR #145899)

Rolf Morel llvmlistbot at llvm.org
Fri Jul 25 11:02:14 PDT 2025


================
@@ -0,0 +1,89 @@
+//===- Target.cpp - MLIR LLVM target interface impls ------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Target/LLVM/Target.h"
+#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
+
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+#include "llvm/Target/TargetMachine.h"
+
+#define DEBUG_TYPE "llvm-target"
+
+using namespace mlir;
+
+namespace {
+class LLVMTargetAttrImpl
+    : public LLVM::TargetAttrInterface::FallbackModel<LLVMTargetAttrImpl> {
+public:
+  FailureOr<std::unique_ptr<llvm::TargetMachine>>
+  getTargetMachine(Attribute attribute) const {
+    auto attr = llvm::cast<LLVM::TargetAttr>(attribute);
+
+    llvm::InitializeAllTargets();
+    llvm::InitializeAllTargetMCs();
+
----------------
rolfmorel wrote:

My understanding is that this is like tools like `mlir-opt` registering all the dialects and their extensions:
https://github.com/llvm/llvm-project/blob/ef98e248c7740fb882b256dd325d22a057de1951/llvm/include/llvm/Support/TargetSelect.h#L58-L89

If you have a concrete suggestion for how to "initialize" just the relevant backends, I am all ears.

https://github.com/llvm/llvm-project/pull/145899


More information about the Mlir-commits mailing list