[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:25:29 PST 2015


jdoerfert added a subscriber: jdoerfert.
jdoerfert added a comment.

> 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




- F1225063: signature.asc <http://reviews.llvm.org/F1225063>


http://reviews.llvm.org/D15693





More information about the llvm-commits mailing list