[poolalloc] r177660 - Improved DSA's ability to infer types when structure indexing is lowered to
John Criswell
criswell at uiuc.edu
Thu Mar 21 13:24:41 PDT 2013
Author: criswell
Date: Thu Mar 21 15:24:41 2013
New Revision: 177660
URL: http://llvm.org/viewvc/llvm-project?rev=177660&view=rev
Log:
Improved DSA's ability to infer types when structure indexing is lowered to
byte-level indexing using constants.
This fixes test/dsa/local/struct_malloc.ll and, I believe, PR#15110:
http://llvm.org/bugs/show_bug.cgi?id=15110
Modified:
poolalloc/branches/release_32/lib/DSA/Local.cpp
poolalloc/branches/release_32/test/dsa/local/struct_malloc.ll
Modified: poolalloc/branches/release_32/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/branches/release_32/lib/DSA/Local.cpp?rev=177660&r1=177659&r2=177660&view=diff
==============================================================================
--- poolalloc/branches/release_32/lib/DSA/Local.cpp (original)
+++ poolalloc/branches/release_32/lib/DSA/Local.cpp Thu Mar 21 15:24:41 2013
@@ -803,9 +803,43 @@ void GraphBuilder::visitGetElementPtrIns
break;
}
} else if (const PointerType *PtrTy = dyn_cast<PointerType>(*I)) {
+ // Get the type pointed to by the pointer
Type *CurTy = PtrTy->getElementType();
//
+ // Some LLVM transforms lower structure indexing into byte-level
+ // indexing. Try to recognize forms of that here.
+ //
+ Type * Int8Type = Type::getInt8Ty(CurTy->getContext());
+ ConstantInt * IS = dyn_cast<ConstantInt>(I.getOperand());
+ if (IS &&
+ (NodeH.getOffset() == 0) &&
+ (!(NodeH.getNode()->isArrayNode())) &&
+ (CurTy == Int8Type)) {
+ // Calculate the offset of the field
+ Offset += IS->getSExtValue() * TD.getTypeAllocSize (Int8Type);
+
+ //
+ // Grow the DSNode size as needed.
+ //
+ unsigned requiredSize = Offset + TD.getTypeAllocSize (Int8Type);
+ if (NodeH.getNode()->getSize() <= requiredSize){
+ NodeH.getNode()->growSize (requiredSize);
+ }
+
+ // Add in the offset calculated...
+ NodeH.setOffset(NodeH.getOffset()+Offset);
+
+ // Check the offset
+ DSNode *N = NodeH.getNode();
+ if (N) N->checkOffsetFoldIfNeeded(NodeH.getOffset());
+
+ // NodeH is now the pointer we want to GEP to be...
+ setDestTo(GEP, NodeH);
+ return;
+ }
+
+ //
// Unless we're advancing the pointer by zero bytes via array indexing,
// fold the node (i.e., mark it type-unknown) and indicate that we're
// indexing zero bytes into the object (because all fields are aliased).
Modified: poolalloc/branches/release_32/test/dsa/local/struct_malloc.ll
URL: http://llvm.org/viewvc/llvm-project/poolalloc/branches/release_32/test/dsa/local/struct_malloc.ll?rev=177660&r1=177659&r2=177660&view=diff
==============================================================================
--- poolalloc/branches/release_32/test/dsa/local/struct_malloc.ll (original)
+++ poolalloc/branches/release_32/test/dsa/local/struct_malloc.ll Thu Mar 21 15:24:41 2013
@@ -1,5 +1,4 @@
-;RUN: dsaopt %s -dsa-local -analyze -check-type=func:struct,0:i32Array
-;XFAIL: *
+;RUN: dsaopt %s -dsa-local -analyze -check-type=func:struct,0:i32::4:i32
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list