Skip to content

Commit ab1a20c

Browse files
authored
merge main into amd-staging (llvm#1854)
2 parents e42c601 + b0bce09 commit ab1a20c

File tree

101 files changed

+2805
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2805
-375
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,12 @@ RISC-V Support
654654
^^^^^^^^^^^^^^
655655

656656
- Add support for `-mtune=generic-ooo` (a generic out-of-order model).
657+
- Adds support for `__attribute__((interrupt("SiFive-CLIC-preemptible")))` and
658+
`__attribute__((interrupt("SiFive-CLIC-stack-swap")))`. The former
659+
automatically saves some interrupt CSRs before re-enabling interrupts in the
660+
function prolog, the latter swaps `sp` with the value in a CSR before it is
661+
used or modified. These two can also be combined, and can be combined with
662+
`interrupt("machine")`.
657663

658664
- Adds support for `__attribute__((interrupt("qci-nest")))` and
659665
`__attribute__((interrupt("qci-nonest")))`. These use instructions from

clang/include/clang/Basic/Attr.td

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,10 +2252,23 @@ def NoMicroMips : InheritableAttr, TargetSpecificAttr<TargetMips32> {
22522252
def RISCVInterrupt : InheritableAttr, TargetSpecificAttr<TargetRISCV> {
22532253
let Spellings = [GCC<"interrupt">];
22542254
let Subjects = SubjectList<[Function]>;
2255-
let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
2256-
["supervisor", "machine", "qci-nest", "qci-nonest"],
2257-
["supervisor", "machine", "qcinest", "qcinonest"],
2258-
1>];
2255+
let Args = [VariadicEnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,
2256+
[
2257+
"supervisor",
2258+
"machine",
2259+
"qci-nest",
2260+
"qci-nonest",
2261+
"SiFive-CLIC-preemptible",
2262+
"SiFive-CLIC-stack-swap",
2263+
],
2264+
[
2265+
"supervisor",
2266+
"machine",
2267+
"qcinest",
2268+
"qcinonest",
2269+
"SiFiveCLICPreemptible",
2270+
"SiFiveCLICStackSwap",
2271+
]>];
22592272
let ParseKind = "Interrupt";
22602273
let Documentation = [RISCVInterruptDocs];
22612274
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,8 +2900,9 @@ targets. This attribute may be attached to a function definition and instructs
29002900
the backend to generate appropriate function entry/exit code so that it can be
29012901
used directly as an interrupt service routine.
29022902

2903-
Permissible values for this parameter are ``supervisor``, ``machine``,
2904-
``qci-nest`` and ``qci-nonest``. If there is no parameter, then it defaults to
2903+
Permissible values for this parameter are ``machine``, ``supervisor``,
2904+
``qci-nest``, ``qci-nonest``, ``SiFive-CLIC-preemptible``, and
2905+
``SiFive-CLIC-stack-swap``. If there is no parameter, then it defaults to
29052906
``machine``.
29062907

29072908
The ``qci-nest`` and ``qci-nonest`` values require Qualcomm's Xqciint extension
@@ -2912,6 +2913,15 @@ restore interrupt state to the stack -- the ``qci-nest`` value will use
29122913
begin the interrupt handler. Both of these will use ``qc.c.mileaveret`` to
29132914
restore the state and return to the previous context.
29142915

2916+
The ``SiFive-CLIC-preemptible`` and ``SiFive-CLIC-stack-swap`` values are used
2917+
for machine-mode interrupts. For ``SiFive-CLIC-preemptible`` interrupts, the
2918+
values of ``mcause`` and ``mepc`` are saved onto the stack, and interrupts are
2919+
re-enabled. For ``SiFive-CLIC-stack-swap`` interrupts, the stack pointer is
2920+
swapped with ``mscratch`` before its first use and after its last use.
2921+
2922+
The SiFive CLIC values may be combined with each other and with the ``machine``
2923+
attribute value. Any other combination of different values is not allowed.
2924+
29152925
Repeated interrupt attribute on the same declaration will cause a warning
29162926
to be emitted. In case of repeated declarations, the last one prevails.
29172927

@@ -2921,6 +2931,7 @@ https://riscv.org/specifications/privileged-isa/
29212931
The RISC-V Instruction Set Manual Volume II: Privileged Architecture
29222932
Version 1.10.
29232933
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7
2934+
https://sifive.cdn.prismic.io/sifive/d1984d2b-c9b9-4c91-8de0-d68a5e64fa0f_sifive-interrupt-cookbook-v1p2.pdf
29242935
}];
29252936
}
29262937

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12767,7 +12767,9 @@ def err_riscv_builtin_invalid_lmul : Error<
1276712767
def err_riscv_type_requires_extension : Error<
1276812768
"RISC-V type %0 requires the '%1' extension">;
1276912769
def err_riscv_attribute_interrupt_requires_extension : Error<
12770-
"RISC-V interrupt attribute '%0' requires extension '%1'">;
12770+
"RISC-V 'interrupt' attribute '%0' requires extension '%1'">;
12771+
def err_riscv_attribute_interrupt_invalid_combination : Error<
12772+
"RISC-V 'interrupt' attribute contains invalid combination of interrupt types">;
1277112773

