Step 2 of 2: conditional passes.

Rationale:
The change introduces actual conditional passes
(dependence on inliner). This ensures more
cases are optimized downstream without
needlessly introducing compile-time.

NOTE:
Some checker tests needed to be rewritten
due to subtle changes in the phase ordering.
No optimizations were harmed in the process,
though.

Bug: b/78171933, b/74026074

Test: test-art-host,target

Change-Id: I335260df780e14ba1f22499ad74d79060c7be44d
diff --git a/compiler/optimizing/optimization.cc b/compiler/optimizing/optimization.cc
index 57db7a6..d37c43d 100644
--- a/compiler/optimizing/optimization.cc
+++ b/compiler/optimizing/optimization.cc
@@ -121,12 +121,15 @@
     case OptimizationPass::kX86MemoryOperandGeneration:
       return x86::X86MemoryOperandGeneration::kX86MemoryOperandGenerationPassName;
 #endif
+    case OptimizationPass::kNone:
+      LOG(FATAL) << "kNone does not represent an actual pass";
+      UNREACHABLE();
   }
 }
 
-#define X(x) if (name == OptimizationPassName((x))) return (x)
+#define X(x) if (pass_name == OptimizationPassName((x))) return (x)
 
-OptimizationPass OptimizationPassByName(const std::string& name) {
+OptimizationPass OptimizationPassByName(const std::string& pass_name) {
   X(OptimizationPass::kBoundsCheckElimination);
   X(OptimizationPass::kCHAGuardOptimization);
   X(OptimizationPass::kCodeSinking);
@@ -160,7 +163,7 @@
   X(OptimizationPass::kPcRelativeFixupsX86);
   X(OptimizationPass::kX86MemoryOperandGeneration);
 #endif
-  LOG(FATAL) << "Cannot find optimization " << name;
+  LOG(FATAL) << "Cannot find optimization " << pass_name;
   UNREACHABLE();
 }
 
@@ -187,9 +190,9 @@
 
   // Loop over the requested optimizations.
   for (size_t i = 0; i < length; i++) {
-    OptimizationPass pass = definitions[i].first;
-    const char* alt_name = definitions[i].second;
-    const char* name = alt_name != nullptr
+    OptimizationPass pass = definitions[i].pass;
+    const char* alt_name = definitions[i].pass_name;
+    const char* pass_name = alt_name != nullptr
         ? alt_name
         : OptimizationPassName(pass);
     HOptimization* opt = nullptr;
@@ -199,47 +202,48 @@
       // Analysis passes (kept in most recent for subsequent passes).
       //
       case OptimizationPass::kSideEffectsAnalysis:
-        opt = most_recent_side_effects = new (allocator) SideEffectsAnalysis(graph, name);
+        opt = most_recent_side_effects = new (allocator) SideEffectsAnalysis(graph, pass_name);
         break;
       case OptimizationPass::kInductionVarAnalysis:
-        opt = most_recent_induction = new (allocator) HInductionVarAnalysis(graph, name);
+        opt = most_recent_induction = new (allocator) HInductionVarAnalysis(graph, pass_name);
         break;
       case OptimizationPass::kLoadStoreAnalysis:
-        opt = most_recent_lsa = new (allocator) LoadStoreAnalysis(graph, name);
+        opt = most_recent_lsa = new (allocator) LoadStoreAnalysis(graph, pass_name);
         break;
       //
       // Passes that need prior analysis.
       //
       case OptimizationPass::kGlobalValueNumbering:
         CHECK(most_recent_side_effects != nullptr);
-        opt = new (allocator) GVNOptimization(graph, *most_recent_side_effects, name);
+        opt = new (allocator) GVNOptimization(graph, *most_recent_side_effects, pass_name);
         break;
       case OptimizationPass::kInvariantCodeMotion:
         CHECK(most_recent_side_effects != nullptr);
-        opt = new (allocator) LICM(graph, *most_recent_side_effects, stats, name);
+        opt = new (allocator) LICM(graph, *most_recent_side_effects, stats, pass_name);
         break;
       case OptimizationPass::kLoopOptimization:
         CHECK(most_recent_induction != nullptr);
-        opt = new (allocator) HLoopOptimization(graph, driver, most_recent_induction, stats, name);
+        opt = new (allocator) HLoopOptimization(
+            graph, driver, most_recent_induction, stats, pass_name);
         break;
       case OptimizationPass::kBoundsCheckElimination:
         CHECK(most_recent_side_effects != nullptr && most_recent_induction != nullptr);
         opt = new (allocator) BoundsCheckElimination(
-            graph, *most_recent_side_effects, most_recent_induction, name);
+            graph, *most_recent_side_effects, most_recent_induction, pass_name);
         break;
       case OptimizationPass::kLoadStoreElimination:
         CHECK(most_recent_side_effects != nullptr && most_recent_induction != nullptr);
         opt = new (allocator) LoadStoreElimination(
-            graph, *most_recent_side_effects, *most_recent_lsa, stats, name);
+            graph, *most_recent_side_effects, *most_recent_lsa, stats, pass_name);
         break;
       //
       // Regular passes.
       //
       case OptimizationPass::kConstantFolding:
