[Polly] [Refactor] Use a function attribute to make polly skip a function

Johannes Doerfert jdoerfert at codeaurora.org
Tue Jul 15 13:49:12 PDT 2014


Thanks for the feedback! I changed the patch according to it.

Now attached is an updated version __but__ I didn't run the cloog tests!

Could somebody run them and verify my regexp works?


--

Johannes Doerfert
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by
The Linux Foundation

-----Original Message-----
From: Tobias Grosser [mailto:tobias at grosser.es] 
Sent: Tuesday, July 15, 2014 12:55 PM
To: Johannes Doerfert; llvm-commits at cs.uiuc.edu
Subject: Re: [Polly] [Refactor] Use a function attribute to make polly skip
a function

On 15/07/2014 21:40, Johannes Doerfert wrote:
> Hey,
>
> I would like to get rid of the code generation -> scop detection 
> dependency we have due to the parallel subfunctions.
>
> Attached is a patch which utilizes a function attribute instead of a 
> "set of invalid functions" to skip functions in scop detection.
>
> The interface is still the same but now you can also use the function 
> attribute without the ScopDetection Pass.
>
> I also attached a test case where I placed that attribute by hand.
>
> What do you think?

Very good idea.

>  From d7a96ae8744c6d63c2b58fd7523c1e8c3d3aa954 Mon Sep 17 00:00:00 
> 2001
> From: Johannes Doerfert<jdoerfert at codeaurora.org>
> Date: Fri, 11 Jul 2014 15:08:24 -0700
> Subject: [PATCH] [Refactor] Use attributes to mark function as invalid for
>   polly
>
>    + Test case
> ---
>   include/polly/ScopDetection.h              | 15 +++-------
>   lib/Analysis/ScopDetection.cpp             |  7 ++++-
>   lib/CodeGen/LoopGenerators.cpp             |  2 +-
>   test/ScopDetect/skip_function_attribute.ll | 44
++++++++++++++++++++++++++++++
>   4 files changed, 55 insertions(+), 13 deletions(-)
>   create mode 100644 test/ScopDetect/skip_function_attribute.ll
>
> diff --git a/include/polly/ScopDetection.h 
> b/include/polly/ScopDetection.h index e62db93..f0b3af4 100644
> --- a/include/polly/ScopDetection.h
> +++ b/include/polly/ScopDetection.h
> @@ -107,6 +107,7 @@ typedef std::map<const SCEVUnknown *, const SCEV 
> *> BaseToElSize;
>
>   extern bool PollyTrackFailures;
>   extern bool PollyDelinearize;
> +extern llvm::StringRef PollySkipFnAttr;

Can you document this variable?

>
//===----------------------------------------------------------------------=
==//
>   /// @brief Pass to detect the maximal static control parts (Scops) 
> of a @@ -146,10 +147,6 @@ class ScopDetection : public FunctionPass {
>     // Remember a list of errors for every region.
>     mutable RejectLogsContainer RejectLogs;
>
> -  // Remember the invalid functions producted by backends;
> -  typedef std::set<const Function *> FunctionSet;
> -  FunctionSet InvalidFunctions;
> -
>     // Delinearize all non affine memory accesses and return false when
there
>     // exists a non affine memory access that cannot be delinearized.
Return true
>     // when all array accesses are affine after delinearization.
> @@ -249,13 +246,9 @@ class ScopDetection : public FunctionPass {
>     /// @return True if the loop is valid in the region.
>     bool isValidLoop(Loop *L, DetectionContext &Context) const;
>
> -  /// @brief Check if a function is an OpenMP subfunction.
> -  ///
> -  /// An OpenMP subfunction is not valid for Scop detection.
> -  ///
> -  /// @param F The function to check.
> +  /// @brief Check if the function @p F is marked as invalid.
>     ///
> -  /// @return True if the function is not an OpenMP subfunction.
> +  /// @note An OpenMP subfunction will be marked as invalid.
>     bool isValidFunction(llvm::Function &F);
>
>     /// @brief Print the locations of all detected scops.
> @@ -347,7 +340,7 @@ public:
>     ///        the function.
>     ///
>     /// @param F The function to mark as invalid.
> -  void markFunctionAsInvalid(const Function *F) { 
> InvalidFunctions.insert(F); }
> +  void markFunctionAsInvalid(Function *F) const;
>
>     /// @brief Verify if all valid Regions in this Function are still
valid
>     /// after some transformations.
> diff --git a/lib/Analysis/ScopDetection.cpp 
> b/lib/Analysis/ScopDetection.cpp index 53c5ed7..f061f01 100644
> --- a/lib/Analysis/ScopDetection.cpp
> +++ b/lib/Analysis/ScopDetection.cpp
> @@ -136,6 +136,7 @@ static cl::opt<bool>
>
>   bool polly::PollyTrackFailures = false;
>   bool polly::PollyDelinearize = false;
> +StringRef polly::PollySkipFnAttr = "polly.skip.fn";
>
>
//===----------------------------------------------------------------------=
==//
>   // Statistics.
> @@ -769,8 +770,12 @@ bool ScopDetection::isValidRegion(DetectionContext
&Context) const {
>     return true;
>   }
>
> +void ScopDetection::markFunctionAsInvalid(Function *F) const {
> +  F->addFnAttr(PollySkipFnAttr);
> +}
> +
>   bool ScopDetection::isValidFunction(llvm::Function &F) {
> -  return !InvalidFunctions.count(&F);
> +  return !F.hasFnAttribute(PollySkipFnAttr);
>   }
>
>   void ScopDetection::printLocations(llvm::Function &F) { diff --git 
> a/lib/CodeGen/LoopGenerators.cpp b/lib/CodeGen/LoopGenerators.cpp 
> index 52a47ef..432960d 100644
> --- a/lib/CodeGen/LoopGenerators.cpp
> +++ b/lib/CodeGen/LoopGenerators.cpp
> @@ -229,7 +229,7 @@ Function *OMPGenerator::createSubfunctionDefinition()
{
>     Function *FN = Function::Create(FT, Function::InternalLinkage,
>                                     F->getName() + ".omp_subfn", M);
>     // Do not run any polly pass on the new function.
> -  P->getAnalysis<polly::ScopDetection>().markFunctionAsInvalid(FN);
> +  FN->addFnAttr(PollySkipFnAttr);
>
>     Function::arg_iterator AI = FN->arg_begin();
>     AI->setName("omp.userContext");
> diff --git a/test/ScopDetect/skip_function_attribute.ll 
> b/test/ScopDetect/skip_function_attribute.ll
> new file mode 100644
> index 0000000..d8ba9a4
> --- /dev/null
> +++ b/test/ScopDetect/skip_function_attribute.ll
> @@ -0,0 +1,44 @@
> +; RUN: opt %loadPolly -polly-detect -stats < %s | FileCheck %s

Please use -analyze instead of -stats, as -stats is only available in assert
builds.

Also, can you add a check line to one of the OpenMP tests to ensure that
this attribute is actually emitted?

Otherwise LGTM.

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Refactor-Use-attributes-to-mark-function-as-invalid-.patch
Type: application/octet-stream
Size: 7598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140715/82afec41/attachment.obj>


More information about the llvm-commits mailing list