aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorAmr Hesham <amr96@programmer.net>2025-06-16 20:10:40 +0200
committerGitHub <noreply@github.com>2025-06-16 20:10:40 +0200
commitfccab5d757778204666d70e2f1592952fc8b336d (patch)
treef244bc6c636b53ba8d665adeb43e3948e6c702cf /clang/lib
parent492d25bbe12af7702a392fa7ad41eb9e09a48cf2 (diff)
downloadllvm-fccab5d757778204666d70e2f1592952fc8b336d.zip
llvm-fccab5d757778204666d70e2f1592952fc8b336d.tar.gz
llvm-fccab5d757778204666d70e2f1592952fc8b336d.tar.bz2
[CIR] Upstream ComplexType ImaginaryLiteral (#144223)
This change adds support for ComplexType ImaginaryLiteral https://github.com/llvm/llvm-project/issues/141365
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 2ffe75a..26070a6 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -21,6 +21,8 @@ public:
bool isInit);
mlir::Value VisitInitListExpr(InitListExpr *e);
+
+ mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
};
} // namespace
@@ -66,6 +68,34 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
return builder.create<cir::ConstantOp>(loc, complexAttr);
}
+mlir::Value
+ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *il) {
+ auto ty = mlir::cast<cir::ComplexType>(cgf.convertType(il->getType()));
+ mlir::Type elementTy = ty.getElementType();
+ mlir::Location loc = cgf.getLoc(il->getExprLoc());
+
+ mlir::TypedAttr realValueAttr;
+ mlir::TypedAttr imagValueAttr;
+
+ if (mlir::isa<cir::IntType>(elementTy)) {
+ llvm::APInt imagValue = cast<IntegerLiteral>(il->getSubExpr())->getValue();
+ realValueAttr = cir::IntAttr::get(elementTy, 0);
+ imagValueAttr = cir::IntAttr::get(elementTy, imagValue);
+ } else {
+ assert(mlir::isa<cir::CIRFPTypeInterface>(elementTy) &&
+ "Expected complex element type to be floating-point");
+
+ llvm::APFloat imagValue =
+ cast<FloatingLiteral>(il->getSubExpr())->getValue();
+ realValueAttr = cir::FPAttr::get(
+ elementTy, llvm::APFloat::getZero(imagValue.getSemantics()));
+ imagValueAttr = cir::FPAttr::get(elementTy, imagValue);
+ }
+
+ auto complexAttr = cir::ConstComplexAttr::get(realValueAttr, imagValueAttr);
+ return builder.create<cir::ConstantOp>(loc, complexAttr);
+}
+
mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) {
assert(e && getComplexType(e->getType()) &&
"Invalid complex expression to emit");