[llvm] [CHERI] Add enum values and LL parse/print support for CHERIoT calling conventions. (PR #156328)
Owen Anderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 04:59:50 PDT 2025
https://github.com/resistor updated https://github.com/llvm/llvm-project/pull/156328
>From 865b95cd7dc2c8e6a9c1a0ab09ac3ee4348d115f Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Mon, 1 Sep 2025 21:27:39 +0800
Subject: [PATCH 1/5] [CHERI] Add enum values and LL parse/print support for
CHERI calling conventions.
This is the union of the calling conventions supported by the CTSRD and CHERIoT CHERI downstreams of LLVM.
---
llvm/include/llvm/AsmParser/LLToken.h | 3 +++
llvm/include/llvm/IR/CallingConv.h | 11 +++++++++++
llvm/lib/AsmParser/LLLexer.cpp | 3 +++
llvm/lib/AsmParser/LLParser.cpp | 9 +++++++++
llvm/lib/IR/AsmWriter.cpp | 9 +++++++++
5 files changed, 35 insertions(+)
diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h
index e6a0eae9da30c..b5b6bff6a27b7 100644
--- a/llvm/include/llvm/AsmParser/LLToken.h
+++ b/llvm/include/llvm/AsmParser/LLToken.h
@@ -187,6 +187,9 @@ enum Kind {
kw_graalcc,
kw_riscv_vector_cc,
kw_riscv_vls_cc,
+ kw_chericcallcc,
+ kw_chericcallee,
+ kw_cherilibcallcc,
// Attributes:
kw_attributes,
diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h
index ef761eb1aed73..c89ffafd3a1c8 100644
--- a/llvm/include/llvm/IR/CallingConv.h
+++ b/llvm/include/llvm/IR/CallingConv.h
@@ -287,6 +287,17 @@ namespace CallingConv {
// Calling convention for AMDGPU whole wave functions.
AMDGPU_Gfx_WholeWave = 124,
+ /// CHERI_CCall - Calling convention used for CHERI when crossing a
+ /// protection boundary.
+ CHERI_CCall = 125,
+ /// CHERI_CCallee - Calling convention used for the callee of CHERI_CCall.
+ /// Ignores the first two capability arguments and the first integer
+ /// argument, zeroes all unused return registers on return.
+ CHERI_CCallee = 126,
+ /// CHERI_LibCall - Calling convention used for cross-library calls to a
+ /// stateless compartment.
+ CHERI_LibCall = 127,
+
/// The highest possible ID. Must be some 2^k - 1.
MaxID = 1023
};
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 3d5bd6155536e..33d042263c9a5 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -685,6 +685,9 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(graalcc);
KEYWORD(riscv_vector_cc);
KEYWORD(riscv_vls_cc);
+ KEYWORD(chericcallcc);
+ KEYWORD(chericcallee);
+ KEYWORD(cherilibcallcc);
KEYWORD(cc);
KEYWORD(c);
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 1bc2906f63b07..52a9eea1ba801 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -2312,6 +2312,15 @@ bool LLParser::parseOptionalCallingConv(unsigned &CC) {
#undef CC_VLS_CASE
}
return false;
+ case lltok::kw_chericcallcc:
+ CC = CallingConv::CHERI_CCall;
+ break;
+ case lltok::kw_chericcallee:
+ CC = CallingConv::CHERI_CCallee;
+ break;
+ case lltok::kw_cherilibcallcc:
+ CC = CallingConv::CHERI_LibCall;
+ break;
case lltok::kw_cc: {
Lex.Lex();
return parseUInt32(CC);
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 094678f32af2b..9f39b27ce4c39 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -430,6 +430,15 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
CC_VLS_CASE(32768)
CC_VLS_CASE(65536)
#undef CC_VLS_CASE
+ case CallingConv::CHERI_CCall:
+ Out << "chericcallcc";
+ break;
+ case CallingConv::CHERI_CCallee:
+ Out << "chericcallee";
+ break;
+ case CallingConv::CHERI_LibCall:
+ Out << "cherilibcallcc";
+ break;
}
}
>From 387974217f14c5ca5f2315be85e33c9e89d4bfeb Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Mon, 8 Sep 2025 22:42:33 +0800
Subject: [PATCH 2/5] Rename calling conventions to be Cheriot-namespaced and
more explicitly named.
---
llvm/include/llvm/AsmParser/LLToken.h | 6 +++---
llvm/include/llvm/IR/CallingConv.h | 9 +++++----
llvm/lib/AsmParser/LLLexer.cpp | 6 +++---
llvm/lib/AsmParser/LLParser.cpp | 12 ++++++------
llvm/lib/IR/AsmWriter.cpp | 12 ++++++------
5 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h
index b5b6bff6a27b7..d976d40e5e956 100644
--- a/llvm/include/llvm/AsmParser/LLToken.h
+++ b/llvm/include/llvm/AsmParser/LLToken.h
@@ -187,9 +187,9 @@ enum Kind {
kw_graalcc,
kw_riscv_vector_cc,
kw_riscv_vls_cc,
- kw_chericcallcc,
- kw_chericcallee,
- kw_cherilibcallcc,
+ kw_cheriot_compartmentcallcc,
+ kw_cheriot_compartmentcalleecc,
+ kw_cheriot_librarycallcc,
// Attributes:
kw_attributes,
diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h
index c89ffafd3a1c8..ece6187d506da 100644
--- a/llvm/include/llvm/IR/CallingConv.h
+++ b/llvm/include/llvm/IR/CallingConv.h
@@ -287,16 +287,17 @@ namespace CallingConv {
// Calling convention for AMDGPU whole wave functions.
AMDGPU_Gfx_WholeWave = 124,
- /// CHERI_CCall - Calling convention used for CHERI when crossing a
+ /// CHERIoT_CompartmentCall - Calling convention used for CHERI when
+ /// crossing a
/// protection boundary.
- CHERI_CCall = 125,
+ CHERIoT_CompartmentCall = 125,
/// CHERI_CCallee - Calling convention used for the callee of CHERI_CCall.
/// Ignores the first two capability arguments and the first integer
/// argument, zeroes all unused return registers on return.
- CHERI_CCallee = 126,
+ CHERIoT_CompartmentCallee = 126,
/// CHERI_LibCall - Calling convention used for cross-library calls to a
/// stateless compartment.
- CHERI_LibCall = 127,
+ CHERIoT_LibraryCall = 127,
/// The highest possible ID. Must be some 2^k - 1.
MaxID = 1023
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 33d042263c9a5..f6937d38eb38c 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -685,9 +685,9 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(graalcc);
KEYWORD(riscv_vector_cc);
KEYWORD(riscv_vls_cc);
- KEYWORD(chericcallcc);
- KEYWORD(chericcallee);
- KEYWORD(cherilibcallcc);
+ KEYWORD(cheriot_compartmentcallcc);
+ KEYWORD(cheriot_compartmentcalleecc);
+ KEYWORD(cheriot_librarycallcc);
KEYWORD(cc);
KEYWORD(c);
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 52a9eea1ba801..209b0f577b784 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -2312,14 +2312,14 @@ bool LLParser::parseOptionalCallingConv(unsigned &CC) {
#undef CC_VLS_CASE
}
return false;
- case lltok::kw_chericcallcc:
- CC = CallingConv::CHERI_CCall;
+ case lltok::kw_cheriot_compartmentcallcc:
+ CC = CallingConv::CHERIoT_CompartmentCall;
break;
- case lltok::kw_chericcallee:
- CC = CallingConv::CHERI_CCallee;
+ case lltok::kw_cheriot_compartmentcalleecc:
+ CC = CallingConv::CHERIoT_CompartmentCallee;
break;
- case lltok::kw_cherilibcallcc:
- CC = CallingConv::CHERI_LibCall;
+ case lltok::kw_cheriot_librarycallcc:
+ CC = CallingConv::CHERIoT_LibraryCall;
break;
case lltok::kw_cc: {
Lex.Lex();
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 9f39b27ce4c39..c638d063eb3c8 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -430,14 +430,14 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
CC_VLS_CASE(32768)
CC_VLS_CASE(65536)
#undef CC_VLS_CASE
- case CallingConv::CHERI_CCall:
- Out << "chericcallcc";
+ case CallingConv::CHERIoT_CompartmentCall:
+ Out << "cheriot_compartmentcallcc";
break;
- case CallingConv::CHERI_CCallee:
- Out << "chericcallee";
+ case CallingConv::CHERIoT_CompartmentCallee:
+ Out << "cheriot_compartmentcalleecc";
break;
- case CallingConv::CHERI_LibCall:
- Out << "cherilibcallcc";
+ case CallingConv::CHERIoT_LibraryCall:
+ Out << "cheriot_librarycallcc";
break;
}
}
>From f2b8ce49b4dd34576d9396a9569483c491126b84 Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Tue, 9 Sep 2025 00:16:20 +0800
Subject: [PATCH 3/5] Update comments
---
llvm/include/llvm/IR/CallingConv.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h
index ece6187d506da..169a7d69942d8 100644
--- a/llvm/include/llvm/IR/CallingConv.h
+++ b/llvm/include/llvm/IR/CallingConv.h
@@ -291,11 +291,13 @@ namespace CallingConv {
/// crossing a
/// protection boundary.
CHERIoT_CompartmentCall = 125,
- /// CHERI_CCallee - Calling convention used for the callee of CHERI_CCall.
+ /// CHERIoT_CompartmentCallee - Calling convention used for the callee of
+ /// CHERI_CCall.
/// Ignores the first two capability arguments and the first integer
/// argument, zeroes all unused return registers on return.
CHERIoT_CompartmentCallee = 126,
- /// CHERI_LibCall - Calling convention used for cross-library calls to a
+ /// CHERIoT_LibraryCall - Calling convention used for cross-library calls to
+ /// a
/// stateless compartment.
CHERIoT_LibraryCall = 127,
>From 9f2c16cd0f697a08b5760211d1b15fc22c7d02df Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Wed, 17 Sep 2025 23:18:59 +0800
Subject: [PATCH 4/5] Apply suggestions from code review
Co-authored-by: Nikita Popov <github at npopov.com>
---
llvm/include/llvm/IR/CallingConv.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h
index 169a7d69942d8..d36908cd6a22d 100644
--- a/llvm/include/llvm/IR/CallingConv.h
+++ b/llvm/include/llvm/IR/CallingConv.h
@@ -288,17 +288,15 @@ namespace CallingConv {
AMDGPU_Gfx_WholeWave = 124,
/// CHERIoT_CompartmentCall - Calling convention used for CHERI when
- /// crossing a
- /// protection boundary.
+ /// crossing a protection boundary.
CHERIoT_CompartmentCall = 125,
/// CHERIoT_CompartmentCallee - Calling convention used for the callee of
- /// CHERI_CCall.
+ /// CHERIoT_CompartmentCall.
/// Ignores the first two capability arguments and the first integer
/// argument, zeroes all unused return registers on return.
CHERIoT_CompartmentCallee = 126,
/// CHERIoT_LibraryCall - Calling convention used for cross-library calls to
- /// a
- /// stateless compartment.
+ /// a stateless compartment.
CHERIoT_LibraryCall = 127,
/// The highest possible ID. Must be some 2^k - 1.
>From 9540be40bfec7787c2fcf9da11d7df35271250eb Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Mon, 22 Sep 2025 20:58:56 +0900
Subject: [PATCH 5/5] Update comments.
---
llvm/include/llvm/IR/CallingConv.h | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h
index d36908cd6a22d..bbf9f8486f31c 100644
--- a/llvm/include/llvm/IR/CallingConv.h
+++ b/llvm/include/llvm/IR/CallingConv.h
@@ -287,16 +287,14 @@ namespace CallingConv {
// Calling convention for AMDGPU whole wave functions.
AMDGPU_Gfx_WholeWave = 124,
- /// CHERIoT_CompartmentCall - Calling convention used for CHERI when
- /// crossing a protection boundary.
+ /// Calling convention used for CHERIoT when crossing a protection boundary.
CHERIoT_CompartmentCall = 125,
- /// CHERIoT_CompartmentCallee - Calling convention used for the callee of
- /// CHERIoT_CompartmentCall.
+ /// Calling convention used for the callee of CHERIoT_CompartmentCall.
/// Ignores the first two capability arguments and the first integer
/// argument, zeroes all unused return registers on return.
CHERIoT_CompartmentCallee = 126,
- /// CHERIoT_LibraryCall - Calling convention used for cross-library calls to
- /// a stateless compartment.
+ /// Calling convention used for CHERIoT for cross-library calls to a
+ /// stateless compartment.
CHERIoT_LibraryCall = 127,
/// The highest possible ID. Must be some 2^k - 1.
More information about the llvm-commits
mailing list