Skip to content

Commit 0e5b6b9

Browse files
authored
Rollup merge of #156156 - DKLoehr:subtarget_info, r=cuviper
Adjust getMCSubtargetInfo signature for LLVM 23+ A recent [LLVM PR](llvm/llvm-project#195032) changed the signature of `getMCSubtargetInfo` to return a reference instead of a pointer. This adjusts uses of the function in `compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp` to account for the different signature.
2 parents aff6ef8 + 7f69708 commit 0e5b6b9

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

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

98102
/// Check whether the target has a specific assembly mnemonic like `ret` or
@@ -274,7 +278,11 @@ static llvm::DebugCompressionType fromRust(LLVMRustCompressionKind Kind) {
274278
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
275279
RustStringRef OutStr) {
276280
ArrayRef<SubtargetSubTypeKV> CPUTable =
281+
#if LLVM_VERSION_GE(23, 0)
282+
unwrap(TM)->getMCSubtargetInfo().getAllProcessorDescriptions();
283+
#else
277284
unwrap(TM)->getMCSubtargetInfo()->getAllProcessorDescriptions();
285+
#endif
278286
auto OS = RawRustStringOstream(OutStr);
279287

280288
// Just print a bare list of target CPU names, and let Rust-side code handle
@@ -286,19 +294,27 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
286294

287295
extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) {
288296
const TargetMachine *Target = unwrap(TM);
289-
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
297+
#if LLVM_VERSION_GE(23, 0)
298+
const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo();
299+
#else
300+
const MCSubtargetInfo &MCInfo = *Target->getMCSubtargetInfo();
301+
#endif
290302
const ArrayRef<SubtargetFeatureKV> FeatTable =
291-
MCInfo->getAllProcessorFeatures();
303+
MCInfo.getAllProcessorFeatures();
292304
return FeatTable.size();
293305
}
294306

295307
extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef TM, size_t Index,
296308
const char **Feature,
297309
const char **Desc) {
298310
const TargetMachine *Target = unwrap(TM);
299-
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
311+
#if LLVM_VERSION_GE(23, 0)
312+
const MCSubtargetInfo &MCInfo = Target->getMCSubtargetInfo();
313+
#else
314+
const MCSubtargetInfo &MCInfo = *Target->getMCSubtargetInfo();
315+
#endif
300316
const ArrayRef<SubtargetFeatureKV> FeatTable =
301-
MCInfo->getAllProcessorFeatures();
317+
MCInfo.getAllProcessorFeatures();
302318
const SubtargetFeatureKV Feat = FeatTable[Index];
303319
*Feature = Feat.Key;
304320
*Desc = Feat.Desc;

0 commit comments

Comments
 (0)