[PATCH] D86047: [clangd] Target member of dependent base made visible via a using-decl

2020-08-17 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 285922.
nridge added a comment.

Update a comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86047/new/

https://reviews.llvm.org/D86047

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -734,7 +734,17 @@
 Fo^o * getFoo() {
   return 0;
 }
-  )objc"};
+  )objc",
+  R"cpp(// Member of dependent base
+template 
+struct Base {
+  void [[waldo]]() {}
+};
+template 
+struct Derived : Base {
+  using Base::w^aldo;
+};
+  )cpp"};
   for (const char *Test : Tests) {
 Annotations T(Test);
 llvm::Optional WantDecl;
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -345,7 +345,7 @@
 
 // Give the underlying decl if navigation is triggered on a non-renaming
 // alias.
-if (llvm::isa(D)) {
+if (llvm::isa(D) || llvm::isa(D)) {
   // FIXME: address more complicated cases. TargetDecl(... Underlying) gives
   // all overload candidates, we only want the targeted one if the cursor is
   // on an using-alias usage, workround it with getDeclAtPosition.
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -100,7 +100,7 @@
 std::vector getMembersReferencedViaDependentName(
 const Type *T,
 llvm::function_ref NameFactory,
-bool IsNonstaticMember) {
+llvm::function_ref Filter) {
   if (!T)
 return {};
   if (auto *ET = T->getAs()) {
@@ -113,17 +113,24 @@
   return {};
 RD = RD->getDefinition();
 DeclarationName Name = NameFactory(RD->getASTContext());
-return RD->lookupDependentName(Name, [=](const NamedDecl *D) {
-  return IsNonstaticMember ? D->isCXXInstanceMember()
-   : !D->isCXXInstanceMember();
-});
+return RD->lookupDependentName(Name, Filter);
   }
   return {};
 }
 
-// Given the type T of a dependent expression that appears of the LHS of a "->",
-// heuristically find a corresponding pointee type in whose scope we could look
-// up the name appearing on the RHS.
+const auto NonStaticFilter = [](const NamedDecl *D) {
+  return D->isCXXInstanceMember();
+};
+const auto StaticFilter = [](const NamedDecl *D) {
+  return !D->isCXXInstanceMember();
+};
+const auto ValueFilter = [](const NamedDecl *D) {
+  return dyn_cast(D) != nullptr;
+};
+
+// Given the type T of a dependent expression that appears of the LHS of a
+// "->", heuristically find a corresponding pointee type in whose scope we
+// could look up the name appearing on the RHS.
 const Type *getPointeeType(const Type *T) {
   if (!T)
 return nullptr;
@@ -141,7 +148,7 @@
   [](ASTContext &Ctx) {
 return Ctx.DeclarationNames.getCXXOperatorName(OO_Arrow);
   },
-  /*IsNonStaticMember=*/true);
+  NonStaticFilter);
   if (ArrowOps.empty())
 return nullptr;
 
@@ -187,13 +194,12 @@
 }
 return getMembersReferencedViaDependentName(
 BaseType, [ME](ASTContext &) { return ME->getMember(); },
-/*IsNonstaticMember=*/true);
+NonStaticFilter);
   }
   if (const auto *RE = dyn_cast(E)) {
 return getMembersReferencedViaDependentName(
 RE->getQualifier()->getAsType(),
-[RE](ASTContext &) { return RE->getDeclName(); },
-/*IsNonstaticMember=*/false);
+[RE](ASTContext &) { return RE->getDeclName(); }, StaticFilter);
   }
   if (const auto *CE = dyn_cast(E)) {
 const auto *CalleeType = resolveExprToType(CE->getCallee());
@@ -291,7 +297,6 @@
 // CXXDependentScopeMemberExpr, but some other constructs remain to be handled:
 //  - DependentTemplateSpecializationType,
 //  - DependentNameType
-//  - UnresolvedUsingValueDecl
 //  - UnresolvedUsingTypenameDecl
 struct TargetFinder {
   using RelSet = DeclRelationSet;
@@ -345,6 +350,15 @@
 } else if (const auto *NAD = dyn_cast(D)) {
   add(NAD->getUnderlyingDecl(), Flags | Rel::Underlying);
   Flags |= Rel::Alias; // continue with the alias
+} else if (const UnresolvedUsingValueDecl *UUVD =
+   dyn_cast(D)) {
+  for (const NamedDecl *Target : getMembersReferencedViaDependentName(
+   UUVD->getQualifier()->getAsType(),
+   [UUVD](ASTContext &) { return UUVD->getNameInfo().getName(); },
+   ValueFilter)) {
+add(Target, Flags | Rel::Underlying);
+  }
+ 

[PATCH] D84415: [analyzer][StdLibraryFunctionsChecker] Add POSIX pthread handling functions

2020-08-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

It is better now, but the refactoring change should be in a separate revision 
(it affects the other already added functions too).




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:350
+  } else {
+*this = Signature(Args, *RetTy);
   }

Not very bad but I do not like to call another constructor and assignment here, 
this can be many redundant operations. It is better to fill the internal arrays 
here and have a separate assert function that checks for validness (of the 
internal arrays) instead of the private constructor.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:378
 
   static QualType getArgType(const FunctionDecl *FD, ArgNo ArgN) {
 assert(FD && "Function must be set");

Check for isInvalid here (with assert)?



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:882
+  const QualType SizePtrTy = getPointerTy(SizeTy);
+  const QualType SizePtrRestrictTy = getRestrictTy(SizePtrTy);
 

Another idea: Have a class that handles all the variants (simple, pointer, 
const pointer, const restrict pointer, restrict). It can have get functions 
that compute the type if not done yet, or get every variant at first time even 
if it is later not used (or has no sense).
For example create it like `TypeVariants SizeTy{ACtx.getSizeType()};` and then 
call `SizeTy.getType()`, `SizeTy.asPtr()`, `SizeTy.asPtrRestrict()`, ... .
```



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1026
   Optional FilePtrTy, FilePtrRestrictTy;
   if (FileTy) {
 // FILE *

These `if`s can be removed too (in another patch).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84415/new/

https://reviews.llvm.org/D84415

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


[PATCH] D86048: [AST][RecoveryExpr] Popagate the error-bit from a VarDecl's initializer to DeclRefExpr.

2020-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.
hokein requested review of this revision.

The error-bit was missing, if a DeclRefExpr (which refers to a VarDecl
with a contains-errors initializer).

It could cause different violations in clang -- the DeclRefExpr is 
value-dependent,
but not contains-errors, `decltype(DeclRefExpr)` could produce a non-error
dependent type in non-template context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86048

Files:
  clang/lib/AST/ComputeDependence.cpp
  clang/test/Sema/invalid-member.cpp
  clang/test/SemaCXX/invalid-template-base-specifier.cpp


Index: clang/test/SemaCXX/invalid-template-base-specifier.cpp
===
--- clang/test/SemaCXX/invalid-template-base-specifier.cpp
+++ clang/test/SemaCXX/invalid-template-base-specifier.cpp
@@ -26,3 +26,10 @@
 };
 
 void test3() { Crash3(); } // expected-note {{in instantiation of 
template class}}
+
+constexpr int N = undef; // expected-error {{use of undeclared identifier}}
+
+class Crash4 : decltype(N) {
+};
+
+static_assert(sizeof(Crash4) == 1, "");
Index: clang/test/Sema/invalid-member.cpp
===
--- clang/test/Sema/invalid-member.cpp
+++ clang/test/Sema/invalid-member.cpp
@@ -19,3 +19,10 @@
 };
 // Should be able to evaluate sizeof without crashing.
 static_assert(sizeof(Z) == 1, "No valid members");
+
+constexpr int N = undef; // expected-error {{use of undeclared identifier}}
+
+class T {
+  decltype(N) member;
+};
+static_assert(sizeof(T) == 1, "No valid members");
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -466,11 +466,13 @@
  : Var->getType()->isIntegralOrEnumerationType()) &&
 (Var->getType().isConstQualified() ||
  Var->getType()->isReferenceType())) {
-  if (const Expr *Init = Var->getAnyInitializer())
-if (Init->isValueDependent()) {
+  if (const Expr *Init = Var->getAnyInitializer()) {
+if (Init->isValueDependent())
   Deps |= ExprDependence::ValueInstantiation;
+if (Init->containsErrors()) {
+  Deps |= ExprDependence::Error;
 }
-}
+  }
 
 // (VD) - FIXME: Missing from the standard:
 //  -  a member function or a static data member of the current


Index: clang/test/SemaCXX/invalid-template-base-specifier.cpp
===
--- clang/test/SemaCXX/invalid-template-base-specifier.cpp
+++ clang/test/SemaCXX/invalid-template-base-specifier.cpp
@@ -26,3 +26,10 @@
 };
 
 void test3() { Crash3(); } // expected-note {{in instantiation of template class}}
+
+constexpr int N = undef; // expected-error {{use of undeclared identifier}}
+
+class Crash4 : decltype(N) {
+};
+
+static_assert(sizeof(Crash4) == 1, "");
Index: clang/test/Sema/invalid-member.cpp
===
--- clang/test/Sema/invalid-member.cpp
+++ clang/test/Sema/invalid-member.cpp
@@ -19,3 +19,10 @@
 };
 // Should be able to evaluate sizeof without crashing.
 static_assert(sizeof(Z) == 1, "No valid members");
+
+constexpr int N = undef; // expected-error {{use of undeclared identifier}}
+
+class T {
+  decltype(N) member;
+};
+static_assert(sizeof(T) == 1, "No valid members");
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -466,11 +466,13 @@
  : Var->getType()->isIntegralOrEnumerationType()) &&
 (Var->getType().isConstQualified() ||
  Var->getType()->isReferenceType())) {
-  if (const Expr *Init = Var->getAnyInitializer())
-if (Init->isValueDependent()) {
+  if (const Expr *Init = Var->getAnyInitializer()) {
+if (Init->isValueDependent())
   Deps |= ExprDependence::ValueInstantiation;
+if (Init->containsErrors()) {
+  Deps |= ExprDependence::Error;
 }
-}
+  }
 
 // (VD) - FIXME: Missing from the standard:
 //  -  a member function or a static data member of the current
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2020-08-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: rjmccall, manmanren, MadCoder.
Herald added subscribers: cfe-commits, dang.
Herald added a project: clang.
plotfi requested review of this revision.

Hi @rjmccall @MadCoder

I'd like to preface this diff: I mostly want to discuss the prospects of 
exporting generated wrappers that call objc_direct methods, or alternately 
exporting the objc_direct methods themselves when an optional CodeGenOpts 
command-line flag is specified. This diff implements generating wrappers when a 
CodeGenOpts command-line flag is provided since C wrappers were mentioned in 
the original objc_direct diff. However I do think it might be possible to 
export the methods directly provided the implicit '_' underbar prefix is 
prepended to satisfy C naming on Darwin, and if thats the case I can post a 
diff that does that instead.  Anyways, thats all I wanted to preface with. 
Thanks.

Motivated by the potential benefit of using the objc_direct attribute, this 
diff aims to expand support to cross dylib objc_direct method calls by 
automatically generating exportable wrapper functions that call objc_direct 
methods internal to a dylib.

In the original patch landed in https://reviews.llvm.org/D69991 it mentions:

"The symbol for the method has enforced hidden visibility and such direct
calls are hence unreachable cross image. An explicit C function must be
made if so desired to wrap them."

This change provides a codegen options flag to clang 
`-fobjc-export-direct-method-wrappers` to generate the wrapper functions that 
begin with the prefix __objc_direct_wrapper and are marked as 
__attribute__((alwaysinline)). This way within a link unit the wrapper 
functions should be inlined away at their call sites, but across a dylib 
boundary the wrapper call is used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86049

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1283,6 +1283,8 @@
 }
   }
 
+  if (Args.hasArg(OPT_fobjc_export_direct_method_wrappers))
+Opts.ObjCExportDirectMethodWrappers = 1;
 
   if (Args.hasArg(OPT_fno_objc_convert_messages_to_runtime_calls))
 Opts.ObjCConvertMessagesToRuntimeCalls = 0;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3462,6 +3462,9 @@
   CmdArgs.push_back("-fno-objc-convert-messages-to-runtime-calls");
   }
 
+  if (Args.hasArg(options::OPT_fobjc_export_direct_method_wrappers))
+CmdArgs.push_back("-fobjc-export-direct-method-wrappers");
+
   // -fobjc-infer-related-result-type is the default, except in the Objective-C
   // rewriter.
   if (InferCovariantReturns)
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -2143,6 +2143,36 @@
   return false;
 }
 
+/// Create or look up the declaration of an objc_direct method wrapper.
+llvm::Function *getObjCDirectWrapper(llvm::Function &F) {
+  std::string NewName = "__objc_direct_wrapper";
+  for (auto C : F.getName().str()) {
+if (C == '\1')
+  continue;
+NewName += C;
+  }
+
+  auto WI = llvm::find_if(*F.getParent(), [NewName](const llvm::Function &F) {
+return F.getName() == NewName;
+  });
+
+  llvm::Function *Wrapper = nullptr;
+  if (WI == F.getParent()->end()) {
+llvm::Module &M = *F.getParent();
+llvm::FunctionType *FnTy = F.getFunctionType();
+Wrapper = llvm::Function::Create(FnTy, F.getLinkage(), F.getAddressSpace(),
+ NewName);
+Wrapper->setLinkage(llvm::GlobalValue::ExternalLinkage);
+Wrapper->addFnAttr(llvm::Attribute::AlwaysInline);
+Wrapper->setVisibility(llvm::Function::DefaultVisibility);
+M.getFunctionList().insert(F.getIterator(), Wrapper);
+  } else {
+Wrapper = &*WI;
+  }
+
+  return Wrapper;
+}
+
 CodeGen::RValue
 CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
  ReturnValueSlot Return,
@@ -2214,7 +2244,13 @@
 
   llvm::FunctionCallee Fn = nullptr;
   if (Method && Method->isDirectMethod()) {
-Fn = GenerateDirectMethod(Method, Method->getClassInterface());
+if (CGM.getCodeGenOpts().ObjCExportDirectMethodWrappers) {
+  llvm::Function *FnDirect =
+GenerateDirectMethod(Method, Method->getClassInterface());
+  Fn = getObjCDirectWrapper(*FnDirect);
+} else {
+  Fn = GenerateDirectMethod(Method, Method->getClassI

[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2020-08-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 285925.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86049/new/

https://reviews.llvm.org/D86049

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenObjC/objc-direct-wrapper.m

Index: clang/test/CodeGenObjC/objc-direct-wrapper.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-direct-wrapper.m
@@ -0,0 +1,43 @@
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN:   -fobjc-export-direct-method-wrappers -c -o - %s | \
+// RUN: llvm-nm - | FileCheck -check-prefix=CHECK-WRAPPER %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s | llvm-nm - | \
+// RUN: FileCheck -check-prefix=CHECK-DEFAULT %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN:   -fobjc-export-direct-method-wrappers -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DEFINE %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -DNO_OBJC_IMPL \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN:   -fobjc-export-direct-method-wrappers -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DECLARE %s
+
+// CHECK-WRAPPER: T ___objc_direct_wrapper-[C testMethod:bar:]
+// CHECK-DEFAULT-NOT: ___objc_direct_wrapper
+// CHECK-WRAPPER-IR-DEFINE: define {{(dso_local )?}}{{(dso_local )?}}void @"__objc_direct_wrapper-[C testMethod:bar:]"
+// CHECK-WRAPPER-IR-DECLARE: declare {{(dso_local )?}}void @"__objc_direct_wrapper-[C testMethod:bar:]"
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 __attribute((objc_direct));
+@end
+
+#ifndef NO_OBJC_IMPL
+@implementation C
+- (void)testMethod:(int)arg1 bar:(float)arg2 __attribute((objc_direct)) {
+}
+@end
+#endif
+
+C *c;
+
+void f() {
+  [c testMethod:1 bar:1.0];
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1283,6 +1283,8 @@
 }
   }
 
+  if (Args.hasArg(OPT_fobjc_export_direct_method_wrappers))
+Opts.ObjCExportDirectMethodWrappers = 1;
 
   if (Args.hasArg(OPT_fno_objc_convert_messages_to_runtime_calls))
 Opts.ObjCConvertMessagesToRuntimeCalls = 0;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3462,6 +3462,9 @@
   CmdArgs.push_back("-fno-objc-convert-messages-to-runtime-calls");
   }
 
+  if (Args.hasArg(options::OPT_fobjc_export_direct_method_wrappers))
+CmdArgs.push_back("-fobjc-export-direct-method-wrappers");
+
   // -fobjc-infer-related-result-type is the default, except in the Objective-C
   // rewriter.
   if (InferCovariantReturns)
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -2143,6 +2143,36 @@
   return false;
 }
 
+/// Create or look up the declaration of an objc_direct method wrapper.
+llvm::Function *getObjCDirectWrapper(llvm::Function &F) {
+  std::string NewName = "__objc_direct_wrapper";
+  for (auto C : F.getName().str()) {
+if (C == '\1')
+  continue;
+NewName += C;
+  }
+
+  auto WI = llvm::find_if(*F.getParent(), [NewName](const llvm::Function &F) {
+return F.getName() == NewName;
+  });
+
+  llvm::Function *Wrapper = nullptr;
+  if (WI == F.getParent()->end()) {
+llvm::Module &M = *F.getParent();
+llvm::FunctionType *FnTy = F.getFunctionType();
+Wrapper = llvm::Function::Create(FnTy, F.getLinkage(), F.getAddressSpace(),
+ NewName);
+Wrapper->setLinkage(llvm::GlobalValue::ExternalLinkage);
+Wrapper->addFnAttr(llvm::Attribute::AlwaysInline);
+Wrapper->setVisibility(llvm::Function::DefaultVisibility);
+M.getFunctionList().insert(F.getIterator(), Wrapper);
+  } else {
+Wrapper = &*WI;
+  }
+
+  return Wrapper;
+}
+
 CodeGen::RValue
 CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
  ReturnValueSlot Return,
@@ -2214,7 +2244,13 @@
 
   llvm::FunctionCallee Fn = nullptr;
   if (Method && Method->isDirectMethod()) {
-Fn = GenerateDirectMethod(Method, Method->getClassInterface());
+if (CGM.getCodeGenOpts().ObjCExportDirectMethodW

[PATCH] D84136: [clang] Fix visitation of ConceptSpecializationExpr in constrained-parameter

2020-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks!




Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:1781
+  if (const auto *TC = D->getTypeConstraint()) {
+Expr *IDC = TC->getImmediatelyDeclaredConstraint();
+TRY_TO(TraverseStmt(IDC));

nit: just 

```
if (Expr *IDC = ...) {
  ...
} else {
TRY_TO(TraverseConceptReference(*TC));
}
```



Comment at: clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp:2
+//===- unittest/Tooling/RecursiveASTVisitorTests/Concept.cpp
+//===//
+//

nit: should be merged in the above line.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84136/new/

https://reviews.llvm.org/D84136

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


[PATCH] D83536: [clangd] Index refs to main-file symbols as well

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, LGTM!




Comment at: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:727
+  // Run the collector again with CollectMainFileRefs = true.
+  InMemoryFileSystem = new llvm::vfs::InMemoryFileSystem();
+  CollectorOpts.CollectMainFileRefs = true;

i don't think this is needed, am I missing something? IIRC, inmemoryfs should 
overwrite any existing files and even if it doesn't we are not really changing 
file contents in here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83536/new/

https://reviews.llvm.org/D83536

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


[PATCH] D85826: [clang] Make signature help work with dependent args

2020-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks better.




Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5513
   for (OverloadCandidate &Candidate : CandidateSet) {
-if (Candidate.Function && Candidate.Function->isDeleted())
-  continue;
+if (Candidate.Function) {
+  if (Candidate.Function->isDeleted())

nit: use early return.

```
if (!Candidate.Function) {
  continue;
}
...
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85826/new/

https://reviews.llvm.org/D85826

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


[PATCH] D85826: [clang] Make signature help work with dependent args

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5513
   for (OverloadCandidate &Candidate : CandidateSet) {
-if (Candidate.Function && Candidate.Function->isDeleted())
-  continue;
+if (Candidate.Function) {
+  if (Candidate.Function->isDeleted())

hokein wrote:
> nit: use early return.
> 
> ```
> if (!Candidate.Function) {
>   continue;
> }
> ...
> ```
i wanted to do that, but it changes the semantics. as push_back below executes 
even when Candidate.Function is `nullptr` :/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85826/new/

https://reviews.llvm.org/D85826

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


[clang] 53c593c - [clang] Make signature help work with dependent args

2020-08-17 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-08-17T10:06:36+02:00
New Revision: 53c593c2c893a40083771789e3d3e164eea1892d

URL: 
https://github.com/llvm/llvm-project/commit/53c593c2c893a40083771789e3d3e164eea1892d
DIFF: 
https://github.com/llvm/llvm-project/commit/53c593c2c893a40083771789e3d3e164eea1892d.diff

LOG: [clang] Make signature help work with dependent args

Fixes https://github.com/clangd/clangd/issues/490

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/call.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index fd144d9391d3..635e036039a0 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1166,46 +1166,75 @@ TEST(SignatureHelpTest, ActiveArg) {
 }
 
 TEST(SignatureHelpTest, OpeningParen) {
-  llvm::StringLiteral Tests[] = {// Recursive function call.
- R"cpp(
-int foo(int a, int b, int c);
-int main() {
-  foo(foo $p^( foo(10, 10, 10), ^ )));
-})cpp",
- // Functional type cast.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  Foo $p^( 10, ^ );
-})cpp",
- // New expression.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  new Foo $p^( 10, ^ );
-})cpp",
- // Macro expansion.
- R"cpp(
-int foo(int a, int b, int c);
-#define FOO foo(
-
-int main() {
-  // Macro expansions.
-  $p^FOO 10, ^ );
-})cpp",
- // Macro arguments.
- R"cpp(
-int foo(int a, int b, int c);
-int main() {
-#define ID(X) X
-  // FIXME: figure out why ID(foo (foo(10), )) doesn't work when preserving
-  // the recovery expression.
-  ID(foo $p^( 10, ^ ))
-})cpp"};
+  llvm::StringLiteral Tests[] = {
+  // Recursive function call.
+  R"cpp(
+int foo(int a, int b, int c);
+int main() {
+  foo(foo $p^( foo(10, 10, 10), ^ )));
+})cpp",
+  // Functional type cast.
+  R"cpp(
+struct Foo {
+  Foo(int a, int b, int c);
+};
+int main() {
+  Foo $p^( 10, ^ );
+})cpp",
+  // New expression.
+  R"cpp(
+struct Foo {
+  Foo(int a, int b, int c);
+};
+int main() {
+  new Foo $p^( 10, ^ );
+})cpp",
+  // Macro expansion.
+  R"cpp(
+int foo(int a, int b, int c);
+#define FOO foo(
+
+int main() {
+  // Macro expansions.
+  $p^FOO 10, ^ );
+})cpp",
+  // Macro arguments.
+  R"cpp(
+int foo(int a, int b, int c);
+int main() {
+#define ID(X) X
+  // FIXME: figure out why ID(foo (foo(10), )) doesn't work when 
preserving
+  // the recovery expression.
+  ID(foo $p^( 10, ^ ))
+})cpp",
+  // Dependent args.
+  R"cpp(
+int foo(int a, int b);
+template  void bar(T t) {
+  foo$p^(t, ^t);
+})cpp",
+  // Dependent args on templated func.
+  R"cpp(
+template 
+int foo(T, T);
+template  void bar(T t) {
+  foo$p^(t, ^t);
+})cpp",
+  // Dependent args on member.
+  R"cpp(
+struct Foo { int foo(int, int); };
+template  void bar(T t) {
+  Foo f;
+  f.foo$p^(t, ^t);
+})cpp",
+  // Dependent args on templated member.
+  R"cpp(
+struct Foo { template  int foo(T, T); };
+template  void bar(T t) {
+  Foo f;
+  f.foo$p^(t, ^t);
+})cpp",
+  };
 
   for (auto Test : Tests) {
 Annotations Code(Test);

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 0a8a27068ebf..cf38b1012e7d 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5500,7 +5500,7 @@ typedef CodeCompleteConsumer::OverloadCandidate 
ResultCandidate;
 
 static void mergeCandidatesWithResults(
 Sema &SemaRef, SmallVectorImpl &Results,
-OverloadCandidateSet &CandidateSet, SourceLocation Loc) {
+OverloadCandidateSet &CandidateSet, SourceLocation Loc, size_t ArgSize) {
   // Sort the overload candidate set by placing the best overloads first.
   llvm::stable_sort(CandidateSet, [&](const OverloadCandidate &X,
   const OverloadCandidate &Y) {
@@ -5510,8 +5510,19 @@ static void 

[PATCH] D85826: [clang] Make signature help work with dependent args

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53c593c2c893: [clang] Make signature help work with 
dependent args (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85826/new/

https://reviews.llvm.org/D85826

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/call.cpp

Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -32,3 +32,23 @@
   // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
   // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
+
+void f(int, int, int, int);
+template 
+void foo(T t) {
+  f(t, t, t);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:39:5 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+  // CHECK-CC4: f()
+  // CHECK-CC4-NEXT: f(<#X#>)
+  // CHECK-CC4-NEXT: f(<#int i#>, int j, int k)
+  // CHECK-CC4-NEXT: f(<#float x#>, float y)
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:39:8 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+  // CHECK-CC5-NOT: f()
+  // CHECK-CC5: f(int i, <#int j#>, int k)
+  // CHECK-CC5-NEXT: f(float x, <#float y#>)
+  f(5, t, t);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:49:11 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
+  // CHECK-CC6-NOT: f(float x, float y)
+  // CHECK-CC6: f(int, int, <#int#>, int)
+  // CHECK-CC6-NEXT: f(int i, int j, <#int k#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5500,7 +5500,7 @@
 
 static void mergeCandidatesWithResults(
 Sema &SemaRef, SmallVectorImpl &Results,
-OverloadCandidateSet &CandidateSet, SourceLocation Loc) {
+OverloadCandidateSet &CandidateSet, SourceLocation Loc, size_t ArgSize) {
   // Sort the overload candidate set by placing the best overloads first.
   llvm::stable_sort(CandidateSet, [&](const OverloadCandidate &X,
   const OverloadCandidate &Y) {
@@ -5510,8 +5510,19 @@
 
   // Add the remaining viable overload candidates as code-completion results.
   for (OverloadCandidate &Candidate : CandidateSet) {
-if (Candidate.Function && Candidate.Function->isDeleted())
-  continue;
+if (Candidate.Function) {
+  if (Candidate.Function->isDeleted())
+continue;
+  if (!Candidate.Function->isVariadic() &&
+  Candidate.Function->getNumParams() <= ArgSize &&
+  // Having zero args is annoying, normally we don't surface a function
+  // with 2 params, if you already have 2 params, because you are
+  // inserting the 3rd now. But with zero, it helps the user to figure
+  // out there are no overloads that take any arguments. Hence we are
+  // keeping the overload.
+  ArgSize > 0)
+continue;
+}
 if (Candidate.Viable)
   Results.push_back(ResultCandidate(Candidate.Function));
   }
@@ -5562,22 +5573,25 @@
 
   // FIXME: Provide support for variadic template functions.
   // Ignore type-dependent call expressions entirely.
-  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args) ||
-  Expr::hasAnyTypeDependentArguments(Args)) {
+  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args))
 return QualType();
-  }
+  // In presence of dependent args we surface all possible signatures using the
+  // non-dependent args in the prefix. Afterwards we do a post filtering to make
+  // sure provided candidates satisfy parameter count restrictions.
+  auto ArgsWithoutDependentTypes =
+  Args.take_while([](Expr *Arg) { return !Arg->isTypeDependent(); });
 
+  SmallVector Results;
+
+  Expr *NakedFn = Fn->IgnoreParenCasts();
   // Build an overload candidate set based on the functions we find.
   SourceLocation Loc = Fn->getExprLoc();
   OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Normal);
 
-  SmallVector Results;
-
-  Expr *NakedFn = Fn->IgnoreParenCasts();
-  if (auto ULE = dyn_cast(NakedFn))
-AddOverloadedCallCandidates(ULE, Args, CandidateSet,
+  if (auto ULE = dyn_cast(NakedFn)) {
+AddOverloadedCallCandidates(ULE, ArgsWithoutDependentTypes, CandidateSet,
 /*PartialOverloading=*/true);
-  else if (auto UME = dyn_cast(NakedFn)) {
+  } else if (auto UME = dyn_cast(NakedFn)) {
 TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr;
 if (UME->hasExplicitTemplateArgs()) {
   UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
@@ -5587,7 +5601,8 @@
 // Add the base as first argument (use a nullptr if the base is implicit).
 SmallVector ArgExprs(
 1, UME->isImplic

[PATCH] D31130: B32239 clang-tidy should not warn about array to pointer decay on system macros

2020-08-17 Thread fiesh via Phabricator via cfe-commits
fiesh added a comment.

Ping everybody?  This is a rather important issue I think since it makes 
clang-tidy not usable in a lot of cases, and the fix would be all done.  Please 
let's get this merged!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D31130/new/

https://reviews.llvm.org/D31130

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


[PATCH] D84387: [AST][RecoveryExpr] Suppress spurious "err_typecheck_expect_scalar_operand" diagnostic

2020-08-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry for losing track of this. Where is CDependence defined? Is this stacked 
on another patch?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84387/new/

https://reviews.llvm.org/D84387

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


[PATCH] D86029: [analyzer] Add modeling for unque_ptr::get()

2020-08-17 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:362-363
+  const auto *InnerPointVal = State->get(ThisRegion);
+  if (!InnerPointVal)
+return;
+

NoQ wrote:
> You'll have to actively handle this case, sooner or later. Consider the 
> following test cases that won't work until you do:
> ```lang=c++
> void foo(std::unique_ptr p) {
>   A *x = p.get();
>   A *y = p.get();
>   clang_analyzer_eval(x == y); // expected-warning{{TRUE}}
>   if (!x) {
> y->foo(); // expected-warning{{Called C++ object pointer is null}}
>   }
> }
> 
> ```
You mean the case where we do not have an inner pointer registered in the state 
yet, right?

I believe we might also have to handle similar cases for `operator bool()` as 
well. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86029/new/

https://reviews.llvm.org/D86029

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


[PATCH] D84387: [AST][RecoveryExpr] Part4: Suppress spurious "err_typecheck_expect_scalar_operand" diagnostic

2020-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D84387#2220845 , @sammccall wrote:

> Sorry for losing track of this. Where is CDependence defined? Is this stacked 
> on another patch?

yes. Sorry for not being clear here, this is stacked on another patch. I have 
renamed these patches (Part 1, 2, 3...). The review should go Part 1 first.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84387/new/

https://reviews.llvm.org/D84387

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


[PATCH] D86027: [analyzer] Add bool operator modeling for unque_ptr

2020-08-17 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:147
 
-if (!move::isMovedFrom(State, ThisR)) {
-  // TODO: Model this case as well. At least, avoid invalidation of
-  // globals.
-  return false;
+if (ModelSmartPtrDereference) {
+  handleBoolOperation(Call, C);

vrnithinkumar wrote:
> This seems little messy here.
> I guess once we model the `std::move` for smart ptr it will be less messy 
I agree. `isNullAfterMoveMethod` is especially confusing as it does not do what 
the name of the function says. It checks if the `Call` is a boolean conversion 
operator. I'd suggest renaming that method to make this code a bit more 
sensible. 

Moreover, when `ModelSmartPtrDereference` is true, we no longer model moves 
below right? I think a comment that this logic is duplicated 
`handleBoolOperation` might make the code cleaner. 

But yeah, this needs to be cleaned up, hopefully really soon.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:389
+}
+C.addTransition(State);
+  } else if (move::isMovedFrom(State, ThisRegion)) {

This looks fine for now, but we often prefer adding a return after each case to 
avoid executing multiple `addTransition`s accidentally after refactoring.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86027/new/

https://reviews.llvm.org/D86027

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


[PATCH] D85753: [clangd] Discard diagnostics from another SourceManager.

2020-08-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:568
+  // If the diagnostic was generated for a different SourceManager, skip it.
+  // This can happen when using implicit modules.
+  if (OrigSrcMgr && Info.hasSourceManager() &&

sammccall wrote:
> sammccall wrote:
> > maybe a FIXME: errors from implicitly built modules should be surfaced 
> > somehow (but then must also be surfaced when the module was cached)
> Can we be a bit more specific: this happens when an #include causes a module 
> to be implicitly built, using a separate SourceManager.
It's not just #include, could be "import". But yes, we can be more specific. 
Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85753/new/

https://reviews.llvm.org/D85753

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


[PATCH] D85753: [clangd] Discard diagnostics from another SourceManager.

2020-08-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 285961.
adamcz marked 3 inline comments as done.
adamcz added a comment.

addressed review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85753/new/

https://reviews.llvm.org/D85753

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/unittests/ModulesTests.cpp

Index: clang-tools-extra/clangd/unittests/ModulesTests.cpp
===
--- clang-tools-extra/clangd/unittests/ModulesTests.cpp
+++ clang-tools-extra/clangd/unittests/ModulesTests.cpp
@@ -39,6 +39,34 @@
   TU.index();
 }
 
+TEST(Modules, Diagnostic) {
+  // Produce a diagnostic while building an implicit module. Use
+  // -fmodules-strict-decluse, but any non-silenced diagnostic will do.
+  TestTU TU = TestTU::withCode(R"cpp(
+/*error-ok*/
+#include "modular.h"
+
+void bar() {}
+)cpp");
+  TU.OverlayRealFileSystemForModules = true;
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
+  TU.ExtraArgs.push_back("-fmodules");
+  TU.ExtraArgs.push_back("-fimplicit-modules");
+  TU.ExtraArgs.push_back("-fmodules-strict-decluse");
+  TU.AdditionalFiles["modular.h"] = R"cpp(
+#include "non-modular.h"
+  )cpp";
+  TU.AdditionalFiles["non-modular.h"] = "";
+  TU.AdditionalFiles["m.modulemap"] = R"modulemap(
+module M {
+  header "modular.h"
+}
+)modulemap";
+
+  // Test that we do not crash.
+  TU.build();
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -122,7 +122,8 @@
   // The ClangTidyContext populates Source and Name for clang-tidy diagnostics.
   std::vector take(const clang::tidy::ClangTidyContext *Tidy = nullptr);
 
-  void BeginSourceFile(const LangOptions &Opts, const Preprocessor *) override;
+  void BeginSourceFile(const LangOptions &Opts,
+   const Preprocessor *PP) override;
   void EndSourceFile() override;
   void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
 const clang::Diagnostic &Info) override;
@@ -148,6 +149,7 @@
   llvm::Optional LastDiag;
   llvm::Optional LastDiagLoc; // Valid only when LastDiag is set.
   bool LastDiagOriginallyError = false;  // Valid only when LastDiag is set.
+  SourceManager *OrigSrcMgr = nullptr;
 
   llvm::DenseSet> IncludedErrorLocations;
   bool LastPrimaryDiagnosticWasSuppressed = false;
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -518,13 +518,17 @@
 }
 
 void StoreDiags::BeginSourceFile(const LangOptions &Opts,
- const Preprocessor *) {
+ const Preprocessor *PP) {
   LangOpts = Opts;
+  if (PP) {
+OrigSrcMgr = &PP->getSourceManager();
+  }
 }
 
 void StoreDiags::EndSourceFile() {
   flushLastDiag();
   LangOpts = None;
+  OrigSrcMgr = nullptr;
 }
 
 /// Sanitizes a piece for presenting it in a synthesized fix message. Ensures
@@ -560,6 +564,16 @@
 
 void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
   const clang::Diagnostic &Info) {
+  // If the diagnostic was generated for a different SourceManager, skip it.
+  // This happens when a module is imported and needs to be implicitly built.
+  // The compilation of that module will use the same StoreDiags, but different
+  // SourceManager.
+  if (OrigSrcMgr && Info.hasSourceManager() &&
+  OrigSrcMgr != &Info.getSourceManager()) {
+IgnoreDiagnostics::log(DiagLevel, Info);
+return;
+  }
+
   DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info);
   bool OriginallyError =
   Info.getDiags()->getDiagnosticIDs()->isDefaultMappingAsError(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85796: [Analysis] Bug fix for exploded graph branching in evalCall for constructor

2020-08-17 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar updated this revision to Diff 285969.
vrnithinkumar added a comment.

- Make exactly single NodeBuilder exists at any given time


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85796/new/

https://reviews.llvm.org/D85796

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp
  clang/test/Analysis/smart-ptr.cpp

Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -41,6 +41,7 @@
 
 void derefAfterValidCtr() {
   std::unique_ptr P(new A());
+  clang_analyzer_numTimesReached(); // expected-warning {{1}}
   P->foo(); // No warning.
 }
 
@@ -50,17 +51,20 @@
 
 void derefAfterDefaultCtr() {
   std::unique_ptr P;
+  clang_analyzer_numTimesReached(); // expected-warning {{1}}
   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 void derefAfterCtrWithNull() {
   std::unique_ptr P(nullptr);
+  clang_analyzer_numTimesReached(); // expected-warning {{1}}
   *P; // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 void derefAfterCtrWithNullVariable() {
   A *InnerPtr = nullptr;
   std::unique_ptr P(InnerPtr);
+  clang_analyzer_numTimesReached(); // expected-warning {{1}}
   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
@@ -87,6 +91,7 @@
 void derefAfterResetWithNonNull() {
   std::unique_ptr P;
   P.reset(new A());
+  clang_analyzer_numTimesReached(); // expected-warning {{1}}
   P->foo(); // No warning.
 }
 
@@ -116,37 +121,40 @@
 void pass_smart_ptr_by_ptr(std::unique_ptr *a);
 void pass_smart_ptr_by_const_ptr(const std::unique_ptr *a);
 
-void regioninvalidationTest() {
-  {
-std::unique_ptr P;
-pass_smart_ptr_by_ref(P);
-P->foo(); // no-warning
-  }
-  {
-std::unique_ptr P;
-pass_smart_ptr_by_const_ref(P);
-P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
-  }
-  {
-std::unique_ptr P;
-pass_smart_ptr_by_rvalue_ref(std::move(P));
-P->foo(); // no-warning
-  }
-  {
-std::unique_ptr P;
-pass_smart_ptr_by_const_rvalue_ref(std::move(P));
-P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
-  }
-  {
-std::unique_ptr P;
-pass_smart_ptr_by_ptr(&P);
-P->foo();
-  }
-  {
-std::unique_ptr P;
-pass_smart_ptr_by_const_ptr(&P);
-P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
-  }
+void regioninvalidationWithPassByRef() {
+  std::unique_ptr P;
+  pass_smart_ptr_by_ref(P);
+  P->foo(); // no-warning
+}
+
+void regioninvalidationWithPassByCostRef() {
+  std::unique_ptr P;
+  pass_smart_ptr_by_const_ref(P);
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+}
+
+void regioninvalidationWithPassByRValueRef() {
+  std::unique_ptr P;
+  pass_smart_ptr_by_rvalue_ref(std::move(P));
+  P->foo(); // no-warning
+}
+
+void regioninvalidationWithPassByConstRValueRef() {
+  std::unique_ptr P;
+  pass_smart_ptr_by_const_rvalue_ref(std::move(P));
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+}
+
+void regioninvalidationWithPassByPtr() {
+  std::unique_ptr P;
+  pass_smart_ptr_by_ptr(&P);
+  P->foo();
+}
+
+void regioninvalidationWithPassByConstPtr() {
+  std::unique_ptr P;
+  pass_smart_ptr_by_const_ptr(&P);
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 }
 
 struct StructWithSmartPtr {
@@ -160,37 +168,40 @@
 void pass_struct_with_smart_ptr_by_ptr(StructWithSmartPtr *a);
 void pass_struct_with_smart_ptr_by_const_ptr(const StructWithSmartPtr *a);
 
-void regioninvalidationTestWithinStruct() {
-  {
-StructWithSmartPtr S;
-pass_struct_with_smart_ptr_by_ref(S);
-S.P->foo(); // no-warning
-  }
-  {
-StructWithSmartPtr S;
-pass_struct_with_smart_ptr_by_const_ref(S);
-S.P->foo(); // expected-warning {{Dereference of null smart pointer 'S.P' [alpha.cplusplus.SmartPtr]}}
-  }
-  {
-StructWithSmartPtr S;
-pass_struct_with_smart_ptr_by_rvalue_ref(std::move(S));
-S.P->foo(); // no-warning
-  }
-  {
-StructWithSmartPtr S;
-pass_struct_with_smart_ptr_by_const_rvalue_ref(std::move(S));
-S.P->foo(); // expected-warning {{Dereference of null smart pointer 'S.P' [alpha.cplusplus.SmartPtr]}}
-  }
-  {
-StructWithSmartPtr S;
-pass_struct_with_smart_ptr_by_ptr(&S);
-S.P->foo();
-  }
-  {
-StructWithSmartPtr S;
-pass_struct_with_smart_ptr_by_const_ptr(&S);
-S.P->foo(); // expected-warning {{Dereference of null smart pointer 'S.P' [alpha.cplusplus.SmartPtr]}}
-  }
+void regioninvalidationWithinStructPassByRef() {
+  StructWi

[PATCH] D85796: [Analysis] Bug fix for exploded graph branching in evalCall for constructor

2020-08-17 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar marked an inline comment as done.
vrnithinkumar added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:682
 anyEvaluated = true;
+Dst.clear();
 Dst.insert(checkDst);

NoQ wrote:
> vrnithinkumar wrote:
> > > runCheckersForEvalCall() already has its own builder, you don't need 
> > > another.
> > 
> > In that case is it okay to clear the  `ExplodedNodeSet DstEvaluated` passed 
> > as `Dst` which contains parent node [[ 
> > https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp#L604
> >  | contains parent node ]] ?
> > 
> > When the any of the evaluated checker is evaluated the node successfully we 
> > can clear the `Dst` which is part of the `StmtNodeBuilder Bldr(DstPreCall, 
> > DstEvaluated, *currBldrCtx);` before inserting new nodes.
> Hmm actually your code is now incorrect because `runCheckersForEvalCall()` is 
> in fact invoked multiple times in a loop (if there were state splits in 
> PreStmt/PreCall), therefore it's possible that `Dst` does in fact already 
> contain nodes.
> 
> That also means that i can't put in the assertions that i thought of; the 
> destination set is indeed potentially non-empty in many cases.
> 
> 
> Anyway, here's what i meant:
> ```lang=diff
>ExplodedNodeSet DstPreCall;
>getCheckerManager().runCheckersForPreCall(DstPreCall, PreInitialized,
>  *Call, *this);
> 
>ExplodedNodeSet DstEvaluated;
> -  StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx);
> 
>if (CE && CE->getConstructor()->isTrivial() &&
>CE->getConstructor()->isCopyOrMoveConstructor() &&
>!CallOpts.IsArrayCtorOrDtor) {
> +StmtNodeBuilder Bldr(DstPreCall, DstEvaluated, *currBldrCtx);
>  // FIXME: Handle other kinds of trivial constructors as well.
>  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = 
> DstPreCall.end();
>   I != E; ++I)
>performTrivialCopy(Bldr, *I, *Call);
> 
>} else {
>  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = 
> DstPreCall.end();
>   I != E; ++I)
>getCheckerManager().runCheckersForEvalCall(DstEvaluated, *I, *Call, 
> *this,
>   CallOpts);
>}
> 
>// If the CFG was constructed without elements for temporary destructors
>// and the just-called constructor created a temporary object then
>// stop exploration if the temporary object has a noreturn constructor.
>// This can lose coverage because the destructor, if it were present
>// in the CFG, would be called at the end of the full expression or
>// later (for life-time extended temporaries) -- but avoids infeasible
>// paths when no-return temporary destructors are used for assertions.
> +  ExplodedNodeSet DstEvaluatedPostProcessed;
> +  StmtNodeBuilder Bldr(DstEvaluated, DstEvaluatedPostProcessed, 
> *currBldrCtx);
>const AnalysisDeclContext *ADC = LCtx->getAnalysisDeclContext();
>if (!ADC->getCFGBuildOptions().AddTemporaryDtors) {
>  if (llvm::isa_and_nonnull(TargetRegion) &&
>  cast(Call->getDecl())
>  ->getParent()
>  ->isAnyDestructorNoReturn()) {
> 
>// If we've inlined the constructor, then DstEvaluated would be empty.
>// In this case we still want a sink, which could be implemented
>// in processCallExit. But we don't have that implemented at the 
> moment,
>// so if you hit this assertion, see if you can avoid inlining
>// the respective constructor when analyzer-config cfg-temporary-dtors
>// is set to false.
>// Otherwise there's nothing wrong with inlining such constructor.
>assert(!DstEvaluated.empty() &&
>   "We should not have inlined this constructor!");
> 
>for (ExplodedNode *N : DstEvaluated) {
>  Bldr.generateSink(E, N, N->getState());
>}
> 
>// There is no need to run the PostCall and PostStmt checker
>// callbacks because we just generated sinks on all nodes in th
>// frontier.
>return;
>  }
>}
> 
>ExplodedNodeSet DstPostArgumentCleanup;
> -  for (ExplodedNode *I : DstEvaluated)
> +  for (ExplodedNode *I : DstEvaluatedPostProcessed)
>  finishArgumentConstruction(DstPostArgumentCleanup, I, *Call);
> ```
> This way exactly one builder exists at any given moment of time and exactly 
> one builder operates on each pair of source-destination sets.
> 
> Also this entire `AddTemporaryDtors` option could probably be banned already 
> which would make things a whole lot easier; i'll look into that.
> Hmm actually your code is now incorrect because runCheckersForEvalCall() is 
> in fact invoked multiple times in a loop (if there were state splits in 
> PreStmt/PreCall), therefore it's possible that Dst does in fact already 
> contain nodes.
Oh, I missed that point.

[PATCH] D86065: [SVE] Make ElementCount members private

2020-08-17 Thread David Sherwood via Phabricator via cfe-commits
david-arm created this revision.
david-arm added reviewers: sdesmalen, ctetreau, efriedma, fpetrogalli, 
kmclaughlin, c-rhodes.
Herald added subscribers: llvm-commits, cfe-commits, psnobl, hiraditya, 
tschuett.
Herald added projects: clang, LLVM.
david-arm requested review of this revision.

This patch changes ElementCount so that the Min and Scalable
members are now private and can only be access via the get
functions getKnownMinValue() and isScalable(). This is now inline
with the TypeSize class.

In addition I've added some other member functions for more
commonly used operations. Hopefully this makes the class more
useful and will reduce the need for calling getKnownMinValue().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86065

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  llvm/include/llvm/Analysis/VectorUtils.h
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/include/llvm/IR/Instructions.h
  llvm/include/llvm/IR/Intrinsics.h
  llvm/include/llvm/Support/MachineValueType.h
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/Analysis/VFABIDemangling.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/ConstantFold.cpp
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/IntrinsicInst.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/lib/Transforms/Utils/FunctionComparator.cpp
  llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
  llvm/unittests/IR/VectorTypesTest.cpp

Index: llvm/unittests/IR/VectorTypesTest.cpp
===
--- llvm/unittests/IR/VectorTypesTest.cpp
+++ llvm/unittests/IR/VectorTypesTest.cpp
@@ -119,8 +119,8 @@
   EXPECT_EQ(ConvTy->getElementType()->getScalarSizeInBits(), 64U);
 
   EltCnt = V8Int64Ty->getElementCount();
-  EXPECT_EQ(EltCnt.Min, 8U);
-  ASSERT_FALSE(EltCnt.Scalable);
+  EXPECT_EQ(EltCnt.getKnownMinValue(), 8U);
+  ASSERT_FALSE(EltCnt.isScalable());
 }
 
 TEST(VectorTypesTest, Scalable) {
@@ -215,8 +215,8 @@
   EXPECT_EQ(ConvTy->getElementType()->getScalarSizeInBits(), 64U);
 
   EltCnt = ScV8Int64Ty->getElementCount();
-  EXPECT_EQ(EltCnt.Min, 8U);
-  ASSERT_TRUE(EltCnt.Scalable);
+  EXPECT_EQ(EltCnt.getKnownMinValue(), 8U);
+  ASSERT_TRUE(EltCnt.isScalable());
 }
 
 TEST(VectorTypesTest, BaseVectorType) {
@@ -249,7 +249,7 @@
 // test I == J
 VectorType *VI = VTys[I];
 ElementCount ECI = VI->getElementCount();
-EXPECT_EQ(isa(VI), ECI.Scalable);
+EXPECT_EQ(isa(VI), ECI.isScalable());
 
 for (size_t J = I + 1, JEnd = VTys.size(); J < JEnd; ++J) {
   // test I < J
Index: llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
===
--- llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
+++ llvm/unittests/CodeGen/ScalableVectorMVTsTest.cpp
@@ -71,8 +71,8 @@
 
   // Check fields inside llvm::ElementCount
   EltCnt = Vnx4i32.getVectorElementCount();
-  EXPECT_EQ(EltCnt.Min, 4U);
-  ASSERT_TRUE(EltCnt.Scalable);
+  EXPECT_EQ(EltCnt.getKnownMinValue(), 4U);
+  ASSERT_TRUE(EltCnt.isScalable());
 
   // Check that fixed-length vector types aren't scalable.
   EVT V8i32 = EVT::getVectorVT(Ctx, MVT::i32, 8);
@@ -82,8 +82,8 @@
 
   // Check that llvm::ElementCount works for fixed-length types.
   EltCnt = V8i32.getVectorElementCount();
-  EXPECT_EQ(EltCnt.Min, 8U);
-  ASSERT_FALSE(EltCnt.Scalable);
+  EXPECT_EQ(EltCnt.getKnownMinValue(), 8U);
+  ASSERT_FALSE(EltCnt.isScalable());
 }
 
 TEST(ScalableVectorMVTsTest, IRToVTTranslation) {
Index: llvm/lib/Transforms/Utils/FunctionComparator.cpp
===
--- llvm/lib/Transforms/Utils/FunctionComparator.cpp
+++ llvm/lib/Transforms/Utils/FunctionComparator.cpp
@@ -488,12 +488,13 @@
   case Type::ScalableVectorTyID: {
 auto *STyL = cast(TyL);
 auto *STyR = cast(TyR);
-if (STyL->getElementCount().Scalable != STyR->getElementCount().Scalable)
-  return cmpNumbers(STyL->getElementCount().Scalable,
-STyR->getElementCount().Scalable);
-if (STyL->getElementCount().Min != STyR->getElementCount().Min)
-  return cmpNumbers(STyL->getElementCount().Min,
-STyR->getElementCount().Min);
+if (STyL->getElementCount().isScalable() !=
+STyR->getElementCount().isScalable())
+  return cmpNumbers(STyL->getElementCount().is

[clang] 687e7d3 - [NFC] Tweak a comment about the lock-free builtins

2020-08-17 Thread Luís Marques via cfe-commits

Author: Luís Marques
Date: 2020-08-17T13:43:53+01:00
New Revision: 687e7d34253b283945bdf9892aa58fd167f9913d

URL: 
https://github.com/llvm/llvm-project/commit/687e7d34253b283945bdf9892aa58fd167f9913d
DIFF: 
https://github.com/llvm/llvm-project/commit/687e7d34253b283945bdf9892aa58fd167f9913d.diff

LOG: [NFC] Tweak a comment about the lock-free builtins

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 448a683c9088..760e5621e0ef 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11519,8 +11519,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   return false;
 
 // For __atomic_is_lock_free(sizeof(_Atomic(T))), if the size is a power
-// of two less than the maximum inline atomic width, we know it is
-// lock-free.  If the size isn't a power of two, or greater than the
+// of two less than or equal to the maximum inline atomic width, we know it
+// is lock-free.  If the size isn't a power of two, or greater than the
 // maximum alignment where we promote atomics, we know it is not lock-free
 // (at least not in the sense of atomic_is_lock_free).  Otherwise,
 // the answer can only be determined at runtime; for example, 16-byte



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


[PATCH] D86069: [clang] When loading preamble from AST file, re-export modules in Sema.

2020-08-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
adamcz requested review of this revision.

This addresses a FIXME in ASTReader.

Modules were already re-exported for Preprocessor, but not for Sema.
The result was that, with -fmodules-local-submodule-visibility, all AST
nodes belonging to a module that was loaded in a premable where not
accesible from the main part of the file and a diagnostic recommending
importing those modules would be generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86069

Files:
  clang-tools-extra/clangd/unittests/ModulesTests.cpp
  clang/include/clang/Sema/Sema.h
  clang/lib/Serialization/ASTReader.cpp
  clang/test/PCH/Inputs/modules/Foo.h
  clang/test/PCH/preamble-modules.cpp

Index: clang/test/PCH/preamble-modules.cpp
===
--- /dev/null
+++ clang/test/PCH/preamble-modules.cpp
@@ -0,0 +1,15 @@
+// Check that modules included in the preamble remain visible to the rest of the
+// file.
+
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -emit-pch -o %t.pch %s -fmodules -fmodule-map-file=%S/Inputs/modules/module.modulemap -fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
+// RUN: %clang_cc1 -include-pch %t.pch %s -fmodules -fmodule-map-file=%S/Inputs/modules/module.modulemap -fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
+
+#ifndef MAIN_FILE
+#define MAIN_FILE
+// Premable section.
+#include "Inputs/modules/Foo.h"
+#else
+// Main section.
+MyType foo;
+#endif
Index: clang/test/PCH/Inputs/modules/Foo.h
===
--- clang/test/PCH/Inputs/modules/Foo.h
+++ clang/test/PCH/Inputs/modules/Foo.h
@@ -1 +1,3 @@
 void make_foo(void);
+
+typedef int MyType;
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4987,10 +4987,8 @@
 /*ImportLoc=*/Import.ImportLoc);
   if (Import.ImportLoc.isValid())
 PP.makeModuleVisible(Imported, Import.ImportLoc);
-  // FIXME: should we tell Sema to make the module visible too?
 }
   }
-  ImportedModules.clear();
 }
 
 void ASTReader::finalizeForWriting() {
@@ -7942,6 +7940,15 @@
   SemaObj->FpPragmaStack.CurrentPragmaLocation = FpPragmaCurrentLocation;
 }
   }
+
+  // For non-modular AST files, restore visiblity of modules.
+  for (auto &Import : ImportedModules) {
+if (Import.ImportLoc.isInvalid())
+  continue;
+if (Module *Imported = getSubmodule(Import.ID)) {
+  SemaObj->makeModuleVisible(Imported, Import.ImportLoc);
+}
+  }
 }
 
 IdentifierInfo *ASTReader::get(StringRef Name) {
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1912,6 +1912,12 @@
 
   bool isModuleVisible(const Module *M, bool ModulePrivate = false);
 
+  // When loading a non-modular PCH files, this is used to restore module
+  // visibility.
+  void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) {
+VisibleModules.setVisible(Mod, ImportLoc);
+  }
+
   /// Determine whether a declaration is visible to name lookup.
   bool isVisible(const NamedDecl *D) {
 return D->isUnconditionallyVisible() || isVisibleSlow(D);
Index: clang-tools-extra/clangd/unittests/ModulesTests.cpp
===
--- clang-tools-extra/clangd/unittests/ModulesTests.cpp
+++ clang-tools-extra/clangd/unittests/ModulesTests.cpp
@@ -26,7 +26,7 @@
 void foo() {}
 )cpp");
   TU.ExtraArgs.push_back("-fmodule-name=M");
-  TU.ExtraArgs.push_back("-fmodule-map-file=m.modulemap");
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
   TU.AdditionalFiles["Textual.h"] = "void foo();";
   TU.AdditionalFiles["m.modulemap"] = R"modulemap(
 module M {
@@ -39,6 +39,31 @@
   TU.index();
 }
 
+// Verify that visibility of AST nodes belonging to modules, but loaded from
+// preamble PCH, is restored.
+TEST(Modules, PreambleBuildVisibility) {
+  TestTU TU = TestTU::withCode(R"cpp(
+#include "module.h"
+
+foo x;
+)cpp");
+  TU.OverlayRealFileSystemForModules = true;
+  TU.ExtraArgs.push_back("-fmodules");
+  TU.ExtraArgs.push_back("-fmodules-strict-decluse");
+  TU.ExtraArgs.push_back("-Xclang");
+  TU.ExtraArgs.push_back("-fmodules-local-submodule-visibility");
+  TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
+  TU.AdditionalFiles["module.h"] = R"cpp(
+typedef int foo;
+)cpp";
+  TU.AdditionalFiles["m.modulemap"] = R"modulemap(
+module M {
+  header "module.h"
+}
+)modulemap";
+  EXPECT_TRUE(TU.build().getDiagnostics().empty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace 

[PATCH] D85091: [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in IfStmt

2020-08-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1288
+def Likely : StmtAttr {
+  let Spellings = [CXX11<"", "likely", 201803>];
+  let Documentation = [LikelihoodDocs];

Mordante wrote:
> Mordante wrote:
> > aaron.ballman wrote:
> > > Mordante wrote:
> > > > aaron.ballman wrote:
> > > > > Hmm, I'm on the fence about specifying `201803` for these attributes. 
> > > > > Given that this is only the start of supporting the attribute, do we 
> > > > > want to claim it already matches the standard's behavior? Or do we 
> > > > > just want to return `1` to signify that we understand this attribute 
> > > > > but we don't yet fully support it in common cases (such as on labels 
> > > > > in switch statements, etc)?
> > > > > 
> > > > > As another question, should we consider adding a C2x spelling 
> > > > > `[[clang::likely]]` and `[[clang::unlikely]]` to add this 
> > > > > functionality to C?
> > > > I was also somewhat on the fence, for now I'll change it to specify `1`.
> > > > 
> > > > I'll have a look at the C2x changes. Just curious do you know whether 
> > > > there's a proposal to add this to C2x?
> > > > I'll have a look at the C2x changes. Just curious do you know whether 
> > > > there's a proposal to add this to C2x?
> > > 
> > > There isn't one currently because there is no implementation experience 
> > > with the attributes in C. This is a way to get that implementation 
> > > experience so it's easier to propose the feature to WG14.
> > > I was also somewhat on the fence, for now I'll change it to specify `1`.
> > 
> > There seems to be an issue using the `1` so I used `2` instead. (Didn't 
> > want to look closely at the issue.)
> > 
> > > I'll have a look at the C2x changes. Just curious do you know whether 
> > > there's a proposal to add this to C2x?
> > 
> > There isn't one currently because there is no implementation experience 
> > with the attributes in C. This is a way to get that implementation 
> > experience so it's easier to propose the feature to WG14.
> 
> Nice to know. It seems the C2x wasn't at straightforward as I hoped, so I 
> didn't implement it yet. I intend to look at it later. I first want the 
> initial part done to see whether this is the right approach.
What issues are you running into? 1 is the default value when you don't specify 
a value specifically.



Comment at: clang/include/clang/Basic/AttrDocs.td:1697
+It's not allowed to annotate a statement with both ``likely`` and
+``unlikely``.  It's not recommended to annotate both branches of an ``if``
+statement with an attribute.

Mordante wrote:
> Mordante wrote:
> > aaron.ballman wrote:
> > > Mordante wrote:
> > > > Quuxplusone wrote:
> > > > > aaron.ballman wrote:
> > > > > > Why? I would expect this to be reasonable code:
> > > > > > ```
> > > > > > if (foo) [[likely]] {
> > > > > >   ...
> > > > > > } else if (bar) [[unlikely]] {
> > > > > >   ...
> > > > > > } else if (baz) [[likely]] {
> > > > > >   ...
> > > > > > } else {
> > > > > >   ...
> > > > > > }
> > > > > > ```
> > > > > > Especially because I would expect this to be reasonable code:
> > > > > > ```
> > > > > > switch (value) {
> > > > > > [[likely]] case 0: ... break;
> > > > > > [[unlikely]] case 1: ... break;
> > > > > > [[likely]] case 2: ... break;
> > > > > > [[unlikely]] default: ... break;
> > > > > > }
> > > > > > ```
> > > > > > As motivating examples, consider a code generator that knows 
> > > > > > whether a particular branch is likely or not and it writes out the 
> > > > > > attribute on all branches. Or, something like this:
> > > > > > ```
> > > > > > float rnd_value = get_super_random_number_between_zero_and_one();
> > > > > > if (rnd_value < .1) [[unlikely]] {
> > > > > > } else if (rnd_value > .9) [[unlikely]] {
> > > > > > } else [[likely]] {
> > > > > > }
> > > > > > ```
> > > > > Right, annotating both/multiple branches of a control statement 
> > > > > should be perfectly fine. Even `if (x) [[likely]] { } else [[likely]] 
> > > > > { }` should be perfectly okay as far as the code generator is 
> > > > > concerned (and we should have a test for that); it's silly, but 
> > > > > there's no reason to warn against it in the compiler docs.
> > > > > 
> > > > > Aaron, notice that `if (x) [[likely]] { } else if (y) [[likely]] { }` 
> > > > > is not actually annotating "both" branches of any single 
> > > > > `if`-statement. There you're annotating the true branch of an if 
> > > > > (without annotating the else branch), and then annotating the true 
> > > > > branch of another if (which doesn't have an else branch).
> > > > > 
> > > > > Mordante, in these docs, please document the "interesting" behavior 
> > > > > of the standard attribute on labels — annotating a label is different 
> > > > > from annotating the labeled statement itself. In particular,
> > > > > 
> > > > > [[likely]] case 1: case 2: foo(); break;
> > > > > case

[PATCH] D31130: B32239 clang-tidy should not warn about array to pointer decay on system macros

2020-08-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D31130#2220729 , @fiesh wrote:

> Ping everybody?  This is a rather important issue I think since it makes 
> clang-tidy not usable in a lot of cases, and the fix would be all done.  
> Please let's get this merged!

Sorry for missing this before -- it's totally fine to pick up someone else's 
patch if the original author isn't able to work on it. IANAL, so I can't 
comment on the licensing question with any authority, but given that the 
original author says they're fine giving up full rights to their patch, that 
seems sufficient to me.

Given how long this review has sat idle for, I'd recommend starting a new 
review with a fully rebased patch, though.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D31130/new/

https://reviews.llvm.org/D31130

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


[PATCH] D86047: [clangd] Target member of dependent base made visible via a using-decl

2020-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

looks mostly good, just a few suggestions on the test.




Comment at: clang-tools-extra/clangd/FindTarget.cpp:128
+const auto ValueFilter = [](const NamedDecl *D) {
+  return dyn_cast(D) != nullptr;
+};

nit: use `isa`.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:354
+} else if (const UnresolvedUsingValueDecl *UUVD =
+   dyn_cast(D)) {
+  for (const NamedDecl *Target : getMembersReferencedViaDependentName(

can we have a test for `FindTarget`? `TEST_F(TargetDeclTest, UsingDecl)` is an 
ideal place.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:738
+  )objc",
+  R"cpp(// Member of dependent base
+template 

nit: move to `Test(LocateSymbol, Alias)`. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86047/new/

https://reviews.llvm.org/D86047

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-17 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:730
+MacroBuilder &Builder) const override {
+Builder.defineMacro("_LONG_LONG");
+Builder.defineMacro("_OPEN_DEFAULT");

hubert.reinterpretcast wrote:
> The comment from https://reviews.llvm.org/D85324?id=283290#inline-786609 
> applies here as well. `_LONG_LONG` should not be defined under `-std=c89 
> -pedantic-errors` or `-std=c89 -Werror=long-long`.
I can add a FIXME here similar to what AIX did. 

```
//FIXME: LONG_LONG should not be defined under -std=c89
```
Let me know if there is a better solution.



Comment at: clang/lib/Basic/Targets/OSTargets.h:755
+  // is not declared as a typedef in system headers.
+  Builder.defineMacro("__wchar_t");
+  // XOPEN_SOURCE=600 is required to build libcxx.

hubert.reinterpretcast wrote:
> The corresponding AIX code checks for `-Xclang -fno-wchar`. The behaviour of 
> `stddef.h` differs when using `-fno-wchar` between AIX and Linux though. 
> Linux suppresses the typedef based on `__cplusplus`. Arguably, the OS header 
> difference should not really factor into whether the compiler defines a macro 
> that indicates the presence of a `wchar_t` fundamental type.
Thanks, I will add the same guard that AIX uses.



Comment at: clang/lib/Basic/Targets/OSTargets.h:766
+if (Opts.C11 || Opts.GNUMode) {
+  Builder.defineMacro("__IBM_UTF_LITERAL");
+  Builder.defineMacro("__IBMC_NORETURN");

hubert.reinterpretcast wrote:
> The GNU extension modes do not cause u-prefixed, etc. string literals to be 
> accepted where the base language level would treat the prefix as a separate 
> identifier. Also noting here that the previous comment from 
> https://reviews.llvm.org/D85324?id=283290#inline-786628 was made based on 
> noting that `__IBM_UTF_LITERAL` is defined by the XL compiler in the 
> appropriate C++ modes.
We've updated the system headers so that we no longer need to define these 
macros.



Comment at: clang/lib/Basic/Targets/OSTargets.h:767
+  Builder.defineMacro("__IBM_UTF_LITERAL");
+  Builder.defineMacro("__IBMC_NORETURN");
+}

hubert.reinterpretcast wrote:
> I would expect that the Clang implementation of the "IBM-style" feature test 
> macros would behave similarly to the native feature testing in Clang. That 
> is, `__IBMC_NORETURN` is defined when `_Noreturn` is available as an 
> extension. `_Noreturn` is available as an "orthogonal" or "conforming" 
> extension in modes such as `-std=c89` and `-std=c++03`. The extension is 
> disabled via warnings-as-errors.
Right, we are able to remove this macro.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85324/new/

https://reviews.llvm.org/D85324

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-17 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 286014.
abhina.sreeskantharajan added a comment.

Addressed Hubert's comments, and removed some macros that are unnecessary with 
system header updates.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85324/new/

https://reviews.llvm.org/D85324

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init.c

Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1038,6 +1038,38 @@
 // S390X:#define __s390__ 1
 // S390X:#define __s390x__ 1
 //
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
+// RUN: %clang_cc1 -x c -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-C %s
+// RUN: %clang_cc1 -E -dM -std=gnu99 -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
+// RUN: %clang_cc1 -E -dM -std=gnu11 -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-CXX %s
+// RUN: %clang_cc1 -x c -std=c99 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-C99 %s
+// RUN: %clang_cc1 -x c++ -std=c++11 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-CXX %s
+// RUN: %clang_cc1 -x c++ -std=c++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-CXX %s
+// RUN: %clang_cc1 -x c++ -std=gnu++11 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-CXX -check-prefix S390X-ZOS-GXX %s
+// RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-CXX -check-prefix S390X-ZOS-GXX %s
+//
+// S390X-ZOS-GXX:#define _EXT 1
+// S390X-ZOS-C99:#define _ISOC99_SOURCE 1
+// S390X-ZOS:#define _LONG_LONG 1
+// S390X-ZOS-GXX:#define _MI_BUILTIN 1
+// S390X-ZOS:#define _OPEN_DEFAULT 1
+// S390X-ZOS:#define _UNIX03_WITHDRAWN 1
+// S390X-ZOS-CXX:#define _XOPEN_SOURCE 600
+// S390X-ZOS:#define __370__ 1
+// S390X-ZOS:#define __64BIT__ 1
+// S390X-ZOS:#define __BFP__ 1
+// S390X-ZOS:#define __BOOL__ 1
+// S390X-ZOS-CXX:#define __DLL__ 1
+// S390X-ZOS:#define __LONGNAME__ 1
+// S390X-ZOS:#define __MVS__ 1
+// S390X-ZOS:#define __THW_370__ 1
+// S390X-ZOS:#define __THW_BIG_ENDIAN__ 1
+// S390X-ZOS:#define __TOS_390__ 1
+// S390X-ZOS:#define __TOS_MVS__ 1
+// S390X-ZOS:#define __XPLINK__ 1
+// S390X-ZOS-CXX:#define __wchar_t 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-rtems-elf < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-DEFAULT %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=sparc-none-netbsd < /dev/null | FileCheck -match-full-lines -check-prefix SPARC -check-prefix SPARC-NETOPENBSD %s
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -727,6 +727,57 @@
   bool defaultsToAIXPowerAlignment() const override { return true; }
 };
 
+// z/OS target
+template 
+class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+MacroBuilder &Builder) const override {
+// FIXME: LONG_LONG should not be defined under -std=c89.
+Builder.defineMacro("_LONG_LONG");
+Builder.defineMacro("_OPEN_DEFAULT");
+// _UNIX03_WITHDRAWN is required to build libcxx.
+Builder.defineMacro("_UNIX03_WITHDRAWN");
+Builder.defineMacro("__370__");
+Builder.defineMacro("__BFP__");
+Builder.defineMacro("__BOOL__");
+Builder.defineMacro("__LONGNAME__");
+Builder.defineMacro("__MVS__");
+Builder.defineMacro("__THW_370__");
+Builder.defineMacro("__THW_BIG_ENDIAN__");
+Builder.defineMacro("__TOS_390__");
+Buil

[PATCH] D86077: [clangd] Add a way for exporting memory usage metrics

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: sammccall, adamcz.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, 
javed.absar.
Herald added a project: clang.
kadircet requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Introduces a helper to collect memory usage metrics from multiple
components.
Adds measurements for dynamic index, ast cache and preambles.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86077

Files:
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/support/Trace.cpp
  clang-tools-extra/clangd/support/Trace.h

Index: clang-tools-extra/clangd/support/Trace.h
===
--- clang-tools-extra/clangd/support/Trace.h
+++ clang-tools-extra/clangd/support/Trace.h
@@ -68,6 +68,10 @@
   const llvm::StringLiteral LabelName;
 };
 
+/// Convenient helper for collecting memory usage metrics from across multiple
+/// components. Results are recorded under a metric named "memory_usage".
+void recordMemoryUsage(double Value, llvm::StringRef ComponentName);
+
 /// A consumer of trace events and measurements. The events are produced by
 /// Spans and trace::log, the measurements are produced by Metrics::record.
 /// Implementations of this interface must be thread-safe.
Index: clang-tools-extra/clangd/support/Trace.cpp
===
--- clang-tools-extra/clangd/support/Trace.cpp
+++ clang-tools-extra/clangd/support/Trace.cpp
@@ -326,6 +326,13 @@
 Context EventTracer::beginSpan(llvm::StringRef Name, llvm::json::Object *Args) {
   return Context::current().clone();
 }
+
+void recordMemoryUsage(double Value, llvm::StringRef ComponentName) {
+  static constexpr Metric MemoryUsage("memory_usage", Metric::Value,
+  "component_name");
+
+  MemoryUsage.record(Value, ComponentName);
+}
 } // namespace trace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/FileIndex.cpp
===
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -23,6 +23,7 @@
 #include "index/dex/Dex.h"
 #include "support/Logger.h"
 #include "support/Path.h"
+#include "support/Trace.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
@@ -399,6 +400,7 @@
   auto NewIndex =
   PreambleSymbols.buildIndex(UseDex ? IndexType::Heavy : IndexType::Light,
  DuplicateHandling::PickOne, &IndexVersion);
+  trace::recordMemoryUsage(NewIndex->estimateMemoryUsage(), "preamble_index");
   {
 std::lock_guard Lock(UpdateIndexMu);
 if (IndexVersion <= PreambleIndexVersion) {
@@ -424,6 +426,7 @@
   size_t IndexVersion = 0;
   auto NewIndex = MainFileSymbols.buildIndex(
   IndexType::Light, DuplicateHandling::Merge, &IndexVersion);
+  trace::recordMemoryUsage(NewIndex->estimateMemoryUsage(), "main_file_index");
   {
 std::lock_guard Lock(UpdateIndexMu);
 if (IndexVersion <= MainIndexVersion) {
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -77,6 +77,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -164,6 +165,14 @@
 return llvm::Optional>(std::move(V));
   }
 
+  size_t getUsedBytes() {
+size_t TotalBytes = 0;
+std::lock_guard Lock(Mut);
+for (const auto &Elem : LRU)
+  TotalBytes += Elem.second->getUsedBytes();
+return TotalBytes;
+  }
+
 private:
   using KVPair = std::pair>;
 
@@ -1286,6 +1295,20 @@
 FD->Contents = Inputs.Contents;
   }
   FD->Worker->update(std::move(Inputs), WantDiags);
+
+  // Update memory usage metrics. Note that these are just estimates.
+  size_t ASTCacheBytes = IdleASTs->getUsedBytes();
+  trace::recordMemoryUsage(ASTCacheBytes, "ast_cache");
+
+  size_t PreambleBytes = 0;
+  // Otherwise preambles are stored on disk and we only keep filename in memory.
+  if (Opts.StorePreamblesInMemory) {
+for (const auto &Elem : fileStats())
+  PreambleBytes += Elem.second.UsedBytes;
+// fileStats results include ast cache sizes too, subtract them.
+PreambleBytes -= ASTCacheBytes;
+  }
+  trace::recordMemoryUsage(PreambleBytes, "preambles");
   return NewFile;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86077: [clangd] Add a way for exporting memory usage metrics

2020-08-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:172
+for (const auto &Elem : LRU)
+  TotalBytes += Elem.second->getUsedBytes();
+return TotalBytes;

Any idea how expensive this is? I suppose TUScheduler::update() is rare enough 
that it's not a big deal?

I ask because of bad experience with estimating memory usage inside critical 
path on another project ;-)

Maybe we can add a span around this, so we can see if it's expensive in traces? 
Or maybe that will turn out to be more expensive than memory estimation? 



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1299
+
+  // Update memory usage metrics. Note that these are just estimates.
+  size_t ASTCacheBytes = IdleASTs->getUsedBytes();

Isn't FD->Worker->update() above async (with correct options)? If so, this is 
still reading the old data, right?



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1311
+  }
+  trace::recordMemoryUsage(PreambleBytes, "preambles");
   return NewFile;

Would it make sense to collect the number of preambles and ASTs cached at this 
point as well? Exported under a different metric, but at the same time, to be 
able to join the data together?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86077/new/

https://reviews.llvm.org/D86077

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


[PATCH] D85091: [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in IfStmt

2020-08-17 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/test/SemaCXX/attr-likelihood.cpp:101
+}
+#endif

aaron.ballman wrote:
> Mordante wrote:
> > aaron.ballman wrote:
> > > Mordante wrote:
> > > > Quuxplusone wrote:
> > > > > I'd like to see a case like `if (x) [[likely]] i=1;` just to prove 
> > > > > that it works on statements that aren't blocks or empty statements. 
> > > > > (My understanding is that this should already work with your current 
> > > > > patch.)
> > > > > 
> > > > > I'd like to see a case like `if (x) { [[likely]] i=1; }` to prove 
> > > > > that it works on arbitrary statements. This //should// have the same 
> > > > > effect as `if (x) [[likely]] { i=1; }`. My understanding is that your 
> > > > > current patch doesn't get us there //yet//. If it's unclear how we'd 
> > > > > get there by proceeding along your current trajectory, then I would 
> > > > > question whether we want to commit to this trajectory at all, yet.
> > > > I agree it would be a good idea to add a test like `if (x) [[likely]] 
> > > > i=1;` but I don't feel adding an additional test in this file proves 
> > > > anything. I'll add a test to 
> > > > `clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp` to prove 
> > > > it not only accepts the code but also honours the attribute. This is 
> > > > especially important due to your correct observation that `if (x) { 
> > > > [[likely]] i=1; }` doesn't have any effect. The code is accepted but 
> > > > the CodeGen won't honour the attribute.
> > > > 
> > > > I think we can use the current approach, but I need to adjust 
> > > > `getLikelihood`. Instead of only testing whether the current `Stmt` is 
> > > > an `AttributedStmt` it needs to iterate over all `Stmt`s and test them 
> > > > for the attribute. Obviously it should avoid looking into `Stmt`s that 
> > > > also use the attribute, e.g:
> > > > ```
> > > > if(b) {
> > > > switch(c) {
> > > > [[unlikely]] case 0: ... break; // The attribute "belongs" to 
> > > > the switch not to the if
> > > > [[likely]] case 1: ... break; // The attribute "belongs" to the 
> > > > switch not to the if
> > > > }
> > > > }
> > > > ```
> > > > 
> > > > This is especially important due to your correct observation that if 
> > > > (x) { [[likely]] i=1; } doesn't have any effect. 
> > > 
> > > This code should diagnose the attribute as being ignored.
> > What I understood from Arthur and rereading the standard this should work, 
> > but the initial version of the patch didn't handle this properly.
> > What I understood from Arthur and rereading the standard this should work, 
> > but the initial version of the patch didn't handle this properly.
> 
> My original belief was  that it's acceptable for the attribute to be placed 
> there in terms of syntax, but the recommended practice doesn't apply to this 
> case because there's no alternative paths of execution once you've entered 
> the compound statement. That means:
> ```
> if (x) [[likely]] { i = 1; }
> // is not the same as
> if (x) { [[likely]] i = 1; }
> ```
> That said, I can squint at the words to get your interpretation and your 
> interpretation matches what's in the original paper 
> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0479r2.html#examples).
> 
> Ultimately, I think we should strive for consistency between implementations, 
> and I think we should file an issue with WG21 to clarify the wording once we 
> figure out how implementations want to interpret questions like these.
I don't know WG21's actual rationale, but I can imagine a programmer wanting to 
annotate something like this:

#define FATAL(msg) [[unlikely]] log_and_abort("Fatal error!", msg);
...
auto packet = receive();
if (packet.malformed()) {
save_to_log(packet);
FATAL("malformed packet");
}
...

The "absolute unlikeliness" of the malformed-packet codepath is encapsulated 
within the `FATAL` macro so that the programmer doesn't have to tediously 
repeat `[[unlikely]]` at some branch arbitrarily far above the `FATAL` point. 
Compilers actually do this already, every time they see a `throw` — every 
`throw` is implicitly "unlikely" and taints its whole codepath. We want to do 
something similar for `[[unlikely]]`.

It's definitely going to be unsatisfyingly fuzzy logic, though, similar to how 
inlining heuristics and `inline` are today.

My understanding is that

if (x) { [[likely]] i = 1; }
if (x) [[likely]] { i = 1; }

have exactly the same surface reading: the same set of codepaths exist in both 
cases, and the same "x true, i gets 1" codepath is `[[likely]]` in both cases. 
Of course your heuristic might //choose// to treat them differently, just as 
you might //choose// to treat

struct S { int f() { ... } };
struct S { inline int f() { ... } };

differently for inlining purposes despite their identical surface readings.


Repository:
  rG LLVM Github Monorepo

CHANGES 

[PATCH] D86077: [clangd] Add a way for exporting memory usage metrics

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:172
+for (const auto &Elem : LRU)
+  TotalBytes += Elem.second->getUsedBytes();
+return TotalBytes;

adamcz wrote:
> Any idea how expensive this is? I suppose TUScheduler::update() is rare 
> enough that it's not a big deal?
> 
> I ask because of bad experience with estimating memory usage inside critical 
> path on another project ;-)
> 
> Maybe we can add a span around this, so we can see if it's expensive in 
> traces? Or maybe that will turn out to be more expensive than memory 
> estimation? 
> TUScheduler::update() is rare enough

actually it can potentially be triggered after every keystroke. I suppose it 
might make sense to move this out of the main thread completely. I suppose 
`runWithPreamble`s action might be a better place to record, which is still 
quite often btw (every signature help and code completion request goes through 
it), but runs on a separate thread.

i would expect `that will turn out to be more expensive than memory estimation` 
to be the case, will do some checks though.

Most of the calculations happening in there is just addition of some members. 
the source manager makes me afraid a little bit tho, as it seems to be going 
over all the buffers.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1299
+
+  // Update memory usage metrics. Note that these are just estimates.
+  size_t ASTCacheBytes = IdleASTs->getUsedBytes();

adamcz wrote:
> Isn't FD->Worker->update() above async (with correct options)? If so, this is 
> still reading the old data, right?
yes that's true. i was aiming for this to be an estimate, rather than an 
accurate view.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1311
+  }
+  trace::recordMemoryUsage(PreambleBytes, "preambles");
   return NewFile;

adamcz wrote:
> Would it make sense to collect the number of preambles and ASTs cached at 
> this point as well? Exported under a different metric, but at the same time, 
> to be able to join the data together?
yeah that definitely makes sense, but I would rather do that on a separate 
patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86077/new/

https://reviews.llvm.org/D86077

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


[PATCH] D86077: [clangd] Add a way for exporting memory usage metrics

2020-08-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:168
 
+  size_t getUsedBytes() {
+size_t TotalBytes = 0;

nit: This is the same name as getUsedBytes(Key K). Maybe rename to 
getTotalUsedBytes()?



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:172
+for (const auto &Elem : LRU)
+  TotalBytes += Elem.second->getUsedBytes();
+return TotalBytes;

kadircet wrote:
> adamcz wrote:
> > Any idea how expensive this is? I suppose TUScheduler::update() is rare 
> > enough that it's not a big deal?
> > 
> > I ask because of bad experience with estimating memory usage inside 
> > critical path on another project ;-)
> > 
> > Maybe we can add a span around this, so we can see if it's expensive in 
> > traces? Or maybe that will turn out to be more expensive than memory 
> > estimation? 
> > TUScheduler::update() is rare enough
> 
> actually it can potentially be triggered after every keystroke. I suppose it 
> might make sense to move this out of the main thread completely. I suppose 
> `runWithPreamble`s action might be a better place to record, which is still 
> quite often btw (every signature help and code completion request goes 
> through it), but runs on a separate thread.
> 
> i would expect `that will turn out to be more expensive than memory 
> estimation` to be the case, will do some checks though.
> 
> Most of the calculations happening in there is just addition of some members. 
> the source manager makes me afraid a little bit tho, as it seems to be going 
> over all the buffers.
+1 to moving call to this to runWithPreamble or something like that. If a 
request gets cancelled, for example, there's no need to update the memory usage.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1299
+
+  // Update memory usage metrics. Note that these are just estimates.
+  size_t ASTCacheBytes = IdleASTs->getUsedBytes();

kadircet wrote:
> adamcz wrote:
> > Isn't FD->Worker->update() above async (with correct options)? If so, this 
> > is still reading the old data, right?
> yes that's true. i was aiming for this to be an estimate, rather than an 
> accurate view.
I think this deserves a comment.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1309
+// fileStats results include ast cache sizes too, subtract them.
+PreambleBytes -= ASTCacheBytes;
+  }

So technically this is incorrect.
IdleASTs might contain AST for a file that is no longer tracked (e.g. had 
removeDocument() called on it). ASTCacheBytes will include it, but 
PreambleBytes will not, since it only asks for size of the tracked files. It's 
probably fine, considering how rare this will be and that these are all 
estimates, but I would recommend a comment, in case someone sees PreambleBytes 
be negative and wonders what's going on.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1311
+  }
+  trace::recordMemoryUsage(PreambleBytes, "preambles");
   return NewFile;

kadircet wrote:
> adamcz wrote:
> > Would it make sense to collect the number of preambles and ASTs cached at 
> > this point as well? Exported under a different metric, but at the same 
> > time, to be able to join the data together?
> yeah that definitely makes sense, but I would rather do that on a separate 
> patch.
Sounds good.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86077/new/

https://reviews.llvm.org/D86077

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


[PATCH] D85977: [release][docs] Update contributions to LLVM 11 for SVE.

2020-08-17 Thread David Sherwood via Phabricator via cfe-commits
david-arm added inline comments.



Comment at: llvm/docs/ReleaseNotes.rst:70
+  ``VFDatabase`` class. When scanning through the set of vector
+  functions associated to a scalar call, the loop vectorizer now
+  relies on ``VFDatabase``, instead of ``TargetLibraryInfo``.

I think this should probably be "associated with a ..."



Comment at: llvm/docs/ReleaseNotes.rst:84
+* LLVM IR now supports two distinct ``llvm::FixedVectorType`` and
+  ``llvm::ScalableVectorType``, both derived from the base class
+  ``llvm::VectorType``. A number of algorithms dealing with IR vector

Perhaps this should be "now support two distinct ... and ... vector types, ..." 
?



Comment at: llvm/docs/ReleaseNotes.rst:117
 
+* Clang supports to the following macros that enable the C-intrinsics
+  from the `Arm C language extensions for SVE

"Clang adds support for the ..." perhaps?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85977/new/

https://reviews.llvm.org/D85977

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


[PATCH] D83536: [clangd] Index refs to main-file symbols as well

2020-08-17 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:727
+  // Run the collector again with CollectMainFileRefs = true.
+  InMemoryFileSystem = new llvm::vfs::InMemoryFileSystem();
+  CollectorOpts.CollectMainFileRefs = true;

kadircet wrote:
> i don't think this is needed, am I missing something? IIRC, inmemoryfs should 
> overwrite any existing files and even if it doesn't we are not really 
> changing file contents in here.
I initially didn't have this, and got the following assertion in the second 
`runSymbolCollector()` call:

```ClangdTests: llvm/src/llvm/lib/Support/MemoryBuffer.cpp:48: void 
llvm::MemoryBuffer::init(const char *, const char *, bool): Assertion 
`(!RequiresNullTerminator || BufEnd[0] == 0) && "Buffer is not null 
terminated!"' failed.
 #0 0x7f4242501c67 llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
llvm/src/llvm/lib/Support/Unix/Signals.inc:563:11
 #1 0x7f4242501e09 PrintStackTraceSignalHandler(void*) 
llvm/src/llvm/lib/Support/Unix/Signals.inc:624:1
 #2 0x7f424250060b llvm::sys::RunSignalHandlers() 
llvm/src/llvm/lib/Support/Signals.cpp:67:5
 #3 0x7f424250251d SignalHandler(int) 
llvm/src/llvm/lib/Support/Unix/Signals.inc:405:1
 #4 0x7f42482a10e0 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x110e0)
 #5 0x7f424157dfff raise 
/build/glibc-77giwP/glibc-2.24/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x7f424157f42a abort /build/glibc-77giwP/glibc-2.24/stdlib/abort.c:91:0
 #7 0x7f4241576e67 __assert_fail_base 
/build/glibc-77giwP/glibc-2.24/assert/assert.c:92:0
 #8 0x7f4241576f12 (/lib/x86_64-linux-gnu/libc.so.6+0x2bf12)
 #9 0x7f4242427350 llvm::MemoryBuffer::init(char const*, char const*, bool) 
llvm/src/llvm/lib/Support/MemoryBuffer.cpp:49:17
#10 0x7f42424275b4 (anonymous 
namespace)::MemoryBufferMem::MemoryBufferMem(llvm::StringRef,
 bool) llvm/src/llvm/lib/Support/MemoryBuffer.cpp:89:3
#11 0x7f4242427400 llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, 
llvm::StringRef, bool) llvm/src/llvm/lib/Support/MemoryBuffer.cpp:115:7
#12 0x7f424249ab20 llvm::vfs::detail::(anonymous 
namespace)::InMemoryFileAdaptor::getBuffer(llvm::Twine const&, long, bool, 
bool) llvm/src/llvm/lib/Support/VirtualFileSystem.cpp:615:12
#13 0x7f4242b0ecf1 clang::FileManager::getBufferForFile(clang::FileEntry 
const*, bool, bool) llvm/src/clang/lib/Basic/FileManager.cpp:474:5
#14 0x7f4242b52013 
clang::SrcMgr::ContentCache::getBuffer(clang::DiagnosticsEngine&, 
clang::FileManager&, clang::SourceLocation, bool*) const 
llvm/src/clang/lib/Basic/SourceManager.cpp:172:8
#15 0x7f4242fe64c0 clang::SourceManager::getBuffer(clang::FileID, 
clang::SourceLocation, bool*) const 
llvm/src/clang/include/clang/Basic/SourceManager.h:976:5
#16 0x7f4242fe2425 clang::Preprocessor::EnterSourceFile(clang::FileID, 
clang::DirectoryLookup const*, clang::SourceLocation) 
llvm/src/clang/lib/Lex/PPLexerChange.cpp:77:29
#17 0x7f424301c104 clang::Preprocessor::EnterMainSourceFile() 
llvm/src/clang/lib/Lex/Preprocessor.cpp:547:5
#18 0x7f423d4a23fe clang::ParseAST(clang::Sema&, bool, bool) 
llvm/src/clang/lib/Parse/ParseAST.cpp:144:33
#19 0x7f42466df752 clang::ASTFrontendAction::ExecuteAction() 
llvm/src/clang/lib/Frontend/FrontendAction.cpp:1059:1
#20 0x7f42466df118 clang::FrontendAction::Execute() 
llvm/src/clang/lib/Frontend/FrontendAction.cpp:954:7
#21 0x7f4246655ae4 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
llvm/src/clang/lib/Frontend/CompilerInstance.cpp:984:23
#22 0x7f42472a622a 
clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr,
 clang::FileManager*, std::shared_ptr, 
clang::DiagnosticConsumer*) llvm/src/clang/lib/Tooling/Tooling.cpp:410:14
#23 0x7f42472a60d4 clang::tooling::ToolInvocation::runInvocation(char 
const*, clang::driver::Compilation*, 
std::shared_ptr, 
std::shared_ptr) 
llvm/src/clang/lib/Tooling/Tooling.cpp:385:3
#24 0x7f42472a5015 clang::tooling::ToolInvocation::run() 
llvm/src/clang/lib/Tooling/Tooling.cpp:370:3
#25 0x00bc916b clang::clangd::(anonymous 
namespace)::SymbolCollectorTest::runSymbolCollector(llvm::StringRef, 
llvm::StringRef, std::vector, std::allocator >, 
std::allocator, 
std::allocator > > > const&) 
llvm/src/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:283:15
#26 0x00bda339 clang::clangd::(anonymous 
namespace)::SymbolCollectorTest_Refs_Test::TestBody() 
llvm/src/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:729:3
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83536/new/

https://reviews.llvm.org/D83536

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


[PATCH] D86065: [SVE] Make ElementCount members private

2020-08-17 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added inline comments.



Comment at: llvm/include/llvm/Support/TypeSize.h:56
 
+  friend bool operator>(const ElementCount &LHS, const ElementCount &RHS) {
+assert(LHS.Scalable == RHS.Scalable &&

I think that @ctetreau is right on 
https://reviews.llvm.org/D85794#inline-793909. We should not overload a 
comparison operator on this class because the set it represent it cannot be 
ordered.

Chris suggests an approach of writing a static function that can be used as a 
comparison operator,  so that we can make it explicit of what kind of 
comparison we  are doing. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86065/new/

https://reviews.llvm.org/D86065

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


[PATCH] D86020: [MemCpyOptimizer] Optimize passing byref function arguments down the stack

2020-08-17 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko updated this revision to Diff 286037.
atrosinenko added a comment.

Restrict transformation to passing through `byref` arguments, not arbitrary 
pointers.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86020/new/

https://reviews.llvm.org/D86020

Files:
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
  llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll

Index: llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll
===
--- /dev/null
+++ llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll
@@ -0,0 +1,45 @@
+; RUN: opt -memcpyopt -dse -S < %s | FileCheck %s
+
+%struct.S = type { i32 }
+
+declare void @llvm.memcpy.p0i8.p0i8.i16(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i16, i1 immarg)
+
+; A caller of this function has to arrange everything for the pointer it passes
+; to be usable with byref attrbiute anyway, so just pass the pointer through.
+define void @function_with_byref_arg(%struct.S* byref(%struct.S) align 4 %0) {
+; CHECK:   define void @function_with_byref_arg{{.*}}byref(%struct.S){{.*}} {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:call void @leaf
+; CHECK-NEXT:ret void
+; CHECK-NEXT:  }
+entry:
+  %x = alloca %struct.S, align 4
+  %1 = bitcast %struct.S* %x to i8*
+  %2 = bitcast %struct.S* %0 to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 %1, i8* align 4 %2, i16 16, i1 false)
+  call void @leaf(%struct.S* byref(%struct.S) align 4 %x)
+  ret void
+}
+
+; A generic pointer may point to memory being modified by other threads,
+; coroutines, etc. during execution of @leaf().
+define void @function_with_pointer_arg(%struct.S* align 4 %0) {
+; CHECK:   define void @function_with_pointer_arg(%struct.S* align 4 [[V0:%.+]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[ALLOCA:%.+]] = alloca %struct.S, align 4
+; CHECK-NEXT:[[V1:%.+]] = bitcast %struct.S* [[ALLOCA]] to i8*
+; CHECK-NEXT:[[V2:%.+]] = bitcast %struct.S* [[V0]] to i8*
+; CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 %1, i8* align 4 %2, i16 16, i1 false)
+; CHECK-NEXT:call void @leaf(%struct.S* byref(%struct.S) align 4 [[ALLOCA]])
+; CHECK-NEXT:ret void
+; CHECK-NEXT:  }
+entry:
+  %x = alloca %struct.S, align 4
+  %1 = bitcast %struct.S* %x to i8*
+  %2 = bitcast %struct.S* %0 to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 %1, i8* align 4 %2, i16 16, i1 false)
+  call void @leaf(%struct.S* byref(%struct.S) align 4 %x)
+  ret void
+}
+
+declare void @leaf(%struct.S* byref(%struct.S) align 4)
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1217,10 +1217,10 @@
   return true;
 }
 
-/// This is called on every byval argument in call sites.
-bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
+/// This is called on every byval/byref argument in call sites.
+bool MemCpyOptPass::processByValOrByRefArgument(CallBase &CB, unsigned ArgNo) {
   const DataLayout &DL = CB.getCaller()->getParent()->getDataLayout();
-  // Find out what feeds this byval argument.
+  // Find out what feeds this byval/byref argument.
   Value *ByValArg = CB.getArgOperand(ArgNo);
   Type *ByValTy = cast(ByValArg->getType())->getElementType();
   uint64_t ByValSize = DL.getTypeAllocSize(ByValTy);
@@ -1238,6 +1238,23 @@
   ByValArg->stripPointerCasts() != MDep->getDest())
 return false;
 
+  // ByRef arguments should be handled with care: they are not implicitly copied
+  // to the calling function's stack frame, so they may be accessible from other
+  // threads, coroutines, etc. On the other hand, there is a special case: just
+  // passing through an argument down the stack like this:
+  // void leaf(struct X /* byref(%struct.X) */);
+  // void intermediate(struct X a /* byref(%struct.X) */) {
+  //   /* prologue: `a` is implicitly copied by clang in the callee frame */
+  //   leaf(a);
+  // }
+  // So, checking whether the memcpy() source is byref argument on itself.
+  if (CB.isByRefArgument(ArgNo)) {
+Argument *SourceAsArgument =
+dyn_cast(MDep->getSource()->stripPointerCasts());
+if (!SourceAsArgument || !SourceAsArgument->hasByRefAttr())
+  return false;
+  }
+
   // The length of the memcpy must be larger or equal to the size of the byval.
   ConstantInt *C1 = dyn_cast(MDep->getLength());
   if (!C1 || C1->getValue().getZExtValue() < ByValSize)
@@ -1287,7 +1304,7 @@
 TmpCast = TmpBitCast;
   }
 
-  LLVM_DEBUG(dbgs() << "MemCpyOptPass: Forwarding memcpy to byval:\n"
+  LLVM_DEBUG(dbgs() << "MemCpyOptPass: Forwarding memcpy to byval or byref:\n"
 << "  " << *MDep << "\n"
 << "  " << CB << "\n");
 
@@ -1

[PATCH] D85091: [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in IfStmt

2020-08-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaCXX/attr-likelihood.cpp:101
+}
+#endif

Quuxplusone wrote:
> aaron.ballman wrote:
> > Mordante wrote:
> > > aaron.ballman wrote:
> > > > Mordante wrote:
> > > > > Quuxplusone wrote:
> > > > > > I'd like to see a case like `if (x) [[likely]] i=1;` just to prove 
> > > > > > that it works on statements that aren't blocks or empty statements. 
> > > > > > (My understanding is that this should already work with your 
> > > > > > current patch.)
> > > > > > 
> > > > > > I'd like to see a case like `if (x) { [[likely]] i=1; }` to prove 
> > > > > > that it works on arbitrary statements. This //should// have the 
> > > > > > same effect as `if (x) [[likely]] { i=1; }`. My understanding is 
> > > > > > that your current patch doesn't get us there //yet//. If it's 
> > > > > > unclear how we'd get there by proceeding along your current 
> > > > > > trajectory, then I would question whether we want to commit to this 
> > > > > > trajectory at all, yet.
> > > > > I agree it would be a good idea to add a test like `if (x) [[likely]] 
> > > > > i=1;` but I don't feel adding an additional test in this file proves 
> > > > > anything. I'll add a test to 
> > > > > `clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp` to 
> > > > > prove it not only accepts the code but also honours the attribute. 
> > > > > This is especially important due to your correct observation that `if 
> > > > > (x) { [[likely]] i=1; }` doesn't have any effect. The code is 
> > > > > accepted but the CodeGen won't honour the attribute.
> > > > > 
> > > > > I think we can use the current approach, but I need to adjust 
> > > > > `getLikelihood`. Instead of only testing whether the current `Stmt` 
> > > > > is an `AttributedStmt` it needs to iterate over all `Stmt`s and test 
> > > > > them for the attribute. Obviously it should avoid looking into 
> > > > > `Stmt`s that also use the attribute, e.g:
> > > > > ```
> > > > > if(b) {
> > > > > switch(c) {
> > > > > [[unlikely]] case 0: ... break; // The attribute "belongs" to 
> > > > > the switch not to the if
> > > > > [[likely]] case 1: ... break; // The attribute "belongs" to 
> > > > > the switch not to the if
> > > > > }
> > > > > }
> > > > > ```
> > > > > 
> > > > > This is especially important due to your correct observation that if 
> > > > > (x) { [[likely]] i=1; } doesn't have any effect. 
> > > > 
> > > > This code should diagnose the attribute as being ignored.
> > > What I understood from Arthur and rereading the standard this should 
> > > work, but the initial version of the patch didn't handle this properly.
> > > What I understood from Arthur and rereading the standard this should 
> > > work, but the initial version of the patch didn't handle this properly.
> > 
> > My original belief was  that it's acceptable for the attribute to be placed 
> > there in terms of syntax, but the recommended practice doesn't apply to 
> > this case because there's no alternative paths of execution once you've 
> > entered the compound statement. That means:
> > ```
> > if (x) [[likely]] { i = 1; }
> > // is not the same as
> > if (x) { [[likely]] i = 1; }
> > ```
> > That said, I can squint at the words to get your interpretation and your 
> > interpretation matches what's in the original paper 
> > (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0479r2.html#examples).
> > 
> > Ultimately, I think we should strive for consistency between 
> > implementations, and I think we should file an issue with WG21 to clarify 
> > the wording once we figure out how implementations want to interpret 
> > questions like these.
> I don't know WG21's actual rationale, but I can imagine a programmer wanting 
> to annotate something like this:
> 
> #define FATAL(msg) [[unlikely]] log_and_abort("Fatal error!", msg);
> ...
> auto packet = receive();
> if (packet.malformed()) {
> save_to_log(packet);
> FATAL("malformed packet");
> }
> ...
> 
> The "absolute unlikeliness" of the malformed-packet codepath is encapsulated 
> within the `FATAL` macro so that the programmer doesn't have to tediously 
> repeat `[[unlikely]]` at some branch arbitrarily far above the `FATAL` point. 
> Compilers actually do this already, every time they see a `throw` — every 
> `throw` is implicitly "unlikely" and taints its whole codepath. We want to do 
> something similar for `[[unlikely]]`.
> 
> It's definitely going to be unsatisfyingly fuzzy logic, though, similar to 
> how inlining heuristics and `inline` are today.
> 
> My understanding is that
> 
> if (x) { [[likely]] i = 1; }
> if (x) [[likely]] { i = 1; }
> 
> have exactly the same surface reading: the same set of codepaths exist in 
> both cases, and the same "x true, i gets 1" codepath is `[[likely]]` in both 
> cases. Of course your heuristic might //choose// to treat them differently, 
> just as

[PATCH] D85917: [MSP430] Fix passing C structs and unions as function arguments

2020-08-17 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko updated this revision to Diff 286038.
atrosinenko added a comment.

Update with implicit pointers being passed through.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85917/new/

https://reviews.llvm.org/D85917

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/msp430-struct-or-union-args.c

Index: clang/test/CodeGen/msp430-struct-or-union-args.c
===
--- /dev/null
+++ clang/test/CodeGen/msp430-struct-or-union-args.c
@@ -0,0 +1,123 @@
+// REQUIRES: msp430-registered-target
+// Optimized to check that some of memcpy intrinsic invocations are optimized out.
+// RUN: %clang -target msp430 -fno-inline-functions -S -Os -o- %s | FileCheck --check-prefixes=ASM %s
+// Do not use any optimization to not clutter the output with deduced LLVM IR attributes.
+// RUN: %clang -target msp430 -fno-inline-functions -S -emit-llvm -o- %s | FileCheck --check-prefixes=IR %s
+
+#include 
+#include 
+
+// According to Section 3.5 of MSP430 EABI, structures and unions are passed
+// by reference, even if an equally-sized integer argument could be passed
+// in registers.
+
+struct S {
+  uint16_t a;
+};
+union U {
+  uint16_t a;
+};
+
+// IR: %struct.S = type { i16 }
+// IR: %union.U = type { i16 }
+
+_Static_assert(sizeof(struct S) * CHAR_BIT == 16, "Unexpected size");
+_Static_assert(sizeof(union U) * CHAR_BIT == 16, "Unexpected size");
+
+extern struct S s;
+extern union U u;
+
+// Cannot know for sure whether they change the argument
+extern void leaf_s(struct S *x);
+extern void leaf_u(union U *);
+
+// Callee is responsible for leaving the byref argument intact
+void middle_s(struct S x) {
+// IR: define {{(dso_local )?}}void @middle_s(%struct.S* byref(%struct.S) align 2 [[S_ARG:%.+]])
+// IR: [[S_COPY:%.+]] = alloca %struct.S, align 2
+// IR: [[S_CASTED_COPY:%.+]] = bitcast %struct.S* [[S_COPY]] to i8*
+// IR: [[S_CASTED_ARG:%.+]] = bitcast %struct.S* [[S_ARG]] to i8*
+// IR: call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 2 [[S_CASTED_COPY]], i8* align 2 [[S_CASTED_ARG]], i16 2, i1 false)
+// IR: call void @leaf_s(%struct.S* [[S_COPY]])
+// IR: ret void
+
+// ASM:  middle_s:
+// ASM:  sub #2, r1
+// ... here memcpy() occurs ...
+// ASM:  mov r1, r12
+// ASM-NEXT: call #leaf_s
+// ASM-NEXT: add #2, r1
+// ASM-NEXT: ret
+  leaf_s(&x);
+}
+void middle_u(union U x) {
+// IR: define {{(dso_local )?}}void @middle_u(%union.U* byref(%union.U) align 2 [[U_ARG:%.+]])
+// IR: [[U_COPY:%.+]] = alloca %union.U, align 2
+// IR: [[U_CASTED_COPY:%.+]] = bitcast %union.U* [[U_COPY]] to i8*
+// IR: [[U_CASTED_ARG:%.+]] = bitcast %union.U* [[U_ARG]] to i8*
+// IR: call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 2 [[U_CASTED_COPY]], i8* align 2 [[U_CASTED_ARG]], i16 2, i1 false)
+// IR: call void @leaf_u(%union.U* [[U_COPY]])
+// IR: ret void
+
+// ASM:  middle_u:
+// ASM:  sub #2, r1
+// ... here memcpy() occurs ...
+// ASM:  mov r1, r12
+// ASM-NEXT: call #leaf_u
+// ASM-NEXT: add #2, r1
+// ASM-NEXT: ret
+  leaf_u(&x);
+}
+
+void caller_s(void) {
+// IR: define {{(dso_local )?}}void @caller_s()
+// IR: call void @middle_s(%struct.S* byref(%struct.S) align 2 @s)
+// IR: ret void
+
+// ASM:  caller_s:
+// ASM:  mov #s, r12
+// ASM-NEXT: call #middle_s
+// ASM-NEXT: ret
+  middle_s(s);
+}
+void caller_u(void) {
+// IR: define dso_local void @caller_u()
+// IR: call void @middle_u(%union.U* byref(%union.U) align 2 @u)
+// IR: ret void
+
+// ASM:  caller_u:
+// ASM:  mov #u, r12
+// ASM-NEXT: call #middle_u
+// ASM-NEXT: ret
+  middle_u(u);
+}
+
+// No need to create a temporary copy of the struct/union-typed argument
+// if it is just passed to other function as-is.
+// TODO For now, it works when size of structure is more than 8 bytes,
+// otherwise the memcpy intrinsic will be replaced by InstCombiner.
+
+struct LL {
+  long long a[2];
+};
+
+extern struct LL ll;
+
+extern void leaf(struct LL x);
+
+void middle(struct LL x) {
+// ASM:  middle:
+// No stack-allocated objects:
+// ASM-NOT:  r1
+// ASM: call #leaf
+// ASM-NEXT: ret
+  leaf(x);
+}
+
+void caller(void) {
+// ASM:  caller:
+// ASM:  mov #ll, r12
+// ASM-NEXT: call #middle
+// ASM-NEXT: ret
+  middle(ll);
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7511,11 +7511,18 @@
 return DefaultABIInfo::classifyReturnType(RetTy);
   }
 
-  ABIArgInfo classifyArgumentType(QualType RetTy) const {
-if (RetTy->isAnyComplexType())
+  ABIArgInfo classifyArgumentType(QualType Ty) const {
+if (Ty->isAnyComplexType())
   return complexArgInfo();
 
-return DefaultABIInfo::classifyArgumentType(RetTy);
+// According to Section 3.5 of MSP430 EABI, structs, classes and unions
+// are passed by reference. The callee is respon

[PATCH] D86020: [MemCpyOptimizer] Optimize passing byref function arguments down the stack

2020-08-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

This looks reasonable on first glance. @arsenm ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86020/new/

https://reviews.llvm.org/D86020

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


[PATCH] D86077: [clangd] Add a way for exporting memory usage metrics

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 8 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1309
+// fileStats results include ast cache sizes too, subtract them.
+PreambleBytes -= ASTCacheBytes;
+  }

adamcz wrote:
> So technically this is incorrect.
> IdleASTs might contain AST for a file that is no longer tracked (e.g. had 
> removeDocument() called on it). ASTCacheBytes will include it, but 
> PreambleBytes will not, since it only asks for size of the tracked files. 
> It's probably fine, considering how rare this will be and that these are all 
> estimates, but I would recommend a comment, in case someone sees 
> PreambleBytes be negative and wonders what's going on.
right, thanks for pointing that out. added a comment, and clamped for 
non-negativity.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86077/new/

https://reviews.llvm.org/D86077

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


[PATCH] D86077: [clangd] Add a way for exporting memory usage metrics

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 286043.
kadircet marked an inline comment as done.
kadircet added a comment.

- Rename the overload
- Add comments around possible caveats that might result in inaccuracies.
- Move the metric recording itself into another thread.
- Keep the calculations in the main thread, as they seemed to have <1ms 
latency, even with huge preambles/asts.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86077/new/

https://reviews.llvm.org/D86077

Files:
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/support/Trace.cpp
  clang-tools-extra/clangd/support/Trace.h

Index: clang-tools-extra/clangd/support/Trace.h
===
--- clang-tools-extra/clangd/support/Trace.h
+++ clang-tools-extra/clangd/support/Trace.h
@@ -68,6 +68,10 @@
   const llvm::StringLiteral LabelName;
 };
 
+/// Convenient helper for collecting memory usage metrics from across multiple
+/// components. Results are recorded under a metric named "memory_usage".
+void recordMemoryUsage(double Value, llvm::StringRef ComponentName);
+
 /// A consumer of trace events and measurements. The events are produced by
 /// Spans and trace::log, the measurements are produced by Metrics::record.
 /// Implementations of this interface must be thread-safe.
Index: clang-tools-extra/clangd/support/Trace.cpp
===
--- clang-tools-extra/clangd/support/Trace.cpp
+++ clang-tools-extra/clangd/support/Trace.cpp
@@ -326,6 +326,13 @@
 Context EventTracer::beginSpan(llvm::StringRef Name, llvm::json::Object *Args) {
   return Context::current().clone();
 }
+
+void recordMemoryUsage(double Value, llvm::StringRef ComponentName) {
+  static constexpr Metric MemoryUsage("memory_usage", Metric::Value,
+  "component_name");
+
+  MemoryUsage.record(Value, ComponentName);
+}
 } // namespace trace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/FileIndex.cpp
===
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -23,6 +23,7 @@
 #include "index/dex/Dex.h"
 #include "support/Logger.h"
 #include "support/Path.h"
+#include "support/Trace.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
@@ -399,6 +400,7 @@
   auto NewIndex =
   PreambleSymbols.buildIndex(UseDex ? IndexType::Heavy : IndexType::Light,
  DuplicateHandling::PickOne, &IndexVersion);
+  trace::recordMemoryUsage(NewIndex->estimateMemoryUsage(), "preamble_index");
   {
 std::lock_guard Lock(UpdateIndexMu);
 if (IndexVersion <= PreambleIndexVersion) {
@@ -424,6 +426,7 @@
   size_t IndexVersion = 0;
   auto NewIndex = MainFileSymbols.buildIndex(
   IndexType::Light, DuplicateHandling::Merge, &IndexVersion);
+  trace::recordMemoryUsage(NewIndex->estimateMemoryUsage(), "main_file_index");
   {
 std::lock_guard Lock(UpdateIndexMu);
 if (IndexVersion <= MainIndexVersion) {
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -298,6 +298,11 @@
   /// This class stores per-file data in the Files map.
   struct FileData;
 
+  /// Records estimated memory usage for the TUScheduler internals. These are
+  /// best-effort estimates as TUScheduler itself is multi-threaded and internal
+  /// state is likely to change during the calculations.
+  void recordMemoryUsage();
+
 public:
   /// Responsible for retaining and rebuilding idle ASTs. An implementation is
   /// an LRU cache.
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -77,6 +77,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -164,6 +165,14 @@
 return llvm::Optional>(std::move(V));
   }
 
+  size_t getTotalUsedBytes() {
+size_t TotalBytes = 0;
+std::lock_guard Lock(Mut);
+for (const auto &Elem : LRU)
+  TotalBytes += Elem.second->getUsedBytes();
+return TotalBytes;
+  }
+
 private:
   using KVPair = std::pair>;
 
@@ -1272,6 +1281,7 @@
 
 bool TUScheduler::update(PathRef File, ParseInputs Inputs,
  WantDiagnostics WantDiags) {
+  recordMemoryUsage();
   std::unique_ptr &FD = Files[File];
   bool NewFile = FD == nullptr;
   if (!FD) {
@@ -1430,5 +1440,32 @@
   return P;
 }
 
+void TUScheduler::recordMemoryUsage() {
+  // We defer recording of the measurements to a worker thread, as it might
+ 

[PATCH] D86089: Add experimental flang driver and frontend with help screen

2020-08-17 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto created this revision.
Herald added subscribers: llvm-commits, cfe-commits, dang, usaxena95, kadircet, 
hiraditya, mgorny.
Herald added a reviewer: DavidTruby.
Herald added a reviewer: sscalpone.
Herald added projects: clang, LLVM.
CarolineConcatto requested review of this revision.
Herald added a subscriber: ilya-biryukov.

This is the first patch implementing the new Flang driver as outlined in [1],
[2] & [3]. It created Flang driver (`flang-new` and Flang frontend driver
(`flang-new -fc1`) with help screen(`-help`) and version(`--version`) options.
These will be renamed as `flang` and `flang -fc1` once the current Flang
throwaway driver, `flang`, can be replaced

`flang-new` is implemented in terms of libclangDriver, defaulting the driver
mode to `flang` (added to libclangDriver in [2]). This ensures that the driver
runs in flang mode regardless of the name of the binary inferred from argv[0].

The design of the new flang compiler and frontend drivers is inspired by it
counterparts in Clang [3]. Currently, the new flang compiler and frontend
drivers re-use Clang libraries: clangBasic, clangDriver and clangFrontend.
To identify Flang options, this patch adds FlangOption enum. printHelp is
updated so that `flang-new` prints only Flang options.

The new Flang driver is disabled by default. To build it, set
'-DBUILD_FLANG_NEW_DRIVER =ON' when configuring Flang and LLVM_ENABLE_PROJECTS
with clang.

[1] RFC: new Flang driver - next steps
http://lists.llvm.org/pipermail/flang-dev/2020-July/000470.html
[2] "RFC: Adding a fortran mode to the clang driver for flang"
http://lists.llvm.org/pipermail/cfe-dev/2019-June/062669.html
[3]RFC: refactoring libclangDriver/libclangFrontend to share with Flan
http://lists.llvm.org/pipermail/cfe-dev/2020-July/066393.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86089

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/test/Driver/flang/flang.f90
  clang/test/Driver/flang/flang_ucase.F90
  clang/test/Driver/flang/multiple-inputs-mixed.f90
  clang/test/Driver/flang/multiple-inputs.f90
  clang/unittests/Driver/SanitizerArgsTest.cpp
  clang/unittests/Driver/ToolChainTest.cpp
  flang/CMakeLists.txt
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/FrontendTool/Utils.h
  flang/lib/CMakeLists.txt
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Flang-Driver/driver-error-cc1.c
  flang/test/Flang-Driver/driver-error-cc1.cpp
  flang/test/Flang-Driver/driver-error-diagnostic.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/driver-version.f90
  flang/test/lit.cfg.py
  flang/test/lit.site.cfg.py.in
  flang/tools/CMakeLists.txt
  flang/tools/flang-driver/CMakeLists.txt
  flang/tools/flang-driver/driver.cpp
  flang/tools/flang-driver/fc1_main.cpp
  flang/unittests/CMakeLists.txt
  flang/unittests/Frontend/CMakeLists.txt
  flang/unittests/Frontend/CompilerInstanceTest.cpp
  llvm/lib/Option/OptTable.cpp

Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -612,7 +612,19 @@
 unsigned Flags = getInfo(Id).Flags;
 if (FlagsToInclude && !(Flags & FlagsToInclude))
   continue;
-if (Flags & FlagsToExclude)
+// If `Flags` is in both the Exclude set and in the Include set - display
+// it.
+if ((Flags & FlagsToExclude) && !(Flags & FlagsToInclude))
+  continue;
+
+// If `Flags` is empty (i.e. it's an option without any flags) then this is
+// a Clang-only option. If:
+// * we _are not_ in Flang Mode (FlagsToExclude contains FlangMode), then
+//   display it.
+// * we _are_ in Flang mode (FlagsToExclude does not contain FlangMode),
+//  don't display it.
+if (!Flags &&
+(FlagsToExclude & /*clang::driver::options::FlangMode*/ (1 << 14)))
   continue;
 
 // If an alias doesn't have a help text, show a help text for the aliased
Index: flang/unittests/Frontend/CompilerInstanceTest.cpp
===
--- /dev/null
+++ flang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -0,0 +1,52 @@
+//===- unittests/Frontend/CompilerInstanceTest.cpp - CI tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license 

[PATCH] D83536: [clangd] Index refs to main-file symbols as well

2020-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:727
+  // Run the collector again with CollectMainFileRefs = true.
+  InMemoryFileSystem = new llvm::vfs::InMemoryFileSystem();
+  CollectorOpts.CollectMainFileRefs = true;

nridge wrote:
> kadircet wrote:
> > i don't think this is needed, am I missing something? IIRC, inmemoryfs 
> > should overwrite any existing files and even if it doesn't we are not 
> > really changing file contents in here.
> I initially didn't have this, and got the following assertion in the second 
> `runSymbolCollector()` call:
> 
> ```ClangdTests: llvm/src/llvm/lib/Support/MemoryBuffer.cpp:48: void 
> llvm::MemoryBuffer::init(const char *, const char *, bool): Assertion 
> `(!RequiresNullTerminator || BufEnd[0] == 0) && "Buffer is not null 
> terminated!"' failed.
>  #0 0x7f4242501c67 llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
> llvm/src/llvm/lib/Support/Unix/Signals.inc:563:11
>  #1 0x7f4242501e09 PrintStackTraceSignalHandler(void*) 
> llvm/src/llvm/lib/Support/Unix/Signals.inc:624:1
>  #2 0x7f424250060b llvm::sys::RunSignalHandlers() 
> llvm/src/llvm/lib/Support/Signals.cpp:67:5
>  #3 0x7f424250251d SignalHandler(int) 
> llvm/src/llvm/lib/Support/Unix/Signals.inc:405:1
>  #4 0x7f42482a10e0 __restore_rt 
> (/lib/x86_64-linux-gnu/libpthread.so.0+0x110e0)
>  #5 0x7f424157dfff raise 
> /build/glibc-77giwP/glibc-2.24/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
>  #6 0x7f424157f42a abort 
> /build/glibc-77giwP/glibc-2.24/stdlib/abort.c:91:0
>  #7 0x7f4241576e67 __assert_fail_base 
> /build/glibc-77giwP/glibc-2.24/assert/assert.c:92:0
>  #8 0x7f4241576f12 (/lib/x86_64-linux-gnu/libc.so.6+0x2bf12)
>  #9 0x7f4242427350 llvm::MemoryBuffer::init(char const*, char const*, 
> bool) llvm/src/llvm/lib/Support/MemoryBuffer.cpp:49:17
> #10 0x7f42424275b4 (anonymous 
> namespace)::MemoryBufferMem::MemoryBufferMem(llvm::StringRef,
>  bool) llvm/src/llvm/lib/Support/MemoryBuffer.cpp:89:3
> #11 0x7f4242427400 llvm::MemoryBuffer::getMemBuffer(llvm::StringRef, 
> llvm::StringRef, bool) llvm/src/llvm/lib/Support/MemoryBuffer.cpp:115:7
> #12 0x7f424249ab20 llvm::vfs::detail::(anonymous 
> namespace)::InMemoryFileAdaptor::getBuffer(llvm::Twine const&, long, bool, 
> bool) llvm/src/llvm/lib/Support/VirtualFileSystem.cpp:615:12
> #13 0x7f4242b0ecf1 clang::FileManager::getBufferForFile(clang::FileEntry 
> const*, bool, bool) llvm/src/clang/lib/Basic/FileManager.cpp:474:5
> #14 0x7f4242b52013 
> clang::SrcMgr::ContentCache::getBuffer(clang::DiagnosticsEngine&, 
> clang::FileManager&, clang::SourceLocation, bool*) const 
> llvm/src/clang/lib/Basic/SourceManager.cpp:172:8
> #15 0x7f4242fe64c0 clang::SourceManager::getBuffer(clang::FileID, 
> clang::SourceLocation, bool*) const 
> llvm/src/clang/include/clang/Basic/SourceManager.h:976:5
> #16 0x7f4242fe2425 clang::Preprocessor::EnterSourceFile(clang::FileID, 
> clang::DirectoryLookup const*, clang::SourceLocation) 
> llvm/src/clang/lib/Lex/PPLexerChange.cpp:77:29
> #17 0x7f424301c104 clang::Preprocessor::EnterMainSourceFile() 
> llvm/src/clang/lib/Lex/Preprocessor.cpp:547:5
> #18 0x7f423d4a23fe clang::ParseAST(clang::Sema&, bool, bool) 
> llvm/src/clang/lib/Parse/ParseAST.cpp:144:33
> #19 0x7f42466df752 clang::ASTFrontendAction::ExecuteAction() 
> llvm/src/clang/lib/Frontend/FrontendAction.cpp:1059:1
> #20 0x7f42466df118 clang::FrontendAction::Execute() 
> llvm/src/clang/lib/Frontend/FrontendAction.cpp:954:7
> #21 0x7f4246655ae4 
> clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
> llvm/src/clang/lib/Frontend/CompilerInstance.cpp:984:23
> #22 0x7f42472a622a 
> clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr,
>  clang::FileManager*, std::shared_ptr, 
> clang::DiagnosticConsumer*) llvm/src/clang/lib/Tooling/Tooling.cpp:410:14
> #23 0x7f42472a60d4 clang::tooling::ToolInvocation::runInvocation(char 
> const*, clang::driver::Compilation*, 
> std::shared_ptr, 
> std::shared_ptr) 
> llvm/src/clang/lib/Tooling/Tooling.cpp:385:3
> #24 0x7f42472a5015 clang::tooling::ToolInvocation::run() 
> llvm/src/clang/lib/Tooling/Tooling.cpp:370:3
> #25 0x00bc916b clang::clangd::(anonymous 
> namespace)::SymbolCollectorTest::runSymbolCollector(llvm::StringRef, 
> llvm::StringRef, std::vector std::char_traits, std::allocator >, 
> std::allocator, 
> std::allocator > > > const&) 
> llvm/src/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:283:15
> #26 0x00bda339 clang::clangd::(anonymous 
> namespace)::SymbolCollectorTest_Refs_Test::TestBody() 
> llvm/src/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:729:3
> ```
ah makes sense. looks like we are calling `MemoryBuffer:getMemBuffer`, which 
would make the buffers unusable after `runSymbolCollector` exits. I must've 
been lucky enough to not overwrite the stack.

could

[PATCH] D86020: [MemCpyOptimizer] Optimize passing byref function arguments down the stack

2020-08-17 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll:44
+}
+
+declare void @leaf(%struct.S* byref(%struct.S) align 4)

I think this is missing an alignment check. Can you add a test where the callee 
requires a higher parameter alignment than the caller?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86020/new/

https://reviews.llvm.org/D86020

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


[PATCH] D86091: [cmake] Fix build of attribute plugin example on Windows

2020-08-17 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added a reviewer: john.brawn.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
krisb requested review of this revision.

Seems '${cmake_2_8_12_PRIVATE}' was removed long time ago, so it should
be just PRIVATE keyword here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86091

Files:
  clang/examples/Attribute/CMakeLists.txt


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ clang/examples/Attribute/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
-  target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE}
+  target_link_libraries(Attribute PRIVATE
 clangAST
 clangBasic
 clangFrontend


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ clang/examples/Attribute/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
-  target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE}
+  target_link_libraries(Attribute PRIVATE
 clangAST
 clangBasic
 clangFrontend
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84988: WIP [Coverage] Add empty line regions to SkippedRegions

2020-08-17 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Hi @zequanwu, are you looking for review for this patch? I wasn't sure because 
of the WIP label.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84988/new/

https://reviews.llvm.org/D84988

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


[PATCH] D85977: [release][docs] Update contributions to LLVM 11 for SVE.

2020-08-17 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 286057.
fpetrogalli marked 3 inline comments as done.
fpetrogalli added a comment.

Thank you for the review @david-arm.

I have addressed all your comments, and I also have removed the
additional unit tests that was checking that the example in the docs
was working. I have decided to do so because I don't want to deal with
the intricacies of making sure that the use of `#include `
when running the test on x86 hardware is correctly handled (for
reference, see failure at
https://reviews.llvm.org/harbormaster/unit/view/160088/). All the code
generation needed by the example in the release note is unit-tested in
the SVE ACLE tests, so the unit test for the example is not really
necessary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85977/new/

https://reviews.llvm.org/D85977

Files:
  llvm/docs/ReleaseNotes.rst


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -66,7 +66,9 @@
   added to describe the mapping between scalar functions and vector
   functions, to enable vectorization of call sites. The information
   provided by the attribute is interfaced via the API provided by the
-  ``VFDatabase`` class.
+  ``VFDatabase`` class. When scanning through the set of vector
+  functions associated with a scalar call, the loop vectorizer now
+  relies on ``VFDatabase``, instead of ``TargetLibraryInfo``.
 
 * `dereferenceable` attributes and metadata on pointers no longer imply
   anything about the alignment of the pointer in question. Previously, some
@@ -78,6 +80,17 @@
   information. This information is used to represent Fortran modules debug
   info at IR level.
 
+* LLVM IR now supports two distinct ``llvm::FixedVectorType`` and
+  ``llvm::ScalableVectorType`` vector types, both derived from the
+  base class ``llvm::VectorType``. A number of algorithms dealing with
+  IR vector types have been updated to make sure they work for both
+  scalable and fixed vector types. Where possible, the code has been
+  made generic to cover both cases using the base class. Specifically,
+  places that were using the type ``unsigned`` to count the number of
+  lanes of a vector are now using ``llvm::ElementCount``. In places
+  where ``uint64_t`` was used to denote the size in bits of a IR type
+  we have partially migrated the codebase to using ``llvm::TypeSize``.
+
 Changes to building LLVM
 
 
@@ -101,6 +114,55 @@
   default may wish to specify ``-fno-omit-frame-pointer`` to get the old
   behavior. This improves compatibility with GCC.
 
+* Clang adds support for the following macros that enable the
+  C-intrinsics from the `Arm C language extensions for SVE
+  `_ (version
+  ``00bet5``, see section 2.1 for the list of intrinsics associated to
+  each macro):
+
+
+  =  =
+  Preprocessor macro Target feature
+  =  =
+  ``__ARM_FEATURE_SVE``  ``+sve``
+  ``__ARM_FEATURE_SVE_BF16`` ``+sve+bf16``
+  ``__ARM_FEATURE_SVE_MATMUL_FP32``  ``+sve+f32mm``
+  ``__ARM_FEATURE_SVE_MATMUL_FP64``  ``+sve+f64mm``
+  ``__ARM_FEATURE_SVE_MATMUL_INT8``  ``+sve+i8mm``
+  ``__ARM_FEATURE_SVE2`` ``+sve2``
+  ``__ARM_FEATURE_SVE2_AES`` ``+sve2-aes``
+  ``__ARM_FEATURE_SVE2_BITPERM`` ``+sve2-bitperm``
+  ``__ARM_FEATURE_SVE2_SHA3````+sve2-sha3``
+  ``__ARM_FEATURE_SVE2_SM4`` ``+sve2-sm4``
+  =  =
+
+  The macros enable users to write C/C++ `Vector Length Agnostic
+  (VLA)` loops, that can be executed on any CPU that implements the
+  underlying instructions supported by the C intrinsics, independently
+  of the hardware vector register size.
+
+  For example, the ``__ARM_FEATURE_SVE`` macro is enabled when
+  targeting AArch64 code generation by setting ``-march=armv8-a+sve``
+  on the command line.
+
+  .. code-block:: c
+ :caption: Example of VLA addition of two arrays with SVE ACLE.
+
+ // Compile with:
+ // `clang++ -march=armv8a+sve ...` (for c++)
+ // `clang -stc=c11 -march=armv8a+sve ...` (for c)
+ #include 
+
+ void VLA_add_arrays(double *x, double *y, double *out, unsigned N) {
+   for (unsigned i = 0; i < N; i += svcntd()) {
+ svbool_t Pg = svwhilelt_b64(i, N);
+ svfloat64_t vx = svld1(Pg, &x[i]);
+ svfloat64_t vy = svld1(Pg, &y[i]);
+ svfloat64_t vout = svadd_x(Pg, vx, vy);
+ svst1(Pg, &out[i], vout);
+   }
+ }
+
 Changes to the MIPS Target
 --
 


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm

[clang] a397319 - [test] Fix thinlto-debug-pm.c in preparation for -enable-npm-optnone

2020-08-17 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2020-08-17T10:06:15-07:00
New Revision: a3973195095ed918915213341c132b41fb269f4e

URL: 
https://github.com/llvm/llvm-project/commit/a3973195095ed918915213341c132b41fb269f4e
DIFF: 
https://github.com/llvm/llvm-project/commit/a3973195095ed918915213341c132b41fb269f4e.diff

LOG: [test] Fix thinlto-debug-pm.c in preparation for -enable-npm-optnone

This fails due to the clang invocation running at -O0, producing an optnone 
function.
Then even with -O2 in the later invocations, LoopVectorizePass doesn't run on 
the optnone function.
So split this into an -O0 run and an -O2 run.

Reviewed By: asbirlea

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-debug-pm.c

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-debug-pm.c 
b/clang/test/CodeGen/thinlto-debug-pm.c
index 175ee90813a2d..4175c4ef37dba 100644
--- a/clang/test/CodeGen/thinlto-debug-pm.c
+++ b/clang/test/CodeGen/thinlto-debug-pm.c
@@ -1,16 +1,22 @@
 // Test to ensure the opt level is passed down to the ThinLTO backend.
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -o %t.o -flto=thin -fexperimental-new-pass-manager -triple 
x86_64-unknown-linux-gnu -emit-llvm-bc %s
+
+// RUN: %clang_cc1 -O2 -o %t.o -flto=thin -fexperimental-new-pass-manager 
-triple x86_64-unknown-linux-gnu -emit-llvm-bc %s
 // RUN: llvm-lto -thinlto -o %t %t.o
 
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm 
-debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O2-OLDPM
+// O2-OLDPM: Loop Vectorization
+
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager 
-fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O2-NEWPM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager 
-fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O0-NEWPM
 // O2-NEWPM: Running pass: LoopVectorizePass
+
+// RUN: %clang_cc1 -O0 -o %t.o -flto=thin -fexperimental-new-pass-manager 
-triple x86_64-unknown-linux-gnu -emit-llvm-bc %s
+// RUN: llvm-lto -thinlto -o %t %t.o
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager 
-fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O0-NEWPM
 // O0-NEWPM-NOT: Running pass: LoopVectorizePass
 
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm 
-debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O2-OLDPM
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm 
-debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O0-OLDPM
-// O2-OLDPM: Loop Vectorization
 // O0-OLDPM-NOT: Loop Vectorization
 
 void foo() {



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


[clang] b0ceff9 - [test] Fix aggregate-assign-call.c in preparation for -enable-npm-optnone

2020-08-17 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2020-08-17T10:06:40-07:00
New Revision: b0ceff94d66372fd88dcf924e1c6751ce5ab5ee4

URL: 
https://github.com/llvm/llvm-project/commit/b0ceff94d66372fd88dcf924e1c6751ce5ab5ee4
DIFF: 
https://github.com/llvm/llvm-project/commit/b0ceff94d66372fd88dcf924e1c6751ce5ab5ee4.diff

LOG: [test] Fix aggregate-assign-call.c in preparation for -enable-npm-optnone

Pin the test to use -enable-npm-optnone.
Before, optnone wasn't implemented under NPM, so the LPM and NPM runs produced 
different IR. Now with -enable-npm-optnone, that is no longer necessary.

Reviewed By: ychen

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

Added: 


Modified: 
clang/test/CodeGen/aggregate-assign-call.c

Removed: 




diff  --git a/clang/test/CodeGen/aggregate-assign-call.c 
b/clang/test/CodeGen/aggregate-assign-call.c
index 9616e6d22562f..a6a253708445d 100644
--- a/clang/test/CodeGen/aggregate-assign-call.c
+++ b/clang/test/CodeGen/aggregate-assign-call.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 
-fno-experimental-new-pass-manager -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1,O1-LEGACY
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 
-fexperimental-new-pass-manager -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1,O1-NEWPM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O0 -S -emit-llvm -o - %s 
| FileCheck %s --check-prefix=O0
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -mllvm -enable-npm-optnone 
-triple x86_64-unknown-linux-gnu -O1 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple 
x86_64-unknown-linux-gnu -O1 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -mllvm -enable-npm-optnone 
-triple x86_64-unknown-linux-gnu -O0 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=O0
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple 
x86_64-unknown-linux-gnu -O0 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=O0
 //
 // Ensure that we place appropriate lifetime markers around indirectly returned
 // temporaries, and that the lifetime.ends appear in a timely manner.
@@ -54,29 +55,21 @@ struct S baz(int i, volatile int *j) {
 
   do {
 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* nonnull 
%[[P]])
+// O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
 //
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: %[[TMP3:.*]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
-// O1-NEWPM: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* nonnull 
%[[P]])
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
 //
-// O1-LEGACY: call void @foo_int(%struct.S* sret align 4 %[[TMP1_ALLOCA]],
-// O1-NEWPM: call void @foo_int(%struct.S* nonnull sret align 4 
%[[TMP1_ALLOCA]],
+// O1: call void @foo_int(%struct.S* sret align 4 %[[TMP1_ALLOCA]],
 // O1: call void @llvm.memcpy
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* nonnull 
%[[P]])
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* nonnull 
%[[TMP3]])
-// O1-LEGACY: call void @foo_int(%struct.S* sret align 4 %[[TMP2_ALLOCA]],
-// O1-NEWPM: call void @foo_int(%struct.S* nonnull sret align 4 
%[[TMP2_ALLOCA]],
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
+// O1: call void @foo_int(%struct.S* sret align 4 %[[TMP2_ALLOCA]],
 // O1: call void @llvm.memcpy
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* nonnull 
%[[TMP3]])
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
 r = foo_int(({
   if (*j)
 break;



___
cfe-commits mailing list
cfe-commits@l

[PATCH] D86011: [test] Fix thinlto-debug-pm.c in preparation for -enable-npm-optnone

2020-08-17 Thread Arthur Eubanks via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa3973195095e: [test] Fix thinlto-debug-pm.c in preparation 
for -enable-npm-optnone (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86011/new/

https://reviews.llvm.org/D86011

Files:
  clang/test/CodeGen/thinlto-debug-pm.c


Index: clang/test/CodeGen/thinlto-debug-pm.c
===
--- clang/test/CodeGen/thinlto-debug-pm.c
+++ clang/test/CodeGen/thinlto-debug-pm.c
@@ -1,16 +1,22 @@
 // Test to ensure the opt level is passed down to the ThinLTO backend.
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -o %t.o -flto=thin -fexperimental-new-pass-manager -triple 
x86_64-unknown-linux-gnu -emit-llvm-bc %s
+
+// RUN: %clang_cc1 -O2 -o %t.o -flto=thin -fexperimental-new-pass-manager 
-triple x86_64-unknown-linux-gnu -emit-llvm-bc %s
 // RUN: llvm-lto -thinlto -o %t %t.o
 
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm 
-debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O2-OLDPM
+// O2-OLDPM: Loop Vectorization
+
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager 
-fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O2-NEWPM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager 
-fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O0-NEWPM
 // O2-NEWPM: Running pass: LoopVectorizePass
+
+// RUN: %clang_cc1 -O0 -o %t.o -flto=thin -fexperimental-new-pass-manager 
-triple x86_64-unknown-linux-gnu -emit-llvm-bc %s
+// RUN: llvm-lto -thinlto -o %t %t.o
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager 
-fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O0-NEWPM
 // O0-NEWPM-NOT: Running pass: LoopVectorizePass
 
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm 
-debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O2-OLDPM
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x 
ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm 
-debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O0-OLDPM
-// O2-OLDPM: Loop Vectorization
 // O0-OLDPM-NOT: Loop Vectorization
 
 void foo() {


Index: clang/test/CodeGen/thinlto-debug-pm.c
===
--- clang/test/CodeGen/thinlto-debug-pm.c
+++ clang/test/CodeGen/thinlto-debug-pm.c
@@ -1,16 +1,22 @@
 // Test to ensure the opt level is passed down to the ThinLTO backend.
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -o %t.o -flto=thin -fexperimental-new-pass-manager -triple x86_64-unknown-linux-gnu -emit-llvm-bc %s
+
+// RUN: %clang_cc1 -O2 -o %t.o -flto=thin -fexperimental-new-pass-manager -triple x86_64-unknown-linux-gnu -emit-llvm-bc %s
 // RUN: llvm-lto -thinlto -o %t %t.o
 
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm -debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O2-OLDPM
+// O2-OLDPM: Loop Vectorization
+
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager -fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O2-NEWPM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager -fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O0-NEWPM
 // O2-NEWPM: Running pass: LoopVectorizePass
+
+// RUN: %clang_cc1 -O0 -o %t.o -flto=thin -fexperimental-new-pass-manager -triple x86_64-unknown-linux-gnu -emit-llvm-bc %s
+// RUN: llvm-lto -thinlto -o %t %t.o
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x ir %t.o -fthinlto-index=%t.thinlto.bc -fdebug-pass-manager -fexperimental-new-pass-manager 2>&1 | FileCheck %s --check-prefix=O0-NEWPM
 // O0-NEWPM-NOT: Running pass: LoopVectorizePass
 
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O2 -o %t2.o -x ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm -debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O2-OLDPM
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x ir %t.o -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm -debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O0-OLDPM
-// O2-OLDPM: Loop Vectorization
 // O0-OLDPM-NOT: 

[PATCH] D86008: [test] Fix aggregate-assign-call.c in preparation for -enable-npm-optnone

2020-08-17 Thread Arthur Eubanks via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0ceff94d663: [test] Fix aggregate-assign-call.c in 
preparation for -enable-npm-optnone (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86008/new/

https://reviews.llvm.org/D86008

Files:
  clang/test/CodeGen/aggregate-assign-call.c


Index: clang/test/CodeGen/aggregate-assign-call.c
===
--- clang/test/CodeGen/aggregate-assign-call.c
+++ clang/test/CodeGen/aggregate-assign-call.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 
-fno-experimental-new-pass-manager -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1,O1-LEGACY
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 
-fexperimental-new-pass-manager -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1,O1-NEWPM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O0 -S -emit-llvm -o - %s 
| FileCheck %s --check-prefix=O0
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -mllvm -enable-npm-optnone 
-triple x86_64-unknown-linux-gnu -O1 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple 
x86_64-unknown-linux-gnu -O1 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=O1
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -mllvm -enable-npm-optnone 
-triple x86_64-unknown-linux-gnu -O0 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=O0
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple 
x86_64-unknown-linux-gnu -O0 -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=O0
 //
 // Ensure that we place appropriate lifetime markers around indirectly returned
 // temporaries, and that the lifetime.ends appear in a timely manner.
@@ -54,29 +55,21 @@
 
   do {
 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* nonnull 
%[[P]])
+// O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
 //
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: %[[TMP3:.*]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
-// O1-NEWPM: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* nonnull 
%[[P]])
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
 //
-// O1-LEGACY: call void @foo_int(%struct.S* sret align 4 %[[TMP1_ALLOCA]],
-// O1-NEWPM: call void @foo_int(%struct.S* nonnull sret align 4 
%[[TMP1_ALLOCA]],
+// O1: call void @foo_int(%struct.S* sret align 4 %[[TMP1_ALLOCA]],
 // O1: call void @llvm.memcpy
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* nonnull 
%[[P]])
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* nonnull 
%[[TMP3]])
-// O1-LEGACY: call void @foo_int(%struct.S* sret align 4 %[[TMP2_ALLOCA]],
-// O1-NEWPM: call void @foo_int(%struct.S* nonnull sret align 4 
%[[TMP2_ALLOCA]],
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
+// O1: call void @foo_int(%struct.S* sret align 4 %[[TMP2_ALLOCA]],
 // O1: call void @llvm.memcpy
-// O1-LEGACY: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
-// O1-LEGACY: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
-// O1-NEWPM: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* nonnull 
%[[TMP3]])
+// O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
+// O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
 r = foo_int(({
   if (*j)
 break;


Index: clang/test/CodeGen/aggregate-assign-call.c
===
--- clang/test/CodeGen/aggregate-assign-call.c
+++ clang/test/CodeGen/aggregate-assign-call.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 -fno-experimental-new-pass-manager -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=O1,O1-LEGACY
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 -fexperimental-new-pass-manager -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=O1,O1-NEWPM
-// RUN: %clang_cc1 -triple x86_64-unknown-linu

[PATCH] D84988: [Coverage] Add empty line regions to SkippedRegions

2020-08-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D84988#2221805 , @vsk wrote:

> Hi @zequanwu, are you looking for review for this patch? I wasn't sure 
> because of the WIP label.

Yes, I removed the label.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84988/new/

https://reviews.llvm.org/D84988

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


[PATCH] D85796: [Analysis] Bug fix for exploded graph branching in evalCall for constructor

2020-08-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thanks!~




Comment at: clang/test/Analysis/smart-ptr.cpp:44
   std::unique_ptr P(new A());
+  clang_analyzer_numTimesReached(); // expected-warning {{1}}
   P->foo(); // No warning.

I'm sooo fond of these sanity checks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85796/new/

https://reviews.llvm.org/D85796

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


[PATCH] D82756: Port some floating point options to new option marshalling infrastructure

2020-08-17 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82756/new/

https://reviews.llvm.org/D82756

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


[PATCH] D86020: [MemCpyOptimizer] Optimize passing byref function arguments down the stack

2020-08-17 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Sorry, I tried to say thiis more succinctly before, but what exactly is the 
semantic property of `byref` that allows this optimization?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86020/new/

https://reviews.llvm.org/D86020

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


[PATCH] D84988: [Coverage] Add empty line regions to SkippedRegions

2020-08-17 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: clang/include/clang/Lex/Lexer.h:131
 
+  const char *NewLinePtr;
+

Could you leave a comment describing what this is?



Comment at: clang/include/clang/Lex/Preprocessor.h:960
+  void setParsingFunctionBody(bool parsing) { ParsingFunctionBody = parsing; }
+  bool isParsingFunctionBody() { return ParsingFunctionBody; }
+

const



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:326
+if (PrevTokLoc.isValid()) {
+  unsigned PrevTokLine = SM.getSpellingLineNumber(PrevTokLoc);
+  if (SR.LineStart == PrevTokLine) {

It looks like this assumes there is some guarantee that the skipped range (as 
given by SR) is in the same file as {Prev,Next}TokLoc. If that's correct, can 
we go ahead and `assert` that?



Comment at: clang/lib/Lex/Lexer.cpp:3290
   IsAtPhysicalStartOfLine = true;
+  NewLinePtr = CurPtr - 1;
 

Is NewLinePtr supposed to point to the start of the most recent newline 
sequence? For "\r\n", is it supposed to be "\r\n" or 
"\r\n"?



Comment at: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp:483
   bool GapRegion = CR.value().Kind == CounterMappingRegion::GapRegion;
 
   if (CR.index() + 1 == Regions.size() ||

Why is this deletion necessary? Do we need to introduce 0-length regions which 
alter the count? An example would help.



Comment at: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp:580
   const auto &R = Segments[I];
-  if (!(L.Line < R.Line) && !(L.Line == R.Line && L.Col < R.Col)) {
+  if (!(L.Line <= R.Line) && !(L.Line == R.Line && L.Col <= R.Col)) {
 LLVM_DEBUG(dbgs() << " ! Segment " << L.Line << ":" << L.Col

I don't think this relaxation is correct, since it permits duplicate segments. 
This is confusing for reporting tools because it's not possible to work out 
which segment applies at a given source location.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84988/new/

https://reviews.llvm.org/D84988

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


[PATCH] D80833: [CodeView] Add full repro to LF_BUILDINFO record

2020-08-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

This seems to be breaking determinism on Windows builds, see 
https://crbug.com/1117026. Can this be reverted and fixed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80833/new/

https://reviews.llvm.org/D80833

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


[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-08-17 Thread Tim Keith via Phabricator via cfe-commits
tskeith requested changes to this revision.
tskeith added inline comments.
This revision now requires changes to proceed.



Comment at: flang/include/flang/Frontend/CompilerInstance.h:11
+
+#include "flang/Frontend/CompilerInvocation.h"
+

Why is this called "Frontend" rather than "Driver"?



Comment at: flang/include/flang/Frontend/CompilerInstance.h:16
+
+namespace flang {
+

Nothing else is in namespace `flang`. `Fortran::frontend` would be more 
consistent.



Comment at: flang/include/flang/Frontend/CompilerInstance.h:21
+  /// The options used in this compiler instance.
+  std::shared_ptr Invocation;
+

Data members, local variables, etc. should start with lower case.
Non-public data members should end with underscore.

Please follow the style in flang/documentation/C++style.md.



Comment at: flang/include/flang/Frontend/FrontendOptions.h:31
+  Language Lang;
+  unsigned Fmt : 3;
+  unsigned Preprocessed : 1;

Why isn't the type `Format`?



Comment at: flang/include/flang/Frontend/FrontendOptions.h:32
+  unsigned Fmt : 3;
+  unsigned Preprocessed : 1;
+

Why isn't the type `bool`?



Comment at: flang/include/flang/Frontend/FrontendOptions.h:65
+  /// Show the -version text.
+  unsigned ShowVersion : 1;
+

Why aren't the types `bool`?



Comment at: flang/include/flang/FrontendTool/Utils.h:18
+
+#include 
+

Is this needed?



Comment at: flang/lib/Frontend/CompilerInstance.cpp:39
+  } else
+Diags->setClient(new clang::TextDiagnosticPrinter(llvm::errs(), Opts));
+

The "then" and "else" statements should have braces around them.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:46
+  InputKind DashX(Language::Unknown);
+  return DashX;
+}

Why not `return InputKind{Language::Unknown};`?



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:91
+  InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags);
+  (void)DashX;
+

What is the purpose of `DashX` here?



Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:20
+
+using namespace flang;
+namespace flang {

What is this for?



Comment at: flang/tools/flang-driver/driver.cpp:30
+extern int fc1_main(
+llvm::ArrayRef Argv, const char *Argv0, void *MainAddr);
+

Why isn't this declared in a header?



Comment at: flang/tools/flang-driver/fc1_main.cpp:32
+int fc1_main(
+llvm::ArrayRef Argv, const char *Argv0, void *MainAddr) {
+

MainAddr isn't used.



Comment at: flang/tools/flang-driver/fc1_main.cpp:54
+  // Execute the frontend actions.
+  { Success = ExecuteCompilerInvocation(Flang.get()); }
+

Why is this statement in a block? Is the result of CreateFromArgs supposed to 
affect the return value of this function?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86089/new/

https://reviews.llvm.org/D86089

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Preprocessor/init.c:1041
 //
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
S390X-ZOS %s
+// RUN: %clang_cc1 -x c -E -dM -ffreestanding -triple=s390x-none-zos 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
S390X-ZOS -check-prefix S390X-ZOS-C %s

The file has been split. You'll want to add new tests to `init-zos.c` or the 
like.

Not sure it is important to run so many invocations of clang_cc1. Can you pick 
some essential ones? The many invocations make the test slow.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85324/new/

https://reviews.llvm.org/D85324

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


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-17 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 286092.
abhina.sreeskantharajan added a comment.

Thanks MaskRay. I moved the zos testcase to a new file called init-zos.c 
instead and reduced the number of RUN commands.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85324/new/

https://reviews.llvm.org/D85324

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init-zos.c

Index: clang/test/Preprocessor/init-zos.c
===
--- /dev/null
+++ clang/test/Preprocessor/init-zos.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
+// RUN: %clang_cc1 -x c -std=c99 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-C99 %s
+// RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-CXX %s
+//
+// S390X-ZOS-CXX:#define _EXT 1
+// S390X-ZOS-C99:#define _ISOC99_SOURCE 1
+// S390X-ZOS:#define _LONG_LONG 1
+// S390X-ZOS-CXX:#define _MI_BUILTIN 1
+// S390X-ZOS:#define _OPEN_DEFAULT 1
+// S390X-ZOS:#define _UNIX03_WITHDRAWN 1
+// S390X-ZOS-CXX:#define _XOPEN_SOURCE 600
+// S390X-ZOS:#define __370__ 1
+// S390X-ZOS:#define __64BIT__ 1
+// S390X-ZOS:#define __BFP__ 1
+// S390X-ZOS:#define __BOOL__ 1
+// S390X-ZOS-CXX:#define __DLL__ 1
+// S390X-ZOS:#define __LONGNAME__ 1
+// S390X-ZOS:#define __MVS__ 1
+// S390X-ZOS:#define __THW_370__ 1
+// S390X-ZOS:#define __THW_BIG_ENDIAN__ 1
+// S390X-ZOS:#define __TOS_390__ 1
+// S390X-ZOS:#define __TOS_MVS__ 1
+// S390X-ZOS:#define __XPLINK__ 1
+// S390X-ZOS-CXX:#define __wchar_t 1
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -727,6 +727,57 @@
   bool defaultsToAIXPowerAlignment() const override { return true; }
 };
 
+// z/OS target
+template 
+class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+MacroBuilder &Builder) const override {
+// FIXME: LONG_LONG should not be defined under -std=c89
+Builder.defineMacro("_LONG_LONG");
+Builder.defineMacro("_OPEN_DEFAULT");
+// _UNIX03_WITHDRAWN is required to build libcxx.
+Builder.defineMacro("_UNIX03_WITHDRAWN");
+Builder.defineMacro("__370__");
+Builder.defineMacro("__BFP__");
+Builder.defineMacro("__BOOL__");
+Builder.defineMacro("__LONGNAME__");
+Builder.defineMacro("__MVS__");
+Builder.defineMacro("__THW_370__");
+Builder.defineMacro("__THW_BIG_ENDIAN__");
+Builder.defineMacro("__TOS_390__");
+Builder.defineMacro("__TOS_MVS__");
+Builder.defineMacro("__XPLINK__");
+
+if (this->PointerWidth == 64)
+  Builder.defineMacro("__64BIT__");
+
+if (Opts.C99)
+  Builder.defineMacro("_ISOC99_SOURCE");
+
+if (Opts.CPlusPlus) {
+  Builder.defineMacro("__DLL__");
+  // XOPEN_SOURCE=600 is required to build libcxx.
+  Builder.defineMacro("_XOPEN_SOURCE", "600");
+}
+
+if (Opts.GNUMode) {
+  Builder.defineMacro("_MI_BUILTIN");
+  Builder.defineMacro("_EXT");
+}
+
+if (Opts.CPlusPlus && Opts.WChar) {
+  // Macro __wchar_t is defined so that the wchar_t data
+  // type is not declared as a typedef in system headers.
+  Builder.defineMacro("__wchar_t");
+}
+  }
+
+public:
+  ZOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {}
+};
+
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder);
 
Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -450,6 +450,8 @@
 switch (os) {
 case llvm::Triple::Linux:
   return new LinuxTargetInfo(Triple, Opts);
+case llvm::Triple::ZOS:
+  return new ZOSTargetInfo(Triple, Opts);
 default:
   return new SystemZTargetInfo(Triple, Opts);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85324: [SystemZ][z/OS] Add z/OS Target and define macros

2020-08-17 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan marked an inline comment as done.
abhina.sreeskantharajan added inline comments.



Comment at: clang/test/Preprocessor/init.c:1041
 //
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
S390X-ZOS %s
+// RUN: %clang_cc1 -x c -E -dM -ffreestanding -triple=s390x-none-zos 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
S390X-ZOS -check-prefix S390X-ZOS-C %s

MaskRay wrote:
> The file has been split. You'll want to add new tests to `init-zos.c` or the 
> like.
> 
> Not sure it is important to run so many invocations of clang_cc1. Can you 
> pick some essential ones? The many invocations make the test slow.
Thanks for the suggestion. I created a new file and reduced the number of 
invocations.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85324/new/

https://reviews.llvm.org/D85324

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


[PATCH] D80833: [CodeView] Add full repro to LF_BUILDINFO record

2020-08-17 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

In D80833#2221866 , @aeubanks wrote:

> This seems to be breaking determinism on Windows builds, see 
> https://crbug.com/1117026. Can this be reverted and fixed?

Will do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80833/new/

https://reviews.llvm.org/D80833

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


[PATCH] D86020: [MemCpyOptimizer] Optimize passing byref function arguments down the stack

2020-08-17 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko updated this revision to Diff 286097.
atrosinenko added a comment.

Add a test for insufficiently aligned source.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86020/new/

https://reviews.llvm.org/D86020

Files:
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/Transforms/Scalar/MemCpyOptimizer.h
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
  llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll

Index: llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll
===
--- /dev/null
+++ llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll
@@ -0,0 +1,68 @@
+; RUN: opt -memcpyopt -dse -S < %s | FileCheck --enable-var-scope %s
+
+%struct.S = type { [4 x i32] }
+
+declare void @llvm.memcpy.p0i8.p0i8.i16(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i16, i1 immarg)
+
+; A caller of this function has to arrange everything for the pointer it passes
+; to be usable with byref attrbiute anyway, so just pass the pointer through.
+define void @function_with_byref_arg(%struct.S* byref(%struct.S) align 4 %0) {
+; CHECK-LABEL: define void @function_with_byref_arg{{.*}}byref(%struct.S){{.*}} {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:call void @leaf
+; CHECK-NEXT:ret void
+; CHECK-NEXT:  }
+entry:
+  %x = alloca %struct.S, align 4
+  %1 = bitcast %struct.S* %x to i8*
+  %2 = bitcast %struct.S* %0 to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 %1, i8* align 4 %2, i16 16, i1 false)
+  call void @leaf(%struct.S* byref(%struct.S) align 4 %x)
+  ret void
+}
+
+; A generic pointer may point to memory being modified by other threads,
+; coroutines, etc. during execution of @leaf().
+define void @function_with_pointer_arg(%struct.S* align 4 %0) {
+; CHECK-LABEL: define void @function_with_pointer_arg
+; CHECK-SAME:(%struct.S* align 4 [[V0:%.+]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[ALLOCA:%.+]] = alloca %struct.S, align 4
+; CHECK-NEXT:[[V1:%.+]] = bitcast %struct.S* [[ALLOCA]] to i8*
+; CHECK-NEXT:[[V2:%.+]] = bitcast %struct.S* [[V0]] to i8*
+; CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 [[V1]], i8* align 4 [[V2]], i16 16, i1 false)
+; CHECK-NEXT:call void @leaf(%struct.S* byref(%struct.S) align 4 [[ALLOCA]])
+; CHECK-NEXT:ret void
+; CHECK-NEXT:  }
+entry:
+  %x = alloca %struct.S, align 4
+  %1 = bitcast %struct.S* %x to i8*
+  %2 = bitcast %struct.S* %0 to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 %1, i8* align 4 %2, i16 16, i1 false)
+  call void @leaf(%struct.S* byref(%struct.S) align 4 %x)
+  ret void
+}
+
+; The case if an available pointer is byref but has weaker alignment is handled
+; identically to @function_with_pointer_arg.
+define void @function_with_byref_arg_2(%struct.S* byref(%struct.S) align 2 %0) {
+; CHECK-LABEL: define void @function_with_byref_arg_2
+; CHECK-SAME:(%struct.S* byref(%struct.S) align 2 [[V0:%.+]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[ALLOCA:%.+]] = alloca %struct.S, align 4
+; CHECK-NEXT:[[V1:%.+]] = bitcast %struct.S* [[ALLOCA]] to i8*
+; CHECK-NEXT:[[V2:%.+]] = bitcast %struct.S* [[V0]] to i8*
+; CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 [[V1]], i8* align 2 [[V2]], i16 16, i1 false)
+; CHECK-NEXT:call void @leaf(%struct.S* byref(%struct.S) align 4 [[ALLOCA]])
+; CHECK-NEXT:ret void
+; CHECK-NEXT:  }
+entry:
+  %x = alloca %struct.S, align 4
+  %1 = bitcast %struct.S* %x to i8*
+  %2 = bitcast %struct.S* %0 to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 %1, i8* align 2 %2, i16 16, i1 false)
+  call void @leaf(%struct.S* byref(%struct.S) align 4 %x)
+  ret void
+}
+
+declare void @leaf(%struct.S* byref(%struct.S) align 4)
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1217,10 +1217,10 @@
   return true;
 }
 
-/// This is called on every byval argument in call sites.
-bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
+/// This is called on every byval/byref argument in call sites.
+bool MemCpyOptPass::processByValOrByRefArgument(CallBase &CB, unsigned ArgNo) {
   const DataLayout &DL = CB.getCaller()->getParent()->getDataLayout();
-  // Find out what feeds this byval argument.
+  // Find out what feeds this byval/byref argument.
   Value *ByValArg = CB.getArgOperand(ArgNo);
   Type *ByValTy = cast(ByValArg->getType())->getElementType();
   uint64_t ByValSize = DL.getTypeAllocSize(ByValTy);
@@ -1238,6 +1238,23 @@
   ByValArg->stripPointerCasts() != MDep->getDest())
 return false;
 
+  // ByRef arguments should be handled with care: they are not implicitly copied
+  // to the calling function's stack frame, so they may be accessible from other
+  // thread

[PATCH] D86020: [MemCpyOptimizer] Optimize passing byref function arguments down the stack

2020-08-17 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko added a comment.

@rjmccall

Maybe I overestimated similarity of `byval` and recently introduced `byref`... 
Looks like some aliasing restrictions are not mentioned in LLVM Language 
Reference . For 
example, the only way for Clang to emit the `byref` attribute to LLVM IR I know 
about is via `ABIArgInfo` with `Kind == IndirectAliased` introduced in D79744: 
clang: Use byref for aggregate kernel arguments 
 - and it has a note that "The object is known 
to not be through any other references for the duration of the call, and the 
callee must not itself modify the object". This seems to be necessary for 
correctness of this transformation. If LLVM Language Reference does not mention 
such restrictions intentionally, then it may be clang that should be 
responsible for such optimizations.




Comment at: llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll:55
+; CHECK-NEXT:[[V2:%.+]] = bitcast %struct.S* [[V0]] to i8*
+; CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 [[V1]], i8* 
align 2 [[V2]], i16 16, i1 false)
+; CHECK-NEXT:call void @leaf(%struct.S* byref(%struct.S) align 4 
[[ALLOCA]])

Interestingly, if I change the alignment of the second argument from 2 back to 
4, then memcpy() is successfully dropped (as if everything has big-enough 
alignment) while it seemingly shouldn't be. Is it just due to the code being 
ill-formed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86020/new/

https://reviews.llvm.org/D86020

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


[PATCH] D86097: [OpenMP][AMDGCN] Generate global variables and attributes for AMDGCN

2020-08-17 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: ABataev, jdoerfert, JonChesterfield.
Herald added subscribers: cfe-commits, guansong, yaxunl, jvesely, jholewinski.
Herald added a project: clang.
saiislam requested review of this revision.
Herald added a subscriber: sstefan1.

Provide support for amdgcn specific global variables and attributes.
Generalize allocation of various common global variables and provide
their specialized implementations for nvptx and amdgcn.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86097

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  clang/test/OpenMP/amdgcn_target_codegen.cpp

Index: clang/test/OpenMP/amdgcn_target_codegen.cpp
===
--- clang/test/OpenMP/amdgcn_target_codegen.cpp
+++ clang/test/OpenMP/amdgcn_target_codegen.cpp
@@ -8,6 +8,22 @@
 
 #define N 1000
 
+// CHECK: @"_openmp_kernel_static_glob_rd$ptr" = weak addrspace(3) externally_initialized global i8* undef
+
+// CHECK: @__omp_offloading_{{.*}}test_amdgcn_target_tid_threadsv_l36_kern_desc = weak constant %struct.__tgt_attribute_struct { i16 2, i16 9, i16 0, i8 1, i8 1, i8 0 }, align 2
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_tid_threadsv_l36_exec_mode = weak constant i8 1
+
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_tid_threads_simdv_l52_kern_desc = weak constant %struct.__tgt_attribute_struct { i16 2, i16 9, i16 0, i8 0, i8 1, i8 0 }, align 2
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_tid_threads_simdv_l52_exec_mode = weak constant i8 0
+
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_attributes_spmdv_l63_wg_size = weak addrspace(1) constant i16 10
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_attributes_spmdv_l63_kern_desc = weak constant %struct.__tgt_attribute_struct { i16 2, i16 9, i16 10, i8 0, i8 1, i8 0 }, align 2
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_attributes_spmdv_l63_exec_mode = weak constant i8 0
+
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_attributes_non_spmdv_l75_wg_size = weak addrspace(1) constant i16 74
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_attributes_non_spmdv_l75_kern_desc = weak constant %struct.__tgt_attribute_struct { i16 2, i16 9, i16 74, i8 1, i8 1, i8 0 }, align 2
+// CHECK : @__omp_offloading_{{.*}}test_amdgcn_target_attributes_non_spmdv_l75_exec_mode = weak constant i8 1
+
 int test_amdgcn_target_tid_threads() {
 // CHECK-LABEL: define weak void @{{.*}}test_amdgcn_target_tid_threads
 
@@ -40,4 +56,40 @@
   return arr[0];
 }
 
+int test_amdgcn_target_attributes_spmd() {
+  int arr[N];
+
+// CHECK: {{.*}}"amdgpu-flat-work-group-size"="10,10"
+#pragma omp target parallel num_threads(10)
+  for (int i = 0; i < N; i++) {
+arr[i] = 1;
+  }
+
+  return arr[0];
+}
+
+int test_amdgcn_target_attributes_non_spmd() {
+  int arr[N];
+
+// CHECK: {{.*}}"amdgpu-flat-work-group-size"="74,74"
+#pragma omp target teams thread_limit(10)
+  for (int i = 0; i < N; i++) {
+arr[i] = 1;
+  }
+
+  return arr[0];
+}
+
+int test_amdgcn_target_attributes_max_work_group_size() {
+  int arr[N];
+
+// CHECK: {{.*}}"amdgpu-flat-work-group-size"="1024,1024"
+#pragma omp target teams thread_limit(1500)
+  for (int i = 0; i < N; i++) {
+arr[i] = 1;
+  }
+
+  return arr[0];
+}
+
 #endif
Index: clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
===
--- clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
+++ clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -35,6 +35,34 @@
 
   /// Get the maximum number of threads in a block of the GPU.
   llvm::Value *getGPUNumThreads(CodeGenFunction &CGF) override;
+
+  /// Allocate global variable for TransferMedium
+  virtual llvm::GlobalVariable *
+  allocateTransferMediumGlobal(CodeGenModule &CGM, llvm::ArrayType *Ty,
+   StringRef Name) override;
+
+  /// Allocate global variable for SharedStaticRD
+  virtual llvm::GlobalVariable *
+  allocateSharedStaticRDGlobal(CodeGenModule &CGM,
+   llvm::Type *LLVMStaticTy) override;
+
+  /// Allocate global variable for KernelStaticGlobalized
+  virtual llvm::GlobalVariable *
+  allocateKernelStaticGlobalized(CodeGenModule &CGM) override;
+
+  /// Emit target specific SPMD kernel
+  virtual void emitSPMDKernelWrapper(const OMPExecutableDirective &D,
+ StringRef ParentName,
+ llvm::Function *&OutlinedFn,
+ llvm::Constant *&OutlinedFnID,
+ bool IsOffloadEntry,
+ const RegionCod

[PATCH] D84375: [git-clang-format] Add --diffstat parameter

2020-08-17 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD added reviewers: MyDeveloperDay, JakeMerdichAMD.
JakeMerdichAMD added a comment.

Reviving this since it looks perfectly fine to me (from my limited commit 
history in git-clang-format :P), is useful, and there's no good reason for it 
to be stalled.

I'll wait a day or two to see if there's any objections, then accept it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84375/new/

https://reviews.llvm.org/D84375

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


[PATCH] D86097: [OpenMP][AMDGCN] Generate global variables and attributes for AMDGCN

2020-08-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:499
+
+  QualType TgtAttributeStructQTy;
   class OffloadEntriesInfoManagerTy {

Cab this type and corresponding functions be made AMDGCN-specific only?



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.cpp:116
+ bool IsGeneric) {
+  if (!CGM.getTriple().isAMDGCN())
+return;

Is this possible?



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.cpp:119
+  int FlatAttr = 0;
+  bool flatAttrEmitted = false;
+  unsigned DefaultWorkGroupSz =

`FlatAttrEmitted`



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.cpp:129
+CGM.getTarget().getGridValue(llvm::omp::GVIDX::GV_Max_WG_Size);
+unsigned compileTimeThreadLimit = 0;
+// Only one of thread_limit or num_threads is used, cant do it for both

`CompileTimeThreadLimit`



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:1390-1392
+  auto *GVMode = new llvm::GlobalVariable(
+  CGM.getModule(), CGM.Int8Ty,
+  /*isConstant=*/true, llvm::GlobalValue::WeakAnyLinkage,

Restore original formatting.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.h:215-243
+  /// Emit outlined function specialized for the Single Program
+  /// Multiple Data programming model for applicable target directives on the
+  /// NVPTX device.
+  /// \param D Directive to emit.
+  /// \param ParentName Name of the function that encloses the target region.
+  /// \param OutlinedFn Outlined function value to be defined by this call.
+  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.

Make them protected, not public if possible. Try the same for other new 
functions.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h:40-65
+  virtual llvm::GlobalVariable *
+  allocateTransferMediumGlobal(CodeGenModule &CGM, llvm::ArrayType *Ty,
+   StringRef Name) override;
+
+  /// Allocate global variable for SharedStaticRD
+  virtual llvm::GlobalVariable *
+  allocateSharedStaticRDGlobal(CodeGenModule &CGM,

No need to add `virtual`, `override` is enough


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86097/new/

https://reviews.llvm.org/D86097

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


[PATCH] D85384: [X86] Add basic support for -mtune command line option in clang

2020-08-17 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85384/new/

https://reviews.llvm.org/D85384

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


[PATCH] D85384: [X86] Add basic support for -mtune command line option in clang

2020-08-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

1 comment, otherwise seems alright to me.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:1752
   StringRef TargetCPU = getTarget().getTargetOpts().CPU;
+  StringRef TuneCPU = getTarget().getTargetOpts().TuneCPU;
   std::vector Features;

Does this lead to a situation in 'attribute-target' where we have a 'tune' 
setting to a processor that is 'before' the 'TargetCPU'?  Should this enforce 
some sort of hierarchy to make sure we only do it if it is 'newer' (read, more 
feature rich) than the target?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85384/new/

https://reviews.llvm.org/D85384

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


[PATCH] D85384: [X86] Add basic support for -mtune command line option in clang

2020-08-17 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:1752
   StringRef TargetCPU = getTarget().getTargetOpts().CPU;
+  StringRef TuneCPU = getTarget().getTargetOpts().TuneCPU;
   std::vector Features;

erichkeane wrote:
> Does this lead to a situation in 'attribute-target' where we have a 'tune' 
> setting to a processor that is 'before' the 'TargetCPU'?  Should this enforce 
> some sort of hierarchy to make sure we only do it if it is 'newer' (read, 
> more feature rich) than the target?
TuneCPU is only supposed to control microarchitectural things like should i 
prefer an "ADD 1" over "INC" instruction. Or should I use more immediate 
controlled shuffles over a single variable controlled shuffle. As such that 
things we get from tune don't have a straightforward relationship with 
architectural features.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85384/new/

https://reviews.llvm.org/D85384

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


[PATCH] D85384: [X86] Add basic support for -mtune command line option in clang

2020-08-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:1752
   StringRef TargetCPU = getTarget().getTargetOpts().CPU;
+  StringRef TuneCPU = getTarget().getTargetOpts().TuneCPU;
   std::vector Features;

craig.topper wrote:
> erichkeane wrote:
> > Does this lead to a situation in 'attribute-target' where we have a 'tune' 
> > setting to a processor that is 'before' the 'TargetCPU'?  Should this 
> > enforce some sort of hierarchy to make sure we only do it if it is 'newer' 
> > (read, more feature rich) than the target?
> TuneCPU is only supposed to control microarchitectural things like should i 
> prefer an "ADD 1" over "INC" instruction. Or should I use more immediate 
> controlled shuffles over a single variable controlled shuffle. As such that 
> things we get from tune don't have a straightforward relationship with 
> architectural features.
My concern is more.  Say:

TargetCPU == "nahalem"

Does it make sense for 
TuneCPU == "pentium"?

It would seem to me that is pretty nonsensical.  I've definitely seen the 
reverse (in within x86_64 at least, where Tune is newer than Target), but 
tuning for an older CPU seems like nonsense.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85384/new/

https://reviews.llvm.org/D85384

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


[PATCH] D85920: [FPEnv][AST] WIP!!! For casts, keep FP options in trailing storage of CastExpr

2020-08-17 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn planned changes to this revision.
kpn added a comment.

It would be better to go with D85960 . I'll 
hedge and keep this open until that one gets pushed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85920/new/

https://reviews.llvm.org/D85920

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


[PATCH] D86100: [Clang][SVE] NFC: Move info about ACLE types into separate function.

2020-08-17 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen created this revision.
sdesmalen added reviewers: c-rhodes, efriedma.
Herald added subscribers: psnobl, tschuett.
Herald added a project: clang.
sdesmalen requested review of this revision.

This function returns a struct `BuiltinVectorTypeInfo` that contains
the builtin vector's element type, element count and number of vectors
(used for vector tuples).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86100

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp

Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -534,99 +534,60 @@
 case BuiltinType::OCLReserveID:
   ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
   break;
-#define GET_SVE_INT_VEC(BITS, ELTS)\
-  llvm::ScalableVectorType::get(   \
-  llvm::IntegerType::get(getLLVMContext(), BITS), ELTS);
 case BuiltinType::SveInt8:
 case BuiltinType::SveUint8:
-  return GET_SVE_INT_VEC(8, 16);
 case BuiltinType::SveInt8x2:
 case BuiltinType::SveUint8x2:
-  return GET_SVE_INT_VEC(8, 32);
 case BuiltinType::SveInt8x3:
 case BuiltinType::SveUint8x3:
-  return GET_SVE_INT_VEC(8, 48);
 case BuiltinType::SveInt8x4:
 case BuiltinType::SveUint8x4:
-  return GET_SVE_INT_VEC(8, 64);
 case BuiltinType::SveInt16:
 case BuiltinType::SveUint16:
-  return GET_SVE_INT_VEC(16, 8);
 case BuiltinType::SveInt16x2:
 case BuiltinType::SveUint16x2:
-  return GET_SVE_INT_VEC(16, 16);
 case BuiltinType::SveInt16x3:
 case BuiltinType::SveUint16x3:
-  return GET_SVE_INT_VEC(16, 24);
 case BuiltinType::SveInt16x4:
 case BuiltinType::SveUint16x4:
-  return GET_SVE_INT_VEC(16, 32);
 case BuiltinType::SveInt32:
 case BuiltinType::SveUint32:
-  return GET_SVE_INT_VEC(32, 4);
 case BuiltinType::SveInt32x2:
 case BuiltinType::SveUint32x2:
-  return GET_SVE_INT_VEC(32, 8);
 case BuiltinType::SveInt32x3:
 case BuiltinType::SveUint32x3:
-  return GET_SVE_INT_VEC(32, 12);
 case BuiltinType::SveInt32x4:
 case BuiltinType::SveUint32x4:
-  return GET_SVE_INT_VEC(32, 16);
 case BuiltinType::SveInt64:
 case BuiltinType::SveUint64:
-  return GET_SVE_INT_VEC(64, 2);
 case BuiltinType::SveInt64x2:
 case BuiltinType::SveUint64x2:
-  return GET_SVE_INT_VEC(64, 4);
 case BuiltinType::SveInt64x3:
 case BuiltinType::SveUint64x3:
-  return GET_SVE_INT_VEC(64, 6);
 case BuiltinType::SveInt64x4:
 case BuiltinType::SveUint64x4:
-  return GET_SVE_INT_VEC(64, 8);
 case BuiltinType::SveBool:
-  return GET_SVE_INT_VEC(1, 16);
-#undef GET_SVE_INT_VEC
-#define GET_SVE_FP_VEC(TY, ISFP16, ELTS)   \
-  llvm::ScalableVectorType::get(   \
-  getTypeForFormat(getLLVMContext(),   \
-   Context.getFloatTypeSemantics(Context.TY),  \
-   /* UseNativeHalf = */ ISFP16),  \
-  ELTS);
 case BuiltinType::SveFloat16:
-  return GET_SVE_FP_VEC(HalfTy, true, 8);
 case BuiltinType::SveFloat16x2:
-  return GET_SVE_FP_VEC(HalfTy, true, 16);
 case BuiltinType::SveFloat16x3:
-  return GET_SVE_FP_VEC(HalfTy, true, 24);
 case BuiltinType::SveFloat16x4:
-  return GET_SVE_FP_VEC(HalfTy, true, 32);
 case BuiltinType::SveFloat32:
-  return GET_SVE_FP_VEC(FloatTy, false, 4);
 case BuiltinType::SveFloat32x2:
-  return GET_SVE_FP_VEC(FloatTy, false, 8);
 case BuiltinType::SveFloat32x3:
-  return GET_SVE_FP_VEC(FloatTy, false, 12);
 case BuiltinType::SveFloat32x4:
-  return GET_SVE_FP_VEC(FloatTy, false, 16);
 case BuiltinType::SveFloat64:
-  return GET_SVE_FP_VEC(DoubleTy, false, 2);
 case BuiltinType::SveFloat64x2:
-  return GET_SVE_FP_VEC(DoubleTy, false, 4);
 case BuiltinType::SveFloat64x3:
-  return GET_SVE_FP_VEC(DoubleTy, false, 6);
 case BuiltinType::SveFloat64x4:
-  return GET_SVE_FP_VEC(DoubleTy, false, 8);
 case BuiltinType::SveBFloat16:
-  return GET_SVE_FP_VEC(BFloat16Ty, false, 8);
 case BuiltinType::SveBFloat16x2:
-  return GET_SVE_FP_VEC(BFloat16Ty, false, 16);
 case BuiltinType::SveBFloat16x3:
-  return GET_SVE_FP_VEC(BFloat16Ty, false, 24);
-case BuiltinType::SveBFloat16x4:
-  return GET_SVE_FP_VEC(BFloat16Ty, false, 32);
-#undef GET_SVE_FP_VEC
+case BuiltinType::SveBFloat16x4: {
+  ASTContext::BuiltinVectorTypeInfo Info =
+  Context.getElementTypeForBuiltinVector(cast(Ty));
+  return llvm::ScalableVectorType::get(ConvertType(Info.ElementType),
+   

[clang] 98e01f5 - Revert "Re-Re-land: [CodeView] Add full repro to LF_BUILDINFO record"

2020-08-17 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-08-17T15:49:18-04:00
New Revision: 98e01f56b0a117f0f32ed2f9b7d61e85830c

URL: 
https://github.com/llvm/llvm-project/commit/98e01f56b0a117f0f32ed2f9b7d61e85830c
DIFF: 
https://github.com/llvm/llvm-project/commit/98e01f56b0a117f0f32ed2f9b7d61e85830c.diff

LOG: Revert "Re-Re-land: [CodeView] Add full repro to LF_BUILDINFO record"

This reverts commit a3036b386383f1c1e9d32c2c8dba995087959da3.

As requested in: https://reviews.llvm.org/D80833#2221866
Bug report: https://crbug.com/1117026

Added: 


Modified: 
clang/cmake/caches/BaremetalARM.cmake
clang/cmake/caches/CrossWinToARMLinux.cmake
clang/cmake/caches/Fuchsia-stage2.cmake
clang/test/CMakeLists.txt
lld/COFF/PDB.cpp
lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
lld/test/COFF/Inputs/pdb_lines_2_relative.yaml
lld/test/COFF/pdb-relative-source-lines.test
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/test/DebugInfo/COFF/build-info.ll
llvm/test/DebugInfo/COFF/global-type-hashes.ll
llvm/test/DebugInfo/COFF/types-basic.ll
llvm/test/DebugInfo/COFF/types-data-members.ll

Removed: 
clang/test/CodeGen/debug-info-codeview-buildinfo.c
lld/test/COFF/pdb-relative-source-lines2.test



diff  --git a/clang/cmake/caches/BaremetalARM.cmake 
b/clang/cmake/caches/BaremetalARM.cmake
index e44355cfcbd7..85295d9db392 100644
--- a/clang/cmake/caches/BaremetalARM.cmake
+++ b/clang/cmake/caches/BaremetalARM.cmake
@@ -31,7 +31,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-dwarfdump
   llvm-nm
   llvm-objdump
-  llvm-pdbutil
   llvm-ranlib
   llvm-readobj
   llvm-size

diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index ccfccce3cb89..9aa0efa8049f 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -137,7 +137,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-lib
   llvm-nm
   llvm-objdump
-  llvm-pdbutil
   llvm-profdata
   llvm-ranlib
   llvm-readobj

diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7cefeedf1bad..e00b64073ca5 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -242,7 +242,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-nm
   llvm-objcopy
   llvm-objdump
-  llvm-pdbutil
   llvm-profdata
   llvm-rc
   llvm-ranlib

diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 3ace9f2521b0..334a90498d0d 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -117,7 +117,6 @@ if( NOT CLANG_BUILT_STANDALONE )
 llvm-nm
 llvm-objcopy
 llvm-objdump
-llvm-pdbutil
 llvm-profdata
 llvm-readelf
 llvm-readobj

diff  --git a/clang/test/CodeGen/debug-info-codeview-buildinfo.c 
b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
deleted file mode 100644
index 93810e829c6d..
--- a/clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ /dev/null
@@ -1,26 +0,0 @@
-// REQUIRES: x86-registered-target
-// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
-// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
-// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj 
-fdebug-compilation-dir=. -- %s
-// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
-
-int main() { return 42; }
-
-// CHECK:   Types (.debug$T)
-// CHECK: 
-// CHECK: 0x[[PWD:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[PWDVAL:.+]]
-// CHECK: 0x[[FILEPATH:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: [[FILEPATHVAL:.+[\\/]debug-info-codeview-buildinfo.c]]
-// CHECK: 0x[[ZIPDB:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String:
-// CHECK: 0x[[TOOL:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[TOOLVAL:.+[\\/]clang.*]]
-// CHECK: 0x[[CMDLINE:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: "-cc1
-// CHECK: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
-// CHECK:  0x[[PWD]]: `[[PWDVAL]]`
-// CHECK:  0x[[TOOL]]: `[[TOOLVAL]]`
-// CHECK:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
-// CHECK:  0x[[ZIPDB]]: ``
-// CHECK:  0x[[CMDLINE]]: `"-cc1
-
-// RELATIVE:   Types (.debug$T)
-// RELATIVE: 
-// RELATIVE: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
-// RELATIVE:  0x{{.+}}: `.`

diff  --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 5738eae7d6c4..49d04add5be0 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -250,72 +250,6 @@ static void addTypeInfo(pdb::TpiStreamBuilder &tpiBuilder,
   });
 }
 
-// LF_BUILDINFO records might contain relative paths, and we want to make them
-// absolute. We do this remapping only after the type records were merged,
-// because the full types graph isn't known during merging. In addition, w

[PATCH] D86101: [AArch64][SVE] Add missing debug info for ACLE types.

2020-08-17 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen created this revision.
sdesmalen added reviewers: rsandifo-arm, efriedma, rjmccall.
Herald added subscribers: llvm-commits, danielkiss, psnobl, hiraditya, 
kristof.beyls, tschuett, aprantl.
Herald added a reviewer: rengolin.
Herald added projects: clang, LLVM.
sdesmalen requested review of this revision.

This patch adds type information for SVE ACLE vector types,
by describing them as vectors, with a lower bound of 0, and
an upper bound described by a DWARF expression using the
AArch64 Vector Granule register (VG), which contains the
runtime multiple of 64bit granules in an SVE vector.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86101

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_debug_vector_types.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_debug_vectorx2_types.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_debug_vectorx3_types.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_debug_vectorx4_types.c
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1398,8 +1398,10 @@
  Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
  "Invalid vector element array, expected one element of type subrange");
   const auto Subrange = cast(Elements[0]);
-  const auto CI = Subrange->getCount().get();
-  const int32_t NumVecElements = CI->getSExtValue();
+  const auto NumVecElements =
+  Subrange->getCount()
+  ? Subrange->getCount().get()->getSExtValue()
+  : 0;
 
   // Ensure we found the element count and that the actual size is wide
   // enough to contain the requested size.
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_debug_vectorx4_types.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_debug_vectorx4_types.c
@@ -0,0 +1,65 @@
+// RUN:  %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -S -O0 -Werror -Wall -emit-llvm -debug-info-kind=limited -dwarf-version=4 -o -  %s | FileCheck %s
+
+#include 
+// CHECK-DAG: name: "__clang_svint8x4_t",{{.*}}, baseType: ![[CT8:[0-9]+]]
+// CHECK-DAG: ![[CT8]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[ELTTY8:[0-9]+]], flags: DIFlagVector, elements: ![[ELTS8x4:[0-9]+]])
+// CHECK-DAG: ![[ELTTY8]] = !DIBasicType(name: "signed char", size: 8, encoding: DW_ATE_signed_char)
+// CHECK-DAG: ![[ELTS8x4]] = !{![[REALELTS8x4:[0-9]+]]}
+// CHECK-DAG: ![[REALELTS8x4]] = !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_constu, 32, DW_OP_bregx, 46, 0, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus))
+svint8x4_t test_svint8x4_t(svint8x4_t op1){ return op1; }
+
+// CHECK-DAG: name: "__clang_svuint8x4_t",{{.*}}, baseType: ![[CT8:[0-9]+]]
+// CHECK-DAG: ![[CT8]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[ELTTY8:[0-9]+]], flags: DIFlagVector, elements: ![[ELTS8x4]])
+// CHECK-DAG: ![[ELTTY8]] = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
+svuint8x4_t test_svuint8x4_t(svuint8x4_t op1){ return op1; }
+
+// CHECK-DAG: name: "__clang_svint16x4_t",{{.*}}, baseType: ![[CT16:[0-9]+]]
+// CHECK-DAG: ![[CT16]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[ELTTY16:[0-9]+]], flags: DIFlagVector, elements: ![[ELTS16x4:[0-9]+]])
+// CHECK-DAG: ![[ELTTY16]] = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
+// CHECK-DAG: ![[ELTS16x4]] = !{![[REALELTS16x4:[0-9]+]]}
+// CHECK-DAG: ![[REALELTS16x4]] = !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_constu, 16, DW_OP_bregx, 46, 0, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus))
+svint16x4_t test_svint16x4_t(svint16x4_t op1){ return op1; }
+
+// CHECK-DAG: name: "__clang_svuint16x4_t",{{.*}}, baseType: ![[CT16:[0-9]+]]
+// CHECK-DAG: ![[CT16]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[ELTTY16:[0-9]+]], flags: DIFlagVector, elements: ![[ELTS16x4]])
+// CHECK-DAG: ![[ELTTY16]] = !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned)
+svuint16x4_t test_svuint16x4_t(svuint16x4_t op1){ return op1; }
+
+// CHECK-DAG: name: "__clang_svint32x4_t",{{.*}}, baseType: ![[CT32:[0-9]+]]
+// CHECK-DAG: ![[CT32]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[ELTTY32:[0-9]+]], flags: DIFlagVector, elements: ![[ELTS32x4:[0-9]+]])
+// CHECK-DAG: ![[ELTTY32]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+// CHECK-DAG: ![[ELTS32x4]] = !{![[REALELTS32x4:[0-9]+]]}
+// CHECK-DAG: ![[REALELTS32x4]] = !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_constu, 8, DW_OP_bregx, 46, 0, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus))
+svint32x4_t test_svint32x4_t(svint32x4_t op1){ return op1; }
+
+// CHECK-DAG: name: "__clang_svuint32x4_t",{{.*}}, baseType: ![[CT32:[0-9]+]]
+//

[PATCH] D84988: [Coverage] Add empty line regions to SkippedRegions

2020-08-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 286123.
zequanwu marked 3 inline comments as done.
zequanwu edited the summary of this revision.
zequanwu added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84988/new/

https://reviews.llvm.org/D84988

Files:
  clang/include/clang/Lex/Lexer.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/lib/CodeGen/CoverageMappingGen.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Parse/ParseStmt.cpp
  compiler-rt/test/profile/coverage_emptylines.cpp
  compiler-rt/test/profile/instrprof-set-file-object-merging.c
  compiler-rt/test/profile/instrprof-set-file-object.c
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Index: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
===
--- llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -481,15 +481,6 @@
 
   bool GapRegion = CR.value().Kind == CounterMappingRegion::GapRegion;
 
-  // Try to emit a segment for the current region.
-  if (CurStartLoc == CR.value().endLoc()) {
-// Avoid making zero-length regions active. If it's the last region,
-// emit a skipped segment. Otherwise use its predecessor's count.
-const bool Skipped = (CR.index() + 1) == Regions.size();
-startSegment(ActiveRegions.empty() ? CR.value() : *ActiveRegions.back(),
- CurStartLoc, !GapRegion, Skipped);
-continue;
-  }
   if (CR.index() + 1 == Regions.size() ||
   CurStartLoc != Regions[CR.index() + 1].startLoc()) {
 // Emit a segment if the next region doesn't start at the same location
@@ -586,7 +577,7 @@
 for (unsigned I = 1, E = Segments.size(); I < E; ++I) {
   const auto &L = Segments[I - 1];
   const auto &R = Segments[I];
-  if (!(L.Line < R.Line) && !(L.Line == R.Line && L.Col < R.Col)) {
+  if (!(L.Line < R.Line) && !(L.Line == R.Line && L.Col <= R.Col)) {
 LLVM_DEBUG(dbgs() << " ! Segment " << L.Line << ":" << L.Col
   << " followed by " << R.Line << ":" << R.Col << "\n");
 assert(false && "Coverage segments not unique or sorted");
Index: compiler-rt/test/profile/instrprof-set-file-object.c
===
--- compiler-rt/test/profile/instrprof-set-file-object.c
+++ compiler-rt/test/profile/instrprof-set-file-object.c
@@ -24,7 +24,7 @@
 // CHECK:   12|  1|int main(int argc, const char *argv[]) {
 // CHECK:   13|  1|  if (argc < 2)
 // CHECK:   14|  0|return 1;
-// CHECK:   15|  1|
+// CHECK:   15|   |
 // CHECK:   16|  1|  FILE *F = fopen(argv[1], "w+b");
 // CHECK:   17|  1|  __llvm_profile_set_file_object(F, 0);
 // CHECK:   18|  1|  return 0;
Index: compiler-rt/test/profile/instrprof-set-file-object-merging.c
===
--- compiler-rt/test/profile/instrprof-set-file-object-merging.c
+++ compiler-rt/test/profile/instrprof-set-file-object-merging.c
@@ -31,13 +31,13 @@
 // CHECK:   14|  2|int main(int argc, const char *argv[]) {
 // CHECK:   15|  2|  if (argc < 2)
 // CHECK:   16|  0|return 1;
-// CHECK:   17|  2|
+// CHECK:   17|   |
 // CHECK:   18|  2|  FILE *F = fopen(argv[1], "r+b");
 // CHECK:   19|  2|  if (!F) {
 // CHECK:   20|   |// File might not exist, try opening with truncation
 // CHECK:   21|  1|F = fopen(argv[1], "w+b");
 // CHECK:   22|  1|  }
 // CHECK:   23|  2|  __llvm_profile_set_file_object(F, 1);
-// CHECK:   24|  2|
+// CHECK:   24|   |
 // CHECK:   25|  2|  return 0;
 // CHECK:   26|  2|}
Index: compiler-rt/test/profile/coverage_emptylines.cpp
===
--- /dev/null
+++ compiler-rt/test/profile/coverage_emptylines.cpp
@@ -0,0 +1,61 @@
+// Remove comments first.
+// RUN: sed 's/[ \t]*\/\/.*//' %s > %t.stripped.cpp
+// RUN: %clangxx_profgen -fcoverage-mapping -o %t %t.stripped.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-cov show %t -instr-profile %t.profdata -path-equivalence=/tmp,%S 2>&1 | FileCheck %s
+
+
+int main() {// CHECK:   [[# @LINE]]| 1|int main() {
+int x = 0;  // CHECK-NEXT:  [[# @LINE]]| 1|
+// CHECK-NEXT:  [[# @LINE]]|  |
+x = 1;  // CHECK-NEXT:  [[# @LINE]]| 1|
+if (x)  // CHECK-NEXT:  [[# @LINE]]| 1|
+// CHECK-NEXT:  [[# @LINE]]|  |
+x   // CHECK-NEXT:  [[# @LINE]]| 1|
+// CHECK-NEXT:  [[# @LINE]]|  |
+

[PATCH] D84988: [Coverage] Add empty line regions to SkippedRegions

2020-08-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:326
+if (PrevTokLoc.isValid()) {
+  unsigned PrevTokLine = SM.getSpellingLineNumber(PrevTokLoc);
+  if (SR.LineStart == PrevTokLine) {

vsk wrote:
> It looks like this assumes there is some guarantee that the skipped range (as 
> given by SR) is in the same file as {Prev,Next}TokLoc. If that's correct, can 
> we go ahead and `assert` that?
Oh, it's a bug in https://reviews.llvm.org/D83592. There is no guarantee that 
they are in the same file. 



Comment at: clang/lib/Lex/Lexer.cpp:3290
   IsAtPhysicalStartOfLine = true;
+  NewLinePtr = CurPtr - 1;
 

vsk wrote:
> Is NewLinePtr supposed to point to the start of the most recent newline 
> sequence? For "\r\n", is it supposed to be "\r\n" or 
> "\r\n"?
I didn't consider this. Updated.
NewLinePtr is supposed to point to the '\n' character. For "\r\n", it will 
point to '\n'.



Comment at: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp:483
   bool GapRegion = CR.value().Kind == CounterMappingRegion::GapRegion;
 
   if (CR.index() + 1 == Regions.size() ||

vsk wrote:
> Why is this deletion necessary? Do we need to introduce 0-length regions 
> which alter the count? An example would help.
Because a single empty line will be a 0 length region. I don't know why is this 
condition necessary before. Does zero-length region exists before this change?

example:
```
int main() {

  return 0;
}
```
Before, llvm-cov gives the following.
```
Counter in file 0 1:12 -> 4:2, #0
Counter in file 0 2:1 -> 2:1, 0
Emitting segments for file: /tmp/a.c
Combined regions:
  1:12 -> 4:2 (count=1)
  2:1 -> 2:1 (count=0)
Segment at 1:12 (count = 1), RegionEntry
Segment at 2:1 (count = 0), RegionEntry, Skipped
Segment at 4:2 (count = 0), Skipped
1|  1|int main() {
2|   |
3|   |return 0;
4|   |}
```
After:
```
Counter in file 0 1:12 -> 4:2, #0
Counter in file 0 2:1 -> 2:1, 0
Emitting segments for file: /tmp/a.c
Combined regions:
  1:12 -> 4:2 (count=1)
  2:1 -> 2:1 (count=0)
Segment at 1:12 (count = 1), RegionEntry
Segment at 2:1 (count = 0), RegionEntry, Skipped
Segment at 2:1 (count = 1)
Segment at 4:2 (count = 0), Skipped
1|  1|int main() {
2|   |
3|  1|return 0;
4|  1|}
```



Comment at: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp:580
   const auto &R = Segments[I];
-  if (!(L.Line < R.Line) && !(L.Line == R.Line && L.Col < R.Col)) {
+  if (!(L.Line <= R.Line) && !(L.Line == R.Line && L.Col <= R.Col)) {
 LLVM_DEBUG(dbgs() << " ! Segment " << L.Line << ":" << L.Col

vsk wrote:
> I don't think this relaxation is correct, since it permits duplicate 
> segments. This is confusing for reporting tools because it's not possible to 
> work out which segment applies at a given source location.
I don't remember why I made this change. Reverting it seems nothing changed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84988/new/

https://reviews.llvm.org/D84988

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


[PATCH] D84988: [Coverage] Add empty line regions to SkippedRegions

2020-08-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp:580
   const auto &R = Segments[I];
-  if (!(L.Line < R.Line) && !(L.Line == R.Line && L.Col < R.Col)) {
+  if (!(L.Line <= R.Line) && !(L.Line == R.Line && L.Col <= R.Col)) {
 LLVM_DEBUG(dbgs() << " ! Segment " << L.Line << ":" << L.Col

zequanwu wrote:
> vsk wrote:
> > I don't think this relaxation is correct, since it permits duplicate 
> > segments. This is confusing for reporting tools because it's not possible 
> > to work out which segment applies at a given source location.
> I don't remember why I made this change. Reverting it seems nothing changed.
Oh, since single empty line will be a 0 length regions. `L.Col`  could equal to 
`R.Col`. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84988/new/

https://reviews.llvm.org/D84988

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


[PATCH] D85810: [clang] Pass-through remarks options to lld

2020-08-17 Thread Wei Wang via Phabricator via cfe-commits
weiwang updated this revision to Diff 286124.
weiwang added a comment.
Herald added subscribers: dang, arichardson, emaste.
Herald added a reviewer: espindola.

update:

1. add `--plugin-opt` alias for remarks in lld
2. handle both lld and ld.gold pass-through
3. simplify target checking logic
4. code format update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85810/new/

https://reviews.llvm.org/D85810

Files:
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/opt-record.c
  lld/ELF/Options.td

Index: lld/ELF/Options.td
===
--- lld/ELF/Options.td
+++ lld/ELF/Options.td
@@ -592,6 +592,21 @@
 def: J<"plugin-opt=obj-path=">,
   Alias,
   HelpText<"Alias for --lto-obj-path=">;
+def: J<"plugin-opt=opt-remarks-filename=">,
+  Alias,
+  HelpText<"Alias for --opt-remarks-filename">;
+def: J<"plugin-opt=opt-remarks-passes=">,
+  Alias,
+  HelpText<"Alias for --opt-remarks-passes">;
+def: J<"plugin-opt=opt-remarks-format=">,
+  Alias,
+  HelpText<"Alias for --opt-remarks-format">;
+def: F<"plugin-opt=opt-remarks-with-hotness">,
+  Alias,
+  HelpText<"Alias for --opt-remarks-with_hotness">;
+def: J<"plugin-opt=opt-remarks-hotness-threshold=">,
+  Alias,
+  HelpText<"Alias for --opt-remarks-hotness-threshold">;
 def: J<"plugin-opt=sample-profile=">,
   Alias, HelpText<"Alias for --lto-sample-profile">;
 def: F<"plugin-opt=save-temps">, Alias, HelpText<"Alias for --save-temps">;
Index: clang/test/Driver/opt-record.c
===
--- clang/test/Driver/opt-record.c
+++ clang/test/Driver/opt-record.c
@@ -18,7 +18,17 @@
 // RUN: %clang -### -S -o FOO -fsave-optimization-record -fsave-optimization-record=some-format %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-FORMAT
 // RUN: %clang -### -S -o FOO -fsave-optimization-record=some-format %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-FORMAT
 // RUN: %clang -### -S -o FOO -fsave-optimization-record=some-format -fno-save-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-FOPT-DISABLE-FORMAT
-//
+
+// Test remarks options pass-through
+// No pass-through: lto is disabled
+// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fdiagnostics-hotness-threshold=100 -fsave-optimization-record %s 2>&1 | not FileCheck %s -check-prefix=CHECK-PASS
+
+// Pass-through:
+// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=lld -flto -fdiagnostics-hotness-threshold=100 -fsave-optimization-record -foptimization-record-passes=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=gold -flto -fdiagnostics-hotness-threshold=100 -fsave-optimization-record -foptimization-record-passes=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=lld -flto=thin -fdiagnostics-hotness-threshold=100 -fsave-optimization-record=some-format -foptimization-record-file=FOO.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS-CUSTOM
+// RUN: %clang -target x86_64-linux-gnu -### -o FOO -fuse-ld=lld -flto=thin -fdiagnostics-hotness-threshold=100 -Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS-RPASS
+
 // CHECK: "-cc1"
 // CHECK: "-opt-record-file" "FOO.opt.yaml"
 
@@ -41,3 +51,17 @@
 // CHECK-EQ-FORMAT: "-opt-record-format" "some-format"
 
 // CHECK-FOPT-DISABLE-FORMAT-NOT: "-fno-save-optimization-record"
+
+// CHECK-PASS: "--plugin-opt=opt-remarks-filename=FOO.opt.ld.yaml"
+// CHECK-PASS: "--plugin-opt=opt-remarks-passes=inline"
+// CHECK-PASS: "--plugin-opt=opt-remarks-format=yaml"
+// CHECK-PASS: "--plugin-opt=opt-remarks-hotness-threshold=100"
+
+// CHECK-PASS-CUSTOM: "--plugin-opt=opt-remarks-filename=FOO.txt.opt.ld.some-format"
+// CHECK-PASS-CUSTOM: "--plugin-opt=opt-remarks-format=some-format"
+// CHECK-PASS-CUSTOM: "--plugin-opt=opt-remarks-hotness-threshold=100"
+
+// CHECK-PASS-RPASS: "--plugin-opt=-pass-remarks=inline"
+// CHECK-PASS-RPASS: "--plugin-opt=-pass-remarks-missed=inline"
+// CHECK-PASS-RPASS: "--plugin-opt=-pass-remarks-analysis=inline"
+// CHECK-PASS-RPASS: "--plugin-opt=opt-remarks-hotness-threshold=100"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -60,6 +60,70 @@
 using namespace clang;
 using namespace llvm::opt;
 
+static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs) {
+  if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ)) {
+CmdArgs.push_back(Args.MakeArgString(Twine("--plugin-opt=-pass-remarks=") +
+ A->getValue()));
+  }
+
+  if (const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ)) {
+CmdArg

[PATCH] D84261: [PGO] Supporting code for always instrumenting entry block

2020-08-17 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 added inline comments.



Comment at: llvm/include/llvm/ProfileData/InstrProfData.inc:676
 #define VARIANT_MASK_CSIR_PROF (0x1ULL << 57)
+#define VARIANT_MASK_INSTR_ENTRY (0x1ULL << 58)
 #define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version

This revision is closed, so excuse me for the question: 
Files `./llvm/include/llvm/ProfileData/InstrProfData.inc` and 
`./compiler-rt/include/profile/InstrProfData.inc` should be two identical 
copies, as stated in their description. 
```
 * The file has two identical copies. The master copy lives in LLVM and
 * the other one  sits in compiler-rt/lib/profile directory. To make changes
 * in this file, first modify the master copy and copy it over to compiler-rt.
 * Testing of any change in this file can start only after the two copies are
 * synced up.
```


Should we add `VARIANT_MASK_INSTR_ENTRY` to `compiler-rt` or change description?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84261/new/

https://reviews.llvm.org/D84261

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


[PATCH] D86065: [SVE] Make ElementCount members private

2020-08-17 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau added a comment.

Perhaps now would be a good time to combine TypeSize and ElementCount into a 
single Polynomial type? We don't have to implement the whole abstraction of 
`c*x^n` (since we currently don't use the exponent, and don't distinguish 
between X's) but if it's ever needed in the future it will be obvious where to 
add it, and it will Just Work.




Comment at: llvm/include/llvm/Support/TypeSize.h:56
 
+  friend bool operator>(const ElementCount &LHS, const ElementCount &RHS) {
+assert(LHS.Scalable == RHS.Scalable &&

fpetrogalli wrote:
> I think that @ctetreau is right on 
> https://reviews.llvm.org/D85794#inline-793909. We should not overload a 
> comparison operator on this class because the set it represent it cannot be 
> ordered.
> 
> Chris suggests an approach of writing a static function that can be used as a 
> comparison operator,  so that we can make it explicit of what kind of 
> comparison we  are doing. 
In C++, it's common to overload the comparison operators for the purposes of 
being able to std::sort and use ordered sets. Normally, I would be OK with such 
usages. However, since `ElementCount` is basically a numeric type, and they 
only have a partial ordering, I think this is dangerous. I'm concerned that 
this will result in more bugs whereby somebody didn't remember that vectors can 
be scalable.

I don't have a strong opinion what the comparator function should be called, 
but I strongly prefer that it not be a comparison operator.



Comment at: llvm/include/llvm/Support/TypeSize.h:290
   static unsigned getHashValue(const ElementCount& EltCnt) {
-if (EltCnt.Scalable)
-  return (EltCnt.Min * 37U) - 1U;
+if (EltCnt.isScalable())
+  return (EltCnt.getKnownMinValue() * 37U) - 1U;

NIT: this can be rewritten without duplicating `EltCnt.getKnownMinValue() * 37U`



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:3522
+  DAG.getNode(ISD::EXTRACT_SUBVECTOR, Dl,
+  MemVT.getHalfNumVectorElementsVT(*DAG.getContext()),
+  StoreNode->getValue(),

What is this `>>` thing? Some indicator of whitespace change, or is this a hard 
tab?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86065/new/

https://reviews.llvm.org/D86065

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


[PATCH] D86105: [darwin] Disable the -Wpsabi warning

2020-08-17 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: ab, t.p.northover, erichkeane.
Herald added subscribers: ributzka, dexonsmith, jkorous.
arphaman requested review of this revision.

The Darwin targets don't enable AVX/AVX512 by default to support Rosetta 2, so 
the new -Wpsabi warning adds unwanted noise to our SDK. Users who build for 
AVX/AVX512 for Darwin are already supposed to take extra care when it comes to 
the ABI differences and the SDK.


https://reviews.llvm.org/D86105

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/target-avx-abi-diag.c


Index: clang/test/CodeGen/target-avx-abi-diag.c
===
--- clang/test/CodeGen/target-avx-abi-diag.c
+++ clang/test/CodeGen/target-avx-abi-diag.c
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -verify=no256,no512 -o - -S
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx 
-verify=no512 -o - -S
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu 
-verify=no256,no512,no256-err,no512-err -o - -S
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx 
-verify=no512,no512-err -o - -S
 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx512f 
-verify=both -o - -S
+
+// RUN: %clang_cc1 %s -triple=x86_64-apple-macos -verify=no256-err,no512-err 
-o - -S
+// RUN: %clang_cc1 %s -triple=x86_64-apple-macos -target-feature +avx 
-verify=no512-err -o - -S
 // REQUIRES: x86-registered-target
 
 // both-no-diagnostics
@@ -31,12 +34,12 @@
 // If only 1 side has an attribute, error.
 void call_errors(void) {
   avx256Type t1;
-  takesAvx256(t1); // no256-error {{AVX vector argument of type 'avx256Type' 
(vector of 16 'short' values) without 'avx' enabled changes the ABI}}
+  takesAvx256(t1); // no256-err-error {{AVX vector argument of type 
'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the 
ABI}}
   avx512fType t2;
-  takesAvx512(t2); // no512-error {{AVX vector argument of type 'avx512fType' 
(vector of 32 'short' values) without 'avx512f' enabled changes the ABI}}
+  takesAvx512(t2); // no512-err-error {{AVX vector argument of type 
'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes 
the ABI}}
 
-  variadic_err(1, t1); // no256-error {{AVX vector argument of type 
'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the 
ABI}}
-  variadic_err(3, t2); // no512-error {{AVX vector argument of type 
'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes 
the ABI}}
+  variadic_err(1, t1); // no256-err-error {{AVX vector argument of type 
'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the 
ABI}}
+  variadic_err(3, t2); // no512-err-error {{AVX vector argument of type 
'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes 
the ABI}}
 }
 
 // These two don't diagnose anything, since these are valid calls.
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2508,12 +2508,17 @@
  const llvm::StringMap &CallerMap,
  const llvm::StringMap &CalleeMap,
  QualType Ty, StringRef Feature,
- bool IsArgument) {
+ bool IsArgument, const llvm::Triple &TT) {
   bool CallerHasFeat = CallerMap.lookup(Feature);
   bool CalleeHasFeat = CalleeMap.lookup(Feature);
-  if (!CallerHasFeat && !CalleeHasFeat)
+  if (!CallerHasFeat && !CalleeHasFeat) {
+// Darwin doesn't enable AVX/AVX512 by default to support Rosetta 2, so 
it's
+// user's responsibility to use AVX/AVX512 safely.
+if (TT.isOSDarwin())
+  return false;
 return Diag.Report(CallLoc, diag::warn_avx_calling_convention)
<< IsArgument << Ty << Feature;
+  }
 
   // Mixing calling conventions here is very clearly an error.
   if (!CallerHasFeat || !CalleeHasFeat)
@@ -2531,13 +2536,14 @@
   const llvm::StringMap &CalleeMap, QualType Ty,
   bool IsArgument) {
   uint64_t Size = Ctx.getTypeSize(Ty);
+  const llvm::Triple &TT = Ctx.getTargetInfo().getTriple();
   if (Size > 256)
 return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty,
-"avx512f", IsArgument);
+"avx512f", IsArgument, TT);
 
   if (Size > 128)
 return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, "avx",
-IsArgument);
+IsArgument, TT);
 
   return false;
 }


Index: clang/test/CodeGen/target-avx-abi-diag.c
===
--- clang/test/CodeGen/target-avx-abi-diag.c
+++ clang/test/CodeGen/target-avx-abi-diag.c
@@ -1,6 +1,9 

[PATCH] D82727: [PowerPC] Implement Vector Expand Mask builtins in LLVM/Clang

2020-08-17 Thread Victor Huang via Phabricator via cfe-commits
NeHuang added a comment.

Overall LGTM. I only have some nits comment.




Comment at: clang/test/CodeGen/builtins-ppc-p10vector.c:136
 
+vector unsigned char test_vexpandm_uc(void) {
+  // CHECK: @llvm.ppc.altivec.vexpandbm(<16 x i8> %{{.+}})

nit: can we change the naming convention to be consistent as above? (e.g.  
"test_vec_expandm_uc") 

I do not have a strong preference for either way since we did have different 
naming conventions in `builtins-ppc-p10vector.c` and `p10-vector-mask-ops.ll` 
for the vector extract cases. 



Comment at: clang/test/CodeGen/builtins-ppc-p10vector.c:142
+
+vector unsigned short test_vexpandm_us(void) {
+  // CHECK: @llvm.ppc.altivec.vexpandhm(<8 x i16> %{{.+}})

ditto



Comment at: clang/test/CodeGen/builtins-ppc-p10vector.c:148
+
+vector unsigned int test_vexpandm_ui(void) {
+  // CHECK: @llvm.ppc.altivec.vexpandwm(<4 x i32> %{{.+}})

ditto



Comment at: clang/test/CodeGen/builtins-ppc-p10vector.c:154
+
+vector unsigned long long test_vexpandm_ull(void) {
+  // CHECK: @llvm.ppc.altivec.vexpanddm(<2 x i64> %{{.+}})

ditto



Comment at: clang/test/CodeGen/builtins-ppc-p10vector.c:160
+
+vector unsigned __int128 test_vexpandm_u128(void) {
+  // CHECK: @llvm.ppc.altivec.vexpandqm(<1 x i128> %{{.+}})

ditto



Comment at: llvm/lib/Target/PowerPC/PPCInstrPrefix.td:881
+ [(set v16i8:$vD, 
(int_ppc_altivec_vexpandbm
+  v16i8:$vB))]>;
   def VEXPANDHM : VXForm_RD5_XO5_RS5<1602, 1, (outs vrrc:$vD), (ins vrrc:$vB),

amyk wrote:
> I have no idea why this indentation is off, since it did not appear like that 
> previously. In any case, I can address this during the commit if it is OK.
This seems does not cause any clang-format check error during phabricator 
pre-merge check.  I tried downloading this patch and found the indentation is 
as expected. It seems like a display issue from phabricator. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82727/new/

https://reviews.llvm.org/D82727

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


[PATCH] D85917: [MSP430] Fix passing C structs and unions as function arguments

2020-08-17 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/CodeGen/TargetInfo.cpp:7523
+  return ABIArgInfo::getIndirectAliased(
+  getContext().getTypeAlignInChars(Ty), /*AddrSpace=*/0);
+

Oh wow, the ABI really is indirect aliased:

  To pass a structure or union by reference, the caller places its address
  in the appropriate location: either in a register or on the stack, according
  to its position in the argument list. To preserve pass-by-value semantics
  (required for C and C++), the callee may need to make its own copy of the
  pointed-to object. In some cases, the callee need not make a copy, such
  as if the callee is a leaf and it does not modify the pointed-to object.

I didn't realize any actual ABIs did this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85917/new/

https://reviews.llvm.org/D85917

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


[libclc] 3a7051d - libclc: Fix FP_ILOGBNAN definition

2020-08-17 Thread Tom Stellard via cfe-commits

Author: Boris Brezillon
Date: 2020-08-17T13:45:43-07:00
New Revision: 3a7051d9c28e3dd6da5048d91b74fad830728e93

URL: 
https://github.com/llvm/llvm-project/commit/3a7051d9c28e3dd6da5048d91b74fad830728e93
DIFF: 
https://github.com/llvm/llvm-project/commit/3a7051d9c28e3dd6da5048d91b74fad830728e93.diff

LOG: libclc: Fix FP_ILOGBNAN definition

Fix FP_ILOGBNAN definition to match the opencl-c-base.h one and
guarantee that FP_ILOGBNAN and FP_ILOGB0 are different. Doing that
implies fixing ilogb() implementation to return the right value.

Signed-off-by: Boris Brezillon 

Reviewed By: jvesely

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

Added: 


Modified: 
libclc/generic/include/clc/float/definitions.h
libclc/generic/lib/math/ilogb.cl

Removed: 




diff  --git a/libclc/generic/include/clc/float/definitions.h 
b/libclc/generic/include/clc/float/definitions.h
index 43335a787403..62501230c92d 100644
--- a/libclc/generic/include/clc/float/definitions.h
+++ b/libclc/generic/include/clc/float/definitions.h
@@ -15,7 +15,7 @@
 #define FLT_EPSILON 0x1.0p-23f
 
 #define FP_ILOGB0 (-2147483647 - 1)
-#define FP_ILOGBNAN (-2147483647 - 1)
+#define FP_ILOGBNAN 2147483647
 
 #define M_E_F   0x1.5bf0a8p+1f
 #define M_LOG2E_F   0x1.715476p+0f

diff  --git a/libclc/generic/lib/math/ilogb.cl 
b/libclc/generic/lib/math/ilogb.cl
index 7ab7899e0c59..050239c9c1ff 100644
--- a/libclc/generic/lib/math/ilogb.cl
+++ b/libclc/generic/lib/math/ilogb.cl
@@ -31,7 +31,15 @@ _CLC_OVERLOAD _CLC_DEF int ilogb(float x) {
 int rs = -118 - (int) clz(ux & MANTBITS_SP32);
 int r = (int) (ax >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;
 r = ax < 0x0080U ? rs : r;
-r = ax > EXPBITS_SP32 | ax == 0 ? 0x8000 : r;
+r = ax == 0 ? FP_ILOGB0 : r;
+
+// We could merge those 2 tests and have:
+//
+//r = ax >= EXPBITS_SP32 ? 0x7fff : r
+//
+// since FP_ILOGBNAN is set to INT_MAX, but it's clearer this way and
+// FP_ILOGBNAN can change without requiring changes to ilogb() code.
+r = ax > EXPBITS_SP32 ? FP_ILOGBNAN : r;
 r = ax == EXPBITS_SP32 ? 0x7fff : r;
 return r;
 }
@@ -47,7 +55,15 @@ _CLC_OVERLOAD _CLC_DEF int ilogb(double x) {
 int r = (int) (ax >> EXPSHIFTBITS_DP64) - EXPBIAS_DP64;
 int rs = -1011 - (int) clz(ax & MANTBITS_DP64);
 r = ax < 0x0010UL ? rs : r;
-r = ax > 0x7ff0UL | ax == 0UL ? 0x8000 : r;
+r = ax == 0UL ? FP_ILOGB0 : r;
+
+// We could merge those 2 tests and have:
+//
+//r = ax >= 0x7ff0UL ? 0x7fff : r
+//
+// since FP_ILOGBNAN is set to INT_MAX, but it's clearer this way and
+// FP_ILOGBNAN can change without requiring changes to ilogb() code.
+r = ax > 0x7ff0UL ? FP_ILOGBNAN : r;
 r = ax == 0x7ff0UL ? 0x7fff : r;
 return r;
 }



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


[PATCH] D82609: [PowerPC] Implement Vector Multiply High/Divide Extended Builtins in LLVM/Clang

2020-08-17 Thread Victor Huang via Phabricator via cfe-commits
NeHuang added inline comments.



Comment at: llvm/test/CodeGen/PowerPC/p10-vector-divide.ll:59
+
+define <4 x i32> @test_vdivesw(<4 x i32> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vdivesw:

nit:  do we also need  `_intrinsic` in the name as the test cases for the 
vector multiply high intrinsics.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82609/new/

https://reviews.llvm.org/D82609

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


[libclc] 3d21fa5 - libclc: Make all built-ins overloadable

2020-08-17 Thread Tom Stellard via cfe-commits

Author: Daniel Stone
Date: 2020-08-17T13:55:48-07:00
New Revision: 3d21fa56f5f5afbbf16b35b199480af71e1189a3

URL: 
https://github.com/llvm/llvm-project/commit/3d21fa56f5f5afbbf16b35b199480af71e1189a3
DIFF: 
https://github.com/llvm/llvm-project/commit/3d21fa56f5f5afbbf16b35b199480af71e1189a3.diff

LOG: libclc: Make all built-ins overloadable

The SPIR spec states that all OpenCL built-in functions should be
overloadable and mangled, to ensure consistency.

Add the overload attribute to functions which were missing them:
work dimensions, memory barriers and fences, and events.

Reviewed By: tstellar, jenatali

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

Added: 


Modified: 
libclc/amdgcn-amdhsa/lib/workitem/get_global_size.cl
libclc/amdgcn-amdhsa/lib/workitem/get_local_size.cl
libclc/amdgcn-amdhsa/lib/workitem/get_num_groups.cl
libclc/amdgcn/lib/mem_fence/fence.cl
libclc/amdgcn/lib/synchronization/barrier.cl
libclc/amdgcn/lib/workitem/get_global_offset.cl
libclc/amdgcn/lib/workitem/get_global_size.cl
libclc/amdgcn/lib/workitem/get_group_id.cl
libclc/amdgcn/lib/workitem/get_local_id.cl
libclc/amdgcn/lib/workitem/get_local_size.cl
libclc/amdgcn/lib/workitem/get_num_groups.cl
libclc/amdgcn/lib/workitem/get_work_dim.cl
libclc/generic/include/clc/async/wait_group_events.h
libclc/generic/include/clc/explicit_fence/explicit_memory_fence.h
libclc/generic/include/clc/synchronization/barrier.h
libclc/generic/include/clc/workitem/get_global_id.h
libclc/generic/include/clc/workitem/get_global_offset.h
libclc/generic/include/clc/workitem/get_global_size.h
libclc/generic/include/clc/workitem/get_group_id.h
libclc/generic/include/clc/workitem/get_local_id.h
libclc/generic/include/clc/workitem/get_local_size.h
libclc/generic/include/clc/workitem/get_num_groups.h
libclc/generic/include/clc/workitem/get_work_dim.h
libclc/generic/lib/async/wait_group_events.cl
libclc/generic/lib/workitem/get_global_id.cl
libclc/generic/lib/workitem/get_global_size.cl
libclc/ptx-nvidiacl/lib/mem_fence/fence.cl
libclc/ptx-nvidiacl/lib/synchronization/barrier.cl
libclc/ptx-nvidiacl/lib/workitem/get_global_id.cl
libclc/ptx-nvidiacl/lib/workitem/get_group_id.cl
libclc/ptx-nvidiacl/lib/workitem/get_local_id.cl
libclc/ptx-nvidiacl/lib/workitem/get_local_size.cl
libclc/ptx-nvidiacl/lib/workitem/get_num_groups.cl
libclc/r600/lib/synchronization/barrier.cl
libclc/r600/lib/workitem/get_global_offset.cl
libclc/r600/lib/workitem/get_global_size.cl
libclc/r600/lib/workitem/get_group_id.cl
libclc/r600/lib/workitem/get_local_id.cl
libclc/r600/lib/workitem/get_local_size.cl
libclc/r600/lib/workitem/get_num_groups.cl
libclc/r600/lib/workitem/get_work_dim.cl

Removed: 




diff  --git a/libclc/amdgcn-amdhsa/lib/workitem/get_global_size.cl 
b/libclc/amdgcn-amdhsa/lib/workitem/get_global_size.cl
index 2f95f9916b2c..62bd2ba28352 100644
--- a/libclc/amdgcn-amdhsa/lib/workitem/get_global_size.cl
+++ b/libclc/amdgcn-amdhsa/lib/workitem/get_global_size.cl
@@ -15,10 +15,9 @@
 CONST_AS uchar * __clc_amdgcn_dispatch_ptr(void) 
__asm("llvm.amdgcn.dispatch.ptr");
 #endif
 
-_CLC_DEF size_t get_global_size(uint dim)
-{
-   CONST_AS uint * ptr = (CONST_AS uint *) __dispatch_ptr();
-   if (dim < 3)
-   return ptr[3 + dim];
-   return 1;
+_CLC_DEF _CLC_OVERLOAD size_t get_global_size(uint dim) {
+  CONST_AS uint *ptr = (CONST_AS uint *)__dispatch_ptr();
+  if (dim < 3)
+return ptr[3 + dim];
+  return 1;
 }

diff  --git a/libclc/amdgcn-amdhsa/lib/workitem/get_local_size.cl 
b/libclc/amdgcn-amdhsa/lib/workitem/get_local_size.cl
index 9f208d8aea77..9f09fd5a16ec 100644
--- a/libclc/amdgcn-amdhsa/lib/workitem/get_local_size.cl
+++ b/libclc/amdgcn-amdhsa/lib/workitem/get_local_size.cl
@@ -15,16 +15,15 @@
 CONST_AS char * __clc_amdgcn_dispatch_ptr(void) 
__asm("llvm.amdgcn.dispatch.ptr");
 #endif
 
-_CLC_DEF size_t get_local_size(uint dim)
-{
-   CONST_AS uint * ptr = (CONST_AS uint *) __dispatch_ptr();
-   switch (dim) {
-   case 0:
-   return ptr[1] & 0xu;
-   case 1:
-   return ptr[1] >> 16;
-   case 2:
-   return ptr[2] & 0xu;
-   }
-   return 1;
+_CLC_DEF _CLC_OVERLOAD size_t get_local_size(uint dim) {
+  CONST_AS uint *ptr = (CONST_AS uint *)__dispatch_ptr();
+  switch (dim) {
+  case 0:
+return ptr[1] & 0xu;
+  case 1:
+return ptr[1] >> 16;
+  case 2:
+return ptr[2] & 0xu;
+  }
+  return 1;
 }

diff  --git a/libclc/amdgcn-amdhsa/lib/workitem/get_num_groups.cl 
b/libclc/amdgcn-amdhsa/lib/workitem/get_num_groups.cl
index 946b526fdb68..35dc22188521 100644
--- a/libclc/amdgcn-amdhsa/lib/workitem/get_num_groups.cl
+++ b/libclc/amdgcn-amdhsa/lib/workitem/get_num_groups.cl
@@ -1,7 +1,7 @@
 
 #include 
 
-_C

[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2020-08-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 286141.
plotfi added a comment.

change for clang-tidy and clang-format.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86049/new/

https://reviews.llvm.org/D86049

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenObjC/objc-direct-wrapper.m

Index: clang/test/CodeGenObjC/objc-direct-wrapper.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/objc-direct-wrapper.m
@@ -0,0 +1,43 @@
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN:   -fobjc-export-direct-method-wrappers -c -o - %s | \
+// RUN: llvm-nm - | FileCheck -check-prefix=CHECK-WRAPPER %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation -c -o - %s | llvm-nm - | \
+// RUN: FileCheck -check-prefix=CHECK-DEFAULT %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN:   -fobjc-export-direct-method-wrappers -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DEFINE %s
+
+// RUN: %clang -fobjc-arc -Wno-objc-root-class -DNO_OBJC_IMPL \
+// RUN: -target x86_64-apple-macosx10.15.0 \
+// RUN: -ObjC -fobjc-runtime=ios -FFoundation \
+// RUN:   -fobjc-export-direct-method-wrappers -c -o - %s -S -emit-llvm | \
+// RUN: FileCheck -check-prefix=CHECK-WRAPPER-IR-DECLARE %s
+
+// CHECK-WRAPPER: T ___objc_direct_wrapper-[C testMethod:bar:]
+// CHECK-DEFAULT-NOT: ___objc_direct_wrapper
+// CHECK-WRAPPER-IR-DEFINE: define {{(dso_local )?}}{{(dso_local )?}}void @"__objc_direct_wrapper-[C testMethod:bar:]"
+// CHECK-WRAPPER-IR-DECLARE: declare {{(dso_local )?}}void @"__objc_direct_wrapper-[C testMethod:bar:]"
+
+@interface C
+- (void)testMethod:(int)arg1 bar:(float)arg2 __attribute((objc_direct));
+@end
+
+#ifndef NO_OBJC_IMPL
+@implementation C
+- (void)testMethod:(int)arg1 bar:(float)arg2 __attribute((objc_direct)) {
+}
+@end
+#endif
+
+C *c;
+
+void f() {
+  [c testMethod:1 bar:1.0];
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1283,6 +1283,8 @@
 }
   }
 
+  if (Args.hasArg(OPT_fobjc_export_direct_method_wrappers))
+Opts.ObjCExportDirectMethodWrappers = 1;
 
   if (Args.hasArg(OPT_fno_objc_convert_messages_to_runtime_calls))
 Opts.ObjCConvertMessagesToRuntimeCalls = 0;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3462,6 +3462,9 @@
   CmdArgs.push_back("-fno-objc-convert-messages-to-runtime-calls");
   }
 
+  if (Args.hasArg(options::OPT_fobjc_export_direct_method_wrappers))
+CmdArgs.push_back("-fobjc-export-direct-method-wrappers");
+
   // -fobjc-infer-related-result-type is the default, except in the Objective-C
   // rewriter.
   if (InferCovariantReturns)
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -2143,6 +2143,36 @@
   return false;
 }
 
+/// Create or look up the declaration of an objc_direct method wrapper.
+llvm::Function *getObjCDirectWrapper(llvm::Function &F) {
+  std::string NewName = "__objc_direct_wrapper";
+  for (auto C : F.getName().str()) {
+if (C == '\1')
+  continue;
+NewName += C;
+  }
+
+  auto WI = llvm::find_if(*F.getParent(), [NewName](const llvm::Function &F) {
+return F.getName() == NewName;
+  });
+
+  llvm::Function *Wrapper = nullptr;
+  if (WI == F.getParent()->end()) {
+llvm::Module &M = *F.getParent();
+llvm::FunctionType *FnTy = F.getFunctionType();
+Wrapper = llvm::Function::Create(FnTy, F.getLinkage(), F.getAddressSpace(),
+ NewName);
+Wrapper->setLinkage(llvm::GlobalValue::ExternalLinkage);
+Wrapper->addFnAttr(llvm::Attribute::AlwaysInline);
+Wrapper->setVisibility(llvm::Function::DefaultVisibility);
+M.getFunctionList().insert(F.getIterator(), Wrapper);
+  } else {
+Wrapper = &*WI;
+  }
+
+  return Wrapper;
+}
+
 CodeGen::RValue
 CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
  ReturnValueSlot Return,
@@ -2214,7 +2244,13 @@
 
   llvm::FunctionCallee Fn = nullptr;
   if (Method && Method->isDirectMethod()) {
-Fn = GenerateDirectMethod(Method, Method->getClassI

[libclc] c37145c - libclc: Add Mesa/SPIR-V target

2020-08-17 Thread Tom Stellard via cfe-commits

Author: Dave Airlie
Date: 2020-08-17T14:01:46-07:00
New Revision: c37145cab12168798a603e22af6b6bf6f606b705

URL: 
https://github.com/llvm/llvm-project/commit/c37145cab12168798a603e22af6b6bf6f606b705
DIFF: 
https://github.com/llvm/llvm-project/commit/c37145cab12168798a603e22af6b6bf6f606b705.diff

LOG: libclc: Add Mesa/SPIR-V target

Add targets to emit SPIR-V targeted to Mesa's OpenCL support, using
SPIR-V 1.1.

Substantially based on Dave Airlie's earlier work.

libclc: spirv: remove step/smoothstep apis not defined for SPIR-V

libclc: disable inlines for SPIR-V builds

Reviewed By: jvesely, tstellar, jenatali

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

Added: 
libclc/spirv/lib/SOURCES
libclc/spirv/lib/subnormal_config.cl
libclc/spirv64/lib/SOURCES
libclc/spirv64/lib/subnormal_config.cl

Modified: 
libclc/CMakeLists.txt
libclc/generic/include/clc/clcfunc.h
libclc/generic/lib/common/smoothstep.cl
libclc/generic/lib/common/step.cl

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c12dc10fa45d..1a77a378e192 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -10,7 +10,9 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
   generic/lib/SOURCES;
   ptx/lib/SOURCES;
   ptx-nvidiacl/lib/SOURCES;
-  r600/lib/SOURCES
+  r600/lib/SOURCES;
+  spirv/lib/SOURCES;
+  spirv64/lib/SOURCES
 )
 
 # List of all targets
@@ -22,6 +24,8 @@ set( LIBCLC_TARGETS_ALL
   nvptx64--
   nvptx--nvidiacl
   nvptx64--nvidiacl
+  spirv-mesa3d-
+  spirv64-mesa3d-
 )
 
 set( LIBCLC_MIN_LLVM "3.9.0" )
@@ -53,8 +57,6 @@ if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" )
set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} )
 endif()
 
-list( SORT LIBCLC_TARGETS_TO_BUILD )
-
 execute_process( COMMAND ${LLVM_CONFIG} "--system-libs"
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE )
@@ -93,17 +95,27 @@ find_program( LLVM_CLANG clang PATHS ${LLVM_BINDIR} 
NO_DEFAULT_PATH )
 find_program( LLVM_AS llvm-as PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH )
 find_program( LLVM_LINK llvm-link PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH )
 find_program( LLVM_OPT opt PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH )
+find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH )
 
 # Print toolchain
 message( "clang: ${LLVM_CLANG}" )
 message( "llvm-as: ${LLVM_AS}" )
 message( "llvm-link: ${LLVM_LINK}" )
 message( "opt: ${LLVM_OPT}" )
+message( "llvm-spirv: ${LLVM_SPIRV}" )
 message( "" )
 if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK )
message( FATAL_ERROR "toolchain incomplete!" )
 endif()
 
+list( SORT LIBCLC_TARGETS_TO_BUILD )
+
+if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" 
IN_LIST LIBCLC_TARGETS_TO_BUILD )
+   if( NOT LLVM_SPIRV )
+   message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools 
is not installed" )
+   endif()
+endif()
+
 set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake )
 set( CMAKE_CLC_COMPILER ${LLVM_CLANG} )
 set( CMAKE_CLC_ARCHIVE ${LLVM_LINK} )
@@ -137,6 +149,8 @@ set( nvptx--_devices none )
 set( nvptx64--_devices none )
 set( nvptx--nvidiacl_devices none )
 set( nvptx64--nvidiacl_devices none )
+set( spirv-mesa3d-_devices none )
+set( spirv64-mesa3d-_devices none )
 
 # Setup aliases
 set( cedar_aliases palm sumo sumo2 redwood juniper )
@@ -187,9 +201,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
list( GET TRIPLE 1 VENDOR )
list( GET TRIPLE 2 OS )
 
-   set( dirs generic )
+   set( dirs )
+
+   if ( NOT ${ARCH} STREQUAL spirv AND NOT ${ARCH} STREQUAL spirv64 )
+   LIST( APPEND dirs generic )
+   endif()
+
if( ${ARCH} STREQUAL r600 OR ${ARCH} STREQUAL amdgcn )
-   set( dirs ${dirs} amdgpu )
+   list( APPEND dirs amdgpu )
endif()
 
#nvptx is special
@@ -215,10 +234,15 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
-   set( rel_files convert.cl )
-   set( objects convert.cl )
-   if( NOT ENABLE_RUNTIME_SUBNORMAL )
-   list( APPEND rel_files generic/lib/subnormal_use_default.ll )
+   if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
+   if( NOT ENABLE_RUNTIME_SUBNORMAL )
+   list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   endif()
+   else()
+   set( rel_files )
+   set( objects )
endif()
 
foreach( l ${source_list} )
@@ -242,7 +266,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 
foreach( d ${${t}_devices} )
# Some targets don't have a specific GPU to target
-   if( ${d} STREQUAL "none" )
+

Re: [PATCH] D84261: [PGO] Supporting code for always instrumenting entry block

2020-08-17 Thread Xinliang David Li via cfe-commits
I think you are right -- the two files need to be in sync.

On Mon, Aug 17, 2020 at 1:17 PM Pavel Kosov via Phabricator via
llvm-commits  wrote:

> kpdev42 added inline comments.
>
>
> 
> Comment at: llvm/include/llvm/ProfileData/InstrProfData.inc:676
>  #define VARIANT_MASK_CSIR_PROF (0x1ULL << 57)
> +#define VARIANT_MASK_INSTR_ENTRY (0x1ULL << 58)
>  #define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version
> 
> This revision is closed, so excuse me for the question:
> Files `./llvm/include/llvm/ProfileData/InstrProfData.inc` and
> `./compiler-rt/include/profile/InstrProfData.inc` should be two identical
> copies, as stated in their description.
> ```
>  * The file has two identical copies. The master copy lives in LLVM and
>  * the other one  sits in compiler-rt/lib/profile directory. To make
> changes
>  * in this file, first modify the master copy and copy it over to
> compiler-rt.
>  * Testing of any change in this file can start only after the two copies
> are
>  * synced up.
> ```
>
>
> Should we add `VARIANT_MASK_INSTR_ENTRY` to `compiler-rt` or change
> description?
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D84261/new/
>
> https://reviews.llvm.org/D84261
>
> ___
> llvm-commits mailing list
> llvm-comm...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] 4cd0937 - [libunwind] Remove compatibility support for macOS 10.6

2020-08-17 Thread Steven Wu via cfe-commits

Author: Steven Wu
Date: 2020-08-17T14:09:03-07:00
New Revision: 4cd09374cdb163573007ccb402f5ba8970eb6134

URL: 
https://github.com/llvm/llvm-project/commit/4cd09374cdb163573007ccb402f5ba8970eb6134
DIFF: 
https://github.com/llvm/llvm-project/commit/4cd09374cdb163573007ccb402f5ba8970eb6134.diff

LOG: [libunwind] Remove compatibility support for macOS 10.6

Remove `_dyld_find_unwind_sections` implementation for macOS that is
10.6 or previous. 10.6 is no longer supported for TOT libunwind after
removing its libkeymgr dependency.

Reviewed By: mstorsjo, pete, #libunwind

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

Added: 


Modified: 
libunwind/src/AddressSpace.hpp

Removed: 




diff  --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 3d1e810f43c0..78d2dd110865 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -55,43 +55,9 @@ struct EHABIIndexEntry {
 const void* compact_unwind_section;
 uintptr_t   compact_unwind_section_length;
   };
-  #if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) \
- && (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1070)) 
\
-  || defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
-// In 10.7.0 or later, libSystem.dylib implements this function.
-extern "C" bool _dyld_find_unwind_sections(void *, dyld_unwind_sections *);
-  #else
-// In 10.6.x and earlier, we need to implement this functionality. Note
-// that this requires a newer version of libmacho (from cctools) than is
-// present in libSystem on 10.6.x (for getsectiondata).
-static inline bool _dyld_find_unwind_sections(void* addr,
-dyld_unwind_sections* 
info) {
-  // Find mach-o image containing address.
-  Dl_info dlinfo;
-  if (!dladdr(addr, &dlinfo))
-return false;
-#if __LP64__
-  const struct mach_header_64 *mh = (const struct mach_header_64 
*)dlinfo.dli_fbase;
-#else
-  const struct mach_header *mh = (const struct mach_header 
*)dlinfo.dli_fbase;
-#endif
-
-  // Initialize the return struct
-  info->mh = (const struct mach_header *)mh;
-  info->dwarf_section = getsectiondata(mh, "__TEXT", "__eh_frame", 
&info->dwarf_section_length);
-  info->compact_unwind_section = getsectiondata(mh, "__TEXT", 
"__unwind_info", &info->compact_unwind_section_length);
-
-  if (!info->dwarf_section) {
-info->dwarf_section_length = 0;
-  }
 
-  if (!info->compact_unwind_section) {
-info->compact_unwind_section_length = 0;
-  }
-
-  return true;
-}
-  #endif
+  // In 10.7.0 or later, libSystem.dylib implements this function.
+  extern "C" bool _dyld_find_unwind_sections(void *, dyld_unwind_sections *);
 
 #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && 
defined(_LIBUNWIND_IS_BAREMETAL)
 



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


[PATCH] D85810: [clang] Pass-through remarks options to linker

2020-08-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: lld/ELF/Options.td:595
   HelpText<"Alias for --lto-obj-path=">;
+def: J<"plugin-opt=opt-remarks-filename=">,
+  Alias,

The change should be moved to a previous patch which will add `--opt-remarks-*` 
options.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85810/new/

https://reviews.llvm.org/D85810

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


[clang] 790878f - [NFC][clang] Adjust test/CodeGenCXX/nrvo.cpp after 03127f795b8244c1039c18d4391374707a3dc75e

2020-08-17 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2020-08-18T00:57:35+03:00
New Revision: 790878f291fa5dc58a1c560cb6cc76fd1bfd1c5a

URL: 
https://github.com/llvm/llvm-project/commit/790878f291fa5dc58a1c560cb6cc76fd1bfd1c5a
DIFF: 
https://github.com/llvm/llvm-project/commit/790878f291fa5dc58a1c560cb6cc76fd1bfd1c5a.diff

LOG: [NFC][clang] Adjust test/CodeGenCXX/nrvo.cpp after 
03127f795b8244c1039c18d4391374707a3dc75e

Added: 


Modified: 
clang/test/CodeGenCXX/nrvo.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/nrvo.cpp b/clang/test/CodeGenCXX/nrvo.cpp
index 1a5e63cd7fd7..51b62e68c3af 100644
--- a/clang/test/CodeGenCXX/nrvo.cpp
+++ b/clang/test/CodeGenCXX/nrvo.cpp
@@ -85,8 +85,6 @@ X test2(bool B) {
   // %lpad: landing pad for ctor of 'y', dtor of 'y'
   // CHECK-EH:  [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 }
   // CHECK-EH-NEXT:   cleanup
-  // CHECK-EH-03-NEXT: extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
-  // CHECK-EH-03-NEXT: extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
   // CHECK-EH-NEXT: br label
   // -> %eh.cleanup
 



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


[PATCH] D83088: Introduce CfgTraits abstraction

2020-08-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D83088#2218559 , @nhaehnle wrote:

> In D83088#2213886 , @dblaikie wrote:
>
>> In D83088#2213864 , @nhaehnle wrote:
>>
>>> In D83088#2213802 , @dblaikie 
>>> wrote:
>>>
 In D83088#2213797 , @nhaehnle 
 wrote:

> In D83088#2208611 , @dblaikie 
> wrote:
>
>> This seems like a strange hybrid between a static-polymorphism (with 
>> traits) and dynamic polymorphism (with base classes/virtual functions). 
>> Could this more readily be just one or the other? (sounds like you're 
>> leaning towards dynamic polymorphism)
>
> No, it's very much this way on purpose. The idea is to support the same 
> set of functionality as much as possible in both static **and** dynamic 
> polymorphism.

 Could it be implemented statically as a primary interface, with a dynamic 
 wrapper? (eg: a base class, then a derived class template that takes the 
 static CFG type to wrap into the dynamic type) keeping the two concepts 
 more clearly separated?
>>>
>>> That is how it is implemented. CfgTraits is the primary static interface, 
>>> and then CfgInterface / CfgInterfaceImpl is the dynamic wrapper.
>>
>> Ah, fair enough. The inheritance details in the traits class confused me a 
>> bit/I had a hard time following, with all the features being in the one 
>> patch. Might be easier separately, but not sure.
>>
>> Would it be possible for this not to use traits - I know @asbirlea and I had 
>> trouble with some things using GraphTraits owing to the traits API. An 
>> alternative would be to describe a CFGGraph concept (same as a standard 
>> container concept, for instance) - where there is a concrete graph object 
>> and that object is queried for things like nodes, edges, etc. (actually one 
>> of the significant things we tripped over was the API choice to navigate 
>> edges from a node itself without any extra state - which meant nodes/edge 
>> iteration had to carry state (potentially pointers back to the graph, etc) 
>> to be able to manifest their edges - trait or concept could both address 
>> this by, for traits, passing the graph as well as the node when querying the 
>> trait for edges, or for a concept passing the node back to the graph to 
>> query for edges).
>
> So there is a bit of a part here where I may admittedly be a bit confused 
> with the C++ lingo, since I don't actually like template programming that 
> much :)

Not sure that's the best place to be designing this fairly integral and 
complicated piece of infrastructure from, but hoping we can find some good 
places/solutions/etc.

> (Which is part of the motivation for this to begin with... so that I can do 
> the later changes in the stack here without *everything* being in templates.)

That concerns me a bit as a motivation - Perhaps the existing GraphTraits 
template approach could be improved, rather than adding another/separate set of 
complexity with both dynamic and static dispatch. (eg: containers in the C++ 
standard library don't support runtime polymorphism (you can't dynamically 
dispatch over a std::vector versus a std::list, for instance)).

What does/will this Cfg abstraction provide that's separate from the current 
Graph (provided by GraphTraits) abstraction? Does it provide things other than 
the ability to write these algorithms as non-templates? (in which case is the 
non-dynamic portion of this functionally equivalent to GraphTraits (but more as 
a concept than a trait, by the sounds of it))

> The way the `CfgTraits` is used is that you never use the `CfgTraits` class 
> directly except to inherit from it using CRTP (curiously recurring template 
> pattern).

side note: Using the same name in multiple namespaces makes this a bit harder 
to read than it might otherwise be (clang::CfgTraits deriving from 
llvm::CfgTraits, etc)
So currently you write a MyCfgTraitsBase, deriving from llvm::CfgTraitsBase

  class MyCfgTraitsBase : public llvm::CfgTraitsBase { ...

then you write CfgTraits that derieves from that with both CRTP and the 
MyCfgTraitsBase

  class MyCfgTraits : public llvm::CfgTraits

Could this be simplified by moving the MyCfgTraitsBase stuff into MyCfgTraits, 
and having llvm::CfgTraits with just one template parameter, the derived class?

> When writing algorithms that want to be generic over the type of CFG, those 
> algorithms then have a derived class of CfgTraits as a template parameter. 
> For example, D83094  adds a 
> `GenericCycleInfo` template class, where the template parameter 
> should be set to e.g. `IrCfgTraits`, if you want cycle info on LLVM IR, or to 
> `MachineCfgTraits`, if you want cycle info on MachineIR. Both of these 
> classes 

[PATCH] D86116: [Coverage] Adjust skipped regions only if {Prev,Next}TokLoc is in the same file as regions' {start, end}Loc

2020-08-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu created this revision.
zequanwu added reviewers: vsk, hans.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
zequanwu requested review of this revision.

Fix a bug if {Prev, Next}TokLoc is in different file from skipped regions' 
{start, end}Loc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86116

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/Inputs/comment.h
  clang/test/CoverageMapping/comment.cpp


Index: clang/test/CoverageMapping/comment.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/comment.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+
+int f() {
+  int x = 0;
+#include "Inputs/comment.h" /*
+*/
+  return x;
+}
+
+// CHECK: File 0, 3:9 -> 8:2 = #0
+// CHECK-NEXT: Expansion,File 0, 5:14 -> 5:32 = #0
+// CHECK-NEXT: Skipped,File 0, 6:1 -> 6:7 = 0
+// CHECK-NEXT: File 1, 1:1 -> 6:7 = #0
\ No newline at end of file
Index: clang/test/CoverageMapping/Inputs/comment.h
===
--- /dev/null
+++ clang/test/CoverageMapping/Inputs/comment.h
@@ -0,0 +1,3 @@
+
+
+x = 0;
\ No newline at end of file
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -44,7 +44,8 @@
   PP.setTokenWatcher([CoverageInfo](clang::Token Tok) {
 // Update previous token location.
 CoverageInfo->PrevTokLoc = Tok.getLocation();
-CoverageInfo->updateNextTokLoc(Tok.getLocation());
+if (Tok.getKind() != clang::tok::eod)
+  CoverageInfo->updateNextTokLoc(Tok.getLocation());
   });
   return CoverageInfo;
 }
@@ -305,20 +306,24 @@
   /// non-comment token. If shrinking the skipped range would make it empty,
   /// this returns None.
   Optional adjustSkippedRange(SourceManager &SM,
-  SpellingRegion SR,
+  SourceLocation LocStart,
+  SourceLocation LocEnd,
   SourceLocation PrevTokLoc,
   SourceLocation NextTokLoc) {
+SpellingRegion SR{SM, LocStart, LocEnd};
 // If Range begin location is invalid, it's not a comment region.
 if (PrevTokLoc.isInvalid())
   return SR;
 unsigned PrevTokLine = SM.getSpellingLineNumber(PrevTokLoc);
 unsigned NextTokLine = SM.getSpellingLineNumber(NextTokLoc);
 SpellingRegion newSR(SR);
-if (SR.LineStart == PrevTokLine) {
+if (SM.isWrittenInSameFile(LocStart, PrevTokLoc) &&
+SR.LineStart == PrevTokLine) {
   newSR.LineStart = SR.LineStart + 1;
   newSR.ColumnStart = 1;
 }
-if (SR.LineEnd == NextTokLine) {
+if (SM.isWrittenInSameFile(LocEnd, NextTokLoc) &&
+SR.LineEnd == NextTokLine) {
   newSR.LineEnd = SR.LineEnd - 1;
   newSR.ColumnEnd = SR.ColumnStart + 1;
 }
@@ -354,14 +359,13 @@
   auto CovFileID = getCoverageFileID(LocStart);
   if (!CovFileID)
 continue;
-  SpellingRegion SR{SM, LocStart, LocEnd};
-  if (Optional res =
-  adjustSkippedRange(SM, SR, I.PrevTokLoc, I.NextTokLoc))
-SR = res.getValue();
-  else
+  Optional SR =
+  adjustSkippedRange(SM, LocStart, LocEnd, I.PrevTokLoc, I.NextTokLoc);
+  if (!SR.hasValue())
 continue;
   auto Region = CounterMappingRegion::makeSkipped(
-  *CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd);
+  *CovFileID, SR->LineStart, SR->ColumnStart, SR->LineEnd,
+  SR->ColumnEnd);
   // Make sure that we only collect the regions that are inside
   // the source code of this function.
   if (Region.LineStart >= FileLineRanges[*CovFileID].first &&


Index: clang/test/CoverageMapping/comment.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/comment.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+
+int f() {
+  int x = 0;
+#include "Inputs/comment.h" /*
+*/
+  return x;
+}
+
+// CHECK: File 0, 3:9 -> 8:2 = #0
+// CHECK-NEXT: Expansion,File 0, 5:14 -> 5:32 = #0
+// CHECK-NEXT: Skipped,File 0, 6:1 -> 6:7 = 0
+// CHECK-NEXT: File 1, 1:1 -> 6:7 = #0
\ No newline at end of file
Index: clang/test/CoverageMapping/Inputs/comment.h
===
--- /dev/null
+++ clang/test/CoverageMapping/Inputs/comment.h
@@ -0,0 +1,3 @@
+
+
+x = 0;
\ No newline at end of file
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
==

[PATCH] D86116: [Coverage] Adjust skipped regions only if {Prev,Next}TokLoc is in the same file as regions' {start, end}Loc

2020-08-17 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 286167.
zequanwu added a comment.

Update test.
The bug is when start or end location skipped regions has the same spelling 
line number as PrevTokLoc or NextTokLoc but in different files.
In the test case, end location of skipped regions is in line 6 and PreTokLoc is 
also in line 6, but since they are in different files, it shouldn't be shrinked.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86116/new/

https://reviews.llvm.org/D86116

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/Inputs/comment.h
  clang/test/CoverageMapping/comment.cpp


Index: clang/test/CoverageMapping/comment.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/comment.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+
+int f() {
+  int x = 0;
+#include "Inputs/comment.h" /*
+*/
+  return x;
+}
+
+// CHECK: File 0, 3:9 -> 8:2 = #0
+// CHECK-NEXT: Expansion,File 0, 5:14 -> 5:32 = #0
+// CHECK-NEXT: Skipped,File 0, 6:1 -> 6:7 = 0
+// CHECK-NEXT: File 1, 1:1 -> 6:7 = #0
Index: clang/test/CoverageMapping/Inputs/comment.h
===
--- /dev/null
+++ clang/test/CoverageMapping/Inputs/comment.h
@@ -0,0 +1,6 @@
+
+
+
+
+
+x = 0;
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -44,7 +44,8 @@
   PP.setTokenWatcher([CoverageInfo](clang::Token Tok) {
 // Update previous token location.
 CoverageInfo->PrevTokLoc = Tok.getLocation();
-CoverageInfo->updateNextTokLoc(Tok.getLocation());
+if (Tok.getKind() != clang::tok::eod)
+  CoverageInfo->updateNextTokLoc(Tok.getLocation());
   });
   return CoverageInfo;
 }
@@ -305,20 +306,24 @@
   /// non-comment token. If shrinking the skipped range would make it empty,
   /// this returns None.
   Optional adjustSkippedRange(SourceManager &SM,
-  SpellingRegion SR,
+  SourceLocation LocStart,
+  SourceLocation LocEnd,
   SourceLocation PrevTokLoc,
   SourceLocation NextTokLoc) {
+SpellingRegion SR{SM, LocStart, LocEnd};
 // If Range begin location is invalid, it's not a comment region.
 if (PrevTokLoc.isInvalid())
   return SR;
 unsigned PrevTokLine = SM.getSpellingLineNumber(PrevTokLoc);
 unsigned NextTokLine = SM.getSpellingLineNumber(NextTokLoc);
 SpellingRegion newSR(SR);
-if (SR.LineStart == PrevTokLine) {
+if (SM.isWrittenInSameFile(LocStart, PrevTokLoc) &&
+SR.LineStart == PrevTokLine) {
   newSR.LineStart = SR.LineStart + 1;
   newSR.ColumnStart = 1;
 }
-if (SR.LineEnd == NextTokLine) {
+if (SM.isWrittenInSameFile(LocEnd, NextTokLoc) &&
+SR.LineEnd == NextTokLine) {
   newSR.LineEnd = SR.LineEnd - 1;
   newSR.ColumnEnd = SR.ColumnStart + 1;
 }
@@ -354,14 +359,13 @@
   auto CovFileID = getCoverageFileID(LocStart);
   if (!CovFileID)
 continue;
-  SpellingRegion SR{SM, LocStart, LocEnd};
-  if (Optional res =
-  adjustSkippedRange(SM, SR, I.PrevTokLoc, I.NextTokLoc))
-SR = res.getValue();
-  else
+  Optional SR =
+  adjustSkippedRange(SM, LocStart, LocEnd, I.PrevTokLoc, I.NextTokLoc);
+  if (!SR.hasValue())
 continue;
   auto Region = CounterMappingRegion::makeSkipped(
-  *CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd);
+  *CovFileID, SR->LineStart, SR->ColumnStart, SR->LineEnd,
+  SR->ColumnEnd);
   // Make sure that we only collect the regions that are inside
   // the source code of this function.
   if (Region.LineStart >= FileLineRanges[*CovFileID].first &&


Index: clang/test/CoverageMapping/comment.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/comment.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+
+int f() {
+  int x = 0;
+#include "Inputs/comment.h" /*
+*/
+  return x;
+}
+
+// CHECK: File 0, 3:9 -> 8:2 = #0
+// CHECK-NEXT: Expansion,File 0, 5:14 -> 5:32 = #0
+// CHECK-NEXT: Skipped,File 0, 6:1 -> 6:7 = 0
+// CHECK-NEXT: File 1, 1:1 -> 6:7 = #0
Index: clang/test/CoverageMapping/Inputs/comment.h
===
--- /dev/null
+++ clang/test/CoverageMapping/Inputs/comment.h
@@ -0,0 +1,6 @@
+
+
+
+
+
+x = 0;
Index: clang/lib/CodeGen/Co

[PATCH] D86105: [darwin] Disable the -Wpsabi warning

2020-08-17 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 286181.
arphaman added a comment.

add missing test fix


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86105/new/

https://reviews.llvm.org/D86105

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/target-avx-abi-diag.c
  clang/test/CodeGen/target-builtin-error-3.c


Index: clang/test/CodeGen/target-builtin-error-3.c
===
--- clang/test/CodeGen/target-builtin-error-3.c
+++ clang/test/CodeGen/target-builtin-error-3.c
@@ -24,6 +24,5 @@
 }
 void avx_test( uint16_t *destData, float16 argbF)
 {
-  // expected-warning@+1{{AVX vector argument of type 'float16' (vector of 16 
'float' values) without 'avx512f' enabled changes the ABI}}
   ((half16U *)destData)[0] = convert_half(argbF);
 }
Index: clang/test/CodeGen/target-avx-abi-diag.c
===
--- clang/test/CodeGen/target-avx-abi-diag.c
+++ clang/test/CodeGen/target-avx-abi-diag.c
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -verify=no256,no512 -o - -S
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx 
-verify=no512 -o - -S
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu 
-verify=no256,no512,no256-err,no512-err -o - -S
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx 
-verify=no512,no512-err -o - -S
 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx512f 
-verify=both -o - -S
+
+// RUN: %clang_cc1 %s -triple=x86_64-apple-macos -verify=no256-err,no512-err 
-o - -S
+// RUN: %clang_cc1 %s -triple=x86_64-apple-macos -target-feature +avx 
-verify=no512-err -o - -S
 // REQUIRES: x86-registered-target
 
 // both-no-diagnostics
@@ -31,12 +34,12 @@
 // If only 1 side has an attribute, error.
 void call_errors(void) {
   avx256Type t1;
-  takesAvx256(t1); // no256-error {{AVX vector argument of type 'avx256Type' 
(vector of 16 'short' values) without 'avx' enabled changes the ABI}}
+  takesAvx256(t1); // no256-err-error {{AVX vector argument of type 
'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the 
ABI}}
   avx512fType t2;
-  takesAvx512(t2); // no512-error {{AVX vector argument of type 'avx512fType' 
(vector of 32 'short' values) without 'avx512f' enabled changes the ABI}}
+  takesAvx512(t2); // no512-err-error {{AVX vector argument of type 
'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes 
the ABI}}
 
