MLIR 22.0.0git
TargetToDataLayout.cpp
Go to the documentation of this file.
1//===- TargetToDataLayout.cpp - extract data layout from TargetMachine ----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11
15
16namespace mlir {
17namespace LLVM {
18#define GEN_PASS_DEF_LLVMTARGETTODATALAYOUT
19#include "mlir/Target/LLVMIR/Transforms/Passes.h.inc"
20} // namespace LLVM
21} // namespace mlir
22
23using namespace mlir;
24
26 : public LLVM::impl::LLVMTargetToDataLayoutBase<TargetToDataLayoutPass> {
27 using LLVM::impl::LLVMTargetToDataLayoutBase<
28 TargetToDataLayoutPass>::LLVMTargetToDataLayoutBase;
29
30 void runOnOperation() override {
31 Operation *op = getOperation();
32
33 if (initializeLLVMTargets)
35
36 auto targetAttr = op->getAttrOfType<LLVM::TargetAttrInterface>(
37 LLVM::LLVMDialect::getTargetAttrName());
38 if (!targetAttr) {
39 op->emitError()
40 << "no TargetAttrInterface-implementing attribute at key \""
41 << LLVM::LLVMDialect::getTargetAttrName() << "\"";
42 return signalPassFailure();
43 }
44
45 FailureOr<llvm::DataLayout> dataLayout =
47 if (failed(dataLayout)) {
48 op->emitError() << "failed to obtain llvm::DataLayout for " << targetAttr;
49 return signalPassFailure();
50 }
51
52 DataLayoutSpecInterface dataLayoutSpec =
53 mlir::translateDataLayout(dataLayout.value(), &getContext());
54
55 if (auto existingDlSpec = op->getAttrOfType<DataLayoutSpecInterface>(
56 DLTIDialect::kDataLayoutAttrName)) {
57 dataLayoutSpec = existingDlSpec.combineWith({dataLayoutSpec});
58 }
59
60 op->setAttr(DLTIDialect::kDataLayoutAttrName, dataLayoutSpec);
61 }
62};
b getContext())
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
AttrClass getAttrOfType(StringAttr name)
Definition Operation.h:550
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
Definition Operation.h:582
FailureOr< llvm::DataLayout > getDataLayout(mlir::LLVM::TargetAttrInterface attr)
Helper to obtain the DataLayout of the target specified by the properties of the TargetAttrInterface-...
void initializeBackendsOnce()
Idempotent helper to register/initialize all backends that LLVM has been configured to support.
Include the generated interface declarations.
DataLayoutSpecInterface translateDataLayout(const llvm::DataLayout &dataLayout, MLIRContext *context)
Translate the given LLVM data layout into an MLIR equivalent using the DLTI dialect.