[PATCH] D79998: Add AST_SIGNATURE record to unhashed control block of pcm files (Patch series 2/3)

2020-05-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 265262.
dang added a comment.
Herald added a subscriber: ormris.

Add a small bug fix and test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79998

Files:
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h


Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t1
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ 
-fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t2
+// RUN: cat %t1 | grep "remark: building module 'MyHeader2'" | cut -d "'" -f 4 
\
+// RUN:  | while read -r MODULE; do llvm-bcanalyzer --dump --disable-histogram 
\
+// RUN:  $MODULE | grep "AST_SIGNATURE" > %t1.sig; done
+// RUN: cat %t2 | grep "remark: building module 'MyHeader2'" | cut -d "'" -f 4 
\
+// RUN:  | while read -r MODULE; do llvm-bcanalyzer --dump --disable-histogram 
\
+// RUN:  $MODULE | grep "AST_SIGNATURE" > %t1.sig; done
+// RUN: diff %t1.sig %t2.sig
+
+#include "my_header_2.h"
+
+my_int var = 42;


Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t1
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t2
+// RUN: cat %t1 | grep "remark: building module 'MyHeader2'" | cut -d "'" -f 4 \
+// RUN:  | while read -r MODULE; do llvm-bcanalyzer --dump --disable-histogram \
+// RUN:  $MODULE | grep "AST_SIGNATURE" > %t1.sig; done
+// RUN: cat %t2 | grep "remark: building module 'MyHeader2'" | cut -d "'" -f 4 \
+// RUN:  | while read -r MODULE; do llvm-bcanalyzer --dump --disable-histogram \
+// RUN:  $MODULE | grep "AST_SIGNATURE" > %t1.sig; done
+// RUN: diff %t1.sig %t2.sig
+
+#include "my_header_2.h"
+
+my_int var = 42;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79998: Add AST_SIGNATURE record to unhashed control block of pcm files (Patch series 2/3)

2020-05-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 265263.
dang added a comment.

Uploaded the wrong diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79998

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t1
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t2
+// RUN: cat %t1 | grep "remark: building module 'MyHeader2'" | cut -d "'" -f 4 \
+// RUN:  | while read -r MODULE; do llvm-bcanalyzer --dump --disable-histogram \
+// RUN:  $MODULE | grep "AST_SIGNATURE" > %t1.sig; done
+// RUN: cat %t2 | grep "remark: building module 'MyHeader2'" | cut -d "'" -f 4 \
+// RUN:  | while read -r MODULE; do llvm-bcanalyzer --dump --disable-histogram \
+// RUN:  $MODULE | grep "AST_SIGNATURE" > %t1.sig; done
+// RUN: diff %t1.sig %t2.sig
+
+#include "my_header_2.h"
+
+my_int var = 42;
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -64,6 +64,7 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTRecordWriter.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
@@ -961,6 +962,7 @@
 
   BLOCK(UNHASHED_CONTROL_BLOCK);
   RECORD(SIGNATURE);
+  RECORD(AST_SIGNATURE);
   RECORD(DIAGNOSTIC_OPTIONS);
   RECORD(DIAG_PRAGMA_MAPPINGS);
 
@@ -1044,8 +1046,9 @@
   return Signature;
 }
 
-ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
-  ASTContext &Context) {
+ASTFileSignature ASTWriter::writeUnhashedControlBlock(
+Preprocessor &PP, ASTContext &Context,
+const std::pair ASTBlockRange) {
   // Flush first to prepare the PCM hash (signature).
   Stream.FlushToWord();
   auto StartOfUnhashedControl = Stream.GetCurrentBitNo() >> 3;
@@ -1062,6 +1065,11 @@
 Record.append(Signature.begin(), Signature.end());
 Stream.EmitRecord(SIGNATURE, Record);
 Record.clear();
+auto ASTSignature = createSignature(
+StringRef(Buffer.begin() + ASTBlockRange.first, ASTBlockRange.second));
+Record.append(ASTSignature.begin(), ASTSignature.end());
+Stream.EmitRecord(AST_SIGNATURE, Record);
+Record.clear();
   }
 
   // Diagnostic options.
@@ -4548,6 +4556,8 @@
   populateInputFileIDs(Context.SourceMgr);
 
   // Write the remaining AST contents.
+  Stream.FlushToWord();
+  auto StartOfASTBlock = Stream.GetCurrentBitNo() >> 3;
   Stream.EnterSubblock(AST_BLOCK_ID, 5);
 
   // This is so that older clang versions, before the introduction
@@ -4679,9 +4689,9 @@
 //   c++-base-specifiers-id:i32
 //   type-id:i32)
 //
-// module-kind is the ModuleKind enum value. If it is MK_PrebuiltModule or
-// MK_ExplicitModule, then the module-name is the module name. Otherwise,
-// it is the module file name.
+// module-kind is the ModuleKind enum value. If it is MK_PrebuiltModule,
+// MK_ExplicitModule or MK_ImplicitModule, then the module-name is the
+// module name. Otherwise, it is the module file name.
 auto Abbrev = s

[PATCH] D79993: Place control block after AST block in PCM files (Patch series 1/3)

2020-05-21 Thread Daniel Grumberg via Phabricator via cfe-commits
dang abandoned this revision.
dang added a comment.
Herald added a subscriber: sstefan1.

After some further discussion offline with @Bigcheese the cleaner course of 
action is to make the AST block relocatable see revision D80383 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79993



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


[PATCH] D79998: Add AST_SIGNATURE record to unhashed control block of pcm files (Patch series 2/3)

2020-05-21 Thread Daniel Grumberg via Phabricator via cfe-commits
dang abandoned this revision.
dang added a comment.

This revision is superseded by D80383 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79998



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


[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-05-21 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

This record is constructed by hashing the bytes of the AST block in a similiar
fashion to the SIGNATURE record. This new signature only means anything if the
AST block is fully relocatable, i.e. it does not embed absolute offsets within
the PCM file. This change ensure this does not happen by repalcing these offsets
with offsets relative to the start of the AST block.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t1
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t2
+// RUN: sed -n "s/.* building module 'MyHeader2' as '\(.*\)' .*/\1/gp" %t1 \
+// RUN:   | xargs llvm-bcanalyzer --dump --disable-histogram | cat > %t1.dump
+// RUN: sed -n "s/.* building module 'MyHeader2' as '\(.*\)' .*/\1/gp" %t2 \
+// RUN:   | xargs llvm-bcanalyzer --dump --disable-histogram | cat > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2428,7 +2428,7 @@
   W.Visit(D);
 
   // Emit this declaration to the bitstream.
-  uint64_t Offset = W.Emit(D);
+  uint64_t Offset = W.Emit(D) - ASTBlockRange.first;
 
   // Record the offset for this declaration
   SourceLocation Loc = D->getLocation();
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -65,6 +65,7 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "clang/Serialization/ModuleFile.h"
@@ -960,6 +961,7 @@
 
   BLOCK(UNHASHED_CONTROL_BLOCK);
   RECORD(SIGNATURE);
+  RECORD(AST_SIGNATURE);
   RECORD(DIAGNOSTIC_OPTIONS);
   RECORD(DIAG_PRAGMA_MAPPINGS);
 
@@ -1025,22 +1027,38 @@
   return Filename + Pos;
 }
 
-ASTFileSignature ASTWriter::createSignature(StringRef Bytes) {
-  // Calculate the hash till start of UNHASHED_CONTROL_BLOCK.
+std::pair
+ASTWriter::createSignature(StringRef AllBytes, StringRef ASTBlockBytes) {
+  // Calculate the hash of the AST block
   llvm::SHA1 Hasher;
-  Hasher.update(ArrayRef(Bytes.bytes_begin(), Bytes.size()));
+  Hasher.update(ASTBlockBytes);
   auto Hash = Hasher.result();
 
   // Convert to an array [5*i32].
-  ASTFileSignature Signature;
   auto LShift = [&](unsigned char Val, unsigned Shift) {
 return (uint32_t)Val << Shift;
   };
+
+  ASTFileSignature ASTSignature;
+  for (int 

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-05-21 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 265530.
dang added a comment.
Herald added a reviewer: jdoerfert.
Herald added subscribers: sstefan1, ormris.

Formatting fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t1
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t2
+// RUN: sed -n "s/.* building module 'MyHeader2' as '\(.*\)' .*/\1/gp" %t1 \
+// RUN:   | xargs llvm-bcanalyzer --dump --disable-histogram | cat > %t1.dump
+// RUN: sed -n "s/.* building module 'MyHeader2' as '\(.*\)' .*/\1/gp" %t2 \
+// RUN:   | xargs llvm-bcanalyzer --dump --disable-histogram | cat > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2428,7 +2428,7 @@
   W.Visit(D);
 
   // Emit this declaration to the bitstream.
-  uint64_t Offset = W.Emit(D);
+  uint64_t Offset = W.Emit(D) - ASTBlockRange.first;
 
   // Record the offset for this declaration
   SourceLocation Loc = D->getLocation();
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/ASTRecordWriter.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "clang/Serialization/ModuleFile.h"
 #include "clang/Serialization/ModuleFileExtension.h"
@@ -960,6 +961,7 @@
 
   BLOCK(UNHASHED_CONTROL_BLOCK);
   RECORD(SIGNATURE);
+  RECORD(AST_SIGNATURE);
   RECORD(DIAGNOSTIC_OPTIONS);
   RECORD(DIAG_PRAGMA_MAPPINGS);
 
@@ -1025,22 +1027,38 @@
   return Filename + 

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-05-21 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 265535.
dang added a comment.

Accidently deleted a line in the previous update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,21 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t1
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t %s -Rmodule-build 2> %t2
+// RUN: sed -n "s/.* building module 'MyHeader2' as '\(.*\)' .*/\1/gp" %t1 \
+// RUN:   | xargs llvm-bcanalyzer --dump --disable-histogram | cat > %t1.dump
+// RUN: sed -n "s/.* building module 'MyHeader2' as '\(.*\)' .*/\1/gp" %t2 \
+// RUN:   | xargs llvm-bcanalyzer --dump --disable-histogram | cat > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2428,7 +2428,7 @@
   W.Visit(D);
 
   // Emit this declaration to the bitstream.
-  uint64_t Offset = W.Emit(D);
+  uint64_t Offset = W.Emit(D) - ASTBlockRange.first;
 
   // Record the offset for this declaration
   SourceLocation Loc = D->getLocation();
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/ASTRecordWriter.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "clang/Serialization/ModuleFile.h"
 #include "clang/Serialization/ModuleFileExtension.h"
@@ -960,6 +961,7 @@
 
   BLOCK(UNHASHED_CONTROL_BLOCK);
   RECORD(SIGNATURE);
+  RECORD(AST_SIGNATURE);
   RECORD(DIAGNOSTIC_OPTIONS);
   RECORD(DIAG_PRAGMA_MAPPINGS);
 
@@ -1025,22 +1027,38 @@
   return Filename + Pos;
 }
 
-ASTFileSignature ASTWriter::createSig

[PATCH] D80003: [clang][clang-scan-deps] Add a mode that can compute overhead in duplicated module builds

2020-05-22 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 265676.
dang added a comment.

Rebase this on top of the new AST Signature patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80003

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -6,12 +6,14 @@
 //
 //===--===//
 
+#include "clang/Basic/Module.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
@@ -20,6 +22,7 @@
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/Threading.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 
@@ -165,6 +168,13 @@
 llvm::cl::init(false),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt GatherMetrics(
+"metrics", llvm::cl::Optional,
+llvm::cl::desc(
+"Gather metrics during tool operation to measure overhead of modules "
+"built in explicit mode with respect to implicit modules."),
+llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
+
 } // end anonymous namespace
 
 /// \returns object-file path derived from source-file path.
@@ -327,6 +337,65 @@
 OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
   }
 
+  void computeAndPrintBuildMetrics(raw_ostream &OS) {
+std::unordered_map
+RelaxedHashesEfficiencyInfo;
+std::set UniqueModuleSignatures;
+for (auto &&M : Modules) {
+  std::string RelaxedHashModule =
+  M.second.ModuleName + '-' + M.second.RelaxedContextHash;
+  auto &BuiltModulesInfo = RelaxedHashesEfficiencyInfo[RelaxedHashModule];
+  BuiltModulesInfo.BuiltModules.push_back(&M.second);
+  auto InsertionResult =
+  UniqueModuleSignatures.insert(M.second.ModuleSignature);
+  if (InsertionResult.second)
+BuiltModulesInfo.UniqueASTFileSignatures++;
+}
+
+size_t TotalStrictContextHashModules = Modules.size();
+size_t TotalRelaxedHashModules = RelaxedHashesEfficiencyInfo.size();
+auto PercentageModuleNumberIncrease =
+100 * ((TotalStrictContextHashModules - TotalRelaxedHashModules) /
+   TotalRelaxedHashModules);
+
+OS << "Total relaxed hash modules: " << TotalRelaxedHashModules << "\n";
+OS << "Total unique AST signatures: " << UniqueModuleSignatures.size()
+   << "\n";
+OS << "Total strict context hash modules: " << TotalStrictContextHashModules
+   << "\n";
+OS << "Module number increase: " << PercentageModuleNumberIncrease
+   << "%\n\n";
+
+OS << "Details:\n";
+for (auto &&It : RelaxedHashesEfficiencyInfo) {
+  auto &Duplicates = It.second.BuiltModules;
+  size_t NumDuplicates = Duplicates.size();
+
+  assert(NumDuplicates > 0 && "Cannot have a relaxed hash module that "
+  "doesn't map to at least a strict"
+  "one!");
+
+  if (NumDuplicates > 1) {
+OS << "Relaxed hash module: " << It.first << " gets duplicated as ("
+   << It.second.UniqueASTFileSignatures << "/" << NumDuplicates
+   << ") modules:\n\n";
+
+auto OutputModuleDep = [](raw_ostream &OS, ModuleDeps *MD) {
+  OS << MD->ModuleName << "-" << MD->ContextHash;
+};
+
+auto DuplicatesIt = Duplicates.begin();
+OutputModuleDep(OS, *DuplicatesIt);
+++DuplicatesIt;
+for (auto End = Duplicates.end(); DuplicatesIt != End; ++DuplicatesIt) {
+  OS << "; ";
+  OutputModuleDep(OS, *DuplicatesIt);
+}
+OS << "\n\n";
+  }
+}
+  }
+
 private:
   StringRef lookupPCMPath(ClangModuleDep CMD) {
 return Modules[ContextModulePair{CMD.ContextHash, CMD.ModuleName, 0}]
@@ -340,6 +409,11 @@
 return I->second;
   };
 
+  struct BuiltModulesEfficiencyInfo {
+std::vector BuiltModules;
+size_t UniqueASTFileSignatures;
+  };
+
   struct ContextModulePair {
 std::string ContextHash;
 std::string ModuleName;
@@ -543,5 +617,8

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-05-25 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 265848.
dang added a comment.

This should address the Windows test failure as well as some offline feedback

- Ensure that DeclOffset instances can only be read by providing an offset to 
the AST block
- Simplify ASTSignature test by using -fdisable-module-hash


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t1.pcm
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t2.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t1.pcm > %t1.dump
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t2.pcm > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[AST_SIGNATURE:]]
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[AST_SIGNATURE]]
+// CHECK-NOT: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2434,12 +2434,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.emplace_back(Loc, Offset);
+DeclOffsets.emplace_back(Loc, Offset, ASTBlockRange.first);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].setBitOffset(Offset);
+DeclOffsets[Index].setBitOffset(Offset, ASTBlockRange.first);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-05-26 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 266195.
dang added a comment.

Address some code review comments and sketch support for options that take a 
single value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -9,6 +9,7 @@
 #include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
@@ -33,6 +34,22 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsBit("IsPositive");
+  OS << ",";
+  OS << R->getValueAsString("DefaultValue");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsString("DefaultValue");
+  OS << ", ";
+  OS << R->getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R->getValueAsString("Denormalizer");
+}
+
+static void emitMarshallingInfoEnum(raw_ostream &OS, const Record *R) {}
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +152,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -149,7 +162,7 @@
 write_cstring(OS, R.getValueAsString("Name"));
 
 // The option identifier name.
-OS  << ", "<< getOptionName(R);
+OS << ", " << getOptionName(R);
 
 // The option kind.
 OS << ", " << R.getValueAsDef("Kind")->getValueAsString("Name");
@@ -190,8 +203,7 @@
 int NumFlags = 0;
 const ListInit *LI = R.getValueAsListInit("Flags");
 for (Init *I : *LI)
-  OS << (NumFlags++ ? " | " : "")
- << cast(I)->getDef()->getName();
+  OS << (NumFlags++ ? " | " : "") << cast(I)->getDef()->getName();
 if (GroupFlags) {
   for (Init *I : *GroupFlags)
 OS << (NumFlags++ ? " | " : "")
@@ -224,11 +236,50 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
 
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
+
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
 
+  OS << "#ifdef OPTION_WITH_MARSHALLING\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+
+if (!isa(R.getValueInit("MarshallingInfo"))) {
+  Record *MarshallingInfoRecord =
+  cast(R.getValueInit("MarshallingInfo"))->getDef();
+  StringRef KindStr = MarshallingInfoRecord->getValueAsString("Kind");
+  auto KindInfoPair =
+  StringSwitch>>(
+  KindStr)
+  .Case("flag", std::make_pair("OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag))
+  .Case("string", std::make_pair("OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString))
+  .Case("enum", std::make_pair("OPTION_WITH_MARSHALLING_ENUM",
+   &emitMarshallingInfoEnum))
+  .Default(std::make_pair("", nullptr));
+  OS << KindInfoPair.first << "(";
+  WriteOptRecordFields(OS, R);
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsBit("ShouldAlwaysEmit");
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsString("KeyPath");
+  OS << ", ";
+  KindInfoPair.second(OS, MarshallingInfoRecord);
+  OS << ")\n";
+}
+  }
+  OS << "#endif // OPTION_WITH_MARSHALLING\n";
+
   OS << "\n";
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -80,6 +80,19 @@
   list Flags = [];
 }
 
+// Add support for g

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-05-26 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 5 inline comments as done.
dang added inline comments.



Comment at: clang/include/clang/Frontend/CompilerInvocation.h:156
   /// \param [out] Res - The resulting invocation.
+  /// \param [in] CommandLineArgs - Array of argument strings, this should not
+  /// contain "-cc1".

Bigcheese wrote:
> Is this really a should not, or is it must not?
You're right updated the wording to be more accurate



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3607
+VALUES, KEYPATH, IS_POSITIVE, DEFAULT_VALUE)   
\
+  if (Option::KIND##Class == Option::FlagClass)
\
+Res.KEYPATH = Args.hasArg(OPT_##ID) && IS_POSITIVE;

Bigcheese wrote:
> How would this handle other option classes? I think it would be good to 
> include a few different types of options in the first patch.
I updated the patch to handle options that take a value. This doesn't show how 
to handle everything yet (it is missing how to handle options that take 
multiple values notably) although there are not that many of them (a quick skim 
of the code seems to indicate there are less than 100)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796



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


[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

I made the decision to make all relative offsets relative to the start of the 
AST block rather than their own sub-block or a neighboring block, in order to 
prevent adding complexity in `ASTReader`. My reasoning that it would be best if 
the reader didn't have to keep track of a bunch of offsets inside the bitcode 
at all times, but that it could just remember the offset of the AST block once 
and always use that for relative offsets. I agree that conceptually making the 
sub-blocks relocatable too would have been nice, but I figured it wasn't worth 
the extra complexity in the reader.




Comment at: clang/lib/Serialization/ASTWriter.cpp:1084
   PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent) {
-Signature = createSignature(StringRef(Buffer.begin(), 
StartOfUnhashedControl));
+Record.append(ASTSignature.begin(), ASTSignature.end());
+Stream.EmitRecord(AST_SIGNATURE, Record);

dexonsmith wrote:
> The default abbreviation (7-VBR) isn't great for hashes. Given that we're 
> going to have two of these records, I suggest specifying a custom 
> abbreviation.
> 
> If you were to split out a prep commit as suggested above to change 
> `SIGNATURE` to be an array of 8-bit values (instead of the current array of 
> 32-bit values), that would be a good opportunity to add an abbreviation.
I think encoding the signature as a blob makes the most sense if we make it an 
array of 20 8-bit values, which is what the hasher gives us. However it is not 
quite so simple, as it would need a big change in the way direct imports are 
serialized. The way it is currently done embeds multiple strings and signatures 
within a single unabbreviated record. I can replace the unabbreviated record 
with a sub-block that keeps track of a string table and a record for each 
import containing offsets inside the string table and blobs for the signature.



Comment at: clang/lib/Serialization/ASTWriter.cpp:4729-4733
+StringRef Name = M.Kind == MK_PrebuiltModule ||
+ M.Kind == MK_ExplicitModule ||
+ M.Kind == MK_ImplicitModule
+ ? M.ModuleName
+ : M.FileName;

dexonsmith wrote:
> Is there ever a reason to use `M.FileName` here, or is that always redundant 
> with what's in the control block? I wonder if we can just remove this 
> complexity.
> 
The control block only tracks this information for direct imports although it 
can maybe be extended to do keep track of this for all dependencies. This bit 
of the table could then become and index inside the `IMPORTS` record in the 
control block.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:2437
   if (DeclOffsets.size() == Index)
-DeclOffsets.emplace_back(Loc, Offset);
+DeclOffsets.emplace_back(Loc, Offset, ASTBlockRange.first);
   else if (DeclOffsets.size() < Index) {

dexonsmith wrote:
> I suggest making `WriteDecls` relative to the start of the 
> `DECLTYPES_BLOCK_ID`. That will make the block itself (more) self-contained, 
> and also make the offsets smaller (and therefore cheaper to store in bitcode).
> 
> I also don't think you need to actually emit that integer, it's just an 
> implicit contract between the reader and writer.
Not sure what you mean by I don't actually need to emit that integer? If you 
mean `ASTBlockRange.first` then I don't emit it but rather pass it to the 
constructor of DeclOffset so that it performs the subtraction there. Since it 
is a self contained type, it forces the Reader to provide a value for it, 
making it harder to read the raw relative offset.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383



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


[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 4 inline comments as done.
dang added inline comments.



Comment at: clang/include/clang/Serialization/ASTBitCodes.h:396-400
   /// Record code for the signature that identifiers this AST file.
   SIGNATURE = 1,
 
+  /// Record code for the signature of the AST block.
+  AST_SIGNATURE,

dexonsmith wrote:
> These names and descriptions hard hard to differentiate. Is there another way 
> of naming these that will be more clear?
> 
> (One idea I had is to create `CONTROL_BLOCK_HASH` and `AST_BLOCK_HASH` and 
> then `SIGNATURE` could just be their hash-combine, but maybe you have another 
> idea.)
I kept the same hasher when computing both of these which mitigates the cost. I 
don't see the need for also emitting a hash for the control block, there are 
some optional records that are not in both the AST block and the control block 
anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383



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


[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 267914.
dang added a comment.

Address some of the code review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t1.pcm
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t2.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t1.pcm > %t1.dump
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t2.pcm > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[AST_BLOCK_HASH:]]
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[AST_BLOCK_HASH]]
+// CHECK-NOT: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2434,12 +2434,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.emplace_back(Loc, Offset);
+DeclOffsets.emplace_back(Loc, Offset, ASTBlockRange.first);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].setBitOffset(Offset);
+DeclOffsets[Index].setBitOffset(Offset, ASTBlockRange.first);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/ASTRecordWriter.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "clang/Serialization/ModuleFile.h"
 #inc

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/lib/Serialization/ASTWriter.cpp:1084
   PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent) {
-Signature = createSignature(StringRef(Buffer.begin(), 
StartOfUnhashedControl));
+Record.append(ASTSignature.begin(), ASTSignature.end());
+Stream.EmitRecord(AST_SIGNATURE, Record);

dang wrote:
> dexonsmith wrote:
> > The default abbreviation (7-VBR) isn't great for hashes. Given that we're 
> > going to have two of these records, I suggest specifying a custom 
> > abbreviation.
> > 
> > If you were to split out a prep commit as suggested above to change 
> > `SIGNATURE` to be an array of 8-bit values (instead of the current array of 
> > 32-bit values), that would be a good opportunity to add an abbreviation.
> I think encoding the signature as a blob makes the most sense if we make it 
> an array of 20 8-bit values, which is what the hasher gives us. However it is 
> not quite so simple, as it would need a big change in the way direct imports 
> are serialized. The way it is currently done embeds multiple strings and 
> signatures within a single unabbreviated record. I can replace the 
> unabbreviated record with a sub-block that keeps track of a string table and 
> a record for each import containing offsets inside the string table and blobs 
> for the signature.
But I do think it is outside the scope of this change to do this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383



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


[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/include/clang/Serialization/ASTBitCodes.h:396-400
   /// Record code for the signature that identifiers this AST file.
   SIGNATURE = 1,
 
+  /// Record code for the signature of the AST block.
+  AST_SIGNATURE,

dang wrote:
> dexonsmith wrote:
> > These names and descriptions hard hard to differentiate. Is there another 
> > way of naming these that will be more clear?
> > 
> > (One idea I had is to create `CONTROL_BLOCK_HASH` and `AST_BLOCK_HASH` and 
> > then `SIGNATURE` could just be their hash-combine, but maybe you have 
> > another idea.)
> I kept the same hasher when computing both of these which mitigates the cost. 
> I don't see the need for also emitting a hash for the control block, there 
> are some optional records that are not in both the AST block and the control 
> block anyway.
I also think that the `AST_BLOCK_HASH` and the `SIGNATURE` are enough 
information already. In most cases you can deduce if the control block was 
different by just checking if the signatures were different and the ASTs the 
same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383



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


[PATCH] D83940: Port HeaderSearch option flags to new option parsing system

2020-07-16 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D83892 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83940

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1885,10 +1885,6 @@
 static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
   const std::string &WorkingDir) {
   Opts.Sysroot = std::string(Args.getLastArgValue(OPT_isysroot, "/"));
-  Opts.Verbose = Args.hasArg(OPT_v);
-  Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
-  Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc);
-  Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx);
   if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
 Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0);
   Opts.ResourceDir = std::string(Args.getLastArgValue(OPT_resource_dir));
@@ -1917,24 +1913,12 @@
   }
   for (const auto *A : Args.filtered(OPT_fprebuilt_module_path))
 Opts.AddPrebuiltModulePath(A->getValue());
-  Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash);
-  Opts.ModulesHashContent = Args.hasArg(OPT_fmodules_hash_content);
-  Opts.ModulesValidateDiagnosticOptions =
-  !Args.hasArg(OPT_fmodules_disable_diagnostic_validation);
-  Opts.ImplicitModuleMaps = Args.hasArg(OPT_fimplicit_module_maps);
-  Opts.ModuleMapFileHomeIsCwd = Args.hasArg(OPT_fmodule_map_file_home_is_cwd);
   Opts.ModuleCachePruneInterval =
   getLastArgIntValue(Args, OPT_fmodules_prune_interval, 7 * 24 * 60 * 60);
   Opts.ModuleCachePruneAfter =
   getLastArgIntValue(Args, OPT_fmodules_prune_after, 31 * 24 * 60 * 60);
-  Opts.ModulesValidateOncePerBuildSession =
-  Args.hasArg(OPT_fmodules_validate_once_per_build_session);
   Opts.BuildSessionTimestamp =
   getLastArgUInt64Value(Args, OPT_fbuild_session_timestamp, 0);
-  Opts.ModulesValidateSystemHeaders =
-  Args.hasArg(OPT_fmodules_validate_system_headers);
-  Opts.ValidateASTInputFilesContent =
-  Args.hasArg(OPT_fvalidate_ast_input_files_content);
   if (const Arg *A = Args.getLastArg(OPT_fmodule_format_EQ))
 Opts.ModuleFormat = A->getValue();
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1040,6 +1040,67 @@
 
 } // Flags = [CC1Option, NoDriverOption]
 
+// HeaderSearch Options
+
+def fmodules_validate_once_per_build_session : Flag<["-"], "fmodules-validate-once-per-build-session">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Don't verify input files for the modules if the module has been "
+   "successfully validated or loaded during this build session">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ModulesValidateOncePerBuildSession", "false">;
+def fmodules_disable_diagnostic_validation : Flag<["-"], "fmodules-disable-diagnostic-validation">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Disable validation of the diagnostic options when loading the module">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ModulesValidateDiagnosticOptions", "true">, IsNegative;
+def fmodules_validate_system_headers : Flag<["-"], "fmodules-validate-system-headers">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Validate the system headers that a module depends on when loading the module">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ModulesValidateSystemHeaders", "false">;
+def fno_modules_validate_system_headers : Flag<["-"], "fno-modules-validate-system-headers">,
+  Group, Flags<[DriverOption]>;
+def fvalidate_ast_input_files_content:
+  Flag <["-"], "fvalidate-ast-input-files-content">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Compute and store the hash of input files used to build an AST."
+   " Files with mismatching mtime's are considered valid"
+   " if both contents is identical">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ValidateASTInputFilesContent", "false">;
+def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, Group,
+  Flags<[DriverOption, CC1Option]>,
+  HelpText<"Implicitly search the file system for module map files.">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ImplicitModuleMaps", "false">;
+def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
+  HelpText<"Disable builtin #include directories">,
+  MarshallingInfoFlag<"HeaderSearchOpts->UseBuiltinIncludes", "true">, IsNegative;
+def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>,
+  HelpText<"Disable standard #include directories for the C++ standard library">,
+  MarshallingInfoFlag<"HeaderSearchOpts->UseStandardCXXInclud

[PATCH] D83979: Port LangOpts option flags to new option parsing system

2020-07-16 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, sstefan1, dexonsmith, aheejin, dschuff.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Depends on D83940 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83979

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -269,7 +269,7 @@
 
 template 
 static T mergeForwardValue(T KeyPath, U Value) {
-  return Value;
+  return static_cast(Value);
 }
 
 template  static T mergeMaskValue(T KeyPath, U Value) {
@@ -285,7 +285,8 @@
   return KeyPath & Value;
 }
 
-static void FixupInvocation(CompilerInvocation &Invocation) {
+static void FixupInvocation(CompilerInvocation &Invocation,
+DiagnosticsEngine &Diags) {
   LangOptions &LangOpts = *Invocation.getLangOpts();
   DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
   CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
@@ -296,7 +297,15 @@
   CodeGenOpts.DisableFree = FrontendOpts.DisableFree;
   FrontendOpts.GenerateGlobalModuleIndex = FrontendOpts.UseGlobalModuleIndex;
 
+  LangOpts.Optimize = CodeGenOpts.OptimizationLevel != 0;
+  LangOpts.OptimizeSize = CodeGenOpts.OptimizeSize != 0;
+  LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables;
+  LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening;
+
   llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
+
+  if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
+Diags.Report(diag::warn_c_kext);
 }
 
 //===--===//
@@ -2292,9 +2301,6 @@
 }
   }
 
-  if (Args.hasArg(OPT_fno_dllexport_inlines))
-Opts.DllExportInlines = false;
-
   if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) {
 StringRef Name = A->getValue();
 if (Name == "full" || Name == "branch") {
@@ -2321,7 +2327,6 @@
   LangStd = OpenCLLangStd;
   }
 
-  Opts.SYCL = Args.hasArg(options::OPT_fsycl);
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
   if (Opts.SYCL) {
 // -sycl-std applies to any SYCL source, not only those containing kernels,
@@ -2339,9 +2344,6 @@
 }
   }
 
-  Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
-  Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);
-
   llvm::Triple T(TargetOpts.Triple);
   CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
 
@@ -2367,20 +2369,9 @@
 
   if (Args.hasArg(OPT_fno_operator_names))
 Opts.CXXOperatorNames = 0;
-
-  if (Args.hasArg(OPT_fcuda_is_device))
-Opts.CUDAIsDevice = 1;
-
-  if (Args.hasArg(OPT_fcuda_allow_variadic_functions))
-Opts.CUDAAllowVariadicFunctions = 1;
-
-  if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
-Opts.CUDAHostDeviceConstexpr = 0;
-
   if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_approx_transcendentals))
 Opts.CUDADeviceApproxTranscendentals = 1;
 
-  Opts.GPURelocatableDeviceCode = Args.hasArg(OPT_fgpu_rdc);
   if (Args.hasArg(OPT_fgpu_allow_device_init)) {
 if (Opts.HIP)
   Opts.GPUAllowDeviceInit = 1;
@@ -2388,7 +2379,6 @@
   Diags.Report(diag::warn_ignored_hip_only_option)
   << Args.getLastArg(OPT_fgpu_allow_device_init)->getAsString(Args);
   }
-  Opts.HIPUseNewLaunchAPI = Args.hasArg(OPT_fhip_new_launch_api);
   if (Opts.HIP)
 Opts.GPUMaxThreadsPerBlock = getLastArgIntValue(
 Args, OPT_gpu_max_threads_per_block_EQ, Opts.GPUMaxThreadsPerBlock);
@@ -2408,7 +2398,6 @@
 else if (Args.hasArg(OPT_fobjc_gc))
   Opts.setGC(LangOptions::HybridGC);
 else if (Args.hasArg(OPT_fobjc_arc)) {
-  Opts.ObjCAutoRefCount = 1;
   if (!Opts.ObjCRuntime.allowsARC())
 Diags.Report(diag::err_arc_unsupported_on_runtime);
 }
