Skip to content

Commit 596d985

Browse files
committed
Adjust getMCSubtargetInfo signature for LLVM 23+
1 parent cb40c25 commit 596d985

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ extern "C" void LLVMRustTimeTraceProfilerFinish(const char *FileName) {
9191
extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
9292
const char *Feature) {
9393
TargetMachine *Target = unwrap(TM);
94+
#if LLVM_VERSION_GE(23, 0)
95+
const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo();
96+
return MCInfo.checkFeatures(std::string("+") + Feature);
97+
#else
9498
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
9599
return MCInfo->checkFeatures(std::string("+") + Feature);
100+
#endif
96101
}
97102

98103
/// Check whether the target has a specific assembly mnemonic like `ret` or
@@ -274,7 +279,11 @@ static llvm::DebugCompressionType fromRust(LLVMRustCompressionKind Kind) {
274279
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
275280
RustStringRef OutStr) {
276281
ArrayRef<SubtargetSubTypeKV> CPUTable =
282+
#if LLVM_VERSION_GE(23, 0)
283+
unwrap(TM)->getMCSubtargetInfo().getAllProcessorDescriptions();
284+
#else
277285
unwrap(TM)->getMCSubtargetInfo()->getAllProcessorDescriptions();
286+
#endif
278287
auto OS = RawRustStringOstream(OutStr);
279288

280289
// Just print a bare list of target CPU names, and let Rust-side code handle
@@ -286,19 +295,31 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
286295

287296
extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) {
288297
const TargetMachine *Target = unwrap(TM);
298+
#if LLVM_VERSION_GE(23, 0)
299+
const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo();
300+
const ArrayRef<SubtargetFeatureKV> FeatTable =
301+
MCInfo.getAllProcessorFeatures();
302+
#else
289303
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
290304
const ArrayRef<SubtargetFeatureKV> FeatTable =
291305
MCInfo->getAllProcessorFeatures();
306+
#endif
292307
return FeatTable.size();
293308
}
294309

295310
extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef TM, size_t Index,
296311
const char **Feature,
297312
const char **Desc) {
298313
const TargetMachine *Target = unwrap(TM);
314+
#if LLVM_VERSION_GE(23, 0)
315+
const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo();
316+
const ArrayRef<SubtargetFeatureKV> FeatTable =
317+
MCInfo.getAllProcessorFeatures();
318+
#else
299319
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
300320
const ArrayRef<SubtargetFeatureKV> FeatTable =
301321
MCInfo->getAllProcessorFeatures();
322+
#endif
302323
const SubtargetFeatureKV Feat = FeatTable[Index];
303324
*Feature = Feat.Key;
304325
*Desc = Feat.Desc;

0 commit comments

Comments
 (0)