mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Add support for new atomics to cpp backend. Misc other fixes while I'm here. PR11268.
llvm-svn: 143406
This commit is contained in:
parent
85caca9190
commit
dc05741b6e
@ -1016,6 +1016,27 @@ std::string CppWriter::getOpName(const Value* V) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static StringRef ConvertAtomicOrdering(AtomicOrdering Ordering) {
|
||||||
|
switch (Ordering) {
|
||||||
|
case NotAtomic: return "NotAtomic";
|
||||||
|
case Unordered: return "Unordered";
|
||||||
|
case Monotonic: return "Monotonic";
|
||||||
|
case Acquire: return "Acquire";
|
||||||
|
case Release: return "Release";
|
||||||
|
case AcquireRelease: return "AcquireRelease";
|
||||||
|
case SequentiallyConsistent: return "SequentiallyConsistent";
|
||||||
|
}
|
||||||
|
llvm_unreachable("Unknown ordering");
|
||||||
|
}
|
||||||
|
|
||||||
|
static StringRef ConvertAtomicSynchScope(SynchronizationScope SynchScope) {
|
||||||
|
switch (SynchScope) {
|
||||||
|
case SingleThread: return "SingleThread";
|
||||||
|
case CrossThread: return "CrossThread";
|
||||||
|
}
|
||||||
|
llvm_unreachable("Unknown synch scope");
|
||||||
|
}
|
||||||
|
|
||||||
// printInstruction - This member is called for each Instruction in a function.
|
// printInstruction - This member is called for each Instruction in a function.
|
||||||
void CppWriter::printInstruction(const Instruction *I,
|
void CppWriter::printInstruction(const Instruction *I,
|
||||||
const std::string& bbname) {
|
const std::string& bbname) {
|
||||||
@ -1237,15 +1258,33 @@ void CppWriter::printInstruction(const Instruction *I,
|
|||||||
printEscapedString(load->getName());
|
printEscapedString(load->getName());
|
||||||
Out << "\", " << (load->isVolatile() ? "true" : "false" )
|
Out << "\", " << (load->isVolatile() ? "true" : "false" )
|
||||||
<< ", " << bbname << ");";
|
<< ", " << bbname << ");";
|
||||||
|
if (load->getAlignment())
|
||||||
|
nl(Out) << iName << "->setAlignment("
|
||||||
|
<< load->getAlignment() << ");";
|
||||||
|
if (load->isAtomic()) {
|
||||||
|
StringRef Ordering = ConvertAtomicOrdering(load->getOrdering());
|
||||||
|
StringRef CrossThread = ConvertAtomicSynchScope(load->getSynchScope());
|
||||||
|
nl(Out) << iName << "->setAtomic("
|
||||||
|
<< Ordering << ", " << CrossThread << ");";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Instruction::Store: {
|
case Instruction::Store: {
|
||||||
const StoreInst* store = cast<StoreInst>(I);
|
const StoreInst* store = cast<StoreInst>(I);
|
||||||
Out << " new StoreInst("
|
Out << "StoreInst* " << iName << " = new StoreInst("
|
||||||
<< opNames[0] << ", "
|
<< opNames[0] << ", "
|
||||||
<< opNames[1] << ", "
|
<< opNames[1] << ", "
|
||||||
<< (store->isVolatile() ? "true" : "false")
|
<< (store->isVolatile() ? "true" : "false")
|
||||||
<< ", " << bbname << ");";
|
<< ", " << bbname << ");";
|
||||||
|
if (store->getAlignment())
|
||||||
|
nl(Out) << iName << "->setAlignment("
|
||||||
|
<< store->getAlignment() << ");";
|
||||||
|
if (store->isAtomic()) {
|
||||||
|
StringRef Ordering = ConvertAtomicOrdering(store->getOrdering());
|
||||||
|
StringRef CrossThread = ConvertAtomicSynchScope(store->getSynchScope());
|
||||||
|
nl(Out) << iName << "->setAtomic("
|
||||||
|
<< Ordering << ", " << CrossThread << ");";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Instruction::GetElementPtr: {
|
case Instruction::GetElementPtr: {
|
||||||
@ -1447,6 +1486,60 @@ void CppWriter::printInstruction(const Instruction *I,
|
|||||||
Out << "\", " << bbname << ");";
|
Out << "\", " << bbname << ");";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Instruction::Fence: {
|
||||||
|
const FenceInst *fi = cast<FenceInst>(I);
|
||||||
|
StringRef Ordering = ConvertAtomicOrdering(fi->getOrdering());
|
||||||
|
StringRef CrossThread = ConvertAtomicSynchScope(fi->getSynchScope());
|
||||||
|
Out << "FenceInst* " << iName
|
||||||
|
<< " = new FenceInst(mod->getContext(), "
|
||||||
|
<< Ordering << ", " << CrossThread
|
||||||
|
<< ");";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Instruction::AtomicCmpXchg: {
|
||||||
|
const AtomicCmpXchgInst *cxi = cast<AtomicCmpXchgInst>(I);
|
||||||
|
StringRef Ordering = ConvertAtomicOrdering(cxi->getOrdering());
|
||||||
|
StringRef CrossThread = ConvertAtomicSynchScope(cxi->getSynchScope());
|
||||||
|
Out << "AtomicCmpXchgInst* " << iName
|
||||||
|
<< " = new AtomicCmpXchgInst("
|
||||||
|
<< opNames[0] << ", " << opNames[1] << ", " << opNames[2] << ", "
|
||||||
|
<< Ordering << ", " << CrossThread
|
||||||
|
<< ");";
|
||||||
|
nl(Out) << iName << "->setName(\"";
|
||||||
|
printEscapedString(cxi->getName());
|
||||||
|
Out << "\");";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Instruction::AtomicRMW: {
|
||||||
|
const AtomicRMWInst *rmwi = cast<AtomicRMWInst>(I);
|
||||||
|
StringRef Ordering = ConvertAtomicOrdering(rmwi->getOrdering());
|
||||||
|
StringRef CrossThread = ConvertAtomicSynchScope(rmwi->getSynchScope());
|
||||||
|
StringRef Operation;
|
||||||
|
switch (rmwi->getOperation()) {
|
||||||
|
case AtomicRMWInst::Xchg: Operation = "AtomicRMWInst::Xchg"; break;
|
||||||
|
case AtomicRMWInst::Add: Operation = "AtomicRMWInst::Add"; break;
|
||||||
|
case AtomicRMWInst::Sub: Operation = "AtomicRMWInst::Sub"; break;
|
||||||
|
case AtomicRMWInst::And: Operation = "AtomicRMWInst::And"; break;
|
||||||
|
case AtomicRMWInst::Nand: Operation = "AtomicRMWInst::Nand"; break;
|
||||||
|
case AtomicRMWInst::Or: Operation = "AtomicRMWInst::Or"; break;
|
||||||
|
case AtomicRMWInst::Xor: Operation = "AtomicRMWInst::Xor"; break;
|
||||||
|
case AtomicRMWInst::Max: Operation = "AtomicRMWInst::Max"; break;
|
||||||
|
case AtomicRMWInst::Min: Operation = "AtomicRMWInst::Min"; break;
|
||||||
|
case AtomicRMWInst::UMax: Operation = "AtomicRMWInst::UMax"; break;
|
||||||
|
case AtomicRMWInst::UMin: Operation = "AtomicRMWInst::UMin"; break;
|
||||||
|
case AtomicRMWInst::BAD_BINOP: llvm_unreachable("Bad atomic operation");
|
||||||
|
}
|
||||||
|
Out << "AtomicRMWInst* " << iName
|
||||||
|
<< " = new AtomicRMWInst("
|
||||||
|
<< Operation << ", "
|
||||||
|
<< opNames[0] << ", " << opNames[1] << ", "
|
||||||
|
<< Ordering << ", " << CrossThread
|
||||||
|
<< ");";
|
||||||
|
nl(Out) << iName << "->setName(\"";
|
||||||
|
printEscapedString(rmwi->getName());
|
||||||
|
Out << "\");";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DefinedValues.insert(I);
|
DefinedValues.insert(I);
|
||||||
nl(Out);
|
nl(Out);
|
||||||
@ -1623,7 +1716,9 @@ void CppWriter::printFunctionBody(const Function *F) {
|
|||||||
Out << "Value* " << getCppName(AI) << " = args++;";
|
Out << "Value* " << getCppName(AI) << " = args++;";
|
||||||
nl(Out);
|
nl(Out);
|
||||||
if (AI->hasName()) {
|
if (AI->hasName()) {
|
||||||
Out << getCppName(AI) << "->setName(\"" << AI->getName() << "\");";
|
Out << getCppName(AI) << "->setName(\"";
|
||||||
|
printEscapedString(AI->getName());
|
||||||
|
Out << "\");";
|
||||||
nl(Out);
|
nl(Out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user