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