[PATCH] D50815: Establish the header

2018-08-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka reopened this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

Reverted r339971 as it breaks sanitizer bots


https://reviews.llvm.org/D50815



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


[PATCH] D38525: Cleanup and generalize -shared-libasan.

2017-10-04 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In https://reviews.llvm.org/D38525#26, @rsmith wrote:

> Could we perhaps rename these flags to e.g. `-static-libsan` (with a 
> `-static-libasan` alias for compatibility)? It seems confusing that the way 
> to enable a static tsan runtime would be with `-static-libasan`.


I like this idea as well. If we go this way we need to deprecate 
"shared-libasan" and avoid adding "static-libasan.


https://reviews.llvm.org/D38525



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


[PATCH] D38525: Cleanup and generalize -shared-libasan.

2017-10-05 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:614
+  if (Arg *A = Args.getLastArg(options::OPT_shared_libsan,
+   options::OPT_static_libsan))
+SharedRuntime = A->getOption().matches(options::OPT_shared_libsan);

```
SharedRuntime = Args.hasFlag(options::OPT_shared_libsan,,
 options::OPT_static_libsan,
 TC.getTriple().isAndroid() || 
TC.getTriple().isOSFuchsia());
```



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:563
+if (SanArgs.needsUbsanRt()) {
+  if (SanArgs.requiresMinimalRuntime()) {
+SharedRuntimes.push_back("ubsan_minimal");

Shouldn't ubsan changes be in the separate patch?


https://reviews.llvm.org/D38525



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


[PATCH] D51049: Driver: Enable address-significance tables by default when targeting COFF.

2018-08-23 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

This breaks Windows bot
 
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/33846/steps/run%20check-asan/logs/stdio

  742542.065 [0/1/37] Running the AddressSanitizer tests
  -- Testing: 607 tests, 16 threads --
  Testing: 0 .. 10.. 20.. 30.. 40.. 50
  FAIL: AddressSanitizer-i386-windows :: TestCases/Windows/coverage-basic.cc 
(332 of 607)
   TEST 'AddressSanitizer-i386-windows :: 
TestCases/Windows/coverage-basic.cc' FAILED 
  Script:
  --
  : 'RUN: at line 1';   rm -rf 
C:\b\slave\sanitizer-windows\build\projects\compiler-rt\test\asan\I386WindowsConfig\TestCases\Windows\Output\coverage-basic.cc.tmp-dir
  : 'RUN: at line 2';   mkdir 
C:\b\slave\sanitizer-windows\build\projects\compiler-rt\test\asan\I386WindowsConfig\TestCases\Windows\Output\coverage-basic.cc.tmp-dir
 && cd 
C:\b\slave\sanitizer-windows\build\projects\compiler-rt\test\asan\I386WindowsConfig\TestCases\Windows\Output\coverage-basic.cc.tmp-dir
  : 'RUN: at line 3';  C:/b/slave/sanitizer-windows/build/./bin/clang.exe  
-fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer 
-fno-optimize-sibling-calls -gline-tables-only -gcodeview -gcolumn-info   
-fms-compatibility-version=19.00.24215.1  -fsanitize-coverage=func 
C:\b\slave\sanitizer-windows\llvm\projects\compiler-rt\test\asan\TestCases\Windows\coverage-basic.cc
 -o test.exe
  : 'RUN: at line 4';   env ASAN_OPTIONS=coverage=1  ./test.exe
  : 'RUN: at line 6';   C:/Python27/python.exe 
C:/b/slave/sanitizer-windows/llvm/projects/compiler-rt\lib\sanitizer_common\scripts\sancov.py
 print *.sancov | FileCheck 
C:\b\slave\sanitizer-windows\llvm\projects\compiler-rt\test\asan\TestCases\Windows\coverage-basic.cc
  --
  Exit Code: 1120
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "rm" "-rf" 
"C:\b\slave\sanitizer-windows\build\projects\compiler-rt\test\asan\I386WindowsConfig\TestCases\Windows\Output\coverage-basic.cc.tmp-dir"
  $ ":" "RUN: at line 2"
  $ "mkdir" 
"C:\b\slave\sanitizer-windows\build\projects\compiler-rt\test\asan\I386WindowsConfig\TestCases\Windows\Output\coverage-basic.cc.tmp-dir"
  $ ":" "RUN: at line 3"
  $ "C:/b/slave/sanitizer-windows/build/./bin/clang.exe" "-fsanitize=address" 
"-mno-omit-leaf-frame-pointer" "-fno-omit-frame-pointer" 
"-fno-optimize-sibling-calls" "-gline-tables-only" "-gcodeview" "-gcolumn-info" 
"-fms-compatibility-version=19.00.24215.1" "-fsanitize-coverage=func" 
"C:\b\slave\sanitizer-windows\llvm\projects\compiler-rt\test\asan\TestCases\Windows\coverage-basic.cc"
 "-o" "test.exe"
  # command output:
 Creating library test.lib and object test.exp
  
  coverage-basic-f4c01a.o : error LNK2001: unresolved external symbol 
___sanitizer_cov_trace_pc
  
  test.exe : fatal error LNK1120: 1 unresolved externals


Repository:
  rC Clang

https://reviews.llvm.org/D51049



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


[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-05 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 132876.
vitalybuka marked 3 inline comments as done.
vitalybuka added a comment.

empty file test


https://reviews.llvm.org/D42680

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+; RUN: wc -c < %t4.o | FileCheck %s --check-prefix=CHECK-SIZE
+; CHECK-SIZE: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,18 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm)
+  return {};
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule &BM : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions &HeaderOpts,
   const CodeGenOptions &CGOpts,
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc
+; RUN: wc -c < %t4.o | FileCheck %s --check-prefix=CHECK-SIZE
+; CHECK-SIZE: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,18 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule

[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-06 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 133111.
vitalybuka added a comment.

Create valid empty object file


https://reviews.llvm.org/D42680

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-SIZE
+; CHECK-SIZE: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,18 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm)
+  return llvm::make_unique("empty", *VMContext);
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule &BM : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions &HeaderOpts,
   const CodeGenOptions &CGOpts,
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-SIZE
+; CHECK-SIZE: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,18 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *

[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-06 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 133116.
vitalybuka added a comment.

set triple


https://reviews.llvm.org/D42680

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-SIZE-EMPTY
+; CHECK-SIZE-EMPTY: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,14 +947,26 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
+auto CreateEmptyModule = [&]() -> std::unique_ptr {
+  auto M = llvm::make_unique("empty", *VMContext);
+  M->setTargetTriple(CI.getTargetOpts().Triple);
+  return M;
+};
 
+Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm)
+  return llvm::make_unique("empty", *VMContext);
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
-  return DiagErrors(MOrErr.takeError());
+  return CreateEmptyModule();
 return std::move(*MOrErr);
   }
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule &BM : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions &HeaderOpts,
   const CodeGenOptions &CGOpts,
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-SIZE-EMPTY
+; CHECK-SIZE-EMPTY: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,14 +947,26 @@
   return {};
 };
 
-Expected BMOrErr =

[PATCH] D42995: [ThinLTO] Ignore object files with empty ThinLTO index

2018-02-06 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: pcc, tejohnson.
Herald added subscribers: eraman, inglorion, mehdi_amini.

Empty ThinLTOIndexFile signals that we don't need this module during
linking. So we should not run ThinLTO backend even if it contains the
ThinLTO module. Backend may fail because of lack of necessary
information which should be provided by ThinLTOIndex.


https://reviews.llvm.org/D42995

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -9,16 +9,14 @@
 ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed 
with '-x ir'
 
 ; Ensure we get expected error for missing index file
-; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 
| FileCheck %s -check-prefix=CHECK-ERROR1
+; RUN: not %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 
2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1
 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc'
 
 ; Ensure we ignore empty index file, and run non-ThinLTO compilation which
 ; would not import f2
 ; RUN: touch %t4.thinlto.bc
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t1.o -c 
-fthinlto-index=%t4.thinlto.bc
-; RUN: llvm-nm %t4.o | FileCheck --check-prefix=CHECK-OBJ-IGNORE-EMPTY %s
-; CHECK-OBJ-IGNORE-EMPTY: T f1
-; CHECK-OBJ-IGNORE-EMPTY: U f2
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-OBJ-EMPTY
 
 ; Ensure we don't fail with index and non-ThinLTO object file, and output must
 ; be empty file.
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -953,6 +953,21 @@
   return M;
 };
 
+sys::fs::file_status Status;
+if (auto E = sys::fs::status(CI.getCodeGenOpts().ThinLTOIndexFile, Status,
+ true)) {
+  return DiagErrors(make_error(
+  "Error loading index file '" + CI.getCodeGenOpts().ThinLTOIndexFile +
+  "'",
+  E));
+}
+// Empty ThinLTOIndexFile signals that we don't need this module during
+// linking. So we should not run ThinLTO backend even if it contains the
+// ThinLTO module. Backend even may fail because of lack of necessary
+// information which should be provided by ThinLTOIndex.
+if (!Status.getSize())
+  return CreateEmptyModule();
+
 Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
 if (!BMsOrErr)
   return DiagErrors(BMsOrErr.takeError());


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -9,16 +9,14 @@
 ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed with '-x ir'
 
 ; Ensure we get expected error for missing index file
-; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1
+; RUN: not %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR1
 ; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc'
 
 ; Ensure we ignore empty index file, and run non-ThinLTO compilation which
 ; would not import f2
 ; RUN: touch %t4.thinlto.bc
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=%t4.thinlto.bc
-; RUN: llvm-nm %t4.o | FileCheck --check-prefix=CHECK-OBJ-IGNORE-EMPTY %s
-; CHECK-OBJ-IGNORE-EMPTY: T f1
-; CHECK-OBJ-IGNORE-EMPTY: U f2
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-OBJ-EMPTY
 
 ; Ensure we don't fail with index and non-ThinLTO object file, and output must
 ; be empty file.
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -953,6 +953,21 @@
   return M;
 };
 
+sys::fs::file_status Status;
+if (auto E = sys::fs::status(CI.getCodeGenOpts().ThinLTOIndexFile, Status,
+ true)) {
+  return DiagErrors(make_error(
+  "Error loading index file '" + CI.getCodeGenOpts().ThinLTOIndexFile +
+  "'",
+  E));
+}
+// Empty ThinLTOIndexFile signals that we don't need this module during
+// linking. So we should not run ThinLTO backend even if it contains the
+// ThinLTO module. Backend even may fail because of lack of necessary
+// information which should be provided by ThinLTOIndex.
+if (!Status.getSize())
+  return CreateEmptyModule();
+
 Expected> BMsOrErr = getBitcodeModuleList(MBRef);
 if (!BMsOrErr)
   r

[PATCH] D42995: [ThinLTO] Ignore object files with empty ThinLTO index

2018-02-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In https://reviews.llvm.org/D42995#125, @tejohnson wrote:

> > Empty ThinLTOIndexFile signals that we don't need this module during
> >  linking.
>
> Not the only case actually. We now also pass an empty index file when we want 
> to compile the bitcode down to object without applying any LTO optimization 
> (there are a few cases where we decide we want to turn off LTO optimizations 
> for some links), and this is currently relying on being able to pass 
> /dev/null for the index file that would be broken by this change.


I'd expect this should be done by indexing and content is already in the merged 
object file.
Not sure how to reproduce this. I've build some large targets and I never seen 
this.

> 
> 
>> So we should not run ThinLTO backend even if it contains the
>>  ThinLTO module. Backend may fail because of lack of necessary
>>  information which should be provided by ThinLTOIndex.
> 
> This shouldn't happen - are you seeing cases where we fail? After 
> loadModule() is called, EmitBackendOutput() is called which passes 
> /*IgnoreEmptyThinLTOIndexFile*/true to  getModuleSummaryIndexForFile, which 
> would cause it to return nullptr if the index file is empty.  Back in 
> EmitBackendOutput(), if the combined index is null we will skip ThinLTO 
> compilation and fall back to normal compilation.

I don't see for regular compilation, but I see for  for CFI. Backend will not 
be able to process llvm.type.test without TypeIdMap from index and it will 
crash in "Instruction Select"


https://reviews.llvm.org/D42995



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


[PATCH] D42995: [ThinLTO] Ignore object files with empty ThinLTO index

2018-02-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In https://reviews.llvm.org/D42995#1000155, @vitalybuka wrote:

> In https://reviews.llvm.org/D42995#125, @tejohnson wrote:
>
> > > Empty ThinLTOIndexFile signals that we don't need this module during
> > >  linking.
> >
> > Not the only case actually. We now also pass an empty index file when we 
> > want to compile the bitcode down to object without applying any LTO 
> > optimization (there are a few cases where we decide we want to turn off LTO 
> > optimizations for some links), and this is currently relying on being able 
> > to pass /dev/null for the index file that would be broken by this change.
>
>
> I'd expect this should be done by indexing and content is already in the 
> merged object file.
>  Not sure how to reproduce this. I've build some large targets and I never 
> seen this.


At least with gold I don't see how this possible. I see that thinlto.bc can be 
empty only
if getSymbolsAndView returns nullptr or if LTOInfo for input object was false.
Former means that we don't need this object and so I created this patch.
For latter we already going to do the same anyway: 
https://reviews.llvm.org/D42680


https://reviews.llvm.org/D42995



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


