Intrinsics.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //===-- llvm/Instrinsics.h - LLVM Intrinsic Function Handling ---*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  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 defines a set of enums which allow processing of intrinsic
  11. // functions. Values of these enum types are returned by
  12. // Function::getIntrinsicID.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_IR_INTRINSICS_H
  16. #define LLVM_IR_INTRINSICS_H
  17. #include "llvm/ADT/ArrayRef.h"
  18. #include <string>
  19. namespace llvm {
  20. class Type;
  21. class FunctionType;
  22. class Function;
  23. class LLVMContext;
  24. class Module;
  25. class AttributeSet;
  26. /// This namespace contains an enum with a value for every intrinsic/builtin
  27. /// function known by LLVM. The enum values are returned by
  28. /// Function::getIntrinsicID().
  29. namespace Intrinsic {
  30. enum ID : unsigned {
  31. not_intrinsic = 0, // Must be zero
  32. // Get the intrinsic enums generated from Intrinsics.td
  33. #define GET_INTRINSIC_ENUM_VALUES
  34. #include "llvm/IR/Intrinsics.gen"
  35. #undef GET_INTRINSIC_ENUM_VALUES
  36. , num_intrinsics
  37. };
  38. /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
  39. std::string getName(ID id, ArrayRef<Type*> Tys = None);
  40. /// Return the function type for an intrinsic.
  41. FunctionType *getType(LLVMContext &Context, ID id,
  42. ArrayRef<Type*> Tys = None);
  43. /// Returns true if the intrinsic can be overloaded.
  44. bool isOverloaded(ID id);
  45. /// Returns true if the intrinsic is a leaf, i.e. it does not make any calls
  46. /// itself. Most intrinsics are leafs, the exceptions being the patchpoint
  47. /// and statepoint intrinsics. These call (or invoke) their "target" argument.
  48. bool isLeaf(ID id);
  49. /// Return the attributes for an intrinsic.
  50. AttributeSet getAttributes(LLVMContext &C, ID id);
  51. /// Create or insert an LLVM Function declaration for an intrinsic, and return
  52. /// it.
  53. ///
  54. /// The Tys parameter is for intrinsics with overloaded types (e.g., those
  55. /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
  56. /// intrinsic, Tys must provide exactly one type for each overloaded type in
  57. /// the intrinsic.
  58. Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys = None);
  59. /// Map a GCC builtin name to an intrinsic ID.
  60. ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName);
  61. /// Map a MS builtin name to an intrinsic ID.
  62. ID getIntrinsicForMSBuiltin(const char *Prefix, const char *BuiltinName);
  63. /// This is a type descriptor which explains the type requirements of an
  64. /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
  65. struct IITDescriptor {
  66. enum IITDescriptorKind {
  67. Void, VarArg, MMX, Metadata, Half, Float, Double,
  68. Integer, Vector, Pointer, Struct,
  69. Argument, ExtendArgument, TruncArgument, HalfVecArgument,
  70. SameVecWidthArgument, PtrToArgument, VecOfPtrsToElt
  71. } Kind;
  72. union {
  73. unsigned Integer_Width;
  74. unsigned Float_Width;
  75. unsigned Vector_Width;
  76. unsigned Pointer_AddressSpace;
  77. unsigned Struct_NumElements;
  78. unsigned Argument_Info;
  79. };
  80. enum ArgKind {
  81. AK_Any,
  82. AK_AnyInteger,
  83. AK_AnyFloat,
  84. AK_AnyVector,
  85. AK_AnyPointer
  86. };
  87. unsigned getArgumentNumber() const {
  88. assert(Kind == Argument || Kind == ExtendArgument ||
  89. Kind == TruncArgument || Kind == HalfVecArgument ||
  90. Kind == SameVecWidthArgument || Kind == PtrToArgument ||
  91. Kind == VecOfPtrsToElt);
  92. return Argument_Info >> 3;
  93. }
  94. ArgKind getArgumentKind() const {
  95. assert(Kind == Argument || Kind == ExtendArgument ||
  96. Kind == TruncArgument || Kind == HalfVecArgument ||
  97. Kind == SameVecWidthArgument || Kind == PtrToArgument ||
  98. Kind == VecOfPtrsToElt);
  99. return (ArgKind)(Argument_Info & 7);
  100. }
  101. static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
  102. IITDescriptor Result = { K, { Field } };
  103. return Result;
  104. }
  105. };
  106. /// Return the IIT table descriptor for the specified intrinsic into an array
  107. /// of IITDescriptors.
  108. void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl<IITDescriptor> &T);
  109. } // End Intrinsic namespace
  110. } // End llvm namespace
  111. #endif