Skip to content

Commit c156d42

Browse files
authored
[RISCV] Remove SeenExtMap from RISCVISAInfo::parseArchString. (#97506)
Use the Exts map directly instead of adding to a temporary MapVector first. There are a couple functional change from this. -If an unknown extension is duplicated, we will now print an error for it being unknown instead of an error for it being duplicated. -If an unknown extension is followed by an underscore with no extension after it, we will error for the unknown extension instead of the dangling underscore. These don't seem like serious changes to me. I've updated tests accordingly.
1 parent 97dc508 commit c156d42

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

clang/test/Driver/riscv-arch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
307307
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
308308
// RV32-XSEP: error: invalid arch name 'rv32ixabc_',
309-
// RV32-XSEP: extension name missing after separator '_'
309+
// RV32-XSEP: unsupported non-standard user-level extension 'xabc'
310310

311311
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
312312
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
@@ -318,10 +318,10 @@
318318
// RV32-X-ORDER: error: invalid arch name 'rv32ixdef_sabc',
319319
// RV32-X-ORDER unsupported non-standard user-level extension 'xdef'
320320

321-
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_xabc -### %s \
321+
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32im_m -### %s \
322322
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XDUP %s
323-
// RV32-XDUP: error: invalid arch name 'rv32ixabc_xabc',
324-
// RV32-XDUP: duplicated non-standard user-level extension 'xabc'
323+
// RV32-XDUP: error: invalid arch name 'rv32im_m',
324+
// RV32-XDUP: duplicated standard user-level extension 'm'
325325

326326
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_xdef -### %s \
327327
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-X-X-INVAL %s

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/TargetParser/RISCVISAInfo.h"
10-
#include "llvm/ADT/MapVector.h"
1110
#include "llvm/ADT/STLExtras.h"
12-
#include "llvm/ADT/SetVector.h"
1311
#include "llvm/ADT/StringExtras.h"
1412
#include "llvm/ADT/StringRef.h"
1513
#include "llvm/Support/Errc.h"
@@ -558,9 +556,6 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
558556
"profile name");
559557

560558
std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
561-
MapVector<std::string, RISCVISAUtils::ExtensionVersion,
562-
std::map<std::string, unsigned>>
563-
SeenExtMap;
564559

565560
// The canonical order specified in ISA manual.
566561
// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
@@ -583,8 +578,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
583578
EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
584579
return std::move(E);
585580

586-
// Postpone AddExtension until end of this function
587-
SeenExtMap[StringRef(&Baseline, 1).str()] = {Major, Minor};
581+
ISAInfo->Exts[std::string(1, Baseline)] = {Major, Minor};
588582
break;
589583
case 'g':
590584
// g expands to extensions in RISCVGImplications.
@@ -597,11 +591,11 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
597591
// No matter which version is given to `g`, we always set imafd to default
598592
// version since the we don't have clear version scheme for that on
599593
// ISA spec.
600-
for (const auto *Ext : RISCVGImplications) {
594+
for (const char *Ext : RISCVGImplications) {
601595
auto Version = findDefaultVersion(Ext);
602596
assert(Version && "Default extension version not found?");
603597
// Postpone AddExtension until end of this function
604-
SeenExtMap[Ext] = {Version->Major, Version->Minor};
598+
ISAInfo->Exts[std::string(Ext)] = {Version->Major, Version->Minor};
605599
}
606600
break;
607601
}
@@ -662,23 +656,19 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
662656
if (Name.size() == 1)
663657
Ext = Ext.substr(ConsumeLength);
664658

665-
// Check if duplicated extension.
666-
if (SeenExtMap.contains(Name.str()))
659+
if (!RISCVISAInfo::isSupportedExtension(Name))
660+
return getErrorForInvalidExt(Name);
661+
662+
// Insert and error for duplicates.
663+
if (!ISAInfo->Exts
664+
.emplace(Name.str(),
665+
RISCVISAUtils::ExtensionVersion{Major, Minor})
666+
.second)
667667
return getError("duplicated " + Desc + " '" + Name + "'");
668668

669-
SeenExtMap[Name.str()] = {Major, Minor};
670669
} while (!Ext.empty());
671670
}
672671

673-
// Check all Extensions are supported.
674-
for (auto &SeenExtAndVers : SeenExtMap) {
675-
const std::string &ExtName = SeenExtAndVers.first;
676-
677-
if (!RISCVISAInfo::isSupportedExtension(ExtName))
678-
return getErrorForInvalidExt(ExtName);
679-
ISAInfo->Exts[ExtName] = SeenExtAndVers.second;
680-
}
681-
682672
return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
683673
}
684674

0 commit comments

Comments
 (0)