[clang] [clang] Lower _BitInt(129+) to a different type in LLVM IR (PR #91364)

Hassnaa Hamdi via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 5 04:37:04 PDT 2024


================
@@ -118,6 +124,37 @@ llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T, bool ForBitField) {
   return R;
 }
 
+bool CodeGenTypes::LLVMTypeLayoutMatchesAST(QualType ASTTy,
+                                            llvm::Type *LLVMTy) {
+  CharUnits ASTSize = Context.getTypeSizeInChars(ASTTy);
+  CharUnits LLVMSize =
+      CharUnits::fromQuantity(getDataLayout().getTypeAllocSize(LLVMTy));
+  return ASTSize == LLVMSize;
+}
+
+llvm::Type *CodeGenTypes::convertTypeForLoadStore(QualType T,
+                                                  llvm::Type *LLVMTy) {
+  if (!LLVMTy)
+    LLVMTy = ConvertType(T);
+
+  if (!T->isBitIntType() && LLVMTy->isIntegerTy(1))
+    return llvm::IntegerType::get(getLLVMContext(),
+                                  (unsigned)Context.getTypeSize(T));
+
+  if (T->isBitIntType()) {
+    llvm::Type *R = ConvertType(T);
+    if (!LLVMTypeLayoutMatchesAST(T, R))
+      return llvm::Type::getIntNTy(
+          getLLVMContext(), Context.getTypeSizeInChars(T).getQuantity() * 8);
----------------
hassnaaHamdi wrote:

`return llvm::Type::getIntNTy(
          getLLVMContext(), Context.getTypeSizeInChars(T).getQuantity() * 8);`
Could you plz explain the logic behind using this implementation ? do you support all types > 128 and also types < 128 ? or it's specific to the types > 128 only ?

https://github.com/llvm/llvm-project/pull/91364


More information about the cfe-commits mailing list