[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-13 15:52:17 +08:00
|
|
|
//==- SemaRISCVVectorLookup.cpp - Name Lookup for RISC-V Vector Intrinsic -==//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements name lookup for RISC-V vector intrinsic.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/Basic/Builtins.h"
|
|
|
|
#include "clang/Basic/TargetInfo.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "clang/Sema/Lookup.h"
|
|
|
|
#include "clang/Sema/RISCVIntrinsicManager.h"
|
|
|
|
#include "clang/Sema/Sema.h"
|
|
|
|
#include "clang/Support/RISCVVIntrinsicUtils.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::RISCV;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Function definition of a RVV intrinsic.
|
|
|
|
struct RVVIntrinsicDef {
|
|
|
|
/// Full function name with suffix, e.g. vadd_vv_i32m1.
|
|
|
|
std::string Name;
|
|
|
|
|
|
|
|
/// Overloaded function name, e.g. vadd.
|
|
|
|
std::string OverloadName;
|
|
|
|
|
|
|
|
/// Mapping to which clang built-in function, e.g. __builtin_rvv_vadd.
|
|
|
|
std::string BuiltinName;
|
|
|
|
|
|
|
|
/// Function signature, first element is return type.
|
|
|
|
RVVTypes Signature;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RVVOverloadIntrinsicDef {
|
|
|
|
// Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
|
|
|
|
SmallVector<size_t, 8> Indexes;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
static const PrototypeDescriptor RVVSignatureTable[] = {
|
|
|
|
#define DECL_SIGNATURE_TABLE
|
|
|
|
#include "clang/Basic/riscv_vector_builtin_sema.inc"
|
|
|
|
#undef DECL_SIGNATURE_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
static const RVVIntrinsicRecord RVVIntrinsicRecords[] = {
|
|
|
|
#define DECL_INTRINSIC_RECORDS
|
|
|
|
#include "clang/Basic/riscv_vector_builtin_sema.inc"
|
|
|
|
#undef DECL_INTRINSIC_RECORDS
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get subsequence of signature table.
|
|
|
|
static ArrayRef<PrototypeDescriptor> ProtoSeq2ArrayRef(uint16_t Index,
|
|
|
|
uint8_t Length) {
|
2023-01-06 16:56:23 +01:00
|
|
|
return ArrayRef(&RVVSignatureTable[Index], Length);
|
[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-13 15:52:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static QualType RVVType2Qual(ASTContext &Context, const RVVType *Type) {
|
|
|
|
QualType QT;
|
|
|
|
switch (Type->getScalarType()) {
|
|
|
|
case ScalarTypeKind::Void:
|
|
|
|
QT = Context.VoidTy;
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::Size_t:
|
|
|
|
QT = Context.getSizeType();
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::Ptrdiff_t:
|
|
|
|
QT = Context.getPointerDiffType();
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::UnsignedLong:
|
|
|
|
QT = Context.UnsignedLongTy;
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::SignedLong:
|
|
|
|
QT = Context.LongTy;
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::Boolean:
|
|
|
|
QT = Context.BoolTy;
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::SignedInteger:
|
|
|
|
QT = Context.getIntTypeForBitwidth(Type->getElementBitwidth(), true);
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::UnsignedInteger:
|
|
|
|
QT = Context.getIntTypeForBitwidth(Type->getElementBitwidth(), false);
|
|
|
|
break;
|
|
|
|
case ScalarTypeKind::Float:
|
|
|
|
switch (Type->getElementBitwidth()) {
|
|
|
|
case 64:
|
|
|
|
QT = Context.DoubleTy;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
QT = Context.FloatTy;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
QT = Context.Float16Ty;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported floating point width.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Invalid:
|
|
|
|
llvm_unreachable("Unhandled type.");
|
|
|
|
}
|
|
|
|
if (Type->isVector())
|
2022-12-17 19:47:45 +00:00
|
|
|
QT = Context.getScalableVectorType(QT, *Type->getScale());
|
[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-13 15:52:17 +08:00
|
|
|
|
|
|
|
if (Type->isConstant())
|
|
|
|
QT = Context.getConstType(QT);
|
|
|
|
|
|
|
|
// Transform the type to a pointer as the last step, if necessary.
|
|
|
|
if (Type->isPointer())
|
|
|
|
QT = Context.getPointerType(QT);
|
|
|
|
|
|
|
|
return QT;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class RISCVIntrinsicManagerImpl : public sema::RISCVIntrinsicManager {
|
|
|
|
private:
|
|
|
|
Sema &S;
|
|
|
|
ASTContext &Context;
|
2022-11-21 22:18:54 +08:00
|
|
|
RVVTypeCache TypeCache;
|
[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-13 15:52:17 +08:00
|
|
|
|
|
|
|
// List of all RVV intrinsic.
|
|
|
|
std::vector<RVVIntrinsicDef> IntrinsicList;
|
|
|
|
// Mapping function name to index of IntrinsicList.
|
|
|
|
StringMap<size_t> Intrinsics;
|
|
|
|
// Mapping function name to RVVOverloadIntrinsicDef.
|
|
|
|
StringMap<RVVOverloadIntrinsicDef> OverloadIntrinsics;
|
|
|
|
|
|
|
|
// Create IntrinsicList
|
|
|
|
void InitIntrinsicList();
|
|
|
|
|
|
|
|
// Create RVVIntrinsicDef.
|
|
|
|
void InitRVVIntrinsic(const RVVIntrinsicRecord &Record, StringRef SuffixStr,
|
|
|
|
StringRef OverloadedSuffixStr, bool IsMask,
|
2022-12-22 01:20:09 -08:00
|
|
|
RVVTypes &Types, bool HasPolicy, Policy PolicyAttrs,
|
2022-05-26 17:19:50 -07:00
|
|
|
bool IsPrototypeDefaultTU);
|
[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-13 15:52:17 +08:00
|
|
|
|
|
|
|
// Create FunctionDecl for a vector intrinsic.
|
|
|
|
void CreateRVVIntrinsicDecl(LookupResult &LR, IdentifierInfo *II,
|
|
|
|
Preprocessor &PP, unsigned Index,
|
|
|
|
bool IsOverload);
|
|
|
|
|
|
|
|
public:
|
|
|
|
RISCVIntrinsicManagerImpl(clang::Sema &S) : S(S), Context(S.Context) {
|
|
|
|
InitIntrinsicList();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create RISC-V vector intrinsic and insert into symbol table if found, and
|
|
|
|
// return true, otherwise return false.
|
|
|
|
bool CreateIntrinsicIfFound(LookupResult &LR, IdentifierInfo *II,
|
|
|
|
Preprocessor &PP) override;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void RISCVIntrinsicManagerImpl::InitIntrinsicList() {
|
|
|
|
const TargetInfo &TI = Context.getTargetInfo();
|
|
|
|
bool HasVectorFloat32 = TI.hasFeature("zve32f");
|
|
|
|
bool HasVectorFloat64 = TI.hasFeature("zve64d");
|
|
|
|
bool HasZvfh = TI.hasFeature("experimental-zvfh");
|
|
|
|
bool HasRV64 = TI.hasFeature("64bit");
|
|
|
|
bool HasFullMultiply = TI.hasFeature("v");
|
|
|
|
|
|
|
|
// Construction of RVVIntrinsicRecords need to sync with createRVVIntrinsics
|
|
|
|
// in RISCVVEmitter.cpp.
|
|
|
|
for (auto &Record : RVVIntrinsicRecords) {
|
|
|
|
// Create Intrinsics for each type and LMUL.
|
|
|
|
BasicType BaseType = BasicType::Unknown;
|
2022-07-26 10:14:03 +00:00
|
|
|
ArrayRef<PrototypeDescriptor> BasicProtoSeq =
|
[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-13 15:52:17 +08:00
|
|
|
ProtoSeq2ArrayRef(Record.PrototypeIndex, Record.PrototypeLength);
|
|
|
|
ArrayRef<PrototypeDescriptor> SuffixProto =
|
|
|
|
ProtoSeq2ArrayRef(Record.SuffixIndex, Record.SuffixLength);
|
|
|
|
ArrayRef<PrototypeDescriptor> OverloadedSuffixProto = ProtoSeq2ArrayRef(
|
|
|
|
Record.OverloadedSuffixIndex, Record.OverloadedSuffixSize);
|
2022-07-26 10:14:03 +00:00
|
|
|
|
2022-05-26 17:19:50 -07:00
|
|
|
PolicyScheme UnMaskedPolicyScheme =
|
|
|
|
static_cast<PolicyScheme>(Record.UnMaskedPolicyScheme);
|
|
|
|
PolicyScheme MaskedPolicyScheme =
|
|
|
|
static_cast<PolicyScheme>(Record.MaskedPolicyScheme);
|
|
|
|
|
2022-07-26 10:14:03 +00:00
|
|
|
llvm::SmallVector<PrototypeDescriptor> ProtoSeq =
|
2022-05-26 17:19:50 -07:00
|
|
|
RVVIntrinsic::computeBuiltinTypes(
|
|
|
|
BasicProtoSeq, /*IsMasked=*/false,
|
|
|
|
/*HasMaskedOffOperand=*/false, Record.HasVL, Record.NF,
|
[RISCV] Refactor RVV Policy by structure
RVV intrinsic function has several policy variants.
Include TU, TA, TAMU, TAMA, TUMU, TUMA, MU, MA, TUM, TAM
Currently, the clang side enumerates these policies, but it's hard to add a new policy.
This patch use structure to replace the origin policy enumeration, and enhance some policy transform logic.
This is a clean-up job that will not affect the RVV intrinsic functionality and make sure riscv_vector_builtin_cg.inc is the same as the original one.
Reviewed By: kito-cheng
Differential Revision: https://reviews.llvm.org/D139995
2022-12-20 01:12:57 -08:00
|
|
|
Record.IsPrototypeDefaultTU, UnMaskedPolicyScheme, Policy());
|
2022-07-26 10:14:03 +00:00
|
|
|
|
|
|
|
llvm::SmallVector<PrototypeDescriptor> ProtoMaskSeq =
|
2022-05-26 17:19:50 -07:00
|
|
|
RVVIntrinsic::computeBuiltinTypes(
|
|
|
|
BasicProtoSeq, /*IsMasked=*/true, Record.HasMaskedOffOperand,
|
|
|
|
Record.HasVL, Record.NF, Record.IsPrototypeDefaultTU,
|
[RISCV] Refactor RVV Policy by structure
RVV intrinsic function has several policy variants.
Include TU, TA, TAMU, TAMA, TUMU, TUMA, MU, MA, TUM, TAM
Currently, the clang side enumerates these policies, but it's hard to add a new policy.
This patch use structure to replace the origin policy enumeration, and enhance some policy transform logic.
This is a clean-up job that will not affect the RVV intrinsic functionality and make sure riscv_vector_builtin_cg.inc is the same as the original one.
Reviewed By: kito-cheng
Differential Revision: https://reviews.llvm.org/D139995
2022-12-20 01:12:57 -08:00
|
|
|
MaskedPolicyScheme, Policy());
|
2022-05-26 17:19:50 -07:00
|
|
|
|
|
|
|
bool UnMaskedHasPolicy = UnMaskedPolicyScheme != PolicyScheme::SchemeNone;
|
|
|
|
bool MaskedHasPolicy = MaskedPolicyScheme != PolicyScheme::SchemeNone;
|
|
|
|
// If unmasked builtin supports policy, they should be TU or TA.
|
[RISCV] Refactor RVV Policy by structure
RVV intrinsic function has several policy variants.
Include TU, TA, TAMU, TAMA, TUMU, TUMA, MU, MA, TUM, TAM
Currently, the clang side enumerates these policies, but it's hard to add a new policy.
This patch use structure to replace the origin policy enumeration, and enhance some policy transform logic.
This is a clean-up job that will not affect the RVV intrinsic functionality and make sure riscv_vector_builtin_cg.inc is the same as the original one.
Reviewed By: kito-cheng
Differential Revision: https://reviews.llvm.org/D139995
2022-12-20 01:12:57 -08:00
|
|
|
llvm::SmallVector<Policy> SupportedUnMaskedPolicies;
|
|
|
|
SupportedUnMaskedPolicies.emplace_back(Policy(
|
|
|
|
Policy::PolicyType::Undisturbed, Policy::PolicyType::Omit)); // TU
|
|
|
|
SupportedUnMaskedPolicies.emplace_back(
|
|
|
|
Policy(Policy::PolicyType::Agnostic, Policy::PolicyType::Omit)); // TA
|
2022-05-26 17:19:50 -07:00
|
|
|
llvm::SmallVector<Policy> SupportedMaskedPolicies =
|
|
|
|
RVVIntrinsic::getSupportedMaskedPolicies(Record.HasTailPolicy,
|
|
|
|
Record.HasMaskPolicy);
|
2022-07-26 10:14:03 +00:00
|
|
|
|
[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-13 15:52:17 +08:00
|
|
|
for (unsigned int TypeRangeMaskShift = 0;
|
|
|
|
TypeRangeMaskShift <= static_cast<unsigned int>(BasicType::MaxOffset);
|
|
|
|
++TypeRangeMaskShift) {
|
|
|
|
unsigned int BaseTypeI = 1 << TypeRangeMaskShift;
|
|
|
|
BaseType = static_cast<BasicType>(BaseTypeI);
|
|
|
|
|
|
|
|
if ((BaseTypeI & Record.TypeRangeMask) != BaseTypeI)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check requirement.
|
|
|
|
if (BaseType == BasicType::Float16 && !HasZvfh)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (BaseType == BasicType::Float32 && !HasVectorFloat32)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (BaseType == BasicType::Float64 && !HasVectorFloat64)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (((Record.RequiredExtensions & RVV_REQ_RV64) == RVV_REQ_RV64) &&
|
|
|
|
!HasRV64)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((BaseType == BasicType::Int64) &&
|
|
|
|
((Record.RequiredExtensions & RVV_REQ_FullMultiply) ==
|
|
|
|
RVV_REQ_FullMultiply) &&
|
|
|
|
!HasFullMultiply)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Expanded with different LMUL.
|
|
|
|
for (int Log2LMUL = -3; Log2LMUL <= 3; Log2LMUL++) {
|
|
|
|
if (!(Record.Log2LMULMask & (1 << (Log2LMUL + 3))))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Optional<RVVTypes> Types =
|
2022-11-21 22:18:54 +08:00
|
|
|
TypeCache.computeTypes(BaseType, Log2LMUL, Record.NF, ProtoSeq);
|
[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-13 15:52:17 +08:00
|
|
|
|
|
|
|
// Ignored to create new intrinsic if there are any illegal types.
|
2022-07-29 21:18:39 -07:00
|
|
|
if (!Types.has_value())
|
[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-13 15:52:17 +08:00
|
|
|
continue;
|
|
|
|
|
2022-11-21 22:18:54 +08:00
|
|
|
std::string SuffixStr = RVVIntrinsic::getSuffixStr(
|
|
|
|
TypeCache, BaseType, Log2LMUL, SuffixProto);
|
[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-13 15:52:17 +08:00
|
|
|
std::string OverloadedSuffixStr = RVVIntrinsic::getSuffixStr(
|
2022-11-21 22:18:54 +08:00
|
|
|
TypeCache, BaseType, Log2LMUL, OverloadedSuffixProto);
|
[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-13 15:52:17 +08:00
|
|
|
|
|
|
|
// Create non-masked intrinsic.
|
2022-05-26 17:19:50 -07:00
|
|
|
InitRVVIntrinsic(Record, SuffixStr, OverloadedSuffixStr, false, *Types,
|
[RISCV] Refactor RVV Policy by structure
RVV intrinsic function has several policy variants.
Include TU, TA, TAMU, TAMA, TUMU, TUMA, MU, MA, TUM, TAM
Currently, the clang side enumerates these policies, but it's hard to add a new policy.
This patch use structure to replace the origin policy enumeration, and enhance some policy transform logic.
This is a clean-up job that will not affect the RVV intrinsic functionality and make sure riscv_vector_builtin_cg.inc is the same as the original one.
Reviewed By: kito-cheng
Differential Revision: https://reviews.llvm.org/D139995
2022-12-20 01:12:57 -08:00
|
|
|
UnMaskedHasPolicy, Policy(),
|
2022-05-26 17:19:50 -07:00
|
|
|
Record.IsPrototypeDefaultTU);
|
|
|
|
|
|
|
|
// Create non-masked policy intrinsic.
|
|
|
|
if (Record.UnMaskedPolicyScheme != PolicyScheme::SchemeNone) {
|
|
|
|
for (auto P : SupportedUnMaskedPolicies) {
|
|
|
|
llvm::SmallVector<PrototypeDescriptor> PolicyPrototype =
|
|
|
|
RVVIntrinsic::computeBuiltinTypes(
|
|
|
|
BasicProtoSeq, /*IsMasked=*/false,
|
|
|
|
/*HasMaskedOffOperand=*/false, Record.HasVL, Record.NF,
|
|
|
|
Record.IsPrototypeDefaultTU, UnMaskedPolicyScheme, P);
|
2022-11-21 22:18:54 +08:00
|
|
|
Optional<RVVTypes> PolicyTypes = TypeCache.computeTypes(
|
2022-05-26 17:19:50 -07:00
|
|
|
BaseType, Log2LMUL, Record.NF, PolicyPrototype);
|
|
|
|
InitRVVIntrinsic(Record, SuffixStr, OverloadedSuffixStr,
|
|
|
|
/*IsMask=*/false, *PolicyTypes, UnMaskedHasPolicy,
|
|
|
|
P, Record.IsPrototypeDefaultTU);
|
|
|
|
}
|
[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-13 15:52:17 +08:00
|
|
|
}
|
2022-05-26 17:19:50 -07:00
|
|
|
if (!Record.HasMasked)
|
|
|
|
continue;
|
|
|
|
// Create masked intrinsic.
|
|
|
|
Optional<RVVTypes> MaskTypes =
|
2022-11-21 22:18:54 +08:00
|
|
|
TypeCache.computeTypes(BaseType, Log2LMUL, Record.NF, ProtoMaskSeq);
|
2022-05-26 17:19:50 -07:00
|
|
|
InitRVVIntrinsic(Record, SuffixStr, OverloadedSuffixStr, true,
|
[RISCV] Refactor RVV Policy by structure
RVV intrinsic function has several policy variants.
Include TU, TA, TAMU, TAMA, TUMU, TUMA, MU, MA, TUM, TAM
Currently, the clang side enumerates these policies, but it's hard to add a new policy.
This patch use structure to replace the origin policy enumeration, and enhance some policy transform logic.
This is a clean-up job that will not affect the RVV intrinsic functionality and make sure riscv_vector_builtin_cg.inc is the same as the original one.
Reviewed By: kito-cheng
Differential Revision: https://reviews.llvm.org/D139995
2022-12-20 01:12:57 -08:00
|
|
|
*MaskTypes, MaskedHasPolicy, Policy(),
|
2022-05-26 17:19:50 -07:00
|
|
|
Record.IsPrototypeDefaultTU);
|
|
|
|
if (Record.MaskedPolicyScheme == PolicyScheme::SchemeNone)
|
|
|
|
continue;
|
|
|
|
// Create masked policy intrinsic.
|
|
|
|
for (auto P : SupportedMaskedPolicies) {
|
|
|
|
llvm::SmallVector<PrototypeDescriptor> PolicyPrototype =
|
|
|
|
RVVIntrinsic::computeBuiltinTypes(
|
|
|
|
BasicProtoSeq, /*IsMasked=*/true, Record.HasMaskedOffOperand,
|
|
|
|
Record.HasVL, Record.NF, Record.IsPrototypeDefaultTU,
|
|
|
|
MaskedPolicyScheme, P);
|
2022-11-21 22:18:54 +08:00
|
|
|
Optional<RVVTypes> PolicyTypes = TypeCache.computeTypes(
|
2022-05-26 17:19:50 -07:00
|
|
|
BaseType, Log2LMUL, Record.NF, PolicyPrototype);
|
|
|
|
InitRVVIntrinsic(Record, SuffixStr, OverloadedSuffixStr,
|
|
|
|
/*IsMask=*/true, *PolicyTypes, MaskedHasPolicy, P,
|
|
|
|
Record.IsPrototypeDefaultTU);
|
|
|
|
}
|
|
|
|
} // End for different LMUL
|
|
|
|
} // End for different TypeRange
|
[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-13 15:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute name and signatures for intrinsic with practical types.
|
|
|
|
void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
|
|
|
|
const RVVIntrinsicRecord &Record, StringRef SuffixStr,
|
2022-05-26 17:19:50 -07:00
|
|
|
StringRef OverloadedSuffixStr, bool IsMasked, RVVTypes &Signature,
|
2022-12-22 01:20:09 -08:00
|
|
|
bool HasPolicy, Policy PolicyAttrs, bool IsPrototypeDefaultTU) {
|
[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-13 15:52:17 +08:00
|
|
|
// Function name, e.g. vadd_vv_i32m1.
|
|
|
|
std::string Name = Record.Name;
|
|
|
|
if (!SuffixStr.empty())
|
|
|
|
Name += "_" + SuffixStr.str();
|
|
|
|
|
|
|
|
// Overloaded function name, e.g. vadd.
|
|
|
|
std::string OverloadedName;
|
|
|
|
if (!Record.OverloadedName)
|
|
|
|
OverloadedName = StringRef(Record.Name).split("_").first.str();
|
|
|
|
else
|
|
|
|
OverloadedName = Record.OverloadedName;
|
|
|
|
if (!OverloadedSuffixStr.empty())
|
|
|
|
OverloadedName += "_" + OverloadedSuffixStr.str();
|
|
|
|
|
|
|
|
// clang built-in function name, e.g. __builtin_rvv_vadd.
|
|
|
|
std::string BuiltinName = "__builtin_rvv_" + std::string(Record.Name);
|
2022-05-26 17:19:50 -07:00
|
|
|
|
|
|
|
RVVIntrinsic::updateNamesAndPolicy(IsMasked, HasPolicy, IsPrototypeDefaultTU,
|
|
|
|
Name, BuiltinName, OverloadedName,
|
2022-12-22 01:20:09 -08:00
|
|
|
PolicyAttrs);
|
[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-13 15:52:17 +08:00
|
|
|
|
|
|
|
// Put into IntrinsicList.
|
|
|
|
size_t Index = IntrinsicList.size();
|
|
|
|
IntrinsicList.push_back({Name, OverloadedName, BuiltinName, Signature});
|
|
|
|
|
|
|
|
// Creating mapping to Intrinsics.
|
|
|
|
Intrinsics.insert({Name, Index});
|
|
|
|
|
|
|
|
// Get the RVVOverloadIntrinsicDef.
|
|
|
|
RVVOverloadIntrinsicDef &OverloadIntrinsicDef =
|
|
|
|
OverloadIntrinsics[OverloadedName];
|
|
|
|
|
|
|
|
// And added the index.
|
|
|
|
OverloadIntrinsicDef.Indexes.push_back(Index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
|
|
|
|
IdentifierInfo *II,
|
|
|
|
Preprocessor &PP,
|
|
|
|
unsigned Index,
|
|
|
|
bool IsOverload) {
|
|
|
|
ASTContext &Context = S.Context;
|
|
|
|
RVVIntrinsicDef &IDef = IntrinsicList[Index];
|
|
|
|
RVVTypes Sigs = IDef.Signature;
|
|
|
|
size_t SigLength = Sigs.size();
|
|
|
|
RVVType *ReturnType = Sigs[0];
|
|
|
|
QualType RetType = RVVType2Qual(Context, ReturnType);
|
|
|
|
SmallVector<QualType, 8> ArgTypes;
|
|
|
|
QualType BuiltinFuncType;
|
|
|
|
|
|
|
|
// Skip return type, and convert RVVType to QualType for arguments.
|
|
|
|
for (size_t i = 1; i < SigLength; ++i)
|
|
|
|
ArgTypes.push_back(RVVType2Qual(Context, Sigs[i]));
|
|
|
|
|
|
|
|
FunctionProtoType::ExtProtoInfo PI(
|
|
|
|
Context.getDefaultCallingConvention(false, false, true));
|
|
|
|
|
|
|
|
PI.Variadic = false;
|
|
|
|
|
|
|
|
SourceLocation Loc = LR.getNameLoc();
|
|
|
|
BuiltinFuncType = Context.getFunctionType(RetType, ArgTypes, PI);
|
|
|
|
DeclContext *Parent = Context.getTranslationUnitDecl();
|
|
|
|
|
|
|
|
FunctionDecl *RVVIntrinsicDecl = FunctionDecl::Create(
|
|
|
|
Context, Parent, Loc, Loc, II, BuiltinFuncType, /*TInfo=*/nullptr,
|
|
|
|
SC_Extern, S.getCurFPFeatures().isFPConstrained(),
|
|
|
|
/*isInlineSpecified*/ false,
|
|
|
|
/*hasWrittenPrototype*/ true);
|
|
|
|
|
|
|
|
// Create Decl objects for each parameter, adding them to the
|
|
|
|
// FunctionDecl.
|
|
|
|
const auto *FP = cast<FunctionProtoType>(BuiltinFuncType);
|
|
|
|
SmallVector<ParmVarDecl *, 8> ParmList;
|
|
|
|
for (unsigned IParm = 0, E = FP->getNumParams(); IParm != E; ++IParm) {
|
|
|
|
ParmVarDecl *Parm =
|
|
|
|
ParmVarDecl::Create(Context, RVVIntrinsicDecl, Loc, Loc, nullptr,
|
|
|
|
FP->getParamType(IParm), nullptr, SC_None, nullptr);
|
|
|
|
Parm->setScopeInfo(0, IParm);
|
|
|
|
ParmList.push_back(Parm);
|
|
|
|
}
|
|
|
|
RVVIntrinsicDecl->setParams(ParmList);
|
|
|
|
|
|
|
|
// Add function attributes.
|
|
|
|
if (IsOverload)
|
|
|
|
RVVIntrinsicDecl->addAttr(OverloadableAttr::CreateImplicit(Context));
|
|
|
|
|
|
|
|
// Setup alias to __builtin_rvv_*
|
|
|
|
IdentifierInfo &IntrinsicII = PP.getIdentifierTable().get(IDef.BuiltinName);
|
|
|
|
RVVIntrinsicDecl->addAttr(
|
|
|
|
BuiltinAliasAttr::CreateImplicit(S.Context, &IntrinsicII));
|
|
|
|
|
|
|
|
// Add to symbol table.
|
|
|
|
LR.addDecl(RVVIntrinsicDecl);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVIntrinsicManagerImpl::CreateIntrinsicIfFound(LookupResult &LR,
|
|
|
|
IdentifierInfo *II,
|
|
|
|
Preprocessor &PP) {
|
|
|
|
StringRef Name = II->getName();
|
|
|
|
|
|
|
|
// Lookup the function name from the overload intrinsics first.
|
|
|
|
auto OvIItr = OverloadIntrinsics.find(Name);
|
|
|
|
if (OvIItr != OverloadIntrinsics.end()) {
|
|
|
|
const RVVOverloadIntrinsicDef &OvIntrinsicDef = OvIItr->second;
|
|
|
|
for (auto Index : OvIntrinsicDef.Indexes)
|
|
|
|
CreateRVVIntrinsicDecl(LR, II, PP, Index,
|
|
|
|
/*IsOverload*/ true);
|
|
|
|
|
|
|
|
// If we added overloads, need to resolve the lookup result.
|
|
|
|
LR.resolveKind();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup the function name from the intrinsics.
|
|
|
|
auto Itr = Intrinsics.find(Name);
|
|
|
|
if (Itr != Intrinsics.end()) {
|
|
|
|
CreateRVVIntrinsicDecl(LR, II, PP, Itr->second,
|
|
|
|
/*IsOverload*/ false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's not an RVV intrinsics.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
std::unique_ptr<clang::sema::RISCVIntrinsicManager>
|
|
|
|
CreateRISCVIntrinsicManager(Sema &S) {
|
|
|
|
return std::make_unique<RISCVIntrinsicManagerImpl>(S);
|
|
|
|
}
|
|
|
|
} // namespace clang
|