Index: llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h =================================================================== --- llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h +++ llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h @@ -13,7 +13,6 @@ #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H #define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H -#include "llvm/IR/Function.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" Index: llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h =================================================================== --- llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h +++ llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h @@ -13,7 +13,6 @@ #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H #define LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" Index: llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h =================================================================== --- llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h +++ llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h @@ -12,13 +12,14 @@ #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H #define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H -#include "llvm/IR/Function.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" namespace llvm { +class Function; + /// Public interface to the memory profiler pass for instrumenting code to /// profile memory accesses. /// Index: llvm/include/llvm/Transforms/Scalar/BDCE.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/BDCE.h +++ llvm/include/llvm/Transforms/Scalar/BDCE.h @@ -16,7 +16,6 @@ #ifndef LLVM_TRANSFORMS_SCALAR_BDCE_H #define LLVM_TRANSFORMS_SCALAR_BDCE_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { Index: llvm/include/llvm/Transforms/Scalar/CallSiteSplitting.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/CallSiteSplitting.h +++ llvm/include/llvm/Transforms/Scalar/CallSiteSplitting.h @@ -9,7 +9,6 @@ #ifndef LLVM_TRANSFORMS_SCALAR_CALLSITESPLITTING_H #define LLVM_TRANSFORMS_SCALAR_CALLSITESPLITTING_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { Index: llvm/include/llvm/Transforms/Scalar/DCE.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/DCE.h +++ llvm/include/llvm/Transforms/Scalar/DCE.h @@ -13,7 +13,6 @@ #ifndef LLVM_TRANSFORMS_SCALAR_DCE_H #define LLVM_TRANSFORMS_SCALAR_DCE_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { Index: llvm/include/llvm/Transforms/Scalar/DFAJumpThreading.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/DFAJumpThreading.h +++ llvm/include/llvm/Transforms/Scalar/DFAJumpThreading.h @@ -13,11 +13,12 @@ #ifndef LLVM_TRANSFORMS_SCALAR_DFAJUMPTHREADING_H #define LLVM_TRANSFORMS_SCALAR_DFAJUMPTHREADING_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { +class Function; + struct DFAJumpThreadingPass : PassInfoMixin { PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; Index: llvm/include/llvm/Transforms/Scalar/LoopDataPrefetch.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/LoopDataPrefetch.h +++ llvm/include/llvm/Transforms/Scalar/LoopDataPrefetch.h @@ -13,7 +13,6 @@ #ifndef LLVM_TRANSFORMS_SCALAR_LOOPDATAPREFETCH_H #define LLVM_TRANSFORMS_SCALAR_LOOPDATAPREFETCH_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { Index: llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h +++ llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h @@ -15,7 +15,6 @@ #ifndef LLVM_TRANSFORMS_SCALAR_LOWEREXPECTINTRINSIC_H #define LLVM_TRANSFORMS_SCALAR_LOWEREXPECTINTRINSIC_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { Index: llvm/include/llvm/Transforms/Scalar/Sink.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/Sink.h +++ llvm/include/llvm/Transforms/Scalar/Sink.h @@ -14,11 +14,12 @@ #ifndef LLVM_TRANSFORMS_SCALAR_SINK_H #define LLVM_TRANSFORMS_SCALAR_SINK_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { +class Function; + /// Move instructions into successor blocks when possible. class SinkingPass : public PassInfoMixin { public: Index: llvm/include/llvm/Transforms/Scalar/TailRecursionElimination.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/TailRecursionElimination.h +++ llvm/include/llvm/Transforms/Scalar/TailRecursionElimination.h @@ -52,11 +52,12 @@ #ifndef LLVM_TRANSFORMS_SCALAR_TAILRECURSIONELIMINATION_H #define LLVM_TRANSFORMS_SCALAR_TAILRECURSIONELIMINATION_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { +class Function; + struct TailCallElimPass : PassInfoMixin { PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; Index: llvm/include/llvm/Transforms/Utils/BreakCriticalEdges.h =================================================================== --- llvm/include/llvm/Transforms/Utils/BreakCriticalEdges.h +++ llvm/include/llvm/Transforms/Utils/BreakCriticalEdges.h @@ -17,7 +17,6 @@ #ifndef LLVM_TRANSFORMS_UTILS_BREAKCRITICALEDGES_H #define LLVM_TRANSFORMS_UTILS_BREAKCRITICALEDGES_H -#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" namespace llvm { Index: llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h =================================================================== --- llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h +++ llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h @@ -14,7 +14,6 @@ #ifndef LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H #define LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H -#include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" namespace llvm { Index: llvm/include/llvm/Transforms/Utils/GlobalStatus.h =================================================================== --- llvm/include/llvm/Transforms/Utils/GlobalStatus.h +++ llvm/include/llvm/Transforms/Utils/GlobalStatus.h @@ -9,7 +9,6 @@ #ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H #define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H -#include "llvm/IR/Instructions.h" #include "llvm/Support/AtomicOrdering.h" namespace llvm { @@ -17,6 +16,7 @@ class Constant; class Function; class Value; +class StoreInst; /// It is safe to destroy a constant iff it is only used by constants itself. /// Note that constants cannot be cyclic, so this test is pretty easy to @@ -61,11 +61,7 @@ /// If only one value (besides the initializer constant) is ever stored to /// this global return the stored value. - Value *getStoredOnceValue() const { - return (StoredType == StoredOnce && StoredOnceStore) - ? StoredOnceStore->getOperand(0) - : nullptr; - } + Value *getStoredOnceValue() const; /// These start out null/false. When the first accessing function is noticed, /// it is recorded. When a second different accessing function is noticed, Index: llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h =================================================================== --- llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h +++ llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h @@ -75,11 +75,8 @@ bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class); -static inline bool CanDecrementRefCount(const Instruction *Inst, - const Value *Ptr, - ProvenanceAnalysis &PA) { - return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst)); -} +bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr, + ProvenanceAnalysis &PA); } // namespace objcarc } // namespace llvm Index: llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp +++ llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp @@ -24,6 +24,7 @@ #include "ProvenanceAnalysis.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/IR/CFG.h" +#include "llvm/IR/Instructions.h" using namespace llvm; using namespace llvm::objcarc; @@ -75,6 +76,12 @@ return CanAlterRefCount(Inst, Ptr, PA, Class); } +bool llvm::objcarc::CanDecrementRefCount(const Instruction *Inst, + const Value *Ptr, + ProvenanceAnalysis &PA) { + return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst)); +} + /// Test whether the given instruction can "use" the given pointer's object in a /// way that requires the reference count to be positive. bool llvm::objcarc::CanUse(const Instruction *Inst, const Value *Ptr, Index: llvm/lib/Transforms/ObjCARC/ObjCARC.h =================================================================== --- llvm/lib/Transforms/ObjCARC/ObjCARC.h +++ llvm/lib/Transforms/ObjCARC/ObjCARC.h @@ -37,41 +37,15 @@ /// so if it's such a call and the return value has users, replace them with the /// argument value. /// -static inline void EraseInstruction(Instruction *CI) { - Value *OldArg = cast(CI)->getArgOperand(0); - - bool Unused = CI->use_empty(); - - if (!Unused) { - // Replace the return value with the argument. - assert((IsForwarding(GetBasicARCInstKind(CI)) || - (IsNoopOnNull(GetBasicARCInstKind(CI)) && - IsNullOrUndef(OldArg->stripPointerCasts()))) && - "Can't delete non-forwarding instruction with users!"); - CI->replaceAllUsesWith(OldArg); - } - - CI->eraseFromParent(); - - if (Unused) - RecursivelyDeleteTriviallyDeadInstructions(OldArg); -} +void EraseInstruction(Instruction *CI); /// If Inst is a ReturnRV and its operand is a call or invoke, return the /// operand. Otherwise return null. -static inline const Instruction *getreturnRVOperand(const Instruction &Inst, - ARCInstKind Class) { - if (Class != ARCInstKind::RetainRV) - return nullptr; - - const auto *Opnd = Inst.getOperand(0)->stripPointerCasts(); - if (const auto *C = dyn_cast(Opnd)) - return C; - return dyn_cast(Opnd); -} +const Instruction *getreturnRVOperand(const Instruction &Inst, + ARCInstKind Class); /// Return the list of PHI nodes that are equivalent to PN. -template +template void getEquivalentPHIs(PHINodeTy &PN, VectorTy &PHIList) { auto *BB = PN.getParent(); for (auto &P : BB->phis()) { @@ -122,33 +96,10 @@ const DenseMap &BlockColors); /// See if an instruction is a bundled retainRV/claimRV call. - bool contains(const Instruction *I) const { - if (auto *CI = dyn_cast(I)) - return RVCalls.count(CI); - return false; - } + bool contains(const Instruction *I) const; /// Remove a retainRV/claimRV call entirely. - void eraseInst(CallInst *CI) { - auto It = RVCalls.find(CI); - if (It != RVCalls.end()) { - // Remove call to @llvm.objc.clang.arc.noop.use. - for (auto U = It->second->user_begin(), E = It->second->user_end(); U != E; ++U) - if (auto *CI = dyn_cast(*U)) - if (CI->getIntrinsicID() == Intrinsic::objc_clang_arc_noop_use) { - CI->eraseFromParent(); - break; - } - - auto *NewCall = CallBase::removeOperandBundle( - It->second, LLVMContext::OB_clang_arc_attachedcall, It->second); - NewCall->copyMetadata(*It->second); - It->second->replaceAllUsesWith(NewCall); - It->second->eraseFromParent(); - RVCalls.erase(It); - } - EraseInstruction(CI); - } + void eraseInst(CallInst *CI); private: /// A map of inserted retainRV/claimRV calls to annotated calls/invokes. Index: llvm/lib/Transforms/ObjCARC/ObjCARC.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/ObjCARC.cpp +++ llvm/lib/Transforms/ObjCARC/ObjCARC.cpp @@ -43,6 +43,37 @@ initializeObjCARCOpts(*unwrap(R)); } +void objcarc::EraseInstruction(Instruction *CI) { + Value *OldArg = cast(CI)->getArgOperand(0); + + bool Unused = CI->use_empty(); + + if (!Unused) { + // Replace the return value with the argument. + assert((IsForwarding(GetBasicARCInstKind(CI)) || + (IsNoopOnNull(GetBasicARCInstKind(CI)) && + IsNullOrUndef(OldArg->stripPointerCasts()))) && + "Can't delete non-forwarding instruction with users!"); + CI->replaceAllUsesWith(OldArg); + } + + CI->eraseFromParent(); + + if (Unused) + RecursivelyDeleteTriviallyDeadInstructions(OldArg); +} + +const Instruction *objcarc::getreturnRVOperand(const Instruction &Inst, + ARCInstKind Class) { + if (Class != ARCInstKind::RetainRV) + return nullptr; + + const auto *Opnd = Inst.getOperand(0)->stripPointerCasts(); + if (const auto *C = dyn_cast(Opnd)) + return C; + return dyn_cast(Opnd); +} + CallInst *objcarc::createCallInstWithColors( FunctionCallee Func, ArrayRef Args, const Twine &NameStr, Instruction *InsertBefore, @@ -113,6 +144,34 @@ return Call; } +bool BundledRetainClaimRVs::contains(const Instruction *I) const { + if (auto *CI = dyn_cast(I)) + return RVCalls.count(CI); + return false; +} + +void BundledRetainClaimRVs::eraseInst(CallInst *CI) { + auto It = RVCalls.find(CI); + if (It != RVCalls.end()) { + // Remove call to @llvm.objc.clang.arc.noop.use. + for (auto U = It->second->user_begin(), E = It->second->user_end(); U != E; + ++U) + if (auto *CI = dyn_cast(*U)) + if (CI->getIntrinsicID() == Intrinsic::objc_clang_arc_noop_use) { + CI->eraseFromParent(); + break; + } + + auto *NewCall = CallBase::removeOperandBundle( + It->second, LLVMContext::OB_clang_arc_attachedcall, It->second); + NewCall->copyMetadata(*It->second); + It->second->replaceAllUsesWith(NewCall); + It->second->eraseFromParent(); + RVCalls.erase(It); + } + EraseInstruction(CI); +} + BundledRetainClaimRVs::~BundledRetainClaimRVs() { for (auto P : RVCalls) { if (ContractPass) { Index: llvm/lib/Transforms/ObjCARC/ObjCARCAPElim.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/ObjCARCAPElim.cpp +++ llvm/lib/Transforms/ObjCARC/ObjCARCAPElim.cpp @@ -26,6 +26,7 @@ #include "ObjCARC.h" #include "llvm/ADT/STLExtras.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/PassManager.h" #include "llvm/InitializePasses.h" #include "llvm/Support/Debug.h" Index: llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -36,6 +36,7 @@ #include "llvm/IR/Dominators.h" #include "llvm/IR/InlineAsm.h" #include "llvm/IR/InstIterator.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/Operator.h" #include "llvm/IR/PassManager.h" #include "llvm/InitializePasses.h" Index: llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp =================================================================== --- llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp +++ llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp @@ -15,7 +15,6 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/Instructions.h" #include "llvm/InitializePasses.h" #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h" #include "llvm/ADT/SmallPtrSet.h" Index: llvm/lib/Transforms/Utils/GlobalStatus.cpp =================================================================== --- llvm/lib/Transforms/Utils/GlobalStatus.cpp +++ llvm/lib/Transforms/Utils/GlobalStatus.cpp @@ -181,6 +181,12 @@ return false; } +Value *GlobalStatus::getStoredOnceValue() const { + return (StoredType == StoredOnce && StoredOnceStore) + ? StoredOnceStore->getOperand(0) + : nullptr; +} + GlobalStatus::GlobalStatus() = default; bool GlobalStatus::analyzeGlobal(const Value *V, GlobalStatus &GS) { Index: llvm/lib/Transforms/Utils/GuardUtils.cpp =================================================================== --- llvm/lib/Transforms/Utils/GuardUtils.cpp +++ llvm/lib/Transforms/Utils/GuardUtils.cpp @@ -11,7 +11,6 @@ #include "llvm/Transforms/Utils/GuardUtils.h" #include "llvm/Analysis/GuardUtils.h" -#include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/MDBuilder.h" Index: llvm/lib/Transforms/Utils/IntegerDivision.cpp =================================================================== --- llvm/lib/Transforms/Utils/IntegerDivision.cpp +++ llvm/lib/Transforms/Utils/IntegerDivision.cpp @@ -14,7 +14,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Utils/IntegerDivision.h" -#include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h"