From 1c3a07834e9bdbde110a3ec0faaee9a40e765760 Mon Sep 17 00:00:00 2001 From: Gerolf Hoflehner Date: Tue, 17 Apr 2018 04:02:24 +0000 Subject: [PATCH] [IR] Upgrade comment token in objc retain release marker for asm call Older compiler issued '#' instead of ';' llvm-svn: 330173 --- llvm/include/llvm/IR/AutoUpgrade.h | 4 ++++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ llvm/lib/IR/AutoUpgrade.cpp | 13 +++++++++++++ llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll | 9 +++++++++ llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll.bc | Bin 0 -> 1312 bytes 5 files changed, 28 insertions(+) create mode 100644 llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll create mode 100644 llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll.bc diff --git a/llvm/include/llvm/IR/AutoUpgrade.h b/llvm/include/llvm/IR/AutoUpgrade.h index a186b05d..8cf574c 100644 --- a/llvm/include/llvm/IR/AutoUpgrade.h +++ b/llvm/include/llvm/IR/AutoUpgrade.h @@ -37,6 +37,10 @@ namespace llvm { /// intrinsic function with a call to the specified new function. void UpgradeIntrinsicCall(CallInst *CI, Function *NewFn); + // This upgrades the comment for objc retain release markers in inline asm + // calls + void UpgradeInlineAsmString(std::string *AsmStr); + /// This is an auto-upgrade hook for any old intrinsic function syntaxes /// which need to have both the function updated as well as all calls updated /// to the new function. This should only be run in a post-processing fashion diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1a65cee..9d826aa 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2522,6 +2522,7 @@ Error BitcodeReader::parseConstants() { for (unsigned i = 0; i != ConstStrSize; ++i) ConstrStr += (char)Record[3+AsmStrSize+i]; PointerType *PTy = cast(CurTy); + UpgradeInlineAsmString(&AsmStr); V = InlineAsm::get(cast(PTy->getElementType()), AsmStr, ConstrStr, HasSideEffects, IsAlignStack); break; @@ -2547,6 +2548,7 @@ Error BitcodeReader::parseConstants() { for (unsigned i = 0; i != ConstStrSize; ++i) ConstrStr += (char)Record[3+AsmStrSize+i]; PointerType *PTy = cast(CurTy); + UpgradeInlineAsmString(&AsmStr); V = InlineAsm::get(cast(PTy->getElementType()), AsmStr, ConstrStr, HasSideEffects, IsAlignStack, InlineAsm::AsmDialect(AsmDialect)); diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 78385ac..f3193f5 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -1169,6 +1169,19 @@ static bool upgradeAVX512MaskToSelect(StringRef Name, IRBuilder<> &Builder, return true; } +/// Upgrade comment in call to inline asm that represents an objc retain release +/// marker. +void llvm::UpgradeInlineAsmString(std::string *AsmStr) { + + unsigned long Pos; + if (AsmStr->find("mov\tfp") == 0 && + AsmStr->find("objc_retainAutoreleaseReturnValue") != std::string::npos && + (Pos = AsmStr->find("# marker")) != std::string::npos) { + AsmStr->replace(Pos, 1, ";"); + } + return; +} + /// Upgrade a call to an old intrinsic. All argument and return casting must be /// provided to seamlessly integrate with existing context. void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { diff --git a/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll b/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll new file mode 100644 index 0000000..e6a99dd --- /dev/null +++ b/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll @@ -0,0 +1,9 @@ +; Test that comment token for objc retain release is upgraded from '#' to ';' +; +; RUN: llvm-dis < %s.bc | FileCheck %s + +define void @inlineasm() { + call void asm sideeffect "mov\09fp, fp\09\09# marker for objc_retainAutoreleaseReturnValue", ""() + ;CHECK: call void asm sideeffect "mov\09fp, fp\09\09; marker for objc_retainAutoreleaseReturnValue", ""() + ret void +} diff --git a/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll.bc b/llvm/test/Bitcode/upgrade-objcretainrelease-asm.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..eb9986b8a4d4bd818b7428ee02ae2acc0bf453de GIT binary patch literal 1312 zcmY*ZZ%i9y7=O!^z7@Lb$(m5MyUX2R2_IJM3PQ0|*Pbpc@}b0kGttmv6k!2&lv+wz zmX_CMxq}yA*Q9M4K@?!vS1|58VVtkkw&MPW{Ez>aEVXyd!BpV z_j#Xx@AFAoLgP z)z|Q-2IOG?jy7L&6|`q`l&$-^CT2KZt8Zep?+-={FV(oO*Sm)(o5`*>zg%at#e0(` zPB9p<&hfp2(v>hwxxuMJ2kNAZcu+3N|X=>Z7P;bR7A>65@AU%o2`=wT`shsmGxR4z?Jw9W zIle}QtK@i+44%SaFAl8fwj)?d<4F#O)^vLj9HwwEjiY$M}+ihK|u+YN4ZImg`0(8Jc+eKYxJk#H6SXM%7RLy3Td zXZ3idSCJ$fmWW_TkvOHP_%ykjB+FLggw?oNC958?omyc^JiX2{%OX2$z2aDs9cx1O z7evpJ+!G@l#i}Xj#j_*0Yeew_k0?@7k-X409DG;{Zl@#4fL@t2EB=%+lZu|$tCD+n z$v?8>u9X-pWavtUF7ERUkzVELl_;|+>h2_k?t;*r+UH;9?el^?PB`ZC&p^;ebB^1D zV=-^|Zd8%ZDt<{0jNp)037C~YT4}oZig6DafAf%)B)NIYSmwxGsDf){HgfE;i@n9u z8&P)SE?p@z_cZLVx!=AhJauOF7#QY8jq;5O~Q2!S%9_SvB zDydT4A5j$`_1qCa7k~qZfd5FfQ|S$W`qoua{r&@lTJ}}+HpHgk6JnRumC=c@(Fvb8 zHQv=`ZL>}VCpdt`-)`%+b##U7odca67EzMMe3o(X+=Z#oNo(85_BQLg(mQ@}$Y;4Q fc>bK<7Z67${Jt@8