Index: llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h =================================================================== --- llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h +++ llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h @@ -13,6 +13,7 @@ #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,6 +13,7 @@ #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,14 +12,13 @@ #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,6 +16,7 @@ #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,6 +9,7 @@ #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,6 +13,7 @@ #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,12 +13,11 @@ #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,6 +13,7 @@ #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,6 +15,7 @@ #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,12 +14,11 @@ #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,12 +52,11 @@ #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,6 +17,7 @@ #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,6 +14,7 @@ #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,6 +9,7 @@ #ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H #define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H +#include "llvm/IR/Instructions.h" #include "llvm/Support/AtomicOrdering.h" namespace llvm { @@ -16,7 +17,6 @@ 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,7 +61,11 @@ /// If only one value (besides the initializer constant) is ever stored to /// this global return the stored value. - Value *getStoredOnceValue() const; + Value *getStoredOnceValue() const { + return (StoredType == StoredOnce && StoredOnceStore) + ? StoredOnceStore->getOperand(0) + : nullptr; + } /// 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,8 +75,11 @@ bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class); -bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr, - ProvenanceAnalysis &PA); +static inline bool CanDecrementRefCount(const Instruction *Inst, + const Value *Ptr, + ProvenanceAnalysis &PA) { + return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst)); +} } // namespace objcarc } // namespace llvm Index: llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp +++ llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp @@ -24,7 +24,6 @@ #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; @@ -76,11 +75,6 @@ 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,15 +37,41 @@ /// so if it's such a call and the return value has users, replace them with the /// argument value. /// -void EraseInstruction(Instruction *CI); +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); +} /// If Inst is a ReturnRV and its operand is a call or invoke, return the /// operand. Otherwise return null. -const Instruction *getreturnRVOperand(const Instruction &Inst, - ARCInstKind Class); +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); +} /// 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()) { @@ -96,10 +122,33 @@ const DenseMap &BlockColors); /// See if an instruction is a bundled retainRV/claimRV call. - bool contains(const Instruction *I) const; + bool contains(const Instruction *I) const { + if (auto *CI = dyn_cast(I)) + return RVCalls.count(CI); + return false; + } /// Remove a retainRV/claimRV call entirely. - void eraseInst(CallInst *CI); + 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); + } 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,37 +43,6 @@ 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, @@ -144,34 +113,6 @@ 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,7 +26,6 @@ #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,7 +36,6 @@ #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,6 +15,7 @@ // //===----------------------------------------------------------------------===// +#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,12 +181,6 @@ 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,6 +11,7 @@ #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,6 +14,7 @@ //===----------------------------------------------------------------------===// #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"