OSDN Git Service

Subzero: Make Ice::Ostream a typedef for llvm::raw_ostream.
authorJim Stichnoth <stichnot@chromium.org>
Mon, 28 Jul 2014 06:14:00 +0000 (23:14 -0700)
committerJim Stichnoth <stichnot@chromium.org>
Mon, 28 Jul 2014 06:14:00 +0000 (23:14 -0700)
Previously Ostream was a class that wrapped a raw_ostream pointer,
structured that way in case we wanted to wrap an alternate stream
type.

Also, Ostream used to include a Cfg pointer, but that had to go away
when the Ostream became associated with the GlobalContext which
persists beyond the Cfg lifetime, so the Cfg pointer was removed
leaving only the raw_ostream.

Since llvm::raw_ostream is supposed to be very lightweight, we can
just give up the abstraction and equate it to Ice::Ostream.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/413393005

src/IceDefs.h
src/IceGlobalContext.cpp
src/IceGlobalContext.h
src/IceTargetLoweringX8632.cpp
src/IceTypes.cpp
src/IceTypes.h

index 6aee09a..cf9052c 100644 (file)
@@ -105,26 +105,7 @@ enum VerboseItem {
 };
 typedef uint32_t VerboseMask;
 
-// The Ostream class wraps an output stream and a Cfg pointer, so
-// that dump routines have access to the Cfg object and can print
-// labels and variable names.
-
-class Ostream {
-public:
-  Ostream(llvm::raw_ostream *Stream) : Stream(Stream) {}
-
-  llvm::raw_ostream *Stream;
-
-private:
-  Ostream(const Ostream &) LLVM_DELETED_FUNCTION;
-  Ostream &operator=(const Ostream &) LLVM_DELETED_FUNCTION;
-};
-
-template <typename T> inline Ostream &operator<<(Ostream &Str, const T &Val) {
-  if (Str.Stream)
-    (*Str.Stream) << Val;
-  return Str;
-}
+typedef llvm::raw_ostream Ostream;
 
 // TODO: Implement in terms of std::chrono after switching to C++11.
 class Timer {
index a7b1b64..113ffc4 100644 (file)
@@ -330,8 +330,7 @@ Constant *GlobalContext::getConstantZero(Type Ty) {
   case IceType_v4f32: {
     IceString Str;
     llvm::raw_string_ostream BaseOS(Str);
-    Ostream OS(&BaseOS);
-    OS << "Unsupported constant type: " << Ty;
+    BaseOS << "Unsupported constant type: " << Ty;
     llvm_unreachable(BaseOS.str().c_str());
   } break;
   case IceType_void:
@@ -362,8 +361,7 @@ ConstantList GlobalContext::getConstantPool(Type Ty) const {
   case IceType_v4f32: {
     IceString Str;
     llvm::raw_string_ostream BaseOS(Str);
-    Ostream OS(&BaseOS);
-    OS << "Unsupported constant type: " << Ty;
+    BaseOS << "Unsupported constant type: " << Ty;
     llvm_unreachable(BaseOS.str().c_str());
   } break;
   case IceType_void:
index 1a3e4cd..e1b67ac 100644 (file)
@@ -47,8 +47,8 @@ public:
   void addVerbose(VerboseMask Mask) { VMask |= Mask; }
   void subVerbose(VerboseMask Mask) { VMask &= ~Mask; }
 
-  Ostream &getStrDump() { return StrDump; }
-  Ostream &getStrEmit() { return StrEmit; }
+  Ostream &getStrDump() { return *StrDump; }
+  Ostream &getStrEmit() { return *StrEmit; }
 
   TargetArch getTargetArch() const { return Arch; }
   OptLevel getOptLevel() const { return Opt; }
@@ -92,8 +92,8 @@ public:
   const Intrinsics &getIntrinsicsInfo() const { return IntrinsicsInfo; }
 
 private:
-  Ostream StrDump; // Stream for dumping / diagnostics
-  Ostream StrEmit; // Stream for code emission
+  Ostream *StrDump; // Stream for dumping / diagnostics
+  Ostream *StrEmit; // Stream for code emission
 
   llvm::BumpPtrAllocator Allocator;
   VerboseMask VMask;
index 83dc5bd..8123e74 100644 (file)
@@ -128,11 +128,10 @@ const unsigned X86_CHAR_BIT = 8;
 IceString typeIdentString(const Type Ty) {
   IceString Str;
   llvm::raw_string_ostream BaseOS(Str);
-  Ostream OS(&BaseOS);
   if (isVectorType(Ty)) {
-    OS << "v" << typeNumElements(Ty) << typeElementType(Ty);
+    BaseOS << "v" << typeNumElements(Ty) << typeElementType(Ty);
   } else {
-    OS << Ty;
+    BaseOS << Ty;
   }
   return BaseOS.str();
 }
index 515be2d..0724e51 100644 (file)
@@ -81,18 +81,13 @@ Type typeElementType(Type Ty) {
   return ElementType;
 }
 
-// ======================== Dump routines ======================== //
-
-template <> Ostream &operator<<(Ostream &Str, const Type &Ty) {
+const char *typeString(Type Ty) {
   size_t Index = static_cast<size_t>(Ty);
   if (Index < TypeAttributesSize) {
-    Str << TypeAttributes[Index].DisplayString;
-  } else {
-    Str << "???";
-    llvm_unreachable("Invalid type for printing");
+    return TypeAttributes[Index].DisplayString;
   }
-
-  return Str;
+  llvm_unreachable("Invalid type for typeString");
+  return "???";
 }
 
 } // end of namespace Ice
index 6bc2ded..fa91763 100644 (file)
@@ -45,10 +45,15 @@ size_t typeWidthInBytes(Type Ty);
 size_t typeAlignInBytes(Type Ty);
 size_t typeNumElements(Type Ty);
 Type typeElementType(Type Ty);
+const char *typeString(Type Ty);
 
 inline bool isVectorType(Type Ty) { return typeNumElements(Ty) > 1; }
 
-template <> Ostream &operator<<(class Ostream &Str, const Type &Ty);
+template <typename StreamType>
+inline StreamType &operator<<(StreamType &Str, const Type &Ty) {
+  Str << typeString(Ty);
+  return Str;
+}
 
 } // end of namespace Ice