@@ -112,6 +112,14 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
112
112
openMPRuntime (new CIRGenOpenMPRuntime(*this )),
113
113
cudaRuntime(new CIRGenCUDARuntime(*this )) {
114
114
115
+ unsigned charSize = astContext.getTargetInfo ().getCharWidth ();
116
+ unsigned intSize = astContext.getTargetInfo ().getIntWidth ();
117
+ unsigned sizeTypeSize = astContext.getTargetInfo ().getMaxPointerWidth ();
118
+
119
+ auto typeSizeInfo = cir::TypeSizesInfoAttr::get (&mlirContext, charSize,
120
+ intSize, sizeTypeSize);
121
+ theModule->setAttr (cir::CIRDialect::getTypeSizesInfoAttrName (), typeSizeInfo);
122
+
115
123
// Initialize CIR signed integer types cache.
116
124
SInt8Ty = cir::IntType::get (&getMLIRContext (), 8 , /* isSigned=*/ true );
117
125
SInt16Ty = cir::IntType::get (&getMLIRContext (), 16 , /* isSigned=*/ true );
@@ -146,19 +154,13 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
146
154
astContext.getTargetInfo ().getPointerAlign (LangAS::Default))
147
155
.getQuantity ();
148
156
SizeSizeInBytes =
149
- astContext
150
- .toCharUnitsFromBits (astContext.getTargetInfo ().getMaxPointerWidth ())
157
+ astContext.toCharUnitsFromBits (typeSizeInfo.getSizeTypeSize ())
151
158
.getQuantity ();
152
159
// TODO: IntAlignInBytes
153
- UCharTy = cir::IntType::get (&getMLIRContext (),
154
- astContext.getTargetInfo ().getCharWidth (),
155
- /* isSigned=*/ false );
156
- UIntTy = cir::IntType::get (&getMLIRContext (),
157
- astContext.getTargetInfo ().getIntWidth (),
158
- /* isSigned=*/ false );
159
- UIntPtrTy = cir::IntType::get (&getMLIRContext (),
160
- astContext.getTargetInfo ().getMaxPointerWidth (),
161
- /* isSigned=*/ false );
160
+ UCharTy = typeSizeInfo.getUCharType (&getMLIRContext ());
161
+ UIntTy = typeSizeInfo.getUIntType (&getMLIRContext ());
162
+ // In CIRGenTypeCache, UIntPtrTy and SizeType are fields of the same union
163
+ UIntPtrTy = typeSizeInfo.getSizeType (&getMLIRContext ());
162
164
UInt8PtrTy = builder.getPointerTo (UInt8Ty);
163
165
UInt8PtrPtrTy = builder.getPointerTo (UInt8PtrTy);
164
166
AllocaInt8PtrTy = UInt8PtrTy;
@@ -167,9 +169,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
167
169
// TODO: ConstGlobalsPtrTy
168
170
CIRAllocaAddressSpace = getTargetCIRGenInfo ().getCIRAllocaAddressSpace ();
169
171
170
- PtrDiffTy = cir::IntType::get (&getMLIRContext (),
171
- astContext.getTargetInfo ().getMaxPointerWidth (),
172
- /* isSigned=*/ true );
172
+ PtrDiffTy = typeSizeInfo.getPtrDiffType (&getMLIRContext ());
173
173
174
174
if (langOpts.OpenCL ) {
175
175
createOpenCLRuntime ();
@@ -197,6 +197,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
197
197
cir::LangAttr::get (&mlirContext, lang));
198
198
theModule->setAttr (cir::CIRDialect::getTripleAttrName (),
199
199
builder.getStringAttr (getTriple ().str ()));
200
+
200
201
if (CGO.OptimizationLevel > 0 || CGO.OptimizeSize > 0 )
201
202
theModule->setAttr (cir::CIRDialect::getOptInfoAttrName (),
202
203
cir::OptInfoAttr::get (&mlirContext,
0 commit comments