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

Fabian Mora llvmlistbot at llvm.org
Fri Jul 25 13:46:52 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();
+
----------------
fabianmcg wrote:

Ok, I'd argue that a better approach would be having a target attribute for each LLVM target, that way only used targets get initialized.

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


More information about the Mlir-commits mailing list