@@ -2438,9 +2427,6 @@
   Opts.ObjCWeak = Opts.ObjCWeakRuntime;
 }
 
-if (Args.hasArg(OPT_fno_objc_infer_related_result_type))
-  Opts.ObjCInferRelatedResultType = 0;
-
 if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime))
   Opts.ObjCSubscriptingLegacyRuntime =
 (Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX);
@@ -2469,18 +2455,6 @@
   Opts.GNUInline = 1;
   }
 
-  if (Args.hasArg(OPT_fapple_kext)) {
-if (!Opts.CPlusPlus)
-  Diags.Report(diag::warn_c_kext);
-else
-  Opts.AppleKext = 1;
-  }
-
-  if (Args.hasArg(OPT_print_ivar_layout))
-Opts.ObjCGCBitmapPrint = 1;
-
-  if (Args.hasArg(OPT_fno_constant_cfstrings))
-Opts.NoConstantCFStrings = 1;
   if (const auto *A = Args.getLastArg(OPT_fcf_runtime_abi_EQ))
 Opts.CFRuntime =
 llvm::StringSwitch(A->getValue())
@@ -2492,12 

[PATCH] D83979: Port LangOpts option flags to new option parsing system

2020-07-17 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 278729.
dang added a comment.

Fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83979

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -269,7 +269,7 @@
 
 template 
 static T mergeForwardValue(T KeyPath, U Value) {
-  return Value;
+  return static_cast(Value);
 }
 
 template  static T mergeMaskValue(T KeyPath, U Value) {
@@ -285,7 +285,8 @@
   return KeyPath & Value;
 }
 
-static void FixupInvocation(CompilerInvocation &Invocation) {
+static void FixupInvocation(CompilerInvocation &Invocation,
+DiagnosticsEngine &Diags) {
   LangOptions &LangOpts = *Invocation.getLangOpts();
   DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
   CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
@@ -296,7 +297,15 @@
   CodeGenOpts.DisableFree = FrontendOpts.DisableFree;
   FrontendOpts.GenerateGlobalModuleIndex = FrontendOpts.UseGlobalModuleIndex;
 
+  LangOpts.Optimize = CodeGenOpts.OptimizationLevel != 0;
+  LangOpts.OptimizeSize = CodeGenOpts.OptimizeSize != 0;
+  LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables;
+  LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening;
+
   llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
+
+  if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
+Diags.Report(diag::warn_c_kext);
 }
 
 //===--===//
@@ -2292,9 +2301,6 @@
 }
   }
 
-  if (Args.hasArg(OPT_fno_dllexport_inlines))
-Opts.DllExportInlines = false;
-
   if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) {
 StringRef Name = A->getValue();
 if (Name == "full" || Name == "branch") {
@@ -2321,7 +2327,6 @@
   LangStd = OpenCLLangStd;
   }
 
-  Opts.SYCL = Args.hasArg(options::OPT_fsycl);
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
   if (Opts.SYCL) {
 // -sycl-std applies to any SYCL source, not only those containing kernels,
@@ -2339,9 +2344,6 @@
 }
   }
 
-  Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
-  Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);
-
   llvm::Triple T(TargetOpts.Triple);
   CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
 
@@ -2367,20 +2369,9 @@
 
   if (Args.hasArg(OPT_fno_operator_names))
 Opts.CXXOperatorNames = 0;
-
-  if (Args.hasArg(OPT_fcuda_is_device))
-Opts.CUDAIsDevice = 1;
-
-  if (Args.hasArg(OPT_fcuda_allow_variadic_functions))
-Opts.CUDAAllowVariadicFunctions = 1;
-
-  if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
-Opts.CUDAHostDeviceConstexpr = 0;
-
   if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_approx_transcendentals))
 Opts.CUDADeviceApproxTranscendentals = 1;
 
-  Opts.GPURelocatableDeviceCode = Args.hasArg(OPT_fgpu_rdc);
   if (Args.hasArg(OPT_fgpu_allow_device_init)) {
 if (Opts.HIP)
   Opts.GPUAllowDeviceInit = 1;
@@ -2388,7 +2379,6 @@
   Diags.Report(diag::warn_ignored_hip_only_option)
   << Args.getLastArg(OPT_fgpu_allow_device_init)->getAsString(Args);
   }
-  Opts.HIPUseNewLaunchAPI = Args.hasArg(OPT_fhip_new_launch_api);
   if (Opts.HIP)
 Opts.GPUMaxThreadsPerBlock = getLastArgIntValue(
 Args, OPT_gpu_max_threads_per_block_EQ, Opts.GPUMaxThreadsPerBlock);
@@ -2408,7 +2398,6 @@
 else if (Args.hasArg(OPT_fobjc_gc))
   Opts.setGC(LangOptions::HybridGC);
 else if (Args.hasArg(OPT_fobjc_arc)) {
-  Opts.ObjCAutoRefCount = 1;
   if (!Opts.ObjCRuntime.allowsARC())
 Diags.Report(diag::err_arc_unsupported_on_runtime);
 }
@@ -2438,9 +2427,6 @@
   Opts.ObjCWeak = Opts.ObjCWeakRuntime;
 }
 
-if (Args.hasArg(OPT_fno_objc_infer_related_result_type))
-  Opts.ObjCInferRelatedResultType = 0;
-
 if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime))
   Opts.ObjCSubscriptingLegacyRuntime =
 (Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX);
@@ -2469,18 +2455,6 @@
   Opts.GNUInline = 1;
   }
 
-  if (Args.hasArg(OPT_fapple_kext)) {
-if (!Opts.CPlusPlus)
-  Diags.Report(diag::warn_c_kext);
-else
-  Opts.AppleKext = 1;
-  }
-
-  if (Args.hasArg(OPT_print_ivar_layout))
-Opts.ObjCGCBitmapPrint = 1;
-
-  if (Args.hasArg(OPT_fno_constant_cfstrings))
-Opts.NoConstantCFStrings = 1;
   if (const auto *A = Args.getLastArg(OPT_fcf_runtime_abi_EQ))
 Opts.CFRuntime =
 llvm::StringSwitch(A->getValue())
@@ -2492,12 +2466,6 @@
 .Case("swift-4.1", LangOptions::CoreFoundationABI::Swift4_1)
 .Default(LangOpt

[PATCH] D84018: Port Preprocessor and PreprocessorOutput option flags to new option parsing system

2020-07-17 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D83979 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84018

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3054,15 +3054,9 @@
   Opts.ImplicitPCHInclude = std::string(Args.getLastArgValue(OPT_include_pch));
   Opts.PCHWithHdrStop = Args.hasArg(OPT_pch_through_hdrstop_create) ||
 Args.hasArg(OPT_pch_through_hdrstop_use);
-  Opts.PCHWithHdrStopCreate = Args.hasArg(OPT_pch_through_hdrstop_create);
   Opts.PCHThroughHeader =
   std::string(Args.getLastArgValue(OPT_pch_through_header_EQ));
-  Opts.UsePredefines = !Args.hasArg(OPT_undef);
-  Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record);
-  Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch);
-  Opts.AllowPCHWithCompilerErrors = Args.hasArg(OPT_fallow_pch_with_errors);
 
-  Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls);
   for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
 
@@ -3145,9 +3139,6 @@
   // "editor placeholder in source file" error in PP only mode.
   if (isStrictlyPreprocessorAction(Action))
 Opts.LexEditorPlaceholders = false;
-
-  Opts.SetUpStaticAnalyzer = Args.hasArg(OPT_setup_static_analyzer);
-  Opts.DisablePragmaDebugCrash = Args.hasArg(OPT_disable_pragma_debug_crash);
 }
 
 static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
@@ -3158,14 +3149,7 @@
   else
 Opts.ShowCPP = 0;
 
-  Opts.ShowComments = Args.hasArg(OPT_C);
-  Opts.ShowLineMarkers = !Args.hasArg(OPT_P);
-  Opts.ShowMacroComments = Args.hasArg(OPT_CC);
   Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD);
-  Opts.ShowIncludeDirectives = Args.hasArg(OPT_dI);
-  Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes);
-  Opts.RewriteImports = Args.hasArg(OPT_frewrite_imports);
-  Opts.UseLineDirectives = Args.hasArg(OPT_fuse_line_directives);
 }
 
 static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1429,6 +1429,57 @@
 
 } // Flags = [CC1Option, NoDriverOption]
 
+// Preprocessor Options
+
+def undef : Flag<["-"], "undef">, Group, Flags<[CC1Option]>,
+  HelpText<"undef all system defines">,
+  MarshallingInfoFlag<"PreprocessorOpts->UsePredefines", "true">, IsNegative;
+
+let Flags = [CC1Option, NoDriverOption] in {
+
+def pch_through_hdrstop_create : Flag<["-"], "pch-through-hdrstop-create">,
+  HelpText<"When creating a PCH, stop PCH generation after #pragma hdrstop.">,
+  MarshallingInfoFlag<"PreprocessorOpts->PCHWithHdrStopCreate", "false">;
+def fno_validate_pch : Flag<["-"], "fno-validate-pch">,
+  HelpText<"Disable validation of precompiled headers">,
+  MarshallingInfoFlag<"PreprocessorOpts->DisablePCHValidation", "false">;
+def fallow_pch_with_errors : Flag<["-"], "fallow-pch-with-compiler-errors">,
+  HelpText<"Accept a PCH file that was created with compiler errors">,
+  MarshallingInfoFlag<"PreprocessorOpts->AllowPCHWithCompilerErrors", "false">;
+def dump_deserialized_pch_decls : Flag<["-"], "dump-deserialized-decls">,
+  HelpText<"Dump declarations that are deserialized from PCH, for testing">,
+  MarshallingInfoFlag<"PreprocessorOpts->DumpDeserializedPCHDecls", "false">;
+def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">,
+  HelpText<"include a detailed record of preprocessing actions">,
+  MarshallingInfoFlag<"PreprocessorOpts->DetailedRecord", "false">;
+def setup_static_analyzer : Flag<["-"], "setup-static-analyzer">,
+  HelpText<"Set up preprocessor for static analyzer (done automatically when static analyzer is run).">,
+  MarshallingInfoFlag<"PreprocessorOpts->SetUpStaticAnalyzer", "false">;
+def disable_pragma_debug_crash : Flag<["-"], "disable-pragma-debug-crash">,
+  HelpText<"Disable any #pragma clang __debug that can lead to crashing behavior. This is meant for testing.">,
+  MarshallingInfoFlag<"PreprocessorOpts->DisablePragmaDebugCrash", "false">;
+
+} // Flags = [CC1Option, NoDriverOption]
+
+// Preprocessor Output Options
+
+def CC : Flag<["-"], "CC">, Flags<[CC1Option]>, Group,
+HelpText<"Include comments from within macros in preprocessed output">,
+MarshallingInfoFlag<"PreprocessorOutputOpts.ShowMacroComments", "false">; 
+def C : Flag<["-"], "C">, Flags<[CC1Option]>, Group,
+HelpText<"Include comments in preprocessed output">,

[PATCH] D84185: Better defaults for MarshallingInfoString

2020-07-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

Depends on D84018 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84185

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td


Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -151,8 +151,11 @@
   code DefaultValue = defaultvalue;
 }
 
-class MarshallingInfoString
-  : MarshallingInfo {}
+class MarshallingInfoString
+  : MarshallingInfo {
+  code Normalizer = "normalizeString";
+  code Denormalizer = "denormalizeString";
+}
 
 class MarshallingInfoFlag
   : MarshallingInfo {
@@ -185,7 +188,6 @@
 class Denormalizer { code Denormalizer = denormalizer; }
 class NormalizedValuesScope { code NormalizedValuesScope = scope; }
 class NormalizedValues definitions> { list NormalizedValues = 
definitions; } 
-class DenormalizeString { code Denormalizer = "denormalizeString"; }
 class AutoNormalizeEnum {
   code Normalizer = "normalizeSimpleEnum";
   code Denormalizer = "denormalizeSimpleEnum";
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -242,6 +242,15 @@
  "the tablegen option description");
 }
 
+static Optional normalizeString(OptSpecifier Opt, int TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
+  auto *Arg = Args.getLastArg(Opt);
+  if (!Arg)
+return None;
+  return std::string(Arg->getValue());
+}
+
 static void denormalizeString(SmallVectorImpl &Args,
   const char *Spelling,
   CompilerInvocation::StringAllocator SA,
@@ -478,8 +487,6 @@
   .Case("false", false)
   .Default(false);
 
-  Opts.DumpExplodedGraphTo =
-  std::string(Args.getLastArgValue(OPT_analyzer_dump_egraph));
   Opts.AnalyzeSpecificFunction =
   std::string(Args.getLastArgValue(OPT_analyze_function));
   Opts.maxBlockVisitOnPath =
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -573,7 +573,7 @@
 def triple : Separate<["-"], "triple">,
   HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
   MarshallingInfoString<"TargetOpts->Triple", 
"llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
-  AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;
+  AlwaysEmit, Normalizer<"normalizeTriple">;
 
 } // Flags = [CC1Option, CC1AsOption, NoDriverOption]
 
@@ -4124,7 +4124,8 @@
   HelpText<"Display exploded graph using GraphViz">,
   MarshallingInfoFlag<"AnalyzerOpts->visualizeExplodedGraphWithGraphViz", 
"false">;
 def analyzer_dump_egraph : Separate<["-"], "analyzer-dump-egraph">,
-  HelpText<"Dump exploded graph to the specified file">;
+  HelpText<"Dump exploded graph to the specified file">,
+  MarshallingInfoString<"AnalyzerOpts->DumpExplodedGraphTo">;
 def analyzer_dump_egraph_EQ : Joined<["-"], "analyzer-dump-egraph=">, 
Alias;
 
 def analyzer_inline_max_stack_depth : Separate<["-"], 
"analyzer-inline-max-stack-depth">,


Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -151,8 +151,11 @@
   code DefaultValue = defaultvalue;
 }
 
-class MarshallingInfoString
-  : MarshallingInfo {}
+class MarshallingInfoString
+  : MarshallingInfo {
+  code Normalizer = "normalizeString";
+  code Denormalizer = "denormalizeString";
+}
 
 class MarshallingInfoFlag
   : MarshallingInfo {
@@ -185,7 +188,6 @@
 class Denormalizer { code Denormalizer = denormalizer; }
 class NormalizedValuesScope { code NormalizedValuesScope = scope; }
 class NormalizedValues definitions> { list NormalizedValues = definitions; } 
-class DenormalizeString { code Denormalizer = "denormalizeString"; }
 class AutoNormalizeEnum {
   code Normalizer = "normalizeSimpleEnum";
   code Denormalizer = "denormalizeSimpleEnum";
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -242,6 +242,15 @@
  "the tablegen option description");
 }
 
+static Optional normalizeString(OptSpecifier Opt, int TableIndex,
+ const ArgList &Args,
+  

[PATCH] D84186: Convert Analyzer option string based options to new option parsing system

2020-07-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, ASDenysPetrov, dkrupp, 
donat.nagy, Szelethus, dexonsmith, a.sidorin, baloghadamsoftware.
Herald added projects: clang, LLVM.

Depends on D84185 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84186

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td


Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -157,6 +157,12 @@
   code Denormalizer = "denormalizeString";
 }
 
+class MarshallingInfoStringInt
+  : MarshallingInfo {
+  code Normalizer = "normalizeStringIntegral<"#type#">";
+  code Denormalizer = "denormalizeString";
+}
+
 class MarshallingInfoFlag
   : MarshallingInfo {
   code Normalizer = "normalizeSimpleFlag";
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -90,6 +90,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -251,12 +252,30 @@
   return std::string(Arg->getValue());
 }
 
+template 
 static void denormalizeString(SmallVectorImpl &Args,
   const char *Spelling,
   CompilerInvocation::StringAllocator SA,
-  unsigned TableIndex, const std::string &Value) {
+  unsigned TableIndex, T &&Value) {
+  static_assert(std::is_constructible::value,
+"Cannot convert this value to Twine");
   Args.push_back(Spelling);
-  Args.push_back(SA(Value));
+  Args.push_back(SA(Twine(std::forward(Value;
+}
+
+template 
+static Optional normalizeStringIntegral(OptSpecifier Opt, int 
TableIndex,
+   const ArgList &Args,
+   DiagnosticsEngine &Diags) {
+  auto *Arg = Args.getLastArg(Opt);
+  if (!Arg)
+return None;
+  IntTy Res;
+  if (StringRef(Arg->getValue()).getAsInteger(0, Res)) {
+Diags.Report(diag::err_drv_invalid_int_value)
+<< Arg->getAsString(Args) << Arg->getValue();
+  }
+  return Res;
 }
 
 static Optional normalizeTriple(OptSpecifier Opt, int TableIndex,
@@ -487,10 +506,6 @@
   .Case("false", false)
   .Default(false);
 
-  Opts.AnalyzeSpecificFunction =
-  std::string(Args.getLastArgValue(OPT_analyze_function));
-  Opts.maxBlockVisitOnPath =
-  getLastArgIntValue(Args, OPT_analyzer_max_loop, 4, Diags);
   Opts.InlineMaxStackDepth =
   getLastArgIntValue(Args, OPT_analyzer_inline_max_stack_depth,
  Opts.InlineMaxStackDepth, Diags);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4115,7 +4115,8 @@
   HelpText<"Emit verbose output about the analyzer's progress">,
   MarshallingInfoFlag<"AnalyzerOpts->AnalyzerDisplayProgress", "false">;
 def analyze_function : Separate<["-"], "analyze-function">,
-  HelpText<"Run analysis on specific function (for C++ include parameters in 
name)">;
+  HelpText<"Run analysis on specific function (for C++ include parameters in 
name)">,
+  MarshallingInfoString<"AnalyzerOpts->AnalyzeSpecificFunction">;
 def analyze_function_EQ : Joined<["-"], "analyze-function=">, 
Alias;
 def trim_egraph : Flag<["-"], "trim-egraph">,
   HelpText<"Only show error-related paths in the analysis graph">,
@@ -4142,7 +4143,8 @@
   MarshallingInfoFlag<"AnalyzerOpts->NoRetryExhausted", "false">;
 
 def analyzer_max_loop : Separate<["-"], "analyzer-max-loop">,
-  HelpText<"The maximum number of times the analyzer will go through a loop">;
+  HelpText<"The maximum number of times the analyzer will go through a loop">,
+  MarshallingInfoStringInt<"AnalyzerOpts->maxBlockVisitOnPath", "4">;
 def analyzer_stats : Flag<["-"], "analyzer-stats">,
   HelpText<"Print internal analyzer statistics.">,
   MarshallingInfoFlag<"AnalyzerOpts->PrintStats", "false">;


Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -157,6 +157,12 @@
   code Denormalizer = "denormalizeString";
 }
 
+class MarshallingInfoStringInt
+  : MarshallingInfo {
+  code Normalizer = "normalizeStringIntegral<"#type#">";
+  code Denormalizer = "denormalizeString";
+}
+
 class MarshallingInfoFlag
   : MarshallingInfo {
   code Normalizer = "normalizeSimpleFlag";
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/li

[PATCH] D84187: Port DependencyOutput string based options to new option parsing system

2020-07-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D84186 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84187

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1347,10 +1347,7 @@
 
 static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
   ArgList &Args) {
-  Opts.OutputFile = std::string(Args.getLastArgValue(OPT_dependency_file));
   Opts.Targets = Args.getAllArgValues(OPT_MT);
-  Opts.HeaderIncludeOutputFile =
-  std::string(Args.getLastArgValue(OPT_header_include_file));
   if (Args.hasArg(OPT_show_includes)) {
 // Writing both /showIncludes and preprocessor output to stdout
 // would produce interleaved output, so use stderr for /showIncludes.
@@ -1362,9 +1359,6 @@
   } else {
 Opts.ShowIncludesDest = ShowIncludesDestination::None;
   }
-  Opts.DOTOutputFile = std::string(Args.getLastArgValue(OPT_dependency_dot));
-  Opts.ModuleDependencyOutputDir =
-  std::string(Args.getLastArgValue(OPT_module_dependency_dir));
   // Add sanitizer blacklists as extra dependencies.
   // They won't be discovered by the regular preprocessor, so
   // we let make / ninja to know about this implicit dependency.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -358,6 +358,16 @@
 HelpText<"Create phony target for each dependency (other than main file)">,
 MarshallingInfoFlag<"DependencyOutputOpts.UsePhonyTargets", "false">;
 
+def dependency_file : Separate<["-"], "dependency-file">, Flags<[CC1Option]>,
+  HelpText<"Filename (or -) to write dependency output to">,
+  MarshallingInfoString<"DependencyOutputOpts.OutputFile">;
+def dependency_dot : Separate<["-"], "dependency-dot">, Flags<[CC1Option]>,
+  HelpText<"Filename to write DOT-formatted header dependencies to">,
+  MarshallingInfoString<"DependencyOutputOpts.DOTOutputFile">;
+def module_dependency_dir : Separate<["-"], "module-dependency-dir">,
+  Flags<[CC1Option]>, HelpText<"Directory to dump module dependencies to">,
+  MarshallingInfoString<"DependencyOutputOpts.ModuleDependencyOutputDir">;
+
 let Flags = [CC1Option, NoDriverOption] in {
 
 def sys_header_deps : Flag<["-"], "sys-header-deps">,
@@ -367,6 +377,10 @@
   HelpText<"Include module files in dependency output">,
   MarshallingInfoFlag<"DependencyOutputOpts.IncludeModuleFiles", "false">;
 
+def header_include_file : Separate<["-"], "header-include-file">,
+  HelpText<"Filename (or -) to write header include output to">,
+  MarshallingInfoString<"DependencyOutputOpts.HeaderIncludeOutputFile">;
+
 } // Flags = [CC1Option, NoDriverOption]
 
 // Diagnostic Options
@@ -1741,12 +1755,6 @@
 def dM : Flag<["-"], "dM">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode instead of normal output">;
 def dead__strip : Flag<["-"], "dead_strip">;
-def dependency_file : Separate<["-"], "dependency-file">, Flags<[CC1Option]>,
-  HelpText<"Filename (or -) to write dependency output to">;
-def dependency_dot : Separate<["-"], "dependency-dot">, Flags<[CC1Option]>,
-  HelpText<"Filename to write DOT-formatted header dependencies to">;
-def module_dependency_dir : Separate<["-"], "module-dependency-dir">,
-  Flags<[CC1Option]>, HelpText<"Directory to dump module dependencies to">;
 def dumpmachine : Flag<["-"], "dumpmachine">;
 def dumpspecs : Flag<["-"], "dumpspecs">, Flags<[Unsupported]>;
 def dumpversion : Flag<["-"], "dumpversion">;
@@ -4322,8 +4330,6 @@
 // Dependency Output Options
 
//===--===//
 
-def header_include_file : Separate<["-"], "header-include-file">,
-  HelpText<"Filename (or -) to write header include output to">;
 def show_includes : Flag<["--"], "show-includes">,
   HelpText<"Print cl.exe style /showIncludes to stdout">;
 


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1347,10 +1347,7 @@
 
 static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
   ArgList &Args) {
-  Opts.OutputFile = std::string(Args.getLastArgValue(OPT_dependency_file));
   Opts.Targets = Args.getAllArgValues(OPT_MT);
-  Opts.HeaderIncludeOutputFile =
-  std::string(Args.getLastArgValue(OPT_header_include_file));
   if (Args.hasArg(OPT_show_includes)) {
 // Writing both /showIncludes an

[PATCH] D84188: Port FileSystem options to new option parsing system

2020-07-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D84187 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84188

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1570,10 +1570,6 @@
   return Success;
 }
 
-static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) {
-  Opts.WorkingDir = std::string(Args.getLastArgValue(OPT_working_directory));
-}
-
 /// Parse the argument to the -ftest-module-file-extension
 /// command-line argument.
 ///
@@ -3273,7 +3269,6 @@
   Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags,
  /*DefaultDiagColor=*/false);
   ParseCommentArgs(LangOpts.CommentOpts, Args);
-  ParseFileSystemArgs(Res.getFileSystemOpts(), Args);
   // FIXME: We shouldn't have to pass the DashX option around here
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags,
   LangOpts.IsHeaderFile);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -342,6 +342,14 @@
 def fparse_all_comments : Flag<["-"], "fparse-all-comments">, 
Group, Flags<[CC1Option]>,
   MarshallingInfoFlag<"LangOpts->CommentOpts.ParseAllComments", "false">;
 
+// Filesystem Options FileSystemOpts
+
+def working_directory : JoinedOrSeparate<["-"], "working-directory">, 
Flags<[CC1Option]>,
+  HelpText<"Resolve file paths relative to the specified directory">,
+  MarshallingInfoString<"FileSystemOpts.WorkingDir">;
+def working_directory_EQ : Joined<["-"], "working-directory=">, 
Flags<[CC1Option]>,
+  Alias;
+
 // Dependency Output Options
 
 def MV : Flag<["-"], "MV">, Group, Flags<[CC1Option]>,
@@ -3516,11 +3524,6 @@
 def : Flag<["-"], "no-integrated-as">, Alias,
   Flags<[CC1Option, DriverOption]>;
 
-def working_directory : JoinedOrSeparate<["-"], "working-directory">, 
Flags<[CC1Option]>,
-  HelpText<"Resolve file paths relative to the specified directory">;
-def working_directory_EQ : Joined<["-"], "working-directory=">, 
Flags<[CC1Option]>,
-  Alias;
-
 // Double dash options, which are usually an alias for one of the previous
 // options.
 


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1570,10 +1570,6 @@
   return Success;
 }
 
-static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) {
-  Opts.WorkingDir = std::string(Args.getLastArgValue(OPT_working_directory));
-}
-
 /// Parse the argument to the -ftest-module-file-extension
 /// command-line argument.
 ///
@@ -3273,7 +3269,6 @@
   Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags,
  /*DefaultDiagColor=*/false);
   ParseCommentArgs(LangOpts.CommentOpts, Args);
-  ParseFileSystemArgs(Res.getFileSystemOpts(), Args);
   // FIXME: We shouldn't have to pass the DashX option around here
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags,
   LangOpts.IsHeaderFile);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -342,6 +342,14 @@
 def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group, Flags<[CC1Option]>,
   MarshallingInfoFlag<"LangOpts->CommentOpts.ParseAllComments", "false">;
 
+// Filesystem Options FileSystemOpts
+
+def working_directory : JoinedOrSeparate<["-"], "working-directory">, Flags<[CC1Option]>,
+  HelpText<"Resolve file paths relative to the specified directory">,
+  MarshallingInfoString<"FileSystemOpts.WorkingDir">;
+def working_directory_EQ : Joined<["-"], "working-directory=">, Flags<[CC1Option]>,
+  Alias;
+
 // Dependency Output Options
 
 def MV : Flag<["-"], "MV">, Group, Flags<[CC1Option]>,
@@ -3516,11 +3524,6 @@
 def : Flag<["-"], "no-integrated-as">, Alias,
   Flags<[CC1Option, DriverOption]>;
 
-def working_directory : JoinedOrSeparate<["-"], "working-directory">, Flags<[CC1Option]>,
-  HelpText<"Resolve file paths relative to the specified directory">;
-def working_directory_EQ : Joined<["-"], "working-directory=">, Flags<[CC1Option]>,
-  Alias;
-
 // Double dash options, which are usually an alias for one of the previous
 // options.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.

[PATCH] D84190: Port FrontendOpts simple string based options to new option parsing system

2020-07-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, aaron.ballman, dexonsmith.
Herald added a project: clang.

Depends on D84189 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84190

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1760,15 +1760,11 @@
 << A->getAsString(Args) << A->getValue();
   }
 
-  Opts.OutputFile = std::string(Args.getLastArgValue(OPT_o));
   Opts.Plugins = Args.getAllArgValues(OPT_load);
-  Opts.TimeTraceGranularity = getLastArgIntValue(
-  Args, OPT_ftime_trace_granularity_EQ, Opts.TimeTraceGranularity, Diags);
   Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
   Opts.ASTDumpDecls = Args.hasArg(OPT_ast_dump, OPT_ast_dump_EQ);
   Opts.ASTDumpAll = Args.hasArg(OPT_ast_dump_all, OPT_ast_dump_all_EQ);
-  Opts.ASTDumpFilter = std::string(Args.getLastArgValue(OPT_ast_dump_filter));
   Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file);
   // Only the -fmodule-file= form.
   for (const auto *A : Args.filtered(OPT_fmodule_file)) {
@@ -1782,22 +1778,10 @@
 Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
<< "-emit-module";
 
-  Opts.OverrideRecordLayoutsFile =
-  std::string(Args.getLastArgValue(OPT_foverride_record_layout_EQ));
-  Opts.AuxTriple = std::string(Args.getLastArgValue(OPT_aux_triple));
   if (Args.hasArg(OPT_aux_target_cpu))
 Opts.AuxTargetCPU = std::string(Args.getLastArgValue(OPT_aux_target_cpu));
   if (Args.hasArg(OPT_aux_target_feature))
 Opts.AuxTargetFeatures = Args.getAllArgValues(OPT_aux_target_feature);
-  Opts.StatsFile = std::string(Args.getLastArgValue(OPT_stats_file));
-
-  Opts.MTMigrateDir =
-  std::string(Args.getLastArgValue(OPT_mt_migrate_directory));
-  Opts.ARCMTMigrateReportOut =
-  std::string(Args.getLastArgValue(OPT_arcmt_migrate_report_output));
-
-  Opts.ObjCMTWhiteListPath =
-  std::string(Args.getLastArgValue(OPT_objcmt_whitelist_dir_path));
 
   if (Opts.ARCMTAction != FrontendOptions::ARCMT_None &&
   Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -313,8 +313,6 @@
   HelpText<"Apply modifications to files to conform to ARC">;
 def ccc_arcmt_migrate : Separate<["-"], "ccc-arcmt-migrate">, InternalDriverOpt,
   HelpText<"Apply modifications and produces temporary files that conform to ARC">;
-def arcmt_migrate_report_output : Separate<["-"], "arcmt-migrate-report-output">,
-  HelpText<"Output path for the plist report">,  Flags<[CC1Option]>;
 def gen_reproducer: Flag<["-"], "gen-reproducer">, InternalDebugOpt,
   HelpText<"Auto-generates preprocessed source files and a reproduction script">;
 def gen_cdb_fragment_path: Separate<["-"], "gen-cdb-fragment-path">, InternalDebugOpt,
@@ -327,13 +325,6 @@
   HelpText<"Apply modifications and produces temporary files to migrate to "
"modern ObjC syntax">;
 
-
-def objcmt_whitelist_dir_path: Joined<["-"], "objcmt-whitelist-dir-path=">, Flags<[CC1Option]>,
-  HelpText<"Only modify files with a filename contained in the provided directory path">;
-// The misspelt "white-list" [sic] alias is due for removal.
-def : Joined<["-"], "objcmt-white-list-dir-path=">, Flags<[CC1Option]>,
-Alias;
-
 // Make sure all other -ccc- options are rejected.
 def ccc_ : Joined<["-"], "ccc-">, Group, Flags<[Unsupported]>;
 
@@ -511,6 +502,23 @@
" it will print the supported cpus for the default target)">,
   MarshallingInfoFlag<"FrontendOpts.PrintSupportedCPUs", "false">;
 
+def o : JoinedOrSeparate<["-"], "o">, Flags<[DriverOption, RenderAsInput, CC1Option, CC1AsOption]>,
+  HelpText<"Write output to ">, MetaVarName<"">,
+  MarshallingInfoString<"FrontendOpts.OutputFile">;
+def ftime_trace_granularity_EQ : Joined<["-"], "ftime-trace-granularity=">, Group,
+  HelpText<"Minimum time granularity (in microseconds) traced by time profiler">,
+  Flags<[CC1Option, CoreOption]>,
+  MarshallingInfoStringInt<"FrontendOpts.TimeTraceGranularity", "500u">;
+def arcmt_migrate_report_output : Separate<["-"], "arcmt-migrate-report-output">,
+  HelpText<"Output path for the plist report">,  Flags<[CC1Option]>,
+  MarshallingInfoString<"FrontendOpts.ARCMTMigrateReportOut">;
+def objcmt_whitelist_dir_path: Joined<["-"], "objcmt-whitelist-dir-path=">, Flags<[CC1Option]>,
+  HelpText<"Only modify files with a filename contained in the provided directory path">,
+  Marshal

[PATCH] D84189: Let denormalizer decide how to render the option based on the option class

2020-07-20 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

Depends on D84188 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84189

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -198,9 +198,6 @@
   code Normalizer = "normalizeSimpleEnum";
   code Denormalizer = "denormalizeSimpleEnum";
 }
-class AutoNormalizeEnumJoined : AutoNormalizeEnum {
-  code Denormalizer = "denormalizeSimpleEnumJoined";
-}
 class ValueMerger { code ValueMerger = merger; }
 class ValueExtractor { code ValueExtractor = extractor; }
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -143,7 +143,8 @@
 void denormalizeSimpleFlag(SmallVectorImpl &Args,
const char *Spelling,
CompilerInvocation::StringAllocator SA,
-   unsigned TableIndex, T Value) {
+   Option::OptionClass OptClass, unsigned TableIndex,
+   T Value) {
   Args.push_back(Spelling);
 }
 
@@ -177,6 +178,38 @@
 Args.push_back(NegSpelling);
 }
 
