| Index: lib/IR/NaClIntrinsics.cpp
|
| diff --git a/lib/IR/NaClIntrinsics.cpp b/lib/IR/NaClIntrinsics.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3c0a4b803e329f5759e028d4be8256a0d7664452
|
| --- /dev/null
|
| +++ b/lib/IR/NaClIntrinsics.cpp
|
| @@ -0,0 +1,102 @@
|
| +//===-- llvm/IR/NaClIntrinsics.cpp - NaCl Intrinsics ------------*- C++ -*-===//
|
| +//
|
| +// The LLVM Compiler Infrastructure
|
| +//
|
| +// This file is distributed under the University of Illinois Open Source
|
| +// License. See LICENSE.TXT for details.
|
| +//
|
| +//===----------------------------------------------------------------------===//
|
| +//
|
| +// This file describes intrinsic functions that are specific to NaCl.
|
| +//
|
| +//===----------------------------------------------------------------------===//
|
| +
|
| +#include "llvm/IR/DerivedTypes.h"
|
| +#include "llvm/IR/NaClIntrinsics.h"
|
| +#include "llvm/IR/Type.h"
|
| +
|
| +namespace llvm {
|
| +
|
| +namespace NaCl {
|
| +
|
| +AtomicIntrinsics::AtomicIntrinsics(LLVMContext &C) {
|
| + Type *IT[NumAtomicIntrinsicTypes] = { Type::getInt8Ty(C), Type::getInt16Ty(C),
|
| + Type::getInt32Ty(C),
|
| + Type::getInt64Ty(C) };
|
| + Type *PT[NumAtomicIntrinsicTypes] = { Type::getInt8PtrTy(C),
|
| + Type::getInt16PtrTy(C),
|
| + Type::getInt32PtrTy(C),
|
| + Type::getInt64PtrTy(C) };
|
| + size_t CurIntrin = 0;
|
| +
|
| +#define SET(V) \
|
| + do { \
|
| + Type *T = \
|
| + ((V == NoP) ? NULL \
|
| + : ((V == Int) ? IT[CurType] \
|
| + : ((V == Ptr) ? PT[CurType] : IT[2]))); \
|
| + I[CurIntrin][CurType].ParamType[Param] = V; \
|
| + I[CurIntrin][CurType].Signature[Param++] = T; \
|
| + } while (0)
|
| +
|
| +#define INIT(P0, P1, P2, P3, P4, INTRIN) \
|
| + do { \
|
| + for (size_t CurType = 0; CurType != NumAtomicIntrinsicTypes; ++CurType) { \
|
| + size_t Param = 0; \
|
| + I[CurIntrin][CurType].ID = Intrinsic::nacl_atomic_##INTRIN; \
|
| + I[CurIntrin][CurType].NumParams = \
|
| + (P0 != NoP) + (P1 != NoP) + (P2 != NoP) + (P3 != NoP) + (P4 != NoP); \
|
| + I[CurIntrin][CurType].Overloaded = \
|
| + P0 == Int || P0 == Ptr || P1 == Int || P1 == Ptr || P2 == Int || \
|
| + P2 == Ptr || P3 == Int || P3 == Ptr || P4 == Int || P4 == Ptr; \
|
| + I[CurIntrin][CurType].OverloadedType = IT[CurType]; \
|
| + SET(P0); \
|
| + SET(P1); \
|
| + SET(P2); \
|
| + SET(P3); \
|
| + SET(P4); \
|
| + } \
|
| + ++CurIntrin; \
|
| + } while (0)
|
| +
|
| + INIT(Ptr, Mem, NoP, NoP, NoP, load);
|
| + INIT(Ptr, Int, Mem, NoP, NoP, store);
|
| + INIT(RMW, Ptr, Int, Mem, NoP, rmw);
|
| + INIT(Ptr, Int, Int, Mem, Mem, cmpxchg);
|
| + INIT(Mem, NoP, NoP, NoP, NoP, fence);
|
| +}
|
| +
|
| +AtomicIntrinsics::const_iterator AtomicIntrinsics::begin() const {
|
| + return &I[0][0];
|
| +}
|
| +
|
| +AtomicIntrinsics::const_iterator AtomicIntrinsics::end() const {
|
| + return begin().I + NumAtomicIntrinsics * NumAtomicIntrinsicTypes;
|
| +}
|
| +
|
| +AtomicIntrinsics::const_iterator
|
| +AtomicIntrinsics::begin(Intrinsic::ID ID) const {
|
| + for (const AtomicIntrinsic *AI = begin().I; AI != end().I; ++AI)
|
| + if (AI->ID == ID)
|
| + return const_iterator(AI);
|
| + llvm_unreachable("unhandled atomic intrinsic");
|
| +}
|
| +
|
| +AtomicIntrinsics::const_iterator AtomicIntrinsics::end(Intrinsic::ID ID) const {
|
| + for (const AtomicIntrinsic *AI = end().I; AI != begin().I; --AI)
|
| + if ((AI - 1)->ID == ID)
|
| + return const_iterator(AI);
|
| + llvm_unreachable("unhandled atomic intrinsic");
|
| +}
|
| +
|
| +AtomicIntrinsics::const_iterator
|
| +AtomicIntrinsics::find(Intrinsic::ID ID, Type *OverloadedType) const {
|
| + for (const AtomicIntrinsic *AI = begin().I; AI != end().I; ++AI)
|
| + if (AI->ID == ID && AI->OverloadedType == OverloadedType)
|
| + return const_iterator(AI);
|
| + llvm_unreachable("unhandled atomic intrinsic");
|
| +}
|
| +
|
| +} // End NaCl namespace
|
| +
|
| +} // End llvm namespace
|
|
|