[cfe-commits] r39666 - in /cfe/cfe/trunk: CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.h clang.xcodeproj/project.pbxproj
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:46:55 PDT 2007
Author: clattner
Date: Wed Jul 11 11:46:55 2007
New Revision: 39666
URL: http://llvm.org/viewvc/llvm-project?rev=39666&view=rev
Log:
implement codegen of the relational operations
One major FIXME though.
Modified:
cfe/cfe/trunk/CodeGen/CGExpr.cpp
cfe/cfe/trunk/CodeGen/CodeGenFunction.h
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
Modified: cfe/cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGExpr.cpp?rev=39666&r1=39665&r2=39666&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGExpr.cpp Wed Jul 11 11:46:55 2007
@@ -337,7 +337,7 @@
switch (E->getStmtClass()) {
default:
- printf("Unimplemented expr!\n");
+ fprintf(stderr, "Unimplemented expr!\n");
E->dump();
return RValue::get(llvm::UndefValue::get(llvm::Type::Int32Ty));
@@ -644,18 +644,35 @@
case BinaryOperator::Sub: return EmitBinarySub(E);
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);
case BinaryOperator::Xor: return EmitBinaryXor(E);
case BinaryOperator::Or : return EmitBinaryOr(E);
case BinaryOperator::LAnd: return EmitBinaryLAnd(E);
case BinaryOperator::LOr: return EmitBinaryLOr(E);
-
+ case BinaryOperator::LT:
+ return EmitBinaryCompare(E, llvm::ICmpInst::ICMP_ULT,
+ llvm::ICmpInst::ICMP_SLT,
+ llvm::FCmpInst::FCMP_OLT);
+ case BinaryOperator::GT:
+ return EmitBinaryCompare(E, llvm::ICmpInst::ICMP_UGT,
+ llvm::ICmpInst::ICMP_SGT,
+ llvm::FCmpInst::FCMP_OGT);
+ case BinaryOperator::LE:
+ return EmitBinaryCompare(E, llvm::ICmpInst::ICMP_ULE,
+ llvm::ICmpInst::ICMP_SLE,
+ llvm::FCmpInst::FCMP_OLE);
+ case BinaryOperator::GE:
+ return EmitBinaryCompare(E, llvm::ICmpInst::ICMP_UGE,
+ llvm::ICmpInst::ICMP_SGE,
+ llvm::FCmpInst::FCMP_OGE);
+ case BinaryOperator::EQ:
+ return EmitBinaryCompare(E, llvm::ICmpInst::ICMP_EQ,
+ llvm::ICmpInst::ICMP_EQ,
+ llvm::FCmpInst::FCMP_OEQ);
+ case BinaryOperator::NE:
+ return EmitBinaryCompare(E, llvm::ICmpInst::ICMP_NE,
+ llvm::ICmpInst::ICMP_NE,
+ llvm::FCmpInst::FCMP_UNE);
case BinaryOperator::Assign: return EmitBinaryAssign(E);
// FIXME: Assignment.
case BinaryOperator::Comma: return EmitBinaryComma(E);
@@ -771,23 +788,26 @@
return RValue::get(Builder.CreateAShr(LHS, RHS, "shr"));
}
-RValue CodeGenFunction::EmitBinaryEquality(const BinaryOperator *E) {
+RValue CodeGenFunction::EmitBinaryCompare(const BinaryOperator *E,
+ unsigned UICmpOpc, unsigned SICmpOpc,
+ unsigned FCmpOpc) {
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");
+ Result = Builder.CreateFCmp((llvm::FCmpInst::Predicate)FCmpOpc,
+ LHS.getVal(), RHS.getVal(), "cmp");
+ } else if (E->getLHS()->getType()->isUnsignedIntegerType()) {
+ // FIXME: This check isn't right for "unsigned short < int" where ushort
+ // promotes to int and does a signed compare.
+ Result = Builder.CreateICmp((llvm::ICmpInst::Predicate)UICmpOpc,
+ LHS.getVal(), RHS.getVal(), "cmp");
} 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");
+ // Signed integers and pointers.
+ Result = Builder.CreateICmp((llvm::ICmpInst::Predicate)SICmpOpc,
+ LHS.getVal(), RHS.getVal(), "cmp");
}
} else {
// Struct/union/complex
Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39666&r1=39665&r2=39666&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:46:55 2007
@@ -272,10 +272,8 @@
RValue EmitBinarySub(const BinaryOperator *E);
RValue EmitBinaryShl(const BinaryOperator *E);
RValue EmitBinaryShr(const BinaryOperator *E);
-
- // FIXME: relational
- RValue EmitBinaryEquality(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);
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39666&r1=39665&r2=39666&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:46:55 2007
@@ -190,7 +190,7 @@
84916BE60C161E800080778F /* Attr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Attr.h; path = clang/AST/Attr.h; sourceTree = "<group>"; };
84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
- 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
More information about the cfe-commits
mailing list