+static Optional normalizeString(OptSpecifier Opt, int TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
+  auto *Arg = Args.getLastArg(Opt);
+  if (!Arg)
+return None;
+  return std::string(Arg->getValue());
+}
+
+template 
+static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
+  CompilerInvocation::StringAllocator SA,
+  Option::OptionClass OptClass, unsigned TableIndex,
+  T &&Value) {
+  static_assert(std::is_constructible::value,
+"Cannot convert this value to Twine");
+  switch (OptClass) {
+  case Option::SeparateClass:
+  case Option::JoinedOrSeparateClass:
+Args.push_back(Spelling);
+Args.push_back(SA(Twine(std::forward(Value;
+break;
+  case Option::JoinedClass:
+Args.push_back(SA(Twine(Spelling) + Twine(std::forward(Value;
+break;
+  default:
+llvm_unreachable("Cannot denormalize an option with option class "
+ "incompatible with string denormalization.");
+  }
+}
+
 static Optional
 findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
   for (int I = 0, E = Table.Size; I != E; ++I)
@@ -218,51 +251,19 @@
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
   const char *Spelling,
   CompilerInvocation::StringAllocator SA,
+  Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
-Args.push_back(Spelling);
-Args.push_back(MaybeEnumVal->Name);
+denormalizeString(Args, Spelling, SA, OptClass, TableIndex,
+  MaybeEnumVal->Name);
   } else {
 llvm_unreachable("The simple enum value was not correctly defined in "
  "the tablegen option description");
   }
 }
 
-static void denormalizeSimpleEnumJoined(SmallVectorImpl &Args,
-const char *Spelling,
-CompilerInvocation::StringAllocator SA,
-unsigned TableIndex, unsigned Value) {
-  assert(TableIndex < SimpleEnumValueTablesSize);
-  const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
-  if (auto MaybeEnumVal = findValueTableByValue(Table, Value))
-Args.push_back(SA(Twine(Spelling) + MaybeEnumVal->Name));
-  else
-llvm_unreachable("The simple enum value was not correctly defined in "
- "the tablegen option description");
-}
-
-static Optional normalizeString(OptSpecifier Opt, int TableIndex,
- const ArgList &Args,
- DiagnosticsEngine &Diags) {
-  auto *Arg = Args.getLastArg(Opt);
-  if (!Arg)
-return None;
-  return std::string(Arg->getValue());
-}
-
-template 
-static void denormalizeString(SmallVectorImpl &Args,
-  const char *Spelling,
-  

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 280945.
dang added a comment.

Update with latest changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -61,8 +61,9 @@
 
 class MarshallingInfo {
 public:
-  static constexpr const char *MacroName = "OPTION_WITH_MARSHALLING";
+  using Ptr = std::unique_ptr;
 
+  const char *MacroName;
   const Record &R;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
@@ -78,6 +79,8 @@
   std::vector NormalizedValues;
   std::string ValueTableName;
 
+  static size_t NextTableIndex;
+
   static constexpr const char *ValueTablePreamble = R"(
 struct SimpleEnumValue {
   const char *Name;
@@ -93,7 +96,14 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  void emit(raw_ostream &OS) const {
+  MarshallingInfo(const Record &R)
+  : MacroName("OPTION_WITH_MARSHALLING"), R(R) {}
+  MarshallingInfo(const char *MacroName, const Record &R)
+  : MacroName(MacroName), R(R){};
+
+  virtual ~MarshallingInfo() = default;
+
+  virtual void emit(raw_ostream &OS) const {
 write_cstring(OS, StringRef(getOptionSpelling(R)));
 OS << ", ";
 OS << ShouldAlwaysEmit;
@@ -131,53 +141,6 @@
 return StringRef(ValueTableName);
   }
 
-  static MarshallingInfo create(const Record &R) {
-assert(!isa(R.getValueInit("KeyPath")) &&
-   !isa(R.getValueInit("DefaultValue")) &&
-   !isa(R.getValueInit("NormalizerRetTy")) &&
-   !isa(R.getValueInit("ValueMerger")) &&
-   "MarshallingInfo must have a type");
-
-MarshallingInfo Ret(R);
-Ret.ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
-Ret.KeyPath = R.getValueAsString("KeyPath");
-Ret.DefaultValue = R.getValueAsString("DefaultValue");
-Ret.NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
-Ret.NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
-
-Ret.Normalizer = R.getValueAsString("Normalizer");
-Ret.Denormalizer = R.getValueAsString("Denormalizer");
-Ret.ValueMerger = R.getValueAsString("ValueMerger");
-Ret.ValueExtractor = R.getValueAsString("ValueExtractor");
-
-if (!isa(R.getValueInit("NormalizedValues"))) {
-  assert(!isa(R.getValueInit("Values")) &&
- "Cannot provide normalized values for value-less options");
-  Ret.TableIndex = NextTableIndex++;
-  Ret.NormalizedValues = R.getValueAsListOfStrings("NormalizedValues");
-  Ret.Values.reserve(Ret.NormalizedValues.size());
-  Ret.ValueTableName = getOptionName(R) + "ValueTable";
-
-  StringRef ValuesStr = R.getValueAsString("Values");
-  for (;;) {
-size_t Idx = ValuesStr.find(',');
-if (Idx == StringRef::npos)
-  break;
-if (Idx > 0)
-  Ret.Values.push_back(ValuesStr.slice(0, Idx));
-ValuesStr = ValuesStr.slice(Idx + 1, StringRef::npos);
-  }
-  if (!ValuesStr.empty())
-Ret.Values.push_back(ValuesStr);
-
-  assert(Ret.Values.size() == Ret.NormalizedValues.size() &&
- "The number of normalized values doesn't match the number of "
- "values");
-}
-
-return Ret;
-  }
-
 private:
   void emitScopedNormalizedValue(raw_ostream &OS,
  StringRef NormalizedValue) const {
@@ -185,13 +148,81 @@
   OS << NormalizedValuesScope << "::";
 OS << NormalizedValue;
   }
+};
+
+size_t MarshallingInfo::NextTableIndex = 0;
 
-  MarshallingInfo(const Record &R) : R(R){};
+class MarshallingInfoBooleanFlag : public MarshallingInfo {
+public:
+  const Record &NegOption;
 
-  static size_t NextTableIndex;
+  MarshallingInfoBooleanFlag(const Record &Option, const Record &NegOption)
+  : MarshallingInfo("OPTION_WITH_MARSHALLING_BOOLEAN", Option),
+NegOption(NegOption) {}
+
+  void emit(raw_ostream &OS) const override {
+MarshallingInfo::emit(OS);
+OS << ", ";
+OS << getOptionName(NegOption);
+OS << ", ";
+write_cstring(OS, getOptionSpelling(NegOption));
+  }
 };
 
-size_t MarshallingInfo::NextTableIndex = 0;
+static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
+  assert(!isa(R.getValueInit("KeyPath")) &&
+ !isa(R.getValueInit("DefaultValue")) &&
+ !isa(R.getValueInit("NormalizerRetTy")) &&
+ !isa(R.getValueInit("ValueMerger")) &&
+ "MarshallingInfo must have a type");
+
+  MarshallingInfo::Ptr Ret;
+  StringRef KindString = R.getValueAsString("MarshallingInfoKind");
+  if (KindString == "Default") {
+Ret = std

[PATCH] D83298: Add ability to make fixups to CompilerInvocation after option parsing

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 280946.
dang added a comment.

Update with latest changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83298

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -249,6 +249,17 @@
   return KeyPath & Value;
 }
 
+static void FixupInvocation(CompilerInvocation &Invocation) {
+  LangOptions &LangOpts = *Invocation.getLangOpts();
+  DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
+  CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
+  CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
+  CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
+  CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
+
+  llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
+}
+
 
//===--===//
 // Deserialization (from args)
 
//===--===//
@@ -1172,16 +1183,8 @@
   Opts.InstrumentFunctionEntryBare =
   Args.hasArg(OPT_finstrument_function_entry_bare);
 
-  Opts.XRayInstrumentFunctions =
-  Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
-  Opts.XRayIgnoreLoops = Args.hasArg(OPT_fxray_ignore_loops);
-  Opts.XRayOmitFunctionIndex = Args.hasArg(OPT_fno_xray_function_index);
 
   auto XRayInstrBundles =
   Args.getAllArgValues(OPT_fxray_instrumentation_bundle);
@@ -3348,13 +3351,6 @@
   systemBlacklists.begin(),
   systemBlacklists.end());
 
-  // -fxray-instrument
-  Opts.XRayInstrument = Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
-
   // -fxray-{always,never}-instrument= filenames.
   Opts.XRayAlwaysInstrumentFiles =
   Args.getAllArgValues(OPT_fxray_always_instrument);
@@ -3722,9 +3718,7 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
-
-  llvm::sys::Process::UseANSIEscapeCodes(
-  Res.DiagnosticOpts->UseANSIEscapeCodes);
+  FixupInvocation(Res);
 
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1290,7 +1290,7 @@
   Alias, AliasArgs<["full"]>,
   HelpText<"Enable cf-protection in 'full' mode">;
 
-defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit">;
+defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit", "", "", [], 
"LangOpts->XRayInstrument">;
 
 def fxray_instruction_threshold_EQ :
   JoinedOrSeparate<["-"], "fxray-instruction-threshold=">,
@@ -1318,15 +1318,15 @@
   HelpText<"List of modes to link in by default into XRay instrumented 
binaries.">;
 
 defm xray_always_emit_customevents : 
OptInFFlag<"xray-always-emit-customevents",
-  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented">;
+  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented", "", "", [], 
"LangOpts->XRayAlwaysEmitCustomEvents">;
 
 defm xray_always_emit_typedevents : OptInFFlag<"xray-always-emit-typedevents",
-  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented">;
+  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented", "", "", [], "LangOpts->XRayAlwaysEmitTypedEvents">;
 
 defm xray_ignore_loops : OptInFFlag<"xray-ignore-loops",
-  "Don't instrument functions with loops unless they also meet the minimum 
function size">;
+  "Don't instrument functions with loops unless they also meet the minimum 
function size", "", "", [], "CodeGenOpts.XRayIgnoreLoops">;
 defm xray_function_index : OptOutFFlag<"xray-function-index", "",
-  "Omit function index section at the expense of single-function patching 
performance">;
+  "Omit function index section at the expense of single-function patching 
performance

[PATCH] D84186: Convert Analyzer option string based options to new option parsing system

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 280948.
dang added a comment.

Update with latest changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84186

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,12 @@
   code Denormalizer = "denormalizeString";
 }
 
+class MarshallingInfoStringInt
+  : MarshallingInfo {
+  code Normalizer = "normalizeStringIntegral<"#type#">";
+  code Denormalizer = "denormalizeString";
+}
+
 class MarshallingInfoFlag
   : MarshallingInfo {
   code Normalizer = "normalizeSimpleFlag";
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -90,6 +90,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -251,12 +252,30 @@
   return std::string(Arg->getValue());
 }
 
+template 
 static void denormalizeString(SmallVectorImpl &Args,
   const char *Spelling,
   CompilerInvocation::StringAllocator SA,
-  unsigned TableIndex, const std::string &Value) {
+  unsigned TableIndex, T &&Value) {
+  static_assert(std::is_constructible::value,
+"Cannot convert this value to Twine");
   Args.push_back(Spelling);
-  Args.push_back(SA(Value));
+  Args.push_back(SA(Twine(std::forward(Value;
+}
+
+template 
+static Optional normalizeStringIntegral(OptSpecifier Opt, int TableIndex,
+   const ArgList &Args,
+   DiagnosticsEngine &Diags) {
+  auto *Arg = Args.getLastArg(Opt);
+  if (!Arg)
+return None;
+  IntTy Res;
+  if (StringRef(Arg->getValue()).getAsInteger(0, Res)) {
+Diags.Report(diag::err_drv_invalid_int_value)
+<< Arg->getAsString(Args) << Arg->getValue();
+  }
+  return Res;
 }
 
 static Optional normalizeTriple(OptSpecifier Opt, int TableIndex,
@@ -487,14 +506,6 @@
   .Case("false", false)
   .Default(false);
 
-  Opts.AnalyzeSpecificFunction =
-  std::string(Args.getLastArgValue(OPT_analyze_function));
-  Opts.maxBlockVisitOnPath =
-  getLastArgIntValue(Args, OPT_analyzer_max_loop, 4, Diags);
-  Opts.InlineMaxStackDepth =
-  getLastArgIntValue(Args, OPT_analyzer_inline_max_stack_depth,
- Opts.InlineMaxStackDepth, Diags);
-
   Opts.CheckersAndPackages.clear();
   for (const Arg *A :
Args.filtered(OPT_analyzer_checker, OPT_analyzer_disable_checker)) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4093,7 +4093,8 @@
   HelpText<"Emit verbose output about the analyzer's progress">,
   MarshallingInfoFlag<"AnalyzerOpts->AnalyzerDisplayProgress", "false">;
 def analyze_function : Separate<["-"], "analyze-function">,
-  HelpText<"Run analysis on specific function (for C++ include parameters in name)">;
+  HelpText<"Run analysis on specific function (for C++ include parameters in name)">,
+  MarshallingInfoString<"AnalyzerOpts->AnalyzeSpecificFunction">;
 def analyze_function_EQ : Joined<["-"], "analyze-function=">, Alias;
 def trim_egraph : Flag<["-"], "trim-egraph">,
   HelpText<"Only show error-related paths in the analysis graph">,
@@ -4107,7 +4108,8 @@
 def analyzer_dump_egraph_EQ : Joined<["-"], "analyzer-dump-egraph=">, Alias;
 
 def analyzer_inline_max_stack_depth : Separate<["-"], "analyzer-inline-max-stack-depth">,
-  HelpText<"Bound on stack depth while inlining (4 by default)">;
+  HelpText<"Bound on stack depth while inlining (4 by default)">,
+  MarshallingInfoStringInt<"AnalyzerOpts->InlineMaxStackDepth", "5">;
 def analyzer_inline_max_stack_depth_EQ : Joined<["-"], "analyzer-inline-max-stack-depth=">,
   Alias;
 
@@ -4120,7 +4122,8 @@
   MarshallingInfoFlag<"AnalyzerOpts->NoRetryExhausted", "false">;
 
 def analyzer_max_loop : Separate<["-"], "analyzer-max-loop">,
-  HelpText<"The maximum number of times the analyzer will go through a loop">;
+  HelpText<"The maximum number of times the analyzer will go through a loop">,
+  MarshallingInfoStringInt<"AnalyzerOpts->maxBlockVisitOnPath", "4">;
 def analyzer_stats : Flag<["-"], "analyzer-stats">,
   HelpText<"Print internal analyzer statistics.">,
   MarshallingInfoFlag<"AnalyzerOpts->PrintStats", "false">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-

[PATCH] D84668: Port TargetOpts simple string based options to new option parsing system

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D84190 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84668

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -248,14 +248,16 @@
   return None;
 }
 
+template 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
   const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   Option::OptionClass OptClass,
-  unsigned TableIndex, unsigned Value) {
+  unsigned TableIndex, T Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
-  if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
+  if (auto MaybeEnumVal =
+  findValueTableByValue(Table, static_cast(Value))) {
 denormalizeString(Args, Spelling, SA, OptClass, TableIndex,
   MaybeEnumVal->Name);
   } else {
@@ -3149,27 +3151,7 @@
 
 static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
 DiagnosticsEngine &Diags) {
-  Opts.CodeModel = std::string(Args.getLastArgValue(OPT_mcmodel_EQ, "default"));
-  Opts.ABI = std::string(Args.getLastArgValue(OPT_target_abi));
-  if (Arg *A = Args.getLastArg(OPT_meabi)) {
-StringRef Value = A->getValue();
-llvm::EABI EABIVersion = llvm::StringSwitch(Value)
- .Case("default", llvm::EABI::Default)
- .Case("4", llvm::EABI::EABI4)
- .Case("5", llvm::EABI::EABI5)
- .Case("gnu", llvm::EABI::GNU)
- .Default(llvm::EABI::Unknown);
-if (EABIVersion == llvm::EABI::Unknown)
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
-<< Value;
-else
-  Opts.EABIVersion = EABIVersion;
-  }
-  Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
-  Opts.FPMath = std::string(Args.getLastArgValue(OPT_mfpmath));
   Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature);
-  Opts.LinkerVersion =
-  std::string(Args.getLastArgValue(OPT_target_linker_version));
   Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
   if (Arg *A = Args.getLastArg(options::OPT_target_sdk_version_EQ)) {
 llvm::VersionTuple Version;
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -576,12 +576,38 @@
   "Use 32-bit pointers for accessing const/local/shared address spaces">;
 defm force_enable_int128 : OptInFFlag<"force-enable-int128", "Enable", "Disable", " support for int128_t type", [], "TargetOpts->ForceEnableInt128">;
 
+def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group, Flags<[CC1Option]>,
+  MarshallingInfoString<"TargetOpts->CodeModel", [{std::string("default")}]>;
+def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>,
+  HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">,
+  MarshallingInfoString<"TargetOpts->EABIVersion", "Default">,
+  NormalizedValuesScope<"llvm::EABI">,
+  NormalizedValues<["Default", "EABI4", "EABI5", "GNU"]>, AutoNormalizeEnum;
+
+let Flags = [CC1Option, NoDriverOption] in {
+
+def target_linker_version : Separate<["-"], "target-linker-version">,
+  HelpText<"Target linker version">,
+  MarshallingInfoString<"TargetOpts->LinkerVersion">;
+def mfpmath : Separate<["-"], "mfpmath">,
+  HelpText<"Which unit to use for fp math">,
+  MarshallingInfoString<"TargetOpts->FPMath">;
+
+} // Flags = [CC1Option, NoDriverOption]
+
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
 
 def triple : Separate<["-"], "triple">,
   HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
   MarshallingInfoString<"TargetOpts->Triple", "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
   AlwaysEmit, Normalizer<"normalizeTriple">;
+def triple_EQ : Joined<["-"], "triple=">, Alias;
+def target_cpu : Separate<["-"], "target-cpu">,
+  HelpText<"Target a specific cpu type">,
+  MarshallingInfoString<"TargetOpts->CPU">;
+def target_abi : Separate<["-"], "target-abi">,
+  HelpText<"Target a particular ABI type">,
+  MarshallingInfoString<"TargetOpts->ABI">;
 
 } // Flags = [CC1Option, CC1AsOption, NoDriverOption]
 
@@ -2866,7 +2892,6 @@
 def mwatchsimulator_version_min_E

[PATCH] D84669: Port CodeGenOpts simple string flags to new option parsing system

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D84668 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84669

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Profile/c-generate.c

Index: clang/test/Profile/c-generate.c
===
--- clang/test/Profile/c-generate.c
+++ clang/test/Profile/c-generate.c
@@ -7,7 +7,7 @@
 //
 // PROF-INSTR-NONE-NOT: __llvm_prf
 //
-// PROF-INSTR-GARBAGE: invalid PGO instrumentor in argument '-fprofile-instrument=garbage'
+// PROF-INSTR-GARBAGE: invalid value 'garbage' in '-fprofile-instrument=garbage'
 
 int main(void) {
   return 0;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -308,16 +308,19 @@
   return KeyPath & Value;
 }
 
-static void FixupInvocation(CompilerInvocation &Invocation,
+static void FixupInvocation(const ArgList &Args, CompilerInvocation &Invocation,
 DiagnosticsEngine &Diags) {
   LangOptions &LangOpts = *Invocation.getLangOpts();
   DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
   CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
   FrontendOptions &FrontendOpts = Invocation.getFrontendOpts();
+  TargetOptions &TargetOpts = Invocation.getTargetOpts();
   CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
   CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
   CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
   CodeGenOpts.DisableFree = FrontendOpts.DisableFree;
+  CodeGenOpts.CodeModel = TargetOpts.CodeModel;
+
   FrontendOpts.GenerateGlobalModuleIndex = FrontendOpts.UseGlobalModuleIndex;
 
   LangOpts.Optimize = CodeGenOpts.OptimizationLevel != 0;
@@ -329,6 +332,11 @@
 
   if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
 Diags.Report(diag::warn_c_kext);
+
+  if (CodeGenOpts.ThreadModel != "posix" && CodeGenOpts.ThreadModel != "single")
+Diags.Report(diag::err_drv_invalid_value)
+<< Args.getLastArg(OPT_mthread_model)->getAsString(Args)
+<< CodeGenOpts.ThreadModel;
 }
 
 //===--===//
@@ -770,28 +778,6 @@
   }
 }
 
-// Set the profile kind for fprofile-instrument.
-static void setPGOInstrumentor(CodeGenOptions &Opts, ArgList &Args,
-   DiagnosticsEngine &Diags) {
-  Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ);
-  if (A == nullptr)
-return;
-  StringRef S = A->getValue();
-  unsigned I = llvm::StringSwitch(S)
-   .Case("none", CodeGenOptions::ProfileNone)
-   .Case("clang", CodeGenOptions::ProfileClangInstr)
-   .Case("llvm", CodeGenOptions::ProfileIRInstr)
-   .Case("csllvm", CodeGenOptions::ProfileCSIRInstr)
-   .Default(~0U);
-  if (I == ~0U) {
-Diags.Report(diag::err_drv_invalid_pgo_instrumentor) << A->getAsString(Args)
- << S;
-return;
-  }
-  auto Instrumentor = static_cast(I);
-  Opts.setProfileInstr(Instrumentor);
-}
-
 // Set the profile kind using fprofile-instrument-use-path.
 static void setPGOUseInstrumentor(CodeGenOptions &Opts,
   const Twine &ProfileName) {
@@ -853,52 +839,6 @@
 }
   }
 
-  if (Arg *A = Args.getLastArg(OPT_fveclib)) {
-StringRef Name = A->getValue();
-if (Name == "Accelerate")
-  Opts.setVecLib(CodeGenOptions::Accelerate);
-else if (Name == "MASSV")
-  Opts.setVecLib(CodeGenOptions::MASSV);
-else if (Name == "SVML")
-  Opts.setVecLib(CodeGenOptions::SVML);
-else if (Name == "none")
-  Opts.setVecLib(CodeGenOptions::NoLibrary);
-else
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
-  }
-
-  if (Arg *A = Args.getLastArg(OPT_debug_info_kind_EQ)) {
-unsigned Val =
-llvm::StringSwitch(A->getValue())
-.Case("line-tables-only", codegenoptions::DebugLineTablesOnly)
-.Case("line-directives-only", codegenoptions::DebugDirectivesOnly)
-.Case("constructor", codegenoptions::DebugInfoConstructor)
-.Case("limited", codegenoptions::LimitedDebugInfo)
-.Case("standalone", codegenoptions::FullDebugInfo)
-.Default(~0U);
-if (Val == ~0U)
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
-<< A->getValue();
-else
-  Opts.setDebugInfo(static_cast(Val));
-  }
-  if (Arg *A = Args.getLastArg(OPT_deb

[PATCH] D84670: Port HeaderSearch simple string options to new option parsing system

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D84669 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84670

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1678,10 +1678,8 @@
 
 static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
   const std::string &WorkingDir) {
-  Opts.Sysroot = std::string(Args.getLastArgValue(OPT_isysroot, "/"));
   if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
 Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0);
-  Opts.ResourceDir = std::string(Args.getLastArgValue(OPT_resource_dir));
 
   // Canonicalize -fmodules-cache-path before storing it.
   SmallString<128> P(Args.getLastArgValue(OPT_fmodules_cache_path));
@@ -1694,8 +1692,6 @@
   llvm::sys::path::remove_dots(P);
   Opts.ModuleCachePath = std::string(P.str());
 
-  Opts.ModuleUserBuildPath =
-  std::string(Args.getLastArgValue(OPT_fmodules_user_build_path));
   // Only the -fmodule-file== form.
   for (const auto *A : Args.filtered(OPT_fmodule_file)) {
 StringRef Val = A->getValue();
@@ -1707,14 +1703,6 @@
   }
   for (const auto *A : Args.filtered(OPT_fprebuilt_module_path))
 Opts.AddPrebuiltModulePath(A->getValue());
-  Opts.ModuleCachePruneInterval =
-  getLastArgIntValue(Args, OPT_fmodules_prune_interval, 7 * 24 * 60 * 60);
-  Opts.ModuleCachePruneAfter =
-  getLastArgIntValue(Args, OPT_fmodules_prune_after, 31 * 24 * 60 * 60);
-  Opts.BuildSessionTimestamp =
-  getLastArgUInt64Value(Args, OPT_fbuild_session_timestamp, 0);
-  if (const Arg *A = Args.getLastArg(OPT_fmodule_format_EQ))
-Opts.ModuleFormat = A->getValue();
 
   for (const auto *A : Args.filtered(OPT_fmodules_ignore_macro)) {
 StringRef MacroDef = A->getValue();
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1279,6 +1279,30 @@
   HelpText<"Show commands to run and use verbose output">,
   MarshallingInfoFlag<"HeaderSearchOpts->Verbose", "false">;
 
+def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, Group,
+  Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
+  HelpText<"Specify the module user build path">,
+  MarshallingInfoString<"HeaderSearchOpts->ModuleUserBuildPath">;
+def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, Group,
+  Flags<[CC1Option]>, MetaVarName<"">,
+  HelpText<"Specify the interval (in seconds) between attempts to prune the module cache">,
+  MarshallingInfoStringInt<"HeaderSearchOpts->ModuleCachePruneInterval", "7 * 24 * 60 * 60">;
+def fmodules_prune_after : Joined<["-"], "fmodules-prune-after=">, Group,
+  Flags<[CC1Option]>, MetaVarName<"">,
+  HelpText<"Specify the interval (in seconds) after which a module file will be considered unused">,
+  MarshallingInfoStringInt<"HeaderSearchOpts->ModuleCachePruneAfter", "31 * 24 *60 * 60">;
+def fbuild_session_timestamp : Joined<["-"], "fbuild-session-timestamp=">,
+  Group, Flags<[CC1Option]>, MetaVarName<"">,
+  HelpText<"Time when the current build session started">,
+  MarshallingInfoStringInt<"HeaderSearchOpts->BuildSessionTimestamp">;
+def isysroot : JoinedOrSeparate<["-"], "isysroot">, Group, Flags<[CC1Option]>,
+  HelpText<"Set the system root directory (usually /)">, MetaVarName<"">,
+  MarshallingInfoString<"HeaderSearchOpts->Sysroot", [{std::string("/")}]>;
+def resource_dir : Separate<["-"], "resource-dir">,
+  Flags<[DriverOption, CC1Option, CoreOption, HelpHidden]>,
+  HelpText<"The directory which holds the compiler resource files">,
+  MarshallingInfoString<"HeaderSearchOpts->ResourceDir">;
+
 let Flags = [CC1Option, NoDriverOption] in {
 
 def fmodule_map_file_home_is_cwd : Flag<["-"], "fmodule-map-file-home-is-cwd">,
@@ -1299,6 +1323,11 @@
"semantics of a module in an implicit build">,
   MarshallingInfoFlag<"HeaderSearchOpts->ModulesStrictContextHash", "false">;
 
+def fmodule_format_EQ : Joined<["-"], "fmodule-format=">,
+  HelpText<"Select the container format for clang modules and PCH. "
+   "Supported options are 'raw' and 'obj'.">,
+  MarshallingInfoString<"HeaderSearchOpts->ModuleFormat", [{std::string("raw")}]>;
+
 } // Flags = [CC1Option, NoDriverOption]
 
 // Language Options
@@ -2443,24 +2472,12 @@
 def fmodules_cache_path : Joined<["-"], "fmodules-cache-path=">, Group,
   Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the module cache path">;
-def fmodules_user_build_path : Separate<["-"], "fmodules-user-bui

[PATCH] D84671: Port LangOpts simple string based options to new option parsing system

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, mgrang.
Herald added projects: clang, LLVM.

Depends on D84670 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84671

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -228,7 +228,8 @@
   // Get the option groups and options.
   const std::vector &Groups =
 Records.getAllDerivedDefinitions("OptionGroup");
-  std::vector Opts = Records.getAllDerivedDefinitions("Option");
+  std::vector Opts = Records.getAllDerivedDefinitions("Option");
+  llvm::sort(Opts.begin(), Opts.end(), LessRecordByID());
 
   emitSourceFileHeader("Option Parsing Definitions", OS);
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -327,12 +327,36 @@
   LangOpts.OptimizeSize = CodeGenOpts.OptimizeSize != 0;
   LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables;
   LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening;
+  LangOpts.CurrentModule = LangOpts.ModuleName;
 
   llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
 
   if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
 Diags.Report(diag::warn_c_kext);
 
+  if (LangOpts.NewAlignOverride &&
+  !llvm::isPowerOf2_32(LangOpts.NewAlignOverride)) {
+Arg *A = Args.getLastArg(OPT_fnew_alignment_EQ);
+Diags.Report(diag::err_fe_invalid_alignment)
+<< A->getAsString(Args) << A->getValue();
+LangOpts.NewAlignOverride = 0;
+  }
+
+  if (auto *Arg = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = T.getArch();
+auto DefaultCC = LangOpts.getDefaultCallingConv();
+bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
+  DefaultCC == LangOptions::DCC_StdCall) &&
+ Arch != llvm::Triple::x86;
+emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
+  DefaultCC == LangOptions::DCC_RegCall) &&
+ !T.isX86();
+if (emitError)
+  Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << Arg->getSpelling() << T.getTriple();
+  }
+
   if (CodeGenOpts.ThreadModel != "posix" && CodeGenOpts.ThreadModel != "single")
 Diags.Report(diag::err_drv_invalid_value)
 << Args.getLastArg(OPT_mthread_model)->getAsString(Args)
@@ -2228,24 +2252,6 @@
   Opts.GNUInline = 1;
   }
 
-  if (const auto *A = Args.getLastArg(OPT_fcf_runtime_abi_EQ))
-Opts.CFRuntime =
-llvm::StringSwitch(A->getValue())
-.Cases("unspecified", "standalone", "objc",
-   LangOptions::CoreFoundationABI::ObjectiveC)
-.Cases("swift", "swift-5.0",
-   LangOptions::CoreFoundationABI::Swift5_0)
-.Case("swift-4.2", LangOptions::CoreFoundationABI::Swift4_2)
-.Case("swift-4.1", LangOptions::CoreFoundationABI::Swift4_1)
-.Default(LangOptions::CoreFoundationABI::ObjectiveC);
-
-  // The value-visibility mode defaults to "default".
-  if (Arg *visOpt = Args.getLastArg(OPT_fvisibility)) {
-Opts.setValueVisibilityMode(parseVisibility(visOpt, Args, Diags));
-  } else {
-Opts.setValueVisibilityMode(DefaultVisibility);
-  }
-
   // The type-visibility mode defaults to the value-visibility mode.
   if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) {
 Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags));
@@ -2285,20 +2291,6 @@
   Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
OPT_fno_dollars_in_identifiers,
Opts.DollarIdents);
-  Opts.setVtorDispMode(
-  MSVtorDispMode(getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags)));
-  if (Arg *A = Args.getLastArg(OPT_flax_vector_conversions_EQ)) {
-using LaxKind = LangOptions::LaxVectorConversionKind;
-if (auto Kind = llvm::StringSwitch>(A->getValue())
-.Case("none", LaxKind::None)
-.Case("integer", LaxKind::Integer)
-.Case("all", LaxKind::All)
-.Default(llvm::None))
-  Opts.setLaxVectorConversions(*Kind);
-else
-  Diags.Report(diag::err_drv_invalid_value)
-  << A->getAsString(Args) << A->getValue();
-  }
 
   // -ffixed-point
   Opts.FixedPoint =
@@ -2352,15 +2344,6 @@
   Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char);
   Opts.WChar = Opts.CPlusPlus && !Arg

[PATCH] D84672: Port PreprocessorOpts simple string based options to new option parsing system

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D84671 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84672

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2677,11 +2677,8 @@
 static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
   DiagnosticsEngine &Diags,
   frontend::ActionKind Action) {
-  Opts.ImplicitPCHInclude = std::string(Args.getLastArgValue(OPT_include_pch));
   Opts.PCHWithHdrStop = Args.hasArg(OPT_pch_through_hdrstop_create) ||
 Args.hasArg(OPT_pch_through_hdrstop_use);
-  Opts.PCHThroughHeader =
-  std::string(Args.getLastArgValue(OPT_pch_through_header_EQ));
 
   for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
@@ -2747,19 +2744,6 @@
 Opts.addRemappedFile(Split.first, Split.second);
   }
 
-  if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) {
-StringRef Name = A->getValue();
-unsigned Library = llvm::StringSwitch(Name)
-  .Case("libc++", ARCXX_libcxx)
-  .Case("libstdc++", ARCXX_libstdcxx)
-  .Case("none", ARCXX_nolib)
-  .Default(~0U);
-if (Library == ~0U)
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << 
Name;
-else
-  Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library;
-  }
-
   // Always avoid lexing editor placeholders when we're just running the
   // preprocessor as we never want to emit the
   // "editor placeholder in source file" error in PP only mode.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1783,6 +1783,10 @@
   HelpText<"undef all system defines">,
   MarshallingInfoFlag<"PreprocessorOpts->UsePredefines", "true">, IsNegative;
 
