-=======
-void CdsPass::initializeCallbacks(Module &M) {
->>>>>>> 0d737ead79278a1a67c5829f9c6bf84ee6a90cec
- LLVMContext &Ctx = M.getContext();
-
- Int8Ty = Type::getInt8Ty(Ctx);
- Int16Ty = Type::getInt16Ty(Ctx);
- Int32Ty = Type::getInt32Ty(Ctx);
- Int64Ty = Type::getInt64Ty(Ctx);
- OrdTy = Type::getInt32Ty(Ctx);
-
- Int8PtrTy = Type::getInt8PtrTy(Ctx);
- Int16PtrTy = Type::getInt16PtrTy(Ctx);
- Int32PtrTy = Type::getInt32PtrTy(Ctx);
- Int64PtrTy = Type::getInt64PtrTy(Ctx);
-
- VoidTy = Type::getVoidTy(Ctx);
-
-
- // Get the function to call from our untime library.
- for (unsigned i = 0; i < FUNCARRAYSIZE; i++) {
- const unsigned ByteSize = 1U << i;
- const unsigned BitSize = ByteSize * 8;
-// errs() << BitSize << "\n";
- std::string ByteSizeStr = utostr(ByteSize);
- std::string BitSizeStr = utostr(BitSize);
-
- Type *Ty = Type::getIntNTy(Ctx, BitSize);
- Type *PtrTy = Ty->getPointerTo();
-
- // uint8_t cds_atomic_load8 (void * obj, int atomic_index)
- // void cds_atomic_store8 (void * obj, int atomic_index, uint8_t val)
- SmallString<32> LoadName("cds_load" + BitSizeStr);
- SmallString<32> StoreName("cds_store" + BitSizeStr);
- SmallString<32> AtomicLoadName("cds_atomic_load" + BitSizeStr);
- SmallString<32> AtomicStoreName("cds_atomic_store" + BitSizeStr);
-
-<<<<<<< HEAD
-// CDSLoad[i] = M.getOrInsertFunction(LoadName, Ty, PtrTy);
-// CDSStore[i] = M.getOrInsertFunction(StoreName, VoidTy, PtrTy, Ty);
- CDSLoad[i] = M.getOrInsertFunction(LoadName, VoidTy, PtrTy);
- CDSStore[i] = M.getOrInsertFunction(StoreName, VoidTy, PtrTy);
- CDSAtomicLoad[i] = M.getOrInsertFunction(AtomicLoadName, Ty, PtrTy, OrdTy);
- CDSAtomicStore[i] = M.getOrInsertFunction(AtomicStoreName, VoidTy, PtrTy, OrdTy, Ty);
-
- for (int op = AtomicRMWInst::FIRST_BINOP; op <= AtomicRMWInst::LAST_BINOP; ++op) {
- CDSAtomicRMW[op][i] = nullptr;
-=======
-// CdsLoad[i] = M.getOrInsertFunction(LoadName, Ty, PtrTy);
-// CdsStore[i] = M.getOrInsertFunction(StoreName, VoidTy, PtrTy, Ty);
- CdsLoad[i] = M.getOrInsertFunction(LoadName, VoidTy, PtrTy);
- CdsStore[i] = M.getOrInsertFunction(StoreName, VoidTy, PtrTy);
- CdsAtomicLoad[i] = M.getOrInsertFunction(AtomicLoadName, Ty, PtrTy, OrdTy);
- CdsAtomicStore[i] = M.getOrInsertFunction(AtomicStoreName, VoidTy, PtrTy, OrdTy, Ty);
-
- for (int op = AtomicRMWInst::FIRST_BINOP; op <= AtomicRMWInst::LAST_BINOP; ++op) {
- CdsAtomicRMW[op][i] = nullptr;
->>>>>>> 0d737ead79278a1a67c5829f9c6bf84ee6a90cec
- std::string NamePart;
-
- if (op == AtomicRMWInst::Xchg)
- NamePart = "_exchange";
- else if (op == AtomicRMWInst::Add)
- NamePart = "_fetch_add";
- else if (op == AtomicRMWInst::Sub)
- NamePart = "_fetch_sub";
- else if (op == AtomicRMWInst::And)
- NamePart = "_fetch_and";
- else if (op == AtomicRMWInst::Or)
- NamePart = "_fetch_or";
- else if (op == AtomicRMWInst::Xor)
- NamePart = "_fetch_xor";
- else
- continue;
-
- SmallString<32> AtomicRMWName("cds_atomic" + NamePart + BitSizeStr);
-<<<<<<< HEAD
- CDSAtomicRMW[op][i] = M.getOrInsertFunction(AtomicRMWName, Ty, PtrTy, OrdTy, Ty);
-=======
- CdsAtomicRMW[op][i] = M.getOrInsertFunction(AtomicRMWName, Ty, PtrTy, OrdTy, Ty);
->>>>>>> 0d737ead79278a1a67c5829f9c6bf84ee6a90cec
- }
-
- // only supportes strong version
- SmallString<32> AtomicCASName("cds_atomic_compare_exchange" + BitSizeStr);
-<<<<<<< HEAD
- CDSAtomicCAS[i] = M.getOrInsertFunction(AtomicCASName, Ty, PtrTy, Ty, Ty, OrdTy, OrdTy);
- }
-
- CDSAtomicThreadFence = M.getOrInsertFunction("cds_atomic_thread_fence", VoidTy, OrdTy);
-=======
- CdsAtomicCAS[i] = M.getOrInsertFunction(AtomicCASName, Ty, PtrTy, Ty, Ty, OrdTy, OrdTy);
- }
-
- CdsAtomicThreadFence = M.getOrInsertFunction("cds_atomic_thread_fence", VoidTy, OrdTy);
->>>>>>> 0d737ead79278a1a67c5829f9c6bf84ee6a90cec
+ LLVMContext &Ctx = M.getContext();
+ AttributeList Attr;
+ Attr = Attr.addAttribute(Ctx, AttributeList::FunctionIndex,
+ Attribute::NoUnwind);
+
+ Type * Int1Ty = Type::getInt1Ty(Ctx);
+ Type * Int32Ty = Type::getInt32Ty(Ctx);
+ OrdTy = Type::getInt32Ty(Ctx);
+
+ Int8PtrTy = Type::getInt8PtrTy(Ctx);
+ Int16PtrTy = Type::getInt16PtrTy(Ctx);
+ Int32PtrTy = Type::getInt32PtrTy(Ctx);
+ Int64PtrTy = Type::getInt64PtrTy(Ctx);
+
+ VoidTy = Type::getVoidTy(Ctx);
+
+ CDSFuncEntry = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction("cds_func_entry",
+ Attr, VoidTy, Int8PtrTy));
+ CDSFuncExit = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction("cds_func_exit",
+ Attr, VoidTy, Int8PtrTy));
+
+ // Get the function to call from our untime library.
+ for (unsigned i = 0; i < kNumberOfAccessSizes; i++) {
+ const unsigned ByteSize = 1U << i;
+ const unsigned BitSize = ByteSize * 8;
+
+ std::string ByteSizeStr = utostr(ByteSize);
+ std::string BitSizeStr = utostr(BitSize);
+
+ Type *Ty = Type::getIntNTy(Ctx, BitSize);
+ Type *PtrTy = Ty->getPointerTo();
+
+ // uint8_t cds_atomic_load8 (void * obj, int atomic_index)
+ // void cds_atomic_store8 (void * obj, int atomic_index, uint8_t val)
+ SmallString<32> LoadName("cds_load" + BitSizeStr);
+ SmallString<32> StoreName("cds_store" + BitSizeStr);
+ SmallString<32> VolatileLoadName("cds_volatile_load" + BitSizeStr);
+ SmallString<32> VolatileStoreName("cds_volatile_store" + BitSizeStr);
+ SmallString<32> AtomicInitName("cds_atomic_init" + BitSizeStr);
+ SmallString<32> AtomicLoadName("cds_atomic_load" + BitSizeStr);
+ SmallString<32> AtomicStoreName("cds_atomic_store" + BitSizeStr);
+
+ CDSLoad[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(LoadName, Attr, VoidTy, Int8PtrTy));
+ CDSStore[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(StoreName, Attr, VoidTy, Int8PtrTy));
+ CDSVolatileLoad[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(VolatileLoadName,
+ Attr, Ty, PtrTy, Int8PtrTy));
+ CDSVolatileStore[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(VolatileStoreName,
+ Attr, VoidTy, PtrTy, Ty, Int8PtrTy));
+ CDSAtomicInit[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(AtomicInitName,
+ Attr, VoidTy, PtrTy, Ty, Int8PtrTy));
+ CDSAtomicLoad[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(AtomicLoadName,
+ Attr, Ty, PtrTy, OrdTy, Int8PtrTy));
+ CDSAtomicStore[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(AtomicStoreName,
+ Attr, VoidTy, PtrTy, Ty, OrdTy, Int8PtrTy));
+
+ for (int op = AtomicRMWInst::FIRST_BINOP;
+ op <= AtomicRMWInst::LAST_BINOP; ++op) {
+ CDSAtomicRMW[op][i] = nullptr;
+ std::string NamePart;
+
+ if (op == AtomicRMWInst::Xchg)
+ NamePart = "_exchange";
+ else if (op == AtomicRMWInst::Add)
+ NamePart = "_fetch_add";
+ else if (op == AtomicRMWInst::Sub)
+ NamePart = "_fetch_sub";
+ else if (op == AtomicRMWInst::And)
+ NamePart = "_fetch_and";
+ else if (op == AtomicRMWInst::Or)
+ NamePart = "_fetch_or";
+ else if (op == AtomicRMWInst::Xor)
+ NamePart = "_fetch_xor";
+ else
+ continue;
+
+ SmallString<32> AtomicRMWName("cds_atomic" + NamePart + BitSizeStr);
+ CDSAtomicRMW[op][i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(AtomicRMWName,
+ Attr, Ty, PtrTy, Ty, OrdTy, Int8PtrTy));
+ }
+
+ // only supportes strong version
+ SmallString<32> AtomicCASName_V1("cds_atomic_compare_exchange" + BitSizeStr + "_v1");
+ SmallString<32> AtomicCASName_V2("cds_atomic_compare_exchange" + BitSizeStr + "_v2");
+ CDSAtomicCAS_V1[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(AtomicCASName_V1,
+ Attr, Ty, PtrTy, Ty, Ty, OrdTy, OrdTy, Int8PtrTy));
+ CDSAtomicCAS_V2[i] = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction(AtomicCASName_V2,
+ Attr, Int1Ty, PtrTy, PtrTy, Ty, OrdTy, OrdTy, Int8PtrTy));
+ }
+
+ CDSAtomicThreadFence = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction("cds_atomic_thread_fence", Attr, VoidTy, OrdTy, Int8PtrTy));
+
+ MemmoveFn = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction("memmove", Attr, Int8PtrTy, Int8PtrTy,
+ Int8PtrTy, IntPtrTy));
+ MemcpyFn = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction("memcpy", Attr, Int8PtrTy, Int8PtrTy,
+ Int8PtrTy, IntPtrTy));
+ MemsetFn = checkCDSPassInterfaceFunction(
+ M.getOrInsertFunction("memset", Attr, Int8PtrTy, Int8PtrTy,
+ Int32Ty, IntPtrTy));
+}
+
+bool CDSPass::doInitialization(Module &M) {
+ const DataLayout &DL = M.getDataLayout();
+ IntPtrTy = DL.getIntPtrType(M.getContext());
+
+ // createSanitizerCtorAndInitFunctions is defined in "llvm/Transforms/Utils/ModuleUtils.h"
+ // We do not support it yet
+ /*
+ std::tie(CDSCtorFunction, std::ignore) = createSanitizerCtorAndInitFunctions(
+ M, kCDSModuleCtorName, kCDSInitName, {}, {});
+
+ appendToGlobalCtors(M, CDSCtorFunction, 0);
+ */
+
+ AtomicFuncNames =
+ {
+ "atomic_init", "atomic_load", "atomic_store",
+ "atomic_fetch_", "atomic_exchange", "atomic_compare_exchange_"
+ };
+
+ PartialAtomicFuncNames =
+ {
+ "load", "store", "fetch", "exchange", "compare_exchange_"
+ };
+
+ return true;