Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions bolt/lib/Passes/AsmDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ void dumpFunction(const BinaryFunction &BF) {
std::unique_ptr<MCAsmBackend> MAB(
BC.TheTarget->createMCAsmBackend(*BC.STI, *BC.MRI, MCTargetOptions()));
int AsmPrinterVariant = BC.AsmInfo->getAssemblerDialect();
MCInstPrinter *InstructionPrinter(BC.TheTarget->createMCInstPrinter(
*BC.TheTriple, AsmPrinterVariant, *BC.AsmInfo, *BC.MII, *BC.MRI));
std::unique_ptr<MCInstPrinter> InstructionPrinter(
BC.TheTarget->createMCInstPrinter(*BC.TheTriple, AsmPrinterVariant,
*BC.AsmInfo, *BC.MII, *BC.MRI));
auto FOut = std::make_unique<formatted_raw_ostream>(OS);
FOut->SetUnbuffered();
std::unique_ptr<MCStreamer> AsmStreamer(
createAsmStreamer(*LocalCtx, std::move(FOut), InstructionPrinter,
std::move(MCEInstance.MCE), std::move(MAB)));
std::unique_ptr<MCStreamer> AsmStreamer(createAsmStreamer(
*LocalCtx, std::move(FOut), std::move(InstructionPrinter),
std::move(MCEInstance.MCE), std::move(MAB)));
AsmStreamer->initSections(true, *BC.STI);
std::unique_ptr<TargetMachine> TM(BC.TheTarget->createTargetMachine(
*BC.TheTriple, "", "", TargetOptions(), std::nullopt));
Expand Down
7 changes: 4 additions & 3 deletions clang/tools/driver/cc1as_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCObjectWriter.h"
Expand Down Expand Up @@ -541,8 +542,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,

// FIXME: There is a bit of code duplication with addPassesToEmitFile.
if (Opts.OutputType == AssemblerInvocation::FT_Asm) {
MCInstPrinter *IP = TheTarget->createMCInstPrinter(
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI);
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(no action required) I wish createMCInstPrinter returned unique_ptr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

I agree... That said, a lot of create* functions in llvm/include/llvm/MC/TargetRegistry.h return a raw pointer, so I feel that we'll have to keep createMCInstPrinter behave so...

llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI));

std::unique_ptr<MCCodeEmitter> CE;
if (Opts.ShowEncoding)
Expand All @@ -551,7 +552,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));

