summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhigang Gong <zhigang.gong@intel.com>2014-12-02 13:48:26 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-12-02 17:01:20 +0800
commit5e70dd0d9f6f4d0659ba9403e27f2403669327a2 (patch)
treea945498631a1aac1ae23adcb6dda757def08bd4c
parentf892b6e05bee640d786840a7b6efee5a13dcaa8c (diff)
GBE: optimize GEP constant offset calculation.
If the type is array or vector, we do not need to iterate each element. We can compute it directly. v2: Use more generic SequentialType and StructType to identify whether we can compute the offset directly. Signed-off-by: Zhigang Gong <zhigang.gong@intel.com> Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com>
-rw-r--r--backend/src/llvm/llvm_passes.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
index 24ad9d0e..ff9ab76f 100644
--- a/backend/src/llvm/llvm_passes.cpp
+++ b/backend/src/llvm/llvm_passes.cpp
@@ -275,7 +275,7 @@ namespace gbe
Value* currentAddrInst =
new PtrToIntInst(parentPointer, IntegerType::get(GEPInst->getContext(), ptrSize), "", GEPInst);
- uint32_t constantOffset = 0;
+ int32_t constantOffset = 0;
for(uint32_t op=1; op<GEPInst->getNumOperands(); ++op)
{
@@ -286,15 +286,17 @@ namespace gbe
int32_t offset = 0;
TypeIndex = ConstOP->getZExtValue();
int32_t step = TypeIndex > 0 ? 1 : -1;
- if (op == 1) {
+ SequentialType * seqType = dyn_cast<SequentialType>(CompTy);
+ if (seqType != NULL) {
if (TypeIndex != 0) {
- Type *elementType = (cast<PointerType>(parentPointer->getType()))->getElementType();
+ Type *elementType = seqType->getElementType();
uint32_t elementSize = getTypeByteSize(unit, elementType);
uint32_t align = getAlignmentByte(unit, elementType);
elementSize += getPadding(elementSize, align);
offset += elementSize * TypeIndex;
}
} else {
+ GBE_ASSERT(CompTy->isStructTy());
for(int32_t ty_i=0; ty_i != TypeIndex; ty_i += step)
{
Type* elementType = CompTy->getTypeAtIndex(ty_i);