[llvm-commits] [gcc-plugin] r81332 - in /gcc-plugin/trunk: llvm-convert.cpp llvm-internal.h
Duncan Sands
baldrick at free.fr
Wed Sep 9 04:14:57 PDT 2009
Author: baldrick
Date: Wed Sep 9 06:14:56 2009
New Revision: 81332
URL: http://llvm.org/viewvc/llvm-project?rev=81332&view=rev
Log:
Implement POINTER_PLUS_EXPR. This is a new GCC expression
that corresponds to a GEP with one index. I'm waiting to
hear from the GCC developers as to whether it is really an
inbounds GEP.
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=81332&r1=81331&r2=81332&view=diff
==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Wed Sep 9 06:14:56 2009
@@ -925,8 +925,6 @@
case RESX_EXPR: Result = EmitRESX_EXPR(exp); break;
// Expressions
- case SSA_NAME:
- Result = EmitSSA_NAME(exp); break;
case VAR_DECL:
case PARM_DECL:
case RESULT_DECL:
@@ -940,12 +938,13 @@
case IMAGPART_EXPR:
Result = EmitLoadOfLValue(exp, DestLoc);
break;
- case OBJ_TYPE_REF: Result = EmitOBJ_TYPE_REF(exp); break;
- case ADDR_EXPR: Result = EmitADDR_EXPR(exp); break;
- case CALL_EXPR: Result = EmitCALL_EXPR(exp, DestLoc); break;
+ case SSA_NAME: Result = EmitSSA_NAME(exp); break;
+ case OBJ_TYPE_REF: Result = EmitOBJ_TYPE_REF(exp); break;
+ case ADDR_EXPR: Result = EmitADDR_EXPR(exp); break;
+ case CALL_EXPR: Result = EmitCALL_EXPR(exp, DestLoc); break;
case INIT_EXPR:
- case MODIFY_EXPR: Result = EmitMODIFY_EXPR(exp, DestLoc); break;
- case ASM_EXPR: Result = EmitASM_EXPR(exp); break;
+ case MODIFY_EXPR: Result = EmitMODIFY_EXPR(exp, DestLoc); break;
+ case ASM_EXPR: Result = EmitASM_EXPR(exp); break;
case NON_LVALUE_EXPR: Result = Emit(TREE_OPERAND(exp, 0), DestLoc); break;
// Unary Operators
@@ -1041,7 +1040,8 @@
Result = EmitMinMaxExpr(exp, ICmpInst::ICMP_UGE, ICmpInst::ICMP_SGE,
FCmpInst::FCMP_OGE);
break;
- case CONSTRUCTOR: Result = EmitCONSTRUCTOR(exp, DestLoc); break;
+ case CONSTRUCTOR: Result = EmitCONSTRUCTOR(exp, DestLoc); break;
+ case POINTER_PLUS_EXPR: Result = EmitPOINTER_PLUS_EXPR(exp); break;
// Complex Math Expressions.
case COMPLEX_CST: EmitCOMPLEX_CST (exp, DestLoc); break;
@@ -3805,6 +3805,24 @@
return Builder.CreateAdd(Quotient, CastToUIntType(Overflowed, Ty), "rdiv");
}
+Value *TreeToLLVM::EmitPOINTER_PLUS_EXPR(tree exp) {
+ tree ptr_type = TREE_TYPE(TREE_OPERAND(exp, 0));
+ Value *Ptr = Emit(TREE_OPERAND(exp, 0), 0);
+ Value *Idx = Emit(TREE_OPERAND(exp, 1), 0);
+
+ // If we are indexing over a fixed-size type, just use a GEP.
+ if (VOID_TYPE_P(TREE_TYPE(ptr_type)) || isSequentialCompatible(ptr_type))
+ return Builder.CreateInBoundsGEP(Ptr, Idx);
+
+ // Otherwise, compute the offset in bytes.
+ Value *Size = Emit(TYPE_SIZE(TREE_TYPE(ptr_type)), 0);
+ Idx = Builder.CreateMul(Idx, CastToUIntType(Size, Idx->getType()));
+
+ // Convert the pointer into an i8* and add the offset to it.
+ Ptr = Builder.CreateBitCast(Ptr, Type::getInt8Ty(Context)->getPointerTo());
+ return Builder.CreateInBoundsGEP(Ptr, Idx);
+}
+
//===----------------------------------------------------------------------===//
// ... Exception Handling ...
//===----------------------------------------------------------------------===//
Modified: gcc-plugin/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-internal.h?rev=81332&r1=81331&r2=81332&view=diff
==============================================================================
--- gcc-plugin/trunk/llvm-internal.h (original)
+++ gcc-plugin/trunk/llvm-internal.h Wed Sep 9 06:14:56 2009
@@ -575,6 +575,7 @@
Value *EmitFLOOR_DIV_EXPR(tree_node *exp);
Value *EmitROUND_DIV_EXPR(tree_node *exp);
Value *EmitFieldAnnotation(Value *FieldPtr, tree_node *FieldDecl);
+ Value *EmitPOINTER_PLUS_EXPR(tree_node *exp);
// Exception Handling.
Value *EmitEXC_PTR_EXPR(tree_node *exp);
More information about the llvm-commits
mailing list