mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 22:28:18 +00:00
[objc-arc] Move initialization of ARCMDKindCache into the class itself. I also made it lazy.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232348 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
~ARCRuntimeEntryPoints() { }
|
~ARCRuntimeEntryPoints() { }
|
||||||
|
|
||||||
void Initialize(Module *M) {
|
void init(Module *M) {
|
||||||
TheModule = M;
|
TheModule = M;
|
||||||
AutoreleaseRV = nullptr;
|
AutoreleaseRV = nullptr;
|
||||||
Release = nullptr;
|
Release = nullptr;
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#define LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
|
#define LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
|
||||||
|
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
#include "llvm/ADT/StringSwitch.h"
|
||||||
|
#include "llvm/ADT/Optional.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/Passes.h"
|
#include "llvm/Analysis/Passes.h"
|
||||||
#include "llvm/Analysis/ValueTracking.h"
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
@@ -258,16 +259,52 @@ static inline bool IsObjCIdentifiedObject(const Value *V) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ARCMDKindID {
|
||||||
|
ImpreciseRelease,
|
||||||
|
CopyOnEscape,
|
||||||
|
NoObjCARCExceptions,
|
||||||
|
};
|
||||||
|
|
||||||
/// A cache of MDKinds used by various ARC optimizations.
|
/// A cache of MDKinds used by various ARC optimizations.
|
||||||
struct ARCMDKindCache {
|
class ARCMDKindCache {
|
||||||
|
Module *M;
|
||||||
|
|
||||||
/// The Metadata Kind for clang.imprecise_release metadata.
|
/// The Metadata Kind for clang.imprecise_release metadata.
|
||||||
unsigned ImpreciseReleaseMDKind;
|
llvm::Optional<unsigned> ImpreciseReleaseMDKind;
|
||||||
|
|
||||||
/// The Metadata Kind for clang.arc.copy_on_escape metadata.
|
/// The Metadata Kind for clang.arc.copy_on_escape metadata.
|
||||||
unsigned CopyOnEscapeMDKind;
|
llvm::Optional<unsigned> CopyOnEscapeMDKind;
|
||||||
|
|
||||||
/// The Metadata Kind for clang.arc.no_objc_arc_exceptions metadata.
|
/// The Metadata Kind for clang.arc.no_objc_arc_exceptions metadata.
|
||||||
unsigned NoObjCARCExceptionsMDKind;
|
llvm::Optional<unsigned> NoObjCARCExceptionsMDKind;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init(Module *Mod) {
|
||||||
|
M = Mod;
|
||||||
|
ImpreciseReleaseMDKind = NoneType::None;
|
||||||
|
CopyOnEscapeMDKind = NoneType::None;
|
||||||
|
NoObjCARCExceptionsMDKind = NoneType::None;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned get(ARCMDKindID ID) {
|
||||||
|
switch (ID) {
|
||||||
|
case ARCMDKindID::ImpreciseRelease:
|
||||||
|
if (!ImpreciseReleaseMDKind)
|
||||||
|
ImpreciseReleaseMDKind =
|
||||||
|
M->getContext().getMDKindID("clang.imprecise_release");
|
||||||
|
return *ImpreciseReleaseMDKind;
|
||||||
|
case ARCMDKindID::CopyOnEscape:
|
||||||
|
if (!CopyOnEscapeMDKind)
|
||||||
|
CopyOnEscapeMDKind =
|
||||||
|
M->getContext().getMDKindID("clang.arc.copy_on_escape");
|
||||||
|
return *CopyOnEscapeMDKind;
|
||||||
|
case ARCMDKindID::NoObjCARCExceptions:
|
||||||
|
if (!NoObjCARCExceptionsMDKind)
|
||||||
|
NoObjCARCExceptionsMDKind =
|
||||||
|
M->getContext().getMDKindID("clang.arc.no_objc_arc_exceptions");
|
||||||
|
return *NoObjCARCExceptionsMDKind;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace objcarc
|
} // end namespace objcarc
|
||||||
|
@@ -647,7 +647,7 @@ bool ObjCARCContract::doInitialization(Module &M) {
|
|||||||
if (!Run)
|
if (!Run)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EP.Initialize(&M);
|
EP.init(&M);
|
||||||
|
|
||||||
// Initialize RetainRVMarker.
|
// Initialize RetainRVMarker.
|
||||||
RetainRVMarker = nullptr;
|
RetainRVMarker = nullptr;
|
||||||
|
@@ -712,7 +712,7 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) {
|
|||||||
Constant *Decl = EP.get(ARCRuntimeEntryPointKind::Release);
|
Constant *Decl = EP.get(ARCRuntimeEntryPointKind::Release);
|
||||||
CallInst *NewCall = CallInst::Create(Decl, Call->getArgOperand(0), "",
|
CallInst *NewCall = CallInst::Create(Decl, Call->getArgOperand(0), "",
|
||||||
Call);
|
Call);
|
||||||
NewCall->setMetadata(MDKindCache.ImpreciseReleaseMDKind,
|
NewCall->setMetadata(MDKindCache.get(ARCMDKindID::ImpreciseRelease),
|
||||||
MDNode::get(C, None));
|
MDNode::get(C, None));
|
||||||
|
|
||||||
DEBUG(dbgs() << "Replacing autorelease{,RV}(x) with objc_release(x) "
|
DEBUG(dbgs() << "Replacing autorelease{,RV}(x) with objc_release(x) "
|
||||||
@@ -1379,7 +1379,8 @@ bool ObjCARCOpt::Visit(Function &F,
|
|||||||
SmallVector<BasicBlock *, 16> PostOrder;
|
SmallVector<BasicBlock *, 16> PostOrder;
|
||||||
SmallVector<BasicBlock *, 16> ReverseCFGPostOrder;
|
SmallVector<BasicBlock *, 16> ReverseCFGPostOrder;
|
||||||
ComputePostOrders(F, PostOrder, ReverseCFGPostOrder,
|
ComputePostOrders(F, PostOrder, ReverseCFGPostOrder,
|
||||||
MDKindCache.NoObjCARCExceptionsMDKind, BBStates);
|
MDKindCache.get(ARCMDKindID::NoObjCARCExceptions),
|
||||||
|
BBStates);
|
||||||
|
|
||||||
// Use reverse-postorder on the reverse CFG for bottom-up.
|
// Use reverse-postorder on the reverse CFG for bottom-up.
|
||||||
bool BottomUpNestingDetected = false;
|
bool BottomUpNestingDetected = false;
|
||||||
@@ -1429,7 +1430,7 @@ void ObjCARCOpt::MoveCalls(Value *Arg, RRInfo &RetainsToMove,
|
|||||||
CallInst *Call = CallInst::Create(Decl, MyArg, "", InsertPt);
|
CallInst *Call = CallInst::Create(Decl, MyArg, "", InsertPt);
|
||||||
// Attach a clang.imprecise_release metadata tag, if appropriate.
|
// Attach a clang.imprecise_release metadata tag, if appropriate.
|
||||||
if (MDNode *M = ReleasesToMove.ReleaseMetadata)
|
if (MDNode *M = ReleasesToMove.ReleaseMetadata)
|
||||||
Call->setMetadata(MDKindCache.ImpreciseReleaseMDKind, M);
|
Call->setMetadata(MDKindCache.get(ARCMDKindID::ImpreciseRelease), M);
|
||||||
Call->setDoesNotThrow();
|
Call->setDoesNotThrow();
|
||||||
if (ReleasesToMove.IsTailCallRelease)
|
if (ReleasesToMove.IsTailCallRelease)
|
||||||
Call->setTailCall();
|
Call->setTailCall();
|
||||||
@@ -2098,20 +2099,13 @@ bool ObjCARCOpt::doInitialization(Module &M) {
|
|||||||
if (!Run)
|
if (!Run)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Identify the imprecise release metadata kind.
|
|
||||||
MDKindCache.ImpreciseReleaseMDKind =
|
|
||||||
M.getContext().getMDKindID("clang.imprecise_release");
|
|
||||||
MDKindCache.CopyOnEscapeMDKind =
|
|
||||||
M.getContext().getMDKindID("clang.arc.copy_on_escape");
|
|
||||||
MDKindCache.NoObjCARCExceptionsMDKind =
|
|
||||||
M.getContext().getMDKindID("clang.arc.no_objc_arc_exceptions");
|
|
||||||
|
|
||||||
// Intuitively, objc_retain and others are nocapture, however in practice
|
// Intuitively, objc_retain and others are nocapture, however in practice
|
||||||
// they are not, because they return their argument value. And objc_release
|
// they are not, because they return their argument value. And objc_release
|
||||||
// calls finalizers which can have arbitrary side effects.
|
// calls finalizers which can have arbitrary side effects.
|
||||||
|
MDKindCache.init(&M);
|
||||||
|
|
||||||
// Initialize our runtime entry point cache.
|
// Initialize our runtime entry point cache.
|
||||||
EP.Initialize(&M);
|
EP.init(&M);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -174,7 +174,8 @@ bool BottomUpPtrState::InitBottomUp(ARCMDKindCache &Cache, Instruction *I) {
|
|||||||
NestingDetected = true;
|
NestingDetected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDNode *ReleaseMetadata = I->getMetadata(Cache.ImpreciseReleaseMDKind);
|
MDNode *ReleaseMetadata =
|
||||||
|
I->getMetadata(Cache.get(ARCMDKindID::ImpreciseRelease));
|
||||||
Sequence NewSeq = ReleaseMetadata ? S_MovableRelease : S_Release;
|
Sequence NewSeq = ReleaseMetadata ? S_MovableRelease : S_Release;
|
||||||
ResetSequenceProgress(NewSeq);
|
ResetSequenceProgress(NewSeq);
|
||||||
SetReleaseMetadata(ReleaseMetadata);
|
SetReleaseMetadata(ReleaseMetadata);
|
||||||
@@ -319,7 +320,8 @@ bool TopDownPtrState::MatchWithRelease(ARCMDKindCache &Cache,
|
|||||||
|
|
||||||
Sequence OldSeq = GetSeq();
|
Sequence OldSeq = GetSeq();
|
||||||
|
|
||||||
MDNode *ReleaseMetadata = Release->getMetadata(Cache.ImpreciseReleaseMDKind);
|
MDNode *ReleaseMetadata =
|
||||||
|
Release->getMetadata(Cache.get(ARCMDKindID::ImpreciseRelease));
|
||||||
|
|
||||||
switch (OldSeq) {
|
switch (OldSeq) {
|
||||||
case S_Retain:
|
case S_Retain:
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace objcarc {
|
namespace objcarc {
|
||||||
|
|
||||||
struct ARCMDKindCache;
|
class ARCMDKindCache;
|
||||||
class ProvenanceAnalysis;
|
class ProvenanceAnalysis;
|
||||||
|
|
||||||
/// \enum Sequence
|
/// \enum Sequence
|
||||||
|
Reference in New Issue
Block a user