Rollup merge of #111274 - cuviper:print-target-cpus, r=Mark-Simulacrum
Expand the LLVM coverage of `--print target-cpus` We've been relying on a custom patch to add `MCSubtargetInfo::getCPUTable` for `rustc --print target-cpus`, and just printing that it's not supported on external LLVM builds. LLVM `main` now has `getAllProcessorDescriptions` that can replace ours, so now we try to use that. In addition, the fallback path can at least print the native and default cpu options. There were also some mismatches in the function signatures here between `LLVM_RUSTLLVM` and otherwise; this is now mitigated by sharing these functions and only using cpp to adjust the function bodies.
This commit is contained in:
commit
ecc0615967
@ -297,7 +297,6 @@ static Reloc::Model fromRust(LLVMRustRelocModel RustReloc) {
|
||||
report_fatal_error("Bad RelocModel.");
|
||||
}
|
||||
|
||||
#ifdef LLVM_RUSTLLVM
|
||||
/// getLongestEntryLength - Return the length of the longest entry in the table.
|
||||
template<typename KV>
|
||||
static size_t getLongestEntryLength(ArrayRef<KV> Table) {
|
||||
@ -312,13 +311,23 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, const char* Tar
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const Triple::ArchType HostArch = Triple(sys::getDefaultTargetTriple()).getArch();
|
||||
const Triple::ArchType TargetArch = Target->getTargetTriple().getArch();
|
||||
|
||||
#if LLVM_VERSION_GE(17, 0)
|
||||
const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getAllProcessorDescriptions();
|
||||
#elif defined(LLVM_RUSTLLVM)
|
||||
const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getCPUTable();
|
||||
#else
|
||||
printf("Full target CPU help is not supported by this LLVM version.\n\n");
|
||||
SubtargetSubTypeKV TargetCPUKV = { TargetCPU, {{}}, {{}} };
|
||||
const ArrayRef<SubtargetSubTypeKV> CPUTable = TargetCPUKV;
|
||||
#endif
|
||||
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
|
||||
|
||||
printf("Available CPUs for this target:\n");
|
||||
// Don't print the "native" entry when the user specifies --target with a
|
||||
// different arch since that could be wrong or misleading.
|
||||
if (HostArch == TargetArch) {
|
||||
MaxCPULen = std::max(MaxCPULen, (unsigned) std::strlen("native"));
|
||||
const StringRef HostCPU = sys::getHostCPUName();
|
||||
printf(" %-*s - Select the CPU of the current host (currently %.*s).\n",
|
||||
MaxCPULen, "native", (int)HostCPU.size(), HostCPU.data());
|
||||
@ -338,34 +347,27 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, const char* Tar
|
||||
}
|
||||
|
||||
extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) {
|
||||
#ifdef LLVM_RUSTLLVM
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||
return FeatTable.size();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef TM, size_t Index,
|
||||
const char** Feature, const char** Desc) {
|
||||
#ifdef LLVM_RUSTLLVM
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||
const SubtargetFeatureKV Feat = FeatTable[Index];
|
||||
*Feature = Feat.Key;
|
||||
*Desc = Feat.Desc;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
|
||||
printf("Target CPU help is not supported by this LLVM version.\n\n");
|
||||
}
|
||||
|
||||
extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef, const char**, const char**) {}
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" const char* LLVMRustGetHostCPUName(size_t *len) {
|
||||
StringRef Name = sys::getHostCPUName();
|
||||
|
Loading…
Reference in New Issue
Block a user