Skip to content

Conversation

resistor
Copy link
Collaborator

@resistor resistor commented Sep 1, 2025

This is the set of the calling conventions supported by the CHERIoT CHERI downstream of LLVM.

@resistor
Copy link
Collaborator Author

resistor commented Sep 1, 2025

Per communication with @davidchisnall I have corrected a misspelling in one of the CC names. This has already been fixed in the CHERIoT downstream as well. You can find the change here if you would like to apply to it other CHERI-enabled LLVM downstream: CHERIoT-Platform/llvm-project@86c8222#diff-312583cccc22b4a5264f77751f2d3aef55fc9b9508c861fc81ea448590e9bf46

@resistor resistor marked this pull request as ready for review September 1, 2025 13:45
@llvmbot llvmbot added the llvm:ir label Sep 1, 2025
@resistor
Copy link
Collaborator Author

resistor commented Sep 1, 2025

@jrtc27 @arichardson

@llvmbot
Copy link
Member

llvmbot commented Sep 1, 2025

@llvm/pr-subscribers-llvm-ir

Author: Owen Anderson (resistor)

Changes

This is the union of the calling conventions supported by the CTSRD and CHERIoT CHERI downstreams of LLVM.


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

5 Files Affected:

  • (modified) llvm/include/llvm/AsmParser/LLToken.h (+3)
  • (modified) llvm/include/llvm/IR/CallingConv.h (+11)
  • (modified) llvm/lib/AsmParser/LLLexer.cpp (+3)
  • (modified) llvm/lib/AsmParser/LLParser.cpp (+9)
  • (modified) llvm/lib/IR/AsmWriter.cpp (+9)
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..8a36df86af21a 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 dc6d599fa9585..0b52fa8aef8cb 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -428,6 +428,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;
   }
 }
 

@jrtc27
Copy link
Collaborator

jrtc27 commented Sep 1, 2025

These are a CHERIoT thing and should be named as such. I keep meaning to rip them out of CHERI LLVM as they only exist for the original MIPS-based compartmentalisation prototype.

@arichardson
Copy link
Member

Upstreaming these makes sense but I wonder if this should wait until we have more of the other core infrastructure landed?

@resistor
Copy link
Collaborator Author

resistor commented Sep 1, 2025

These are a CHERIoT thing and should be named as such. I keep meaning to rip them out of CHERI LLVM as they only exist for the original MIPS-based compartmentalisation prototype.

I'll rename and come back to this then.

@resistor
Copy link
Collaborator Author

resistor commented Sep 1, 2025

Upstreaming these makes sense but I wonder if this should wait until we have more of the other core infrastructure landed?

I would prefer to upstream things like enum values early, as they're minimally invasive to LLVM and save on merge conflicts for the downstream.

@arichardson
Copy link
Member

Upstreaming these makes sense but I wonder if this should wait until we have more of the other core infrastructure landed?

I would prefer to upstream things like enum values early, as they're minimally invasive to LLVM and save on merge conflicts for the downstream.

That is a good point - even though they are trivial, all these merge conflicts are very annoying.

…conventions.

This is the union of the calling conventions supported by the CTSRD and CHERIoT CHERI downstreams of LLVM.
@resistor
Copy link
Collaborator Author

resistor commented Sep 8, 2025

These are a CHERIoT thing and should be named as such. I keep meaning to rip them out of CHERI LLVM as they only exist for the original MIPS-based compartmentalisation prototype.

Done now.

Copy link

github-actions bot commented Sep 8, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@resistor resistor changed the title [CHERI] Add enum values and LL parse/print support for CHERI calling conventions. [CHERI] Add enum values and LL parse/print support for CHERIoT calling conventions. Sep 11, 2025
@resistor
Copy link
Collaborator Author

Gentle nudge.

@resistor
Copy link
Collaborator Author

Nudge

@nikic nikic added the cheri Related to CHERI support label Sep 17, 2025
Copy link
Contributor

@nikic nikic 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 someone working on CHERI should also approve.

Copy link
Member

@arichardson arichardson left a comment

Choose a reason for hiding this comment

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

LGTM

@resistor resistor merged commit 6438d01 into llvm:main Sep 22, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cheri Related to CHERI support llvm:ir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants