7777#include " llvm/Support/DebugCounter.h"
7878#include " llvm/Support/ErrorHandling.h"
7979#include " llvm/Support/raw_ostream.h"
80+ #include " llvm/Transforms/Scalar.h"
8081#include " llvm/Transforms/Utils/AssumeBundleBuilder.h"
8182#include " llvm/Transforms/Utils/BuildLibCalls.h"
8283#include " llvm/Transforms/Utils/Local.h"
@@ -805,9 +806,8 @@ tryToMergePartialOverlappingStores(StoreInst *KillingI, StoreInst *DeadI,
805806 return nullptr ;
806807}
807808
808- namespace {
809809// Returns true if \p I is an intrinsic that does not read or write memory.
810- bool isNoopIntrinsic (Instruction *I) {
810+ static bool isNoopIntrinsic (Instruction *I) {
811811 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
812812 switch (II->getIntrinsicID ()) {
813813 case Intrinsic::lifetime_start:
@@ -828,7 +828,7 @@ bool isNoopIntrinsic(Instruction *I) {
828828}
829829
830830// Check if we can ignore \p D for DSE.
831- bool canSkipDef (MemoryDef *D, bool DefVisibleToCaller) {
831+ static bool canSkipDef (MemoryDef *D, bool DefVisibleToCaller) {
832832 Instruction *DI = D->getMemoryInst ();
833833 // Calls that only access inaccessible memory cannot read or write any memory
834834 // locations we consider for elimination.
@@ -856,6 +856,8 @@ bool canSkipDef(MemoryDef *D, bool DefVisibleToCaller) {
856856 return false ;
857857}
858858
859+ namespace {
860+
859861// A memory location wrapper that represents a MemoryLocation, `MemLoc`,
860862// defined by `MemDef`.
861863struct MemoryLocationWrapper {
@@ -889,23 +891,25 @@ struct MemoryDefWrapper {
889891 SmallVector<MemoryLocationWrapper, 1 > DefinedLocations;
890892};
891893
892- bool hasInitializesAttr (Instruction *I) {
893- CallBase *CB = dyn_cast<CallBase>(I);
894- return CB && CB->getArgOperandWithAttribute (Attribute::Initializes);
895- }
896-
897894struct ArgumentInitInfo {
898895 unsigned Idx;
899896 bool IsDeadOrInvisibleOnUnwind;
900897 ConstantRangeList Inits;
901898};
899+ } // namespace
900+
901+ static bool hasInitializesAttr (Instruction *I) {
902+ CallBase *CB = dyn_cast<CallBase>(I);
903+ return CB && CB->getArgOperandWithAttribute (Attribute::Initializes);
904+ }
902905
903906// Return the intersected range list of the initializes attributes of "Args".
904907// "Args" are call arguments that alias to each other.
905908// If any argument in "Args" doesn't have dead_on_unwind attr and
906909// "CallHasNoUnwindAttr" is false, return empty.
907- ConstantRangeList getIntersectedInitRangeList (ArrayRef<ArgumentInitInfo> Args,
908- bool CallHasNoUnwindAttr) {
910+ static ConstantRangeList
911+ getIntersectedInitRangeList (ArrayRef<ArgumentInitInfo> Args,
912+ bool CallHasNoUnwindAttr) {
909913 if (Args.empty ())
910914 return {};
911915
@@ -925,6 +929,8 @@ ConstantRangeList getIntersectedInitRangeList(ArrayRef<ArgumentInitInfo> Args,
925929 return IntersectedIntervals;
926930}
927931
932+ namespace {
933+
928934struct DSEState {
929935 Function &F;
930936 AliasAnalysis &AA;
@@ -2328,10 +2334,11 @@ struct DSEState {
23282334 // change state: whether make any change.
23292335 bool eliminateDeadDefs (const MemoryDefWrapper &KillingDefWrapper);
23302336};
2337+ } // namespace
23312338
23322339// Return true if "Arg" is function local and isn't captured before "CB".
2333- bool isFuncLocalAndNotCaptured (Value *Arg, const CallBase *CB,
2334- EarliestEscapeAnalysis &EA) {
2340+ static bool isFuncLocalAndNotCaptured (Value *Arg, const CallBase *CB,
2341+ EarliestEscapeAnalysis &EA) {
23352342 const Value *UnderlyingObj = getUnderlyingObject (Arg);
23362343 return isIdentifiedFunctionLocal (UnderlyingObj) &&
23372344 capturesNothing (
@@ -2627,7 +2634,6 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
26272634
26282635 return MadeChange;
26292636}
2630- } // end anonymous namespace
26312637
26322638// ===----------------------------------------------------------------------===//
26332639// DSE Pass
@@ -2728,8 +2734,6 @@ INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
27282734INITIALIZE_PASS_END(DSELegacyPass, " dse" , " Dead Store Elimination" , false ,
27292735 false )
27302736
2731- namespace llvm {
2732- LLVM_ABI FunctionPass *createDeadStoreEliminationPass () {
2737+ LLVM_ABI FunctionPass *llvm::createDeadStoreEliminationPass() {
27332738 return new DSELegacyPass ();
27342739}
2735- } // namespace llvm
0 commit comments