r339152 - [OPENMP] Mark variables captured in declare target region as implicitly

2018-08-07 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Aug  7 09:14:36 2018
New Revision: 339152

URL: http://llvm.org/viewvc/llvm-project?rev=339152&view=rev
Log:
[OPENMP] Mark variables captured in declare target region as implicitly
declare target.

According to OpenMP 5.0, variables captured in lambdas in declare target
regions must be considered as implicitly declare target.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=339152&r1=339151&r2=339152&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Aug  7 09:14:36 2018
@@ -8662,7 +8662,7 @@ public:
   /// Check if the specified variable is used in one of the private
   /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP
   /// constructs.
-  VarDecl *isOpenMPCapturedDecl(ValueDecl *D) const;
+  VarDecl *isOpenMPCapturedDecl(ValueDecl *D);
   ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK,
ExprObjectKind OK, SourceLocation Loc);
 
@@ -8746,8 +8746,9 @@ public:
 OMPDeclareTargetDeclAttr::MapTypeTy MT,
 NamedDeclSetType &SameDirectiveDecls);
   /// Check declaration inside target region.
-  void checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
-SourceLocation IdLoc = 
SourceLocation());
+  void
+  checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
+   SourceLocation IdLoc = SourceLocation());
   /// Return true inside OpenMP declare target region.
   bool isInOpenMPDeclareTargetContext() const {
 return IsInOpenMPDeclareTargetContext;

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=339152&r1=339151&r2=339152&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Aug  7 09:14:36 2018
@@ -8106,7 +8106,12 @@ bool CGOpenMPRuntime::emitTargetGlobalVa
   // Do not to emit variable if it is not marked as declare target.
   llvm::Optional Res =
   isDeclareTargetDeclaration(cast(GD.getDecl()));
-  return !Res || *Res == OMPDeclareTargetDeclAttr::MT_Link;
+  if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_Link) {
+if (CGM.getContext().DeclMustBeEmitted(GD.getDecl()))
+  DeferredGlobalVariables.insert(cast(GD.getDecl()));
+return true;
+  }
+  return false;
 }
 
 void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD,
@@ -8163,6 +8168,18 @@ bool CGOpenMPRuntime::emitTargetGlobal(G
   return emitTargetGlobalVariable(GD);
 }
 
+void CGOpenMPRuntime::emitDeferredTargetDecls() const {
+  for (const VarDecl *VD : DeferredGlobalVariables) {
+llvm::Optional Res =
+isDeclareTargetDeclaration(VD);
+if (Res) {
+  assert(*Res != OMPDeclareTargetDeclAttr::MT_Link &&
+ "Implicit declare target variables must be only to().");
+  CGM.EmitGlobal(VD);
+}
+  }
+}
+
 CGOpenMPRuntime::DisableAutoDeclareTargetRAII::DisableAutoDeclareTargetRAII(
 CodeGenModule &CGM)
 : CGM(CGM) {

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=339152&r1=339151&r2=339152&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Tue Aug  7 09:14:36 2018
@@ -602,6 +602,10 @@ private:
   bool ShouldMarkAsGlobal = true;
   llvm::SmallDenseSet AlreadyEmittedTargetFunctions;
 
+  /// List of variables that can become declare target implicitly and, thus,
+  /// must be emitted.
+  llvm::SmallDenseSet DeferredGlobalVariables;
+
   /// Creates and registers offloading binary descriptor for the current
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
@@ -1509,6 +1513,8 @@ public:
   /// true, if it was marked already, and false, otherwise.
   bool markAsGlobalTarget(GlobalDecl GD);
 
+  /// Emit deferred declare target variables marked for deferred emission.
+  void emitDeferredTargetDecls() const;
 };
 
 /// Class supports emissionof SIMD-only code.

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Co

r339568 - [OPENMP] Fix emission of the loop doacross constructs.

2018-08-13 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 13 07:05:43 2018
New Revision: 339568

URL: http://llvm.org/viewvc/llvm-project?rev=339568&view=rev
Log:
[OPENMP] Fix emission of the loop doacross constructs.

The number of loops associated with the OpenMP loop constructs should
not be considered as the number loops to collapse.

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/ordered_doacross_codegen.c
cfe/trunk/test/OpenMP/ordered_doacross_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=339568&r1=339567&r2=339568&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Aug 13 07:05:43 2018
@@ -930,8 +930,11 @@ public:
 /// \endcode
 /// In this example directive '#pragma omp for' has 'ordered' clause with
 /// parameter 2.
-class OMPOrderedClause : public OMPClause {
+class OMPOrderedClause final
+: public OMPClause,
+  private llvm::TrailingObjects {
   friend class OMPClauseReader;
+  friend TrailingObjects;
 
   /// Location of '('.
   SourceLocation LParenLoc;
@@ -939,6 +942,26 @@ class OMPOrderedClause : public OMPClaus
   /// Number of for-loops.
   Stmt *NumForLoops = nullptr;
 
+  /// Real number of loops.
+  unsigned NumberOfLoops = 0;
+
+  /// Build 'ordered' clause.
+  ///
+  /// \param Num Expression, possibly associated with this clause.
+  /// \param NumLoops Number of loops, associated with this clause.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
+   SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
+NumForLoops(Num), NumberOfLoops(NumLoops) {}
+
+  /// Build an empty clause.
+  explicit OMPOrderedClause(unsigned NumLoops)
+  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
+NumberOfLoops(NumLoops) {}
+
   /// Set the number of associated for-loops.
   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
 
@@ -946,17 +969,17 @@ public:
   /// Build 'ordered' clause.
   ///
   /// \param Num Expression, possibly associated with this clause.
+  /// \param NumLoops Number of loops, associated with this clause.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
-SourceLocation LParenLoc, SourceLocation EndLoc)
-  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
-NumForLoops(Num) {}
+  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
+  unsigned NumLoops, SourceLocation StartLoc,
+  SourceLocation LParenLoc,
+  SourceLocation EndLoc);
 
   /// Build an empty clause.
-  explicit OMPOrderedClause()
-  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
+  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
 
   /// Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
@@ -967,6 +990,17 @@ public:
   /// Return the number of associated for-loops.
   Expr *getNumForLoops() const { return cast_or_null(NumForLoops); }
 
+  /// Set number of iterations for the specified loop.
+  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
+  /// Get number of iterations for all the loops.
+  ArrayRef getLoopNumIterations() const;
+
+  /// Set loop counter for the specified loop.
+  void setLoopCounter(unsigned NumLoop, Expr *Counter);
+  /// Get loops counter for the specified loop.
+  Expr *getLoopCunter(unsigned NumLoop);
+  const Expr *getLoopCunter(unsigned NumLoop) const;
+
   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); 
}
 
   static bool classof(const OMPClause *T) {
@@ -3095,24 +3129,32 @@ class OMPDependClause final
   /// Colon location.
   SourceLocation ColonLoc;
 
+  /// Number of loops, associated with the depend clause.
+  unsigned NumLoops = 0;
+
   /// Build clause with number of variables \a N.
   ///
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location

r339574 - Revert "[OPENMP] Fix emission of the loop doacross constructs."

2018-08-13 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 13 07:42:18 2018
New Revision: 339574

URL: http://llvm.org/viewvc/llvm-project?rev=339574&view=rev
Log:
Revert "[OPENMP] Fix emission of the loop doacross constructs."

This reverts commit r339568 because of the problems with the buildbots.

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/ordered_doacross_codegen.c
cfe/trunk/test/OpenMP/ordered_doacross_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=339574&r1=339573&r2=339574&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Aug 13 07:42:18 2018
@@ -930,11 +930,8 @@ public:
 /// \endcode
 /// In this example directive '#pragma omp for' has 'ordered' clause with
 /// parameter 2.
-class OMPOrderedClause final
-: public OMPClause,
-  private llvm::TrailingObjects {
+class OMPOrderedClause : public OMPClause {
   friend class OMPClauseReader;
-  friend TrailingObjects;
 
   /// Location of '('.
   SourceLocation LParenLoc;
@@ -942,26 +939,6 @@ class OMPOrderedClause final
   /// Number of for-loops.
   Stmt *NumForLoops = nullptr;
 
-  /// Real number of loops.
-  unsigned NumberOfLoops = 0;
-
-  /// Build 'ordered' clause.
-  ///
-  /// \param Num Expression, possibly associated with this clause.
-  /// \param NumLoops Number of loops, associated with this clause.
-  /// \param StartLoc Starting location of the clause.
-  /// \param LParenLoc Location of '('.
-  /// \param EndLoc Ending location of the clause.
-  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
-   SourceLocation LParenLoc, SourceLocation EndLoc)
-  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
-NumForLoops(Num), NumberOfLoops(NumLoops) {}
-
-  /// Build an empty clause.
-  explicit OMPOrderedClause(unsigned NumLoops)
-  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
-NumberOfLoops(NumLoops) {}
-
   /// Set the number of associated for-loops.
   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
 
@@ -969,17 +946,17 @@ public:
   /// Build 'ordered' clause.
   ///
   /// \param Num Expression, possibly associated with this clause.
-  /// \param NumLoops Number of loops, associated with this clause.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
-  unsigned NumLoops, SourceLocation StartLoc,
-  SourceLocation LParenLoc,
-  SourceLocation EndLoc);
+  OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
+SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
+NumForLoops(Num) {}
 
   /// Build an empty clause.
-  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
+  explicit OMPOrderedClause()
+  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
 
   /// Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
@@ -990,17 +967,6 @@ public:
   /// Return the number of associated for-loops.
   Expr *getNumForLoops() const { return cast_or_null(NumForLoops); }
 
-  /// Set number of iterations for the specified loop.
-  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
-  /// Get number of iterations for all the loops.
-  ArrayRef getLoopNumIterations() const;
-
-  /// Set loop counter for the specified loop.
-  void setLoopCounter(unsigned NumLoop, Expr *Counter);
-  /// Get loops counter for the specified loop.
-  Expr *getLoopCunter(unsigned NumLoop);
-  const Expr *getLoopCunter(unsigned NumLoop) const;
-
   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); 
}
 
   static bool classof(const OMPClause *T) {
@@ -3129,32 +3095,24 @@ class OMPDependClause final
   /// Colon location.
   SourceLocation ColonLoc;
 
-  /// Number of loops, associated with the depend clause.
-  unsigned NumLoops = 0;
-
   /// Build clause with number of variables \a N.
   ///
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   /// \param N Number of the variab

r339603 - [OPENMP] Fix emission of the loop doacross constructs.

2018-08-13 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 13 12:04:24 2018
New Revision: 339603

URL: http://llvm.org/viewvc/llvm-project?rev=339603&view=rev
Log:
[OPENMP] Fix emission of the loop doacross constructs.

The number of loops associated with the OpenMP loop constructs should
not be considered as the number loops to collapse.

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/ordered_doacross_codegen.c
cfe/trunk/test/OpenMP/ordered_doacross_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=339603&r1=339602&r2=339603&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Aug 13 12:04:24 2018
@@ -930,8 +930,11 @@ public:
 /// \endcode
 /// In this example directive '#pragma omp for' has 'ordered' clause with
 /// parameter 2.
-class OMPOrderedClause : public OMPClause {
+class OMPOrderedClause final
+: public OMPClause,
+  private llvm::TrailingObjects {
   friend class OMPClauseReader;
+  friend TrailingObjects;
 
   /// Location of '('.
   SourceLocation LParenLoc;
@@ -939,6 +942,26 @@ class OMPOrderedClause : public OMPClaus
   /// Number of for-loops.
   Stmt *NumForLoops = nullptr;
 
+  /// Real number of loops.
+  unsigned NumberOfLoops = 0;
+
+  /// Build 'ordered' clause.
+  ///
+  /// \param Num Expression, possibly associated with this clause.
+  /// \param NumLoops Number of loops, associated with this clause.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
+   SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
+NumForLoops(Num), NumberOfLoops(NumLoops) {}
+
+  /// Build an empty clause.
+  explicit OMPOrderedClause(unsigned NumLoops)
+  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
+NumberOfLoops(NumLoops) {}
+
   /// Set the number of associated for-loops.
   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
 
@@ -946,17 +969,17 @@ public:
   /// Build 'ordered' clause.
   ///
   /// \param Num Expression, possibly associated with this clause.
+  /// \param NumLoops Number of loops, associated with this clause.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
-SourceLocation LParenLoc, SourceLocation EndLoc)
-  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
-NumForLoops(Num) {}
+  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
+  unsigned NumLoops, SourceLocation StartLoc,
+  SourceLocation LParenLoc,
+  SourceLocation EndLoc);
 
   /// Build an empty clause.
-  explicit OMPOrderedClause()
-  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
+  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
 
   /// Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
@@ -967,6 +990,17 @@ public:
   /// Return the number of associated for-loops.
   Expr *getNumForLoops() const { return cast_or_null(NumForLoops); }
 
+  /// Set number of iterations for the specified loop.
+  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
+  /// Get number of iterations for all the loops.
+  ArrayRef getLoopNumIterations() const;
+
+  /// Set loop counter for the specified loop.
+  void setLoopCounter(unsigned NumLoop, Expr *Counter);
+  /// Get loops counter for the specified loop.
+  Expr *getLoopCunter(unsigned NumLoop);
+  const Expr *getLoopCunter(unsigned NumLoop) const;
+
   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); 
}
 
   static bool classof(const OMPClause *T) {
@@ -3095,24 +3129,32 @@ class OMPDependClause final
   /// Colon location.
   SourceLocation ColonLoc;
 
+  /// Number of loops, associated with the depend clause.
+  unsigned NumLoops = 0;
+
   /// Build clause with number of variables \a N.
   ///
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location

r339704 - [OPENMP] Fix processing of declare target construct.

2018-08-14 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Aug 14 11:31:20 2018
New Revision: 339704

URL: http://llvm.org/viewvc/llvm-project?rev=339704&view=rev
Log:
[OPENMP] Fix processing of declare target construct.

The attribute marked as inheritable since OpenMP 5.0 supports it +
additional fixes to support new functionality.

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=339704&r1=339703&r2=339704&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Aug 14 11:31:20 2018
@@ -2956,9 +2956,10 @@ def OMPDeclareSimdDecl : Attr {
   }];
 }
 
-def OMPDeclareTargetDecl : Attr {
+def OMPDeclareTargetDecl : InheritableAttr {
   let Spellings = [Pragma<"omp", "declare target">];
   let SemaHandler = 0;
+  let Subjects = SubjectList<[Function, SharedVar]>;
   let Documentation = [OMPDeclareTargetDocs];
   let Args = [
 EnumArgument<"MapType", "MapTypeTy",
@@ -2971,6 +2972,15 @@ def OMPDeclareTargetDecl : Attr {
   if (getMapType() != MT_To)
 OS << ' ' << ConvertMapTypeTyToStr(getMapType());
 }
+static llvm::Optional
+isDeclareTargetDeclaration(const ValueDecl *VD) {
+  if (!VD->hasAttrs())
+return llvm::None;
+  if (const auto *Attr = VD->getAttr())
+return Attr->getMapType();
+
+  return llvm::None;
+}
   }];
 }
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=339704&r1=339703&r2=339704&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Aug 14 11:31:20 2018
@@ -9806,13 +9806,9 @@ bool ASTContext::DeclMustBeEmitted(const
   return true;
 
   // If the decl is marked as `declare target`, it should be emitted.
-  for (const auto *Decl : D->redecls()) {
-if (!Decl->hasAttrs())
-  continue;
-if (const auto *Attr = Decl->getAttr())
-  if (Attr->getMapType() != OMPDeclareTargetDeclAttr::MT_Link)
-return true;
-  }
+  if (const llvm::Optional Res =
+  OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD))
+return *Res != OMPDeclareTargetDeclAttr::MT_Link;
 
   return false;
 }

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=339704&r1=339703&r2=339704&view=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Tue Aug 14 11:31:20 2018
@@ -1091,6 +1091,10 @@ void DeclPrinter::VisitFunctionTemplateD
   printTemplateParameters(FD->getTemplateParameterList(I));
   }
   VisitRedeclarableTemplateDecl(D);
+  // Declare target attribute is special one, natural spelling for the pragma
+  // assumes "ending" construct so print it here.
+  if (D->getTemplatedDecl()->hasAttr())
+Out << "#pragma omp end declare target\n";
 
   // Never print "instantiations" for deduction guides (they don't really
   // have them).

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=339704&r1=339703&r2=339704&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Aug 14 11:31:20 2018
@@ -897,25 +897,6 @@ static void EmitOMPAggregateInit(CodeGen
   CGF.EmitBlock(DoneBB, /*IsFinished=*/true);
 }
 
-static llvm::Optional
-isDeclareTargetDeclaration(const ValueDecl *VD) {
-  for (const Decl *D : VD->redecls()) {
-if (!D->hasAttrs())
-  continue;
-if (const auto *Attr = D->getAttr())
-  return Attr->getMapType();
-  }
-  if (const auto *V = dyn_cast(VD)) {
-if (const VarDecl *TD = V->getTemplateInstantiationPattern())
-  return isDeclareTargetDeclaration(TD);
-  } else if (const auto *FD = dyn_cast(VD)) {
-if (const auto *TD = FD->getTemplateInstantiationPattern())
-  return isDeclareTargetDeclaration(TD);
-  }
-
-  return llvm::None;
-}
-
 LValue ReductionCodeGen::emitSharedLValue(CodeGenFunction &CGF, const Expr *E) 
{
   return CGF.EmitOMPSharedLValue(E);
 }
@@ -2417,7 +2398,7 @@ Address CGOpenMPRuntime::getAddrOfDeclar
   if (CGM.getLangOpts().OpenMPSimd)
 return Address::invalid();
   llvm::Optional Res =
-  isDeclareTargetDeclaration(VD);
+  OMPDeclareTargetDeclAttr::isDeclareTar

r339805 - [OPENMP] FIx processing of declare target variables.

2018-08-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Aug 15 12:45:12 2018
New Revision: 339805

URL: http://llvm.org/viewvc/llvm-project?rev=339805&view=rev
Log:
[OPENMP] FIx processing of declare target variables.

The compiler may produce unexpected error messages/crashes when declare
target variables were used. Patch fixes problems with the declarations
marked as declare target to or link.

Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp
cfe/trunk/test/OpenMP/declare_target_link_codegen.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=339805&r1=339804&r2=339805&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Aug 15 12:45:12 2018
@@ -9774,6 +9774,12 @@ bool ASTContext::DeclMustBeEmitted(const
   const auto *VD = cast(D);
   assert(VD->isFileVarDecl() && "Expected file scoped var");
 
+  // If the decl is marked as `declare target to`, it should be emitted for the
+  // host and for the device.
+  if (LangOpts.OpenMP &&
+  OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD))
+return true;
+
   if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly &&
   !isMSStaticDataMemberInlineDefinition(VD))
 return false;
@@ -9805,11 +9811,6 @@ bool ASTContext::DeclMustBeEmitted(const
 if (DeclMustBeEmitted(BindingVD))
   return true;
 
-  // If the decl is marked as `declare target`, it should be emitted.
-  if (const llvm::Optional Res =
-  OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD))
-return *Res != OMPDeclareTargetDeclAttr::MT_Link;
-
   return false;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=339805&r1=339804&r2=339805&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Aug 15 12:45:12 2018
@@ -2270,18 +2270,14 @@ static LValue EmitThreadPrivateVarDeclLV
 
 static Address emitDeclTargetLinkVarDeclLValue(CodeGenFunction &CGF,
const VarDecl *VD, QualType T) {
-  for (const auto *D : VD->redecls()) {
-if (!VD->hasAttrs())
-  continue;
-if (const auto *Attr = D->getAttr())
-  if (Attr->getMapType() == OMPDeclareTargetDeclAttr::MT_Link) {
-QualType PtrTy = CGF.getContext().getPointerType(VD->getType());
-Address Addr =
-CGF.CGM.getOpenMPRuntime().getAddrOfDeclareTargetLink(VD);
-return CGF.EmitLoadOfPointer(Addr, PtrTy->castAs());
-  }
-  }
-  return Address::invalid();
+  llvm::Optional Res =
+  OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
+  if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_To)
+return Address::invalid();
+  assert(*Res == OMPDeclareTargetDeclAttr::MT_Link && "Expected link clause");
+  QualType PtrTy = CGF.getContext().getPointerType(VD->getType());
+  Address Addr = CGF.CGM.getOpenMPRuntime().getAddrOfDeclareTargetLink(VD);
+  return CGF.EmitLoadOfPointer(Addr, PtrTy->castAs());
 }
 
 Address

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=339805&r1=339804&r2=339805&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Aug 15 12:45:12 2018
@@ -2622,7 +2622,7 @@ bool CGOpenMPRuntime::emitDeclareTargetV
   Optional Res =
   OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
   if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_Link)
-return false;
+return CGM.getLangOpts().OpenMPIsDevice;
   VD = VD->getDefinition(CGM.getContext());
   if (VD && !DeclareTargetWithDefinition.insert(VD).second)
 return CGM.getLangOpts().OpenMPIsDevice;
@@ -8089,8 +8089,7 @@ bool CGOpenMPRuntime::emitTargetGlobalVa
   OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(
   cast(GD.getDecl()));
   if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_Link) {
-if (CGM.getContext().DeclMustBeEmitted(GD.getDecl()))
-  DeferredGlobalVariables.insert(cast(GD.getDecl()));
+DeferredGlobalVariables.insert(cast(GD.getDecl()));
 return true;
   }
   return false;
@@ -8154,10 +8153,14 @@ void CGOpenMPRuntime::emitDeferredTarget
   for (const VarDecl *VD : DeferredGlobalVariables) {
 llvm::Optional Res =
 OMPDeclareTargetDeclAttr::isDeclareTar

Re: r339603 - [OPENMP] Fix emission of the loop doacross constructs.

2018-08-16 Thread Alexey Bataev via cfe-commits
Hans, thanks a lot. 

Best regards,
Alexey Bataev

> 16 авг. 2018 г., в 5:36, Hans Wennborg  написал(а):
> 
> I've gone ahead and merged it in r339851.
> 
>> On Wed, Aug 15, 2018 at 3:23 PM, Alexey Bataev  wrote:
>> I think it would be good to backport it. Could you do that, Jonas?
>> 
>> -
>> Best regards,
>> Alexey Bataev
>> 
>> 15.08.2018 5:02, Jonas Hahnfeld via cfe-commits пишет:
>> 
>> Alexey, Hans,
>> 
>> does it make sense to backport for 7.0 as it fixes PR37580?
>> 
>> Thanks,
>> Jonas
>> 
>> On 2018-08-13 21:04, Alexey Bataev via cfe-commits wrote:
>> 
>> Author: abataev
>> Date: Mon Aug 13 12:04:24 2018
>> New Revision: 339603
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=339603&view=rev
>> Log:
>> [OPENMP] Fix emission of the loop doacross constructs.
>> 
>> The number of loops associated with the OpenMP loop constructs should
>> not be considered as the number loops to collapse.
>> 
>> Modified:
>>cfe/trunk/include/clang/AST/OpenMPClause.h
>>cfe/trunk/lib/AST/OpenMPClause.cpp
>>cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>>cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
>>cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
>>cfe/trunk/lib/Sema/SemaOpenMP.cpp
>>cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
>>cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
>>cfe/trunk/test/OpenMP/ordered_doacross_codegen.c
>>cfe/trunk/test/OpenMP/ordered_doacross_codegen.cpp
>>cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp
>> 
>> Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=339603&r1=339602&r2=339603&view=diff
>> ==
>> --- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
>> +++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Aug 13 12:04:24 2018
>> @@ -930,8 +930,11 @@ public:
>> /// \endcode
>> /// In this example directive '#pragma omp for' has 'ordered' clause with
>> /// parameter 2.
>> -class OMPOrderedClause : public OMPClause {
>> +class OMPOrderedClause final
>> +: public OMPClause,
>> +  private llvm::TrailingObjects {
>>   friend class OMPClauseReader;
>> +  friend TrailingObjects;
>> 
>>   /// Location of '('.
>>   SourceLocation LParenLoc;
>> @@ -939,6 +942,26 @@ class OMPOrderedClause : public OMPClaus
>>   /// Number of for-loops.
>>   Stmt *NumForLoops = nullptr;
>> 
>> +  /// Real number of loops.
>> +  unsigned NumberOfLoops = 0;
>> +
>> +  /// Build 'ordered' clause.
>> +  ///
>> +  /// \param Num Expression, possibly associated with this clause.
>> +  /// \param NumLoops Number of loops, associated with this clause.
>> +  /// \param StartLoc Starting location of the clause.
>> +  /// \param LParenLoc Location of '('.
>> +  /// \param EndLoc Ending location of the clause.
>> +  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
>> +   SourceLocation LParenLoc, SourceLocation EndLoc)
>> +  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
>> +NumForLoops(Num), NumberOfLoops(NumLoops) {}
>> +
>> +  /// Build an empty clause.
>> +  explicit OMPOrderedClause(unsigned NumLoops)
>> +  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
>> +NumberOfLoops(NumLoops) {}
>> +
>>   /// Set the number of associated for-loops.
>>   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
>> 
>> @@ -946,17 +969,17 @@ public:
>>   /// Build 'ordered' clause.
>>   ///
>>   /// \param Num Expression, possibly associated with this clause.
>> +  /// \param NumLoops Number of loops, associated with this clause.
>>   /// \param StartLoc Starting location of the clause.
>>   /// \param LParenLoc Location of '('.
>>   /// \param EndLoc Ending location of the clause.
>> -  OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
>> -SourceLocation LParenLoc, SourceLocation EndLoc)
>> -  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
>> -NumForLoops(Num) {}
>> +  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
>> +  unsigned NumLoops, SourceLocation
>> StartLoc,
>> +  

r340181 - [OPENMP][BLOCKS]Fix PR38923: reference to a global variable is captured

2018-08-20 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 20 09:00:22 2018
New Revision: 340181

URL: http://llvm.org/viewvc/llvm-project?rev=340181&view=rev
Log:
[OPENMP][BLOCKS]Fix PR38923: reference to a global variable is captured
by a block.

Added checks for capturing of the variable in the block when trying to
emit correct address for the variable with the reference type. This
extra check allows correctly identify the variables that are not
captured in the block context.

Added:
cfe/trunk/test/CodeGenCXX/block-byref.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=340181&r1=340180&r2=340181&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Aug 20 09:00:22 2018
@@ -2437,6 +2437,7 @@ LValue CodeGenFunction::EmitDeclRefLValu
 // A DeclRefExpr for a reference initialized by a constant expression can
 // appear without being odr-used. Directly emit the constant initializer.
 const Expr *Init = VD->getAnyInitializer(VD);
+const auto *BD = dyn_cast_or_null(CurCodeDecl);
 if (Init && !isa(VD) && VD->getType()->isReferenceType() &&
 VD->isUsableInConstantExpressions(getContext()) &&
 VD->checkInitIsICE() &&
@@ -2446,7 +2447,7 @@ LValue CodeGenFunction::EmitDeclRefLValu
 (LocalDeclMap.count(VD->getCanonicalDecl()) ||
  CapturedStmtInfo->lookup(VD->getCanonicalDecl( ||
LambdaCaptureFields.lookup(VD->getCanonicalDecl()) ||
-   isa(CurCodeDecl {
+   (BD && BD->capturesVariable(VD) {
   llvm::Constant *Val =
 ConstantEmitter(*this).emitAbstract(E->getLocation(),
 *VD->evaluateValue(),

Added: cfe/trunk/test/CodeGenCXX/block-byref.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/block-byref.cpp?rev=340181&view=auto
==
--- cfe/trunk/test/CodeGenCXX/block-byref.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/block-byref.cpp Mon Aug 20 09:00:22 2018
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -std=c++11 
-emit-llvm -o - | FileCheck %s
+// REQUIRES: x86-registered-target
+
+// CHECK: @b = global i32 0,
+
+// CHECK: define {{.*}}void @{{.*}}test{{.*}}_block_invoke(
+// CHECK: store i32 2, i32* @b,
+// CHECK: ret void
+
+int b;
+
+void test() {
+  int &a = b;
+  ^{ a = 2; };
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r340191 - [OPENMP] Fix crash on the emission of the weak function declaration.

2018-08-20 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 20 11:03:40 2018
New Revision: 340191

URL: http://llvm.org/viewvc/llvm-project?rev=340191&view=rev
Log:
[OPENMP] Fix crash on the emission of the weak function declaration.

If the function is actually a weak reference, it should not be marked as
deferred definition as this is only a declaration. Patch adds checks for
the definitions if they must be emitted. Otherwise, only declaration is
emitted.

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=340191&r1=340190&r2=340191&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Aug 20 11:03:40 2018
@@ -2558,15 +2558,17 @@ llvm::Constant *CodeGenModule::GetOrCrea
 if (getLangOpts().OpenMPIsDevice && OpenMPRuntime &&
 !OpenMPRuntime->markAsGlobalTarget(GD) && FD->isDefined() &&
 !DontDefer && !IsForDefinition) {
-  const FunctionDecl *FDDef = FD->getDefinition();
-  GlobalDecl GDDef;
-  if (const auto *CD = dyn_cast(FDDef))
-GDDef = GlobalDecl(CD, GD.getCtorType());
-  else if (const auto *DD = dyn_cast(FDDef))
-GDDef = GlobalDecl(DD, GD.getDtorType());
-  else
-GDDef = GlobalDecl(FDDef);
-  addDeferredDeclToEmit(GDDef);
+  if (const FunctionDecl *FDDef = FD->getDefinition())
+if (getContext().DeclMustBeEmitted(FDDef)) {
+  GlobalDecl GDDef;
+  if (const auto *CD = dyn_cast(FDDef))
+GDDef = GlobalDecl(CD, GD.getCtorType());
+  else if (const auto *DD = dyn_cast(FDDef))
+GDDef = GlobalDecl(DD, GD.getDtorType());
+  else
+GDDef = GlobalDecl(FDDef);
+  addDeferredDeclToEmit(GDDef);
+}
 }
 
 if (FD->isMultiVersion()) {

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=340191&r1=340190&r2=340191&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Mon Aug 20 11:03:40 2018
@@ -128,5 +128,19 @@ int baz2() {
   return 2 + baz3();
 }
 
+extern int create() throw();
+
+static __typeof(create) __t_create __attribute__((__weakref__("__create")));
+
+int baz5() {
+  bool a;
+// CHECK-DAG: define weak void 
@__omp_offloading_{{.*}}baz5{{.*}}_l[[@LINE+1]](i64 {{.*}})
+#pragma omp target
+  a = __extension__(void *) & __t_create != 0;
+  return a;
+}
+
+// CHECK-DAG: declare extern_weak signext i32 @__create()
+
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
 #endif // HEADER


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r331879 - [OPENMP] Mark global tors/dtors as used.

2018-05-09 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed May  9 07:15:18 2018
New Revision: 331879

URL: http://llvm.org/viewvc/llvm-project?rev=331879&view=rev
Log:
[OPENMP] Mark global tors/dtors as used.

If the global variables are marked as declare target and they need
ctors/dtors, these ctors/dtors are emitted and then invoked by the
offloading runtime library. They are not explicitly used in the emitted
code and thus can be optimized out. Patch marks these functions as used,
so the optimizer cannot remove these function during the optimization
phase.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=331879&r1=331878&r2=331879&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed May  9 07:15:18 2018
@@ -2686,6 +2686,7 @@ bool CGOpenMPRuntime::emitDeclareTargetV
   CtorCGF.FinishFunction();
   Ctor = Fn;
   ID = llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy);
+  CGM.addUsedGlobal(cast(Ctor));
 } else {
   Ctor = new llvm::GlobalVariable(
   CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,
@@ -2724,6 +2725,7 @@ bool CGOpenMPRuntime::emitDeclareTargetV
   DtorCGF.FinishFunction();
   Dtor = Fn;
   ID = llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy);
+  CGM.addUsedGlobal(cast(Dtor));
 } else {
   Dtor = new llvm::GlobalVariable(
   CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=331879&r1=331878&r2=331879&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Wed May  9 07:15:18 2018
@@ -17,10 +17,13 @@
 // CHECK-DAG: @b = global i32 15,
 // CHECK-DAG: @d = global i32 0,
 // CHECK-DAG: @c = external global i32,
+// CHECK-DAG: @globals = global %struct.S zeroinitializer,
+// CHECK-DAG: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* 
@__omp_offloading__{{.+}}_globals_l[[@LINE+41]]_ctor to i8*)], section 
"llvm.metadata"
 
 // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}()
 // CHECK-DAG: define {{.*}}void 
@{{.*}}TemplateClass{{.*}}(%class.TemplateClass* %{{.*}})
 // CHECK-DAG: define {{.*}}i32 
@{{.*}}TemplateClass{{.*}}f_method{{.*}}(%class.TemplateClass* %{{.*}})
+// CHECK-DAG: define {{.*}}void 
@__omp_offloading__{{.*}}_globals_l[[@LINE+36]]_ctor()
 
 #ifndef HEADER
 #define HEADER
@@ -56,6 +59,7 @@ struct S {
 int foo() { return 0; }
 int b = 15;
 int d;
+S globals(d);
 #pragma omp end declare target
 int c;
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r331899 - [OPENMP] Generate unique names for offloading regions id.

2018-05-09 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed May  9 11:02:37 2018
New Revision: 331899

URL: http://llvm.org/viewvc/llvm-project?rev=331899&view=rev
Log:
[OPENMP] Generate unique names for offloading regions id.

It is required to emit unique names for offloading regions ids. Required
to support compilation and linking of several compilation units.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp
cfe/trunk/test/OpenMP/target_map_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=331899&r1=331898&r2=331899&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed May  9 11:02:37 2018
@@ -6286,7 +6286,7 @@ void CGOpenMPRuntime::emitTargetOutlined
 OutlinedFn->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
 OutlinedFn->setDSOLocal(false);
   } else {
-std::string Name = getName({"omp_offload", "region_id"});
+std::string Name = getName({EntryFnName, "region_id"});
 OutlinedFnID = new llvm::GlobalVariable(
 CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,
 llvm::GlobalValue::WeakAnyLinkage,

Modified: cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp?rev=331899&r1=331898&r2=331899&view=diff
==
--- cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_is_device_ptr_codegen.cpp Wed May  9 11:02:37 
2018
@@ -206,12 +206,18 @@ void bar(float *&a, int *&b) {
 
 // CK2: [[ST:%.+]] = type { double*, double** }
 
+// CK2-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}_l245.region_id = weak 
constant i8 0
+
 // CK2: [[SIZE00:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 
{{8|4}}]
 // CK2: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 33]
 
+// CK2-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}_l269.region_id = weak 
constant i8 0
+
 // CK2: [[SIZE01:@.+]] = {{.+}}constant [2 x i[[sz]]] [i[[sz]] {{8|4}}, 
i[[sz]] {{8|4}}]
 // CK2: [[MTYPE01:@.+]] = {{.+}}constant [2 x i64] [i64 32, i64 17]
 
+// CK2-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}_l301.region_id = weak 
constant i8 0
+
 // CK2: [[SIZE02:@.+]] = {{.+}}constant [3 x i[[sz]]] [i[[sz]] {{8|4}}, 
i[[sz]] {{8|4}}, i[[sz]] {{8|4}}]
 // CK2: [[MTYPE02:@.+]] = {{.+}}constant [3 x i64] [i64 33, i64 0, i64 17]
 

Modified: cfe/trunk/test/OpenMP/target_map_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_map_codegen.cpp?rev=331899&r1=331898&r2=331899&view=diff
==
--- cfe/trunk/test/OpenMP/target_map_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_map_codegen.cpp Wed May  9 11:02:37 2018
@@ -39,6 +39,8 @@ public:
 };
 double B::VAR = 1.0;
 
+// CK1-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_integer{{.*}}_l68.region_id = weak 
constant i8 0
+
 // CK1-DAG: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK1-DAG: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
@@ -94,9 +96,14 @@ void implicit_maps_integer (int a){
 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
 #ifdef CK2
 
+// CK2-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_reference{{.*}}_l128.region_id = weak 
constant i8 0
+
 // CK2: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK2: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
+
+// CK2-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_reference{{.*}}_l147.region_id = weak 
constant i8 0
+
 // CK2: [[SIZES2:@.+]] = {{.+}}constant [1 x i[[sz]]] zeroinitializer
 // Map types: OMP_MAP_IS_PTR = 32
 // CK2: [[TYPES2:@.+]] = {{.+}}constant [1 x i64] [i64 32]
@@ -181,6 +188,8 @@ void implicit_maps_reference (int a, int
 // SIMD-ONLY2-NOT: {{__kmpc|__tgt}}
 #ifdef CK3
 
+// CK3-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_parameter{{.*}}_l214.region_id = weak 
constant i8 0
+
 // CK3-DAG: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK3-DAG: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
@@ -233,6 +242,8 @@ void implicit_maps_parameter (int a){
 // SIMD-ONLY3-NOT: {{__kmpc|__tgt}}
 #ifdef CK4
 
+// CK4-LABEL: 
@.__omp_offloading_{{.*}}implicit_maps_nested_integer{{.*}}_l276.region_id = 
weak constant i8 0
+
 // CK4-DAG: [[SIZES:@.+]] = {{.+}}constant [1 x i[[sz:64|32]]] [i{{64|32}} 4]
 // Map types: OMP_MAP_PRIVATE_VAL | OMP_MAP_IS_FIRST = 288
 // CK4-DAG: [[TYPES:@.+]] = {{.+}}constant [1 x i64] [i64 288]
@@ -297,6 +308,8 @@ void implicit_maps_nested_integer (int a

r332016 - [OPENMP, NVPTX] Initial support for L2 parallelism in SPMD mode.

2018-05-10 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu May 10 11:32:08 2018
New Revision: 332016

URL: http://llvm.org/viewvc/llvm-project?rev=332016&view=rev
Log:
[OPENMP, NVPTX] Initial support for L2 parallelism in SPMD mode.

Added initial support for L2 parallelism in SPMD mode. Note, though,
that the orphaned parallel directives are not currently supported in
SPMD mode.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/test/OpenMP/nvptx_parallel_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp

cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=332016&r1=332015&r2=332016&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu May 10 11:32:08 2018
@@ -140,13 +140,15 @@ public:
 /// to emit optimized code.
 class ExecutionModeRAII {
 private:
-  bool SavedMode;
-  bool &Mode;
+  CGOpenMPRuntimeNVPTX::ExecutionMode SavedMode;
+  CGOpenMPRuntimeNVPTX::ExecutionMode &Mode;
 
 public:
-  ExecutionModeRAII(bool &Mode, bool NewMode) : Mode(Mode) {
+  ExecutionModeRAII(CGOpenMPRuntimeNVPTX::ExecutionMode &Mode, bool IsSPMD)
+  : Mode(Mode) {
 SavedMode = Mode;
-Mode = NewMode;
+Mode = IsSPMD ? CGOpenMPRuntimeNVPTX::EM_SPMD
+  : CGOpenMPRuntimeNVPTX::EM_NonSPMD;
   }
   ~ExecutionModeRAII() { Mode = SavedMode; }
 };
@@ -579,8 +581,9 @@ void CGOpenMPRuntimeNVPTX::WorkerFunctio
   WorkerFn->setDoesNotRecurse();
 }
 
-bool CGOpenMPRuntimeNVPTX::isInSpmdExecutionMode() const {
-  return IsInSPMDExecutionMode;
+CGOpenMPRuntimeNVPTX::ExecutionMode
+CGOpenMPRuntimeNVPTX::getExecutionMode() const {
+  return CurrentExecutionMode;
 }
 
 static CGOpenMPRuntimeNVPTX::DataSharingMode
@@ -589,34 +592,96 @@ getDataSharingMode(CodeGenModule &CGM) {
   : CGOpenMPRuntimeNVPTX::Generic;
 }
 
-/// Check for inner (nested) SPMD construct, if any
-static bool hasNestedSPMDDirective(const OMPExecutableDirective &D) {
-  const auto *CS = D.getCapturedStmt(OMPD_target);
-  const auto *Body = CS->getCapturedStmt()->IgnoreContainers();
-  const Stmt *ChildStmt = nullptr;
+/// Checks if the \p Body is the \a CompoundStmt and returns its child 
statement
+/// iff there is only one.
+static const Stmt *getSingleCompoundChild(const Stmt *Body) {
   if (const auto *C = dyn_cast(Body))
 if (C->size() == 1)
-  ChildStmt = C->body_front();
-  if (!ChildStmt)
-return false;
+  return C->body_front();
+  return Body;
+}
+
+/// Check if the parallel directive has an 'if' clause with non-constant or
+/// false condition.
+static bool hasParallelIfClause(ASTContext &Ctx,
+const OMPExecutableDirective &D) {
+  for (const auto *C : D.getClausesOfKind()) {
+OpenMPDirectiveKind NameModifier = C->getNameModifier();
+if (NameModifier != OMPD_parallel && NameModifier != OMPD_unknown)
+  continue;
+const Expr *Cond = C->getCondition();
+bool Result;
+if (!Cond->EvaluateAsBooleanCondition(Result, Ctx) || !Result)
+  return true;
+  }
+  return false;
+}
+
+/// Check for inner (nested) SPMD construct, if any
+static bool hasNestedSPMDDirective(ASTContext &Ctx,
+   const OMPExecutableDirective &D) {
+  const auto *CS = D.getInnermostCapturedStmt();
+  const auto *Body = CS->getCapturedStmt()->IgnoreContainers();
+  const Stmt *ChildStmt = getSingleCompoundChild(Body);
 
   if (const auto *NestedDir = dyn_cast(ChildStmt)) {
 OpenMPDirectiveKind DKind = NestedDir->getDirectiveKind();
-// TODO: add further analysis for inner teams|distribute directives, if 
any.
 switch (D.getDirectiveKind()) {
 case OMPD_target:
-  return (isOpenMPParallelDirective(DKind) &&
-  !isOpenMPTeamsDirective(DKind) &&
-  !isOpenMPDistributeDirective(DKind)) ||
- isOpenMPSimdDirective(DKind) ||
- DKind == OMPD_teams_distribute_parallel_for;
+  if ((isOpenMPParallelDirective(DKind) &&
+   !hasParallelIfClause(Ctx, *NestedDir)) ||
+  isOpenMPSimdDirective(DKind))
+return true;
+  if (DKind == OMPD_teams || DKind == OMPD_teams_distribute) {
+Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
+if (!Body)
+  return false;
+ChildStmt = getSingleCompoundChild(Body);
+if (const auto *NND = dyn_cast(ChildStmt)) {
+  DKind = NND->getDirectiveKind();
+  if ((isOpenMPParallelDirective(DKind) &&
+   !hasParallelIfClause(Ctx, *NND)) ||
+  isOpenMPSimdDirective(DKind))
+ 

r332129 - [OPENMP, NVPTX] Do not use SPMD mode for target simd and target teams

2018-05-11 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri May 11 12:45:14 2018
New Revision: 332129

URL: http://llvm.org/viewvc/llvm-project?rev=332129&view=rev
Log:
[OPENMP, NVPTX] Do not use SPMD mode for target simd and target teams
distribute simd directives.

Directives `target simd` and `target teams distribute simd` must be
executed in non-SPMD mode.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=332129&r1=332128&r2=332129&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri May 11 12:45:14 2018
@@ -628,9 +628,8 @@ static bool hasNestedSPMDDirective(ASTCo
 OpenMPDirectiveKind DKind = NestedDir->getDirectiveKind();
 switch (D.getDirectiveKind()) {
 case OMPD_target:
-  if ((isOpenMPParallelDirective(DKind) &&
-   !hasParallelIfClause(Ctx, *NestedDir)) ||
-  isOpenMPSimdDirective(DKind))
+  if (isOpenMPParallelDirective(DKind) &&
+  !hasParallelIfClause(Ctx, *NestedDir))
 return true;
   if (DKind == OMPD_teams || DKind == OMPD_teams_distribute) {
 Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
@@ -639,9 +638,8 @@ static bool hasNestedSPMDDirective(ASTCo
 ChildStmt = getSingleCompoundChild(Body);
 if (const auto *NND = dyn_cast(ChildStmt)) {
   DKind = NND->getDirectiveKind();
-  if ((isOpenMPParallelDirective(DKind) &&
-   !hasParallelIfClause(Ctx, *NND)) ||
-  isOpenMPSimdDirective(DKind))
+  if (isOpenMPParallelDirective(DKind) &&
+  !hasParallelIfClause(Ctx, *NND))
 return true;
   if (DKind == OMPD_distribute) {
 Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
@@ -652,18 +650,16 @@ static bool hasNestedSPMDDirective(ASTCo
   return false;
 if (const auto *NND = dyn_cast(ChildStmt)) 
{
   DKind = NND->getDirectiveKind();
-  return (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfClause(Ctx, *NND)) ||
- isOpenMPSimdDirective(DKind);
+  return isOpenMPParallelDirective(DKind) &&
+ !hasParallelIfClause(Ctx, *NND);
 }
   }
 }
   }
   return false;
 case OMPD_target_teams:
-  if ((isOpenMPParallelDirective(DKind) &&
-   !hasParallelIfClause(Ctx, *NestedDir)) ||
-  isOpenMPSimdDirective(DKind))
+  if (isOpenMPParallelDirective(DKind) &&
+  !hasParallelIfClause(Ctx, *NestedDir))
 return true;
   if (DKind == OMPD_distribute) {
 Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
@@ -672,16 +668,14 @@ static bool hasNestedSPMDDirective(ASTCo
 ChildStmt = getSingleCompoundChild(Body);
 if (const auto *NND = dyn_cast(ChildStmt)) {
   DKind = NND->getDirectiveKind();
-  return (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfClause(Ctx, *NND)) ||
- isOpenMPSimdDirective(DKind);
+  return isOpenMPParallelDirective(DKind) &&
+ !hasParallelIfClause(Ctx, *NND);
 }
   }
   return false;
 case OMPD_target_teams_distribute:
-  return (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfClause(Ctx, *NestedDir)) ||
- isOpenMPSimdDirective(DKind);
+  return isOpenMPParallelDirective(DKind) &&
+ !hasParallelIfClause(Ctx, *NestedDir);
 case OMPD_target_simd:
 case OMPD_target_parallel:
 case OMPD_target_parallel_for:
@@ -755,7 +749,7 @@ static bool supportsSPMDExecutionMode(AS
 return !hasParallelIfClause(Ctx, D);
   case OMPD_target_simd:
   case OMPD_target_teams_distribute_simd:
-return true;
+return false;
   case OMPD_parallel:
   case OMPD_for:
   case OMPD_parallel_for:

Modified: cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp?rev=332129&r1=332128&r2=332129&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_simd_codegen.cpp Fri May 11 12:45:14 2018
@@ -8,11 +8,11 @@
 #ifndef HEADER
 #define HEADER
 
-// Check that the execution mode of all 2 target regions on the gpu is set to 
SPMD Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l25}}_exec_mode = weak constant i8 0
-// CHECK-DAG: {{@__omp_offloading_.+l30}}_exec_mode = weak constant i8 0
-// CHECK-DAG: {{@__om

r332380 - [OPENMP, NVPTX] Do not globalize variables with reference/pointer types.

2018-05-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue May 15 11:01:01 2018
New Revision: 332380

URL: http://llvm.org/viewvc/llvm-project?rev=332380&view=rev
Log:
[OPENMP, NVPTX] Do not globalize variables with reference/pointer types.

In generic data-sharing mode we do not need to globalize
variables/parameters of reference/pointer types. They already are placed
in the global memory.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp

cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=332380&r1=332379&r2=332380&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue May 15 11:01:01 2018
@@ -220,7 +220,10 @@ class CheckVarsEscapingDeclContext final
"Parameter captured by value with variably modified type");
 EscapedParameters.insert(VD);
   }
-}
+} else if (VD->getType()->isAnyPointerType() ||
+   VD->getType()->isReferenceType())
+  // Do not globalize variables with reference or pointer type.
+  return;
 if (VD->getType()->isVariablyModifiedType())
   EscapedVariableLengthDecls.insert(VD);
 else
@@ -602,9 +605,12 @@ static const Stmt *getSingleCompoundChil
 }
 
 /// Check if the parallel directive has an 'if' clause with non-constant or
-/// false condition.
-static bool hasParallelIfClause(ASTContext &Ctx,
-const OMPExecutableDirective &D) {
+/// false condition. Also, check if the number of threads is strictly specified
+/// and run those directives in non-SPMD mode.
+static bool hasParallelIfNumThreadsClause(ASTContext &Ctx,
+  const OMPExecutableDirective &D) {
+  if (D.hasClausesOfKind())
+return true;
   for (const auto *C : D.getClausesOfKind()) {
 OpenMPDirectiveKind NameModifier = C->getNameModifier();
 if (NameModifier != OMPD_parallel && NameModifier != OMPD_unknown)
@@ -629,7 +635,7 @@ static bool hasNestedSPMDDirective(ASTCo
 switch (D.getDirectiveKind()) {
 case OMPD_target:
   if (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfClause(Ctx, *NestedDir))
+  !hasParallelIfNumThreadsClause(Ctx, *NestedDir))
 return true;
   if (DKind == OMPD_teams || DKind == OMPD_teams_distribute) {
 Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
@@ -639,7 +645,7 @@ static bool hasNestedSPMDDirective(ASTCo
 if (const auto *NND = dyn_cast(ChildStmt)) {
   DKind = NND->getDirectiveKind();
   if (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfClause(Ctx, *NND))
+  !hasParallelIfNumThreadsClause(Ctx, *NND))
 return true;
   if (DKind == OMPD_distribute) {
 Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
@@ -651,7 +657,7 @@ static bool hasNestedSPMDDirective(ASTCo
 if (const auto *NND = dyn_cast(ChildStmt)) 
{
   DKind = NND->getDirectiveKind();
   return isOpenMPParallelDirective(DKind) &&
- !hasParallelIfClause(Ctx, *NND);
+ !hasParallelIfNumThreadsClause(Ctx, *NND);
 }
   }
 }
@@ -659,7 +665,7 @@ static bool hasNestedSPMDDirective(ASTCo
   return false;
 case OMPD_target_teams:
   if (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfClause(Ctx, *NestedDir))
+  !hasParallelIfNumThreadsClause(Ctx, *NestedDir))
 return true;
   if (DKind == OMPD_distribute) {
 Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
@@ -669,13 +675,13 @@ static bool hasNestedSPMDDirective(ASTCo
 if (const auto *NND = dyn_cast(ChildStmt)) {
   DKind = NND->getDirectiveKind();
   return isOpenMPParallelDirective(DKind) &&
- !hasParallelIfClause(Ctx, *NND);
+ !hasParallelIfNumThreadsClause(Ctx, *NND);
 }
   }
   return false;
 case OMPD_target_teams_distribute:
   return isOpenMPParallelDirective(DKind) &&
- !hasParallelIfClause(Ctx, *NestedDir);
+ !hasParallelIfNumThreadsClause(Ctx, *NestedDir);
 case OMPD_target_simd:
 case OMPD_target_parallel:
 case OMPD_target_parallel_for:
@@ -746,7 +752,7 @@ static bool supportsSPMDExecutionMode(AS
   case OMPD_target_parallel_for_simd:
   case OMPD_target_teams_distribute_parallel_for:
   case OMPD_target_teams_distribute_

r332467 - [OPENMP, NVPTX] Add check for SPMD mode in orphaned parallel directives.

2018-05-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed May 16 06:36:30 2018
New Revision: 332467

URL: http://llvm.org/viewvc/llvm-project?rev=332467&view=rev
Log:
[OPENMP, NVPTX] Add check for SPMD mode in orphaned parallel directives.

If the orphaned directive is executed in SPMD mode, we need to emit the
check for the SPMD mode and run the orphaned parallel directive in
sequential mode.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=332467&r1=332466&r2=332467&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Wed May 16 06:36:30 2018
@@ -96,6 +96,8 @@ enum OpenMPRTLFunctionNVPTX {
   /// Call to uint16_t __kmpc_parallel_level(ident_t *loc, kmp_int32
   /// global_tid);
   OMPRTL_NVPTX__kmpc_parallel_level,
+  /// Call to int8_t __kmpc_is_spmd_exec_mode();
+  OMPRTL_NVPTX__kmpc_is_spmd_exec_mode,
 };
 
 /// Pre(post)-action for different OpenMP constructs specialized for NVPTX.
@@ -220,8 +222,7 @@ class CheckVarsEscapingDeclContext final
"Parameter captured by value with variably modified type");
 EscapedParameters.insert(VD);
   }
-} else if (VD->getType()->isAnyPointerType() ||
-   VD->getType()->isReferenceType())
+} else if (VD->getType()->isReferenceType())
   // Do not globalize variables with reference or pointer type.
   return;
 if (VD->getType()->isVariablyModifiedType())
@@ -317,8 +318,18 @@ public:
   return;
 if (D->hasAssociatedStmt()) {
   if (const auto *S =
-  dyn_cast_or_null(D->getAssociatedStmt()))
+  dyn_cast_or_null(D->getAssociatedStmt())) {
+// Do not analyze directives that do not actually require capturing,
+// like `omp for` or `omp simd` directives.
+llvm::SmallVector CaptureRegions;
+getOpenMPCaptureRegions(CaptureRegions, D->getDirectiveKind());
+if (CaptureRegions.size() == 1 &&
+CaptureRegions.back() == OMPD_unknown) {
+  VisitStmt(S->getCapturedStmt());
+  return;
+}
 VisitOpenMPCapturedStmt(S);
+  }
 }
   }
   void VisitCapturedStmt(const CapturedStmt *S) {
@@ -1411,6 +1422,12 @@ CGOpenMPRuntimeNVPTX::createNVPTXRuntime
 RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_parallel_level");
 break;
   }
+  case OMPRTL_NVPTX__kmpc_is_spmd_exec_mode: {
+// Build int8_t __kmpc_is_spmd_exec_mode();
+auto *FnTy = llvm::FunctionType::get(CGM.Int8Ty, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_is_spmd_exec_mode");
+break;
+  }
   }
   return RTLFn;
 }
@@ -1828,7 +1845,9 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   RCG(CGF);
 } else {
   // Check for master and then parallelism:
-  // if (is_master) {
+  // if (__kmpc_is_spmd_exec_mode()) {
+  //  Serialized execution.
+  // } else if (is_master) {
   //   Worker call.
   // } else if (__kmpc_parallel_level(loc, gtid)) {
   //   Serialized execution.
@@ -1837,13 +1856,22 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   // }
   CGBuilderTy &Bld = CGF.Builder;
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
+  llvm::BasicBlock *SPMDCheckBB = CGF.createBasicBlock(".spmdcheck");
   llvm::BasicBlock *MasterCheckBB = CGF.createBasicBlock(".mastercheck");
   llvm::BasicBlock *ParallelCheckBB =
   CGF.createBasicBlock(".parallelcheck");
+  llvm::Value *IsSPMD = Bld.CreateIsNotNull(CGF.EmitNounwindRuntimeCall(
+  createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_is_spmd_exec_mode)));
+  Bld.CreateCondBr(IsSPMD, SPMDCheckBB, MasterCheckBB);
+  CGF.EmitBlock(SPMDCheckBB);
+  SeqGen(CGF, Action);
+  CGF.EmitBranch(ExitBB);
+  CGF.EmitBlock(MasterCheckBB);
+  llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
   llvm::Value *IsMaster =
   Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
-  Bld.CreateCondBr(IsMaster, MasterCheckBB, ParallelCheckBB);
-  CGF.EmitBlock(MasterCheckBB);
+  Bld.CreateCondBr(IsMaster, MasterThenBB, ParallelCheckBB);
+  CGF.EmitBlock(MasterThenBB);
   L0ParallelGen(CGF, Action);
   CGF.EmitBranch(ExitBB);
   // There is no need to emit line number for unconditional branch.

Modified: cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp?rev=332467&r1=332466&r2=332467&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp Wed May 16 06:36:30 2

r332477 - [OPENMP] DO not crash on combined constructs in declare target

2018-05-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed May 16 08:08:32 2018
New Revision: 332477

URL: http://llvm.org/viewvc/llvm-project?rev=332477&view=rev
Log:
[OPENMP] DO not crash on combined constructs in declare target
functions.

If the combined construct is specified in the declare target function
and the device code is emitted, the compiler crashes because of the
incorrectly chosen captured stmt. We should choose the innermost
captured statement, not the outermost.

Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=332477&r1=332476&r2=332477&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Wed May 16 08:08:32 2018
@@ -3935,7 +3935,7 @@ static void emitCommonOMPTargetDirective
 OMPLexicalScope Scope(CGF, S, OMPD_target);
 CGM.getOpenMPRuntime().emitInlinedDirective(
 CGF, OMPD_target, [&S](CodeGenFunction &CGF, PrePostActionTy &) {
-  CGF.EmitStmt(S.getCapturedStmt(OMPD_target)->getCapturedStmt());
+  CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt());
 });
 return;
   }

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=332477&r1=332476&r2=332477&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Wed May 16 08:08:32 2018
@@ -82,7 +82,7 @@ int maini1() {
 int baz3() { return 2 + baz2(); }
 int baz2() {
 // CHECK-DAG: define weak void 
@__omp_offloading_{{.*}}baz2{{.*}}_l[[@LINE+1]](i64 {{.*}})
-#pragma omp target
+#pragma omp target parallel
   ++c;
   return 2 + baz3();
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r332852 - [OPENMP-SIMD] Fix PR37536: Fix definition of _OPENMP macro.

2018-05-21 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon May 21 09:40:32 2018
New Revision: 332852

URL: http://llvm.org/viewvc/llvm-project?rev=332852&view=rev
Log:
[OPENMP-SIMD] Fix PR37536: Fix definition of _OPENMP macro.

if `-fopenmp-simd` is specified alone, `_OPENMP` macro should not be
  defined. If `-fopenmp-simd` is specified along with the `-fopenmp`,
  `_OPENMP` macro should be defined with the value `201511`.

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/OpenMP/driver.c
cfe/trunk/test/OpenMP/predefined_macro.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=332852&r1=332851&r2=332852&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon May 21 09:40:32 2018
@@ -3989,6 +3989,8 @@ void Clang::ConstructJob(Compilation &C,
   if (!Args.hasFlag(options::OPT_fopenmp_use_tls,
 options::OPT_fnoopenmp_use_tls, /*Default=*/true))
 CmdArgs.push_back("-fnoopenmp-use-tls");
+  Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
+  options::OPT_fno_openmp_simd);
   Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
 
   // When in OpenMP offloading mode with NVPTX target, forward

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=332852&r1=332851&r2=332852&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon May 21 09:40:32 2018
@@ -2562,9 +2562,10 @@ static void ParseLangArgs(LangOptions &O
   // Check if -fopenmp is specified.
   Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 1 : 0;
   // Check if -fopenmp-simd is specified.
-  Opts.OpenMPSimd = !Opts.OpenMP && Args.hasFlag(options::OPT_fopenmp_simd,
- options::OPT_fno_openmp_simd,
- /*Default=*/false);
+  bool IsSimdSpecified =
+  Args.hasFlag(options::OPT_fopenmp_simd, options::OPT_fno_openmp_simd,
+   /*Default=*/false);
+  Opts.OpenMPSimd = !Opts.OpenMP && IsSimdSpecified;
   Opts.OpenMPUseTLS =
   Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
   Opts.OpenMPIsDevice =
@@ -2573,9 +2574,9 @@ static void ParseLangArgs(LangOptions &O
   if (Opts.OpenMP || Opts.OpenMPSimd) {
 if (int Version =
 getLastArgIntValue(Args, OPT_fopenmp_version_EQ,
-   Opts.OpenMPSimd ? 45 : Opts.OpenMP, Diags))
+   IsSimdSpecified ? 45 : Opts.OpenMP, Diags))
   Opts.OpenMP = Version;
-else if (Opts.OpenMPSimd)
+else if (IsSimdSpecified)
   Opts.OpenMP = 45;
 // Provide diagnostic when a given target is not expected to be an OpenMP
 // device or host.

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=332852&r1=332851&r2=332852&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon May 21 09:40:32 2018
@@ -1027,19 +1027,21 @@ static void InitializePredefinedMacros(c
   //   macro name is defined to have the decimal value mm where
   //    and mm are the year and the month designations of the
   //   version of the OpenMP API that the implementation support.
-  switch (LangOpts.OpenMP) {
-  case 0:
-break;
-  case 40:
-Builder.defineMacro("_OPENMP", "201307");
-break;
-  case 45:
-Builder.defineMacro("_OPENMP", "201511");
-break;
-  default:
-// Default version is OpenMP 3.1, in Simd only mode - 4.5
-Builder.defineMacro("_OPENMP", LangOpts.OpenMPSimd ? "201511" : "201107");
-break;
+  if (!LangOpts.OpenMPSimd) {
+switch (LangOpts.OpenMP) {
+case 0:
+  break;
+case 40:
+  Builder.defineMacro("_OPENMP", "201307");
+  break;
+case 45:
+  Builder.defineMacro("_OPENMP", "201511");
+  break;
+default:
+  // Default version is OpenMP 3.1
+  Builder.defineMacro("_OPENMP", "201107");
+  break;
+}
   }
 
   // CUDA device path compilaton

Modified: cfe/trunk/test/OpenMP/driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/driver.c?rev=332852&r1=332851&r2=332852&view=diff
==
--- cfe/trunk/test/OpenMP/driver.c (original)
+++ cfe/trunk/test/OpenMP/driver.c Mon May 21 09:40:32 2018
@@ -18,19 

r333301 - [OPENMP, NVPTX] Fixed codegen for orphaned parallel region.

2018-05-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri May 25 13:16:03 2018
New Revision: 01

URL: http://llvm.org/viewvc/llvm-project?rev=01&view=rev
Log:
[OPENMP, NVPTX] Fixed codegen for orphaned parallel region.

If orphaned parallel region is found, the next code must be emitted:
```
if(__kmpc_is_spmd_exec_mode() || __kmpc_parallel_level(loc, gtid))
  Serialized execution.
else if (IsMasterThread())
  Prepare and signal worker.
else
  Outined function call.
```

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=01&r1=00&r2=01&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri May 25 13:16:03 2018
@@ -1845,35 +1845,21 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   RCG(CGF);
 } else {
   // Check for master and then parallelism:
-  // if (__kmpc_is_spmd_exec_mode()) {
+  // if (__kmpc_is_spmd_exec_mode() || __kmpc_parallel_level(loc, gtid)) {
   //  Serialized execution.
-  // } else if (is_master) {
+  // } else if (master) {
   //   Worker call.
-  // } else if (__kmpc_parallel_level(loc, gtid)) {
-  //   Serialized execution.
   // } else {
   //   Outlined function call.
   // }
   CGBuilderTy &Bld = CGF.Builder;
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
-  llvm::BasicBlock *SPMDCheckBB = CGF.createBasicBlock(".spmdcheck");
+  llvm::BasicBlock *SeqBB = CGF.createBasicBlock(".sequential");
+  llvm::BasicBlock *ParallelCheckBB = CGF.createBasicBlock(".parcheck");
   llvm::BasicBlock *MasterCheckBB = CGF.createBasicBlock(".mastercheck");
-  llvm::BasicBlock *ParallelCheckBB =
-  CGF.createBasicBlock(".parallelcheck");
   llvm::Value *IsSPMD = Bld.CreateIsNotNull(CGF.EmitNounwindRuntimeCall(
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_is_spmd_exec_mode)));
-  Bld.CreateCondBr(IsSPMD, SPMDCheckBB, MasterCheckBB);
-  CGF.EmitBlock(SPMDCheckBB);
-  SeqGen(CGF, Action);
-  CGF.EmitBranch(ExitBB);
-  CGF.EmitBlock(MasterCheckBB);
-  llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
-  llvm::Value *IsMaster =
-  Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
-  Bld.CreateCondBr(IsMaster, MasterThenBB, ParallelCheckBB);
-  CGF.EmitBlock(MasterThenBB);
-  L0ParallelGen(CGF, Action);
-  CGF.EmitBranch(ExitBB);
+  Bld.CreateCondBr(IsSPMD, SeqBB, ParallelCheckBB);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
   CGF.EmitBlock(ParallelCheckBB);
@@ -1883,15 +1869,23 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_parallel_level),
   {RTLoc, ThreadID});
   llvm::Value *Res = Bld.CreateIsNotNull(PL);
-  llvm::BasicBlock *ThenBlock = CGF.createBasicBlock("omp_if.then");
-  llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("omp_if.else");
-  Bld.CreateCondBr(Res, ThenBlock, ElseBlock);
-  // Emit the 'then' code.
-  CGF.EmitBlock(ThenBlock);
+  Bld.CreateCondBr(Res, SeqBB, MasterCheckBB);
+  CGF.EmitBlock(SeqBB);
   SeqGen(CGF, Action);
+  CGF.EmitBranch(ExitBB);
+  // There is no need to emit line number for unconditional branch.
+  (void)ApplyDebugLocation::CreateEmpty(CGF);
+  CGF.EmitBlock(MasterCheckBB);
+  llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
+  llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("omp_if.else");
+  llvm::Value *IsMaster =
+  Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
+  Bld.CreateCondBr(IsMaster, MasterThenBB, ElseBlock);
+  CGF.EmitBlock(MasterThenBB);
+  L0ParallelGen(CGF, Action);
+  CGF.EmitBranch(ExitBB);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
-  // Emit the 'else' code.
   CGF.EmitBlock(ElseBlock);
   RCG(CGF);
   // There is no need to emit line number for unconditional branch.

Modified: cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp?rev=01&r1=00&r2=01&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp Fri May 25 13:16:03 2018
@@ -566,6 +566,10 @@ int baz(int f, double &a) {
   // CHECK: icmp ne i8 [[RES]], 0
   // CHECK: br i1
 
+  // CHECK: [[RES:%.+]] = call i16 @__kmpc_parallel_level(%stru

r314205 - [OPENMP] Generate implicit map|firstprivate clauses for target-based

2017-09-26 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Sep 26 06:47:31 2017
New Revision: 314205

URL: http://llvm.org/viewvc/llvm-project?rev=314205&view=rev
Log:
[OPENMP] Generate implicit map|firstprivate clauses for target-based
directives.

If the variable is used in the target-based region but is not found in
any private|mapping clause, then generate implicit firstprivate|map
clauses for these implicitly mapped variables.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_codegen.cpp
cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/target_map_codegen.cpp
cfe/trunk/test/OpenMP/target_map_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_shared_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_shared_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_shared_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_shared_messages.cpp
cfe/trunk/test/OpenMP/teams_shared_messages.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=314205&r1=314204&r2=314205&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Sep 26 06:47:31 2017
@@ -862,18 +862,7 @@ static void EmitOMPAggregateInit(CodeGen
 }
 
 LValue ReductionCodeGen::emitSharedLValue(CodeGenFunction &CGF, const Expr *E) 
{
-  if (const auto *OASE = dyn_cast(E))
-return CGF.EmitOMPArraySectionExpr(OASE);
-  if (const auto *ASE = dyn_cast(E))
-return CGF.EmitLValue(ASE);
-  auto *OrigVD = cast(cast(E)->getDecl());
-  DeclRefExpr DRE(const_cast(OrigVD),
-  CGF.CapturedStmtInfo &&
-  CGF.CapturedStmtInfo->lookup(OrigVD) != nullptr,
-  E->getType(), VK_LValue, E->getExprLoc());
-  // Store the address of the original variable associated with the LHS
-  // implicit variable.
-  return CGF.EmitLValue(&DRE);
+  return CGF.EmitOMPSharedLValue(E);
 }
 
 LValue ReductionCodeGen::emitSharedLValueUB(CodeGenFunction &CGF,
@@ -5978,6 +5967,8 @@ public:
 OMP_MAP_PRIVATE_PTR = 0x80,
 /// \brief Pass the element to the device by value.
 OMP_MAP_PRIVATE_VAL = 0x100,
+/// Implicit map
+OMP_MAP_IMPLICIT = 0x200,
   };
 
   /// Class that associates information with a base pointer to be passed to the
@@ -6148,7 +6139,7 @@ private:
   OMPClauseMappableExprCommon::MappableExprComponentListRef Components,
   MapBaseValuesArrayTy &BasePointers, MapValuesArrayTy &Pointers,
   MapValuesArrayTy &Sizes, MapFlagsArrayTy &Types,
-  bool IsFirstComponentList) const {
+  bool IsFirstComponentList, bool IsImplicit) const {
 
 // The following summarizes what has to be generated for each map and the
 // types bellow. The generated information is expressed in this order:
@@ -6283,8 +6274,7 @@ private:
 } else {
   // The base is the reference to the variable.
   // BP = &Var.
-  BP = CGF.EmitLValue(cast(I->getAssociatedExpression()))
-   .getPointer();
+  BP = CGF.EmitOMPSharedLValue(I->getAssociatedExpression()).getPointer();
 
   // If the variable is a pointer and is being dereferenced (i.e. is not
   // the last component), the base has to be the pointer itself, not its
@@ -6303,6 +6293,7 @@ private:
   }
 }
 
+unsigned DefaultFlags = IsImplicit ? OMP_MAP_IMPLICIT : 0;
 for (; I != CE; ++I) {
   auto Next = std::next(I);
 
@@ -6337,7 +6328,8 @@ private:
 isa(Next->getAssociatedExpression())) &&
"Unexpected expression");
 
-auto *LB = CGF.EmitLValue(I->getAssociatedExpression()).getPointer();
+llvm::Value *LB =
+CGF.EmitOMPSharedLValue(I->getAssociatedExpression()).getPointer();
 auto *Size = getExprTypeSize(I->getAssociatedExpression());
 
 // If we have a member expression and the current component is a
@@ -6352,9 +6344,11 @@ private:
   BasePointers.push_back(BP);
   Pointers.push_back(RefAddr);
   Sizes.push_back(CGF.getTypeSize(CGF.getContext().VoidPtrTy));
-  Types.push_back(getMapTypeBits(
-  /*MapType*/ OMPC_MAP_alloc, /*MapTypeModifier=*/OMPC_MAP_unknown,
-  !IsExpressionFirstInfo, IsCaptureFirstInfo));
+  Types.push_back(DefaultFlags |
+  getMapTypeBits(
+  /*MapType*/ OMPC_MAP_alloc,
+  /*MapTypeModifier=*/OMPC_MAP_unknown,
+  !IsExpressionFirstInfo, IsCaptureFirstInfo));
   IsExpressionFirstInfo = 

r314220 - [OPENMP] Fix handling of implicit mapping of array sections.

2017-09-26 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Sep 26 09:19:04 2017
New Revision: 314220

URL: http://llvm.org/viewvc/llvm-project?rev=314220&view=rev
Log:
[OPENMP] Fix handling of implicit mapping of array sections.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_map_messages.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=314220&r1=314219&r2=314220&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Sep 26 09:19:04 2017
@@ -1972,9 +1972,8 @@ public:
   OMPClauseMappableExprCommon::MappableExprComponentListRef
   StackComponents,
   OpenMPClauseKind) {
-if (CurComponents.size() < StackComponents.size())
-  return false;
 auto CCI = CurComponents.rbegin();
+auto CCE = CurComponents.rend();
 for (const auto &SC : llvm::reverse(StackComponents)) {
   // Do both expressions have the same kind?
   if (CCI->getAssociatedExpression()->getStmtClass() !=
@@ -1992,6 +1991,8 @@ public:
   if (SCD != CCD)
 return false;
   std::advance(CCI, 1);
+  if (CCI == CCE)
+break;
 }
 return true;
   })) {

Modified: cfe/trunk/test/OpenMP/target_map_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_map_messages.cpp?rev=314220&r1=314219&r2=314220&view=diff
==
--- cfe/trunk/test/OpenMP/target_map_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/target_map_messages.cpp Tue Sep 26 09:19:04 2017
@@ -592,6 +592,8 @@ int main(int argc, char **argv) {
 #pragma omp target map(s.p->p->p->a)
 // expected-error@+1 {{variable already marked as mapped in current construct}}
   { s.a++; }
+#pragma omp target map(s.s.s.b[:2])
+  { s.s.s.b[0]++; }
 
   return tmain(argc)+tmain(argc); // expected-note {{in 
instantiation of function template specialization 'tmain' requested 
here}} expected-note {{in instantiation of function template specialization 
'tmain' requested here}}
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r314670 - [OPENMP] Simplify codegen for non-offloading code.

2017-10-02 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Oct  2 07:20:58 2017
New Revision: 314670

URL: http://llvm.org/viewvc/llvm-project?rev=314670&view=rev
Log:
[OPENMP] Simplify codegen for non-offloading code.

Simplified and generalized codegen for non-offloading part that works if
offloading is failed or condition of the `if` clause is `false`.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/target_codegen.cpp
cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_if_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_num_threads_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=314670&r1=314669&r2=314670&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Oct  2 07:20:58 2017
@@ -6865,8 +6865,6 @@ void CGOpenMPRuntime::emitTargetCall(Cod
 
   assert(OutlinedFn && "Invalid outlined function!");
 
-  auto &Ctx = CGF.getContext();
-
   // Fill up the arrays with all the captured variables.
   MappableExprsHandler::MapValuesArrayTy KernelArgs;
   MappableExprsHandler::MapBaseValuesArrayTy BasePointers;
@@ -6931,19 +6929,10 @@ void CGOpenMPRuntime::emitTargetCall(Cod
 MapTypes.append(CurMapTypes.begin(), CurMapTypes.end());
   }
 
-  // Keep track on whether the host function has to be executed.
-  auto OffloadErrorQType =
-  Ctx.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/true);
-  auto OffloadError = CGF.MakeAddrLValue(
-  CGF.CreateMemTemp(OffloadErrorQType, ".run_host_version"),
-  OffloadErrorQType);
-  CGF.EmitStoreOfScalar(llvm::Constant::getNullValue(CGM.Int32Ty),
-OffloadError);
-
   // Fill up the pointer arrays and transfer execution to the device.
-  auto &&ThenGen = [&BasePointers, &Pointers, &Sizes, &MapTypes, Device,
-OutlinedFnID, OffloadError,
-&D](CodeGenFunction &CGF, PrePostActionTy &) {
+  auto &&ThenGen = [this, &BasePointers, &Pointers, &Sizes, &MapTypes, Device,
+OutlinedFn, OutlinedFnID, &D,
+&KernelArgs](CodeGenFunction &CGF, PrePostActionTy &) {
 auto &RT = CGF.CGM.getOpenMPRuntime();
 // Emit the offloading arrays.
 TargetDataInfo Info;
@@ -7034,13 +7023,26 @@ void CGOpenMPRuntime::emitTargetCall(Cod
OffloadingArgs);
 }
 
-CGF.EmitStoreOfScalar(Return, OffloadError);
+// Check the error code and execute the host version if required.
+llvm::BasicBlock *OffloadFailedBlock =
+CGF.createBasicBlock("omp_offload.failed");
+llvm::BasicBlock *OffloadContBlock =
+CGF.createBasicBlock("omp_offload.cont");
+llvm::Value *Failed = CGF.Builder.CreateIsNotNull(Return);
+CGF.Builder.CreateCondBr(Failed, OffloadFailedBlock, OffloadContBlock);
+
+CGF.EmitBlock(OffloadFailedBlock);
+emitOutlinedFunctionCall(CGF, D.getLocStart(), OutlinedFn, KernelArgs);
+CGF.EmitBranch(OffloadContBlock);
+
+CGF.EmitBlock(OffloadContBlock, /*IsFinished=*/true);
   };
 
   // Notify that the host version must be executed.
-  auto &&ElseGen = [OffloadError](CodeGenFunction &CGF, PrePostActionTy &) {
-CGF.EmitStoreOfScalar(llvm::ConstantInt::get(CGF.Int32Ty, /*V=*/-1u),
-  OffloadError);
+  auto &&ElseGen = [this, &D, OutlinedFn, &KernelArgs](CodeGenFunction &CGF,
+  PrePostActionTy &) {
+emitOutlinedFunctionCall(CGF, D.getLocStart(), OutlinedFn,
+ KernelArgs);
   };
 
   // If we have a target function ID it means that we need to support
@@ -7058,19 +7060,6 @@ void CGOpenMPRuntime::emitTargetCall(Cod
 RegionCodeGenTy ElseRCG(ElseGen);
 ElseRCG(CGF);
   }
-
-  // Check the error code and execute the host version if required.
-  auto OffloadFailedBlock = CGF.createBasicBlock("omp_offload.failed");
-  auto OffloadContBlock = CGF.createBasicBlock("omp_offload.cont");
-  auto OffloadErrorVal = CGF.EmitLoadOfScalar(OffloadError, SourceLocation());
-  auto Failed = CGF.Builder.CreateIsNotNull(OffloadErrorVal);
-  CGF.Builder.CreateCondBr(Failed, OffloadFailedBlock, OffloadContBlock);
-
-  CGF.EmitBlock(OffloadFailedBlock);
-  emitOutlinedFunctionCall(CGF, D.getLocStart(), OutlinedFn, KernelArgs);
-  CGF.EmitBranch(OffloadContBlock);
-
-  CGF.EmitBlock(OffloadContBlock, /*IsFinished=*/true);
 }
 
 void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,

Modified: cfe/trunk/test/OpenMP/target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-projec

r314673 - [OPENMP] Fix test, NFC.

2017-10-02 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Oct  2 07:35:31 2017
New Revision: 314673

URL: http://llvm.org/viewvc/llvm-project?rev=314673&view=rev
Log:
[OPENMP] Fix test, NFC.

Modified:
cfe/trunk/test/OpenMP/target_codegen.cpp

Modified: cfe/trunk/test/OpenMP/target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_codegen.cpp?rev=314673&r1=314672&r2=314673&view=diff
==
--- cfe/trunk/test/OpenMP/target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_codegen.cpp Mon Oct  2 07:35:31 2017
@@ -183,7 +183,7 @@ int foo(int n) {
   // CHECK:   [[CNSIZE:%.+]] = mul nuw i[[SZ]] [[CNELEMSIZE2]], 8
 
   // CHECK:   [[IF:%.+]] = icmp sgt i32 {{[^,]+}}, 20
-  // CHECK:   br i1 [[IF]], label %[[TRY:[^,]+]], label %[[FAIL:[^,]+]]
+  // CHECK:   br i1 [[IF]], label %[[TRY:[^,]+]], label %[[IFELSE:[^,]+]]
   // CHECK:   [[TRY]]
   // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target(i32 -1, i8* @{{[^,]+}}, 
i32 9, i8** [[BPR:%[^,]+]], i8** [[PR:%[^,]+]], i[[SZ]]* [[SR:%[^,]+]], i32* 
getelementptr inbounds ([9 x i32], [9 x i32]* [[MAPT4]], i32 0, i32 0))
   // CHECK-DAG:   [[BPR]] = getelementptr inbounds [9 x i8*], [9 x i8*]* 
[[BP:%[^,]+]], i32 0, i32 0
@@ -459,7 +459,7 @@ int bar(int n){
 // CHECK:   [[CSIZE:%.+]] = mul nuw i[[SZ]] [[CELEMSIZE2]], 2
 
 // CHECK:   [[IF:%.+]] = icmp sgt i32 {{[^,]+}}, 60
-// CHECK:   br i1 [[IF]], label %[[TRY:[^,]+]], label %[[FAIL:[^,]+]]
+// CHECK:   br i1 [[IF]], label %[[TRY:[^,]+]], label %[[IFELSE:[^,]+]]
 // CHECK:   [[TRY]]
 // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target(i32 -1, i8* @{{[^,]+}}, 
i32 5, i8** [[BPR:%[^,]+]], i8** [[PR:%[^,]+]], i[[SZ]]* [[SR:%[^,]+]], i32* 
getelementptr inbounds ([5 x i32], [5 x i32]* [[MAPT7]], i32 0, i32 0))
 // CHECK-DAG:   [[BPR]] = getelementptr inbounds [5 x i8*], [5 x i8*]* 
[[BP:%.+]], i32 0, i32 0


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r314686 - [OPENMP] Capture argument of `device` clause for target-based

2017-10-02 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Oct  2 09:32:39 2017
New Revision: 314686

URL: http://llvm.org/viewvc/llvm-project?rev=314686&view=rev
Log:
[OPENMP] Capture argument of `device` clause for target-based
directives.

The argument of the `device` clause in target-based executable
directives must be captured to support codegen for the `target`
directives with the `depend` clauses.

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/target_codegen.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=314686&r1=314685&r2=314686&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Oct  2 09:32:39 2017
@@ -3141,7 +3141,7 @@ public:
 /// In this example directive '#pragma omp target' has clause 'device'
 /// with single expression 'a'.
 ///
-class OMPDeviceClause : public OMPClause {
+class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// \brief Location of '('.
   SourceLocation LParenLoc;
@@ -3161,16 +3161,19 @@ public:
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPDeviceClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, 
-  SourceLocation EndLoc)
-  : OMPClause(OMPC_device, StartLoc, EndLoc), LParenLoc(LParenLoc), 
-Device(E) {}
+  OMPDeviceClause(Expr *E, Stmt *HelperE, SourceLocation StartLoc,
+  SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
+LParenLoc(LParenLoc), Device(E) {
+setPreInitStmt(HelperE);
+  }
 
   /// \brief Build an empty clause.
   ///
   OMPDeviceClause()
-  : OMPClause(OMPC_device, SourceLocation(), SourceLocation()), 
-LParenLoc(SourceLocation()), Device(nullptr) {}
+  : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
+OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
+Device(nullptr) {}
   /// \brief Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   /// \brief Returns the location of '('.

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=314686&r1=314685&r2=314686&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Oct  2 09:32:39 2017
@@ -3109,6 +3109,7 @@ bool RecursiveASTVisitor::Visit
 
 template 
 bool RecursiveASTVisitor::VisitOMPDeviceClause(OMPDeviceClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
   TRY_TO(TraverseStmt(C->getDevice()));
   return true;
 }

Modified: cfe/trunk/lib/AST/OpenMPClause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OpenMPClause.cpp?rev=314686&r1=314685&r2=314686&view=diff
==
--- cfe/trunk/lib/AST/OpenMPClause.cpp (original)
+++ cfe/trunk/lib/AST/OpenMPClause.cpp Mon Oct  2 09:32:39 2017
@@ -60,6 +60,8 @@ const OMPClauseWithPreInit *OMPClauseWit
 return static_cast(C);
   case OMPC_thread_limit:
 return static_cast(C);
+  case OMPC_device:
+return static_cast(C);
   case OMPC_default:
   case OMPC_proc_bind:
   case OMPC_final:
@@ -83,7 +85,6 @@ const OMPClauseWithPreInit *OMPClauseWit
   case OMPC_capture:
   case OMPC_seq_cst:
   case OMPC_depend:
-  case OMPC_device:
   case OMPC_threads:
   case OMPC_simd:
   case OMPC_map:

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=314686&r1=314685&r2=314686&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Mon Oct  2 09:32:39 2017
@@ -2091,6 +2091,7 @@ void CodeGenFunction::EmitOMPTeamsDistri
 
 void CodeGenFunction::EmitOMPTargetTeamsDistributeDirective(
 const OMPTargetTeamsDistributeDirective &S) {
+  OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
   CGM.getOpenMPRuntime().emitInlinedDirective(
   *this, OMPD_target_teams_distribute,
   [&S](CodeGenFunction &CGF, PrePostActionTy &) {
@@ -2101,6 +2102,7 @@ void CodeGenFunction::EmitOMPTargetTeams
 
 void CodeGenFunction::EmitOMPTargetTeamsDistributeParallelForDirective

Re: r270962 - [OPENMP] Fixed processing of '-fopenmp-version=' option and test.

2017-10-02 Thread Alexey Bataev via cfe-commits
Hi Hal,
As soon as we get the support for 4.5, including offloading. Otherwise there 
always are going to be some people blaming the compiler for not supporting 4.5 
in full. Will try to support it ASAP.
Meanwhile, you can use -fopenmp-version=45 option to force to 4.5

Best regards,
Alexey Bataev

2 окт. 2017 г., в 19:53, Hal Finkel mailto:hfin...@anl.gov>> 
написал(а):

Hi, Alexey,

At what point can we switch, by default, to reporting a version for _OPENMP 
corresponding to 4.x? We're missing out on some OpenMP simd directives because 
the source code guards them with '#if _OPENMP >= 201307' or similar.

Thanks again,
Hal

On 05/26/2016 11:13 PM, Alexey Bataev via cfe-commits wrote:
Author: abataev
Date: Thu May 26 23:13:39 2016
New Revision: 270962

URL: http://llvm.org/viewvc/llvm-project?rev=270962&view=rev
Log:
[OPENMP] Fixed processing of '-fopenmp-version=' option and test.

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/OpenMP/driver.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=270962&r1=270961&r2=270962&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu May 26 23:13:39 2016
@@ -4864,7 +4864,6 @@ void Clang::ConstructJob(Compilation &C,
   // Forward flags for OpenMP
   if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
options::OPT_fno_openmp, false)) {
-Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
 switch (getOpenMPRuntime(getToolChain(), Args)) {
 case OMPRT_OMP:
 case OMPRT_IOMP5:
@@ -4877,6 +4876,7 @@ void Clang::ConstructJob(Compilation &C,
   if (!Args.hasFlag(options::OPT_fopenmp_use_tls,
 options::OPT_fnoopenmp_use_tls, /*Default=*/true))
 CmdArgs.push_back("-fnoopenmp-use-tls");
+  Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
   break;
 default:
   // By default, if Clang doesn't know how to generate useful OpenMP code

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=270962&r1=270961&r2=270962&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu May 26 23:13:39 2016
@@ -1954,15 +1954,16 @@ static void ParseLangArgs(LangOptions &O
   }
 // Check if -fopenmp is specified.
-  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp);
+  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 1 : 0;
   Opts.OpenMPUseTLS =
   Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
 if (Opts.OpenMP) {
-if (int Version = getLastArgIntValue(Args, OPT_fopenmp_version_EQ,
- Opts.OpenMP, Diags))
+int Version =
+getLastArgIntValue(Args, OPT_fopenmp_version_EQ, Opts.OpenMP, Diags);
+if (Version != 0)
   Opts.OpenMP = Version;
 // Provide diagnostic when a given target is not expected to be an OpenMP
 // device or host.

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=270962&r1=270961&r2=270962&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu May 26 23:13:39 2016
@@ -922,24 +922,24 @@ static void InitializePredefinedMacros(c
   }
 // OpenMP definition
-  if (LangOpts.OpenMP) {
-// OpenMP 2.2:
-//   In implementations that support a preprocessor, the _OPENMP
-//   macro name is defined to have the decimal value mm where
-//    and mm are the year and the month designations of the
-//   version of the OpenMP API that the implementation support.
-switch (LangOpts.OpenMP) {
-case 40:
-  Builder.defineMacro("_OPENMP", "201307");
-  break;
-case 45:
-  Builder.defineMacro("_OPENMP", "201511");
-  break;
-default:
-  // Default version is OpenMP 3.1
-  Builder.defineMacro("_OPENMP", "201107");
-  break;
-}
+  // OpenMP 2.2:
+  //   In implementations that support a preprocessor, the _OPENMP
+  //   macro name is defined to have the decimal value mm where
+  //    and mm are the year and the month designations of the
+  //   version of the O

Re: r270962 - [OPENMP] Fixed processing of '-fopenmp-version=' option and test.

2017-10-02 Thread Alexey Bataev via cfe-commits
No, there is no such page. We parse everything from 4.5, but have very limited 
support in codegen for target-specific directives, especially combined one. 
Moreover, some of them are not implemented at all and we may produce incorrect 
code. I can try to revisit these "badly" supported constructs and provide some 
basic codegen to produce working code at least, though without actual 
offloading. But not sure that I will be able to do it quickly.

Best regards,
Alexey Bataev

2 окт. 2017 г., в 20:22, Hal Finkel mailto:hfin...@anl.gov>> 
написал(а):



On 10/02/2017 07:08 PM, Alexey Bataev wrote:
Hi Hal,
As soon as we get the support for 4.5, including offloading. Otherwise there 
always are going to be some people blaming the compiler for not supporting 4.5 
in full. Will try to support it ASAP.
Meanwhile, you can use -fopenmp-version=45 option to force to 4.5

Thanks!

Do we have a status page anywhere that shows where we stand on the various 
features? Are there still features that we don't parse, or where we don't 
generate something that conservatively correct (e.g., as with "declare simd")?

 -Hal


Best regards,
Alexey Bataev

2 окт. 2017 г., в 19:53, Hal Finkel mailto:hfin...@anl.gov>> 
написал(а):

Hi, Alexey,

At what point can we switch, by default, to reporting a version for _OPENMP 
corresponding to 4.x? We're missing out on some OpenMP simd directives because 
the source code guards them with '#if _OPENMP >= 201307' or similar.

Thanks again,
Hal

On 05/26/2016 11:13 PM, Alexey Bataev via cfe-commits wrote:
Author: abataev
Date: Thu May 26 23:13:39 2016
New Revision: 270962

URL: http://llvm.org/viewvc/llvm-project?rev=270962&view=rev
Log:
[OPENMP] Fixed processing of '-fopenmp-version=' option and test.

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/OpenMP/driver.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=270962&r1=270961&r2=270962&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu May 26 23:13:39 2016
@@ -4864,7 +4864,6 @@ void Clang::ConstructJob(Compilation &C,
   // Forward flags for OpenMP
   if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
options::OPT_fno_openmp, false)) {
-Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
 switch (getOpenMPRuntime(getToolChain(), Args)) {
 case OMPRT_OMP:
 case OMPRT_IOMP5:
@@ -4877,6 +4876,7 @@ void Clang::ConstructJob(Compilation &C,
   if (!Args.hasFlag(options::OPT_fopenmp_use_tls,
 options::OPT_fnoopenmp_use_tls, /*Default=*/true))
 CmdArgs.push_back("-fnoopenmp-use-tls");
+  Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
   break;
 default:
   // By default, if Clang doesn't know how to generate useful OpenMP code

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=270962&r1=270961&r2=270962&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu May 26 23:13:39 2016
@@ -1954,15 +1954,16 @@ static void ParseLangArgs(LangOptions &O
   }
 // Check if -fopenmp is specified.
-  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp);
+  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 1 : 0;
   Opts.OpenMPUseTLS =
   Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
 if (Opts.OpenMP) {
-if (int Version = getLastArgIntValue(Args, OPT_fopenmp_version_EQ,
- Opts.OpenMP, Diags))
+int Version =
+getLastArgIntValue(Args, OPT_fopenmp_version_EQ, Opts.OpenMP, Diags);
+if (Version != 0)
   Opts.OpenMP = Version;
 // Provide diagnostic when a given target is not expected to be an OpenMP
 // device or host.

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=270962&r1=270961&r2=270962&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu May 26 23:13:39 2016
@@ -922,24 +922,24 @@ static void InitializePredefinedMacros(c
   }
 // OpenMP definition
-  if (LangOpts.OpenMP) {
-// OpenMP 2.2:
-//   In implementations t

r314833 - [OPENMP] Allow use of declare target directive inside struct

2017-10-03 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct  3 13:00:00 2017
New Revision: 314833

URL: http://llvm.org/viewvc/llvm-project?rev=314833&view=rev
Log:
[OPENMP] Allow use of declare target directive inside struct
declaration.

Patch allows using of the `#pragma omp declare target`| `#pragma omp end
declare target` directives inside the structures if we need to mark as
declare target only some static members.

Modified:
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp
cfe/trunk/test/OpenMP/declare_target_messages.cpp

Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=314833&r1=314832&r2=314833&view=diff
==
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Tue Oct  3 13:00:00 2017
@@ -760,9 +760,17 @@ Parser::DeclGroupPtrTy Parser::ParseOpen
 DKind = ParseOpenMPDirectiveKind(*this);
 while (DKind != OMPD_end_declare_target && DKind != OMPD_declare_target &&
Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) {
-  ParsedAttributesWithRange attrs(AttrFactory);
-  MaybeParseCXX11Attributes(attrs);
-  ParseExternalDeclaration(attrs);
+  DeclGroupPtrTy Ptr;
+  // Here we expect to see some function declaration.
+  if (AS == AS_none) {
+assert(TagType == DeclSpec::TST_unspecified);
+MaybeParseCXX11Attributes(Attrs);
+ParsingDeclSpec PDS(*this);
+Ptr = ParseExternalDeclaration(Attrs, &PDS);
+  } else {
+Ptr =
+ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
+  }
   if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) {
 TentativeParsingAction TPA(*this);
 ConsumeAnnotationToken();

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=314833&r1=314832&r2=314833&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Oct  3 13:00:00 2017
@@ -11914,7 +11914,11 @@ bool Sema::ActOnStartOpenMPDeclareTarget
   DeclContext *CurLexicalContext = getCurLexicalContext();
   if (!CurLexicalContext->isFileContext() &&
   !CurLexicalContext->isExternCContext() &&
-  !CurLexicalContext->isExternCXXContext()) {
+  !CurLexicalContext->isExternCXXContext() &&
+  !isa(CurLexicalContext) &&
+  !isa(CurLexicalContext) &&
+  !isa(CurLexicalContext) &&
+  !isa(CurLexicalContext)) {
 Diag(Loc, diag::err_omp_region_not_file_context);
 return false;
   }

Modified: cfe/trunk/test/OpenMP/declare_target_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_ast_print.cpp?rev=314833&r1=314832&r2=314833&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_ast_print.cpp Tue Oct  3 13:00:00 2017
@@ -124,6 +124,33 @@ void f3() {
 // CHECK: void f3()
 // CHECK: #pragma omp end declare target
 
+struct SSSt {
+#pragma omp declare target
+  static int a;
+  int b;
+#pragma omp end declare target
+};
+
+// CHECK: struct SSSt {
+// CHECK: #pragma omp declare target
+// CHECK: static int a;
+// CHECK: #pragma omp end declare target
+// CHECK: int b;
+
+template 
+struct SSSTt {
+#pragma omp declare target
+  static T a;
+  int b;
+#pragma omp end declare target
+};
+
+// CHECK: template  struct SSSTt {
+// CHECK: #pragma omp declare target
+// CHECK: static T a;
+// CHECK: #pragma omp end declare target
+// CHECK: int b;
+
 int main (int argc, char **argv) {
   foo();
   foo_c();

Modified: cfe/trunk/test/OpenMP/declare_target_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_messages.cpp?rev=314833&r1=314832&r2=314833&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_messages.cpp Tue Oct  3 13:00:00 2017
@@ -73,9 +73,9 @@ int C::method() {
 }
 
 struct S {
-#pragma omp declare target // expected-error {{directive must be at file or 
namespace scope}}
+#pragma omp declare target
   int v;
-#pragma omp end declare target // expected-error {{unexpected OpenMP directive 
'#pragma omp end declare target'}}
+#pragma omp end declare target
 };
 
 int main (int argc, char **argv) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r314995 - [OPENMP] Fix mapping|privatization of implicitly captured variables.

2017-10-05 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Oct  5 10:51:39 2017
New Revision: 314995

URL: http://llvm.org/viewvc/llvm-project?rev=314995&view=rev
Log:
[OPENMP] Fix mapping|privatization of implicitly captured variables.

If the `defaultmap(tofrom:scalar)` clause is specified, the scalars must
be mapped with 'tofrom' modifiers, otherwise they must be captured as
firstprivates.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_map_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_firstprivate_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=314995&r1=314994&r2=314995&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Oct  5 10:51:39 2017
@@ -45,7 +45,13 @@ namespace {
 enum DefaultDataSharingAttributes {
   DSA_unspecified = 0, /// \brief Data sharing attribute not specified.
   DSA_none = 1 << 0,   /// \brief Default data sharing attribute 'none'.
-  DSA_shared = 1 << 1  /// \brief Default data sharing attribute 'shared'.
+  DSA_shared = 1 << 1, /// \brief Default data sharing attribute 'shared'.
+};
+
+/// Attributes of the defaultmap clause.
+enum DefaultMapAttributes {
+  DMA_unspecified,   /// Default mapping is not specified.
+  DMA_tofrom_scalar, /// Default mapping is 'tofrom:scalar'.
 };
 
 /// \brief Stack for tracking declarations used in OpenMP directives and
@@ -115,6 +121,8 @@ private:
 LoopControlVariablesMapTy LCVMap;
 DefaultDataSharingAttributes DefaultAttr = DSA_unspecified;
 SourceLocation DefaultAttrLoc;
+DefaultMapAttributes DefaultMapAttr = DMA_unspecified;
+SourceLocation DefaultMapAttrLoc;
 OpenMPDirectiveKind Directive = OMPD_unknown;
 DeclarationNameInfo DirectiveName;
 Scope *CurScope = nullptr;
@@ -341,6 +349,12 @@ public:
 Stack.back().first.back().DefaultAttr = DSA_shared;
 Stack.back().first.back().DefaultAttrLoc = Loc;
   }
+  /// Set default data mapping attribute to 'tofrom:scalar'.
+  void setDefaultDMAToFromScalar(SourceLocation Loc) {
+assert(!isStackEmpty());
+Stack.back().first.back().DefaultMapAttr = DMA_tofrom_scalar;
+Stack.back().first.back().DefaultMapAttrLoc = Loc;
+  }
 
   DefaultDataSharingAttributes getDefaultDSA() const {
 return isStackEmpty() ? DSA_unspecified
@@ -350,6 +364,17 @@ public:
 return isStackEmpty() ? SourceLocation()
   : Stack.back().first.back().DefaultAttrLoc;
   }
+  DefaultMapAttributes getDefaultDMA() const {
+return isStackEmpty() ? DMA_unspecified
+  : Stack.back().first.back().DefaultMapAttr;
+  }
+  DefaultMapAttributes getDefaultDMAAtLevel(unsigned Level) const {
+return Stack.back().first[Level].DefaultMapAttr;
+  }
+  SourceLocation getDefaultDMALocation() const {
+return isStackEmpty() ? SourceLocation()
+  : Stack.back().first.back().DefaultMapAttrLoc;
+  }
 
   /// \brief Checks if the specified variable is a threadprivate.
   bool isThreadPrivate(VarDecl *D) {
@@ -1242,7 +1267,8 @@ bool Sema::IsOpenMPCapturedByRef(ValueDe
   IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection);
 } else {
   // By default, all the data that has a scalar type is mapped by copy.
-  IsByRef = !Ty->isScalarType();
+  IsByRef = !Ty->isScalarType() ||
+DSAStack->getDefaultDMAAtLevel(Level) == DMA_tofrom_scalar;
 }
   }
 
@@ -1804,7 +1830,7 @@ public:
 if (auto *VD = dyn_cast(E->getDecl())) {
   VD = VD->getCanonicalDecl();
   // Skip internally declared variables.
-  if (VD->isLocalVarDecl() && !CS->capturesVariable(VD))
+  if (VD->hasLocalStorage() && !CS->capturesVariable(VD))
 return;
 
   auto DVar = Stack->getTopDSA(VD, false);
@@ -1848,20 +1874,16 @@ public:
MC.getAssociatedExpression()));
  });
 })) {
-  bool CapturedByCopy = false;
+  bool IsFirstprivate = false;
   // By default lambdas are captured as firstprivates.
   if (const auto *RD =
   VD->getType().getNonReferenceType()->getAsCXXRecordDecl())
-if (RD->isLambda())
-  CapturedByCopy = true;
-  CapturedByCopy =
-  CapturedByCopy ||
-  llvm::any_of(
-  CS->captures(), [VD](const CapturedStmt::Capture &I) {
-return I.capturesVariableByCopy() &&
-   I.getCapturedVar()->getCanonicalDecl() == VD;
-  });
-  if (CapturedByCopy)
+IsFirstprivate = RD->isLambda();
+  IsFirstprivate =
+  IsFirstprivate ||
+  (VD->getType().getNonReferenceType()->isScalarType() &&
+   Stack->getDefaultDMA() != DMA_tofrom_scalar)

r315074 - [OPENMP] Capture references to global variables.

2017-10-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Oct  6 09:17:25 2017
New Revision: 315074

URL: http://llvm.org/viewvc/llvm-project?rev=315074&view=rev
Log:
[OPENMP] Capture references to global variables.

In C++11 variable to global variables are considered as constant
expressions and these variables are not captured in the outlined
regions. Patch allows capturing of such variables in the OpenMP regions.

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/OpenMP/for_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/for_lastprivate_codegen.cpp
cfe/trunk/test/OpenMP/for_private_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_private_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=315074&r1=315073&r2=315074&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Oct  6 09:17:25 2017
@@ -2297,8 +2297,12 @@ LValue CodeGenFunction::EmitDeclRefLValu
 VD->isUsableInConstantExpressions(getContext()) &&
 VD->checkInitIsICE() &&
 // Do not emit if it is private OpenMP variable.
-!(E->refersToEnclosingVariableOrCapture() && CapturedStmtInfo &&
-  LocalDeclMap.count(VD))) {
+!(E->refersToEnclosingVariableOrCapture() &&
+  ((CapturedStmtInfo &&
+(LocalDeclMap.count(VD->getCanonicalDecl()) ||
+ CapturedStmtInfo->lookup(VD->getCanonicalDecl( ||
+   LambdaCaptureFields.lookup(VD->getCanonicalDecl()) ||
+   isa(CurCodeDecl {
   llvm::Constant *Val =
 ConstantEmitter(*this).emitAbstract(E->getLocation(),
 *VD->evaluateValue(),

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=315074&r1=315073&r2=315074&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Oct  6 09:17:25 2017
@@ -14893,7 +14893,8 @@ static void DoMarkVarDeclReferenced(Sema
   IsVariableAConstantExpression(Var, SemaRef.Context)) {
 // A reference initialized by a constant expression can never be
 // odr-used, so simply ignore it.
-if (!Var->getType()->isReferenceType())
+if (!Var->getType()->isReferenceType() ||
+(SemaRef.LangOpts.OpenMP && SemaRef.IsOpenMPCapturedDecl(Var)))
   SemaRef.MaybeODRUseExprs.insert(E);
   } else if (OdrUseContext) {
 MarkVarDeclODRUsed(Var, Loc, SemaRef,

Modified: cfe/trunk/test/OpenMP/for_firstprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_firstprivate_codegen.cpp?rev=315074&r1=315073&r2=315074&view=diff
==
--- cfe/trunk/test/OpenMP/for_firstprivate_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_firstprivate_codegen.cpp Fri Oct  6 09:17:25 2017
@@ -83,6 +83,7 @@ int main() {
 // LAMBDA: alloca i{{[0-9]+}},
 // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
 // LAMBDA: [[G1_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
+// LAMBDA: [[G1_PRIVATE_REF:%.+]] = alloca i{{[0-9]+}}*,
 // LAMBDA: [[SIVAR2_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
 
 // LAMBDA:  store i{{[0-9]+}}* [[SIVAR_REF]], i{{[0-9]+}}** %{{.+}},
@@ -91,20 +92,26 @@ int main() {
 
 // LAMBDA: [[G_VAL:%.+]] = load volatile i{{[0-9]+}}, i{{[0-9]+}}* [[G]]
 // LAMBDA: store i{{[0-9]+}} [[G_VAL]], i{{[0-9]+}}* [[G_PRIVATE_ADDR]]
+// LAMBDA: store i{{[0-9]+}}* [[G1_PRIVATE_ADDR]], i{{[0-9]+}}** 
[[G1_PRIVATE_REF]],
 // LAMBDA: [[SIVAR2_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* 
[[SIVAR2_PRIVATE_ADDR_REF]]
 // LAMBDA: store i{{[0-9]+}} [[SIVAR2_VAL]], i{{[0-9]+}}* 
[[SIVAR2_PRIVATE_ADDR]]
 
 // LAMBDA-NOT: call void @__kmpc_barrier(
 g = 1;
-g1 = 1;
-sivar = 2;
+g1 = 2;
+sivar = 3;
 // LAMBDA: call void @__kmpc_for_static_init_4(
 
 // LAMBDA: store i{{[0-9]+}} 1, i{{[0-9]+}}* [[G_PRIVATE_ADDR]],
-// LAMBDA: store i{{[0-9]+}} 2, i{{[0-9]+}}* [[SIVAR2_PRIVATE_ADDR]],
+// LAMBDA: [[G1_PRIVATE_ADDR:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** 
[[G1_PRIVATE_REF]],
+// LAMBDA: store volatile i{{[0-9]+}} 2, i{{[0-9]+}}* [[G1_PRIVATE_ADDR]],
+// LAMBDA: store i{{[0-9]+}} 3, i{{[0-9]+}}* [[SIVAR2_PRIVATE_ADDR]],
 // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, 
%{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
 // LAMBDA: store i{{[0-9]+}}* [[G_PRIVATE_ADDR]], i{{[0-9]+}}** 
[[G_PRIVATE_ADDR_REF]]
-// LAMBDA: [[SIVAR_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds 
%{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
+// LAMBDA: [[

r315076 - [OPENMP] Do not capture local static variables.

2017-10-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Oct  6 10:00:28 2017
New Revision: 315076

URL: http://llvm.org/viewvc/llvm-project?rev=315076&view=rev
Log:
[OPENMP] Do not capture local static variables.

Previously we may erroneously try to capture locally declared static
variables, which will lead to crash for target-based constructs.
Patch fixes this problem.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=315076&r1=315075&r2=315076&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Oct  6 10:00:28 2017
@@ -1838,6 +1838,10 @@ public:
   if (DVar.RefExpr || !ImplicitDeclarations.insert(VD).second)
 return;
 
+  // Skip internally declared static variables.
+  if (VD->hasGlobalStorage() && !CS->capturesVariable(VD))
+return;
+
   auto ELoc = E->getExprLoc();
   auto DKind = Stack->getCurrentDirective();
   // The default(none) clause requires that each variable that is 
referenced

Modified: cfe/trunk/test/OpenMP/target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_codegen.cpp?rev=315076&r1=315075&r2=315076&view=diff
==
--- cfe/trunk/test/OpenMP/target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_codegen.cpp Fri Oct  6 10:00:28 2017
@@ -34,7 +34,9 @@
 // code, only 6 will have mapped arguments, and only 4 have all-constant map
 // sizes.
 
-// CHECK-DAG: [[SIZET2:@.+]] = private unnamed_addr constant [1 x i{{32|64}}] 
[i[[SZ:32|64]] 2]
+// CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [2 x i[[SZ]]] 
[i[[SZ]] 0, i[[SZ]] 4]
+// CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [2 x i32] [i32 32, 
i32 288]
+// CHECK-DAG: [[SIZET2:@.+]] = private unnamed_addr constant [1 x i{{32|64}}] 
[i[[SZ]] 2]
 // CHECK-DAG: [[MAPT2:@.+]] = private unnamed_addr constant [1 x i32] [i32 288]
 // CHECK-DAG: [[SIZET3:@.+]] = private unnamed_addr constant [2 x i[[SZ]]] 
[i[[SZ]] 4, i[[SZ]] 2]
 // CHECK-DAG: [[MAPT3:@.+]] = private unnamed_addr constant [2 x i32] [i32 
288, i32 288]
@@ -59,6 +61,7 @@
 // TCHECK: @{{.+}} = constant [[ENTTY]]
 // TCHECK: @{{.+}} = constant [[ENTTY]]
 // TCHECK: @{{.+}} = constant [[ENTTY]]
+// TCHECK: @{{.+}} = {{.*}}constant [[ENTTY]]
 // TCHECK-NOT: @{{.+}} = constant [[ENTTY]]
 
 // Check if offloading descriptor is created.
@@ -91,6 +94,7 @@ int foo(int n) {
   double c[5][10];
   double cn[5][n];
   TT d;
+  static long *plocal;
 
   // CHECK:   [[ADD:%.+]] = add nsw i32
   // CHECK:   store i32 [[ADD]], i32* [[CAPTURE:%.+]],
@@ -106,6 +110,39 @@ int foo(int n) {
   {
   }
 
+  // CHECK:   [[ADD:%.+]] = add nsw i32
+  // CHECK:   store i32 [[ADD]], i32* [[CAPTURE:%.+]],
+  // CHECK-DAG:   [[LD:%.+]] = load i32, i32* [[CAPTURE]],
+  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target(i32 [[LD]], i8* 
@{{[^,]+}}, i32 2, i8** [[BPR:%[^,]+]], i8** [[PR:%[^,]+]], i[[SZ]]* 
getelementptr inbounds ([2 x i[[SZ]]], [2 x i[[SZ]]]* [[SIZET]], i32 0, i32 0), 
i32* getelementptr inbounds ([2 x i32], [2 x i32]* [[MAPT]], i32 0, i32 0)
+  // CHECK-DAG:   [[BPR]] = getelementptr inbounds [2 x i8*], [2 x i8*]* 
[[BP:%[^,]+]], i32 0, i32 0
+  // CHECK-DAG:   [[PR]] = getelementptr inbounds [2 x i8*], [2 x i8*]* 
[[P:%[^,]+]], i32 0, i32 0
+
+  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x 
i8*]* [[BP]], i32 0, i32 0
+  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x 
i8*]* [[P]], i32 0, i32 0
+  // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]**
+  // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]**
+  // CHECK-DAG:   store i[[SZ]]* [[BP0:%[^,]+]], i[[SZ]]** [[CBPADDR0]]
+  // CHECK-DAG:   store i[[SZ]]* [[BP0]], i[[SZ]]** [[CPADDR0]]
+
+  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x 
i8*]* [[BP]], i32 0, i32 1
+  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x 
i8*]* [[P]], i32 0, i32 1
+  // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
+  // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
+  // CHECK-DAG:   store i[[SZ]] [[BP1:%[^,]+]], i[[SZ]]* [[CBPADDR1]]
+  // CHECK-DAG:   store i[[SZ]] [[BP1]], i[[SZ]]* [[CPADDR1]]
+  // CHECK:   [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
+  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
+  // CHECK:   [[FAIL]]
+  // CHECK:   call void [[HVT0_:@.+]](i[[SZ]]* [[BP0]], i[[SZ]] [[BP1]])
+  // CHECK-NEXT:  br label %[[END]]
+  // CHECK:   [[END]]
+  #pragma omp target device(global + a)
+  {
+static int local1;
+*plocal = global;
+local1 = global;
+  }
+
   // CHECK:  

r315315 - [OPENMP] Add default codegen|tests for 'target parallel for[ simd]'

2017-10-10 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct 10 07:14:43 2017
New Revision: 315315

URL: http://llvm.org/viewvc/llvm-project?rev=315315&view=rev
Log:
[OPENMP] Add default codegen|tests for 'target parallel for[ simd]'
constructs.

Added default codegen for 'target parallel for' construct + tests for
default codegen of 'target parallel for[ simd]' constructs.

Added:
cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=315315&r1=315314&r2=315315&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Oct 10 07:14:43 2017
@@ -4126,7 +4126,14 @@ void CodeGenFunction::EmitOMPTargetParal
 
 void CodeGenFunction::EmitOMPTargetParallelForDirective(
 const OMPTargetParallelForDirective &S) {
-  // TODO: codegen for target parallel for.
+  OMPLexicalScope Scope(*this, S, /*AsInlined=*/true);
+  CGM.getOpenMPRuntime().emitInlinedDirective(
+  *this, OMPD_target_parallel_for,
+  [&S](CodeGenFunction &CGF, PrePostActionTy &) {
+OMPLoopScope PreInitScope(CGF, S);
+CGF.EmitStmt(
+cast(S.getAssociatedStmt())->getCapturedStmt());
+  });
 }
 
 /// Emit a helper variable and return corresponding lvalue.

Added: cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp?rev=315315&view=auto
==
--- cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp (added)
+++ cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp Tue Oct 10 07:14:43 
2017
@@ -0,0 +1,232 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck %s --check-prefix=TERM_DEBUG
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+long long get_val() { return 0; }
+double *g_ptr;
+
+// CHECK-LABEL: define {{.*void}} @{{.*}}simple{{.*}}(float* {{.+}}, float* 
{{.+}}, float* {{.+}}, float* {{.+}})
+void simple(float *a, float *b, float *c, float *d) {
+  // CHECK: store i32 3, i32* %
+  // CHECK: icmp slt i32 %{{.+}}, 32
+  // CHECK: fmul float
+  // CHECK: fmul float
+  // CHECK: add nsw i32 %{{.+}}, 5
+  #pragma omp target parallel for device((int)*a)
+  for (int i = 3; i < 32; i += 5) {
+a[i] = b[i] * c[i] * d[i];
+  }
+
+  // CHECK: call i{{.+}} @{{.+}}get_val{{.+}}()
+  // CHECK: store i32 10, i32* %
+  // CHECK: icmp sgt i32 %{{.+}}, 1
+  // CHECK: fadd float %{{.+}}, 1.00e+00
+  // CHECK: add nsw {{.+}} %{{.+}}, 3
+  // CHECK: add nsw i32 %{{.+}}, -1
+  long long k = get_val();
+  #pragma omp target parallel for linear(k : 3) schedule(dynamic)
+  for (int i = 10; i > 1; i--) {
+a[k]++;
+k = k + 3;
+  }
+
+  // CHECK: store i32 12, i32* %
+  // CHECK: store i{{.+}} 2000, i{{.+}}* %
+  // CHECK: icmp uge i{{.+}} %{{.+}}, 600
+  // CHECK: store double 0.00e+00,
+  // CHECK: fadd float %{{.+}}, 1.00e+00
+  // CHECK: sub i{{.+}} %{{.+}}, 400
+  int lin = 12;
+  #pragma omp target parallel for linear(lin : get_val()), linear(g_ptr)
+  for (unsigned long long it = 2000; it >= 600; it-=400) {
+*g_ptr++ = 0.0;
+a[it + lin]++;
+  }
+
+  // CHECK: store i{{.+}} 6, i{{.+}}* %
+  // CHECK: icmp sle i{{.+}} %{{.+}}, 20
+  // CHECK: sub nsw i{{.+}} %{{.+}}, -4
+  #pragma omp target parallel for
+  for (short it = 6; it <= 20; it-=-4) {
+  }
+
+  // CHECK: store i8 122, i8* %
+  // CHECK: icmp sge i32 %{{.+}}, 97
+  // CHECK: add nsw i32 %{{.+}}, -1
+  #pragma omp target parallel for
+  for (unsigned char it = 'z'; it >= 'a'; it+=-1) {
+  }
+
+  // CHECK: store i32 100, i32* %
+  // CHECK: icmp ult i32 %{{.+}}, 10
+  // CHECK: add i32 %{{.+}}, 10
+  #pragma omp target parallel for
+  for (unsigned i=100; i<10; i+=10) {
+  }
+
+  int A;
+  {
+  A = -1;
+  // CHECK: store i{{.+}} -10, i{{.+}}* %
+  // CHECK: icmp slt i{{.+}} %{{.+}}, 10
+  // CHECK: add nsw i{{.+}} %{{.+}}, 3
+  #pragma omp target parallel for lastprivate(A)
+  for (long long i = -10; i < 10; i += 3) {
+A = i;
+  }
+  }
+  int R;
+  {
+  R = -1;
+  // CHECK: store i{{.+}} -10, i{{.+}}* %
+  // CHECK: icmp slt i{{.+}} %{{.+}

r315464 - [OPENMP] Fix PR34916: Crash on mixing taskloop|tasks directives.

2017-10-11 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Oct 11 08:29:40 2017
New Revision: 315464

URL: http://llvm.org/viewvc/llvm-project?rev=315464&view=rev
Log:
[OPENMP] Fix PR34916: Crash on mixing taskloop|tasks directives.

If both taskloop and task directives are used at the same time in one
program, we may ran into the situation when the particular type for task
directive is reused for taskloop directives. Patch fixes this problem.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/test/OpenMP/taskloop_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=315464&r1=315463&r2=315464&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Oct 11 08:29:40 2017
@@ -4268,9 +4268,20 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFun
   // Build type kmp_routine_entry_t (if not built yet).
   emitKmpRoutineEntryT(KmpInt32Ty);
   // Build type kmp_task_t (if not built yet).
-  if (KmpTaskTQTy.isNull()) {
-KmpTaskTQTy = C.getRecordType(createKmpTaskTRecordDecl(
-CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
+  if (isOpenMPTaskLoopDirective(D.getDirectiveKind())) {
+if (SavedKmpTaskloopTQTy.isNull()) {
+  SavedKmpTaskloopTQTy = C.getRecordType(createKmpTaskTRecordDecl(
+  CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
+}
+KmpTaskTQTy = SavedKmpTaskloopTQTy;
+  } else if (D.getDirectiveKind() == OMPD_task) {
+assert(D.getDirectiveKind() == OMPD_task &&
+   "Expected taskloop or task directive");
+if (SavedKmpTaskTQTy.isNull()) {
+  SavedKmpTaskTQTy = C.getRecordType(createKmpTaskTRecordDecl(
+  CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
+}
+KmpTaskTQTy = SavedKmpTaskTQTy;
   }
   auto *KmpTaskTQTyRD = cast(KmpTaskTQTy->getAsTagDecl());
   // Build particular struct kmp_task_t for the given task.

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=315464&r1=315463&r2=315464&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Wed Oct 11 08:29:40 2017
@@ -318,6 +318,10 @@ private:
   ///deconstructors of firstprivate C++ objects */
   /// } kmp_task_t;
   QualType KmpTaskTQTy;
+  /// Saved kmp_task_t for task directive.
+  QualType SavedKmpTaskTQTy;
+  /// Saved kmp_task_t for taskloop-based directive.
+  QualType SavedKmpTaskloopTQTy;
   /// \brief Type typedef struct kmp_depend_info {
   ///kmp_intptr_t   base_addr;
   ///size_t len;

Modified: cfe/trunk/test/OpenMP/taskloop_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_codegen.cpp?rev=315464&r1=315463&r2=315464&view=diff
==
--- cfe/trunk/test/OpenMP/taskloop_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/taskloop_codegen.cpp Wed Oct 11 08:29:40 2017
@@ -8,6 +8,10 @@
 // CHECK-LABEL: @main
 int main(int argc, char **argv) {
 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%ident_t* 
[[DEFLOC:@.+]])
+// CHECK: call i8* @__kmpc_omp_task_alloc(%ident_t* [[DEFLOC]], i32 [[GTID]],
+// CHECK: call i32 @__kmpc_omp_task(%ident_t* [[DEFLOC]], i32 [[GTID]],
+#pragma omp task
+  ;
 // CHECK: call void @__kmpc_taskgroup(%ident_t* [[DEFLOC]], i32 [[GTID]])
 // CHECK: [[TASKV:%.+]] = call i8* @__kmpc_omp_task_alloc(%ident_t* 
[[DEFLOC]], i32 [[GTID]], i32 33, i64 80, i64 1, i32 (i32, i8*)* bitcast (i32 
(i32, [[TDP_TY:%.+]]*)* [[TASK1:@.+]] to i32 (i32, i8*)*))
 // CHECK: [[TASK:%.+]] = bitcast i8* [[TASKV]] to [[TDP_TY]]*


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r315467 - [OPENMP] Remove extra if, NFC.

2017-10-11 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Oct 11 08:56:38 2017
New Revision: 315467

URL: http://llvm.org/viewvc/llvm-project?rev=315467&view=rev
Log:
[OPENMP] Remove extra if, NFC.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=315467&r1=315466&r2=315467&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Oct 11 08:56:38 2017
@@ -4274,7 +4274,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFun
   CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
 }
 KmpTaskTQTy = SavedKmpTaskloopTQTy;
-  } else if (D.getDirectiveKind() == OMPD_task) {
+  } else {
 assert(D.getDirectiveKind() == OMPD_task &&
"Expected taskloop or task directive");
 if (SavedKmpTaskTQTy.isNull()) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r315578 - [OPENMP] Fix PR34925: Fix getting thread_id lvalue for inlined regions

2017-10-12 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Oct 12 06:51:32 2017
New Revision: 315578

URL: http://llvm.org/viewvc/llvm-project?rev=315578&view=rev
Log:
[OPENMP] Fix PR34925: Fix getting thread_id lvalue for inlined regions
in C.

If we try to get the lvalue for thread_id variables in inlined regions,
we did not use the correct version of function. Fixed this bug by adding
overrided version of the function getThreadIDVariableLValue for inlined
regions.

Added:
cfe/trunk/test/OpenMP/task_codegen.c
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=315578&r1=315577&r2=315578&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Oct 12 06:51:32 2017
@@ -265,6 +265,13 @@ public:
 return nullptr;
   }
 
+  /// \brief Get an LValue for the current ThreadID variable.
+  LValue getThreadIDVariableLValue(CodeGenFunction &CGF) override {
+if (OuterRegionInfo)
+  return OuterRegionInfo->getThreadIDVariableLValue(CGF);
+llvm_unreachable("No LValue for inlined OpenMP construct");
+  }
+
   /// \brief Get the name of the capture helper.
   StringRef getHelperName() const override {
 if (auto *OuterRegionInfo = getOldCSI())

Added: cfe/trunk/test/OpenMP/task_codegen.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/task_codegen.c?rev=315578&view=auto
==
--- cfe/trunk/test/OpenMP/task_codegen.c (added)
+++ cfe/trunk/test/OpenMP/task_codegen.c Thu Oct 12 06:51:32 2017
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c 
-emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -emit-pch -o %t 
%s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+void foo();
+
+// CHECK-LABEL: @main
+int main() {
+  // CHECK: call i32 @__kmpc_global_thread_num(
+  // CHECK: call i8* @__kmpc_omp_task_alloc(
+  // CHECK: call i32 @__kmpc_omp_task(
+#pragma omp task
+  {
+#pragma omp taskgroup
+{
+#pragma omp task
+  foo();
+}
+  }
+  // CHECK: ret i32 0
+  return 0;
+}
+// CHECK: call void @__kmpc_taskgroup(
+// CHECK: call i8* @__kmpc_omp_task_alloc(
+// CHECK: call i32 @__kmpc_omp_task(
+// CHECK: call void @__kmpc_end_taskgroup(
+#endif


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r315586 - [OPENMP] Fix PR34926: Fix handling of the array sections passed as

2017-10-12 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Oct 12 08:18:41 2017
New Revision: 315586

URL: http://llvm.org/viewvc/llvm-project?rev=315586&view=rev
Log:
[OPENMP] Fix PR34926: Fix handling of the array sections passed as
function params.

Codegen could crash if the array section base expression is the
function parameter.

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/OpenMP/parallel_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=315586&r1=315585&r2=315586&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Oct 12 08:18:41 2017
@@ -3349,12 +3349,7 @@ static Address emitOMPArraySectionBase(C
 
 LValue CodeGenFunction::EmitOMPArraySectionExpr(const OMPArraySectionExpr *E,
 bool IsLowerBound) {
-  QualType BaseTy;
-  if (auto *ASE =
-  dyn_cast(E->getBase()->IgnoreParenImpCasts()))
-BaseTy = OMPArraySectionExpr::getBaseOriginalType(ASE);
-  else
-BaseTy = E->getBase()->getType();
+  QualType BaseTy = OMPArraySectionExpr::getBaseOriginalType(E->getBase());
   QualType ResultExprTy;
   if (auto *AT = getContext().getAsArrayType(BaseTy))
 ResultExprTy = AT->getElementType();

Modified: cfe/trunk/test/OpenMP/parallel_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_reduction_codegen.cpp?rev=315586&r1=315585&r2=315586&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_reduction_codegen.cpp Thu Oct 12 08:18:41 
2017
@@ -80,6 +80,14 @@ struct SST {
 // CHECK-DAG: [[REDUCTION_LOC:@.+]] = private unnamed_addr constant %{{.+}} { 
i32 0, i32 18, i32 0, i32 0, i8*
 // CHECK-DAG: [[REDUCTION_LOCK:@.+]] = common global [8 x i32] zeroinitializer
 
+//CHECK: foo_array_sect
+//CHECK: call void {{.+}}@__kmpc_fork_call(
+//CHECK: ret void
+void foo_array_sect(short x[1]) {
+#pragma omp parallel reduction(+ : x[:])
+  {}
+}
+
 template 
 T tmain() {
   T t;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r315611 - [OPENMP] Fix PR34927: Emit initializer for reduction array with declare

2017-10-12 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Oct 12 13:03:39 2017
New Revision: 315611

URL: http://llvm.org/viewvc/llvm-project?rev=315611&view=rev
Log:
[OPENMP] Fix PR34927: Emit initializer for reduction array with declare
reduction.

If the reduction is an array or an array section and reduction operation
is declare reduction without initializer, it may lead to crash.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/declare_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=315611&r1=315610&r2=315611&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Oct 12 13:03:39 2017
@@ -786,7 +786,8 @@ static void emitInitWithReductionInitial
 /// \param Init Initial expression of array.
 /// \param SrcAddr Address of the original array.
 static void EmitOMPAggregateInit(CodeGenFunction &CGF, Address DestAddr,
- QualType Type, const Expr *Init,
+ QualType Type, bool EmitDeclareReductionInit,
+ const Expr *Init,
  const OMPDeclareReductionDecl *DRD,
  Address SrcAddr = Address::invalid()) {
   // Perform element-by-element initialization.
@@ -840,7 +841,7 @@ static void EmitOMPAggregateInit(CodeGen
   // Emit copy.
   {
 CodeGenFunction::RunCleanupsScope InitScope(CGF);
-if (DRD && (DRD->getInitializer() || !Init)) {
+if (EmitDeclareReductionInit) {
   emitInitWithReductionInitializer(CGF, DRD, Init, DestElementCurrent,
SrcElementCurrent, ElementTy);
 } else
@@ -887,8 +888,12 @@ void ReductionCodeGen::emitAggregateInit
   // captured region.
   auto *PrivateVD =
   cast(cast(ClausesData[N].Private)->getDecl());
+  bool EmitDeclareReductionInit =
+  DRD && (DRD->getInitializer() || !PrivateVD->hasInit());
   EmitOMPAggregateInit(CGF, PrivateAddr, PrivateVD->getType(),
-   DRD ? ClausesData[N].ReductionOp : PrivateVD->getInit(),
+   EmitDeclareReductionInit,
+   EmitDeclareReductionInit ? ClausesData[N].ReductionOp
+: PrivateVD->getInit(),
DRD, SharedLVal.getAddress());
 }
 

Modified: cfe/trunk/test/OpenMP/declare_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_reduction_codegen.cpp?rev=315611&r1=315610&r2=315611&view=diff
==
--- cfe/trunk/test/OpenMP/declare_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_reduction_codegen.cpp Thu Oct 12 13:03:39 2017
@@ -9,6 +9,26 @@
 // CHECK: [[SSS_INT:.+]] = type { i32 }
 // CHECK-LOAD: [[SSS_INT:.+]] = type { i32 }
 
+// CHECK: add
+void add(short &out, short &in) {}
+
+#pragma omp declare reduction(my_add : short : add(omp_out, omp_in))
+
+// CHECK: define internal void @.
+// CHECK: call void @{{.+}}add{{.+}}(
+// CHECK: ret void
+
+// CHECK: foo_reduction_array
+void foo_reduction_array() {
+  short y[1];
+  // CHECK: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) 
@__kmpc_fork_call(
+#pragma omp parallel for reduction(my_add : y)
+  for (int i = 0; i < 1; i++) {
+  }
+}
+
+// CHECK: define internal void @
+
 #pragma omp declare reduction(+ : int, char : omp_out *= omp_in)
 // CHECK: define internal {{.*}}void @{{[^(]+}}(i32* noalias, i32* noalias)
 // CHECK: [[MUL:%.+]] = mul nsw i32


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316011 - [OPENMP] Fix capturing of boolean variables in debug mode.

2017-10-17 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct 17 09:47:34 2017
New Revision: 316011

URL: http://llvm.org/viewvc/llvm-project?rev=316011&view=rev
Log:
[OPENMP] Fix capturing of boolean variables in debug mode.

If the variables is boolean and we generating inner function with real
types, the codegen may crash because of not loading boolean value from
memory.

Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=316011&r1=316010&r2=316011&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Oct 17 09:47:34 2017
@@ -501,9 +501,10 @@ CodeGenFunction::GenerateOpenMPCapturedS
 llvm::Value *CallArg;
 auto I = LocalAddrs.find(Arg);
 if (I != LocalAddrs.end()) {
-  LValue LV =
-  WrapperCGF.MakeAddrLValue(I->second.second, Arg->getType(),
-AlignmentSource::Decl);
+  LValue LV = WrapperCGF.MakeAddrLValue(
+  I->second.second,
+  I->second.first ? I->second.first->getType() : Arg->getType(),
+  AlignmentSource::Decl);
   CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation());
 } else {
   auto EI = VLASizes.find(Arg);
@@ -516,7 +517,7 @@ CodeGenFunction::GenerateOpenMPCapturedS
 CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation());
   }
 }
-CallArgs.emplace_back(CallArg);
+CallArgs.emplace_back(WrapperCGF.EmitFromMemory(CallArg, Arg->getType()));
   }
   CGM.getOpenMPRuntime().emitOutlinedFunctionCall(WrapperCGF, S.getLocStart(),
   F, CallArgs);

Modified: cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp?rev=316011&r1=316010&r2=316011&view=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp Tue Oct 17 09:47:34 
2017
@@ -11,7 +11,7 @@ int main() {
   int c[10][10][10];
 #pragma omp target parallel firstprivate(a, b) map(tofrom  \
: c) map(tofrom \
-: bb)
+: bb) if (a)
   {
 int &f = c[1][1][1];
 int &g = a;
@@ -54,7 +54,7 @@ int main() {
   return 0;
 }
 
-// CHECK: define internal void @__omp_offloading{{[^(]+}}([10 x [10 x [10 x 
i32]]] addrspace(1)* {{[^,]+}}, i32 {{[^,]+}}, [10 x [10 x i32]]* {{[^,]+}}, i8 
addrspace(1)* noalias{{[^)]+}})
+// CHECK: define internal void @__omp_offloading{{[^(]+}}([10 x [10 x [10 x 
i32]]] addrspace(1)* {{[^,]+}}, i32 {{[^,]+}}, [10 x [10 x i32]]* {{[^,]+}}, i8 
addrspace(1)* noalias{{[^,]+}}, i1 {{[^)]+}})
 // CHECK: addrspacecast [10 x [10 x [10 x i32]]] addrspace(1)* %{{.+}} to [10 
x [10 x [10 x i32]]]*
 // CHECK: call void [[NONDEBUG_WRAPPER:.+]](i32* {{[^,]+}}, i32* {{[^,]+}}, 
[10 x [10 x [10 x i32]]]* {{[^,]+}}, i64 {{[^,]+}}, [10 x [10 x i32]]* 
{{[^,]+}}, i8* {{[^)]+}})
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316488 - [OPENMP] Fix PR35013: Fix passing VLAs captures to outlined functions.

2017-10-24 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct 24 12:52:31 2017
New Revision: 316488

URL: http://llvm.org/viewvc/llvm-project?rev=316488&view=rev
Log:
[OPENMP] Fix PR35013: Fix passing VLAs captures to outlined functions.

Fixed passing of VLAs and variably-modified types to outlined functions.
Synchronized passing with the types codegen.

Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
cfe/trunk/test/OpenMP/parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/vla_crash.c

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=316488&r1=316487&r2=316488&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Oct 24 12:52:31 2017
@@ -254,6 +254,12 @@ static QualType getCanonicalParamType(AS
   }
   if (T->isPointerType())
 return C.getPointerType(getCanonicalParamType(C, T->getPointeeType()));
+  if (auto *A = T->getAsArrayTypeUnsafe()) {
+if (auto *VLA = dyn_cast(A))
+  return getCanonicalParamType(C, VLA->getElementType());
+else if (!A->isVariablyModifiedType())
+  return C.getCanonicalType(T);
+  }
   return C.getCanonicalParamType(T);
 }
 
@@ -327,7 +333,7 @@ static llvm::Function *emitOutlinedFunct
   II = &Ctx.Idents.get("vla");
 }
 if (ArgType->isVariablyModifiedType())
-  ArgType = getCanonicalParamType(Ctx, ArgType.getNonReferenceType());
+  ArgType = getCanonicalParamType(Ctx, ArgType);
 auto *Arg =
 ImplicitParamDecl::Create(Ctx, /*DC=*/nullptr, FD->getLocation(), II,
   ArgType, ImplicitParamDecl::Other);

Modified: cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_reduction_codegen.cpp?rev=316488&r1=316487&r2=316488&view=diff
==
--- cfe/trunk/test/OpenMP/for_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_reduction_codegen.cpp Tue Oct 24 12:52:31 2017
@@ -524,7 +524,7 @@ int main() {
 // CHECK: store float [[UP]], float* [[T_VAR1_LHS]],
 // CHECK: ret void
 
-// CHECK: define internal void [[MAIN_MICROTASK1]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i32* 
%{{.+}}, [2 x i32]* dereferenceable(8) %{{.+}}, [10 x [4 x [[S_FLOAT_TY* 
dereferenceable(160) %{{.+}})
+// CHECK: define internal void [[MAIN_MICROTASK1]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i32* 
{{.+}} %{{.+}}, [2 x i32]* dereferenceable(8) %{{.+}}, [10 x [4 x 
[[S_FLOAT_TY* dereferenceable(160) %{{.+}})
 
 // Reduction list for runtime.
 // CHECK: [[RED_LIST:%.+]] = alloca [4 x i8*],
@@ -725,7 +725,7 @@ int main() {
 
 // CHECK: ret void
 
-// CHECK: define internal void [[MAIN_MICROTASK2]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i32* 
%{{.+}}, [10 x [4 x [[S_FLOAT_TY* dereferenceable(160) %{{.+}})
+// CHECK: define internal void [[MAIN_MICROTASK2]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i32* 
{{.+}} %{{.+}}, [10 x [4 x [[S_FLOAT_TY* dereferenceable(160) %{{.+}})
 
 // CHECK: [[ARRS_PRIV:%.+]] = alloca [10 x [4 x [[S_FLOAT_TY,
 

Modified: cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp?rev=316488&r1=316487&r2=316488&view=diff
==
--- cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp (original)
+++ cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp Tue Oct 24 12:52:31 2017
@@ -307,7 +307,7 @@ int main() {
 // CHECK: fadd float 5.55e+02, %
 // CHECK: ret void
 
-// CHECK: define internal void [[MAIN_MICROTASK1]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i32* 
%{{.+}}, [2 x i32]* dereferenceable(8) %{{.+}}, [10 x [4 x [[S_FLOAT_TY* 
dereferenceable(480) %{{.+}})
+// CHECK: define internal void [[MAIN_MICROTASK1]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i32* 
{{.+}} %{{.+}}, [2 x i32]* dereferenceable(8) %{{.+}}, [10 x [4 x 
[[S_FLOAT_TY* dereferenceable(480) %{{.+}})
 
 // Reduction list for runtime.
 // CHECK: [[RED_LIST:%.+]] = alloca [4 x i8*],
@@ -503,7 +503,7 @@ int main() {
 
 // CHECK: ret void
 
-// CHECK: define internal void [[MAIN_MICROTASK2]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-

r316584 - [OPENMP] Constify function parameters, NFC.

2017-10-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Oct 25 08:44:52 2017
New Revision: 316584

URL: http://llvm.org/viewvc/llvm-project?rev=316584&view=rev
Log:
[OPENMP] Constify function parameters, NFC.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=316584&r1=316583&r2=316584&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Oct 25 08:44:52 2017
@@ -4322,7 +4322,7 @@ static bool FitsInto(unsigned Bits, bool
 
 /// Build preinits statement for the given declarations.
 static Stmt *buildPreInits(ASTContext &Context,
-   SmallVectorImpl &PreInits) {
+   MutableArrayRef PreInits) {
   if (!PreInits.empty()) {
 return new (Context) DeclStmt(
 DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()),
@@ -4332,8 +4332,9 @@ static Stmt *buildPreInits(ASTContext &C
 }
 
 /// Build preinits statement for the given declarations.
-static Stmt *buildPreInits(ASTContext &Context,
-   llvm::MapVector &Captures) {
+static Stmt *
+buildPreInits(ASTContext &Context,
+  const llvm::MapVector &Captures) {
   if (!Captures.empty()) {
 SmallVector PreInits;
 for (auto &Pair : Captures)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316585 - [OPENMP] Improve debug info for taskgroup implicitly generated

2017-10-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Oct 25 08:54:04 2017
New Revision: 316585

URL: http://llvm.org/viewvc/llvm-project?rev=316585&view=rev
Log:
[OPENMP] Improve debug info for taskgroup implicitly generated
expressions.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=316585&r1=316584&r2=316585&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Oct 25 08:54:04 2017
@@ -835,10 +835,10 @@ void DSAStackTy::addTaskgroupReductionDa
   Expr *&TaskgroupReductionRef =
   Stack.back().first.back().TaskgroupReductionRef;
   if (!TaskgroupReductionRef) {
-auto *VD = buildVarDecl(SemaRef, SourceLocation(),
+auto *VD = buildVarDecl(SemaRef, SR.getBegin(),
 SemaRef.Context.VoidPtrTy, ".task_red.");
-TaskgroupReductionRef = buildDeclRefExpr(
-SemaRef, VD, SemaRef.Context.VoidPtrTy, SourceLocation());
+TaskgroupReductionRef =
+buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, 
SR.getBegin());
   }
 }
 
@@ -858,10 +858,10 @@ void DSAStackTy::addTaskgroupReductionDa
   Expr *&TaskgroupReductionRef =
   Stack.back().first.back().TaskgroupReductionRef;
   if (!TaskgroupReductionRef) {
-auto *VD = buildVarDecl(SemaRef, SourceLocation(),
-SemaRef.Context.VoidPtrTy, ".task_red.");
-TaskgroupReductionRef = buildDeclRefExpr(
-SemaRef, VD, SemaRef.Context.VoidPtrTy, SourceLocation());
+auto *VD = buildVarDecl(SemaRef, SR.getBegin(), SemaRef.Context.VoidPtrTy,
+".task_red.");
+TaskgroupReductionRef =
+buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, 
SR.getBegin());
   }
 }
 
@@ -9720,8 +9720,7 @@ static bool ActOnOMPReductionKindClause(
   // (type of the variable or single array element).
   PrivateTy = Context.getVariableArrayType(
   Type,
-  new (Context) OpaqueValueExpr(SourceLocation(), 
Context.getSizeType(),
-VK_RValue),
+  new (Context) OpaqueValueExpr(ELoc, Context.getSizeType(), 
VK_RValue),
   ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange());
 } else if (!ASE && !OASE &&
Context.getAsArrayType(D->getType().getNonReferenceType()))
@@ -9803,8 +9802,7 @@ static bool ActOnOMPReductionKindClause(
   if (Type->isPointerType()) {
 // Cast to pointer type.
 auto CastExpr = S.BuildCStyleCastExpr(
-SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc),
-SourceLocation(), Init);
+ELoc, Context.getTrivialTypeSourceInfo(Type, ELoc), ELoc, 
Init);
 if (CastExpr.isInvalid())
   continue;
 Init = CastExpr.get();
@@ -9898,9 +9896,9 @@ static bool ActOnOMPReductionKindClause(
   S.BuildBinOp(Stack->getCurScope(), ReductionId.getLocStart(),
BO_Assign, LHSDRE, ReductionOp.get());
 } else {
-  auto *ConditionalOp = new (Context) ConditionalOperator(
-  ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(),
-  RHSDRE, Type, VK_LValue, OK_Ordinary);
+  auto *ConditionalOp = new (Context)
+  ConditionalOperator(ReductionOp.get(), ELoc, LHSDRE, ELoc, 
RHSDRE,
+  Type, VK_LValue, OK_Ordinary);
   ReductionOp =
   S.BuildBinOp(Stack->getCurScope(), ReductionId.getLocStart(),
BO_Assign, LHSDRE, ConditionalOp);
@@ -10782,7 +10780,7 @@ Sema::ActOnOpenMPDependClause(OpenMPDepe
 }
 bool Suppress = getDiagnostics().getSuppressAllDiagnostics();
 getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true);
-ExprResult Res = CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf,
+ExprResult Res = CreateBuiltinUnaryOp(ELoc, UO_AddrOf,
   RefExpr->IgnoreParenImpCasts());
 getDiagnostics().setSuppressAllDiagnostics(Suppress);
 if (!Res.isUsable() && !isa(SimpleExpr)) {

Modified: cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp?rev=316585&r1=316584&r2=316585&view=diff
==
--- cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp Wed Oct 25 
08:54:04 2017
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c++ 
-emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64

r340953 - [OPENMP][NVPTX] Add support for lightweight runtime.

2018-08-29 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Aug 29 11:32:21 2018
New Revision: 340953

URL: http://llvm.org/viewvc/llvm-project?rev=340953&view=rev
Log:
[OPENMP][NVPTX] Add support for lightweight runtime.

If the target construct can be executed in SPMD mode + it is a loop
based directive with static scheduling, we can use lightweight runtime
support.

Added:
cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/test/OpenMP/declare_target_codegen_globalization.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp

cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=340953&r1=340952&r2=340953&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Wed Aug 29 11:32:21 2018
@@ -672,11 +672,19 @@ static bool hasParallelIfNumThreadsClaus
   return false;
 }
 
+/// Checks if the directive is the distribute clause with the lastprivate
+/// clauses. This construct does not support SPMD execution mode.
+static bool hasDistributeWithLastprivateClauses(const OMPExecutableDirective 
&D) {
+  return isOpenMPDistributeDirective(D.getDirectiveKind()) &&
+ D.hasClausesOfKind();
+}
+
 /// Check for inner (nested) SPMD construct, if any
 static bool hasNestedSPMDDirective(ASTContext &Ctx,
const OMPExecutableDirective &D) {
   const auto *CS = D.getInnermostCapturedStmt();
-  const auto *Body = CS->getCapturedStmt()->IgnoreContainers();
+  const auto *Body =
+  CS->getCapturedStmt()->IgnoreContainers(/*IgnoreCaptured=*/true);
   const Stmt *ChildStmt = getSingleCompoundChild(Body);
 
   if (const auto *NestedDir = dyn_cast(ChildStmt)) {
@@ -684,29 +692,221 @@ static bool hasNestedSPMDDirective(ASTCo
 switch (D.getDirectiveKind()) {
 case OMPD_target:
   if (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfNumThreadsClause(Ctx, *NestedDir))
+  !hasParallelIfNumThreadsClause(Ctx, *NestedDir) &&
+  !hasDistributeWithLastprivateClauses(*NestedDir))
 return true;
-  if (DKind == OMPD_teams || DKind == OMPD_teams_distribute) {
-Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
+  if (DKind == OMPD_teams) {
+Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers(
+/*IgnoreCaptured=*/true);
 if (!Body)
   return false;
 ChildStmt = getSingleCompoundChild(Body);
 if (const auto *NND = dyn_cast(ChildStmt)) {
   DKind = NND->getDirectiveKind();
   if (isOpenMPParallelDirective(DKind) &&
-  !hasParallelIfNumThreadsClause(Ctx, *NND))
+  !hasParallelIfNumThreadsClause(Ctx, *NND) &&
+  !hasDistributeWithLastprivateClauses(*NND))
 return true;
-  if (DKind == OMPD_distribute) {
-Body = NestedDir->getInnermostCapturedStmt()->IgnoreContainers();
+}
+  }
+  return false;
+case OMPD_target_teams:
+  return isOpenMPParallelDirective(DKind) &&
+ !hasParallelIfNumThreadsClause(Ctx, *NestedDir) &&
+ !hasDistributeWithLastprivateClauses(*NestedDir);
+case OMPD_target_simd:
+case OMPD_target_parallel:
+case OMPD_target_parallel_for:
+case OMPD_target_parallel_for_simd:
+case OMPD_target_teams_distribute:
+case OMPD_target_teams_distribute_simd:
+case OMPD_target_teams_distribute_parallel_for:
+case OMPD_target_teams_distribute_parallel_for_simd:
+case OMPD_parallel:
+case OMPD_for:
+case OMPD_parallel_for:
+case OMPD_parallel_sections:
+case OMPD_for_simd:
+case OMPD_parallel_for_simd:
+case OMPD_cancel:
+case OMPD_cancellation_point:
+case OMPD_ordered:
+case OMPD_threadprivate:
+case OMPD_task:
+case OMPD_simd:
+case OMPD_sections:
+case OMPD_section:
+case OMPD_single:
+case OMPD_master:
+case OMPD_critical:
+case OMPD_taskyield:
+case OMPD_barrier:
+case OMPD_taskwait:
+case OMPD_taskgroup:
+case OMPD_atomic:
+case OMPD_flush:
+case OMPD_teams:
+case OMPD_target_data:
+case OMPD_target_exit_data:
+case OMPD_target_enter_data:
+case OMPD_distribute:
+case OMPD_distribute_simd:
+case OMPD_distribute_parallel_for:
+case OMPD_

r340968 - [OPENMP] Do not create offloading entry for declare target variables

2018-08-29 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Aug 29 13:41:37 2018
New Revision: 340968

URL: http://llvm.org/viewvc/llvm-project?rev=340968&view=rev
Log:
[OPENMP] Do not create offloading entry for declare target variables
declarations.

We should not create offloading entries for declare target var
declarations as it causes compiler crash.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=340968&r1=340967&r2=340968&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Aug 29 13:41:37 2018
@@ -3989,6 +3989,9 @@ void CGOpenMPRuntime::createOffloadEntri
   CGM.getDiags().Report(DiagID);
   continue;
 }
+// The vaiable has no definition - no need to add the entry.
+if (CE->getVarSize().isZero())
+  continue;
 break;
   }
   case OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryLink:
@@ -8108,7 +8111,12 @@ void CGOpenMPRuntime::registerTargetGlob
 case OMPDeclareTargetDeclAttr::MT_To:
   Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryTo;
   VarName = CGM.getMangledName(VD);
-  VarSize = CGM.getContext().getTypeSizeInChars(VD->getType());
+  if (VD->hasDefinition(CGM.getContext()) != VarDecl::DeclarationOnly) {
+VarSize = CGM.getContext().getTypeSizeInChars(VD->getType());
+assert(!VarSize.isZero() && "Expected non-zero size of the variable");
+  } else {
+VarSize = CharUnits::Zero();
+  }
   Linkage = CGM.getLLVMLinkageVarDefinition(VD, /*IsConstant=*/false);
   // Temp solution to prevent optimizations of the internal variables.
   if (CGM.getLangOpts().OpenMPIsDevice && !VD->isExternallyVisible()) {

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=340968&r1=340967&r2=340968&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Wed Aug 29 13:41:37 2018
@@ -143,4 +143,8 @@ int baz5() {
 // CHECK-DAG: declare extern_weak signext i32 @__create()
 
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
+
+// CHECK-DAG: !{i32 1, !"aaa", i32 0, i32 {{[0-9]+}}}
+// CHECK-DAG: !{i32 1, !"ccc", i32 0, i32 {{[0-9]+}}}
+
 #endif // HEADER


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341073 - [OPENMP][NVPTX] Add options -f[no-]openmp-cuda-force-full-runtime.

2018-08-30 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Aug 30 07:45:24 2018
New Revision: 341073

URL: http://llvm.org/viewvc/llvm-project?rev=341073&view=rev
Log:
[OPENMP][NVPTX] Add options -f[no-]openmp-cuda-force-full-runtime.

Added options -f[no-]openmp-cuda-force-full-runtime to [not] force use
of the full runtime for OpenMP offloading to CUDA devices.

Added:
cfe/trunk/test/OpenMP/nvptx_force_full_runtime_SPMD_codegen.cpp
Modified:
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/openmp-offload-gpu.c

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=341073&r1=341072&r2=341073&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Thu Aug 30 07:45:24 2018
@@ -203,6 +203,7 @@ LANGOPT(OpenMPSimd, 1, 0, "Use S
 LANGOPT(OpenMPUseTLS  , 1, 0, "Use TLS for threadprivates or runtime 
calls")
 LANGOPT(OpenMPIsDevice, 1, 0, "Generate code only for OpenMP target 
device")
 LANGOPT(OpenMPCUDAMode, 1, 0, "Generate code for OpenMP pragmas in 
SIMT/SPMD mode")
+LANGOPT(OpenMPCUDAForceFullRuntime , 1, 0, "Force to use full runtime in all 
constructs when offloading to CUDA devices")
 LANGOPT(OpenMPHostCXXExceptions, 1, 0, "C++ exceptions handling in the 
host code.")
 LANGOPT(RenderScript  , 1, 0, "RenderScript")
 

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=341073&r1=341072&r2=341073&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Aug 30 07:45:24 2018
@@ -1531,6 +1531,10 @@ def fopenmp_cuda_mode : Flag<["-"], "fop
   Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
 def fno_openmp_cuda_mode : Flag<["-"], "fno-openmp-cuda-mode">, Group,
   Flags<[NoArgumentUnused, HelpHidden]>;
+def fopenmp_cuda_force_full_runtime : Flag<["-"], 
"fopenmp-cuda-force-full-runtime">, Group,
+  Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
+def fno_openmp_cuda_force_full_runtime : Flag<["-"], 
"fno-openmp-cuda-force-full-runtime">, Group,
+  Flags<[NoArgumentUnused, HelpHidden]>;
 def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, 
Group;
 def foptimize_sibling_calls : Flag<["-"], "foptimize-sibling-calls">, 
Group;
 def fno_escaping_block_tail_calls : Flag<["-"], 
"fno-escaping-block-tail-calls">, Group, Flags<[CC1Option]>;

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=341073&r1=341072&r2=341073&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Aug 30 07:45:24 2018
@@ -1218,7 +1218,8 @@ void CGOpenMPRuntimeNVPTX::emitSPMDEntry
   EST.ExitBB = CGF.createBasicBlock(".exit");
 
   // Initialize the OMP state in the runtime; called by all active threads.
-  bool RequiresFullRuntime = !supportsLightweightRuntime(CGF.getContext(), D);
+  bool RequiresFullRuntime = CGM.getLangOpts().OpenMPCUDAForceFullRuntime ||
+ !supportsLightweightRuntime(CGF.getContext(), D);
   llvm::Value *Args[] = {
   getThreadLimit(CGF, /*IsInSPMDExecutionMode=*/true),
   /*RequiresOMPRuntime=*/

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=341073&r1=341072&r2=341073&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Aug 30 07:45:24 2018
@@ -4039,8 +4039,16 @@ void Clang::ConstructJob(Compilation &C,
 
   // When in OpenMP offloading mode with NVPTX target, forward
   // cuda-mode flag
-  Args.AddLastArg(CmdArgs, options::OPT_fopenmp_cuda_mode,
-  options::OPT_fno_openmp_cuda_mode);
+  if (Args.hasFlag(options::OPT_fopenmp_cuda_mode,
+   options::OPT_fno_openmp_cuda_mode, /*Default=*/false))
+CmdArgs.push_back("-fopenmp-cuda-mode");
+
+  // When in OpenMP offloading mode with NVPTX target, check if full 
runtime
+  // is required.
+  if (Args.hasFlag(options::OPT_fopenmp_cuda_force_full_runtime,
+   options::OPT_fno_openmp_cuda_force_full_runtime,
+   /*Default=*/false))
+CmdArgs.push_back

r341093 - [OPENMP] Fix PR38710: static functions are not emitted as implicitly

2018-08-30 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Aug 30 11:56:11 2018
New Revision: 341093

URL: http://llvm.org/viewvc/llvm-project?rev=341093&view=rev
Log:
[OPENMP] Fix PR38710: static functions are not emitted as implicitly
'declare target'.

All the functions, referenced in implicit|explicit target regions must
be emitted during code emission for the device.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=341093&r1=341092&r2=341093&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Aug 30 11:56:11 2018
@@ -1832,7 +1832,8 @@ llvm::Value *CGOpenMPRuntimeNVPTX::emitT
 }
 
 void CGOpenMPRuntimeNVPTX::emitGenericVarsProlog(CodeGenFunction &CGF,
- SourceLocation Loc) {
+ SourceLocation Loc,
+ bool WithSPMDCheck) {
   if (getDataSharingMode(CGM) != CGOpenMPRuntimeNVPTX::Generic)
 return;
 
@@ -1855,7 +1856,8 @@ void CGOpenMPRuntimeNVPTX::emitGenericVa
 GlobalRecordSize = llvm::alignTo(GlobalRecordSize, Alignment);
 
 llvm::Value *GlobalRecCastAddr;
-if (getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
+if (WithSPMDCheck ||
+getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
   llvm::BasicBlock *SPMDBB = CGF.createBasicBlock(".spmd");
   llvm::BasicBlock *NonSPMDBB = CGF.createBasicBlock(".non-spmd");
@@ -1963,7 +1965,8 @@ void CGOpenMPRuntimeNVPTX::emitGenericVa
   I->getSecond().MappedParams->apply(CGF);
 }
 
-void CGOpenMPRuntimeNVPTX::emitGenericVarsEpilog(CodeGenFunction &CGF) {
+void CGOpenMPRuntimeNVPTX::emitGenericVarsEpilog(CodeGenFunction &CGF,
+ bool WithSPMDCheck) {
   if (getDataSharingMode(CGM) != CGOpenMPRuntimeNVPTX::Generic)
 return;
 
@@ -1979,7 +1982,8 @@ void CGOpenMPRuntimeNVPTX::emitGenericVa
   Addr);
 }
 if (I->getSecond().GlobalRecordAddr) {
-  if (getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
+  if (WithSPMDCheck ||
+  getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
 CGBuilderTy &Bld = CGF.Builder;
 llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
 llvm::BasicBlock *NonSPMDBB = CGF.createBasicBlock(".non-spmd");
@@ -3972,13 +3976,13 @@ void CGOpenMPRuntimeNVPTX::emitFunctionP
 Data.insert(std::make_pair(VD, std::make_pair(FD, Address::invalid(;
   }
   if (!NeedToDelayGlobalization) {
-emitGenericVarsProlog(CGF, D->getBeginLoc());
+emitGenericVarsProlog(CGF, D->getBeginLoc(), /*WithSPMDCheck=*/true);
 struct GlobalizationScope final : EHScopeStack::Cleanup {
   GlobalizationScope() = default;
 
   void Emit(CodeGenFunction &CGF, Flags flags) override {
 static_cast(CGF.CGM.getOpenMPRuntime())
-.emitGenericVarsEpilog(CGF);
+.emitGenericVarsEpilog(CGF, /*WithSPMDCheck=*/true);
   }
 };
 CGF.EHStack.pushCleanup(NormalAndEHCleanup);

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h?rev=341093&r1=341092&r2=341093&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h Thu Aug 30 11:56:11 2018
@@ -72,10 +72,11 @@ private:
   void emitNonSPMDEntryFooter(CodeGenFunction &CGF, EntryFunctionState &EST);
 
   /// Helper for generic variables globalization prolog.
-  void emitGenericVarsProlog(CodeGenFunction &CGF, SourceLocation Loc);
+  void emitGenericVarsProlog(CodeGenFunction &CGF, SourceLocation Loc,
+ bool WithSPMDCheck = false);
 
   /// Helper for generic variables globalization epilog.
-  void emitGenericVarsEpilog(CodeGenFunction &CGF);
+  void emitGenericVarsEpilog(CodeGenFunction &CGF, bool WithSPMDCheck = false);
 
   /// Helper for SPMD mode target directive's entry function.
   void emitSPMDEntryHeader(CodeGenFunction &CGF, EntryFunctionState &EST,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=341093&r1=341092&r2=341093&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Aug 30 11:56:11 2018
@@ -257

r341212 - [DEBUGINFO] Add support for emission of the debug directives only.

2018-08-31 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Aug 31 06:56:14 2018
New Revision: 341212

URL: http://llvm.org/viewvc/llvm-project?rev=341212&view=rev
Log:
[DEBUGINFO] Add support for emission of the debug directives only.

Summary:
Added option -gline-directives-only to support emission of the debug directives
only. It behaves very similar to -gline-tables-only, except that it sets
llvm debug info emission kind to
llvm::DICompileUnit::DebugDirectivesOnly.

Reviewers: echristo

Subscribers: aprantl, fedor.sergeev, JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D51177

Modified:
cfe/trunk/include/clang/Basic/DebugInfoOptions.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/debug-info-gline-tables-only.c
cfe/trunk/test/CodeGen/debug-info-gline-tables-only2.c
cfe/trunk/test/CodeGen/debug-info-line.c
cfe/trunk/test/CodeGen/debug-info-macro.c
cfe/trunk/test/CodeGen/debug-info-scope.c
cfe/trunk/test/CodeGen/lifetime-debuginfo-1.c
cfe/trunk/test/CodeGen/lifetime-debuginfo-2.c
cfe/trunk/test/CodeGenCXX/crash.cpp
cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-gline-tables-only.cpp
cfe/trunk/test/CodeGenCXX/debug-info-line.cpp
cfe/trunk/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
cfe/trunk/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
cfe/trunk/test/CodeGenCXX/debug-info-windows-dtor.cpp
cfe/trunk/test/CodeGenCXX/linetable-virtual-variadic.cpp
cfe/trunk/test/CodeGenObjCXX/debug-info-line.mm
cfe/trunk/test/CodeGenObjCXX/pr14474-gline-tables-only.mm
cfe/trunk/test/Driver/debug-options.c

Modified: cfe/trunk/include/clang/Basic/DebugInfoOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DebugInfoOptions.h?rev=341212&r1=341211&r2=341212&view=diff
==
--- cfe/trunk/include/clang/Basic/DebugInfoOptions.h (original)
+++ cfe/trunk/include/clang/Basic/DebugInfoOptions.h Fri Aug 31 06:56:14 2018
@@ -21,6 +21,7 @@ enum DebugInfoKind {
/// locations for instructions without actually
/// emitting debug info for them (e.g., when -Rpass
/// is used).
+  DebugDirectivesOnly, /// Emit only debug directives with the line numbers 
data
   DebugLineTablesOnly, /// Emit only debug info necessary for generating
/// line number tables (-gline-tables-only).
   LimitedDebugInfo,/// Limit generated debug info to reduce size

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=341212&r1=341211&r2=341212&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 31 06:56:14 2018
@@ -1777,6 +1777,8 @@ def g_Flag : Flag<["-"], "g">, Group;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
   Flags<[CoreOption]>, HelpText<"Emit debug line number tables only">;
+def gline_directives_only : Flag<["-"], "gline-directives-only">, 
Group,
+  Flags<[CoreOption]>, HelpText<"Emit debug line info directives only">;
 def gmlt : Flag<["-"], "gmlt">, Alias;
 def g0 : Flag<["-"], "g0">, Group;
 def g1 : Flag<["-"], "g1">, Group, Alias;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=341212&r1=341211&r2=341212&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Aug 31 06:56:14 2018
@@ -557,6 +557,9 @@ void CGDebugInfo::CreateCompileUnit() {
   case codegenoptions::DebugLineTablesOnly:
 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
 break;
+  case codegenoptions::DebugDirectivesOnly:
+EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
+break;
   case codegenoptions::LimitedDebugInfo:
   case codegenoptions::FullDebugInfo:
 EmissionKind = llvm::DICompileUnit::FullDebug;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=341212&r1=341211&r2=341212&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Aug 31 06:56:14 2018
@@ -493,6 +493,8 @@ static codegenoptions::DebugInfoKind Deb
   if (A.getOption().matches(options::OPT_gline_tables_only) ||
   A.getOption().matches(options::OPT_ggdb1))
   

r341483 - [OPENMP][NVPTX] Disable runtime-type info for CUDA devices.

2018-09-05 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Sep  5 10:10:30 2018
New Revision: 341483

URL: http://llvm.org/viewvc/llvm-project?rev=341483&view=rev
Log:
[OPENMP][NVPTX] Disable runtime-type info for CUDA devices.

RTTI is not supported by the NVPTX target.

Added:
cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp
Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=341483&r1=341482&r2=341483&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Sep  5 10:10:30 2018
@@ -2650,6 +2650,11 @@ static void ParseLangArgs(LangOptions &O
 Opts.Exceptions = 0;
 Opts.CXXExceptions = 0;
   }
+  // NVPTX does not support RTTI.
+  if (Opts.OpenMPIsDevice && T.isNVPTX()) {
+Opts.RTTI = 0;
+Opts.RTTIData = 0;
+  }
 
   // Get the OpenMP target triples if any.
   if (Arg *A = Args.getLastArg(options::OPT_fopenmp_targets_EQ)) {

Added: cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp?rev=341483&view=auto
==
--- cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp (added)
+++ cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp Wed Sep  5 10:10:30 
2018
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc 
-fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ferror-limit 100
+
+#ifndef HEADER
+#define HEADER
+
+namespace std {
+  class type_info;
+}
+
+template 
+class TemplateClass {
+  T a;
+public:
+  TemplateClass() { (void)typeid(int); } // expected-error {{use of typeid 
requires -frtti}}
+  T f_method() const { return a; }
+};
+
+int foo();
+
+int baz1();
+
+int baz2();
+
+int baz4() { return 5; }
+
+template 
+T FA() {
+  TemplateClass s;
+  return s.f_method();
+}
+
+#pragma omp declare target
+struct S {
+  int a;
+  S(int a) : a(a) { (void)typeid(int); } // expected-error {{use of typeid 
requires -frtti}}
+};
+
+int foo() { return 0; }
+int b = 15;
+int d;
+#pragma omp end declare target
+int c;
+
+int bar() { return 1 + foo() + bar() + baz1() + baz2(); }
+
+int maini1() {
+  int a;
+  static long aa = 32;
+#pragma omp target map(tofrom \
+   : a, b)
+  {
+S s(a);
+static long aaa = 23;
+a = foo() + bar() + b + c + d + aa + aaa + FA();
+(void)typeid(int); // expected-error {{use of typeid requires -frtti}}
+  }
+  return baz4();
+}
+
+int baz3() { return 2 + baz2(); }
+int baz2() {
+#pragma omp target
+  (void)typeid(int); // expected-error {{use of typeid requires -frtti}}
+  return 2 + baz3();
+}
+
+#endif // HEADER


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341570 - [OPENMP] Fix PR38823: Do not emit vtable if it is not used in target

2018-09-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Sep  6 10:56:28 2018
New Revision: 341570

URL: http://llvm.org/viewvc/llvm-project?rev=341570&view=rev
Log:
[OPENMP] Fix PR38823: Do not emit vtable if it is not used in target
context.

If the explicit template instantiation definition defined outside of the
target context, its vtable should not be marked as used. This is true
for other situations where the compiler want to emit vtables
unconditionally.

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=341570&r1=341569&r2=341570&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Sep  6 10:56:28 2018
@@ -14903,6 +14903,11 @@ void Sema::MarkVTableUsed(SourceLocation
   if (!Class->isDynamicClass() || Class->isDependentContext() ||
   CurContext->isDependentContext() || isUnevaluatedContext())
 return;
+  // Do not mark as used if compiling for the device outside of the target
+  // region.
+  if (LangOpts.OpenMP && LangOpts.OpenMPIsDevice &&
+  !isInOpenMPDeclareTargetContext() && !getCurFunctionDecl())
+return;
 
   // Try to insert this class into the map.
   LoadExternalVTableUses();

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=341570&r1=341569&r2=341570&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Thu Sep  6 10:56:28 2018
@@ -12,7 +12,8 @@
 
 // SIMD-ONLY-NOT: {{__kmpc|__tgt}}
 
-// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
+// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base}}
+// CHECK-DAG: Bake
 // CHECK-NOT: @{{hhh|ggg|fff|eee}} =
 // CHECK-DAG: @aaa = external global i32,
 // CHECK-DAG: @bbb = global i32 0,
@@ -140,9 +141,25 @@ int baz5() {
   return a;
 }
 
+template 
+struct Base {
+  virtual ~Base() {}
+};
+
+template class Base;
+
+template 
+struct Bake {
+  virtual ~Bake() {}
+};
+
+#pragma omp declare target
+template class Bake;
+#pragma omp end declare target
+
 // CHECK-DAG: declare extern_weak signext i32 @__create()
 
-// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
+// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base}}
 
 // CHECK-DAG: !{i32 1, !"aaa", i32 0, i32 {{[0-9]+}}}
 // CHECK-DAG: !{i32 1, !"ccc", i32 0, i32 {{[0-9]+}}}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341668 - Revert "[OPENMP][NVPTX] Disable runtime-type info for CUDA devices."

2018-09-07 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Sep  7 07:50:25 2018
New Revision: 341668

URL: http://llvm.org/viewvc/llvm-project?rev=341668&view=rev
Log:
Revert "[OPENMP][NVPTX] Disable runtime-type info for CUDA devices."

Still need the RTTI for NVPTX target to pass sema checks.

Removed:
cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp
Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=341668&r1=341667&r2=341668&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Sep  7 07:50:25 2018
@@ -2648,11 +2648,6 @@ static void ParseLangArgs(LangOptions &O
 Opts.Exceptions = 0;
 Opts.CXXExceptions = 0;
   }
-  // NVPTX does not support RTTI.
-  if (Opts.OpenMPIsDevice && T.isNVPTX()) {
-Opts.RTTI = 0;
-Opts.RTTIData = 0;
-  }
 
   // Get the OpenMP target triples if any.
   if (Arg *A = Args.getLastArg(options::OPT_fopenmp_targets_EQ)) {

Removed: cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp?rev=341667&view=auto
==
--- cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_rtti_messages.cpp (removed)
@@ -1,68 +0,0 @@
-// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc 
-fexceptions -fcxx-exceptions
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ferror-limit 100
-
-#ifndef HEADER
-#define HEADER
-
-namespace std {
-  class type_info;
-}
-
-template 
-class TemplateClass {
-  T a;
-public:
-  TemplateClass() { (void)typeid(int); } // expected-error {{use of typeid 
requires -frtti}}
-  T f_method() const { return a; }
-};
-
-int foo();
-
-int baz1();
-
-int baz2();
-
-int baz4() { return 5; }
-
-template 
-T FA() {
-  TemplateClass s;
-  return s.f_method();
-}
-
-#pragma omp declare target
-struct S {
-  int a;
-  S(int a) : a(a) { (void)typeid(int); } // expected-error {{use of typeid 
requires -frtti}}
-};
-
-int foo() { return 0; }
-int b = 15;
-int d;
-#pragma omp end declare target
-int c;
-
-int bar() { return 1 + foo() + bar() + baz1() + baz2(); }
-
-int maini1() {
-  int a;
-  static long aa = 32;
-#pragma omp target map(tofrom \
-   : a, b)
-  {
-S s(a);
-static long aaa = 23;
-a = foo() + bar() + b + c + d + aa + aaa + FA();
-(void)typeid(int); // expected-error {{use of typeid requires -frtti}}
-  }
-  return baz4();
-}
-
-int baz3() { return 2 + baz2(); }
-int baz2() {
-#pragma omp target
-  (void)typeid(int); // expected-error {{use of typeid requires -frtti}}
-  return 2 + baz3();
-}
-
-#endif // HEADER


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341939 - [OPENMP] Simplified checks for declarations in declare target regions.

2018-09-11 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Sep 11 06:59:10 2018
New Revision: 341939

URL: http://llvm.org/viewvc/llvm-project?rev=341939&view=rev
Log:
[OPENMP] Simplified checks for declarations in declare target regions.

Sema analysis should not mark functions as an implicit declare target,
it may break codegen. Simplified semantic analysis and removed extra
code for implicit declare target functions.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_target_messages.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=341939&r1=341938&r2=341939&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Sep 11 06:59:10 2018
@@ -12998,16 +12998,20 @@ void Sema::ActOnOpenMPDeclareTargetName(
   }
 
   NamedDecl *ND = Lookup.getAsSingle();
-  if (isa(ND) || isa(ND)) {
+  if (isa(ND) || isa(ND) ||
+  isa(ND)) {
 if (!SameDirectiveDecls.insert(cast(ND->getCanonicalDecl(
   Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName();
-if (!ND->hasAttr()) {
+llvm::Optional Res =
+OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(
+cast(ND));
+if (!Res) {
   auto *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT);
   ND->addAttr(A);
   if (ASTMutationListener *ML = Context.getASTMutationListener())
 ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
   checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Id.getLoc());
-} else if (ND->getAttr()->getMapType() != MT) {
+} else if (*Res != MT) {
   Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link)
   << Id.getName();
 }
@@ -13018,79 +13022,13 @@ void Sema::ActOnOpenMPDeclareTargetName(
 
 static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR,
  Sema &SemaRef, Decl *D) {
-  if (!D)
+  if (!D || !isa(D))
 return;
-  const Decl *LD = nullptr;
-  if (isa(D)) {
-LD = cast(D)->getDefinition();
-  } else if (isa(D)) {
-LD = cast(D)->getDefinition();
-
-// If this is an implicit variable that is legal and we do not need to do
-// anything.
-if (cast(D)->isImplicit()) {
-  auto *A = OMPDeclareTargetDeclAttr::CreateImplicit(
-  SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To);
-  D->addAttr(A);
-  if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener())
-ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
-  return;
-}
-  } else if (const auto *F = dyn_cast(D)) {
-const FunctionDecl *FD = nullptr;
-if (cast(D)->hasBody(FD)) {
-  LD = FD;
-  // If the definition is associated with the current declaration in the
-  // target region (it can be e.g. a lambda) that is legal and we do not
-  // need to do anything else.
-  if (LD == D) {
-auto *A = OMPDeclareTargetDeclAttr::CreateImplicit(
-SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To);
-D->addAttr(A);
-if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener())
-  ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
-return;
-  }
-} else if (F->isFunctionTemplateSpecialization() &&
-   F->getTemplateSpecializationKind() ==
-   TSK_ImplicitInstantiation) {
-  // Check if the function is implicitly instantiated from the template
-  // defined in the declare target region.
-  const FunctionTemplateDecl *FTD = F->getPrimaryTemplate();
-  if (FTD && FTD->hasAttr())
-return;
-}
-  }
-  if (!LD)
-LD = D;
-  if (LD && !LD->hasAttr() &&
-  ((isa(LD) && !isa(LD)) || isa(LD))) {
-// Outlined declaration is not declared target.
-if (!isa(LD)) {
-  if (LD->isOutOfLine()) {
-SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context);
-SemaRef.Diag(SL, diag::note_used_here) << SR;
-  } else {
-const DeclContext *DC = LD->getDeclContext();
-while (DC &&
-   (!isa(DC) ||
-!cast(DC)->hasAttr()))
-  DC = DC->getParent();
-if (DC)
-  return;
-
-// Is not declared in target context.
-SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context);
-SemaRef.Diag(SL, diag::note_used_here) << SR;
-  }
-}
-// Mark decl as declared target to prevent further diagnostic.
-auto *A = OMPDeclareTargetDeclAttr::CreateImplicit(
-SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To);
-D->addAttr(A);
-if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener())
-  ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
-  }
+  auto *VD = cast(D);
+  if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD))
+return;
+  SemaRef.Diag(VD->getLocation(), diag::warn_omp_not_in_tar

r342062 - [OPENMP] Fix PR38902: support ADL for declare reduction constructs.

2018-09-12 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Sep 12 09:31:59 2018
New Revision: 342062

URL: http://llvm.org/viewvc/llvm-project?rev=342062&view=rev
Log:
[OPENMP] Fix PR38902: support ADL for declare reduction constructs.

Added support for argument-dependent lookup when trying to find the
required declare reduction decl.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_reduction_ast_print.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=342062&r1=342061&r2=342062&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Sep 12 09:31:59 2018
@@ -10068,6 +10068,79 @@ static T filterLookupForUDR(SmallVectorI
   return T();
 }
 
+static NamedDecl *findAcceptableDecl(Sema &SemaRef, NamedDecl *D) {
+  assert(!LookupResult::isVisible(SemaRef, D) && "not in slow case");
+
+  for (auto RD : D->redecls()) {
+// Don't bother with extra checks if we already know this one isn't 
visible.
+if (RD == D)
+  continue;
+
+auto ND = cast(RD);
+if (LookupResult::isVisible(SemaRef, ND))
+  return ND;
+  }
+
+  return nullptr;
+}
+
+static void
+argumentDependentLookup(Sema &SemaRef, const DeclarationNameInfo &ReductionId,
+SourceLocation Loc, QualType Ty,
+SmallVectorImpl> &Lookups) {
+  // Find all of the associated namespaces and classes based on the
+  // arguments we have.
+  Sema::AssociatedNamespaceSet AssociatedNamespaces;
+  Sema::AssociatedClassSet AssociatedClasses;
+  OpaqueValueExpr OVE(Loc, Ty, VK_LValue);
+  SemaRef.FindAssociatedClassesAndNamespaces(Loc, &OVE, AssociatedNamespaces,
+ AssociatedClasses);
+
+  // C++ [basic.lookup.argdep]p3:
+  //   Let X be the lookup set produced by unqualified lookup (3.4.1)
+  //   and let Y be the lookup set produced by argument dependent
+  //   lookup (defined as follows). If X contains [...] then Y is
+  //   empty. Otherwise Y is the set of declarations found in the
+  //   namespaces associated with the argument types as described
+  //   below. The set of declarations found by the lookup of the name
+  //   is the union of X and Y.
+  //
+  // Here, we compute Y and add its members to the overloaded
+  // candidate set.
+  for (auto *NS : AssociatedNamespaces) {
+//   When considering an associated namespace, the lookup is the
+//   same as the lookup performed when the associated namespace is
+//   used as a qualifier (3.4.3.2) except that:
+//
+// -- Any using-directives in the associated namespace are
+//ignored.
+//
+// -- Any namespace-scope friend functions declared in
+//associated classes are visible within their respective
+//namespaces even if they are not visible during an ordinary
+//lookup (11.4).
+DeclContext::lookup_result R = NS->lookup(ReductionId.getName());
+for (auto *D : R) {
+  auto *Underlying = D;
+  if (auto *USD = dyn_cast(D))
+Underlying = USD->getTargetDecl();
+
+  if (!isa(Underlying))
+continue;
+
+  if (!SemaRef.isVisible(D)) {
+D = findAcceptableDecl(SemaRef, D);
+if (!D)
+  continue;
+if (auto *USD = dyn_cast(D))
+  Underlying = USD->getTargetDecl();
+  }
+  Lookups.emplace_back();
+  Lookups.back().addDecl(Underlying);
+}
+  }
+}
+
 static ExprResult
 buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range,
  Scope *S, CXXScopeSpec &ReductionIdScopeSpec,
@@ -10086,7 +10159,7 @@ buildDeclareReductionRef(Sema &SemaRef,
   } while (S && !S->isDeclScope(D));
   if (S)
 S = S->getParent();
-  Lookups.push_back(UnresolvedSet<8>());
+  Lookups.emplace_back();
   Lookups.back().append(Lookup.begin(), Lookup.end());
   Lookup.clear();
 }
@@ -10113,6 +10186,8 @@ buildDeclareReductionRef(Sema &SemaRef,
   })) {
 UnresolvedSet<8> ResSet;
 for (const UnresolvedSet<8> &Set : Lookups) {
+  if (Set.empty())
+continue;
   ResSet.append(Set.begin(), Set.end());
   // The last item marks the end of all declarations at the specified 
scope.
   ResSet.addDecl(Set[Set.size() - 1]);
@@ -10122,6 +10197,36 @@ buildDeclareReductionRef(Sema &SemaRef,
 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId,
 /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end());
   }
+  // Lookup inside the classes.
+  // C++ [over.match.oper]p3:
+  //   For a unary operator @ with an operand of a type whose
+  //   cv-unqualified version is T1, and for a binary operator @ with
+  //   a left operand of a type whose cv-unqualified version is T1 and
+  //   a right operand of a type whose cv-unqualified version is T2,
+

r342151 - [OPENMP] Fix PR38903: Crash on instantiation of the non-dependent

2018-09-13 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Sep 13 09:54:05 2018
New Revision: 342151

URL: http://llvm.org/viewvc/llvm-project?rev=342151&view=rev
Log:
[OPENMP] Fix PR38903: Crash on instantiation of the non-dependent
declare reduction.

If the declare reduction construct with the non-dependent type is
defined in the template construct, the compiler might crash on the
template instantition. Reworked the whole instantiation scheme for the
declare reduction constructs to fix this problem correctly.

Modified:
cfe/trunk/include/clang/AST/DeclOpenMP.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/OpenMP/declare_reduction_messages.cpp

Modified: cfe/trunk/include/clang/AST/DeclOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclOpenMP.h?rev=342151&r1=342150&r2=342151&view=diff
==
--- cfe/trunk/include/clang/AST/DeclOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/DeclOpenMP.h Thu Sep 13 09:54:05 2018
@@ -112,9 +112,17 @@ public:
 private:
   friend class ASTDeclReader;
   /// Combiner for declare reduction construct.
-  Expr *Combiner;
+  Expr *Combiner = nullptr;
   /// Initializer for declare reduction construct.
-  Expr *Initializer;
+  Expr *Initializer = nullptr;
+  /// In parameter of the combiner.
+  Expr *In = nullptr;
+  /// Out parameter of the combiner.
+  Expr *Out = nullptr;
+  /// Priv parameter of the initializer.
+  Expr *Priv = nullptr;
+  /// Orig parameter of the initializer.
+  Expr *Orig = nullptr;
 
   /// Reference to the previous declare reduction construct in the same
   /// scope with the same name. Required for proper templates instantiation if
@@ -143,8 +151,19 @@ public:
   /// Get combiner expression of the declare reduction construct.
   Expr *getCombiner() { return Combiner; }
   const Expr *getCombiner() const { return Combiner; }
+  /// Get In variable of the combiner.
+  Expr *getCombinerIn() { return In; }
+  const Expr *getCombinerIn() const { return In; }
+  /// Get Out variable of the combiner.
+  Expr *getCombinerOut() { return Out; }
+  const Expr *getCombinerOut() const { return Out; }
   /// Set combiner expression for the declare reduction construct.
   void setCombiner(Expr *E) { Combiner = E; }
+  /// Set combiner In and Out vars.
+  void setCombinerData(Expr *InE, Expr *OutE) {
+In = InE;
+Out = OutE;
+  }
 
   /// Get initializer expression (if specified) of the declare reduction
   /// construct.
@@ -154,11 +173,22 @@ public:
   InitKind getInitializerKind() const {
 return static_cast(OMPDeclareReductionDeclBits.InitializerKind);
   }
+  /// Get Orig variable of the initializer.
+  Expr *getInitOrig() { return Orig; }
+  const Expr *getInitOrig() const { return Orig; }
+  /// Get Priv variable of the initializer.
+  Expr *getInitPriv() { return Priv; }
+  const Expr *getInitPriv() const { return Priv; }
   /// Set initializer expression for the declare reduction construct.
   void setInitializer(Expr *E, InitKind IK) {
 Initializer = E;
 OMPDeclareReductionDeclBits.InitializerKind = IK;
   }
+  /// Set initializer Orig and Priv vars.
+  void setInitializerData(Expr *OrigE, Expr *PrivE) {
+Orig = OrigE;
+Priv = PrivE;
+  }
 
   /// Get reference to previous declare reduction construct in the same
   /// scope with the same name.

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=342151&r1=342150&r2=342151&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Sep 13 09:54:05 2018
@@ -1295,27 +1295,19 @@ void CGOpenMPRuntime::emitUserDefinedRed
 CodeGenFunction *CGF, const OMPDeclareReductionDecl *D) {
   if (UDRMap.count(D) > 0)
 return;
-  ASTContext &C = CGM.getContext();
-  if (!In || !Out) {
-In = &C.Idents.get("omp_in");
-Out = &C.Idents.get("omp_out");
-  }
   llvm::Function *Combiner = emitCombinerOrInitializer(
-  CGM, D->getType(), D->getCombiner(), 
cast(D->lookup(In).front()),
-  cast(D->lookup(Out).front()),
+  CGM, D->getType(), D->getCombiner(),
+  cast(cast(D->getCombinerIn())->getDecl()),
+  cast(cast(D->getCombinerOut())->getDecl()),
   /*IsCombiner=*/true);
   llvm::Function *Initializer = nullptr;
   if (const Expr *Init = D->getInitializer()) {
-if (!Priv || !Orig) {
-  Priv = &C.Idents.get("omp_priv");
-  Orig = &C.Idents.get("omp_orig");
-}
 Initializer = emitCombinerOrInitializer(
 CGM, D->getType(),
 D->getInitializerKind() =

r337928 - [OPENMP] Fix PR38256: Fix locations of the artificial conditional op.

2018-07-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Jul 25 07:40:26 2018
New Revision: 337928

URL: http://llvm.org/viewvc/llvm-project?rev=337928&view=rev
Log:
[OPENMP] Fix PR38256: Fix locations of the artificial conditional op.

Fixed the source locations of the conditional op so that they don'r
crash coverage pass.

Added:
cfe/trunk/test/CoverageMapping/openmp.c
Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=337928&r1=337927&r2=337928&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Jul 25 07:40:26 2018
@@ -4909,7 +4909,8 @@ checkOpenMPLoop(OpenMPDirectiveKind DKin
 ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT,
 UB.get(), LastIteration.get());
 ExprResult CondOp = SemaRef.ActOnConditionalOp(
-InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get());
+LastIteration.get()->getExprLoc(), InitLoc, IsUBGreater.get(),
+LastIteration.get(), UB.get());
 EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
  CondOp.get());
 EUB = SemaRef.ActOnFinishFullExpr(EUB.get());

Added: cfe/trunk/test/CoverageMapping/openmp.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/openmp.c?rev=337928&view=auto
==
--- cfe/trunk/test/CoverageMapping/openmp.c (added)
+++ cfe/trunk/test/CoverageMapping/openmp.c Wed Jul 25 07:40:26 2018
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fopenmp -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only -main-file-name openmp.c %s | FileCheck 
%s
+
+// CHECK: openmp.c:{{.+}}omp_outlined{{.+}}:
+// CHECK: File 0, 10:3 -> 10:31
+// CHECK: File 0, 10:19 -> 10:24
+// CHECK: File 0, 10:26 -> 10:29
+// CHECK: File 0, 10:30 -> 10:31
+int foo(int time, int n) {
+#pragma omp parallel for default(shared) schedule(dynamic, 1) reduction(+ : 
time)
+  for (int i = 1; i < n; ++i);
+  return 0;
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337941 - [OPENMP] Exclude service expressions/statements from the list of

2018-07-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Jul 25 10:27:45 2018
New Revision: 337941

URL: http://llvm.org/viewvc/llvm-project?rev=337941&view=rev
Log:
[OPENMP] Exclude service expressions/statements from the list of
the children.

Special internal helper expressions/statements for the OpenMP directives
should not be exposed as children, only the main substatement must be
represented as the child.

Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/test/OpenMP/dump.cpp

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=337941&r1=337940&r2=337941&view=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Wed Jul 25 10:27:45 2018
@@ -252,7 +252,9 @@ public:
 if (!hasAssociatedStmt())
   return child_range(child_iterator(), child_iterator());
 Stmt **ChildStorage = reinterpret_cast(getClauses().end());
-return child_range(ChildStorage, ChildStorage + NumChildren);
+/// Do not mark all the special expression/statements as children, except
+/// for the associated statement.
+return child_range(ChildStorage, ChildStorage + 1);
   }
 
   ArrayRef clauses() { return getClauses(); }

Modified: cfe/trunk/test/OpenMP/dump.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/dump.cpp?rev=337941&r1=337940&r2=337941&view=diff
==
--- cfe/trunk/test/OpenMP/dump.cpp (original)
+++ cfe/trunk/test/OpenMP/dump.cpp Wed Jul 25 10:27:45 2018
@@ -53,11 +53,11 @@ struct S {
 // CHECK-NEXT: |   |-OMPScheduleClause {{.+}} 
 // CHECK-NEXT: |   | `-ImplicitCastExpr {{.+}}  'int' 

 // CHECK-NEXT: |   |   `-DeclRefExpr {{.+}}  'int' lvalue 
OMPCapturedExpr {{.+}} '.capture_expr.' 'int'
-// CHECK-NEXT: |   |-CapturedStmt {{.+}} 
-// CHECK-NEXT: |   | |-CapturedDecl {{.+}} <> 
-// CHECK-NEXT: |   | | |-ForStmt {{.+}} 
-// CHECK:  |   | | | `-UnaryOperator {{.+}}  'int' 
lvalue prefix '++'
-// CHECK-NEXT: |   | | |   `-DeclRefExpr {{.+}}  'int' lvalue 
OMPCapturedExpr {{.+}} 'a' 'int &'
+// CHECK-NEXT: |   `-CapturedStmt {{.+}} 
+// CHECK-NEXT: | |-CapturedDecl {{.+}} <> 
+// CHECK-NEXT: | | |-ForStmt {{.+}} 
+// CHECK:  | | | `-UnaryOperator {{.+}}  'int' 
lvalue prefix '++'
+// CHECK-NEXT: | | |   `-DeclRefExpr {{.+}}  'int' lvalue 
OMPCapturedExpr {{.+}} 'a' 'int &'
 
 #pragma omp declare simd
 #pragma omp declare simd inbranch


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r337957 - [OPENMP] ThreadId in serialized parallel regions is 0.

2018-07-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Jul 25 13:03:01 2018
New Revision: 337957

URL: http://llvm.org/viewvc/llvm-project?rev=337957&view=rev
Log:
[OPENMP] ThreadId in serialized parallel regions is 0.

The first argument for the parallel outlined functions, called as
serialized parallel regions, should be a pointer to the global thread id
that always is 0.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
cfe/trunk/test/OpenMP/parallel_if_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=337957&r1=337956&r2=337957&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Jul 25 13:03:01 2018
@@ -2839,12 +2839,12 @@ void CGOpenMPRuntime::emitParallelCall(C
 RT.createRuntimeFunction(OMPRTL__kmpc_serialized_parallel), Args);
 
 // OutlinedFn(>id, &zero, CapturedStruct);
-Address ThreadIDAddr = RT.emitThreadIDAddress(CGF, Loc);
 Address ZeroAddr = CGF.CreateDefaultAlignTempAlloca(CGF.Int32Ty,
 /*Name*/ ".zero.addr");
 CGF.InitTempAlloca(ZeroAddr, CGF.Builder.getInt32(/*C*/ 0));
 llvm::SmallVector OutlinedFnArgs;
-OutlinedFnArgs.push_back(ThreadIDAddr.getPointer());
+// ThreadId for serialized parallels is 0.
+OutlinedFnArgs.push_back(ZeroAddr.getPointer());
 OutlinedFnArgs.push_back(ZeroAddr.getPointer());
 OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end());
 RT.emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs);

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=337957&r1=337956&r2=337957&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Wed Jul 25 13:03:01 2018
@@ -1784,8 +1784,9 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
/*DestWidth=*/32, /*Signed=*/1),
".zero.addr");
   CGF.InitTempAlloca(ZeroAddr, CGF.Builder.getInt32(/*C*/ 0));
-  Address ThreadIDAddr = emitThreadIDAddress(CGF, Loc);
-  auto &&CodeGen = [this, Fn, CapturedVars, Loc, ZeroAddr, ThreadIDAddr](
+  // ThreadId for serialized parallels is 0.
+  Address ThreadIDAddr = ZeroAddr;
+  auto &&CodeGen = [this, Fn, CapturedVars, Loc, ZeroAddr, &ThreadIDAddr](
CodeGenFunction &CGF, PrePostActionTy &Action) {
 Action.Enter(CGF);
 
@@ -1883,8 +1884,9 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
 Work.emplace_back(WFn);
   };
 
-  auto &&LNParallelGen = [this, Loc, &SeqGen, &L0ParallelGen, &CodeGen](
- CodeGenFunction &CGF, PrePostActionTy &Action) {
+  auto &&LNParallelGen = [this, Loc, &SeqGen, &L0ParallelGen, &CodeGen,
+  &ThreadIDAddr](CodeGenFunction &CGF,
+ PrePostActionTy &Action) {
 RegionCodeGenTy RCG(CodeGen);
 if (IsInParallelRegion) {
   SeqGen(CGF, Action);
@@ -1936,6 +1938,8 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
   CGF.EmitBlock(ElseBlock);
+  // In the worker need to use the real thread id.
+  ThreadIDAddr = emitThreadIDAddress(CGF, Loc);
   RCG(CGF);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
@@ -1965,10 +1969,11 @@ void CGOpenMPRuntimeNVPTX::emitSPMDParal
/*DestWidth=*/32, /*Signed=*/1),
".zero.addr");
   CGF.InitTempAlloca(ZeroAddr, CGF.Builder.getInt32(/*C*/ 0));
-  Address ThreadIDAddr = emitThreadIDAddress(CGF, Loc);
+  // ThreadId for serialized parallels is 0.
+  Address ThreadIDAddr = ZeroAddr;
   auto &&CodeGen = [this, OutlinedFn, CapturedVars, Loc, ZeroAddr,
-ThreadIDAddr](CodeGenFunction &CGF,
-  PrePostActionTy &Action) {
+&ThreadIDAddr](CodeGenFunction &CGF,
+   PrePostActionTy &Action) {
 Action.Enter(CGF);
 
 llvm::SmallVector OutlinedFnArgs;
@@ -1995,6 +2000,8 @@ void CGOpenMPRuntimeNVPTX::emitSPMDParal
   };
 
   if (IsInTargetMasterThreadRegion) {
+// In the worker need to use the real thread id.
+ThreadIDAddr = emitThreadIDAddress(CGF, Loc);
 RegionCodeGenTy RCG(CodeGen);
 RCG(CGF);
   } else {

Modified: cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
URL: 
ht

r338032 - [OPENMP] Force OpenMP 4.5 when compiling for offloading.

2018-07-26 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Jul 26 08:17:38 2018
New Revision: 338032

URL: http://llvm.org/viewvc/llvm-project?rev=338032&view=rev
Log:
[OPENMP] Force OpenMP 4.5 when compiling for offloading.

If the user requested compilation for OpenMP with the offloading
support, force the version of the OpenMP standard to 4.5 by default.

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/OpenMP/driver.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=338032&r1=338031&r2=338032&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Jul 26 08:17:38 2018
@@ -4698,7 +4698,7 @@ void Clang::ConstructJob(Compilation &C,
 
   // For all the host OpenMP offloading compile jobs we need to pass the 
targets
   // information using -fopenmp-targets= option.
-  if (isa(JA) && JA.isHostOffloading(Action::OFK_OpenMP)) {
+  if (JA.isHostOffloading(Action::OFK_OpenMP)) {
 SmallString<128> TargetInfo("-fopenmp-targets=");
 
 Arg *Tgts = Args.getLastArg(options::OPT_fopenmp_targets_EQ);

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=338032&r1=338031&r2=338032&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Jul 26 08:17:38 2018
@@ -2594,13 +2594,15 @@ static void ParseLangArgs(LangOptions &O
   Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
+  bool IsTargetSpecified =
+  Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
 
   if (Opts.OpenMP || Opts.OpenMPSimd) {
-if (int Version =
-getLastArgIntValue(Args, OPT_fopenmp_version_EQ,
-   IsSimdSpecified ? 45 : Opts.OpenMP, Diags))
+if (int Version = getLastArgIntValue(
+Args, OPT_fopenmp_version_EQ,
+(IsSimdSpecified || IsTargetSpecified) ? 45 : Opts.OpenMP, Diags))
   Opts.OpenMP = Version;
-else if (IsSimdSpecified)
+else if (IsSimdSpecified || IsTargetSpecified)
   Opts.OpenMP = 45;
 // Provide diagnostic when a given target is not expected to be an OpenMP
 // device or host.

Modified: cfe/trunk/test/OpenMP/driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/driver.c?rev=338032&r1=338031&r2=338032&view=diff
==
--- cfe/trunk/test/OpenMP/driver.c (original)
+++ cfe/trunk/test/OpenMP/driver.c Thu Jul 26 08:17:38 2018
@@ -1,3 +1,4 @@
+// REQUIRES: x86-registered-target
 // Test that by default -fnoopenmp-use-tls is passed to frontend.
 //
 // RUN: %clang %s -### -o %t.o 2>&1 -fopenmp=libomp | FileCheck 
--check-prefix=CHECK-DEFAULT %s
@@ -23,7 +24,9 @@
 
 // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=45 | FileCheck 
--check-prefix=CHECK-45-VERSION %s
 // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-simd | FileCheck 
--check-prefix=CHECK-45-VERSION %s
+// RUN: %clang %s -c -E -dM -fopenmp=libomp 
-fopenmp-targets=x86_64-unknown-unknown -o - | FileCheck 
--check-prefix=CHECK-45-VERSION --check-prefix=CHECK-45-VERSION2 %s
 // CHECK-45-VERSION: #define _OPENMP 201511
+// CHECK-45-VERSION2: #define _OPENMP 201511
 
 // RUN: %clang %s -c -E -dM -fopenmp-version=1 | FileCheck 
--check-prefix=CHECK-VERSION %s
 // RUN: %clang %s -c -E -dM -fopenmp-version=31 | FileCheck 
--check-prefix=CHECK-VERSION %s


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r338049 - [OPENMP] What's new for OpenMP in clang.

2018-07-26 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Jul 26 10:53:45 2018
New Revision: 338049

URL: http://llvm.org/viewvc/llvm-project?rev=338049&view=rev
Log:
[OPENMP] What's new for OpenMP in clang.

Updated ReleaseNotes + Status of the OpenMP support in clang.

Modified:
cfe/trunk/docs/OpenMPSupport.rst
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/OpenMPSupport.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/OpenMPSupport.rst?rev=338049&r1=338048&r2=338049&view=diff
==
--- cfe/trunk/docs/OpenMPSupport.rst (original)
+++ cfe/trunk/docs/OpenMPSupport.rst Thu Jul 26 10:53:45 2018
@@ -10,13 +10,15 @@
 .. role:: partial
 .. role:: good
 
+.. contents::
+   :local:
+
 ==
 OpenMP Support
 ==
 
-Clang fully supports OpenMP 3.1 + some elements of OpenMP 4.5. Clang supports 
offloading to X86_64, AArch64 and PPC64[LE] devices.
-Support for Cuda devices is not ready yet.
-The status of major OpenMP 4.5 features support in Clang.
+Clang fully supports OpenMP 4.5. Clang supports offloading to X86_64, AArch64,
+PPC64[LE] and has `basic support for Cuda devices`_.
 
 Standalone directives
 =
@@ -35,7 +37,7 @@ Standalone directives
 
 * #pragma omp target: :good:`Complete`.
 
-* #pragma omp declare target: :partial:`Partial`.  No full codegen support.
+* #pragma omp declare target: :good:`Complete`.
 
 * #pragma omp teams: :good:`Complete`.
 
@@ -64,5 +66,66 @@ Combined directives
 
 * #pragma omp target teams distribute parallel for [simd]: :good:`Complete`.
 
-Clang does not support any constructs/updates from upcoming OpenMP 5.0 except 
for `reduction`-based clauses in the `task` and `target`-based directives.
-In addition, the LLVM OpenMP runtime `libomp` supports the OpenMP Tools 
Interface (OMPT) on x86, x86_64, AArch64, and PPC64 on Linux, Windows, and mac 
OS.
+Clang does not support any constructs/updates from upcoming OpenMP 5.0 except
+for `reduction`-based clauses in the `task` and `target`-based directives.
+
+In addition, the LLVM OpenMP runtime `libomp` supports the OpenMP Tools
+Interface (OMPT) on x86, x86_64, AArch64, and PPC64 on Linux, Windows, and mac 
OS.
+ows, and mac OS.
+
+.. _basic support for Cuda devices:
+
+Cuda devices support
+
+
+Directives execution modes
+--
+
+Clang code generation for target regions supports two modes: the SPMD and
+non-SPMD modes. Clang chooses one of these two modes automatically based on the
+way directives and clauses on those directives are used. The SPMD mode uses a
+simplified set of runtime functions thus increasing performance at the cost of
+supporting some OpenMP features. The non-SPMD mode is the most generic mode and
+supports all currently available OpenMP features. The compiler will always
+attempt to use the SPMD mode wherever possible. SPMD mode will not be used if:
+
+   - The target region contains an `if()` clause that refers to a `parallel`
+ directive.
+
+   - The target region contains a `parallel` directive with a `num_threads()`
+ clause.
+
+   - The target region contains user code (other than OpenMP-specific
+ directives) in between the `target` and the `parallel` directives.
+
+Data-sharing modes
+--
+
+Clang supports two data-sharing models for Cuda devices: `Generic` and `Cuda`
+modes. The default mode is `Generic`. `Cuda` mode can give an additional
+performance and can be activated using the `-fopenmp-cuda-mode` flag. In
+`Generic` mode all local variables that can be shared in the parallel regions
+are stored in the global memory. In `Cuda` mode local variables are not shared
+between the threads and it is user responsibility to share the required data
+between the threads in the parallel regions.
+
+Features not supported or with limited support for Cuda devices
+---
+
+- Reductions across the teams are not supported yet.
+
+- Cancellation constructs are not supported.
+
+- Doacross loop nest is not supported.
+
+- User-defined reductions are supported only for trivial types.
+
+- Nested parallelism: inner parallel regions are executed sequentially.
+
+- Static linking of libraries containing device code is not supported yet.
+
+- Automatic translation of math functions in target regions to device-specific
+  math functions is not implemented yet.
+
+- Debug information for OpenMP target regions is not supported yet.
+

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=338049&r1=338048&r2=338049&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Thu Jul 26 10:53:45 2018
@@ -216,7 +216,21 @@ OpenCL C Language Changes in Clang
 OpenMP Support in Clang
 

r338055 - [OPENMP, DOCS] Fixed typo, NFC.

2018-07-26 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Jul 26 11:40:41 2018
New Revision: 338055

URL: http://llvm.org/viewvc/llvm-project?rev=338055&view=rev
Log:
[OPENMP, DOCS] Fixed typo, NFC.

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=338055&r1=338054&r2=338055&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Thu Jul 26 11:40:41 2018
@@ -226,7 +226,7 @@ OpenMP Support in Clang
   option will be forwarded to the respective OpenMP device offloading toolchain
   described by the triple. For example passing the compute capability to
   the OpenMP NVPTX offloading toolchain can be done as follows:
-  `-Xopenmp-target=nvptx62-nvidia-cuda -march=sm_60`. For the case when only 
one
+  `-Xopenmp-target=nvptx64-nvidia-cuda -march=sm_60`. For the case when only 
one
   target offload toolchain is specified under the `-fopenmp-targets=`
   option, then the triple can be skipped: `-Xopenmp-target -march=sm_60`.
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r338139 - [OPENMP] Static variables on device must be externally visible.

2018-07-27 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Jul 27 10:37:32 2018
New Revision: 338139

URL: http://llvm.org/viewvc/llvm-project?rev=338139&view=rev
Log:
[OPENMP] Static variables on device must be externally visible.

Do not mark static variable as internal on the device as they must be
visible from the host to be mapped correctly.

Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=338139&r1=338138&r2=338139&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jul 27 10:37:32 2018
@@ -9504,6 +9504,21 @@ static GVALinkage basicGVALinkageForFunc
   return GVA_DiscardableODR;
 }
 
+static bool isDeclareTargetToDeclaration(const Decl *VD) {
+  for (const Decl *D : VD->redecls()) {
+if (!D->hasAttrs())
+  continue;
+if (const auto *Attr = D->getAttr())
+  return Attr->getMapType() == OMPDeclareTargetDeclAttr::MT_To;
+  }
+  if (const auto *V = dyn_cast(VD)) {
+if (const VarDecl *TD = V->getTemplateInstantiationPattern())
+  return isDeclareTargetToDeclaration(TD);
+  }
+
+  return false;
+}
+
 static GVALinkage adjustGVALinkageForAttributes(const ASTContext &Context,
 const Decl *D, GVALinkage L) {
   // See http://msdn.microsoft.com/en-us/library/xa0d9ste.aspx
@@ -9520,6 +9535,12 @@ static GVALinkage adjustGVALinkageForAtt
 // visible externally so they can be launched from host.
 if (L == GVA_DiscardableODR || L == GVA_Internal)
   return GVA_StrongODR;
+  } else if (Context.getLangOpts().OpenMP && 
Context.getLangOpts().OpenMPIsDevice &&
+ isDeclareTargetToDeclaration(D)) {
+// Static variables must be visible externally so they can be mapped from
+// host.
+if (L == GVA_Internal)
+  return GVA_StrongODR;
   }
   return L;
 }

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=338139&r1=338138&r2=338139&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Fri Jul 27 10:37:32 2018
@@ -18,12 +18,14 @@
 // CHECK-DAG: @d = global i32 0,
 // CHECK-DAG: @c = external global i32,
 // CHECK-DAG: @globals = global %struct.S zeroinitializer,
-// CHECK-DAG: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* 
@__omp_offloading__{{.+}}_globals_l[[@LINE+41]]_ctor to i8*)], section 
"llvm.metadata"
+// CHECK-DAG: @{{.+}}stat = weak_odr global %struct.S zeroinitializer,
+// CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* 
@__omp_offloading__{{.+}}_globals_l[[@LINE+42]]_ctor to i8*), i8* bitcast (void 
()* @__omp_offloading__{{.+}}_stat_l[[@LINE+43]]_ctor to i8*)], section 
"llvm.metadata"
 
 // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}()
 // CHECK-DAG: define {{.*}}void 
@{{.*}}TemplateClass{{.*}}(%class.TemplateClass* %{{.*}})
 // CHECK-DAG: define {{.*}}i32 
@{{.*}}TemplateClass{{.*}}f_method{{.*}}(%class.TemplateClass* %{{.*}})
-// CHECK-DAG: define {{.*}}void 
@__omp_offloading__{{.*}}_globals_l[[@LINE+36]]_ctor()
+// CHECK-DAG: define {{.*}}void 
@__omp_offloading__{{.*}}_globals_l[[@LINE+37]]_ctor()
+// CHECK-DAG: define {{.*}}void 
@__omp_offloading__{{.*}}_stat_l[[@LINE+37]]_ctor()
 
 #ifndef HEADER
 #define HEADER
@@ -60,6 +62,7 @@ int foo() { return 0; }
 int b = 15;
 int d;
 S globals(d);
+static S stat(d);
 #pragma omp end declare target
 int c;
 

Modified: cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp?rev=338139&r1=338138&r2=338139&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp 
(original)
+++ cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp Fri 
Jul 27 10:37:32 2018
@@ -15,7 +15,7 @@
 
 // SIMD-ONLY-NOT: {{__kmpc|__tgt}}
 
-// DEVICE-DAG: [[C_ADDR:.+]] = internal global i32 0,
+// DEVICE-DAG: [[C_ADDR:.+]] = weak_odr global i32 0,
 // DEVICE-DAG: [[CD_ADDR:@.+]] = global %struct.S zeroinitializer,
 // HOST-DAG: @[[C_ADDR:.+]] = internal global i32 0,
 // HOST-DAG: @[[CD_ADDR:.+]] = global %struct.S zeroinitializer,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r338155 - [DEBUGINFO] Disable unsupported debug info options for NVPTX target.

2018-07-27 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Jul 27 12:45:14 2018
New Revision: 338155

URL: http://llvm.org/viewvc/llvm-project?rev=338155&view=rev
Log:
[DEBUGINFO] Disable unsupported debug info options for NVPTX target.

Summary:
Some targets support only default set of the debug options and do not
support additional debug options, like NVPTX target. Patch introduced
virtual function supportsDebugInfoOptions() that can be overloaded
by the toolchain, checks if the target supports some debug
options and emits warning when an unsupported debug option is
found.

Reviewers: echristo

Subscribers: aprantl, JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D49148

Added:
cfe/trunk/test/Driver/cuda-unsupported-debug-options.cu
cfe/trunk/test/Driver/openmp-unsupported-debug-options.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.h
cfe/trunk/test/Driver/cuda-dwarf-2.cu
cfe/trunk/test/Driver/openmp-offload-gpu.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=338155&r1=338154&r2=338155&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri Jul 27 12:45:14 
2018
@@ -226,6 +226,9 @@ def warn_ignored_clang_option : Warning<
 def warn_drv_unsupported_opt_for_target : Warning<
   "optimization flag '%0' is not supported for target '%1'">,
   InGroup;
+def warn_drv_unsupported_debug_info_opt_for_target : Warning<
+  "debug information option '%0' is not supported for target '%1'">,
+  InGroup;
 def warn_c_kext : Warning<
   "ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
 def warn_drv_input_file_unused : Warning<

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=338155&r1=338154&r2=338155&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Jul 27 12:45:14 2018
@@ -72,6 +72,7 @@ def UnsupportedNan : DiagGroup<"unsuppor
 def UnsupportedAbs : DiagGroup<"unsupported-abs">;
 def UnsupportedCB : DiagGroup<"unsupported-cb">;
 def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
+def UnsupportedTargetOpt : DiagGroup<"unsupported-target-opt">;
 def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;
 def NullConversion : DiagGroup<"null-conversion">;
 def ImplicitConversionFloatingPointToBool :

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=338155&r1=338154&r2=338155&view=diff
==
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Fri Jul 27 12:45:14 2018
@@ -413,6 +413,11 @@ public:
 return llvm::DebuggerKind::GDB;
   }
 
+  /// Does this toolchain supports given debug info option or not.
+  virtual bool supportsDebugInfoOption(const llvm::opt::Arg *) const {
+return true;
+  }
+
   /// GetExceptionModel - Return the tool chain exception model.
   virtual llvm::ExceptionHandling
   GetExceptionModel(const llvm::opt::ArgList &Args) const;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=338155&r1=338154&r2=338155&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Jul 27 12:45:14 2018
@@ -919,34 +919,46 @@ static void RenderDebugEnablingArgs(cons
   }
 }
 
+static bool checkDebugInfoOption(const Arg *A, const ArgList &Args,
+ const Driver &D, const ToolChain &TC) {
+  assert(A && "Expected non-nullptr argument.");
+  if (TC.supportsDebugInfoOption(A))
+return true;
+  D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
+  << A->getAsString(Args) << TC.getTripleString();
+  return false;
+}
+
 static void RenderDebugInfoCompressionArgs(const ArgList &Args,
ArgStringList &CmdArgs,
-   const Driver &D) {
+   const Driver &D,
+   const ToolChain &TC) {
   const Arg *A = Args.getLastArg(options::OPT_gz, opt

r338158 - [DEBUG_INFO] Fix tests, NFC.

2018-07-27 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Jul 27 13:16:44 2018
New Revision: 338158

URL: http://llvm.org/viewvc/llvm-project?rev=338158&view=rev
Log:
[DEBUG_INFO] Fix tests, NFC.

Modified:
cfe/trunk/test/Driver/cuda-unsupported-debug-options.cu
cfe/trunk/test/Driver/openmp-unsupported-debug-options.c

Modified: cfe/trunk/test/Driver/cuda-unsupported-debug-options.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-unsupported-debug-options.cu?rev=338158&r1=338157&r2=338158&view=diff
==
--- cfe/trunk/test/Driver/cuda-unsupported-debug-options.cu (original)
+++ cfe/trunk/test/Driver/cuda-unsupported-debug-options.cu Fri Jul 27 13:16:44 
2018
@@ -1,6 +1,7 @@
 // REQUIRES: clang-driver
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: zlib
 
 // RUN: %clang -### -target x86_64-linux-gnu -c %s -g -gz 2>&1 | FileCheck %s
 // RUN: %clang -### -target x86_64-linux-gnu -c %s -gdwarf 
-fdebug-info-for-profiling 2>&1 | FileCheck %s

Modified: cfe/trunk/test/Driver/openmp-unsupported-debug-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openmp-unsupported-debug-options.c?rev=338158&r1=338157&r2=338158&view=diff
==
--- cfe/trunk/test/Driver/openmp-unsupported-debug-options.c (original)
+++ cfe/trunk/test/Driver/openmp-unsupported-debug-options.c Fri Jul 27 
13:16:44 2018
@@ -1,6 +1,7 @@
 // REQUIRES: clang-driver
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: zlib
 
 // RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -c %s -g -gz 2>&1 | FileCheck %s
 // RUN: %clang -### -target x86_64-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -c %s -gdwarf -fdebug-info-for-profiling 
2>&1 | FileCheck %s


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r338049 - [OPENMP] What's new for OpenMP in clang.

2018-07-29 Thread Alexey Bataev via cfe-commits
Yes, that would be good

Best regards,
Alexey Bataev

> 29 июля 2018 г., в 12:41, Jonas Hahnfeld via cfe-commits 
>  написал(а):
> 
> I just noticed that UsersManual says: "Clang supports all OpenMP 3.1 
> directives and clauses." Maybe this should link to OpenMPSupport?
> 
>> On 2018-07-26 19:53, Alexey Bataev via cfe-commits wrote:
>> Author: abataev
>> Date: Thu Jul 26 10:53:45 2018
>> New Revision: 338049
>> URL: http://llvm.org/viewvc/llvm-project?rev=338049&view=rev
>> Log:
>> [OPENMP] What's new for OpenMP in clang.
>> Updated ReleaseNotes + Status of the OpenMP support in clang.
>> Modified:
>>cfe/trunk/docs/OpenMPSupport.rst
>>cfe/trunk/docs/ReleaseNotes.rst
>> Modified: cfe/trunk/docs/OpenMPSupport.rst
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/OpenMPSupport.rst?rev=338049&r1=338048&r2=338049&view=diff
>> ==
>> --- cfe/trunk/docs/OpenMPSupport.rst (original)
>> +++ cfe/trunk/docs/OpenMPSupport.rst Thu Jul 26 10:53:45 2018
>> @@ -10,13 +10,15 @@
>> .. role:: partial
>> .. role:: good
>> +.. contents::
>> +   :local:
>> +
>> ==
>> OpenMP Support
>> ==
>> -Clang fully supports OpenMP 3.1 + some elements of OpenMP 4.5. Clang
>> supports offloading to X86_64, AArch64 and PPC64[LE] devices.
>> -Support for Cuda devices is not ready yet.
>> -The status of major OpenMP 4.5 features support in Clang.
>> +Clang fully supports OpenMP 4.5. Clang supports offloading to X86_64, 
>> AArch64,
>> +PPC64[LE] and has `basic support for Cuda devices`_.
>> Standalone directives
>> =
>> @@ -35,7 +37,7 @@ Standalone directives
>> * #pragma omp target: :good:`Complete`.
>> -* #pragma omp declare target: :partial:`Partial`.  No full codegen support.
>> +* #pragma omp declare target: :good:`Complete`.
>> * #pragma omp teams: :good:`Complete`.
>> @@ -64,5 +66,66 @@ Combined directives
>> * #pragma omp target teams distribute parallel for [simd]: :good:`Complete`.
>> -Clang does not support any constructs/updates from upcoming OpenMP
>> 5.0 except for `reduction`-based clauses in the `task` and
>> `target`-based directives.
>> -In addition, the LLVM OpenMP runtime `libomp` supports the OpenMP
>> Tools Interface (OMPT) on x86, x86_64, AArch64, and PPC64 on Linux,
>> Windows, and mac OS.
>> +Clang does not support any constructs/updates from upcoming OpenMP 5.0 
>> except
>> +for `reduction`-based clauses in the `task` and `target`-based directives.
>> +
>> +In addition, the LLVM OpenMP runtime `libomp` supports the OpenMP Tools
>> +Interface (OMPT) on x86, x86_64, AArch64, and PPC64 on Linux,
>> Windows, and mac OS.
>> +ows, and mac OS.
>> +
>> +.. _basic support for Cuda devices:
>> +
>> +Cuda devices support
>> +
>> +
>> +Directives execution modes
>> +--
>> +
>> +Clang code generation for target regions supports two modes: the SPMD and
>> +non-SPMD modes. Clang chooses one of these two modes automatically based on 
>> the
>> +way directives and clauses on those directives are used. The SPMD mode uses 
>> a
>> +simplified set of runtime functions thus increasing performance at the cost 
>> of
>> +supporting some OpenMP features. The non-SPMD mode is the most generic mode 
>> and
>> +supports all currently available OpenMP features. The compiler will always
>> +attempt to use the SPMD mode wherever possible. SPMD mode will not be used 
>> if:
>> +
>> +   - The target region contains an `if()` clause that refers to a `parallel`
>> + directive.
>> +
>> +   - The target region contains a `parallel` directive with a 
>> `num_threads()`
>> + clause.
>> +
>> +   - The target region contains user code (other than OpenMP-specific
>> + directives) in between the `target` and the `parallel` directives.
>> +
>> +Data-sharing modes
>> +--
>> +
>> +Clang supports two data-sharing models for Cuda devices: `Generic` and 
>> `Cuda`
>> +modes. The default mode is `Generic`. `Cuda` mode can give an additional
>> +performance and can be activated using the `-fopenmp-cuda-mode` flag. In
>> +`Generic` mode all local variables that can be shared in the parallel 
>> regions
>> +are stored in the global memory. In `Cuda` mode local variables are not 
>> shared
>> +between the thread

r338252 - [OPENMP] Modify the info about OpenMP support in UsersManual, NFC.

2018-07-30 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jul 30 07:44:29 2018
New Revision: 338252

URL: http://llvm.org/viewvc/llvm-project?rev=338252&view=rev
Log:
[OPENMP] Modify the info about OpenMP support in UsersManual, NFC.

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=338252&r1=338251&r2=338252&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Mon Jul 30 07:44:29 2018
@@ -2155,13 +2155,8 @@ Objective-C++ Language Features
 OpenMP Features
 ===
 
-Clang supports all OpenMP 3.1 directives and clauses.  In addition, some
-features of OpenMP 4.0 are supported.  For example, ``#pragma omp simd``,
-``#pragma omp for simd``, ``#pragma omp parallel for simd`` directives, 
extended
-set of atomic constructs, ``proc_bind`` clause for all parallel-based
-directives, ``depend`` clause for ``#pragma omp task`` directive (except for
-array sections), ``#pragma omp cancel`` and ``#pragma omp cancellation point``
-directives, and ``#pragma omp taskgroup`` directive.
+Clang supports all OpenMP 4.5 directives and clauses. See :doc:`OpenMPSupport`
+for additional details.
 
 Use `-fopenmp` to enable OpenMP. Support for OpenMP can be disabled with
 `-fno-openmp`.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r338399 - [OPENMP] Prevent problems with linking of the static variables.

2018-07-31 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Jul 31 09:40:15 2018
New Revision: 338399

URL: http://llvm.org/viewvc/llvm-project?rev=338399&view=rev
Log:
[OPENMP] Prevent problems with linking of the static variables.

No need to change the linkage, we can avoid the problem using special variable. 
That points to the original variable and, thus, prevent some of the 
optimizations that might break the compilation.

Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=338399&r1=338398&r2=338399&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jul 31 09:40:15 2018
@@ -9535,21 +9535,6 @@ static GVALinkage basicGVALinkageForFunc
   return GVA_DiscardableODR;
 }
 
-static bool isDeclareTargetToDeclaration(const Decl *VD) {
-  for (const Decl *D : VD->redecls()) {
-if (!D->hasAttrs())
-  continue;
-if (const auto *Attr = D->getAttr())
-  return Attr->getMapType() == OMPDeclareTargetDeclAttr::MT_To;
-  }
-  if (const auto *V = dyn_cast(VD)) {
-if (const VarDecl *TD = V->getTemplateInstantiationPattern())
-  return isDeclareTargetToDeclaration(TD);
-  }
-
-  return false;
-}
-
 static GVALinkage adjustGVALinkageForAttributes(const ASTContext &Context,
 const Decl *D, GVALinkage L) {
   // See http://msdn.microsoft.com/en-us/library/xa0d9ste.aspx
@@ -9566,12 +9551,6 @@ static GVALinkage adjustGVALinkageForAtt
 // visible externally so they can be launched from host.
 if (L == GVA_DiscardableODR || L == GVA_Internal)
   return GVA_StrongODR;
-  } else if (Context.getLangOpts().OpenMP && 
Context.getLangOpts().OpenMPIsDevice &&
- isDeclareTargetToDeclaration(D)) {
-// Static variables must be visible externally so they can be mapped from
-// host.
-if (L == GVA_Internal)
-  return GVA_StrongODR;
   }
   return L;
 }

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=338399&r1=338398&r2=338399&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jul 31 09:40:15 2018
@@ -8109,6 +8109,19 @@ void CGOpenMPRuntime::registerTargetGlob
   VarName = CGM.getMangledName(VD);
   VarSize = CGM.getContext().getTypeSizeInChars(VD->getType());
   Linkage = CGM.getLLVMLinkageVarDefinition(VD, /*IsConstant=*/false);
+  // Temp solution to prevent optimizations of the internal variables.
+  if (CGM.getLangOpts().OpenMPIsDevice && !VD->isExternallyVisible()) {
+std::string RefName = getName({VarName, "ref"});
+if (!CGM.GetGlobalValue(RefName)) {
+  llvm::Constant *AddrRef =
+  getOrCreateInternalVariable(Addr->getType(), RefName);
+  auto *GVAddrRef = cast(AddrRef);
+  GVAddrRef->setConstant(/*Val=*/true);
+  GVAddrRef->setLinkage(llvm::GlobalValue::InternalLinkage);
+  GVAddrRef->setInitializer(Addr);
+  CGM.addCompilerUsedGlobal(GVAddrRef);
+}
+  }
   break;
 case OMPDeclareTargetDeclAttr::MT_Link:
   Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryLink;

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=338399&r1=338398&r2=338399&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Tue Jul 31 09:40:15 2018
@@ -18,14 +18,15 @@
 // CHECK-DAG: @d = global i32 0,
 // CHECK-DAG: @c = external global i32,
 // CHECK-DAG: @globals = global %struct.S zeroinitializer,
-// CHECK-DAG: @{{.+}}stat = weak_odr global %struct.S zeroinitializer,
-// CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* 
@__omp_offloading__{{.+}}_globals_l[[@LINE+42]]_ctor to i8*), i8* bitcast (void 
()* @__omp_offloading__{{.+}}_stat_l[[@LINE+43]]_ctor to i8*)], section 
"llvm.metadata"
+// CHECK-DAG: [[STAT:@.+stat]] = internal global %struct.S zeroinitializer,
+// CHECK-DAG: [[STAT_REF:@.+]] = internal constant %struct.S* [[STAT]]
+// CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* 
@__omp_offloading__{{.+}}_globals_l[[@LINE+42]]_ctor to i8*), i8* bitcast (void 
()* @__omp_offloading__{{.+}}_stat_l[[@LINE+43]]_ctor to i8*)],
+// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast 
(%struct

r338413 - [OPENMP] Change linkage of offloading symbols to support dropping

2018-07-31 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Jul 31 11:27:42 2018
New Revision: 338413

URL: http://llvm.org/viewvc/llvm-project?rev=338413&view=rev
Log:
[OPENMP] Change linkage of offloading symbols to support dropping
offload targets.

Changed the linkage of omp_offloading.img_start. and 
omp_offloading.img_end. symbols from external to external weak to allow 
dropping of some targets during linking.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/target_codegen.cpp
cfe/trunk/test/OpenMP/target_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_for_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_if_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_num_threads_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_simd_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_depend_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=338413&r1=338412&r2=338413&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jul 31 11:27:42 2018
@@ -3750,11 +3750,13 @@ CGOpenMPRuntime::createOffloadingBinaryD
 StringRef T = Device.getTriple();
 std::string BeginName = getName({"omp_offloading", "img_start", ""});
 auto *ImgBegin = new llvm::GlobalVariable(
-M, CGM.Int8Ty, /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage,
+M, CGM.Int8Ty, /*isConstant=*/true,
+llvm::GlobalValue::ExternalWeakLinkage,
 /*Initializer=*/nullptr, Twine(BeginName).concat(T));
 std::string EndName = getName({"omp_offloading", "img_end", ""});
 auto *ImgEnd = new llvm::GlobalVariable(
-M, CGM.Int8Ty, /*isConstant=*/true, llvm::GlobalValue::ExternalLinkage,
+M, CGM.Int8Ty, /*isConstant=*/true,
+llvm::GlobalValue::ExternalWeakLinkage,
 /*Initializer=*/nullptr, Twine(EndName).concat(T));
 
 llvm::Constant *Data[] = {ImgBegin, ImgEnd, HostEntriesBegin,

Modified: cfe/trunk/test/OpenMP/target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_codegen.cpp?rev=338413&r1=338412&r2=338413&view=diff
==
--- cfe/trunk/test/OpenMP/target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_codegen.cpp Tue Jul 31 11:27:42 2018
@@ -85,8 +85,8 @@
 // Check if offloading descriptor is created.
 // CHECK: [[ENTBEGIN:@.+]] = external constant [[ENTTY]]
 // CHECK: [[ENTEND:@.+]] = external constant [[ENTTY]]
-// CHECK: [[DEVBEGIN:@.+]] = external constant i8
-// CHECK: [[DEVEND:@.+]] = external constant i8
+// CHECK: [[DEVBEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEVEND:@.+]] = extern_weak constant i8
 // CHECK: [[IMAGES:@.+]] = internal unnamed_addr constant [1 x [[DEVTY]]] 
[{{.+}} { i8* [[DEVBEGIN]], i8* [[DEVEND]], [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* 
[[ENTEND]] }], comdat($[[REGFN]])
 // CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 1, [[DEVTY]]* 
getelementptr inbounds ([1 x [[DEVTY]]], [1 x [[DEVTY]]]* [[IMAGES]], i32 0, 
i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
 

Modified: cfe/trunk/test/OpenMP/target_codegen_registration.cpp
URL: 

r325145 - [OpenMP] Fix trailing space when printing pragmas, by Joel. E. Denny

2018-02-14 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Feb 14 09:38:47 2018
New Revision: 325145

URL: http://llvm.org/viewvc/llvm-project?rev=325145&view=rev
Log:
[OpenMP] Fix trailing space when printing pragmas, by Joel. E. Denny

Summary:
-ast-print prints omp pragmas with a trailing space.  While this
behavior is likely of little concern to most users, surely it's
unintentional, and it's annoying for some source-level work I'm
pursuing.  This patch focuses on omp pragmas, but it also fixes
init_seg and loop hint pragmas because they share implementation.

The testing strategy here is to add usually just one '{{$}}' per
relevant -ast-print test file.  This seems to achieve good code
coverage.  However, this strategy is probably easy to forget as the
tests evolve.  That's probably fine as this fix is far from critical.
The main goal of the testing is to aid the initial review.

This patch also adds a fixme for "#pragma unroll", which prints as
"#pragma unroll (enable)", which is invalid syntax.

Reviewers: ABataev

Reviewed By: ABataev

Subscribers: guansong, cfe-commits

Differential Revision: https://reviews.llvm.org/D43204

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/test/Misc/ast-print-pragmas.cpp
cfe/trunk/test/OpenMP/atomic_ast_print.cpp
cfe/trunk/test/OpenMP/barrier_ast_print.cpp
cfe/trunk/test/OpenMP/cancel_ast_print.cpp
cfe/trunk/test/OpenMP/cancellation_point_ast_print.cpp
cfe/trunk/test/OpenMP/critical_ast_print.cpp
cfe/trunk/test/OpenMP/declare_reduction_ast_print.c
cfe/trunk/test/OpenMP/declare_reduction_ast_print.cpp
cfe/trunk/test/OpenMP/declare_simd_ast_print.c
cfe/trunk/test/OpenMP/declare_simd_ast_print.cpp
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp
cfe/trunk/test/OpenMP/distribute_ast_print.cpp
cfe/trunk/test/OpenMP/distribute_dist_schedule_ast_print.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_ast_print.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_ast_print.cpp
cfe/trunk/test/OpenMP/distribute_simd_ast_print.cpp
cfe/trunk/test/OpenMP/flush_ast_print.cpp
cfe/trunk/test/OpenMP/for_ast_print.cpp
cfe/trunk/test/OpenMP/for_simd_ast_print.cpp
cfe/trunk/test/OpenMP/master_ast_print.cpp
cfe/trunk/test/OpenMP/ordered_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_for_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp
cfe/trunk/test/OpenMP/parallel_sections_ast_print.cpp
cfe/trunk/test/OpenMP/sections_ast_print.cpp
cfe/trunk/test/OpenMP/simd_ast_print.cpp
cfe/trunk/test/OpenMP/single_ast_print.cpp
cfe/trunk/test/OpenMP/target_ast_print.cpp
cfe/trunk/test/OpenMP/target_data_ast_print.cpp
cfe/trunk/test/OpenMP/target_data_use_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp
cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp
cfe/trunk/test/OpenMP/target_is_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_parallel_ast_print.cpp
cfe/trunk/test/OpenMP/target_parallel_for_ast_print.cpp
cfe/trunk/test/OpenMP/target_parallel_for_is_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_ast_print.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_is_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_parallel_is_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_simd_ast_print.cpp
cfe/trunk/test/OpenMP/target_teams_ast_print.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_ast_print.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_ast_print.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_is_device_ptr_ast_print.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_ast_print.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_is_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_ast_print.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_simd_is_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_teams_is_device_ptr_ast_print.cpp
cfe/trunk/test/OpenMP/target_update_ast_print.cpp
cfe/trunk/test/OpenMP/task_ast_print.cpp
cfe/trunk/test/OpenMP/taskgroup_ast_print.cpp
cfe/trunk/test/OpenMP/taskloop_ast_print.cpp
cfe/trunk/test/OpenMP/taskloop_simd_ast_print.cpp
cfe/trunk/test/OpenMP/taskwait_ast_print.cpp
cfe/trunk/test/OpenMP/taskyield_ast_print.cpp
cfe/trunk/test/OpenMP/teams_ast_print.cpp
cfe/trunk/test/OpenMP/teams_distribute_ast_print.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_ast_print.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_ast_print.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_ast_print.cpp
cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp
cfe/trunk/test/PCH/pragma-loop.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/

r325302 - [OPENMP] Fix PR38398: compiler crash on standalone pragma ordered with depend sink|source clause.

2018-02-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Feb 15 14:42:57 2018
New Revision: 325302

URL: http://llvm.org/viewvc/llvm-project?rev=325302&view=rev
Log:
[OPENMP] Fix PR38398: compiler crash on standalone pragma ordered with depend 
sink|source clause.

Patch fixes compiler crash on standalone #pragmas ordered with
depend(sink|source) clauses.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/ordered_messages.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=325302&r1=325301&r2=325302&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Feb 15 14:42:57 2018
@@ -11367,138 +11367,135 @@ Sema::ActOnOpenMPDependClause(OpenMPDepe
   TotalDepCount.setIsUnsigned(/*Val=*/true);
 }
   }
-  if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) ||
-  DSAStack->getParentOrderedRegionParam()) {
-for (auto &RefExpr : VarList) {
-  assert(RefExpr && "NULL expr in OpenMP shared clause.");
-  if (isa(RefExpr)) {
+  for (auto &RefExpr : VarList) {
+assert(RefExpr && "NULL expr in OpenMP shared clause.");
+if (isa(RefExpr)) {
+  // It will be analyzed later.
+  Vars.push_back(RefExpr);
+  continue;
+}
+
+SourceLocation ELoc = RefExpr->getExprLoc();
+auto *SimpleExpr = RefExpr->IgnoreParenCasts();
+if (DepKind == OMPC_DEPEND_sink) {
+  if (DSAStack->getParentOrderedRegionParam() &&
+  DepCounter >= TotalDepCount) {
+Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr);
+continue;
+  }
+  ++DepCounter;
+  // OpenMP  [2.13.9, Summary]
+  // depend(dependence-type : vec), where dependence-type is:
+  // 'sink' and where vec is the iteration vector, which has the form:
+  //  x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn]
+  // where n is the value specified by the ordered clause in the loop
+  // directive, xi denotes the loop iteration variable of the i-th nested
+  // loop associated with the loop directive, and di is a constant
+  // non-negative integer.
+  if (CurContext->isDependentContext()) {
 // It will be analyzed later.
 Vars.push_back(RefExpr);
 continue;
   }
+  SimpleExpr = SimpleExpr->IgnoreImplicit();
+  OverloadedOperatorKind OOK = OO_None;
+  SourceLocation OOLoc;
+  Expr *LHS = SimpleExpr;
+  Expr *RHS = nullptr;
+  if (auto *BO = dyn_cast(SimpleExpr)) {
+OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode());
+OOLoc = BO->getOperatorLoc();
+LHS = BO->getLHS()->IgnoreParenImpCasts();
+RHS = BO->getRHS()->IgnoreParenImpCasts();
+  } else if (auto *OCE = dyn_cast(SimpleExpr)) {
+OOK = OCE->getOperator();
+OOLoc = OCE->getOperatorLoc();
+LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts();
+RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts();
+  } else if (auto *MCE = dyn_cast(SimpleExpr)) {
+OOK = MCE->getMethodDecl()
+  ->getNameInfo()
+  .getName()
+  .getCXXOverloadedOperator();
+OOLoc = MCE->getCallee()->getExprLoc();
+LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts();
+RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts();
+  }
+  SourceLocation ELoc;
+  SourceRange ERange;
+  auto Res = getPrivateItem(*this, LHS, ELoc, ERange,
+/*AllowArraySection=*/false);
+  if (Res.second) {
+// It will be analyzed later.
+Vars.push_back(RefExpr);
+  }
+  ValueDecl *D = Res.first;
+  if (!D)
+continue;
 
-  SourceLocation ELoc = RefExpr->getExprLoc();
-  auto *SimpleExpr = RefExpr->IgnoreParenCasts();
-  if (DepKind == OMPC_DEPEND_sink) {
-if (DepCounter >= TotalDepCount) {
-  Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr);
-  continue;
-}
-++DepCounter;
-// OpenMP  [2.13.9, Summary]
-// depend(dependence-type : vec), where dependence-type is:
-// 'sink' and where vec is the iteration vector, which has the form:
-//  x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn]
-// where n is the value specified by the ordered clause in the loop
-// directive, xi denotes the loop iteration variable of the i-th nested
-// loop associated with the loop directive, and di is a constant
-// non-negative integer.
-if (CurContext->isDependentContext()) {
-  // It will be analyzed later.
-  Vars.push_back(RefExpr);
-  continue;
-}
-SimpleExpr = SimpleExpr->IgnoreImplicit();
-OverloadedOperatorKind OOK = OO_None;
-SourceLocation OOLoc;
-Expr *LHS = SimpleExpr;
-Expr *RHS = nullptr;
-if (au

r325304 - [OPENMP] Fix PR36399: Crash on C code with ordered doacross construct.

2018-02-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Feb 15 15:39:43 2018
New Revision: 325304

URL: http://llvm.org/viewvc/llvm-project?rev=325304&view=rev
Log:
[OPENMP] Fix PR36399: Crash on C code with ordered doacross construct.

Codegen for ordered with doacross construct might produce incorrect code
because of missing cleanup scope for the construct. Without this scope
the final runtime function call could be emitted in the wrong order that
leads to incorrect codegen.

Added:
cfe/trunk/test/OpenMP/ordered_doacross_codegen.c
Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=325304&r1=325303&r2=325304&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Thu Feb 15 15:39:43 2018
@@ -2230,6 +2230,7 @@ bool CodeGenFunction::EmitOMPWorksharing
   incrementProfileCounter(&S);
 }
 
+RunCleanupsScope DoacrossCleanupScope(*this);
 bool Ordered = false;
 if (auto *OrderedClause = S.getSingleClause()) {
   if (OrderedClause->getNumForLoops())
@@ -2366,6 +2367,7 @@ bool CodeGenFunction::EmitOMPWorksharing
   return CGF.Builder.CreateIsNotNull(
   CGF.EmitLoadOfScalar(IL, S.getLocStart()));
 });
+DoacrossCleanupScope.ForceCleanup();
 // We're now done with the loop, so jump to the continuation block.
 if (ContBlock) {
   EmitBranch(ContBlock);

Added: cfe/trunk/test/OpenMP/ordered_doacross_codegen.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/ordered_doacross_codegen.c?rev=325304&view=auto
==
--- cfe/trunk/test/OpenMP/ordered_doacross_codegen.c (added)
+++ cfe/trunk/test/OpenMP/ordered_doacross_codegen.c Thu Feb 15 15:39:43 2018
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -emit-pch -o 
%t %s
+// RUN: %clang_cc1 -fopenmp-simd -triple x86_64-unknown-unknown -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+// CHECK: [[KMP_DIM:%.+]] = type { i64, i64, i64 }
+extern int n;
+int a[10], b[10], c[10], d[10];
+void foo();
+
+// CHECK-LABEL: @main()
+int main() {
+  int i;
+// CHECK: [[DIMS:%.+]] = alloca [[KMP_DIM]],
+// CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT:%.+]])
+// CHECK: icmp
+// CHECK-NEXT: br i1 %
+// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
+// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 [[CAST]], i8 0, i64 24, 
i1 false)
+// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, 
i32 1
+// CHECK: store i64 %{{.+}}, i64* %
+// CHECK: getelementptr inbounds [[KMP_DIM]], [[KMP_DIM]]* [[DIMS]], i32 0, 
i32 2
+// CHECK: store i64 1, i64* %
+// CHECK: [[CAST:%.+]] = bitcast [[KMP_DIM]]* [[DIMS]] to i8*
+// CHECK: call void @__kmpc_doacross_init([[IDENT]], i32 [[GTID]], i32 1, i8* 
[[CAST]])
+// CHECK: call void @__kmpc_for_static_init_4(
+#pragma omp for ordered(1)
+  for (i = 0; i < n; ++i) {
+a[i] = b[i] + 1;
+foo();
+// CHECK: call void [[FOO:.+]](
+// CHECK: load i32, i32* [[CNT:%.+]],
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
+// CHECK-NEXT: call void @__kmpc_doacross_post([[IDENT]], i32 [[GTID]], i64* 
[[TMP]])
+#pragma omp ordered depend(source)
+c[i] = c[i] + 1;
+foo();
+// CHECK: call void [[FOO]]
+// CHECK: load i32, i32* [[CNT]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 2
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: store i64 %{{.+}}, i64* [[TMP:%.+]],
+// CHECK-NEXT: call void @__kmpc_doacross_wait([[IDENT]], i32 [[GTID]], i64* 
[[TMP]])
+#pragma omp ordered depend(sink : i - 2)
+d[i] = a[i - 2];
+  }
+  // CHECK: call void @__kmpc_for_static_fini(
+  // CHECK: call void @__kmpc_doacross_fini([[IDENT]], i32 [[GTID]])
+  // CHECK: ret i32 0
+  return 0;
+}
+#endif // HEADER


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r325369 - [OPENMP] Fix parsing of the directives with inner directives.

2018-02-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Feb 16 10:36:44 2018
New Revision: 325369

URL: http://llvm.org/viewvc/llvm-project?rev=325369&view=rev
Log:
[OPENMP] Fix parsing of the directives with inner directives.

The parsing may lead to compiler hanging because of the incorrect
processing of inner OpenMP pragmas.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/test/OpenMP/openmp_check.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=325369&r1=325368&r2=325369&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Feb 16 10:36:44 
2018
@@ -1072,7 +1072,7 @@ def warn_pragma_expected_colon_r_paren :
 def err_omp_unknown_directive : Error<
   "expected an OpenMP directive">;
 def err_omp_unexpected_directive : Error<
-  "unexpected OpenMP directive '#pragma omp %0'">;
+  "unexpected OpenMP directive %select{|'#pragma omp %1'}0">;
 def err_omp_expected_punc : Error<
   "expected ',' or ')' in '%0' %select{clause|directive}1">;
 def err_omp_unexpected_clause : Error<

Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=325369&r1=325368&r2=325369&view=diff
==
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Fri Feb 16 10:36:44 2018
@@ -851,7 +851,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpen
   case OMPD_target_teams_distribute_parallel_for_simd:
   case OMPD_target_teams_distribute_simd:
 Diag(Tok, diag::err_omp_unexpected_directive)
-<< getOpenMPDirectiveName(DKind);
+<< 1 << getOpenMPDirectiveName(DKind);
 break;
   }
   while (Tok.isNot(tok::annot_pragma_openmp_end))
@@ -1107,7 +1107,7 @@ StmtResult Parser::ParseOpenMPDeclarativ
   case OMPD_declare_target:
   case OMPD_end_declare_target:
 Diag(Tok, diag::err_omp_unexpected_directive)
-<< getOpenMPDirectiveName(DKind);
+<< 1 << getOpenMPDirectiveName(DKind);
 SkipUntil(tok::annot_pragma_openmp_end);
 break;
   case OMPD_unknown:

Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=325369&r1=325368&r2=325369&view=diff
==
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Fri Feb 16 10:36:44 2018
@@ -2117,9 +2117,21 @@ PragmaOpenMPHandler::HandlePragma(Prepro
   Tok.setKind(tok::annot_pragma_openmp);
   Tok.setLocation(FirstTok.getLocation());
 
-  while (Tok.isNot(tok::eod)) {
+  while (Tok.isNot(tok::eod) && Tok.isNot(tok::eof)) {
 Pragma.push_back(Tok);
 PP.Lex(Tok);
+if (Tok.is(tok::annot_pragma_openmp)) {
+  PP.Diag(Tok, diag::err_omp_unexpected_directive) << 0;
+  unsigned InnerPragmaCnt = 1;
+  while (InnerPragmaCnt != 0) {
+PP.Lex(Tok);
+if (Tok.is(tok::annot_pragma_openmp))
+  ++InnerPragmaCnt;
+else if (Tok.is(tok::annot_pragma_openmp_end))
+  --InnerPragmaCnt;
+  }
+  PP.Lex(Tok);
+}
   }
   SourceLocation EodLoc = Tok.getLocation();
   Tok.startToken();

Modified: cfe/trunk/test/OpenMP/openmp_check.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/openmp_check.cpp?rev=325369&r1=325368&r2=325369&view=diff
==
--- cfe/trunk/test/OpenMP/openmp_check.cpp (original)
+++ cfe/trunk/test/OpenMP/openmp_check.cpp Fri Feb 16 10:36:44 2018
@@ -7,7 +7,11 @@
 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++11 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 
+#define p _Pragma("omp parallel")
+
 int nested(int a) {
+#pragma omp parallel p // expected-error {{unexpected OpenMP directive}}
+  ++a;
 #pragma omp parallel
   ++a;
 
@@ -16,8 +20,6 @@ int nested(int a) {
   // expected-warning@-2 {{'auto' type specifier is a C++11 extension}}
   // expected-error@-3 {{expected expression}}
   // expected-error@-4 {{expected ';' at end of declaration}}
-#else
-  // expected-no-diagnostics
 #endif
 
 #pragma omp parallel


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r325373 - [OPENMP] Fix PR35873: Fix data-sharing attributes for const variables.

2018-02-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Feb 16 11:16:54 2018
New Revision: 325373

URL: http://llvm.org/viewvc/llvm-project?rev=325373&view=rev
Log:
[OPENMP] Fix PR35873: Fix data-sharing attributes for const variables.

Compiler erroneously returned wrong data-sharing attributes for the
constant variables if they have explictly specified attributes.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=325373&r1=325372&r2=325373&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Feb 16 11:16:54 2018
@@ -1025,7 +1025,7 @@ DSAStackTy::DSAVarData DSAStackTy::getTo
 D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; },
 MatchesAlways, FromParent);
 if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr)
-  return DVar;
+  return DVarTemp;
 
 DVar.CKind = OMPC_shared;
 return DVar;

Modified: cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_for_codegen.cpp?rev=325373&r1=325372&r2=325373&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_for_codegen.cpp Fri Feb 16 11:16:54 2018
@@ -354,9 +354,9 @@ int foo() {return 0;};
 
 // TERM_DEBUG-LABEL: parallel_for
 // CLEANUP: parallel_for
-void parallel_for(float *a, int n) {
+void parallel_for(float *a, const int n) {
   float arr[n];
-#pragma omp parallel for schedule(static, 5) private(arr)
+#pragma omp parallel for schedule(static, 5) private(arr) default(none) 
firstprivate(n) shared(a)
   // TERM_DEBUG-NOT: __kmpc_global_thread_num
   // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg 
[[DBG_LOC_START:![0-9]+]]
   // TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}()
@@ -370,7 +370,7 @@ void parallel_for(float *a, int n) {
   // CLEANUP: call void @__kmpc_for_static_init_4u({{.+}})
   // CLEANUP: call void @__kmpc_for_static_fini({{.+}})
   for (unsigned i = 131071; i <= 2147483647; i += 127)
-a[i] += foo() + arr[i];
+a[i] += foo() + arr[i] + n;
 }
 // Check source line corresponds to "#pragma omp parallel for schedule(static, 
5)" above:
 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-4]],


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r325391 - [OPENMP] Do not emit messages for templates in declare target

2018-02-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Feb 16 13:23:23 2018
New Revision: 325391

URL: http://llvm.org/viewvc/llvm-project?rev=325391&view=rev
Log:
[OPENMP] Do not emit messages for templates in declare target
constructs.

The compiler may emit some extra warnings for functions, that are
implicit specialization of the templates, declared in the target region.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_target_messages.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=325391&r1=325390&r2=325391&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Feb 16 13:23:23 2018
@@ -12798,7 +12798,7 @@ static void checkDeclInTargetContext(Sou
  Sema &SemaRef, Decl *D) {
   if (!D)
 return;
-  Decl *LD = nullptr;
+  const Decl *LD = nullptr;
   if (isa(D)) {
 LD = cast(D)->getDefinition();
   } else if (isa(D)) {
@@ -12814,22 +12814,29 @@ static void checkDeclInTargetContext(Sou
 ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
   return;
 }
-
-  } else if (isa(D)) {
+  } else if (auto *F = dyn_cast(D)) {
 const FunctionDecl *FD = nullptr;
-if (cast(D)->hasBody(FD))
-  LD = const_cast(FD);
-
-// If the definition is associated with the current declaration in the
-// target region (it can be e.g. a lambda) that is legal and we do not need
-// to do anything else.
-if (LD == D) {
-  Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(
-  SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To);
-  D->addAttr(A);
-  if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener())
-ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
-  return;
+if (cast(D)->hasBody(FD)) {
+  LD = FD;
+  // If the definition is associated with the current declaration in the
+  // target region (it can be e.g. a lambda) that is legal and we do not
+  // need to do anything else.
+  if (LD == D) {
+Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(
+SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To);
+D->addAttr(A);
+if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener())
+  ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
+return;
+  }
+} else if (F->isFunctionTemplateSpecialization() &&
+   F->getTemplateSpecializationKind() ==
+   TSK_ImplicitInstantiation) {
+  // Check if the function is implicitly instantiated from the template
+  // defined in the declare target region.
+  const FunctionTemplateDecl *FTD = F->getPrimaryTemplate();
+  if (FTD && FTD->hasAttr())
+return;
 }
   }
   if (!LD)
@@ -12841,7 +12848,7 @@ static void checkDeclInTargetContext(Sou
   SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context);
   SemaRef.Diag(SL, diag::note_used_here) << SR;
 } else {
-  DeclContext *DC = LD->getDeclContext();
+  const DeclContext *DC = LD->getDeclContext();
   while (DC) {
 if (isa(DC) &&
 cast(DC)->hasAttr())
@@ -12894,7 +12901,8 @@ void Sema::checkDeclIsAllowedInOpenMPTar
 if ((E || !VD->getType()->isIncompleteType()) &&
 !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) {
   // Mark decl as declared target to prevent further diagnostic.
-  if (isa(VD) || isa(VD)) {
+  if (isa(VD) || isa(VD) ||
+  isa(VD)) {
 Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(
 Context, OMPDeclareTargetDeclAttr::MT_To);
 VD->addAttr(A);
@@ -12914,10 +12922,21 @@ void Sema::checkDeclIsAllowedInOpenMPTar
   return;
 }
   }
+  if (auto *FTD = dyn_cast(D)) {
+if (FTD->hasAttr() &&
+(FTD->getAttr()->getMapType() ==
+ OMPDeclareTargetDeclAttr::MT_Link)) {
+  assert(IdLoc.isValid() && "Source location is expected");
+  Diag(IdLoc, diag::err_omp_function_in_link_clause);
+  Diag(FTD->getLocation(), diag::note_defined_here) << FTD;
+  return;
+}
+  }
   if (!E) {
 // Checking declaration inside declare target region.
 if (!D->hasAttr() &&
-(isa(D) || isa(D))) {
+(isa(D) || isa(D) ||
+ isa(D))) {
   Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(
   Context, OMPDeclareTargetDeclAttr::MT_To);
   D->addAttr(A);

Modified: cfe/trunk/test/OpenMP/declare_target_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_messages.cpp?rev=325391&r1=325390&r2=325391&view=diff
==
--- cfe/trunk/test/OpenMP/declare_target_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_messages.cpp Fri Feb 16 13:23:23 2018
@@ -33,6 +33,33 @@ struct NonT {

r325812 - [OPENMP] Require valid SourceLocation in function call, NFC.

2018-02-22 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Feb 22 10:33:31 2018
New Revision: 325812

URL: http://llvm.org/viewvc/llvm-project?rev=325812&view=rev
Log:
[OPENMP] Require valid SourceLocation in function call, NFC.

Removed default empty SourceLocation argument from `emitCall` function
and require valid location.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=325812&r1=325811&r2=325812&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Feb 22 10:33:31 2018
@@ -8057,9 +8057,10 @@ void CGOpenMPRuntime::emitDoacrossOrdere
   CGF.EmitRuntimeCall(RTLFn, Args);
 }
 
-void CGOpenMPRuntime::emitCall(CodeGenFunction &CGF, llvm::Value *Callee,
-   ArrayRef Args,
-   SourceLocation Loc) const {
+void CGOpenMPRuntime::emitCall(CodeGenFunction &CGF, SourceLocation Loc,
+   llvm::Value *Callee,
+   ArrayRef Args) const {
+  assert(Loc.isValid() && "Outlined function call location must be valid.");
   auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
 
   if (auto *Fn = dyn_cast(Callee)) {
@@ -8074,8 +8075,7 @@ void CGOpenMPRuntime::emitCall(CodeGenFu
 void CGOpenMPRuntime::emitOutlinedFunctionCall(
 CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *OutlinedFn,
 ArrayRef Args) const {
-  assert(Loc.isValid() && "Outlined function call location must be valid.");
-  emitCall(CGF, OutlinedFn, Args, Loc);
+  emitCall(CGF, Loc, OutlinedFn, Args);
 }
 
 Address CGOpenMPRuntime::getParameterAddress(CodeGenFunction &CGF,

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=325812&r1=325811&r2=325812&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Thu Feb 22 10:33:31 2018
@@ -251,9 +251,8 @@ protected:
   virtual StringRef getOutlinedHelperName() const { return ".omp_outlined."; }
 
   /// Emits \p Callee function call with arguments \p Args with location \p 
Loc.
-  void emitCall(CodeGenFunction &CGF, llvm::Value *Callee,
-ArrayRef Args = llvm::None,
-SourceLocation Loc = SourceLocation()) const;
+  void emitCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *Callee,
+ArrayRef Args = llvm::None) const;
 
 private:
   /// \brief Default const ident_t object used for initialization of all other


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r303768 - [OPENMP] Allow value of thread local variables in target regions.

2017-05-24 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed May 24 11:00:02 2017
New Revision: 303768

URL: http://llvm.org/viewvc/llvm-project?rev=303768&view=rev
Log:
[OPENMP] Allow value of thread local variables in target regions.

If the variable is marked as TLS variable and target device does not
support TLS, the error is emitted for the variable even if it is not
used in target regions. Patch fixes this and allows to use the values of
the TLS variables in target regions.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=303768&r1=303767&r2=303768&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 24 11:00:02 2017
@@ -6516,7 +6516,7 @@ NamedDecl *Sema::ActOnVariableDeclarator
diag::err_thread_non_global)
 << DeclSpec::getSpecifierName(TSCS);
 else if (!Context.getTargetInfo().isTLSSupported()) {
-  if (getLangOpts().CUDA) {
+  if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
 // Postpone error emission until we've collected attributes required to
 // figure out whether it's a host or device variable and whether the
 // error should be ignored.
@@ -6578,8 +6578,11 @@ NamedDecl *Sema::ActOnVariableDeclarator
   // Handle attributes prior to checking for duplicates in MergeVarDecl
   ProcessDeclAttributes(S, NewVD, D);
 
-  if (getLangOpts().CUDA) {
-if (EmitTLSUnsupportedError && DeclAttrsMatchCUDAMode(getLangOpts(), 
NewVD))
+  if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
+if (EmitTLSUnsupportedError &&
+((getLangOpts().CUDA && DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) 
||
+ (getLangOpts().OpenMPIsDevice &&
+  NewVD->hasAttr(
   Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
diag::err_thread_unsupported);
 // CUDA B.2.5: "__shared__ and __constant__ variables have implied static

Modified: cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp?rev=303768&r1=303767&r2=303768&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp Wed May 24 11:00:02 2017
@@ -9,12 +9,14 @@
 #define HEADER
 
 // Check that the execution mode of all 6 target regions is set to Generic 
Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l98}}_exec_mode = weak constant i8 1
-// CHECK-DAG: {{@__omp_offloading_.+l175}}_exec_mode = weak constant i8 1
-// CHECK-DAG: {{@__omp_offloading_.+l284}}_exec_mode = weak constant i8 1
-// CHECK-DAG: {{@__omp_offloading_.+l321}}_exec_mode = weak constant i8 1
-// CHECK-DAG: {{@__omp_offloading_.+l339}}_exec_mode = weak constant i8 1
-// CHECK-DAG: {{@__omp_offloading_.+l304}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l100}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l177}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l287}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l324}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l342}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l307}}_exec_mode = weak constant i8 1
+
+__thread int id;
 
 template
 struct TT{
@@ -31,7 +33,7 @@ int foo(int n) {
   double cn[5][n];
   TT d;
 
-  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+foo.+l98}}_worker()
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+foo.+l100}}_worker()
   // CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8,
   // CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*,
   // CHECK: store i8* null, i8** [[OMP_WORK_FN]],
@@ -62,7 +64,7 @@ int foo(int n) {
   // CHECK: [[EXIT]]
   // CHECK: ret void
 
-  // CHECK: define {{.*}}void [[T1:@__omp_offloading_.+foo.+l98]]()
+  // CHECK: define {{.*}}void [[T1:@__omp_offloading_.+foo.+l100]]()
   // CHECK-DAG: [[TID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
   // CHECK-DAG: [[NTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
   // CHECK-DAG: [[WS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
@@ -104,7 +106,7 @@ int foo(int n) {
   {
   }
 
-  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+foo.+l175}}_worker()
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+foo.+l177}}_worker()
   // CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8,
   // CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*,
   // CHECK: store i8* null, i8** [[OMP_WORK_FN]],
@@ -135,7 +137,7 @@ int foo(int n) {
   // CHECK: [[EXIT]]
   // CHECK: ret void
 
-  // CHECK: define {{.*}}void 
[[T2:@__omp_offloading_.+foo.+l175]](i[[SZ:32|64]] [[ARG1:%[a-zA-Z_]+]])
+  // CHECK: define {{.*}}void 
[[

r304216 - [OPENMP] Allow 'use_device_ptr' clause in 'target data' alone.

2017-05-30 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue May 30 11:00:04 2017
New Revision: 304216

URL: http://llvm.org/viewvc/llvm-project?rev=304216&view=rev
Log:
[OPENMP] Allow 'use_device_ptr' clause in 'target data' alone.

According to OpenMP 5.0 at least one 'map' or 'use_device_ptr' clause
must be specified for 'target data' construct. Patch adds support for
this feature.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_data_messages.c
cfe/trunk/test/OpenMP/target_enter_data_map_messages.c
cfe/trunk/test/OpenMP/target_enter_data_nowait_messages.cpp
cfe/trunk/test/OpenMP/target_exit_data_map_messages.c
cfe/trunk/test/OpenMP/target_exit_data_nowait_messages.cpp
cfe/trunk/test/OpenMP/target_map_messages.cpp
cfe/trunk/test/OpenMP/target_teams_map_messages.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=304216&r1=304215&r2=304216&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 30 11:00:04 
2017
@@ -8749,8 +8749,8 @@ def err_omp_not_mappable_type : Error<
   "type %0 is not mappable to target">;
 def err_omp_invalid_map_type_for_directive : Error<
   "%select{map type '%1' is not allowed|map type must be specified}0 for 
'#pragma omp %2'">;
-def err_omp_no_map_for_directive : Error<
-  "expected at least one map clause for '#pragma omp %0'">;
+def err_omp_no_clause_for_directive : Error<
+  "expected at least one %0 clause for '#pragma omp %1'">;
 def note_omp_polymorphic_in_target : Note<
   "mappable type cannot be polymorphic">;
 def note_omp_static_member_in_target : Note<

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=304216&r1=304215&r2=304216&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue May 30 11:00:04 2017
@@ -5929,16 +5929,17 @@ StmtResult Sema::ActOnOpenMPTargetParall
B, DSAStack->isCancelRegion());
 }
 
-/// \brief Check for existence of a map clause in the list of clauses.
-static bool HasMapClause(ArrayRef Clauses) {
-  for (ArrayRef::iterator I = Clauses.begin(), E = Clauses.end();
-   I != E; ++I) {
-if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) {
-  return true;
-}
-  }
+/// Check for existence of a map clause in the list of clauses.
+static bool hasClauses(ArrayRef Clauses,
+   const OpenMPClauseKind K) {
+  return llvm::any_of(
+  Clauses, [K](const OMPClause *C) { return C->getClauseKind() == K; });
+}
 
-  return false;
+template 
+static bool hasClauses(ArrayRef Clauses, const OpenMPClauseKind K,
+   const Params... ClauseTypes) {
+  return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...);
 }
 
 StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef Clauses,
@@ -5952,8 +5953,9 @@ StmtResult Sema::ActOnOpenMPTargetDataDi
 
   // OpenMP [2.10.1, Restrictions, p. 97]
   // At least one map clause must appear on the directive.
-  if (!HasMapClause(Clauses)) {
-Diag(StartLoc, diag::err_omp_no_map_for_directive)
+  if (!hasClauses(Clauses, OMPC_map, OMPC_use_device_ptr)) {
+Diag(StartLoc, diag::err_omp_no_clause_for_directive)
+<< "'map' or 'use_device_ptr'"
 << getOpenMPDirectiveName(OMPD_target_data);
 return StmtError();
   }
@@ -5970,9 +5972,9 @@ Sema::ActOnOpenMPTargetEnterDataDirectiv
   SourceLocation EndLoc) {
   // OpenMP [2.10.2, Restrictions, p. 99]
   // At least one map clause must appear on the directive.
-  if (!HasMapClause(Clauses)) {
-Diag(StartLoc, diag::err_omp_no_map_for_directive)
-<< getOpenMPDirectiveName(OMPD_target_enter_data);
+  if (!hasClauses(Clauses, OMPC_map)) {
+Diag(StartLoc, diag::err_omp_no_clause_for_directive)
+<< "'map'" << getOpenMPDirectiveName(OMPD_target_enter_data);
 return StmtError();
   }
 
@@ -5986,9 +5988,9 @@ Sema::ActOnOpenMPTargetExitDataDirective
  SourceLocation EndLoc) {
   // OpenMP [2.10.3, Restrictions, p. 102]
   // At least one map clause must appear on the directive.
-  if (!HasMapClause(Clauses)) {
-Diag(StartLoc, diag::err_omp_no_map_for_directive)
-<< getOpenMPDirectiveName(OMPD_target_exit_data);
+  if (!hasClauses(Clauses, OMPC_map)) {
+Diag(StartLoc, diag::err_omp_no_clause_for_directive)
+<< "'map'" << getOpenMPDirectiveName(OMPD_target_exit_data);
 return StmtError();
   }
 
@@ -5998,12 +6000,7 @@ Sema::ActOnOpenMPTargetExitDataDirective
 StmtResult Se

r304229 - [OpenMP][Driver] Put target binary for each offload target into a

2017-05-30 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue May 30 13:57:51 2017
New Revision: 304229

URL: http://llvm.org/viewvc/llvm-project?rev=304229&view=rev
Log:
[OpenMP][Driver] Put target binary for each offload target into a
separate section, by Sergey Dmitriev

Linker script that is generated by the clang driver for creating fat binary 
puts target binaries for all offload targets into a single ELF section 
.omp_offloading. This is not convenient because it greatly complicates 
operations with the final fat binary once it is linked. For example extracting 
target binary for a particular target from such fat executable would not be an 
easy task if you have more than one offload target.

Attached patch changes clang driver to put target binary for each
offload target into a separate ELF section .omp_offloading..

Differential Revision: https://reviews.llvm.org/D33254

Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/test/Driver/openmp-offload.c

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=304229&r1=304228&r2=304229&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue May 30 13:57:51 2017
@@ -278,20 +278,20 @@ static void AddOpenMPLinkerScript(const
 
   LksStream << "SECTIONS\n";
   LksStream << "{\n";
-  LksStream << "  .omp_offloading :\n";
-  LksStream << "  ALIGN(0x10)\n";
-  LksStream << "  {\n";
 
-  for (auto &BI : InputBinaryInfo) {
-LksStream << ". = ALIGN(0x10);\n";
+  // Put each target binary into a separate section.
+  for (const auto &BI : InputBinaryInfo) {
+LksStream << "  .omp_offloading." << BI.first << " :\n";
+LksStream << "  ALIGN(0x10)\n";
+LksStream << "  {\n";
 LksStream << "PROVIDE_HIDDEN(.omp_offloading.img_start." << BI.first
   << " = .);\n";
 LksStream << "" << BI.second << "\n";
 LksStream << "PROVIDE_HIDDEN(.omp_offloading.img_end." << BI.first
   << " = .);\n";
+LksStream << "  }\n";
   }
 
-  LksStream << "  }\n";
   // Add commands to define host entries begin and end. We use 1-byte subalign
   // so that the linker does not add any padding and the elements in this
   // section form an array.

Modified: cfe/trunk/test/Driver/openmp-offload.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openmp-offload.c?rev=304229&r1=304228&r2=304229&view=diff
==
--- cfe/trunk/test/Driver/openmp-offload.c (original)
+++ cfe/trunk/test/Driver/openmp-offload.c Tue May 30 13:57:51 2017
@@ -210,14 +210,16 @@
 // CHK-LKS-ST: INPUT([[T2BIN:.+\.out-openmp-x86_64-pc-linux-gnu]])
 // CHK-LKS: SECTIONS
 // CHK-LKS: {
-// CHK-LKS:   .omp_offloading :
+// CHK-LKS:   .omp_offloading.powerpc64le-ibm-linux-gnu :
 // CHK-LKS:   ALIGN(0x10)
 // CHK-LKS:   {
-// CHK-LKS: . = ALIGN(0x10);
 // CHK-LKS: 
PROVIDE_HIDDEN(.omp_offloading.img_start.powerpc64le-ibm-linux-gnu = .);
 // CHK-LKS: [[T1BIN]]
 // CHK-LKS: 
PROVIDE_HIDDEN(.omp_offloading.img_end.powerpc64le-ibm-linux-gnu = .);
-// CHK-LKS: . = ALIGN(0x10);
+// CHK-LKS:   }
+// CHK-LKS:   .omp_offloading.x86_64-pc-linux-gnu :
+// CHK-LKS:   ALIGN(0x10)
+// CHK-LKS:   {
 // CHK-LKS: PROVIDE_HIDDEN(.omp_offloading.img_start.x86_64-pc-linux-gnu = 
.);
 // CHK-LKS: [[T2BIN]]
 // CHK-LKS: PROVIDE_HIDDEN(.omp_offloading.img_end.x86_64-pc-linux-gnu = 
.);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305075 - [DebugInfo] Add kind of ImplicitParamDecl for emission of FlagObjectPointer.

2017-06-09 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Jun  9 08:40:18 2017
New Revision: 305075

URL: http://llvm.org/viewvc/llvm-project?rev=305075&view=rev
Log:
[DebugInfo] Add kind of ImplicitParamDecl for emission of FlagObjectPointer.

Summary:
If the first parameter of the function is the ImplicitParamDecl, codegen
automatically marks it as an implicit argument with `this` or `self`
pointer. Added internal kind of the ImplicitParamDecl to separate
'this', 'self', 'vtt' and other implicit parameters from other kind of
parameters.

Reviewers: rjmccall, aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D33735

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGCXXABI.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGen/captured-statements.c
cfe/trunk/test/CodeGenCXX/captured-statements.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=305075&r1=305074&r2=305075&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Jun  9 08:40:18 2017
@@ -851,6 +851,7 @@ protected:
 
   class NonParmVarDeclBitfields {
 friend class VarDecl;
+friend class ImplicitParamDecl;
 friend class ASTDeclReader;
 
 unsigned : NumVarDeclBits;
@@ -894,6 +895,10 @@ protected:
 /// declared in the same block scope. This controls whether we should merge
 /// the type of this declaration with its previous declaration.
 unsigned PreviousDeclInSameBlockScope : 1;
+
+/// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
+/// something else.
+unsigned ImplicitParamKind : 3;
   };
 
   union {
@@ -1376,20 +1381,50 @@ public:
 
 class ImplicitParamDecl : public VarDecl {
   void anchor() override;
+
 public:
+  /// Defines the kind of the implicit parameter: is this an implicit parameter
+  /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
+  /// context or something else.
+  enum ImplicitParamKind : unsigned {
+ObjCSelf,/// Parameter for Objective-C 'self' argument
+ObjCCmd, /// Parameter for Objective-C '_cmd' argument
+CXXThis, /// Parameter for C++ 'this' argument
+CXXVTT,  /// Parameter for C++ virtual table pointers
+CapturedContext, /// Parameter for captured context
+Other,   /// Other implicit parameter
+  };
+
+  /// Create implicit parameter.
   static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation IdLoc, IdentifierInfo *Id,
-   QualType T);
+   QualType T, ImplicitParamKind ParamKind);
+  static ImplicitParamDecl *Create(ASTContext &C, QualType T,
+   ImplicitParamKind ParamKind);
 
   static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
   ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
-IdentifierInfo *Id, QualType Type)
-: VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
-  /*tinfo*/ nullptr, SC_None) {
+IdentifierInfo *Id, QualType Type,
+ImplicitParamKind ParamKind)
+  : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
+/*TInfo=*/nullptr, SC_None) {
+NonParmVarDeclBits.ImplicitParamKind = ParamKind;
 setImplicit();
   }
 
+  ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
+  : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
+SourceLocation(), /*Id=*/nullptr, Type,
+/*TInfo=*/nullptr, SC_None) {
+NonParmVarDeclBits.ImplicitParamKind = ParamKind;
+setImplicit();
+  }
+
+  /// Returns the implicit parameter kind.
+  ImplicitParamKind getParameterKind() const {
+return 
static_cast(NonParmVarDeclBits.ImplicitParamKind);
+  }
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == ImplicitParam; }

Modified: cfe/t

r305076 - [DebugInfo] Fix comment, NFC.

2017-06-09 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Jun  9 08:55:08 2017
New Revision: 305076

URL: http://llvm.org/viewvc/llvm-project?rev=305076&view=rev
Log:
[DebugInfo] Fix comment, NFC.

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=305076&r1=305075&r2=305076&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Jun  9 08:55:08 2017
@@ -3466,8 +3466,8 @@ void CGDebugInfo::EmitDeclare(const VarD
   unsigned AddressSpace = 
CGM.getContext().getTargetAddressSpace(VD->getType());
   AppendAddressSpaceXDeref(AddressSpace, Expr);
 
-  // If this is implicit parameter and has IPK_CXXThis or IPK_ObjCSelf 
attribute
-  // then give it an object pointer flag.
+  // If this is implicit parameter of CXXThis or ObjCSelf kind, then give it an
+  // object pointer flag.
   if (const auto *IPD = dyn_cast(VD)) {
 if (IPD->getParameterKind() == ImplicitParamDecl::CXXThis ||
 IPD->getParameterKind() == ImplicitParamDecl::ObjCSelf)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r320717 - [OPENMP] Add codegen for target data constructs with `nowait` clause.

2017-12-14 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Dec 14 09:00:17 2017
New Revision: 320717

URL: http://llvm.org/viewvc/llvm-project?rev=320717&view=rev
Log:
[OPENMP] Add codegen for target data constructs with `nowait` clause.

Added codegen for the `nowait` clause in target data constructs.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/target_enter_data_codegen.cpp
cfe/trunk/test/OpenMP/target_exit_data_codegen.cpp
cfe/trunk/test/OpenMP/target_update_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=320717&r1=320716&r2=320717&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Dec 14 09:00:17 2017
@@ -691,12 +691,24 @@ enum OpenMPRTLFunction {
   // Call to void __tgt_target_data_begin(int64_t device_id, int32_t arg_num,
   // void** args_base, void **args, size_t *arg_sizes, int64_t *arg_types);
   OMPRTL__tgt_target_data_begin,
+  // Call to void __tgt_target_data_begin_nowait(int64_t device_id, int32_t
+  // arg_num, void** args_base, void **args, size_t *arg_sizes, int64_t
+  // *arg_types);
+  OMPRTL__tgt_target_data_begin_nowait,
   // Call to void __tgt_target_data_end(int64_t device_id, int32_t arg_num,
   // void** args_base, void **args, size_t *arg_sizes, int64_t *arg_types);
   OMPRTL__tgt_target_data_end,
+  // Call to void __tgt_target_data_end_nowait(int64_t device_id, int32_t
+  // arg_num, void** args_base, void **args, size_t *arg_sizes, int64_t
+  // *arg_types);
+  OMPRTL__tgt_target_data_end_nowait,
   // Call to void __tgt_target_data_update(int64_t device_id, int32_t arg_num,
   // void** args_base, void **args, size_t *arg_sizes, int64_t *arg_types);
   OMPRTL__tgt_target_data_update,
+  // Call to void __tgt_target_data_update_nowait(int64_t device_id, int32_t
+  // arg_num, void** args_base, void **args, size_t *arg_sizes, int64_t
+  // *arg_types);
+  OMPRTL__tgt_target_data_update_nowait,
 };
 
 /// A basic class for pre|post-action for advanced codegen sequence for OpenMP
@@ -2136,6 +2148,21 @@ CGOpenMPRuntime::createRuntimeFunction(u
 RTLFn = CGM.CreateRuntimeFunction(FnTy, "__tgt_target_data_begin");
 break;
   }
+  case OMPRTL__tgt_target_data_begin_nowait: {
+// Build void __tgt_target_data_begin_nowait(int64_t device_id, int32_t
+// arg_num, void** args_base, void **args, size_t *arg_sizes, int64_t
+// *arg_types);
+llvm::Type *TypeParams[] = {CGM.Int64Ty,
+CGM.Int32Ty,
+CGM.VoidPtrPtrTy,
+CGM.VoidPtrPtrTy,
+CGM.SizeTy->getPointerTo(),
+CGM.Int64Ty->getPointerTo()};
+auto *FnTy =
+llvm::FunctionType::get(CGM.VoidTy, TypeParams, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__tgt_target_data_begin_nowait");
+break;
+  }
   case OMPRTL__tgt_target_data_end: {
 // Build void __tgt_target_data_end(int64_t device_id, int32_t arg_num,
 // void** args_base, void **args, size_t *arg_sizes, int64_t *arg_types);
@@ -2150,6 +2177,21 @@ CGOpenMPRuntime::createRuntimeFunction(u
 RTLFn = CGM.CreateRuntimeFunction(FnTy, "__tgt_target_data_end");
 break;
   }
+  case OMPRTL__tgt_target_data_end_nowait: {
+// Build void __tgt_target_data_end_nowait(int64_t device_id, int32_t
+// arg_num, void** args_base, void **args, size_t *arg_sizes, int64_t
+// *arg_types);
+llvm::Type *TypeParams[] = {CGM.Int64Ty,
+CGM.Int32Ty,
+CGM.VoidPtrPtrTy,
+CGM.VoidPtrPtrTy,
+CGM.SizeTy->getPointerTo(),
+CGM.Int64Ty->getPointerTo()};
+auto *FnTy =
+llvm::FunctionType::get(CGM.VoidTy, TypeParams, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__tgt_target_data_end_nowait");
+break;
+  }
   case OMPRTL__tgt_target_data_update: {
 // Build void __tgt_target_data_update(int64_t device_id, int32_t arg_num,
 // void** args_base, void **args, size_t *arg_sizes, int64_t *arg_types);
@@ -2164,6 +2206,21 @@ CGOpenMPRuntime::createRuntimeFunction(u
 RTLFn = CGM.CreateRuntimeFunction(FnTy, "__tgt_target_data_update");
 break;
   }
+  case OMPRTL__tgt_target_data_update_nowait: {
+// Build void __tgt_target_data_update_nowait(int64_t device_id, int32_t
+// arg_num, void** args_base, void **args, size_t *arg_sizes, int64_t
+// *arg_types);
+llvm::Type *TypeParams[] = {CGM.Int64Ty,
+CGM.Int32Ty,
+CGM.VoidPtrPtrTy,
+CGM.VoidPtrPtrTy,
+CGM.SizeTy->getPointerTo(),
+

r320826 - [OPENMP] Codegen `declare simd` for function declarations.

2017-12-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Dec 15 08:28:31 2017
New Revision: 320826

URL: http://llvm.org/viewvc/llvm-project?rev=320826&view=rev
Log:
[OPENMP] Codegen `declare simd` for function declarations.

Previously the attributes were emitted only for function definitions.
Patch adds emission of the attributes for function declarations.

Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/OpenMP/declare_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=320826&r1=320825&r2=320826&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Dec 15 08:28:31 2017
@@ -899,10 +899,6 @@ void CodeGenFunction::StartFunction(Glob
 }
   }
 
-  if (const FunctionDecl *FD = dyn_cast_or_null(D))
-if (CGM.getLangOpts().OpenMP && FD->hasAttr())
-  CGM.getOpenMPRuntime().emitDeclareSimdFunction(FD, Fn);
-
   // Add no-jump-tables value.
   Fn->addFnAttr("no-jump-tables",
 llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables));

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=320826&r1=320825&r2=320826&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Dec 15 08:28:31 2017
@@ -1238,6 +1238,9 @@ void CodeGenModule::SetFunctionAttribute
   // is handled with better precision by the receiving DSO.
   if (!CodeGenOpts.SanitizeCfiCrossDso)
 CreateFunctionTypeMetadata(FD, F);
+
+  if (getLangOpts().OpenMP && FD->hasAttr())
+getOpenMPRuntime().emitDeclareSimdFunction(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {

Modified: cfe/trunk/test/OpenMP/declare_simd_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_simd_codegen.cpp?rev=320826&r1=320825&r2=320826&view=diff
==
--- cfe/trunk/test/OpenMP/declare_simd_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_simd_codegen.cpp Fri Dec 15 08:28:31 2017
@@ -8,11 +8,22 @@
 #pragma omp declare simd linear(d : 8)
 #pragma omp declare simd inbranch simdlen(32)
 #pragma omp declare simd notinbranch
+void add_1(float *d);
+
+#pragma omp declare simd linear(d : 8)
+#pragma omp declare simd inbranch simdlen(32)
+#pragma omp declare simd notinbranch
 void add_1(float *d) {}
 
+#pragma omp declare simd linear(d : 8)
+#pragma omp declare simd inbranch simdlen(32)
+#pragma omp declare simd notinbranch
+void add_2(float *d);
+
 #pragma omp declare simd aligned(hp, hp2)
 template 
 void h(C *hp, C *hp2, C *hq, C *lin) {
+  add_2(0);
 }
 
 // Explicit specialization with .
@@ -110,6 +121,7 @@ double foo(double x) { return 0; }
 // CHECK-DAG: define {{.+}}@_Z3bax2VVPdi(
 // CHECK-DAG: define {{.+}}@_Z3fooPffi(
 // CHECK-DAG: define {{.+}}@_Z3food(
+// CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
 
 // CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
@@ -277,6 +289,23 @@ double foo(double x) { return 0; }
 // CHECK-DAG: "_ZGVeM16ua16vl1__Z3fooPffi"
 // CHECK-DAG: "_ZGVeN16ua16vl1__Z3fooPffi"
 
+// CHECK-DAG: "_ZGVbM4l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVbN4l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVcM8l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVcN8l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVdM8l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVdN8l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVeM16l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVeN16l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVbM32v__Z5add_2Pf"
+// CHECK-DAG: "_ZGVcM32v__Z5add_2Pf"
+// CHECK-DAG: "_ZGVdM32v__Z5add_2Pf"
+// CHECK-DAG: "_ZGVeM32v__Z5add_2Pf"
+// CHECK-DAG: "_ZGVbN2v__Z5add_2Pf"
+// CHECK-DAG: "_ZGVcN4v__Z5add_2Pf"
+// CHECK-DAG: "_ZGVdN4v__Z5add_2Pf"
+// CHECK-DAG: "_ZGVeN8v__Z5add_2Pf"
+
 // CHECK-DAG: "_ZGVbN2v__Z3food"
 // CHECK-DAG: "_ZGVcN4v__Z3food"
 // CHECK-DAG: "_ZGVdN4v__Z3food"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321386 - [OPENMP] Captured arguments of the capturable clauses by value.

2017-12-22 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Dec 22 13:01:52 2017
New Revision: 321386

URL: http://llvm.org/viewvc/llvm-project?rev=321386&view=rev
Log:
[OPENMP] Captured arguments of the capturable clauses by value.

If the clause is applied to the combined construct and has captured
expression, try to capture this expression by value rather than by
reference.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp

cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=321386&r1=321385&r2=321386&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Dec 22 13:01:52 2017
@@ -1290,9 +1290,14 @@ bool Sema::IsOpenMPCapturedByRef(ValueDe
   }
 
   if (IsByRef && Ty.getNonReferenceType()->isScalarType()) {
-IsByRef = !DSAStack->hasExplicitDSA(
-D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; },
-Level, /*NotLastprivate=*/true);
+IsByRef =
+!DSAStack->hasExplicitDSA(
+D,
+[](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; },
+Level, /*NotLastprivate=*/true) &&
+// If the variable is artificial and must be captured by value - try to
+// capture by value.
+!(isa(D) && D->hasAttr());
   }
 
   // When passing data by copy, we need to make sure it fits the uintptr size
@@ -2321,10 +2326,11 @@ static OMPCapturedExprDecl *buildCapture
   ASTContext &C = S.getASTContext();
   Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts();
   QualType Ty = Init->getType();
+  Attr *OMPCaptureKind = nullptr;
   if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) 
{
-if (S.getLangOpts().CPlusPlus)
+if (S.getLangOpts().CPlusPlus) {
   Ty = C.getLValueReferenceType(Ty);
-else {
+} else {
   Ty = C.getPointerType(Ty);
   ExprResult Res =
   S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init);
@@ -2333,11 +2339,16 @@ static OMPCapturedExprDecl *buildCapture
   Init = Res.get();
 }
 WithInit = true;
+  } else if (AsExpression) {
+// This variable must be captured by value.
+OMPCaptureKind = OMPCaptureKindAttr::CreateImplicit(C, OMPC_unknown);
   }
   auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty,
   CaptureExpr->getLocStart());
   if (!WithInit)
 CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange()));
+  if (OMPCaptureKind)
+CED->addAttr(OMPCaptureKind);
   S.CurContext->addHiddenDecl(CED);
   S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false);
   return CED;
@@ -2346,31 +2357,34 @@ static OMPCapturedExprDecl *buildCapture
 static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr,
  bool WithInit) {
   OMPCapturedExprDecl *CD;
-  if (auto *VD = S.IsOpenMPCapturedDecl(D))
+  if (auto *VD = S.IsOpenMPCapturedDecl(D)) {
 CD = cast(VD);
-  else
+  } else {
 CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit,
   /*AsExpression=*/false);
+  }
   return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(),
   CaptureExpr->getExprLoc());
 }
 
 static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) {
+  CaptureExpr = S.DefaultLvalueConversion(CaptureExpr).get();
   if (!Ref) {
-auto *CD =
-buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."),
- CaptureExpr, /*WithInit=*/true, 
/*AsExpression=*/true);
+OMPCapturedExprDecl *CD = buildCaptureDecl(
+S, &S.getASTContext().Idents.get(".capture_expr."), CaptureExpr,
+/*WithInit=*/true, /*AsExpression=*/true);
 Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(),
CaptureExpr->getExprLoc());
   }
   ExprResult Res = Ref;
   if (!S.getLangOpts().CPlusPlus &&
   CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() 
&&
-  Ref->getType()->isPointerType())
+  Ref->getType()->isPointerType()) {
 Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref);
-  if (!Res.isUsable())
-return ExprError();
-  return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get());
+if (!Res.isUsable())
+  return ExprError();
+  }
+  return S.DefaultLvalueConversion(Res.get());
 }
 
 namespace {
@@ -8117,12 +8131,13 @@ OMPClause *Sema::ActOnOpenMPIfClause(Ope
 if (Val.isInvalid())
   return nullptr;
 
-ValExpr = MakeFullExpr(Val.get()).get();
+ValExpr = Val.get();
 
 OpenMPDir

Re: r321386 - [OPENMP] Captured arguments of the capturable clauses by value.

2017-12-24 Thread Alexey Bataev via cfe-commits
Sure, thanks for the report. 

Best regards,
Alexey Bataev

24 дек. 2017 г., в 8:27, Maxim Kuvyrkov  написал(а):

>> On Dec 23, 2017, at 12:01 AM, Alexey Bataev via cfe-commits 
>>  wrote:
>> 
>> Author: abataev
>> Date: Fri Dec 22 13:01:52 2017
>> New Revision: 321386
>> 
>> URL: 
>> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D321386%26view%3Drev&data=02%7C01%7C%7C4bbee209c7424ec17ef908d54ad20f6c%7C84df9e7fe9f640afb435%7C1%7C0%7C636497188414868889&sdata=4uGGwkVO9vEMdod3ZJ2c9QrzPC2GZXRkOweo2jBkNvM%3D&reserved=0
>> Log:
>> [OPENMP] Captured arguments of the capturable clauses by value.
>> 
>> If the clause is applied to the combined construct and has captured
>> expression, try to capture this expression by value rather than by
>> reference.
>> 
>> Modified:
>>   cfe/trunk/lib/Sema/SemaOpenMP.cpp
>>   cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
>>   cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
>>   
>> cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
> 
> Hi Alexey,
> 
> Changes to the teams_distribute_parallel_* tests break 32-bit ARM buildbots, 
> e.g., 
> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Flab.llvm.org%3A8011%2Fbuilders%2Fclang-cmake-armv7-a15%2Fbuilds%2F14264&data=02%7C01%7C%7C4bbee209c7424ec17ef908d54ad20f6c%7C84df9e7fe9f640afb435%7C1%7C0%7C636497188414868889&sdata=vp2zxOQa%2B0t7WeKV4255eNXy9A3jewY2SlBMT0OGN18%3D&reserved=0
>  .  Would you please investigate?
> 
> Thanks,
> 
> --
> Maxim Kuvyrkov
> https://nam04.safelinks.protection.outlook.com/?url=www.linaro.org&data=02%7C01%7C%7C4bbee209c7424ec17ef908d54ad20f6c%7C84df9e7fe9f640afb435%7C1%7C0%7C636497188414868889&sdata=DzCf1pJo44ETXnttUW322oN40IwtK%2FNrxveBtOtAfT0%3D&reserved=0
> 
> 
>> 
>> Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
>> URL: 
>> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FSema%2FSemaOpenMP.cpp%3Frev%3D321386%26r1%3D321385%26r2%3D321386%26view%3Ddiff&data=02%7C01%7C%7C4bbee209c7424ec17ef908d54ad20f6c%7C84df9e7fe9f640afb435%7C1%7C0%7C636497188414868889&sdata=omvXI%2Fct%2B%2BsGN2SZxlfd33cCISW6RIMa2wF7BK1Q%2FEY%3D&reserved=0
>> ==
>> --- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Dec 22 13:01:52 2017
>> @@ -1290,9 +1290,14 @@ bool Sema::IsOpenMPCapturedByRef(ValueDe
>>  }
>> 
>>  if (IsByRef && Ty.getNonReferenceType()->isScalarType()) {
>> -IsByRef = !DSAStack->hasExplicitDSA(
>> -D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; 
>> },
>> -Level, /*NotLastprivate=*/true);
>> +IsByRef =
>> +!DSAStack->hasExplicitDSA(
>> +D,
>> +[](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; 
>> },
>> +Level, /*NotLastprivate=*/true) &&
>> +// If the variable is artificial and must be captured by value - 
>> try to
>> +// capture by value.
>> +!(isa(D) && D->hasAttr());
>>  }
>> 
>>  // When passing data by copy, we need to make sure it fits the uintptr size
>> @@ -2321,10 +2326,11 @@ static OMPCapturedExprDecl *buildCapture
>>  ASTContext &C = S.getASTContext();
>>  Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts();
>>  QualType Ty = Init->getType();
>> +  Attr *OMPCaptureKind = nullptr;
>>  if (CaptureExpr->getObjectKind() == OK_Ordinary && 
>> CaptureExpr->isGLValue()) {
>> -if (S.getLangOpts().CPlusPlus)
>> +if (S.getLangOpts().CPlusPlus) {
>>  Ty = C.getLValueReferenceType(Ty);
>> -else {
>> +} else {
>>  Ty = C.getPointerType(Ty);
>>  ExprResult Res =
>>  S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init);
>> @@ -2333,11 +2339,16 @@ static OMPCapturedExprDecl *buildCapture
>>  Init = Res.get();
>>}
>>WithInit = true;
>> +  } else if (AsExpression) {
>> +// This variable must be captured by value.
>> +OMPCaptureKind = OMPCaptureKindAttr::CreateImplicit(C, OMPC_unknown);
>>  }
>>  auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty,
>>  CaptureExpr->getLocStart());
>>  if (!

r321427 - [OPENMP] Fix the tests for 32bits targets, NFC.

2017-12-24 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Sun Dec 24 06:18:33 2017
New Revision: 321427

URL: http://llvm.org/viewvc/llvm-project?rev=321427&view=rev
Log:
[OPENMP] Fix the tests for 32bits targets, NFC.

Modified:
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp

cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp

Modified: 
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp?rev=321427&r1=321426&r2=321427&view=diff
==
--- cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp 
(original)
+++ cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp 
Sun Dec 24 06:18:33 2017
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple %itanium_abi_triple 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple %itanium_abi_triple 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-ibm-linux-gnu -emit-llvm %s -fexceptions -fcxx-exceptions -o - | 
FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple 
powerpc64le-ibm-linux-gnu -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-ibm-linux-gnu -fexceptions -fcxx-exceptions -std=c++11 -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck %s
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER

Modified: 
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp?rev=321427&r1=321426&r2=321427&view=diff
==
--- 
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
 (original)
+++ 
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp
 Sun Dec 24 06:18:33 2017
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple %itanium_abi_triple 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple %itanium_abi_triple 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-ibm-linux-gnu -emit-llvm %s -fexceptions -fcxx-exceptions -o - | 
FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple 
powerpc64le-ibm-linux-gnu -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-ibm-linux-gnu -fexceptions -fcxx-exceptions -std=c++11 -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck %s
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321493 - [OPENMP] Support for `depend` clauses on `target data update`.

2017-12-27 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Dec 27 09:58:32 2017
New Revision: 321493

URL: http://llvm.org/viewvc/llvm-project?rev=321493&view=rev
Log:
[OPENMP] Support for `depend` clauses on `target data update`.

Added codegen for `depend` clauses on `target data update` directives.

Added:
cfe/trunk/test/OpenMP/target_update_depend_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=321493&r1=321492&r2=321493&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Dec 27 09:58:32 2017
@@ -4175,14 +4175,23 @@ static void emitPrivatesInit(CodeGenFunc
   auto FI = std::next(KmpTaskTWithPrivatesQTyRD->field_begin());
   LValue PrivatesBase = CGF.EmitLValueForField(TDBase, *FI);
   LValue SrcBase;
-  if (!Data.FirstprivateVars.empty()) {
+  bool IsTargetTask =
+  isOpenMPTargetDataManagementDirective(D.getDirectiveKind()) ||
+  isOpenMPTargetExecutionDirective(D.getDirectiveKind());
+  // For target-based directives skip 3 firstprivate arrays BasePointersArray,
+  // PointersArray and SizesArray. The original variables for these arrays are
+  // not captured and we get their addresses explicitly.
+  if ((!IsTargetTask && !Data.FirstprivateVars.empty()) ||
+  (IsTargetTask && Data.FirstprivateVars.size() > 3)) {
 SrcBase = CGF.MakeAddrLValue(
 CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
 KmpTaskSharedsPtr, CGF.ConvertTypeForMem(SharedsPtrTy)),
 SharedsTy);
   }
-  CodeGenFunction::CGCapturedStmtInfo CapturesInfo(
-  cast(*D.getAssociatedStmt()));
+  OpenMPDirectiveKind Kind = isOpenMPTaskLoopDirective(D.getDirectiveKind())
+ ? OMPD_taskloop
+ : OMPD_task;
+  CodeGenFunction::CGCapturedStmtInfo CapturesInfo(*D.getCapturedStmt(Kind));
   FI = cast(FI->getType()->getAsTagDecl())->field_begin();
   for (auto &&Pair : Privates) {
 auto *VD = Pair.second.PrivateCopy;
@@ -4192,14 +4201,27 @@ static void emitPrivatesInit(CodeGenFunc
   LValue PrivateLValue = CGF.EmitLValueForField(PrivatesBase, *FI);
   if (auto *Elem = Pair.second.PrivateElemInit) {
 auto *OriginalVD = Pair.second.Original;
-auto *SharedField = CapturesInfo.lookup(OriginalVD);
-auto SharedRefLValue = CGF.EmitLValueForField(SrcBase, SharedField);
-SharedRefLValue = CGF.MakeAddrLValue(
-Address(SharedRefLValue.getPointer(), C.getDeclAlign(OriginalVD)),
-SharedRefLValue.getType(),
-LValueBaseInfo(AlignmentSource::Decl),
-SharedRefLValue.getTBAAInfo());
+// Check if the variable is the target-based BasePointersArray,
+// PointersArray or SizesArray.
+LValue SharedRefLValue;
 QualType Type = OriginalVD->getType();
+if (IsTargetTask && isa(OriginalVD) &&
+isa(OriginalVD->getDeclContext()) &&
+cast(OriginalVD->getDeclContext())->getNumParams() ==
+0 &&
+isa(
+cast(OriginalVD->getDeclContext())
+->getDeclContext())) {
+  SharedRefLValue =
+  CGF.MakeAddrLValue(CGF.GetAddrOfLocalVar(OriginalVD), Type);
+} else {
+  auto *SharedField = CapturesInfo.lookup(OriginalVD);
+  SharedRefLValue = CGF.EmitLValueForField(SrcBase, SharedField);
+  SharedRefLValue = CGF.MakeAddrLValue(
+  Address(SharedRefLValue.getPointer(), 
C.getDeclAlign(OriginalVD)),
+  SharedRefLValue.getType(), LValueBaseInfo(AlignmentSource::Decl),
+  SharedRefLValue.getTBAAInfo());
+}
 if (Type->isArrayType()) {
   // Initialize firstprivate array.
   if (!isa(Init) || CGF.isTrivialInitializer(Init)) {
@@ -4400,8 +4422,10 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFun
 }
 KmpTaskTQTy = SavedKmpTaskloopTQTy;
   } else {
-assert(D.getDirectiveKind() == OMPD_task &&
-   "Expected taskloop or task directive");
+assert((D.getDirectiveKind() == OMPD_task ||
+isOpenMPTargetExecutionDirective(D.getDirectiveKind()) ||
+isOpenMPTargetDataManagementDirective(D.getDirectiveKind())) &&
+   "Expected taskloop, task or target directive");
 if (SavedKmpTaskTQTy.isNull()) {
   SavedKmpTaskTQTy = C.getRecordType(createKmpTaskTRecordDecl(
   CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
@@ -7417,8 +7441,8 @@ void CGOpenMPRuntime::emitTargetDataCall
   // Generate the code for the opening of the data environment. Capture all the
   // arguments of the runtime call by reference be

r321495 - [OPENMP] Support for `depend` clauses on `target enter|exit data`.

2017-12-27 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Dec 27 10:49:38 2017
New Revision: 321495

URL: http://llvm.org/viewvc/llvm-project?rev=321495&view=rev
Log:
[OPENMP] Support for `depend` clauses on `target enter|exit data`.

Added codegen for `depend` clauses on `target enter|exit data` directives.

Added:
cfe/trunk/test/OpenMP/target_enter_data_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_exit_data_depend_codegen.cpp
Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=321495&r1=321494&r2=321495&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Dec 27 10:49:38 2017
@@ -7624,6 +7624,8 @@ static OpenMPDirectiveKind getOpenMPCapt
   CaptureRegion = OMPD_teams;
   break;
 case OMPD_target_update:
+case OMPD_target_enter_data:
+case OMPD_target_exit_data:
   CaptureRegion = OMPD_task;
   break;
 case OMPD_cancel:
@@ -7642,8 +7644,6 @@ static OpenMPDirectiveKind getOpenMPCapt
 case OMPD_taskloop:
 case OMPD_taskloop_simd:
 case OMPD_target_data:
-case OMPD_target_enter_data:
-case OMPD_target_exit_data:
   // Do not capture if-clause expressions.
   break;
 case OMPD_threadprivate:
@@ -8005,6 +8005,8 @@ static OpenMPDirectiveKind getOpenMPCapt
   case OMPC_device:
 switch (DKind) {
 case OMPD_target_update:
+case OMPD_target_enter_data:
+case OMPD_target_exit_data:
   CaptureRegion = OMPD_task;
   break;
 case OMPD_target_teams:
@@ -8013,8 +8015,6 @@ static OpenMPDirectiveKind getOpenMPCapt
 case OMPD_target_teams_distribute_parallel_for:
 case OMPD_target_teams_distribute_parallel_for_simd:
 case OMPD_target_data:
-case OMPD_target_enter_data:
-case OMPD_target_exit_data:
 case OMPD_target:
 case OMPD_target_simd:
 case OMPD_target_parallel:

Added: cfe/trunk/test/OpenMP/target_enter_data_depend_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_enter_data_depend_codegen.cpp?rev=321495&view=auto
==
--- cfe/trunk/test/OpenMP/target_enter_data_depend_codegen.cpp (added)
+++ cfe/trunk/test/OpenMP/target_enter_data_depend_codegen.cpp Wed Dec 27 
10:49:38 2017
@@ -0,0 +1,378 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
--check-prefix CK1 --check-prefix CK1-64
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck %s  --check-prefix CK1 --check-prefix CK1-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ 
-triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s  --check-prefix 
CK1 --check-prefix CK1-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ 
-std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple 
i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s  --check-prefix CK1 --check-prefix CK1-32
+
+// expected-no-diagnostics
+// CK1: [[ST:%.+]] = type { i32, double* }
+// CK1: %struct.kmp_depend_info = type { i[[sz:64|32]],
+// CK1-SAME: i[[sz]], i8 }
+#ifndef HEADER
+#define HEADER
+
+template 
+struct ST {
+  T a;
+  double *b;
+};
+
+ST gb;
+double gc[100];
+
+// CK1: [[SIZE00:@.+]] = {{.+}}constant [1 x i[[sz]]] [i[[sz]] 800]
+// CK1: [[MTYPE00:@.+]] = {{.+}}constant [1 x i64] [i64 32]
+
+// CK1: [[SIZE02:@.+]] = {{.+}}constant [1 x i[[sz]]] [i[[sz]] 4]
+// CK1: [[MTYPE02:@.+]] = {{.+}}constant [1 x i64] [i64 33]
+
+// CK1: [[MTYPE03:@.+]] = {{.+}}constant [1 x i64] [i64 32]
+
+// CK1: [[SIZE04:@.+]] = {{.+}}constant [2 x i[[sz]]] [i[[sz]] {{8|4}}, 
i[[sz]] 24]
+// CK1: [[MTYPE04:@.+]] = {{.+}}constant [2 x i64] [i64 33, i64 17]
+
+// CK1-LABEL: _Z3fooi
+void foo(int arg) {
+  int la;
+  float lb[arg];
+
+  // CK1: alloca [1 x %struct.kmp_depend_info],
+  // CK1: alloca [3 x %struct.kmp_depend_info],
+  // CK1: alloca [4 x %struct.kmp_depend_info],
+  // CK1: alloca [5 x %struct.kmp_depend_info],
+
+  // Region 00
+  // CK1: [[BP0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* 
[[BP:%.+]], i32 0, i32 0
+  // CK1: [[BP0_BC:%.+]] = bitcast i8** [[BP0]] to [100 x double]**
+  // CK1: store [100 x double]* @gc, [100 x double]** [[BP0_BC]],
+  // CK1: [[P0:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[P:%.+]], 
i32 0, i32 0
+  // CK1: [[P0_BC:%.+]] = bitcast i8** [[P0]] to [

r321558 - [OPENMP] Initial support for `-fopenmp-simd` option.

2017-12-29 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Dec 29 09:36:15 2017
New Revision: 321558

URL: http://llvm.org/viewvc/llvm-project?rev=321558&view=rev
Log:
[OPENMP] Initial support for `-fopenmp-simd` option.

Added basic support for `-fopenmp-simd` options.

Modified:
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/OpenMP/driver.c
cfe/trunk/test/OpenMP/linking.c
cfe/trunk/test/OpenMP/predefined_macro.c

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=321558&r1=321557&r2=321558&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Fri Dec 29 09:36:15 2017
@@ -194,6 +194,7 @@ LANGOPT(NativeHalfArgsAndReturns, 1, 0,
 LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")
 LANGOPT(CUDA  , 1, 0, "CUDA")
 LANGOPT(OpenMP, 32, 0, "OpenMP support and version of OpenMP (31, 
40 or 45)")
+LANGOPT(OpenMPSimd, 1, 0, "Use SIMD only OpenMP support.")
 LANGOPT(OpenMPUseTLS  , 1, 0, "Use TLS for threadprivates or runtime 
calls")
 LANGOPT(OpenMPIsDevice, 1, 0, "Generate code only for OpenMP target 
device")
 LANGOPT(RenderScript  , 1, 0, "RenderScript")

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=321558&r1=321557&r2=321558&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Dec 29 09:36:15 2017
@@ -1369,12 +1369,16 @@ def fopenmp_use_tls : Flag<["-"], "fopen
 def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group, 
Flags<[CC1Option, NoArgumentUnused]>;
 def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">, 
Flags<[DriverOption, CC1Option]>,
   HelpText<"Specify comma-separated list of triples OpenMP offloading targets 
to be supported">;
-def fopenmp_dump_offload_linker_script : Flag<["-"], 
"fopenmp-dump-offload-linker-script">, Group, 
+def fopenmp_dump_offload_linker_script : Flag<["-"], 
"fopenmp-dump-offload-linker-script">, Group,
   Flags<[NoArgumentUnused]>;
 def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">, 
Group, Flags<[CC1Option, NoArgumentUnused]>,
   HelpText<"OpenMP target code is compiled as relocatable using the -c flag. 
For OpenMP targets the code is relocatable by default.">;
 def fnoopenmp_relocatable_target : Flag<["-"], 
"fnoopenmp-relocatable-target">, Group, Flags<[CC1Option, 
NoArgumentUnused]>,
   HelpText<"Do not compile OpenMP target code as relocatable.">;
+def fopenmp_simd : Flag<["-"], "fopenmp-simd">, Group, 
Flags<[CC1Option, NoArgumentUnused]>,
+  HelpText<"Emit OpenMP code only for SIMD-based constructs.">;
+def fno_openmp_simd : Flag<["-"], "fno-openmp-simd">, Group, 
Flags<[CC1Option, NoArgumentUnused]>,
+  HelpText<"Disable OpenMP code for SIMD-based constructs.">;
 def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, 
Group;
 def foptimize_sibling_calls : Flag<["-"], "foptimize-sibling-calls">, 
Group;
 def force__cpusubtype__ALL : Flag<["-"], "force_cpusubtype_ALL">;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=321558&r1=321557&r2=321558&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Dec 29 09:36:15 2017
@@ -3901,6 +3901,10 @@ void Clang::ConstructJob(Compilation &C,
   // semantic analysis, etc.
   break;
 }
+  } else {
+Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
+options::OPT_fno_openmp_simd);
+Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
   }
 
   const SanitizerArgs &Sanitize = getToolChain().getSanitizerArgs();

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=321558&r1=321557&r2=321558&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Dec 29 09:36:15 2017
@@ -2407,16 +2407,22 @@ static void ParseLangArgs(LangOptions &O
 
   // Check if -fopenmp is specified.
   Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 1 : 0;
+  // Check if -fopenmp-simd is specified.
+  Opts.OpenMPSimd = !Opts.OpenMP && Args.hasFlag(options::OPT_fopenmp_simd,
+   

r321561 - [docs] Updated ReleaseNotes for OpenMP part.

2017-12-29 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Dec 29 10:23:12 2017
New Revision: 321561

URL: http://llvm.org/viewvc/llvm-project?rev=321561&view=rev
Log:
[docs] Updated ReleaseNotes for OpenMP part.

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=321561&r1=321560&r2=321561&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Fri Dec 29 10:23:12 2017
@@ -209,7 +209,18 @@ OpenCL C Language Changes in Clang
 OpenMP Support in Clang
 --
 
-...
+- Added options `-f[no]-openmp-simd` that support code emission only foe OpenMP
+  SIMD-based directives, like `#pragma omp simd`, `#pragma omp parallel for 
simd`
+  etc. The code is emitted only for simd-based part of the combined directives
+  and clauses.
+
+- Added support for almost all target-based directives except for
+  `#pragma omp target teams distribute parallel for [simd]`. Although, please
+  note that `depend` clauses on target-based directives are not supported yet.
+  Clang supports offloading to X86_64, AArch64 and PPC64[LE] devices.
+
+- Added support for `reduction`-based clauses on `task`-based directives from
+  upcoming OpenMP 5.0.
 
 Internal API Changes
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321562 - [docs] Added description of `-f[no]-openmp-simd` option to UsersManual.

2017-12-29 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Dec 29 10:27:00 2017
New Revision: 321562

URL: http://llvm.org/viewvc/llvm-project?rev=321562&view=rev
Log:
[docs] Added description of `-f[no]-openmp-simd` option to UsersManual.

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=321562&r1=321561&r2=321562&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Fri Dec 29 10:27:00 2017
@@ -2042,6 +2042,11 @@ directives, and ``#pragma omp taskgroup`
 Use `-fopenmp` to enable OpenMP. Support for OpenMP can be disabled with
 `-fno-openmp`.
 
+Use `-fopenmp-simd` to enable OpenMP simd features only, without linking
+the runtime library; for combined constructs
+(e.g. ``#pragma omp parallel for simd``) the non-simd directives and clauses
+will be ignored. This can be disabled with `-fno-openmp-simd`.
+
 Controlling implementation limits
 -
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321816 - [OPENMP] Add debug info for generated functions.

2018-01-04 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Jan  4 11:45:16 2018
New Revision: 321816

URL: http://llvm.org/viewvc/llvm-project?rev=321816&view=rev
Log:
[OPENMP] Add debug info for generated functions.

Most of the generated functions for the OpenMP were generated with
disabled debug info. Patch fixes this for better user experience.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=321816&r1=321815&r2=321816&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan  4 11:45:16 2018
@@ -1216,7 +1216,8 @@ emitCombinerOrInitializer(CodeGenModule
   CodeGenFunction CGF(CGM);
   // Map "T omp_in;" variable to "*omp_in_parm" value in all expressions.
   // Map "T omp_out;" variable to "*omp_out_parm" value in all expressions.
-  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args);
+  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args, 
In->getLocation(),
+Out->getLocation());
   CodeGenFunction::OMPPrivateScope Scope(CGF);
   Address AddrIn = CGF.GetAddrOfLocalVar(&OmpInParm);
   Scope.addPrivate(In, [&CGF, AddrIn, PtrTy]() -> Address {
@@ -2383,7 +2384,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
   // threadprivate copy of the variable VD
   CodeGenFunction CtorCGF(CGM);
   FunctionArgList Args;
-  ImplicitParamDecl Dst(CGM.getContext(), CGM.getContext().VoidPtrTy,
+  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr, Loc,
+/*Id=*/nullptr, CGM.getContext().VoidPtrTy,
 ImplicitParamDecl::Other);
   Args.push_back(&Dst);
 
@@ -2393,13 +2395,13 @@ llvm::Function *CGOpenMPRuntime::emitThr
   auto Fn = CGM.CreateGlobalInitOrDestructFunction(
   FTy, ".__kmpc_global_ctor_.", FI, Loc);
   CtorCGF.StartFunction(GlobalDecl(), CGM.getContext().VoidPtrTy, Fn, FI,
-Args, SourceLocation());
+Args, Loc, Loc);
   auto ArgVal = CtorCGF.EmitLoadOfScalar(
   CtorCGF.GetAddrOfLocalVar(&Dst), /*Volatile=*/false,
   CGM.getContext().VoidPtrTy, Dst.getLocation());
   Address Arg = Address(ArgVal, VDAddr.getAlignment());
-  Arg = CtorCGF.Builder.CreateElementBitCast(Arg,
- CtorCGF.ConvertTypeForMem(ASTTy));
+  Arg = CtorCGF.Builder.CreateElementBitCast(
+  Arg, CtorCGF.ConvertTypeForMem(ASTTy));
   CtorCGF.EmitAnyExprToMem(Init, Arg, Init->getType().getQualifiers(),
/*IsInitializer=*/true);
   ArgVal = CtorCGF.EmitLoadOfScalar(
@@ -2414,7 +2416,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
   // of the variable VD
   CodeGenFunction DtorCGF(CGM);
   FunctionArgList Args;
-  ImplicitParamDecl Dst(CGM.getContext(), CGM.getContext().VoidPtrTy,
+  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr, Loc,
+/*Id=*/nullptr, CGM.getContext().VoidPtrTy,
 ImplicitParamDecl::Other);
   Args.push_back(&Dst);
 
@@ -2425,7 +2428,7 @@ llvm::Function *CGOpenMPRuntime::emitThr
   FTy, ".__kmpc_global_dtor_.", FI, Loc);
   auto NL = ApplyDebugLocation::CreateEmpty(DtorCGF);
   DtorCGF.StartFunction(GlobalDecl(), CGM.getContext().VoidTy, Fn, FI, 
Args,
-SourceLocation());
+Loc, Loc);
   // Create a scope with an artificial location for the body of this 
function.
   auto AL = ApplyDebugLocation::CreateArtificial(DtorCGF);
   auto ArgVal = DtorCGF.EmitLoadOfScalar(
@@ -2469,7 +2472,7 @@ llvm::Function *CGOpenMPRuntime::emitThr
   FunctionArgList ArgList;
   InitCGF.StartFunction(GlobalDecl(), CGM.getContext().VoidTy, 
InitFunction,
 CGM.getTypes().arrangeNullaryFunction(), ArgList,
-Loc);
+Loc, Loc);
   emitThreadPrivateVarInit(InitCGF, VDAddr, Ctor, CopyCtor, Dtor, Loc);
   InitCGF.FinishFunction();
   return InitFunction;
@@ -2783,12 +2786,15 @@ static Address emitAddrOfVarFromArray(Co
 static llvm::Value *emitCopyprivateCopyFunction(
 CodeGenModule &CGM, llvm::Type *ArgsType,
 ArrayRef CopyprivateVars, ArrayRef DestExprs,
-ArrayRef SrcExprs, ArrayRef AssignmentOps) {
+ArrayRef SrcExprs, ArrayRef AssignmentOps,
+SourceLocation Loc) {
   auto &C = CGM.getContext();
   // void copy_func(void *LHSArg, void *RHSArg);
   FunctionArgList Args;
-  ImplicitParamDecl LHSArg(C, C.VoidPtrTy, Impl

r321818 - [OPENMP] Fix casting in NVPTX support library.

2018-01-04 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Jan  4 12:18:55 2018
New Revision: 321818

URL: http://llvm.org/viewvc/llvm-project?rev=321818&view=rev
Log:
[OPENMP] Fix casting in NVPTX support library.

If the reduction required shuffle in the NVPTX codegen, we may need to
cast the reduced value to the integer type. This casting was implemented
incorrectly and may cause compiler crash. Patch fixes this problem.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_teams_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=321818&r1=321817&r2=321818&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Jan  4 12:18:55 2018
@@ -1059,19 +1059,41 @@ void CGOpenMPRuntimeNVPTX::emitSpmdParal
   emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs);
 }
 
+/// Cast value to the specified type.
+static llvm::Value *
+castValueToType(CodeGenFunction &CGF, llvm::Value *Val, llvm::Type *CastTy,
+llvm::Optional IsSigned = llvm::None) {
+  if (Val->getType() == CastTy)
+return Val;
+  if (Val->getType()->getPrimitiveSizeInBits() > 0 &&
+  CastTy->getPrimitiveSizeInBits() > 0 &&
+  Val->getType()->getPrimitiveSizeInBits() ==
+  CastTy->getPrimitiveSizeInBits())
+return CGF.Builder.CreateBitCast(Val, CastTy);
+  if (IsSigned.hasValue() && CastTy->isIntegerTy() &&
+  Val->getType()->isIntegerTy())
+return CGF.Builder.CreateIntCast(Val, CastTy, *IsSigned);
+  Address CastItem = CGF.CreateTempAlloca(
+  CastTy,
+  CharUnits::fromQuantity(
+  CGF.CGM.getDataLayout().getPrefTypeAlignment(Val->getType(;
+  Address ValCastItem = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+  CastItem, Val->getType()->getPointerTo(CastItem.getAddressSpace()));
+  CGF.Builder.CreateStore(Val, ValCastItem);
+  return CGF.Builder.CreateLoad(CastItem);
+}
+
 /// This function creates calls to one of two shuffle functions to copy
 /// variables between lanes in a warp.
 static llvm::Value *createRuntimeShuffleFunction(CodeGenFunction &CGF,
- QualType ElemTy,
  llvm::Value *Elem,
  llvm::Value *Offset) {
   auto &CGM = CGF.CGM;
-  auto &C = CGM.getContext();
   auto &Bld = CGF.Builder;
   CGOpenMPRuntimeNVPTX &RT =
   *(static_cast(&CGM.getOpenMPRuntime()));
 
-  unsigned Size = CGM.getContext().getTypeSizeInChars(ElemTy).getQuantity();
+  unsigned Size = CGM.getDataLayout().getTypeStoreSize(Elem->getType());
   assert(Size <= 8 && "Unsupported bitwidth in shuffle instruction.");
 
   OpenMPRTLFunctionNVPTX ShuffleFn = Size <= 4
@@ -1079,17 +1101,16 @@ static llvm::Value *createRuntimeShuffle
  : OMPRTL_NVPTX__kmpc_shuffle_int64;
 
   // Cast all types to 32- or 64-bit values before calling shuffle routines.
-  auto CastTy = Size <= 4 ? CGM.Int32Ty : CGM.Int64Ty;
-  auto *ElemCast = Bld.CreateSExtOrBitCast(Elem, CastTy);
-  auto *WarpSize = CGF.EmitScalarConversion(
-  getNVPTXWarpSize(CGF), C.getIntTypeForBitwidth(32, /* Signed */ true),
-  C.getIntTypeForBitwidth(16, /* Signed */ true), SourceLocation());
+  llvm::Type *CastTy = Size <= 4 ? CGM.Int32Ty : CGM.Int64Ty;
+  llvm::Value *ElemCast = castValueToType(CGF, Elem, CastTy, 
/*isSigned=*/true);
+  auto *WarpSize =
+  Bld.CreateIntCast(getNVPTXWarpSize(CGF), CGM.Int16Ty, /*isSigned=*/true);
 
   auto *ShuffledVal =
   CGF.EmitRuntimeCall(RT.createNVPTXRuntimeFunction(ShuffleFn),
   {ElemCast, Offset, WarpSize});
 
-  return Bld.CreateTruncOrBitCast(ShuffledVal, CGF.ConvertTypeForMem(ElemTy));
+  return castValueToType(CGF, ShuffledVal, Elem->getType(), /*isSigned=*/true);
 }
 
 namespace {
@@ -1151,10 +1172,9 @@ static void emitReductionListCopy(
   // Step 1.1: Get the address for the src element in the Reduce list.
   Address SrcElementPtrAddr =
   Bld.CreateConstArrayGEP(SrcBase, Idx, CGF.getPointerSize());
-  llvm::Value *SrcElementPtrPtr = CGF.EmitLoadOfScalar(
-  SrcElementPtrAddr, /*Volatile=*/false, C.VoidPtrTy, 
SourceLocation());
-  SrcElementAddr =
-  Address(SrcElementPtrPtr, C.getTypeAlignInChars(Private->getType()));
+  SrcElementAddr = CGF.EmitLoadOfPointer(
+  SrcElementPtrAddr,
+  C.getPointerType(Private->getType())->castAs());
 
   // Step 1.2: Create a temporary to store the element in the destination
   // Reduce list.
@@ -1170,32 +1190,26 @@ static void emitReductionListCopy(
   // Step 1.1: Get the address for the src element in the Reduce l

r321820 - [OPENMP] Fix capturing of expressions in clauses.

2018-01-04 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Jan  4 12:50:08 2018
New Revision: 321820

URL: http://llvm.org/viewvc/llvm-project?rev=321820&view=rev
Log:
[OPENMP] Fix capturing of expressions in clauses.

Patch fixes incorrect capturing of the expressions in clauses with
expressions that must be captured for the combined constructs. Incorrect
capturing may lead to compiler crash during codegen phase.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=321820&r1=321819&r2=321820&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Jan  4 12:50:08 2018
@@ -7732,12 +7732,12 @@ static OpenMPDirectiveKind getOpenMPCapt
 case OMPD_target_parallel:
 case OMPD_target_parallel_for:
 case OMPD_target_parallel_for_simd:
-case OMPD_target_teams_distribute_parallel_for:
-case OMPD_target_teams_distribute_parallel_for_simd:
   CaptureRegion = OMPD_target;
   break;
 case OMPD_teams_distribute_parallel_for:
 case OMPD_teams_distribute_parallel_for_simd:
+case OMPD_target_teams_distribute_parallel_for:
+case OMPD_target_teams_distribute_parallel_for_simd:
   CaptureRegion = OMPD_teams;
   break;
 case OMPD_parallel:
@@ -7920,20 +7920,16 @@ static OpenMPDirectiveKind getOpenMPCapt
 break;
   case OMPC_schedule:
 switch (DKind) {
-case OMPD_target_parallel_for:
-case OMPD_target_parallel_for_simd:
-case OMPD_target_teams_distribute_parallel_for:
-case OMPD_target_teams_distribute_parallel_for_simd:
-  CaptureRegion = OMPD_target;
-  break;
-case OMPD_teams_distribute_parallel_for:
-case OMPD_teams_distribute_parallel_for_simd:
-  CaptureRegion = OMPD_teams;
-  break;
 case OMPD_parallel_for:
 case OMPD_parallel_for_simd:
 case OMPD_distribute_parallel_for:
 case OMPD_distribute_parallel_for_simd:
+case OMPD_teams_distribute_parallel_for:
+case OMPD_teams_distribute_parallel_for_simd:
+case OMPD_target_parallel_for:
+case OMPD_target_parallel_for_simd:
+case OMPD_target_teams_distribute_parallel_for:
+case OMPD_target_teams_distribute_parallel_for_simd:
   CaptureRegion = OMPD_parallel;
   break;
 case OMPD_for:
@@ -7991,18 +7987,14 @@ static OpenMPDirectiveKind getOpenMPCapt
 case OMPD_teams_distribute_parallel_for_simd:
 case OMPD_teams_distribute:
 case OMPD_teams_distribute_simd:
-  CaptureRegion = OMPD_teams;
-  break;
 case OMPD_target_teams_distribute_parallel_for:
 case OMPD_target_teams_distribute_parallel_for_simd:
 case OMPD_target_teams_distribute:
 case OMPD_target_teams_distribute_simd:
-  CaptureRegion = OMPD_target;
+  CaptureRegion = OMPD_teams;
   break;
 case OMPD_distribute_parallel_for:
 case OMPD_distribute_parallel_for_simd:
-  CaptureRegion = OMPD_parallel;
-  break;
 case OMPD_distribute:
 case OMPD_distribute_simd:
   // Do not capture thread_limit-clause expressions.

Modified: cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp?rev=321820&r1=321819&r2=321820&view=diff
==
--- cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp Thu Jan  4 
12:50:08 2018
@@ -62,7 +62,7 @@
 // CHECK-DAG: [[MAPT2:@.+]] = private unnamed_addr constant [1 x i64] [i64 288]
 // CHECK-DAG: [[SIZET3:@.+]] = private unnamed_addr constant [2 x i[[SZ]]] 
[i[[SZ]] 4, i[[SZ]] 2]
 // CHECK-DAG: [[MAPT3:@.+]] = private unnamed_addr constant [2 x i64] [i64 
288, i64 288]
-// CHECK-DAG: [[MAPT4:@.+]] = private unnamed_addr constant [9 x i64] [i64 
288, i64 547, i64 288, i64 547, i64 547, i64 288, i64 288, i64 547, i64 547]
+// CHECK-DAG: [[MAPT4:@.+]] = private unnamed_addr constant [10 x i64] [i64 
288, i64 547, i64 288, i64 547, i64 547, i64 288, i64 288, i64 547, i64 547, 
i64 288]
 // CHECK-DAG: [[MAPT5:@.+]] = private unnamed_addr constant [5 x i64] [i64 
547, i64 288, i64 288, i64 288, i64 547]
 // CHECK-DAG: [[SIZET6:@.+]] = private unnamed_addr constant [5 x i[[SZ]]] 
[i[[SZ]] 4, i[[SZ]] 4, i[[SZ]] 2, i[[SZ]] 1, i[[SZ]] 40]
 // CHECK-DAG: [[MAPT6:@.+]] = private unnamed_addr constant [5 x i64] [i64 
288, i64 288, i64 288, i64 288, i64 547]
@@ -211,6 +211,7 @@ int foo(int n) {
   }
 
   // We capture 3 VLA sizes in this target region
+  // CHECK:  load i32, i32* %
   // CHECK-64:   [[A_VAL:%.+]] = load i32, i32* %{{.+}},
   // CHECK-64:   [[A_ADDR:%.+]] = bitcast i[[SZ]]* [[A_CADDR:%.+]] to i32*
   // CHECK-64:   store i32 [[A_VAL]], i32

Re: r321816 - [OPENMP] Add debug info for generated functions.

2018-01-05 Thread Alexey Bataev via cfe-commits
Hi Jonas, I don't think it is necessary. It is better to backport my 2
next patches with bug fixes.

Best regards,
Alexey

04.01.2018 15:54, Jonas Hahnfeld пишет:
> Hi Alexey,
>
> should this change be backported to 6.0?
>
> Regards,
> Jonas
>
> Am 2018-01-04 20:45, schrieb Alexey Bataev via cfe-commits:
>> Author: abataev
>> Date: Thu Jan  4 11:45:16 2018
>> New Revision: 321816
>>
>> URL:
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D321816%26view%3Drev&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=g3DdxRoQ%2B8RbIORsLLfEJAAP4Zn2Orsshr6PwIthnQw%3D&reserved=0
>> Log:
>> [OPENMP] Add debug info for generated functions.
>>
>> Most of the generated functions for the OpenMP were generated with
>> disabled debug info. Patch fixes this for better user experience.
>>
>> Modified:
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
>>     cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>> URL:
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCGOpenMPRuntime.cpp%3Frev%3D321816%26r1%3D321815%26r2%3D321816%26view%3Ddiff&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=2ppjOPjnpev4zlt1Fh6ByuYdotTiSr0Z1WyvBa8WWHo%3D&reserved=0
>>
>> ==
>>
>> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan  4 11:45:16 2018
>> @@ -1216,7 +1216,8 @@ emitCombinerOrInitializer(CodeGenModule
>>    CodeGenFunction CGF(CGM);
>>    // Map "T omp_in;" variable to "*omp_in_parm" value in all
>> expressions.
>>    // Map "T omp_out;" variable to "*omp_out_parm" value in all
>> expressions.
>> -  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args);
>> +  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args,
>> In->getLocation(),
>> +    Out->getLocation());
>>    CodeGenFunction::OMPPrivateScope Scope(CGF);
>>    Address AddrIn = CGF.GetAddrOfLocalVar(&OmpInParm);
>>    Scope.addPrivate(In, [&CGF, AddrIn, PtrTy]() -> Address {
>> @@ -2383,7 +2384,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>    // threadprivate copy of the variable VD
>>    CodeGenFunction CtorCGF(CGM);
>>    FunctionArgList Args;
>> -  ImplicitParamDecl Dst(CGM.getContext(),
>> CGM.getContext().VoidPtrTy,
>> +  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr, Loc,
>> +    /*Id=*/nullptr, CGM.getContext().VoidPtrTy,
>>  ImplicitParamDecl::Other);
>>    Args.push_back(&Dst);
>>
>> @@ -2393,13 +2395,13 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>    auto Fn = CGM.CreateGlobalInitOrDestructFunction(
>>    FTy, ".__kmpc_global_ctor_.", FI, Loc);
>>    CtorCGF.StartFunction(GlobalDecl(),
>> CGM.getContext().VoidPtrTy, Fn, FI,
>> -    Args, SourceLocation());
>> +    Args, Loc, Loc);
>>    auto ArgVal = CtorCGF.EmitLoadOfScalar(
>>    CtorCGF.GetAddrOfLocalVar(&Dst), /*Volatile=*/false,
>>    CGM.getContext().VoidPtrTy, Dst.getLocation());
>>    Address Arg = Address(ArgVal, VDAddr.getAlignment());
>> -  Arg = CtorCGF.Builder.CreateElementBitCast(Arg,
>> -
>> CtorCGF.ConvertTypeForMem(ASTTy));
>> +  Arg = CtorCGF.Builder.CreateElementBitCast(
>> +  Arg, CtorCGF.ConvertTypeForMem(ASTTy));
>>    CtorCGF.EmitAnyExprToMem(Init, Arg,
>> Init->getType().getQualifiers(),
>>     /*IsInitializer=*/true);
>>    ArgVal = CtorCGF.EmitLoadOfScalar(
>> @@ -2414,7 +2416,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>    // of the variable VD
>>    CodeGenFunction DtorCGF(CGM);
>>    FunctionArgList Args;
>> -  ImplicitParamDecl Dst(CGM.getContext(),
>> CGM.getContext().VoidPtrTy,
>> +  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr, Loc,
>&g

Re: r321816 - [OPENMP] Add debug info for generated functions.

2018-01-05 Thread Alexey Bataev via cfe-commits
Yes, I mean these 2.

-
Best regards,
Alexey Bataev

04.01.2018 16:02, Jonas Hahnfeld пишет:
> You mean r321818 and r321820? I skipped them because they are for
> NVPTX and target directives which aren't fully functional in 6.0
> anyway, right?
> Or patches in the future?
>
> Am 2018-01-04 21:58, schrieb Alexey Bataev:
>> Hi Jonas, I don't think it is necessary. It is better to backport my 2
>> next patches with bug fixes.
>>
>> Best regards,
>> Alexey
>>
>> 04.01.2018 15:54, Jonas Hahnfeld пишет:
>>
>>> Hi Alexey,
>>>
>>> should this change be backported to 6.0?
>>>
>>> Regards,
>>> Jonas
>>>
>>> Am 2018-01-04 20:45, schrieb Alexey Bataev via cfe-commits:
>>>
>>>> Author: abataev
>>>> Date: Thu Jan  4 11:45:16 2018
>>>> New Revision: 321816
>>>>
>>>> URL:
>>>>
>>>
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D321816%26view%3Drev&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=g3DdxRoQ%2B8RbIORsLLfEJAAP4Zn2Orsshr6PwIthnQw%3D&reserved=0
>>
>>>> Log:
>>>> [OPENMP] Add debug info for generated functions.
>>>>
>>>> Most of the generated functions for the OpenMP were generated with
>>>>
>>>> disabled debug info. Patch fixes this for better user experience.
>>>>
>>>> Modified:
>>>> cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>>>> cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
>>>> cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
>>>> cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
>>>> cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
>>>>
>>>> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>>>> URL:
>>>>
>>>
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCGOpenMPRuntime.cpp%3Frev%3D321816%26r1%3D321815%26r2%3D321816%26view%3Ddiff&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=2ppjOPjnpev4zlt1Fh6ByuYdotTiSr0Z1WyvBa8WWHo%3D&reserved=0
>>
>>>>
>>>>
>>>
>> ==
>>
>>>>
>>>> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
>>>> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan  4 11:45:16
>>>> 2018
>>>> @@ -1216,7 +1216,8 @@ emitCombinerOrInitializer(CodeGenModule
>>>> CodeGenFunction CGF(CGM);
>>>> // Map "T omp_in;" variable to "*omp_in_parm" value in all
>>>> expressions.
>>>> // Map "T omp_out;" variable to "*omp_out_parm" value in all
>>>> expressions.
>>>> -  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args);
>>>> +  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args,
>>>> In->getLocation(),
>>>> +    Out->getLocation());
>>>> CodeGenFunction::OMPPrivateScope Scope(CGF);
>>>> Address AddrIn = CGF.GetAddrOfLocalVar(&OmpInParm);
>>>> Scope.addPrivate(In, [&CGF, AddrIn, PtrTy]() -> Address {
>>>> @@ -2383,7 +2384,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>>> // threadprivate copy of the variable VD
>>>> CodeGenFunction CtorCGF(CGM);
>>>> FunctionArgList Args;
>>>> -  ImplicitParamDecl Dst(CGM.getContext(),
>>>> CGM.getContext().VoidPtrTy,
>>>> +  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr,
>>>> Loc,
>>>> +    /*Id=*/nullptr,
>>>> CGM.getContext().VoidPtrTy,
>>>> ImplicitParamDecl::Other);
>>>> Args.push_back(&Dst);
>>>>
>>>> @@ -2393,13 +2395,13 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>>> auto Fn = CGM.CreateGlobalInitOrDestructFunction(
>>>> FTy, ".__kmpc_global_ctor_.", FI, Loc);
>>>> CtorCGF.StartFunction(GlobalDecl(),
>>>> CGM.getContext().VoidPtrTy, Fn, FI,
>>>> -    Args, SourceLocation());
>>>> +    Args, Loc, Loc);
>>>> auto ArgVal = CtorCGF.EmitLoadOfScalar(
>>>> CtorCGF.GetAddrOfLocalVar(&Dst), /*Vol

Re: r321816 - [OPENMP] Add debug info for generated functions.

2018-01-08 Thread Alexey Bataev via cfe-commits
Will add some more tests later today
-
Best regards,
Alexey Bataev

08.01.2018 11:13, David Blaikie пишет:
> Rough guess: That seems like a lot of code changes for relatively
> little test changes - are all parts of this change tested? (Might well
> be - just lots of layers to plumb things through - but if there's lots
> of places that get locations and only a few of those are tested, maybe
> this could use more coverage?)
>
> On Thu, Jan 4, 2018 at 11:46 AM Alexey Bataev via cfe-commits
> mailto:cfe-commits@lists.llvm.org>> wrote:
>
> Author: abataev
> Date: Thu Jan  4 11:45:16 2018
> New Revision: 321816
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321816&view=rev
> 
> <https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D321816%26view%3Drev&data=02%7C01%7C%7C25225d1cd7514865a93b08d556b2d5fc%7C84df9e7fe9f640afb435%7C1%7C0%7C636510248447058818&sdata=317%2FhTn9NeM8wKh6VQWxKyaJUrlSoUqmVJKP4Fe3aJo%3D&reserved=0>
> Log:
> [OPENMP] Add debug info for generated functions.
>
> Most of the generated functions for the OpenMP were generated with
> disabled debug info. Patch fixes this for better user experience.
>
> Modified:
>     cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>     cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
>     cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
>     cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
>     cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
> URL:
> 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=321816&r1=321815&r2=321816&view=diff
> 
> <https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCGOpenMPRuntime.cpp%3Frev%3D321816%26r1%3D321815%26r2%3D321816%26view%3Ddiff&data=02%7C01%7C%7C25225d1cd7514865a93b08d556b2d5fc%7C84df9e7fe9f640afb435%7C1%7C0%7C636510248447058818&sdata=Hn1jlQrsgVAEtGyfTbuwkX1HEg4aBKOeXn%2FIJMz%2By1A%3D&reserved=0>
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan  4 11:45:16 2018
> @@ -1216,7 +1216,8 @@ emitCombinerOrInitializer(CodeGenModule
>    CodeGenFunction CGF(CGM);
>    // Map "T omp_in;" variable to "*omp_in_parm" value in all
> expressions.
>    // Map "T omp_out;" variable to "*omp_out_parm" value in all
> expressions.
> -  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args);
> +  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args,
> In->getLocation(),
> +                    Out->getLocation());
>    CodeGenFunction::OMPPrivateScope Scope(CGF);
>    Address AddrIn = CGF.GetAddrOfLocalVar(&OmpInParm);
>    Scope.addPrivate(In, [&CGF, AddrIn, PtrTy]() -> Address {
> @@ -2383,7 +2384,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
>        // threadprivate copy of the variable VD
>        CodeGenFunction CtorCGF(CGM);
>        FunctionArgList Args;
> -      ImplicitParamDecl Dst(CGM.getContext(),
> CGM.getContext().VoidPtrTy,
> +      ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr, Loc,
> +                            /*Id=*/nullptr,
> CGM.getContext().VoidPtrTy,
>                              ImplicitParamDecl::Other);
>        Args.push_back(&Dst);
>
> @@ -2393,13 +2395,13 @@ llvm::Function *CGOpenMPRuntime::emitThr
>        auto Fn = CGM.CreateGlobalInitOrDestructFunction(
>            FTy, ".__kmpc_global_ctor_.", FI, Loc);
>        CtorCGF.StartFunction(GlobalDecl(),
> CGM.getContext().VoidPtrTy, Fn, FI,
> -                            Args, SourceLocation());
> +                            Args, Loc, Loc);
>        auto ArgVal = CtorCGF.EmitLoadOfScalar(
>            CtorCGF.GetAddrOfLocalVar(&Dst), /*Volatile=*/false,
>            CGM.getContext().VoidPtrTy, Dst.getLocation());
>        Address Arg = Address(ArgVal, VDAddr.getAlignment());
> -      Arg = CtorCGF.Builder.CreateElementBitCast(Arg,
> -                                           
>  CtorCGF.ConvertTypeForMem(ASTTy));
> +      Arg = CtorCGF.Builder.CreateElementBitCast(
> +          Arg, CtorCGF.ConvertTypeForMem(ASTTy));
>        CtorCGF.EmitAnyExprToMem(Init, Arg,
> Init->getType().getQualifiers(),
>               

r322018 - [OPENMP] Current status of OpenMP support.

2018-01-08 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jan  8 11:02:51 2018
New Revision: 322018

URL: http://llvm.org/viewvc/llvm-project?rev=322018&view=rev
Log:
[OPENMP] Current status of OpenMP support.

Summary: Some info about supported features of OpenMP 4.5-5.0.

Reviewers: hfinkel, rsmith

Subscribers: kkwli0, Hahnfeld, cfe-commits

Differential Revision: https://reviews.llvm.org/D39457

Added:
cfe/trunk/docs/OpenMPSupport.rst
Modified:
cfe/trunk/docs/index.rst

Added: cfe/trunk/docs/OpenMPSupport.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/OpenMPSupport.rst?rev=322018&view=auto
==
--- cfe/trunk/docs/OpenMPSupport.rst (added)
+++ cfe/trunk/docs/OpenMPSupport.rst Mon Jan  8 11:02:51 2018
@@ -0,0 +1,68 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.partial { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: partial
+.. role:: good
+
+==
+OpenMP Support
+==
+
+Clang fully supports OpenMP 3.1 + some elements of OpenMP 4.5. Clang supports 
offloading to X86_64, AArch64 and PPC64[LE] devices.
+Support for Cuda devices is not ready yet.
+The status of major OpenMP 4.5 features support in Clang.
+
+Standalone directives
+=
+
+* #pragma omp [for] simd: :good:`Complete`.
+
+* #pragma omp declare simd: :partial:`Partial`.  We support parsing/semantic
+  analysis + generation of special attributes for X86 target, but still
+  missing the LLVM pass for vectorization.
+
+* #pragma omp taskloop [simd]: :good:`Complete`.
+
+* #pragma omp target [enter|exit] data: :good:`Complete`.
+
+* #pragma omp target update: :good:`Complete`.
+
+* #pragma omp target: :partial:`Partial`.  No support for the `depend` clauses.
+
+* #pragma omp declare target: :partial:`Partial`.  No full codegen support.
+
+* #pragma omp teams: :good:`Complete`.
+
+* #pragma omp distribute [simd]: :good:`Complete`.
+
+* #pragma omp distribute parallel for [simd]: :good:`Complete`.
+
+Combined directives
+===
+
+* #pragma omp parallel for simd: :good:`Complete`.
+
+* #pragma omp target parallel: :partial:`Partial`.  No support for the 
`depend` clauses.
+
+* #pragma omp target parallel for [simd]: :partial:`Partial`.  No support for 
the `depend` clauses.
+
+* #pragma omp target simd: :partial:`Partial`.  No support for the `depend` 
clauses.
+
+* #pragma omp target teams: :partial:`Partial`.  No support for the `depend` 
clauses.
+
+* #pragma omp teams distribute [simd]: :good:`Complete`.
+
+* #pragma omp target teams distribute [simd]: :partial:`Partial`.  No support 
for the and `depend` clauses.
+
+* #pragma omp teams distribute parallel for [simd]: :good:`Complete`.
+
+* #pragma omp target teams distribute parallel for [simd]: :partial:`Partial`. 
 No full codegen support.
+
+Clang does not support any constructs/updates from upcoming OpenMP 5.0 except 
for `reduction`-based clauses in the `task` and `target`-based directives.
+

Modified: cfe/trunk/docs/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/index.rst?rev=322018&r1=322017&r2=322018&view=diff
==
--- cfe/trunk/docs/index.rst (original)
+++ cfe/trunk/docs/index.rst Mon Jan  8 11:02:51 2018
@@ -39,6 +39,7 @@ Using Clang as a Compiler
SourceBasedCodeCoverage
Modules
MSVCCompatibility
+   OpenMPSupport
ThinLTO
CommandGuide/index
FAQ


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322022 - [OPENMP] Fix debug info for outlined functions in NVPTX + add more tests.

2018-01-08 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jan  8 12:09:47 2018
New Revision: 322022

URL: http://llvm.org/viewvc/llvm-project?rev=322022&view=rev
Log:
[OPENMP] Fix debug info for outlined functions in NVPTX  + add more tests.

Fixed name of emitted outlined functions in NVPTX target + extra tests
for the debug info.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_debug_codegen.cpp
cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=322022&r1=322021&r2=322022&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Mon Jan  8 12:09:47 2018
@@ -262,7 +262,7 @@ void CGOpenMPRuntimeNVPTX::WorkerFunctio
 
   WorkerFn = llvm::Function::Create(
   CGM.getTypes().GetFunctionType(*CGFI), 
llvm::GlobalValue::InternalLinkage,
-  /* placeholder */ "_worker", &CGM.getModule());
+  /*placeholder=*/"_worker", &CGM.getModule());
   CGM.SetInternalFunctionAttributes(/*D=*/nullptr, WorkerFn, *CGFI);
 }
 
@@ -323,12 +323,12 @@ void CGOpenMPRuntimeNVPTX::emitGenericKe
   emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
IsOffloadEntry, CodeGen);
 
-  // Create the worker function
-  emitWorkerFunction(WST);
-
   // Now change the name of the worker function to correspond to this target
   // region's entry function.
   WST.WorkerFn->setName(OutlinedFn->getName() + "_worker");
+
+  // Create the worker function
+  emitWorkerFunction(WST);
 }
 
 // Setup NVPTX threads for master-worker OpenMP scheme.

Modified: cfe/trunk/test/OpenMP/nvptx_target_firstprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_firstprivate_codegen.cpp?rev=322022&r1=322021&r2=322022&view=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_firstprivate_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_firstprivate_codegen.cpp Mon Jan  8 
12:09:47 2018
@@ -219,3 +219,9 @@ int bar(int n, double *ptr) {
 // TCHECK: ret void
 
 #endif
+
+// TCHECK-DAG: distinct !DISubprogram(linkageName: 
"__omp_offloading_{{.+}}_worker",
+// TCHECK-DAG: distinct !DISubprogram(linkageName: 
"__omp_offloading_{{.+}}_worker",
+// TCHECK-DAG: distinct !DISubprogram(linkageName: 
"__omp_offloading_{{.+}}_worker",
+// TCHECK-DAG: distinct !DISubprogram(linkageName: 
"__omp_offloading_{{.+}}_worker",
+// TCHECK-DAG: distinct !DISubprogram(linkageName: 
"__omp_offloading_{{.+}}_worker",

Modified: cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp?rev=322022&r1=322021&r2=322022&view=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp Mon Jan  8 12:09:47 
2018
@@ -92,18 +92,18 @@ int main() {
 // CHECK: addrspacecast [10 x [10 x [10 x i32]]] addrspace(1)* %{{.+}} to [10 
x [10 x [10 x i32]]]*
 // CHECK: addrspacecast i32 addrspace(1)* %{{.+}} to i32*
 // CHECK: addrspacecast [10 x [10 x i32]] addrspace(1)* %{{.+}} to [10 x [10 x 
i32]]*
-// CHECK: call void [[NONDEBUG_WRAPPER:@.+]](i32* {{[^,]+}}, i32* {{[^,]+}}, 
[10 x [10 x [10 x i32]]]* {{[^,]+}}, i32* {{[^,]+}}, [10 x [10 x i32]]* 
{{[^,]+}}, i8* {{[^)]+}})
+// CHECK: call void @[[NONDEBUG_WRAPPER:.+]](i32* {{[^,]+}}, i32* {{[^,]+}}, 
[10 x [10 x [10 x i32]]]* {{[^,]+}}, i32* {{[^,]+}}, [10 x [10 x i32]]* 
{{[^,]+}}, i8* {{[^)]+}})
 
-// CHECK: define internal void [[DEBUG_PARALLEL:@.+]](i32* {{[^,]+}}, i32* 
{{[^,]+}}, [10 x [10 x [10 x i32]]] addrspace(1)* noalias{{[^,]+}}, i32 
addrspace(1)* noalias{{[^,]+}}, [10 x [10 x i32]] addrspace(1)* 
noalias{{[^,]+}}, i8 addrspace(1)* noalias{{[^)]+}})
+// CHECK: define internal void @[[DEBUG_PARALLEL:.+]](i32* {{[^,]+}}, i32* 
{{[^,]+}}, [10 x [10 x [10 x i32]]] addrspace(1)* noalias{{[^,]+}}, i32 
addrspace(1)* noalias{{[^,]+}}, [10 x [10 x i32]] addrspace(1)* 
noalias{{[^,]+}}, i8 addrspace(1)* noalias{{[^)]+}})
 // CHECK: addrspacecast [10 x [10 x [10 x i32]]] addrspace(1)* %{{.+}} to [10 
x [10 x [10 x i32]]]*
 // CHECK: addrspacecast i32 addrspace(1)* %{{.+}} to i32*
 // CHECK: addrspacecast [10 x [10 x i32]] addrspace(1)* %{{.+}} to [10 x [10 x 
i32]]*
 
-// CHECK: define internal void [[NONDEBUG_WRAPPER]](i32* {{[^,]+}}, i32* 
{{[^,]+}}, 

r322107 - [OpenMP] Fix handling of clause on wrong directive, by Joel. E. Denny

2018-01-09 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Jan  9 11:21:04 2018
New Revision: 322107

URL: http://llvm.org/viewvc/llvm-project?rev=322107&view=rev
Log:
[OpenMP] Fix handling of clause on wrong directive, by Joel. E. Denny

Summary:
First, this patch fixes an assert failure when, for example, "omp for"
has num_teams.

Second, this patch prevents duplicate diagnostics when, for example,
"omp for" has uniform.

This patch makes the general assumption (even where it doesn't
necessarily fix an existing bug) that it is worthless to perform sema
for a clause that appears on a directive on which OpenMP does not
permit that clause.  However, due to this assumption, this patch
suppresses some diagnostics that were expected in the test suite.  I
assert that those diagnostics were likely just distracting to the
user.

Reviewers: ABataev

Reviewed By: ABataev

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D41841

Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/test/OpenMP/distribute_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/for_misc_messages.c
cfe/trunk/test/OpenMP/parallel_messages.cpp
cfe/trunk/test/OpenMP/simd_loop_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_messages.cpp
cfe/trunk/test/OpenMP/taskloop_loop_messages.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=322107&r1=322106&r2=322107&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Jan  9 11:21:04 2018
@@ -2675,30 +2675,42 @@ private:
   /// \brief Parses clause with a single expression of a kind \a Kind.
   ///
   /// \param Kind Kind of current clause.
+  /// \param ParseOnly true to skip the clause's semantic actions and return
+  /// nullptr.
   ///
-  OMPClause *ParseOpenMPSingleExprClause(OpenMPClauseKind Kind);
+  OMPClause *ParseOpenMPSingleExprClause(OpenMPClauseKind Kind,
+ bool ParseOnly);
   /// \brief Parses simple clause of a kind \a Kind.
   ///
   /// \param Kind Kind of current clause.
+  /// \param ParseOnly true to skip the clause's semantic actions and return
+  /// nullptr.
   ///
-  OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind);
+  OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind, bool ParseOnly);
   /// \brief Parses clause with a single expression and an additional argument
   /// of a kind \a Kind.
   ///
   /// \param Kind Kind of current clause.
+  /// \param ParseOnly true to skip the clause's semantic actions and return
+  /// nullptr.
   ///
-  OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind);
+  OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind,
+bool ParseOnly);
   /// \brief Parses clause without any additional arguments.
   ///
   /// \param Kind Kind of current clause.
+  /// \param ParseOnly true to skip the clause's semantic actions and return
+  /// nullptr.
   ///
-  OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind);
+  OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly = false);
   /// \brief Parses clause with the list of variables of a kind \a Kind.
   ///
   /// \param Kind Kind of current clause.
+  /// \param ParseOnly true to skip the clause's semantic actions and return
+  /// nullptr.
   ///
   OMPClause *ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
-  OpenMPClauseKind Kind);
+  OpenMPClauseKind Kind, bool ParseOnly);
 
 public:
   /// Parses simple expression in parens for single-expression clauses of 
OpenMP

Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=322107&r1=322106&r2=322107&view=diff
==
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Tue Jan  9 11:21:04 2018
@@ -1205,11 +1205,13 @@ OMPClause *Parser::ParseOpenMPClause(Ope
  OpenMPClauseKind CKind, bool FirstClause) 
{
   OMPClause *Clause = nullptr;
   bool ErrorFound = false;
+  bool WrongDirective = false;
   // Check if clause is allowed for the given directive.
   if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
<< 
getOpenMPDirectiveName(DKind);
 ErrorFound = true;
+WrongDirective = true;
   }
 
   switch (CKind) {
@@ -1253,9 +1255,9 @@ OMPClause *Parser::ParseOpenMPClause(Ope
 }
 
 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
-  Clause = ParseOp

r322112 - [OPENMP] Fix directive kind on stand-alone target data directives, NFC.

2018-01-09 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Jan  9 11:59:25 2018
New Revision: 322112

URL: http://llvm.org/viewvc/llvm-project?rev=322112&view=rev
Log:
[OPENMP] Fix directive kind on stand-alone target data directives, NFC.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=322112&r1=322111&r2=322112&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jan  9 11:59:25 2018
@@ -7662,7 +7662,7 @@ void CGOpenMPRuntime::emitTargetDataStan
 if (D.hasClausesOfKind())
   CGF.EmitOMPTargetTaskBasedDirective(D, ThenGen, InputInfo);
 else
-  emitInlinedDirective(CGF, OMPD_target_update, ThenGen);
+  emitInlinedDirective(CGF, D.getDirectiveKind(), ThenGen);
   };
 
   if (IfCond)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Re: r322112 - [OPENMP] Fix directive kind on stand-alone target data directives, NFC.

2018-01-10 Thread Alexey Bataev via cfe-commits
These changes are just cosmetic, it does not affect real codegen for
target data directives.

-
Best regards,
Alexey Bataev

09.01.2018 15:31, Jonas Hahnfeld via cfe-commits пишет:
> Why is this NFC and doesn't change a test?
>
> Am 2018-01-09 20:59, schrieb Alexey Bataev via cfe-commits:
>> Author: abataev
>> Date: Tue Jan  9 11:59:25 2018
>> New Revision: 322112
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=322112&view=rev
>> Log:
>> [OPENMP] Fix directive kind on stand-alone target data directives, NFC.
>>
>> Modified:
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=322112&r1=322111&r2=322112&view=diff
>>
>> ==
>>
>> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jan  9 11:59:25 2018
>> @@ -7662,7 +7662,7 @@ void CGOpenMPRuntime::emitTargetDataStan
>>  if (D.hasClausesOfKind())
>>    CGF.EmitOMPTargetTaskBasedDirective(D, ThenGen, InputInfo);
>>  else
>> -  emitInlinedDirective(CGF, OMPD_target_update, ThenGen);
>> +  emitInlinedDirective(CGF, D.getDirectiveKind(), ThenGen);
>>    };
>>
>>    if (IfCond)
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>



signature.asc
Description: OpenPGP digital signature
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r326212 - [OPENMP] Allow multiple mappings for member expressions for pointers.

2018-02-27 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Feb 27 09:42:00 2018
New Revision: 326212

URL: http://llvm.org/viewvc/llvm-project?rev=326212&view=rev
Log:
[OPENMP] Allow multiple mappings for member expressions for pointers.

If several member expressions are mapped and they reference the same
address as a base, but access different members, this must be allowed.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_map_messages.cpp
cfe/trunk/test/OpenMP/target_teams_map_messages.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=326212&r1=326211&r2=326212&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Feb 27 09:42:00 
2018
@@ -8646,8 +8646,8 @@ def err_omp_pointer_mapped_along_with_de
   "pointer cannot be mapped along with a section derived from itself">;
 def err_omp_original_storage_is_shared_and_does_not_contain : Error<
   "original storage of expression in data environment is shared but data 
environment do not fully contain mapped expression storage">;
-def err_omp_same_pointer_derreferenced : Error<
-  "same pointer derreferenced in multiple different ways in map clause 
expressions">;
+def err_omp_same_pointer_dereferenced : Error<
+  "same pointer dereferenced in multiple different ways in map clause 
expressions">;
 def note_omp_task_predetermined_firstprivate_here : Note<
   "predetermined as a firstprivate in a task construct here">;
 def err_omp_threadprivate_incomplete_type : Error<

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=326212&r1=326211&r2=326212&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Feb 27 09:42:00 2018
@@ -11987,14 +11987,20 @@ static bool CheckMapConflicts(
 DerivedLoc,
 diag::err_omp_pointer_mapped_along_with_derived_section)
 << DerivedLoc;
-  } else {
+SemaRef.Diag(RE->getExprLoc(), diag::note_used_here)
+<< RE->getSourceRange();
+return true;
+  } else if (CI->getAssociatedExpression()->getStmtClass() !=
+ SI->getAssociatedExpression()->getStmtClass() ||
+ CI->getAssociatedDeclaration()->getCanonicalDecl() ==
+ SI->getAssociatedDeclaration()->getCanonicalDecl()) {
 assert(CI != CE && SI != SE);
-SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced)
+SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_dereferenced)
 << DerivedLoc;
+SemaRef.Diag(RE->getExprLoc(), diag::note_used_here)
+<< RE->getSourceRange();
+return true;
   }
-  SemaRef.Diag(RE->getExprLoc(), diag::note_used_here)
-  << RE->getSourceRange();
-  return true;
 }
 
 // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4]

Modified: cfe/trunk/test/OpenMP/target_map_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_map_messages.cpp?rev=326212&r1=326211&r2=326212&view=diff
==
--- cfe/trunk/test/OpenMP/target_map_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/target_map_messages.cpp Tue Feb 27 09:42:00 2018
@@ -235,9 +235,17 @@ void SAclient(int arg) {
   {}
   #pragma omp target map(r.ArrS[0].A, t.ArrS[1].A)
   {}
-  #pragma omp target map(r.PtrS[0], r.PtrS->B) // expected-error {{same 
pointer derreferenced in multiple different ways in map clause expressions}} 
expected-note {{used here}}
+  #pragma omp target map(r.PtrS[0], r.PtrS->B) // expected-error {{same 
pointer dereferenced in multiple different ways in map clause expressions}} 
expected-note {{used here}}
   {}
-  #pragma omp target map(r.RPtrS[0], r.RPtrS->B) // expected-error {{same 
pointer derreferenced in multiple different ways in map clause expressions}} 
expected-note {{used here}}
+  #pragma omp target map(r.PtrS, r.PtrS->B) // expected-error {{pointer cannot 
be mapped along with a section derived from itself}} expected-note {{used here}}
+  {}
+  #pragma omp target map(r.PtrS->A, r.PtrS->B)
+  {}
+  #pragma omp target map(r.RPtrS[0], r.RPtrS->B) // expected-error {{same 
pointer dereferenced in multiple different ways in map clause expressions}} 
expected-note {{used here}}
+  {}
+  #pragma omp target map(r.RPtrS, r.RPtrS->B) // expected-error {{pointer 
cannot be mapped along with a section derived from itself}} expected-note 
{{used here}}
+

r326590 - [OPENMP] Treat local variables in CUDA mode as thread local.

2018-03-02 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Mar  2 09:17:12 2018
New Revision: 326590

URL: http://llvm.org/viewvc/llvm-project?rev=326590&view=rev
Log:
[OPENMP] Treat local variables in CUDA mode as thread local.

In CUDA mode all local variables are actually thread
local|threadprivate, not private, and, thus, they cannot be shared
between threads|lanes.

Added:
cfe/trunk/test/OpenMP/nvptx_target_cuda_mode_messages.cpp
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=326590&r1=326589&r2=326590&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Mar  2 09:17:12 2018
@@ -1427,7 +1427,7 @@ def fopenmp_simd : Flag<["-"], "fopenmp-
   HelpText<"Emit OpenMP code only for SIMD-based constructs.">;
 def fno_openmp_simd : Flag<["-"], "fno-openmp-simd">, Group, 
Flags<[CC1Option, NoArgumentUnused]>;
 def fopenmp_cuda_mode : Flag<["-"], "fopenmp-cuda-mode">, Group, 
Flags<[CC1Option, NoArgumentUnused]>;
-def fno_openmp_cuda_mode : Flag<["-"], "fno-openmp-cuda-mode">, 
Group, Flags<[CC1Option, NoArgumentUnused]>;
+def fno_openmp_cuda_mode : Flag<["-"], "fno-openmp-cuda-mode">, 
Group, Flags<[NoArgumentUnused]>;
 def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, 
Group;
 def foptimize_sibling_calls : Flag<["-"], "foptimize-sibling-calls">, 
Group;
 def fno_escaping_block_tail_calls : Flag<["-"], 
"fno-escaping-block-tail-calls">, Group, Flags<[CC1Option]>;

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=326590&r1=326589&r2=326590&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Mar  2 09:17:12 2018
@@ -936,10 +936,11 @@ DSAStackTy::getTopMostTaskgroupReduction
 
 bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) {
   D = D->getCanonicalDecl();
-  if (!isStackEmpty() && Stack.back().first.size() > 1) {
+  if (!isStackEmpty()) {
 reverse_iterator I = Iter, E = Stack.back().first.rend();
 Scope *TopScope = nullptr;
-while (I != E && !isParallelOrTaskRegion(I->Directive))
+while (I != E && !isParallelOrTaskRegion(I->Directive) &&
+   !isOpenMPTargetExecutionDirective(I->Directive))
   ++I;
 if (I == E)
   return false;
@@ -956,20 +957,7 @@ DSAStackTy::DSAVarData DSAStackTy::getTo
   D = getCanonicalDecl(D);
   DSAVarData DVar;
 
-  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
-  // in a Construct, C/C++, predetermined, p.1]
-  //  Variables appearing in threadprivate directives are threadprivate.
   auto *VD = dyn_cast(D);
-  if ((VD && VD->getTLSKind() != VarDecl::TLS_None &&
-   !(VD->hasAttr() &&
- SemaRef.getLangOpts().OpenMPUseTLS &&
- SemaRef.getASTContext().getTargetInfo().isTLSSupported())) ||
-  (VD && VD->getStorageClass() == SC_Register &&
-   VD->hasAttr() && !VD->isLocalVarDecl())) {
-addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(),
-   D->getLocation()),
-   OMPC_threadprivate);
-  }
   auto TI = Threadprivates.find(D);
   if (TI != Threadprivates.end()) {
 DVar.RefExpr = TI->getSecond().RefExpr.getPointer();
@@ -981,6 +969,62 @@ DSAStackTy::DSAVarData DSAStackTy::getTo
 VD->getAttr()->getLocation());
 DVar.CKind = OMPC_threadprivate;
 addDSA(D, DVar.RefExpr, OMPC_threadprivate);
+return DVar;
+  }
+  // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
+  // in a Construct, C/C++, predetermined, p.1]
+  //  Variables appearing in threadprivate directives are threadprivate.
+  if ((VD && VD->getTLSKind() != VarDecl::TLS_None &&
+   !(VD->hasAttr() &&
+ SemaRef.getLangOpts().OpenMPUseTLS &&
+ SemaRef.getASTContext().getTargetInfo().isTLSSupported())) ||
+  (VD && VD->getStorageClass() == SC_Register &&
+   VD->hasAttr() && !VD->isLocalVarDecl())) {
+DVar.RefExpr = buildDeclRefExpr(
+SemaRef, VD, D->getType().getNonReferenceType(), D->getLocation());
+DVar.CKind = OMPC_threadprivate;
+addDSA(D, DVar.RefExpr, OMPC_threadprivate);
+return DVar;
+  }
+  if (SemaRef.getLangOpts().OpenMPCUDAMode && VD &&
+  VD->isLocalVarDeclOrParm() && !isStackEmpty() &&
+  !isLoopControlVariable(D).first) {
+auto IterTarget =
+std::find_if(Stack.back().first.rbegin(), Stack.back().first.rend(),
+ [](const SharingMapTy &Data) {
+   return isOpenMPTargetExecutionDirective(Data.Directive);
+ });
+if (IterTarget != Stack.back().first.r

r326594 - [OPENMP] Scan all redeclarations looking for `declare simd` attribute.

2018-03-02 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Mar  2 10:07:00 2018
New Revision: 326594

URL: http://llvm.org/viewvc/llvm-project?rev=326594&view=rev
Log:
[OPENMP] Scan all redeclarations looking for `declare simd` attribute.

Patch fixes the problem with the functions marked as `declare simd`. If
the canonical declaration does not have associated `declare simd`
construct, we may not generate required code even if other
redeclarations are marked as `declare simd`.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/declare_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=326594&r1=326593&r2=326594&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Mar  2 10:07:00 2018
@@ -7861,7 +7861,7 @@ emitX86DeclareSimdFunction(const Functio
 void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
   llvm::Function *Fn) {
   ASTContext &C = CGM.getContext();
-  FD = FD->getCanonicalDecl();
+  FD = FD->getMostRecentDecl();
   // Map params to their positions in function decl.
   llvm::DenseMap ParamPositions;
   if (isa(FD))
@@ -7871,80 +7871,84 @@ void CGOpenMPRuntime::emitDeclareSimdFun
 ParamPositions.insert({P->getCanonicalDecl(), ParamPos});
 ++ParamPos;
   }
-  for (auto *Attr : FD->specific_attrs()) {
-llvm::SmallVector ParamAttrs(ParamPositions.size());
-// Mark uniform parameters.
-for (auto *E : Attr->uniforms()) {
-  E = E->IgnoreParenImpCasts();
-  unsigned Pos;
-  if (isa(E))
-Pos = ParamPositions[FD];
-  else {
-auto *PVD = cast(cast(E)->getDecl())
-->getCanonicalDecl();
-Pos = ParamPositions[PVD];
-  }
-  ParamAttrs[Pos].Kind = Uniform;
-}
-// Get alignment info.
-auto NI = Attr->alignments_begin();
-for (auto *E : Attr->aligneds()) {
-  E = E->IgnoreParenImpCasts();
-  unsigned Pos;
-  QualType ParmTy;
-  if (isa(E)) {
-Pos = ParamPositions[FD];
-ParmTy = E->getType();
-  } else {
-auto *PVD = cast(cast(E)->getDecl())
-->getCanonicalDecl();
-Pos = ParamPositions[PVD];
-ParmTy = PVD->getType();
+  while (FD) {
+for (auto *Attr : FD->specific_attrs()) {
+  llvm::SmallVector ParamAttrs(ParamPositions.size());
+  // Mark uniform parameters.
+  for (auto *E : Attr->uniforms()) {
+E = E->IgnoreParenImpCasts();
+unsigned Pos;
+if (isa(E))
+  Pos = ParamPositions[FD];
+else {
+  auto *PVD = cast(cast(E)->getDecl())
+  ->getCanonicalDecl();
+  Pos = ParamPositions[PVD];
+}
+ParamAttrs[Pos].Kind = Uniform;
   }
-  ParamAttrs[Pos].Alignment =
-  (*NI) ? (*NI)->EvaluateKnownConstInt(C)
+  // Get alignment info.
+  auto NI = Attr->alignments_begin();
+  for (auto *E : Attr->aligneds()) {
+E = E->IgnoreParenImpCasts();
+unsigned Pos;
+QualType ParmTy;
+if (isa(E)) {
+  Pos = ParamPositions[FD];
+  ParmTy = E->getType();
+} else {
+  auto *PVD = cast(cast(E)->getDecl())
+  ->getCanonicalDecl();
+  Pos = ParamPositions[PVD];
+  ParmTy = PVD->getType();
+}
+ParamAttrs[Pos].Alignment =
+(*NI)
+? (*NI)->EvaluateKnownConstInt(C)
 : llvm::APSInt::getUnsigned(
   
C.toCharUnitsFromBits(C.getOpenMPDefaultSimdAlign(ParmTy))
   .getQuantity());
-  ++NI;
-}
-// Mark linear parameters.
-auto SI = Attr->steps_begin();
-auto MI = Attr->modifiers_begin();
-for (auto *E : Attr->linears()) {
-  E = E->IgnoreParenImpCasts();
-  unsigned Pos;
-  if (isa(E))
-Pos = ParamPositions[FD];
-  else {
-auto *PVD = cast(cast(E)->getDecl())
-->getCanonicalDecl();
-Pos = ParamPositions[PVD];
+++NI;
   }
-  auto &ParamAttr = ParamAttrs[Pos];
-  ParamAttr.Kind = Linear;
-  if (*SI) {
-if (!(*SI)->EvaluateAsInt(ParamAttr.StrideOrArg, C,
-  Expr::SE_AllowSideEffects)) {
-  if (auto *DRE = cast((*SI)->IgnoreParenImpCasts())) {
-if (auto *StridePVD = cast(DRE->getDecl())) {
-  ParamAttr.Kind = LinearWithVarStride;
-  ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(
-  ParamPositions[StridePVD->getCanonicalDecl()]);
+  // Mark linear parameters.
+  auto SI = Attr->steps_begin();
+  auto MI = Attr->modifiers_begin();
+  for (auto *E : Attr->linears()) {
+E = E->IgnoreParenImp

r326827 - [OPENMP] Fix generation of the unique names for task reduction

2018-03-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Mar  6 10:59:43 2018
New Revision: 326827

URL: http://llvm.org/viewvc/llvm-project?rev=326827&view=rev
Log:
[OPENMP] Fix generation of the unique names for task reduction
variables.

If the task has reduction construct and this construct for some variable
requires unique threadprivate storage, we may generate different names
for variables used in taskgroup task_reduction clause and in task
  in_reduction clause. Patch fixes this problem.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=326827&r1=326826&r2=326827&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Mar  6 10:59:43 2018
@@ -1101,11 +1101,9 @@ static Address castToBase(CodeGenFunctio
   return Address(Addr, BaseLVAlignment);
 }
 
-Address ReductionCodeGen::adjustPrivateAddress(CodeGenFunction &CGF, unsigned 
N,
-   Address PrivateAddr) {
-  const DeclRefExpr *DE;
+static const VarDecl *getBaseDecl(const Expr *Ref, const DeclRefExpr *&DE) {
   const VarDecl *OrigVD = nullptr;
-  if (auto *OASE = dyn_cast(ClausesData[N].Ref)) {
+  if (auto *OASE = dyn_cast(Ref)) {
 auto *Base = OASE->getBase()->IgnoreParenImpCasts();
 while (auto *TempOASE = dyn_cast(Base))
   Base = TempOASE->getBase()->IgnoreParenImpCasts();
@@ -1113,14 +,20 @@ Address ReductionCodeGen::adjustPrivateA
   Base = TempASE->getBase()->IgnoreParenImpCasts();
 DE = cast(Base);
 OrigVD = cast(DE->getDecl());
-  } else if (auto *ASE = dyn_cast(ClausesData[N].Ref)) {
+  } else if (auto *ASE = dyn_cast(Ref)) {
 auto *Base = ASE->getBase()->IgnoreParenImpCasts();
 while (auto *TempASE = dyn_cast(Base))
   Base = TempASE->getBase()->IgnoreParenImpCasts();
 DE = cast(Base);
 OrigVD = cast(DE->getDecl());
   }
-  if (OrigVD) {
+  return OrigVD;
+}
+
+Address ReductionCodeGen::adjustPrivateAddress(CodeGenFunction &CGF, unsigned 
N,
+   Address PrivateAddr) {
+  const DeclRefExpr *DE;
+  if (const VarDecl *OrigVD = ::getBaseDecl(ClausesData[N].Ref, DE)) {
 BaseDecls.emplace_back(OrigVD);
 auto OriginalBaseLValue = CGF.EmitLValue(DE);
 LValue BaseLValue =
@@ -5355,12 +5359,19 @@ void CGOpenMPRuntime::emitReduction(Code
 }
 
 /// Generates unique name for artificial threadprivate variables.
-/// Format is:  "."  "_" 
-static std::string generateUniqueName(StringRef Prefix, SourceLocation Loc,
-  unsigned N) {
+/// Format is:  "."  "_" ""
+static std::string generateUniqueName(CodeGenModule &CGM, StringRef Prefix,
+  const Expr *Ref) {
   SmallString<256> Buffer;
   llvm::raw_svector_ostream Out(Buffer);
-  Out << Prefix << "." << Loc.getRawEncoding() << "_" << N;
+  const clang::DeclRefExpr *DE;
+  const VarDecl *D = ::getBaseDecl(Ref, DE);
+  if (!D)
+D = cast(cast(Ref)->getDecl());
+  D = D->getCanonicalDecl();
+  Out << Prefix << "."
+  << (D->isLocalVarDeclOrParm() ? D->getName() : CGM.getMangledName(D))
+  << "_" << D->getCanonicalDecl()->getLocStart().getRawEncoding();
   return Out.str();
 }
 
@@ -5397,7 +5408,7 @@ static llvm::Value *emitReduceInitFuncti
   if (RCG.getSizes(N).second) {
 Address SizeAddr = CGM.getOpenMPRuntime().getAddrOfArtificialThreadPrivate(
 CGF, CGM.getContext().getSizeType(),
-generateUniqueName("reduction_size", Loc, N));
+generateUniqueName(CGM, "reduction_size", RCG.getRefExpr(N)));
 Size = CGF.EmitLoadOfScalar(SizeAddr, /*Volatile=*/false,
 CGM.getContext().getSizeType(), Loc);
   }
@@ -5410,7 +5421,7 @@ static llvm::Value *emitReduceInitFuncti
 Address SharedAddr =
 CGM.getOpenMPRuntime().getAddrOfArtificialThreadPrivate(
 CGF, CGM.getContext().VoidPtrTy,
-generateUniqueName("reduction", Loc, N));
+generateUniqueName(CGM, "reduction", RCG.getRefExpr(N)));
 SharedLVal = CGF.MakeAddrLValue(SharedAddr, CGM.getContext().VoidPtrTy);
   } else {
 SharedLVal = CGF.MakeNaturalAlignAddrLValue(
@@ -5466,7 +5477,7 @@ static llvm::Value *emitReduceCombFuncti
   if (RCG.getSizes(N).second) {
 Address SizeAddr = CGM.getOpenMPRuntime().getAddrOfArtificialThreadPrivate(
 CGF, CGM.getContext().getSizeType(),
-generateUniqueName("reduction_size", Loc, N));
+generateUniqueName(CGM, "reduction_size", RCG.getRefExpr(N)));
 Size = CGF.EmitLoadOfScalar(SizeAddr, /*Volatile=*/false,
 CGM.getContext().getSizeType(), Loc);
   }
@@ -5537,7 +5548,7 @@ static 

  1   2   3   4   5   6   7   8   9   10   >