@@ -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 sizeTSize = astContext.getTargetInfo ().getMaxPointerWidth ();
118
+
119
+ auto typeSizeInfo =
120
+ cir::TypeSizeInfoAttr::get (&mlirContext, charSize, intSize, sizeTSize);
121
+ theModule->setAttr (cir::CIRDialect::getTypeSizeInfoAttrName (), 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,12 @@ 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 ())
151
- .getQuantity ();
157
+ astContext.toCharUnitsFromBits (typeSizeInfo.getSizeTSize ()).getQuantity ();
152
158
// 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 ());
162
163
UInt8PtrTy = builder.getPointerTo (UInt8Ty);
163
164
UInt8PtrPtrTy = builder.getPointerTo (UInt8PtrTy);
164
165
AllocaInt8PtrTy = UInt8PtrTy;
@@ -167,9 +168,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
167
168
// TODO: ConstGlobalsPtrTy
168
169
CIRAllocaAddressSpace = getTargetCIRGenInfo ().getCIRAllocaAddressSpace ();
169
170
170
- PtrDiffTy = cir::IntType::get (&getMLIRContext (),
171
- astContext.getTargetInfo ().getMaxPointerWidth (),
172
- /* isSigned=*/ true );
171
+ PtrDiffTy = typeSizeInfo.getPtrDiffType (&getMLIRContext ());
173
172
174
173
if (langOpts.OpenCL ) {
175
174
createOpenCLRuntime ();
@@ -197,6 +196,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
197
196
cir::LangAttr::get (&mlirContext, lang));
198
197
theModule->setAttr (cir::CIRDialect::getTripleAttrName (),
199
198
builder.getStringAttr (getTriple ().str ()));
199
+
200
200
if (CGO.OptimizationLevel > 0 || CGO.OptimizeSize > 0 )
201
201
theModule->setAttr (cir::CIRDialect::getOptInfoAttrName (),
202
202
cir::OptInfoAttr::get (&mlirContext,
0 commit comments