diff options
Diffstat (limited to 'clang/lib/CIR')
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenAtomic.cpp | 20 | ||||
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenCall.cpp | 26 | ||||
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenCall.h | 2 | ||||
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp | 14 | ||||
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 20 | ||||
-rw-r--r-- | clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 13 | ||||
-rw-r--r-- | clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 15 |
7 files changed, 80 insertions, 30 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp b/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp index e943b02..0f4d6d2 100644 --- a/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp @@ -718,10 +718,26 @@ void CIRGenFunction::emitAtomicInit(Expr *init, LValue dest) { return; } - case cir::TEK_Aggregate: - cgm.errorNYI(init->getSourceRange(), "emitAtomicInit: aggregate type"); + case cir::TEK_Aggregate: { + // Fix up the destination if the initializer isn't an expression + // of atomic type. + bool zeroed = false; + if (!init->getType()->isAtomicType()) { + zeroed = atomics.emitMemSetZeroIfNecessary(); + dest = atomics.projectValue(); + } + + // Evaluate the expression directly into the destination. + assert(!cir::MissingFeatures::aggValueSlotGC()); + AggValueSlot slot = AggValueSlot::forLValue( + dest, AggValueSlot::IsNotDestructed, AggValueSlot::IsNotAliased, + AggValueSlot::DoesNotOverlap, + zeroed ? AggValueSlot::IsZeroed : AggValueSlot::IsNotZeroed); + + emitAggExpr(init, slot); return; } + } llvm_unreachable("bad evaluation kind"); } diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index 2970b36..61072f0 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -522,7 +522,8 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo, assert(!cir::MissingFeatures::opCallPaddingArgs()); mlir::Type argType = convertType(canQualArgType); - if (!mlir::isa<cir::RecordType>(argType)) { + if (!mlir::isa<cir::RecordType>(argType) && + !mlir::isa<cir::ComplexType>(argType)) { mlir::Value v; if (arg.isAggregate()) cgm.errorNYI(loc, "emitCall: aggregate call argument"); @@ -540,15 +541,16 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo, cirCallArgs[argNo] = v; } else { Address src = Address::invalid(); - if (!arg.isAggregate()) - cgm.errorNYI(loc, "emitCall: non-aggregate call argument"); - else + if (!arg.isAggregate()) { + src = createMemTemp(arg.ty, loc, "coerce"); + arg.copyInto(*this, src, loc); + } else { src = arg.hasLValue() ? arg.getKnownLValue().getAddress() : arg.getKnownRValue().getAggregateAddress(); + } // Fast-isel and the optimizer generally like scalar values better than // FCAs, so we flatten them if this is safe to do for this argument. - auto argRecordTy = cast<cir::RecordType>(argType); mlir::Type srcTy = src.getElementType(); // FIXME(cir): get proper location for each argument. mlir::Location argLoc = loc; @@ -564,7 +566,7 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo, // uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy); // if (SrcSize < DstSize) { assert(!cir::MissingFeatures::dataLayoutTypeAllocSize()); - if (srcTy != argRecordTy) { + if (srcTy != argType) { cgm.errorNYI(loc, "emitCall: source type does not match argument type"); } else { // FIXME(cir): this currently only runs when the types are exactly the @@ -676,6 +678,18 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo, llvm_unreachable("Invalid evaluation kind"); } +void CallArg::copyInto(CIRGenFunction &cgf, Address addr, + mlir::Location loc) const { + LValue dst = cgf.makeAddrLValue(addr, ty); + if (!hasLV && rv.isScalar()) + cgf.cgm.errorNYI(loc, "copyInto scalar value"); + else if (!hasLV && rv.isComplex()) + cgf.emitStoreOfComplex(loc, rv.getComplexValue(), dst, /*isInit=*/true); + else + cgf.cgm.errorNYI(loc, "copyInto hasLV"); + isUsed = true; +} + void CIRGenFunction::emitCallArg(CallArgList &args, const clang::Expr *e, clang::QualType argType) { assert(argType->isReferenceType() == e->isGLValue() && diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.h b/clang/lib/CIR/CodeGen/CIRGenCall.h index 52d541f..55b3d97 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.h +++ b/clang/lib/CIR/CodeGen/CIRGenCall.h @@ -224,6 +224,8 @@ public: } bool isAggregate() const { return hasLV || rv.isAggregate(); } + + void copyInto(CIRGenFunction &cgf, Address addr, mlir::Location loc) const; }; class CallArgList : public llvm::SmallVector<CallArg, 8> { diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp index 1e987f3..e51c3fc 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp @@ -144,10 +144,7 @@ public: void VisitUnaryCoawait(UnaryOperator *e) { cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitUnaryCoawait"); } - void VisitUnaryExtension(UnaryOperator *e) { - cgf.cgm.errorNYI(e->getSourceRange(), - "AggExprEmitter: VisitUnaryExtension"); - } + void VisitUnaryExtension(UnaryOperator *e) { Visit(e->getSubExpr()); } void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e) { cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitSubstNonTypeTemplateParmExpr"); @@ -184,7 +181,8 @@ public: cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitBinAssign"); } void VisitBinComma(const BinaryOperator *e) { - cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitBinComma"); + cgf.emitIgnoredExpr(e->getLHS()); + Visit(e->getRHS()); } void VisitBinCmp(const BinaryOperator *e) { cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitBinCmp"); @@ -212,9 +210,11 @@ public: } void VisitChooseExpr(const ChooseExpr *e) { Visit(e->getChosenSubExpr()); } void VisitCXXParenListInitExpr(CXXParenListInitExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), - "AggExprEmitter: VisitCXXParenListInitExpr"); + visitCXXParenListOrInitListExpr(e, e->getInitExprs(), + e->getInitializedFieldInUnion(), + e->getArrayFiller()); } + void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *e, llvm::Value *outerBegin = nullptr) { cgf.cgm.errorNYI(e->getSourceRange(), diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 500007f..768d75d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -2159,16 +2159,16 @@ mlir::Value ScalarExprEmitter::VisitRealImag(const UnaryOperator *e, // __imag on a scalar returns zero. Emit the subexpr to ensure side // effects are evaluated, but not the actual value. - if (op->isGLValue()) - cgf.emitLValue(op); - else if (!promotionTy.isNull()) - cgf.emitPromotedScalarExpr(op, promotionTy); - else - cgf.emitScalarExpr(op); - - mlir::Type valueTy = - cgf.convertType(promotionTy.isNull() ? e->getType() : promotionTy); - return builder.getNullValue(valueTy, loc); + mlir::Value operand; + if (op->isGLValue()) { + operand = cgf.emitLValue(op).getPointer(); + operand = cir::LoadOp::create(builder, loc, operand); + } else if (!promotionTy.isNull()) { + operand = cgf.emitPromotedScalarExpr(op, promotionTy); + } else { + operand = cgf.emitScalarExpr(op); + } + return builder.createComplexImag(loc, operand); } /// Return the size or alignment of the type of argument of the sizeof diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index fba094f..cdd4e3c 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2402,9 +2402,8 @@ OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) { LogicalResult cir::ComplexRealOp::verify() { mlir::Type operandTy = getOperand().getType(); - if (auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy)) { + if (auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy)) operandTy = complexOperandTy.getElementType(); - } if (getType() != operandTy) { emitOpError() << ": result type does not match operand type"; @@ -2431,14 +2430,22 @@ OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) { //===----------------------------------------------------------------------===// LogicalResult cir::ComplexImagOp::verify() { - if (getType() != getOperand().getType().getElementType()) { + mlir::Type operandTy = getOperand().getType(); + if (auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy)) + operandTy = complexOperandTy.getElementType(); + + if (getType() != operandTy) { emitOpError() << ": result type does not match operand type"; return failure(); } + return success(); } OpFoldResult cir::ComplexImagOp::fold(FoldAdaptor adaptor) { + if (!mlir::isa<cir::ComplexType>(getOperand().getType())) + return nullptr; + if (auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>()) return complexCreateOp.getOperand(1); diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index bfb1262..1ff8cc5 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -3061,8 +3061,19 @@ mlir::LogicalResult CIRToLLVMComplexImagOpLowering::matchAndRewrite( cir::ComplexImagOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const { mlir::Type resultLLVMTy = getTypeConverter()->convertType(op.getType()); - rewriter.replaceOpWithNewOp<mlir::LLVM::ExtractValueOp>( - op, resultLLVMTy, adaptor.getOperand(), llvm::ArrayRef<std::int64_t>{1}); + mlir::Value operand = adaptor.getOperand(); + mlir::Location loc = op.getLoc(); + + if (mlir::isa<cir::ComplexType>(op.getOperand().getType())) { + operand = mlir::LLVM::ExtractValueOp::create( + rewriter, loc, resultLLVMTy, operand, llvm::ArrayRef<std::int64_t>{1}); + } else { + mlir::TypedAttr zeroAttr = rewriter.getZeroAttr(resultLLVMTy); + operand = + mlir::LLVM::ConstantOp::create(rewriter, loc, resultLLVMTy, zeroAttr); + } + + rewriter.replaceOp(op, operand); return mlir::success(); } |