[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 28 11:51:57 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>(
----------------
erichkeane wrote:
Its a shame this is such a manual list/sub-par interface here :/ it would be way neater if it was able to deduce these. *sigh*
That said, I think this is quite a bit of a nicer interface, so I'm ok with it.
https://github.com/llvm/llvm-project/pull/129293
More information about the cfe-commits
mailing list