+def include_pch : Separate<["-"], "include-pch">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Include precompiled header file">, MetaVarName<"">,
+  MarshallingInfoString<"PreprocessorOpts->ImplicitPCHInclude">;
+
 let Flags = [CC1Option, NoDriverOption] in {
 
 def pch_through_hdrstop_create : Flag<["-"], "pch-through-hdrstop-create">,
@@ -1807,6 +1811,15 @@
   HelpText<"Disable any #pragma clang __debug that can lead to crashing 
behavior. This is meant for testing.">,
   MarshallingInfoFlag<"PreprocessorOpts->DisablePragmaDebugCrash", "false">;
 
+def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
+  HelpText<"Stop PCH generation after including this file.  When using a PCH, "
+   "skip tokens until after this file is included.">,
+  MarshallingInfoString<"PreprocessorOpts->PCHThroughHeader">;
+def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">,
+  HelpText<"Objective-C++ Automatic Reference Counting standard library 
kind">, Values<"libc++,libstdc++,none">,
+  MarshallingInfoString<"PreprocessorOpts->ObjCXXARCStandardLibrary", 
"ARCXX_nolib">,
+  NormalizedValues<["ARCXX_libcxx", "ARCXX_libstdcxx", "ARCXX_nolib"]>, 
AutoNormalizeEnum; 
+
 } // Flags = [CC1Option, NoDriverOption]
 
 // Preprocessor Output Options
@@ -3034,8 +3047,6 @@
 def image__base : Separate<["-"], "image_base">;
 def include_ : JoinedOrSeparate<["-", "--"], "include">, Group, 
EnumName<"include">,
 MetaVarName<"">, HelpText<"Include file before parsing">, 
Flags<[CC1Option]>;
-def include_pch : Separate<["-"], "include-pch">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Include precompiled header file">, MetaVarName<"">;
 def verify_pch : Flag<["-"], "verify-pch">, Group, 
Flags<[CC1Option]>,
   HelpText<"Load and verify that a pre-compiled header file is not stale">;
 def init : Separate<["-"], "init">;
@@ -4706,9 +4717,6 @@
 def fdump_record_layouts : Flag<["-"], "fdump-record-layouts">,
   HelpText<"Dump record layout information">;
 
-def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
-  HelpText<"Stop PCH generation after including this file.  When using a PCH, "
-   "skip tokens until after this file is included.">;
 def pch_through_hdrstop_use : Flag<["-"], "pch-through-hdrstop-use">,
   HelpText<"When using a PCH, skip tokens until after a #pragma hdrstop.">;
 
@@ -4721,8 +4729,6 @@
 
 def fno_wchar : Flag<["-"], "fno-wchar">,
   HelpText<"Disable C++ builtin type wchar_t">;
-def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">,
-  HelpText<"Objective-C++ Automatic Reference Counting standard library 
kind">, Values<"libc++,libstdc++,none">;
 def fobjc_ru

[PATCH] D84673: Port DiagnosticOpts to new option parsing system

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

DiagnosticOpts are special because the parsing is code is shared with
the driver. To ensure the code can still be shared this commit let's
diagnostic options be handled seperately so that the behavior of
ParseDiagnosticArgs can be preserved.

Depends on D84672 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84673

Files:
  clang/include/clang/Basic/DiagnosticOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -156,6 +156,9 @@
   MarshallingInfoBooleanFlag(const Record &Option, const Record &NegOption)
   : MarshallingInfo("OPTION_WITH_MARSHALLING_BOOLEAN", Option),
 NegOption(NegOption) {}
+  MarshallingInfoBooleanFlag(const char *MacroName, const Record &Option,
+ const Record &NegOption)
+  : MarshallingInfo(MacroName, Option), NegOption(NegOption) {}
 
   void emit(raw_ostream &OS) const override {
 MarshallingInfo::emit(OS);
@@ -176,10 +179,18 @@
   MarshallingInfo::Ptr Ret;
   StringRef KindString = R.getValueAsString("MarshallingInfoKind");
   if (KindString == "Default") {
-Ret = std::make_unique(R);
+if (R.getValueAsBit("IsDiagnosticsArg"))
+  Ret =
+  std::make_unique("DIAG_OPTION_WITH_MARSHALLING", R);
+else
+  Ret = std::make_unique(R);
   } else if (KindString == "BooleanFlag") {
-Ret = std::make_unique(
-R, *R.getValueAsDef("NegOption"));
+const Record &NegOption = *R.getValueAsDef("NegOption");
+if (R.getValueAsBit("IsDiagnosticsArg"))
+  Ret = std::make_unique(
+  "DIAG_OPTION_WITH_MARSHALLING_BOOLEAN", R, NegOption);
+else
+  Ret = std::make_unique(R, NegOption);
   }
 
   Ret->ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -98,6 +98,7 @@
   Option Alias = ?;
   list AliasArgs = [];
   string MarshallingInfoKind = ?;
+  bit IsDiagnosticsArg = 0;
   code KeyPath = ?;
   code DefaultValue = ?;
   bit ShouldAlwaysEmit = 0;
@@ -199,6 +200,7 @@
 }
 class ValueMerger { code ValueMerger = merger; }
 class ValueExtractor { code ValueExtractor = extractor; }
+class DiagnosticArg { bit IsDiagnosticArg = 1; }
 
 // Predefined options.
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -129,13 +129,13 @@
 static llvm::Optional normalizeSimpleFlag(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
-DiagnosticsEngine &Diags) {
+DiagnosticsEngine *Diags) {
   return Args.hasArg(Opt);
 }
 
 static llvm::Optional
 normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned TableIndex,
-const ArgList &Args, DiagnosticsEngine &Diags) {
+const ArgList &Args, DiagnosticsEngine *Diags) {
   return !Args.hasArg(Opt);
 }
 
@@ -151,7 +151,7 @@
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
- DiagnosticsEngine &Diags) {
+ DiagnosticsEngine *Diags) {
   if (Args.hasArg(Opt))
 return Value;
   return None;
@@ -161,7 +161,7 @@
OptSpecifier NegOpt,
unsigned TableIndex,
const ArgList &Args,
-   DiagnosticsEngine &Diags) {
+   DiagnosticsEngine *Diags) {
   if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
 return A->getOption().matches(PosOpt);
   return None;
@@ -180,7 +180,7 @@
 
 static Optional normalizeString(OptSpecifier Opt, int TableIndex,
  const ArgList &Args,
- DiagnosticsEngine &Diags) {
+ DiagnosticsEngine *Diags) {
   auto *Arg = Args.getLastArg(Opt);
   if (!Arg)
 return None;
@@ -231,7 +231,7 @@
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
   

[PATCH] D84674: Allow users to specify a conditional to prevent parsing options with MarshallingInfo

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

Depends on D84673 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84674

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -66,6 +66,7 @@
   const char *MacroName;
   const Record &R;
   bool ShouldAlwaysEmit;
+  StringRef ShouldParse;
   StringRef KeyPath;
   StringRef DefaultValue;
   StringRef NormalizedValuesScope;
@@ -107,6 +108,8 @@
 OS << ", ";
 OS << ShouldAlwaysEmit;
 OS << ", ";
+OS << ShouldParse;
+OS << ", ";
 OS << KeyPath;
 OS << ", ";
 emitScopedNormalizedValue(OS, DefaultValue);
@@ -194,6 +197,7 @@
   }
 
   Ret->ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
+  Ret->ShouldParse = R.getValueAsString("ShouldParse");
   Ret->KeyPath = R.getValueAsString("KeyPath");
   Ret->DefaultValue = R.getValueAsString("DefaultValue");
   Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -102,6 +102,7 @@
   code KeyPath = ?;
   code DefaultValue = ?;
   bit ShouldAlwaysEmit = 0;
+  code ShouldParse = "true";
   code NormalizedValuesScope = "";
   code Normalizer = "";
   code Denormalizer = "";
@@ -201,6 +202,7 @@
 class ValueMerger { code ValueMerger = merger; }
 class ValueExtractor { code ValueExtractor = extractor; }
 class DiagnosticArg { bit IsDiagnosticArg = 1; }
+class ShouldParseIf { code ShouldParse = shouldparse; }
 
 // Predefined options.
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1260,9 +1260,9 @@
 
 #define DIAG_OPTION_WITH_MARSHALLING(  \
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
-NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)  \
-  {\
+HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, SHOULD_PARSE, KEYPATH,   \
+DEFAULT_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)   \
+  if (SHOULD_PARSE) {  \
 if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))  \
   Opts.KEYPATH = MERGER(Opts.KEYPATH,  \
 static_cast(*MaybeValue)); \
@@ -1272,10 +1272,10 @@
 
 #define DIAG_OPTION_WITH_MARSHALLING_BOOLEAN(  \
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
-NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,  \
-NEG_SPELLING)  \
-  {\
+HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, SHOULD_PARSE, KEYPATH,   \
+DEFAULT_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX,   \
+NEG_ID, NEG_SPELLING)  \
+  if (SHOULD_PARSE) {  \
 if (auto MaybeValue =  \
 NORMALIZER(OPT_##ID, OPT_##NEG_ID, TABLE_INDEX, Args, Diags))  \
   Opts.KEYPATH = MERGER(Opts.KEYPATH,  \
@@ -2065,21 +2065,6 @@
   }
 
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
-  if (Opts.SYCL) {
-// -sycl-std applies to any SYCL source, not only those containing kernels,
-// but also those using the SYCL API
-if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
-  Opts.SYCLVersion = llvm::StringSwitch(A->getValue())
- .Cases("2017", "1.2.1", "121", "sycl-1.2.1", 2017)
- .Default(0U);
-
-  if (Opts.SYCLVersion == 0U) {
-// User has passed an invalid value to the flag, this is an error
-Diags.Report(diag::err_drv_invalid_value)
-<< A->getAsString(Args) << A->

[PATCH] D84675: Streamline MarhsallingInfoFlag description

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1, dexonsmith, 
aheejin.
Herald added a reviewer: jdoerfert.
Herald added projects: clang, LLVM.

This replaces the existing `MarshallingInfoFlag` and `IsNegative` with simpler
`MarshalllingInfoFlag` and `MarshallingInfoNegativeFlag` mixins. This change
makes existing marshalling info specifications in Options.td easier to read.

Depends on D84674 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84675

Files:
  clang/include/clang/Driver/Options.td
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -164,20 +164,26 @@
   code Denormalizer = "denormalizeString";
 }
 
-class MarshallingInfoFlag
-  : MarshallingInfo {
+class MarshallingInfoFlag
+  : MarshallingInfo {
   code Normalizer = "normalizeSimpleFlag";
   code Denormalizer = "denormalizeSimpleFlag";
 }
 
-class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
+class MarshallingInfoNegativeFlag
+  : MarshallingInfo {
+  code Normalizer = "normalizeSimpleNegativeFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
+}
+
+class MarshallingInfoBitfieldFlag : MarshallingInfo {
   code Normalizer = "(normalizeFlagToValue)";
   code ValueMerger = "mergeMaskValue";
   code ValueExtractor = "(extractMaskValue)";
 }
 
 class MarshallingInfoBooleanFlag
-  : MarshallingInfoFlag {
+  : MarshallingInfo {
   bit ShouldAlwaysEmit = 1;
   string MarshallingInfoKind = "BooleanFlag";
   code Normalizer = "normalizeBooleanFlag";
@@ -187,9 +193,7 @@
 
 // Mixins for additional marshalling attributes.
 
-class IsNegative {
-  code Normalizer = "normalizeSimpleNegativeFlag";
-}
+class DefaultValue { code DefaultValue = defaultvalue; }
 class AlwaysEmit { bit ShouldAlwaysEmit = 1; }
 class Normalizer { code Normalizer = normalizer; }
 class Denormalizer { code Denormalizer = denormalizer; }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -233,7 +233,7 @@
   string help="", list flags=[], code keypath=""> {
   def f#NAME : Flag<["-"], "f"#name>, Flags,
Group, HelpText,
-   MarshallingInfoFlag;
+   MarshallingInfoFlag;
   def fno_#NAME : Flag<["-"], "fno-"#name>, Flags,
Group, HelpText;
 }
@@ -246,7 +246,7 @@
Group, HelpText;
   def fno_#NAME : Flag<["-"], "fno-"#name>, Flags,
Group, HelpText,
-   MarshallingInfoFlag;
+   MarshallingInfoFlag;
 }
 
 multiclass BooleanMarshalledFFlag {
@@ -331,7 +331,7 @@
 // Comment Options
 
 def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group, Flags<[CC1Option]>,
-  MarshallingInfoFlag<"LangOpts->CommentOpts.ParseAllComments", "false">;
+  MarshallingInfoFlag<"LangOpts->CommentOpts.ParseAllComments">;
 
 // Filesystem Options FileSystemOpts
 
@@ -345,17 +345,18 @@
 
 def MV : Flag<["-"], "MV">, Group, Flags<[CC1Option]>,
 HelpText<"Use NMake/Jom format for the depfile">,
-MarshallingInfoFlag<"DependencyOutputOpts.OutputFormat", "DependencyOutputFormat::Make">,
+MarshallingInfoFlag<"DependencyOutputOpts.OutputFormat">,
+DefaultValue<"DependencyOutputFormat::Make">,
 Normalizer<"(normalizeFlagToValue)">;
 def H : Flag<["-"], "H">, Flags<[CC1Option]>, Group,
 HelpText<"Show header includes and nesting depth">,
-MarshallingInfoFlag<"DependencyOutputOpts.ShowHeaderIncludes", "false">;
+MarshallingInfoFlag<"DependencyOutputOpts.ShowHeaderIncludes">;
 def MG : Flag<["-"], "MG">, Group, Flags<[CC1Option]>,
 HelpText<"Add missing headers to depfile">,
-MarshallingInfoFlag<"DependencyOutputOpts.AddMissingHeaderDeps", "false">;
+MarshallingInfoFlag<"DependencyOutputOpts.AddMissingHeaderDeps">;
 def MP : Flag<["-"], "MP">, Group, Flags<[CC1Option]>,
 HelpText<"Create phony target for each dependency (other than main file)">,
-MarshallingInfoFlag<"DependencyOutputOpts.UsePhonyTargets", "false">;
+MarshallingInfoFlag<"DependencyOutputOpts.UsePhonyTargets">;
 
 def dependency_file : Separate<["-"], "dependency-file">, Flags<[CC1Option]>,
   HelpText<"Filename (or -) to write dependency output to">,
@@ -371,10 +372,10 @@
 
 def sys_header_deps : Flag<["-"], "sys-header-deps">,
   HelpText<"Include system headers in dependency output">,
-  MarshallingInfoFlag<"DependencyOutputOpts.IncludeSystemHeaders", "false">;
+  MarshallingInfoFlag<"DependencyOutputOpts.IncludeSystemHeaders">;
 def module_file_deps : Flag<["-"], "module-file-deps">,
   HelpText<"Include module files in dependency output">,
-  MarshallingInfoFlag<"DependencyOutputOpts.IncludeModul

[PATCH] D84676: Add new diagnostic for invalid value provided for enum-based option

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

This adds a more precise diagnostics for options that have a well defined set of
acceptable values.

Depends on D84675 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84676

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/debug-options.c
  clang/test/Driver/eabi.c
  clang/test/Driver/fveclib.c
  clang/test/Driver/reloc-model.c
  clang/test/Profile/c-generate.c
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -90,6 +90,7 @@
 struct SimpleEnumValueTable {
   const SimpleEnumValue *Table;
   unsigned Size;
+  const char *EnumValuesString;
 };
 )";
 
@@ -452,16 +453,21 @@
   OS << "#ifdef SIMPLE_ENUM_VALUE_TABLE";
   OS << "\n";
   OS << MarshallingInfo::ValueTablePreamble;
-  std::vector ValueTableNames;
+  std::vector> ValueTableDescs;
   for (const auto &KindInfo : OptsWithMarshalling)
 if (auto MaybeValueTableName = KindInfo->emitValueTable(OS))
-  ValueTableNames.push_back(*MaybeValueTableName);
+  ValueTableDescs.push_back(
+  {*MaybeValueTableName, KindInfo->R.getValueAsString("Values")});
 
   OS << MarshallingInfo::ValueTablesDecl << "{";
-  for (auto ValueTableName : ValueTableNames)
-OS << "{" << ValueTableName << ", sizeof(" << ValueTableName
-   << ") / sizeof(SimpleEnumValue)"
-   << "},\n";
+  for (auto ValueTable : ValueTableDescs) {
+auto Name = ValueTable.first;
+auto ValuesString = ValueTable.second;
+OS << "{" << Name << ", sizeof(" << Name << ") / sizeof(SimpleEnumValue)"
+   << ", ";
+write_cstring(OS, ValuesString);
+OS << "},\n";
+  }
   OS << "};\n";
   OS << "static const unsigned SimpleEnumValueTablesSize = "
 "sizeof(SimpleEnumValueTables) / sizeof(SimpleEnumValueTable);\n";
Index: clang/test/Profile/c-generate.c
===
--- clang/test/Profile/c-generate.c
+++ clang/test/Profile/c-generate.c
@@ -7,7 +7,7 @@
 //
 // PROF-INSTR-NONE-NOT: __llvm_prf
 //
-// PROF-INSTR-GARBAGE: invalid value 'garbage' in '-fprofile-instrument=garbage'
+// PROF-INSTR-GARBAGE: invalid value 'garbage' in '-fprofile-instrument=garbage', expected one of none,clang,llvm,csllvm
 
 int main(void) {
   return 0;
Index: clang/test/Driver/reloc-model.c
===
--- clang/test/Driver/reloc-model.c
+++ clang/test/Driver/reloc-model.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -cc1 -mrelocation-model tinkywinky \
 // RUN: -emit-llvm %s 2>&1 | FileCheck -check-prefix CHECK-INVALID %s
 
-// CHECK-INVALID: error: invalid value 'tinkywinky' in '-mrelocation-model tinkywinky'
+// CHECK-INVALID: error: invalid value 'tinkywinky' in '-mrelocation-model tinkywinky', expected one of static,pic,ropi,rwpi,ropi-rwpi,dynamic-no-pic
Index: clang/test/Driver/fveclib.c
===
--- clang/test/Driver/fveclib.c
+++ clang/test/Driver/fveclib.c
@@ -7,7 +7,7 @@
 // CHECK-ACCELERATE: "-fveclib=Accelerate"
 // CHECK-MASSV: "-fveclib=MASSV"
 
-// CHECK-INVALID: error: invalid value 'something' in '-fveclib=something'
+// CHECK-INVALID: error: invalid value 'something' in '-fveclib=something', expected one of Accelerate,MASSV,SVML,none
 
 // RUN: %clang -fveclib=Accelerate %s -target arm64-apple-ios8.0.0 -### 2>&1 | FileCheck --check-prefix=CHECK-LINK %s
 // CHECK-LINK: "-framework" "Accelerate"
Index: clang/test/Driver/eabi.c
===
--- clang/test/Driver/eabi.c
+++ clang/test/Driver/eabi.c
@@ -10,4 +10,4 @@
 // CHECK-EABI4: "-meabi" "4"
 // CHECK-EABI5: "-meabi" "5"
 // CHECK-GNUEABI: "-meabi" "gnu"
-// CHECK-UNKNOWN: error: invalid value 'unknown' in '-meabi unknown'
+// CHECK-UNKNOWN: error: invalid value 'unknown' in '-meabi unknown', expected one of default,4,5,gnu
Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -342,7 +342,7 @@
 // GEXTREFS: "-debug-info-kind={{standalone|constructor}}"
 
 // RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
-// BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
+// BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind', expected one of line-tables-only,line-directives-only,constructor,limited,standalone
 // RUN: not %clang -cc1 -debugger-tuning=gmodal 2>&1 | FileCheck -check-prefix=BADSTRING2 %s
 // BADSTRI

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

2020-07-27 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/test/CodeGen/fp-function-attrs.cpp:2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffinite-math-only 
-menable-unsafe-fp-math \
+// RUN:   -menable-no-infs -menable-no-nans -fno-signed-zeros 
-freciprocal-math \
+// RUN:   -fapprox-func -mreassociate -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s

Anastasia wrote:
> dang wrote:
> > Anastasia wrote:
> > > Not clear why do you need to pass these extra flags now?
> > Previously passing -ffast-math to CC1 implied all these other flags. I am 
> > trying to make CC1 option parsing as simple as possible, so that we can 
> > then make it easy to generate a command line from a CompilerInvocation 
> > instance. You can refer to [[ 
> > http://lists.llvm.org/pipermail/cfe-dev/2020-May/065421.html | 
> > http://lists.llvm.org/pipermail/cfe-dev/2020-May/065421.html ]] for more 
> > details on why we want to be able to do this
> Just to understand, there used to be implied flags and it made the manual 
> command line use of clang more compact and easy... Is the idea now to change 
> those compound flags such that individul flags always need to be passed?
> 
> Although I thought you are still adding the implicit flags:
> 
>   {options::OPT_cl_fast_relaxed_math,
>[&](const Arg *Arg) {
>  RenderArg(Arg);
> 
>  CmdArgs.push_back(GetArgString(options::OPT_cl_mad_enable));
>  CmdArgs.push_back(GetArgString(options::OPT_ffast_math));
>  CmdArgs.push_back(GetArgString(options::OPT_ffinite_math_only));
>  CmdArgs.push_back(
>  GetArgString(options::OPT_menable_unsafe_fp_math));
>  CmdArgs.push_back(GetArgString(options::OPT_mreassociate));
>  CmdArgs.push_back(GetArgString(options::OPT_menable_no_nans));
>  CmdArgs.push_back(
>  GetArgString(options::OPT_menable_no_infinities));
>  CmdArgs.push_back(GetArgString(options::OPT_fno_signed_zeros));
>  CmdArgs.push_back(GetArgString(options::OPT_freciprocal_math));
>  CmdArgs.push_back(GetArgString(options::OPT_fapprox_func));
>}}
> 
> Do I just misunderstand something?
The command line of the driver doesn't change. This patch only affects what CC1 
understands, now CC1 doesn't know anymore that `-cl-fast-relaxed-math` implies 
all these other options so the driver is responsible for specifying them when 
it constructs the CC1 command line.

To summarize, the clang driver command line isn't affected by this patch and it 
shouldn't be so let me know if something is wrong there. However, manually 
constructed `clang -cc1` invocations need to specify the all the implied flags 
manually now.


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] D84674: Allow users to specify a conditional to prevent parsing options with MarshallingInfo

2020-07-29 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 281614.
dang added a comment.

Ensure that the default value is assigned even if the option should not get
parsed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84674

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -66,6 +66,7 @@
   const char *MacroName;
   const Record &R;
   bool ShouldAlwaysEmit;
+  StringRef ShouldParse;
   StringRef KeyPath;
   StringRef DefaultValue;
   StringRef NormalizedValuesScope;
@@ -107,6 +108,8 @@
 OS << ", ";
 OS << ShouldAlwaysEmit;
 OS << ", ";
+OS << ShouldParse;
+OS << ", ";
 OS << KeyPath;
 OS << ", ";
 emitScopedNormalizedValue(OS, DefaultValue);
@@ -194,6 +197,7 @@
   }
 
   Ret->ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
+  Ret->ShouldParse = R.getValueAsString("ShouldParse");
   Ret->KeyPath = R.getValueAsString("KeyPath");
   Ret->DefaultValue = R.getValueAsString("DefaultValue");
   Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -102,6 +102,7 @@
   code KeyPath = ?;
   code DefaultValue = ?;
   bit ShouldAlwaysEmit = 0;
+  code ShouldParse = "true";
   code NormalizedValuesScope = "";
   code Normalizer = "";
   code Denormalizer = "";
@@ -201,6 +202,7 @@
 class ValueMerger { code ValueMerger = merger; }
 class ValueExtractor { code ValueExtractor = extractor; }
 class DiagnosticArg { bit IsDiagnosticArg = 1; }
+class ShouldParseIf { code ShouldParse = shouldparse; }
 
 // Predefined options.
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1260,29 +1260,25 @@
 
 #define DIAG_OPTION_WITH_MARSHALLING(  \
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
-NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)  \
-  {\
+HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, SHOULD_PARSE, KEYPATH,   \
+DEFAULT_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)   \
+  Opts.KEYPATH = MERGER(Opts.KEYPATH, DEFAULT_VALUE);  \
+  if (SHOULD_PARSE)\
 if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))  \
   Opts.KEYPATH = MERGER(Opts.KEYPATH,  \
-static_cast(*MaybeValue)); \
-else   \
-  Opts.KEYPATH = MERGER(Opts.KEYPATH, DEFAULT_VALUE);  \
-  }
+static_cast(*MaybeValue));
 
 #define DIAG_OPTION_WITH_MARSHALLING_BOOLEAN(  \
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
-NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,  \
-NEG_SPELLING)  \
-  {\
+HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, SHOULD_PARSE, KEYPATH,   \
+DEFAULT_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX,   \
+NEG_ID, NEG_SPELLING)  \
+  Opts.KEYPATH = MERGER(Opts.KEYPATH, DEFAULT_VALUE);  \
+  if (SHOULD_PARSE)\
 if (auto MaybeValue =  \
 NORMALIZER(OPT_##ID, OPT_##NEG_ID, TABLE_INDEX, Args, Diags))  \
   Opts.KEYPATH = MERGER(Opts.KEYPATH,  \
-static_cast(*MaybeValue)); \
-else   \
-  Opts.KEYPATH = MERGER(Opts.KEYPATH, DEFAULT_VALUE);  \
-  }
+static_cast(*MaybeValue));
 
 #include "clang/Driver/Options.inc"
 #undef DIAG_OPT

[PATCH] D84671: Port LangOpts simple string based options to new option parsing system

2020-07-30 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 281820.
dang added a comment.

Remove accidental addition


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84671

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -228,7 +228,7 @@
   // Get the option groups and options.
   const std::vector &Groups =
 Records.getAllDerivedDefinitions("OptionGroup");
-  std::vector Opts = Records.getAllDerivedDefinitions("Option");
+  std::vector Opts = Records.getAllDerivedDefinitions("Option");
 
   emitSourceFileHeader("Option Parsing Definitions", OS);
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -327,12 +327,36 @@
   LangOpts.OptimizeSize = CodeGenOpts.OptimizeSize != 0;
   LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables;
   LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening;
+  LangOpts.CurrentModule = LangOpts.ModuleName;
 
   llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
 
   if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
 Diags.Report(diag::warn_c_kext);
 
+  if (LangOpts.NewAlignOverride &&
+  !llvm::isPowerOf2_32(LangOpts.NewAlignOverride)) {
+Arg *A = Args.getLastArg(OPT_fnew_alignment_EQ);
+Diags.Report(diag::err_fe_invalid_alignment)
+<< A->getAsString(Args) << A->getValue();
+LangOpts.NewAlignOverride = 0;
+  }
+
+  if (auto *Arg = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = T.getArch();
+auto DefaultCC = LangOpts.getDefaultCallingConv();
+bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
+  DefaultCC == LangOptions::DCC_StdCall) &&
+ Arch != llvm::Triple::x86;
+emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
+  DefaultCC == LangOptions::DCC_RegCall) &&
+ !T.isX86();
+if (emitError)
+  Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << Arg->getSpelling() << T.getTriple();
+  }
+
   if (CodeGenOpts.ThreadModel != "posix" && CodeGenOpts.ThreadModel != "single")
 Diags.Report(diag::err_drv_invalid_value)
 << Args.getLastArg(OPT_mthread_model)->getAsString(Args)
@@ -2228,24 +2252,6 @@
   Opts.GNUInline = 1;
   }
 
-  if (const auto *A = Args.getLastArg(OPT_fcf_runtime_abi_EQ))
-Opts.CFRuntime =
-llvm::StringSwitch(A->getValue())
-.Cases("unspecified", "standalone", "objc",
-   LangOptions::CoreFoundationABI::ObjectiveC)
-.Cases("swift", "swift-5.0",
-   LangOptions::CoreFoundationABI::Swift5_0)
-.Case("swift-4.2", LangOptions::CoreFoundationABI::Swift4_2)
-.Case("swift-4.1", LangOptions::CoreFoundationABI::Swift4_1)
-.Default(LangOptions::CoreFoundationABI::ObjectiveC);
-
-  // The value-visibility mode defaults to "default".
-  if (Arg *visOpt = Args.getLastArg(OPT_fvisibility)) {
-Opts.setValueVisibilityMode(parseVisibility(visOpt, Args, Diags));
-  } else {
-Opts.setValueVisibilityMode(DefaultVisibility);
-  }
-
   // The type-visibility mode defaults to the value-visibility mode.
   if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) {
 Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags));
@@ -2285,20 +2291,6 @@
   Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
OPT_fno_dollars_in_identifiers,
Opts.DollarIdents);
-  Opts.setVtorDispMode(
-  MSVtorDispMode(getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags)));
-  if (Arg *A = Args.getLastArg(OPT_flax_vector_conversions_EQ)) {
-using LaxKind = LangOptions::LaxVectorConversionKind;
-if (auto Kind = llvm::StringSwitch>(A->getValue())
-.Case("none", LaxKind::None)
-.Case("integer", LaxKind::Integer)
-.Case("all", LaxKind::All)
-.Default(llvm::None))
-  Opts.setLaxVectorConversions(*Kind);
-else
-  Diags.Report(diag::err_drv_invalid_value)
-  << A->getAsString(Args) << A->getValue();
-  }
 
   // -ffixed-point
   Opts.FixedPoint =
@@ -2352,15 +2344,6 @@
   Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char);
   Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar);
   Opts.Char8 = Args.hasFlag(OPT_fchar8__t, OPT_fno_char8__t, Opts.CPlusPlus20);
-  if (const Arg *

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 268746.
dang marked 3 inline comments as done.
dang added a comment.

Address some code review feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -9,6 +9,7 @@
 #include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
@@ -33,18 +34,18 @@
   return OS;
 }
 
-static void emitMarshallingInfo(raw_ostream &OS, const Record &R) {
-  OS << R.getValueAsString("KeyPath");
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsBit("IsPositive");
+  OS << ",";
+  OS << R->getValueAsString("DefaultValue");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsString("DefaultValue");
   OS << ", ";
-  if (!isa(R.getValueInit("IsPositive")))
-OS << R.getValueAsBit("IsPositive");
-  else
-OS << "INVALID";
+  OS << R->getValueAsString("Normalizer");
   OS << ", ";
-  if (!isa(R.getValueInit("DefaultValue")))
-OS << R.getValueAsString("DefaultValue");
-  else
-OS << "INVALID";
+  OS << R->getValueAsString("Denormalizer");
 }
 
 /// OptParserEmitter - This tablegen backend takes an input .td file
@@ -246,15 +247,30 @@
   OS << "#endif // OPTION\n";
 
   OS << "#ifdef OPTION_WITH_MARSHALLING\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
 
 if (!isa(R.getValueInit("MarshallingInfo"))) {
-  OS << "OPTION_WITH_MARSHALLING(";
+  Record *MarshallingInfoRecord =
+  cast(R.getValueInit("MarshallingInfo"))->getDef();
+  StringRef KindStr = MarshallingInfoRecord->getValueAsString("Kind");
+  auto KindInfoPair =
+  StringSwitch>>(
+  KindStr)
+  .Case("flag", std::make_pair("OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag))
+  .Case("string", std::make_pair("OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString))
+  .Default(std::make_pair("", nullptr));
+  OS << KindInfoPair.first << "(";
   WriteOptRecordFields(OS, R);
   OS << ", ";
-  emitMarshallingInfo(
-  OS, *cast(R.getValueInit("MarshallingInfo"))->getDef());
+  OS << MarshallingInfoRecord->getValueAsBit("ShouldAlwaysEmit");
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsString("KeyPath");
+  OS << ", ";
+  KindInfoPair.second(OS, MarshallingInfoRecord);
   OS << ")\n";
 }
   }
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -81,13 +81,15 @@
 }
 
 // Add support for generating marshalling code
-
-class OptionMarshallingInfo {
+class OptionMarshallingInfo {
+  string Kind = kind;
+  bit ShouldAlwaysEmit = 0;
   code KeyPath = keypath;
   // Used by the Flag option kind.
   bit IsPositive = ?;
   code DefaultValue = ?;
-  list EnumValues = ?;
+  code Normalizer = ?;
+  code Denormalizer = ?;
 }
 
 // Define the option class.
@@ -143,20 +145,24 @@
 
 class MarshallingInfo { OptionMarshallingInfo MarshallingInfo = info; }
 class MarshallingFlag
-  : OptionMarshallingInfo {
+  : OptionMarshallingInfo<"flag", keypath> {
   bit IsPositive = ispositive;
   code DefaultValue = defaultvalue;
 }
-class MarshallingString
-  : OptionMarshallingInfo {
-  code DefaultValue = defaultvalue;
+class MarshallingFlagAlwaysEmit
+  : MarshallingFlag {
+  let ShouldAlwaysEmit = 1;
 }
-class MarshallingEnum enumvalues>
-  : OptionMarshallingInfo {
+class MarshallingString
+  : OptionMarshallingInfo<"string", keypath> {
   code DefaultValue = defaultvalue;
-  listEnumValues = enumvalues;
+  code Normalizer = normalizer;
+  code Denormalizer = denormalizer;
+}
+class MarshallingStringAlwaysEmit
+  : MarshallingString {
+  let ShouldAlwaysEmit = 1;
 }
-
 // Predefined options.
 
 // FIXME: Have generator validate that these appear in correct position (and
Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- c

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 4 inline comments as done.
dang added inline comments.



Comment at: clang/include/clang/Frontend/CompilerInvocation.h:248
+  /// \returns - True if parsing was successful, false otherwise
+  bool parseSimpleArgs(const llvm::opt::ArgList &Args,
+   DiagnosticsEngine &Diags);

Bigcheese wrote:
> Is there a reason for this to be a member of `CompilerInvocation`? The rest 
> of the argument parsing functions are static file local functions.
All the keypaths have to be "relative" to `CompilerInvocation` so that 
different options can be processed uniformly i.e. we don't want to add extra 
specialization to the table-gen file that indicates if an option is for the 
analyzer or for codegen e.t.c. Some of the members of `CompilerInvocation` that 
store options are private, which means that if parseSimpleArgs which precludes 
it from being an free function with internal linkage. Unless you think all the 
`CompilerInvocation` members should be public, but that is a different can of 
worms.



Comment at: clang/unittests/Frontend/CompilerInvocationTest.cpp:41
+TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineFlag) {
+  const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", 
"-"};
+

Bigcheese wrote:
> This reminded me that some of the -cc1 arguments are positional such as 
> `-xc++`. I think we'll need custom handling for `INPUT` arguments, although 
> we don't need them (or want them) for the modules use case. Do you have any 
> thoughts on how to handle them? I don't think answering that should block the 
> initial patch though.
`-x` flags are no `INPUT` arguments as in it can appear anywhere but will apply 
to the inputs. The only part of `CompilerInvocation` that uses positional 
arguments is the input file(s) which is quite small (21 LOC) so I am happy to 
leave it as is, having a few line to add it at the end of the command line is 
not a big problem IMO. 
The thing I am more worried about is that the processing for some options 
depends on other options having already been processed, I was planning to 
reorder them accordingly in the td file although I am not a fan of doing this, 
I think it would be better to addd the information using table-gen's DAG 
support although that would complicated the table-gen backend.



Comment at: llvm/include/llvm/Option/OptParser.td:167-171
+class MarshallingEnum enumvalues>
+  : OptionMarshallingInfo<"enum", keypath> {
+  code DefaultValue = defaultvalue;
+  listEnumValues = enumvalues;
+}

Bigcheese wrote:
> I noticed that this isn't being used for the enum case you added 
> (`-mrelocation-model`). Do you intend to use it? You should either use it in 
> this patch or remove it until it actually is used.
Yeah, I forgot to remove it, since the normalizer scheme subsumes the 
functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796



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


[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 268869.
dang marked an inline comment as done.
dang added a comment.

Updating the patch with the correct merge base


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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -9,6 +9,7 @@
 #include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
@@ -33,6 +34,20 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsBit("IsPositive");
+  OS << ",";
+  OS << R->getValueAsString("DefaultValue");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsString("DefaultValue");
+  OS << ", ";
+  OS << R->getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R->getValueAsString("Denormalizer");
+}
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +150,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -223,11 +234,48 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
+
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
 
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
 
+  OS << "#ifdef OPTION_WITH_MARSHALLING\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+
+if (!isa(R.getValueInit("MarshallingInfo"))) {
+  Record *MarshallingInfoRecord =
+  cast(R.getValueInit("MarshallingInfo"))->getDef();
+  StringRef KindStr = MarshallingInfoRecord->getValueAsString("Kind");
+  auto KindInfoPair =
+  StringSwitch>>(
+  KindStr)
+  .Case("flag", std::make_pair("OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag))
+  .Case("string", std::make_pair("OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString))
+  .Default(std::make_pair("", nullptr));
+  OS << KindInfoPair.first << "(";
+  WriteOptRecordFields(OS, R);
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsBit("ShouldAlwaysEmit");
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsString("KeyPath");
+  OS << ", ";
+  KindInfoPair.second(OS, MarshallingInfoRecord);
+  OS << ")\n";
+}
+  }
+  OS << "#endif // OPTION_WITH_MARSHALLING\n";
+
   OS << "\n";
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -80,6 +80,18 @@
   list Flags = [];
 }
 
+// Add support for generating marshalling code
+class OptionMarshallingInfo {
+  string Kind = kind;
+  bit ShouldAlwaysEmit = 0;
+  code KeyPath = keypath;
+  // Used by the Flag option kind.
+  bit IsPositive = ?;
+  code DefaultValue = ?;
+  code Normalizer = ?;
+  code Denormalizer = ?;
+}
+
 // Define the option class.
 
 class Option prefixes, string name, OptionKind kind> {
@@ -97,6 +109,7 @@
   OptionGroup Group = ?;
   Option Alias = ?;
   list AliasArgs = [];
+  OptionMarshallingInfo MarshallingInfo = ?;
 }
 
 // Helpers for defining options.
@@ -130,6 +143,26 @@
 class Values { string Values = value; }
 class ValuesCode { code ValuesCode = valuecode; }
 
+class MarshallingInfo { OptionMarshallingInfo MarshallingInfo = info; }
+class MarshallingFlag
+  : OptionMarshallingInfo<"flag", keypath> {
+  bit IsPositive = ispositive;
+  code DefaultValue = defaultvalue;
+}
+class MarshallingFlagAlwaysEmit
+  : MarshallingFlag {
+  

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 268872.
dang added a comment.

This is the good diff


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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -9,6 +9,7 @@
 #include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
@@ -33,6 +34,20 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsBit("IsPositive");
+  OS << ",";
+  OS << R->getValueAsString("DefaultValue");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record *R) {
+  OS << R->getValueAsString("DefaultValue");
+  OS << ", ";
+  OS << R->getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R->getValueAsString("Denormalizer");
+}
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +150,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -223,11 +234,48 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
+
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
 
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
   }
   OS << "#endif // OPTION\n";
 
+  OS << "#ifdef OPTION_WITH_MARSHALLING\n";
+  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
+const Record &R = *Opts[I];
+
+if (!isa(R.getValueInit("MarshallingInfo"))) {
+  Record *MarshallingInfoRecord =
+  cast(R.getValueInit("MarshallingInfo"))->getDef();
+  StringRef KindStr = MarshallingInfoRecord->getValueAsString("Kind");
+  auto KindInfoPair =
+  StringSwitch>>(
+  KindStr)
+  .Case("flag", std::make_pair("OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag))
+  .Case("string", std::make_pair("OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString))
+  .Default(std::make_pair("", nullptr));
+  OS << KindInfoPair.first << "(";
+  WriteOptRecordFields(OS, R);
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsBit("ShouldAlwaysEmit");
+  OS << ", ";
+  OS << MarshallingInfoRecord->getValueAsString("KeyPath");
+  OS << ", ";
+  KindInfoPair.second(OS, MarshallingInfoRecord);
+  OS << ")\n";
+}
+  }
+  OS << "#endif // OPTION_WITH_MARSHALLING\n";
+
   OS << "\n";
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -80,6 +80,18 @@
   list Flags = [];
 }
 
+// Add support for generating marshalling code
+class OptionMarshallingInfo {
+  string Kind = kind;
+  bit ShouldAlwaysEmit = 0;
+  code KeyPath = keypath;
+  // Used by the Flag option kind.
+  bit IsPositive = ?;
+  code DefaultValue = ?;
+  code Normalizer = ?;
+  code Denormalizer = ?;
+}
+
 // Define the option class.
 
 class Option prefixes, string name, OptionKind kind> {
@@ -97,6 +109,7 @@
   OptionGroup Group = ?;
   Option Alias = ?;
   list AliasArgs = [];
+  OptionMarshallingInfo MarshallingInfo = ?;
 }
 
 // Helpers for defining options.
@@ -130,6 +143,26 @@
 class Values { string Values = value; }
 class ValuesCode { code ValuesCode = valuecode; }
 
+class MarshallingInfo { OptionMarshallingInfo MarshallingInfo = info; }
+class MarshallingFlag
+  : OptionMarshallingInfo<"flag", keypath> {
+  bit IsPositive = ispositive;
+  code DefaultValue = defaultvalue;
+}
+class MarshallingFlagAlwaysEmit
+  : MarshallingFlag {
+  let ShouldAlwaysEmit = 1;
+}
+class MarshallingString
+  : Optio

[PATCH] D81347: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t

2020-06-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/include/clang/Basic/Module.h:70
+
+  static ASTFileSignature createDISentinel() {
+ASTFileSignature Sentinel;

I couldn't find anywhere in the code base that checks the bit-pattern so I left 
it as is. If anyone knows if someone could point me to the code that checks 
this (if any code does check it) that would be nice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81347



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


[PATCH] D81347: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t

2020-06-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added reviewers: aprantl, dexonsmith, Bigcheese.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/include/clang/Basic/Module.h:70
+
+  static ASTFileSignature createDISentinel() {
+ASTFileSignature Sentinel;

I couldn't find anywhere in the code base that checks the bit-pattern so I left 
it as is. If anyone knows if someone could point me to the code that checks 
this (if any code does check it) that would be nice.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81347

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp

Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -643,10 +643,10 @@
 
 // Skip the stored signature.
 // FIXME: we could read the signature out of the import and validate it.
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 // Skip the module name (currently this is only used for prebuilt
 // modules while here we are only dealing with cached).
@@ -704,9 +704,8 @@
 
 // Get Signature.
 if (State == DiagnosticOptionsBlock && Code == SIGNATURE)
-  getModuleFileInfo(File).Signature = {
-  {{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  getModuleFileInfo(File).Signature = ASTFileSignature::create(
+  Record.begin(), Record.begin() + ASTFileSignature::size);
 
 // We don't care about this record.
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1032,16 +1032,7 @@
   Hasher.update(ArrayRef(Bytes.bytes_begin(), Bytes.size()));
   auto Hash = Hasher.result();
 
-  // Convert to an array [5*i32].
-  ASTFileSignature Signature;
-  auto LShift = [&](unsigned char Val, unsigned Shift) {
-return (uint32_t)Val << Shift;
-  };
-  for (int I = 0; I != 5; ++I)
-Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) |
-   LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0);
-
-  return Signature;
+  return ASTFileSignature::create(Hash);
 }
 
 ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2791,10 +2791,10 @@
 ReadUntranslatedSourceLocation(Record[Idx++]);
 off_t StoredSize = (off_t)Record[Idx++];
 time_t StoredModTime = (time_t)Record[Idx++];
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 std::string ImportedName = ReadString(Record, Idx);
 std::string ImportedFile;
@@ -5023,8 +5023,8 @@
   return ASTFileSignature();
 }
 if (SIGNATURE == MaybeRecord.get())
-  return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  return ASTFileSignature::create(Record.begin(),
+  Record.begin() + ASTFileSignature::size);
   }
 }
 
@@ -5322,7 +5322,9 @@
   unsigned Idx = 0, N = Record.size();
   while (Idx < N) {
 // Read information about the AST file.
-Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
+Idx +=
+1 + 1 + 1 + 1 +
+ASTFileSignature::size; // Kind, ImportLoc, Size, ModTime, Signature
 std::string ModuleName = ReadString(Record, Idx);
 std::string Filename = ReadString(Record, Idx);
 ResolveImportedPath(F

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 269155.
dang marked an inline comment as done.
dang added a comment.

Address some code review feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t1.pcm
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t2.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t1.pcm > %t1.dump
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t2.pcm > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[AST_BLOCK_HASH:]]
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[AST_BLOCK_HASH]]
+// CHECK-NOT: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2434,12 +2434,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.emplace_back(Loc, Offset);
+DeclOffsets.emplace_back(Loc, Offset, ASTBlockRange.first);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].setBitOffset(Offset);
+DeclOffsets[Index].setBitOffset(Offset, ASTBlockRange.first);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/ASTRecordWriter.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "clang/Serialization/ModuleFile.h"
 #include 

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added a comment.

See D81347  for the parent revision that makes 
ASTFileSignature a `std::array`. Adding the abbreviation doesn't 
make that much sense at the moment because of how the `IMPORTS` record is 
structured as discussed offline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383



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


[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 3 inline comments as done.
dang added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:137-142
+.Case("static", llvm::Reloc::Static)
+.Case("pic", llvm::Reloc::PIC_)
+.Case("ropi", llvm::Reloc::ROPI)
+.Case("rwpi", llvm::Reloc::RWPI)
+.Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI)
+.Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC)

dexonsmith wrote:
> I wonder if it's worth creating a `.def` file for the driver enums, something 
> like:
> ```
> #ifdef HANDLE_RELOCATION_MODEL
> HANDLE_RELOCATION_MODEL("static", llvm::Reloc::Static)
> HANDLE_RELOCATION_MODEL("pic", llvm::Reloc::PIC_)
> HANDLE_RELOCATION_MODEL("ropi", llvm::Reloc::ROPI)
> HANDLE_RELOCATION_MODEL("rwpi", llvm::Reloc::RWPI)
> HANDLE_RELOCATION_MODEL("ropi-rwpio", llvm::Reloc::ROPI_RWPI)
> HANDLE_RELOCATION_MODEL("dynamic-no-pic", llvm::Reloc::DynamicNoPIC)
> #undef HANDLE_RELOCATION_MODEL
> #endif // HANDLE_RELOCATION_MODEL
> 
> #ifdef HANDLE_DEBUG_INFO_KIND
> HANDLE_DEBUG_INFO_KIND("line-tables-only", 
> codegenoptions::DebugLineTablesOnly)
> HANDLE_DEBUG_INFO_KIND("line-directives-only", 
> codegenoptions::DebugDirectivesOnly)
> HANDLE_DEBUG_INFO_KIND("limited", codegenoptions::LimitedDebugInfo)
> HANDLE_DEBUG_INFO_KIND("standalone", codegenoptions::FullDebugInfo)
> #undef HANDLE_DEBUG_INFO_KIND
> #endif // HANDLE_DEBUG_INFO_KIND
> 
> // ...
> ```
> Then you can use `HANDLE_RELOCATION_MODEL` in both `normalize` and 
> `denormalize`, rather than duplicating the table.
> 
> Maybe we can go even further. Can you expand the `Values` array from the 
> tablegen to include this info? Or rejigger the help text to leverage 
> `HANDLE_RELOCATION_MODEL` (maybe pass in 
> `ValuesDefine`)? The current patch adds a value 
> table; my first suggestion leaves us even; but maybe we can get rid of one.
I think this suggestion, I can definitely do at least this to generate the 
necessary switch statements. I don't see why this should be a separate .def 
file, I can generate this from the tablegen with an extra field named 
`ValuesAssociatedDefinitions` or something to that effect. I'll do that now.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3647
+ DiagnosticsEngine &Diags) {
+#define OPTION_WITH_MARSHALLING
+#define OPTION_WITH_MARSHALLING_FLAG(PREFIX_TYPE, NAME, ID, KIND, GROUP,   
\

dexonsmith wrote:
> Seems like `Options.inc` could provide this as a default definition, not sure 
> if that seems error-prone?
Not sure how much of this do you mean? `OPTION_WITH_MARSHALLING` is a 
convenience thing that forces users to opt into getting the marshalling 
definitions. I think it might be better to provide default empty definitions 
for `OPTION_WITH_MARSHALLING_FLAG` and friends to achieve a similar effect 
without needing `OPTION_WITH_MARSHALLING`. I you mean the actual definitions 
here they rely on the `ArgList &` to be named Args which might make it error 
prone to include these as defaults.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3665-3667
+#undef OPTION_WITH_MARSHALLING_STRING
+#undef OPTION_WITH_MARSHALLING_FLAG
+#undef OPTION_WITH_MARSHALLING

dexonsmith wrote:
> I prefer the style where the `.inc` file is responsible for the `#undef` 
> calls. It avoids having to duplicate it everywhere (and the risk of 
> forgetting it). WDYT?
I prefer it too, but the current tablegen backend doesn't generate them for 
other macros it defines, so I wanted to make it consistent... I could change 
the existing backend to work that way but I would then need to track all the 
usages of this across all the llvm-projects which I don't fancy doing. Let me 
know if you thing it is fine to break with the existing style for this one.


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

https://reviews.llvm.org/D79796



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


[PATCH] D81347: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t

2020-06-09 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 269468.
dang marked an inline comment as done.
dang added a comment.

Address @aprantl's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81347

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp

Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -643,10 +643,10 @@
 
 // Skip the stored signature.
 // FIXME: we could read the signature out of the import and validate it.
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 // Skip the module name (currently this is only used for prebuilt
 // modules while here we are only dealing with cached).
@@ -704,9 +704,8 @@
 
 // Get Signature.
 if (State == DiagnosticOptionsBlock && Code == SIGNATURE)
-  getModuleFileInfo(File).Signature = {
-  {{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  getModuleFileInfo(File).Signature = ASTFileSignature::create(
+  Record.begin(), Record.begin() + ASTFileSignature::size);
 
 // We don't care about this record.
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1032,16 +1032,7 @@
   Hasher.update(ArrayRef(Bytes.bytes_begin(), Bytes.size()));
   auto Hash = Hasher.result();
 
-  // Convert to an array [5*i32].
-  ASTFileSignature Signature;
-  auto LShift = [&](unsigned char Val, unsigned Shift) {
-return (uint32_t)Val << Shift;
-  };
-  for (int I = 0; I != 5; ++I)
-Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) |
-   LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0);
-
-  return Signature;
+  return ASTFileSignature::create(Hash);
 }
 
 ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2791,10 +2791,10 @@
 ReadUntranslatedSourceLocation(Record[Idx++]);
 off_t StoredSize = (off_t)Record[Idx++];
 time_t StoredModTime = (time_t)Record[Idx++];
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 std::string ImportedName = ReadString(Record, Idx);
 std::string ImportedFile;
@@ -5023,8 +5023,8 @@
   return ASTFileSignature();
 }
 if (SIGNATURE == MaybeRecord.get())
-  return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  return ASTFileSignature::create(Record.begin(),
+  Record.begin() + ASTFileSignature::size);
   }
 }
 
@@ -5322,7 +5322,9 @@
   unsigned Idx = 0, N = Record.size();
   while (Idx < N) {
 // Read information about the AST file.
-Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
+Idx +=
+1 + 1 + 1 + 1 +
+ASTFileSignature::size; // Kind, ImportLoc, Size, ModTime, Signature
 std::string ModuleName = ReadString(Record, Idx);
 std::string Filename = ReadString(Record, Idx);
 ResolveImportedPath(Filename, ModuleDir);
Index: clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===
--- clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -173,8 +173,8 @@
 // Prepare CGDebugInfo to emit debug info for a clang module.
 auto *DI = B

[PATCH] D81347: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t

2020-06-09 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 269473.
dang marked 3 inline comments as done.
dang added a comment.

Fix bug


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81347

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp

Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -643,10 +643,10 @@
 
 // Skip the stored signature.
 // FIXME: we could read the signature out of the import and validate it.
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 // Skip the module name (currently this is only used for prebuilt
 // modules while here we are only dealing with cached).
@@ -704,9 +704,8 @@
 
 // Get Signature.
 if (State == DiagnosticOptionsBlock && Code == SIGNATURE)
-  getModuleFileInfo(File).Signature = {
-  {{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  getModuleFileInfo(File).Signature = ASTFileSignature::create(
+  Record.begin(), Record.begin() + ASTFileSignature::size);
 
 // We don't care about this record.
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1032,16 +1032,7 @@
   Hasher.update(ArrayRef(Bytes.bytes_begin(), Bytes.size()));
   auto Hash = Hasher.result();
 
-  // Convert to an array [5*i32].
-  ASTFileSignature Signature;
-  auto LShift = [&](unsigned char Val, unsigned Shift) {
-return (uint32_t)Val << Shift;
-  };
-  for (int I = 0; I != 5; ++I)
-Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) |
-   LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0);
-
-  return Signature;
+  return ASTFileSignature::create(Hash);
 }
 
 ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2791,10 +2791,10 @@
 ReadUntranslatedSourceLocation(Record[Idx++]);
 off_t StoredSize = (off_t)Record[Idx++];
 time_t StoredModTime = (time_t)Record[Idx++];
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 std::string ImportedName = ReadString(Record, Idx);
 std::string ImportedFile;
@@ -5023,8 +5023,8 @@
   return ASTFileSignature();
 }
 if (SIGNATURE == MaybeRecord.get())
-  return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  return ASTFileSignature::create(Record.begin(),
+  Record.begin() + ASTFileSignature::size);
   }
 }
 
@@ -5322,7 +5322,9 @@
   unsigned Idx = 0, N = Record.size();
   while (Idx < N) {
 // Read information about the AST file.
-Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
+Idx +=
+1 + 1 + 1 + 1 +
+ASTFileSignature::size; // Kind, ImportLoc, Size, ModTime, Signature
 std::string ModuleName = ReadString(Record, Idx);
 std::string Filename = ReadString(Record, Idx);
 ResolveImportedPath(Filename, ModuleDir);
Index: clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===
--- clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -173,8 +173,8 @@
 // Prepare CGDebugInfo to emit debug info for a clang module.
 auto *DI = Builder->getModuleDeb

[PATCH] D81347: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t

2020-06-09 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/include/clang/Basic/Module.h:29
 #include "llvm/ADT/iterator_range.h"
+#include 
 #include 

aprantl wrote:
> Can you move the code that depends on algorithm into a .cpp file?
That code is the call to `std::copy` in the template function so it can't 
really be moved out... But I removed the include because `STLExtras.h` already 
includes it, so I think it is ok to remove the include.



Comment at: clang/include/clang/Basic/Module.h:70
+
+  static ASTFileSignature createDISentinel() {
+ASTFileSignature Sentinel;

aprantl wrote:
> dang wrote:
> > I couldn't find anywhere in the code base that checks the bit-pattern so I 
> > left it as is. If anyone knows if someone could point me to the code that 
> > checks this (if any code does check it) that would be nice.
> The PCM hash is reused in CGDebugInfo as the DW_AT_dwo_id hash for the 
> -gmodules debug info. This value is checked by dsymutil and LLDB.
DW_AT_dwo_id is 64 bit so using `0xFF` everywhere is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81347



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


[PATCH] D81347: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t

2020-06-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 269845.
dang added a comment.

Missed a case where an ASTFileSignature was created using an explicit 
`std::copy`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81347

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp

Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -643,10 +643,10 @@
 
 // Skip the stored signature.
 // FIXME: we could read the signature out of the import and validate it.
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 // Skip the module name (currently this is only used for prebuilt
 // modules while here we are only dealing with cached).
@@ -704,9 +704,8 @@
 
 // Get Signature.
 if (State == DiagnosticOptionsBlock && Code == SIGNATURE)
-  getModuleFileInfo(File).Signature = {
-  {{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  getModuleFileInfo(File).Signature = ASTFileSignature::create(
+  Record.begin(), Record.begin() + ASTFileSignature::size);
 
 // We don't care about this record.
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1032,16 +1032,7 @@
   Hasher.update(ArrayRef(Bytes.bytes_begin(), Bytes.size()));
   auto Hash = Hasher.result();
 
-  // Convert to an array [5*i32].
-  ASTFileSignature Signature;
-  auto LShift = [&](unsigned char Val, unsigned Shift) {
-return (uint32_t)Val << Shift;
-  };
-  for (int I = 0; I != 5; ++I)
-Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) |
-   LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0);
-
-  return Signature;
+  return ASTFileSignature::create(Hash);
 }
 
 ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2791,10 +2791,10 @@
 ReadUntranslatedSourceLocation(Record[Idx++]);
 off_t StoredSize = (off_t)Record[Idx++];
 time_t StoredModTime = (time_t)Record[Idx++];
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 std::string ImportedName = ReadString(Record, Idx);
 std::string ImportedFile;
@@ -4734,7 +4734,7 @@
 switch ((UnhashedControlBlockRecordTypes)MaybeRecordType.get()) {
 case SIGNATURE:
   if (F)
-std::copy(Record.begin(), Record.end(), F->Signature.data());
+F->Signature = ASTFileSignature::create(Record.begin(), Record.end());
   break;
 case DIAGNOSTIC_OPTIONS: {
   bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
@@ -5023,8 +5023,8 @@
   return ASTFileSignature();
 }
 if (SIGNATURE == MaybeRecord.get())
-  return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  return ASTFileSignature::create(Record.begin(),
+  Record.begin() + ASTFileSignature::size);
   }
 }
 
@@ -5322,7 +5322,9 @@
   unsigned Idx = 0, N = Record.size();
   while (Idx < N) {
 // Read information about the AST file.
-Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
+Idx +=
+1 + 1 + 1 + 1 +
+ASTFileSignature::size; // Kind, ImportLoc, Size, ModTime, Signature
 std::string ModuleName = ReadString(Record, Idx);
 std::string Filename = ReadString(Record

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 269854.
dang marked an inline comment as done.
dang added a comment.

Address @dexonsmith feedback about making the relative offsets in the AST block 
relative to the nearest relevant subblock.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t1.pcm
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t2.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t1.pcm > %t1.dump
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t2.pcm > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[AST_BLOCK_HASH:]]
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[AST_BLOCK_HASH]]
+// CHECK-NOT: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2434,12 +2434,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.emplace_back(Loc, Offset);
+DeclOffsets.emplace_back(Loc, Offset, DeclTypesBlockStartOffset);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].setBitOffset(Offset);
+DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
+#include

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/include/clang/Serialization/ASTBitCodes.h:396-400
   /// Record code for the signature that identifiers this AST file.
   SIGNATURE = 1,
 
+  /// Record code for the signature of the AST block.
+  AST_SIGNATURE,

dexonsmith wrote:
> dang wrote:
> > dang wrote:
> > > dexonsmith wrote:
> > > > These names and descriptions hard hard to differentiate. Is there 
> > > > another way of naming these that will be more clear?
> > > > 
> > > > (One idea I had is to create `CONTROL_BLOCK_HASH` and `AST_BLOCK_HASH` 
> > > > and then `SIGNATURE` could just be their hash-combine, but maybe you 
> > > > have another idea.)
> > > I kept the same hasher when computing both of these which mitigates the 
> > > cost. I don't see the need for also emitting a hash for the control 
> > > block, there are some optional records that are not in both the AST block 
> > > and the control block anyway.
> > I also think that the `AST_BLOCK_HASH` and the `SIGNATURE` are enough 
> > information already. In most cases you can deduce if the control block was 
> > different by just checking if the signatures were different and the ASTs 
> > the same.
> Thanks for updating to `AST_BLOCK_HASH`, I think that addressed the concern I 
> had.
> 
> However, having thought further about it, I don't think it makes sense to 
> create a new record type. I suggest just having a convention of writing the 
> hashes out in a particular order.
> - First record is the overall signature.
> - Second record is the AST block hash.
> - In the future, we can add a third record for the control block hash.
> 
> In which case, the (single) record name should be something generic like 
> `SIGNATURE` or `SHA1_HASH`.
> 
> Note: I doubt there would be additional cost to computing the AST and control 
> block hashes separately, but I agree there isn't a compelling use for the 
> control block hash currently (although it would be nice to confirm properties 
> like if the `CONTROL_BLOCK_HASH` were typically stable when sources changed).
> 
> Note: I don't think the content of the "hashed" control block vs. unhashed 
> control block have been carefully considered from first principles. At some 
> point we might do that. I expect there are currently things that change the 
> control block that would not invalidate it for importers.
I agree with the fact that it might be worth maintaining a control block hash, 
but I do think this is not the purpose of this change. I can do it as a follow 
up when I have some time. I am somewhat opposed to keeping them all in the same 
record for now, because it makes it harder to grep for one of the signatures in 
the output of `llvm-bcanalyzer` which is currently the only available tooling 
for looking inside the unhashed control block.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383



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


[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 269926.
dang added a comment.

This address a bunch of existing feedback and makes the TableGen definitions of 
the additional information significantly nicer to write.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -9,6 +9,7 @@
 #include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
@@ -33,6 +34,40 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsBit("IsPositive");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R.getValueAsString("Denormalizer");
+}
+
+static void emitValueTable(raw_ostream &OS, StringRef OptionID,
+   StringRef Values,
+   std::vector AssociatedDefinitions) {
+  SmallVector SplitValues;
+  Values.split(SplitValues, ',');
+  assert(SplitValues.size() == AssociatedDefinitions.size() &&
+ "The number of associated definitions doesn't match the number of "
+ "values");
+
+  SmallString<64> MacroName("HANDLE_");
+  MacroName += OptionID.upper();
+  MacroName += "_VALUES";
+  OS << "#ifdef " << MacroName << "\n";
+  for (unsigned I = 0, E = SplitValues.size(); I != E; ++I)
+OS << MacroName << "(\"" << SplitValues[I] << "\","
+   << AssociatedDefinitions[I] << ")\n";
+  OS << "#endif\n";
+}
+
+struct MarshallingKindInfo {
+  const char *MacroName;
+  void (*Emit)(raw_ostream &OS, const Record &R);
+};
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +170,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -223,11 +254,56 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
 
+  std::vector OptsWithMarshalling;
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
+
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
+if (!isa(R.getValueInit("MarshallingKind")))
+  OptsWithMarshalling.push_back(&R);
   }
   OS << "#endif // OPTION\n";
 
+  for (unsigned I = 0, E = OptsWithMarshalling.size(); I != E; ++I) {
+const Record &R = *OptsWithMarshalling[I];
+assert(!isa(R.getValueInit("KeyPath")) &&
+   !isa(R.getValueInit("DefaultValue")) &&
+   "Must provide at least a key-path and a default value for emitting "
+   "marshalling information");
+StringRef KindStr = R.getValueAsString("MarshallingKind");
+auto KindInfo = StringSwitch(KindStr)
+.Case("flag", {"OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag})
+.Case("string", {"OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString})
+.Default({"", nullptr});
+OS << "#ifdef " << KindInfo.MacroName << "\n";
+OS << KindInfo.MacroName << "(";
+WriteOptRecordFields(OS, R);
+OS << ", ";
+OS << R.getValueAsBit("ShouldAlwaysEmit");
+OS << ", ";
+OS << R.getValueAsString("KeyPath");
+OS << ", ";
+OS << R.getValueAsString("DefaultValue");
+OS << ",";
+KindInfo.Emit(OS, R);
+OS << ")\n";
+OS << "#endif\n";
+
+if (!isa(R.getValueInit("ValuesAssociatedDefinitions"))) {
+  assert(!isa(R.getValueInit("Values")) &&
+ "Cannot provide associated definitions for value-less options");
+  emitValueTable(OS, getOptionName(R), R.getValueAsString("Values"),
+ R.getValueAsListOfStrings("ValuesAssociatedDefinitions"));
+ 

[PATCH] D81347: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t

2020-06-11 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe87e55edbc79: Make ASTFileSignature an array of 20 uint8_t 
instead of 5 uint32_t (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81347

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GlobalModuleIndex.cpp

Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -643,10 +643,10 @@
 
 // Skip the stored signature.
 // FIXME: we could read the signature out of the import and validate it.
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 // Skip the module name (currently this is only used for prebuilt
 // modules while here we are only dealing with cached).
@@ -704,9 +704,8 @@
 
 // Get Signature.
 if (State == DiagnosticOptionsBlock && Code == SIGNATURE)
-  getModuleFileInfo(File).Signature = {
-  {{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  getModuleFileInfo(File).Signature = ASTFileSignature::create(
+  Record.begin(), Record.begin() + ASTFileSignature::size);
 
 // We don't care about this record.
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1032,16 +1032,7 @@
   Hasher.update(ArrayRef(Bytes.bytes_begin(), Bytes.size()));
   auto Hash = Hasher.result();
 
-  // Convert to an array [5*i32].
-  ASTFileSignature Signature;
-  auto LShift = [&](unsigned char Val, unsigned Shift) {
-return (uint32_t)Val << Shift;
-  };
-  for (int I = 0; I != 5; ++I)
-Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) |
-   LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0);
-
-  return Signature;
+  return ASTFileSignature::create(Hash);
 }
 
 ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2791,10 +2791,10 @@
 ReadUntranslatedSourceLocation(Record[Idx++]);
 off_t StoredSize = (off_t)Record[Idx++];
 time_t StoredModTime = (time_t)Record[Idx++];
-ASTFileSignature StoredSignature = {
-{{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
-  (uint32_t)Record[Idx++]}}};
+auto FirstSignatureByte = Record.begin() + Idx;
+ASTFileSignature StoredSignature = ASTFileSignature::create(
+FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+Idx += ASTFileSignature::size;
 
 std::string ImportedName = ReadString(Record, Idx);
 std::string ImportedFile;
@@ -4734,7 +4734,7 @@
 switch ((UnhashedControlBlockRecordTypes)MaybeRecordType.get()) {
 case SIGNATURE:
   if (F)
-std::copy(Record.begin(), Record.end(), F->Signature.data());
+F->Signature = ASTFileSignature::create(Record.begin(), Record.end());
   break;
 case DIAGNOSTIC_OPTIONS: {
   bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
@@ -5023,8 +5023,8 @@
   return ASTFileSignature();
 }
 if (SIGNATURE == MaybeRecord.get())
-  return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
-(uint32_t)Record[3], (uint32_t)Record[4]}}};
+  return ASTFileSignature::create(Record.begin(),
+  Record.begin() + ASTFileSignature::size);
   }
 }
 
@@ -5322,7 +5322,9 @@
   unsigned Idx = 0, N = Record.size();
   while (Idx < N) {
 // Read information about the AST file.
-Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
+Idx +=
+1 + 1 + 1 + 1 +
+ASTFileSignature::size; // Kind, ImportLoc, Size, ModTime, Signature
 std::string ModuleName = ReadString(Record, Idx);

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-11 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 270077.
dang marked 3 inline comments as done.
dang added a comment.

Rebase on top of latest master that has needed NFC changes to calm down 
clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t1.pcm
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t2.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t1.pcm > %t1.dump
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t2.pcm > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[AST_BLOCK_HASH:]]
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[AST_BLOCK_HASH]]
+// CHECK-NOT: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2432,12 +2432,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.emplace_back(Loc, Offset);
+DeclOffsets.emplace_back(Loc, Offset, DeclTypesBlockStartOffset);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].setBitOffset(Offset);
+DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/ASTRecordWriter

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-11 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:3706
   unsigned LocalBaseMacroID = Record[1];
-  F.MacroOffsetsBase = Record[2];
+  F.MacroOffsetsBase = Record[2] + F.ASTBlockStartOffset;
   F.BaseMacroID = getTotalNumMacros();

@dexonsmith the field you asked about is used here and the MacroOffsetsBase is 
used in other places to compute offsets



Comment at: clang/lib/Serialization/ASTWriter.cpp:2345
FirstMacroID - NUM_PREDEF_MACRO_IDS,
-   MacroOffsetsBase};
+   MacroOffsetsBase - ASTBlockStartOffset};
 Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets));

