[polly] r213272 - [Refactor] Move code out of the IslAst header

Johannes Doerfert jdoerfert at codeaurora.org
Thu Jul 17 09:11:28 PDT 2014


Author: jdoerfert
Date: Thu Jul 17 11:11:28 2014
New Revision: 213272

URL: http://llvm.org/viewvc/llvm-project?rev=213272&view=rev
Log:
[Refactor] Move code out of the IslAst header

  Offer the static functions to extract information out of an IslAst for node
  as members of IslAstInfo not as top level entities.

  + Refactor common code
  + Add isParallel and isReductionParallel
  + Rename IslAstUser to IslAstUserPayload to make it clear this is just a (or
    the) payload struct.

Modified:
    polly/trunk/include/polly/CodeGen/IslAst.h
    polly/trunk/lib/CodeGen/IslAst.cpp
    polly/trunk/lib/CodeGen/IslCodeGeneration.cpp

Modified: polly/trunk/include/polly/CodeGen/IslAst.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/IslAst.h?rev=213272&r1=213271&r2=213272&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/IslAst.h (original)
+++ polly/trunk/include/polly/CodeGen/IslAst.h Thu Jul 17 11:11:28 2014
@@ -27,7 +27,6 @@
 
 #include "isl/ast.h"
 
-struct clast_name;
 namespace llvm {
 class raw_ostream;
 }
@@ -42,7 +41,7 @@ class Scop;
 class IslAst;
 
 // Information about an ast node.
