Skip to content

[RISCV] Allocate Feature Bits for Zilsd/Zclsd/Zcmp #135197

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 1 commit into from
Apr 25, 2025

Conversation

lenary
Copy link
Member

@lenary lenary commented Apr 10, 2025

As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.

As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

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

Author: Sam Elliott (lenary)

Changes

As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.


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

2 Files Affected:

  • (modified) compiler-rt/lib/builtins/cpu_model/riscv.c (+6)
  • (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+6-3)
diff --git a/compiler-rt/lib/builtins/cpu_model/riscv.c b/compiler-rt/lib/builtins/cpu_model/riscv.c
index 6879c2ad48264..4d0fda473c87e 100644
--- a/compiler-rt/lib/builtins/cpu_model/riscv.c
+++ b/compiler-rt/lib/builtins/cpu_model/riscv.c
@@ -128,6 +128,12 @@ struct {
 #define ZCMOP_BITMASK (1ULL << 6)
 #define ZAWRS_GROUPID 1
 #define ZAWRS_BITMASK (1ULL << 7)
+#define ZILSD_GROUPID 1
+#define ZILSD_BITMASK (1ULL << 8)
+#define ZCLSD_GROUPID 1
+#define ZCLSD_BITMASK (1ULL << 9)
+#define ZCMP_GROUPID 1
+#define ZCMP_BITMASK (1ULL << 10)
 
 #if defined(__linux__)
 
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 60d3c0f397371..b3def7c437a2d 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -178,7 +178,8 @@ def NoHasStdExtZicfiss : Predicate<"!Subtarget->hasStdExtZicfiss()">;
 
 def FeatureStdExtZilsd
     : RISCVExtension<1, 0,
-                     "Load/Store Pair Instructions">;
+                     "Load/Store Pair Instructions">,
+      RISCVExtensionBitmask<1, 8>;
 def HasStdExtZilsd : Predicate<"Subtarget->hasStdExtZilsd()">,
                        AssemblerPredicate<(all_of FeatureStdExtZilsd),
                                           "'Zilsd' (Load/Store pair instructions)">;
@@ -411,7 +412,8 @@ def FeatureStdExtZcf
 def FeatureStdExtZclsd
     : RISCVExtension<1, 0,
                      "Compressed Load/Store Pair Instructions",
-                     [FeatureStdExtZilsd, FeatureStdExtZca]>;
+                     [FeatureStdExtZilsd, FeatureStdExtZca]>,
+      RISCVExtensionBitmask<1, 9>;
 def HasStdExtZclsd : Predicate<"Subtarget->hasStdExtZclsd()">,
                     AssemblerPredicate<(all_of FeatureStdExtZclsd),
                         "'Zclsd' (Compressed Load/Store pair instructions)">;
@@ -419,7 +421,8 @@ def HasStdExtZclsd : Predicate<"Subtarget->hasStdExtZclsd()">,
 def FeatureStdExtZcmp
     : RISCVExtension<1, 0,
                      "sequenced instructions for code-size reduction",
-                     [FeatureStdExtZca]>;
+                     [FeatureStdExtZca]>,
+      RISCVExtensionBitmask<1, 10>;
 def HasStdExtZcmp : Predicate<"Subtarget->hasStdExtZcmp() && !Subtarget->hasStdExtC()">,
                     AssemblerPredicate<(all_of FeatureStdExtZcmp),
                         "'Zcmp' (sequenced instructions for code-size reduction)">;

Copy link
Contributor

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

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

LGTM but is it right to land this before kernel supports?

@lenary
Copy link
Member Author

lenary commented Apr 10, 2025

is it right to land this before kernel supports?

To provide some context I provided on the toolchains call, with assistance from Kito:

  • Zilsd/Zclsd are 32-bit only, so may take some time to appear in linux, if they ever do.
  • Zcmp is incompatible with Zcd, so may not appear in linux hwcaps if linux focuses on rv64gc (or the profiles that include C+D, which implicitly have Zcd)

These bitmaps have been proposed because the Hazard3 core wants to skip any heavyweight capabilites spec, and just directly implement the C API's bitmap layout in hardware. This core implements these three extensions, and it is perfectly possible for a SDK to expose something compatible with the C API without it being linux.

LLVM/GCC implementations are a prerequisite for allocating these bits in the C API, which is why we have this implementation.

@wangpc-pp
Copy link
Contributor

is it right to land this before kernel supports?

To provide some context I provided on the toolchains call, with assistance from Kito:

  • Zilsd/Zclsd are 32-bit only, so may take some time to appear in linux, if they ever do.
  • Zcmp is incompatible with Zcd, so may not appear in linux hwcaps if linux focuses on rv64gc (or the profiles that include C+D, which implicitly have Zcd)

These bitmaps have been proposed because the Hazard3 core wants to skip any heavyweight capabilites spec, and just directly implement the C API's bitmap layout in hardware. This core implements these three extensions, and it is perfectly possible for a SDK to expose something compatible with the C API without it being linux.

LLVM/GCC implementations are a prerequisite for allocating these bits in the C API, which is why we have this implementation.

Got it! Then I am OK with this, please go ahead!

@BeMg
Copy link
Contributor

BeMg commented Apr 14, 2025

Should we update here as well, or wait until the real implementation in FMV/compiler-rt?

constexpr static RISCVExtBit RISCVBitPositions[] = {

It will make Clang raise a warning and ignore the FMV if target_clones/target_version uses an extension not in this list.

@wangpc-pp
Copy link
Contributor

Should we update here as well, or wait until the real implementation in FMV/compiler-rt?

constexpr static RISCVExtBit RISCVBitPositions[] = {

It will make Clang raise a warning and ignore the FMV if target_clones/target_version uses an extension not in this list.

Why is this table not generated by TableGen?

@BeMg
Copy link
Contributor

BeMg commented Apr 14, 2025

Should we update here as well, or wait until the real implementation in FMV/compiler-rt?

constexpr static RISCVExtBit RISCVBitPositions[] = {

It will make Clang raise a warning and ignore the FMV if target_clones/target_version uses an extension not in this list.

Why is this table not generated by TableGen?

In my opinion, it should be generated by TableGen. It is a standalone table according to #99700 (comment).

@lenary
Copy link
Member Author

lenary commented Apr 14, 2025

That table explains why I couldn't find uses of the structures generated from tablegen that I was expecting to find. Yes I shall update it. Yes all the info in that table is now available in tablegen and we should generate it.

@wangpc-pp
Copy link
Contributor

That table explains why I couldn't find uses of the structures generated from tablegen that I was expecting to find. Yes I shall update it. Yes all the info in that table is now available in tablegen and we should generate it.

#135600

@lenary
Copy link
Member Author

lenary commented Apr 14, 2025

I don't think we need to wait for a "real" implementation in compiler-rt, because we don't expect linux HW_CAPS to come for these extensions for quite some time. The question remains as to whether anything else is needed for this change, maybe a test? I'm not sure.

Copy link
Contributor

@BeMg BeMg left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

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

LGTM. I think we can go ahead with current version. I have no idea how this can be tested so I'd just let it go.

@lenary lenary merged commit 683c3b8 into llvm:main Apr 25, 2025
15 checks passed
jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
As proposed in riscv-non-isa/riscv-c-api-doc#104

No real compiler-rt implementation, as these are not exposed by Linux.
@lenary lenary deleted the pr/riscv-bitmask-more branch June 16, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants