-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[CHERI] Add enum values and LL parse/print support for CHERIoT calling conventions. #156328
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
Conversation
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 |
@llvm/pr-subscribers-llvm-ir Author: Owen Anderson (resistor) ChangesThis 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:
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;
}
}
|
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. |
Upstreaming these makes sense but I wonder if this should wait until we have more of the other core infrastructure landed? |
I'll rename and come back to this then. |
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.
Done now. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
Gentle nudge. |
Nudge |
Co-authored-by: Nikita Popov <[email protected]>
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This is the set of the calling conventions supported by the CHERIoT CHERI downstream of LLVM.