[llvm-commits] [gcc-plugin] r81623 - /gcc-plugin/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Sat Sep 12 12:47:47 PDT 2009


Author: baldrick
Date: Sat Sep 12 14:47:47 2009
New Revision: 81623

URL: http://llvm.org/viewvc/llvm-project?rev=81623&view=rev
Log:
The LLVM ARRAY_REF extension (allowing ARRAY_REF with pointer types,
improving code quality by mapping pointer arithmetic to GEP) does not
exist in mainline gcc, and is less useful since POINTER_PLUS_EXPR is
now used by gcc, and that maps directly to a GEP.  Remove dead code
that existed to handle this extension.

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

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

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Sat Sep 12 14:47:47 2009
@@ -6515,33 +6515,20 @@
   tree IndexType = TREE_TYPE(Index);
   tree ElementType = TREE_TYPE(ArrayTreeType);
 
-  assert((TREE_CODE (ArrayTreeType) == ARRAY_TYPE ||
-          TREE_CODE (ArrayTreeType) == POINTER_TYPE ||
-          TREE_CODE (ArrayTreeType) == REFERENCE_TYPE) &&
-         "Unknown ARRAY_REF!");
+  assert(TREE_CODE (ArrayTreeType) == ARRAY_TYPE && "Unknown ARRAY_REF!");
 
-  // As an LLVM extension, we allow ARRAY_REF with a pointer as the first
-  // operand.  This construct maps directly to a getelementptr instruction.
   Value *ArrayAddr;
   unsigned ArrayAlign;
 
-  if (TREE_CODE(ArrayTreeType) == ARRAY_TYPE) {
-    // First subtract the lower bound, if any, in the type of the index.
-    tree LowerBound = array_ref_low_bound(exp);
-    if (!integer_zerop(LowerBound))
-      Index = fold(build2(MINUS_EXPR, IndexType, Index, LowerBound));
-
-    LValue ArrayAddrLV = EmitLV(Array);
-    assert(!ArrayAddrLV.isBitfield() && "Arrays cannot be bitfields!");
-    ArrayAddr = ArrayAddrLV.Ptr;
-    ArrayAlign = ArrayAddrLV.getAlignment();
-  } else {
-    ArrayAddr = Emit(Array, 0);
-    if (TREE_CODE (ArrayTreeType) == POINTER_TYPE)
-      ArrayAlign = getPointerAlignment(Array);
-    else
-      ArrayAlign = 1;
-  }
+  // First subtract the lower bound, if any, in the type of the index.
+  tree LowerBound = array_ref_low_bound(exp);
+  if (!integer_zerop(LowerBound))
+    Index = fold(build2(MINUS_EXPR, IndexType, Index, LowerBound));
+
+  LValue ArrayAddrLV = EmitLV(Array);
+  assert(!ArrayAddrLV.isBitfield() && "Arrays cannot be bitfields!");
+  ArrayAddr = ArrayAddrLV.Ptr;
+  ArrayAlign = ArrayAddrLV.getAlignment();
 
   Value *IndexVal = Emit(Index, 0);
 
@@ -6555,13 +6542,12 @@
 
   // If we are indexing over a fixed-size type, just use a GEP.
   if (isSequentialCompatible(ArrayTreeType)) {
-    SmallVector<Value*, 2> Idx;
-    if (TREE_CODE(ArrayTreeType) == ARRAY_TYPE)
-      Idx.push_back(ConstantInt::get(IntPtrTy, 0));
-    Idx.push_back(IndexVal);
+    Value *Idx[2];
+    Idx[0] = ConstantInt::get(IntPtrTy, 0);
+    Idx[1] = IndexVal;
     Value *Ptr = POINTER_TYPE_OVERFLOW_UNDEFINED ?
-      Builder.CreateInBoundsGEP(ArrayAddr, Idx.begin(), Idx.end()) :
-      Builder.CreateGEP(ArrayAddr, Idx.begin(), Idx.end());
+      Builder.CreateInBoundsGEP(ArrayAddr, Idx, Idx + 2) :
+      Builder.CreateGEP(ArrayAddr, Idx, Idx + 2);
 
     const Type *ElementTy = ConvertType(ElementType);
     unsigned Alignment = MinAlign(ArrayAlign, TD.getABITypeAlignment(ElementTy));
@@ -8059,27 +8045,18 @@
   tree ArrayType = TREE_TYPE(Array);
   tree Index = TREE_OPERAND(exp, 1);
   tree IndexType = TREE_TYPE(Index);
-  assert((TREE_CODE(ArrayType) == ARRAY_TYPE ||
-          TREE_CODE(ArrayType) == POINTER_TYPE ||
-          TREE_CODE(ArrayType) == REFERENCE_TYPE) &&
-         "Unknown ARRAY_REF!");
+  assert(TREE_CODE(ArrayType) == ARRAY_TYPE && "Unknown ARRAY_REF!");
 
   // Check for variable sized reference.
   // FIXME: add support for array types where the size doesn't fit into 64 bits
   assert(isSequentialCompatible(ArrayType) && "Global with variable size?");
 
-  // As an LLVM extension, we allow ARRAY_REF with a pointer as the first
-  // operand.  This construct maps directly to a getelementptr instruction.
   Constant *ArrayAddr;
-  if (TREE_CODE(ArrayType) == ARRAY_TYPE) {
-    // First subtract the lower bound, if any, in the type of the index.
-    tree LowerBound = array_ref_low_bound(exp);
-    if (!integer_zerop(LowerBound))
-      Index = fold(build2(MINUS_EXPR, IndexType, Index, LowerBound));
-    ArrayAddr = EmitLV(Array);
-  } else {
-    ArrayAddr = Convert(Array);
-  }
+  // First subtract the lower bound, if any, in the type of the index.
+  tree LowerBound = array_ref_low_bound(exp);
+  if (!integer_zerop(LowerBound))
+    Index = fold(build2(MINUS_EXPR, IndexType, Index, LowerBound));
+  ArrayAddr = EmitLV(Array);
 
   Constant *IndexVal = Convert(Index);
 
@@ -8088,12 +8065,11 @@
     IndexVal = TheFolder->CreateIntCast(IndexVal, IntPtrTy,
                                         !TYPE_UNSIGNED(IndexType));
 
-  std::vector<Value*> Idx;
-  if (TREE_CODE(ArrayType) == ARRAY_TYPE)
-    Idx.push_back(ConstantInt::get(IntPtrTy, 0));
-  Idx.push_back(IndexVal);
+  Value *Idx[2];
+  Idx[0] = ConstantInt::get(IntPtrTy, 0);
+  Idx[1] = IndexVal;
 
-  return TheFolder->CreateGetElementPtr(ArrayAddr, &Idx[0], Idx.size());
+  return TheFolder->CreateGetElementPtr(ArrayAddr, Idx, 2);
 }
 
 Constant *TreeConstantToLLVM::EmitLV_COMPONENT_REF(tree exp) {





More information about the llvm-commits mailing list