[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 28 13:05:20 PST 2025


================
@@ -37,63 +37,78 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor<CIRAttrToValue, mlir::Value> {
+class CIRAttrToValue {
 public:
   CIRAttrToValue(mlir::Operation *parentOp,
                  mlir::ConversionPatternRewriter &rewriter,
                  const mlir::TypeConverter *converter)
       : parentOp(parentOp), rewriter(rewriter), converter(converter) {}
 
-  mlir::Value lowerCirAttrAsValue(mlir::Attribute attr) { return visit(attr); }
-
-  mlir::Value visitCirIntAttr(cir::IntAttr intAttr) {
-    mlir::Location loc = parentOp->getLoc();
-    return rewriter.create<mlir::LLVM::ConstantOp>(
-        loc, converter->convertType(intAttr.getType()), intAttr.getValue());
-  }
-
-  mlir::Value visitCirFPAttr(cir::FPAttr fltAttr) {
-    mlir::Location loc = parentOp->getLoc();
-    return rewriter.create<mlir::LLVM::ConstantOp>(
-        loc, converter->convertType(fltAttr.getType()), fltAttr.getValue());
+  mlir::Value visit(mlir::Attribute attr) {
+    return llvm::TypeSwitch<mlir::Attribute, mlir::Value>(attr)
+        .Case<cir::IntAttr, cir::FPAttr, cir::ConstPtrAttr>(
----------------
andykaylor wrote:

I think it needs to be a manual list because it's never going to be the complete list. These are just the types we intend to handle here, with other types going to the Default() handler.

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


More information about the cfe-commits mailing list