Clean up generated operator<<(os, enum).

Pass enums by value instead of const reference.

Do not generate operator<< sources for headers that have no
enums or no declarations of operator<<. Do not define the
operator<< for flag enums; these were unused anyway.

Add generated operator<< for some enums in nodes.h . Change
the operator<< for ComparisonBias so that the graph
visualizer can use it but do not use the generated
operator<< yet as that would require changing checker tests.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: Ifd4c455c2fa921a9668c966a13068d43b9c6e173
diff --git a/compiler/Android.bp b/compiler/Android.bp
index bd4cfce..513394e 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -181,9 +181,9 @@
     cmd: "$(location generate_operator_out) art/compiler $(in) > $(out)",
     tools: ["generate_operator_out"],
     srcs: [
-        "driver/compiler_options.h",
         "linker/linker_patch.h",
         "optimizing/locations.h",
+        "optimizing/nodes.h",
         "optimizing/optimizing_compiler_stats.h",
 
         "utils/arm/constants_arm.h",
diff --git a/compiler/linker/linker_patch.h b/compiler/linker/linker_patch.h
index 1c523de..7fedf2e 100644
--- a/compiler/linker/linker_patch.h
+++ b/compiler/linker/linker_patch.h
@@ -287,7 +287,7 @@
   friend bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs);
   friend bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs);
 };
-std::ostream& operator<<(std::ostream& os, const LinkerPatch::Type& type);
+std::ostream& operator<<(std::ostream& os, LinkerPatch::Type type);
 
 inline bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs) {
   return lhs.literal_offset_ == rhs.literal_offset_ &&
diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc
index d94c1fa..23b93fc 100644
--- a/compiler/optimizing/graph_visualizer.cc
+++ b/compiler/optimizing/graph_visualizer.cc
@@ -449,10 +449,7 @@
   }
 
   void VisitCompare(HCompare* compare) override {
-    ComparisonBias bias = compare->GetBias();
-    StartAttributeStream("bias") << (bias == ComparisonBias::kGtBias
-                                     ? "gt"
-                                     : (bias == ComparisonBias::kLtBias ? "lt" : "none"));
+    StartAttributeStream("bias") << compare->GetBias();
   }
 
   void VisitInvoke(HInvoke* invoke) override {
diff --git a/compiler/optimizing/locations.h b/compiler/optimizing/locations.h
index 5e7e74b..8f5eed7 100644
--- a/compiler/optimizing/locations.h
+++ b/compiler/optimizing/locations.h
@@ -440,8 +440,8 @@
   // way that none of them can be interpreted as a kConstant tag.
   uintptr_t value_;
 };
-std::ostream& operator<<(std::ostream& os, const Location::Kind& rhs);
-std::ostream& operator<<(std::ostream& os, const Location::Policy& rhs);
+std::ostream& operator<<(std::ostream& os, Location::Kind rhs);
+std::ostream& operator<<(std::ostream& os, Location::Policy rhs);
 
 class RegisterSet : public ValueObject {
  public:
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 3ea13b6..ec4b79e 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -1702,14 +1702,15 @@
   }
 }
 
-std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs) {
+std::ostream& operator<<(std::ostream& os, ComparisonBias rhs) {
+  // TODO: Replace with auto-generated operator<<.
   switch (rhs) {
     case ComparisonBias::kNoBias:
-      return os << "no_bias";
+      return os << "none";
     case ComparisonBias::kGtBias:
-      return os << "gt_bias";
+      return os << "gt";
     case ComparisonBias::kLtBias:
-      return os << "lt_bias";
+      return os << "lt";
     default:
       LOG(FATAL) << "Unknown ComparisonBias: " << static_cast<int>(rhs);
       UNREACHABLE();
@@ -1735,7 +1736,7 @@
   return true;
 }
 
-std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs) {
+std::ostream& operator<<(std::ostream& os, HInstruction::InstructionKind rhs) {
 #define DECLARE_CASE(type, super) case HInstruction::k##type: os << #type; break;
   switch (rhs) {
     FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_CASE)
@@ -2933,28 +2934,6 @@
   return !opt.GetDoesNotNeedDexCache();
 }
 
-std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs) {
-  switch (rhs) {
-    case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
-      return os << "StringInit";
-    case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
-      return os << "Recursive";
-    case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative:
-      return os << "BootImageLinkTimePcRelative";
-    case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo:
-      return os << "BootImageRelRo";
-    case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry:
-      return os << "BssEntry";
-    case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress:
-      return os << "JitDirectAddress";
-    case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall:
-      return os << "RuntimeCall";
-    default:
-      LOG(FATAL) << "Unknown MethodLoadKind: " << static_cast<int>(rhs);
-      UNREACHABLE();
-  }
-}
-
 std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs) {
   switch (rhs) {
     case HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit:
@@ -2990,28 +2969,6 @@
   }
 }
 
-std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs) {
-  switch (rhs) {
-    case HLoadClass::LoadKind::kReferrersClass:
-      return os << "ReferrersClass";
-    case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
-      return os << "BootImageLinkTimePcRelative";
-    case HLoadClass::LoadKind::kBootImageRelRo:
-      return os << "BootImageRelRo";
-    case HLoadClass::LoadKind::kBssEntry:
-      return os << "BssEntry";
-    case HLoadClass::LoadKind::kJitBootImageAddress:
-      return os << "JitBootImageAddress";
-    case HLoadClass::LoadKind::kJitTableAddress:
-      return os << "JitTableAddress";
-    case HLoadClass::LoadKind::kRuntimeCall:
-      return os << "RuntimeCall";
-    default:
-      LOG(FATAL) << "Unknown HLoadClass::LoadKind: " << static_cast<int>(rhs);
-      UNREACHABLE();
-  }
-}
-
 bool HLoadString::InstructionDataEquals(const HInstruction* other) const {
   const HLoadString* other_load_string = other->AsLoadString();
   // TODO: To allow GVN for HLoadString from different dex files, we should compare the strings
@@ -3032,26 +2989,6 @@
   }
 }
 
