@@ -112,6 +112,14 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
112112 openMPRuntime (new CIRGenOpenMPRuntime(*this )),
113113 cudaRuntime(new CIRGenCUDARuntime(*this )) {
114114
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+
115123 // Initialize CIR signed integer types cache.
116124 SInt8Ty = cir::IntType::get (&getMLIRContext (), 8 , /* isSigned=*/ true );
117125 SInt16Ty = cir::IntType::get (&getMLIRContext (), 16 , /* isSigned=*/ true );
@@ -146,19 +154,13 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
146154 astContext.getTargetInfo ().getPointerAlign (LangAS::Default))
147155 .getQuantity ();
148156 SizeSizeInBytes =
149- astContext
150- .toCharUnitsFromBits (astContext.getTargetInfo ().getMaxPointerWidth ())
157+ astContext.toCharUnitsFromBits (typeSizeInfo.getSizeTypeSize ())
151158 .getQuantity ();
152159 // 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 ());
162164 UInt8PtrTy = builder.getPointerTo (UInt8Ty);
163165 UInt8PtrPtrTy = builder.getPointerTo (UInt8PtrTy);
164166 AllocaInt8PtrTy = UInt8PtrTy;
@@ -167,9 +169,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
167169 // TODO: ConstGlobalsPtrTy
168170 CIRAllocaAddressSpace = getTargetCIRGenInfo ().getCIRAllocaAddressSpace ();
169171
170- PtrDiffTy = cir::IntType::get (&getMLIRContext (),
171- astContext.getTargetInfo ().getMaxPointerWidth (),
172- /* isSigned=*/ true );
172+ PtrDiffTy = typeSizeInfo.getPtrDiffType (&getMLIRContext ());
173173
174174 if (langOpts.OpenCL ) {
175175 createOpenCLRuntime ();
@@ -197,6 +197,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
197197 cir::LangAttr::get (&mlirContext, lang));
198198 theModule->setAttr (cir::CIRDialect::getTripleAttrName (),
199199 builder.getStringAttr (getTriple ().str ()));
200+
200201 if (CGO.OptimizationLevel > 0 || CGO.OptimizeSize > 0 )
201202 theModule->setAttr (cir::CIRDialect::getOptInfoAttrName (),
202203 cir::OptInfoAttr::get (&mlirContext,
0 commit comments