[cfe-dev] [RFC][RISCV] Add intrinsic and/or builtin functions by #pragma

Kito Cheng via cfe-dev cfe-dev at lists.llvm.org
Mon Jun 14 23:59:47 PDT 2021

Hi :

# TL;DR:

It's the intrinsic and/or builtin functions related issue again, in
this RFC we are trying to use pragma to import intrinsics and declare
intrinsic wrappers function to reduce the compilation time.

And here is the PoC for this RFC:

# Background:

RISC-V vector extension has defined 25,386 intrinsic and 2,102
overloaded intrinsic functions in riscv_vector.h which increase a lot
of compilation time; the header file contains ~60k lines for those
overload functions and intrinsic wrapper functions.

An empty file with include riscv_vector.h takes 0.395s on release
build and 8.067s second on debug build, and this also increases the
clang test time.

# Proposal:

Using Tablegen to generate the table of the intrinsic wrapper
functions and then using pragma to declare intrinsic wrapper

#pragma riscv intrinsic vector

Then import all builtin functions and intrinsic wrappers into the
symbol table, this could save lots of time parsing the prototypes of
the intrinsic wrapper function.

And this idea of trick is borrowing from AArch64/SVE's implementation on GCC:

# Experimental Results:
## Size of riscv_vector.h:
      |      size |     LoC |
Before | 4,434,725 |  69,749 |
After  |     5,463 |     159 |

## Compilation Speed for Simple File

#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);

Release build:
  Before: 0m0.417s
  After:  0m0.090s

Debug build:
  Before: 0m8.016s
  After:  0m2.295s

## Regression Time
LLVM regression on our 48 core server:
Release build:
  Before : Testing Time: 203.81s
  After : Testing Time: 181.13s

Debug build:
  Before : Testing Time: 675.18s
  After : Testing Time: 647.20s

Any comments or feedback are appreciated!

More information about the cfe-dev mailing list