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,7 @@ bool canSkipDef(MemoryDef *D, bool DefVisibleToCaller) {
856856 return false ;
857857}
858858
859+ namespace {
859860// A memory location wrapper that represents a MemoryLocation, `MemLoc`,
860861// defined by `MemDef`.
861862struct MemoryLocationWrapper {
@@ -889,23 +890,25 @@ struct MemoryDefWrapper {
889890 SmallVector<MemoryLocationWrapper, 1 > DefinedLocations;
890891};
891892
892- bool hasInitializesAttr (Instruction *I) {
893- CallBase *CB = dyn_cast<CallBase>(I);
894- return CB && CB->getArgOperandWithAttribute (Attribute::Initializes);
895- }
896-
897893struct ArgumentInitInfo {
898894 unsigned Idx;
899895 bool IsDeadOrInvisibleOnUnwind;
900896 ConstantRangeList Inits;
901897};
898+ } // namespace
899+
900+ static bool hasInitializesAttr (Instruction *I) {
901+ CallBase *CB = dyn_cast<CallBase>(I);
902+ return CB && CB->getArgOperandWithAttribute (Attribute::Initializes);
903+ }
902904
903905// Return the intersected range list of the initializes attributes of "Args".
904906// "Args" are call arguments that alias to each other.
905907// If any argument in "Args" doesn't have dead_on_unwind attr and
906908// "CallHasNoUnwindAttr" is false, return empty.
907- ConstantRangeList getIntersectedInitRangeList (ArrayRef<ArgumentInitInfo> Args,
908- bool CallHasNoUnwindAttr) {
909+ static ConstantRangeList
910+ getIntersectedInitRangeList (ArrayRef<ArgumentInitInfo> Args,
911+ bool CallHasNoUnwindAttr) {
909912 if (Args.empty ())
910913 return {};
911914
@@ -925,6 +928,7 @@ ConstantRangeList getIntersectedInitRangeList(ArrayRef<ArgumentInitInfo> Args,
925928 return IntersectedIntervals;
926929}
927930
931+ namespace {
928932struct DSEState {
929933 Function &F;
930934 AliasAnalysis &AA;
@@ -2328,10 +2332,11 @@ struct DSEState {
23282332 // change state: whether make any change.
23292333 bool eliminateDeadDefs (const MemoryDefWrapper &KillingDefWrapper);
23302334};
2335+ } // namespace
23312336
23322337// Return true if "Arg" is function local and isn't captured before "CB".
2333- bool isFuncLocalAndNotCaptured (Value *Arg, const CallBase *CB,
2334- EarliestEscapeAnalysis &EA) {
2338+ static bool isFuncLocalAndNotCaptured (Value *Arg, const CallBase *CB,
2339+ EarliestEscapeAnalysis &EA) {
23352340 const Value *UnderlyingObj = getUnderlyingObject (Arg);
23362341 return isIdentifiedFunctionLocal (UnderlyingObj) &&
23372342 capturesNothing (
@@ -2627,7 +2632,6 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
26272632
26282633 return MadeChange;
26292634}
2630- } // end anonymous namespace
26312635
26322636// ===----------------------------------------------------------------------===//
26332637// DSE Pass
@@ -2728,8 +2732,6 @@ INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
27282732INITIALIZE_PASS_END(DSELegacyPass, " dse" , " Dead Store Elimination" , false ,
27292733 false )
27302734
2731- namespace llvm {
2732- LLVM_ABI FunctionPass *createDeadStoreEliminationPass () {
2735+ LLVM_ABI FunctionPass *llvm::createDeadStoreEliminationPass() {
27332736 return new DSELegacyPass ();
27342737}
2735- } // namespace llvm
0 commit comments