blob: 8aafbfd6c44a5502829f9fc0fd40a0d92e40ba4e [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
Jim Stichnothf7c9a142014-04-29 10:52:43 -070019#include <cassert>
Jim Stichnotha18cc9c2014-09-30 19:10:22 -070020#include <cstdint>
Jim Stichnothf7c9a142014-04-29 10:52:43 -070021#include <cstdio> // snprintf
22#include <functional> // std::less
Jan Voungbc004632014-09-16 15:09:10 -070023#include <limits>
Jim Stichnothf7c9a142014-04-29 10:52:43 -070024#include <list>
25#include <map>
Jim Stichnothf7c9a142014-04-29 10:52:43 -070026#include <string>
27#include <vector>
Jan Voungb17f61d2014-08-28 16:00:53 -070028#include "llvm/ADT/ArrayRef.h"
Jim Stichnothf7c9a142014-04-29 10:52:43 -070029#include "llvm/ADT/BitVector.h"
Jim Stichnoth607e9f02014-11-06 13:32:05 -080030#include "llvm/ADT/ilist.h"
31#include "llvm/ADT/ilist_node.h"
Jim Stichnothf7c9a142014-04-29 10:52:43 -070032#include "llvm/ADT/SmallBitVector.h"
Jim Stichnoth586d4c22014-12-05 16:43:08 -080033#include "llvm/ADT/SmallVector.h"
Jim Stichnothf7c9a142014-04-29 10:52:43 -070034#include "llvm/ADT/STLExtras.h"
Jim Stichnoth31c95592014-12-19 12:51:35 -080035#include "llvm/Support/Allocator.h"
Jim Stichnothf7c9a142014-04-29 10:52:43 -070036#include "llvm/Support/Casting.h"
Jan Voung08c3bcd2014-12-01 17:55:16 -080037#include "llvm/Support/ELF.h"
Jim Stichnothf7c9a142014-04-29 10:52:43 -070038#include "llvm/Support/raw_ostream.h"
Jim Stichnothf7c9a142014-04-29 10:52:43 -070039
40namespace Ice {
41
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070042class Cfg;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070043class CfgNode;
44class Constant;
Karl Schimpf9d98d792014-10-13 15:01:08 -070045class FunctionDeclaration;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070046class GlobalContext;
Karl Schimpf9d98d792014-10-13 15:01:08 -070047class GlobalDeclaration;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070048class Inst;
Jim Stichnoth336f6c42014-10-30 15:01:31 -070049class InstAssign;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070050class InstPhi;
51class InstTarget;
Jim Stichnothd97c7df2014-06-04 11:57:08 -070052class LiveRange;
53class Liveness;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070054class Operand;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070055class TargetLowering;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070056class Variable;
Karl Schimpf9d98d792014-10-13 15:01:08 -070057class VariableDeclaration;
Jim Stichnoth144cdce2014-09-22 16:02:59 -070058class VariablesMetadata;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070059
Jim Stichnoth31c95592014-12-19 12:51:35 -080060typedef llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 1024 * 1024>
61ArenaAllocator;
62
63ArenaAllocator *getCurrentCfgAllocator();
64
65template <typename T> struct CfgLocalAllocator {
66 using value_type = T;
67 CfgLocalAllocator() = default;
68 template <class U> CfgLocalAllocator(const CfgLocalAllocator<U> &) {}
69 T *allocate(std::size_t Num) {
70 return getCurrentCfgAllocator()->Allocate<T>(Num);
71 }
72 void deallocate(T *, std::size_t) {}
73};
74template <typename T, typename U>
75inline bool operator==(const CfgLocalAllocator<T> &,
76 const CfgLocalAllocator<U> &) {
77 return true;
78}
79template <typename T, typename U>
80inline bool operator!=(const CfgLocalAllocator<T> &,
81 const CfgLocalAllocator<U> &) {
82 return false;
83}
84
Jim Stichnothf7c9a142014-04-29 10:52:43 -070085typedef std::string IceString;
Jim Stichnoth607e9f02014-11-06 13:32:05 -080086typedef llvm::ilist<Inst> InstList;
Jim Stichnoth1502e592014-12-11 09:22:45 -080087// Ideally PhiList would be llvm::ilist<InstPhi>, and similar for
88// AssignList, but this runs into issues with SFINAE.
89typedef InstList PhiList;
90typedef InstList AssignList;
Jim Stichnoth31c95592014-12-19 12:51:35 -080091// VarList and NodeList are arena-allocated from the Cfg's allocator.
92typedef std::vector<Variable *, CfgLocalAllocator<Variable *>> VarList;
93typedef std::vector<CfgNode *, CfgLocalAllocator<CfgNode *>> NodeList;
Jim Stichnothf61d5b22014-05-23 13:31:24 -070094typedef std::vector<Constant *> ConstantList;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070095
96// SizeT is for holding small-ish limits like number of source
97// operands in an instruction. It is used instead of size_t (which
98// may be 64-bits wide) when we want to save space.
99typedef uint32_t SizeT;
100
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700101// InstNumberT is for holding an instruction number. Instruction
102// numbers are used for representing Variable live ranges.
103typedef int32_t InstNumberT;
104
Jim Stichnoth47752552014-10-13 17:15:08 -0700105// A LiveBeginEndMapEntry maps a Variable::Number value to an
106// Inst::Number value, giving the instruction number that begins or
107// ends a variable's live range.
108typedef std::pair<SizeT, InstNumberT> LiveBeginEndMapEntry;
Jim Stichnothc599e462015-01-08 16:56:49 -0800109typedef std::vector<LiveBeginEndMapEntry,
110 CfgLocalAllocator<LiveBeginEndMapEntry> > LiveBeginEndMap;
Jim Stichnoth47752552014-10-13 17:15:08 -0700111typedef llvm::BitVector LivenessBV;
112
Jim Stichnoth8363a062014-10-07 10:02:38 -0700113typedef uint32_t TimerStackIdT;
Jim Stichnothc4554d72014-09-30 16:49:38 -0700114typedef uint32_t TimerIdT;
115
Jan Voungfe14fb82014-10-13 15:56:32 -0700116// PNaCl is ILP32, so theoretically we should only need 32-bit offsets.
117typedef int32_t RelocOffsetT;
Jan Voungc0d965f2014-11-04 16:55:01 -0800118enum { RelocAddrSize = 4 };
Jan Voungfe14fb82014-10-13 15:56:32 -0700119
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700120enum LivenessMode {
121 // Basic version of live-range-end calculation. Marks the last uses
122 // of variables based on dataflow analysis. Records the set of
123 // live-in and live-out variables for each block. Identifies and
124 // deletes dead instructions (primarily stores).
125 Liveness_Basic,
126
127 // In addition to Liveness_Basic, also calculate the complete
128 // live range for each variable in a form suitable for interference
129 // calculation and register allocation.
130 Liveness_Intervals
131};
132
Jim Stichnoth70d0a052014-11-14 15:53:46 -0800133enum RegAllocKind {
134 RAK_Global, // full, global register allocation
135 RAK_InfOnly // allocation only for infinite-weight Variables
136};
137
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700138enum VerboseItem {
139 IceV_None = 0,
140 IceV_Instructions = 1 << 0,
141 IceV_Deleted = 1 << 1,
142 IceV_InstNumbers = 1 << 2,
143 IceV_Preds = 1 << 3,
144 IceV_Succs = 1 << 4,
145 IceV_Liveness = 1 << 5,
146 IceV_RegManager = 1 << 6,
147 IceV_RegOrigins = 1 << 7,
148 IceV_LinearScan = 1 << 8,
149 IceV_Frame = 1 << 9,
Jim Stichnothc4554d72014-09-30 16:49:38 -0700150 IceV_AddrOpt = 1 << 10,
Jim Stichnothe6d24782014-12-19 05:42:24 -0800151 IceV_Random = 1 << 11,
Jim Stichnothad403532014-09-25 12:44:17 -0700152 IceV_All = ~IceV_None,
Jim Stichnothc4554d72014-09-30 16:49:38 -0700153 IceV_Most = IceV_All & ~IceV_LinearScan
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700154};
155typedef uint32_t VerboseMask;
156
Jim Stichnoth78282f62014-07-27 23:14:00 -0700157typedef llvm::raw_ostream Ostream;
Jan Voung08c3bcd2014-12-01 17:55:16 -0800158typedef llvm::raw_fd_ostream Fdstream;
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700159
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700160} // end of namespace Ice
161
162#endif // SUBZERO_SRC_ICEDEFS_H