[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

ping


https://reviews.llvm.org/D42680



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


[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 133966.
vitalybuka added a comment.

fix rebase issues introduced in the last patch


https://reviews.llvm.org/D42680

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-SIZE-EMPTY
+; CHECK-SIZE-EMPTY: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm) {
+  auto M = llvm::make_unique("empty", *VMContext);
+  M->setTargetTriple(CI.getTargetOpts().Triple);
+  return M;
+}
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule &BM : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions &HeaderOpts,
   const CodeGenOptions &CGOpts,
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,13 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | wc -l | FileCheck %s --check-prefix=CHECK-SIZE-EMPTY
+; CHECK-SIZE-EMPTY: {{^0$}}
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrE

[PATCH] D42995: [ThinLTO] Ignore object files with empty ThinLTO index

2018-02-13 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka planned changes to this revision.
vitalybuka added a comment.




https://reviews.llvm.org/D42995



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


[PATCH] D42611: [ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK

2018-02-14 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325182: [ThinLTO/CFI] Include TYPE_ID summaries into 
GLOBALVAL_SUMMARY_BLOCK (authored by vitalybuka, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42611?vs=134317&id=134320#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42611

Files:
  test/CMakeLists.txt
  test/CodeGen/thinlto-distributed-cfi-devirt.ll
  test/CodeGen/thinlto-distributed-cfi.ll
  test/CodeGen/thinlto-distributed.ll

Index: test/CodeGen/thinlto-distributed.ll
===
--- test/CodeGen/thinlto-distributed.ll
+++ test/CodeGen/thinlto-distributed.ll
@@ -0,0 +1,21 @@
+; REQUIRES: x86-registered-target
+
+; Trivial test for distributes ThinLTO
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN:   -o %t2.index \
+; RUN:   -r=%t.o,main,px
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
+; RUN:   -o %t.native.o -x ir %t.o
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+define i32 @main() {
+entry:
+  ret i32 0
+}
Index: test/CodeGen/thinlto-distributed-cfi-devirt.ll
===
--- test/CodeGen/thinlto-distributed-cfi-devirt.ll
+++ test/CodeGen/thinlto-distributed-cfi-devirt.ll
@@ -0,0 +1,101 @@
+; REQUIRES: x86-registered-target
+
+; Backend test for distribute ThinLTO with CFI.
+; It additionally enables -fwhole-program-vtables to get more information in
+; TYPE_IDs of GLOBALVAL_SUMMARY_BLOCK.
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN:   -o %t2.index \
+; RUN:   -r=%t.o,test,px \
+; RUN:   -r=%t.o,_ZN1A1nEi,p \
+; RUN:   -r=%t.o,_ZN1B1fEi,p \
+; RUN:   -r=%t.o,_ZN1C1fEi,p \
+; RUN:   -r=%t.o,_ZTV1B, \
+; RUN:   -r=%t.o,_ZTV1C, \
+; RUN:   -r=%t.o,_ZN1A1nEi, \
+; RUN:   -r=%t.o,_ZN1B1fEi, \
+; RUN:   -r=%t.o,_ZN1C1fEi, \
+; RUN:   -r=%t.o,_ZTV1B,px \
+; RUN:   -r=%t.o,_ZTV1C,px
+
+; Ensure that typeids are in the index.
+; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s
+; CHECK-LABEL: 
+; CHECK-LABEL: 
+; CHECK-LABEL: ___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42611: [ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK

2018-02-14 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325182: [ThinLTO/CFI] Include TYPE_ID summaries into 
GLOBALVAL_SUMMARY_BLOCK (authored by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42611?vs=134317&id=134321#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42611

Files:
  cfe/trunk/test/CMakeLists.txt
  cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll
  cfe/trunk/test/CodeGen/thinlto-distributed.ll
  llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
  llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
  llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

Index: llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
===
--- llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
+++ llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
@@ -671,7 +671,6 @@
 
   /// Mapping from type identifiers to summary information for that type
   /// identifier.
-  // FIXME: Add bitcode read/write support for this field.
   std::map TypeIdMap;
 
   /// Mapping from original ID to GUID. If original ID can map to multiple
Index: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
===
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
@@ -263,6 +263,11 @@
   FS_PERMODULE_RELBF = 19,
   // Index-wide flags
   FS_FLAGS = 20,
+  // Maps type identifier to summary information for that type identifier.
+  // TYPE_ID: [typeid, kind, bitwidth, align, size, bitmask, inlinebits,
+  //   n x (typeid, kind, name, numrba,
+  //numrba x (numarg, numarg x arg, kind, info, byte, bit))]
+  FS_TYPE_ID = 21,
 };
 
 enum MetadataCodes {
Index: llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
===
--- llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
+++ llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
@@ -22,8 +22,9 @@
 ; COMBINED:   
 ; COMBINED: 
+; COMBINED: 
 ; COMBINED:   
 
 ; COMBINED:   blob data = 'foobar'
+; COMBINED-NEXT:blob data = 'foobartypeid1'
 ; COMBINED-NEXT: 
Index: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5071,6 +5071,56 @@
   return Ret;
 }
 
+static void
+parseWholeProgramDevirtResolutionByArg(ArrayRef Record, size_t &Slot,
+   WholeProgramDevirtResolution &Wpd) {
+  uint64_t ArgNum = Record[Slot++];
+  WholeProgramDevirtResolution::ByArg &B =
+  Wpd.ResByArg[{Record.begin() + Slot, Record.begin() + Slot + ArgNum}];
+  Slot += ArgNum;
+
+  B.TheKind =
+  static_cast(Record[Slot++]);
+  B.Info = Record[Slot++];
+  B.Byte = Record[Slot++];
+  B.Bit = Record[Slot++];
+}
+
+static void parseWholeProgramDevirtResolution(ArrayRef Record,
+  StringRef Strtab, size_t &Slot,
+  TypeIdSummary &TypeId) {
+  uint64_t Id = Record[Slot++];
+  WholeProgramDevirtResolution &Wpd = TypeId.WPDRes[Id];
+
+  Wpd.TheKind = static_cast(Record[Slot++]);
+  Wpd.SingleImplName = {Strtab.data() + Record[Slot],
+static_cast(Record[Slot + 1])};
+  Slot += 2;
+
+  uint64_t ResByArgNum = Record[Slot++];
+  for (uint64_t I = 0; I != ResByArgNum; ++I)
+parseWholeProgramDevirtResolutionByArg(Record, Slot, Wpd);
+}
+
+static void parseTypeIdSummaryRecord(ArrayRef Record,
+ StringRef Strtab,
+ ModuleSummaryIndex &TheIndex) {
+  size_t Slot = 0;
+  TypeIdSummary &TypeId = TheIndex.getOrInsertTypeIdSummary(
+  {Strtab.data() + Record[Slot], static_cast(Record[Slot + 1])});
+  Slot += 2;
+
+  TypeId.TTRes.TheKind = static_cast(Record[Slot++]);
+  TypeId.TTRes.SizeM1BitWidth = Record[Slot++];
+  TypeId.TTRes.AlignLog2 = Record[Slot++];
+  TypeId.TTRes.SizeM1 = Record[Slot++];
+  TypeId.TTRes.BitMask = Record[Slot++];
+  TypeId.TTRes.InlineBits = Record[Slot++];
+
+  while (Slot < Record.size())
+parseWholeProgramDevirtResolution(Record, Strtab, Slot, TypeId);
+}
+
 // Eagerly parse the entire summary block. This populates the GlobalValueSummary
 // objects in the index.
 Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
@@ -5388,13 +5438,18 @@
 {Strtab.data() + Record[I], static_cast(Record[I + 1])});
   break;
 }
+
 case bitc::FS_CFI_FUNCTION_DECLS: {
   std::set &CfiFunctionDecls = TheIndex.cfiFunctionDecls();
   for (unsigned I = 0; I != Record.size(); I += 2)
 CfiFuncti

[PATCH] D42611: [ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK

2018-02-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll:59
+  ; Check that the call was devirtualized.
+  ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
+  %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, 
metadata !"_ZTS1A")

pcc wrote:
> Move this to before line 71.
done in r325184


Repository:
  rC Clang

https://reviews.llvm.org/D42611



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


[PATCH] D42995: [ThinLTO] Ignore object files with empty ThinLTO index

2018-02-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 134385.
vitalybuka added a comment.
Herald added a subscriber: hiraditya.

Don't use empty index file


https://reviews.llvm.org/D42995

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc
  clang/test/CodeGen/thinlto-distributed-backend-skip.ll
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
  llvm/tools/gold/gold-plugin.cpp

Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -811,9 +811,12 @@
 // final link. Frequently the distributed build system will want to
 // confirm that all expected outputs are created based on all of the
 // modules provided to the linker.
+// If SkipModule is true write empty .thinlto.bc with the flag which
+// request backend to skip corresponding object file.
 static void writeEmptyDistributedBuildOutputs(const std::string &ModulePath,
   const std::string &OldPrefix,
-  const std::string &NewPrefix) {
+  const std::string &NewPrefix,
+  bool Skip) {
   std::string NewModulePath =
   getThinLTOOutputFile(ModulePath, OldPrefix, NewPrefix);
   std::error_code EC;
@@ -823,6 +826,12 @@
 if (EC)
   message(LDPL_FATAL, "Failed to write '%s': %s",
   (NewModulePath + ".thinlto.bc").c_str(), EC.message().c_str());
+
+if (Skip) {
+  ModuleSummaryIndex Index(false);
+  Index.setSkipModule();
+  WriteIndexToFile(Index, OS, nullptr);
+}
   }
   if (options::thinlto_emit_imports_files) {
 raw_fd_ostream OS(NewModulePath + ".imports", EC,
@@ -878,6 +887,10 @@
 assert(ObjFilename.second);
 if (const void *View = getSymbolsAndView(F))
   addModule(*Lto, F, View, ObjFilename.first->first());
+else {
+  ObjFilename.first->second = true;
+  writeEmptyDistributedBuildOutputs(Identifier, OldPrefix, NewPrefix, true);
+}
   }
 
   SmallString<128> Filename;
@@ -920,7 +933,7 @@
 for (auto &Identifier : ObjectToIndexFileState)
   if (!Identifier.getValue())
 writeEmptyDistributedBuildOutputs(Identifier.getKey(), OldPrefix,
-  NewPrefix);
+  NewPrefix, false);
 
   if (options::TheOutputType == options::OT_DISABLE ||
   options::TheOutputType == options::OT_BC_ONLY)
Index: llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
===
--- llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
+++ llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
@@ -31,6 +31,22 @@
 ; RUN: ls %t2.o.imports
 ; RUN: ls %t3.o.imports
 
+; Regular *thinlto.bc file. "SkipModule" flags (0x2) should not be set.
+; RUN: llvm-bcanalyzer --dump %t1.o.thinlto.bc | FileCheck %s -check-prefixes=CHECK-BC1
+; CHECK-BC1: 
+; CHECK-BC1: 
+; CHECK-BC2: &1 | FileCheck %s -check-prefixes=CHECK-BC3
+; CHECK-BC3: LLVM ERROR: Unexpected end of file
+
 ; RUN: cat %t.index | FileCheck %s
 ; CHECK: thinlto_emit_linked_objects.ll.tmp1.o
 ; CHECK-NOT: thinlto_emit_linked_objects.ll.tmp2.o
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3604,10 +3604,13 @@
   Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3);
   Stream.EmitRecord(bitc::FS_VERSION, ArrayRef{INDEX_VERSION});
 
-  // Write the index flags. Currently we only write a single flag, the value of
-  // withGlobalValueDeadStripping, which only applies to the combined index.
-  Stream.EmitRecord(bitc::FS_FLAGS,
-ArrayRef{Index.withGlobalValueDeadStripping()});
+  // Write the index flags.
+  uint64_t Flags = 0;
+  if (Index.withGlobalValueDeadStripping())
+Flags |= 0x1;
+  if (Index.skipModule())
+Flags |= 0x2;
+  Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef{Flags});
 
   for (const auto &GVI : valueIds()) {
 Stream.EmitRecord(bitc::FS_VALUE_GUID,
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5186,11 +5186,14 @@
 case bitc::FS_FLAGS: {  // [flags]
   uint64_t Flags = Record[0];
   // Scan flags (set only on the combined index).
-  assert(Flags <= 1 && "Unexpected bits in flag");
+  assert(Flags <= 0x3 && "Unexpected bits in flag");
 
   // 1 bit: WithGlobalValueDeadStripping flag.
   if (Flags & 0x1)

[PATCH] D42995: [ThinLTO] Allow indexing to request backend to ignore the module

2018-02-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 134657.
vitalybuka marked 6 inline comments as done.
vitalybuka added a comment.

addressed comments


https://reviews.llvm.org/D42995

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc
  clang/test/CodeGen/thinlto-distributed-backend-skip.ll
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
  llvm/tools/gold/gold-plugin.cpp

Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -811,9 +811,14 @@
 // final link. Frequently the distributed build system will want to
 // confirm that all expected outputs are created based on all of the
 // modules provided to the linker.
+// If SkipModule is true then .thinlto.bc should contain just
+// SkipModuleByDistributedBackend flag which requests distributed backend
+// to skip the compilation of the corresponding module and produce an empty
+// object file.
 static void writeEmptyDistributedBuildOutputs(const std::string &ModulePath,
   const std::string &OldPrefix,
-  const std::string &NewPrefix) {
+  const std::string &NewPrefix,
+  bool SkipModule) {
   std::string NewModulePath =
   getThinLTOOutputFile(ModulePath, OldPrefix, NewPrefix);
   std::error_code EC;
@@ -823,6 +828,12 @@
 if (EC)
   message(LDPL_FATAL, "Failed to write '%s': %s",
   (NewModulePath + ".thinlto.bc").c_str(), EC.message().c_str());
+
+if (SkipModule) {
+  ModuleSummaryIndex Index(false);
+  Index.setSkipModuleByDistributedBackend();
+  WriteIndexToFile(Index, OS, nullptr);
+}
   }
   if (options::thinlto_emit_imports_files) {
 raw_fd_ostream OS(NewModulePath + ".imports", EC,
@@ -878,6 +889,11 @@
 assert(ObjFilename.second);
 if (const void *View = getSymbolsAndView(F))
   addModule(*Lto, F, View, ObjFilename.first->first());
+else if (options::thinlto_index_only) {
+  ObjFilename.first->second = true;
+  writeEmptyDistributedBuildOutputs(Identifier, OldPrefix, NewPrefix,
+/* SkipModule */ true);
+}
   }
 
   SmallString<128> Filename;
@@ -895,7 +911,7 @@
   auto AddStream =
   [&](size_t Task) -> std::unique_ptr {
 IsTemporary[Task] = !SaveTemps;
-int FD = getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps,
+int FD = getOutputFileName(Filename, /* TempOutFile */ !SaveTemps,
Filenames[Task], Task);
 return llvm::make_unique(
 llvm::make_unique(FD, true));
@@ -920,7 +936,7 @@
 for (auto &Identifier : ObjectToIndexFileState)
   if (!Identifier.getValue())
 writeEmptyDistributedBuildOutputs(Identifier.getKey(), OldPrefix,
-  NewPrefix);
+  NewPrefix, /* SkipModule */ false);
 
   if (options::TheOutputType == options::OT_DISABLE ||
   options::TheOutputType == options::OT_BC_ONLY)
Index: llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
===
--- llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
+++ llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
@@ -31,6 +31,24 @@
 ; RUN: ls %t2.o.imports
 ; RUN: ls %t3.o.imports
 
+; Regular *thinlto.bc file. "SkipModuleByDistributedBackend" flag (0x2)
+; should not be set.
+; RUN: llvm-bcanalyzer --dump %t1.o.thinlto.bc | FileCheck %s -check-prefixes=CHECK-BC1
+; CHECK-BC1: 
+; CHECK-BC1: 
+; CHECK-BC2: &1 | FileCheck %s -check-prefixes=CHECK-BC3
+; CHECK-BC3: LLVM ERROR: Unexpected end of file
+
 ; RUN: cat %t.index | FileCheck %s
 ; CHECK: thinlto_emit_linked_objects.ll.tmp1.o
 ; CHECK-NOT: thinlto_emit_linked_objects.ll.tmp2.o
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3604,10 +3604,13 @@
   Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3);
   Stream.EmitRecord(bitc::FS_VERSION, ArrayRef{INDEX_VERSION});
 
-  // Write the index flags. Currently we only write a single flag, the value of
-  // withGlobalValueDeadStripping, which only applies to the combined index.
-  Stream.EmitRecord(bitc::FS_FLAGS,
-ArrayRef{Index.withGlobalValueDeadStripping()});
+  // Write the index flags.
+  uint64_t Flags = 0;
+  if (Index.withGlobalValueDeadStripping())
+Flags |= 0x1;
+  if (Index.skipModuleByDistributedBackend())
+Flags |= 0x2;
+  Stream.EmitRecord(b

[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

@pcc Could you please take a look?


https://reviews.llvm.org/D42680



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


[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 134752.
vitalybuka marked an inline comment as done.
vitalybuka added a comment.

use count 0


https://reviews.llvm.org/D42680

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,12 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | count 0
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm) {
+  auto M = llvm::make_unique("empty", *VMContext);
+  M->setTargetTriple(CI.getTargetOpts().Triple);
+  return M;
+}
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule &BM : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions &HeaderOpts,
   const CodeGenOptions &CGOpts,
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,12 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | count 0
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTO

[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-16 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325410: [ThinLTO] Ignore object files with no ThinLTO 
modules if -fthinlto-index= is set (authored by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42680?vs=134752&id=134753#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42680

Files:
  include/clang/CodeGen/BackendUtil.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenAction.cpp
  test/CodeGen/thinlto_backend.ll


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm) {
+  auto M = llvm::make_unique("empty", *VMContext);
+  M->setTargetTriple(CI.getTargetOpts().Triple);
+  return M;
+}
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule &BM : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions &HeaderOpts,
   const CodeGenOptions &CGOpts,
Index: include/clang/CodeGen/BackendUtil.h
===
--- include/clang/CodeGen/BackendUtil.h
+++ include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif
Index: test/CodeGen/thinlto_backend.ll
===
--- test/CodeGen/thinlto_backend.ll
+++ test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,12 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | count 0
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s


Index: lib/CodeGen/CodeGenAction.cpp
===
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm) {
+  auto M = llvm::make_unique("empty", *VMContext);
+  M->setTargetTriple(CI.getTargetOpts().Triple);
+  return M;
+}
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: lib

[PATCH] D42680: [ThinLTO] Ignore object files with no ThinLTO modules if -fthinlto-index= is set

2018-02-16 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325410: [ThinLTO] Ignore object files with no ThinLTO 
modules if -fthinlto-index= is set (authored by vitalybuka, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42680?vs=134752&id=134754#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42680

Files:
  cfe/trunk/include/clang/CodeGen/BackendUtil.h
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/CodeGen/CodeGenAction.cpp
  cfe/trunk/test/CodeGen/thinlto_backend.ll


Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = 
getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm) {
+  auto M = llvm::make_unique("empty", *VMContext);
+  M->setTargetTriple(CI.getTargetOpts().Triple);
+  return M;
+}
 Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
+Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
 return std::move(*MOrErr);
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -1025,16 +1025,22 @@
 
   // The bitcode file may contain multiple modules, we want the one that is
   // marked as being the ThinLTO module.
-  for (BitcodeModule &BM : *BMsOrErr) {
-Expected LTOInfo = BM.getLTOInfo();
-if (LTOInfo && LTOInfo->IsThinLTO)
-  return BM;
-  }
+  if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr))
+return *Bm;
 
   return make_error("Could not find module summary",
  inconvertibleErrorCode());
 }
 
+BitcodeModule *clang::FindThinLTOModule(MutableArrayRef BMs) {
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
+}
+
 static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
   const HeaderSearchOptions &HeaderOpts,
   const CodeGenOptions &CGOpts,
Index: cfe/trunk/include/clang/CodeGen/BackendUtil.h
===
--- cfe/trunk/include/clang/CodeGen/BackendUtil.h
+++ cfe/trunk/include/clang/CodeGen/BackendUtil.h
@@ -49,6 +49,8 @@
 
   llvm::Expected
   FindThinLTOModule(llvm::MemoryBufferRef MBRef);
+  llvm::BitcodeModule *
+  FindThinLTOModule(llvm::MutableArrayRef BMs);
 }
 
 #endif
Index: cfe/trunk/test/CodeGen/thinlto_backend.ll
===
--- cfe/trunk/test/CodeGen/thinlto_backend.ll
+++ cfe/trunk/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,12 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and output must
+; be empty file.
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+; RUN: llvm-nm %t4.o | count 0
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s


Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp
@@ -947,12 +947,21 @@
   return {};
 };
 
-Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
+Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+if (!BMsOrErr)
+  return DiagErrors(BMsOrErr.takeError());
+BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
+// We have nothing to do if the file contains no ThinLTO module. This is
+// possible if ThinLTO compilation was not able to split module. Content of
+// the file was already processed by indexing and will be passed to the
+// linker using merged object file.
+if (!Bm) {
+  auto M = llvm::make_unique("empty", *VMContext);
+  M->setTargetTriple(CI.getTargetOpts().Triple);
+   

[PATCH] D42995: [ThinLTO] Allow indexing to request backend to ignore the module

2018-02-16 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325411: [ThinLTO] Allow indexing to request backend to 
ignore the module (authored by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42995?vs=134657&id=134755#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42995

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc
  test/CodeGen/thinlto-distributed-backend-skip.ll


Index: test/CodeGen/thinlto-distributed-backend-skip.ll
===
--- test/CodeGen/thinlto-distributed-backend-skip.ll
+++ test/CodeGen/thinlto-distributed-backend-skip.ll
@@ -0,0 +1,21 @@
+; REQUIRES: x86-registered-target
+
+; Check that ThinLTO backend respects "SkipModuleByDistributedBackend"
+; flag which can be set by indexing.
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -fthinlto-index=%S/Inputs/thinlto-distributed-backend-skip.bc \
+; RUN:   -emit-llvm -o - -x ir %t.o | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+; CHECK: "empty"
+; CHECK: target triple =
+; CHECK-NOT: @main
+define i32 @main() {
+entry:
+  ret i32 0
+}
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1153,6 +1153,7 @@
   const llvm::DataLayout &TDesc, Module *M,
   BackendAction Action,
   std::unique_ptr OS) {
+  std::unique_ptr EmptyModule;
   if (!CGOpts.ThinLTOIndexFile.empty()) {
 // If we are performing a ThinLTO importing compile, load the function 
index
 // into memory and pass it into runThinLTOBackend, which will run the
@@ -1170,11 +1171,22 @@
 // A null CombinedIndex means we should skip ThinLTO compilation
 // (LLVM will optionally ignore empty index files, returning null instead
 // of an error).
-bool DoThinLTOBackend = CombinedIndex != nullptr;
-if (DoThinLTOBackend) {
-  runThinLTOBackend(CombinedIndex.get(), M, HeaderOpts, CGOpts, TOpts,
-LOpts, std::move(OS), CGOpts.SampleProfileFile, 
Action);
-  return;
+if (CombinedIndex) {
+  if (!CombinedIndex->skipModuleByDistributedBackend()) {
+runThinLTOBackend(CombinedIndex.get(), M, HeaderOpts, CGOpts, TOpts,
+  LOpts, std::move(OS), CGOpts.SampleProfileFile,
+  Action);
+return;
+  }
+  // Distributed indexing detected that nothing from the module is needed
+  // for the final linking. So we can skip the compilation. We sill need to
+  // output an empty object file to make sure that a linker does not fail
+  // trying to read it. Also for some features, like CFI, we must skip
+  // the compilation as CombinedIndex does not contain all required
+  // information.
+  EmptyModule = llvm::make_unique("empty", M->getContext());
+  EmptyModule->setTargetTriple(M->getTargetTriple());
+  M = EmptyModule.get();
 }
   }
 


Index: test/CodeGen/thinlto-distributed-backend-skip.ll
===
--- test/CodeGen/thinlto-distributed-backend-skip.ll
+++ test/CodeGen/thinlto-distributed-backend-skip.ll
@@ -0,0 +1,21 @@
+; REQUIRES: x86-registered-target
+
+; Check that ThinLTO backend respects "SkipModuleByDistributedBackend"
+; flag which can be set by indexing.
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -fthinlto-index=%S/Inputs/thinlto-distributed-backend-skip.bc \
+; RUN:   -emit-llvm -o - -x ir %t.o | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+; CHECK: "empty"
+; CHECK: target triple =
+; CHECK-NOT: @main
+define i32 @main() {
+entry:
+  ret i32 0
+}
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1153,6 +1153,7 @@
   const llvm::DataLayout &TDesc, Module *M,
   BackendAction Action,
   std::unique_ptr OS) {
+  std::unique_ptr EmptyModule;
   if (!CGOpts.ThinLTOIndexFile.empty()) {
 // If we are performing a ThinLTO importing compile, load the function index
 // into memory and pass it into runThinLTOBackend, which will run the
@@ -1170,11 +1171,22 @@
 // A null CombinedIndex means we should skip ThinLTO compilation
 // (LLVM will optionally ignore empty index files, returning null instead
 // of an error).
-bool DoThinLTOBackend = CombinedIndex != nullptr;
-if (DoThinLTOBackend) {
-  runThinLTOBacke

[PATCH] D43423: [SimplifyCFG] Create flag to disable simplifyCFG.

2018-02-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:109
 
 static cl::opt MergeCondStores(
 "simplifycfg-merge-cond-stores", cl::Hidden, cl::init(true),

why metadata instead of cl:opt like these?


https://reviews.llvm.org/D43423



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


[PATCH] D43423: [SimplifyCFG] Create flag to disable simplifyCFG.

2018-02-21 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6056
SmallPtrSetImpl *LoopHeaders) {
+  const Function *Fn = BB->getParent();
+  if (Fn && Fn->getMetadata("no_simplify_cfg"))

So maybe Attribute::SanitizeFuzzer for each function with --fsanitizer=fuzzer 
and then

```
if (... getFunction()->hasFnAttribute(Attribute::SanitizeFuzzer))
return;
```


https://reviews.llvm.org/D43423



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


[PATCH] D43606: [Driver] Add SafeStack to a map of incompatible sanitizers

2018-02-25 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:384
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};

I guess we check only one direction.
E.g. we have std::make_pair(Address, Thread but no std::make_pair(Thread, 
Address

So either this line or changes above are not needed.



Repository:
  rC Clang

https://reviews.llvm.org/D43606



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-25 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: test/asan/TestCases/intercept-rethrow-exception.cc:48
+  // memcpy is intercepted by asan which performs checks on src and dst
+  using T = int[1000];
+  T x {};

You can include #include 
and use __asan_region_is_poisoned


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: test/asan/TestCases/intercept-rethrow-exception.cc:48
+  // memcpy is intercepted by asan which performs checks on src and dst
+  using T = int[1000];
+  T x {};

robot wrote:
> vitalybuka wrote:
> > You can include #include 
> > and use __asan_region_is_poisoned
> We don't have commit rights, can you commit it? Should we first change to 
> `__asan_region_is_poisoned` and kill the program if it is indeed poisoined?
Sure, I'll update and commit this for you.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-26 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT326132: [asan] Intercept std::rethrow_exception indirectly 
(authored by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42644?vs=132990&id=135965#toc

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644

Files:
  lib/asan/asan_interceptors.cc
  lib/asan/asan_interceptors.h
  test/asan/TestCases/intercept-rethrow-exception.cc

Index: test/asan/TestCases/intercept-rethrow-exception.cc
===
--- test/asan/TestCases/intercept-rethrow-exception.cc
+++ test/asan/TestCases/intercept-rethrow-exception.cc
@@ -0,0 +1,64 @@
+// Regression test for
+// https://bugs.llvm.org/show_bug.cgi?id=32434
+
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: %run %t
+
+#include 
+#include 
+#include 
+
+namespace {
+
+// Not instrumented because std::rethrow_exception is a [[noreturn]] function,
+// for which the compiler would emit a call to __asan_handle_no_return which
+// unpoisons the stack.
+// We emulate here some code not compiled with asan. This function is not
+// [[noreturn]] because the scenario we're emulating doesn't always throw. If it
+// were [[noreturn]], the calling code would emit a call to
+// __asan_handle_no_return.
+void __attribute__((no_sanitize("address")))
+uninstrumented_rethrow_exception(std::exception_ptr const &exc_ptr) {
+  std::rethrow_exception(exc_ptr);
+}
+
+char *poisoned1;
+char *poisoned2;
+
+// Create redzones for stack variables in shadow memory and call
+// std::rethrow_exception which should unpoison the entire stack.
+void create_redzones_and_throw(std::exception_ptr const &exc_ptr) {
+  char a[100];
+  poisoned1 = a - 1;
+  poisoned2 = a + sizeof(a);
+  assert(__asan_address_is_poisoned(poisoned1));
+  assert(__asan_address_is_poisoned(poisoned2));
+  uninstrumented_rethrow_exception(exc_ptr);
+}
+
+} // namespace
+
+// Check that std::rethrow_exception is intercepted by asan and the interception
+// unpoisons the stack.
+// If std::rethrow_exception is NOT intercepted, then calls to this function
+// from instrumented code will still unpoison the stack because
+// std::rethrow_exception is a [[noreturn]] function and any [[noreturn]]
+// function call will be instrumented with __asan_handle_no_return.
+// However, calls to std::rethrow_exception from UNinstrumented code will not
+// unpoison the stack, so we need to intercept std::rethrow_exception to
+// unpoison the stack.
+int main() {
+  // In some implementations of std::make_exception_ptr, e.g. libstdc++ prior to
+  // gcc 7, this function calls __cxa_throw. The __cxa_throw is intercepted by
+  // asan to unpoison the entire stack; since this test essentially tests that
+  // the stack is unpoisoned by a call to std::rethrow_exception, we need to
+  // generate the exception_ptr BEFORE we have the local variables poison the
+  // stack.
+  std::exception_ptr my_exception_ptr = std::make_exception_ptr("up");
+
+  try {
+create_redzones_and_throw(my_exception_ptr);
+  } catch(char const *) {
+assert(!__asan_region_is_poisoned(poisoned1, poisoned2 - poisoned1 + 1));
+  }
+}
Index: lib/asan/asan_interceptors.cc
===
--- lib/asan/asan_interceptors.cc
+++ lib/asan/asan_interceptors.cc
@@ -33,6 +33,11 @@
 #include "sanitizer_common/sanitizer_posix.h"
 #endif
 
+#if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION || \
+ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
+#include 
+#endif
+
 #if defined(__i386) && SANITIZER_LINUX
 #define ASAN_PTHREAD_CREATE_VERSION "GLIBC_2.1"
 #elif defined(__mips__) && SANITIZER_LINUX
@@ -319,6 +324,32 @@
 }
 #endif
 
+#if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
+INTERCEPTOR(void, __cxa_rethrow_primary_exception, void *a) {
+  CHECK(REAL(__cxa_rethrow_primary_exception));
+  __asan_handle_no_return();
+  REAL(__cxa_rethrow_primary_exception)(a);
+}
+#endif
+
+#if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION
+INTERCEPTOR(_Unwind_Reason_Code, _Unwind_RaiseException,
+struct _Unwind_Exception *object) {
+  CHECK(REAL(_Unwind_RaiseException));
+  __asan_handle_no_return();
+  return REAL(_Unwind_RaiseException)(object);
+}
+#endif
+
+#if ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
+INTERCEPTOR(_Unwind_Reason_Code, _Unwind_SjLj_RaiseException,
+struct _Unwind_Exception *object) {
+  CHECK(REAL(_Unwind_SjLj_RaiseException));
+  __asan_handle_no_return();
+  return REAL(_Unwind_SjLj_RaiseException)(object);
+}
+#endif
+
 #if ASAN_INTERCEPT_INDEX
 # if ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
 INTERCEPTOR(char*, index, const char *string, int c)
@@ -599,6 +630,17 @@
 #if ASAN_INTERCEPT___CXA_THROW
   ASAN_INTERCEPT_FUNC(__cxa_throw);
 #endif
+#if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
+  ASAN_INTERCEPT_FUNC(__cxa_rethrow_primary_exception);
+#endif
+  // Indirectly intercept std::rethrow_exception.
+#if ASAN_INTERCEPT__UNWIND_R

[PATCH] D41103: [CMake] Allow passing extra CMake arguments to custom libc++

2017-12-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Can you please add some details about why someone wants to customize LIBXX here?
Or even better attach a patch which uses this.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D41103



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


[PATCH] D43423: [SimplifyCFG] Create flag to disable simplifyCFG.

2018-03-02 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added a comment.
This revision now requires changes to proceed.

I assume this is going to be abandoned in favor of 
https://reviews.llvm.org/D44057


https://reviews.llvm.org/D43423



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


[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-05 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:369
   // Check that LTO is enabled if we need it.
   if ((Kinds & NeedsLTO) && !D.isUsingLTO()) {
 D.Diag(diag::err_drv_argument_only_allowed_with)

Is this change needed to avoid errors at "Kinds & NeedsLTO" and KindsToDiagnose?
Could you create a test for this change?


Repository:
  rC Clang

https://reviews.llvm.org/D44064



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


[PATCH] D47665: Refactored clang-fuzzer in preparation for adding new loop-proto-fuzzer

2018-06-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: tools/clang-fuzzer/CMakeLists.txt:17
   ExampleClangProtoFuzzer.cpp
+  FuzzerInitialize.cpp
   )

this file is missing



Comment at: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp:29
 
+/*
 static std::vector CLArgs;

don't keep dead code



Comment at: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp:26
 std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::ProtoToCxx(
-reinterpret_cast(str.data()), str.size());
+//std::cout << clang_fuzzer::ProtoToCxx(
+//reinterpret_cast(str.data()), str.size());

Probably some debug changes?


Repository:
  rC Clang

https://reviews.llvm.org/D47665



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Good practice is to avoid merging changes into a single one.
Here one patch should be "refactoring" and the second for "loop-proto-fuzzer."




Comment at: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp:29
+/*
 static std::vector CLArgs;
 

Please delete commented code.



Comment at: tools/clang-fuzzer/FuzzerInitialize.h:11
+
+static std::vector CLArgs;
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv);

static here means that each module which includes this header is going to have 
own instance of the variable.
I guess you need only one instance in FuzzerInitialize.cpp which can be 
achieved with 
```
extern std::vector CLArgs;

```

However I'd recommend getter:

```
const std::vector& GetCLArgs();
```
with implementation and 
```
static std::vector CLArgs;
```
in FuzzerInitialize.cpp



Comment at: tools/clang-fuzzer/FuzzerInitialize.h:12
+static std::vector CLArgs;
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv);
+

you need only CLArgs here.
code which includes this header is not going to call LLVMFuzzerInitialize



Comment at: tools/clang-fuzzer/experimental/ExampleClangLoopProtoFuzzer.cpp:30
 
+/*
 static std::vector CLArgs;

Please remove deleted code


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In https://reviews.llvm.org/D47666#1119821, @vitalybuka wrote:

> Good practice is to avoid merging changes into a single one.
>  Here one patch should be "refactoring" and the second for 
> "loop-proto-fuzzer."


We are doing this for several reasons:

1. smaller patches, faster review
2. easier to investigate regressions caused by smaller patches


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added inline comments.
This revision now requires changes to proceed.



Comment at: tools/clang-fuzzer/FuzzerInitialize.cpp:11
 /// \file
 /// This file implements a function that runs Clang on a single
 ///  input and uses libprotobuf-mutator to find new inputs. This function is

Could you please update this description?



Comment at: tools/clang-fuzzer/experimental/ExampleClangLoopProtoFuzzer.cpp:22
+
+#include "FuzzerInitialize.h"
 

Please move ExampleClangLoopProtoFuzzer into a separate patch


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-06 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added inline comments.
This revision now requires changes to proceed.



Comment at: tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp:23
+
+namespace clang_fuzzer {
+

I guess you already committed this patch.
Could you please try rebase to upstream, e.g. "git pull -r" and re-upload the 
review



Repository:
  rC Clang

https://reviews.llvm.org/D47843



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


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 150380.
vitalybuka added a comment.

git clang-format -f --style=file HEAD^


Repository:
  rC Clang

https://reviews.llvm.org/D47843

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h

Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function &input);
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction &input);
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,32 @@
+//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {
+std::fstream in(argv[i]);
+std::string str((std::istreambuf_iterator(in)),
+std::istreambuf_iterator());
+std::cout << "// " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,148 @@
+//==-- loop_proto_to_cxx.cpp - Protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and C++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#include "cxx_loop_proto.pb.h"
+#include "proto_to_cxx.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls.
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x);
+std::ostream &operator<<(std::ostream &os, const StatementSeq &x);
+
+// Proto to C++.
+std::ostream &operator<<(std::ostream &os, const Const &x) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream &operator<<(std::ostream &os, const VarRef &x) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+return os << "a[" << static_cast(x.varnum()) << " % s]";
+  }
+}
+std::ostream &operator<<(std::ostream &os, const Lvalue &x) {
+  return os << x.varref();
+}
+std::ostream &operator<<(std::ostream &os, const Rvalue &x) {
+  if (x.has_varref())
+return os << x.varref();
+  if (x.has_cons())
+return os << x.cons();
+  if (x.has_binop())
+return os << x.binop();
+  return os << "1";
+}
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x) {
+  os << "(" << x.left();
+  switch (x.op()) {
+  case BinaryOp::PLUS:
+os << "+";
+break;
+  case BinaryOp::MINUS:
+os << "-";
+break;
+  case BinaryOp::MUL:
+os << "*";
+break;
+  case BinaryOp::DIV:
+os << "/";
+break;
+  case BinaryOp::MOD:
+os << "%";
+break;
+  case BinaryOp::XOR:
+os << "^";
+break;
+  case BinaryOp::AND:
+os << "&";
+break;
+  case BinaryOp::OR:
+os << "|";
+break;
+  case BinaryOp::EQ:
+os << "==";
+break;
+  case BinaryOp::NE:
+os << "!=";
+break;
+  case BinaryOp::LE:
+os << "<=";
+break;
+  case BinaryOp::GE:
+os << ">=";
+break;
+  

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334216: Introducing single for loop into clang_proto_fuzzer 
(authored by vitalybuka, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D47843

Files:
  cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
  cfe/trunk/tools/clang-fuzzer/cxx_loop_proto.proto
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h

Index: cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
===
--- cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
+++ cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
@@ -0,0 +1,30 @@
+//===-- ExampleClangLoopProtoFuzzer.cpp - Fuzz Clang --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+///  This file implements a function that runs Clang on a single
+///  input and uses libprotobuf-mutator to find new inputs. This function is
+///  then linked into the Fuzzer library. This file differs from
+///  ExampleClangProtoFuzzer in that it uses the new protobuf that includes
+///  C++ code with a single for loop.
+///
+//===--===//
+
+#include "cxx_loop_proto.pb.h"
+#include "fuzzer-initialize/fuzzer_initialize.h"
+#include "handle-cxx/handle_cxx.h"
+#include "proto-to-cxx/proto_to_cxx.h"
+#include "src/libfuzzer/libfuzzer_macro.h"
+
+using namespace clang_fuzzer;
+
+DEFINE_BINARY_PROTO_FUZZER(const LoopFunction &input) {
+  auto S = LoopFunctionToString(input);
+  HandleCXX(S, GetCLArgs());
+}
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function &input);
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction &input);
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
@@ -2,12 +2,21 @@
 set(CMAKE_CXX_FLAGS ${CXX_FLAGS_NOFUZZ})
 
 # Needed by LLVM's CMake checks because this file defines multiple targets.
-set(LLVM_OPTIONAL_SOURCES proto_to_cxx.cpp proto_to_cxx_main.cpp)
+set(LLVM_OPTIONAL_SOURCES proto_to_cxx.cpp proto_to_cxx_main.cpp
+  loop_proto_to_cxx.cpp loop_proto_to_cxx_main.cpp)
 
 add_clang_library(clangProtoToCXX proto_to_cxx.cpp
   DEPENDS clangCXXProto
   LINK_LIBS clangCXXProto ${PROTOBUF_LIBRARIES}
   )
 
+add_clang_library(clangLoopProtoToCXX loop_proto_to_cxx.cpp
+  DEPENDS clangCXXLoopProto
+  LINK_LIBS clangCXXLoopProto ${PROTOBUF_LIBRARIES}
+  )
+
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
+add_clang_executable(clang-loop-proto-to-cxx loop_proto_to_cxx_main.cpp)
+
 target_link_libraries(clang-proto-to-cxx PRIVATE clangProtoToCXX)
+target_link_libraries(clang-loop-proto-to-cxx PRIVATE clangLoopProtoToCXX)
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,32 @@
+//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {

[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-06-13 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Is this stale?


Repository:
  rC Clang

https://reviews.llvm.org/D42043



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


[PATCH] D60807: Test for Oz fail

2019-04-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

-Oz builds are usually significantly large than -Os build


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60807

Files:
  clang/test/CodeGen/oz.cpp




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


[PATCH] D60485: [AArch64] Add support for MTE intrinsics

2019-04-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

fixed with r359366


Repository:
  rC Clang

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

https://reviews.llvm.org/D60485



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


[PATCH] D60485: [AArch64] Add support for MTE intrinsics

2019-04-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added subscribers: hctim, vitalybuka.
vitalybuka added a comment.

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan/builds/12035

  -- Testing: 14692 tests, 96 threads --
  Testing: 
  FAIL: Clang :: AST/float16.cpp (132 of 14692)
   TEST 'Clang :: AST/float16.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/lib/clang/9.0.0/include
 -nostdsysteminc -std=c++11 -ast-dump -triple aarch64-linux-gnu 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/test/AST/float16.cpp
 | /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/FileCheck 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/test/AST/float16.cpp
 --strict-whitespace
  : 'RUN: at line 2';   
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/lib/clang/9.0.0/include
 -nostdsysteminc -std=c++11 -ast-dump -triple aarch64-linux-gnu 
-fnative-half-type 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/test/AST/float16.cpp
 | /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/FileCheck 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/test/AST/float16.cpp
 --check-prefix=CHECK-NATIVE --strict-whitespace
  --
  Exit Code: 2
  
  Command Output (stderr):
  --
  ==12261==WARNING: MemorySanitizer: use-of-uninitialized-value
  #0 0xd4212a8 in 
clang::targets::AArch64TargetInfo::getTargetDefines(clang::LangOptions const&, 
clang::MacroBuilder&) const 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Basic/Targets/AArch64.cpp:197:7
  #1 0xd422b5b in 
clang::targets::AArch64leTargetInfo::getTargetDefines(clang::LangOptions 
const&, clang::MacroBuilder&) const 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Basic/Targets/AArch64.cpp:463:22
  #2 0xd3ee87e in 
clang::targets::OSTargetInfo::getTargetDefines(clang::LangOptions
 const&, clang::MacroBuilder&) const 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Basic/Targets/OSTargets.h:33:14
  #3 0x784d4c7 in InitializePredefinedMacros(clang::TargetInfo const&, 
clang::LangOptions const&, clang::FrontendOptions const&, clang::MacroBuilder&) 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Frontend/InitPreprocessor.cpp:1087:6
  #4 0x7830b1f in clang::InitializePreprocessor(clang::Preprocessor&, 
clang::PreprocessorOptions const&, clang::PCHContainerReader const&, 
clang::FrontendOptions const&) 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Frontend/InitPreprocessor.cpp:1117:5
  #5 0x76a550e in 
clang::CompilerInstance::createPreprocessor(clang::TranslationUnitKind) 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:392:3
  #6 0x779314b in 
clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, 
clang::FrontendInputFile const&) 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:742:8
  #7 0x76b49f8 in 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:943:13
  #8 0x79d07f6 in 
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:271:25
  #9 0xb19a3a in cc1_main(llvm::ArrayRef, char const*, void*) 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/tools/driver/cc1_main.cpp:225:15
  #10 0xb12983 in ExecuteCC1Tool 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/tools/driver/driver.cpp:309:12
  #11 0xb12983 in main 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/tools/driver/driver.cpp:381
  #12 0x7f69ddc1c2e0 in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
  #13 0xa91139 in _start 
(/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/clang-9+0xa91139)
  
  SUMMARY: MemorySanitizer: use-of-uninitialized-value 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/Basic/Targets/AArch64.cpp:197:7
 in clang::targets::AArch64TargetInfo::getTargetDefines(clang::LangOptions 
const&, clang::MacroBuilder&) const
  Exiting
  FileCheck error: '-' is empty.
  FileCheck command line:  
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build_msan/bin/FileCheck 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/test/AST/float16.cpp
 --strict-whitespace

FYI @hctim


Repository:
  rC Clang

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

https://reviews.llvm.org/D60485



___

[PATCH] D50901: [clang][ubsan] Split Implicit Integer Truncation Sanitizer into unsigned and signed checks

2018-09-18 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:305
   enum ImplicitConversionCheckKind : unsigned char {
-ICCK_IntegerTruncation = 0,
+ICCK_IntegerTruncation = 0, // Legacy, no longer used.
+ICCK_UnsignedIntegerTruncation = 1,

why do you need to keep it?


Repository:
  rC Clang

https://reviews.llvm.org/D50901



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


[PATCH] D50901: [clang][ubsan] Split Implicit Integer Truncation Sanitizer into unsigned and signed checks

2018-09-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:305
   enum ImplicitConversionCheckKind : unsigned char {
-ICCK_IntegerTruncation = 0,
+ICCK_IntegerTruncation = 0, // Legacy, no longer used.
+ICCK_UnsignedIntegerTruncation = 1,

lebedev.ri wrote:
> vitalybuka wrote:
> > why do you need to keep it?
> *Here* - for consistency with the compiler-rt part.
> 
> There - what about mismatch in the used clang version
> (which still only produced the `(ImplicitConversionCheckKind)0`), and 
> compiler-rt version
> (which has `(ImplicitConversionCheckKind)1` and 
> `(ImplicitConversionCheckKind)2`)?
> Is it 100.00% guaranteed not to happen? I'm not so sure.
I don't think we try support mismatched versions of clang and compiler-rt


Repository:
  rC Clang

https://reviews.llvm.org/D50901



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


[PATCH] D45045: [DebugInfo] Generate debug information for labels.

2018-09-27 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka reopened this revision.
vitalybuka added a comment.

Reverted in r343183
https://bugs.llvm.org/show_bug.cgi?id=39094
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/29356/steps/build%20release%20tsan%20with%20clang/logs/stdio


Repository:
  rL LLVM

https://reviews.llvm.org/D45045



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


[PATCH] D52589: [clang][ubsan][NFC] Slight test cleanup in preparation for D50901

2018-09-27 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: test/CodeGen/catch-implicit-integer-truncations-basics-negatives.c:7
+////
+// Unsigned case.
+////

This is a new test, not just cleanup?


Repository:
  rC Clang

https://reviews.llvm.org/D52589



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/include/clang/Driver/Options.td:854
  HelpText<"Enable use-after-destroy 
detection in MemorySanitizer">;
+def fno_sanitize_memory_use_after_dtor : Flag<["-"], 
"fno-sanitize-memory-use-after-dtor">,
+ Group,

I'd recommend to split patch in two:
1. Add no-sanitize with tests
2. Flip default



Comment at: clang/lib/Driver/SanitizerArgs.cpp:492
+if (Arg *A =
+Args.getLastArg(options::OPT_fsanitize_memory_use_after_dtor,
+options::OPT_fno_sanitize_memory_use_after_dtor)) {

Can you use parsing similar to AsanUseAfterScope at line 645



Comment at: compiler-rt/test/msan/dtor-bit-fields.cc:3
 
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory 
-fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
+// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
 

Please keep -fsanitize-memory-use-after-dtor in dtor* tests.
We test the check itself here, not default value. So we don't flip it every 
time default switched.



Comment at: compiler-rt/test/msan/use-after-dtor.cc:13
 
 #include 
 #include 

Probably we need one test which check that we stop detecting bugs with 
-fno-sanitize-memory-track-origins. Maybe this one or in separate file.


https://reviews.llvm.org/D37860



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added inline comments.
This revision now requires changes to proceed.



Comment at: clang/test/Driver/fsanitize.c:175
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MSAN-USE-AFTER-DTOR
-// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR

Somewhere we need to have test that default is ON or OFF.
Maybe here?


https://reviews.llvm.org/D37860



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/test/msan/use-after-dtor.cc:13
 
 #include 
 #include 

morehouse wrote:
> vitalybuka wrote:
> > Probably we need one test which check that we stop detecting bugs with 
> > -fno-sanitize-memory-track-origins. Maybe this one or in separate file.
> Do you mean `-fno-sanitize-memory-use-after-dtor`?  See `dtor-member.cc` test.
Right.
use-after-dtor.cc seems more general than dtor-member.cc. So maybe having it 
here as well would be nice.


https://reviews.llvm.org/D37860



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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In https://reviews.llvm.org/D37867#871353, @eugenis wrote:

> Have you looked at performance?


Not the answer to your question, but this patch just adds negative flag without 
changing defaults.


https://reviews.llvm.org/D37867



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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:494
+ options::OPT_fno_sanitize_memory_use_after_dtor,
+ false);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&

false -> MsanUseAfterDtor


https://reviews.llvm.org/D37867



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


[PATCH] D63967: Handle IntToPtr in isBytewiseValue

2019-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: llvm/lib/Analysis/ValueTracking.cpp:3222
 
+  if (auto *CE = dyn_cast(C)) {
+if (CE->getOpcode() == Instruction::IntToPtr) {

@pcc BTW, your original patch just gave up on size mismatch
Something like:
```
if (auto *CE = dyn_cast(C)) {
if (CE->getOpcode() == Instruction::IntToPtr &&
cast(CE->getOperand(0)->getType())->getBitWidth() ==
DL.getPointerSizeInBits(
cast(CE->getType())->getAddressSpace())) {
  return isBytewiseValue(CE->getOperand(0), DL);
}
return nullptr;
  }
```

Both versions affect binary size about the same.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63967



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


[PATCH] D64597: CodeGet: Init 32bit pointers with 0xAAAAAAAA

2019-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: pcc, eugenis, glider, jfb.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Patch extends effect of D63967  to 32bit 
platforms and improves pattern
initialization there. It cuts size of 32bit binary compiled with 
-ftrivial-auto-var-init=pattern by 2%.

Using pointer on the first page was useful but is not worth of 2%

Binary size change on CTMark, (with -fuse-ld=lld -Wl,--icf=all, similar results 
with default linker options)

 master   patch  diff
  Os pattern   7.915580e+057.727164e+05 -0.026256 
  O3 pattern   9.953688e+059.769336e+05 -0.018545 

Zero vs Pattern on master

 zero   pattern  diff
  Os 7.689712e+05  7.915580e+05  0.031380
  O3 9.744796e+05  9.953688e+05  0.021133

Zero vs Pattern with the patch

 zero   pattern  diff
  Os 7.689712e+05  7.727164e+05  0.003025
  O3 9.744796e+05  9.769336e+05  0.001525


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64597

Files:
  clang/lib/CodeGen/PatternInit.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp

Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -65,9 +65,9 @@
 // PATTERN-O1-NOT: @__const.test_nullinit_uninit.uninit
 // PATTERN-O1-NOT: @__const.test_nullinit_braces.braces
 // PATTERN-O1-NOT: @__const.test_nullinit_custom.custom
-// PATTERN-I386: @__const.test_nullinit_uninit.uninit = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i32 170 to i8*) }, align 4
-// PATTERN-I386: @__const.test_nullinit_braces.braces = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i32 170 to i8*) }, align 4
-// PATTERN-I386: @__const.test_nullinit_custom.custom = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i32 170 to i8*) }, align 4
+// PATTERN-I386: @__const.test_nullinit_uninit.uninit = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i32 -1431655766 to i8*) }, align 4
+// PATTERN-I386: @__const.test_nullinit_braces.braces = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i32 -1431655766 to i8*) }, align 4
+// PATTERN-I386: @__const.test_nullinit_custom.custom = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i32 -1431655766 to i8*) }, align 4
 struct nullinit { char* null = nullptr; };
 // PATTERN-O0: @__const.test_padded_uninit.uninit = private unnamed_addr constant { i8, [3 x i8], i32 } { i8 -86, [3 x i8] c"\AA\AA\AA", i32 -1431655766 }, align 4
 // PATTERN-O0: @__const.test_padded_custom.custom = private unnamed_addr constant { i8, [3 x i8], i32 } { i8 42, [3 x i8] zeroinitializer, i32 13371337 }, align 4
@@ -181,19 +181,19 @@
 // PATTERN-O1-NOT: @__const.test_base_uninit.uninit
 // PATTERN-O0: @__const.test_base_braces.braces = private unnamed_addr constant %struct.base { i32 (...)** inttoptr (i64 -6148914691236517206 to i32 (...)**) }, align 8
 // PATTERN-O1-NOT: @__const.test_base_braces.braces
-// PATTERN-I386: @__const.test_base_uninit.uninit = private unnamed_addr constant %struct.base { i32 (...)** inttoptr (i32 170 to i32 (...)**) }, align 4
+// PATTERN-I386: @__const.test_base_uninit.uninit = private unnamed_addr constant %struct.base { i32 (...)** inttoptr (i32 -1431655766 to i32 (...)**) }, align 4
 struct base { virtual ~base(); };
 // PATTERN-O0: @__const.test_derived_uninit.uninit = private unnamed_addr constant %struct.derived { %struct.base { i32 (...)** inttoptr (i64 -6148914691236517206 to i32 (...)**) } }, align 8
 // PATTERN-O1-NOT: @__const.test_derived_uninit.uninit
 // PATTERN-O0: @__const.test_derived_braces.braces = private unnamed_addr constant %struct.derived { %struct.base { i32 (...)** inttoptr (i64 -6148914691236517206 to i32 (...)**) } }, align 8
 // PATTERN-O1-NOT: @__const.test_derived_braces.braces
-// PATTERN-I386: @__const.test_derived_uninit.uninit = private unnamed_addr constant %struct.derived { %struct.base { i32 (...)** inttoptr (i32 170 to i32 (...)**) } }, align 4
+// PATTERN-I386: @__const.test_derived_uninit.uninit = private unnamed_addr constant %struct.derived { %struct.base { i32 (...)** inttoptr (i32 -1431655766 to i32 (...)**) } }, align 4
 struct derived : public base {};
 // PATTERN-O0: @__const.test_virtualderived_uninit.uninit = private unnamed_addr constant %struct.virtualderived { %struct.base { i32 (...)** inttoptr (i64 -6148914691236517206 to i32 (...)**) }, %struct.derived { %struct.base { i32 (...)** inttoptr (i64 -6148914691236517206 to i32 (...)**) } } }, align 8
 // PATTERN-O1-NOT: @__const.test_virtualderived_uninit.uninit
 // PATTERN-O0: @__const.test_virtualderived_braces.braces = private unnamed_addr constant %struct.virtualderived { %struct.base { i32 (...)** inttoptr (i64 -6148914691236517206 to i32 (.

[PATCH] D63967: Handle IntToPtr in isBytewiseValue

2019-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365858: Handle IntToPtr in isBytewiseValue (authored by 
vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63967?vs=207180&id=209394#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63967

Files:
  cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
  llvm/trunk/lib/Analysis/ValueTracking.cpp
  llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp


Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -3218,6 +3218,17 @@
 }
   }
 
+  if (auto *CE = dyn_cast(C)) {
+if (CE->getOpcode() == Instruction::IntToPtr) {
+  auto PS = DL.getPointerSizeInBits(
+  cast(CE->getType())->getAddressSpace());
+  return isBytewiseValue(
+  ConstantExpr::getIntegerCast(CE->getOperand(0),
+   Type::getIntNTy(Ctx, PS), false),
+  DL);
+}
+  }
+
   auto Merge = [&](Value *LHS, Value *RHS) -> Value * {
 if (LHS == RHS)
   return LHS;
Index: llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp
===
--- llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp
@@ -794,11 +794,11 @@
 "i16* inttoptr (i64 0 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i64 -1 to i16*)",
 },
 {
-"",
+"i8 -86",
 "i16* inttoptr (i64 -6148914691236517206 to i16*)",
 },
 {
@@ -806,7 +806,7 @@
 "i16* inttoptr (i48 -1 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i96 -1 to i16*)",
 },
 {
Index: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
===
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
@@ -1042,14 +1042,8 @@
 // CHECK:%uninit = alloca [4 x i32*], align
 // CHECK-NEXT:   call void @{{.*}}used{{.*}}%uninit)
 // PATTERN-O1-LABEL: @test_intptr4_uninit()
-// PATTERN-O1:   %1 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 0
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %1, align 16
-// PATTERN-O1-NEXT:  %2 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 1
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %2, align 8
-// PATTERN-O1-NEXT:  %3 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 2
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %3, align 16
-// PATTERN-O1-NEXT:  %4 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 3
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %4, align 8
+// PATTERN-O1:   %1 = bitcast [4 x i32*]* %uninit to i8*
+// PATTERN-O1-NEXT:  call void @llvm.memset.p0i8.i64(i8* nonnull align 16 %1, 
i8 -86, i64 32, i1 false)
 // ZERO-LABEL:   @test_intptr4_uninit()
 // ZERO: call void @llvm.memset{{.*}}, i8 0,
 


Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -3218,6 +3218,17 @@
 }
   }
 
+  if (auto *CE = dyn_cast(C)) {
+if (CE->getOpcode() == Instruction::IntToPtr) {
+  auto PS = DL.getPointerSizeInBits(
+  cast(CE->getType())->getAddressSpace());
+  return isBytewiseValue(
+  ConstantExpr::getIntegerCast(CE->getOperand(0),
+   Type::getIntNTy(Ctx, PS), false),
+  DL);
+}
+  }
+
   auto Merge = [&](Value *LHS, Value *RHS) -> Value * {
 if (LHS == RHS)
   return LHS;
Index: llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp
===
--- llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp
@@ -794,11 +794,11 @@
 "i16* inttoptr (i64 0 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i64 -1 to i16*)",
 },
 {
-"",
+"i8 -86",
 "i16* inttoptr (i64 -6148914691236517206 to i16*)",
 },
 {
@@ -806,7 +806,7 @@
 "i16* inttoptr (i48 -1 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i96 -1 to i16*)",
 },
 {
Index: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
===
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.c

[PATCH] D64597: CodeGet: Init 32bit pointers with 0xFFFFFFFF

2019-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D64597#1581654 , @jfb wrote:

> In D64597#1581605 , @pcc wrote:
>
> > The problem with `0x` on 32-bit is that it is likely to be a valid 
> > address.
> >
> > When I discussed this with JF I proposed a pointer initialization of 
> > `0x` which he agreed to. This value is very likely to trap when 
> > accessed (due to accesses likely wrapping to zero) and also has the benefit 
> > of being the same pattern as for floats.
>
>
> Indeed.


Done. This is even more effective.
Maybe we should consider 0xAA for floats on 64bit?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64597



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


[PATCH] D64597: CodeGet: Init 32bit pointers with 0xFFFFFFFF

2019-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 209400.
vitalybuka added a comment.

0x


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64597

Files:
  clang/lib/CodeGen/PatternInit.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp


Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -12,7 +12,7 @@
 #ifdef __x86_64__
 char inits[] = 
{"-86/-21846/-1431655766/i64/-6148914691236517206/-6148914691236517206/i128/-113427455640312821154458202477256070486/i64/-6148914691236517206/AA/"};
 #else
-char inits[] = 
{"-86/-21846/-1431655766/i32/-1431655766/-6148914691236517206/i32/-1431655766/i32/170/AA/"};
+char inits[] = {"-1/-1/-1/i32/-1/-1/i32/-1/i32/-1/FF/"};
 #define __int128 int;
 #endif
 // PATTERN: @inits = {{.*}} 
c"[[I8:[^/]+]]/[[I16:[^/]+]]/[[I32:[^/]+]]/[[ILONGT:[^/]+]]/[[ILONG:[^/]+]]/[[I64:[^/]+]]/[[I128T:[^/]+]]/[[I128:[^/]+]]/[[IPTRT:[^/]+]]/[[IPTR:[^/]+]]/[[IC:[^/]+]]/\00",
 align 1
@@ -1043,7 +1043,7 @@
 // CHECK-NEXT:   call void @{{.*}}used{{.*}}%uninit)
 // PATTERN-O1-LABEL: @test_intptr4_uninit()
 // PATTERN-O1:   %1 = bitcast [4 x i32*]* %uninit to i8*
-// PATTERN-O1-NEXT:  call void @llvm.memset.p0i8.i64(i8* nonnull align 16 %1, 
i8 -86, i64 32, i1 false)
+// PATTERN-O1-NEXT:  call void @llvm.memset.p0i8.i64(i8* nonnull align 16 %1, 
i8 [[I8]], i64 32, i1 false)
 // ZERO-LABEL:   @test_intptr4_uninit()
 // ZERO: call void @llvm.memset{{.*}}, i8 0,
 
Index: clang/lib/CodeGen/PatternInit.cpp
===
--- clang/lib/CodeGen/PatternInit.cpp
+++ clang/lib/CodeGen/PatternInit.cpp
@@ -17,12 +17,13 @@
   // repeated byte-pattern which makes it easier to synthesize. We use it for
   // pointers as well as integers so that aggregates are likely to be
   // initialized with this repeated value.
-  constexpr uint64_t LargeValue = 0xull;
   // For 32-bit platforms it's a bit trickier because, across systems, only the
-  // zero page can reasonably be expected to be unmapped, and even then we need
-  // a very low address. We use a smaller value, and that value sadly doesn't
-  // have a repeated byte-pattern. We don't use it for integers.
-  constexpr uint32_t SmallValue = 0x00AA;
+  // zero page can reasonably be expected to be unmapped. We use max 0x
+  // assuming that memory access will overlap into zero page.
+  const uint64_t IntValue =
+  CGM.getContext().getTargetInfo().getMaxPointerWidth() < 64
+  ? 0xull
+  : 0xull;
   // Floating-point values are initialized as NaNs because they propagate. 
Using
   // a repeated byte pattern means that it will be easier to initialize
   // all-floating-point aggregates and arrays with memset. Further, aggregates
@@ -36,27 +37,18 @@
 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty)
 ->getBitWidth();
 if (BitWidth <= 64)
-  return llvm::ConstantInt::get(Ty, LargeValue);
+  return llvm::ConstantInt::get(Ty, IntValue);
 return llvm::ConstantInt::get(
-Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, LargeValue)));
+Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, IntValue)));
   }
   if (Ty->isPtrOrPtrVectorTy()) {
 auto *PtrTy = cast(
 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty);
 unsigned PtrWidth = CGM.getContext().getTargetInfo().getPointerWidth(
 PtrTy->getAddressSpace());
-llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth);
-uint64_t IntValue;
-switch (PtrWidth) {
-default:
+if (PtrWidth > 64)
   llvm_unreachable("pattern initialization of unsupported pointer width");
-case 64:
-  IntValue = LargeValue;
-  break;
-case 32:
-  IntValue = SmallValue;
-  break;
-}
+llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth);
 auto *Int = llvm::ConstantInt::get(IntTy, IntValue);
 return llvm::ConstantExpr::getIntToPtr(Int, PtrTy);
   }


Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -12,7 +12,7 @@
 #ifdef __x86_64__
 char inits[] = {"-86/-21846/-1431655766/i64/-6148914691236517206/-6148914691236517206/i128/-113427455640312821154458202477256070486/i64/-6148914691236517206/AA/"};
 #else
-char inits[] = {"-86/-21846/-1431655766/i32/-1431655766/-6148914691236517206/i32/-1431655766/i32/170/AA/"};
+char inits[] = {"-1/-1/-1/i32/-1/-1/i32/-1/i32/-1/FF/"};
 #define __int128 int;
 #endif
 // PATTERN: @inits = {{.*}} c"[[I8:[^/]+]]/[[I16:[^/]+]]/[[I32:[^/]+]]/[[ILONGT:[^/]+]]/[[ILONG:[^/]+]]/[[I64:

[PATCH] D64597: CodeGet: Init 32bit pointers with 0xFFFFFFFF

2019-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 209401.
vitalybuka added a comment.

undo unrelated line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64597

Files:
  clang/lib/CodeGen/PatternInit.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp


Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -12,7 +12,7 @@
 #ifdef __x86_64__
 char inits[] = 
{"-86/-21846/-1431655766/i64/-6148914691236517206/-6148914691236517206/i128/-113427455640312821154458202477256070486/i64/-6148914691236517206/AA/"};
 #else
-char inits[] = 
{"-86/-21846/-1431655766/i32/-1431655766/-6148914691236517206/i32/-1431655766/i32/170/AA/"};
+char inits[] = {"-1/-1/-1/i32/-1/-1/i32/-1/i32/-1/FF/"};
 #define __int128 int;
 #endif
 // PATTERN: @inits = {{.*}} 
c"[[I8:[^/]+]]/[[I16:[^/]+]]/[[I32:[^/]+]]/[[ILONGT:[^/]+]]/[[ILONG:[^/]+]]/[[I64:[^/]+]]/[[I128T:[^/]+]]/[[I128:[^/]+]]/[[IPTRT:[^/]+]]/[[IPTR:[^/]+]]/[[IC:[^/]+]]/\00",
 align 1
Index: clang/lib/CodeGen/PatternInit.cpp
===
--- clang/lib/CodeGen/PatternInit.cpp
+++ clang/lib/CodeGen/PatternInit.cpp
@@ -17,12 +17,13 @@
   // repeated byte-pattern which makes it easier to synthesize. We use it for
   // pointers as well as integers so that aggregates are likely to be
   // initialized with this repeated value.
-  constexpr uint64_t LargeValue = 0xull;
   // For 32-bit platforms it's a bit trickier because, across systems, only the
-  // zero page can reasonably be expected to be unmapped, and even then we need
-  // a very low address. We use a smaller value, and that value sadly doesn't
-  // have a repeated byte-pattern. We don't use it for integers.
-  constexpr uint32_t SmallValue = 0x00AA;
+  // zero page can reasonably be expected to be unmapped. We use max 0x
+  // assuming that memory access will overlap into zero page.
+  const uint64_t IntValue =
+  CGM.getContext().getTargetInfo().getMaxPointerWidth() < 64
+  ? 0xull
+  : 0xull;
   // Floating-point values are initialized as NaNs because they propagate. 
Using
   // a repeated byte pattern means that it will be easier to initialize
   // all-floating-point aggregates and arrays with memset. Further, aggregates
@@ -36,27 +37,18 @@
 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty)
 ->getBitWidth();
 if (BitWidth <= 64)
-  return llvm::ConstantInt::get(Ty, LargeValue);
+  return llvm::ConstantInt::get(Ty, IntValue);
 return llvm::ConstantInt::get(
-Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, LargeValue)));
+Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, IntValue)));
   }
   if (Ty->isPtrOrPtrVectorTy()) {
 auto *PtrTy = cast(
 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty);
 unsigned PtrWidth = CGM.getContext().getTargetInfo().getPointerWidth(
 PtrTy->getAddressSpace());
-llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth);
-uint64_t IntValue;
-switch (PtrWidth) {
-default:
+if (PtrWidth > 64)
   llvm_unreachable("pattern initialization of unsupported pointer width");
-case 64:
-  IntValue = LargeValue;
-  break;
-case 32:
-  IntValue = SmallValue;
-  break;
-}
+llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth);
 auto *Int = llvm::ConstantInt::get(IntTy, IntValue);
 return llvm::ConstantExpr::getIntToPtr(Int, PtrTy);
   }


Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -12,7 +12,7 @@
 #ifdef __x86_64__
 char inits[] = {"-86/-21846/-1431655766/i64/-6148914691236517206/-6148914691236517206/i128/-113427455640312821154458202477256070486/i64/-6148914691236517206/AA/"};
 #else
-char inits[] = {"-86/-21846/-1431655766/i32/-1431655766/-6148914691236517206/i32/-1431655766/i32/170/AA/"};
+char inits[] = {"-1/-1/-1/i32/-1/-1/i32/-1/i32/-1/FF/"};
 #define __int128 int;
 #endif
 // PATTERN: @inits = {{.*}} c"[[I8:[^/]+]]/[[I16:[^/]+]]/[[I32:[^/]+]]/[[ILONGT:[^/]+]]/[[ILONG:[^/]+]]/[[I64:[^/]+]]/[[I128T:[^/]+]]/[[I128:[^/]+]]/[[IPTRT:[^/]+]]/[[IPTR:[^/]+]]/[[IC:[^/]+]]/\00", align 1
Index: clang/lib/CodeGen/PatternInit.cpp
===
--- clang/lib/CodeGen/PatternInit.cpp
+++ clang/lib/CodeGen/PatternInit.cpp
@@ -17,12 +17,13 @@
   // repeated byte-pattern which makes it easier to synthesize. We use it for
   // pointers as well as integers so that aggregates are likely to be
   // initialized with this repeated value.
- 

[PATCH] D64597: CodeGet: Init 32bit pointers with 0xFFFFFFFF

2019-07-12 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365921: CodeGet: Init 32bit pointers with 0x 
(authored by vitalybuka, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64597?vs=209401&id=209522#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64597

Files:
  cfe/trunk/lib/CodeGen/PatternInit.cpp
  cfe/trunk/test/CodeGenCXX/auto-var-init.cpp


Index: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
===
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
@@ -12,7 +12,7 @@
 #ifdef __x86_64__
 char inits[] = 
{"-86/-21846/-1431655766/i64/-6148914691236517206/-6148914691236517206/i128/-113427455640312821154458202477256070486/i64/-6148914691236517206/AA/"};
 #else
-char inits[] = 
{"-86/-21846/-1431655766/i32/-1431655766/-6148914691236517206/i32/-1431655766/i32/170/AA/"};
+char inits[] = {"-1/-1/-1/i32/-1/-1/i32/-1/i32/-1/FF/"};
 #define __int128 int;
 #endif
 // PATTERN: @inits = {{.*}} 
c"[[I8:[^/]+]]/[[I16:[^/]+]]/[[I32:[^/]+]]/[[ILONGT:[^/]+]]/[[ILONG:[^/]+]]/[[I64:[^/]+]]/[[I128T:[^/]+]]/[[I128:[^/]+]]/[[IPTRT:[^/]+]]/[[IPTR:[^/]+]]/[[IC:[^/]+]]/\00",
 align 1
Index: cfe/trunk/lib/CodeGen/PatternInit.cpp
===
--- cfe/trunk/lib/CodeGen/PatternInit.cpp
+++ cfe/trunk/lib/CodeGen/PatternInit.cpp
@@ -17,12 +17,13 @@
   // repeated byte-pattern which makes it easier to synthesize. We use it for
   // pointers as well as integers so that aggregates are likely to be
   // initialized with this repeated value.
-  constexpr uint64_t LargeValue = 0xull;
   // For 32-bit platforms it's a bit trickier because, across systems, only the
-  // zero page can reasonably be expected to be unmapped, and even then we need
-  // a very low address. We use a smaller value, and that value sadly doesn't
-  // have a repeated byte-pattern. We don't use it for integers.
-  constexpr uint32_t SmallValue = 0x00AA;
+  // zero page can reasonably be expected to be unmapped. We use max 0x
+  // assuming that memory access will overlap into zero page.
+  const uint64_t IntValue =
+  CGM.getContext().getTargetInfo().getMaxPointerWidth() < 64
+  ? 0xull
+  : 0xull;
   // Floating-point values are initialized as NaNs because they propagate. 
Using
   // a repeated byte pattern means that it will be easier to initialize
   // all-floating-point aggregates and arrays with memset. Further, aggregates
@@ -36,27 +37,18 @@
 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty)
 ->getBitWidth();
 if (BitWidth <= 64)
-  return llvm::ConstantInt::get(Ty, LargeValue);
+  return llvm::ConstantInt::get(Ty, IntValue);
 return llvm::ConstantInt::get(
-Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, LargeValue)));
+Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, IntValue)));
   }
   if (Ty->isPtrOrPtrVectorTy()) {
 auto *PtrTy = cast(
 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty);
 unsigned PtrWidth = CGM.getContext().getTargetInfo().getPointerWidth(
 PtrTy->getAddressSpace());
-llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth);
-uint64_t IntValue;
-switch (PtrWidth) {
-default:
+if (PtrWidth > 64)
   llvm_unreachable("pattern initialization of unsupported pointer width");
-case 64:
-  IntValue = LargeValue;
-  break;
-case 32:
-  IntValue = SmallValue;
-  break;
-}
+llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth);
 auto *Int = llvm::ConstantInt::get(IntTy, IntValue);
 return llvm::ConstantExpr::getIntToPtr(Int, PtrTy);
   }


Index: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
===
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
@@ -12,7 +12,7 @@
 #ifdef __x86_64__
 char inits[] = {"-86/-21846/-1431655766/i64/-6148914691236517206/-6148914691236517206/i128/-113427455640312821154458202477256070486/i64/-6148914691236517206/AA/"};
 #else
-char inits[] = {"-86/-21846/-1431655766/i32/-1431655766/-6148914691236517206/i32/-1431655766/i32/170/AA/"};
+char inits[] = {"-1/-1/-1/i32/-1/-1/i32/-1/i32/-1/FF/"};
 #define __int128 int;
 #endif
 // PATTERN: @inits = {{.*}} c"[[I8:[^/]+]]/[[I16:[^/]+]]/[[I32:[^/]+]]/[[ILONGT:[^/]+]]/[[ILONG:[^/]+]]/[[I64:[^/]+]]/[[I128T:[^/]+]]/[[I128:[^/]+]]/[[IPTRT:[^/]+]]/[[IPTR:[^/]+]]/[[IC:[^/]+]]/\00", align 1
Index: cfe/trunk/lib/CodeGen/PatternInit.cpp
===
--- cfe/trunk/li

[PATCH] D64675: WIP: Disable optimization in emitStoresForConstant

2019-07-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: glider, jfb.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Not rely a review, but removing this code I see slight improvements in
binary size on CTMark. Looks like with "ptr" patches MemCpyOptPass is
capable to handle this.

WDYT?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64675

Files:
  clang/lib/CodeGen/CGDecl.cpp

Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1162,62 +1162,62 @@
 
   auto *SizeVal = llvm::ConstantInt::get(CGM.IntPtrTy, ConstantSize);
 
-  // If the initializer is all or mostly the same, codegen with bzero / memset
-  // then do a few stores afterward.
-  if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
-Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal,
- isVolatile);
-
-bool valueAlreadyCorrect =
-constant->isNullValue() || isa(constant);
-if (!valueAlreadyCorrect) {
-  Loc = Builder.CreateBitCast(Loc, Ty->getPointerTo(Loc.getAddressSpace()));
-  emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder);
-}
-return;
-  }
-
-  // If the initializer is a repeated byte pattern, use memset.
-  llvm::Value *Pattern =
-  shouldUseMemSetToInitialize(constant, ConstantSize, CGM.getDataLayout());
-  if (Pattern) {
-uint64_t Value = 0x00;
-if (!isa(Pattern)) {
-  const llvm::APInt &AP = cast(Pattern)->getValue();
-  assert(AP.getBitWidth() <= 8);
-  Value = AP.getLimitedValue();
-}
-Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal,
- isVolatile);
-return;
-  }
+  // // If the initializer is all or mostly the same, codegen with bzero / memset
+  // // then do a few stores afterward.
+  // if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
+  //   Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal,
+  //isVolatile);
+
+  //   bool valueAlreadyCorrect =
+  //   constant->isNullValue() || isa(constant);
+  //   if (!valueAlreadyCorrect) {
+  // Loc = Builder.CreateBitCast(Loc, Ty->getPointerTo(Loc.getAddressSpace()));
+  // emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder);
+  //   }
+  //   return;
+  // }
+
+  // // If the initializer is a repeated byte pattern, use memset.
+  // llvm::Value *Pattern =
+  // shouldUseMemSetToInitialize(constant, ConstantSize, CGM.getDataLayout());
+  // if (Pattern) {
+  //   uint64_t Value = 0x00;
+  //   if (!isa(Pattern)) {
+  // const llvm::APInt &AP = cast(Pattern)->getValue();
+  // assert(AP.getBitWidth() <= 8);
+  // Value = AP.getLimitedValue();
+  //   }
+  //   Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal,
+  //isVolatile);
+  //   return;
+  // }
 
   // If the initializer is small, use a handful of stores.
-  if (shouldSplitConstantStore(CGM, ConstantSize)) {
-if (auto *STy = dyn_cast(Ty)) {
-  // FIXME: handle the case when STy != Loc.getElementType().
-  if (STy == Loc.getElementType()) {
-for (unsigned i = 0; i != constant->getNumOperands(); i++) {
-  Address EltPtr = Builder.CreateStructGEP(Loc, i);
-  emitStoresForConstant(
-  CGM, D, EltPtr, isVolatile, Builder,
-  cast(Builder.CreateExtractValue(constant, i)));
-}
-return;
-  }
-} else if (auto *ATy = dyn_cast(Ty)) {
-  // FIXME: handle the case when ATy != Loc.getElementType().
-  if (ATy == Loc.getElementType()) {
-for (unsigned i = 0; i != ATy->getNumElements(); i++) {
-  Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
-  emitStoresForConstant(
-  CGM, D, EltPtr, isVolatile, Builder,
-  cast(Builder.CreateExtractValue(constant, i)));
-}
-return;
-  }
-}
-  }
+  // if (shouldSplitConstantStore(CGM, ConstantSize)) {
+  //   if (auto *STy = dyn_cast(Ty)) {
+  // // FIXME: handle the case when STy != Loc.getElementType().
+  // if (STy == Loc.getElementType()) {
+  //   for (unsigned i = 0; i != constant->getNumOperands(); i++) {
+  // Address EltPtr = Builder.CreateStructGEP(Loc, i);
+  // emitStoresForConstant(
+  // CGM, D, EltPtr, isVolatile, Builder,
+  // cast(Builder.CreateExtractValue(constant, i)));
+  //   }
+  //   return;
+  // }
+  //   } else if (auto *ATy = dyn_cast(Ty)) {
+  // // FIXME: handle the case when ATy != Loc.getElementType().
+  // if (ATy == Loc.getElementType()) {
+  //   for (unsigned i = 0; i != ATy->getNumElements(); i++) {
+  // Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
+  // emitStoresF

[PATCH] D64675: WIP: Disable optimization in emitStoresForConstant

2019-07-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 209638.
vitalybuka added a comment.

Remove single store


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64675

Files:
  clang/lib/CodeGen/CGDecl.cpp


Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1153,72 +1153,8 @@
   if (!ConstantSize)
 return;
 
-  bool canDoSingleStore = Ty->isIntOrIntVectorTy() ||
-  Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
-  if (canDoSingleStore) {
-Builder.CreateStore(constant, Loc, isVolatile);
-return;
-  }
-
   auto *SizeVal = llvm::ConstantInt::get(CGM.IntPtrTy, ConstantSize);
 
-  // If the initializer is all or mostly the same, codegen with bzero / memset
-  // then do a few stores afterward.
-  if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
-Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal,
- isVolatile);
-
-bool valueAlreadyCorrect =
-constant->isNullValue() || isa(constant);
-if (!valueAlreadyCorrect) {
-  Loc = Builder.CreateBitCast(Loc, 
Ty->getPointerTo(Loc.getAddressSpace()));
-  emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder);
-}
-return;
-  }
-
-  // If the initializer is a repeated byte pattern, use memset.
-  llvm::Value *Pattern =
-  shouldUseMemSetToInitialize(constant, ConstantSize, CGM.getDataLayout());
-  if (Pattern) {
-uint64_t Value = 0x00;
-if (!isa(Pattern)) {
-  const llvm::APInt &AP = cast(Pattern)->getValue();
-  assert(AP.getBitWidth() <= 8);
-  Value = AP.getLimitedValue();
-}
-Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), 
SizeVal,
- isVolatile);
-return;
-  }
-
-  // If the initializer is small, use a handful of stores.
-  if (shouldSplitConstantStore(CGM, ConstantSize)) {
-if (auto *STy = dyn_cast(Ty)) {
-  // FIXME: handle the case when STy != Loc.getElementType().
-  if (STy == Loc.getElementType()) {
-for (unsigned i = 0; i != constant->getNumOperands(); i++) {
-  Address EltPtr = Builder.CreateStructGEP(Loc, i);
-  emitStoresForConstant(
-  CGM, D, EltPtr, isVolatile, Builder,
-  cast(Builder.CreateExtractValue(constant, i)));
-}
-return;
-  }
-} else if (auto *ATy = dyn_cast(Ty)) {
-  // FIXME: handle the case when ATy != Loc.getElementType().
-  if (ATy == Loc.getElementType()) {
-for (unsigned i = 0; i != ATy->getNumElements(); i++) {
-  Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
-  emitStoresForConstant(
-  CGM, D, EltPtr, isVolatile, Builder,
-  cast(Builder.CreateExtractValue(constant, i)));
-}
-return;
-  }
-}
-  }
-
   // Copy from a global.
   Builder.CreateMemCpy(Loc,
createUnnamedGlobalForMemcpyFrom(


Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1153,72 +1153,8 @@
   if (!ConstantSize)
 return;
 
-  bool canDoSingleStore = Ty->isIntOrIntVectorTy() ||
-  Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
-  if (canDoSingleStore) {
-Builder.CreateStore(constant, Loc, isVolatile);
-return;
-  }
-
   auto *SizeVal = llvm::ConstantInt::get(CGM.IntPtrTy, ConstantSize);
 
-  // If the initializer is all or mostly the same, codegen with bzero / memset
-  // then do a few stores afterward.
-  if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
-Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal,
- isVolatile);
-
-bool valueAlreadyCorrect =
-constant->isNullValue() || isa(constant);
-if (!valueAlreadyCorrect) {
-  Loc = Builder.CreateBitCast(Loc, Ty->getPointerTo(Loc.getAddressSpace()));
-  emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder);
-}
-return;
-  }
-
-  // If the initializer is a repeated byte pattern, use memset.
-  llvm::Value *Pattern =
-  shouldUseMemSetToInitialize(constant, ConstantSize, CGM.getDataLayout());
-  if (Pattern) {
-uint64_t Value = 0x00;
-if (!isa(Pattern)) {
-  const llvm::APInt &AP = cast(Pattern)->getValue();
-  assert(AP.getBitWidth() <= 8);
-  Value = AP.getLimitedValue();
-}
-Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal,
- isVolatile);
-return;
-  }
-
-  // If the initializer is small, use a handful of stores.
-  if (shouldSplitConstantStore(CGM, ConstantSize)) {
-if (auto *STy = dyn_cast(Ty)) {
-  // FIXME: handle the case when STy != 

[PATCH] D64675: WIP: Disable optimization in emitStoresForConstant

2019-07-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D64675#1584016 , @jfb wrote:

> I would keep single stores because it's pretty silly codegen to copy from a 
> global for that.
>
> I would also verify that `-O0` isn't affected too badly by this change.


I will. And maybe I'll measure compilation time as well.

So far I tried -O3 and -Os.
Also I tried Chromium arm, arm64, x86_64. No regression in binary size without 
autoinit, with zero or pattern init.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64675



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


[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-07-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 209942.
vitalybuka added a comment.

Rebase only


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61879

Files:
  clang/test/CodeGenCXX/union-tbaa2.cpp
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/include/llvm/Transforms/Scalar/DeadStoreEliminationExp.h
  llvm/lib/Analysis/Analysis.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExp.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalArgInfoGen.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalGUIDListGen.h
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Other/pass-pipelines.ll
  llvm/test/Transforms/Coroutines/ArgAddr.ll
  llvm/test/Transforms/Coroutines/coro-split-01.ll
  llvm/test/Transforms/Coroutines/ex0.ll
  llvm/test/Transforms/Coroutines/ex1.ll
  llvm/test/Transforms/Coroutines/ex2.ll
  llvm/test/Transforms/Coroutines/ex3.ll
  llvm/test/Transforms/Coroutines/ex4.ll
  llvm/test/Transforms/Coroutines/ex5.ll
  llvm/test/Transforms/Coroutines/phi-coro-end.ll
  llvm/test/Transforms/Coroutines/restart-trigger.ll
  llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
@@ -19,6 +19,8 @@
 "CorrelatedValuePropagation.cpp",
 "DCE.cpp",
 "DeadStoreElimination.cpp",
+"DeadStoreEliminationExp.cpp",
+"DeadStoreEliminationExpGlobal.cpp",
 "DivRemPairs.cpp",
 "EarlyCSE.cpp",
 "FlattenCFGPass.cpp",
Index: llvm/test/Transforms/Coroutines/restart-trigger.ll
===
--- llvm/test/Transforms/Coroutines/restart-trigger.ll
+++ llvm/test/Transforms/Coroutines/restart-trigger.ll
@@ -7,6 +7,8 @@
 ; CHECK:  CoroSplit: Processing coroutine 'f' state: 0
 ; CHECK-NEXT: CoroSplit: Processing coroutine 'f' state: 1
 
+; REQUIRES: abcd
+
 define void @f() {
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
   %size = call i32 @llvm.coro.size.i32()
Index: llvm/test/Transforms/Coroutines/phi-coro-end.ll
===
--- llvm/test/Transforms/Coroutines/phi-coro-end.ll
+++ llvm/test/Transforms/Coroutines/phi-coro-end.ll
@@ -1,6 +1,8 @@
 ; Verify that we correctly handle suspend when the coro.end block contains phi
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex5.ll
===
--- llvm/test/Transforms/Coroutines/ex5.ll
+++ llvm/test/Transforms/Coroutines/ex5.ll
@@ -1,6 +1,8 @@
 ; Fifth example from Doc/Coroutines.rst (final suspend)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex4.ll
===
--- llvm/test/Transforms/Coroutines/ex4.ll
+++ llvm/test/Transforms/Coroutines/ex4.ll
@@ -1,6 +1,8 @@
 ; Fourth example from Doc/Coroutines.rst (coroutine promise)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %promise = alloca i32
Index: llvm/test/Transforms/Coroutines/ex3.ll
===
--- llvm/test/Transforms/Coroutines/ex3.ll
+++ llvm/test/Transforms/Coroutines/ex3.ll
@@ -1,6 +1,8 @@
 ; Third example from Doc/Coroutines.rst (two suspend points)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex2.ll
===
--- llvm/test/Transforms/Coroutines/ex2.ll
+++ llvm/test/Transforms/Coroutines/ex2.ll
@@ -1,6 +1,8 @@
 ; Second example from Doc/Coroutines.rst (custom alloc and free

[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-07-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:27
+static const char GlobalArgumentMemAccess[] = {
+// grep  -P -o "(?<=FUNCTION_INFO: ).*"  | sort -u >
+// ../llvm-project/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpData.h

glider wrote:
> vitalybuka wrote:
> > glider wrote:
> > > Ditto.
> > These files should be empty. Raw diff 
> > https://reviews.llvm.org/file/data/o6sk6gw2gqs4u4pmodrn/PHID-FILE-s6c6nsofxnqekkcvzdzs/D61879.diff
> >  already contains them. 
> > It's ThinLTO replacement experiments. They don't improve results enough, so 
> > I didn't bother to create real ThinLTO stuff. Anyway it is not needed for 
> > full LTO.
> > 
> ```
> $ ninja -j64 check-clang
> ...
> /usr/local/google/src/llvm-git-monorepo/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:20:32:
>  error: zero-size array ‘llvm::GUIDS_LOOKUP’
>  static const GlobalValue::GUID GUIDS_LOOKUP[] = {
> ^~~~
> /usr/local/google/src/llvm-git-monorepo/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:26:19:
>  error: zero-size array ‘llvm::GlobalArgumentMemAccess’
>  static const char GlobalArgumentMemAccess[] = {
>^~~
> ```
> Am I doing something wrong? Looks like empty files aren't enough.
> I've fixed the problem by putting "0" into each file, but it's strange it 
> works differently for us.
You must be using LLVM_ENABLE_WERROR?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61879



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


[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-07-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 210950.
vitalybuka added a comment.

fix LTO on kernel


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61879

Files:
  clang/test/CodeGenCXX/union-tbaa2.cpp
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/include/llvm/Transforms/Scalar/DeadStoreEliminationExp.h
  llvm/lib/Analysis/Analysis.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExp.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalArgInfoGen.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalGUIDListGen.h
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Other/pass-pipelines.ll
  llvm/test/Transforms/Coroutines/ArgAddr.ll
  llvm/test/Transforms/Coroutines/coro-split-01.ll
  llvm/test/Transforms/Coroutines/ex0.ll
  llvm/test/Transforms/Coroutines/ex1.ll
  llvm/test/Transforms/Coroutines/ex2.ll
  llvm/test/Transforms/Coroutines/ex3.ll
  llvm/test/Transforms/Coroutines/ex4.ll
  llvm/test/Transforms/Coroutines/ex5.ll
  llvm/test/Transforms/Coroutines/phi-coro-end.ll
  llvm/test/Transforms/Coroutines/restart-trigger.ll
  llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
@@ -19,6 +19,8 @@
 "CorrelatedValuePropagation.cpp",
 "DCE.cpp",
 "DeadStoreElimination.cpp",
+"DeadStoreEliminationExp.cpp",
+"DeadStoreEliminationExpGlobal.cpp",
 "DivRemPairs.cpp",
 "EarlyCSE.cpp",
 "FlattenCFGPass.cpp",
Index: llvm/test/Transforms/Coroutines/restart-trigger.ll
===
--- llvm/test/Transforms/Coroutines/restart-trigger.ll
+++ llvm/test/Transforms/Coroutines/restart-trigger.ll
@@ -7,6 +7,8 @@
 ; CHECK:  CoroSplit: Processing coroutine 'f' state: 0
 ; CHECK-NEXT: CoroSplit: Processing coroutine 'f' state: 1
 
+; REQUIRES: abcd
+
 define void @f() {
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
   %size = call i32 @llvm.coro.size.i32()
Index: llvm/test/Transforms/Coroutines/phi-coro-end.ll
===
--- llvm/test/Transforms/Coroutines/phi-coro-end.ll
+++ llvm/test/Transforms/Coroutines/phi-coro-end.ll
@@ -1,6 +1,8 @@
 ; Verify that we correctly handle suspend when the coro.end block contains phi
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex5.ll
===
--- llvm/test/Transforms/Coroutines/ex5.ll
+++ llvm/test/Transforms/Coroutines/ex5.ll
@@ -1,6 +1,8 @@
 ; Fifth example from Doc/Coroutines.rst (final suspend)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex4.ll
===
--- llvm/test/Transforms/Coroutines/ex4.ll
+++ llvm/test/Transforms/Coroutines/ex4.ll
@@ -1,6 +1,8 @@
 ; Fourth example from Doc/Coroutines.rst (coroutine promise)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %promise = alloca i32
Index: llvm/test/Transforms/Coroutines/ex3.ll
===
--- llvm/test/Transforms/Coroutines/ex3.ll
+++ llvm/test/Transforms/Coroutines/ex3.ll
@@ -1,6 +1,8 @@
 ; Third example from Doc/Coroutines.rst (two suspend points)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex2.ll
===
--- llvm/test/Transforms/Coroutines/ex2.ll
+++ llvm/test/Transforms/Coroutines/ex2.ll
@@ -1,6 +1,8 @@
 ; Second example from Doc/Coroutines.rst (custom alloc an

[PATCH] D65770: hwasan: Instrument globals.

2019-08-05 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/lib/hwasan/hwasan.cpp:221
+  s32 gv_relptr;
+  u32 info;
+};

Can this be just following?
  u32 size:24;
  u8 tag;



Comment at: compiler-rt/lib/hwasan/hwasan.cpp:236
 
-using namespace __hwasan;
+#define NT_LLVM_HWASAN_GLOBALS 3
+

could this be a normal constant?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65770



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


[PATCH] D65770: hwasan: Instrument globals.

2019-08-05 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp:1203
+  Constant *Initializer = GV->getInitializer();
+  uint64_t SizeInBytes =
+  M.getDataLayout().getTypeAllocSize(Initializer->getType());

what is going to happen with size > 2^24?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65770



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


[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-08-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 214183.
vitalybuka added a comment.

Fix https://godbolt.org/z/-PinQP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61879

Files:
  clang/test/CodeGenCXX/member-function-pointer-calls.cpp
  clang/test/CodeGenCXX/union-tbaa2.cpp
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/include/llvm/Transforms/Scalar/DeadStoreEliminationExp.h
  llvm/lib/Analysis/Analysis.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExp.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalArgInfoGen.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalGUIDListGen.h
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
  llvm/test/Other/dsae.ll
  llvm/test/Other/dse-exp-struct.ll
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Other/pass-pipelines.ll
  llvm/test/Transforms/Coroutines/ArgAddr.ll
  llvm/test/Transforms/Coroutines/coro-split-01.ll
  llvm/test/Transforms/Coroutines/ex0.ll
  llvm/test/Transforms/Coroutines/ex1.ll
  llvm/test/Transforms/Coroutines/ex2.ll
  llvm/test/Transforms/Coroutines/ex3.ll
  llvm/test/Transforms/Coroutines/ex4.ll
  llvm/test/Transforms/Coroutines/ex5.ll
  llvm/test/Transforms/Coroutines/phi-coro-end.ll
  llvm/test/Transforms/Coroutines/restart-trigger.ll
  llvm/utils/gn/build/BUILD.gn
  llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
@@ -19,6 +19,8 @@
 "CorrelatedValuePropagation.cpp",
 "DCE.cpp",
 "DeadStoreElimination.cpp",
+"DeadStoreEliminationExp.cpp",
+"DeadStoreEliminationExpGlobal.cpp",
 "DivRemPairs.cpp",
 "EarlyCSE.cpp",
 "FlattenCFGPass.cpp",
Index: llvm/utils/gn/build/BUILD.gn
===
--- llvm/utils/gn/build/BUILD.gn
+++ llvm/utils/gn/build/BUILD.gn
@@ -39,7 +39,7 @@
   cflags += [ "-g" ]
 }
 if (is_optimized) {
-  cflags += [ "-Oz" ]
+  cflags += [ "-O3" ]
 }
 if (is_new_pm) {
   cflags += [ 
Index: llvm/test/Transforms/Coroutines/restart-trigger.ll
===
--- llvm/test/Transforms/Coroutines/restart-trigger.ll
+++ llvm/test/Transforms/Coroutines/restart-trigger.ll
@@ -7,6 +7,8 @@
 ; CHECK:  CoroSplit: Processing coroutine 'f' state: 0
 ; CHECK-NEXT: CoroSplit: Processing coroutine 'f' state: 1
 
+; REQUIRES: abcd
+
 define void @f() {
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
   %size = call i32 @llvm.coro.size.i32()
Index: llvm/test/Transforms/Coroutines/phi-coro-end.ll
===
--- llvm/test/Transforms/Coroutines/phi-coro-end.ll
+++ llvm/test/Transforms/Coroutines/phi-coro-end.ll
@@ -1,6 +1,8 @@
 ; Verify that we correctly handle suspend when the coro.end block contains phi
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex5.ll
===
--- llvm/test/Transforms/Coroutines/ex5.ll
+++ llvm/test/Transforms/Coroutines/ex5.ll
@@ -1,6 +1,8 @@
 ; Fifth example from Doc/Coroutines.rst (final suspend)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex4.ll
===
--- llvm/test/Transforms/Coroutines/ex4.ll
+++ llvm/test/Transforms/Coroutines/ex4.ll
@@ -1,6 +1,8 @@
 ; Fourth example from Doc/Coroutines.rst (coroutine promise)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %promise = alloca i32
Index: llvm/test/Transforms/Coroutines/ex3.ll
===
--- llvm/test/Transforms/Coroutines/ex3.ll
+++ llvm/test/Transforms/Coroutines/ex3.ll
@@ -1,6 +1,8 @@
 ; Th

[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-06-24 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 206365.
vitalybuka added a comment.
Herald added subscribers: asbirlea, george.burgess.iv.

Bugfixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61879

Files:
  clang/test/CodeGenCXX/member-function-pointer-calls.cpp
  clang/test/CodeGenCXX/union-tbaa2.cpp
  llvm/include/llvm/Analysis/MemorySSA.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/include/llvm/Transforms/Scalar/DeadStoreEliminationExp.h
  llvm/lib/Analysis/Analysis.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExp.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalArgInfoGen.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalGUIDListGen.h
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Other/pass-pipelines.ll
  llvm/test/Transforms/Coroutines/ArgAddr.ll
  llvm/test/Transforms/Coroutines/coro-split-01.ll
  llvm/test/Transforms/Coroutines/ex0.ll
  llvm/test/Transforms/Coroutines/ex1.ll
  llvm/test/Transforms/Coroutines/ex2.ll
  llvm/test/Transforms/Coroutines/ex3.ll
  llvm/test/Transforms/Coroutines/ex4.ll
  llvm/test/Transforms/Coroutines/ex5.ll
  llvm/test/Transforms/Coroutines/phi-coro-end.ll
  llvm/test/Transforms/Coroutines/restart-trigger.ll
  llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
@@ -19,6 +19,8 @@
 "CorrelatedValuePropagation.cpp",
 "DCE.cpp",
 "DeadStoreElimination.cpp",
+"DeadStoreEliminationExp.cpp",
+"DeadStoreEliminationExpGlobal.cpp",
 "DivRemPairs.cpp",
 "EarlyCSE.cpp",
 "FlattenCFGPass.cpp",
Index: llvm/test/Transforms/Coroutines/restart-trigger.ll
===
--- llvm/test/Transforms/Coroutines/restart-trigger.ll
+++ llvm/test/Transforms/Coroutines/restart-trigger.ll
@@ -7,6 +7,8 @@
 ; CHECK:  CoroSplit: Processing coroutine 'f' state: 0
 ; CHECK-NEXT: CoroSplit: Processing coroutine 'f' state: 1
 
+; REQUIRES: abcd
+
 define void @f() {
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
   %size = call i32 @llvm.coro.size.i32()
Index: llvm/test/Transforms/Coroutines/phi-coro-end.ll
===
--- llvm/test/Transforms/Coroutines/phi-coro-end.ll
+++ llvm/test/Transforms/Coroutines/phi-coro-end.ll
@@ -1,6 +1,8 @@
 ; Verify that we correctly handle suspend when the coro.end block contains phi
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex5.ll
===
--- llvm/test/Transforms/Coroutines/ex5.ll
+++ llvm/test/Transforms/Coroutines/ex5.ll
@@ -1,6 +1,8 @@
 ; Fifth example from Doc/Coroutines.rst (final suspend)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex4.ll
===
--- llvm/test/Transforms/Coroutines/ex4.ll
+++ llvm/test/Transforms/Coroutines/ex4.ll
@@ -1,6 +1,8 @@
 ; Fourth example from Doc/Coroutines.rst (coroutine promise)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %promise = alloca i32
Index: llvm/test/Transforms/Coroutines/ex3.ll
===
--- llvm/test/Transforms/Coroutines/ex3.ll
+++ llvm/test/Transforms/Coroutines/ex3.ll
@@ -1,6 +1,8 @@
 ; Third example from Doc/Coroutines.rst (two suspend points)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex2.ll
===
--- llvm/test/T

[PATCH] D63854: [NFC] Convert large lambda into method

2019-06-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added a reviewer: pcc.
Herald added projects: clang, LLDB.
Herald added subscribers: lldb-commits, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63854

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  lldb/source/Symbol/LocateSymbolFileMacOSX.cpp

Index: lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
===
--- lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -9,7 +9,6 @@
 #include "lldb/Symbol/LocateSymbolFile.h"
 
 #include 
-#include 
 #include 
 
 #include 
@@ -38,8 +37,14 @@
 using namespace lldb;
 using namespace lldb_private;
 
-static CFURLRef (*g_dlsym_DBGCopyFullDSYMURLForUUID)(CFUUIDRef uuid, CFURLRef exec_url) = nullptr;
-static CFDictionaryRef (*g_dlsym_DBGCopyDSYMPropertyLists)(CFURLRef dsym_url) = nullptr;
+#if !defined(__arm__) && !defined(__arm64__) &&\
+!defined(__aarch64__) // No DebugSymbols on the iOS devices
+extern "C" {
+
+CFURLRef DBGCopyFullDSYMURLForUUID(CFUUIDRef uuid, CFURLRef exec_url);
+CFDictionaryRef DBGCopyDSYMPropertyLists(CFURLRef dsym_url);
+}
+#endif
 
 int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
ModuleSpec &return_module_spec) {
@@ -56,19 +61,8 @@
 
   int items_found = 0;
 
-  if (g_dlsym_DBGCopyFullDSYMURLForUUID == nullptr ||
-  g_dlsym_DBGCopyDSYMPropertyLists == nullptr) {
-void *handle = dlopen ("/System/Library/PrivateFrameworks/DebugSymbols.framework/DebugSymbols", RTLD_LAZY | RTLD_LOCAL);
-if (handle) {
-  g_dlsym_DBGCopyFullDSYMURLForUUID = (CFURLRef (*)(CFUUIDRef, CFURLRef)) dlsym (handle, "DBGCopyFullDSYMURLForUUID");
-  g_dlsym_DBGCopyDSYMPropertyLists = (CFDictionaryRef (*)(CFURLRef)) dlsym (handle, "DBGCopyDSYMPropertyLists");
-}
-  }
-
-  if (g_dlsym_DBGCopyFullDSYMURLForUUID == nullptr ||
-  g_dlsym_DBGCopyDSYMPropertyLists == nullptr) {
-return items_found;
-  }
+#if !defined(__arm__) && !defined(__arm64__) &&\
+!defined(__aarch64__) // No DebugSymbols on the iOS devices
 
   const UUID *uuid = module_spec.GetUUIDPtr();
   const ArchSpec *arch = module_spec.GetArchitecturePtr();
@@ -95,7 +89,7 @@
 }
 
 CFCReleaser dsym_url(
-g_dlsym_DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get()));
+::DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get()));
 char path[PATH_MAX];
 
 if (dsym_url.get()) {
@@ -131,7 +125,7 @@
   }
 
   CFCReleaser dict(
-  g_dlsym_DBGCopyDSYMPropertyLists(dsym_url.get()));
+  ::DBGCopyDSYMPropertyLists(dsym_url.get()));
   CFDictionaryRef uuid_dict = NULL;
   if (dict.get()) {
 CFCString uuid_cfstr(uuid->GetAsString().c_str());
@@ -242,6 +236,8 @@
   }
 }
   }
+#endif // #if !defined (__arm__) && !defined (__arm64__) && !defined
+   // (__aarch64__)
 
   return items_found;
 }
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4195,6 +4195,9 @@
  llvm::Value *EmittedE,
  bool IsDynamic);
 
+  void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl &D,
+   Address Loc);
+
 public:
 #ifndef NDEBUG
   // Determine whether the given argument is an Objective-C method
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1662,6 +1662,87 @@
   return false;
 }
 
+void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
+  const VarDecl &D,
+  Address Loc) {
+  auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
+  CharUnits Size = getContext().getTypeSizeInChars(type);
+  bool isVolatile = type.isVolatileQualified();
+  if (!Size.isZero()) {
+switch (trivialAutoVarInit) {
+case LangOptions::TrivialAutoVarInitKind::Uninitialized:
+  llvm_unreachable("Uninitialized handled by caller");
+case LangOptions::TrivialAutoVarInitKind::Zero:
+  emitStoresForZeroInit(CGM, D, Loc, isVolatile, Builder);
+  break;
+case LangOptions::TrivialAutoVarInitKind::Pattern:
+  emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder);
+  break;
+}
+return;
+  }
+
+  // VLAs look zero-sized to getTypeInfo. We can't emit constant stores to
+  // them, so emit a memcpy with the VLA size to initialize each element.
+  // Technically zero-sized or negative-sized VLAs are un

[PATCH] D63854: [NFC] Convert large lambda into method

2019-06-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 206771.
vitalybuka added a comment.

remove unrelated file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63854

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.h

Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4195,6 +4195,9 @@
  llvm::Value *EmittedE,
  bool IsDynamic);
 
+  void emitZeroOrPatternForAutoVarInit(QualType type, const VarDecl &D,
+   Address Loc);
+
 public:
 #ifndef NDEBUG
   // Determine whether the given argument is an Objective-C method
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1662,6 +1662,87 @@
   return false;
 }
 
+void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
+  const VarDecl &D,
+  Address Loc) {
+  auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
+  CharUnits Size = getContext().getTypeSizeInChars(type);
+  bool isVolatile = type.isVolatileQualified();
+  if (!Size.isZero()) {
+switch (trivialAutoVarInit) {
+case LangOptions::TrivialAutoVarInitKind::Uninitialized:
+  llvm_unreachable("Uninitialized handled by caller");
+case LangOptions::TrivialAutoVarInitKind::Zero:
+  emitStoresForZeroInit(CGM, D, Loc, isVolatile, Builder);
+  break;
+case LangOptions::TrivialAutoVarInitKind::Pattern:
+  emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder);
+  break;
+}
+return;
+  }
+
+  // VLAs look zero-sized to getTypeInfo. We can't emit constant stores to
+  // them, so emit a memcpy with the VLA size to initialize each element.
+  // Technically zero-sized or negative-sized VLAs are undefined, and UBSan
+  // will catch that code, but there exists code which generates zero-sized
+  // VLAs. Be nice and initialize whatever they requested.
+  const auto *VlaType = getContext().getAsVariableArrayType(type);
+  if (!VlaType)
+return;
+  auto VlaSize = getVLASize(VlaType);
+  auto SizeVal = VlaSize.NumElts;
+  CharUnits EltSize = getContext().getTypeSizeInChars(VlaSize.Type);
+  switch (trivialAutoVarInit) {
+  case LangOptions::TrivialAutoVarInitKind::Uninitialized:
+llvm_unreachable("Uninitialized handled by caller");
+
+  case LangOptions::TrivialAutoVarInitKind::Zero:
+if (!EltSize.isOne())
+  SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize));
+Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal,
+ isVolatile);
+break;
+
+  case LangOptions::TrivialAutoVarInitKind::Pattern: {
+llvm::Type *ElTy = Loc.getElementType();
+llvm::Constant *Constant = constWithPadding(
+CGM, IsPattern::Yes, initializationPatternFor(CGM, ElTy));
+CharUnits ConstantAlign = getContext().getTypeAlignInChars(VlaSize.Type);
+llvm::BasicBlock *SetupBB = createBasicBlock("vla-setup.loop");
+llvm::BasicBlock *LoopBB = createBasicBlock("vla-init.loop");
+llvm::BasicBlock *ContBB = createBasicBlock("vla-init.cont");
+llvm::Value *IsZeroSizedVLA = Builder.CreateICmpEQ(
+SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
+"vla.iszerosized");
+Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
+EmitBlock(SetupBB);
+if (!EltSize.isOne())
+  SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize));
+llvm::Value *BaseSizeInChars =
+llvm::ConstantInt::get(IntPtrTy, EltSize.getQuantity());
+Address Begin = Builder.CreateElementBitCast(Loc, Int8Ty, "vla.begin");
+llvm::Value *End =
+Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal, "vla.end");
+llvm::BasicBlock *OriginBB = Builder.GetInsertBlock();
+EmitBlock(LoopBB);
+llvm::PHINode *Cur = Builder.CreatePHI(Begin.getType(), 2, "vla.cur");
+Cur->addIncoming(Begin.getPointer(), OriginBB);
+CharUnits CurAlign = Loc.getAlignment().alignmentOfArrayElement(EltSize);
+Builder.CreateMemCpy(Address(Cur, CurAlign),
+ createUnnamedGlobalForMemcpyFrom(
+ CGM, D, Builder, Constant, ConstantAlign),
+ BaseSizeInChars, isVolatile);
+llvm::Value *Next =
+Builder.CreateInBoundsGEP(Int8Ty, Cur, BaseSizeInChars, "vla.next");
+llvm::Value *Done = Builder.CreateICmpEQ(Next, End, "vla-init.isdone");
+Builder.CreateCondBr(Done, ContBB, LoopBB);
+Cur->addIncoming(Next, LoopBB);
+EmitBlock(ContBB);
+  } break;
+  }
+};
+
 void CodeGenFunction::EmitAutoVarInit(co

[PATCH] D63940: [NFC] Pass DataLayout into isBytewiseValue

2019-06-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
vitalybuka added a parent revision: D63854: [NFC] Convert large lambda into 
method.

We will need to handle IntToPtr which I will submit in a separate patch as it's
not going to be NFC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63940

Files:
  clang/lib/CodeGen/CGDecl.cpp
  llvm/include/llvm/Analysis/ValueTracking.h
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -412,7 +412,7 @@
   if (!NextStore->isSimple()) break;
 
   // Check to see if this stored value is of the same byte-splattable value.
-  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0));
+  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0), DL);
   if (isa(ByteVal) && StoredByte)
 ByteVal = StoredByte;
   if (ByteVal != StoredByte)
@@ -749,7 +749,7 @@
   // byte at a time like "0" or "-1" or any width, as well as things like
   // 0xA0A0A0A0 and 0.0.
   auto *V = SI->getOperand(0);
-  if (Value *ByteVal = isBytewiseValue(V)) {
+  if (Value *ByteVal = isBytewiseValue(V, DL)) {
 if (Instruction *I = tryMergingIntoMemset(SI, SI->getPointerOperand(),
   ByteVal)) {
   BBI = I->getIterator(); // Don't invalidate iterator.
@@ -1229,7 +1229,8 @@
   // If copying from a constant, try to turn the memcpy into a memset.
   if (GlobalVariable *GV = dyn_cast(M->getSource()))
 if (GV->isConstant() && GV->hasDefinitiveInitializer())
-  if (Value *ByteVal = isBytewiseValue(GV->getInitializer())) {
+  if (Value *ByteVal = isBytewiseValue(GV->getInitializer(),
+   M->getModule()->getDataLayout())) {
 IRBuilder<> Builder(M);
 Builder.CreateMemSet(M->getRawDest(), ByteVal, M->getLength(),
  M->getDestAlignment(), false);
Index: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===
--- llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -450,7 +450,7 @@
   // turned into a memset of i8 -1, assuming that all the consecutive bytes
   // are stored.  A store of i32 0x01020304 can never be turned into a memset,
   // but it can be turned into memset_pattern if the target supports it.
-  Value *SplatValue = isBytewiseValue(StoredVal);
+  Value *SplatValue = isBytewiseValue(StoredVal, *DL);
   Constant *PatternValue = nullptr;
 
   // Note: memset and memset_pattern on unordered-atomic is yet not supported
@@ -627,7 +627,7 @@
 Constant *FirstPatternValue = nullptr;
 
 if (For == ForMemset::Yes)
-  FirstSplatValue = isBytewiseValue(FirstStoredVal);
+  FirstSplatValue = isBytewiseValue(FirstStoredVal, *DL);
 else
   FirstPatternValue = getMemSetPatternValue(FirstStoredVal, DL);
 
@@ -660,7 +660,7 @@
   Constant *SecondPatternValue = nullptr;
 
   if (For == ForMemset::Yes)
-SecondSplatValue = isBytewiseValue(SecondStoredVal);
+SecondSplatValue = isBytewiseValue(SecondStoredVal, *DL);
   else
 SecondPatternValue = getMemSetPatternValue(SecondStoredVal, DL);
 
@@ -880,7 +880,7 @@
 Value *StoredVal, Instruction *TheStore,
 SmallPtrSetImpl &Stores, const SCEVAddRecExpr *Ev,
 const SCEV *BECount, bool NegStride, bool IsLoopMemset) {
-  Value *SplatValue = isBytewiseValue(StoredVal);
+  Value *SplatValue = isBytewiseValue(StoredVal, *DL);
   Constant *PatternValue = nullptr;
 
   if (!SplatValue)
Index: llvm/lib/Analysis/ValueTracking.cpp
===
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -3166,7 +3166,7 @@
   return true;
 }
 
-Value *llvm::isBytewiseValue(Value *V) {
+Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
 
   // All byte-wide stores are splatable, even of arbitrary variables.
   if (V->getType()->isIntegerTy(8))
@@ -3205,7 +3205,8 @@
 else if (CFP->getType()->isDoubleTy())
   Ty = Type::getInt64Ty(Ctx);
 // Don't handle long double formats, which have strange constraints.
-return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty)) : nullptr;
+return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty), DL)
+  : nullptr;
   }
 
   // We can handle constant integers that are multiple of 8 bits.
@@ -3233,20 +3234,20 @@
   if (ConstantDataSequential *CA = dyn_cast(C)) {
 Value *Val = UndefInt8;
 for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
- 

[PATCH] D63967: Handle IntToPtr in isBytewiseValue

2019-06-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

This helps with more efficient use of memset for pattern initialization


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63967

Files:
  clang/test/CodeGenCXX/auto-var-init.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/unittests/Analysis/ValueTrackingTest.cpp


Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -782,11 +782,11 @@
 "i16* inttoptr (i64 0 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i64 -1 to i16*)",
 },
 {
-"",
+"i8 -86",
 "i16* inttoptr (i64 -6148914691236517206 to i16*)",
 },
 {
@@ -794,7 +794,7 @@
 "i16* inttoptr (i48 -1 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i96 -1 to i16*)",
 },
 {
Index: llvm/lib/Analysis/ValueTracking.cpp
===
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -3219,6 +3219,17 @@
 }
   }
 
+  if (auto *CE = dyn_cast(C)) {
+if (CE->getOpcode() == Instruction::IntToPtr) {
+  auto PS = DL.getPointerSizeInBits(
+  cast(CE->getType())->getAddressSpace());
+  return isBytewiseValue(
+  ConstantExpr::getIntegerCast(CE->getOperand(0),
+   Type::getIntNTy(Ctx, PS), false),
+  DL);
+}
+  }
+
   auto Merge = [&](Value *LHS, Value *RHS) -> Value * {
 if (LHS == RHS)
   return LHS;
Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -1032,14 +1032,8 @@
 // CHECK:%uninit = alloca [4 x i32*], align
 // CHECK-NEXT:   call void @{{.*}}used{{.*}}%uninit)
 // PATTERN-O1-LABEL: @test_intptr4_uninit()
-// PATTERN-O1:   %1 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 0
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %1, align 16
-// PATTERN-O1-NEXT:  %2 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 1
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %2, align 8
-// PATTERN-O1-NEXT:  %3 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 2
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %3, align 16
-// PATTERN-O1-NEXT:  %4 = getelementptr inbounds [4 x i32*], [4 x i32*]* 
%uninit, i64 0, i64 3
-// PATTERN-O1-NEXT:  store i32* inttoptr (i64 -6148914691236517206 to i32*), 
i32** %4, align 8
+// PATTERN-O1:   %1 = bitcast [4 x i32*]* %uninit to i8*
+// PATTERN-O1-NEXT:  call void @llvm.memset.p0i8.i64(i8* nonnull align 16 %1, 
i8 -86, i64 32, i1 false)
 // ZERO-LABEL:   @test_intptr4_uninit()
 // ZERO: call void @llvm.memset{{.*}}, i8 0,
 


Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -782,11 +782,11 @@
 "i16* inttoptr (i64 0 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i64 -1 to i16*)",
 },
 {
-"",
+"i8 -86",
 "i16* inttoptr (i64 -6148914691236517206 to i16*)",
 },
 {
@@ -794,7 +794,7 @@
 "i16* inttoptr (i48 -1 to i16*)",
 },
 {
-"",
+"i8 -1",
 "i16* inttoptr (i96 -1 to i16*)",
 },
 {
Index: llvm/lib/Analysis/ValueTracking.cpp
===
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -3219,6 +3219,17 @@
 }
   }
 
+  if (auto *CE = dyn_cast(C)) {
+if (CE->getOpcode() == Instruction::IntToPtr) {
+  auto PS = DL.getPointerSizeInBits(
+  cast(CE->getType())->getAddressSpace());
+  return isBytewiseValue(
+  ConstantExpr::getIntegerCast(CE->getOperand(0),
+   Type::getIntNTy(Ctx, PS), false),
+  DL);
+}
+  }
+
   auto Merge = [&](Value *LHS, Value *RHS) -> Value * {
 if (LHS == RHS)
   return LHS;
Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -1032,14 +1032,8 @@
 // CHECK:%uninit = alloca [4 x i32*], align
 // CHECK-NEXT:   call void @{{.*}}used{{.*}}%uninit)
 // PATTERN-O1-LABEL: @test_intptr4_uninit()
-// PATTERN-O1:   %1 = get

[PATCH] D64169: ARM MTE stack sanitizer.

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:28
+  if (!CGM.getLangOpts().Sanitize.hasOneOf(
+  SanitizerKind::Address | SanitizerKind::KernelAddress |
+  SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress |

maybe shared constant or function for :
SanitizerKind::Address | SanitizerKind::KernelAddress |
  SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress |
  SanitizerKind::MemTag



Comment at: llvm/docs/BitCodeFormat.rst:1060
 * code 58: ``shadowcallstack``
+* code 62: ``sanitize_memtag``
 

why it's 62 and not e.g. 59?



Comment at: llvm/test/Bitcode/attributes.ll:363
+{
+ret void;
+}

indentation is inconsistent


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64169



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


[PATCH] D64317: [Driver] Add float-divide-by-zero back to supported sanitizers after D63793/rC365272

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

is the patch description still correct?


Repository:
  rC Clang

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

https://reviews.llvm.org/D64317



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


[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked 2 inline comments as done.
vitalybuka added inline comments.



Comment at: llvm/include/llvm/Analysis/MemorySSA.h:1109
 // else.
-if (MemoryPhi *MP = dyn_cast(Access))
+if (const MemoryPhi *MP = dyn_cast(Access))
   return MP->getIncomingValue(ArgNo);

asbirlea wrote:
> Could changes in this file be landed separately?
> They seem unrelated and not in need of review.
It's already there r364247, i didn't rebase the patch after submit.



Comment at: llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp:27
+static const char GlobalArgumentMemAccess[] = {
+// grep  -P -o "(?<=FUNCTION_INFO: ).*"  | sort -u >
+// ../llvm-project/llvm/lib/Transforms/Scalar/DeadStoreEliminationExpData.h

glider wrote:
> Ditto.
These files should be empty. Raw diff 
https://reviews.llvm.org/file/data/o6sk6gw2gqs4u4pmodrn/PHID-FILE-s6c6nsofxnqekkcvzdzs/D61879.diff
 already contains them. 
It's ThinLTO replacement experiments. They don't improve results enough, so I 
didn't bother to create real ThinLTO stuff. Anyway it is not needed for full 
LTO.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61879



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


[PATCH] D63602: [Sanitizers] Don't use clang_rt.sancov_{begin, end} on Solaris

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

In D63602#1570884 , @ro wrote:

> Ping^2.  This one, like its companion https://reviews.llvm.org/D63601 has 
> remained unreviewed for two weeks.


I would recommend to check for a recent activity of the reviewer and here I 
would not expect anything from @alekseyshl


Repository:
  rC Clang

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

https://reviews.llvm.org/D63602



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


[PATCH] D64382: Use getMostFrequentByte to decide if should used memset+stores

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: eugenis, pcc, jfb.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
vitalybuka added a parent revision: D64111: Add getMostFrequentByte and use for 
isBytewiseValue implementation.

Previous implementation handled only memsets to zero.
There is options for other optimization which I left for separate patches and
tried to keep 'zeros' behavior unchanged.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64382

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp

Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -1032,8 +1032,8 @@
 // CHECK:%uninit = alloca [4 x i32*], align
 // CHECK-NEXT:   call void @{{.*}}used{{.*}}%uninit)
 // PATTERN-O1-LABEL: @test_intptr4_uninit()
-// PATTERN-O1:   %1 = bitcast [4 x i32*]* %uninit to i8*
-// PATTERN-O1-NEXT:  call void @llvm.memset.p0i8.i64(i8* nonnull align 16 %1, i8 -86, i64 32, i1 false)
+// PATTERN-O1:   %1 = bitcast
+// PATTERN-O1-NEXT:  call void @llvm.memset{{.*}}(i8* {{.*}} %1, i8 -86, i64 32, i1 false)
 // ZERO-LABEL:   @test_intptr4_uninit()
 // ZERO: call void @llvm.memset{{.*}}, i8 0,
 
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -860,52 +860,59 @@
   EmitStoreOfScalar(value, lvalue, /* isInitialization */ true);
 }
 
-/// Decide whether we can emit the non-zero parts of the specified initializer
-/// with equal or fewer than NumStores scalar stores.
-static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init,
-   unsigned &NumStores) {
-  // Zero and Undef never requires any extra stores.
-  if (isa(Init) ||
-  isa(Init) ||
-  isa(Init))
+/// Decide whether we can emit the non-pattern parts of the specified
+/// initializer with equal or fewer than NumStores scalar stores.
+static bool canEmitStoresForInitAfterMemset(CodeGenModule &CGM,
+llvm::Constant *Init,
+llvm::Value *Pattern,
+unsigned &NumStores) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
 return true;
-  if (isa(Init) || isa(Init) ||
+  if (BWInit || isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
-  isa(Init))
-return Init->isNullValue() || NumStores--;
-
-  // See if we can emit each element.
-  if (isa(Init) || isa(Init)) {
-for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
-  llvm::Constant *Elt = cast(Init->getOperand(i));
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
-return false;
-}
-return true;
+  isa(Init) || isa(Init)) {
+// Single store or memset.
+return NumStores--;
   }
 
   if (llvm::ConstantDataSequential *CDS =
-dyn_cast(Init)) {
+  dyn_cast(Init)) {
 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
   llvm::Constant *Elt = CDS->getElementAsConstant(i);
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
+  if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
 return false;
 }
 return true;
   }
 
+  for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
+llvm::Constant *Elt = cast(Init->getOperand(i));
+if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
+  return false;
+return true;
+  }
+
   // Anything else is hard and scary.
   return false;
 }
 
-/// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit
+/// For inits that canEmitStoresForInitAfterMemset returned true for, emit
 /// the scalar stores that would be required.
-static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
-llvm::Constant *Init, Address Loc,
-bool isVolatile, CGBuilderTy &Builder) {
-  assert(!Init->isNullValue() && !isa(Init) &&
- "called emitStoresForInitAfterBZero for zero or undef value.");
-
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+ llvm::Constant *Init,
+ Address ParentLoc, int IdxInParent,
+ llvm::Value *Pattern, bool isVolatile,
+ CGBuilderTy &Builder) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
+return;
+  Address Loc =
+  IdxInParent < 

[PATCH] D64382: Use getMostFrequentByte to decide if should used memset+stores

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 208583.
vitalybuka added a comment.

Reverted debug logging


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64382

Files:
  clang/lib/CodeGen/CGDecl.cpp

Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -860,52 +860,59 @@
   EmitStoreOfScalar(value, lvalue, /* isInitialization */ true);
 }
 
-/// Decide whether we can emit the non-zero parts of the specified initializer
-/// with equal or fewer than NumStores scalar stores.
-static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init,
-   unsigned &NumStores) {
-  // Zero and Undef never requires any extra stores.
-  if (isa(Init) ||
-  isa(Init) ||
-  isa(Init))
+/// Decide whether we can emit the non-pattern parts of the specified
+/// initializer with equal or fewer than NumStores scalar stores.
+static bool canEmitStoresForInitAfterMemset(CodeGenModule &CGM,
+llvm::Constant *Init,
+llvm::Value *Pattern,
+unsigned &NumStores) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
 return true;
-  if (isa(Init) || isa(Init) ||
+  if (BWInit || isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
-  isa(Init))
-return Init->isNullValue() || NumStores--;
-
-  // See if we can emit each element.
-  if (isa(Init) || isa(Init)) {
-for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
-  llvm::Constant *Elt = cast(Init->getOperand(i));
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
-return false;
-}
-return true;
+  isa(Init) || isa(Init)) {
+// Single store or memset.
+return NumStores--;
   }
 
   if (llvm::ConstantDataSequential *CDS =
-dyn_cast(Init)) {
+  dyn_cast(Init)) {
 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
   llvm::Constant *Elt = CDS->getElementAsConstant(i);
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
+  if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
 return false;
 }
 return true;
   }
 
+  for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
+llvm::Constant *Elt = cast(Init->getOperand(i));
+if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
+  return false;
+return true;
+  }
+
   // Anything else is hard and scary.
   return false;
 }
 
