- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
[NFC][Flang] Prefer triple overloads of lookupTarget #162186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The overloads accepting a string will be deprecated soon, like other functions in TargetRegistry.
| 
          
 @llvm/pr-subscribers-flang-driver Author: Aiden Grossman (boomanaiden154) ChangesThe overloads accepting a string will be deprecated soon, like other functions in TargetRegistry. Full diff: https://github.com/llvm/llvm-project/pull/162186.diff 3 Files Affected: 
 diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index d97b4b8af6d61..5920ed82114f8 100644
--- a/flang/lib/Frontend/CompilerInstance.cpp
+++ b/flang/lib/Frontend/CompilerInstance.cpp
@@ -344,9 +344,10 @@ bool CompilerInstance::setUpTargetMachine() {
   const std::string &theTriple = targetOpts.triple;
 
   // Create `Target`
+  const llvm::Triple triple(theTriple);
   std::string error;
   const llvm::Target *theTarget =
-      llvm::TargetRegistry::lookupTarget(theTriple, error);
+      llvm::TargetRegistry::lookupTarget(triple, error);
   if (!theTarget) {
     getDiagnostics().Report(clang::diag::err_fe_unable_to_create_target)
         << error;
@@ -365,13 +366,12 @@ bool CompilerInstance::setUpTargetMachine() {
   tOpts.EnableAIXExtendedAltivecABI = targetOpts.EnableAIXExtendedAltivecABI;
 
   targetMachine.reset(theTarget->createTargetMachine(
-      llvm::Triple(theTriple), /*CPU=*/targetOpts.cpu,
+      triple, /*CPU=*/targetOpts.cpu,
       /*Features=*/featuresStr, /*Options=*/tOpts,
       /*Reloc::Model=*/CGOpts.getRelocationModel(),
       /*CodeModel::Model=*/cm, OptLevel));
   assert(targetMachine && "Failed to create TargetMachine");
   if (cm.has_value()) {
-    const llvm::Triple triple(theTriple);
     if ((cm == llvm::CodeModel::Medium || cm == llvm::CodeModel::Large) &&
         triple.getArch() == llvm::Triple::x86_64) {
       targetMachine->setLargeDataThreshold(CGOpts.LargeDataThreshold);
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 69a45c66a079a..8b12da3a7b50a 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -316,13 +316,14 @@ createTargetMachine(llvm::StringRef targetTriple, std::string &error) {
   std::string triple{targetTriple};
   if (triple.empty())
     triple = llvm::sys::getDefaultTargetTriple();
+  llvm::Triple parsedTriple(triple);
 
   const llvm::Target *theTarget =
-      llvm::TargetRegistry::lookupTarget(triple, error);
+      llvm::TargetRegistry::lookupTarget(parsedTriple, error);
   if (!theTarget)
     return nullptr;
   return std::unique_ptr<llvm::TargetMachine>{
-      theTarget->createTargetMachine(llvm::Triple(triple), /*CPU=*/"",
+      theTarget->createTargetMachine(parsedTriple, /*CPU=*/"",
                                      /*Features=*/"", llvm::TargetOptions(),
                                      /*Reloc::Model=*/std::nullopt)};
 }
diff --git a/flang/tools/flang-driver/fc1_main.cpp b/flang/tools/flang-driver/fc1_main.cpp
index d9b103dbe6c8c..b5bbb0b86232d 100644
--- a/flang/tools/flang-driver/fc1_main.cpp
+++ b/flang/tools/flang-driver/fc1_main.cpp
@@ -34,9 +34,10 @@ using namespace Fortran::frontend;
 
 /// Print supported cpus of the given target.
 static int printSupportedCPUs(llvm::StringRef triple) {
+  llvm::Triple parsedTriple(triple);
   std::string error;
   const llvm::Target *target =
-      llvm::TargetRegistry::lookupTarget(triple, error);
+      llvm::TargetRegistry::lookupTarget(parsedTriple, error);
   if (!target) {
     llvm::errs() << error;
     return 1;
@@ -45,7 +46,7 @@ static int printSupportedCPUs(llvm::StringRef triple) {
   // the target machine will handle the mcpu printing
   llvm::TargetOptions targetOpts;
   std::unique_ptr<llvm::TargetMachine> targetMachine(
-      target->createTargetMachine(llvm::Triple(triple), "", "+cpuhelp",
+      target->createTargetMachine(parsedTriple, "", "+cpuhelp",
                                   targetOpts, std::nullopt));
   return 0;
 }
 | 
    
| 
          
 ✅ With the latest revision this PR passed the C/C++ code formatter.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Carries same 2 reverts as previous integrates #22200 and #22214 Change in IREE for change some TOSA pass logic: llvm/llvm-project#153771 Change in IREE for deprecated LLVM Triple API: llvm/llvm-project#162186 Currently includes patch #22241 which is a pure IREE fix Increases golden times for 2 models (<5%): `assert 10.864054075338773 <= 10.5` Noticed this potential flake on windows at some point: lit test ksplitmatmul_basic Follow-up: understand #22241 (why can we not just assert it is not null?) --------- Signed-off-by: James Newling <[email protected]>
Carries same 2 reverts as previous integrates iree-org#22200 and iree-org#22214 Change in IREE for change some TOSA pass logic: llvm/llvm-project#153771 Change in IREE for deprecated LLVM Triple API: llvm/llvm-project#162186 Currently includes patch iree-org#22241 which is a pure IREE fix Increases golden times for 2 models (<5%): `assert 10.864054075338773 <= 10.5` Noticed this potential flake on windows at some point: lit test ksplitmatmul_basic Follow-up: understand iree-org#22241 (why can we not just assert it is not null?) --------- Signed-off-by: James Newling <[email protected]> Signed-off-by: Philipp <[email protected]>
The overloads accepting a string will be deprecated soon, like other functions in TargetRegistry.