Chromium Code Reviews| Index: src/IceDefs.h |
| diff --git a/src/IceDefs.h b/src/IceDefs.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..afd0e61d75686c1aeea874cc2c7c03efa62f2e56 |
| --- /dev/null |
| +++ b/src/IceDefs.h |
| @@ -0,0 +1,142 @@ |
| +//===- subzero/src/IceDefs.h - Common Subzero declaraions -------*- C++ -*-===// |
| +// |
| +// The Subzero Code Generator |
| +// |
| +// This file is distributed under the University of Illinois Open Source |
| +// License. See LICENSE.TXT for details. |
| +// |
| +//===----------------------------------------------------------------------===// |
| +// |
| +// This file declares various useful types and classes that have |
| +// widespread use across Subzero. Every Subzero source file is |
| +// expected to include IceDefs.h. |
| +// |
| +//===----------------------------------------------------------------------===// |
| + |
| +#ifndef SUBZERO_SRC_ICEDEFS_H |
| +#define SUBZERO_SRC_ICEDEFS_H |
| + |
| +#include <cassert> |
| +#include <stdint.h> |
| +#include <cstdio> // snprintf |
| + |
| +#include <list> |
| +#include <map> |
| +#include <set> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "llvm/ADT/BitVector.h" |
| +#include "llvm/ADT/SmallBitVector.h" |
| +#include "llvm/Support/Casting.h" |
| +#include "llvm/Support/raw_ostream.h" |
| +#include "llvm/Support/Timer.h" |
| + |
| +namespace Ice { |
| + |
| +class CfgNode; |
| +class Constant; |
| +class GlobalContext; |
| +class IceCfg; |
|
JF
2014/04/23 03:51:28
Why not shed the Ice (or melt?) for Cfg and the ot
Jim Stichnoth
2014/04/26 15:02:11
Done. Except I'd prefer to keep IceString, since
|
| +class Inst; |
| +class InstPhi; |
| +class InstTarget; |
| +class Operand; |
| +class Variable; |
| + |
| +// TODO: Switch over to LLVM's ADT container classes. |
| +// http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure-for-a-task |
| +typedef std::string IceString; |
| +typedef std::list<Inst *> InstList; |
| +typedef std::list<InstPhi *> PhiList; |
| +typedef std::vector<Variable *> VarList; |
| +typedef std::vector<CfgNode *> NodeList; |
| + |
| +// IceSize_t is for holding small-ish limits like number of source |
| +// operands in an instruction. It is used instead of size_t (which |
| +// may be 64-bits wide) when we want to save space. |
| +typedef uint32_t IceSize_t; |
|
JF
2014/04/23 03:51:28
Names ending in _t are reserved by POSIX. Why not
Jim Stichnoth
2014/04/26 15:02:11
Can we compromise on SizeT? :)
|
| + |
| +// This is a convenience templated class that provides a mapping |
| +// between a parameterized type and small unsigned integers. |
| +template <typename T, typename Cmp = std::less<T> > class ValueTranslation { |
|
JF
2014/04/23 03:51:28
You need to #include <functional> to use std::less
Jim Stichnoth
2014/04/26 15:02:11
Done.
|
| +public: |
| + typedef typename std::map<const T, IceSize_t, Cmp> ContainerType; |
|
JF
2014/04/23 03:51:28
Just to restore my template sanity, could you use
Jim Stichnoth
2014/04/26 15:02:11
Done (sort of). Sadly, static_assert and is_float
|
| + ValueTranslation() {} |
| + void clear() { Entries.clear(); } |
| + IceSize_t translate(const T &Value) { |
| + typename ContainerType::const_iterator Iter = Entries.find(Value); |
| + if (Iter != Entries.end()) |
| + return Iter->second; |
| + IceSize_t Index = Entries.size(); |
| + Entries[Value] = Index; |
| + return Index; |
| + } |
| + |
| +private: |
| + ContainerType Entries; |
| + ValueTranslation(const ValueTranslation &) LLVM_DELETED_FUNCTION; |
| + ValueTranslation &operator=(const ValueTranslation &) LLVM_DELETED_FUNCTION; |
| +}; |
| + |
| +enum IceVerbose { |
| + IceV_None = 0, |
| + IceV_Instructions = 1 << 0, |
| + IceV_Deleted = 1 << 1, |
| + IceV_InstNumbers = 1 << 2, |
| + IceV_Preds = 1 << 3, |
| + IceV_Succs = 1 << 4, |
| + IceV_Liveness = 1 << 5, |
| + IceV_RegManager = 1 << 6, |
| + IceV_RegOrigins = 1 << 7, |
| + IceV_LinearScan = 1 << 8, |
| + IceV_Frame = 1 << 9, |
| + IceV_Timing = 1 << 10, |
| + IceV_All = ~IceV_None |
| +}; |
| +typedef uint32_t IceVerboseMask; |
| + |
| +// The IceOstream class wraps an output stream and an IceCfg pointer, |
| +// so that dump routines have access to the IceCfg object and can |
| +// print labels and variable names. |
| + |
| +class IceOstream { |
| +public: |
| + IceOstream(llvm::raw_ostream *Stream) : Stream(Stream) {} |
| + |
| + llvm::raw_ostream *Stream; |
| + |
| +private: |
| + IceOstream(const IceOstream &) LLVM_DELETED_FUNCTION; |
| + IceOstream &operator=(const IceOstream &) LLVM_DELETED_FUNCTION; |
| +}; |
| + |
| +template <typename T> |
| +inline IceOstream &operator<<(IceOstream &Str, const T &Val) { |
| + if (Str.Stream) |
| + (*Str.Stream) << Val; |
| + return Str; |
| +} |
| + |
| +// TODO: Implement in terms of std::chrono after switching to C++11. |
| +class IceTimer { |
| +public: |
| + IceTimer() : Start(llvm::TimeRecord::getCurrentTime(false)) {} |
| + uint64_t getElapsedNs() const { return getElapsedSec() * 1000 * 1000 * 1000; } |
| + uint64_t getElapsedUs() const { return getElapsedSec() * 1000 * 1000; } |
| + uint64_t getElapsedMs() const { return getElapsedSec() * 1000; } |
| + double getElapsedSec() const { |
| + llvm::TimeRecord End = llvm::TimeRecord::getCurrentTime(false); |
| + return End.getWallTime() - Start.getWallTime(); |
| + } |
| + void printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const; |
| + |
| +private: |
| + const llvm::TimeRecord Start; |
| + IceTimer(const IceTimer &) LLVM_DELETED_FUNCTION; |
| + IceTimer &operator=(const IceTimer &) LLVM_DELETED_FUNCTION; |
| +}; |
| + |
| +} // end of namespace Ice |
| + |
| +#endif // SUBZERO_SRC_ICEDEFS_H |