[flang-commits] [flang] [mlir] [MLIR][LLVMIR][DLTI] Add #llvm.target, #llvm.data_layout and TargetAttrInterface (PR #145899)
Renato Golin via flang-commits
flang-commits at lists.llvm.org
Tue Aug 5 04:12:42 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();
+
----------------
rengolin wrote:
Do you mean one macro per target? That sounds convoluted and error prone.
If we only have two options: `init-all` or `init-none`, then another tool can opt for `init-none` and do its own initialization.
https://github.com/llvm/llvm-project/pull/145899
More information about the flang-commits
mailing list