[cfe-commits] r39665 - in /cfe/cfe/trunk/CodeGen: CGExpr.cpp CodeGenFunction.h
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:46:54 PDT 2007
Author: clattner
Date: Wed Jul 11 11:46:54 2007
New Revision: 39665
URL: http://llvm.org/viewvc/llvm-project?rev=39665&view=rev
Log:
Implement the equality operators for simple types
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=39665&r1=39664&r2=39665&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGExpr.cpp Wed Jul 11 11:46:54 2007
@@ -645,6 +645,9 @@
case BinaryOperator::Shl: return EmitBinaryShl(E);
case BinaryOperator::Shr: return EmitBinaryShr(E);
+ case BinaryOperator::EQ:
+ case BinaryOperator::NE: return EmitBinaryEquality(E);
+
// FIXME: relational
case BinaryOperator::And: return EmitBinaryAnd(E);
@@ -768,6 +771,33 @@
return RValue::get(Builder.CreateAShr(LHS, RHS, "shr"));
}
+RValue CodeGenFunction::EmitBinaryEquality(const BinaryOperator *E) {
+ RValue LHS, RHS;
+ EmitUsualArithmeticConversions(E, LHS, RHS);
+
+ llvm::Value *Result;
+ if (LHS.isScalar()) {
+ if (LHS.getVal()->getType()->isFloatingPoint()) {
+ if (E->getOpcode() == BinaryOperator::EQ)
+ Result = Builder.CreateFCmpOEQ(LHS.getVal(), RHS.getVal(), "eq");
+ else
+ Result = Builder.CreateFCmpUNE(LHS.getVal(), RHS.getVal(), "ne");
+ } else {
+ // Otherwise, it is an integer or pointer comparison.
+ if (E->getOpcode() == BinaryOperator::EQ)
+ Result = Builder.CreateICmpEQ(LHS.getVal(), RHS.getVal(), "eq");
+ else
+ Result = Builder.CreateICmpNE(LHS.getVal(), RHS.getVal(), "ne");
+ }
+ } else {
+ // Struct/union/complex
+ assert(0 && "Aggregate comparisons not implemented yet!");
+ }
+
+ // ZExt result to int.
+ return RValue::get(Builder.CreateZExt(Result, LLVMIntTy, "cmp.ext"));
+}
+
RValue CodeGenFunction::EmitBinaryAnd(const BinaryOperator *E) {
RValue LHS, RHS;
EmitUsualArithmeticConversions(E, LHS, RHS);
@@ -869,7 +899,6 @@
return RHS;
}
-
RValue CodeGenFunction::EmitBinaryComma(const BinaryOperator *E) {
EmitExpr(E->getLHS());
return EmitExpr(E->getRHS());
Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39665&r1=39664&r2=39665&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:46:54 2007
@@ -274,6 +274,7 @@
RValue EmitBinaryShr(const BinaryOperator *E);
// FIXME: relational
+ RValue EmitBinaryEquality(const BinaryOperator *E);
RValue EmitBinaryAnd(const BinaryOperator *E);
RValue EmitBinaryXor(const BinaryOperator *E);
More information about the cfe-commits
mailing list