[llvm-commits] [gcc-plugin] r81918 - in /gcc-plugin/trunk: llvm-convert.cpp llvm-internal.h

Duncan Sands baldrick at free.fr
Tue Sep 15 14:24:15 PDT 2009


Author: baldrick
Date: Tue Sep 15 16:24:15 2009
New Revision: 81918

URL: http://llvm.org/viewvc/llvm-project?rev=81918&view=rev
Log:
Add support for constant POINTER_PLUS_EXPR.

Modified:
    gcc-plugin/trunk/llvm-convert.cpp
    gcc-plugin/trunk/llvm-internal.h

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=81918&r1=81917&r2=81918&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Tue Sep 15 16:24:15 2009
@@ -6941,6 +6941,7 @@
   case MINUS_EXPR:    return ConvertBinOp_CST(exp);
   case CONSTRUCTOR:   return ConvertCONSTRUCTOR(exp);
   case VIEW_CONVERT_EXPR: return Convert(TREE_OPERAND(exp, 0));
+  case POINTER_PLUS_EXPR: return ConvertPOINTER_PLUS_EXPR(exp);
   case ADDR_EXPR:
     return TheFolder->CreateBitCast(EmitLV(TREE_OPERAND(exp, 0)),
                                     ConvertType(TREE_TYPE(exp)));
@@ -7152,6 +7153,20 @@
   return TheFolder->CreateCast(opcode, Elt, Ty);
 }
 
+Constant *TreeConstantToLLVM::ConvertPOINTER_PLUS_EXPR(tree exp) {
+  Constant *Ptr = Convert(TREE_OPERAND(exp, 0)); // The pointer.
+  Constant *Idx = Convert(TREE_OPERAND(exp, 1)); // The offset in bytes.
+
+  // Convert the pointer into an i8* and add the offset to it.
+  Ptr = TheFolder->CreateBitCast(Ptr, Type::getInt8Ty(Context)->getPointerTo());
+  Constant *GEP = POINTER_TYPE_OVERFLOW_UNDEFINED ?
+    TheFolder->CreateInBoundsGetElementPtr(Ptr, &Idx, 1) :
+    TheFolder->CreateGetElementPtr(Ptr, &Idx, 1);
+
+  // The result may be of a different pointer type.
+  return TheFolder->CreateBitCast(GEP, ConvertType(TREE_TYPE(exp)));
+}
+
 Constant *TreeConstantToLLVM::ConvertBinOp_CST(tree exp) {
   Constant *LHS = Convert(TREE_OPERAND(exp, 0));
   bool LHSIsSigned = !TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND(exp,0)));

Modified: gcc-plugin/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-internal.h?rev=81918&r1=81917&r2=81918&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-internal.h (original)
+++ gcc-plugin/trunk/llvm-internal.h Tue Sep 15 16:24:15 2009
@@ -683,7 +683,8 @@
   static Constant *ConvertArrayCONSTRUCTOR(tree_node *exp);
   static Constant *ConvertRecordCONSTRUCTOR(tree_node *exp);
   static Constant *ConvertUnionCONSTRUCTOR(tree_node *exp);
-  
+  static Constant *ConvertPOINTER_PLUS_EXPR(tree_node *exp);
+
   // Constant Expression l-values.
   static Constant *EmitLV(tree_node *exp);
   static Constant *EmitLV_Decl(tree_node *exp);





More information about the llvm-commits mailing list