|
1 | 1 | #include "clang/CIR/Dialect/IR/CIRDataLayout.h" |
| 2 | +#include "clang/CIR/Dialect/IR/CIRDialect.h" |
2 | 3 | #include "clang/CIR/Dialect/IR/CIRTypes.h" |
3 | 4 | #include "clang/CIR/MissingFeatures.h" |
4 | 5 | #include "llvm/IR/DataLayout.h" |
@@ -112,6 +113,12 @@ class StructLayoutMap { |
112 | 113 |
|
113 | 114 | CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} { |
114 | 115 | reset(modOp.getDataLayoutSpec()); |
| 116 | + |
| 117 | + if (auto attr = modOp->getAttr(cir::CIRDialect::getTypeSizesAttrName())) { |
| 118 | + auto typeSizeAttr = mlir::cast<cir::TypeSizesAttr>(attr); |
| 119 | + intSize = typeSizeAttr.getIntSize(); |
| 120 | + sizeTypeSize = typeSizeAttr.getSizeTypeSize(); |
| 121 | + } |
115 | 122 | } |
116 | 123 |
|
117 | 124 | void CIRDataLayout::reset(mlir::DataLayoutSpecInterface spec) { |
@@ -220,3 +227,15 @@ llvm::TypeSize CIRDataLayout::getTypeSizeInBits(mlir::Type Ty) const { |
220 | 227 |
|
221 | 228 | return llvm::TypeSize::getFixed(layout.getTypeSizeInBits(Ty)); |
222 | 229 | } |
| 230 | + |
| 231 | +mlir::Type CIRDataLayout::getPtrDiffType(mlir::MLIRContext *ctx) const { |
| 232 | + return cir::IntType::get(ctx, sizeTypeSize, /*signed=*/true); |
| 233 | +} |
| 234 | + |
| 235 | +mlir::Type CIRDataLayout::getSizeType(mlir::MLIRContext *ctx) const { |
| 236 | + return cir::IntType::get(ctx, sizeTypeSize, /*signed=*/false); |
| 237 | +} |
| 238 | + |
| 239 | +mlir::Type CIRDataLayout::getIntType(mlir::MLIRContext *ctx) const { |
| 240 | + return cir::IntType::get(ctx, intSize, /*signed=*/true); |
| 241 | +} |
0 commit comments