[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

Philip Reames via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 19 09:35:08 PDT 2024


================
@@ -14266,6 +14277,71 @@ CodeGenFunction::EmitAArch64CpuSupports(ArrayRef<StringRef> FeaturesStrs) {
   return Result;
 }
 
+Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef<StringRef> FeaturesStrs,
+                                             unsigned &MaxGroupIDUsed) {
+
+  const unsigned FeatureBitSize = llvm::RISCV::RISCVFeatureBitSize;
+  llvm::ArrayType *ArrayOfInt64Ty =
+      llvm::ArrayType::get(Int64Ty, FeatureBitSize);
+  llvm::Type *StructTy = llvm::StructType::get(Int32Ty, ArrayOfInt64Ty);
+  llvm::Constant *RISCVFeaturesBits =
+      CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits");
+  cast<llvm::GlobalValue>(RISCVFeaturesBits)->setDSOLocal(true);
+
+  auto LoadFeatureBit = [&](unsigned Index) {
+    // Create GEP then load.
+    Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
+    llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
+                                 IndexVal};
+    Value *Ptr =
+        Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
+    Value *FeaturesBit =
+        Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8));
+    return FeaturesBit;
+  };
+
+  SmallVector<uint64_t> RequireFeatureBits =
----------------
preames wrote:

The naming here is quite confusing.  This structure is not a list of bits.  It's a single bitmask for which we do a single comparison.  See other comments about false generality.  

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


More information about the cfe-commits mailing list