Chromium Code Reviews| Index: src/IceDefs.h |
| diff --git a/src/IceDefs.h b/src/IceDefs.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6d400f2d301e09cd15409801aedc7710e137d66 |
| --- /dev/null |
| +++ b/src/IceDefs.h |
| @@ -0,0 +1,125 @@ |
| +//===- 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 <assert.h> |
| +#include <stdint.h> |
| +#include <stdio.h> // sprintf |
|
JF
2014/04/16 01:27:32
Since this is a new code base I'd go with the <c*>
Jim Stichnoth
2014/04/21 20:26:40
Done for <cassert> and <cstdio>. stdint.h seems r
JF
2014/04/23 03:51:28
What are the issues? I assume something newlib+lib
Jim Stichnoth
2014/04/26 15:02:11
It looks like <cstdint> is C++11, at least accordi
JF
2014/04/26 20:20:56
Hah, I did not know that.
|
| + |
| +#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" |
| + |
|
JF
2014/04/16 01:27:32
It would be nicer to put everything in a namespace
Jim Stichnoth
2014/04/21 20:26:40
Done. Used the "Ice" namespace. In some cases, I
|
| +class IceCfg; |
| +class IceCfgNode; |
| +class IceConstant; |
| +class IceGlobalContext; |
| +class IceInst; |
| +class IceInstPhi; |
| +class IceInstTarget; |
| +class IceOperand; |
| +class IceVariable; |
| + |
| +// 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<IceInst *> IceInstList; |
| +typedef std::list<IceInstPhi *> IcePhiList; |
| +typedef std::vector<IceOperand *> IceOpList; |
| +typedef std::vector<IceVariable *> IceVarList; |
| +typedef std::vector<IceCfgNode *> IceNodeList; |
| + |
| +// This is a convenience templated class that provides a mapping |
| +// between a parameterized type and small unsigned integers. |
| +template <typename T> class IceValueTranslation { |
| +public: |
| + typedef typename std::map<const T, uint32_t> ContainerType; |
| + IceValueTranslation() {} |
|
JF
2014/04/16 01:27:32
dtor, copy ctor, assign?
Jim Stichnoth
2014/04/21 20:26:40
Done. No dtor for this simple wrapper class.
|
| + void clear() { Entries.clear(); } |
| + uint32_t translate(const T &Value) { |
| + typename ContainerType::const_iterator Iter = Entries.find(Value); |
| + if (Iter != Entries.end()) |
| + return Iter->second; |
| + uint32_t Index = Entries.size(); |
| + Entries[Value] = Index; |
| + return Index; |
| + } |
| + |
| +private: |
| + ContainerType Entries; |
| +}; |
| + |
| +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; |
|
JF
2014/04/16 01:27:32
Why typedef this to uint32_t instead of just using
Jim Stichnoth
2014/04/21 20:26:40
IceVerboseMask is a bitmask of IceVerbose values.
|
| + |
| +// 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; |
|
JF
2014/04/16 01:27:32
dtor, copy ctor, assign.
Jim Stichnoth
2014/04/21 20:26:40
Done. No dtor for this simple wrapper class.
|
| +}; |
| + |
| +template <typename T> |
| +inline IceOstream &operator<<(IceOstream &Str, const T &Val) { |
| + if (Str.Stream) |
| + (*Str.Stream) << Val; |
| + return Str; |
| +} |
| + |
| +class IceTimer { |
|
JF
2014/04/16 01:27:32
Can you put a TODO to use std::chrono when we sync
Jim Stichnoth
2014/04/21 20:26:40
Done.
|
| +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(IceGlobalContext *Ctx, const IceString &Tag) const; |
| + |
| +private: |
| + const llvm::TimeRecord Start; |
| +}; |
| + |
| +#endif // SUBZERO_SRC_ICEDEFS_H |