|
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,14 @@ class StructLayoutMap { |
112 | 113 |
|
113 | 114 | CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} { |
114 | 115 | reset(modOp.getDataLayoutSpec()); |
| 116 | + |
| 117 | + auto intSizeAttr = mlir::cast<cir::IntSizeAttr>( |
| 118 | + modOp->getAttr(cir::CIRDialect::getIntSizeAttrName())); |
| 119 | + intSize = intSizeAttr.getSize(); |
| 120 | + |
| 121 | + auto sizeTypeSizeAttr = mlir::cast<cir::SizeTypeSizeAttr>( |
| 122 | + modOp->getAttr(cir::CIRDialect::getSizeTypeSizeAttrName())); |
| 123 | + sizeTypeSize = sizeTypeSizeAttr.getSize(); |
115 | 124 | } |
116 | 125 |
|
117 | 126 | void CIRDataLayout::reset(mlir::DataLayoutSpecInterface spec) { |
@@ -220,3 +229,15 @@ llvm::TypeSize CIRDataLayout::getTypeSizeInBits(mlir::Type Ty) const { |
220 | 229 |
|
221 | 230 | return llvm::TypeSize::getFixed(layout.getTypeSizeInBits(Ty)); |
222 | 231 | } |
| 232 | + |
| 233 | +mlir::Type CIRDataLayout::getPtrDiffType(mlir::MLIRContext *ctx) const { |
| 234 | + return cir::IntType::get(ctx, sizeTypeSize, /*signed=*/true); |
| 235 | +} |
| 236 | + |
| 237 | +mlir::Type CIRDataLayout::getSizeType(mlir::MLIRContext *ctx) const { |
| 238 | + return cir::IntType::get(ctx, sizeTypeSize, /*signed=*/false); |
| 239 | +} |
| 240 | + |
| 241 | +mlir::Type CIRDataLayout::getIntType(mlir::MLIRContext *ctx) const { |
| 242 | + return cir::IntType::get(ctx, intSize, /*signed=*/true); |
| 243 | +} |
0 commit comments