-  variadic_err(1, t1); // no256-error {{AVX vector argument of type 
'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the 
ABI}}
-  variadic_err(3, t2); // no512-error {{AVX vector argument of type 
'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes 
the ABI}}
+  variadic_err(1, t1); // no256-err-error {{AVX vector argument of type 
'avx256Type' (vector of 16 'short' values) without 'avx' enabled changes the 
ABI}}
+  variadic_err(3, t2); // no512-err-error {{AVX vector argument of type 
'avx512fType' (vector of 32 'short' values) without 'avx512f' enabled changes 
the ABI}}
 }
 
 // These two don't diagnose anything, since these are valid calls.
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2508,12 +2508,17 @@
  const llvm::StringMap &CallerMap,
  const llvm::StringMap &CalleeMap,
  QualType Ty, StringRef Feature,
- bool IsArgument) {
+ bool IsArgument, const llvm::Triple &TT) {
   bool CallerHasFeat = CallerMap.lookup(Feature);
   bool CalleeHasFeat = CalleeMap.lookup(Feature);
-  if (!CallerHasFeat && !CalleeHasFeat)
+  if (!CallerHasFeat && !CalleeHasFeat) {
+// Darwin doesn't enable AVX/AVX512 by default to support Rosetta 2, so 
it's
+// user's responsibility to use AVX/AVX512 safely.
+if (TT.isOSDarwin())
+  return false;
 return Diag.Report(CallLoc, diag::warn_avx_calling_convention)
<< IsArgument << Ty << Feature;
+  }
 
   // Mixing calling conventions here is very clearly an error.
   if (!CallerHasFeat || !CalleeHasFeat)
@@ -2531,13 +2536,14 @@
   const llvm::StringMap &CalleeMap, QualType Ty,
   bool IsArgument) {
   uint64_t Size = Ctx.getTypeSize(Ty);
+  const llvm::Triple &TT = Ctx.getTargetInfo().getTriple();
   if (Size > 256)
 return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty,
-"avx512f", IsArgument);
+"avx512f", IsArgument, TT);
 
   if (Size > 128)
 return checkAVXParamFeature(Diag, CallLoc, CallerMap, CalleeMap, Ty, "avx",
-IsArgument);
+IsArgument, TT);
 
   return f