dexonsmith wrote:
> It looks to me like this field is ignored in the reader. If so we should just 
> strip it. Can you confirm?
No, look at line 3706 of the Reader in the updated version. I added a comment 
on the relevant line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383



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


[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-11 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 270117.
dang added a comment.

This addresses the usability concern with having to specify fully scoped 
definitions for normalized values in the TableGen files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -9,7 +9,9 @@
 #include "OptEmitter.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
@@ -33,6 +35,50 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsBit("IsPositive");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R.getValueAsString("Denormalizer");
+}
+
+static void emitScopedNormalizedValue(raw_ostream &OS,
+  StringRef NormalizedValuesScope,
+  StringRef NormalizedValue) {
+  if (!NormalizedValuesScope.empty())
+OS << NormalizedValuesScope << "::";
+  OS << NormalizedValue;
+}
+
+static void emitValueTable(raw_ostream &OS, StringRef OptionID,
+   StringRef Values, StringRef NormalizedValuesScope,
+   std::vector NormalizedValues) {
+  SmallVector SplitValues;
+  Values.split(SplitValues, ',');
+  assert(SplitValues.size() == NormalizedValues.size() &&
+ "The number of associated definitions doesn't match the number of "
+ "values");
+
+  SmallString<64> MacroName("HANDLE_");
+  MacroName += OptionID.upper();
+  MacroName += "_VALUES";
+  OS << "#ifdef " << MacroName << "\n";
+  for (unsigned I = 0, E = SplitValues.size(); I != E; ++I) {
+OS << MacroName << "(\"" << SplitValues[I] << "\",";
+emitScopedNormalizedValue(OS, NormalizedValuesScope, NormalizedValues[I]);
+OS << ")\n";
+  }
+  OS << "#endif\n";
+}
+
+struct MarshallingKindInfo {
+  const char *MacroName;
+  void (*Emit)(raw_ostream &OS, const Record &R);
+};
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +181,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -223,11 +265,62 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
 
+  std::vector OptsWithMarshalling;
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
+
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
+if (!isa(R.getValueInit("MarshallingKind")))
+  OptsWithMarshalling.push_back(&R);
   }
   OS << "#endif // OPTION\n";
 
