Files
TheRock/compiler/amd-llvm/clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

61 lines
2.6 KiB
C++

#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "clang/CIR/MissingFeatures.h"
using namespace cir;
//===----------------------------------------------------------------------===//
// DataLayout Class Implementation
//===----------------------------------------------------------------------===//
CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout(modOp) {
reset(modOp.getDataLayoutSpec());
}
void CIRDataLayout::reset(mlir::DataLayoutSpecInterface spec) {
bigEndian = false;
if (spec) {
mlir::StringAttr key = mlir::StringAttr::get(
spec.getContext(), mlir::DLTIDialect::kDataLayoutEndiannessKey);
if (mlir::DataLayoutEntryInterface entry = spec.getSpecForIdentifier(key))
if (auto str = llvm::dyn_cast<mlir::StringAttr>(entry.getValue()))
bigEndian = str == mlir::DLTIDialect::kDataLayoutEndiannessBig;
mlir::StringAttr addrSpKey = mlir::StringAttr::get(
spec.getContext(), mlir::DLTIDialect::kDataLayoutProgramMemorySpaceKey);
if (mlir::DataLayoutEntryInterface entry =
spec.getSpecForIdentifier(addrSpKey))
if (auto val = llvm::dyn_cast<mlir::IntegerAttr>(entry.getValue()))
programAddrSpace = val.getInt();
}
}
llvm::Align CIRDataLayout::getAlignment(mlir::Type ty, bool useABIAlign) const {
// FIXME(cir): This does not account for differnt address spaces, and relies
// on CIR's data layout to give the proper alignment.
assert(!cir::MissingFeatures::addressSpace());
// Fetch type alignment from MLIR's data layout.
unsigned align = useABIAlign ? layout.getTypeABIAlignment(ty)
: layout.getTypePreferredAlignment(ty);
return llvm::Align(align);
}
// The implementation of this method is provided inline as it is particularly
// well suited to constant folding when called on a specific Type subclass.
llvm::TypeSize CIRDataLayout::getTypeSizeInBits(mlir::Type ty) const {
assert(cir::isSized(ty) && "Cannot getTypeInfo() on a type that is unsized!");
if (auto structTy = llvm::dyn_cast<cir::StructType>(ty))
return structTy.getTypeSizeInBits(layout, {});
if (auto unionTy = llvm::dyn_cast<cir::UnionType>(ty))
return unionTy.getTypeSizeInBits(layout, {});
// FIXME(cir): This does not account for different address spaces, and relies
// on CIR's data layout to give the proper ABI-specific type width.
assert(!cir::MissingFeatures::addressSpace());
// This is calling mlir::DataLayout::getTypeSizeInBits().
return llvm::TypeSize::getFixed(layout.getTypeSizeInBits(ty));
}