This is an archive of the discontinued LLVM Phabricator instance.

[PoC][RISCV] Using pragma to register vector intrinsic
AbandonedPublic

Authored by kito-cheng on May 26 2021, 11:46 PM.

Details

Summary

This patch is *NOT* ready to commite yet, it's PoC of the pragma approache to
reduce the size of riscv_vector.h and speed up the including effort.

Syntax for the new pragma:

#pragma riscv intrinsic <extension name>

And we only support for vector now:

#pragma riscv intrinsic vector

Size of riscv_vector.h:

       |      size |     LoC |
------------------------------
Before | 4,434,725 |  69,749 |
After  |     5,463 |     159 |

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

Release build:

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

Debug build:

Before: 0m8.016s
After:  0m2.295s
  • Measure by time command.

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

Diff Detail

Event Timeline

kito-cheng created this revision.May 26 2021, 11:46 PM
kito-cheng requested review of this revision.May 26 2021, 11:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2021, 11:46 PM
kito-cheng edited the summary of this revision. (Show Details)
kito-cheng edited the summary of this revision. (Show Details)

Minor cleanup

craig.topper added inline comments.May 27 2021, 12:04 AM
clang/lib/Sema/SemaRISCV.cpp
22

Can we capture Sema in the lambda capture list here so that it's not really passed to initializeTargetOverloadBuiltins. I don't think forward declaring Sema in Builtins.h is a good idea since the "Basic" library isn't supposed to know about Sema. That probably means you need to use a std::function instead of a function pointer.

kito-cheng added inline comments.May 27 2021, 12:33 AM
clang/lib/Sema/SemaRISCV.cpp
22

Thanks for the input, I am not family with modern C++ since GCC still using limited set of C++98 :P

kito-cheng updated this revision to Diff 349784.Jun 4 2021, 1:07 AM

Changes:

  • Using less invasive way to add intrinsic functions.
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2021, 1:08 AM
kito-cheng planned changes to this revision.EditedJul 8 2021, 8:00 AM

Update:

Send RFC[1] to cfe-dev list, and got useful feedback from OpenCL:

  • OpenCL's way is the fastest way to declare builtin, since it defer until symbol look-up, however that require re-implement vector intrinsic with their new intrinsic infrastructure.
  • OpenCL folks agree we (RISC-V) need some way to enable that like pragma, OpenCL are default enabled built-in function without including header file, but RVV intrinsic are only need to import until riscv_vector.h included.

So my next step is investigate the OpenCL's intrinsic infrastructure to get the best performance to declare bunch of intrinsic function, it might take several weeks.
and #pragma is still required.

[1] https://lists.llvm.org/pipermail/cfe-dev/2021-June/068340.html

kito-cheng abandoned this revision.Jan 16 2022, 7:48 PM

Further development move to https://reviews.llvm.org/D111617