[cfe-commits] r39712 - in /cfe/cfe/trunk/CodeGen: CGExpr.cpp CodeGenFunction.h
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:47:25 PDT 2007
Author: clattner
Date: Wed Jul 11 11:47:25 2007
New Revision: 39712
URL: http://llvm.org/viewvc/llvm-project?rev=39712&view=rev
Log:
Implement the rest of the compound assignment operators, except shifts.
Modified:
cfe/cfe/trunk/CodeGen/CGExpr.cpp
cfe/cfe/trunk/CodeGen/CodeGenFunction.h
Modified: cfe/cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGExpr.cpp?rev=39712&r1=39711&r2=39712&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGExpr.cpp Wed Jul 11 11:47:25 2007
@@ -752,12 +752,18 @@
RValue LHS, RHS;
switch (E->getOpcode()) {
default:
- fprintf(stderr, "Unimplemented expr!\n");
+ fprintf(stderr, "Unimplemented binary expr!\n");
E->dump();
return RValue::get(llvm::UndefValue::get(llvm::Type::Int32Ty));
- case BinaryOperator::Mul: return EmitBinaryMul(E);
- case BinaryOperator::Div: return EmitBinaryDiv(E);
- case BinaryOperator::Rem: return EmitBinaryRem(E);
+ case BinaryOperator::Mul:
+ EmitUsualArithmeticConversions(E, LHS, RHS);
+ return EmitMul(LHS, RHS, E->getType());
+ case BinaryOperator::Div:
+ EmitUsualArithmeticConversions(E, LHS, RHS);
+ return EmitDiv(LHS, RHS, E->getType());
+ case BinaryOperator::Rem:
+ EmitUsualArithmeticConversions(E, LHS, RHS);
+ return EmitRem(LHS, RHS, E->getType());
case BinaryOperator::Add:
// FIXME: This doesn't handle ptr+int etc yet.
EmitUsualArithmeticConversions(E, LHS, RHS);
@@ -768,9 +774,15 @@
return EmitSub(LHS, RHS, E->getType());
case BinaryOperator::Shl: return EmitBinaryShl(E);
case BinaryOperator::Shr: return EmitBinaryShr(E);
- case BinaryOperator::And: return EmitBinaryAnd(E);
- case BinaryOperator::Xor: return EmitBinaryXor(E);
- case BinaryOperator::Or : return EmitBinaryOr(E);
+ case BinaryOperator::And:
+ EmitUsualArithmeticConversions(E, LHS, RHS);
+ return EmitAnd(LHS, RHS, E->getType());
+ case BinaryOperator::Xor:
+ EmitUsualArithmeticConversions(E, LHS, RHS);
+ return EmitXor(LHS, RHS, E->getType());
+ case BinaryOperator::Or :
+ EmitUsualArithmeticConversions(E, LHS, RHS);
+ return EmitOr(LHS, RHS, E->getType());
case BinaryOperator::LAnd: return EmitBinaryLAnd(E);
case BinaryOperator::LOr: return EmitBinaryLOr(E);
case BinaryOperator::LT:
@@ -800,6 +812,27 @@
case BinaryOperator::Assign:
return EmitBinaryAssign(E);
+ case BinaryOperator::MulAssign: {
+ const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+ LValue LHSLV;
+ EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+ LHS = EmitMul(LHS, RHS, CAO->getComputationType());
+ return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+ }
+ case BinaryOperator::DivAssign: {
+ const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+ LValue LHSLV;
+ EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+ LHS = EmitDiv(LHS, RHS, CAO->getComputationType());
+ return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+ }
+ case BinaryOperator::RemAssign: {
+ const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+ LValue LHSLV;
+ EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+ LHS = EmitRem(LHS, RHS, CAO->getComputationType());
+ return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+ }
case BinaryOperator::AddAssign: {
const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
LValue LHSLV;
@@ -814,31 +847,44 @@
LHS = EmitSub(LHS, RHS, CAO->getComputationType());
return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
}
-
- // FIXME: Assignment.
+ case BinaryOperator::AndAssign: {
+ const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+ LValue LHSLV;
+ EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+ LHS = EmitAnd(LHS, RHS, CAO->getComputationType());
+ return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+ }
+ case BinaryOperator::OrAssign: {
+ const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+ LValue LHSLV;
+ EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+ LHS = EmitOr(LHS, RHS, CAO->getComputationType());
+ return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+ }
+ case BinaryOperator::XorAssign: {
+ const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+ LValue LHSLV;
+ EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+ LHS = EmitXor(LHS, RHS, CAO->getComputationType());
+ return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+ }
case BinaryOperator::Comma: return EmitBinaryComma(E);
}
}
-RValue CodeGenFunction::EmitBinaryMul(const BinaryOperator *E) {
- RValue LHS, RHS;
- EmitUsualArithmeticConversions(E, LHS, RHS);
-
+RValue CodeGenFunction::EmitMul(RValue LHS, RValue RHS, QualType ResTy) {
if (LHS.isScalar())
return RValue::get(Builder.CreateMul(LHS.getVal(), RHS.getVal(), "mul"));
assert(0 && "FIXME: This doesn't handle complex operands yet");
}
-RValue CodeGenFunction::EmitBinaryDiv(const BinaryOperator *E) {
- RValue LHS, RHS;
- EmitUsualArithmeticConversions(E, LHS, RHS);
-
+RValue CodeGenFunction::EmitDiv(RValue LHS, RValue RHS, QualType ResTy) {
if (LHS.isScalar()) {
llvm::Value *RV;
if (LHS.getVal()->getType()->isFloatingPoint())
RV = Builder.CreateFDiv(LHS.getVal(), RHS.getVal(), "div");
- else if (E->getType()->isUnsignedIntegerType())
+ else if (ResTy->isUnsignedIntegerType())
RV = Builder.CreateUDiv(LHS.getVal(), RHS.getVal(), "div");
else
RV = Builder.CreateSDiv(LHS.getVal(), RHS.getVal(), "div");
@@ -847,14 +893,11 @@
assert(0 && "FIXME: This doesn't handle complex operands yet");
}
-RValue CodeGenFunction::EmitBinaryRem(const BinaryOperator *E) {
- RValue LHS, RHS;
- EmitUsualArithmeticConversions(E, LHS, RHS);
-
+RValue CodeGenFunction::EmitRem(RValue LHS, RValue RHS, QualType ResTy) {
if (LHS.isScalar()) {
llvm::Value *RV;
// Rem in C can't be a floating point type: C99 6.5.5p2.
- if (E->getType()->isUnsignedIntegerType())
+ if (ResTy->isUnsignedIntegerType())
RV = Builder.CreateURem(LHS.getVal(), RHS.getVal(), "rem");
else
RV = Builder.CreateSRem(LHS.getVal(), RHS.getVal(), "rem");
@@ -959,30 +1002,21 @@
return RValue::get(Builder.CreateZExt(Result, LLVMIntTy, "cmp.ext"));
}
-RValue CodeGenFunction::EmitBinaryAnd(const BinaryOperator *E) {
- RValue LHS, RHS;
- EmitUsualArithmeticConversions(E, LHS, RHS);
-
+RValue CodeGenFunction::EmitAnd(RValue LHS, RValue RHS, QualType ResTy) {
if (LHS.isScalar())
return RValue::get(Builder.CreateAnd(LHS.getVal(), RHS.getVal(), "and"));
assert(0 && "FIXME: This doesn't handle complex integer operands yet (GNU)");
}
-RValue CodeGenFunction::EmitBinaryXor(const BinaryOperator *E) {
- RValue LHS, RHS;
- EmitUsualArithmeticConversions(E, LHS, RHS);
-
+RValue CodeGenFunction::EmitXor(RValue LHS, RValue RHS, QualType ResTy) {
if (LHS.isScalar())
return RValue::get(Builder.CreateXor(LHS.getVal(), RHS.getVal(), "xor"));
assert(0 && "FIXME: This doesn't handle complex integer operands yet (GNU)");
}
-RValue CodeGenFunction::EmitBinaryOr(const BinaryOperator *E) {
- RValue LHS, RHS;
- EmitUsualArithmeticConversions(E, LHS, RHS);
-
+RValue CodeGenFunction::EmitOr(RValue LHS, RValue RHS, QualType ResTy) {
if (LHS.isScalar())
return RValue::get(Builder.CreateOr(LHS.getVal(), RHS.getVal(), "or"));
Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39712&r1=39711&r2=39712&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:47:25 2007
@@ -299,22 +299,22 @@
RValue EmitBinaryMul(const BinaryOperator *E);
RValue EmitBinaryDiv(const BinaryOperator *E);
RValue EmitBinaryRem(const BinaryOperator *E);
+ RValue EmitMul(RValue LHS, RValue RHS, QualType EltTy);
+ RValue EmitDiv(RValue LHS, RValue RHS, QualType EltTy);
+ RValue EmitRem(RValue LHS, RValue RHS, QualType EltTy);
RValue EmitAdd(RValue LHS, RValue RHS, QualType EltTy);
RValue EmitSub(RValue LHS, RValue RHS, QualType EltTy);
RValue EmitBinaryShl(const BinaryOperator *E);
RValue EmitBinaryShr(const BinaryOperator *E);
RValue EmitBinaryCompare(const BinaryOperator *E, unsigned UICmpOpc,
unsigned SICmpOpc, unsigned FCmpOpc);
- RValue EmitBinaryAnd(const BinaryOperator *E);
- RValue EmitBinaryXor(const BinaryOperator *E);
- RValue EmitBinaryOr (const BinaryOperator *E);
+ RValue EmitAnd(RValue LHS, RValue RHS, QualType EltTy);
+ RValue EmitOr (RValue LHS, RValue RHS, QualType EltTy);
+ RValue EmitXor(RValue LHS, RValue RHS, QualType EltTy);
RValue EmitBinaryLAnd(const BinaryOperator *E);
RValue EmitBinaryLOr(const BinaryOperator *E);
RValue EmitBinaryAssign(const BinaryOperator *E);
-
- // FIXME: Assignment.
-
RValue EmitBinaryComma(const BinaryOperator *E);
};
} // end namespace CodeGen
More information about the cfe-commits
mailing list