sdesmalen created this revision.
sdesmalen added reviewers: rsandifo-arm, rovka, rjmccall, efriedma.
Herald added subscribers: llvm-commits, psnobl, rkruppe, hiraditya, 
kristof.beyls, tschuett.
Herald added projects: clang, LLVM.

This patch adds codegen support for the ACLE builtin types added in:

  https://reviews.llvm.org/D62960

so that the ACLE builtin types are emitted as corresponding scalable
vector types in LLVM.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74724

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/CodeGen/aarch64-sve.c
  llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -226,7 +226,8 @@
   if (FrameIndices.find(&AI) != FrameIndices.end())
     return FrameIndices[&AI];
 
-  uint64_t ElementSize = DL->getTypeAllocSize(AI.getAllocatedType());
+  uint64_t ElementSize =
+      DL->getTypeAllocSize(AI.getAllocatedType()).getKnownMinSize();
   uint64_t Size =
       ElementSize * cast<ConstantInt>(AI.getArraySize())->getZExtValue();
 
Index: clang/test/CodeGen/aarch64-sve.c
===================================================================
--- clang/test/CodeGen/aarch64-sve.c
+++ clang/test/CodeGen/aarch64-sve.c
@@ -1,9 +1,51 @@
 // RUN: not %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve \
-// RUN:  -emit-llvm -o - %s -debug-info-kind=limited 2>&1 | FileCheck %s
+// RUN:  -emit-llvm -o - %s -debug-info-kind=limited 2>&1 | FileCheck %s -check-prefix=CHECK-DEBUG
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN:  -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefix=CHECK
 
-// Placeholder test for SVE types
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVInt8_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVInt16_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVInt32_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVInt64_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVUint8_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVUint16_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVUint32_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVUint64_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVFloat16_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVFloat32_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVFloat64_t'
+// CHECK-DEBUG: cannot yet generate debug info for SVE type '__SVBool_t'
 
-// CHECK: cannot yet generate code for SVE type '__SVInt8_t'
-// CHECK: cannot yet generate debug info for SVE type '__SVInt8_t'
+// CHECK: @ptr = common global <vscale x 16 x i8>* null, align 8
+// CHECK: %s8 = alloca <vscale x 16 x i8>, align 16
+// CHECK: %s16 = alloca <vscale x 8 x i16>, align 16
+// CHECK: %s32 = alloca <vscale x 4 x i32>, align 16
+// CHECK: %s64 = alloca <vscale x 2 x i64>, align 16
+// CHECK: %u8 = alloca <vscale x 16 x i8>, align 16
+// CHECK: %u16 = alloca <vscale x 8 x i16>, align 16
+// CHECK: %u32 = alloca <vscale x 4 x i32>, align 16
+// CHECK: %u64 = alloca <vscale x 2 x i64>, align 16
+// CHECK: %f16 = alloca <vscale x 8 x half>, align 16
+// CHECK: %f32 = alloca <vscale x 4 x float>, align 16
+// CHECK: %f64 = alloca <vscale x 2 x double>, align 16
+// CHECK: %b8 = alloca <vscale x 16 x i1>, align 2
 
 __SVInt8_t *ptr;
+
+void test_locals(void) {
+  __SVInt8_t s8;
+  __SVInt16_t s16;
+  __SVInt32_t s32;
+  __SVInt64_t s64;
+
+  __SVUint8_t u8;
+  __SVUint16_t u16;
+  __SVUint32_t u32;
+  __SVUint64_t u64;
+
+  __SVFloat16_t f16;
+  __SVFloat32_t f32;
+  __SVFloat64_t f64;
+
+  __SVBool_t b8;
+}
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -377,6 +377,48 @@
   return ResultType;
 }
 
