@@ -83,9 +83,9 @@ static cl::opt<std::string>
8383 cl::cat(ToolOptions));
8484
8585static cl::opt<std::string>
86- TripleName (" mtriple" ,
87- cl::desc (" Target triple. See -version for available targets" ),
88- cl::cat(ToolOptions));
86+ TripleNameOpt (" mtriple" ,
87+ cl::desc (" Target triple. See -version for available targets" ),
88+ cl::cat(ToolOptions));
8989
9090static cl::opt<std::string>
9191 MCPU (" mcpu" ,
@@ -292,11 +292,7 @@ static cl::opt<bool> DisableInstrumentManager(
292292
293293namespace {
294294
295- const Target *getTarget (const char *ProgName) {
296- if (TripleName.empty ())
297- TripleName = Triple::normalize (sys::getDefaultTargetTriple ());
298- Triple TheTriple (TripleName);
299-
295+ const Target *getTarget (Triple &TheTriple, const char *ProgName) {
300296 // Get the target specific parser.
301297 std::string Error;
302298 const Target *TheTarget =
@@ -306,9 +302,6 @@ const Target *getTarget(const char *ProgName) {
306302 return nullptr ;
307303 }
308304
309- // Update TripleName with the updated triple from the target lookup.
310- TripleName = TheTriple.str ();
311-
312305 // Return the found target.
313306 return TheTarget;
314307}
@@ -387,18 +380,18 @@ int main(int argc, char **argv) {
387380 cl::ParseCommandLineOptions (argc, argv,
388381 " llvm machine code performance analyzer.\n " );
389382
383+ Triple TheTriple (TripleNameOpt.empty ()
384+ ? Triple::normalize (sys::getDefaultTargetTriple ())
385+ : TripleNameOpt);
386+
390387 // Get the target from the triple. If a triple is not specified, then select
391388 // the default triple for the host. If the triple doesn't correspond to any
392389 // registered target, then exit with an error message.
393390 const char *ProgName = argv[0 ];
394- const Target *TheTarget = getTarget (ProgName);
391+ const Target *TheTarget = getTarget (TheTriple, ProgName);
395392 if (!TheTarget)
396393 return 1 ;
397394
398- // GetTarget() may replaced TripleName with a default triple.
399- // For safety, reconstruct the Triple object.
400- Triple TheTriple (TripleName);
401-
402395 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
403396 MemoryBuffer::getFileOrSTDIN (InputFilename);
404397 if (std::error_code EC = BufferPtr.getError ()) {
@@ -469,7 +462,7 @@ int main(int argc, char **argv) {
469462 unsigned IPtempOutputAsmVariant =
470463 OutputAsmVariant == -1 ? 0 : OutputAsmVariant;
471464 std::unique_ptr<MCInstPrinter> IPtemp (TheTarget->createMCInstPrinter (
472- Triple (TripleName) , IPtempOutputAsmVariant, *MAI, *MCII, *MRI));
465+ TheTriple , IPtempOutputAsmVariant, *MAI, *MCII, *MRI));
473466 if (!IPtemp) {
474467 WithColor::error ()
475468 << " unable to create instruction printer for target triple '"
@@ -558,7 +551,7 @@ int main(int argc, char **argv) {
558551 if (OutputAsmVariant >= 0 )
559552 AssemblerDialect = static_cast <unsigned >(OutputAsmVariant);
560553 std::unique_ptr<MCInstPrinter> IP (TheTarget->createMCInstPrinter (
561- Triple (TripleName) , AssemblerDialect, *MAI, *MCII, *MRI));
554+ TheTriple , AssemblerDialect, *MAI, *MCII, *MRI));
562555 if (!IP) {
563556 WithColor::error ()
564557 << " unable to create instruction printer for target triple '"
0 commit comments