[cfe-commits] r41255 - /cfe/trunk/CodeGen/CGComplexExpr.cpp
Chris Lattner
sabre at nondot.org
Tue Aug 21 15:25:29 PDT 2007
Author: lattner
Date: Tue Aug 21 17:25:29 2007
New Revision: 41255
URL: http://llvm.org/viewvc/llvm-project?rev=41255&view=rev
Log:
implement codegen for --/++
Modified:
cfe/trunk/CodeGen/CGComplexExpr.cpp
Modified: cfe/trunk/CodeGen/CGComplexExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGComplexExpr.cpp?rev=41255&r1=41254&r2=41255&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGComplexExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGComplexExpr.cpp Tue Aug 21 17:25:29 2007
@@ -74,6 +74,21 @@
ComplexPairTy VisitArraySubscriptExpr(Expr *E) { return EmitLoadOfLValue(E); }
// Operators.
+ ComplexPairTy VisitPrePostIncDec(const UnaryOperator *E,
+ bool isInc, bool isPre);
+ ComplexPairTy VisitUnaryPostDec(const UnaryOperator *E) {
+ return VisitPrePostIncDec(E, false, false);
+ }
+ ComplexPairTy VisitUnaryPostInc(const UnaryOperator *E) {
+ return VisitPrePostIncDec(E, true, false);
+ }
+ ComplexPairTy VisitUnaryPreDec(const UnaryOperator *E) {
+ return VisitPrePostIncDec(E, false, true);
+ }
+ ComplexPairTy VisitUnaryPreInc(const UnaryOperator *E) {
+ return VisitPrePostIncDec(E, true, true);
+ }
+ ComplexPairTy VisitUnaryDeref(const Expr *E) { return EmitLoadOfLValue(E); }
ComplexPairTy VisitUnaryPlus (const UnaryOperator *E) {
return Visit(E->getSubExpr());
}
@@ -152,6 +167,33 @@
return ComplexPairTy(U, U);
}
+ComplexPairTy ComplexExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
+ bool isInc, bool isPre) {
+ LValue LV = CGF.EmitLValue(E->getSubExpr());
+ // FIXME: Handle volatile!
+ ComplexPairTy InVal = EmitLoadOfComplex(LV.getAddress(), false);
+
+ int AmountVal = isInc ? 1 : -1;
+
+ llvm::Value *NextVal;
+ if (isa<llvm::IntegerType>(InVal.first->getType()))
+ NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal);
+ else
+ NextVal = llvm::ConstantFP::get(InVal.first->getType(), AmountVal);
+
+ // Add the inc/dec to the real part.
+ NextVal = Builder.CreateAdd(InVal.first, NextVal, isInc ? "inc" : "dec");
+
+ ComplexPairTy IncVal(NextVal, InVal.second);
+
+ // Store the updated result through the lvalue.
+ EmitStoreOfComplex(IncVal, LV.getAddress(), false); /* FIXME: Volatile */
+
+ // If this is a postinc, return the value read from memory, otherwise use the
+ // updated value.
+ return isPre ? IncVal : InVal;
+}
+
ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E) {
ComplexPairTy Op = Visit(E->getSubExpr());
llvm::Value *ResR = Builder.CreateNeg(Op.first, "neg.r");
More information about the cfe-commits
mailing list