[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


[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] 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] [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] [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 &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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


@@ -52,63 +53,129 @@ static ABI checkABIStandardized(ABI Abi) {
   return Abi;
 }
 
-ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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 &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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 &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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' 
"
+"instru

[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 &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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 &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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 &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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' 
"
+"instru

[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 &TT, StringRef ABIName) {
-  ABI ArgProvidedABI = getTargetABI(ABIName);
+static ABI getTripleABI(const Triple &TT) {
   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 &TT, const FeatureBitset &FeatureBits,
+ 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' 
"
+"instru

[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] [llvm] release/19.x: [LoongArch] Fix the assertion for atomic store with 'ptr' type (PR #109915)

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

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

fixes loongson-community/discussions#68

https://github.com/llvm/llvm-project/pull/109915
___
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] [clang] release/19.x: [LoongArch][Clang] Make the parameters and return value of {x, }vxor.v builti ns `unsigned char` vectors (#114513) (PR #114958)

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

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

Test failures shouldn't be relevant.

https://github.com/llvm/llvm-project/pull/114958
___
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] [lld] [lld][LoongArch] Relax TLS LE/GD/LD (PR #123600)

2025-02-16 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -0,0 +1,115 @@
+# REQUIRES: loongarch
+
+# RUN: llvm-mc --filetype=obj --triple=loongarch32 -mattr=+relax --defsym 
ELF32=1 %s -o %t.32.o
+# RUN: llvm-mc --filetype=obj --triple=loongarch64 -mattr=+relax %s -o %t.64.o
+
+# RUN: ld.lld %t.32.o -o %t.32
+# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck 
--check-prefixes=RELAX32 %s
+
+# RUN: ld.lld %t.64.o -o %t.64
+# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck 
--check-prefixes=RELAX64 %s
+
+# RELAX32-LABEL: <_start>:
+## .LANCHOR0@tprel = 8
+# RELAX32-NEXT:addi.w  $a0, $tp, 8 
+# RELAX32-NEXT:ld.w$a1, $a0, 0
+# RELAX32-NEXT:ld.w$a2, $tp, 8
+## .a@tprel - 4 = 0x7fc
+# RELAX32-NEXT:addi.w  $a1, $zero, 1
+# RELAX32-NEXT:addi.w $a1, $a1, 2
+# RELAX32-NEXT:st.w   $a1, $tp, 2044
+## .a@tprel = 0x800
+# RELAX32-NEXT:lu12i.w $a0, 1
+# RELAX32-NEXT:add.w   $a0, $a0, $tp
+# RELAX32-NEXT:addi.w  $a0, $a0, -2048
+
+# RELAX64-LABEL: <_start>:
+## .LANCHOR0@tprel = 8
+# RELAX64-NEXT:addi.d  $a0, $tp, 8 
+# RELAX64-NEXT:ld.d$a1, $a0, 0
+# RELAX64-NEXT:ld.d$a2, $tp, 8
+## .a@tprel - 4 = 0x7fc
+# RELAX64-NEXT:addi.d  $a1, $zero, 1
+# RELAX64-NEXT:addi.d $a1, $a1, 2
+# RELAX64-NEXT:st.d   $a1, $tp, 2044
+## .a@tprel = 0x800
+# RELAX64-NEXT:lu12i.w $a0, 1
+# RELAX64-NEXT:add.d   $a0, $a0, $tp
+# RELAX64-NEXT:addi.d  $a0, $a0, -2048
+
+.macro add dst, src1, src2, src3
+.ifdef ELF32
+add.w \dst, \src1, \src2, \src3
+.else
+add.d \dst, \src1, \src2, \src3
+.endif
+.endm
+.macro inst op dst, src1, src2
+.ifdef ELF32
+  .ifc  \op, addi
+addi.w  \dst, \src1, \src2
+  .else;.ifc   \op, ld
+ld.w\dst, \src1, \src2
+  .else;.ifc   \op, st
+st.w\dst, \src1, \src2
+  .else;.ifc   \op, ldptr
+ldptr.w \dst, \src1, \src2
+  .else
+.error "Unknown op in ELF32 mode"
+  .endif; .endif; .endif; .endif
+.else
+  .ifc  \op, addi
+addi.d  \dst, \src1, \src2
+  .else;.ifc   \op, ld
+ld.d\dst, \src1, \src2
+  .else;.ifc   \op, st
+st.d\dst, \src1, \src2
+  .else;.ifc   \op, ldptr
+ldptr.d \dst, \src1, \src2
+  .else
+.error "Unknown op in ELF64 mode"
+  .endif; .endif; .endif; .endif
+.endif
+.endm
+
+.macro addi dst, src1, src2
+inst addi \dst, \src1, \src2
+.endm
+.macro ld dst, src1, src2
+inst ld \dst, \src1, \src2
+.endm
+.macro st dst, src1, src2
+inst st \dst, \src1, \src2
+.endm
+.macro ldptr dst, src1, src2
+inst ldptr \dst, \src1, \src2
+.endm
+
+_start:
+## Test instructions not in pairs.
+lu12i.w $a0, %le_hi20_r(.LANCHOR0)

xen0n wrote:

Yeah, the instructions should be indented by 2 or 4 spaces for readability. We 
should re-format some test cases e.g. `loongarch-tlsdesc.s` as well in a 
separate change.

https://github.com/llvm/llvm-project/pull/123600
___
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] [lld] [lld][LoongArch] Relax TLS LE/GD/LD (PR #123600)

2025-02-16 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -1015,8 +1063,20 @@ void LoongArch::finalizeRelax(int passes) const {
 r.expr = r.sym->hasFlag(NEEDS_PLT) ? R_PLT_PC : R_PC;
 break;
   case R_LARCH_B26:
+  case R_LARCH_TLS_LE_LO12_R:
+skip = 4;
+write32le(p, aux.writes[writesIdx++]);
+break;
+  case R_LARCH_TLS_GD_PCREL20_S2:
+// Note: R_LARCH_TLS_LD_PCREL20_S2 must also use R_TLSGD_PC instead
+// of R_TLSLD_PC because the processing of relocation
+// R_LARCH_TLS_LD_PC_HI20 is the same as R_LARCH_TLS_GD_PC_HI20. If

xen0n wrote:

According to [this mold 
commit](https://github.com/rui314/mold/commit/5dfa1cf07c03bd57cb3d493b652ef22441bcd71c)
 this is mostly due to human error (compiler bug that's unfortunately too late 
to fix without revising psABI), so you may want to mention it somehow to reduce 
reader confusion. "If not, ... will error" is clearly not the root cause and 
likely will not satisfy the curiosity of many.

https://github.com/llvm/llvm-project/pull/123600
___
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] [lld] [lld][LoongArch] Relax TLS LE/GD/LD (PR #123600)

2025-02-16 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -863,6 +874,35 @@ static void relaxCall36(Ctx &ctx, const InputSection &sec, 
size_t i,
   }
 }
 
+// Relax code sequence.
+// From:
+//   lu12i.w $rd, %le_hi20_r(sym)
+//   add.w/d $rd, $rd, $tp, %le_add_r(sym)
+//   addi/ld/st.w/d $rd, $rd, %le_lo12_r(sym)
+// To:
+//   addi/ld/st.w/d $rd, $tp, %le_lo12_r(sym)
+static void relaxTlsLe(Ctx &ctx, const InputSection &sec, size_t i,
+   uint64_t loc, Relocation &r, uint32_t &remove) {
+  uint64_t val = r.sym->getVA(ctx, r.addend);
+  // Check if the val exceeds the range of addi/ld/st.
+  if (!isInt<12>(val))
+return;
+  uint32_t currInsn = read32le(sec.content().data() + r.offset);
+  switch (r.type) {
+  case R_LARCH_TLS_LE_HI20_R:
+  case R_LARCH_TLS_LE_ADD_R:
+sec.relaxAux->relocTypes[i] = R_LARCH_RELAX;
+remove = 4;
+break;
+  case R_LARCH_TLS_LE_LO12_R:
+currInsn =
+insn(extractBits(currInsn, 31, 22) << 22, getD5(currInsn), R_TP, 0);
+sec.relaxAux->writes.push_back(currInsn);

xen0n wrote:

It's probably better to add a `setJ` helper (near the `setJ20` helper maybe) 
and use it instead, so that the expression becomes shorter and no need to 
change the `currInsn` variable.

https://github.com/llvm/llvm-project/pull/123600
___
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] [lld] [lld][LoongArch] Relax TLS LE/GD/LD (PR #123600)

2025-02-16 Thread WÁNG Xuěruì via llvm-branch-commits


@@ -1015,8 +1063,20 @@ void LoongArch::finalizeRelax(int passes) const {
 r.expr = r.sym->hasFlag(NEEDS_PLT) ? R_PLT_PC : R_PC;
 break;
   case R_LARCH_B26:
+  case R_LARCH_TLS_LE_LO12_R:
+skip = 4;
+write32le(p, aux.writes[writesIdx++]);
+break;
+  case R_LARCH_TLS_GD_PCREL20_S2:
+// Note: R_LARCH_TLS_LD_PCREL20_S2 must also use R_TLSGD_PC instead
+// of R_TLSLD_PC because the processing of relocation
+// R_LARCH_TLS_LD_PC_HI20 is the same as R_LARCH_TLS_GD_PC_HI20. If

xen0n wrote:

> Thanks for your review. I will revise it to the following description. Do you 
> think it is clear?
> 
> ```
> Note: R_LARCH_TLS_LD_PCREL20_S2 must also use R_TLSGD_PC instead
> of R_TLSLD_PC due to historical reasons. In fact, TLSLD is not fully supported
> on LoongArch. We need to handle relocation of R_LARCH_TLS_LD_PC_HI20
> as equivalent to R_LARCH_TLS_GD_PC_HI20.
> 
> This reason has also been mentioned in mold commit:
> https://github.com/rui314/mold/commit/5dfa1cf07c03bd57cb3d493b652ef22441bcd71c
> ```

"In fact, right now TLS LD behaves exactly like GD on LoongArch." is enough, 
and the "We need to ..." sentence can be omitted this way.

https://github.com/llvm/llvm-project/pull/123600
___
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] [lld] [lld][LoongArch] Relax TLS LE/GD/LD (PR #123600)

2025-02-17 Thread WÁNG Xuěruì via llvm-branch-commits

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

Thanks!

https://github.com/llvm/llvm-project/pull/123600
___
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][MC] Add relocation support for fld fst [x]vld [x]vst (PR #133225)

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

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

Nice catch!

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