llvm-project/clang/lib/Sema
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
..
AnalysisBasedWarnings.cpp Use the range-based overload of llvm::sort where possible 2022-07-23 15:13:25 +02:00
CMakeLists.txt [RISCV] Lazily add RVV C intrinsics. 2022-07-26 15:47:47 +08:00
CodeCompleteConsumer.cpp Argument name support for function pointer signature hints 2022-07-19 20:02:26 -04:00
CoroutineStmtBuilder.h
DeclSpec.cpp Revert "Rename llvm::array_lengthof into llvm::size to match std::size from C++17" 2022-01-26 16:55:53 +01:00
DelayedDiagnostic.cpp
HLSLExternalSemaSource.cpp [NFC][HLSL] Add tests for vector alias. Remove dead code. 2022-07-05 16:32:59 -05:00
IdentifierResolver.cpp Reland "[Clang][Sema] Fix invalid redefinition error in if/switch/for statement" 2022-04-21 01:18:58 +08:00
JumpDiagnostics.cpp [clang] Add range accessor for ObjCAtTryStmt catch_stmts and use it 2021-10-27 08:57:05 -04:00
MultiplexExternalSemaSource.cpp [clang][AST] Improve AST Reader/Writer memory footprint 2021-05-20 15:34:29 -07:00
OpenCLBuiltins.td [OpenCL] Fix atomic_fetch_add/sub half overloads 2022-06-17 09:53:45 +01:00
ParsedAttr.cpp [clang] Reject non-declaration C++11 attributes on declarations 2022-06-15 11:58:26 +02:00
Scope.cpp Revert D119136 "[clang] Implement Change scope of lambda trailing-return-type" and its follow-up 2022-04-20 10:57:12 -07:00
ScopeInfo.cpp [clang] Disallow mixing SEH and Objective-C exceptions 2021-10-20 14:18:12 -04:00
Sema.cpp [RISCV] Lazily add RVV C intrinsics. 2022-07-26 15:47:47 +08:00
SemaAccess.cpp [C++2b] Implement multidimentional subscript operator 2022-02-08 12:10:47 -05:00
SemaAttr.cpp [clang-cl] Handle some pragma alloc_text corner cases handled by MSVC 2022-06-29 06:45:59 -07:00
SemaAvailability.cpp [clang] Don't use Optional::getValue (NFC) 2022-06-20 22:59:26 -07:00
SemaCUDA.cpp [CUDA] remove duplicate condition 2022-07-22 11:27:19 -04:00
SemaCXXScopeSpec.cpp [C++20] [Module] Support reachable definition initially/partially 2022-06-29 12:48:48 +08:00
SemaCast.cpp [randstruct] Add randomize structure layout support 2022-04-09 13:15:36 -07:00
SemaChecking.cpp [clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible arrays 2022-07-18 12:45:52 +02:00
SemaCodeComplete.cpp Argument name support for function pointer signature hints 2022-07-19 20:02:26 -04:00
SemaConcept.cpp Revert "Re-apply "Deferred Concept Instantiation Implementation""" 2022-07-01 11:20:16 -07:00
SemaConsumer.cpp
SemaCoroutine.cpp [NFC] [Coroutines] Add test for ambiguous allocation functions in 2022-06-06 14:23:35 +08:00
SemaDecl.cpp [Clang] Fix how we set the NumPositiveBits on an EnumDecl to cover the case of single enumerator with value zero or an empty enum 2022-07-25 16:01:01 -07:00
SemaDeclAttr.cpp [clang] Use value instead of getValue (NFC) 2022-07-13 23:39:33 -07:00
SemaDeclCXX.cpp Revert "[clang] Implement ElaboratedType sugaring for types written bare" 2022-07-14 21:17:48 -07:00
SemaDeclObjC.cpp [clang] Don't use Optional::hasValue (NFC) 2022-06-20 10:51:34 -07:00
SemaExceptionSpec.cpp [OpenMP] Initial parsing and semantic support for 'parallel masked taskloop simd' construct 2022-07-01 08:57:15 -07:00
SemaExpr.cpp [Clang] De-deprecate volatile compound operations 2022-07-24 16:16:52 +02:00
SemaExprCXX.cpp Revert "[clang] Implement ElaboratedType sugaring for types written bare" 2022-07-14 21:17:48 -07:00
SemaExprMember.cpp Add some helpers to better check Scope's kind. NFC 2022-04-16 11:31:40 +08:00
SemaExprObjC.cpp Revert "[clang] Implement ElaboratedType sugaring for types written bare" 2022-07-14 21:17:48 -07:00
SemaFixItUtils.cpp [clang] NFC: Rename rvalue to prvalue 2021-06-09 12:27:10 +02:00
SemaInit.cpp [Clang] Rename StringLiteral::isAscii() => isOrdinary() [NFC] 2022-06-29 18:28:51 +02:00
SemaLambda.cpp [clang] Don't use Optional::getValue (NFC) 2022-06-20 22:59:26 -07:00
SemaLookup.cpp [RISCV] Lazily add RVV C intrinsics. 2022-07-26 15:47:47 +08:00
SemaModule.cpp re-land [C++20][Modules] Build module static initializers per P1874R1. 2022-07-22 08:38:07 +01:00
SemaObjCProperty.cpp [Clang][Sema] Fix attribute mismatch warning for ObjC class properties 2022-01-11 12:10:18 +00:00
SemaOpenMP.cpp [clang] Use value instead of getValue (NFC) 2022-07-13 23:39:33 -07:00
SemaOverload.cpp [C++20][Modules] Update ADL to handle basic.lookup.argdep p4 [P1815R2 part 1] 2022-07-25 14:28:59 +01:00
SemaPseudoObject.cpp [clang] NFC: Rename rvalue to prvalue 2021-06-09 12:27:10 +02:00
SemaRISCVVectorLookup.cpp [RISCV] Lazily add RVV C intrinsics. 2022-07-26 15:47:47 +08:00
SemaSYCL.cpp [SYCL] Diagnose uses of zero length arrays 2021-12-29 15:30:18 +03:00
SemaStmt.cpp [FPEnv] Allow CompoundStmt to keep FP options 2022-07-03 17:06:26 +07:00
SemaStmtAsm.cpp [Clang] Rename StringLiteral::isAscii() => isOrdinary() [NFC] 2022-06-29 18:28:51 +02:00
SemaStmtAttr.cpp [clang][parse] Move source range into ParsedAttibutesView 2022-03-24 08:11:57 +01:00
SemaTemplate.cpp [Sema] Merge C++20 concept definitions from different modules in same TU 2022-07-25 14:43:38 +02:00
SemaTemplateDeduction.cpp Revert "Re-apply "Deferred Concept Instantiation Implementation""" 2022-07-01 11:20:16 -07:00
SemaTemplateInstantiate.cpp Revert "Re-apply "Deferred Concept Instantiation Implementation""" 2022-07-01 11:20:16 -07:00
SemaTemplateInstantiateDecl.cpp [NFC] Start saving InstantiatedFromDecl in non-template functions 2022-07-22 12:37:14 -07:00
SemaTemplateVariadic.cpp Use range based for loop in Sema::CheckParameterPacksForExpansion. NFC 2022-04-22 13:31:31 +08:00
SemaType.cpp [C++20] [Modules] Handle reachability for enum class 2022-07-15 15:57:04 +08:00
TreeTransform.h Revert "[clang] Implement ElaboratedType sugaring for types written bare" 2022-07-14 21:17:48 -07:00
TypeLocBuilder.cpp Revert "[clang] Implement ElaboratedType sugaring for types written bare" 2022-07-14 21:17:48 -07:00
TypeLocBuilder.h Revert "[clang] Implement ElaboratedType sugaring for types written bare" 2022-07-14 21:17:48 -07:00
UsedDeclVisitor.h [HIP][OpenMP] Fix assertion in deferred diag 2021-10-25 11:07:40 -04:00