auto FOut = std::make_unique<formatted_raw_ostream>(*Out);
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP,
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), std::move(IP),
std::move(CE), std::move(MAB)));
} else if (Opts.OutputType == AssemblerInvocation::FT_Null) {
Str.reset(createNullStreamer(Ctx));
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/DWARFLinker/Classic/DWARFStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ class DwarfStreamer : public DwarfEmitter {
MCAsmBackend *MAB; // Owned by MCStreamer
std::unique_ptr<MCInstrInfo> MII;
std::unique_ptr<MCSubtargetInfo> MSTI;
MCInstPrinter *MIP; // Owned by AsmPrinter
MCCodeEmitter *MCE; // Owned by MCStreamer
MCStreamer *MS; // Owned by AsmPrinter
std::unique_ptr<TargetMachine> TM;
Expand Down
19 changes: 10 additions & 9 deletions llvm/include/llvm/MC/TargetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ MCStreamer *createNullStreamer(MCContext &Ctx);
///
/// \param ShowInst - Whether to show the MCInst representation inline with
/// the assembly.
MCStreamer *
createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *InstPrint, std::unique_ptr<MCCodeEmitter> &&CE,
std::unique_ptr<MCAsmBackend> &&TAB);
MCStreamer *createAsmStreamer(MCContext &Ctx,
std::unique_ptr<formatted_raw_ostream> OS,
std::unique_ptr<MCInstPrinter> InstPrint,
std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB);

MCStreamer *createELFStreamer(MCContext &Ctx,
std::unique_ptr<MCAsmBackend> &&TAB,
Expand Down Expand Up @@ -208,10 +209,10 @@ class Target {
using AsmTargetStreamerCtorTy =
MCTargetStreamer *(*)(MCStreamer &S, formatted_raw_ostream &OS,
MCInstPrinter *InstPrint);
using AsmStreamerCtorTy =
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP, std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB);
using AsmStreamerCtorTy = MCStreamer
*(*)(MCContext & Ctx, std::unique_ptr<formatted_raw_ostream> OS,
std::unique_ptr<MCInstPrinter> IP, std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB);
using ObjectTargetStreamerCtorTy =
MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI);
using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
Expand Down Expand Up @@ -552,7 +553,7 @@ class Target {

MCStreamer *createAsmStreamer(MCContext &Ctx,
std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP,
std::unique_ptr<MCInstPrinter> IP,
std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB) const;

Expand Down
14 changes: 6 additions & 8 deletions llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,13 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,

switch (FileType) {
case CodeGenFileType::AssemblyFile: {
MCInstPrinter *InstPrinter = getTarget().createMCInstPrinter(
std::unique_ptr<MCInstPrinter> InstPrinter(getTarget().createMCInstPrinter(
getTargetTriple(),
Options.MCOptions.OutputAsmVariant.value_or(MAI.getAssemblerDialect()),
MAI, MII, MRI);
for (StringRef Opt : Options.MCOptions.InstPrinterOptions) {
if (!InstPrinter->applyTargetSpecificCLOption(Opt)) {
delete InstPrinter;
MAI, MII, MRI));
for (StringRef Opt : Options.MCOptions.InstPrinterOptions)
if (!InstPrinter->applyTargetSpecificCLOption(Opt))
return createStringError("invalid InstPrinter option '" + Opt + "'");
}
}

// Create a code emitter if asked to show the encoding.
std::unique_ptr<MCCodeEmitter> MCE;
Expand All @@ -182,7 +179,8 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions));
auto FOut = std::make_unique<formatted_raw_ostream>(Out);
MCStreamer *S = getTarget().createAsmStreamer(
Context, std::move(FOut), InstPrinter, std::move(MCE), std::move(MAB));
Context, std::move(FOut), std::move(InstPrinter), std::move(MCE),
std::move(MAB));
AsmStreamer.reset(S);
break;
}
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCStreamer.h"
Expand Down Expand Up @@ -100,10 +101,10 @@ Error DwarfStreamer::init(Triple TheTriple,

switch (OutFileType) {
case DWARFLinker::OutputFileType::Assembly: {
MIP = TheTarget->createMCInstPrinter(TheTriple, MAI->getAssemblerDialect(),
*MAI, *MII, *MRI);
std::unique_ptr<MCInstPrinter> MIP(TheTarget->createMCInstPrinter(
TheTriple, MAI->getAssemblerDialect(), *MAI, *MII, *MRI));
MS = TheTarget->createAsmStreamer(
*MC, std::make_unique<formatted_raw_ostream>(OutFile), MIP,
*MC, std::make_unique<formatted_raw_ostream>(OutFile), std::move(MIP),
std::unique_ptr<MCCodeEmitter>(MCE),
std::unique_ptr<MCAsmBackend>(MAB));
break;
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "DWARFLinkerCompileUnit.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCTargetOptions.h"
Expand Down Expand Up @@ -79,10 +80,10 @@ Error DwarfEmitterImpl::init(Triple TheTriple,

switch (OutFileType) {
case DWARFLinker::OutputFileType::Assembly: {
MIP = TheTarget->createMCInstPrinter(TheTriple, MAI->getAssemblerDialect(),
*MAI, *MII, *MRI);
std::unique_ptr<MCInstPrinter> MIP(TheTarget->createMCInstPrinter(
TheTriple, MAI->getAssemblerDialect(), *MAI, *MII, *MRI));
MS = TheTarget->createAsmStreamer(
*MC, std::make_unique<formatted_raw_ostream>(OutFile), MIP,
*MC, std::make_unique<formatted_raw_ostream>(OutFile), std::move(MIP),
std::unique_ptr<MCCodeEmitter>(MCE),
std::unique_ptr<MCAsmBackend>(MAB));
break;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
Expand Down Expand Up @@ -110,7 +111,7 @@ class DwarfEmitterImpl {
MCAsmBackend *MAB; // Owned by MCStreamer
std::unique_ptr<MCInstrInfo> MII;
std::unique_ptr<MCSubtargetInfo> MSTI;
MCInstPrinter *MIP; // Owned by AsmPrinter
std::unique_ptr<MCInstPrinter> MIP; // Owned by AsmPrinter
MCCodeEmitter *MCE; // Owned by MCStreamer
MCStreamer *MS; // Owned by AsmPrinter
std::unique_ptr<TargetMachine> TM;
Expand Down
13 changes: 7 additions & 6 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class MCAsmStreamer final : public MCStreamer {

public:
MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
MCInstPrinter *printer, std::unique_ptr<MCCodeEmitter> emitter,
std::unique_ptr<MCInstPrinter> printer,
std::unique_ptr<MCCodeEmitter> emitter,
std::unique_ptr<MCAsmBackend> asmbackend)
: MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
MAI(Context.getAsmInfo()), InstPrinter(printer),
MAI(Context.getAsmInfo()), InstPrinter(std::move(printer)),
Assembler(std::make_unique<MCAssembler>(
Context, std::move(asmbackend), std::move(emitter),
(asmbackend) ? asmbackend->createObjectWriter(NullStream)
Expand Down Expand Up @@ -2649,9 +2650,9 @@ void MCAsmStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,

MCStreamer *llvm::createAsmStreamer(MCContext &Context,
std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP,
std::unique_ptr<MCCodeEmitter> &&CE,
std::unique_ptr<MCAsmBackend> &&MAB) {
return new MCAsmStreamer(Context, std::move(OS), IP, std::move(CE),
std::unique_ptr<MCInstPrinter> IP,
std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> MAB) {
return new MCAsmStreamer(Context, std::move(OS), std::move(IP), std::move(CE),
std::move(MAB));
}
12 changes: 7 additions & 5 deletions llvm/lib/MC/TargetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -79,19 +80,20 @@ MCStreamer *Target::createMCObjectStreamer(

MCStreamer *Target::createAsmStreamer(MCContext &Ctx,
std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP,
std::unique_ptr<MCInstPrinter> IP,
std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB) const {
MCInstPrinter *Printer = IP.get();
formatted_raw_ostream &OSRef = *OS;
MCStreamer *S;
if (AsmStreamerCtorFn)
S = AsmStreamerCtorFn(Ctx, std::move(OS), IP, std::move(CE),
S = AsmStreamerCtorFn(Ctx, std::move(OS), std::move(IP), std::move(CE),
std::move(TAB));
else
S = llvm::createAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
std::move(TAB));
S = llvm::createAsmStreamer(Ctx, std::move(OS), std::move(IP),
std::move(CE), std::move(TAB));

createAsmTargetStreamer(*S, OSRef, IP);
createAsmTargetStreamer(*S, OSRef, Printer);
return S;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class SystemZHLASMAsmStreamer final : public MCStreamer {
public:
SystemZHLASMAsmStreamer(MCContext &Context,
std::unique_ptr<formatted_raw_ostream> os,
MCInstPrinter *printer,
std::unique_ptr<MCInstPrinter> printer,
std::unique_ptr<MCCodeEmitter> emitter,
std::unique_ptr<MCAsmBackend> asmbackend)
: MCStreamer(Context), FOSOwner(std::move(os)), FOS(*FOSOwner), OS(Str),
MAI(Context.getAsmInfo()), InstPrinter(printer),
MAI(Context.getAsmInfo()), InstPrinter(std::move(printer)),
Assembler(std::make_unique<MCAssembler>(
Context, std::move(asmbackend), std::move(emitter),
(asmbackend) ? asmbackend->createObjectWriter(NullStream)
Expand Down
20 changes: 10 additions & 10 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,18 @@ static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
return new SystemZTargetGNUStreamer(S, OS);
}

static MCStreamer *createAsmStreamer(MCContext &Ctx,
std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP,
std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB) {
static MCStreamer *createSystemZAsmStreamer(
MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
std::unique_ptr<MCInstPrinter> IP, std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB) {

auto TT = Ctx.getTargetTriple();
if (TT.isOSzOS() && !GNUAsOnzOSCL)
return new SystemZHLASMAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
std::move(TAB));
return new SystemZHLASMAsmStreamer(Ctx, std::move(OS), std::move(IP),
std::move(CE), std::move(TAB));

return llvm::createAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
std::move(TAB));
return llvm::createAsmStreamer(Ctx, std::move(OS), std::move(IP),
std::move(CE), std::move(TAB));
}

static MCTargetStreamer *
Expand Down Expand Up @@ -254,7 +253,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZTargetMC() {
createSystemZMCInstPrinter);

// Register the asm streamer.
TargetRegistry::RegisterAsmStreamer(getTheSystemZTarget(), createAsmStreamer);
TargetRegistry::RegisterAsmStreamer(getTheSystemZTarget(),
createSystemZAsmStreamer);

// Register the asm target streamer.
TargetRegistry::RegisterAsmTargetStreamer(getTheSystemZTarget(),
Expand Down
1 change: 0 additions & 1 deletion llvm/test/tools/llvm-mc/disassembler-options.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# RUN: export LSAN_OPTIONS=detect_leaks=0
# RUN: not llvm-mc -M invalid /dev/null 2>&1 | FileCheck %s

# CHECK: error: invalid InstPrinter option 'invalid'
25 changes: 15 additions & 10 deletions llvm/tools/llvm-mc/llvm-mc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,10 @@ int main(int argc, char **argv) {
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
assert(MCII && "Unable to create instruction info!");

MCInstPrinter *IP = nullptr;
std::unique_ptr<MCInstPrinter> IP;
if (FileType == OFT_AssemblyFile) {
IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant,
*MAI, *MCII, *MRI);
IP.reset(TheTarget->createMCInstPrinter(
Triple(TripleName), OutputAsmVariant, *MAI, *MCII, *MRI));

if (!IP) {
WithColor::error()
Expand All @@ -541,6 +541,17 @@ int main(int argc, char **argv) {
// Set the display preference for hex vs. decimal immediates.
IP->setPrintImmHex(PrintImmHex);

switch (Action) {
case AC_MDisassemble:
IP->setUseMarkup(true);
break;
case AC_CDisassemble:
IP->setUseColor(true);
break;
default:
break;
}

// Set up the AsmStreamer.
std::unique_ptr<MCCodeEmitter> CE;
if (ShowEncoding)
Expand All @@ -549,7 +560,7 @@ int main(int argc, char **argv) {
std::unique_ptr<MCAsmBackend> MAB(
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
auto FOut = std::make_unique<formatted_raw_ostream>(*OS);
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP,
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), std::move(IP),
std::move(CE), std::move(MAB)));

} else if (FileType == OFT_Null) {
Expand Down Expand Up @@ -586,13 +597,7 @@ int main(int argc, char **argv) {
*MCII, MCOptions);
break;
case AC_MDisassemble:
IP->setUseMarkup(true);
disassemble = true;
break;
case AC_CDisassemble:
IP->setUseColor(true);
disassemble = true;
break;
case AC_Disassemble:
disassemble = true;
break;
Expand Down
7 changes: 3 additions & 4 deletions llvm/tools/llvm-ml/llvm-ml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,12 @@ int llvm_ml_main(int Argc, char **Argv, const llvm::ToolContext &) {
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
assert(MCII && "Unable to create instruction info!");

MCInstPrinter *IP = nullptr;
if (FileType == "s") {
const bool OutputATTAsm = InputArgs.hasArg(OPT_output_att_asm);
const unsigned OutputAsmVariant = OutputATTAsm ? 0U // ATT dialect
: 1U; // Intel dialect
IP = TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI,
*MCII, *MRI);
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
TheTriple, OutputAsmVariant, *MAI, *MCII, *MRI));

if (!IP) {
WithColor::error()
Expand All @@ -390,7 +389,7 @@ int llvm_ml_main(int Argc, char **Argv, const llvm::ToolContext &) {
std::unique_ptr<MCAsmBackend> MAB(
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
auto FOut = std::make_unique<formatted_raw_ostream>(*OS);
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP,
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), std::move(IP),
std::move(CE), std::move(MAB)));

} else if (FileType == "null") {
Expand Down
Loading