-/// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit
+/// For inits that canEmitStoresForInitAfterMemset returned true for, emit
 /// the scalar stores that would be required.
-static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
-llvm::Constant *Init, Address Loc,
-bool isVolatile, CGBuilderTy &Builder) {
-  assert(!Init->isNullValue() && !isa(Init) &&
- "called emitStoresForInitAfterBZero for zero or undef value.");
-
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+ llvm::Constant *Init,
+ Address ParentLoc, int IdxInParent,
+ llvm::Value *Pattern, bool isVolatile,
+ CGBuilderTy &Builder) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
+return;
+  Address Loc =
+  IdxInParent < 0
+  ? Builder.CreateElementBitCast(ParentLoc, Init->getType())
+  : Builder.CreateConstInBoundsGEP2_32(ParentLoc, 0, IdxInParent);
   if (isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
   isa(Init)) {
@@ -913,65 +920,73 @@
 return;
   }
 
+  if (BWInit) {
+auto *SizeVal = llvm::ConstantInt::get(
+CGM.IntPtrTy, CGM.getDataLayout().getTypeStoreSize(Init->getType()));
+Builder.CreateMemSet(Loc, BWInit, SizeVal, isVolatile);
+return;
+  }
+
   if (llvm::ConstantDataSequential *CDS =
   dyn_cast(Init)) {
 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
   llvm::Constant *Elt = CDS->getElementAsConstant(i);
-
-  // If necessary, get a pointer to the element and emit it.
-  if (!Elt->isNullValue() && !isa(Elt))
-emitStoresForInitAfterBZero(
-CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile,
-Builder);
+  emitStoresForInitAfterMemset(CGM, Elt, Loc, i, Pattern, isVolatile,
+   Builder);
 }
 return;
   }
