[cfe-commits] r45427 - /cfe/trunk/CodeGen/CodeGenModule.cpp
Chris Lattner
sabre at nondot.org
Sat Dec 29 15:43:40 PST 2007
Author: lattner
Date: Sat Dec 29 17:43:37 2007
New Revision: 45427
URL: http://llvm.org/viewvc/llvm-project?rev=45427&view=rev
Log:
implement codegen support for most unary operators when
initializing a global. This handles important cases like:
float foo3 = -0.01f;
Modified:
cfe/trunk/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=45427&r1=45426&r2=45427&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Sat Dec 29 17:43:37 2007
@@ -424,7 +424,42 @@
case Stmt::CastExprClass:
return GenerateConstantCast(cast<CastExpr>(Expression)->getSubExpr(), type,
CGM);
-
+ case Stmt::UnaryOperatorClass: {
+ const UnaryOperator *Op = cast<UnaryOperator>(Expression);
+ llvm::Constant *SubExpr = GenerateConstantExpr(Op->getSubExpr(), CGM);
+ // FIXME: These aren't right for complex.
+ switch (Op->getOpcode()) {
+ default: break;
+ case UnaryOperator::Plus:
+ case UnaryOperator::Extension:
+ return SubExpr;
+ case UnaryOperator::Minus:
+ return llvm::ConstantExpr::getNeg(SubExpr);
+ case UnaryOperator::Not:
+ return llvm::ConstantExpr::getNot(SubExpr);
+ case UnaryOperator::LNot:
+ if (Op->getSubExpr()->getType()->isRealFloatingType()) {
+ // Compare against 0.0 for fp scalars.
+ llvm::Constant *Zero = llvm::Constant::getNullValue(SubExpr->getType());
+ SubExpr = llvm::ConstantExpr::getFCmp(llvm::FCmpInst::FCMP_UNE, SubExpr,
+ Zero);
+ } else {
+ assert((Op->getSubExpr()->getType()->isIntegerType() ||
+ Op->getSubExpr()->getType()->isPointerType()) &&
+ "Unknown scalar type to convert");
+ // Compare against an integer or pointer null.
+ llvm::Constant *Zero = llvm::Constant::getNullValue(SubExpr->getType());
+ SubExpr = llvm::ConstantExpr::getICmp(llvm::ICmpInst::ICMP_NE, SubExpr,
+ Zero);
+ }
+
+ return llvm::ConstantExpr::getZExt(SubExpr, Types.ConvertType(type));
+ //SizeOf, AlignOf, // [C99 6.5.3.4] Sizeof (expr, not type) operator.
+ //Real, Imag, // "__real expr"/"__imag expr" Extension.
+ //OffsetOf // __builtin_offsetof
+ }
+ break;
+ }
case Stmt::ImplicitCastExprClass: {
const ImplicitCastExpr *ICExpr = cast<ImplicitCastExpr>(Expression);
More information about the cfe-commits
mailing list