[polly] r245451 - Generate alias metadata even in OpenMP mode

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 09:04:36 PDT 2015


Author: grosser
Date: Wed Aug 19 11:04:35 2015
New Revision: 245451

URL: http://llvm.org/viewvc/llvm-project?rev=245451&view=rev
Log:
Generate alias metadata even in OpenMP mode

To make alias scope metadata generation work in OpenMP mode we now provide
the ScopAnnotator with information about the base pointer rewrite that happens
when passing arrays into the OpenMP subfunction.

Added:
    polly/trunk/test/Isl/CodeGen/OpenMP/alias-metadata.ll
Modified:
    polly/trunk/include/polly/CodeGen/IRBuilder.h
    polly/trunk/lib/CodeGen/IRBuilder.cpp
    polly/trunk/lib/CodeGen/IslNodeBuilder.cpp

Modified: polly/trunk/include/polly/CodeGen/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/IRBuilder.h?rev=245451&r1=245450&r2=245451&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/IRBuilder.h (original)
+++ polly/trunk/include/polly/CodeGen/IRBuilder.h Wed Aug 19 11:04:35 2015
@@ -17,6 +17,7 @@
 
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/ValueMap.h"
 
 namespace llvm {
 class ScalarEvolution;
@@ -59,6 +60,25 @@ public:
   void annotateLoopLatch(llvm::BranchInst *B, llvm::Loop *L,
                          bool IsParallel) const;
 
+  /// @brief Add alternative alias based pointers
+  ///
+  /// When annotating instructions with alias scope metadata, the right metadata
+  /// is identified through the base pointer of the memory access. In some cases
+  /// (e.g. OpenMP code generation), the base pointer of the memory accesses is
+  /// not the original base pointer, but was changed when passing the original
+  /// base pointer over a function boundary. This function allows to provide a
+  /// map that maps from these new base pointers to the original base pointers
+  /// to allow the ScopAnnotator to still find the right alias scop annotations.
+  ///
+  /// @param NewMap A map from new base pointers to original base pointers.
+  void addAlternativeAliasBases(
+      llvm::ValueMap<llvm::Value *, llvm::Value *> &NewMap) {
+    AlternativeAliasBases.insert(NewMap.begin(), NewMap.end());
+  }
+
+  /// @brief Delete the set of alternative alias bases
+  void resetAlternativeAliasBases() { AlternativeAliasBases.clear(); }
+
 private:
   /// @brief The ScalarEvolution analysis we use to find base pointers.
   llvm::ScalarEvolution *SE;
@@ -77,6 +97,8 @@ private:
 
   /// @brief A map from base pointers to an alias scope list of other pointers.
   llvm::DenseMap<llvm::Value *, llvm::MDNode *> OtherAliasScopeListMap;
+
+  llvm::ValueMap<llvm::Value *, llvm::Value *> AlternativeAliasBases;
 };
 
 /// @brief Add Polly specifics when running IRBuilder.

Modified: polly/trunk/lib/CodeGen/IRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IRBuilder.cpp?rev=245451&r1=245450&r2=245451&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IRBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IRBuilder.cpp Wed Aug 19 11:04:35 2015
@@ -135,8 +135,16 @@ void ScopAnnotator::annotate(Instruction
     }
 
     if (BasePtr) {
-      Inst->setMetadata("alias.scope", AliasScopeMap[BasePtr]);
-      Inst->setMetadata("noalias", OtherAliasScopeListMap[BasePtr]);
+      auto *AliasScope = AliasScopeMap[BasePtr];
+
+      if (!AliasScope)
+        BasePtr = AlternativeAliasBases[BasePtr];
+
+      AliasScope = AliasScopeMap[BasePtr];
+      auto *OtherAliasScopeList = OtherAliasScopeListMap[BasePtr];
+
+      Inst->setMetadata("alias.scope", AliasScope);
+      Inst->setMetadata("noalias", OtherAliasScopeList);
     }
   }
 

Modified: polly/trunk/lib/CodeGen/IslNodeBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslNodeBuilder.cpp?rev=245451&r1=245450&r2=245451&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslNodeBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslNodeBuilder.cpp Wed Aug 19 11:04:35 2015
@@ -519,8 +519,16 @@ void IslNodeBuilder::createForParallel(_
   updateValues(NewValues);
   IDToValue[IteratorID] = IV;
 
+  ParallelLoopGenerator::ValueToValueMapTy NewValuesReverse;
+
+  for (auto P : NewValues)
+    NewValuesReverse[P.second] = P.first;
+
+  Annotator.addAlternativeAliasBases(NewValuesReverse);
+
   create(Body);
 
+  Annotator.resetAlternativeAliasBases();
   // Restore the original values.
   ValueMap = ValueMapCopy;
   IDToValue = IDToValueCopy;

Added: polly/trunk/test/Isl/CodeGen/OpenMP/alias-metadata.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/alias-metadata.ll?rev=245451&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/alias-metadata.ll (added)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/alias-metadata.ll Wed Aug 19 11:04:35 2015
@@ -0,0 +1,52 @@
+; RUN: opt %loadPolly -polly-codegen -polly-parallel -S < %s | FileCheck %s
+;
+;    void foo(float *A, float *B) {
+;      for (long i = 0; i < 1000; i++)
+;        for (long j = 0; j < 1000; j++)
+;          A[i] = B[i];
+;    }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+; CHECK: define internal void @foo.polly.subfn
+
+define void @foo(float* %A, float* %B) {
+bb:
+  br label %bb2
+
+bb2:                                              ; preds = %bb11, %bb
+  %i.0 = phi i64 [ 0, %bb ], [ %tmp12, %bb11 ]
+  %exitcond1 = icmp ne i64 %i.0, 1000
+  br i1 %exitcond1, label %bb3, label %bb13
+
+bb3:                                              ; preds = %bb2
+  br label %bb4
+
+bb4:                                              ; preds = %bb8, %bb3
+  %j.0 = phi i64 [ 0, %bb3 ], [ %tmp9, %bb8 ]
+  %exitcond = icmp ne i64 %j.0, 1000
+  br i1 %exitcond, label %bb5, label %bb10
+
+bb5:                                              ; preds = %bb4
+  %tmp = getelementptr inbounds float, float* %B, i64 %i.0
+  %tmp7 = getelementptr inbounds float, float* %A, i64 %i.0
+  %tmp6 = load float, float* %tmp, align 4
+  store float %tmp6, float* %tmp7, align 4
+; CHECK: %tmp6_p_scalar_ = load float, float* %scevgep, align 4, !alias.scope !0, !noalias !2
+; CHECK: store float %tmp6_p_scalar_, float* %scevgep8, align 4, !alias.scope !3, !noalias !4
+  br label %bb8
+
+bb8:                                              ; preds = %bb5
+  %tmp9 = add nsw i64 %j.0, 1
+  br label %bb4
+
+bb10:                                             ; preds = %bb4
+  br label %bb11
+
+bb11:                                             ; preds = %bb10
+  %tmp12 = add nsw i64 %i.0, 1
+  br label %bb2
+
+bb13:                                             ; preds = %bb2
+  ret void
+}




More information about the llvm-commits mailing list