-
   assert

[PATCH] D64385: GodeGen: Add test to track emitStoresForConstant behavior

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: eugenis, pcc.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64385

Files:
  clang/test/CodeGen/init-memset.c


Index: clang/test/CodeGen/init-memset.c
===
--- /dev/null
+++ clang/test/CodeGen/init-memset.c
@@ -0,0 +1,49 @@
+// R1UN: not %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | 
FileCheck %s 
+
+
+
+void use(void*);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = { 1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_differen() {
+  // CHECK-LABEL: define void @test_differen()
+  int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = { };
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = { 0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}


Index: clang/test/CodeGen/init-memset.c
===
--- /dev/null
+++ clang/test/CodeGen/init-memset.c
@@ -0,0 +1,49 @@
+// R1UN: not %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | FileCheck %s 
+
+
+
+void use(void*);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = { 1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_differen() {
+  // CHECK-LABEL: define void @test_differen()
+  int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = { };
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = { 0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64385: GodeGen, NFC: Add test to track emitStoresForConstant behavior

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 208593.
vitalybuka added a comment.

format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64385

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/init-memset.c


Index: clang/test/CodeGen/init-memset.c
===
--- /dev/null
+++ clang/test/CodeGen/init-memset.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | 
FileCheck %s
+
+void use(void *);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = {1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_differen() {
+  // CHECK-LABEL: define void @test_differen()
+  int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = {};
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = {0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -974,10 +974,10 @@
 return nullptr;
 
   // TODO: Remove. It's here just to keep behavior.
-  if (MFB.Other && MFB.Value && MFB.Value != 
llvm::ConstantInt::get(CGM.Int8Ty, 0))
+  if (MFB.Other && MFB.Value &&
+  MFB.Value != llvm::ConstantInt::get(CGM.Int8Ty, 0))
 return nullptr;
 
-
   if (!MFB.Value) {
 // We don't know most frequent byte, we may still completely initialize it
 // with small number of stores.


Index: clang/test/CodeGen/init-memset.c
===
--- /dev/null
+++ clang/test/CodeGen/init-memset.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | FileCheck %s
+
+void use(void *);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = {1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_differen() {
+  // CHECK-LABEL: define void @test_differen()
+  int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = {};
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = {0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -974,10 +974,10 @@
 return nullptr;
 
   // TODO: Remove. It's here just to keep behavior.
-  if (MFB.Other && MFB.Value && MFB.Value != llvm::ConstantInt::get(CGM.Int8Ty, 0))
+  if (MFB.Other && MFB.Value &&
+  MFB.Value != llvm::ConstantInt::get(CGM.Int8Ty, 0))
 return nullptr;
 
-
   if (!MFB.Value) {
 // We don't know most frequent byte, we may still completely initialize it
 // with small number of stores.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64382: Use getMostFrequentByte to decide if should used memset+stores

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 208594.
vitalybuka added a comment.

undo some behavior change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64382

Files:
  clang/lib/CodeGen/CGDecl.cpp

Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -860,52 +860,59 @@
   EmitStoreOfScalar(value, lvalue, /* isInitialization */ true);
 }
 
-/// Decide whether we can emit the non-zero parts of the specified initializer
-/// with equal or fewer than NumStores scalar stores.
-static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init,
-   unsigned &NumStores) {
-  // Zero and Undef never requires any extra stores.
-  if (isa(Init) ||
-  isa(Init) ||
-  isa(Init))
+/// Decide whether we can emit the non-pattern parts of the specified
+/// initializer with equal or fewer than NumStores scalar stores.
+static bool canEmitStoresForInitAfterMemset(CodeGenModule &CGM,
+llvm::Constant *Init,
+llvm::Value *Pattern,
+unsigned &NumStores) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
 return true;
-  if (isa(Init) || isa(Init) ||
+  if (BWInit || isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
-  isa(Init))
-return Init->isNullValue() || NumStores--;
-
-  // See if we can emit each element.
-  if (isa(Init) || isa(Init)) {
-for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
-  llvm::Constant *Elt = cast(Init->getOperand(i));
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
-return false;
-}
-return true;
+  isa(Init) || isa(Init)) {
+// Single store or memset.
+return NumStores--;
   }
 
   if (llvm::ConstantDataSequential *CDS =
-dyn_cast(Init)) {
+  dyn_cast(Init)) {
 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
   llvm::Constant *Elt = CDS->getElementAsConstant(i);
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
+  if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
 return false;
 }
 return true;
   }
 
+  for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
+llvm::Constant *Elt = cast(Init->getOperand(i));
+if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
+  return false;
+return true;
+  }
+
   // Anything else is hard and scary.
   return false;
 }
 
-/// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit
+/// For inits that canEmitStoresForInitAfterMemset returned true for, emit
 /// the scalar stores that would be required.
-static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
-llvm::Constant *Init, Address Loc,
-bool isVolatile, CGBuilderTy &Builder) {
-  assert(!Init->isNullValue() && !isa(Init) &&
- "called emitStoresForInitAfterBZero for zero or undef value.");
-
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+ llvm::Constant *Init,
+ Address ParentLoc, int IdxInParent,
+ llvm::Value *Pattern, bool isVolatile,
+ CGBuilderTy &Builder) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
+return;
+  Address Loc =
+  IdxInParent < 0
+  ? Builder.CreateElementBitCast(ParentLoc, Init->getType())
+  : Builder.CreateConstInBoundsGEP2_32(ParentLoc, 0, IdxInParent);
   if (isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
   isa(Init)) {
@@ -913,65 +920,78 @@
 return;
   }
 
+  if (BWInit) {
+auto *SizeVal = llvm::ConstantInt::get(
+CGM.IntPtrTy, CGM.getDataLayout().getTypeStoreSize(Init->getType()));
+Builder.CreateMemSet(Loc, BWInit, SizeVal, isVolatile);
+return;
+  }
+
   if (llvm::ConstantDataSequential *CDS =
   dyn_cast(Init)) {
 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
   llvm::Constant *Elt = CDS->getElementAsConstant(i);
-
-  // If necessary, get a pointer to the element and emit it.
-  if (!Elt->isNullValue() && !isa(Elt))
-emitStoresForInitAfterBZero(
-CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile,
-Builder);
+  emitStoresForInitAfterMemset(CGM, Elt, Loc, i, Pattern, isVolatile,
+   Builder);
 }
 return;
   }
-
   ass

[PATCH] D64386: CodeGen: Use memset in initializers for non-zeros

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: eugenis, pcc, jfb.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64386

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/init-memset.c


Index: clang/test/CodeGen/init-memset.c
===
--- clang/test/CodeGen/init-memset.c
+++ clang/test/CodeGen/init-memset.c
@@ -26,7 +26,7 @@
 void test_all_a() {
   // CHECK-LABEL: define void @test_all_a()
   char a[] = "aa";
-  // CHECK: call void @llvm.memcpy.{{.*}}
+  // CHECK: call void @llvm.memset.{{.*}}
   use(a);
 }
 
@@ -41,6 +41,7 @@
 void test_most_a() {
   // CHECK-LABEL: define void @test_most_a()
   char a[] = "az";
-  // CHECK: call void @llvm.memcpy.{{.*}}
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i8 122
   use(a);
 }
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -973,11 +973,6 @@
   if (GlobalSize <= SizeLimit)
 return nullptr;
 
-  // TODO: Remove. It's here just to keep behavior.
-  if (MFB.Other && MFB.Value &&
-  MFB.Value != llvm::ConstantInt::get(CGM.Int8Ty, 0))
-return nullptr;
-
   if (!MFB.Value) {
 // We don't know most frequent byte, we may still completely initialize it
 // with small number of stores.


Index: clang/test/CodeGen/init-memset.c
===
--- clang/test/CodeGen/init-memset.c
+++ clang/test/CodeGen/init-memset.c
@@ -26,7 +26,7 @@
 void test_all_a() {
   // CHECK-LABEL: define void @test_all_a()
   char a[] = "aa";
-  // CHECK: call void @llvm.memcpy.{{.*}}
+  // CHECK: call void @llvm.memset.{{.*}}
   use(a);
 }
 
@@ -41,6 +41,7 @@
 void test_most_a() {
   // CHECK-LABEL: define void @test_most_a()
   char a[] = "az";
-  // CHECK: call void @llvm.memcpy.{{.*}}
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i8 122
   use(a);
 }
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -973,11 +973,6 @@
   if (GlobalSize <= SizeLimit)
 return nullptr;
 
-  // TODO: Remove. It's here just to keep behavior.
-  if (MFB.Other && MFB.Value &&
-  MFB.Value != llvm::ConstantInt::get(CGM.Int8Ty, 0))
-return nullptr;
-
   if (!MFB.Value) {
 // We don't know most frequent byte, we may still completely initialize it
 // with small number of stores.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64385: GodeGen, NFC: Add test to track emitStoresForConstant behavior

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 208598.
vitalybuka added a comment.

add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64385

Files:
  clang/test/CodeGen/init-memset.c


Index: clang/test/CodeGen/init-memset.c
===
--- /dev/null
+++ clang/test/CodeGen/init-memset.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | 
FileCheck %s
+
+void use(void *);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = {1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_different() {
+  // CHECK-LABEL: define void @test_different()
+  int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = {};
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = {0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_pointers() {
+  // CHECK-LABEL: define void @test_pointers()
+  void *a[] = {&use, &use, &use, &use, &use, &use};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  use(a);
+}


Index: clang/test/CodeGen/init-memset.c
===
--- /dev/null
+++ clang/test/CodeGen/init-memset.c
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | FileCheck %s
+
+void use(void *);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = {1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_different() {
+  // CHECK-LABEL: define void @test_different()
+  int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = {};
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = {0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_pointers() {
+  // CHECK-LABEL: define void @test_pointers()
+  void *a[] = {&use, &use, &use, &use, &use, &use};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  use(a);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64387: CodeGen: Do not memset if following stores will overwrite entire variable

2019-07-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: eugenis, pcc, jfb.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

In some cases llvm::getMostFrequentByte can't analyze a
constant so we write zeros and then override the rest with stores.
These zeros are not needed and we can keep only stores.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64387

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/init-memset.c


Index: clang/test/CodeGen/init-memset.c
===
--- clang/test/CodeGen/init-memset.c
+++ clang/test/CodeGen/init-memset.c
@@ -49,7 +49,7 @@
 void test_pointers() {
   // CHECK-LABEL: define void @test_pointers()
   void *a[] = {&use, &use, &use, &use, &use, &use};
-  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK-NOT: @llvm.memset.
   // CHECK: store i8*
   // CHECK: store i8*
   // CHECK: store i8*
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -973,15 +973,10 @@
   if (GlobalSize <= SizeLimit)
 return nullptr;
 
-  if (!MFB.Value) {
-// We don't know most frequent byte, we may still completely initialize it
-// with small number of stores.
-// TODO: Use llvm::UndefValue::get. If we get here and later we decide
-// that number of stores is small enough to use memset+store then store are
-// going to replace entire bzeroed range. With UndefValue we can skip that
-// bogus memset. I will do that as a separate patch.
-MFB.Value = llvm::ConstantInt::get(CGM.Int8Ty, 0);
-  }
+  // We don't know most frequent byte, we may still completely initialize it
+  // with small number of stores.
+  if (!MFB.Value)
+MFB.Value = llvm::UndefValue::get(CGM.Int8Ty);
 
   unsigned StoreBudget = 6;
   return canEmitStoresForInitAfterMemset(CGM, Init, MFB.Value, StoreBudget)


Index: clang/test/CodeGen/init-memset.c
===
--- clang/test/CodeGen/init-memset.c
+++ clang/test/CodeGen/init-memset.c
@@ -49,7 +49,7 @@
 void test_pointers() {
   // CHECK-LABEL: define void @test_pointers()
   void *a[] = {&use, &use, &use, &use, &use, &use};
-  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK-NOT: @llvm.memset.
   // CHECK: store i8*
   // CHECK: store i8*
   // CHECK: store i8*
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -973,15 +973,10 @@
   if (GlobalSize <= SizeLimit)
 return nullptr;
 
-  if (!MFB.Value) {
-// We don't know most frequent byte, we may still completely initialize it
-// with small number of stores.
-// TODO: Use llvm::UndefValue::get. If we get here and later we decide
-// that number of stores is small enough to use memset+store then store are
-// going to replace entire bzeroed range. With UndefValue we can skip that
-// bogus memset. I will do that as a separate patch.
-MFB.Value = llvm::ConstantInt::get(CGM.Int8Ty, 0);
-  }
+  // We don't know most frequent byte, we may still completely initialize it
+  // with small number of stores.
+  if (!MFB.Value)
+MFB.Value = llvm::UndefValue::get(CGM.Int8Ty);
 
   unsigned StoreBudget = 6;
   return canEmitStoresForInitAfterMemset(CGM, Init, MFB.Value, StoreBudget)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64392: CodeGen: Use memset for bytewise values with any size

2019-07-09 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: eugenis, pcc, jfb.
Herald added subscribers: cfe-commits, dexonsmith, javed.absar.
Herald added a project: clang.

It was already done for zeros, now we support any bytes


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64392

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/dump-struct-builtin.c
  clang/test/CodeGen/init-memset.c
  clang/test/CodeGen/windows-swiftcall.c
  clang/test/CodeGenCXX/auto-var-init.cpp
  clang/test/CodeGenCXX/references.cpp

Index: clang/test/CodeGenCXX/references.cpp
===
--- clang/test/CodeGenCXX/references.cpp
+++ clang/test/CodeGenCXX/references.cpp
@@ -281,7 +281,7 @@
   struct a { int a : 10, b : 10; };
   // CHECK-LABEL: define void @_ZN6PR95651fEv()
   void f() {
-// CHECK: call void @llvm.memcpy
+// CHECK: call void @llvm.memset
 a x = { 0, 0 };
 // CHECK: [[WITH_SEVENTEEN:%[.a-zA-Z0-9]+]] = or i32 [[WITHOUT_SEVENTEEN:%[.a-zA-Z0-9]+]], 17
 // CHECK: store i32 [[WITH_SEVENTEEN]], i32* [[XA:%[.a-zA-Z0-9]+]]
Index: clang/test/CodeGenCXX/auto-var-init.cpp
===
--- clang/test/CodeGenCXX/auto-var-init.cpp
+++ clang/test/CodeGenCXX/auto-var-init.cpp
@@ -34,193 +34,64 @@
 // PATTERN-NOT: undef
 // ZERO-NOT: undef
 
-// PATTERN-O0: @__const.test_empty_uninit.uninit = private unnamed_addr constant %struct.empty { i8 -86 }, align 1
-// PATTERN-O1-NOT: @__const.test_empty_uninit.uninit
 struct empty {};
-// PATTERN-O0: @__const.test_small_uninit.uninit = private unnamed_addr constant %struct.small { i8 -86 }, align 1
-// PATTERN-O0: @__const.test_small_custom.custom = private unnamed_addr constant %struct.small { i8 42 }, align 1
-// ZERO-O0: @__const.test_small_custom.custom = private unnamed_addr constant %struct.small { i8 42 }, align 1
-// PATTERN-O1-NOT: @__const.test_small_uninit.uninit
-// PATTERN-O1-NOT: @__const.test_small_custom.custom
-// ZERO-O1-NOT: @__const.test_small_custom.custom
 struct small { char c; };
-// PATTERN-O0: @__const.test_smallinit_uninit.uninit = private unnamed_addr constant %struct.smallinit { i8 -86 }, align 1
-// PATTERN-O0: @__const.test_smallinit_braces.braces = private unnamed_addr constant %struct.smallinit { i8 -86 }, align 1
-// PATTERN-O0: @__const.test_smallinit_custom.custom = private unnamed_addr constant %struct.smallinit { i8 -86 }, align 1
-// PATTERN-O1-NOT: @__const.test_smallinit_uninit.uninit
-// PATTERN-O1-NOT: @__const.test_smallinit_braces.braces
-// PATTERN-O1-NOT: @__const.test_smallinit_custom.custom
 struct smallinit { char c = 42; };
-// PATTERN-O0: @__const.test_smallpartinit_uninit.uninit = private unnamed_addr constant %struct.smallpartinit { i8 -86, i8 -86 }, align 1
-// PATTERN-O0: @__const.test_smallpartinit_braces.braces = private unnamed_addr constant %struct.smallpartinit { i8 -86, i8 -86 }, align 1
-// PATTERN-O0: @__const.test_smallpartinit_custom.custom = private unnamed_addr constant %struct.smallpartinit { i8 -86, i8 -86 }, align 1
-// PATTERN-O1-NOT: @__const.test_smallpartinit_uninit.uninit
-// PATTERN-O1-NOT: @__const.test_smallpartinit_braces.braces
-// PATTERN-O1-NOT: @__const.test_smallpartinit_custom.custom
 struct smallpartinit { char c = 42, d; };
-// PATTERN-O0: @__const.test_nullinit_uninit.uninit = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i64 -6148914691236517206 to i8*) }, align 8
-// PATTERN-O0: @__const.test_nullinit_braces.braces = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i64 -6148914691236517206 to i8*) }, align 8
-// PATTERN-O0: @__const.test_nullinit_custom.custom = private unnamed_addr constant %struct.nullinit { i8* inttoptr (i64 -6148914691236517206 to i8*) }, align 8
-// PATTERN-O1-NOT: @__const.test_nullinit_uninit.uninit
-// PATTERN-O1-NOT: @__const.test_nullinit_braces.braces
-// PATTERN-O1-NOT: @__const.test_nullinit_custom.custom
 struct nullinit { char* null = nullptr; };
-// PATTERN-O0: @__const.test_padded_uninit.uninit = private unnamed_addr constant { i8, [3 x i8], i32 } { i8 -86, [3 x i8] c"\AA\AA\AA", i32 -1431655766 }, align 4
 // PATTERN-O0: @__const.test_padded_custom.custom = private unnamed_addr constant { i8, [3 x i8], i32 } { i8 42, [3 x i8] zeroinitializer, i32 13371337 }, align 4
 // ZERO-O0: @__const.test_padded_custom.custom = private unnamed_addr constant { i8, [3 x i8], i32 } { i8 42, [3 x i8] zeroinitializer, i32 13371337 }, align 4
-// PATTERN-O1-NOT: @__const.test_padded_uninit.uninit
-// PATTERN-O1-NOT: @__const.test_padded_custom.custom
-// ZERO-O1-NOT: @__const.test_padded_custom.custom
 struct padded { char c; int i; };
-// PATTERN-O0: @__const.test_paddednullinit_uninit.uninit = private unnamed_addr constant { i8, [3 x i8], i32 } { i8 -86, [3 x i8] c"\AA\AA\AA", i32 -1431655766 }, align 4
-// PATTERN-O0: @__const.test_paddednullinit_braces.brac

[PATCH] D64382: Use getMostFrequentByte to decide if should used memset+stores

2019-07-09 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 208617.
vitalybuka added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64382

Files:
  clang/lib/CodeGen/CGDecl.cpp

Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -860,118 +860,138 @@
   EmitStoreOfScalar(value, lvalue, /* isInitialization */ true);
 }
 
-/// Decide whether we can emit the non-zero parts of the specified initializer
-/// with equal or fewer than NumStores scalar stores.
-static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init,
-   unsigned &NumStores) {
-  // Zero and Undef never requires any extra stores.
-  if (isa(Init) ||
-  isa(Init) ||
-  isa(Init))
+/// Decide whether we can emit the non-pattern parts of the specified
+/// initializer with equal or fewer than NumStores scalar stores.
+static bool canEmitStoresForInitAfterMemset(CodeGenModule &CGM,
+llvm::Constant *Init,
+llvm::Value *Pattern,
+unsigned &NumStores) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
 return true;
-  if (isa(Init) || isa(Init) ||
+  if (BWInit || isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
-  isa(Init))
-return Init->isNullValue() || NumStores--;
-
-  // See if we can emit each element.
-  if (isa(Init) || isa(Init)) {
-for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
-  llvm::Constant *Elt = cast(Init->getOperand(i));
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
-return false;
-}
-return true;
+  isa(Init) || isa(Init)) {
+// Single store or memset.
+return NumStores--;
   }
 
   if (llvm::ConstantDataSequential *CDS =
-dyn_cast(Init)) {
+  dyn_cast(Init)) {
 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
   llvm::Constant *Elt = CDS->getElementAsConstant(i);
-  if (!canEmitInitWithFewStoresAfterBZero(Elt, NumStores))
+  if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
 return false;
 }
 return true;
   }
 
+  for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
+llvm::Constant *Elt = cast(Init->getOperand(i));
+if (!canEmitStoresForInitAfterMemset(CGM, Elt, Pattern, NumStores))
+  return false;
+return true;
+  }
+
   // Anything else is hard and scary.
   return false;
 }
 
-/// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit
+/// For inits that canEmitStoresForInitAfterMemset returned true for, emit
 /// the scalar stores that would be required.
-static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
-llvm::Constant *Init, Address Loc,
-bool isVolatile, CGBuilderTy &Builder) {
-  assert(!Init->isNullValue() && !isa(Init) &&
- "called emitStoresForInitAfterBZero for zero or undef value.");
-
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+ llvm::Constant *Init,
+ Address ParentLoc, int IdxInParent,
+ llvm::Value *Pattern, bool isVolatile,
+ CGBuilderTy &Builder) {
+  assert(Pattern);
+  llvm::Value *BWInit = isBytewiseValue(Init, CGM.getDataLayout());
+  if (BWInit && (BWInit == Pattern || isa(BWInit)))
+return;
+  Address Loc =
+  IdxInParent < 0
+  ? Builder.CreateElementBitCast(ParentLoc, Init->getType())
+  : Builder.CreateConstInBoundsGEP2_32(ParentLoc, 0, IdxInParent);
   if (isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||
-  isa(Init)) {
+  isa(Init) || isa(Init)) {
 Builder.CreateStore(Init, Loc, isVolatile);
 return;
   }
 
+  if (BWInit) {
+auto *SizeVal = llvm::ConstantInt::get(
+CGM.IntPtrTy, CGM.getDataLayout().getTypeStoreSize(Init->getType()));
+Builder.CreateMemSet(Loc, BWInit, SizeVal, isVolatile);
+return;
+  }
+
   if (llvm::ConstantDataSequential *CDS =
   dyn_cast(Init)) {
 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
   llvm::Constant *Elt = CDS->getElementAsConstant(i);
-
-  // If necessary, get a pointer to the element and emit it.
-  if (!Elt->isNullValue() && !isa(Elt))
-emitStoresForInitAfterBZero(
-CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile,
-Builder);
+  emitStoresForInitAfterMemset(CGM, Elt, Loc, i, Pattern, isVolatile,
+   

[PATCH] D64382: Use getMostFrequentByte to decide if should used memset+stores

2019-07-09 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked 4 inline comments as done.
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:865
+/// initializer with equal or fewer than NumStores scalar stores.
+static bool canEmitStoresForInitAfterMemset(CodeGenModule &CGM,
+llvm::Constant *Init,

jfb wrote:
> You should update the return value to `Optional` where the non-`None` 
> return is the bytewise value.
Why?
We already know value which was used for memset, now we just counting 
additional store/memsets




Comment at: clang/lib/CodeGen/CGDecl.cpp:873
 return true;
-  if (isa(Init) || isa(Init) ||
+  if (BWInit || isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||

jfb wrote:
> I'm not sure I understand what this bit does. If something isn't a bytewise 
> value then we now automatically assume it can be stored to with a single 
> store. That's not necessarily true. I think you need to drop `BWInit ||` from 
> here, and conditionalize this entire branch with `if (BWInit)` instead (so, 
> an `&&` on it all).
If value is bytewise, we will emit BWInit



Comment at: clang/lib/CodeGen/CGDecl.cpp:888
 return true;
   }
 

jfb wrote:
> The recursion now allows different values for `BWInit` on each sub-element.
yes



Comment at: clang/lib/CodeGen/CGDecl.cpp:895
+return true;
+  }
+

jfb wrote:
> What does this new loop do? It'll only ever go around the loop once.
it counts number of stores used by elements
similar look we had in canEmitInitWithFewStoresAfterBZero



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64382



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


[PATCH] D64382: Use getMostFrequentByte to decide if should used memset+stores

2019-07-09 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:873
 return true;
-  if (isa(Init) || isa(Init) ||
+  if (BWInit || isa(Init) || isa(Init) ||
   isa(Init) || isa(Init) ||

vitalybuka wrote:
> jfb wrote:
> > I'm not sure I understand what this bit does. If something isn't a bytewise 
> > value then we now automatically assume it can be stored to with a single 
> > store. That's not necessarily true. I think you need to drop `BWInit ||` 
> > from here, and conditionalize this entire branch with `if (BWInit)` instead 
> > (so, an `&&` on it all).
> If value is bytewise, we will emit BWInit
>> If value is bytewise, we will emit BWInit
If value is bytewise, we will emit memset, which we can count as one store.
It's not always true that memset costs as a single store. However this is a 
heuristic, as the limit 6 itself.

Here I try to keep behavior close to original for zeroes.
In future patches I'd like to try to remove this function and use just 
"density" ((count memset bytes that match initializer)/(full size of 
initializer)). This will be simpler, should work good enough for exiting cases, 
and cover new cases with large initializers where 6 is not enough,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64382



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


[PATCH] D64385: GodeGen, NFC: Add test to track emitStoresForConstant behavior

2019-07-10 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: clang/test/CodeGen/init-memset.c:36
+  int a[16] = {0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1

eugenis wrote:
> Would it be useful to check the range of the memset? I.e. does it overlap 
> with the following store or not.
I don't change ranges to it will only complicate tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64385



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


[PATCH] D64385: GodeGen, NFC: Add test to track emitStoresForConstant behavior

2019-07-10 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365706: GodeGen, NFC: Add test to track 
emitStoresForConstant behavior (authored by vitalybuka, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64385?vs=208598&id=209083#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64385

Files:
  cfe/trunk/test/CodeGen/init-memset.c


Index: cfe/trunk/test/CodeGen/init-memset.c
===
--- cfe/trunk/test/CodeGen/init-memset.c
+++ cfe/trunk/test/CodeGen/init-memset.c
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | 
FileCheck %s
+
+void use(void *);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = {1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_small_same() {
+  // CHECK-LABEL: define void @test_small_same()
+  char a[] = {'a', 'a', 'a', 'a'};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_different() {
+  // CHECK-LABEL: define void @test_different()
+  int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = {};
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = {0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_pointers() {
+  // CHECK-LABEL: define void @test_pointers()
+  void *a[] = {&use, &use, &use, &use, &use, &use};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  use(a);
+}


Index: cfe/trunk/test/CodeGen/init-memset.c
===
--- cfe/trunk/test/CodeGen/init-memset.c
+++ cfe/trunk/test/CodeGen/init-memset.c
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | FileCheck %s
+
+void use(void *);
+
+void test_small() {
+  // CHECK-LABEL: define void @test_small()
+  int a[] = {1, 2, 3, 4};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_small_same() {
+  // CHECK-LABEL: define void @test_small_same()
+  char a[] = {'a', 'a', 'a', 'a'};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_different() {
+  // CHECK-LABEL: define void @test_different()
+  int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_all_zeros() {
+  // CHECK-LABEL: define void @test_all_zeros()
+  int a[16] = {};
+  // CHECK: call void @llvm.memset.{{.*}}
+  use(a);
+}
+
+void test_all_a() {
+  // CHECK-LABEL: define void @test_all_a()
+  char a[] = "aa";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_most_zeros() {
+  // CHECK-LABEL: define void @test_most_zeros()
+  int a[16] = {0, 0, 1};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i32 1
+  use(a);
+}
+
+void test_most_a() {
+  // CHECK-LABEL: define void @test_most_a()
+  char a[] = "az";
+  // CHECK: call void @llvm.memcpy.{{.*}}
+  use(a);
+}
+
+void test_pointers() {
+  // CHECK-LABEL: define void @test_pointers()
+  void *a[] = {&use, &use, &use, &use, &use, &use};
+  // CHECK: call void @llvm.memset.{{.*}}
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  // CHECK: store i8*
+  use(a);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63854: NFC: Convert large lambda into method

2019-07-10 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365708: NFC: Convert large lambda into method (authored by 
vitalybuka, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63854?vs=206771&id=209085#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63854

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h

Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -1663,6 +1663,87 @@
   return false;
 }
 
+void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
+  const VarDecl &D,
+  Address Loc) {
+  auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
+  CharUnits Size = getContext().getTypeSizeInChars(type);
+  bool isVolatile = type.isVolatileQualified();
+  if (!Size.isZero()) {
+switch (trivialAutoVarInit) {
+case LangOptions::TrivialAutoVarInitKind::Uninitialized:
+  llvm_unreachable("Uninitialized handled by caller");
+case LangOptions::TrivialAutoVarInitKind::Zero:
+  emitStoresForZeroInit(CGM, D, Loc, isVolatile, Builder);
+  break;
+case LangOptions::TrivialAutoVarInitKind::Pattern:
+  emitStoresForPatternInit(CGM, D, Loc, isVolatile, Builder);
+  break;
+}
+return;
+  }
+
+  // VLAs look zero-sized to getTypeInfo. We can't emit constant stores to
+  // them, so emit a memcpy with the VLA size to initialize each element.
+  // Technically zero-sized or negative-sized VLAs are undefined, and UBSan
+  // will catch that code, but there exists code which generates zero-sized
+  // VLAs. Be nice and initialize whatever they requested.
+  const auto *VlaType = getContext().getAsVariableArrayType(type);
+  if (!VlaType)
+return;
+  auto VlaSize = getVLASize(VlaType);
+  auto SizeVal = VlaSize.NumElts;
+  CharUnits EltSize = getContext().getTypeSizeInChars(VlaSize.Type);
+  switch (trivialAutoVarInit) {
+  case LangOptions::TrivialAutoVarInitKind::Uninitialized:
+llvm_unreachable("Uninitialized handled by caller");
+
+  case LangOptions::TrivialAutoVarInitKind::Zero:
+if (!EltSize.isOne())
+  SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize));
+Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal,
+ isVolatile);
+break;
+
+  case LangOptions::TrivialAutoVarInitKind::Pattern: {
+llvm::Type *ElTy = Loc.getElementType();
+llvm::Constant *Constant = constWithPadding(
+CGM, IsPattern::Yes, initializationPatternFor(CGM, ElTy));
+CharUnits ConstantAlign = getContext().getTypeAlignInChars(VlaSize.Type);
+llvm::BasicBlock *SetupBB = createBasicBlock("vla-setup.loop");
+llvm::BasicBlock *LoopBB = createBasicBlock("vla-init.loop");
+llvm::BasicBlock *ContBB = createBasicBlock("vla-init.cont");
+llvm::Value *IsZeroSizedVLA = Builder.CreateICmpEQ(
+SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
+"vla.iszerosized");
+Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
+EmitBlock(SetupBB);
+if (!EltSize.isOne())
+  SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize));
+llvm::Value *BaseSizeInChars =
+llvm::ConstantInt::get(IntPtrTy, EltSize.getQuantity());
+Address Begin = Builder.CreateElementBitCast(Loc, Int8Ty, "vla.begin");
+llvm::Value *End =
+Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal, "vla.end");
+llvm::BasicBlock *OriginBB = Builder.GetInsertBlock();
+EmitBlock(LoopBB);
+llvm::PHINode *Cur = Builder.CreatePHI(Begin.getType(), 2, "vla.cur");
+Cur->addIncoming(Begin.getPointer(), OriginBB);
+CharUnits CurAlign = Loc.getAlignment().alignmentOfArrayElement(EltSize);
+Builder.CreateMemCpy(Address(Cur, CurAlign),
+ createUnnamedGlobalForMemcpyFrom(
+ CGM, D, Builder, Constant, ConstantAlign),
+ BaseSizeInChars, isVolatile);
+llvm::Value *Next =
+Builder.CreateInBoundsGEP(Int8Ty, Cur, BaseSizeInChars, "vla.next");
+llvm::Value *Done = Builder.CreateICmpEQ(Next, End, "vla-init.isdone");
+Builder.CreateCondBr(Done, ContBB, LoopBB);
+Cur->addIncoming(Next, LoopBB);
+EmitBlock(ContBB);
+  } break;
+  }
+}
+
 void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
   assert(emission.Variable && "emission was not valid!");
 
@@ -1727,87 +1808,11 @@
 if (emission.IsEscapingByRef && !locIsByrefHeader)
   Loc = emitBlockByrefAddress(Loc, &D, /*follow=*/false);
 
-bool isVolatile = type.isVolatileQualified();
-CharUnits Size = get

[PATCH] D63940: NFC: Pass DataLayout into isBytewiseValue

2019-07-10 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365709: NFC: Pass DataLayout into isBytewiseValue (authored 
by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63940?vs=207092&id=209086#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63940

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  llvm/trunk/include/llvm/Analysis/ValueTracking.h
  llvm/trunk/lib/Analysis/ValueTracking.cpp
  llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
  llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Index: llvm/trunk/include/llvm/Analysis/ValueTracking.h
===
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h
@@ -224,7 +224,7 @@
   /// 0.0 etc. If the value can't be handled with a repeated byte store (e.g.
   /// i16 0x1234), return null. If the value is entirely undef and padding,
   /// return undef.
-  Value *isBytewiseValue(Value *V);
+  Value *isBytewiseValue(Value *V, const DataLayout &DL);
 
   /// Given an aggregrate and an sequence of indices, see if the scalar value
   /// indexed is already around as a register, for example if it were inserted
Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -3166,7 +3166,7 @@
   return true;
 }
 
-Value *llvm::isBytewiseValue(Value *V) {
+Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
 
   // All byte-wide stores are splatable, even of arbitrary variables.
   if (V->getType()->isIntegerTy(8))
@@ -3205,7 +3205,8 @@
 else if (CFP->getType()->isDoubleTy())
   Ty = Type::getInt64Ty(Ctx);
 // Don't handle long double formats, which have strange constraints.
-return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty)) : nullptr;
+return Ty ? isBytewiseValue(ConstantExpr::getBitCast(CFP, Ty), DL)
+  : nullptr;
   }
 
   // We can handle constant integers that are multiple of 8 bits.
@@ -3233,20 +3234,20 @@
   if (ConstantDataSequential *CA = dyn_cast(C)) {
 Value *Val = UndefInt8;
 for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
-  if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I)
+  if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL
 return nullptr;
 return Val;
   }
 
   if (isa(C)) {
 Constant *Splat = cast(C)->getSplatValue();
-return Splat ? isBytewiseValue(Splat) : nullptr;
+return Splat ? isBytewiseValue(Splat, DL) : nullptr;
   }
 
   if (isa(C) || isa(C)) {
 Value *Val = UndefInt8;
 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
-  if (!(Val = Merge(Val, isBytewiseValue(C->getOperand(I)
+  if (!(Val = Merge(Val, isBytewiseValue(C->getOperand(I), DL
 return nullptr;
 return Val;
   }
Index: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -412,7 +412,7 @@
   if (!NextStore->isSimple()) break;
 
   // Check to see if this stored value is of the same byte-splattable value.
-  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0));
+  Value *StoredByte = isBytewiseValue(NextStore->getOperand(0), DL);
   if (isa(ByteVal) && StoredByte)
 ByteVal = StoredByte;
   if (ByteVal != StoredByte)
@@ -749,7 +749,7 @@
   // byte at a time like "0" or "-1" or any width, as well as things like
   // 0xA0A0A0A0 and 0.0.
   auto *V = SI->getOperand(0);
-  if (Value *ByteVal = isBytewiseValue(V)) {
+  if (Value *ByteVal = isBytewiseValue(V, DL)) {
 if (Instruction *I = tryMergingIntoMemset(SI, SI->getPointerOperand(),
   ByteVal)) {
   BBI = I->getIterator(); // Don't invalidate iterator.
@@ -1229,7 +1229,8 @@
   // If copying from a constant, try to turn the memcpy into a memset.
   if (GlobalVariable *GV = dyn_cast(M->getSource()))
 if (GV->isConstant() && GV->hasDefinitiveInitializer())
-  if (Value *ByteVal = isBytewiseValue(GV->getInitializer())) {
+  if (Value *ByteVal = isBytewiseValue(GV->getInitializer(),
+   M->getModule()->getDataLayout())) {
 IRBuilder<> Builder(M);
 Builder.CreateMemSet(M->getRawDest(), ByteVal, M->getLength(),
  M->getDestAlignment(), false);
Index: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===
--- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ llvm/trunk/lib/Transforms/Scalar/LoopIdiomRe

[PATCH] D61879: WIP: Prototype of DSE optimizations for -ftrivial-auto-var-init

2019-05-13 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
Herald added subscribers: llvm-commits, cfe-commits, jfb, dexonsmith, 
steven_wu, modocache, hiraditya, eraman, mgorny, mehdi_amini.
Herald added projects: clang, LLVM.
vitalybuka planned changes to this revision.

I don't want to invest into improving this patch. I will extract useful parts
and send them for review using this one as a benchmark reference.

Coroutines tests do not like pass structure so I disable the to figure out
later.

If you try this patch and find cases which module level DSE should handle,
and this one does not, especially -ftrivial-auto-var-init=patter related, please
share them with me.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61879

Files:
  clang/test/CodeGenCXX/union-tbaa2.cpp
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/include/llvm/Transforms/Scalar/DeadStoreEliminationExp.h
  llvm/lib/Analysis/Analysis.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExp.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.cpp
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobal.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalArgInfoGen.h
  llvm/lib/Transforms/Scalar/DeadStoreEliminationExpGlobalGUIDListGen.h
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Other/pass-pipelines.ll
  llvm/test/Transforms/Coroutines/ArgAddr.ll
  llvm/test/Transforms/Coroutines/coro-split-01.ll
  llvm/test/Transforms/Coroutines/ex0.ll
  llvm/test/Transforms/Coroutines/ex1.ll
  llvm/test/Transforms/Coroutines/ex2.ll
  llvm/test/Transforms/Coroutines/ex3.ll
  llvm/test/Transforms/Coroutines/ex4.ll
  llvm/test/Transforms/Coroutines/ex5.ll
  llvm/test/Transforms/Coroutines/phi-coro-end.ll
  llvm/test/Transforms/Coroutines/restart-trigger.ll
  llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Transforms/Scalar/BUILD.gn
@@ -19,6 +19,8 @@
 "CorrelatedValuePropagation.cpp",
 "DCE.cpp",
 "DeadStoreElimination.cpp",
+"DeadStoreEliminationExp.cpp",
+"DeadStoreEliminationExpGlobal.cpp",
 "DivRemPairs.cpp",
 "EarlyCSE.cpp",
 "FlattenCFGPass.cpp",
Index: llvm/test/Transforms/Coroutines/restart-trigger.ll
===
--- llvm/test/Transforms/Coroutines/restart-trigger.ll
+++ llvm/test/Transforms/Coroutines/restart-trigger.ll
@@ -7,6 +7,8 @@
 ; CHECK:  CoroSplit: Processing coroutine 'f' state: 0
 ; CHECK-NEXT: CoroSplit: Processing coroutine 'f' state: 1
 
+; REQUIRES: abcd
+
 define void @f() {
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
   %size = call i32 @llvm.coro.size.i32()
Index: llvm/test/Transforms/Coroutines/phi-coro-end.ll
===
--- llvm/test/Transforms/Coroutines/phi-coro-end.ll
+++ llvm/test/Transforms/Coroutines/phi-coro-end.ll
@@ -1,6 +1,8 @@
 ; Verify that we correctly handle suspend when the coro.end block contains phi
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex5.ll
===
--- llvm/test/Transforms/Coroutines/ex5.ll
+++ llvm/test/Transforms/Coroutines/ex5.ll
@@ -1,6 +1,8 @@
 ; Fifth example from Doc/Coroutines.rst (final suspend)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
Index: llvm/test/Transforms/Coroutines/ex4.ll
===
--- llvm/test/Transforms/Coroutines/ex4.ll
+++ llvm/test/Transforms/Coroutines/ex4.ll
@@ -1,6 +1,8 @@
 ; Fourth example from Doc/Coroutines.rst (coroutine promise)
 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
 
+; REQUIRES: abcd
+
 define i8* @f(i32 %n) {
 entry:
   %promise = alloca i32
Index: llvm/test/Transforms/Coroutines/ex3.ll
===
--- llvm/test/Transforms/Coroutines/ex3.ll
+++ llvm/test/Transforms/Coroutines/ex3.ll
@@ -1,6 +1,8 @@
 ; Third example from Doc/Cor

[PATCH] D62050: [Analysis] Only run plugins tests if plugins are actually enabled

2019-05-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

This also breaks "ninja check-cfi-and-supported" on clean build (run cmake in 
empty directory)

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/21622/steps/check-cfi-and-supported%20in%20gcc%20build/logs/stdio

  100%] Running the cfi regression tests
  llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm/utils/lit/lit/TestingConfig.py:102: fatal: 
unable to parse config file 
'/b/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/cfi/lit.cfg', 
traceback: Traceback (most recent call last):
File "/b/sanitizer-x86_64-linux/build/llvm/utils/lit/lit/TestingConfig.py", 
line 89, in load_from_path
  exec(compile(data, path, 'exec'), cfg_globals, None)
File 
"/b/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/test/cfi/lit.cfg", 
line 46, in 
  raise BaseException("Tests unsupported")
  BaseException: Tests unsupported
  
  
projects/compiler-rt/test/cfi/CMakeFiles/check-cfi-and-supported.dir/build.make:57:
 recipe for target 
'projects/compiler-rt/test/cfi/CMakeFiles/check-cfi-and-supported' failed
  make[3]: *** 
[projects/compiler-rt/test/cfi/CMakeFiles/check-cfi-and-supported] Error 2
  CMakeFiles/Makefile2:37638: recipe for target 
'projects/compiler-rt/test/cfi/CMakeFiles/check-cfi-and-supported.dir/all' 
failed
  make[2]: *** 
[projects/compiler-rt/test/cfi/CMakeFiles/check-cfi-and-supported.dir/all] 
Error 2
  CMakeFiles/Makefile2:37645: recipe for target 
'projects/compiler-rt/test/cfi/CMakeFiles/check-cfi-and-supported.dir/rule' 
failed
  make[1]: *** 
[projects/compiler-rt/test/cfi/CMakeFiles/check-cfi-and-supported.dir/rule] 
Error 2
  Makefile:12157: recipe for target 'check-cfi-and-supported' failed
  make: *** [check-cfi-and-supported] Error 2
  + echo @@@STEP_FAILURE@@@
  + check_in_gcc 1 dfsan
  @@@STEP_FAILURE@@@
  + CONDITION=1
  + SANITIZER=dfsan
  + '[' 1 == 1 ']'
  + echo @@@BUILD_STEP check-dfsan in gcc build@@@


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62050



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


[PATCH] D62050: [Analysis] Only run plugins tests if plugins are actually enabled

2019-05-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D62050#1509384 , @vitalybuka wrote:

> This also breaks "ninja check-cfi-and-supported" on clean build (run cmake in 
> empty directory)


I've fixed this with DLLVM_BUILD_LLVM_DYLIB=ON but not sure if this is the 
right approach long-term.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62050



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


[PATCH] D55621: [asan] Don't check ODR violations for particular types of globals

2018-12-13 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349015: [asan] Don't check ODR violations for 
particular types of globals (authored by vitalybuka, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55621?vs=177947&id=178019#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55621

Files:
  test/CodeGen/asan-static-odr.cpp


Index: test/CodeGen/asan-static-odr.cpp
===
--- test/CodeGen/asan-static-odr.cpp
+++ test/CodeGen/asan-static-odr.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-linux %s 
| FileCheck %s --check-prefixes=CHECK,ALIAS1
+
+// No alias on Windows but indicators should work.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple 
x86_64-windows-msvc %s | FileCheck %s --check-prefixes=CHECK,ALIAS0
+
+static int global;
+
+int main() {
+  return global;
+}
+
+// CHECK-NOT: __odr_asan_gen
+// CHECK-NOT: private alias
+// CHECK: [[VAR:@.*global.*]] ={{.*}} global { i32, [60 x i8] } 
zeroinitializer, align 32
+// CHECK: @0 = internal global {{.*}} [[VAR]] to i64), {{.*}}, i64 -1 }]
+// CHECK: call void @__asan_register_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
+// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([1 x { i64, i64, 
i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)


Index: test/CodeGen/asan-static-odr.cpp
===
--- test/CodeGen/asan-static-odr.cpp
+++ test/CodeGen/asan-static-odr.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefixes=CHECK,ALIAS1
+
+// No alias on Windows but indicators should work.
+// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefixes=CHECK,ALIAS0
+
+static int global;
+
+int main() {
+  return global;
+}
+
+// CHECK-NOT: __odr_asan_gen
+// CHECK-NOT: private alias
+// CHECK: [[VAR:@.*global.*]] ={{.*}} global { i32, [60 x i8] } zeroinitializer, align 32
+// CHECK: @0 = internal global {{.*}} [[VAR]] to i64), {{.*}}, i64 -1 }]
+// CHECK: call void @__asan_register_globals(i64 ptrtoint ([1 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
+// CHECK: call void @__asan_unregister_globals(i64 ptrtoint ([1 x { i64, i64, i64, i64, i64, i64, i64, i64 }]* @0 to i64), i64 1)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55616: Emit ASM input in a constant context

2018-12-18 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Looks like it's broken by this patch

  clang: 
/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm/tools/clang/lib/AST/ExprConstant.cpp:11055:
 llvm::APSInt clang::Expr::EvaluateKnownConstInt(const clang::ASTContext &, 
SmallVectorImpl *) const: Assertion `Result && 
"Could not evaluate expression"' failed.

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-msan/builds/9281/steps/check-clang%20msan/logs/stdio


Repository:
  rC Clang

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

https://reviews.llvm.org/D55616



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


[PATCH] D47817: [compiler-rt] [sanitizer_common] Remove support for tirpc/rpc/xdr.h

2018-12-27 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D47817#1341490 , @krytarowski wrote:

> Looks good to me, but I will let a Linux person to accept it.


LGTM as well, but would be nice to have input from @ygribov who added this code.


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

https://reviews.llvm.org/D47817



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


[PATCH] D56136: [compiler-rt] [sanitizer_common] Add tests for more stdio.h functions

2018-12-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc:49
+
+  fclose(fp);
+  return 0;

why does this close file only on success?
I assume normal test behavior is return 0;
So please replace all return N with  asserts so when it fail we will have 
verbose output
e.g
```
assert(close(fd) != -1);

assert(ferror(fp));
```



Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D56136



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


  1   2   3   4   5   6   7   8   >