+  for (unsigned I = 0, E = OptsWithMarshalling.size(); I != E; ++I) {
+const Record &R = *OptsWithMarshalling[I];
+assert(!isa(R.getValueInit("KeyPath")) &&
+   !isa(R.getValueInit("DefaultValue")) &&
+   "Must provide at least a key-path and a default value for emitting "
+   "marshalling information");
+StringRef KindStr = R.getValueAsString("MarshallingKind");
+auto KindInfo = StringSwitch(KindStr)
+.Case("flag", {"OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag})
+.Case("string", {"OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString})
+.Default({"", nullptr});
+StringRef NormalizedValuesScope;
+if (!isa(R.getValueInit("NormalizedValuesScope")))
+  NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
+
+OS << "#ifdef " << KindInfo.MacroName << "\n";
+OS << KindInfo.MacroName << "(";
+WriteOptRecordFields(OS, R);
+OS << ", ";

[PATCH] D80383: Add AST_SIGNATURE record to unhashed control block of PCM files

2020-06-11 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb8c7e756c51: Add AST_SIGNATURE record to unhashed control 
block of PCM files (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80383

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/ASTSignature.c
  clang/test/Modules/Inputs/ASTHash/module.modulemap
  clang/test/Modules/Inputs/ASTHash/my_header_1.h
  clang/test/Modules/Inputs/ASTHash/my_header_2.h

Index: clang/test/Modules/Inputs/ASTHash/my_header_2.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_2.h
@@ -0,0 +1,3 @@
+#include "my_header_1.h"
+
+extern my_int var;
Index: clang/test/Modules/Inputs/ASTHash/my_header_1.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/my_header_1.h
@@ -0,0 +1 @@
+typedef int my_int;
Index: clang/test/Modules/Inputs/ASTHash/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/ASTHash/module.modulemap
@@ -0,0 +1,8 @@
+module MyHeader1 {
+  header "my_header_1.h"
+}
+
+module MyHeader2 {
+  header "my_header_2.h"
+  export *
+}
Index: clang/test/Modules/ASTSignature.c
===
--- /dev/null
+++ clang/test/Modules/ASTSignature.c
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote %S/Inputs/ASTHash/ -fsyntax-only -fmodules \
+// RUN:   -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t1.pcm
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -iquote "/dev/null" -iquote %S/Inputs/ASTHash/ -fsyntax-only \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-strict-context-hash \
+// RUN:   -fmodules-cache-path=%t -fdisable-module-hash %s
+// RUN: cp %t/MyHeader2.pcm %t2.pcm
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t1.pcm > %t1.dump
+// RUN: llvm-bcanalyzer --dump --disable-histogram %t2.pcm > %t2.dump
+// RUN: cat %t1.dump %t2.dump | FileCheck %s
+
+#include "my_header_2.h"
+
+my_int var = 42;
+
+// CHECK: [[AST_BLOCK_HASH:]]
+// CHECK: [[SIGNATURE:]]
+// CHECK: [[AST_BLOCK_HASH]]
+// CHECK-NOT: [[SIGNATURE]]
+// The modules built by this test are designed to yield the same AST. If this
+// test fails, it means that the AST block is has become non-relocatable.
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2432,12 +2432,12 @@
   SourceLocation Loc = D->getLocation();
   unsigned Index = ID - FirstDeclID;
   if (DeclOffsets.size() == Index)
-DeclOffsets.emplace_back(Loc, Offset);
+DeclOffsets.emplace_back(Loc, Offset, DeclTypesBlockStartOffset);
   else if (DeclOffsets.size() < Index) {
 // FIXME: Can/should this happen?
 DeclOffsets.resize(Index+1);
 DeclOffsets[Index].setLocation(Loc);
-DeclOffsets[Index].setBitOffset(Offset);
+DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset);
   } else {
 llvm_unreachable("declarations should be emitted in ID order");
   }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -10,14 +10,12 @@
 //
 //===--===//
 
-#include "clang/AST/OpenMPClause.h"
-#include "clang/Serialization/ASTRecordWriter.h"
 #include "ASTCommon.h"
 #include "ASTReaderInternals.h"
 #include "MultiOnDiskHashTable.h"
-#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTUnresolvedSet.h"
+#include "clang/AST/AbstractTypeWriter.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
@@ -31,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -65,7 +64,9 @@
 #include "clang/Sema/ObjCMethodList.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/Weak.h"
+#include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTReader.h"
+#include "clang/Serialization/ASTRecordWriter.

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-12 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 270445.
dang edited the summary of this revision.
dang added a comment.

Implemented a draft of normalizer generation for simple enum based options


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -10,6 +10,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
@@ -33,6 +34,50 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsBit("IsPositive");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R.getValueAsString("Denormalizer");
+}
+
+static void emitScopedNormalizedValue(raw_ostream &OS,
+  StringRef NormalizedValuesScope,
+  StringRef NormalizedValue) {
+  if (!NormalizedValuesScope.empty())
+OS << NormalizedValuesScope << "::";
+  OS << NormalizedValue;
+}
+
+static void emitValueTable(raw_ostream &OS, StringRef OptionID,
+   StringRef Values, StringRef NormalizedValuesScope,
+   std::vector NormalizedValues) {
+  SmallVector SplitValues;
+  Values.split(SplitValues, ',');
+  assert(SplitValues.size() == NormalizedValues.size() &&
+ "The number of associated definitions doesn't match the number of "
+ "values");
+
+  SmallString<64> MacroName("HANDLE_");
+  MacroName += OptionID.upper();
+  MacroName += "_VALUES";
+  OS << "#ifdef " << MacroName << "\n";
+  for (unsigned I = 0, E = SplitValues.size(); I != E; ++I) {
+OS << MacroName << "(\"" << SplitValues[I] << "\",";
+emitScopedNormalizedValue(OS, NormalizedValuesScope, NormalizedValues[I]);
+OS << ")\n";
+  }
+  OS << "#endif\n";
+}
+
+struct MarshallingKindInfo {
+  const char *MacroName;
+  void (*Emit)(raw_ostream &OS, const Record &R);
+};
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +180,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -223,11 +264,119 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
 
+  std::vector OptsWithMarshalling;
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
+
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
+if (!isa(R.getValueInit("MarshallingKind")))
+  OptsWithMarshalling.push_back(&R);
   }
   OS << "#endif // OPTION\n";
 
+  std::vector AutoNormalizableOpts;
+  for (unsigned I = 0, E = OptsWithMarshalling.size(); I != E; ++I) {
+const Record &R = *OptsWithMarshalling[I];
+assert(!isa(R.getValueInit("KeyPath")) &&
+   !isa(R.getValueInit("DefaultValue")) &&
+   "Must provide at least a key-path and a default value for emitting "
+   "marshalling information");
+StringRef KindStr = R.getValueAsString("MarshallingKind");
+auto KindInfo = StringSwitch(KindStr)
+.Case("flag", {"OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag})
+.Case("string", {"OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString})
+.Default({"", nullptr});
+StringRef NormalizedValuesScope;
+if (!isa(R.getValueInit("NormalizedValuesScope")))
+  NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
+
+OS << "#ifdef " << KindInfo.MacroName << "\n";
+OS << KindInfo.MacroName << "(";
+WriteOptRecordFields(OS, R);
+OS << ", ";
+OS << R.getValueAsBit("Should

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-15 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 270802.
dang marked an inline comment as done.
dang added a comment.

Implement constant table based marshaling for simple enum based options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -10,11 +10,13 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
 #include 
 #include 
+#include 
 
 using namespace llvm;
 
@@ -33,6 +35,182 @@
   return OS;
 }
 
+class MarshallingKindInfo {
+public:
+  const Record &R;
+  const char *MacroName;
+  bool ShouldAlwaysEmit;
+  StringRef KeyPath;
+  StringRef DefaultValue;
+  StringRef NormalizedValuesScope;
+
+  void emit(raw_ostream &OS) const {
+OS << ShouldAlwaysEmit;
+OS << ", ";
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
+emitSpecific(OS);
+  }
+
+  virtual Optional emitValueTable(raw_ostream &OS) const {
+return None;
+  }
+
+  virtual ~MarshallingKindInfo() = default;
+
+  static std::unique_ptr create(const Record &R);
+
+protected:
+  void emitScopedNormalizedValue(raw_ostream &OS,
+ StringRef NormalizedValue) const {
+if (!NormalizedValuesScope.empty())
+  OS << NormalizedValuesScope << "::";
+OS << NormalizedValue;
+  }
+
+  virtual void emitSpecific(raw_ostream &OS) const = 0;
+  MarshallingKindInfo(const Record &R, const char *MacroName)
+  : R(R), MacroName(MacroName) {}
+};
+
+class MarshallingFlagInfo final : public MarshallingKindInfo {
+public:
+  bool IsPositive;
+
+  void emitSpecific(raw_ostream &OS) const override { OS << IsPositive; }
+
+  static std::unique_ptr create(const Record &R) {
+std::unique_ptr Ret(new MarshallingFlagInfo(R));
+Ret->IsPositive = R.getValueAsBit("IsPositive");
+return Ret;
+  }
+
+private:
+  MarshallingFlagInfo(const Record &R)
+  : MarshallingKindInfo(R, "OPTION_WITH_MARSHALLING_FLAG") {}
+};
+
+class MarshallingStringInfo final : public MarshallingKindInfo {
+public:
+  StringRef NormalizerRetTy;
+  StringRef Normalizer;
+  StringRef Denormalizer;
+  int TableIndex = -1;
+  std::vector Values;
+  std::vector NormalizedValues;
+  std::string ValueTableName;
+
+  static constexpr const char *ValueTablePreamble = R"(
+struct SimpleEnumValue {
+  const char *Name;
+  unsigned Value;
+};
+
+struct SimpleEnumValueTable {
+  const SimpleEnumValue *Table;
+  unsigned Size;
+};
+)";
+
+  static constexpr const char *ValueTablesDecl =
+  "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
+
+  void emitSpecific(raw_ostream &OS) const override {
+emitScopedNormalizedValue(OS, NormalizerRetTy);
+OS << ", ";
+OS << Normalizer;
+OS << ", ";
+OS << Denormalizer;
+OS << ", ";
+OS << TableIndex;
+  }
+
+  Optional emitValueTable(raw_ostream &OS) const override {
+if (TableIndex == -1)
+  return {};
+OS << "static const SimpleEnumValue " << ValueTableName << "[] = {\n";
+for (unsigned I = 0, E = Values.size(); I != E; ++I) {
+  OS << "{\"" << Values[I] << "\",";
+  OS << "static_cast(";
+  emitScopedNormalizedValue(OS, NormalizedValues[I]);
+  OS << ")},";
+}
+OS << "};\n";
+return StringRef(ValueTableName);
+  }
+
+  static std::unique_ptr create(const Record &R) {
+assert(!isa(R.getValueInit("NormalizerRetTy")) &&
+   "String options must have a type");
+
+std::unique_ptr Ret(new MarshallingStringInfo(R));
+Ret->NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
+
+Ret->Normalizer = R.getValueAsString("Normalizer");
+Ret->Denormalizer = R.getValueAsString("Denormalizer");
+
+if (!isa(R.getValueInit("NormalizedValues"))) {
+  assert(!isa(R.getValueInit("Values")) &&
+ "Cannot provide normalized values for value-less options");
+  Ret->TableIndex = NextTableIndex++;
+  Ret->NormalizedValues = R.getValueAsListOfStrings("NormalizedValues");
+  Ret->Values.reserve(Ret->NormalizedValues.size());
+  Ret->ValueTableName = getOptionName(R) + "ValueTable";
+
+  StringRef ValuesStr = R.getValueAsString("Values");
+  for (;;) {
+size_t Idx = ValuesStr.find(',');
+if (Idx == StringRef::npos)
+  brea

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-15 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 2 inline comments as done.
dang added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3845
+  IS_POSITIVE != DEFAULT_VALUE && this->KEYPATH != DEFAULT_VALUE)  
\
+Args.push_back(StringAllocator(Twine(PREFIX_TYPE[0]) + NAME));
+#include "clang/Driver/Options.inc"

dexonsmith wrote:
> Bigcheese wrote:
> > It's a little sad that we need to allocation every string just because of 
> > the `-`. We definitely need to be able to allocate strings for options with 
> > data, but it would be good if we could just have the strings with `-` 
> > prefixed in the option table if that's reasonable to do.
> I want to highlight @Bigcheese's comment again so it doesn't get lost. I 
> think a reasonable name would be `SPELLING`.
Yes I haven't forgotten just have not gotten around to it yet. I just want to 
do some form of suffix merging with the string the the OptTable receives



Comment at: llvm/utils/TableGen/OptParserEmitter.cpp:351-354
+OS << "#define " << MacroName << "(V, D) .Case(V, D)\n";
+emitValueTable(OS, OptionName, R.getValueAsString("Values"),
+   NormalizedValuesScope, NormalizedValues);
+OS << "#undef " << MacroName << "\n";

dexonsmith wrote:
> It seems unnecessary to generate macros here; you can just generate the code 
> directly...
> 
> But looking more closely, I wonder if we really need this generated code at 
> all.
> 
> Instead, can we create a table like this in Options.inc?
> ```
> struct EnumValue {
>   const char *Name;
>   unsigned Value;
> };
> 
> struct EnumValueTable {
>   const EnumValue *Table;
>   unsigned Size;
> };
> 
> static const EnumValue RelocationModelTable[] = {
>   {"static", static_cast(llvm::Reloc::Static)},
>   {"pic", static_cast(llvm::Reloc::_PIC)},
>   // ...
> };
> 
> static const EnumValue SomeOtherTable[] = {
>   {"name", static_cast(clang::SomeOtherEnumValue)},
>   // ...
> };
> 
> static const EnumValueTable *EnumValueTables[] = {
>   {&RelocationModelTable, sizeof(RelocationModelTable) / sizeof(EnumValue)},
>   {&SomeOtherTable, sizeof(SomeOtherTable) / sizeof(EnumValue)},
> };
> static const unsigned EnumValueTablesSize =
> sizeof(EnumValueTables) / sizeof(EnumValueTable);
> ```
> 
> We can then have this code directly in Options.cpp:
> ```
> static llvm::Optional extractSimpleEnum(
> llvm::opt::OptSpecifier Opt, int TableIndex,
> const ArgList &ArgList, DiagnosticsEngine &Diags) {
>   assert(TableIndex >= 0);
>   assert(TableIndex < EnumValueTablesSize);
>   const EnumValueTable &Table = *EnumValueTables[TableIndex];
> 
>   auto Arg = Args.getLastArg(Opt);
>   if (!Arg)
> return None;
> 
>   StringRef ArgValue = Arg->getValue();
>   for (int I = 0, E = Table.Size; I != E; ++I)
> if (ArgValue == Table.Table[I].Name)
>   return Table.Table[I].Value;
> 
>   Diags.Report(diag::err_drv_invalid_value)
>   << Arg->getAsString(ArgList) << ArgValue;
>   return None;
> }
> ```
> and change the normalizer contract to:
> - return an `Optional`,
> - take an `llvm::opt::OptSpecifier`,
> - take an index into a table (set to `-1` if there's no relevant table), and
> - be responsible for the boilerplate call to `getLastArg`.
> Simple enums would have `NORMALIZER` hardcoded to `extractSimpleEnum`. The 
> handler code that calls it needs new arguments `TABLE_INDEX` and `TYPE` but 
> also looks simpler this way:
> ```
> if (auto MaybeValue = NORMALIZER(Opt##ID, TABLE_INDEX, Args, Diags)) \
>   this->KEYPATH = static_cast(*MaybeValue);\
> else \
>   this->KEYPATH = DEFAULT_VALUE;
> ```
> 
> We could similarly have a single `serializeSimpleEnum` function in 
> Options.cpp for a hardcoded `DENORMALIZER` for simple enums:
> ```
> static const char *serializeSimpleEnum(int TableIndex, unsigned Value) {
>   assert(TableIndex >= 0);
>   assert(TableIndex < EnumValueTablesSize);
>   const EnumValueTable &Table = *EnumValueTables[TableIndex];
>   for (int I = 0, E = Table.Size; I != E; ++I)
> if (Value == Table.Table[I].Value)
>   return Table.Table[I].Name;
> 
>   llvm::report_fatal_error("good error message");
> }
> ```
I originally wanted to generate the normalizers without the table to allow and 
arbitrary code fragment to be used as the normalized value (one that is 
potentially not a constant evaluated expression) and just regenerating the 
macros was the path of least resistance at the time. Having had a closer look 
at the existing cases of enum based options there doesn't seem to be a need for 
this functionality so I went ahead and did this. Although I haven't split the 
backends yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
h

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-16 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 271006.
dang marked 5 inline comments as done and an inline comment as not done.
dang added a comment.

Implement suffix merging to avoid allocations for option spelling when 
generating the command line. This update also removes unnecessary allocation 
for `std::string` based options and for enum based options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -10,11 +10,13 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
 #include 
 #include 
+#include 
 
 using namespace llvm;
 
@@ -33,6 +35,208 @@
   return OS;
 }
 
+static const std::string getOptionSpelling(const Record &R,
+   size_t &PrefixLength) {
+  std::vector Prefixes = R.getValueAsListOfStrings("Prefixes");
+  StringRef Name = R.getValueAsString("Name");
+  if (Prefixes.empty())
+return Name.str();
+  PrefixLength = Prefixes[0].size();
+  return (Twine(Prefixes[0]) + Twine(Name)).str();
+}
+
+static const std::string getOptionSpelling(const Record &R) {
+  size_t PrefixLength;
+  return getOptionSpelling(R, PrefixLength);
+}
+
+static void emitNameUsingSpelling(raw_ostream &OS, const Record &R) {
+  size_t PrefixLength;
+  OS << "&";
+  write_cstring(OS, StringRef(getOptionSpelling(R, PrefixLength)));
+  OS << "[" << PrefixLength << "]";
+}
+
+class MarshallingKindInfo {
+public:
+  const Record &R;
+  const char *MacroName;
+  bool ShouldAlwaysEmit;
+  StringRef KeyPath;
+  StringRef DefaultValue;
+  StringRef NormalizedValuesScope;
+
+  void emit(raw_ostream &OS) const {
+write_cstring(OS, StringRef(getOptionSpelling(R)));
+OS << ", ";
+OS << ShouldAlwaysEmit;
+OS << ", ";
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
+emitSpecific(OS);
+  }
+
+  virtual Optional emitValueTable(raw_ostream &OS) const {
+return None;
+  }
+
+  virtual ~MarshallingKindInfo() = default;
+
+  static std::unique_ptr create(const Record &R);
+
+protected:
+  void emitScopedNormalizedValue(raw_ostream &OS,
+ StringRef NormalizedValue) const {
+if (!NormalizedValuesScope.empty())
+  OS << NormalizedValuesScope << "::";
+OS << NormalizedValue;
+  }
+
+  virtual void emitSpecific(raw_ostream &OS) const = 0;
+  MarshallingKindInfo(const Record &R, const char *MacroName)
+  : R(R), MacroName(MacroName) {}
+};
+
+class MarshallingFlagInfo final : public MarshallingKindInfo {
+public:
+  bool IsPositive;
+
+  void emitSpecific(raw_ostream &OS) const override { OS << IsPositive; }
+
+  static std::unique_ptr create(const Record &R) {
+std::unique_ptr Ret(new MarshallingFlagInfo(R));
+Ret->IsPositive = R.getValueAsBit("IsPositive");
+return Ret;
+  }
+
+private:
+  MarshallingFlagInfo(const Record &R)
+  : MarshallingKindInfo(R, "OPTION_WITH_MARSHALLING_FLAG") {}
+};
+
+class MarshallingStringInfo final : public MarshallingKindInfo {
+public:
+  StringRef NormalizerRetTy;
+  StringRef Normalizer;
+  StringRef Denormalizer;
+  int TableIndex = -1;
+  std::vector Values;
+  std::vector NormalizedValues;
+  std::string ValueTableName;
+
+  static constexpr const char *ValueTablePreamble = R"(
+struct SimpleEnumValue {
+  const char *Name;
+  unsigned Value;
+};
+
+struct SimpleEnumValueTable {
+  const SimpleEnumValue *Table;
+  unsigned Size;
+};
+)";
+
+  static constexpr const char *ValueTablesDecl =
+  "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
+
+  void emitSpecific(raw_ostream &OS) const override {
+emitScopedNormalizedValue(OS, NormalizerRetTy);
+OS << ", ";
+OS << Normalizer;
+OS << ", ";
+OS << Denormalizer;
+OS << ", ";
+OS << TableIndex;
+  }
+
+  Optional emitValueTable(raw_ostream &OS) const override {
+if (TableIndex == -1)
+  return {};
+OS << "static const SimpleEnumValue " << ValueTableName << "[] = {\n";
+for (unsigned I = 0, E = Values.size(); I != E; ++I) {
+  OS << "{";
+  write_cstring(OS, Values[I]);
+  OS << ",";
+  OS << "static_cast(";
+  emitScopedNormalizedValue(OS, NormalizedValues[I]);
+  OS << ")},";
+}
+OS << "};\n";
+return String

[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-17 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 271392.
dang added a comment.

Fixed a couple of bugs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -10,11 +10,13 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
 #include 
 #include 
+#include 
 
 using namespace llvm;
 
@@ -33,6 +35,210 @@
   return OS;
 }
 
+static const std::string getOptionSpelling(const Record &R,
+   size_t &PrefixLength) {
+  std::vector Prefixes = R.getValueAsListOfStrings("Prefixes");
+  StringRef Name = R.getValueAsString("Name");
+  if (Prefixes.empty()) {
+PrefixLength = 0;
+return Name.str();
+  }
+  PrefixLength = Prefixes[0].size();
+  return (Twine(Prefixes[0]) + Twine(Name)).str();
+}
+
+static const std::string getOptionSpelling(const Record &R) {
+  size_t PrefixLength;
+  return getOptionSpelling(R, PrefixLength);
+}
+
+static void emitNameUsingSpelling(raw_ostream &OS, const Record &R) {
+  size_t PrefixLength;
+  OS << "&";
+  write_cstring(OS, StringRef(getOptionSpelling(R, PrefixLength)));
+  OS << "[" << PrefixLength << "]";
+}
+
+class MarshallingKindInfo {
+public:
+  const Record &R;
+  const char *MacroName;
+  bool ShouldAlwaysEmit;
+  StringRef KeyPath;
+  StringRef DefaultValue;
+  StringRef NormalizedValuesScope;
+
+  void emit(raw_ostream &OS) const {
+write_cstring(OS, StringRef(getOptionSpelling(R)));
+OS << ", ";
+OS << ShouldAlwaysEmit;
+OS << ", ";
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
+emitSpecific(OS);
+  }
+
+  virtual Optional emitValueTable(raw_ostream &OS) const {
+return None;
+  }
+
+  virtual ~MarshallingKindInfo() = default;
+
+  static std::unique_ptr create(const Record &R);
+
+protected:
+  void emitScopedNormalizedValue(raw_ostream &OS,
+ StringRef NormalizedValue) const {
+if (!NormalizedValuesScope.empty())
+  OS << NormalizedValuesScope << "::";
+OS << NormalizedValue;
+  }
+
+  virtual void emitSpecific(raw_ostream &OS) const = 0;
+  MarshallingKindInfo(const Record &R, const char *MacroName)
+  : R(R), MacroName(MacroName) {}
+};
+
+class MarshallingFlagInfo final : public MarshallingKindInfo {
+public:
+  bool IsPositive;
+
+  void emitSpecific(raw_ostream &OS) const override { OS << IsPositive; }
+
+  static std::unique_ptr create(const Record &R) {
+std::unique_ptr Ret(new MarshallingFlagInfo(R));
+Ret->IsPositive = R.getValueAsBit("IsPositive");
+return Ret;
+  }
+
+private:
+  MarshallingFlagInfo(const Record &R)
+  : MarshallingKindInfo(R, "OPTION_WITH_MARSHALLING_FLAG") {}
+};
+
+class MarshallingStringInfo final : public MarshallingKindInfo {
+public:
+  StringRef NormalizerRetTy;
+  StringRef Normalizer;
+  StringRef Denormalizer;
+  int TableIndex = -1;
+  std::vector Values;
+  std::vector NormalizedValues;
+  std::string ValueTableName;
+
+  static constexpr const char *ValueTablePreamble = R"(
+struct SimpleEnumValue {
+  const char *Name;
+  unsigned Value;
+};
+
+struct SimpleEnumValueTable {
+  const SimpleEnumValue *Table;
+  unsigned Size;
+};
+)";
+
+  static constexpr const char *ValueTablesDecl =
+  "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
+
+  void emitSpecific(raw_ostream &OS) const override {
+emitScopedNormalizedValue(OS, NormalizerRetTy);
+OS << ", ";
+OS << Normalizer;
+OS << ", ";
+OS << Denormalizer;
+OS << ", ";
+OS << TableIndex;
+  }
+
+  Optional emitValueTable(raw_ostream &OS) const override {
+if (TableIndex == -1)
+  return {};
+OS << "static const SimpleEnumValue " << ValueTableName << "[] = {\n";
+for (unsigned I = 0, E = Values.size(); I != E; ++I) {
+  OS << "{";
+  write_cstring(OS, Values[I]);
+  OS << ",";
+  OS << "static_cast(";
+  emitScopedNormalizedValue(OS, NormalizedValues[I]);
+  OS << ")},";
+}
+OS << "};\n";
+return StringRef(ValueTableName);
+  }
+
+  static std::unique_ptr create(const Record &R) {
+assert(!isa(R.getValueInit("NormalizerRetTy")) &&
+   "String options must have a type");
+
+std::unique_ptr Ret(new MarshallingStri

[PATCH] D82860: Port ObjCMTAction to new option parsing system

2020-07-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 275171.
dang added a comment.

Ensure that `mergeForwardValue` can accept default values whose type doesn't 
quite match the associated keypath.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82860

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -59,70 +59,20 @@
   OS << "[" << PrefixLength << "]";
 }
 
-class MarshallingKindInfo {
+class MarshallingInfo {
 public:
+  static constexpr const char *MacroName = "OPTION_WITH_MARSHALLING";
+
   const Record &R;
-  const char *MacroName;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
   StringRef DefaultValue;
   StringRef NormalizedValuesScope;
-
-  void emit(raw_ostream &OS) const {
-write_cstring(OS, StringRef(getOptionSpelling(R)));
-OS << ", ";
-OS << ShouldAlwaysEmit;
-OS << ", ";
-OS << KeyPath;
-OS << ", ";
-emitScopedNormalizedValue(OS, DefaultValue);
-OS << ", ";
-emitSpecific(OS);
-  }
-
-  virtual Optional emitValueTable(raw_ostream &OS) const {
-return None;
-  }
-
-  virtual ~MarshallingKindInfo() = default;
-
-  static std::unique_ptr create(const Record &R);
-
-protected:
-  void emitScopedNormalizedValue(raw_ostream &OS,
- StringRef NormalizedValue) const {
-if (!NormalizedValuesScope.empty())
-  OS << NormalizedValuesScope << "::";
-OS << NormalizedValue;
-  }
-
-  virtual void emitSpecific(raw_ostream &OS) const = 0;
-  MarshallingKindInfo(const Record &R, const char *MacroName)
-  : R(R), MacroName(MacroName) {}
-};
-
-class MarshallingFlagInfo final : public MarshallingKindInfo {
-public:
-  bool IsPositive;
-
-  void emitSpecific(raw_ostream &OS) const override { OS << IsPositive; }
-
-  static std::unique_ptr create(const Record &R) {
-std::unique_ptr Ret(new MarshallingFlagInfo(R));
-Ret->IsPositive = R.getValueAsBit("IsPositive");
-return Ret;
-  }
-
-private:
-  MarshallingFlagInfo(const Record &R)
-  : MarshallingKindInfo(R, "OPTION_WITH_MARSHALLING_FLAG") {}
-};
-
-class MarshallingStringInfo final : public MarshallingKindInfo {
-public:
   StringRef NormalizerRetTy;
   StringRef Normalizer;
   StringRef Denormalizer;
+  StringRef ValueMerger;
+  StringRef ValueExtractor;
   int TableIndex = -1;
   std::vector Values;
   std::vector NormalizedValues;
@@ -143,17 +93,29 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  void emitSpecific(raw_ostream &OS) const override {
+  void emit(raw_ostream &OS) const {
+write_cstring(OS, StringRef(getOptionSpelling(R)));
+OS << ", ";
+OS << ShouldAlwaysEmit;
+OS << ", ";
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
 emitScopedNormalizedValue(OS, NormalizerRetTy);
 OS << ", ";
 OS << Normalizer;
 OS << ", ";
 OS << Denormalizer;
 OS << ", ";
+OS << ValueMerger;
+OS << ", ";
+OS << ValueExtractor;
+OS << ", ";
 OS << TableIndex;
   }
 
-  Optional emitValueTable(raw_ostream &OS) const override {
+  Optional emitValueTable(raw_ostream &OS) const {
 if (TableIndex == -1)
   return {};
 OS << "static const SimpleEnumValue " << ValueTableName << "[] = {\n";
@@ -169,23 +131,32 @@
 return StringRef(ValueTableName);
   }
 
-  static std::unique_ptr create(const Record &R) {
-assert(!isa(R.getValueInit("NormalizerRetTy")) &&
-   "String options must have a type");
-
-std::unique_ptr Ret(new MarshallingStringInfo(R));
-Ret->NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
-
-Ret->Normalizer = R.getValueAsString("Normalizer");
-Ret->Denormalizer = R.getValueAsString("Denormalizer");
+  static MarshallingInfo create(const Record &R) {
+assert(!isa(R.getValueInit("KeyPath")) &&
+   !isa(R.getValueInit("DefaultValue")) &&
+   !isa(R.getValueInit("NormalizerRetTy")) &&
+   !isa(R.getValueInit("ValueMerger")) &&
+   "MarshallingInfo must have a type");
+
+MarshallingInfo Ret(R);
+Ret.ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
+Ret.KeyPath = R.getValueAsString("KeyPath");
+Ret.DefaultValue = R.getValueAsString("DefaultValue");
+Ret.NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
+Ret.NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
+
+Ret.Normalizer = R.getValueAsString("Normalizer");
+Ret.Denormalizer = R.getValueAsString("Denormalizer");
+Ret.ValueMerger = R.getValueAsString("ValueMerger");
+Ret.Value

[PATCH] D82874: Add diagnostic option backing field for -fansi-escape-codes

2020-07-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 275187.
dang added a comment.

Make the tablegen description of the new option more consistent with other 
flags.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82874

Files:
  clang/include/clang/Basic/DiagnosticOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1618,8 +1618,6 @@
   Opts.AbsolutePath = Args.hasArg(OPT_fdiagnostics_absolute_paths);
   Opts.ShowOptionNames = !Args.hasArg(OPT_fno_diagnostics_show_option);
 
-  llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes));
-
   // Default behavior is to not to show note include stacks.
   Opts.ShowNoteIncludeStack = false;
   if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
@@ -3678,6 +3676,10 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
+
+  llvm::sys::Process::UseANSIEscapeCodes(
+  Res.DiagnosticOpts->UseANSIEscapeCodes);
+
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -871,7 +871,8 @@
   Flags<[CoreOption, DriverOption]>;
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
-  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for 
diagnostics">;
+  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for 
diagnostics">,
+  MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes", "false">;
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">;
Index: clang/include/clang/Basic/DiagnosticOptions.def
===
--- clang/include/clang/Basic/DiagnosticOptions.def
+++ clang/include/clang/Basic/DiagnosticOptions.def
@@ -65,6 +65,7 @@
 ENUM_DIAGOPT(Format, TextDiagnosticFormat, 2, Clang) /// Format for 
diagnostics:
 
 DIAGOPT(ShowColors, 1, 0)   /// Show diagnostics with ANSI color sequences.
+DIAGOPT(UseANSIEscapeCodes, 1, 0)
 ENUM_DIAGOPT(ShowOverloads, OverloadsShown, 1,
  Ovl_All)/// Overload candidates to show.
 DIAGOPT(VerifyDiagnostics, 1, 0) /// Check that diagnostics match the expected


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1618,8 +1618,6 @@
   Opts.AbsolutePath = Args.hasArg(OPT_fdiagnostics_absolute_paths);
   Opts.ShowOptionNames = !Args.hasArg(OPT_fno_diagnostics_show_option);
 
-  llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes));
-
   // Default behavior is to not to show note include stacks.
   Opts.ShowNoteIncludeStack = false;
   if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
@@ -3678,6 +3676,10 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
+
+  llvm::sys::Process::UseANSIEscapeCodes(
+  Res.DiagnosticOpts->UseANSIEscapeCodes);
+
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -871,7 +871,8 @@
   Flags<[CoreOption, DriverOption]>;
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, Group;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
-  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for diagnostics">;
+  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for diagnostics">,
+  MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes", "false">;
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation comment block command">,
   MetaVarName<"">;
Index: clang/include/clang/Basic/DiagnosticOptions.def
===
--- clang/include/clang/Basic/DiagnosticOptions.def
+++ clang/include/cl

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-02 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

This enables automatically parsing and generating CC1 arguments for options 
where two flags control the same field, e.g. -fexperimental-new-pass-manager 
and -fno-experimental new pass manager.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer ="normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer ="normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,10 +154,37 @@
   return None;
 }
 
-static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
-unsigned TableIndex,
-const ArgList &Args,
-DiagnosticsEngine &Diags) {
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (!Args.hasArg(PosOpt, NegOpt))
+return None;
+  return Args.hasFlag(PosOpt, NegOpt);
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (!Args.hasArg(PosOpt, NegOpt))
+return None;
+  return Args.hasFlag(PosOpt, NegOpt);
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
+static Optional normalizeSimpleEnum(OptSpecifier Opt,
+  unsigned TableIndex,
+  const ArgList &Args,
+  DiagnosticsEngine &Diags) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
 
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -782,10 +820,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassMana

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 275586.
dang added a comment.

Revert accidental namespace removal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer ="normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer ="normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,6 +154,33 @@
   return None;
 }
 
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (!Args.hasArg(PosOpt, NegOpt))
+return None;
+  return Args.hasFlag(PosOpt, NegOpt);
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (!Args.hasArg(PosOpt, NegOpt))
+return None;
+  return Args.hasFlag(PosOpt, NegOpt);
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -782,10 +820,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassManager =
   Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager,
/* Default */ false);
@@ -3895,13 +3929,7 @@
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
   if (((FLAGS)&options::CC1Option) &&  \
   (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-if (Option::KIND##Class == Option::FlagClass) {\
-  Args.push_back(SPELLING);\
-}  \
-if (Option::KIND##Class 

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 5 inline comments as done.
dang added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:150
 
-static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
-unsigned TableIndex,

dexonsmith wrote:
> I'm not sure if removing the `llvm::` namespace is intentional here, but if 
> so please do it in a separate NFC patch to avoid adding noise in this one.
Yes it was accidental sorry about that.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:161-163
+  if (!Args.hasArg(PosOpt, NegOpt))
+return None;
+  return Args.hasFlag(PosOpt, NegOpt);

dexonsmith wrote:
> This should be:
> ```
> if (Arg *A = Args.getLastArg(PosOpt, NegOpt))
>   return A->getOption().matches(PosOpt);
> return None;
> ```
> Note that `hasArg` and `hasFlag` both resolve to `getLastArg`, so calling 
> them one after another would be unfortunate.
> 
> ... but I'm not even sure where `NegOpt` is coming from here, that looks like 
> it hasn't been passed in. I think you need to change the signature to 
> something like this:
> ```
> static llvm::Optional
> normalizeSimpleFlag(OptSpecifier Opt,
> Optional NegOpt,
> unsigned TableIndex,
> const ArgList &Args,
> DiagnosticsEngine &Diags) {
>   // Handle case without a `no-*` flag.
>   if (!NegOpt)
> return Args.hasArg(Opt);
> 
>   // Handle case with a `no-*` flag.
>   return Args.hasFlagAsOptional(Opt, *NegOpt);
> }
> ```
> 
> It's possible you'll need to split up `OPTION_WITH_MARSHALLING` into two 
> disjoint lists of options:
> - The list of options that can't be negated.
> - The list of options that can be negated, calling a different macro that 
> adds macro arguments for the `CANCEL_ID` and `CANCEL_SPELLING`. For the 
> denormalizer you might also need `CANCEL_VALUE`.
> - Note: the negating options themselves wouldn't be visited in either list.
> - Note: the (de)normalizer APIs would ideally work naturally for something 
> like `-farg=val1` vs. `-farg=val2` vs. `-fno-arg`.
`NegOpt` is passed in via the template parameter, the only weird bit about it 
is that the option name (for example OPT_fno_experimental_pass_manager) is 
constructed in tablegen by hardcoding the OPT_ prefix. What is currently there 
supports the case where the positive option takes a value and the negative one 
doesn't by using different normalizer/denormalizer pairs for the positive and 
the negative option. The bad thing about the current setup is that both options 
have identical normalizers, but I felt that was less bad than splitting the 
list of options and using different macros. 



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3931-3932
   if (((FLAGS)&options::CC1Option) &&  
\
   (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-if (Option::KIND##Class == Option::FlagClass) {
\
-  Args.push_back(SPELLING);
\
-}  
\
-if (Option::KIND##Class == Option::SeparateClass) {
\
-  Args.push_back(SPELLING);
\
-  DENORMALIZER(Args, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
-}  
\
+DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
   }

dexonsmith wrote:
> I realize this commit doesn't introduce it, but it seems unfortunate to call 
> `EXTRACTOR` twice. Maybe in a follow-up or prep commit you can fix that... 
> maybe something like this?
> ```
>   if ((FLAGS)&options::CC1Option) {
> const auto &Extracted = EXTRACTOR(this->KEYPATH);
> if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE)
>   DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));
>   }
> ```
Yes I can do that of course. Although EXTRACTOR is meant to be very cheap and 
in most cases it expands to just `this->KEYPATH`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071



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


[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 275591.
dang marked an inline comment as done.
dang added a comment.

Address some code review feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,6 +154,33 @@
   return None;
 }
 
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -782,10 +820,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassManager =
   Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager,
/* Default */ false);
@@ -3895,13 +3929,7 @@
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
   if (((FLAGS)&options::CC1Option) &&  \
   (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-if (Option::KIND##Class == Option::FlagClass) {\
-  Args.push_back(SPELLING);\
-}  

[PATCH] D83209: Factor out call to EXTRACTOR in generateCC1CommandLine

2020-07-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83209

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,6 +154,33 @@
   return None;
 }
 
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -782,10 +820,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassManager =
   Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager,
/* Default */ false);
@@ -3893,15 +3927,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
-  if (((FLAGS)&options::CC1Option) &&  \
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-if (Option::KIND##Class == Option::FlagClass) {   

[PATCH] D83211: Factor out call to EXTRACTOR in generateCC1CommandLine

2020-07-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83211

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3927,9 +3927,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)
\
-  if (((FLAGS)&options::CC1Option) &&  
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) 
\
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);
\
   }
 
 #include "clang/Driver/Options.inc"


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3927,9 +3927,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
-  if (((FLAGS)&options::CC1Option) &&  \
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   \
+  if ((FLAGS)&options::CC1Option) {\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  \
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) \
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);\
   }
 
 #include "clang/Driver/Options.inc"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3931-3932
   if (((FLAGS)&options::CC1Option) &&  
\
   (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-if (Option::KIND##Class == Option::FlagClass) {
\
-  Args.push_back(SPELLING);
\
-}  
\
-if (Option::KIND##Class == Option::SeparateClass) {
\
-  Args.push_back(SPELLING);
\
-  DENORMALIZER(Args, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
-}  
\
+DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
   }

dang wrote:
> dexonsmith wrote:
> > I realize this commit doesn't introduce it, but it seems unfortunate to 
> > call `EXTRACTOR` twice. Maybe in a follow-up or prep commit you can fix 
> > that... maybe something like this?
> > ```
> >   if ((FLAGS)&options::CC1Option) {
> > const auto &Extracted = EXTRACTOR(this->KEYPATH);
> > if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE)
> >   DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, 
> > EXTRACTOR(this->KEYPATH));
> >   }
> > ```
> Yes I can do that of course. Although EXTRACTOR is meant to be very cheap and 
> in most cases it expands to just `this->KEYPATH`
See D83211


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071



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


[PATCH] D83298: Add ability to make fixups to CompilerInvocation after option parsing

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D83211 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83298

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -256,6 +256,14 @@
   return KeyPath & Value;
 }
 
+static void FixupInvocation(CompilerInvocation &Invocation) {
+  LangOptions &LangOpts = *Invocation.getLangOpts();
+  CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
+  CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
+  CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
+  CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
+}
+
 
//===--===//
 // Deserialization (from args)
 
//===--===//
@@ -1180,16 +1188,8 @@
   Opts.InstrumentFunctionEntryBare =
   Args.hasArg(OPT_finstrument_function_entry_bare);
 
-  Opts.XRayInstrumentFunctions =
-  Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
-  Opts.XRayIgnoreLoops = Args.hasArg(OPT_fxray_ignore_loops);
-  Opts.XRayOmitFunctionIndex = Args.hasArg(OPT_fno_xray_function_index);
 
   auto XRayInstrBundles =
   Args.getAllArgValues(OPT_fxray_instrumentation_bundle);
@@ -3350,13 +3350,6 @@
   systemBlacklists.begin(),
   systemBlacklists.end());
 
-  // -fxray-instrument
-  Opts.XRayInstrument = Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
-
   // -fxray-{always,never}-instrument= filenames.
   Opts.XRayAlwaysInstrumentFiles =
   Args.getAllArgValues(OPT_fxray_always_instrument);
@@ -3710,6 +3703,7 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
+  FixupInvocation(Res);
 
   llvm::sys::Process::UseANSIEscapeCodes(
   Res.DiagnosticOpts->UseANSIEscapeCodes);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1281,7 +1281,7 @@
   Alias, AliasArgs<["full"]>,
   HelpText<"Enable cf-protection in 'full' mode">;
 
-defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit">;
+defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit", "", "", [], 
"LangOpts->XRayInstrument">;
 
 def fxray_instruction_threshold_EQ :
   JoinedOrSeparate<["-"], "fxray-instruction-threshold=">,
@@ -1309,15 +1309,15 @@
   HelpText<"List of modes to link in by default into XRay instrumented 
binaries.">;
 
 defm xray_always_emit_customevents : 
OptInFFlag<"xray-always-emit-customevents",
-  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented">;
+  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented", "", "", [], 
"LangOpts->XRayAlwaysEmitCustomEvents">;
 
 defm xray_always_emit_typedevents : OptInFFlag<"xray-always-emit-typedevents",
-  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented">;
+  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented", "", "", [], "LangOpts->XRayAlwaysEmitTypedEvents">;
 
 defm xray_ignore_loops : OptInFFlag<"xray-ignore-loops",
-  "Don't instrument functions with loops unless they also meet the minimum 
function size">;
+  "Don't instrument functions with loops unless they also meet the minimum 
function size", "", "", [], "CodeGenOpts.XRayIgnoreLoops">;
 defm xray_function_index : OptOutFFlag<"xray-function-index", "",
-  "Omit function index section at the expense of single-function patching 
performance">;
+  "Omit function index section at the expense of single-function patching 
performance", "", [], "CodeGenOpts.XRayOmitFunctionIndex">;
 
 def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group,
   Flags<[CC1Option]>,


Index: clang/lib/Frontend/CompilerInvocation.cpp
=

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276007.
dang added a comment.

Make mergers use values directly instead of constant references


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,6 +154,33 @@
   return None;
 }
 
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -200,12 +238,11 @@
 }
 
 template 
-static T mergeForwardValue(T KeyPath, const U &Value) {
+static T mergeForwardValue(T KeyPath, U Value) {
   return Value;
 }
 
-template 
-static T mergeMaskValue(T KeyPath, const U &Value) {
+template  static T mergeMaskValue(T KeyPath, U Value) {
   return KeyPath | Value;
 }
 
@@ -782,10 +819,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassManager =
   Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager,
/* Default */ false);
@@ -3895,13 +3928,7 @@
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
   if (((FLAGS)&options::CC1Option) &&   

[PATCH] D82860: Port ObjCMTAction to new option parsing system

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276008.
dang added a comment.

Make mergers use values directly instead of constant references.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82860

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -59,70 +59,20 @@
   OS << "[" << PrefixLength << "]";
 }
 
-class MarshallingKindInfo {
+class MarshallingInfo {
 public:
+  static constexpr const char *MacroName = "OPTION_WITH_MARSHALLING";
+
   const Record &R;
-  const char *MacroName;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
   StringRef DefaultValue;
   StringRef NormalizedValuesScope;
-
-  void emit(raw_ostream &OS) const {
-write_cstring(OS, StringRef(getOptionSpelling(R)));
-OS << ", ";
-OS << ShouldAlwaysEmit;
-OS << ", ";
-OS << KeyPath;
-OS << ", ";
-emitScopedNormalizedValue(OS, DefaultValue);
-OS << ", ";
-emitSpecific(OS);
-  }
-
-  virtual Optional emitValueTable(raw_ostream &OS) const {
-return None;
-  }
-
-  virtual ~MarshallingKindInfo() = default;
-
-  static std::unique_ptr create(const Record &R);
-
-protected:
-  void emitScopedNormalizedValue(raw_ostream &OS,
- StringRef NormalizedValue) const {
-if (!NormalizedValuesScope.empty())
-  OS << NormalizedValuesScope << "::";
-OS << NormalizedValue;
-  }
-
-  virtual void emitSpecific(raw_ostream &OS) const = 0;
-  MarshallingKindInfo(const Record &R, const char *MacroName)
-  : R(R), MacroName(MacroName) {}
-};
-
-class MarshallingFlagInfo final : public MarshallingKindInfo {
-public:
-  bool IsPositive;
-
-  void emitSpecific(raw_ostream &OS) const override { OS << IsPositive; }
-
-  static std::unique_ptr create(const Record &R) {
-std::unique_ptr Ret(new MarshallingFlagInfo(R));
-Ret->IsPositive = R.getValueAsBit("IsPositive");
-return Ret;
-  }
-
-private:
-  MarshallingFlagInfo(const Record &R)
-  : MarshallingKindInfo(R, "OPTION_WITH_MARSHALLING_FLAG") {}
-};
-
-class MarshallingStringInfo final : public MarshallingKindInfo {
-public:
   StringRef NormalizerRetTy;
   StringRef Normalizer;
   StringRef Denormalizer;
+  StringRef ValueMerger;
+  StringRef ValueExtractor;
   int TableIndex = -1;
   std::vector Values;
   std::vector NormalizedValues;
@@ -143,17 +93,29 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  void emitSpecific(raw_ostream &OS) const override {
+  void emit(raw_ostream &OS) const {
+write_cstring(OS, StringRef(getOptionSpelling(R)));
+OS << ", ";
+OS << ShouldAlwaysEmit;
+OS << ", ";
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
 emitScopedNormalizedValue(OS, NormalizerRetTy);
 OS << ", ";
 OS << Normalizer;
 OS << ", ";
 OS << Denormalizer;
 OS << ", ";
+OS << ValueMerger;
+OS << ", ";
+OS << ValueExtractor;
+OS << ", ";
 OS << TableIndex;
   }
 
-  Optional emitValueTable(raw_ostream &OS) const override {
+  Optional emitValueTable(raw_ostream &OS) const {
 if (TableIndex == -1)
   return {};
 OS << "static const SimpleEnumValue " << ValueTableName << "[] = {\n";
@@ -169,23 +131,32 @@
 return StringRef(ValueTableName);
   }
 
-  static std::unique_ptr create(const Record &R) {
-assert(!isa(R.getValueInit("NormalizerRetTy")) &&
-   "String options must have a type");
-
-std::unique_ptr Ret(new MarshallingStringInfo(R));
-Ret->NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
-
-Ret->Normalizer = R.getValueAsString("Normalizer");
-Ret->Denormalizer = R.getValueAsString("Denormalizer");
+  static MarshallingInfo create(const Record &R) {
+assert(!isa(R.getValueInit("KeyPath")) &&
+   !isa(R.getValueInit("DefaultValue")) &&
+   !isa(R.getValueInit("NormalizerRetTy")) &&
+   !isa(R.getValueInit("ValueMerger")) &&
+   "MarshallingInfo must have a type");
+
+MarshallingInfo Ret(R);
+Ret.ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
+Ret.KeyPath = R.getValueAsString("KeyPath");
+Ret.DefaultValue = R.getValueAsString("DefaultValue");
+Ret.NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
+Ret.NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
+
+Ret.Normalizer = R.getValueAsString("Normalizer");
+Ret.Denormalizer = R.getValueAsString("Denormalizer");
+Ret.ValueMerger = R.getValueAsString("ValueMerger");
+Ret.ValueExtractor = R.getValueAsString("ValueExtractor");

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276009.
dang added a comment.

Rebase on top of some changes to parent patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td

Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -156,6 +156,7 @@
   : MarshallingInfo {
   code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
+  code Denormalizer = "denormalizeSimpleFlag";
 }
 
 class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
@@ -164,6 +165,20 @@
   code ValueExtractor = "(extractMaskValue)";
 }
 
+class MarshallingInfoBooleanTrueFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanTrueFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
+class MarshallingInfoBooleanFalseFlag
+  : MarshallingInfoFlag {
+  bit ShouldAlwaysEmit = 1;
+  code Normalizer = "normalizeBooleanFalseFlag";
+  code Denormalizer = "denormalizeBooleanFlag";
+}
+
 // Mixins for additional marshalling attributes.
 
 class IsNegative {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -138,6 +138,13 @@
   return !Args.hasArg(Opt);
 }
 
+void denormalizeSimpleFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  Args.push_back(Spelling);
+}
+
 template 
 static llvm::Optional
 normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
@@ -147,6 +154,33 @@
   return None;
 }
 
+template 
+static Optional
+normalizeBooleanTrueFlag(OptSpecifier PosOpt, unsigned TableIndex,
+ const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static Optional
+normalizeBooleanFalseFlag(OptSpecifier NegOpt, unsigned TableIndex,
+  const ArgList &Args, DiagnosticsEngine &Diags) {
+  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+return A->getOption().matches(PosOpt);
+  return None;
+}
+
+template 
+static void denormalizeBooleanFlag(SmallVectorImpl &Args,
+   const char *Spelling,
+   CompilerInvocation::StringAllocator SA,
+   unsigned TableIndex, unsigned Value) {
+  if (Value == IsPositive)
+Args.push_back(Spelling);
+}
+
 static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
 unsigned TableIndex,
 const ArgList &Args,
@@ -169,12 +203,14 @@
 }
 
 static void denormalizeSimpleEnum(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   for (int I = 0, E = Table.Size; I != E; ++I) {
 if (Value == Table.Table[I].Value) {
+  Args.push_back(Spelling);
   Args.push_back(Table.Table[I].Name);
   return;
 }
@@ -185,8 +221,10 @@
 }
 
 static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
   CompilerInvocation::StringAllocator SA,
   unsigned TableIndex, const std::string &Value) {
+  Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
@@ -781,10 +819,6 @@
 }
   }
 
-  Opts.ExperimentalNewPassManager = Args.hasFlag(
-  OPT_fexperimental_new_pass_manager, OPT_fno_experimental_new_pass_manager,
-  /* Default */ ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER);
-
   Opts.DebugPassManager =
   Args.hasFlag(OPT_fdebug_pass_manager, OPT_fno_debug_pass_manager,
/* Default */ false);
@@ -3894,13 +3928,7 @@
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
   if (((FLAGS)&options::CC1Option) &&  \
   (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-if (Option::KIND##Class == Option::FlagClass) {\
-  Args.push_back(SPELLING);\
-}   

[PATCH] D83298: Add ability to make fixups to CompilerInvocation after option parsing

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276010.
dang added a comment.

Move the UseANSIEscapeCodes fixup to the correct place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83298

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -255,6 +255,17 @@
   return KeyPath & Value;
 }
 
+static void FixupInvocation(CompilerInvocation &Invocation) {
+  LangOptions &LangOpts = *Invocation.getLangOpts();
+  DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
+  CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
+  CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
+  CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
+  CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
+
+  llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
+}
+
 
//===--===//
 // Deserialization (from args)
 
//===--===//
@@ -1179,16 +1190,8 @@
   Opts.InstrumentFunctionEntryBare =
   Args.hasArg(OPT_finstrument_function_entry_bare);
 
-  Opts.XRayInstrumentFunctions =
-  Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
-  Opts.XRayIgnoreLoops = Args.hasArg(OPT_fxray_ignore_loops);
-  Opts.XRayOmitFunctionIndex = Args.hasArg(OPT_fno_xray_function_index);
 
   auto XRayInstrBundles =
   Args.getAllArgValues(OPT_fxray_instrumentation_bundle);
@@ -3349,13 +3352,6 @@
   systemBlacklists.begin(),
   systemBlacklists.end());
 
-  // -fxray-instrument
-  Opts.XRayInstrument = Args.hasArg(OPT_fxray_instrument);
-  Opts.XRayAlwaysEmitCustomEvents =
-  Args.hasArg(OPT_fxray_always_emit_customevents);
-  Opts.XRayAlwaysEmitTypedEvents =
-  Args.hasArg(OPT_fxray_always_emit_typedevents);
-
   // -fxray-{always,never}-instrument= filenames.
   Opts.XRayAlwaysInstrumentFiles =
   Args.getAllArgValues(OPT_fxray_always_instrument);
@@ -3709,9 +3705,7 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
-
-  llvm::sys::Process::UseANSIEscapeCodes(
-  Res.DiagnosticOpts->UseANSIEscapeCodes);
+  FixupInvocation(Res);
 
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1281,7 +1281,7 @@
   Alias, AliasArgs<["full"]>,
   HelpText<"Enable cf-protection in 'full' mode">;
 
-defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit">;
+defm xray_instrument : OptInFFlag<"xray-instrument", "Generate XRay 
instrumentation sleds on function entry and exit", "", "", [], 
"LangOpts->XRayInstrument">;
 
 def fxray_instruction_threshold_EQ :
   JoinedOrSeparate<["-"], "fxray-instruction-threshold=">,
@@ -1309,15 +1309,15 @@
   HelpText<"List of modes to link in by default into XRay instrumented 
binaries.">;
 
 defm xray_always_emit_customevents : 
OptInFFlag<"xray-always-emit-customevents",
-  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented">;
+  "Always emit __xray_customevent(...) calls even if the containing function 
is not always instrumented", "", "", [], 
"LangOpts->XRayAlwaysEmitCustomEvents">;
 
 defm xray_always_emit_typedevents : OptInFFlag<"xray-always-emit-typedevents",
-  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented">;
+  "Always emit __xray_typedevent(...) calls even if the containing function is 
not always instrumented", "", "", [], "LangOpts->XRayAlwaysEmitTypedEvents">;
 
 defm xray_ignore_loops : OptInFFlag<"xray-ignore-loops",
-  "Don't instrument functions with loops unless they also meet the minimum 
function size">;
+  "Don't instrument functions with loops unless they also meet the minimum 
function size", "", "", [], "CodeGenOpts.XRayIgnoreLoops">;
 defm xray_function_index : OptOutFFlag<"xray-function-index", "",
-  "Omit function index section at the expense of single-function patching 
performance">;
+  "Omit function index section at the expense of single-fu

[PATCH] D83315: Turn arcmt-* options into a single option

2020-07-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

- The new option, -arcmt-action, is a simple enum based option.
- The driver is modified to translate the existing -ccc-acmt-* options 
accordingly

Depends on D83298 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83315

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/ARCMT/GC-check-warn-nsalloc.m
  clang/test/ARCMT/GC-check.m
  clang/test/ARCMT/atautorelease-check.m
  clang/test/ARCMT/check-api.m
  clang/test/ARCMT/check-with-pch.m
  clang/test/ARCMT/check-with-serialized-diag.m
  clang/test/ARCMT/checking-in-arc.m
  clang/test/ARCMT/checking.m
  clang/test/ARCMT/cxx-checking.mm
  clang/test/ARCMT/driver-migrate.m
  clang/test/ARCMT/migrate-emit-errors.m
  clang/test/ARCMT/migrate-plist-output.m
  clang/test/ARCMT/migrate-space-in-path.m
  clang/test/ARCMT/migrate-with-pch.m
  clang/test/ARCMT/migrate.m
  clang/test/ARCMT/no-canceling-bridge-to-bridge-cast.m
  clang/test/ARCMT/nonobjc-to-objc-cast-2.m
  clang/test/ARCMT/releases-driver.m
  clang/test/ARCMT/releases-driver.m.result
  clang/test/ARCMT/verify.m
  clang/test/ARCMT/with-arc-mode-modify.m
  clang/test/ARCMT/with-arc-mode-modify.m.result
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -102,7 +102,7 @@
 OS << ", ";
 emitScopedNormalizedValue(OS, DefaultValue);
 OS << ", ";
-emitScopedNormalizedValue(OS, NormalizerRetTy);
+OS << NormalizerRetTy;
 OS << ", ";
 OS << Normalizer;
 OS << ", ";
Index: clang/test/ARCMT/with-arc-mode-modify.m.result
===
--- clang/test/ARCMT/with-arc-mode-modify.m.result
+++ clang/test/ARCMT/with-arc-mode-modify.m.result
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action modify -fsyntax-only -fobjc-arc -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/with-arc-mode-modify.m
===
--- clang/test/ARCMT/with-arc-mode-modify.m
+++ clang/test/ARCMT/with-arc-mode-modify.m
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action modify -fsyntax-only -fobjc-arc -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/verify.m
===
--- clang/test/ARCMT/verify.m
+++ clang/test/ARCMT/verify.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -arcmt-check -verify %s
-// RUN: not %clang_cc1 -arcmt-check -verify %t.invalid 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -arcmt-action check -verify %s
+// RUN: not %clang_cc1 -arcmt-action check -verify %t.invalid 2>&1 | FileCheck %s
 
 #if 0
 // expected-error {{should be ignored}}
Index: clang/test/ARCMT/releases-driver.m.result
===
--- clang/test/ARCMT/releases-driver.m.result
+++ clang/test/ARCMT/releases-driver.m.result
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action modify -triple x86_64-apple-macosx10.6 -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/releases-driver.m
===
--- clang/test/ARCMT/releases-driver.m
+++ clang/test/ARCMT/releases-driver.m
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action modify -triple x86_64-apple-macosx10.6 -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/nonobjc-to-objc-cast-2.m
===
--- clang/test/ARCMT/nonobjc-to-objc-cast-2.m
+++ clang/test/ARCMT/nonobjc-to-objc-cast-2.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s
+// RUN: %clang_cc1 -arcmt-action check -verify -triple x86_64-apple-darwin10 %s
 
 #include "Common.h"
 
Index: clang/test/ARCMT/no-canceling-bridge-to-bridge-cast.m

[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276400.
dang added a comment.

Split into two macro kinds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -61,8 +61,9 @@
 
 class MarshallingInfo {
 public:
-  static constexpr const char *MacroName = "OPTION_WITH_MARSHALLING";
+  using Ptr = std::unique_ptr;
 
+  const char *MacroName;
   const Record &R;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
@@ -78,6 +79,8 @@
   std::vector NormalizedValues;
   std::string ValueTableName;
 
+  static size_t NextTableIndex;
+
   static constexpr const char *ValueTablePreamble = R"(
 struct SimpleEnumValue {
   const char *Name;
@@ -93,7 +96,14 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  void emit(raw_ostream &OS) const {
+  MarshallingInfo(const Record &R)
+  : MacroName("OPTION_WITH_MARSHALLING"), R(R) {}
+  MarshallingInfo(const char *MacroName, const Record &R)
+  : MacroName(MacroName), R(R){};
+
+  virtual ~MarshallingInfo() = default;
+
+  virtual void emit(raw_ostream &OS) const {
 write_cstring(OS, StringRef(getOptionSpelling(R)));
 OS << ", ";
 OS << ShouldAlwaysEmit;
@@ -131,53 +141,6 @@
 return StringRef(ValueTableName);
   }
 
-  static MarshallingInfo create(const Record &R) {
-assert(!isa(R.getValueInit("KeyPath")) &&
-   !isa(R.getValueInit("DefaultValue")) &&
-   !isa(R.getValueInit("NormalizerRetTy")) &&
-   !isa(R.getValueInit("ValueMerger")) &&
-   "MarshallingInfo must have a type");
-
-MarshallingInfo Ret(R);
-Ret.ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
-Ret.KeyPath = R.getValueAsString("KeyPath");
-Ret.DefaultValue = R.getValueAsString("DefaultValue");
-Ret.NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
-Ret.NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
-
-Ret.Normalizer = R.getValueAsString("Normalizer");
-Ret.Denormalizer = R.getValueAsString("Denormalizer");
-Ret.ValueMerger = R.getValueAsString("ValueMerger");
-Ret.ValueExtractor = R.getValueAsString("ValueExtractor");
-
-if (!isa(R.getValueInit("NormalizedValues"))) {
-  assert(!isa(R.getValueInit("Values")) &&
- "Cannot provide normalized values for value-less options");
-  Ret.TableIndex = NextTableIndex++;
-  Ret.NormalizedValues = R.getValueAsListOfStrings("NormalizedValues");
-  Ret.Values.reserve(Ret.NormalizedValues.size());
-  Ret.ValueTableName = getOptionName(R) + "ValueTable";
-
-  StringRef ValuesStr = R.getValueAsString("Values");
-  for (;;) {
-size_t Idx = ValuesStr.find(',');
-if (Idx == StringRef::npos)
-  break;
-if (Idx > 0)
-  Ret.Values.push_back(ValuesStr.slice(0, Idx));
-ValuesStr = ValuesStr.slice(Idx + 1, StringRef::npos);
-  }
-  if (!ValuesStr.empty())
-Ret.Values.push_back(ValuesStr);
-
-  assert(Ret.Values.size() == Ret.NormalizedValues.size() &&
- "The number of normalized values doesn't match the number of "
- "values");
-}
-
-return Ret;
-  }
-
 private:
   void emitScopedNormalizedValue(raw_ostream &OS,
  StringRef NormalizedValue) const {
@@ -185,13 +148,79 @@
   OS << NormalizedValuesScope << "::";
 OS << NormalizedValue;
   }
+};
+
+size_t MarshallingInfo::NextTableIndex = 0;
 
-  MarshallingInfo(const Record &R) : R(R){};
+class MarshallingInfoBooleanFlag : public MarshallingInfo {
+public:
+  const Record &NegOption;
 
-  static size_t NextTableIndex;
+  MarshallingInfoBooleanFlag(const Record &Option, const Record &NegOption)
+  : MarshallingInfo("OPTION_WITH_MARSHALLING_BOOLEAN", Option),
+NegOption(NegOption) {}
+
+  void emit(raw_ostream &OS) const override {
+MarshallingInfo::emit(OS);
+OS << ", ";
+OS << getOptionName(NegOption);
+OS << ", ";
+write_cstring(OS, getOptionSpelling(NegOption));
+  }
 };
 
-size_t MarshallingInfo::NextTableIndex = 0;
+static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
+  assert(!isa(R.getValueInit("KeyPath")) &&
+ !isa(R.getValueInit("DefaultValue")) &&
+ !isa(R.getValueInit("NormalizerRetTy")) &&
+ !isa(R.getValueInit("ValueMerger")) &&
+ "MarshallingInfo must have a type");
+
+  MarshallingInfo::Ptr Ret;
+  if (Record *MaybeNegOption = R.getValueAsOptionalDef("NegOption")) {
+Ret = std::make_unique(R, *MaybeNegOpti

[PATCH] D83315: Turn arcmt-* options into a single option

2020-07-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276438.
dang added a comment.

Instead of using a Separate option kind (-arcmt-action action) use a Joined 
kind (-arcmt-action=*)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83315

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/ARCMT/GC-check-warn-nsalloc.m
  clang/test/ARCMT/GC-check.m
  clang/test/ARCMT/atautorelease-check.m
  clang/test/ARCMT/check-api.m
  clang/test/ARCMT/check-with-pch.m
  clang/test/ARCMT/check-with-serialized-diag.m
  clang/test/ARCMT/checking-in-arc.m
  clang/test/ARCMT/checking.m
  clang/test/ARCMT/cxx-checking.mm
  clang/test/ARCMT/driver-migrate.m
  clang/test/ARCMT/migrate-emit-errors.m
  clang/test/ARCMT/migrate-plist-output.m
  clang/test/ARCMT/migrate-space-in-path.m
  clang/test/ARCMT/migrate-with-pch.m
  clang/test/ARCMT/migrate.m
  clang/test/ARCMT/no-canceling-bridge-to-bridge-cast.m
  clang/test/ARCMT/nonobjc-to-objc-cast-2.m
  clang/test/ARCMT/releases-driver.m
  clang/test/ARCMT/releases-driver.m.result
  clang/test/ARCMT/verify.m
  clang/test/ARCMT/with-arc-mode-modify.m
  clang/test/ARCMT/with-arc-mode-modify.m.result
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -112,7 +112,7 @@
 OS << ", ";
 emitScopedNormalizedValue(OS, DefaultValue);
 OS << ", ";
-emitScopedNormalizedValue(OS, NormalizerRetTy);
+OS << NormalizerRetTy;
 OS << ", ";
 OS << Normalizer;
 OS << ", ";
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -193,6 +193,9 @@
   code Normalizer = "normalizeSimpleEnum";
   code Denormalizer = "denormalizeSimpleEnum";
 }
+class AutoNormalizeEnumJoined : AutoNormalizeEnum {
+  code Denormalizer = "denormalizeSimpleEnumJoined";
+}
 class ValueMerger { code ValueMerger = merger; }
 class ValueExtractor { code ValueExtractor = extractor; }
 
Index: clang/test/ARCMT/with-arc-mode-modify.m.result
===
--- clang/test/ARCMT/with-arc-mode-modify.m.result
+++ clang/test/ARCMT/with-arc-mode-modify.m.result
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -fsyntax-only -fobjc-arc -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/with-arc-mode-modify.m
===
--- clang/test/ARCMT/with-arc-mode-modify.m
+++ clang/test/ARCMT/with-arc-mode-modify.m
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -fsyntax-only -fobjc-arc -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/verify.m
===
--- clang/test/ARCMT/verify.m
+++ clang/test/ARCMT/verify.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -arcmt-check -verify %s
-// RUN: not %clang_cc1 -arcmt-check -verify %t.invalid 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -arcmt-action=check -verify %s
+// RUN: not %clang_cc1 -arcmt-action=check -verify %t.invalid 2>&1 | FileCheck %s
 
 #if 0
 // expected-error {{should be ignored}}
Index: clang/test/ARCMT/releases-driver.m.result
===
--- clang/test/ARCMT/releases-driver.m.result
+++ clang/test/ARCMT/releases-driver.m.result
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -triple x86_64-apple-macosx10.6 -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/releases-driver.m
===
--- clang/test/ARCMT/releases-driver.m
+++ clang/test/ARCMT/releases-driver.m
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -triple x86_64-apple-macosx10.6 -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/nonobjc-to-obj

[PATCH] D83405: Factor out EXTRACTOR call

2020-07-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D83071 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83405

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3934,9 +3934,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)
\
-  if (((FLAGS)&options::CC1Option) &&  
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) 
\
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);
\
   }
 
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   
\
@@ -3944,10 +3945,10 @@
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,
\
 NEG_SPELLING)  
\
-  if (((FLAGS)&options::CC1Option) &&  
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX,
\
- EXTRACTOR(this->KEYPATH));
\
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) 
\
+  DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, Extracted);  
\
   }
 
 #include "clang/Driver/Options.inc"


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3934,9 +3934,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
-  if (((FLAGS)&options::CC1Option) &&  \
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   \
+  if ((FLAGS)&options::CC1Option) {\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  \
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) \
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);\
   }
 
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   \
@@ -3944,10 +3945,10 @@
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,\
 NEG_SPELLING)  \
-  if (((FLAGS)&options::CC1Option) &&  \
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX,\
- EXTRACTOR(this->KEYPATH));\
+  if ((FLAGS)&options::CC1Option) {\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  \
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) \
+  DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, Extracted);  \
   }
 
 #include "clang/Driver/Options.inc"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83211: Factor out call to EXTRACTOR in generateCC1CommandLine

2020-07-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276466.
dang added a comment.

Rebase on top of latest changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83211

Files:
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3934,9 +3934,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)
\
-  if (((FLAGS)&options::CC1Option) &&  
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) 
\
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);
\
   }
 
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   
\
@@ -3944,10 +3945,10 @@
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,
\
 NEG_SPELLING)  
\
-  if (((FLAGS)&options::CC1Option) &&  
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX,
\
- EXTRACTOR(this->KEYPATH));
\
+  if ((FLAGS)&options::CC1Option) {
\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  
\
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) 
\
+  DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, Extracted);  
\
   }
 
 #include "clang/Driver/Options.inc"


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3934,9 +3934,10 @@
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
-  if (((FLAGS)&options::CC1Option) &&  \
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   \
+  if ((FLAGS)&options::CC1Option) {\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  \
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) \
+  DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);\
   }
 
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   \
@@ -3944,10 +3945,10 @@
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
 TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,\
 NEG_SPELLING)  \
