================
@@ -0,0 +1,150 @@
+//====- LoweringHelpers.cpp - Lowering helper functions 
-------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains helper functions for lowering from CIR to LLVM or MLIR.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/CIR/LoweringHelpers.h"
+
+mlir::DenseElementsAttr
+convertStringAttrToDenseElementsAttr(cir::ConstArrayAttr attr,
+                                     mlir::Type type) {
+  auto values = llvm::SmallVector<mlir::APInt, 8>{};
+  const auto stringAttr = mlir::dyn_cast<mlir::StringAttr>(attr.getElts());
+  assert(stringAttr && "expected string attribute here");
+
+  for (auto element : stringAttr)
+    values.push_back({8, (uint64_t)element});
+
+  const auto arrayTy = mlir::dyn_cast<cir::ArrayType>(attr.getType());
+  assert(arrayTy && "String attribute must have an array type");
+  if (arrayTy.getSize() != stringAttr.size())
+    llvm_unreachable("array type of the length not equal to that of the string 
"
----------------
andykaylor wrote:

I'm not suggesting `errorNYI`. I'm suggesting `op.emitError()`. We can't do 
that here either, but maybe we could do it in the function from which this is 
called?

https://github.com/llvm/llvm-project/pull/132974
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to