Skip to content

Commit

Permalink
fix bug for consecutive atomic instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruobing Han committed Jun 4, 2021
1 parent 8250122 commit af2e174
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions lib/SPIRV/OCL20ToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,36 +376,37 @@ bool OCL20ToSPIRV::runOnModule(Module &Module) {
}

void OCL20ToSPIRV::visitAtomicRMWInst(AtomicRMWInst &ARMWI) {
SmallVector<Value *, 16> 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<Value *, 16> 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.
Expand Down

0 comments on commit af2e174

Please sign in to comment.