llvm-project/clang/lib
Kito Cheng 7a5cb15ea6 [RISCV] Lazily add RVV C intrinsics.
Leverage the method OpenCL uses that adds C intrinsics when the lookup
failed. There is no need to define C intrinsics in the header file any
more. It could help to avoid the large header file to speed up the
compilation of RVV source code. Besides that, only the C intrinsics used
by the users will be added into the declaration table.

This patch is based on https://reviews.llvm.org/D103228 and inspired by
OpenCL implementation.

### Experimental Results

#### TL;DR:

- Binary size of clang increase ~200k, which is +0.07%  for debug build and +0.13% for release build.
- Single file compilation speed up ~33x for debug build and ~8.5x for release build
- Regression time reduce ~10% (`ninja check-all`, enable all targets)

#### Header size change
```
       |      size |     LoC |
------------------------------
Before | 4,434,725 |  69,749 |
After  |     6,140 |     162 |
```

#### Single File Compilation Time
Testcase:
```
#include <riscv_vector.h>

vint32m1_t test_vadd_vv_vfloat32m1_t(vint32m1_t op1, vint32m1_t op2, size_t vl) {
  return vadd(op1, op2, vl);
}
```
##### Debug build:
Before:
```
real    0m19.352s
user    0m19.252s
sys     0m0.092s
```

After:
```
real    0m0.576s
user    0m0.552s
sys     0m0.024s
```

~33x speed up for debug build

##### Release build:
Before:
```
real    0m0.773s
user    0m0.741s
sys     0m0.032s
```

After:
```
real    0m0.092s
user    0m0.080s
sys     0m0.012s
```

~8.5x speed up for release build

#### Regression time
Note: the failed case is `tools/llvm-debuginfod-find/debuginfod.test` which is unrelated to this patch.

##### Debug build
Before:
```
Testing Time: 1358.38s
  Skipped          :    11
  Unsupported      :   446
  Passed           : 75767
  Expectedly Failed:   190
  Failed           :     1
```
After
```
Testing Time: 1220.29s
  Skipped          :    11
  Unsupported      :   446
  Passed           : 75767
  Expectedly Failed:   190
  Failed           :     1
```
##### Release build
Before:
```
Testing Time: 381.98s
  Skipped          :    12
  Unsupported      :  1407
  Passed           : 74765
  Expectedly Failed:   176
  Failed           :     1
```
After:
```
Testing Time: 346.25s
  Skipped          :    12
  Unsupported      :  1407
  Passed           : 74765
  Expectedly Failed:   176
  Failed           :     1
```

#### Binary size of clang

##### Debug build
Before
```
   text    data     bss     dec     hex filename
335261851       12726004         552812 348540667       14c64efb        bin/clang
```
After
```
   text    data     bss     dec     hex filename
335442803       12798708         552940 348794451       14ca2e53        bin/clang
```
+253K, +0.07% code size

##### Release build
Before
```
   text    data     bss     dec     hex filename
144123975       8374648  483140 152981763       91e5103 bin/clang
```
After
```
   text    data     bss     dec     hex filename
144255762       8447296  483268 153186326       9217016 bin/clang
```
+204K, +0.13%

Authored-by: Kito Cheng <kito.cheng@sifive.com>
Co-Authored-by: Hsiangkai Wang <kai.wang@sifive.com>

Reviewed By: khchen, aaron.ballman

Differential Revision: https://reviews.llvm.org/D111617
2022-07-26 15:47:47 +08:00
..
APINotes
ARCMigrate Revert "[clang] Implement ElaboratedType sugaring for types written bare" 2022-07-14 21:17:48 -07:00
AST [C++20] [Modules] Make the linkage consistent for class template and its 2022-07-25 17:57:02 +08:00
ASTMatchers Adds AST matcher for ObjCStringLiteral 2022-06-30 15:20:10 -07:00
Analysis [analyzer] Lambda capture non-POD type array 2022-07-26 09:40:25 +02:00
Basic Remove redundaunt virtual specifiers (NFC) 2022-07-25 23:00:59 -07:00
CodeGen Remove redundaunt virtual specifiers (NFC) 2022-07-25 23:00:59 -07:00
CrossTU [clang][NFC][AST] rename the ImportError to ASTImportError 2022-06-15 00:40:32 +05:30
DirectoryWatcher [clang] Don't use Optional::hasValue (NFC) 2022-06-20 10:51:34 -07:00
Driver [Driver] Ignore unimplemented -mtune= for ARM/PowerPC 2022-07-25 15:05:38 -07:00
Edit Use any_of (NFC) 2022-07-24 14:48:11 -07:00
ExtractAPI [NFC] Start saving InstantiatedFromDecl in non-template functions 2022-07-22 12:37:14 -07:00
Format [clang-format] Fix a hang when formatting C# $@ string literals 2022-07-25 23:17:54 -07:00
Frontend Use the range-based overload of llvm::sort where possible 2022-07-23 15:13:25 +02:00
FrontendTool [C++20][Modules][HU 1/5] Introduce header units as a module type. 2022-03-25 09:17:14 +00:00
Headers Use `<stdatomic.h>` with MSVC and C++ 2022-07-25 19:00:29 +02:00
Index [AST] Improve traversal of concepts and concept requirements 2022-04-28 09:33:26 +00:00
IndexSerialization
Interpreter [clang] Remove unused forward declarations (NFC) 2022-07-24 20:51:06 -07:00
Lex [Clang] Adjust extension warnings for #warning 2022-07-23 14:10:11 +02:00
Parse [RISCV] Lazily add RVV C intrinsics. 2022-07-26 15:47:47 +08:00
Rewrite Add assert on End iteration distance to Rewriter::getRewrittenText. 2022-01-25 17:26:13 +00:00
Sema [RISCV] Lazily add RVV C intrinsics. 2022-07-26 15:47:47 +08:00
Serialization [NFC] Start saving InstantiatedFromDecl in non-template functions 2022-07-22 12:37:14 -07:00
StaticAnalyzer [analyzer] Lambda capture non-POD type array 2022-07-26 09:40:25 +02:00
Support [RISCV] Lazily add RVV C intrinsics. 2022-07-26 15:47:47 +08:00
Testing [include-cleaner] Include-cleaner library structure, and simplistic AST walking. 2022-04-29 11:04:11 +02:00
Tooling [Tooling/DependencyScanning] Enable passing a `vfs::FileSystem` object to `DependencyScanningTool` 2022-07-18 09:37:17 -07:00
CMakeLists.txt [RISCV] Moving RVV intrinsic type related util to clang/Support 2022-04-20 21:13:13 +08:00