Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceIntrinsics.h - List of Ice Intrinsics -----*- 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 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the kinds of intrinsics supported by PNaCl. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef SUBZERO_SRC_ICEINTRINSICS_H |
| 15 | #define SUBZERO_SRC_ICEINTRINSICS_H |
| 16 | |
| 17 | #include "IceDefs.h" |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 18 | #include "IceTypes.h" |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 19 | |
| 20 | namespace Ice { |
| 21 | |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 22 | class InstCall; |
| 23 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 24 | static const size_t kMaxIntrinsicParameters = 6; |
| 25 | |
| 26 | class Intrinsics { |
| 27 | public: |
| 28 | Intrinsics(); |
| 29 | ~Intrinsics(); |
| 30 | |
| 31 | // Some intrinsics allow overloading by type. This enum collapses all |
| 32 | // overloads into a single ID, but the type can still be recovered by the |
| 33 | // type of the intrinsic function call's return value and parameters. |
| 34 | enum IntrinsicID { |
| 35 | UnknownIntrinsic = 0, |
| 36 | // Arbitrary (alphabetical) order. |
| 37 | AtomicCmpxchg, |
| 38 | AtomicFence, |
| 39 | AtomicFenceAll, |
| 40 | AtomicIsLockFree, |
| 41 | AtomicLoad, |
| 42 | AtomicRMW, |
| 43 | AtomicStore, |
| 44 | Bswap, |
| 45 | Ctlz, |
| 46 | Ctpop, |
| 47 | Cttz, |
| 48 | Longjmp, |
| 49 | Memcpy, |
| 50 | Memmove, |
| 51 | Memset, |
| 52 | NaClReadTP, |
| 53 | Setjmp, |
| 54 | Sqrt, |
| 55 | Stacksave, |
| 56 | Stackrestore, |
| 57 | Trap |
| 58 | }; |
| 59 | |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 60 | /// Operations that can be represented by the AtomicRMW |
| 61 | /// intrinsic. |
| 62 | /// |
| 63 | /// Do not reorder these values: their order offers forward |
| 64 | /// compatibility of bitcode targeted to PNaCl. |
| 65 | enum AtomicRMWOperation { |
| 66 | AtomicInvalid = 0, // Invalid, keep first. |
| 67 | AtomicAdd, |
| 68 | AtomicSub, |
| 69 | AtomicOr, |
| 70 | AtomicAnd, |
| 71 | AtomicXor, |
| 72 | AtomicExchange, |
| 73 | AtomicNum // Invalid, keep last. |
| 74 | }; |
| 75 | |
| 76 | /// Memory orderings supported by PNaCl IR. |
| 77 | /// |
| 78 | /// Do not reorder these values: their order offers forward |
| 79 | /// compatibility of bitcode targeted to PNaCl. |
| 80 | enum MemoryOrder { |
| 81 | MemoryOrderInvalid = 0, // Invalid, keep first. |
| 82 | MemoryOrderRelaxed, |
| 83 | MemoryOrderConsume, |
| 84 | MemoryOrderAcquire, |
| 85 | MemoryOrderRelease, |
| 86 | MemoryOrderAcquireRelease, |
| 87 | MemoryOrderSequentiallyConsistent, |
| 88 | MemoryOrderNum // Invalid, keep last. |
| 89 | }; |
| 90 | |
| 91 | static bool VerifyMemoryOrder(uint64_t Order); |
| 92 | |
Jan Voung | 44d53e1 | 2014-09-11 19:18:03 -0700 | [diff] [blame] | 93 | enum SideEffects { |
| 94 | SideEffects_F=0, |
| 95 | SideEffects_T=1 |
| 96 | }; |
| 97 | |
| 98 | enum ReturnsTwice { |
| 99 | ReturnsTwice_F=0, |
| 100 | ReturnsTwice_T=1 |
| 101 | }; |
| 102 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 103 | // Basic attributes related to each intrinsic, that are relevant to |
Jan Voung | 44d53e1 | 2014-09-11 19:18:03 -0700 | [diff] [blame] | 104 | // code generation. Perhaps the attributes representation can be shared |
| 105 | // with general function calls, but PNaCl currently strips all |
| 106 | // attributes from functions. |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 107 | struct IntrinsicInfo { |
Jan Voung | 44d53e1 | 2014-09-11 19:18:03 -0700 | [diff] [blame] | 108 | enum IntrinsicID ID : 30; |
| 109 | enum SideEffects HasSideEffects : 1; |
| 110 | enum ReturnsTwice ReturnsTwice : 1; |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 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 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 121 | // The complete set of information about an intrinsic. |
| 122 | struct FullIntrinsicInfo { |
| 123 | struct IntrinsicInfo Info; // Information that CodeGen would care about. |
| 124 | |
| 125 | // Sanity check during parsing. |
| 126 | Type Signature[kMaxIntrinsicParameters]; |
| 127 | uint8_t NumTypes; |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 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 | // Returns the return type of the intrinsic. |
| 136 | Type getReturnType() const { |
| 137 | assert(NumTypes > 1); |
| 138 | return Signature[0]; |
| 139 | } |
| 140 | |
| 141 | // Returns number of arguments expected. |
| 142 | SizeT getNumArgs() const { |
| 143 | assert(NumTypes > 1); |
| 144 | return NumTypes - 1; |
| 145 | } |
| 146 | |
| 147 | // Returns type of Index-th argument. |
| 148 | Type getArgType(SizeT Index) const; |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | // Find the information about a given intrinsic, based on function name. |
| 152 | // The function name is expected to have the common "llvm." prefix |
| 153 | // stripped. If found, returns a reference to a FullIntrinsicInfo entry |
| 154 | // (valid for the lifetime of the map). Otherwise returns null. |
| 155 | const FullIntrinsicInfo *find(const IceString &Name) const; |
| 156 | |
| 157 | private: |
| 158 | // TODO(jvoung): May want to switch to something like LLVM's StringMap. |
| 159 | typedef std::map<IceString, FullIntrinsicInfo> IntrinsicMap; |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 160 | IntrinsicMap Map; |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 161 | |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 162 | Intrinsics(const Intrinsics &) = delete; |
| 163 | Intrinsics &operator=(const Intrinsics &) = delete; |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | } // end of namespace Ice |
| 167 | |
| 168 | #endif // SUBZERO_SRC_ICEINTRINSICS_H |