Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===-- llvm/IR/NaClIntrinsics.h - NaCl Intrinsics --------------*- 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 describes intrinsic functions that are specific to NaCl. | |
|
Derek Schuff
2013/07/03 16:08:55
since these files are really only for atomic intri
JF
2013/07/03 21:28:12
Done in a single change.
| |
| 11 // | |
| 12 //===----------------------------------------------------------------------===// | |
| 13 | |
| 14 #ifndef LLVM_IR_NACL_H | |
| 15 #define LLVM_IR_NACL_H | |
| 16 | |
| 17 #include "llvm/IR/Intrinsics.h" | |
| 18 #include "llvm/Support/Compiler.h" | |
| 19 #include <cstddef> | |
| 20 | |
| 21 namespace llvm { | |
| 22 | |
| 23 namespace NaCl { | |
| 24 | |
| 25 static const size_t NumAtomicIntrinsics = 5; | |
| 26 static const size_t NumAtomicIntrinsicTypes = 4; | |
| 27 static const size_t MaxAtomicIntrinsicsParameters = 5; | |
| 28 | |
| 29 // Describe all the atomic intrinsics and their type signature. Most can | |
| 30 // be overloaded on a type. | |
| 31 class AtomicIntrinsics { | |
| 32 public: | |
| 33 enum ParamType { | |
| 34 NoP, // No parameter. | |
| 35 Int, // Overloaded. | |
| 36 Ptr, // Overloaded. | |
| 37 RMW, // Atomic RMW operation type. | |
| 38 Mem // Memory order. | |
| 39 }; | |
| 40 | |
| 41 struct AtomicIntrinsic { | |
| 42 Intrinsic::ID ID : 16; | |
| 43 uint8_t NumParams; | |
| 44 bool Overloaded; | |
| 45 Type *OverloadedType; | |
| 46 // Full function signature, excluding return type. | |
| 47 Type *Signature[MaxAtomicIntrinsicsParameters]; | |
| 48 uint8_t ParamType[MaxAtomicIntrinsicsParameters]; | |
| 49 | |
| 50 Type *Parameter(size_t P) const { return Signature[P]; } | |
| 51 Function *getDeclaration(Module *M) const { | |
| 52 return Intrinsic::getDeclaration( | |
| 53 M, ID, ArrayRef<Type *>(&OverloadedType, Overloaded ? 1 : 0)); | |
| 54 } | |
| 55 }; | |
| 56 | |
| 57 AtomicIntrinsics(LLVMContext &C); | |
| 58 ~AtomicIntrinsics() {} | |
| 59 | |
| 60 class const_iterator { | |
| 61 public: | |
| 62 const_iterator(const AtomicIntrinsic *I) : I(I) {} | |
| 63 ~const_iterator() {} | |
| 64 const_iterator(const const_iterator &rhs) : I(rhs.I) {} | |
| 65 const_iterator &operator=(const const_iterator &rhs) { | |
| 66 I = rhs.I; | |
| 67 return *this; | |
| 68 } | |
| 69 void operator++() { ++I; } | |
| 70 bool operator!=(const const_iterator &rhs) { return I != rhs.I; } | |
| 71 const AtomicIntrinsic *operator->() const { return I; } | |
| 72 | |
| 73 private: | |
| 74 const AtomicIntrinsic *I; | |
| 75 const_iterator() LLVM_DELETED_FUNCTION; | |
| 76 friend class AtomicIntrinsics; | |
| 77 }; | |
| 78 | |
| 79 // Iterator through all ID+Type overloads. | |
| 80 const_iterator begin() const; | |
| 81 const_iterator end() const; | |
| 82 | |
| 83 // Iterator through all Type overloads for a single ID. | |
| 84 const_iterator begin(Intrinsic::ID ID) const; | |
| 85 const_iterator end(Intrinsic::ID ID) const; | |
| 86 | |
| 87 const_iterator find(Intrinsic::ID ID, Type *OverloadedType) const; | |
| 88 | |
| 89 private: | |
| 90 AtomicIntrinsic I[NumAtomicIntrinsics][NumAtomicIntrinsicTypes]; | |
| 91 | |
| 92 AtomicIntrinsics() LLVM_DELETED_FUNCTION; | |
| 93 AtomicIntrinsics(const AtomicIntrinsics &) LLVM_DELETED_FUNCTION; | |
| 94 AtomicIntrinsics &operator=(const AtomicIntrinsics &) LLVM_DELETED_FUNCTION; | |
| 95 }; | |
| 96 | |
| 97 // Operations that can be represented by the @llvm.nacl.atomic.rmw | |
| 98 // intrinsic. | |
| 99 // | |
| 100 // Do not reorder these values: their order offers forward compatibility | |
| 101 // of bitcode targeted to NaCl. | |
| 102 enum AtomicRMWOperation { | |
| 103 AtomicInvalid = 0, // Invalid, keep first. | |
| 104 AtomicAdd, | |
| 105 AtomicSub, | |
| 106 AtomicOr, | |
| 107 AtomicAnd, | |
| 108 AtomicXor, | |
| 109 AtomicExchange, | |
| 110 AtomicNum // Invalid, keep last. | |
| 111 }; | |
| 112 | |
| 113 // Memory orderings supported by C11/C++11. | |
| 114 // | |
| 115 // Do not reorder these values: their order offers forward compatibility | |
| 116 // of bitcode targeted to NaCl. | |
| 117 enum MemoryOrder { | |
| 118 MemoryOrderInvalid = 0, // Invalid, keep first. | |
| 119 MemoryOrderRelaxed, | |
| 120 MemoryOrderConsume, | |
| 121 MemoryOrderAcquire, | |
| 122 MemoryOrderRelease, | |
| 123 MemoryOrderAcquireRelease, | |
| 124 MemoryOrderSequentiallyConsistent, | |
| 125 MemoryOrderNum // Invalid, keep last. | |
| 126 }; | |
| 127 | |
| 128 } // End NaCl namespace | |
| 129 | |
| 130 } // End llvm namespace | |
| 131 | |
| 132 #endif | |
| OLD | NEW |