-std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs) {
-  switch (rhs) {
-    case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
-      return os << "BootImageLinkTimePcRelative";
-    case HLoadString::LoadKind::kBootImageRelRo:
-      return os << "BootImageRelRo";
-    case HLoadString::LoadKind::kBssEntry:
-      return os << "BssEntry";
-    case HLoadString::LoadKind::kJitBootImageAddress:
-      return os << "JitBootImageAddress";
-    case HLoadString::LoadKind::kJitTableAddress:
-      return os << "JitTableAddress";
-    case HLoadString::LoadKind::kRuntimeCall:
-      return os << "RuntimeCall";
-    default:
-      LOG(FATAL) << "Unknown HLoadString::LoadKind: " << static_cast<int>(rhs);
-      UNREACHABLE();
-  }
-}
-
 void HInstruction::RemoveEnvironmentUsers() {
   for (const HUseListNode<HEnvironment*>& use : GetEnvUses()) {
     HEnvironment* user = use.GetUser();
@@ -3163,25 +3100,6 @@
   }
 }
 
-std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind) {
-  switch (kind) {
-    case MemBarrierKind::kAnyStore:
-      return os << "AnyStore";
-    case MemBarrierKind::kLoadAny:
-      return os << "LoadAny";
-    case MemBarrierKind::kStoreStore:
-      return os << "StoreStore";
-    case MemBarrierKind::kAnyAny:
-      return os << "AnyAny";
-    case MemBarrierKind::kNTStoreStore:
-      return os << "NTStoreStore";
-
-    default:
-      LOG(FATAL) << "Unknown MemBarrierKind: " << static_cast<int>(kind);
-      UNREACHABLE();
-  }
-}
-
 // Check that intrinsic enum values fit within space set aside in ArtMethod modifier flags.
 #define CHECK_INTRINSICS_ENUM_VALUES(Name, InvokeType, _, SideEffects, Exceptions, ...) \
   static_assert( \
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 00dc50c..a7ea371 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -2090,7 +2090,7 @@
 class HInstruction : public ArenaObject<kArenaAllocInstruction> {
  public:
 #define DECLARE_KIND(type, super) k##type,
-  enum InstructionKind {
+  enum InstructionKind {  // private marker to avoid generate-operator-out.py from processing.
     FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND)
     kLastInstructionKind
   };
@@ -2648,7 +2648,7 @@
   friend class HGraph;
   friend class HInstructionList;
 };
-std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs);
+std::ostream& operator<<(std::ostream& os, HInstruction::InstructionKind rhs);
 
 // Iterates over the instructions, while preserving the next instruction
 // in case the current instruction gets removed from the list by the user
@@ -3673,14 +3673,14 @@
 
 // The comparison bias applies for floating point operations and indicates how NaN
 // comparisons are treated:
-enum class ComparisonBias {
+enum class ComparisonBias {  // private marker to avoid generate-operator-out.py from processing.
   kNoBias,  // bias is not applicable (i.e. for long operation)
   kGtBias,  // return 1 for NaN comparisons
   kLtBias,  // return -1 for NaN comparisons
   kLast = kLtBias
 };
 
-std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs);
+std::ostream& operator<<(std::ostream& os, ComparisonBias rhs);
 
 class HCondition : public HBinaryOperation {
  public:
@@ -4565,7 +4565,7 @@
  public:
   // Requirements of this method call regarding the class
   // initialization (clinit) check of its declaring class.
-  enum class ClinitCheckRequirement {
+  enum class ClinitCheckRequirement {  // private marker to avoid generate-operator-out.py from processing.
     kNone,      // Class already initialized.
     kExplicit,  // Static call having explicit clinit check as last input.
     kImplicit,  // Static call implicitly requiring a clinit check.
@@ -7200,7 +7200,7 @@
  * Implementation strategies for the code generator of a HInstanceOf
  * or `HCheckCast`.
  */
-enum class TypeCheckKind {
+enum class TypeCheckKind {  // private marker to avoid generate-operator-out.py from processing.
   kUnresolvedCheck,       // Check against an unresolved type.
   kExactCheck,            // Can do a single class compare.
   kClassHierarchyCheck,   // Can just walk the super class chain.
@@ -7474,7 +7474,7 @@
   kNTStoreStore,
   kLastBarrierKind = kNTStoreStore
 };
-std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind);
+std::ostream& operator<<(std::ostream& os, MemBarrierKind kind);
 
 class HMemoryBarrier final : public HExpression<0> {
  public:
diff --git a/compiler/optimizing/optimizing_compiler_stats.h b/compiler/optimizing/optimizing_compiler_stats.h
index 621e863..475c532 100644
--- a/compiler/optimizing/optimizing_compiler_stats.h
+++ b/compiler/optimizing/optimizing_compiler_stats.h
@@ -110,7 +110,7 @@
   kJitOutOfMemoryForCommit,
   kLastStat
 };
-std::ostream& operator<<(std::ostream& os, const MethodCompilationStat& rhs);
+std::ostream& operator<<(std::ostream& os, MethodCompilationStat rhs);
 
 class OptimizingCompilerStats {
  public: