41
41
#include " mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
42
42
#include " mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
43
43
#include " mlir/Target/LLVMIR/Export.h"
44
- #include " clang/CIR/Dialect/IR/CIRAttrVisitor.h"
45
44
#include " clang/CIR/Dialect/Passes.h"
46
45
#include " clang/CIR/LoweringHelpers.h"
47
46
#include " clang/CIR/MissingFeatures.h"
52
51
#include " llvm/ADT/SmallVector.h"
53
52
#include " llvm/ADT/StringRef.h"
54
53
#include " llvm/ADT/Twine.h"
54
+ #include " llvm/ADT/TypeSwitch.h"
55
55
#include " llvm/IR/DataLayout.h"
56
56
#include " llvm/IR/DerivedTypes.h"
57
57
#include " llvm/Support/Casting.h"
@@ -426,7 +426,7 @@ emitCirAttrToMemory(mlir::Operation *parentOp, mlir::Attribute attr,
426
426
}
427
427
428
428
// / Switches on the type of attribute and calls the appropriate conversion.
429
- class CirAttrToValue : public CirAttrVisitor <CirAttrToValue, mlir::Value> {
429
+ class CirAttrToValue {
430
430
public:
431
431
CirAttrToValue (mlir::Operation *parentOp,
432
432
mlir::ConversionPatternRewriter &rewriter,
@@ -435,19 +435,29 @@ class CirAttrToValue : public CirAttrVisitor<CirAttrToValue, mlir::Value> {
435
435
: parentOp(parentOp), rewriter(rewriter), converter(converter),
436
436
dataLayout (dataLayout) {}
437
437
438
- mlir::Value visitCirIntAttr (cir::IntAttr attr);
439
- mlir::Value visitCirFPAttr (cir::FPAttr attr);
440
- mlir::Value visitCirConstPtrAttr (cir::ConstPtrAttr attr);
441
- mlir::Value visitCirConstStructAttr (cir::ConstStructAttr attr);
442
- mlir::Value visitCirConstArrayAttr (cir::ConstArrayAttr attr);
443
- mlir::Value visitCirConstVectorAttr (cir::ConstVectorAttr attr);
444
- mlir::Value visitCirBoolAttr (cir::BoolAttr attr);
445
- mlir::Value visitCirZeroAttr (cir::ZeroAttr attr);
446
- mlir::Value visitCirUndefAttr (cir::UndefAttr attr);
447
- mlir::Value visitCirPoisonAttr (cir::PoisonAttr attr);
448
- mlir::Value visitCirGlobalViewAttr (cir::GlobalViewAttr attr);
449
- mlir::Value visitCirVTableAttr (cir::VTableAttr attr);
450
- mlir::Value visitCirTypeInfoAttr (cir::TypeInfoAttr attr);
438
+ mlir::Value visit (mlir::Attribute attr) {
439
+ return llvm::TypeSwitch<mlir::Attribute, mlir::Value>(attr)
440
+ .Case <cir::IntAttr, cir::FPAttr, cir::ConstPtrAttr,
441
+ cir::ConstStructAttr, cir::ConstArrayAttr, cir::ConstVectorAttr,
442
+ cir::BoolAttr, cir::ZeroAttr, cir::UndefAttr, cir::PoisonAttr,
443
+ cir::GlobalViewAttr, cir::VTableAttr, cir::TypeInfoAttr>(
444
+ [&](auto attrT) { return visitCirAttr (attrT); })
445
+ .Default ([&](auto attrT) { return mlir::Value (); });
446
+ }
447
+
448
+ mlir::Value visitCirAttr (cir::IntAttr attr);
449
+ mlir::Value visitCirAttr (cir::FPAttr attr);
450
+ mlir::Value visitCirAttr (cir::ConstPtrAttr attr);
451
+ mlir::Value visitCirAttr (cir::ConstStructAttr attr);
452
+ mlir::Value visitCirAttr (cir::ConstArrayAttr attr);
453
+ mlir::Value visitCirAttr (cir::ConstVectorAttr attr);
454
+ mlir::Value visitCirAttr (cir::BoolAttr attr);
455
+ mlir::Value visitCirAttr (cir::ZeroAttr attr);
456
+ mlir::Value visitCirAttr (cir::UndefAttr attr);
457
+ mlir::Value visitCirAttr (cir::PoisonAttr attr);
458
+ mlir::Value visitCirAttr (cir::GlobalViewAttr attr);
459
+ mlir::Value visitCirAttr (cir::VTableAttr attr);
460
+ mlir::Value visitCirAttr (cir::TypeInfoAttr attr);
451
461
452
462
private:
453
463
mlir::Operation *parentOp;
@@ -457,21 +467,21 @@ class CirAttrToValue : public CirAttrVisitor<CirAttrToValue, mlir::Value> {
457
467
};
458
468
459
469
// / IntAttr visitor.
460
- mlir::Value CirAttrToValue::visitCirIntAttr (cir::IntAttr intAttr) {
470
+ mlir::Value CirAttrToValue::visitCirAttr (cir::IntAttr intAttr) {
461
471
auto loc = parentOp->getLoc ();
462
472
return rewriter.create <mlir::LLVM::ConstantOp>(
463
473
loc, converter->convertType (intAttr.getType ()), intAttr.getValue ());
464
474
}
465
475
466
476
// / BoolAttr visitor.
467
- mlir::Value CirAttrToValue::visitCirBoolAttr (cir::BoolAttr boolAttr) {
477
+ mlir::Value CirAttrToValue::visitCirAttr (cir::BoolAttr boolAttr) {
468
478
auto loc = parentOp->getLoc ();
469
479
return rewriter.create <mlir::LLVM::ConstantOp>(
470
480
loc, converter->convertType (boolAttr.getType ()), boolAttr.getValue ());
471
481
}
472
482
473
483
// / ConstPtrAttr visitor.
474
- mlir::Value CirAttrToValue::visitCirConstPtrAttr (cir::ConstPtrAttr ptrAttr) {
484
+ mlir::Value CirAttrToValue::visitCirAttr (cir::ConstPtrAttr ptrAttr) {
475
485
auto loc = parentOp->getLoc ();
476
486
if (ptrAttr.isNullValue ()) {
477
487
return rewriter.create <mlir::LLVM::ZeroOp>(
@@ -486,36 +496,35 @@ mlir::Value CirAttrToValue::visitCirConstPtrAttr(cir::ConstPtrAttr ptrAttr) {
486
496
}
487
497
488
498
// / FPAttr visitor.
489
- mlir::Value CirAttrToValue::visitCirFPAttr (cir::FPAttr fltAttr) {
499
+ mlir::Value CirAttrToValue::visitCirAttr (cir::FPAttr fltAttr) {
490
500
auto loc = parentOp->getLoc ();
491
501
return rewriter.create <mlir::LLVM::ConstantOp>(
492
502
loc, converter->convertType (fltAttr.getType ()), fltAttr.getValue ());
493
503
}
494
504
495
505
// / ZeroAttr visitor.
496
- mlir::Value CirAttrToValue::visitCirZeroAttr (cir::ZeroAttr zeroAttr) {
506
+ mlir::Value CirAttrToValue::visitCirAttr (cir::ZeroAttr zeroAttr) {
497
507
auto loc = parentOp->getLoc ();
498
508
return rewriter.create <mlir::LLVM::ZeroOp>(
499
509
loc, converter->convertType (zeroAttr.getType ()));
500
510
}
501
511
502
512
// / UndefAttr visitor.
503
- mlir::Value CirAttrToValue::visitCirUndefAttr (cir::UndefAttr undefAttr) {
513
+ mlir::Value CirAttrToValue::visitCirAttr (cir::UndefAttr undefAttr) {
504
514
auto loc = parentOp->getLoc ();
505
515
return rewriter.create <mlir::LLVM::UndefOp>(
506
516
loc, converter->convertType (undefAttr.getType ()));
507
517
}
508
518
509
519
// / PoisonAttr visitor.
510
- mlir::Value CirAttrToValue::visitCirPoisonAttr (cir::PoisonAttr poisonAttr) {
520
+ mlir::Value CirAttrToValue::visitCirAttr (cir::PoisonAttr poisonAttr) {
511
521
auto loc = parentOp->getLoc ();
512
522
return rewriter.create <mlir::LLVM::PoisonOp>(
513
523
loc, converter->convertType (poisonAttr.getType ()));
514
524
}
515
525
516
526
// / ConstStruct visitor.
517
- mlir::Value
518
- CirAttrToValue::visitCirConstStructAttr (cir::ConstStructAttr constStruct) {
527
+ mlir::Value CirAttrToValue::visitCirAttr (cir::ConstStructAttr constStruct) {
519
528
auto llvmTy = converter->convertType (constStruct.getType ());
520
529
auto loc = parentOp->getLoc ();
521
530
mlir::Value result = rewriter.create <mlir::LLVM::UndefOp>(loc, llvmTy);
@@ -531,7 +540,7 @@ CirAttrToValue::visitCirConstStructAttr(cir::ConstStructAttr constStruct) {
531
540
}
532
541
533
542
// VTableAttr visitor.
534
- mlir::Value CirAttrToValue::visitCirVTableAttr (cir::VTableAttr vtableArr) {
543
+ mlir::Value CirAttrToValue::visitCirAttr (cir::VTableAttr vtableArr) {
535
544
auto llvmTy = converter->convertType (vtableArr.getType ());
536
545
auto loc = parentOp->getLoc ();
537
546
mlir::Value result = rewriter.create <mlir::LLVM::UndefOp>(loc, llvmTy);
@@ -545,8 +554,7 @@ mlir::Value CirAttrToValue::visitCirVTableAttr(cir::VTableAttr vtableArr) {
545
554
}
546
555
547
556
// TypeInfoAttr visitor.
548
- mlir::Value
549
- CirAttrToValue::visitCirTypeInfoAttr (cir::TypeInfoAttr typeinfoArr) {
557
+ mlir::Value CirAttrToValue::visitCirAttr (cir::TypeInfoAttr typeinfoArr) {
550
558
auto llvmTy = converter->convertType (typeinfoArr.getType ());
551
559
auto loc = parentOp->getLoc ();
552
560
mlir::Value result = rewriter.create <mlir::LLVM::UndefOp>(loc, llvmTy);
@@ -560,8 +568,7 @@ CirAttrToValue::visitCirTypeInfoAttr(cir::TypeInfoAttr typeinfoArr) {
560
568
}
561
569
562
570
// ConstArrayAttr visitor
563
- mlir::Value
564
- CirAttrToValue::visitCirConstArrayAttr (cir::ConstArrayAttr constArr) {
571
+ mlir::Value CirAttrToValue::visitCirAttr (cir::ConstArrayAttr constArr) {
565
572
auto llvmTy = converter->convertType (constArr.getType ());
566
573
auto loc = parentOp->getLoc ();
567
574
mlir::Value result;
@@ -604,8 +611,7 @@ CirAttrToValue::visitCirConstArrayAttr(cir::ConstArrayAttr constArr) {
604
611
}
605
612
606
613
// ConstVectorAttr visitor.
607
- mlir::Value
608
- CirAttrToValue::visitCirConstVectorAttr (cir::ConstVectorAttr constVec) {
614
+ mlir::Value CirAttrToValue::visitCirAttr (cir::ConstVectorAttr constVec) {
609
615
auto llvmTy = converter->convertType (constVec.getType ());
610
616
auto loc = parentOp->getLoc ();
611
617
SmallVector<mlir::Attribute> mlirValues;
@@ -630,8 +636,7 @@ CirAttrToValue::visitCirConstVectorAttr(cir::ConstVectorAttr constVec) {
630
636
}
631
637
632
638
// GlobalViewAttr visitor.
633
- mlir::Value
634
- CirAttrToValue::visitCirGlobalViewAttr (cir::GlobalViewAttr globalAttr) {
639
+ mlir::Value CirAttrToValue::visitCirAttr (cir::GlobalViewAttr globalAttr) {
635
640
auto module = parentOp->getParentOfType <mlir::ModuleOp>();
636
641
mlir::Type sourceType;
637
642
unsigned sourceAddrSpace = 0 ;
0 commit comments