llvm.org GIT mirror llvm / 39be04a
Merging r143406: ------------------------------------------------------------------------ r143406 | efriedma | 2011-10-31 16:59:22 -0700 (Mon, 31 Oct 2011) | 3 lines Add support for new atomics to cpp backend. Misc other fixes while I'm here. PR11268. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_30@143998 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 7 years ago
1 changed file(s) with 97 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
10151015 return result;
10161016 }
10171017
1018 static StringRef ConvertAtomicOrdering(AtomicOrdering Ordering) {
1019 switch (Ordering) {
1020 case NotAtomic: return "NotAtomic";
1021 case Unordered: return "Unordered";
1022 case Monotonic: return "Monotonic";
1023 case Acquire: return "Acquire";
1024 case Release: return "Release";
1025 case AcquireRelease: return "AcquireRelease";
1026 case SequentiallyConsistent: return "SequentiallyConsistent";
1027 }
1028 llvm_unreachable("Unknown ordering");
1029 }
1030
1031 static StringRef ConvertAtomicSynchScope(SynchronizationScope SynchScope) {
1032 switch (SynchScope) {
1033 case SingleThread: return "SingleThread";
1034 case CrossThread: return "CrossThread";
1035 }
1036 llvm_unreachable("Unknown synch scope");
1037 }
1038
10181039 // printInstruction - This member is called for each Instruction in a function.
10191040 void CppWriter::printInstruction(const Instruction *I,
10201041 const std::string& bbname) {
12361257 printEscapedString(load->getName());
12371258 Out << "\", " << (load->isVolatile() ? "true" : "false" )
12381259 << ", " << bbname << ");";
1260 if (load->getAlignment())
1261 nl(Out) << iName << "->setAlignment("
1262 << load->getAlignment() << ");";
1263 if (load->isAtomic()) {
1264 StringRef Ordering = ConvertAtomicOrdering(load->getOrdering());
1265 StringRef CrossThread = ConvertAtomicSynchScope(load->getSynchScope());
1266 nl(Out) << iName << "->setAtomic("
1267 << Ordering << ", " << CrossThread << ");";
1268 }
12391269 break;
12401270 }
12411271 case Instruction::Store: {
12421272 const StoreInst* store = cast(I);
1243 Out << " new StoreInst("
1273 Out << "StoreInst* " << iName << " = new StoreInst("
12441274 << opNames[0] << ", "
12451275 << opNames[1] << ", "
12461276 << (store->isVolatile() ? "true" : "false")
12471277 << ", " << bbname << ");";
1278 if (store->getAlignment())
1279 nl(Out) << iName << "->setAlignment("
1280 << store->getAlignment() << ");";
1281 if (store->isAtomic()) {
1282 StringRef Ordering = ConvertAtomicOrdering(store->getOrdering());
1283 StringRef CrossThread = ConvertAtomicSynchScope(store->getSynchScope());
1284 nl(Out) << iName << "->setAtomic("
1285 << Ordering << ", " << CrossThread << ");";
1286 }
12481287 break;
12491288 }
12501289 case Instruction::GetElementPtr: {
14461485 Out << "\", " << bbname << ");";
14471486 break;
14481487 }
1488 case Instruction::Fence: {
1489 const FenceInst *fi = cast(I);
1490 StringRef Ordering = ConvertAtomicOrdering(fi->getOrdering());
1491 StringRef CrossThread = ConvertAtomicSynchScope(fi->getSynchScope());
1492 Out << "FenceInst* " << iName
1493 << " = new FenceInst(mod->getContext(), "
1494 << Ordering << ", " << CrossThread
1495 << ");";
1496 break;
1497 }
1498 case Instruction::AtomicCmpXchg: {
1499 const AtomicCmpXchgInst *cxi = cast(I);
1500 StringRef Ordering = ConvertAtomicOrdering(cxi->getOrdering());
1501 StringRef CrossThread = ConvertAtomicSynchScope(cxi->getSynchScope());
1502 Out << "AtomicCmpXchgInst* " << iName
1503 << " = new AtomicCmpXchgInst("
1504 << opNames[0] << ", " << opNames[1] << ", " << opNames[2] << ", "
1505 << Ordering << ", " << CrossThread
1506 << ");";
1507 nl(Out) << iName << "->setName(\"";
1508 printEscapedString(cxi->getName());
1509 Out << "\");";
1510 break;
1511 }
1512 case Instruction::AtomicRMW: {
1513 const AtomicRMWInst *rmwi = cast(I);
1514 StringRef Ordering = ConvertAtomicOrdering(rmwi->getOrdering());
1515 StringRef CrossThread = ConvertAtomicSynchScope(rmwi->getSynchScope());
1516 StringRef Operation;
1517 switch (rmwi->getOperation()) {
1518 case AtomicRMWInst::Xchg: Operation = "AtomicRMWInst::Xchg"; break;
1519 case AtomicRMWInst::Add: Operation = "AtomicRMWInst::Add"; break;
1520 case AtomicRMWInst::Sub: Operation = "AtomicRMWInst::Sub"; break;
1521 case AtomicRMWInst::And: Operation = "AtomicRMWInst::And"; break;
1522 case AtomicRMWInst::Nand: Operation = "AtomicRMWInst::Nand"; break;
1523 case AtomicRMWInst::Or: Operation = "AtomicRMWInst::Or"; break;
1524 case AtomicRMWInst::Xor: Operation = "AtomicRMWInst::Xor"; break;
1525 case AtomicRMWInst::Max: Operation = "AtomicRMWInst::Max"; break;
1526 case AtomicRMWInst::Min: Operation = "AtomicRMWInst::Min"; break;
1527 case AtomicRMWInst::UMax: Operation = "AtomicRMWInst::UMax"; break;
1528 case AtomicRMWInst::UMin: Operation = "AtomicRMWInst::UMin"; break;
1529 case AtomicRMWInst::BAD_BINOP: llvm_unreachable("Bad atomic operation");
1530 }
1531 Out << "AtomicRMWInst* " << iName
1532 << " = new AtomicRMWInst("
1533 << Operation << ", "
1534 << opNames[0] << ", " << opNames[1] << ", "
1535 << Ordering << ", " << CrossThread
1536 << ");";
1537 nl(Out) << iName << "->setName(\"";
1538 printEscapedString(rmwi->getName());
1539 Out << "\");";
1540 break;
1541 }
14491542 }
14501543 DefinedValues.insert(I);
14511544 nl(Out);
16221715 Out << "Value* " << getCppName(AI) << " = args++;";
16231716 nl(Out);
16241717 if (AI->hasName()) {
1625 Out << getCppName(AI) << "->setName(\"" << AI->getName() << "\");";
1718 Out << getCppName(AI) << "->setName(\"";
1719 printEscapedString(AI->getName());
1720 Out << "\");";
16261721 nl(Out);
16271722 }
16281723 }