[clang] c7ec3a7 - [PowerPC] Implement Vector Extract Mask builtins in LLVM/Clang

2020-08-17 Thread Amy Kwan via cfe-commits

Author: Amy Kwan
Date: 2020-08-17T21:14:17-05:00
New Revision: c7ec3a7e338cd8e58424a66d29162e9b6a5847f7

URL: 
https://github.com/llvm/llvm-project/commit/c7ec3a7e338cd8e58424a66d29162e9b6a5847f7
DIFF: 
https://github.com/llvm/llvm-project/commit/c7ec3a7e338cd8e58424a66d29162e9b6a5847f7.diff

LOG: [PowerPC] Implement Vector Extract Mask builtins in LLVM/Clang

This patch implements the vec_extractm function prototypes in altivec.h in
order to utilize the vector extract with mask instructions introduced in 
Power10.

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

Added: 
llvm/test/CodeGen/PowerPC/p10-vector-mask-ops.ll

Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/Headers/altivec.h
clang/test/CodeGen/builtins-ppc-p10vector.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCInstrPrefix.td

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index b79ed41284ac..73c607800415 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -298,6 +298,13 @@ BUILTIN(__builtin_altivec_vrldmi, 
"V2ULLiV2ULLiV2ULLiV2ULLi", "")
 BUILTIN(__builtin_altivec_vrlwnm, "V4UiV4UiV4Ui", "")
 BUILTIN(__builtin_altivec_vrldnm, "V2ULLiV2ULLiV2ULLi", "")
 
