clang 24.0.0git
CIRDataLayoutSpec.cpp
Go to the documentation of this file.
1//===--- CIRDataLayoutSpec.cpp - DLTI data layout for CIR modules ---------===//
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//
9// This file attaches the DLTI data-layout spec, including the CIR-native
10// pointer entry, to a CIR module.
11//
12//===----------------------------------------------------------------------===//
13
15
16#include "mlir/Dialect/DLTI/DLTI.h"
17#include "mlir/IR/BuiltinOps.h"
18#include "mlir/Target/LLVMIR/Import.h"
19
23#include "llvm/IR/DataLayout.h"
24
25void cir::setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl) {
26 mlir::MLIRContext *mlirContext = mod.getContext();
27 mlir::DataLayoutSpecInterface dlSpec =
28 mlir::translateDataLayout(dl, mlirContext);
29
30 // Append the !cir.ptr-keyed #cir.ptr_spec entry.
31 // TODO(cir): only the default address space is recorded.
33 constexpr unsigned kBitsInByte = 8;
34 unsigned ptrSizeBits = dl.getPointerSizeInBits(/*AS=*/0);
35 unsigned ptrAbiBits =
36 dl.getPointerABIAlignment(/*AS=*/0).value() * kBitsInByte;
37 unsigned ptrPrefBits =
38 dl.getPointerPrefAlignment(/*AS=*/0).value() * kBitsInByte;
39 unsigned ptrIndexBits = dl.getIndexSizeInBits(/*AS=*/0);
40 auto ptrKey = cir::PointerType::get(cir::VoidType::get(mlirContext));
41 auto ptrSpec = cir::PtrSpecAttr::get(mlirContext, ptrSizeBits, ptrAbiBits,
42 ptrPrefBits, ptrIndexBits);
44 dlSpec.getEntries().begin(), dlSpec.getEntries().end());
45 entries.push_back(mlir::DataLayoutEntryAttr::get(ptrKey, ptrSpec));
46
47 mod->setAttr(mlir::DLTIDialect::kDataLayoutAttrName,
48 mlir::DataLayoutSpecAttr::get(mlirContext, entries));
49}
void setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl)
Translate dl into a DLTI data-layout spec and attach it to mod.
static bool dataLayoutPtrHandlingBasedOnLangAS()