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