-  if (((FLAGS)&options::CC1Option) &&  \
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {\
-DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX,\
- EXTRACTOR(this->KEYPATH));\
+  if ((FLAGS)&options::CC1Option) {\
+const auto &Extracted = EXTRACTOR(this->KEYPATH);  \
+if (ALWAYS_EMIT || Extracted != DEFAULT_VALUE) \
+  DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, Extracted);  \
   }
 
 #include "clang/Driver/Options.inc"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83406: Remove NormalizerRetTy and use the decltype of the KeyPath instead

2020-07-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

Depends on D83315 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83406

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -69,7 +69,6 @@
   StringRef KeyPath;
   StringRef DefaultValue;
   StringRef NormalizedValuesScope;
-  StringRef NormalizerRetTy;
   StringRef Normalizer;
   StringRef Denormalizer;
   StringRef ValueMerger;
@@ -112,8 +111,6 @@
 OS << ", ";
 emitScopedNormalizedValue(OS, DefaultValue);
 OS << ", ";
-OS << NormalizerRetTy;
-OS << ", ";
 OS << Normalizer;
 OS << ", ";
 OS << Denormalizer;
@@ -172,9 +169,9 @@
 static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
   assert(!isa(R.getValueInit("KeyPath")) &&
  !isa(R.getValueInit("DefaultValue")) &&
- !isa(R.getValueInit("NormalizerRetTy")) &&
  !isa(R.getValueInit("ValueMerger")) &&
- "MarshallingInfo must have a type");
+ "MarshallingInfo must have a provide a keypath, default value and a "
+ "value merger");
 
   MarshallingInfo::Ptr Ret;
   if (Record *MaybeNegOption = R.getValueAsOptionalDef("NegOption")) {
@@ -187,7 +184,6 @@
   Ret->KeyPath = R.getValueAsString("KeyPath");
   Ret->DefaultValue = R.getValueAsString("DefaultValue");
   Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
-  Ret->NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
 
   Ret->Normalizer = R.getValueAsString("Normalizer");
   Ret->Denormalizer = R.getValueAsString("Denormalizer");
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -151,19 +151,16 @@
   code DefaultValue = defaultvalue;
 }
 
-class MarshallingInfoString
-  : MarshallingInfo {
-  code NormalizerRetTy = normalizerretty;
-}
+class MarshallingInfoString
+  : MarshallingInfo {}
 
-class MarshallingInfoFlag
+class MarshallingInfoFlag
   : MarshallingInfo {
-  code NormalizerRetTy = ty;
   code Normalizer = "normalizeSimpleFlag";
   code Denormalizer = "denormalizeSimpleFlag";
 }
 
-class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
+class MarshallingInfoBitfieldFlag : MarshallingInfoFlag {
   code Normalizer = "(normalizeFlagToValue)";
   code ValueMerger = "mergeMaskValue";
   code ValueExtractor = "(extractMaskValue)";
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -260,7 +260,7 @@
 
 template 
 static T mergeForwardValue(T KeyPath, U Value) {
-  return static_cast(Value);
+  return Value;
 }
 
 template  static T mergeMaskValue(T KeyPath, U Value) {
@@ -3662,10 +3662,11 @@
 #define OPTION_WITH_MARSHALLING(   \
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
-TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)\
+NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)  \
   {\
 if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))  \
-  this->KEYPATH = MERGER(this->KEYPATH, static_cast(*MaybeValue));   \
+  this->KEYPATH = MERGER(  \
+  this->KEYPATH, static_castKEYPATH)>(*MaybeValue));   \
 else   \
   this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);\
   }
@@ -3673,12 +3674,13 @@
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   \
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  \
-TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,\
+NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,  \
 NEG_SPELLING)  \
   {\
 if (auto MaybeValue =  \
 NORMALIZER(OPT_##I

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

2020-07-09 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1176
+defm reciprocal_math : OptInFFlag< "reciprocal-math", "Allow division 
operations to be reassociated", "", "", [], "LangOpts->AllowRecip">;
+def fapprox_func : Flag<["-"], "fapprox-func">, Group, 
Flags<[CC1Option, NoDriverOption]>,
+  MarshallingInfoFlag<"LangOpts->ApproxFunc", "false">;

Anastasia wrote:
> could this also be OptInFFlag?
The aim was to keep the driver semantics the same as before and this was not 
something you could control with the driver, so I left it as just a CC1 flag. 
However if it makes sense to be able to control this from the driver then we 
can definitely make this `OptInFFLag`.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2805
 CmdArgs.push_back("-menable-unsafe-fp-math");
+ApproxFunc = true;
+  }

Anastasia wrote:
> Is this a bug fix ?
No, in current trunk approximating floating point functions was something that 
was implied by other optimization flags, i.e. disabling math errno, enabling 
associative/reciprocal math, disabling signed zeros and disabling trapping math 
and -ffast-math which does all the previously mentioned things. This patch 
moves this logic in the driver by introducing a new CC1 flag for this so that 
parsing CC1 options can be more easily automated. This just reflects the logic 
that was previously inside cc1.



Comment at: clang/test/CodeGen/fp-function-attrs.cpp:2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffinite-math-only 
-menable-unsafe-fp-math \
+// RUN:   -menable-no-infs -menable-no-nans -fno-signed-zeros 
-freciprocal-math \
+// RUN:   -fapprox-func -mreassociate -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s

Anastasia wrote:
> Not clear why do you need to pass these extra flags now?
Previously passing -ffast-math to CC1 implied all these other flags. I am 
trying to make CC1 option parsing as simple as possible, so that we can then 
make it easy to generate a command line from a CompilerInvocation instance. You 
can refer to [[ http://lists.llvm.org/pipermail/cfe-dev/2020-May/065421.html | 
http://lists.llvm.org/pipermail/cfe-dev/2020-May/065421.html ]] for more 
details on why we want to be able to do this


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] D83474: Add support for specifying only a denormalizer

2020-07-09 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.

This commit adds a denormalyzer for optimization level.
Depends on D83406 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83474

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -63,8 +63,11 @@
 public:
   using Ptr = std::unique_ptr;
 
-  const char *MacroName;
+  static constexpr const char *MacroNameSerializing = "OPTION_WITH_SERIALIZING";
+  static constexpr const char *MacroNameParsing = "OPTION_WITH_PARSING";
+
   const Record &R;
+  bool CanParse;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
   StringRef DefaultValue;
@@ -95,31 +98,36 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  MarshallingInfo(const Record &R)
-  : MacroName("OPTION_WITH_MARSHALLING"), R(R) {}
-  MarshallingInfo(const char *MacroName, const Record &R)
-  : MacroName(MacroName), R(R){};
+  MarshallingInfo(const Record &R) : R(R) {}
 
   virtual ~MarshallingInfo() = default;
 
-  virtual void emit(raw_ostream &OS) const {
-write_cstring(OS, StringRef(getOptionSpelling(R)));
-OS << ", ";
-OS << ShouldAlwaysEmit;
-OS << ", ";
-OS << KeyPath;
-OS << ", ";
-emitScopedNormalizedValue(OS, DefaultValue);
-OS << ", ";
-OS << Normalizer;
-OS << ", ";
-OS << Denormalizer;
-OS << ", ";
-OS << ValueMerger;
+  virtual void
+  emitParsing(raw_ostream &OS,
+  llvm::function_ref
+  WriteOptRecordFields) const {
+if (!CanParse)
+  return;
+OS << "#ifdef " << MacroNameParsing << "\n";
+OS << MacroNameParsing << "(";
+WriteOptRecordFields(OS, R);
 OS << ", ";
-OS << ValueExtractor;
+emitParsingFields(OS);
+OS << ")\n";
+OS << "#endif // " << MacroNameParsing << "\n";
+  }
+
+  virtual void
+  emitSerialiazing(raw_ostream &OS,
+   llvm::function_ref
+   WriteOptRecordFields) const {
+OS << "#ifdef " << MacroNameSerializing << "\n";
+OS << MacroNameSerializing << "(";
+WriteOptRecordFields(OS, R);
 OS << ", ";
-OS << TableIndex;
+emitSerializingFields(OS);
+OS << ")\n";
+OS << "#endif // " << MacroNameSerializing << "\n";
   }
 
   Optional emitValueTable(raw_ostream &OS) const {
@@ -138,6 +146,35 @@
 return StringRef(ValueTableName);
   }
 
+protected:
+  void emitParsingFields(raw_ostream &OS) const {
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
+OS << Normalizer;
+OS << ", ";
+OS << ValueMerger;
+OS << ", ";
+OS << TableIndex;
+  }
+
+  void emitSerializingFields(raw_ostream &OS) const {
+OS << KeyPath;
+OS << ", ";
+emitScopedNormalizedValue(OS, DefaultValue);
+OS << ", ";
+write_cstring(OS, StringRef(getOptionSpelling(R)));
+OS << ", ";
+OS << ShouldAlwaysEmit;
+OS << ", ";
+OS << Denormalizer;
+OS << ", ";
+OS << ValueExtractor;
+OS << ", ";
+OS << TableIndex;
+  }
+
 private:
   void emitScopedNormalizedValue(raw_ostream &OS,
  StringRef NormalizedValue) const {
@@ -154,24 +191,45 @@
   const Record &NegOption;
 
   MarshallingInfoBooleanFlag(const Record &Option, const Record &NegOption)
-  : MarshallingInfo("OPTION_WITH_MARSHALLING_BOOLEAN", Option),
-NegOption(NegOption) {}
-
-  void emit(raw_ostream &OS) const override {
-MarshallingInfo::emit(OS);
+  : MarshallingInfo(Option), NegOption(NegOption) {}
+
+  void emitParsing(raw_ostream &OS,
+   llvm::function_ref
+   WriteOptRecordFields) const override {
+if (!CanParse)
+  return;
+OS << "#ifdef " << MacroNameParsing << "_BOOLEAN\n";
+OS << MacroNameParsing << "_BOOLEAN(";
+WriteOptRecordFields(OS, R);
+OS << ", ";
+emitParsingFields(OS);
 OS << ", ";
 OS << getOptionName(NegOption);
+OS << ")\n";
+OS << "#endif // " << MacroNameParsing << "_BOOLEAN\n";
+  }
+
+  void emitSerialiazing(raw_ostream &OS,
+llvm::function_ref
+WriteOptRecordFields) const override {
+OS << "#ifdef " << MacroNameSerializing << "_BOOLEAN\n";
+OS << MacroNameSerializing << "_BOOLEAN(";
+WriteOptRecordFields(OS, R);
+OS << ", ";
+emitSerializingFields(OS);
 OS << ", ";
 write_cstring(OS, getOptionSpelling(NegOption));
+OS << ")\n";
+OS << "#endif // " <

[PATCH] D82574: Merge TableGen files used for clang options

2020-07-09 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfccd29dddee9: Merge TableGen files used for clang options 
(authored by dang).

Changed prior to commit:
  https://reviews.llvm.org/D82574?vs=273407&id=276775#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82574

Files:
  clang/include/clang/Driver/CLCompatOptions.td
  clang/include/clang/Driver/Options.td

Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3434,6 +3434,1409 @@
 def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
   HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 1.2.1, sycl-1.2.1">;
 
-include "CC1Options.td"
+//===--===//
+// CC1 Options
+//===--===//
+
+let Flags = [CC1Option, NoDriverOption] in {
+
+//===--===//
+// Target Options
+//===--===//
+
+let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
+
+def target_cpu : Separate<["-"], "target-cpu">,
+  HelpText<"Target a specific cpu type">;
+def target_feature : Separate<["-"], "target-feature">,
+  HelpText<"Target specific attributes">;
+def triple : Separate<["-"], "triple">,
+  HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
+  MarshallingInfoString<"TargetOpts->Triple", "llvm::sys::getDefaultTargetTriple()", "std::string">,
+  AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;
+def target_abi : Separate<["-"], "target-abi">,
+  HelpText<"Target a particular ABI type">;
+def target_sdk_version_EQ : Joined<["-"], "target-sdk-version=">,
+  HelpText<"The version of target SDK used for compilation">;
+
+}
+
+def target_linker_version : Separate<["-"], "target-linker-version">,
+  HelpText<"Target linker version">;
+def triple_EQ : Joined<["-"], "triple=">, Alias;
+def mfpmath : Separate<["-"], "mfpmath">,
+  HelpText<"Which unit to use for fp math">;
+
+def fpadding_on_unsigned_fixed_point : Flag<["-"], "fpadding-on-unsigned-fixed-point">,
+  HelpText<"Force each unsigned fixed point type to have an extra bit of padding to align their scales with those of signed fixed point types">;
+def fno_padding_on_unsigned_fixed_point : Flag<["-"], "fno-padding-on-unsigned-fixed-point">;
+
+//===--===//
+// Analyzer Options
+//===--===//
+
+def analysis_UnoptimizedCFG : Flag<["-"], "unoptimized-cfg">,
+  HelpText<"Generate unoptimized CFGs for all analyses">;
+def analysis_CFGAddImplicitDtors : Flag<["-"], "cfg-add-implicit-dtors">,
+  HelpText<"Add C++ implicit destructors to CFGs for all analyses">;
+
+def analyzer_store : Separate<["-"], "analyzer-store">,
+  HelpText<"Source Code Analysis - Abstract Memory Store Models">;
+def analyzer_store_EQ : Joined<["-"], "analyzer-store=">, Alias;
+
+def analyzer_constraints : Separate<["-"], "analyzer-constraints">,
+  HelpText<"Source Code Analysis - Symbolic Constraint Engines">;
+def analyzer_constraints_EQ : Joined<["-"], "analyzer-constraints=">,
+  Alias;
+
+def analyzer_output : Separate<["-"], "analyzer-output">,
+  HelpText<"Source Code Analysis - Output Options">;
+def analyzer_output_EQ : Joined<["-"], "analyzer-output=">,
+  Alias;
+
+def analyzer_purge : Separate<["-"], "analyzer-purge">,
+  HelpText<"Source Code Analysis - Dead Symbol Removal Frequency">;
+def analyzer_purge_EQ : Joined<["-"], "analyzer-purge=">, Alias;
+
+def analyzer_opt_analyze_headers : Flag<["-"], "analyzer-opt-analyze-headers">,
+  HelpText<"Force the static analyzer to analyze functions defined in header files">;
+def analyzer_opt_analyze_nested_blocks : Flag<["-"], "analyzer-opt-analyze-nested-blocks">,
+  HelpText<"Analyze the definitions of blocks in addition to functions">;
+def analyzer_display_progress : Flag<["-"], "analyzer-display-progress">,
+  HelpText<"Emit verbose output about the analyzer's progress">;
+def analyze_function : Separate<["-"], "analyze-function">,
+  HelpText<"Run analysis on specific function (for C++ include parameters in name)">;
+def analyze_function_EQ : Joined<["-"], "analyze-function=">, Alias;
+def trim_egraph : Flag<["-"], "trim-egraph">,
+  HelpText<"Only show error-related paths in the analysis graph">;
+def analyzer_viz_egraph_graphviz : Flag<["-"], "analyzer-viz-egraph-graphviz">,
+  HelpText<"Display exploded graph using GraphViz">;
+def analyzer_dump_egraph : Separate<["-"], "analyzer-dump-egraph">,
+  HelpText<"Dump exploded graph to the speci

[PATCH] D82574: Merge TableGen files used for clang options

2020-07-09 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

Yes I committed this a while ago, I duplicated all the functionality in 
Options.td.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82574



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


[PATCH] D82874: Add diagnostic option backing field for -fansi-escape-codes

2020-07-09 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG50f24331fd91: Add diagnostic option backing field for 
-fansi-escape-codes (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82874

Files:
  clang/include/clang/Basic/DiagnosticOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1580,8 +1580,6 @@
   Opts.AbsolutePath = Args.hasArg(OPT_fdiagnostics_absolute_paths);
   Opts.ShowOptionNames = !Args.hasArg(OPT_fno_diagnostics_show_option);
 
-  llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes));
-
   // Default behavior is to not to show note include stacks.
   Opts.ShowNoteIncludeStack = false;
   if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
@@ -3724,6 +3722,10 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
+
+  llvm::sys::Process::UseANSIEscapeCodes(
+  Res.DiagnosticOpts->UseANSIEscapeCodes);
+
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -849,7 +849,8 @@
   Flags<[CoreOption, DriverOption]>;
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
-  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for 
diagnostics">;
+  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for 
diagnostics">,
+  MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes", "false">;
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">;
Index: clang/include/clang/Basic/DiagnosticOptions.def
===
--- clang/include/clang/Basic/DiagnosticOptions.def
+++ clang/include/clang/Basic/DiagnosticOptions.def
@@ -65,6 +65,7 @@
 ENUM_DIAGOPT(Format, TextDiagnosticFormat, 2, Clang) /// Format for 
diagnostics:
 
 DIAGOPT(ShowColors, 1, 0)   /// Show diagnostics with ANSI color sequences.
+DIAGOPT(UseANSIEscapeCodes, 1, 0)
 ENUM_DIAGOPT(ShowOverloads, OverloadsShown, 1,
  Ovl_All)/// Overload candidates to show.
 DIAGOPT(VerifyDiagnostics, 1, 0) /// Check that diagnostics match the expected


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1580,8 +1580,6 @@
   Opts.AbsolutePath = Args.hasArg(OPT_fdiagnostics_absolute_paths);
   Opts.ShowOptionNames = !Args.hasArg(OPT_fno_diagnostics_show_option);
 
-  llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes));
-
   // Default behavior is to not to show note include stacks.
   Opts.ShowNoteIncludeStack = false;
   if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
@@ -3724,6 +3722,10 @@
   }
 
   Success &= Res.parseSimpleArgs(Args, Diags);
+
+  llvm::sys::Process::UseANSIEscapeCodes(
+  Res.DiagnosticOpts->UseANSIEscapeCodes);
+
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
   Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -849,7 +849,8 @@
   Flags<[CoreOption, DriverOption]>;
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, Group;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
-  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for diagnostics">;
+  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for diagnostics">,
+  MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes", "false">;
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation comment block command">,
   MetaVarName<"">;
Index: clang/include/clang/Basic/DiagnosticOptions.def
===
--- clang/include/clang/Basic/Diag

[PATCH] D82574: Merge TableGen files used for clang options

2020-07-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3455
+  HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
+  MarshallingInfoString<"TargetOpts->Triple", 
"llvm::sys::getDefaultTargetTriple()", "std::string">,
+  AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;

herhut wrote:
> There is some explicit normalization missing here. In CC1Options.td this is
> 
> ```
> def triple : Separate<["-"], "triple">,
>   HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
>   MarshallingInfoString<"TargetOpts->Triple", 
> "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())", 
> "std::string">,
>   AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;
> ```
> 
> It seems the normalizer does not apply to the defaults and we now see a 
> failure in `clang/unittests/Frontend/CompilerInvocationTest.cpp` for powerpc 
> targets.
Of course, I must have lost it at some point. Can you link me to the failure 
for reference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82574



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


[PATCH] D82574: Merge TableGen files used for clang options

2020-07-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 2 inline comments as done.
dang added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3455
+  HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
+  MarshallingInfoString<"TargetOpts->Triple", 
"llvm::sys::getDefaultTargetTriple()", "std::string">,
+  AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;

dang wrote:
> herhut wrote:
> > There is some explicit normalization missing here. In CC1Options.td this is
> > 
> > ```
> > def triple : Separate<["-"], "triple">,
> >   HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
> >   MarshallingInfoString<"TargetOpts->Triple", 
> > "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())", 
> > "std::string">,
> >   AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;
> > ```
> > 
> > It seems the normalizer does not apply to the defaults and we now see a 
> > failure in `clang/unittests/Frontend/CompilerInvocationTest.cpp` for 
> > powerpc targets.
> Of course, I must have lost it at some point. Can you link me to the failure 
> for reference.
Done in 0555db0a5df4 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82574



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


[PATCH] D80952: [FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support.

2020-07-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.
Herald added a subscriber: dexonsmith.



Comment at: clang/include/clang/Driver/Options.td:1246
   HelpText<"Enables an experimental new pass manager in LLVM.">;
+def fexperimental_strict_floating_point : Flag<["-"], 
"fexperimental-strict-floating-point">,
+  Group, Flags<[CC1Option]>,

A bit late to the party, but can you mark this as 
`MarshallingInfoFlag<"LangOpts->ExpStrictFP", "false>` so that `if 
(Args.hasArg(OPT_fexperimental_strict_floating_point)) Opts.ExpStrictFP = 
true;` in CompilerInvocation.cpp gets generated automatically, we also get 
serializing the option for free this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80952



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


[PATCH] D80952: [FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support.

2020-07-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1246
   HelpText<"Enables an experimental new pass manager in LLVM.">;
+def fexperimental_strict_floating_point : Flag<["-"], 
"fexperimental-strict-floating-point">,
+  Group, Flags<[CC1Option]>,

kpn wrote:
> dang wrote:
> > A bit late to the party, but can you mark this as 
> > `MarshallingInfoFlag<"LangOpts->ExpStrictFP", "false>` so that `if 
> > (Args.hasArg(OPT_fexperimental_strict_floating_point)) Opts.ExpStrictFP = 
> > true;` in CompilerInvocation.cpp gets generated automatically, we also get 
> > serializing the option for free this way.
> Assuming this patch makes it to the afternoon, how about I open a new review 
> for this?
Sure no problem


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80952



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


[PATCH] D82574: Merge TableGen files used for clang options

2020-07-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

In D82574#2144140 , @jeroen.dobbelaere 
wrote:

> I think that 'clang/include/clang/Driver/CC1Options.td' should also be 
> removed ?


Yes must have missed it when rebasing. Done now in 3607aacc5981 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82574



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


[PATCH] D82574: Merge TableGen files used for clang options

2020-07-10 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

Sorry again, removed the offending options in a2cffb11e287 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82574



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


[PATCH] D83690: Port Migator option flags to new option parsing system

2020-07-13 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D83406 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83690

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -695,12 +695,6 @@
<< "a filename";
 }
 
-static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) {
-  Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error);
-  Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal);
-  return true;
-}
-
 static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) {
   Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands);
   Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments);
@@ -3740,7 +3734,6 @@
   FixupInvocation(Res);
 
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
-  Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
   if (!Res.getDependencyOutputOpts().OutputFile.empty() &&
   Res.getDependencyOutputOpts().Targets.empty()) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3637,10 +3637,12 @@
 // Migrator Options
 
//===--===//
 def migrator_no_nsalloc_error : Flag<["-"], "no-ns-alloc-error">,
-  HelpText<"Do not error on use of 
NSAllocateCollectable/NSReallocateCollectable">;
+  HelpText<"Do not error on use of 
NSAllocateCollectable/NSReallocateCollectable">,
+  MarshallingInfoFlag<"MigratorOpts.NoNSAllocReallocError", "false">;
 
 def migrator_no_finalize_removal : Flag<["-"], "no-finalize-removal">,
-  HelpText<"Do not remove finalize method in gc mode">;
+  HelpText<"Do not remove finalize method in gc mode">,
+  MarshallingInfoFlag<"MigratorOpts.NoFinalizeRemoval", "false">;
 
 
//===--===//
 // CodeGen Options


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -695,12 +695,6 @@
<< "a filename";
 }
 
-static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) {
-  Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error);
-  Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal);
-  return true;
-}
-
 static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) {
   Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands);
   Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments);
@@ -3740,7 +3734,6 @@
   FixupInvocation(Res);
 
   Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
-  Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args);
   if (!Res.getDependencyOutputOpts().OutputFile.empty() &&
   Res.getDependencyOutputOpts().Targets.empty()) {
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3637,10 +3637,12 @@
 // Migrator Options
 //===--===//
 def migrator_no_nsalloc_error : Flag<["-"], "no-ns-alloc-error">,
-  HelpText<"Do not error on use of NSAllocateCollectable/NSReallocateCollectable">;
+  HelpText<"Do not error on use of NSAllocateCollectable/NSReallocateCollectable">,
+  MarshallingInfoFlag<"MigratorOpts.NoNSAllocReallocError", "false">;
 
 def migrator_no_finalize_removal : Flag<["-"], "no-finalize-removal">,
-  HelpText<"Do not remove finalize method in gc mode">;
+  HelpText<"Do not remove finalize method in gc mode">,
+  MarshallingInfoFlag<"MigratorOpts.NoFinalizeRemoval", "false">;
 
 //===--===//
 // CodeGen Options
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83691: Port Comment option flags to new parsing system

2020-07-13 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Depends on D83690 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83691

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -697,7 +697,6 @@
 
 static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) {
   Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands);
-  Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments);
 }
 
 /// Create a new Regex instance out of the string value in \p RpassArg.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -385,6 +385,11 @@
 // Make sure all other -ccc- options are rejected.
 def ccc_ : Joined<["-"], "ccc-">, Group, Flags<[Unsupported]>;
 
+// Comment Options
+
+def fparse_all_comments : Flag<["-"], "fparse-all-comments">, 
Group, Flags<[CC1Option]>,
+  MarshallingInfoFlag<"LangOpts->CommentOpts.ParseAllComments", "false">;
+
 // Standard Options
 
 def _HASH_HASH_HASH : Flag<["-"], "###">, Flags<[DriverOption, CoreOption]>,
@@ -891,7 +896,6 @@
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">;
-def fparse_all_comments : Flag<["-"], "fparse-all-comments">, 
Group, Flags<[CC1Option]>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
   Group;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -697,7 +697,6 @@
 
 static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) {
   Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands);
-  Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments);
 }
 
 /// Create a new Regex instance out of the string value in \p RpassArg.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -385,6 +385,11 @@
 // Make sure all other -ccc- options are rejected.
 def ccc_ : Joined<["-"], "ccc-">, Group, Flags<[Unsupported]>;
 
+// Comment Options
+
+def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group, Flags<[CC1Option]>,
+  MarshallingInfoFlag<"LangOpts->CommentOpts.ParseAllComments", "false">;
+
 // Standard Options
 
 def _HASH_HASH_HASH : Flag<["-"], "###">, Flags<[DriverOption, CoreOption]>,
@@ -891,7 +896,6 @@
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation comment block command">,
   MetaVarName<"">;
-def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group, Flags<[CC1Option]>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
   Group;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >