[flang-commits] [flang] [mlir] [MLIR][LLVMIR][DLTI] Add `LLVM::TargetAttrInterface` and `#llvm.target` attr (PR #145899)
Rolf Morel via flang-commits
flang-commits at lists.llvm.org
Wed Aug 20 11:30:29 PDT 2025
================
@@ -0,0 +1,104 @@
+//===- TargetToDataLayout.cpp - extract data layout from TargetMachine ----===//
+//
+// 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/LLVMIR/Transforms/Passes.h"
+
+#include "mlir/Dialect/DLTI/DLTI.h"
+#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Target/LLVMIR/DataLayoutImporter.h"
+
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+#include "llvm/Target/TargetMachine.h"
+
+#define DEBUG_TYPE "mlir-llvm-target-to-data-layout"
+
+namespace mlir {
+namespace LLVM {
+#define GEN_PASS_DEF_LLVMTARGETTODATALAYOUT
+#include "mlir/Target/LLVMIR/Transforms/Passes.h.inc"
+} // namespace LLVM
+} // namespace mlir
+
+using namespace mlir;
+
+static FailureOr<std::unique_ptr<llvm::TargetMachine>>
+getTargetMachine(LLVM::TargetAttrInterface attr) {
+ StringRef triple = attr.getTripleAttr();
+ StringRef chipAKAcpu = attr.getChipAttr();
+ StringRef features =
+ attr.getFeaturesAttr() ? attr.getFeaturesAttr().getValue() : "";
+
+ std::string error;
+ const llvm::Target *target =
+ llvm::TargetRegistry::lookupTarget(triple, error);
+ if (!target || !error.empty()) {
+ LLVM_DEBUG({
+ llvm::dbgs() << "Looking up target '" << triple << "' failed: " << error
+ << "\n";
+ });
----------------
rolfmorel wrote:
Done.
https://github.com/llvm/llvm-project/pull/145899
More information about the flang-commits
mailing list