+static llvm::Type *getSVEType(ASTContext &Ctx, llvm::LLVMContext &LLVMCtx,
+                              BuiltinType::Kind K) {
+  switch (K) {
+  case BuiltinType::SveInt8:
+  case BuiltinType::SveUint8:
+    return llvm::VectorType::get(llvm::IntegerType::get(LLVMCtx, 8),
+                                 {16, true});
+  case BuiltinType::SveInt16:
+  case BuiltinType::SveUint16:
+    return llvm::VectorType::get(llvm::IntegerType::get(LLVMCtx, 16),
+                                 {8, true});
+  case BuiltinType::SveInt32:
+  case BuiltinType::SveUint32:
+    return llvm::VectorType::get(llvm::IntegerType::get(LLVMCtx, 32),
+                                 {4, true});
+  case BuiltinType::SveInt64:
+  case BuiltinType::SveUint64:
+    return llvm::VectorType::get(llvm::IntegerType::get(LLVMCtx, 64),
+                                 {2, true});
+  case BuiltinType::SveFloat16:
+    return llvm::VectorType::get(
+        getTypeForFormat(LLVMCtx, Ctx.getFloatTypeSemantics(Ctx.HalfTy),
+                         /* UseNativeHalf = */ true),
+        {8, true});
+  case BuiltinType::SveFloat32:
+    return llvm::VectorType::get(
+        getTypeForFormat(LLVMCtx, Ctx.getFloatTypeSemantics(Ctx.FloatTy),
+                         /* UseNativeHalf = */ false),
+        {4, true});
+  case BuiltinType::SveFloat64:
+    return llvm::VectorType::get(
+        getTypeForFormat(LLVMCtx, Ctx.getFloatTypeSemantics(Ctx.DoubleTy),
+                         /* UseNativeHalf = */ false),
+        {2, true});
+  case BuiltinType::SveBool:
+    return llvm::VectorType::get(llvm::IntegerType::get(LLVMCtx, 1),
+                                 {16, true});
+  default:
+    break;
+  }
+  return nullptr;
+}
 /// ConvertType - Convert the specified type to its LLVM form.
 llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   T = Context.getCanonicalType(T);
@@ -511,23 +553,22 @@
     case BuiltinType::OCLReserveID:
       ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
       break;
-
-    // TODO: real CodeGen support for SVE types requires more infrastructure
-    // to be added first.  Report an error until then.
-#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#define SVE_TYPE(Name, Id, SingletonId) \
+    case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
-    {
-      unsigned DiagID = CGM.getDiags().getCustomDiagID(
-          DiagnosticsEngine::Error,
-          "cannot yet generate code for SVE type '%0'");
-      auto *BT = cast<BuiltinType>(Ty);
-      auto Name = BT->getName(CGM.getContext().getPrintingPolicy());
-      CGM.getDiags().Report(DiagID) << Name;
-      // Return something safe.
-      ResultType = llvm::IntegerType::get(getLLVMContext(), 32);
-      break;
+      ResultType = getSVEType(getContext(), getLLVMContext(),
+                              cast<BuiltinType>(Ty)->getKind());
+      if (!ResultType) {
+        unsigned DiagID = CGM.getDiags().getCustomDiagID(
+            DiagnosticsEngine::Error,
+            "cannot yet generate code for SVE type '%0'");
+        auto *BT = cast<BuiltinType>(Ty);
+        auto Name = BT->getName(CGM.getContext().getPrintingPolicy());
+        CGM.getDiags().Report(DiagID) << Name;
+        // Return something safe.
+        ResultType = llvm::IntegerType::get(getLLVMContext(), 32);
     }
-
+    break;
     case BuiltinType::Dependent:
 #define BUILTIN_TYPE(Id, SingletonId)
 #define PLACEHOLDER_TYPE(Id, SingletonId) \
Index: clang/lib/CodeGen/CGDecl.cpp
===================================================================
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1517,9 +1517,12 @@
         // is rare.
         if (!Bypasses.IsBypassed(&D) &&
             !(!getLangOpts().CPlusPlus && hasLabelBeenSeenInCurrentScope())) {
-          uint64_t size = CGM.getDataLayout().getTypeAllocSize(allocaTy);
+          llvm::TypeSize size =
+              CGM.getDataLayout().getTypeAllocSize(allocaTy);
           emission.SizeForLifetimeMarkers =
-              EmitLifetimeStart(size, AllocaAddr.getPointer());
+              size.isScalable() ? EmitLifetimeStart(-1, AllocaAddr.getPointer())
+                                : EmitLifetimeStart(size.getFixedSize(),
+                                                    AllocaAddr.getPointer());
         }
       } else {
         assert(!emission.useLifetimeMarkers());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to