@@ -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 sizeTSize = astContext.getTargetInfo ().getMaxPointerWidth ();
118+
119+ auto typeSizeInfo =
120+ cir::TypeSizeInfoAttr::get (&mlirContext, charSize, intSize, sizeTSize);
121+ theModule->setAttr (cir::CIRDialect::getTypeSizeInfoAttrName (), 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,12 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
146154 astContext.getTargetInfo ().getPointerAlign (LangAS::Default))
147155 .getQuantity ();
148156 SizeSizeInBytes =
149- astContext
150- .toCharUnitsFromBits (astContext.getTargetInfo ().getMaxPointerWidth ())
151- .getQuantity ();
157+ astContext.toCharUnitsFromBits (typeSizeInfo.getSizeTSize ()).getQuantity ();
152158 // 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 );
159+ UCharTy = typeSizeInfo.getUCharType (&getMLIRContext ());
160+ UIntTy = typeSizeInfo.getUIntType (&getMLIRContext ());
161+ // In CIRGenTypeCache, UIntPtrTy and SizeType are fields of the same union
162+ UIntPtrTy = typeSizeInfo.getSizeType (&getMLIRContext ());
162163 UInt8PtrTy = builder.getPointerTo (UInt8Ty);
163164 UInt8PtrPtrTy = builder.getPointerTo (UInt8PtrTy);
164165 AllocaInt8PtrTy = UInt8PtrTy;
@@ -167,9 +168,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
167168 // TODO: ConstGlobalsPtrTy
168169 CIRAllocaAddressSpace = getTargetCIRGenInfo ().getCIRAllocaAddressSpace ();
169170
170- PtrDiffTy = cir::IntType::get (&getMLIRContext (),
171- astContext.getTargetInfo ().getMaxPointerWidth (),
172- /* isSigned=*/ true );
171+ PtrDiffTy = typeSizeInfo.getPtrDiffType (&getMLIRContext ());
173172
174173 if (langOpts.OpenCL ) {
175174 createOpenCLRuntime ();
@@ -197,6 +196,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
197196 cir::LangAttr::get (&mlirContext, lang));
198197 theModule->setAttr (cir::CIRDialect::getTripleAttrName (),
199198 builder.getStringAttr (getTriple ().str ()));
199+
200200 if (CGO.OptimizationLevel > 0 || CGO.OptimizeSize > 0 )
201201 theModule->setAttr (cir::CIRDialect::getOptInfoAttrName (),
202202 cir::OptInfoAttr::get (&mlirContext,
0 commit comments