-struct IslAstUser {
+struct IslAstUserPayload {
   struct isl_ast_build *Context;
   // The node is the outermost parallel loop.
   int IsOutermostParallel;
@@ -77,37 +76,31 @@ public:
 
   bool runOnScop(Scop &S);
   void printScop(llvm::raw_ostream &OS) const;
+
+  /// @name Extract information attached to an isl ast (for) node.
+  ///
+  ///{
+
+  /// @brief Get the complete payload attached to @p Node.
+  static IslAstUserPayload *getNodePayload(__isl_keep isl_ast_node *Node);
+
+  /// @brief Is this loop a parallel loop?
+  static bool isParallel(__isl_keep isl_ast_node *Node);
+
+  /// @brief Is this loop an outer parallel loop?
+  static bool isOuterParallel(__isl_keep isl_ast_node *Node);
+
+  /// @brief Is this loop an innermost parallel loop?
+  static bool isInnermostParallel(__isl_keep isl_ast_node *Node);
+
+  /// @brief Is this loop a reduction parallel loop?
+  static bool isReductionParallel(__isl_keep isl_ast_node *Node);
+
+  ///}
+
   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
   virtual void releaseMemory();
 };
-
-// Returns true when Node has been tagged as an innermost parallel loop.
-static inline bool isInnermostParallel(__isl_keep isl_ast_node *Node) {
-  isl_id *Id = isl_ast_node_get_annotation(Node);
-  if (!Id)
-    return false;
-  struct IslAstUser *Info = (struct IslAstUser *)isl_id_get_user(Id);
-
-  bool Res = false;
-  if (Info)
-    Res = Info->IsInnermostParallel && !Info->IsReductionParallel;
-  isl_id_free(Id);
-  return Res;
-}
-
-// Returns true when Node has been tagged as an outermost parallel loop.
-static inline bool isOutermostParallel(__isl_keep isl_ast_node *Node) {
-  isl_id *Id = isl_ast_node_get_annotation(Node);
-  if (!Id)
-    return false;
-  struct IslAstUser *Info = (struct IslAstUser *)isl_id_get_user(Id);
-
-  bool Res = false;
-  if (Info)
-    Res = Info->IsOutermostParallel && !Info->IsReductionParallel;
-  isl_id_free(Id);
-  return Res;
-}
 }
 
 namespace llvm {

Modified: polly/trunk/lib/CodeGen/IslAst.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslAst.cpp?rev=213272&r1=213271&r2=213272&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslAst.cpp (original)
+++ polly/trunk/lib/CodeGen/IslAst.cpp Thu Jul 17 11:11:28 2014
@@ -86,7 +86,7 @@ struct AstBuildUserInfo {
 static __isl_give isl_printer *
 printParallelFor(__isl_keep isl_ast_node *Node, __isl_take isl_printer *Printer,
                  __isl_take isl_ast_print_options *PrintOptions,
-                 IslAstUser *Info) {
+                 IslAstUserPayload *Info) {
   if (Info) {
     if (Info->IsInnermostParallel) {
       Printer = isl_printer_start_line(Printer);
@@ -115,16 +115,18 @@ printFor(__isl_take isl_printer *Printer
   if (!Id)
     return isl_ast_node_for_print(Node, Printer, PrintOptions);
 
-  struct IslAstUser *Info = (struct IslAstUser *)isl_id_get_user(Id);
+  struct IslAstUserPayload *Info =
+      (struct IslAstUserPayload *)isl_id_get_user(Id);
   Printer = printParallelFor(Node, Printer, PrintOptions, Info);
   isl_id_free(Id);
   return Printer;
 }
 
 // Allocate an AstNodeInfo structure and initialize it with default values.
-static struct IslAstUser *allocateIslAstUser() {
-  struct IslAstUser *NodeInfo;
-  NodeInfo = (struct IslAstUser *)malloc(sizeof(struct IslAstUser));
+static struct IslAstUserPayload *allocateIslAstUser() {
+  struct IslAstUserPayload *NodeInfo;
+  NodeInfo =
+      (struct IslAstUserPayload *)malloc(sizeof(struct IslAstUserPayload));
   NodeInfo->Context = 0;
   NodeInfo->IsOutermostParallel = 0;
   NodeInfo->IsInnermostParallel = 0;
@@ -134,7 +136,7 @@ static struct IslAstUser *allocateIslAst
 
 // Free the AstNodeInfo structure.
 static void freeIslAstUser(void *Ptr) {
-  struct IslAstUser *UserStruct = (struct IslAstUser *)Ptr;
+  struct IslAstUserPayload *UserStruct = (struct IslAstUserPayload *)Ptr;
   isl_ast_build_free(UserStruct->Context);
   free(UserStruct);
 }
@@ -220,7 +222,7 @@ static bool astScheduleDimIsParallel(__i
 // Mark a for node openmp parallel, if it is the outermost parallel for node.
 static void markOpenmpParallel(__isl_keep isl_ast_build *Build,
                                struct AstBuildUserInfo *BuildInfo,
-                               struct IslAstUser *NodeInfo) {
+                               struct IslAstUserPayload *NodeInfo) {
   if (BuildInfo->InParallelFor)
     return;
 
@@ -241,7 +243,7 @@ static void markOpenmpParallel(__isl_kee
 static __isl_give isl_id *astBuildBeforeFor(__isl_keep isl_ast_build *Build,
                                             void *User) {
   struct AstBuildUserInfo *BuildInfo = (struct AstBuildUserInfo *)User;
-  struct IslAstUser *NodeInfo = allocateIslAstUser();
+  struct IslAstUserPayload *NodeInfo = allocateIslAstUser();
   isl_id *Id = isl_id_alloc(isl_ast_build_get_ctx(Build), "", NodeInfo);
   Id = isl_id_set_free_user(Id, freeIslAstUser);
 
@@ -303,7 +305,8 @@ astBuildAfterFor(__isl_take isl_ast_node
   isl_id *Id = isl_ast_node_get_annotation(Node);
   if (!Id)
     return Node;
-  struct IslAstUser *Info = (struct IslAstUser *)isl_id_get_user(Id);
+  struct IslAstUserPayload *Info =
+      (struct IslAstUserPayload *)isl_id_get_user(Id);
   struct AstBuildUserInfo *BuildInfo = (struct AstBuildUserInfo *)User;
 
   if (Info) {
@@ -324,11 +327,11 @@ astBuildAfterFor(__isl_take isl_ast_node
 static __isl_give isl_ast_node *AtEachDomain(__isl_take isl_ast_node *Node,
                                              __isl_keep isl_ast_build *Context,
                                              void *User) {
-  struct IslAstUser *Info = nullptr;
+  struct IslAstUserPayload *Info = nullptr;
   isl_id *Id = isl_ast_node_get_annotation(Node);
 
   if (Id)
-    Info = (struct IslAstUser *)isl_id_get_user(Id);
+    Info = (struct IslAstUserPayload *)isl_id_get_user(Id);
 
   if (!Info) {
     // Allocate annotations once: parallel for detection might have already
@@ -489,6 +492,37 @@ void IslAstInfo::printScop(raw_ostream &
   Ast->pprint(OS);
 }
 
+IslAstUserPayload *IslAstInfo::getNodePayload(__isl_keep isl_ast_node *Node) {
+  isl_id *Id = isl_ast_node_get_annotation(Node);
+  if (!Id)
+    return nullptr;
+  IslAstUserPayload *Payload = (IslAstUserPayload *)isl_id_get_user(Id);
+  isl_id_free(Id);
+  return Payload;
+}
+
+bool IslAstInfo::isParallel(__isl_keep isl_ast_node *Node) {
+  return (isInnermostParallel(Node) || isOuterParallel(Node)) &&
+         !isReductionParallel(Node);
+}
+
+bool IslAstInfo::isInnermostParallel(__isl_keep isl_ast_node *Node) {
+  IslAstUserPayload *Payload = getNodePayload(Node);
+  return Payload && Payload->IsInnermostParallel &&
+         !Payload->IsReductionParallel;
+}
+
+bool IslAstInfo::isOuterParallel(__isl_keep isl_ast_node *Node) {
+  IslAstUserPayload *Payload = getNodePayload(Node);
+  return Payload && Payload->IsOutermostParallel &&
+         !Payload->IsReductionParallel;
+}
+
+bool IslAstInfo::isReductionParallel(__isl_keep isl_ast_node *Node) {
+  IslAstUserPayload *Payload = getNodePayload(Node);
+  return Payload && Payload->IsReductionParallel;
+}
+
 void IslAstInfo::getAnalysisUsage(AnalysisUsage &AU) const {
   // Get the Common analysis usage of ScopPasses.
   ScopPass::getAnalysisUsage(AU);

Modified: polly/trunk/lib/CodeGen/IslCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslCodeGeneration.cpp?rev=213272&r1=213271&r2=213272&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslCodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/IslCodeGeneration.cpp Thu Jul 17 11:11:28 2014
@@ -781,7 +781,8 @@ unsigned IslNodeBuilder::getNumberOfIter
   if (!Annotation)
     return -1;
 
-  struct IslAstUser *Info = (struct IslAstUser *)isl_id_get_user(Annotation);
+  struct IslAstUserPayload *Info =
+      (struct IslAstUserPayload *)isl_id_get_user(Annotation);
   if (!Info) {
     isl_id_free(Annotation);
     return -1;
@@ -849,7 +850,8 @@ void IslNodeBuilder::createForVector(__i
   isl_id *Annotation = isl_ast_node_get_annotation(For);
   assert(Annotation && "For statement is not annotated");
 
-  struct IslAstUser *Info = (struct IslAstUser *)isl_id_get_user(Annotation);
+  struct IslAstUserPayload *Info =
+      (struct IslAstUserPayload *)isl_id_get_user(Annotation);
   assert(Info && "For statement annotation does not contain info");
 
   isl_union_map *Schedule = isl_ast_build_get_schedule(Info->Context);
@@ -898,7 +900,7 @@ void IslNodeBuilder::createForSequential
   CmpInst::Predicate Predicate;
   bool Parallel;
 
-  Parallel = isInnermostParallel(For);
+  Parallel = IslAstInfo::isInnermostParallel(For);
 
   Body = isl_ast_node_for_get_body(For);
 
@@ -950,7 +952,7 @@ void IslNodeBuilder::createForSequential
 void IslNodeBuilder::createFor(__isl_take isl_ast_node *For) {
   bool Vector = PollyVectorizerChoice != VECTORIZER_NONE;
 
-  if (Vector && isInnermostParallel(For)) {
+  if (Vector && IslAstInfo::isInnermostParallel(For)) {
     int VectorWidth = getNumberOfIterations(For);
     if (1 < VectorWidth && VectorWidth <= 16) {
       createForVector(For, VectorWidth);





More information about the llvm-commits mailing list