[PATCH] D15693: [Polly] Take a PHI's incoming block as value user

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 16:15:22 PST 2015


> Meinersbur created this revision.
> Meinersbur added reviewers: grosser, jdoerfert.
> Meinersbur added subscribers: llvm-commits, pollydev.
> Meinersbur added a project: Polly.
> 
> Before this patch, we determine whether a value escapes the SCoP by checking whether it the instruction itself is within the scop. This is wrong for PHINodes because the value must be available in the incoming block instead of of where the PHI is.
I don't get it. A PHI (here Inst in the BlockGenerators) which is in the
SCoP escapes the SCoP, if it is used outside the SCoP, or not? Where is
the difference to any other instruction? Or do you talk about a user
PHI? In that case I would say an instruction (here Inst) escapes the
SCoP, if the user PHI is not in the SCoP. Either way the code we had
seems fine to me but I could have missed something here...

> To fix this, we introduce a function "getUseBlock" to determine the location of a value's use for PHIs and other instructions. It will also be used in subsequent patches.
> 
> I could not produce a test case because of region simplification and loop versioning which adds additional block between the PHIs and the SCoP region. Nonetheless, it happend during debugging of preliminary code and is in general the correct way.
> 
> http://reviews.llvm.org/D15693
> 
> Files:
>   include/polly/Support/ScopHelper.h
>   lib/CodeGen/BlockGenerators.cpp
>   lib/Support/ScopHelper.cpp
> 
> Index: lib/Support/ScopHelper.cpp
> ===================================================================
> --- lib/Support/ScopHelper.cpp
> +++ lib/Support/ScopHelper.cpp
> @@ -453,3 +453,14 @@
>  
>    return false;
>  }
> +
> +llvm::BasicBlock *polly::getUseBlock(llvm::Use &U) {
> +  Instruction *UI = dyn_cast<Instruction>(U.getUser());
> +  if (!UI)
> +    return nullptr;
> +
> +  if (PHINode *PHI = dyn_cast<PHINode>(UI))
> +    return PHI->getIncomingBlock(U);
> +
> +  return UI->getParent();
> +}
> Index: lib/CodeGen/BlockGenerators.cpp
> ===================================================================
> --- lib/CodeGen/BlockGenerators.cpp
> +++ lib/CodeGen/BlockGenerators.cpp
> @@ -365,14 +365,14 @@
>      return;
>  
>    EscapeUserVectorTy EscapeUsers;
> -  for (User *U : Inst->users()) {
> +  for (Use &U : Inst->uses()) {
>  
>      // Non-instruction user will never escape.
> -    Instruction *UI = dyn_cast<Instruction>(U);
> +    Instruction *UI = dyn_cast<Instruction>(U.getUser());
>      if (!UI)
>        continue;
>  
> -    if (R.contains(UI))
> +    if (R.contains(getUseBlock(U)))
>        continue;
>  
>      EscapeUsers.push_back(UI);
> Index: include/polly/Support/ScopHelper.h
> ===================================================================
> --- include/polly/Support/ScopHelper.h
> +++ include/polly/Support/ScopHelper.h
> @@ -164,5 +164,14 @@
>  ///         otherwise return false.
>  bool canSynthesize(const llvm::Value *V, const llvm::LoopInfo *LI,
>                     llvm::ScalarEvolution *SE, const llvm::Region *R);
> +
> +/// @brief Return the block in which a value is used.
> +///
> +/// For normal instructions, this is the instruction's parent block. For PHI
> +/// nodes, this is the incoming block of that use, because this is where the
> +/// operand must be defined (i.e. its definition dominates this block).
> +/// Non-instructions do not use operands at a specific point such that in this
> +/// case this function returns nullptr.
> +llvm::BasicBlock *getUseBlock(llvm::Use &U);
>  }
>  #endif
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups "Polly Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to polly-dev+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

> Index: lib/Support/ScopHelper.cpp
> ===================================================================
> --- lib/Support/ScopHelper.cpp
> +++ lib/Support/ScopHelper.cpp
> @@ -453,3 +453,14 @@
>  
>    return false;
>  }
> +
> +llvm::BasicBlock *polly::getUseBlock(llvm::Use &U) {
> +  Instruction *UI = dyn_cast<Instruction>(U.getUser());
> +  if (!UI)
> +    return nullptr;
> +
> +  if (PHINode *PHI = dyn_cast<PHINode>(UI))
> +    return PHI->getIncomingBlock(U);
> +
> +  return UI->getParent();
> +}
> Index: lib/CodeGen/BlockGenerators.cpp
> ===================================================================
> --- lib/CodeGen/BlockGenerators.cpp
> +++ lib/CodeGen/BlockGenerators.cpp
> @@ -365,14 +365,14 @@
>      return;
>  
>    EscapeUserVectorTy EscapeUsers;
> -  for (User *U : Inst->users()) {
> +  for (Use &U : Inst->uses()) {
>  
>      // Non-instruction user will never escape.
> -    Instruction *UI = dyn_cast<Instruction>(U);
> +    Instruction *UI = dyn_cast<Instruction>(U.getUser());
>      if (!UI)
>        continue;
>  
> -    if (R.contains(UI))
> +    if (R.contains(getUseBlock(U)))
>        continue;
>  
>      EscapeUsers.push_back(UI);
> Index: include/polly/Support/ScopHelper.h
> ===================================================================
> --- include/polly/Support/ScopHelper.h
> +++ include/polly/Support/ScopHelper.h
> @@ -164,5 +164,14 @@
>  ///         otherwise return false.
>  bool canSynthesize(const llvm::Value *V, const llvm::LoopInfo *LI,
>                     llvm::ScalarEvolution *SE, const llvm::Region *R);
> +
> +/// @brief Return the block in which a value is used.
> +///
> +/// For normal instructions, this is the instruction's parent block. For PHI
> +/// nodes, this is the incoming block of that use, because this is where the
> +/// operand must be defined (i.e. its definition dominates this block).
> +/// Non-instructions do not use operands at a specific point such that in this
> +/// case this function returns nullptr.
> +llvm::BasicBlock *getUseBlock(llvm::Use &U);
>  }
>  #endif


-- 

Johannes Doerfert
Researcher / PhD Student

Compiler Design Lab (Prof. Hack)
Saarland University, Computer Science
Building E1.3, Room 4.31

Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
Fax. +49 (0)681 302-3065  : http://www.cdl.uni-saarland.de/people/doerfert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151222/d34cebfe/attachment.sig>


More information about the llvm-commits mailing list