Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: src/IceIntrinsics.h

Issue 577353003: Add call instructions to Subzero's bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceIntrinsics.h - List of Ice Intrinsics -----*- C++ -*-===// 1 //===- subzero/src/IceIntrinsics.h - List of Ice Intrinsics -----*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file declares the kinds of intrinsics supported by PNaCl. 10 // This file declares the kinds of intrinsics supported by PNaCl.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #ifndef SUBZERO_SRC_ICEINTRINSICS_H 14 #ifndef SUBZERO_SRC_ICEINTRINSICS_H
15 #define SUBZERO_SRC_ICEINTRINSICS_H 15 #define SUBZERO_SRC_ICEINTRINSICS_H
16 16
17 #include "IceDefs.h" 17 #include "IceDefs.h"
18 #include "IceTypes.h" 18 #include "IceTypes.h"
19 19
20 namespace Ice { 20 namespace Ice {
21 21
22 class InstCall;
23
22 static const size_t kMaxIntrinsicParameters = 6; 24 static const size_t kMaxIntrinsicParameters = 6;
23 25
24 class Intrinsics { 26 class Intrinsics {
25 public: 27 public:
26 Intrinsics(); 28 Intrinsics();
27 ~Intrinsics(); 29 ~Intrinsics();
28 30
29 // Some intrinsics allow overloading by type. This enum collapses all 31 // Some intrinsics allow overloading by type. This enum collapses all
30 // overloads into a single ID, but the type can still be recovered by the 32 // overloads into a single ID, but the type can still be recovered by the
31 // type of the intrinsic function call's return value and parameters. 33 // type of the intrinsic function call's return value and parameters.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Basic attributes related to each intrinsic, that are relevant to 103 // Basic attributes related to each intrinsic, that are relevant to
102 // code generation. Perhaps the attributes representation can be shared 104 // code generation. Perhaps the attributes representation can be shared
103 // with general function calls, but PNaCl currently strips all 105 // with general function calls, but PNaCl currently strips all
104 // attributes from functions. 106 // attributes from functions.
105 struct IntrinsicInfo { 107 struct IntrinsicInfo {
106 enum IntrinsicID ID : 30; 108 enum IntrinsicID ID : 30;
107 enum SideEffects HasSideEffects : 1; 109 enum SideEffects HasSideEffects : 1;
108 enum ReturnsTwice ReturnsTwice : 1; 110 enum ReturnsTwice ReturnsTwice : 1;
109 }; 111 };
110 112
113 // The types of validation values for FullIntrinsicInfo.validateCall.
114 enum ValidateCallValue {
115 IsValidCall, // Valid use of instrinsic call.
116 BadReturnType, // Return type invalid for intrinsic.
117 WrongNumOfArgs, // Wrong number of arguments for intrinsic.
118 WrongCallArgType, // Argument of wrong type.
119 };
120
111 // The complete set of information about an intrinsic. 121 // The complete set of information about an intrinsic.
112 struct FullIntrinsicInfo { 122 struct FullIntrinsicInfo {
113 struct IntrinsicInfo Info; // Information that CodeGen would care about. 123 struct IntrinsicInfo Info; // Information that CodeGen would care about.
114 124
115 // Sanity check during parsing. 125 // Sanity check during parsing.
116 Type Signature[kMaxIntrinsicParameters]; 126 Type Signature[kMaxIntrinsicParameters];
117 uint8_t NumTypes; 127 uint8_t NumTypes;
128
129 // Validates that type signature of call matches intrinsic.
130 // If WrongArgumentType is returned, ArgIndex is set to corresponding
131 // argument index.
132 ValidateCallValue validateCall(const Ice::InstCall *Call,
133 SizeT &ArgIndex) const;
134
135 // Validates that type signature of call matches intrinsic.
136 ValidateCallValue validateCall(const Ice::InstCall *Call) const {
137 SizeT ArgIndexIgnore;
138 return validateCall(Call, ArgIndexIgnore);
139 }
140
141 // Returns the return type of the intrinsic.
142 Type getReturnType() const {
143 assert(NumTypes > 1);
144 return Signature[0];
145 }
146
147 // Returns number of arguments expected.
148 SizeT getNumArgs() const {
149 assert(NumTypes > 1);
150 return NumTypes - 1;
151 }
152
153 // Returns type of Index-th argument.
154 Type getArgType(SizeT Index) const;
118 }; 155 };
119 156
120 // Find the information about a given intrinsic, based on function name. 157 // Find the information about a given intrinsic, based on function name.
121 // The function name is expected to have the common "llvm." prefix 158 // The function name is expected to have the common "llvm." prefix
122 // stripped. If found, returns a reference to a FullIntrinsicInfo entry 159 // stripped. If found, returns a reference to a FullIntrinsicInfo entry
123 // (valid for the lifetime of the map). Otherwise returns null. 160 // (valid for the lifetime of the map). Otherwise returns null.
124 const FullIntrinsicInfo *find(const IceString &Name) const; 161 const FullIntrinsicInfo *find(const IceString &Name) const;
125 162
126 private: 163 private:
127 // TODO(jvoung): May want to switch to something like LLVM's StringMap. 164 // TODO(jvoung): May want to switch to something like LLVM's StringMap.
128 typedef std::map<IceString, FullIntrinsicInfo> IntrinsicMap; 165 typedef std::map<IceString, FullIntrinsicInfo> IntrinsicMap;
129 IntrinsicMap map; 166 IntrinsicMap map;
130 167
131 Intrinsics(const Intrinsics &) LLVM_DELETED_FUNCTION; 168 Intrinsics(const Intrinsics &) LLVM_DELETED_FUNCTION;
132 Intrinsics &operator=(const Intrinsics &) LLVM_DELETED_FUNCTION; 169 Intrinsics &operator=(const Intrinsics &) LLVM_DELETED_FUNCTION;
133 }; 170 };
134 171
135 } // end of namespace Ice 172 } // end of namespace Ice
136 173
137 #endif // SUBZERO_SRC_ICEINTRINSICS_H 174 #endif // SUBZERO_SRC_ICEINTRINSICS_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698