• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_SEM_INTRINSIC_H_
16 #define SRC_SEM_INTRINSIC_H_
17 
18 #include <string>
19 #include <vector>
20 
21 #include "src/sem/call_target.h"
22 #include "src/sem/intrinsic_type.h"
23 #include "src/sem/pipeline_stage_set.h"
24 #include "src/utils/hash.h"
25 
26 namespace tint {
27 namespace sem {
28 
29 /// Determines if the given `i` is a coarse derivative
30 /// @param i the intrinsic type
31 /// @returns true if the given derivative is coarse.
32 bool IsCoarseDerivativeIntrinsic(IntrinsicType i);
33 
34 /// Determines if the given `i` is a fine derivative
35 /// @param i the intrinsic type
36 /// @returns true if the given derivative is fine.
37 bool IsFineDerivativeIntrinsic(IntrinsicType i);
38 
39 /// Determine if the given `i` is a derivative intrinsic
40 /// @param i the intrinsic type
41 /// @returns true if the given `i` is a derivative intrinsic
42 bool IsDerivativeIntrinsic(IntrinsicType i);
43 
44 /// Determines if the given `i` is a float classification intrinsic
45 /// @param i the intrinsic type
46 /// @returns true if the given `i` is a float intrinsic
47 bool IsFloatClassificationIntrinsic(IntrinsicType i);
48 
49 /// Determines if the given `i` is a texture operation intrinsic
50 /// @param i the intrinsic type
51 /// @returns true if the given `i` is a texture operation intrinsic
52 bool IsTextureIntrinsic(IntrinsicType i);
53 
54 /// Determines if the given `i` is a image query intrinsic
55 /// @param i the intrinsic type
56 /// @returns true if the given `i` is a image query intrinsic
57 bool IsImageQueryIntrinsic(IntrinsicType i);
58 
59 /// Determines if the given `i` is a data packing intrinsic
60 /// @param i the intrinsic
61 /// @returns true if the given `i` is a data packing intrinsic
62 bool IsDataPackingIntrinsic(IntrinsicType i);
63 
64 /// Determines if the given `i` is a data unpacking intrinsic
65 /// @param i the intrinsic
66 /// @returns true if the given `i` is a data unpacking intrinsic
67 bool IsDataUnpackingIntrinsic(IntrinsicType i);
68 
69 /// Determines if the given `i` is a barrier intrinsic
70 /// @param i the intrinsic
71 /// @returns true if the given `i` is a barrier intrinsic
72 bool IsBarrierIntrinsic(IntrinsicType i);
73 
74 /// Determines if the given `i` is a atomic intrinsic
75 /// @param i the intrinsic
76 /// @returns true if the given `i` is a atomic intrinsic
77 bool IsAtomicIntrinsic(IntrinsicType i);
78 
79 /// Intrinsic holds the semantic information for an intrinsic function.
80 class Intrinsic : public Castable<Intrinsic, CallTarget> {
81  public:
82   /// Constructor
83   /// @param type the intrinsic type
84   /// @param return_type the return type for the intrinsic call
85   /// @param parameters the parameters for the intrinsic overload
86   /// @param supported_stages the pipeline stages that this intrinsic can be
87   /// used in
88   /// @param is_deprecated true if the particular overload is considered
89   /// deprecated
90   Intrinsic(IntrinsicType type,
91             const sem::Type* return_type,
92             std::vector<Parameter*> parameters,
93             PipelineStageSet supported_stages,
94             bool is_deprecated);
95 
96   /// Destructor
97   ~Intrinsic() override;
98 
99   /// @return the type of the intrinsic
Type()100   IntrinsicType Type() const { return type_; }
101 
102   /// @return the pipeline stages that this intrinsic can be used in
SupportedStages()103   PipelineStageSet SupportedStages() const { return supported_stages_; }
104 
105   /// @return true if the intrinsic overload is considered deprecated
IsDeprecated()106   bool IsDeprecated() const { return is_deprecated_; }
107 
108   /// @returns the name of the intrinsic function type. The spelling, including
109   /// case, matches the name in the WGSL spec.
110   const char* str() const;
111 
112   /// @returns true if intrinsic is a coarse derivative intrinsic
113   bool IsCoarseDerivative() const;
114 
115   /// @returns true if intrinsic is a fine a derivative intrinsic
116   bool IsFineDerivative() const;
117 
118   /// @returns true if intrinsic is a derivative intrinsic
119   bool IsDerivative() const;
120 
121   /// @returns true if intrinsic is a float intrinsic
122   bool IsFloatClassification() const;
123 
124   /// @returns true if intrinsic is a texture operation intrinsic
125   bool IsTexture() const;
126 
127   /// @returns true if intrinsic is a image query intrinsic
128   bool IsImageQuery() const;
129 
130   /// @returns true if intrinsic is a data packing intrinsic
131   bool IsDataPacking() const;
132 
133   /// @returns true if intrinsic is a data unpacking intrinsic
134   bool IsDataUnpacking() const;
135 
136   /// @returns true if intrinsic is a barrier intrinsic
137   bool IsBarrier() const;
138 
139   /// @returns true if intrinsic is a atomic intrinsic
140   bool IsAtomic() const;
141 
142  private:
143   const IntrinsicType type_;
144   const PipelineStageSet supported_stages_;
145   const bool is_deprecated_;
146 };
147 
148 }  // namespace sem
149 }  // namespace tint
150 
151 namespace std {
152 
153 /// Custom std::hash specialization for tint::sem::Intrinsic
154 template <>
155 class hash<tint::sem::Intrinsic> {
156  public:
157   /// @param i the Intrinsic to create a hash for
158   /// @return the hash value
operator()159   inline std::size_t operator()(const tint::sem::Intrinsic& i) const {
160     return tint::utils::Hash(i.Type(), i.SupportedStages(), i.ReturnType(),
161                              i.Parameters(), i.IsDeprecated());
162   }
163 };
164 
165 }  // namespace std
166 
167 #endif  // SRC_SEM_INTRINSIC_H_
168