Merge pull request #962 from ncos/cbackend-cmpxchg
Fix llvm->c++ translation of cmxchg instruction
This commit is contained in:
20
cbackend.cpp
20
cbackend.cpp
@@ -501,8 +501,14 @@ namespace {
|
||||
static bool isInlinableInst(const llvm::Instruction &I) {
|
||||
// Always inline cmp instructions, even if they are shared by multiple
|
||||
// expressions. GCC generates horrible code if we don't.
|
||||
if (llvm::isa<llvm::CmpInst>(I) && llvm::isa<llvm::VectorType>(I.getType()) == false)
|
||||
return true;
|
||||
if (llvm::isa<llvm::CmpInst>(I) && llvm::isa<llvm::VectorType>(I.getType()) == false)
|
||||
return true;
|
||||
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+
|
||||
// This instruction returns a struct on LLVM older than 3.4, and can not be inlined
|
||||
if (llvm::isa<llvm::AtomicCmpXchgInst>(I))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
// Must be an expression, must be used exactly once. If it is dead, we
|
||||
// emit it inline where it would go.
|
||||
@@ -4512,13 +4518,21 @@ void CWriter::visitAtomicRMWInst(llvm::AtomicRMWInst &AI) {
|
||||
|
||||
void CWriter::visitAtomicCmpXchgInst(llvm::AtomicCmpXchgInst &ACXI) {
|
||||
Out << "(";
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4)
|
||||
printType(Out, ACXI.getType(), false);
|
||||
Out << "::init("; // LLVM cmpxchg returns a struct, so we need make an assighment properly
|
||||
#endif
|
||||
Out << "__atomic_cmpxchg(";
|
||||
writeOperand(ACXI.getPointerOperand());
|
||||
Out << ", ";
|
||||
writeOperand(ACXI.getCompareOperand());
|
||||
Out << ", ";
|
||||
writeOperand(ACXI.getNewValOperand());
|
||||
Out << "))";
|
||||
Out << ")";
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4)
|
||||
Out << ", true /* There is no way to learn the value of this bit inside ISPC, so making it constant */)";
|
||||
#endif
|
||||
Out << ")";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user