[llvm] [TargetLowering] Deduplicate choosing InlineAsm constraint between ISels (PR #67057)

Bill Wendling via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 14:06:07 PDT 2023


================
@@ -5701,13 +5702,19 @@ TargetLowering::ParseConstraints(const DataLayout &DL,
   return ConstraintOperands;
 }
 
-/// Return an integer indicating how general CT is.
-static unsigned getConstraintGenerality(TargetLowering::ConstraintType CT) {
+/// Return a number indicating our preference for chosing a type of constraint
+/// over another, for the purpose of sorting them. Immediates are almost always
+/// preferrable (when they can be emitted).
+/// FIXME: We should prefer registers over memory but doing so may lead to
+/// unrecoverable register exhaustion later.
+/// https://github.com/llvm/llvm-project/issues/20571
+static unsigned getConstraintPiority(TargetLowering::ConstraintType CT) {
   switch (CT) {
-  case TargetLowering::C_Immediate:
-  case TargetLowering::C_Other:
   case TargetLowering::C_Unknown:
     return 0;
+  case TargetLowering::C_Immediate:
+  case TargetLowering::C_Other:
+    return 4;
----------------
bwendling wrote:

I don't quite get what the numbers represent here. Is "higher" more preferable or is "lower"? If lower is preferable, then shouldn't `C_Immediate` be more like `C_Register` rather than `C_Other`? Also, please reorder the cases into the sort order...

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


More information about the llvm-commits mailing list