Skip to content

Commit d50631f

Browse files
authored
MCContext/TargetMachine: Take MCRegisterInfo and MCSubtargetInfo by reference. NFC (llvm#195032)
Both MCRegisterInfo and MCSubtargetInfo are non-null at every callsite that matters (only nullable in unit tests like `llvm/unittests/CodeGen/MFCommon.inc`), mirroring the recent `const MCAsmInfo &` cleanup. * TargetMachine::getMCRegisterInfo and getMCSubtargetInfo return references. * MCContext's constructor takes const MCRegisterInfo & and const MCSubtargetInfo &.
1 parent 5f9b0ad commit d50631f

72 files changed

Lines changed: 140 additions & 134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,7 @@ class BinaryContext {
15451545
/// won't be used in the main code emitter.
15461546
IndependentCodeEmitter createIndependentMCCodeEmitter() const {
15471547
IndependentCodeEmitter MCEInstance;
1548-
MCEInstance.LocalCtx.reset(
1549-
new MCContext(*TheTriple, *AsmInfo, MRI.get(), STI.get()));
1548+
MCEInstance.LocalCtx.reset(new MCContext(*TheTriple, *AsmInfo, *MRI, *STI));
15501549
MCEInstance.LocalMOFI.reset(
15511550
TheTarget->createMCObjectFileInfo(*MCEInstance.LocalCtx,
15521551
/*PIC=*/!HasFixedLoadAddress));

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Expected<std::unique_ptr<BinaryContext>> BinaryContext::createBinaryContext(
255255
Twine("BOLT-ERROR: no instruction info for target ", TripleName));
256256

257257
std::unique_ptr<MCContext> Ctx(
258-
new MCContext(TheTriple, *AsmInfo, MRI.get(), STI.get()));
258+
new MCContext(TheTriple, *AsmInfo, *MRI, *STI));
259259
std::unique_ptr<MCObjectFileInfo> MOFI(
260260
TheTarget->createMCObjectFileInfo(*Ctx, IsPIC));
261261
Ctx->setObjectFileInfo(MOFI.get());

clang/lib/Parse/ParseStmtAsm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
566566
}
567567

568568
llvm::SourceMgr TempSrcMgr;
569-
llvm::MCContext Ctx(TheTriple, *MAI, MRI.get(), STI.get(), &TempSrcMgr);
569+
llvm::MCContext Ctx(TheTriple, *MAI, *MRI, *STI, &TempSrcMgr);
570570
std::unique_ptr<llvm::MCObjectFileInfo> MOFI(
571571
TheTarget->createMCObjectFileInfo(Ctx, /*PIC=*/false));
572572
Ctx.setObjectFileInfo(MOFI.get());

clang/tools/driver/cc1_main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ static int PrintSupportedExtensions(std::string TargetStr) {
144144
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
145145
TheTarget->createTargetMachine(Triple, "", "", Options, std::nullopt));
146146
const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
147-
const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
147+
const llvm::MCSubtargetInfo &MCInfo = TheTargetMachine->getMCSubtargetInfo();
148148
const llvm::ArrayRef<llvm::SubtargetFeatureKV> Features =
149-
MCInfo->getAllProcessorFeatures();
149+
MCInfo.getAllProcessorFeatures();
150150

151151
llvm::StringMap<llvm::StringRef> DescMap;
152152
for (const llvm::SubtargetFeatureKV &feature : Features)
@@ -187,13 +187,13 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
187187
TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
188188
BackendOptions, std::nullopt));
189189
const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
190-
const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
190+
const llvm::MCSubtargetInfo &MCInfo = TheTargetMachine->getMCSubtargetInfo();
191191

192192
// Extract the feature names that are enabled for the given target.
193193
// We do that by capturing the key from the set of SubtargetFeatureKV entries
194194
// provided by MCSubtargetInfo, which match the '-target-feature' values.
195195
const std::vector<llvm::SubtargetFeatureKV> Features =
196-
MCInfo->getEnabledProcessorFeatures();
196+
MCInfo.getEnabledProcessorFeatures();
197197
std::set<llvm::StringRef> EnabledFeatureNames;
198198
for (const llvm::SubtargetFeatureKV &feature : Features)
199199
EnabledFeatureNames.insert(feature.Key);

