Skip to content

Commit 9312d5b

Browse files
authored
[llvm][RISCV] Handle required features of intrinsic correctly (#143062)
Current approach generates intrinsic records when users specify corresponding required features by using command line option. However it's not able to handle features passed by using target attributes correctly where each function might have different features. This patch resolves this by generating all of intrinsic records which carry the required features in their function declaration using attribute and check the required extensions in CheckBuiltinFunctionCall. This should fix [56592](#56592), [134962](#134962) and [121603](#121603)
1 parent e65d323 commit 9312d5b

File tree

13 files changed

+260
-357
lines changed

13 files changed

+260
-357
lines changed

clang/include/clang/Basic/riscv_andes_vector.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ multiclass RVVFPMAD {
3030
}
3131
}
3232

33-
let RequiredFeatures = ["Xandesvpackfph"],
33+
let RequiredFeatures = ["xandesvpackfph"],
3434
UnMaskedPolicyScheme = HasPassthruOperand in {
3535
let ManualCodegen = [{
3636
{
@@ -86,7 +86,7 @@ let ManualCodegen = [{
8686

8787
multiclass RVVD4DOT<list<list<string>> i_suffixes_prototypes,
8888
list<list<string>> l_suffixes_prototypes> {
89-
let RequiredFeatures = ["Xandesvdot"],
89+
let RequiredFeatures = ["xandesvdot"],
9090
UnMaskedPolicyScheme = HasPolicyOperand,
9191
HasMaskedOffOperand = false,
9292
Log2LMUL = [-1, 0, 1, 2, 3],

clang/include/clang/Basic/riscv_sifive_vector.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ multiclass RVVVCIXBuiltinSet<list<string> range, string prototype,
5050
string suffix = "Uv"> {
5151
foreach r = range in
5252
let RequiredFeatures = !if(!and(UseGPR, !eq(r, "l")),
53-
["Xsfvcp", "RV64"], ["Xsfvcp"]) in
53+
["xsfvcp", "64bit"], ["xsfvcp"]) in
5454
defm : VCIXBuiltinSet<NAME, NAME, suffix, prototype, r, intrinsic_types>;
5555
}
5656

@@ -126,26 +126,26 @@ multiclass RVVVFNRCLIPBuiltinSet<string suffix, string prototype, string type_ra
126126
}
127127

128128
let UnMaskedPolicyScheme = HasPolicyOperand in
129-
let RequiredFeatures = ["Xsfvqmaccdod"] in {
129+
let RequiredFeatures = ["xsfvqmaccdod"] in {
130130
defm sf_vqmaccu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", "vv(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
131131
defm sf_vqmacc_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", "vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
132132
defm sf_vqmaccus_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", "vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
133133
defm sf_vqmaccsu_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", "vv(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
134134
}
135135

136136
let UnMaskedPolicyScheme = HasPolicyOperand in
137-
let RequiredFeatures = ["Xsfvqmaccqoq"] in {
137+
let RequiredFeatures = ["xsfvqmaccqoq"] in {
138138
defm sf_vqmaccu_4x8x4 : RVVVQMACCQOQBuiltinSet<[["", "w", "ww(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
139139
defm sf_vqmacc_4x8x4 : RVVVQMACCQOQBuiltinSet<[["", "w", "ww(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
140140
defm sf_vqmaccus_4x8x4 : RVVVQMACCQOQBuiltinSet<[["", "w", "ww(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
141141
defm sf_vqmaccsu_4x8x4 : RVVVQMACCQOQBuiltinSet<[["", "w", "ww(FixedSEW:8)Sv(FixedSEW:8)Uv"]]>;
142142
}
143143

144144
let UnMaskedPolicyScheme = HasPolicyOperand in
145-
let RequiredFeatures = ["Xsfvfwmaccqqq"] in
145+
let RequiredFeatures = ["xsfvfwmaccqqq"] in
146146
defm sf_vfwmacc_4x4x4 : RVVVFWMACCBuiltinSet<[["", "Fw", "FwFwSvv"]]>;
147147

148-
let UnMaskedPolicyScheme = HasPassthruOperand, RequiredFeatures = ["Xsfvfnrclipxfqf"] in {
148+
let UnMaskedPolicyScheme = HasPassthruOperand, RequiredFeatures = ["xsfvfnrclipxfqf"] in {
149149
let ManualCodegen = [{
150150
{
151151
// LLVM intrinsic

clang/include/clang/Basic/riscv_vector.td

Lines changed: 120 additions & 128 deletions
Large diffs are not rendered by default.

clang/include/clang/Basic/riscv_vector_common.td

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ let HasMaskedOffOperand = false in {
466466
defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
467467
[["vv", "v", "vvvv"],
468468
["vf", "v", "vvev"]]>;
469-
let RequiredFeatures = ["Zvfh"] in
469+
let RequiredFeatures = ["zvfh"] in
470470
defm "" : RVVOutOp1BuiltinSet<NAME, "x",
471471
[["vv", "v", "vvvv"],
472472
["vf", "v", "vvev"]]>;
@@ -475,7 +475,7 @@ let HasMaskedOffOperand = false in {
475475
defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
476476
[["vv", "v", "vvvvu"],
477477
["vf", "v", "vvevu"]]>;
478-
let RequiredFeatures = ["Zvfh"] in
478+
let RequiredFeatures = ["zvfh"] in
479479
defm "" : RVVOutOp1BuiltinSet<NAME, "x",
480480
[["vv", "v", "vvvvu"],
481481
["vf", "v", "vvevu"]]>;
@@ -487,7 +487,7 @@ let HasMaskedOffOperand = false, Log2LMUL = [-2, -1, 0, 1, 2] in {
487487
defm "" : RVVOutOp1Op2BuiltinSet<NAME, "f",
488488
[["vv", "w", "wwvv"],
489489
["vf", "w", "wwev"]]>;
490-
let RequiredFeatures = ["Zvfh"] in
490+
let RequiredFeatures = ["zvfh"] in
491491
defm "" : RVVOutOp1Op2BuiltinSet<NAME, "x",
492492
[["vv", "w", "wwvv"],
493493
["vf", "w", "wwev"]]>;
@@ -496,7 +496,7 @@ let HasMaskedOffOperand = false, Log2LMUL = [-2, -1, 0, 1, 2] in {
496496
defm "" : RVVOutOp1Op2BuiltinSet<NAME, "f",
497497
[["vv", "w", "wwvvu"],
498498
["vf", "w", "wwevu"]]>;
499-
let RequiredFeatures = ["Zvfh"] in
499+
let RequiredFeatures = ["zvfh"] in
500500
defm "" : RVVOutOp1Op2BuiltinSet<NAME, "x",
501501
[["vv", "w", "wwvvu"],
502502
["vf", "w", "wwevu"]]>;
@@ -507,7 +507,7 @@ multiclass RVVFloatingBinBuiltinSet {
507507
defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
508508
[["vv", "v", "vvv"],
509509
["vf", "v", "vve"]]>;
510-
let RequiredFeatures = ["Zvfh"] in
510+
let RequiredFeatures = ["zvfh"] in
511511
defm "" : RVVOutOp1BuiltinSet<NAME, "x",
512512
[["vv", "v", "vvv"],
513513
["vf", "v", "vve"]]>;
@@ -517,7 +517,7 @@ multiclass RVVFloatingBinBuiltinSetRoundingMode {
517517
defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
518518
[["vv", "v", "vvvu"],
519519
["vf", "v", "vveu"]]>;
520-
let RequiredFeatures = ["Zvfh"] in
520+
let RequiredFeatures = ["zvfh"] in
521521
defm "" : RVVOutOp1BuiltinSet<NAME, "x",
522522
[["vv", "v", "vvvu"],
523523
["vf", "v", "vveu"]]>;
@@ -526,15 +526,15 @@ multiclass RVVFloatingBinBuiltinSetRoundingMode {
526526
multiclass RVVFloatingBinVFBuiltinSet {
527527
defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
528528
[["vf", "v", "vve"]]>;
529-
let RequiredFeatures = ["Zvfh"] in
529+
let RequiredFeatures = ["zvfh"] in
530530
defm "" : RVVOutOp1BuiltinSet<NAME, "x",
531531
[["vf", "v", "vve"]]>;
532532
}
533533

534534
multiclass RVVFloatingBinVFBuiltinSetRoundingMode {
535535
defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
536536
[["vf", "v", "vveu"]]>;
537-
let RequiredFeatures = ["Zvfh"] in
537+
let RequiredFeatures = ["zvfh"] in
538538
defm "" : RVVOutOp1BuiltinSet<NAME, "x",
539539
[["vf", "v", "vveu"]]>;
540540
}
@@ -543,7 +543,7 @@ multiclass RVVFloatingMaskOutBuiltinSet {
543543
defm "" : RVVOp0Op1BuiltinSet<NAME, "fd",
544544
[["vv", "vm", "mvv"],
545545
["vf", "vm", "mve"]]>;
546-
let RequiredFeatures = ["Zvfh"] in
546+
let RequiredFeatures = ["zvfh"] in
547547
defm "" : RVVOp0Op1BuiltinSet<NAME, "x",
548548
[["vv", "vm", "mvv"],
549549
["vf", "vm", "mve"]]>;
@@ -593,7 +593,7 @@ let UnMaskedPolicyScheme = HasPolicyOperand,
593593
multiclass RVVSlideUpBuiltinSet {
594594
defm "" : RVVOutBuiltinSet<NAME, "csilfd",
595595
[["vx","v", "vvvz"]]>;
596-
let RequiredFeatures = ["Zvfh"] in
596+
let RequiredFeatures = ["zvfh"] in
597597
defm "" : RVVOutBuiltinSet<NAME, "x",
598598
[["vx","v", "vvvz"]]>;
599599
defm "" : RVVOutBuiltinSet<NAME, "csil",
@@ -618,7 +618,7 @@ let UnMaskedPolicyScheme = HasPassthruOperand,
618618
multiclass RVVSlideDownBuiltinSet {
619619
defm "" : RVVOutBuiltinSet<NAME, "csilfd",
620620
[["vx","v", "vvz"]]>;
621-
let RequiredFeatures = ["Zvfh"] in
621+
let RequiredFeatures = ["zvfh"] in
622622
defm "" : RVVOutBuiltinSet<NAME, "x",
623623
[["vx","v", "vvz"]]>;
624624
defm "" : RVVOutBuiltinSet<NAME, "csil",
@@ -663,28 +663,28 @@ let HasMaskedOffOperand = true in {
663663
multiclass RVVFloatingReductionBuiltin {
664664
defm "" : RVVOutOp0BuiltinSet<NAME, "fd",
665665
[["vs", "vSv", "SvvSv"]]>;
666-
let RequiredFeatures = ["Zvfh"] in
666+
let RequiredFeatures = ["zvfh"] in
667667
defm "" : RVVOutOp0BuiltinSet<NAME, "x",
668668
[["vs", "vSv", "SvvSv"]]>;
669669
}
670670
multiclass RVVFloatingReductionBuiltinRoundingMode {
671671
defm "" : RVVOutOp0BuiltinSet<NAME, "fd",
672672
[["vs", "vSv", "SvvSvu"]]>;
673-
let RequiredFeatures = ["Zvfh"] in
673+
let RequiredFeatures = ["zvfh"] in
674674
defm "" : RVVOutOp0BuiltinSet<NAME, "x",
675675
[["vs", "vSv", "SvvSvu"]]>;
676676
}
677677
multiclass RVVFloatingWidenReductionBuiltin {
678678
defm "" : RVVOutOp0BuiltinSet<NAME, "f",
679679
[["vs", "vSw", "SwvSw"]]>;
680-
let RequiredFeatures = ["Zvfh"] in
680+
let RequiredFeatures = ["zvfh"] in
681681
defm "" : RVVOutOp0BuiltinSet<NAME, "x",
682682
[["vs", "vSw", "SwvSw"]]>;
683683
}
684684
multiclass RVVFloatingWidenReductionBuiltinRoundingMode {
685685
defm "" : RVVOutOp0BuiltinSet<NAME, "f",
686686
[["vs", "vSw", "SwvSwu"]]>;
687-
let RequiredFeatures = ["Zvfh"] in
687+
let RequiredFeatures = ["zvfh"] in
688688
defm "" : RVVOutOp0BuiltinSet<NAME, "x",
689689
[["vs", "vSw", "SwvSwu"]]>;
690690
}
@@ -750,7 +750,7 @@ multiclass RVVFloatingWidenBinBuiltinSet {
750750
defm "" : RVVWidenBuiltinSet<NAME, "f",
751751
[["vv", "w", "wvv"],
752752
["vf", "w", "wve"]]>;
753-
let RequiredFeatures = ["Zvfh"] in
753+
let RequiredFeatures = ["zvfh"] in
754754
defm "" : RVVWidenBuiltinSet<NAME, "x",
755755
[["vv", "w", "wvv"],
756756
["vf", "w", "wve"]]>;
@@ -760,7 +760,7 @@ multiclass RVVFloatingWidenBinBuiltinSetRoundingMode {
760760
defm "" : RVVWidenBuiltinSet<NAME, "f",
761761
[["vv", "w", "wvvu"],
762762
["vf", "w", "wveu"]]>;
763-
let RequiredFeatures = ["Zvfh"] in
763+
let RequiredFeatures = ["zvfh"] in
764764
defm "" : RVVWidenBuiltinSet<NAME, "x",
765765
[["vv", "w", "wvvu"],
766766
["vf", "w", "wveu"]]>;
@@ -770,7 +770,7 @@ multiclass RVVFloatingWidenOp0BinBuiltinSet {
770770
defm "" : RVVWidenWOp0BuiltinSet<NAME # "_w", "f",
771771
[["wv", "w", "wwv"],
772772
["wf", "w", "wwe"]]>;
773-
let RequiredFeatures = ["Zvfh"] in
773+
let RequiredFeatures = ["zvfh"] in
774774
defm "" : RVVWidenWOp0BuiltinSet<NAME # "_w", "x",
775775
[["wv", "w", "wwv"],
776776
["wf", "w", "wwe"]]>;
@@ -780,7 +780,7 @@ multiclass RVVFloatingWidenOp0BinBuiltinSetRoundingMode {
780780
defm "" : RVVWidenWOp0BuiltinSet<NAME # "_w", "f",
781781
[["wv", "w", "wwvu"],
782782
["wf", "w", "wweu"]]>;
783-
let RequiredFeatures = ["Zvfh"] in
783+
let RequiredFeatures = ["zvfh"] in
784784
defm "" : RVVWidenWOp0BuiltinSet<NAME # "_w", "x",
785785
[["wv", "w", "wwvu"],
786786
["wf", "w", "wweu"]]>;

clang/include/clang/Support/RISCVVIntrinsicUtils.h

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/ADT/BitmaskEnum.h"
14-
#include "llvm/ADT/Bitset.h"
1514
#include "llvm/ADT/SmallVector.h"
1615
#include "llvm/ADT/StringRef.h"
1716
#include <cstdint>
@@ -484,51 +483,6 @@ class RVVIntrinsic {
484483
Policy &PolicyAttrs, bool HasFRMRoundModeOp);
485484
};
486485

487-
// RVVRequire should be sync'ed with target features, but only
488-
// required features used in riscv_vector.td.
489-
enum RVVRequire {
490-
RVV_REQ_RV64,
491-
RVV_REQ_Zvfhmin,
492-
RVV_REQ_Xandesvdot,
493-
RVV_REQ_Xandesvpackfph,
494-
RVV_REQ_Xsfvcp,
495-
RVV_REQ_Xsfvfnrclipxfqf,
496-
RVV_REQ_Xsfvfwmaccqqq,
497-
RVV_REQ_Xsfvqmaccdod,
498-
RVV_REQ_Xsfvqmaccqoq,
499-
RVV_REQ_Zvbb,
500-
RVV_REQ_Zvbc,
501-
RVV_REQ_Zvkb,
502-
RVV_REQ_Zvkg,
503-
RVV_REQ_Zvkned,
504-
RVV_REQ_Zvknha,
505-
RVV_REQ_Zvknhb,
506-
RVV_REQ_Zvksed,
507-
RVV_REQ_Zvksh,
508-
RVV_REQ_Zvfbfwma,
509-
RVV_REQ_Zvfbfmin,
510-
RVV_REQ_Zvfh,
511-
RVV_REQ_Experimental,
512-
RVV_REQ_NUM,
513-
};
514-
515-
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum RVVRequire Require);
516-
517-
struct RequiredExtensionBits {
518-
llvm::Bitset<RVV_REQ_NUM> Bits;
519-
RequiredExtensionBits() {}
520-
RequiredExtensionBits(std::initializer_list<RVVRequire> Init) {
521-
for (auto I : Init)
522-
Bits.set(I);
523-
}
524-
525-
void set(unsigned I) { Bits.set(I); }
526-
bool operator[](unsigned I) const { return Bits[I]; }
527-
};
528-
529-
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
530-
const RequiredExtensionBits &Exts);
531-
532486
// Raw RVV intrinsic info, used to expand later.
533487
// This struct is highly compact for minimized code size.
534488
struct RVVIntrinsicRecord {
@@ -540,7 +494,7 @@ struct RVVIntrinsicRecord {
540494
const char *OverloadedName;
541495

542496
// Required target features for this intrinsic.
543-
RequiredExtensionBits RequiredExtensions;
497+
const char *RequiredExtensions;
544498

545499
// Prototype for this intrinsic, index of RVVSignatureTable.
546500
uint16_t PrototypeIndex;

0 commit comments

Comments
 (0)