1277212774
def err_std_source_location_impl_not_found : Error<
1277312775
"'std::source_location::__impl' was not found; it must be defined before '__builtin_source_location' is called">;

clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#endif
2828

2929
// Defines the various types of enum
30+
#ifndef UNBOUNDED_ENUM
31+
#define UNBOUNDED_ENUM(NAME, LIT) ENUM(NAME, LIT)
32+
#endif
3033
#ifndef DESCRIPTOR_RANGE_OFFSET_ENUM
3134
#define DESCRIPTOR_RANGE_OFFSET_ENUM(NAME, LIT) ENUM(NAME, LIT)
3235
#endif
@@ -87,6 +90,9 @@ KEYWORD(flags)
8790
KEYWORD(numDescriptors)
8891
KEYWORD(offset)
8992

93+
// Unbounded Enum:
94+
UNBOUNDED_ENUM(unbounded, "unbounded")
95+
9096
// Descriptor Range Offset Enum:
9197
DESCRIPTOR_RANGE_OFFSET_ENUM(DescriptorRangeOffsetAppend, "DESCRIPTOR_RANGE_OFFSET_APPEND")
9298

@@ -118,6 +124,7 @@ SHADER_VISIBILITY_ENUM(Mesh, "SHADER_VISIBILITY_MESH")
118124
#undef DESCRIPTOR_RANGE_FLAG_ENUM_ON
119125
#undef ROOT_DESCRIPTOR_FLAG_ENUM
120126
#undef DESCRIPTOR_RANGE_OFFSET_ENUM
127+
#undef UNBOUNDED_ENUM
121128
#undef ENUM
122129
#undef KEYWORD
123130
#undef PUNCTUATOR

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class RootSignatureParser {
8080
/// state of parsed params
8181
struct ParsedClauseParams {
8282
std::optional<llvm::hlsl::rootsig::Register> Reg;
83+
std::optional<uint32_t> NumDescriptors;
8384
std::optional<uint32_t> Space;
85+
std::optional<uint32_t> Offset;
8486
std::optional<llvm::hlsl::rootsig::DescriptorRangeFlags> Flags;
8587
};
8688
std::optional<ParsedClauseParams>

clang/lib/CodeGen/Targets/RISCV.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -829,16 +829,39 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
829829
if (!Attr)
830830
return;
831831

832-
const char *Kind;
833-
switch (Attr->getInterrupt()) {
834-
case RISCVInterruptAttr::supervisor: Kind = "supervisor"; break;
835-
case RISCVInterruptAttr::machine: Kind = "machine"; break;
836-
case RISCVInterruptAttr::qcinest:
837-
Kind = "qci-nest";
838-
break;
839-
case RISCVInterruptAttr::qcinonest:
840-
Kind = "qci-nonest";
841-
break;
832+
StringRef Kind = "machine";
833+
bool HasSiFiveCLICPreemptible = false;
834+
bool HasSiFiveCLICStackSwap = false;
835+
for (RISCVInterruptAttr::InterruptType type : Attr->interrupt()) {
836+
switch (type) {
837+
case RISCVInterruptAttr::machine:
838+
// Do not update `Kind` because `Kind` is already "machine", or the
839+
// kinds also contains SiFive types which need to be applied.
840+
break;
841+
case RISCVInterruptAttr::supervisor:
842+
Kind = "supervisor";
843+
break;
844+
case RISCVInterruptAttr::qcinest:
845+
Kind = "qci-nest";
846+
break;
847+
case RISCVInterruptAttr::qcinonest:
848+
Kind = "qci-nonest";
849+
break;
850+
// There are three different LLVM IR attribute values for SiFive CLIC
851+
// interrupt kinds, one for each kind and one extra for their combination.
852+
case RISCVInterruptAttr::SiFiveCLICPreemptible: {
853+
HasSiFiveCLICPreemptible = true;
854+
Kind = HasSiFiveCLICStackSwap ? "SiFive-CLIC-preemptible-stack-swap"
855+
: "SiFive-CLIC-preemptible";
856+
break;
857+
}
858+
case RISCVInterruptAttr::SiFiveCLICStackSwap: {
859+
HasSiFiveCLICStackSwap = true;
860+
Kind = HasSiFiveCLICPreemptible ? "SiFive-CLIC-preemptible-stack-swap"
861+
: "SiFive-CLIC-stack-swap";
862+
break;
863+
}
864+
}
842865
}
843866

844867
Fn->addFnAttr("interrupt", Kind);

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,15 @@ RootSignatureParser::parseDescriptorTableClause() {
145145
Clause.Reg = Params->Reg.value();
146146

147147
// Fill in optional values
148+
if (Params->NumDescriptors.has_value())
149+
Clause.NumDescriptors = Params->NumDescriptors.value();
150+
148151
if (Params->Space.has_value())
149152
Clause.Space = Params->Space.value();
150153

154+
if (Params->Offset.has_value())
155+
Clause.Offset = Params->Offset.value();
156+
151157
if (Params->Flags.has_value())
152158
Clause.Flags = Params->Flags.value();
153159

@@ -182,6 +188,29 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
182188
Params.Reg = Reg;
183189
}
184190

191+
// `numDescriptors` `=` POS_INT | unbounded
192+
if (tryConsumeExpectedToken(TokenKind::kw_numDescriptors)) {
193+
if (Params.NumDescriptors.has_value()) {
194+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
195+
<< CurToken.TokKind;
196+
return std::nullopt;
197+
}
198+
199+
if (consumeExpectedToken(TokenKind::pu_equal))
200+
return std::nullopt;
201+
202+
std::optional<uint32_t> NumDescriptors;
203+
if (tryConsumeExpectedToken(TokenKind::en_unbounded))
204+
NumDescriptors = NumDescriptorsUnbounded;
205+
else {
206+
NumDescriptors = parseUIntParam();
207+
if (!NumDescriptors.has_value())
208+
return std::nullopt;
209+
}
210+
211+
Params.NumDescriptors = NumDescriptors;
212+
}
213+
185214
// `space` `=` POS_INT
186215
if (tryConsumeExpectedToken(TokenKind::kw_space)) {
187216
if (Params.Space.has_value()) {
@@ -199,6 +228,29 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
199228
Params.Space = Space;
200229
}
201230

231+
// `offset` `=` POS_INT | DESCRIPTOR_RANGE_OFFSET_APPEND
232+
if (tryConsumeExpectedToken(TokenKind::kw_offset)) {
233+
if (Params.Offset.has_value()) {
234+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
235+
<< CurToken.TokKind;
236+
return std::nullopt;
237+
}
238+
239+
if (consumeExpectedToken(TokenKind::pu_equal))
240+
return std::nullopt;
241+
242+
std::optional<uint32_t> Offset;
243+
if (tryConsumeExpectedToken(TokenKind::en_DescriptorRangeOffsetAppend))
244+
Offset = DescriptorTableOffsetAppend;
245+
else {
246+
Offset = parseUIntParam();
247+
if (!Offset.has_value())
248+
return std::nullopt;
249+
}
250+
251+
Params.Offset = Offset;
252+
}
253+
202254
// `flags` `=` DESCRIPTOR_RANGE_FLAGS
203255
if (tryConsumeExpectedToken(TokenKind::kw_flags)) {
204256
if (Params.Flags.has_value()) {

0 commit comments

Comments
 (0)