+// P10 Vector Extract with Mask built-ins.
+BUILTIN(__builtin_altivec_vextractbm, "UiV16Uc", "")
+BUILTIN(__builtin_altivec_vextracthm, "UiV8Us", "")
+BUILTIN(__builtin_altivec_vextractwm, "UiV4Ui", "")
+BUILTIN(__builtin_altivec_vextractdm, "UiV2ULLi", "")
+BUILTIN(__builtin_altivec_vextractqm, "UiV1ULLLi", "")
+
 // P10 Vector Parallel Bits built-ins.
 BUILTIN(__builtin_altivec_vpdepd, "V2ULLiV2ULLiV2ULLi", "")
 BUILTIN(__builtin_altivec_vpextd, "V2ULLiV2ULLiV2ULLi", "")

diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index ac4182613cdd..b1e70f6c41bb 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -16815,6 +16815,34 @@ static vector signed char __ATTRS_o_ai vec_nabs(vector 
signed char __a) {
 }
 
 #ifdef __POWER10_VECTOR__
+
+/* vec_extractm */
+
+static __inline__ unsigned int __ATTRS_o_ai
+vec_extractm(vector unsigned char __a) {
+  return __builtin_altivec_vextractbm(__a);
+}
+
+static __inline__ unsigned int __ATTRS_o_ai
+vec_extractm(vector unsigned short __a) {
+  return __builtin_altivec_vextracthm(__a);
+}
+
+static __inline__ unsigned int __ATTRS_o_ai
+vec_extractm(vector unsigned int __a) {
+  return __builtin_altivec_vextractwm(__a);
+}
+
+static __inline__ unsigned int __ATTRS_o_ai
+vec_extractm(vector unsigned long long __a) {
+  return __builtin_altivec_vextractdm(__a);
+}
+
+static __inline__ unsigned int __ATTRS_o_ai
+vec_extractm(vector unsigned __int128 __a) {
+  return __builtin_altivec_vextractqm(__a);
+}
+
 /* vec_pdep */
 
 static __inline__ vector unsigned long long __ATTRS_o_ai

diff  --git a/clang/test/CodeGen/builtins-ppc-p10vector.c 
b/clang/test/CodeGen/builtins-ppc-p10vector.c
index a575f5a924c5..fe3e678a5794 100644
--- a/clang/test/CodeGen/builtins-ppc-p10vector.c
+++ b/clang/test/CodeGen/builtins-ppc-p10vector.c
@@ -97,6 +97,36 @@ vector unsigned long long test_vpextd(void) {
   return vec_pext(vulla, vullb);
 }
 
+unsigned int test_vec_extractm_uc(void) {
+  // CHECK: @llvm.ppc.altivec.vextractbm(<16 x i8> %{{.+}})
+  // CHECK-NEXT: ret i32
+  return vec_extractm(vuca);
+}
+
+unsigned int test_vec_extractm_us(void) {
+  // CHECK: @llvm.ppc.altivec.vextracthm(<8 x i16> %{{.+}})
+  // CHECK-NEXT: ret i32
+  return vec_extractm(vusa);
+}
+
+unsigned int test_vec_extractm_ui(void) {
+  // CHECK: @llvm.ppc.altivec.vextractwm(<4 x i32> %{{.+}})
+  // CHECK-NEXT: ret i32
+  return vec_extractm(vuia);
+}
+
+unsigned int test_vec_extractm_ull(void) {
+  // CHECK: @llvm.ppc.altivec.vextractdm(<2 x i64> %{{.+}})
+  // CHECK-NEXT: ret i32
+  return vec_extractm(vulla);
+}
+
+unsigned int test_vec_extractm_u128(void) {
+  // CHECK: @llvm.ppc.altivec.vextractqm(<1 x i128> %{{.+}})
+  // CHECK-NEXT: ret i32
+  return vec_extractm(vui128a);
+}
+
 vector unsigned long long test_vcfuged(void) {
   // CHECK: @llvm.ppc.altivec.vcfuged(<2 x i64>
   // CHECK-NEXT: ret <2 x i64>

diff  --git a/llvm/include/llvm/IR/IntrinsicsPowerPC.td 
b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
index ae25bb400e46..ce4c98968a7b 100644
--- a/llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ b/llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -434,6 +434,18 @@ let TargetPrefix = "ppc" in {  // All intrinsics start 
with "llvm.ppc.".
   def int_ppc_altivec_vprtybq : GCCBuiltin<"__builtin_altivec_vprtybq">,
   Intrinsic<[llvm_v1i128_ty],[llvm_v1i128_ty],[IntrNoMem]>;
 
+  // P10 Vector Extract with Mask
+  def int_ppc_altivec_vextractbm : GCCBuiltin<"__builtin_altivec_vextractbm">,
+  Intrinsic<[llvm_i32_ty], [llvm_v16i8_ty], [IntrNoMem]>;
+  def int_ppc_altive

[PATCH] D82675: [PowerPC] Implement Vector Extract Mask builtins in LLVM/Clang

2020-08-17 Thread Amy Kwan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7ec3a7e338c: [PowerPC] Implement Vector Extract Mask 
builtins in LLVM/Clang (authored by amyk).

Changed prior to commit:
  https://reviews.llvm.org/D82675?vs=281107&id=286190#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82675/new/

https://reviews.llvm.org/D82675

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/p10-vector-mask-ops.ll

Index: llvm/test/CodeGen/PowerPC/p10-vector-mask-ops.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/p10-vector-mask-ops.ll
@@ -0,0 +1,66 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
+; RUN:   FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
+; RUN:   FileCheck %s
+
+; This test case aims to test the vector mask manipulation operations
+; on Power10.
+
+declare i32 @llvm.ppc.altivec.vextractbm(<16 x i8>)
+declare i32 @llvm.ppc.altivec.vextracthm(<8 x i16>)
+declare i32 @llvm.ppc.altivec.vextractwm(<4 x i32>)
+declare i32 @llvm.ppc.altivec.vextractdm(<2 x i64>)
+declare i32 @llvm.ppc.altivec.vextractqm(<1 x i128>)
+
+define i32 @test_vextractbm(<16 x i8> %a) {
+; CHECK-LABEL: test_vextractbm:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextractbm r3, v2
+; CHECK-NEXT:blr
+entry:
+  %ext = tail call i32 @llvm.ppc.altivec.vextractbm(<16 x i8> %a)
+  ret i32 %ext
+}
+
+define i32 @test_vextracthm(<8 x i16> %a) {
+; CHECK-LABEL: test_vextracthm:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextracthm r3, v2
+; CHECK-NEXT:blr
+entry:
+  %ext = tail call i32 @llvm.ppc.altivec.vextracthm(<8 x i16> %a)
+  ret i32 %ext
+}
+
+define i32 @test_vextractwm(<4 x i32> %a) {
+; CHECK-LABEL: test_vextractwm:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextractwm r3, v2
+; CHECK-NEXT:blr
+entry:
+  %ext = tail call i32 @llvm.ppc.altivec.vextractwm(<4 x i32> %a)
+  ret i32 %ext
+}
+
+define i32 @test_vextractdm(<2 x i64> %a) {
+; CHECK-LABEL: test_vextractdm:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextractdm r3, v2
+; CHECK-NEXT:blr
+entry:
+  %ext = tail call i32 @llvm.ppc.altivec.vextractdm(<2 x i64> %a)
+  ret i32 %ext
+}
+
+define i32 @test_vextractqm(<1 x i128> %a) {
+; CHECK-LABEL: test_vextractqm:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vextractqm r3, v2
+; CHECK-NEXT:blr
+entry:
+  %ext = tail call i32 @llvm.ppc.altivec.vextractqm(<1 x i128> %a)
+  ret i32 %ext
+}
Index: llvm/lib/Target/PowerPC/PPCInstrPrefix.td
===
--- llvm/lib/Target/PowerPC/PPCInstrPrefix.td
+++ llvm/lib/Target/PowerPC/PPCInstrPrefix.td
@@ -965,19 +965,24 @@
   RegConstraint<"$vDi = $vD">, NoEncode<"$vDi">;
   def VEXTRACTBM : VXForm_RD5_XO5_RS5<1602, 8, (outs gprc:$rD), (ins vrrc:$vB),
   "vextractbm $rD, $vB", IIC_VecGeneral,
-  []>;
+  [(set i32:$rD,
+  (int_ppc_altivec_vextractbm v16i8:$vB))]>;
   def VEXTRACTHM : VXForm_RD5_XO5_RS5<1602, 9, (outs gprc:$rD), (ins vrrc:$vB),
   "vextracthm $rD, $vB", IIC_VecGeneral,
-  []>;
+  [(set i32:$rD,
+  (int_ppc_altivec_vextracthm v8i16:$vB))]>;
   def VEXTRACTWM : VXForm_RD5_XO5_RS5<1602, 10, (outs gprc:$rD), (ins vrrc:$vB),
   "vextractwm $rD, $vB", IIC_VecGeneral,
-  []>;
+  [(set i32:$rD,
+  (int_ppc_altivec_vextractwm v4i32:$vB))]>;
   def VEXTRACTDM : VXForm_RD5_XO5_RS5<1602, 11, (outs gprc:$rD), (ins vrrc:$vB),
   "vextractdm $rD, $vB", IIC_VecGeneral,
-  []>;
+  [(set i32:$rD,
+  (int_ppc_altivec_vextractdm v2i64:$vB))]>;
   def VEXTRACTQM : VXForm_RD5_XO5_RS5<1602, 12, (outs gprc:$rD), (ins vrrc:$vB),
   "vextractqm $rD, $vB", IIC_VecGeneral,
-  []>;
+  [(set i32:$rD,
+ 

  1   2   >