summaryrefslogtreecommitdiffstats
path: root/clang/CodeGen/CGStmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-06-02 19:33:17 +0000
committerChris Lattner <sabre@nondot.org>2007-06-02 19:33:17 +0000
commitf0106d25785985add9f55a6f22f0f8771f8538d2 (patch)
tree797252942881db0ad3f321b6c609d25706e3cb54 /clang/CodeGen/CGStmt.cpp
parentbe31ed8e88c83dcbc19e86890cc02bc7f852a1b3 (diff)
downloadbcm5719-llvm-f0106d25785985add9f55a6f22f0f8771f8538d2.tar.gz
bcm5719-llvm-f0106d25785985add9f55a6f22f0f8771f8538d2.zip
Refactor EvaluateScalarValueToBool out of if statement emission, so it can
be shared. Implement infrastructure for unary operator emission. Implement basic logical not support. We now compile: register short X; if (!X) { into: %tmp = load i16* %X ; <i16> [#uses=1] %tobool = icmp ne i16 %tmp, 0 ; <i1> [#uses=1] %lnot = xor i1 %tobool, true ; <i1> [#uses=1] zext i1 %lnot to i32 ; <i32>:0 [#uses=1] %tobool1 = icmp ne i32 %0, 0 ; <i1> [#uses=1] br i1 %tobool1, label %ifthen, label %ifend llvm-svn: 39559
Diffstat (limited to 'clang/CodeGen/CGStmt.cpp')
-rw-r--r--clang/CodeGen/CGStmt.cpp58
1 files changed, 2 insertions, 56 deletions
diff --git a/clang/CodeGen/CGStmt.cpp b/clang/CodeGen/CGStmt.cpp
index cac8a5f675c..6332f3ecd5f 100644
--- a/clang/CodeGen/CGStmt.cpp
+++ b/clang/CodeGen/CGStmt.cpp
@@ -97,62 +97,8 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
// C99 6.8.4.1: The first substatement is executed if the expression compares
// unequal to 0. The condition must be a scalar type.
- llvm::Value *BoolCondVal;
-
- // MOVE this to a helper method, to share with for/while, assign to bool, etc.
- if (const BuiltinType *BT = dyn_cast<BuiltinType>(CondTy)) {
- switch (BT->getKind()) {
- default: assert(0 && "Unknown scalar value");
- case BuiltinType::Bool:
- BoolCondVal = CondVal.getVal();
- // Bool is already evaluated right.
- assert(BoolCondVal->getType() == llvm::Type::Int1Ty &&
- "Unexpected bool value type!");
- break;
- case BuiltinType::Char:
- case BuiltinType::SChar:
- case BuiltinType::UChar:
- case BuiltinType::Int:
- case BuiltinType::UInt:
- case BuiltinType::Long:
- case BuiltinType::ULong:
- case BuiltinType::LongLong:
- case BuiltinType::ULongLong: {
- // Compare against zero for integers.
- BoolCondVal = CondVal.getVal();
- llvm::Value *Zero = Constant::getNullValue(BoolCondVal->getType());
- BoolCondVal = Builder.CreateICmpNE(BoolCondVal, Zero, "tobool");
- break;
- }
- case BuiltinType::Float:
- case BuiltinType::Double:
- case BuiltinType::LongDouble: {
- // Compare against 0.0 for fp scalars.
- BoolCondVal = CondVal.getVal();
- llvm::Value *Zero = Constant::getNullValue(BoolCondVal->getType());
- // FIXME: llvm-gcc produces a une comparison: validate this is right.
- BoolCondVal = Builder.CreateFCmpUNE(BoolCondVal, Zero, "tobool");
- break;
- }
-
- case BuiltinType::FloatComplex:
- case BuiltinType::DoubleComplex:
- case BuiltinType::LongDoubleComplex:
- assert(0 && "comparisons against complex not implemented yet");
- }
- } else if (isa<PointerType>(CondTy)) {
- BoolCondVal = CondVal.getVal();
- llvm::Value *NullPtr = Constant::getNullValue(BoolCondVal->getType());
- BoolCondVal = Builder.CreateICmpNE(BoolCondVal, NullPtr, "tobool");
-
- } else {
- const TagType *TT = cast<TagType>(CondTy);
- assert(TT->getDecl()->getKind() == Decl::Enum && "Unknown scalar type");
- // Compare against zero.
- BoolCondVal = CondVal.getVal();
- llvm::Value *Zero = Constant::getNullValue(BoolCondVal->getType());
- BoolCondVal = Builder.CreateICmpNE(BoolCondVal, Zero, "tobool");
- }
+ llvm::Value *BoolCondVal =
+ EvaluateScalarValueToBool(CondVal, S.getCond()->getType());
BasicBlock *ContBlock = new BasicBlock("ifend");
BasicBlock *ThenBlock = new BasicBlock("ifthen");
OpenPOWER on IntegriCloud