Skip to content

[RISCV] Reduce the size of the index used for RVV intrinsics. NFC #74906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2023

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Dec 9, 2023

Rather than using size_t, use unsigned. We don't have more than 4 billion intrinsics.

@topperc topperc requested review from kito-cheng and eopXD December 9, 2023 01:08
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:RISC-V clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 9, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2023

@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)

Changes

Rather than using size_t, use unsigned. We don't have more than 4 billion intrinsics.


Full diff: https://github.com/llvm/llvm-project/pull/74906.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaRISCVVectorLookup.cpp (+3-3)
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 9a5aecf669a07..b7add334c7f37 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -49,7 +49,7 @@ struct RVVIntrinsicDef {
 
 struct RVVOverloadIntrinsicDef {
   // Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
-  SmallVector<size_t, 8> Indexes;
+  SmallVector<unsigned, 8> Indexes;
 };
 
 } // namespace
@@ -168,7 +168,7 @@ class RISCVIntrinsicManagerImpl : public sema::RISCVIntrinsicManager {
   // List of all RVV intrinsic.
   std::vector<RVVIntrinsicDef> IntrinsicList;
   // Mapping function name to index of IntrinsicList.
-  StringMap<size_t> Intrinsics;
+  StringMap<unsigned> Intrinsics;
   // Mapping function name to RVVOverloadIntrinsicDef.
   StringMap<RVVOverloadIntrinsicDef> OverloadIntrinsics;
 
@@ -392,7 +392,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
                                      Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  size_t Index = IntrinsicList.size();
+  unsigned Index = IntrinsicList.size();
   IntrinsicList.push_back({Name, OverloadedName, BuiltinName, Signature});
 
   // Creating mapping to Intrinsics.

@topperc topperc requested a review from preames December 11, 2023 19:40
Copy link
Collaborator

@preames preames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - though maybe use uint32_t?

Looking at this code, the whole Intrinsics map vs OverloadIntrinsic map structure loops to have heavy redundancy and could be greatly simplified. Maybe a follow up?

Rather than using size_t, use unsigned. We don't have more than
4 billion intrinsics.
@topperc topperc force-pushed the pr/rvv-intrinsic-index branch from 0067a9c to 86ffbd6 Compare December 12, 2023 17:58
@topperc
Copy link
Collaborator Author

topperc commented Dec 12, 2023

LGTM - though maybe use uint32_t?

Looking at this code, the whole Intrinsics map vs OverloadIntrinsic map structure loops to have heavy redundancy and could be greatly simplified. Maybe a follow up?

Did you have a specific idea in mind? Maybe we could use a single map and use the size of the vector being more than 1 to detect overloaded?

I'm skeptical that the 8 is the correct inline space for the SmallVector in OverloadedIntrinsicMap.

@preames
Copy link
Collaborator

preames commented Dec 12, 2023

LGTM - though maybe use uint32_t?
Looking at this code, the whole Intrinsics map vs OverloadIntrinsic map structure loops to have heavy redundancy and could be greatly simplified. Maybe a follow up?

Did you have a specific idea in mind? Maybe we could use a single map and use the size of the vector being more than 1 to detect overloaded?

I'm skeptical that the 8 is the correct inline space for the SmallVector in OverloadedIntrinsicMap.

That's basically where I was going. We track every name to index mapping twice, and we really only need to do so once. Maybe the cost of a SmallVector<uint32_t, 1> is high enough to be worth two structures, but then why not have a signal value in the primary map and a much smaller index keyed overload structure?

@topperc topperc merged commit 0523bf1 into llvm:main Dec 13, 2023
@topperc topperc deleted the pr/rvv-intrinsic-index branch December 13, 2023 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:RISC-V clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants