[llvm-commits] [polly] r147305 - /polly/trunk/lib/CodeGeneration.cpp

Raghesh Aloor raghesh.a at gmail.com
Tue Dec 27 18:48:26 PST 2011


Author: raghesh
Date: Tue Dec 27 20:48:26 2011
New Revision: 147305

URL: http://llvm.org/viewvc/llvm-project?rev=147305&view=rev
Log:
Memaccess: Using isl_map_dim_max

Use isl_map_dim_max to extract the details of the changed
access relation. Only constant access functions are supported
now.


Modified:
    polly/trunk/lib/CodeGeneration.cpp

Modified: polly/trunk/lib/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGeneration.cpp?rev=147305&r1=147304&r2=147305&view=diff
==============================================================================
--- polly/trunk/lib/CodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGeneration.cpp Tue Dec 27 20:48:26 2011
@@ -44,6 +44,8 @@
 #include "cloog/cloog.h"
 #include "cloog/isl/cloog.h"
 
+#include "isl/aff.h"
+
 #include <vector>
 #include <utility>
 
@@ -83,6 +85,11 @@
 typedef DenseMap<const Value*, Value*> ValueMapT;
 typedef DenseMap<const char*, Value*> CharMapT;
 typedef std::vector<ValueMapT> VectorValueMapT;
+typedef struct {
+  Value *BaseAddress;
+  Value *Result;
+  IRBuilder<> *Builder;
+}IslPwAffUserInfo;
 
 // Create a new loop.
 //
@@ -315,6 +322,58 @@
     return vector;
   }
 
+  static Value* islAffToValue(__isl_take isl_aff *Aff,
+                              IslPwAffUserInfo *UserInfo) {
+    assert(isl_aff_is_cst(Aff) && "Only constant access functions supported");
+
+    IRBuilder<> *Builder = UserInfo->Builder;
+
+    isl_int OffsetIsl;
+    mpz_t OffsetMPZ;
+
+    isl_int_init(OffsetIsl);
+    mpz_init(OffsetMPZ);
+    isl_aff_get_constant(Aff, &OffsetIsl);
+    isl_int_get_gmp(OffsetIsl, OffsetMPZ);
+
+    Value *OffsetValue = NULL;
+    APInt Offset = APInt_from_MPZ(OffsetMPZ);
+    OffsetValue = ConstantInt::get(Builder->getContext(), Offset);
+
+    mpz_clear(OffsetMPZ);
+    isl_int_clear(OffsetIsl);
+    isl_aff_free(Aff);
+
+    return OffsetValue;
+  }
+
+  static int mergeIslAffValues(__isl_take isl_set *Set,
+                               __isl_take isl_aff *Aff, void *User) {
+    IslPwAffUserInfo *UserInfo = (IslPwAffUserInfo *)User;
+
+    assert((UserInfo->Result == NULL) && "Result is already set."
+           "Currently only single isl_aff is supported");
+    assert(isl_set_plain_is_universe(Set)
+           && "Code generation failed because the set is not universe");
+
+    UserInfo->Result = islAffToValue(Aff, UserInfo);
+
+    isl_set_free(Set);
+    return 0;
+  }
+
+  Value* islPwAffToValue(__isl_take isl_pw_aff *PwAff, Value *BaseAddress) {
+    IslPwAffUserInfo UserInfo;
+    UserInfo.BaseAddress = BaseAddress;
+    UserInfo.Result = NULL;
+    UserInfo.Builder = &Builder;
+    isl_pw_aff_foreach_piece(PwAff, mergeIslAffValues, &UserInfo);
+    assert(UserInfo.Result && "Code generation for isl_pw_aff failed");
+
+    isl_pw_aff_free(PwAff);
+    return UserInfo.Result;
+  }
+
   /// @brief Get the memory access offset to be added to the base address
   std::vector <Value*> getMemoryAccessIndex(__isl_keep isl_map *AccessRelation,
                                             Value *BaseAddress) {
@@ -324,13 +383,9 @@
     assert((isl_map_dim(AccessRelation, isl_dim_out) == 1)
            && "Only single dimensional access functions supported");
 
-    if (isl_map_plain_is_fixed(AccessRelation, isl_dim_out,
-                               0, &OffsetMPZ) == -1)
-      errs() << "Only fixed value access functions supported\n";
+    isl_pw_aff *PwAff = isl_map_dim_max(isl_map_copy(AccessRelation), 0);
+    Value *OffsetValue = islPwAffToValue(PwAff, BaseAddress);
 
-    // Convert the offset from MPZ to Value*.
-    APInt Offset = APInt_from_MPZ(OffsetMPZ);
-    Value *OffsetValue = ConstantInt::get(Builder.getContext(), Offset);
     PointerType *BaseAddressType = dyn_cast<PointerType>(
                                    BaseAddress->getType());
     Type *ArrayTy = BaseAddressType->getElementType();





More information about the llvm-commits mailing list