-        opt = new (allocator) HConstantFolding(graph, name);
+        opt = new (allocator) HConstantFolding(graph, pass_name);
         break;
       case OptimizationPass::kDeadCodeElimination:
-        opt = new (allocator) HDeadCodeElimination(graph, stats, name);
+        opt = new (allocator) HDeadCodeElimination(graph, stats, pass_name);
         break;
       case OptimizationPass::kInliner: {
         CodeItemDataAccessor accessor(*dex_compilation_unit.GetDexFile(),
@@ -256,33 +260,33 @@
                                        /* total_number_of_instructions */ 0,
                                        /* parent */ nullptr,
                                        /* depth */ 0,
-                                       name);
+                                       pass_name);
         break;
       }
       case OptimizationPass::kSharpening:
-        opt = new (allocator) HSharpening(graph, codegen, driver, name);
+        opt = new (allocator) HSharpening(graph, codegen, driver, pass_name);
         break;
       case OptimizationPass::kSelectGenerator:
-        opt = new (allocator) HSelectGenerator(graph, handles, stats, name);
+        opt = new (allocator) HSelectGenerator(graph, handles, stats, pass_name);
         break;
       case OptimizationPass::kInstructionSimplifier:
-        opt = new (allocator) InstructionSimplifier(graph, codegen, driver, stats, name);
+        opt = new (allocator) InstructionSimplifier(graph, codegen, driver, stats, pass_name);
         break;
       case OptimizationPass::kIntrinsicsRecognizer:
-        opt = new (allocator) IntrinsicsRecognizer(graph, stats, name);
+        opt = new (allocator) IntrinsicsRecognizer(graph, stats, pass_name);
         break;
       case OptimizationPass::kCHAGuardOptimization:
-        opt = new (allocator) CHAGuardOptimization(graph, name);
+        opt = new (allocator) CHAGuardOptimization(graph, pass_name);
         break;
       case OptimizationPass::kCodeSinking:
-        opt = new (allocator) CodeSinking(graph, stats, name);
+        opt = new (allocator) CodeSinking(graph, stats, pass_name);
         break;
       case OptimizationPass::kConstructorFenceRedundancyElimination:
-        opt = new (allocator) ConstructorFenceRedundancyElimination(graph, stats, name);
+        opt = new (allocator) ConstructorFenceRedundancyElimination(graph, stats, pass_name);
         break;
       case OptimizationPass::kScheduling:
         opt = new (allocator) HInstructionScheduling(
-            graph, driver->GetInstructionSet(), codegen, name);
+            graph, driver->GetInstructionSet(), codegen, pass_name);
         break;
       //
       // Arch-specific passes.
@@ -319,11 +323,14 @@
         opt = new (allocator) x86::X86MemoryOperandGeneration(graph, codegen, stats);
         break;
 #endif
+      case OptimizationPass::kNone:
+        LOG(FATAL) << "kNone does not represent an actual pass";
+        UNREACHABLE();
     }  // switch
 
     // Add each next optimization to result vector.
     CHECK(opt != nullptr);
-    DCHECK_STREQ(name, opt->GetPassName());  // sanity
+    DCHECK_STREQ(pass_name, opt->GetPassName());  // sanity
     optimizations.push_back(opt);
   }