blob: 9870716d7b27391530adede5fffd58c53e9b7abe [file] [log] [blame]
Jim Stichnothf7c9a142014-04-29 10:52:43 -07001//===- subzero/src/IceDefs.h - Common Subzero declaraions -------*- C++ -*-===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares various useful types and classes that have
11// widespread use across Subzero. Every Subzero source file is
12// expected to include IceDefs.h.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef SUBZERO_SRC_ICEDEFS_H
17#define SUBZERO_SRC_ICEDEFS_H
18
19#include <stdint.h> // TODO: <cstdint> with C++11
20
21#include <cassert>
22#include <cstdio> // snprintf
23#include <functional> // std::less
24#include <list>
25#include <map>
26#include <set>
27#include <string>
28#include <vector>
29
30#include "llvm/ADT/BitVector.h"
31#include "llvm/ADT/SmallBitVector.h"
32#include "llvm/ADT/STLExtras.h"
33#include "llvm/Support/Casting.h"
34#include "llvm/Support/Compiler.h" // LLVM_STATIC_ASSERT
35#include "llvm/Support/raw_ostream.h"
36#include "llvm/Support/Timer.h"
37
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070038// Roll our own static_assert<> in the absence of C++11. TODO: change
39// to static_assert<> with C++11.
40template <bool> struct staticAssert;
41template <> struct staticAssert<true> {}; // only true is defined
42#define STATIC_ASSERT(x) staticAssert<(x)>()
43
Jim Stichnothf7c9a142014-04-29 10:52:43 -070044namespace Ice {
45
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070046class Cfg;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070047class CfgNode;
48class Constant;
49class GlobalContext;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070050class Inst;
51class InstPhi;
52class InstTarget;
53class Operand;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070054class TargetLowering;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070055class Variable;
56
57// TODO: Switch over to LLVM's ADT container classes.
58// http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure-for-a-task
59typedef std::string IceString;
60typedef std::list<Inst *> InstList;
61typedef std::list<InstPhi *> PhiList;
62typedef std::vector<Variable *> VarList;
63typedef std::vector<CfgNode *> NodeList;
Jim Stichnothf61d5b22014-05-23 13:31:24 -070064typedef std::vector<Constant *> ConstantList;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070065
66// SizeT is for holding small-ish limits like number of source
67// operands in an instruction. It is used instead of size_t (which
68// may be 64-bits wide) when we want to save space.
69typedef uint32_t SizeT;
70
71enum VerboseItem {
72 IceV_None = 0,
73 IceV_Instructions = 1 << 0,
74 IceV_Deleted = 1 << 1,
75 IceV_InstNumbers = 1 << 2,
76 IceV_Preds = 1 << 3,
77 IceV_Succs = 1 << 4,
78 IceV_Liveness = 1 << 5,
79 IceV_RegManager = 1 << 6,
80 IceV_RegOrigins = 1 << 7,
81 IceV_LinearScan = 1 << 8,
82 IceV_Frame = 1 << 9,
83 IceV_Timing = 1 << 10,
84 IceV_All = ~IceV_None
85};
86typedef uint32_t VerboseMask;
87
88// The Ostream class wraps an output stream and a Cfg pointer, so
89// that dump routines have access to the Cfg object and can print
90// labels and variable names.
91
92class Ostream {
93public:
94 Ostream(llvm::raw_ostream *Stream) : Stream(Stream) {}
95
96 llvm::raw_ostream *Stream;
97
98private:
99 Ostream(const Ostream &) LLVM_DELETED_FUNCTION;
100 Ostream &operator=(const Ostream &) LLVM_DELETED_FUNCTION;
101};
102
103template <typename T> inline Ostream &operator<<(Ostream &Str, const T &Val) {
104 if (Str.Stream)
105 (*Str.Stream) << Val;
106 return Str;
107}
108
109// TODO: Implement in terms of std::chrono after switching to C++11.
110class Timer {
111public:
112 Timer() : Start(llvm::TimeRecord::getCurrentTime(false)) {}
113 uint64_t getElapsedNs() const { return getElapsedSec() * 1000 * 1000 * 1000; }
114 uint64_t getElapsedUs() const { return getElapsedSec() * 1000 * 1000; }
115 uint64_t getElapsedMs() const { return getElapsedSec() * 1000; }
116 double getElapsedSec() const {
117 llvm::TimeRecord End = llvm::TimeRecord::getCurrentTime(false);
118 return End.getWallTime() - Start.getWallTime();
119 }
120 void printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const;
121
122private:
123 const llvm::TimeRecord Start;
124 Timer(const Timer &) LLVM_DELETED_FUNCTION;
125 Timer &operator=(const Timer &) LLVM_DELETED_FUNCTION;
126};
127
128} // end of namespace Ice
129
130#endif // SUBZERO_SRC_ICEDEFS_H