[PATCH] D25559: [LoopVersioning] Get versionLoop to return a basic block with RT checks + allow user's RuntimePointerChecking in annotateLoopWithNoAlias and prepareNoAliasMetadata

Evgeny Astigeevich via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 07:25:47 PDT 2016


eastig created this revision.
eastig added reviewers: anemet, sbaranga, ashutosh.nema.
eastig added a subscriber: llvm-commits.

- A user of LoopVersioning might need a basic block where RT checks have been created. This patch provides such functionality.
- LoopVersioning allows a user to provide own checks. Also LoopVersioning can annotate a loop with no-alias metadata but it uses RuntimePointerChecking provided by LoopAccessInfo. This RuntimePointerChecking must correspond to the checks provided by the user which is not always possible. This patch allows a user to provide RuntimePointerChecking which corresponds to the provided checks.


https://reviews.llvm.org/D25559

Files:
  include/llvm/Transforms/Utils/LoopVersioning.h
  lib/Transforms/Utils/LoopVersioning.cpp


Index: lib/Transforms/Utils/LoopVersioning.cpp
===================================================================
--- lib/Transforms/Utils/LoopVersioning.cpp
+++ lib/Transforms/Utils/LoopVersioning.cpp
@@ -52,7 +52,7 @@
   Preds = std::move(Check);
 }
 
-void LoopVersioning::versionLoop(
+BasicBlock* LoopVersioning::versionLoop(
     const SmallVectorImpl<Instruction *> &DefsUsedOutside) {
   Instruction *FirstCheckInst;
   Instruction *MemRuntimeCheck;
@@ -119,6 +119,8 @@
   // Adds the necessary PHI nodes for the versioned loops based on the
   // loop-defined values used outside of the loop.
   addPHINodes(DefsUsedOutside);
+
+  return RuntimeCheckBB;
 }
 
 void LoopVersioning::addPHINodes(
@@ -162,15 +164,18 @@
   }
 }
 
-void LoopVersioning::prepareNoAliasMetadata() {
+void LoopVersioning::prepareNoAliasMetadata(
+    const RuntimePointerChecking *RtPtrChecking) {
   // We need to turn the no-alias relation between pointer checking groups into
   // no-aliasing annotations between instructions.
   //
   // We accomplish this by mapping each pointer checking group (a set of
   // pointers memchecked together) to an alias scope and then also mapping each
   // group to the list of scopes it can't alias.
 
-  const RuntimePointerChecking *RtPtrChecking = LAI.getRuntimePointerChecking();
+  if (!RtPtrChecking)
+    RtPtrChecking = LAI.getRuntimePointerChecking();
+
   LLVMContext &Context = VersionedLoop->getHeader()->getContext();
 
   // First allocate an aliasing scope for each pointer checking group.
@@ -204,12 +209,13 @@
     GroupToNonAliasingScopeList[Pair.first] = MDNode::get(Context, Pair.second);
 }
 
-void LoopVersioning::annotateLoopWithNoAlias() {
+void LoopVersioning::annotateLoopWithNoAlias(
+    const RuntimePointerChecking *RtPtrChecking) {
   if (!AnnotateNoAlias)
     return;
 
   // First prepare the maps.
-  prepareNoAliasMetadata();
+  prepareNoAliasMetadata(RtPtrChecking);
 
   // Add the scope and no-alias metadata to the instructions.
   for (Instruction *I : LAI.getDepChecker().getMemoryInstructions()) {
Index: include/llvm/Transforms/Utils/LoopVersioning.h
===================================================================
--- include/llvm/Transforms/Utils/LoopVersioning.h
+++ include/llvm/Transforms/Utils/LoopVersioning.h
@@ -56,11 +56,17 @@
   ///        analyze L
   ///        if versioning is necessary version L
   ///        transform L
-  void versionLoop() { versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop)); }
+  ///
+  /// \return BasicBlock which contains runtime checks.
+  BasicBlock *versionLoop() {
+    return versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop));
+  }
 
   /// \brief Same but if the client has already precomputed the set of values
   /// used outside the loop, this API will allows passing that.
-  void versionLoop(const SmallVectorImpl<Instruction *> &DefsUsedOutside);
+  ///
+  /// \return BasicBlock which contains runtime checks.
+  BasicBlock *versionLoop(const SmallVectorImpl<Instruction *> &DefsUsedOutside);
 
   /// \brief Returns the versioned loop.  Control flows here if pointers in the
   /// loop don't alias (i.e. all memchecks passed).  (This loop is actually the
@@ -83,11 +89,13 @@
   ///
   /// This is just wrapper that calls prepareNoAliasMetadata and
   /// annotateInstWithNoAlias on the instructions of the versioned loop.
-  void annotateLoopWithNoAlias();
+  void annotateLoopWithNoAlias(
+      const RuntimePointerChecking *RtPtrChecking = nullptr);
 
   /// \brief Set up the aliasing scopes based on the memchecks.  This needs to
   /// be called before the first call to annotateInstWithNoAlias.
-  void prepareNoAliasMetadata();
+  void
+  prepareNoAliasMetadata(const RuntimePointerChecking *RtPtrChecking = nullptr);
 
   /// \brief Add the noalias annotations to \p VersionedInst.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25559.74506.patch
Type: text/x-patch
Size: 3837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161013/dd3c4c8a/attachment.bin>


More information about the llvm-commits mailing list