Skip to content

Commit 14b2d2c

Browse files
authored
RuntimeLibcalls: Add entries for objc runtime calls (#147920)
Stop emitting these calls by name in PreISelIntrinsicLowering. This is still kind of a hack. We should be going through the abstract RTLIB:Libcall, and then checking if the call is really supported in this module. Do this as a placeholder until RuntimeLibcalls is a module analysis.
1 parent 545b075 commit 14b2d2c

File tree

2 files changed

+94
-28
lines changed

2 files changed

+94
-28
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,34 @@ def HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES : RuntimeLibcall;
387387
// XCore calls
388388
def MEMCPY_ALIGN_4 : RuntimeLibcall;
389389

390+
// Objective-C calls
391+
def OBJC_AUTORELEASE : RuntimeLibcall;
392+
def OBJC_AUTORELEASEPOOLPOP : RuntimeLibcall;
393+
def OBJC_AUTORELEASEPOOLPUSH : RuntimeLibcall;
394+
def OBJC_AUTORELEASERETURNVALUE : RuntimeLibcall;
395+
def OBJC_COPYWEAK : RuntimeLibcall;
396+
def OBJC_DESTROYWEAK : RuntimeLibcall;
397+
def OBJC_INITWEAK : RuntimeLibcall;
398+
def OBJC_LOADWEAK : RuntimeLibcall;
399+
def OBJC_LOADWEAKRETAINED : RuntimeLibcall;
400+
def OBJC_MOVEWEAK : RuntimeLibcall;
401+
def OBJC_RELEASE : RuntimeLibcall;
402+
def OBJC_RETAIN : RuntimeLibcall;
403+
def OBJC_RETAINAUTORELEASE : RuntimeLibcall;
404+
def OBJC_RETAINAUTORELEASERETURNVALUE : RuntimeLibcall;
405+
def OBJC_RETAINAUTORELEASEDRETURNVALUE : RuntimeLibcall;
406+
def OBJC_CLAIMAUTORELEASEDRETURNVALUE : RuntimeLibcall;
407+
def OBJC_RETAINBLOCK : RuntimeLibcall;
408+
def OBJC_STORESTRONG : RuntimeLibcall;
409+
def OBJC_STOREWEAK : RuntimeLibcall;
410+
def OBJC_UNSAFECLAIMAUTORELEASEDRETURNVALUE : RuntimeLibcall;
411+
def OBJC_RETAINEDOBJECT : RuntimeLibcall;
412+
def OBJC_UNRETAINEDOBJECT : RuntimeLibcall;
413+
def OBJC_UNRETAINEDPOINTER : RuntimeLibcall;
414+
def OBJC_RETAIN_AUTORELEASE : RuntimeLibcall;
415+
def OBJC_SYNC_ENTER : RuntimeLibcall;
416+
def OBJC_SYNC_EXIT : RuntimeLibcall;
417+
390418
//--------------------------------------------------------------------
391419
// Define implementation default libcalls
392420
//--------------------------------------------------------------------
@@ -1032,6 +1060,37 @@ defvar LibmHasSinCosF80 = LibcallImpls<(add sincos_f80), hasSinCos>;
10321060
defvar LibmHasSinCosF128 = LibcallImpls<(add sincos_f128), hasSinCos>;
10331061
defvar LibmHasSinCosPPCF128 = LibcallImpls<(add sincos_ppcf128), hasSinCos>;
10341062

1063+
//===----------------------------------------------------------------------===//
1064+
// Objective-C Runtime Libcalls
1065+
//===----------------------------------------------------------------------===//
1066+
1067+
def objc_autorelease : RuntimeLibcallImpl<OBJC_AUTORELEASE>;
1068+
def objc_autoreleasePoolPop : RuntimeLibcallImpl<OBJC_AUTORELEASEPOOLPOP>;
1069+
def objc_autoreleasePoolPush : RuntimeLibcallImpl<OBJC_AUTORELEASEPOOLPUSH>;
1070+
def objc_autoreleaseReturnValue : RuntimeLibcallImpl<OBJC_AUTORELEASERETURNVALUE>;
1071+
def objc_copyWeak : RuntimeLibcallImpl<OBJC_COPYWEAK>;
1072+
def objc_destroyWeak : RuntimeLibcallImpl<OBJC_DESTROYWEAK>;
1073+
def objc_initWeak : RuntimeLibcallImpl<OBJC_INITWEAK>;
1074+
def objc_loadWeak : RuntimeLibcallImpl<OBJC_LOADWEAK>;
1075+
def objc_loadWeakRetained : RuntimeLibcallImpl<OBJC_LOADWEAKRETAINED>;
1076+
def objc_moveWeak : RuntimeLibcallImpl<OBJC_MOVEWEAK>;
1077+
def objc_release : RuntimeLibcallImpl<OBJC_RELEASE>;
1078+
def objc_retain : RuntimeLibcallImpl<OBJC_RETAIN>;
1079+
def objc_retainAutorelease : RuntimeLibcallImpl<OBJC_RETAINAUTORELEASE>;
1080+
def objc_retainAutoreleaseReturnValue : RuntimeLibcallImpl<OBJC_RETAINAUTORELEASERETURNVALUE>;
1081+
def objc_retainAutoreleasedReturnValue : RuntimeLibcallImpl<OBJC_RETAINAUTORELEASEDRETURNVALUE>;
1082+
def objc_claimAutoreleasedReturnValue : RuntimeLibcallImpl<OBJC_CLAIMAUTORELEASEDRETURNVALUE>;
1083+
def objc_retainBlock : RuntimeLibcallImpl<OBJC_RETAINBLOCK>;
1084+
def objc_storeStrong : RuntimeLibcallImpl<OBJC_STORESTRONG>;
1085+
def objc_storeWeak : RuntimeLibcallImpl<OBJC_STOREWEAK>;
1086+
def objc_unsafeClaimAutoreleasedReturnValue : RuntimeLibcallImpl<OBJC_UNSAFECLAIMAUTORELEASEDRETURNVALUE>;
1087+
def objc_retainedObject : RuntimeLibcallImpl<OBJC_RETAINEDOBJECT>;
1088+
def objc_unretainedObject : RuntimeLibcallImpl<OBJC_UNRETAINEDOBJECT>;
1089+
def objc_unretainedPointer : RuntimeLibcallImpl<OBJC_UNRETAINEDPOINTER>;
1090+
def objc_retain_autorelease : RuntimeLibcallImpl<OBJC_RETAIN_AUTORELEASE>;
1091+
def objc_sync_enter : RuntimeLibcallImpl<OBJC_SYNC_ENTER>;
1092+
def objc_sync_exit : RuntimeLibcallImpl<OBJC_SYNC_EXIT>;
1093+
10351094
//===----------------------------------------------------------------------===//
10361095
// AArch64 Runtime Libcalls
10371096
//===----------------------------------------------------------------------===//

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/IR/Instructions.h"
2626
#include "llvm/IR/IntrinsicInst.h"
2727
#include "llvm/IR/Module.h"
28+
#include "llvm/IR/RuntimeLibcalls.h"
2829
#include "llvm/IR/Type.h"
2930
#include "llvm/IR/Use.h"
3031
#include "llvm/InitializePasses.h"
@@ -135,17 +136,22 @@ static CallInst::TailCallKind getOverridingTailCallKind(const Function &F) {
135136
return CallInst::TCK_None;
136137
}
137138

138-
static bool lowerObjCCall(Function &F, const char *NewFn,
139+
static bool lowerObjCCall(Function &F, RTLIB::LibcallImpl NewFn,
139140
bool setNonLazyBind = false) {
140141
assert(IntrinsicInst::mayLowerToFunctionCall(F.getIntrinsicID()) &&
141142
"Pre-ISel intrinsics do lower into regular function calls");
142143
if (F.use_empty())
143144
return false;
144145

146+
// FIXME: When RuntimeLibcalls is an analysis, check if the function is really
147+
// supported, and go through RTLIB::Libcall.
148+
const char *NewFnName = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(NewFn);
149+
145150
// If we haven't already looked up this function, check to see if the
146151
// program already contains a function with this name.
147152
Module *M = F.getParent();
148-
FunctionCallee FCache = M->getOrInsertFunction(NewFn, F.getFunctionType());
153+
FunctionCallee FCache =
154+
M->getOrInsertFunction(NewFnName, F.getFunctionType());
149155

150156
if (Function *Fn = dyn_cast<Function>(FCache.getCallee())) {
151157
Fn->setLinkage(F.getLinkage());
@@ -501,82 +507,83 @@ bool PreISelIntrinsicLowering::lowerIntrinsics(Module &M) const {
501507
});
502508
break;
503509
case Intrinsic::objc_autorelease:
504-
Changed |= lowerObjCCall(F, "objc_autorelease");
510+
Changed |= lowerObjCCall(F, RTLIB::objc_autorelease);
505511
break;
506512
case Intrinsic::objc_autoreleasePoolPop:
507-
Changed |= lowerObjCCall(F, "objc_autoreleasePoolPop");
513+
Changed |= lowerObjCCall(F, RTLIB::objc_autoreleasePoolPop);
508514
break;
509515
case Intrinsic::objc_autoreleasePoolPush:
510-
Changed |= lowerObjCCall(F, "objc_autoreleasePoolPush");
516+
Changed |= lowerObjCCall(F, RTLIB::objc_autoreleasePoolPush);
511517
break;
512518
case Intrinsic::objc_autoreleaseReturnValue:
513-
Changed |= lowerObjCCall(F, "objc_autoreleaseReturnValue");
519+
Changed |= lowerObjCCall(F, RTLIB::objc_autoreleaseReturnValue);
514520
break;
515521
case Intrinsic::objc_copyWeak:
516-
Changed |= lowerObjCCall(F, "objc_copyWeak");
522+
Changed |= lowerObjCCall(F, RTLIB::objc_copyWeak);
517523
break;
518524
case Intrinsic::objc_destroyWeak:
519-
Changed |= lowerObjCCall(F, "objc_destroyWeak");
525+
Changed |= lowerObjCCall(F, RTLIB::objc_destroyWeak);
520526
break;
521527
case Intrinsic::objc_initWeak:
522-
Changed |= lowerObjCCall(F, "objc_initWeak");
528+
Changed |= lowerObjCCall(F, RTLIB::objc_initWeak);
523529
break;
524530
case Intrinsic::objc_loadWeak:
525-
Changed |= lowerObjCCall(F, "objc_loadWeak");
531+
Changed |= lowerObjCCall(F, RTLIB::objc_loadWeak);
526532
break;
527533
case Intrinsic::objc_loadWeakRetained:
528-
Changed |= lowerObjCCall(F, "objc_loadWeakRetained");
534+
Changed |= lowerObjCCall(F, RTLIB::objc_loadWeakRetained);
529535
break;
530536
case Intrinsic::objc_moveWeak:
531-
Changed |= lowerObjCCall(F, "objc_moveWeak");
537+
Changed |= lowerObjCCall(F, RTLIB::objc_moveWeak);
532538
break;
533539
case Intrinsic::objc_release:
534-
Changed |= lowerObjCCall(F, "objc_release", true);
540+
Changed |= lowerObjCCall(F, RTLIB::objc_release, true);
535541
break;
536542
case Intrinsic::objc_retain:
537-
Changed |= lowerObjCCall(F, "objc_retain", true);
543+
Changed |= lowerObjCCall(F, RTLIB::objc_retain, true);
538544
break;
539545
case Intrinsic::objc_retainAutorelease:
540-
Changed |= lowerObjCCall(F, "objc_retainAutorelease");
546+
Changed |= lowerObjCCall(F, RTLIB::objc_retainAutorelease);
541547
break;
542548
case Intrinsic::objc_retainAutoreleaseReturnValue:
543-
Changed |= lowerObjCCall(F, "objc_retainAutoreleaseReturnValue");
549+
Changed |= lowerObjCCall(F, RTLIB::objc_retainAutoreleaseReturnValue);
544550
break;
545551
case Intrinsic::objc_retainAutoreleasedReturnValue:
546-
Changed |= lowerObjCCall(F, "objc_retainAutoreleasedReturnValue");
552+
Changed |= lowerObjCCall(F, RTLIB::objc_retainAutoreleasedReturnValue);
547553
break;
548554
case Intrinsic::objc_claimAutoreleasedReturnValue:
549-
Changed |= lowerObjCCall(F, "objc_claimAutoreleasedReturnValue");
555+
Changed |= lowerObjCCall(F, RTLIB::objc_claimAutoreleasedReturnValue);
550556
break;
551557
case Intrinsic::objc_retainBlock:
552-
Changed |= lowerObjCCall(F, "objc_retainBlock");
558+
Changed |= lowerObjCCall(F, RTLIB::objc_retainBlock);
553559
break;
554560
case Intrinsic::objc_storeStrong:
555-
Changed |= lowerObjCCall(F, "objc_storeStrong");
561+
Changed |= lowerObjCCall(F, RTLIB::objc_storeStrong);
556562
break;
557563
case Intrinsic::objc_storeWeak:
558-
Changed |= lowerObjCCall(F, "objc_storeWeak");
564+
Changed |= lowerObjCCall(F, RTLIB::objc_storeWeak);
559565
break;
560566
case Intrinsic::objc_unsafeClaimAutoreleasedReturnValue:
561-
Changed |= lowerObjCCall(F, "objc_unsafeClaimAutoreleasedReturnValue");
567+
Changed |=
568+
lowerObjCCall(F, RTLIB::objc_unsafeClaimAutoreleasedReturnValue);
562569
break;
563570
case Intrinsic::objc_retainedObject:
564-
Changed |= lowerObjCCall(F, "objc_retainedObject");
571+
Changed |= lowerObjCCall(F, RTLIB::objc_retainedObject);
565572
break;
566573
case Intrinsic::objc_unretainedObject:
567-
Changed |= lowerObjCCall(F, "objc_unretainedObject");
574+
Changed |= lowerObjCCall(F, RTLIB::objc_unretainedObject);
568575
break;
569576
case Intrinsic::objc_unretainedPointer:
570-
Changed |= lowerObjCCall(F, "objc_unretainedPointer");
577+
Changed |= lowerObjCCall(F, RTLIB::objc_unretainedPointer);
571578
break;
572579
case Intrinsic::objc_retain_autorelease:
573-
Changed |= lowerObjCCall(F, "objc_retain_autorelease");
580+
Changed |= lowerObjCCall(F, RTLIB::objc_retain_autorelease);
574581
break;
575582
case Intrinsic::objc_sync_enter:
576-
Changed |= lowerObjCCall(F, "objc_sync_enter");
583+
Changed |= lowerObjCCall(F, RTLIB::objc_sync_enter);
577584
break;
578585
case Intrinsic::objc_sync_exit:
579-
Changed |= lowerObjCCall(F, "objc_sync_exit");
586+
Changed |= lowerObjCCall(F, RTLIB::objc_sync_exit);
580587
break;
581588
case Intrinsic::exp:
582589
case Intrinsic::exp2:

0 commit comments

Comments
 (0)