Commit 78282f6c by Jim Stichnoth

Subzero: Make Ice::Ostream a typedef for llvm::raw_ostream.

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
parent cfe5146f
......@@ -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 {
......
......@@ -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:
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment