blob: 05580361d92dd6830c4506b3f2afd88cc39bb26d [file] [log] [blame]
Jim Stichnothf7c9a142014-04-29 10:52:43 -07001//===- subzero/src/IceTypes.h - Primitive ICE types -------------*- 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//===----------------------------------------------------------------------===//
Andrew Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Declares a few properties of the primitive types allowed in Subzero.
12/// Every Subzero source file is expected to include IceTypes.h.
Andrew Scull9612d322015-07-06 14:53:25 -070013///
Jim Stichnothf7c9a142014-04-29 10:52:43 -070014//===----------------------------------------------------------------------===//
15
16#ifndef SUBZERO_SRC_ICETYPES_H
17#define SUBZERO_SRC_ICETYPES_H
18
John Porto67f8de92015-06-25 10:14:17 -070019#include "IceDefs.h"
Jim Stichnothf7c9a142014-04-29 10:52:43 -070020#include "IceTypes.def"
21
22namespace Ice {
23
24enum Type {
Jim Stichnoth2544d4d2016-01-22 13:07:46 -080025#define X(tag, sizeLog2, align, elts, elty, str, rcstr) IceType_##tag,
Jim Stichnothf7c9a142014-04-29 10:52:43 -070026 ICETYPE_TABLE
27#undef X
Jim Stichnoth4376d292014-05-23 13:39:02 -070028 IceType_NUM
Jim Stichnothf7c9a142014-04-29 10:52:43 -070029};
30
Jim Stichnoth2544d4d2016-01-22 13:07:46 -080031/// RegClass indicates the physical register class that a Variable may be
32/// register-allocated from. By default, a variable's register class is
33/// directly associated with its type. However, the target lowering may define
34/// additional target-specific register classes by extending the set of enum
35/// values.
36enum RegClass : uint8_t {
37// Define RC_void, RC_i1, RC_i8, etc.
38#define X(tag, sizeLog2, align, elts, elty, str, rcstr) \
39 RC_##tag = IceType_##tag,
40 ICETYPE_TABLE
41#undef X
42 RC_Target,
43 // Leave plenty of space for target-specific values.
44 RC_Max = std::numeric_limits<uint8_t>::max()
45};
46static_assert(RC_Target == static_cast<RegClass>(IceType_NUM),
47 "Expected RC_Target and IceType_NUM to be the same");
48
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070049enum TargetArch {
Jan Voung08c3bcd2014-12-01 17:55:16 -080050#define X(tag, str, is_elf64, e_machine, e_flags) tag,
Karl Schimpfb262c5e2014-10-27 14:41:57 -070051 TARGETARCH_TABLE
52#undef X
Jim Stichnoth336f6c42014-10-30 15:01:31 -070053 TargetArch_NUM
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070054};
55
Karl Schimpfb262c5e2014-10-27 14:41:57 -070056const char *targetArchString(TargetArch Arch);
57
58inline Ostream &operator<<(Ostream &Stream, TargetArch Arch) {
59 return Stream << targetArchString(Arch);
60}
61
Andrew Scull57e12682015-09-16 11:30:19 -070062/// The list of all target instruction sets. Individual targets will map this to
63/// include only what is valid for the target.
Jan Voung1f47ad02015-03-20 15:01:26 -070064enum TargetInstructionSet {
Jan Voungd062f732015-06-15 17:17:31 -070065 // Represents baseline that can be assumed for a target (usually "Begin").
66 BaseInstructionSet,
Jan Voung1f47ad02015-03-20 15:01:26 -070067 X86InstructionSet_Begin,
Jan Voung1f47ad02015-03-20 15:01:26 -070068 X86InstructionSet_SSE2 = X86InstructionSet_Begin,
69 X86InstructionSet_SSE4_1,
70 X86InstructionSet_End,
Jan Voungd062f732015-06-15 17:17:31 -070071 ARM32InstructionSet_Begin,
72 ARM32InstructionSet_Neon = ARM32InstructionSet_Begin,
73 ARM32InstructionSet_HWDivArm,
74 ARM32InstructionSet_End,
Jan Voung1f47ad02015-03-20 15:01:26 -070075};
76
Jim Stichnothdd842db2015-01-27 12:53:53 -080077enum OptLevel { Opt_m1, Opt_0, Opt_1, Opt_2 };
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070078
Jim Stichnothf7c9a142014-04-29 10:52:43 -070079size_t typeWidthInBytes(Type Ty);
Andrew Scull87f80c12015-07-20 10:19:16 -070080int8_t typeWidthInBytesLog2(Type Ty);
Jim Stichnothf7c9a142014-04-29 10:52:43 -070081size_t typeAlignInBytes(Type Ty);
Matt Wala928f1292014-07-07 16:50:46 -070082size_t typeNumElements(Type Ty);
83Type typeElementType(Type Ty);
Jim Stichnoth78282f62014-07-27 23:14:00 -070084const char *typeString(Type Ty);
Jim Stichnoth467ffe52016-03-29 15:01:06 -070085inline std::string typeStdString(Type Ty) { return typeString(Ty); }
Jim Stichnoth2544d4d2016-01-22 13:07:46 -080086const char *regClassString(RegClass C);
Matt Wala928f1292014-07-07 16:50:46 -070087
Nicolas Capens32f9cce2016-10-19 01:24:27 -040088Type getPointerType();
Karl Schimpf4019f082014-12-15 13:45:00 -080089
Karl Schimpfd6064a12014-08-27 15:34:58 -070090bool isVectorType(Type Ty);
91
Nicolas Capense9655302017-02-13 10:21:20 -050092bool isBooleanType(Type Ty); // scalar or vector
Karl Schimpfd6064a12014-08-27 15:34:58 -070093bool isIntegerType(Type Ty); // scalar or vector
94bool isScalarIntegerType(Type Ty);
95bool isVectorIntegerType(Type Ty);
96bool isIntegerArithmeticType(Type Ty);
97
98bool isFloatingType(Type Ty); // scalar or vector
99bool isScalarFloatingType(Type Ty);
100bool isVectorFloatingType(Type Ty);
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700101
Karl Schimpf41689df2014-09-10 14:36:07 -0700102/// Returns true if the given type can be used in a load instruction.
103bool isLoadStoreType(Type Ty);
104
Karl Schimpfff94f592015-09-18 10:37:44 -0700105/// Returns true if the given type can be used as a parameter type in a call.
106bool isCallParameterType(Type Ty);
107
108/// Returns true if the given type can be used as the return type of a call.
109inline bool isCallReturnType(Type Ty) {
110 return Ty == IceType_void || isCallParameterType(Ty);
111}
112
Karl Schimpf83f9f0c2014-09-05 08:30:55 -0700113/// Returns type generated by applying the compare instructions (icmp and fcmp)
114/// to arguments of the given type. Returns IceType_void if compare is not
115/// allowed.
116Type getCompareResultType(Type Ty);
117
Karl Schimpfd1a971a2014-09-17 15:38:17 -0700118/// Returns the number of bits in a scalar integer type.
119SizeT getScalarIntBitWidth(Type Ty);
120
Andrew Scull9612d322015-07-06 14:53:25 -0700121/// Check if a type is byte sized (slight optimization over typeWidthInBytes).
Jan Voung3a569182014-09-29 10:16:01 -0700122inline bool isByteSizedType(Type Ty) {
123 bool result = Ty == IceType_i8 || Ty == IceType_i1;
124 assert(result == (1 == typeWidthInBytes(Ty)));
125 return result;
126}
127
Andrew Scull57e12682015-09-16 11:30:19 -0700128/// Check if Ty is byte sized and specifically i8. Assert that it's not byte
129/// sized due to being an i1.
Jan Voung3a569182014-09-29 10:16:01 -0700130inline bool isByteSizedArithType(Type Ty) {
131 assert(Ty != IceType_i1);
132 return Ty == IceType_i8;
133}
134
Andrew Scull9612d322015-07-06 14:53:25 -0700135/// Return true if Ty is i32. This asserts that Ty is either i32 or i64.
Jan Voung3a569182014-09-29 10:16:01 -0700136inline bool isInt32Asserting32Or64(Type Ty) {
137 bool result = Ty == IceType_i32;
138 assert(result || Ty == IceType_i64);
139 return result;
140}
141
Andrew Scull9612d322015-07-06 14:53:25 -0700142/// Return true if Ty is f32. This asserts that Ty is either f32 or f64.
Jan Voung3a569182014-09-29 10:16:01 -0700143inline bool isFloat32Asserting32Or64(Type Ty) {
144 bool result = Ty == IceType_f32;
145 assert(result || Ty == IceType_f64);
146 return result;
147}
148
Jim Stichnoth78282f62014-07-27 23:14:00 -0700149template <typename StreamType>
150inline StreamType &operator<<(StreamType &Str, const Type &Ty) {
151 Str << typeString(Ty);
152 return Str;
153}
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700154
Karl Schimpf645aa1a2014-10-08 09:05:53 -0700155/// Models a type signature for a function.
Karl Schimpf645aa1a2014-10-08 09:05:53 -0700156class FuncSigType {
Karl Schimpf645aa1a2014-10-08 09:05:53 -0700157 FuncSigType &operator=(const FuncSigType &Ty) = delete;
Jim Stichnothdd842db2015-01-27 12:53:53 -0800158
Karl Schimpf645aa1a2014-10-08 09:05:53 -0700159public:
Andrew Scull8072bae2015-09-14 16:01:26 -0700160 using ArgListType = std::vector<Type>;
Karl Schimpf645aa1a2014-10-08 09:05:53 -0700161
Andrew Scull57e12682015-09-16 11:30:19 -0700162 /// Creates a function signature type with the given return type. Parameter
163 /// types should be added using calls to appendArgType.
Jim Stichnotheafb56c2015-06-22 10:35:22 -0700164 FuncSigType() = default;
Jim Stichnoth7e571362015-01-09 11:43:26 -0800165 FuncSigType(const FuncSigType &Ty) = default;
Karl Schimpf645aa1a2014-10-08 09:05:53 -0700166
167 void appendArgType(Type ArgType) { ArgList.push_back(ArgType); }
168
169 Type getReturnType() const { return ReturnType; }
170 void setReturnType(Type NewType) { ReturnType = NewType; }
171 SizeT getNumArgs() const { return ArgList.size(); }
172 Type getArgType(SizeT Index) const {
173 assert(Index < ArgList.size());
174 return ArgList[Index];
175 }
176 const ArgListType &getArgList() const { return ArgList; }
177 void dump(Ostream &Stream) const;
178
179private:
Andrew Scull9612d322015-07-06 14:53:25 -0700180 /// The return type.
Jim Stichnotheafb56c2015-06-22 10:35:22 -0700181 Type ReturnType = IceType_void;
Andrew Scull9612d322015-07-06 14:53:25 -0700182 /// The list of parameters.
Karl Schimpf645aa1a2014-10-08 09:05:53 -0700183 ArgListType ArgList;
184};
185
186inline Ostream &operator<<(Ostream &Stream, const FuncSigType &Sig) {
187 Sig.dump(Stream);
188 return Stream;
189}
190
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700191} // end of namespace Ice
192
193#endif // SUBZERO_SRC_ICETYPES_H