clang/tools/driver/cc1as_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
506506
<< Opts.CPU << FS.empty() << FS;
507507
}
508508

509-
MCContext Ctx(Triple(Opts.Triple), *MAI, MRI.get(), STI.get(), &SrcMgr);
509+
MCContext Ctx(Triple(Opts.Triple), *MAI, *MRI, *STI, &SrcMgr);
510510

511511
bool PIC = false;
512512
if (Opts.RelocationModel == "static") {

lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,9 +1283,8 @@ DisassemblerLLVMC::MCDisasmInstance::Create(const char *triple_name,
12831283
if (!asm_info_up)
12841284
return Instance();
12851285

1286-
std::unique_ptr<llvm::MCContext> context_up(
1287-
new llvm::MCContext(llvm::Triple(triple), *asm_info_up, reg_info_up.get(),
1288-
subtarget_info_up.get()));
1286+
std::unique_ptr<llvm::MCContext> context_up(new llvm::MCContext(
1287+
llvm::Triple(triple), *asm_info_up, *reg_info_up, *subtarget_info_up));
12891288
if (!context_up)
12901289
return Instance();
12911290

lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ EmulateInstructionMIPS::EmulateInstructionMIPS(
157157
m_subtype_info.reset(target->createMCSubtargetInfo(triple, cpu, features));
158158
assert(m_asm_info.get() && m_subtype_info.get());
159159

160-
m_context = std::make_unique<llvm::MCContext>(
161-
triple, *m_asm_info, m_reg_info.get(), m_subtype_info.get());
160+
m_context = std::make_unique<llvm::MCContext>(triple, *m_asm_info,
161+
*m_reg_info, *m_subtype_info);
162162
assert(m_context.get());
163163

164164
m_disasm.reset(target->createMCDisassembler(*m_subtype_info, *m_context));

lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ EmulateInstructionMIPS64::EmulateInstructionMIPS64(
161161
m_subtype_info.reset(target->createMCSubtargetInfo(triple, cpu, features));
162162
assert(m_asm_info.get() && m_subtype_info.get());
163163

164-
m_context = std::make_unique<llvm::MCContext>(
165-
triple, *m_asm_info, m_reg_info.get(), m_subtype_info.get());
164+
m_context = std::make_unique<llvm::MCContext>(triple, *m_asm_info,
165+
*m_reg_info, *m_subtype_info);
166166
assert(m_context.get());
167167

168168
m_disasm.reset(target->createMCDisassembler(*m_subtype_info, *m_context));

llvm/include/llvm/MC/MCContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ class MCContext {
377377

378378
public:
379379
LLVM_ABI explicit MCContext(const Triple &TheTriple, const MCAsmInfo &MAI,
380-
const MCRegisterInfo *MRI,
381-
const MCSubtargetInfo *MSTI,
380+
const MCRegisterInfo &MRI,
381+
const MCSubtargetInfo &MSTI,
382382
const SourceMgr *Mgr = nullptr,
383383
bool DoAutoReset = true,
384384
StringRef Swift5ReflSegmentName = {});

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ class LLVM_ABI TargetMachine {
239239
/// Return target specific asm information.
240240
const MCAsmInfo &getMCAsmInfo() const { return *AsmInfo; }
241241

242-
const MCRegisterInfo *getMCRegisterInfo() const { return MRI.get(); }
242+
const MCRegisterInfo &getMCRegisterInfo() const { return *MRI; }
243243
const MCInstrInfo *getMCInstrInfo() const { return MII.get(); }
244-
const MCSubtargetInfo *getMCSubtargetInfo() const { return STI.get(); }
244+
const MCSubtargetInfo &getMCSubtargetInfo() const { return *STI; }
245245

246246
/// Return the ExceptionHandling to use, considering TargetOptions and the
247247
/// Triple's default.

0 commit comments

Comments
 (0)