1 void CDSPass::initializeCallbacks(Module &M) {
2 LLVMContext &Ctx = M.getContext();
4 Type * Int1Ty = Type::getInt1Ty(Ctx);
5 Int8Ty = Type::getInt8Ty(Ctx);
6 Int16Ty = Type::getInt16Ty(Ctx);
7 Int32Ty = Type::getInt32Ty(Ctx);
8 Int64Ty = Type::getInt64Ty(Ctx);
9 OrdTy = Type::getInt32Ty(Ctx);
11 Int8PtrTy = Type::getInt8PtrTy(Ctx);
12 Int16PtrTy = Type::getInt16PtrTy(Ctx);
13 Int32PtrTy = Type::getInt32PtrTy(Ctx);
14 Int64PtrTy = Type::getInt64PtrTy(Ctx);
16 VoidTy = Type::getVoidTy(Ctx);
18 // Get the function to call from our untime library.
19 for (unsigned i = 0; i < FUNCARRAYSIZE; i++) {
20 const unsigned ByteSize = 1U << i;
21 const unsigned BitSize = ByteSize * 8;
23 std::string ByteSizeStr = utostr(ByteSize);
24 std::string BitSizeStr = utostr(BitSize);
26 Type *Ty = Type::getIntNTy(Ctx, BitSize);
27 Type *PtrTy = Ty->getPointerTo();
29 // uint8_t cds_atomic_load8 (void * obj, int atomic_index)
30 // void cds_atomic_store8 (void * obj, int atomic_index, uint8_t val)
31 SmallString<32> LoadName("cds_load" + BitSizeStr);
32 SmallString<32> StoreName("cds_store" + BitSizeStr);
33 SmallString<32> AtomicInitName("cds_atomic_init" + BitSizeStr);
34 SmallString<32> AtomicLoadName("cds_atomic_load" + BitSizeStr);
35 SmallString<32> AtomicStoreName("cds_atomic_store" + BitSizeStr);
37 CDSLoad[i] = M.getOrInsertFunction(LoadName, VoidTy, PtrTy);
38 CDSStore[i] = M.getOrInsertFunction(StoreName, VoidTy, PtrTy);
39 CDSAtomicInit[i] = M.getOrInsertFunction(AtomicInitName,
40 VoidTy, PtrTy, Ty, Int8PtrTy);
41 CDSAtomicLoad[i] = M.getOrInsertFunction(AtomicLoadName,
42 Ty, PtrTy, OrdTy, Int8PtrTy);
43 CDSAtomicStore[i] = M.getOrInsertFunction(AtomicStoreName,
44 VoidTy, PtrTy, Ty, OrdTy, Int8PtrTy);
46 for (int op = AtomicRMWInst::FIRST_BINOP;
47 op <= AtomicRMWInst::LAST_BINOP; ++op) {
48 CDSAtomicRMW[op][i] = nullptr;
51 if (op == AtomicRMWInst::Xchg)
52 NamePart = "_exchange";
53 else if (op == AtomicRMWInst::Add)
54 NamePart = "_fetch_add";
55 else if (op == AtomicRMWInst::Sub)
56 NamePart = "_fetch_sub";
57 else if (op == AtomicRMWInst::And)
58 NamePart = "_fetch_and";
59 else if (op == AtomicRMWInst::Or)
60 NamePart = "_fetch_or";
61 else if (op == AtomicRMWInst::Xor)
62 NamePart = "_fetch_xor";
66 SmallString<32> AtomicRMWName("cds_atomic" + NamePart + BitSizeStr);
67 CDSAtomicRMW[op][i] = M.getOrInsertFunction(AtomicRMWName,
68 Ty, PtrTy, Ty, OrdTy, Int8PtrTy);
71 // only supportes strong version
72 SmallString<32> AtomicCASName_V1("cds_atomic_compare_exchange" + BitSizeStr + "_v1");
73 SmallString<32> AtomicCASName_V2("cds_atomic_compare_exchange" + BitSizeStr + "_v2");
74 CDSAtomicCAS_V1[i] = M.getOrInsertFunction(AtomicCASName_V1,
75 Ty, PtrTy, Ty, Ty, OrdTy, OrdTy, Int8PtrTy);
76 CDSAtomicCAS_V2[i] = M.getOrInsertFunction(AtomicCASName_V2,
77 Int1Ty, PtrTy, PtrTy, Ty, OrdTy, OrdTy, Int8PtrTy);
80 CDSAtomicThreadFence = M.getOrInsertFunction("cds_atomic_thread_fence",
81 VoidTy, OrdTy, Int8PtrTy);