[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-16 Thread WÁNG Xuěruì via llvm-branch-commits

https://github.com/xen0n approved this pull request.


https://github.com/llvm/llvm-project/pull/92223
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {
+switch (Abi) {
+default:
+  return false;
+case ABI_ILP32S:
+  return !Is64Bit;
+case ABI_ILP32F:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_ILP32D:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+case ABI_LP64S:
+  return Is64Bit;
+case ABI_LP64F:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_LP64D:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+}
+  };
+
+  // 1. If the '-target-abi' is valid, use it.
+  if (IsValidABI(ArgProvidedABI)) {
+if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+  errs()
+  << "warning: triple-implied ABI conflicts with provided target-abi '"
+  << ABIName << "', using target-abi\n";
+return checkABIStandardized(ArgProvidedABI);
+  }
+
+  // 2. If the triple-implied ABI is valid, use it.
+  if (IsValidABI(TripleABI)) {
+// If not specifie target-abi, use the valid triple-implied ABI.
+if (ABIName.empty())
+  return checkABIStandardized(TripleABI);
 
-  switch (ArgProvidedABI) {
-  case LoongArchABI::ABI_Unknown:
-// Fallback to the triple-implied ABI if ABI name is not specified or
-// invalid.
-if (!ABIName.empty())
+switch (ArgProvidedABI) {
+case ABI_Unknown:
+  // Fallback to the triple-implied ABI if ABI name is specified and
+  // invalid.
   errs() << "'" << ABIName
  << "' is not a recognized ABI for this target, ignoring and using 
"
 "triple-implied ABI\n";
-return checkABIStandardized(TripleABI);
-
-  case LoongArchABI::ABI_ILP32S:
-  case LoongArchABI::ABI_ILP32F:
-  case LoongArchABI::ABI_ILP32D:
-if (Is64Bit) {
-  errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
   return checkABIStandardized(TripleABI);
+case ABI_ILP32S:
+case ABI_ILP32F:
+case ABI_ILP32D:
+  if (Is64Bit) {
+errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
+case ABI_LP64S:
+case ABI_LP64F:
+case ABI_LP64D:
+  if (!Is64Bit) {
+errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
 }
-break;
 
-  case LoongArchABI::ABI_LP64S:
-  case LoongArchABI::ABI_LP64F:
-  case LoongArchABI::ABI_LP64D:
-if (!Is64Bit) {
-  errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
-  return checkABIStandardized(TripleABI);
+switch (ArgProvidedABI) {
+case ABI_ILP32F:
+case ABI_LP64F:
+  errs() << "'" << ABIName
+ << "' ABI can't be used for a target that doesn't support the 'F' 
"
+"instruction set, ignoring target-abi and using triple-implied 
"
+"ABI\n";
+  break;
+case ABI_ILP32D:
+case ABI_LP64D:
+  errs() << "'" << ABIName
+ << "' ABI can't be used for a target that doesn't support the 'D' 
"
+"instruction set, ignoring 

[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {
+switch (Abi) {
+default:
+  return false;
+case ABI_ILP32S:
+  return !Is64Bit;
+case ABI_ILP32F:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_ILP32D:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+case ABI_LP64S:
+  return Is64Bit;
+case ABI_LP64F:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_LP64D:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+}
+  };
+
+  // 1. If the '-target-abi' is valid, use it.
+  if (IsValidABI(ArgProvidedABI)) {
+if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+  errs()
+  << "warning: triple-implied ABI conflicts with provided target-abi '"
+  << ABIName << "', using target-abi\n";
+return checkABIStandardized(ArgProvidedABI);
+  }
+
+  // 2. If the triple-implied ABI is valid, use it.
+  if (IsValidABI(TripleABI)) {
+// If not specifie target-abi, use the valid triple-implied ABI.
+if (ABIName.empty())
+  return checkABIStandardized(TripleABI);
 
-  switch (ArgProvidedABI) {
-  case LoongArchABI::ABI_Unknown:
-// Fallback to the triple-implied ABI if ABI name is not specified or
-// invalid.
-if (!ABIName.empty())
+switch (ArgProvidedABI) {
+case ABI_Unknown:
+  // Fallback to the triple-implied ABI if ABI name is specified and
+  // invalid.
   errs() << "'" << ABIName
  << "' is not a recognized ABI for this target, ignoring and using 
"
 "triple-implied ABI\n";
-return checkABIStandardized(TripleABI);
-
-  case LoongArchABI::ABI_ILP32S:
-  case LoongArchABI::ABI_ILP32F:
-  case LoongArchABI::ABI_ILP32D:
-if (Is64Bit) {
-  errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
   return checkABIStandardized(TripleABI);
+case ABI_ILP32S:
+case ABI_ILP32F:
+case ABI_ILP32D:
+  if (Is64Bit) {
+errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
+case ABI_LP64S:
+case ABI_LP64F:
+case ABI_LP64D:
+  if (!Is64Bit) {
+errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
 }
-break;
 
-  case LoongArchABI::ABI_LP64S:
-  case LoongArchABI::ABI_LP64F:
-  case LoongArchABI::ABI_LP64D:
-if (!Is64Bit) {
-  errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
-  return checkABIStandardized(TripleABI);
+switch (ArgProvidedABI) {
+case ABI_ILP32F:
+case ABI_LP64F:
+  errs() << "'" << ABIName
+ << "' ABI can't be used for a target that doesn't support the 'F' 
"
+"instruction set, ignoring target-abi and using triple-implied 
"
+"ABI\n";
+  break;
+case ABI_ILP32D:
+case ABI_LP64D:
+  errs() << "'" << ABIName
+ << "' ABI can't be used for a target that doesn't support the 'D' 
"
+"instruction set, ignoring 

[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {

xen0n wrote:

name this `IsABIValidForFeature` for extra clarity?

https://github.com/llvm/llvm-project/pull/92223
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {
+switch (Abi) {
+default:
+  return false;
+case ABI_ILP32S:
+  return !Is64Bit;
+case ABI_ILP32F:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_ILP32D:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+case ABI_LP64S:
+  return Is64Bit;
+case ABI_LP64F:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_LP64D:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+}
+  };
+
+  // 1. If the '-target-abi' is valid, use it.
+  if (IsValidABI(ArgProvidedABI)) {
+if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+  errs()
+  << "warning: triple-implied ABI conflicts with provided target-abi '"
+  << ABIName << "', using target-abi\n";
+return checkABIStandardized(ArgProvidedABI);
+  }
+
+  // 2. If the triple-implied ABI is valid, use it.
+  if (IsValidABI(TripleABI)) {
+// If not specifie target-abi, use the valid triple-implied ABI.
+if (ABIName.empty())
+  return checkABIStandardized(TripleABI);
 
-  switch (ArgProvidedABI) {
-  case LoongArchABI::ABI_Unknown:
-// Fallback to the triple-implied ABI if ABI name is not specified or
-// invalid.
-if (!ABIName.empty())
+switch (ArgProvidedABI) {
+case ABI_Unknown:
+  // Fallback to the triple-implied ABI if ABI name is specified and
+  // invalid.
   errs() << "'" << ABIName
  << "' is not a recognized ABI for this target, ignoring and using 
"
 "triple-implied ABI\n";
-return checkABIStandardized(TripleABI);
-
-  case LoongArchABI::ABI_ILP32S:
-  case LoongArchABI::ABI_ILP32F:
-  case LoongArchABI::ABI_ILP32D:
-if (Is64Bit) {
-  errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
   return checkABIStandardized(TripleABI);
+case ABI_ILP32S:
+case ABI_ILP32F:
+case ABI_ILP32D:
+  if (Is64Bit) {
+errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
+case ABI_LP64S:
+case ABI_LP64F:
+case ABI_LP64D:
+  if (!Is64Bit) {
+errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
 }
-break;
 
-  case LoongArchABI::ABI_LP64S:
-  case LoongArchABI::ABI_LP64F:
-  case LoongArchABI::ABI_LP64D:
-if (!Is64Bit) {
-  errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
-  return checkABIStandardized(TripleABI);
+switch (ArgProvidedABI) {
+case ABI_ILP32F:
+case ABI_LP64F:
+  errs() << "'" << ABIName

xen0n wrote:

```suggestion
  errs() << "warning: the '" << ABIName
```

https://github.com/llvm/llvm-project/pull/92223
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {
+switch (Abi) {
+default:
+  return false;
+case ABI_ILP32S:
+  return !Is64Bit;
+case ABI_ILP32F:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_ILP32D:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+case ABI_LP64S:
+  return Is64Bit;
+case ABI_LP64F:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_LP64D:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+}
+  };
+
+  // 1. If the '-target-abi' is valid, use it.
+  if (IsValidABI(ArgProvidedABI)) {
+if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+  errs()
+  << "warning: triple-implied ABI conflicts with provided target-abi '"
+  << ABIName << "', using target-abi\n";
+return checkABIStandardized(ArgProvidedABI);
+  }
+
+  // 2. If the triple-implied ABI is valid, use it.
+  if (IsValidABI(TripleABI)) {
+// If not specifie target-abi, use the valid triple-implied ABI.
+if (ABIName.empty())
+  return checkABIStandardized(TripleABI);
 
-  switch (ArgProvidedABI) {
-  case LoongArchABI::ABI_Unknown:
-// Fallback to the triple-implied ABI if ABI name is not specified or
-// invalid.
-if (!ABIName.empty())
+switch (ArgProvidedABI) {
+case ABI_Unknown:
+  // Fallback to the triple-implied ABI if ABI name is specified and
+  // invalid.
   errs() << "'" << ABIName
  << "' is not a recognized ABI for this target, ignoring and using 
"
 "triple-implied ABI\n";
-return checkABIStandardized(TripleABI);
-
-  case LoongArchABI::ABI_ILP32S:
-  case LoongArchABI::ABI_ILP32F:
-  case LoongArchABI::ABI_ILP32D:
-if (Is64Bit) {
-  errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
   return checkABIStandardized(TripleABI);
+case ABI_ILP32S:
+case ABI_ILP32F:
+case ABI_ILP32D:
+  if (Is64Bit) {
+errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
+case ABI_LP64S:
+case ABI_LP64F:
+case ABI_LP64D:
+  if (!Is64Bit) {
+errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
 }
-break;
 
-  case LoongArchABI::ABI_LP64S:
-  case LoongArchABI::ABI_LP64F:
-  case LoongArchABI::ABI_LP64D:
-if (!Is64Bit) {
-  errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
-  return checkABIStandardized(TripleABI);
+switch (ArgProvidedABI) {
+case ABI_ILP32F:
+case ABI_LP64F:
+  errs() << "'" << ABIName
+ << "' ABI can't be used for a target that doesn't support the 'F' 
"
+"instruction set, ignoring target-abi and using triple-implied 
"
+"ABI\n";
+  break;
+case ABI_ILP32D:
+case ABI_LP64D:
+  errs() << "'" << ABIName
+ << "' ABI can't be used for a target that doesn't support the 'D' 
"
+"instruction set, ignoring 

[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {
+switch (Abi) {
+default:
+  return false;
+case ABI_ILP32S:
+  return !Is64Bit;
+case ABI_ILP32F:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_ILP32D:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+case ABI_LP64S:
+  return Is64Bit;
+case ABI_LP64F:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_LP64D:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+}
+  };
+
+  // 1. If the '-target-abi' is valid, use it.
+  if (IsValidABI(ArgProvidedABI)) {
+if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+  errs()
+  << "warning: triple-implied ABI conflicts with provided target-abi '"
+  << ABIName << "', using target-abi\n";
+return checkABIStandardized(ArgProvidedABI);
+  }
+
+  // 2. If the triple-implied ABI is valid, use it.
+  if (IsValidABI(TripleABI)) {
+// If not specifie target-abi, use the valid triple-implied ABI.
+if (ABIName.empty())
+  return checkABIStandardized(TripleABI);
 
-  switch (ArgProvidedABI) {
-  case LoongArchABI::ABI_Unknown:
-// Fallback to the triple-implied ABI if ABI name is not specified or
-// invalid.
-if (!ABIName.empty())
+switch (ArgProvidedABI) {
+case ABI_Unknown:
+  // Fallback to the triple-implied ABI if ABI name is specified and
+  // invalid.
   errs() << "'" << ABIName
  << "' is not a recognized ABI for this target, ignoring and using 
"
 "triple-implied ABI\n";
-return checkABIStandardized(TripleABI);
-
-  case LoongArchABI::ABI_ILP32S:
-  case LoongArchABI::ABI_ILP32F:
-  case LoongArchABI::ABI_ILP32D:
-if (Is64Bit) {
-  errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
   return checkABIStandardized(TripleABI);
+case ABI_ILP32S:
+case ABI_ILP32F:
+case ABI_ILP32D:
+  if (Is64Bit) {
+errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
+case ABI_LP64S:
+case ABI_LP64F:
+case ABI_LP64D:
+  if (!Is64Bit) {
+errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
+  "target-abi and using triple-implied ABI\n";
+return checkABIStandardized(TripleABI);
+  }
+  break;
 }
-break;
 
-  case LoongArchABI::ABI_LP64S:
-  case LoongArchABI::ABI_LP64F:
-  case LoongArchABI::ABI_LP64D:
-if (!Is64Bit) {
-  errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
-"target-abi and using triple-implied ABI\n";
-  return checkABIStandardized(TripleABI);
+switch (ArgProvidedABI) {
+case ABI_ILP32F:
+case ABI_LP64F:
+  errs() << "'" << ABIName
+ << "' ABI can't be used for a target that doesn't support the 'F' 
"
+"instruction set, ignoring target-abi and using triple-implied 
"
+"ABI\n";
+  break;
+case ABI_ILP32D:
+case ABI_LP64D:
+  errs() << "'" << ABIName

xen0n wrote:

same here

https://github.com/llvm/llvm-project/pull/92223

[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {
+switch (Abi) {
+default:
+  return false;
+case ABI_ILP32S:
+  return !Is64Bit;
+case ABI_ILP32F:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_ILP32D:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+case ABI_LP64S:
+  return Is64Bit;
+case ABI_LP64F:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_LP64D:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+}
+  };
+
+  // 1. If the '-target-abi' is valid, use it.
+  if (IsValidABI(ArgProvidedABI)) {
+if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+  errs()
+  << "warning: triple-implied ABI conflicts with provided target-abi '"
+  << ABIName << "', using target-abi\n";
+return checkABIStandardized(ArgProvidedABI);
+  }
+
+  // 2. If the triple-implied ABI is valid, use it.
+  if (IsValidABI(TripleABI)) {
+// If not specifie target-abi, use the valid triple-implied ABI.
+if (ABIName.empty())
+  return checkABIStandardized(TripleABI);
 
-  switch (ArgProvidedABI) {
-  case LoongArchABI::ABI_Unknown:
-// Fallback to the triple-implied ABI if ABI name is not specified or
-// invalid.
-if (!ABIName.empty())
+switch (ArgProvidedABI) {
+case ABI_Unknown:
+  // Fallback to the triple-implied ABI if ABI name is specified and

xen0n wrote:

```suggestion
  // Fallback to the triple-implied ABI if ABI name is specified but
```

https://github.com/llvm/llvm-project/pull/92223
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple , StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple ) {
   bool Is64Bit = TT.isArch64Bit();
   ABI TripleABI;
-
-  // Figure out the ABI explicitly requested via the triple's environment type.
   switch (TT.getEnvironment()) {
   case llvm::Triple::EnvironmentType::GNUSF:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64S : LoongArchABI::ABI_ILP32S;
+TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
 break;
   case llvm::Triple::EnvironmentType::GNUF32:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64F : LoongArchABI::ABI_ILP32F;
+TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
 break;
-
   // Let the fallback case behave like {ILP32,LP64}D.
   case llvm::Triple::EnvironmentType::GNUF64:
   default:
-TripleABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
+TripleABI = Is64Bit ? ABI_LP64D : ABI_ILP32D;
 break;
   }
+  return TripleABI;
+}
+
+ABI computeTargetABI(const Triple , const FeatureBitset ,
+ StringRef ABIName) {
+  bool Is64Bit = TT.isArch64Bit();
+  ABI ArgProvidedABI = getTargetABI(ABIName);
+  ABI TripleABI = getTripleABI(TT);
+
+  auto GetFeatureABI = [=]() {
+if (FeatureBits[LoongArch::FeatureBasicD])
+  return Is64Bit ? ABI_LP64D : ABI_ILP32D;
+if (FeatureBits[LoongArch::FeatureBasicF])
+  return Is64Bit ? ABI_LP64F : ABI_ILP32F;
+return Is64Bit ? ABI_LP64S : ABI_ILP32S;
+  };
+  auto IsValidABI = [=](ABI Abi) {
+switch (Abi) {
+default:
+  return false;
+case ABI_ILP32S:
+  return !Is64Bit;
+case ABI_ILP32F:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_ILP32D:
+  return !Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+case ABI_LP64S:
+  return Is64Bit;
+case ABI_LP64F:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicF];
+case ABI_LP64D:
+  return Is64Bit && FeatureBits[LoongArch::FeatureBasicD];
+}
+  };
+
+  // 1. If the '-target-abi' is valid, use it.
+  if (IsValidABI(ArgProvidedABI)) {
+if (TT.hasEnvironment() && ArgProvidedABI != TripleABI)
+  errs()
+  << "warning: triple-implied ABI conflicts with provided target-abi '"
+  << ABIName << "', using target-abi\n";
+return checkABIStandardized(ArgProvidedABI);
+  }
+
+  // 2. If the triple-implied ABI is valid, use it.
+  if (IsValidABI(TripleABI)) {
+// If not specifie target-abi, use the valid triple-implied ABI.

xen0n wrote:

```suggestion
// If target-abi is not specified, use the valid triple-implied ABI.
```

https://github.com/llvm/llvm-project/pull/92223
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits

https://github.com/xen0n commented:

Maybe unify all warning messages' format into `warning: blah blah`? LGTM apart 
from the natural language usages.

https://github.com/llvm/llvm-project/pull/92223
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [LoongArch] Refactor LoongArchABI::computeTargetABI (PR #92223)

2024-05-15 Thread WÁNG Xuěruì via llvm-branch-commits

https://github.com/xen0n edited https://github.com/llvm/llvm-project/pull/92223
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [LoongArch] Assume no-op addrspacecasts by default (#82332) (PR #86372)

2024-03-22 Thread WÁNG Xuěruì via llvm-branch-commits

https://github.com/xen0n approved this pull request.


https://github.com/llvm/llvm-project/pull/86372
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [llvm][LoongArch] Improve loongarch_lasx_xvpermi_q instrinsic (#82984) (PR #83540)

2024-03-07 Thread WÁNG Xuěruì via llvm-branch-commits

xen0n wrote:

For the record, based on the principle of "explicit is better than implicit" 
that generally holds, I'd favor an approach where such compile-time-verifiable 
out-of-range operands are given compile-time errors, or we should just pass 
through the value unmodified. Otherwise the intrinsic would have to carry the 
workaround effectively forever, and we could find ourselves trapped if later 
micro-architectures actually start to make use of the currently cleared bits.

https://github.com/llvm/llvm-project/pull/83540
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/18.x: [LoongArch] Override LoongArchTargetLowering::getExtendForAtomicCmpSwapArg (#83656) (PR #83750)

2024-03-03 Thread WÁNG Xuěruì via llvm-branch-commits

xen0n wrote:

I agree with backporting the change, as the actual code change is trivial and 
fixes a bug regarding atomic ops, which is known to be a subtle area important 
to overall system stability. Without the backport distro maintainers would 
still have to cherry-pick it themselves, duplicating efforts.

https://github.com/llvm/llvm-project/pull/83750
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits