[cfe-commits] r39713 - in /cfe/cfe/trunk: CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.h include/clang/AST/Expr.h

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:47:26 PDT 2007


Author: clattner
Date: Wed Jul 11 11:47:25 2007
New Revision: 39713

URL: http://llvm.org/viewvc/llvm-project?rev=39713&view=rev
Log:
add codegen support for <<= and >>=.

Modified:
    cfe/cfe/trunk/CodeGen/CGExpr.cpp
    cfe/cfe/trunk/CodeGen/CodeGenFunction.h
    cfe/cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGExpr.cpp?rev=39713&r1=39712&r2=39713&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGExpr.cpp Wed Jul 11 11:47:25 2007
@@ -724,6 +724,14 @@
   QualType RHSTy;
   RHS = EmitExprWithUsualUnaryConversions(E->getRHS(), RHSTy);
   
+  // Shift operands do the usual unary conversions, but do not do the binary
+  // conversions.
+  if (E->isShiftAssignOp()) {
+    // FIXME: This is broken.  Implicit conversions should be made explicit,
+    // so that this goes away.  This causes us to reload the LHS.
+    LHS = EmitExprWithUsualUnaryConversions(E->getLHS(), LHSTy);
+  }
+  
   // Convert the LHS and RHS to the common evaluation type.
   LHS = EmitConversion(LHS, LHSTy, E->getComputationType());
   RHS = EmitConversion(RHS, RHSTy, E->getComputationType());
@@ -772,8 +780,12 @@
     // FIXME: This doesn't handle ptr-int etc yet.
     EmitUsualArithmeticConversions(E, LHS, RHS);
     return EmitSub(LHS, RHS, E->getType());
-  case BinaryOperator::Shl: return EmitBinaryShl(E);
-  case BinaryOperator::Shr: return EmitBinaryShr(E);
+  case BinaryOperator::Shl:
+    EmitShiftOperands(E, LHS, RHS);
+    return EmitShl(LHS, RHS, E->getType());
+  case BinaryOperator::Shr:
+    EmitShiftOperands(E, LHS, RHS);
+    return EmitShr(LHS, RHS, E->getType());
   case BinaryOperator::And:
     EmitUsualArithmeticConversions(E, LHS, RHS);
     return EmitAnd(LHS, RHS, E->getType());
@@ -847,6 +859,20 @@
     LHS = EmitSub(LHS, RHS, CAO->getComputationType());
     return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
   }
+  case BinaryOperator::ShlAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitShl(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::ShrAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitShr(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
   case BinaryOperator::AndAssign: {
     const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
     LValue LHSLV;
@@ -932,17 +958,19 @@
   assert(0 && "FIXME: This doesn't handle complex operands yet");
 }
 
-
-RValue CodeGenFunction::EmitBinaryShl(const BinaryOperator *E) {
+void CodeGenFunction::EmitShiftOperands(const BinaryOperator *E,
+                                        RValue &LHS, RValue &RHS) {
   // For shifts, integer promotions are performed, but the usual arithmetic 
   // conversions are not.  The LHS and RHS need not have the same type.
-  
   QualType ResTy;
-  llvm::Value *LHS = 
-    EmitExprWithUsualUnaryConversions(E->getLHS(), ResTy).getVal();
-  llvm::Value *RHS = 
-    EmitExprWithUsualUnaryConversions(E->getRHS(), ResTy).getVal();
+  LHS = EmitExprWithUsualUnaryConversions(E->getLHS(), ResTy);
+  RHS = EmitExprWithUsualUnaryConversions(E->getRHS(), ResTy);
+}
+
 
+RValue CodeGenFunction::EmitShl(RValue LHSV, RValue RHSV, QualType ResTy) {
+  llvm::Value *LHS = LHSV.getVal(), *RHS = RHSV.getVal();
+  
   // LLVM requires the LHS and RHS to be the same type, promote or truncate the
   // RHS to the same size as the LHS.
   if (LHS->getType() != RHS->getType())
@@ -951,22 +979,15 @@
   return RValue::get(Builder.CreateShl(LHS, RHS, "shl"));
 }
 
-RValue CodeGenFunction::EmitBinaryShr(const BinaryOperator *E) {
-  // For shifts, integer promotions are performed, but the usual arithmetic 
-  // conversions are not.  The LHS and RHS need not have the same type.
-  
-  QualType ResTy;
-  llvm::Value *LHS = 
-    EmitExprWithUsualUnaryConversions(E->getLHS(), ResTy).getVal();
-  llvm::Value *RHS = 
-    EmitExprWithUsualUnaryConversions(E->getRHS(), ResTy).getVal();
+RValue CodeGenFunction::EmitShr(RValue LHSV, RValue RHSV, QualType ResTy) {
+  llvm::Value *LHS = LHSV.getVal(), *RHS = RHSV.getVal();
   
   // LLVM requires the LHS and RHS to be the same type, promote or truncate the
   // RHS to the same size as the LHS.
   if (LHS->getType() != RHS->getType())
     RHS = Builder.CreateIntCast(RHS, LHS->getType(), false, "sh_prom");
   
-  if (E->getType()->isUnsignedIntegerType())
+  if (ResTy->isUnsignedIntegerType())
     return RValue::get(Builder.CreateLShr(LHS, RHS, "shr"));
   else
     return RValue::get(Builder.CreateAShr(LHS, RHS, "shr"));

Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39713&r1=39712&r2=39713&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:47:25 2007
@@ -270,7 +270,8 @@
   RValue EmitExprWithUsualUnaryConversions(const Expr *E, QualType &ResTy);
   QualType EmitUsualArithmeticConversions(const BinaryOperator *E,
                                           RValue &LHS, RValue &RHS);
-  
+  void EmitShiftOperands(const BinaryOperator *E, RValue &LHS, RValue &RHS);
+
   void EmitCompoundAssignmentOperands(const CompoundAssignOperator *CAO,
                                       LValue &LHSLV, RValue &LHS, RValue &RHS);
   RValue EmitCompoundAssignmentResult(const CompoundAssignOperator *E,
@@ -304,8 +305,8 @@
   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 EmitShl(RValue LHS, RValue RHS, QualType ResTy);
+  RValue EmitShr(RValue LHS, RValue RHS, QualType ResTy);
   RValue EmitBinaryCompare(const BinaryOperator *E, unsigned UICmpOpc,
                            unsigned SICmpOpc, unsigned FCmpOpc);
   RValue EmitAnd(RValue LHS, RValue RHS, QualType EltTy);

Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39713&r1=39712&r2=39713&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:47:25 2007
@@ -504,6 +504,7 @@
   bool isLogicalOp() const { return Opc == LAnd || Opc == LOr; }
   bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
   bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
+  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
   
   virtual void visit(StmtVisitor &Visitor);
   static bool classof(const Stmt *T) { 





More information about the cfe-commits mailing list