Skip to content
Merged
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
35 changes: 16 additions & 19 deletions llvm/tools/llvm-mca/llvm-mca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ static cl::opt<std::string>
cl::cat(ToolOptions));

static cl::opt<std::string>
TripleName("mtriple",
cl::desc("Target triple. See -version for available targets"),
cl::cat(ToolOptions));
TripleNameOpt("mtriple",
cl::desc("Target triple. See -version for available targets"),
cl::cat(ToolOptions));

static cl::opt<std::string>
MCPU("mcpu",
Expand Down Expand Up @@ -292,11 +292,7 @@ static cl::opt<bool> DisableInstrumentManager(

namespace {

const Target *getTarget(const char *ProgName) {
if (TripleName.empty())
TripleName = Triple::normalize(sys::getDefaultTargetTriple());
Triple TheTriple(TripleName);

const Target *getTarget(Triple &TheTriple, const char *ProgName) {
// Get the target specific parser.
std::string Error;
const Target *TheTarget =
Expand All @@ -306,9 +302,6 @@ const Target *getTarget(const char *ProgName) {
return nullptr;
}

// Update TripleName with the updated triple from the target lookup.
TripleName = TheTriple.str();

// Return the found target.
return TheTarget;
}
Expand Down Expand Up @@ -387,18 +380,18 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv,
"llvm machine code performance analyzer.\n");

Triple TheTriple(TripleNameOpt.empty()
? Triple::normalize(sys::getDefaultTargetTriple())
: TripleNameOpt);

// Get the target from the triple. If a triple is not specified, then select
// the default triple for the host. If the triple doesn't correspond to any
// registered target, then exit with an error message.
const char *ProgName = argv[0];
const Target *TheTarget = getTarget(ProgName);
const Target *TheTarget = getTarget(TheTriple, ProgName);
if (!TheTarget)
return 1;

// GetTarget() may replaced TripleName with a default triple.
// For safety, reconstruct the Triple object.
Triple TheTriple(TripleName);

ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
MemoryBuffer::getFileOrSTDIN(InputFilename);
if (std::error_code EC = BufferPtr.getError()) {
Expand All @@ -420,7 +413,11 @@ int main(int argc, char **argv) {

std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TheTriple, MCPU, FeaturesStr));
assert(STI && "Unable to create subtarget info!");
if (!STI) {
WithColor::error() << "unable to create subtarget info\n";
return 1;
}

if (!STI->isCPUStringValid(MCPU))
return 1;

Expand Down Expand Up @@ -469,7 +466,7 @@ int main(int argc, char **argv) {
unsigned IPtempOutputAsmVariant =
OutputAsmVariant == -1 ? 0 : OutputAsmVariant;
std::unique_ptr<MCInstPrinter> IPtemp(TheTarget->createMCInstPrinter(
Triple(TripleName), IPtempOutputAsmVariant, *MAI, *MCII, *MRI));
TheTriple, IPtempOutputAsmVariant, *MAI, *MCII, *MRI));
if (!IPtemp) {
WithColor::error()
<< "unable to create instruction printer for target triple '"
Expand Down Expand Up @@ -558,7 +555,7 @@ int main(int argc, char **argv) {
if (OutputAsmVariant >= 0)
AssemblerDialect = static_cast<unsigned>(OutputAsmVariant);
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
Triple(TripleName), AssemblerDialect, *MAI, *MCII, *MRI));
TheTriple, AssemblerDialect, *MAI, *MCII, *MRI));
if (!IP) {
WithColor::error()
<< "unable to create instruction printer for target triple '"
Expand Down