llvm.org GIT mirror llvm / d6b7d70
fix documentation comments; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271584 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 4 years ago
2 changed file(s) with 68 addition(s) and 114 deletion(s). Raw diff Collapse all Expand all
7575 };
7676
7777 private:
78 /// Context - This refers to the LLVMContext in which this type was uniqued.
78 /// This refers to the LLVMContext in which this type was uniqued.
7979 LLVMContext &Context;
8080
8181 TypeID ID : 8; // The current base type of this type.
9696 assert(getSubclassData() == val && "Subclass data too large for field");
9797 }
9898
99 /// NumContainedTys - Keeps track of how many Type*'s there are in the
100 /// ContainedTys list.
99 /// Keeps track of how many Type*'s there are in the ContainedTys list.
101100 unsigned NumContainedTys;
102101
103 /// ContainedTys - A pointer to the array of Types contained by this Type.
104 /// For example, this includes the arguments of a function type, the elements
105 /// of a structure, the pointee of a pointer, the element type of an array,
106 /// etc. This pointer may be 0 for types that don't contain other types
107 /// (Integer, Double, Float).
102 /// A pointer to the array of Types contained by this Type. For example, this
103 /// includes the arguments of a function type, the elements of a structure,
104 /// the pointee of a pointer, the element type of an array, etc. This pointer
105 /// may be 0 for types that don't contain other types (Integer, Double,
106 /// Float).
108107 Type * const *ContainedTys;
109108
110109 static bool isSequentialType(TypeID TyID) {
122121 bool NoDetails = false) const;
123122 void dump() const;
124123
125 /// getContext - Return the LLVMContext in which this type was uniqued.
124 /// Return the LLVMContext in which this type was uniqued.
126125 LLVMContext &getContext() const { return Context; }
127126
128127 //===--------------------------------------------------------------------===//
129128 // Accessors for working with types.
130129 //
131130
132 /// getTypeID - Return the type id for the type. This will return one
133 /// of the TypeID enum elements defined above.
134 ///
131 /// Return the type id for the type. This will return one of the TypeID enum
132 /// elements defined above.
135133 TypeID getTypeID() const { return ID; }
136134
137 /// isVoidTy - Return true if this is 'void'.
135 /// Return true if this is 'void'.
138136 bool isVoidTy() const { return getTypeID() == VoidTyID; }
139137
140 /// isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
138 /// Return true if this is 'half', a 16-bit IEEE fp type.
141139 bool isHalfTy() const { return getTypeID() == HalfTyID; }
142140
143 /// isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
141 /// Return true if this is 'float', a 32-bit IEEE fp type.
144142 bool isFloatTy() const { return getTypeID() == FloatTyID; }
145143
146 /// isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
144 /// Return true if this is 'double', a 64-bit IEEE fp type.
147145 bool isDoubleTy() const { return getTypeID() == DoubleTyID; }
148146
149 /// isX86_FP80Ty - Return true if this is x86 long double.
147 /// Return true if this is x86 long double.
150148 bool isX86_FP80Ty() const { return getTypeID() == X86_FP80TyID; }
151149
152 /// isFP128Ty - Return true if this is 'fp128'.
150 /// Return true if this is 'fp128'.
153151 bool isFP128Ty() const { return getTypeID() == FP128TyID; }
154152
155 /// isPPC_FP128Ty - Return true if this is powerpc long double.
153 /// Return true if this is powerpc long double.
156154 bool isPPC_FP128Ty() const { return getTypeID() == PPC_FP128TyID; }
157155
158 /// isFloatingPointTy - Return true if this is one of the six floating point
159 /// types
156 /// Return true if this is one of the six floating-point types
160157 bool isFloatingPointTy() const {
161158 return getTypeID() == HalfTyID || getTypeID() == FloatTyID ||
162159 getTypeID() == DoubleTyID ||
176173 }
177174 }
178175
179 /// isX86_MMXTy - Return true if this is X86 MMX.
176 /// Return true if this is X86 MMX.
180177 bool isX86_MMXTy() const { return getTypeID() == X86_MMXTyID; }
181178
182 /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP.
183 ///
179 /// Return true if this is a FP type or a vector of FP.
184180 bool isFPOrFPVectorTy() const { return getScalarType()->isFloatingPointTy(); }
185181
186 /// isLabelTy - Return true if this is 'label'.
182 /// Return true if this is 'label'.
187183 bool isLabelTy() const { return getTypeID() == LabelTyID; }
188184
189 /// isMetadataTy - Return true if this is 'metadata'.
185 /// Return true if this is 'metadata'.
190186 bool isMetadataTy() const { return getTypeID() == MetadataTyID; }
191187
192 /// isTokenTy - Return true if this is 'token'.
188 /// Return true if this is 'token'.
193189 bool isTokenTy() const { return getTypeID() == TokenTyID; }
194190
195 /// isIntegerTy - True if this is an instance of IntegerType.
196 ///
191 /// True if this is an instance of IntegerType.
197192 bool isIntegerTy() const { return getTypeID() == IntegerTyID; }
198193
199 /// isIntegerTy - Return true if this is an IntegerType of the given width.
194 /// Return true if this is an IntegerType of the given width.
200195 bool isIntegerTy(unsigned Bitwidth) const;
201196
202 /// isIntOrIntVectorTy - Return true if this is an integer type or a vector of
203 /// integer types.
204 ///
197 /// Return true if this is an integer type or a vector of integer types.
205198 bool isIntOrIntVectorTy() const { return getScalarType()->isIntegerTy(); }
206199
207 /// isFunctionTy - True if this is an instance of FunctionType.
208 ///
200 /// True if this is an instance of FunctionType.
209201 bool isFunctionTy() const { return getTypeID() == FunctionTyID; }
210202
211 /// isStructTy - True if this is an instance of StructType.
212 ///
203 /// True if this is an instance of StructType.
213204 bool isStructTy() const { return getTypeID() == StructTyID; }
214205
215 /// isArrayTy - True if this is an instance of ArrayType.
216 ///
206 /// True if this is an instance of ArrayType.
217207 bool isArrayTy() const { return getTypeID() == ArrayTyID; }
218208
219 /// isPointerTy - True if this is an instance of PointerType.
220 ///
209 /// True if this is an instance of PointerType.
221210 bool isPointerTy() const { return getTypeID() == PointerTyID; }
222211
223 /// isPtrOrPtrVectorTy - Return true if this is a pointer type or a vector of
224 /// pointer types.
225 ///
212 /// Return true if this is a pointer type or a vector of pointer types.
226213 bool isPtrOrPtrVectorTy() const { return getScalarType()->isPointerTy(); }
227214
228 /// isVectorTy - True if this is an instance of VectorType.
229 ///
215 /// True if this is an instance of VectorType.
230216 bool isVectorTy() const { return getTypeID() == VectorTyID; }
231217
232 /// canLosslesslyBitCastTo - Return true if this type could be converted
233 /// with a lossless BitCast to type 'Ty'. For example, i8* to i32*. BitCasts
234 /// are valid for types of the same size only where no re-interpretation of
235 /// the bits is done.
218 /// Return true if this type could be converted with a lossless BitCast to
219 /// type 'Ty'. For example, i8* to i32*. BitCasts are valid for types of the
220 /// same size only where no re-interpretation of the bits is done.
236221 /// @brief Determine if this type could be losslessly bitcast to Ty
237222 bool canLosslesslyBitCastTo(Type *Ty) const;
238223
239 /// isEmptyTy - Return true if this type is empty, that is, it has no
240 /// elements or all its elements are empty.
224 /// Return true if this type is empty, that is, it has no elements or all of
225 /// its elements are empty.
241226 bool isEmptyTy() const;
242227
243 /// isFirstClassType - Return true if the type is "first class", meaning it
244 /// is a valid type for a Value.
245 ///
228 /// Return true if the type is "first class", meaning it is a valid type for a
229 /// Value.
246230 bool isFirstClassType() const {
247231 return getTypeID() != FunctionTyID && getTypeID() != VoidTyID;
248232 }
249233
250 /// isSingleValueType - Return true if the type is a valid type for a
251 /// register in codegen. This includes all first-class types except struct
252 /// and array types.
253 ///
234 /// Return true if the type is a valid type for a register in codegen. This
235 /// includes all first-class types except struct and array types.
254236 bool isSingleValueType() const {
255237 return isFloatingPointTy() || isX86_MMXTy() || isIntegerTy() ||
256238 isPointerTy() || isVectorTy();
257239 }
258240
259 /// isAggregateType - Return true if the type is an aggregate type. This
260 /// means it is valid as the first operand of an insertvalue or
261 /// extractvalue instruction. This includes struct and array types, but
262 /// does not include vector types.
263 ///
241 /// Return true if the type is an aggregate type. This means it is valid as
242 /// the first operand of an insertvalue or extractvalue instruction. This
243 /// includes struct and array types, but does not include vector types.
264244 bool isAggregateType() const {
265245 return getTypeID() == StructTyID || getTypeID() == ArrayTyID;
266246 }
267247
268 /// isSized - Return true if it makes sense to take the size of this type. To
269 /// get the actual size for a particular target, it is reasonable to use the
248 /// Return true if it makes sense to take the size of this type. To get the
249 /// actual size for a particular target, it is reasonable to use the
270250 /// DataLayout subsystem to do this.
271 ///
272251 bool isSized(SmallPtrSetImpl *Visited = nullptr) const {
273252 // If it's a primitive, it is always sized.
274253 if (getTypeID() == IntegerTyID || isFloatingPointTy() ||
284263 return isSizedDerivedType(Visited);
285264 }
286265
287 /// getPrimitiveSizeInBits - Return the basic size of this type if it is a
288 /// primitive type. These are fixed by LLVM and are not target dependent.
266 /// Return the basic size of this type if it is a primitive type. These are
267 /// fixed by LLVM and are not target-dependent.
289268 /// This will return zero if the type does not have a size or is not a
290269 /// primitive type.
291270 ///
296275 ///
297276 unsigned getPrimitiveSizeInBits() const LLVM_READONLY;
298277
299 /// getScalarSizeInBits - If this is a vector type, return the
300 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
301 /// getPrimitiveSizeInBits value for this type.
278 /// If this is a vector type, return the getPrimitiveSizeInBits value for the
279 /// element type. Otherwise return the getPrimitiveSizeInBits value for this
280 /// type.
302281 unsigned getScalarSizeInBits() const LLVM_READONLY;
303282
304 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
305 /// is only valid on floating point types. If the FP type does not
306 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
283 /// Return the width of the mantissa of this type. This is only valid on
284 /// floating-point types. If the FP type does not have a stable mantissa (e.g.
285 /// ppc long double), this method returns -1.
307286 int getFPMantissaWidth() const;
308287
309 /// getScalarType - If this is a vector type, return the element type,
310 /// otherwise return 'this'.
288 /// If this is a vector type, return the element type, otherwise return
289 /// 'this'.
311290 Type *getScalarType() const LLVM_READONLY;
312291
313292 //===--------------------------------------------------------------------===//
328307 return subtype_reverse_iterator(subtype_begin());
329308 }
330309
331 /// getContainedType - This method is used to implement the type iterator
332 /// (defined at the end of the file). For derived types, this returns the
333 /// types 'contained' in the derived type.
334 ///
310 /// This method is used to implement the type iterator (defined at the end of
311 /// the file). For derived types, this returns the types 'contained' in the
312 /// derived type.
335313 Type *getContainedType(unsigned i) const {
336314 assert(i < NumContainedTys && "Index out of range!");
337315 return ContainedTys[i];
338316 }
339317
340 /// getNumContainedTypes - Return the number of types in the derived type.
341 ///
318 /// Return the number of types in the derived type.
342319 unsigned getNumContainedTypes() const { return NumContainedTys; }
343320
344321 //===--------------------------------------------------------------------===//
371348
372349 Type *getPointerElementType() const { return getSequentialElementType(); }
373350
374 /// \brief Get the address space of this pointer or pointer vector type.
351 /// Get the address space of this pointer or pointer vector type.
375352 inline unsigned getPointerAddressSpace() const;
376353
377354 //===--------------------------------------------------------------------===//
379356 // instances of Type.
380357 //
381358
382 /// getPrimitiveType - Return a type based on an identifier.
359 /// Return a type based on an identifier.
383360 static Type *getPrimitiveType(LLVMContext &C, TypeID IDNumber);
384361
385362 //===--------------------------------------------------------------------===//
422399 static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
423400 static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
424401
425 /// getPointerTo - Return a pointer to the current type. This is equivalent
426 /// to PointerType::get(Foo, AddrSpace).
402 /// Return a pointer to the current type. This is equivalent to
403 /// PointerType::get(Foo, AddrSpace).
427404 PointerType *getPointerTo(unsigned AddrSpace = 0) const;
428405
429406 private:
430 /// isSizedDerivedType - Derived types like structures and arrays are sized
431 /// iff all of the members of the type are sized as well. Since asking for
432 /// their size is relatively uncommon, move this operation out of line.
407 /// Derived types like structures and arrays are sized iff all of the members
408 /// of the type are sized as well. Since asking for their size is relatively
409 /// uncommon, move this operation out-of-line.
433410 bool isSizedDerivedType(SmallPtrSetImpl *Visited = nullptr) const;
434411 };
435412
4040 }
4141 }
4242
43 /// getScalarType - If this is a vector type, return the element type,
44 /// otherwise return this.
4543 Type *Type::getScalarType() const {
4644 if (auto *VTy = dyn_cast(this))
4745 return VTy->getElementType();
4846 return const_cast(this);
4947 }
5048
51 /// isIntegerTy - Return true if this is an IntegerType of the specified width.
5249 bool Type::isIntegerTy(unsigned Bitwidth) const {
5350 return isIntegerTy() && cast(this)->getBitWidth() == Bitwidth;
5451 }
5552
56 // canLosslesslyBitCastTo - Return true if this type can be converted to
57 // 'Ty' without any reinterpretation of bits. For example, i8* to i32*.
58 //
5953 bool Type::canLosslesslyBitCastTo(Type *Ty) const {
6054 // Identity cast means no change so return true
6155 if (this == Ty)
125119 }
126120 }
127121
128 /// getScalarSizeInBits - If this is a vector type, return the
129 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
130 /// getPrimitiveSizeInBits value for this type.
131122 unsigned Type::getScalarSizeInBits() const {
132123 return getScalarType()->getPrimitiveSizeInBits();
133124 }
134125
135 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
136 /// is only valid on floating point types. If the FP type does not
137 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
138126 int Type::getFPMantissaWidth() const {
139127 if (auto *VTy = dyn_cast(this))
140128 return VTy->getElementType()->getFPMantissaWidth();
148136 return -1;
149137 }
150138
151 /// isSizedDerivedType - Derived types like structures and arrays are sized
152 /// iff all of the members of the type are sized as well. Since asking for
153 /// their size is relatively uncommon, move this operation out of line.
154139 bool Type::isSizedDerivedType(SmallPtrSetImpl *Visited) const {
155140 if (auto *ATy = dyn_cast(this))
156141 return ATy->getElementType()->isSized(Visited);
301286 NumContainedTys = Params.size() + 1; // + 1 for result type
302287 }
303288
304 // FunctionType::get - The factory function for the FunctionType class.
289 // This is the factory function for the FunctionType class.
305290 FunctionType *FunctionType::get(Type *ReturnType,
306291 ArrayRef Params, bool isVarArg) {
307292 LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
326311 return get(Result, None, isVarArg);
327312 }
328313
329 /// isValidReturnType - Return true if the specified type is valid as a return
330 /// type.
331314 bool FunctionType::isValidReturnType(Type *RetTy) {
332315 return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
333316 !RetTy->isMetadataTy();
334317 }
335318
336 /// isValidArgumentType - Return true if the specified type is valid as an
337 /// argument type.
338319 bool FunctionType::isValidArgumentType(Type *ArgTy) {
339320 return ArgTy->isFirstClassType();
340321 }
551532 !ElemTy->isTokenTy();
552533 }
553534
554 /// isLayoutIdentical - Return true if this is layout identical to the
555 /// specified struct.
556535 bool StructType::isLayoutIdentical(StructType *Other) const {
557536 if (this == Other) return true;
558537
562541 return elements() == Other->elements();
563542 }
564543
565 /// getTypeByName - Return the type with the specified name, or null if there
566 /// is none by that name.
567544 StructType *Module::getTypeByName(StringRef Name) const {
568545 return getContext().pImpl->NamedStructTypes.lookup(Name);
569546 }