diff --git a/lib/SPIRV/OCL20ToSPIRV.cpp b/lib/SPIRV/OCL20ToSPIRV.cpp index d63eff4..348a90e 100644 --- a/lib/SPIRV/OCL20ToSPIRV.cpp +++ b/lib/SPIRV/OCL20ToSPIRV.cpp @@ -376,36 +376,37 @@ bool OCL20ToSPIRV::runOnModule(Module &Module) { } void OCL20ToSPIRV::visitAtomicRMWInst(AtomicRMWInst &ARMWI) { - SmallVector Args; - Args.push_back(ARMWI.getPointerOperand()); - Args.push_back(ARMWI.getValOperand()); - FunctionType *FT = - FunctionType::get(ARMWI.getType(), getTypes(Args), false /*isVarArg*/); - // TODO: remove this hard code function name - std::string lib_func_name = ""; - if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Add) { - lib_func_name = "_Z10atomic_addPU8CLglobalVii"; - } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Xchg) { - lib_func_name = "_Z11atomic_xchgPU8CLglobalVii"; - } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Max) { - lib_func_name = "_Z10atomic_maxPU8CLglobalVii"; - } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Min) { - lib_func_name = "_Z10atomic_minPU8CLglobalVii"; - } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::And) { - lib_func_name = "_Z10atomic_andPU8CLglobalVii"; - } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Or) { - lib_func_name = "_Z9atomic_orPU8CLglobalVii"; - } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Xor) { - lib_func_name = "_Z10atomic_xorPU8CLglobalVii"; - } else { - std::cout << "unsupport atomic instruction\n"; - exit(1); - } - Function *NewF = - Function::Create(FT, GlobalValue::ExternalLinkage, lib_func_name, M); - CallInst *NewCall = CallInst::Create(NewF, Args, "", &ARMWI); - ARMWI.replaceAllUsesWith(NewCall); - ARMWI.eraseFromParent(); + SmallVector Args; + Args.push_back(ARMWI.getPointerOperand()); + Args.push_back(ARMWI.getValOperand()); + FunctionType *FT = + FunctionType::get(ARMWI.getType(), getTypes(Args), false /*isVarArg*/); + // TODO: remove this hard code function name + std::string lib_func_name = ""; + if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Add) { + lib_func_name = "_Z10atomic_addPU8CLglobalVii"; + } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Xchg) { + lib_func_name = "_Z11atomic_xchgPU8CLglobalVii"; + } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Max) { + lib_func_name = "_Z10atomic_maxPU8CLglobalVii"; + } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Min) { + lib_func_name = "_Z10atomic_minPU8CLglobalVii"; + } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::And) { + lib_func_name = "_Z10atomic_andPU8CLglobalVii"; + } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Or) { + lib_func_name = "_Z9atomic_orPU8CLglobalVii"; + } else if (ARMWI.getOperation() == llvm::AtomicRMWInst::BinOp::Xor) { + lib_func_name = "_Z10atomic_xorPU8CLglobalVii"; + } else { + std::cout << "unsupport atomic instruction\n"; + exit(1); + } + auto NewF = M->getOrInsertFunction(lib_func_name, FT); + // Function *NewF = + // Function::Create(FT, GlobalValue::ExternalLinkage, lib_func_name, M); + CallInst *NewCall = CallInst::Create(NewF, Args, "", &ARMWI); + ARMWI.replaceAllUsesWith(NewCall); + ARMWI.eraseFromParent(); } // The order of handling OCL builtin functions is important.