[clang] [AArch64][Clang] Refactor code to emit SVE & SME builtins (PR #70662)

Sander de Smalen via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 31 09:58:08 PDT 2023


================
@@ -9924,12 +9917,56 @@ Value *CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
       // immediate requires more than a handful of bits.
       *Result = Result->extOrTrunc(32);
       Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), *Result));
+      continue;
+    }
+
+    if (IsTupleGetOrSet) {
+      Ops.push_back(EmitScalarExpr(E->getArg(i)));
+      continue;
     }
+
+    if (!isa<ScalableVectorType>(Arg->getType())) {
+      Ops.push_back(Arg);
+      continue;
+    }
+
+    auto *VTy = cast<ScalableVectorType>(Arg->getType());
+    unsigned MinElts = VTy->getMinNumElements();
+    bool IsPred = VTy->getElementType()->isIntegerTy(1);
+    unsigned N = (MinElts * VTy->getScalarSizeInBits()) / (IsPred ? 16 : 128);
+
+    if (N == 1) {
+      Ops.push_back(Arg);
+      continue;
+    }
+
+    for (unsigned I = 0; I < N; ++I) {
+      Value *Idx = ConstantInt::get(CGM.Int64Ty, (I * MinElts) / N);
+      auto *NewVTy =
+          ScalableVectorType::get(VTy->getElementType(), MinElts / N);
+      Ops.push_back(Builder.CreateExtractVector(NewVTy, Arg, Idx));
+    }
+  }
+
+  return;
----------------
sdesmalen-arm wrote:

`return` is unnecessary for a function returning `void`.

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


More information about the cfe-commits mailing list