LLVM: lib/Transforms/Scalar/InstSimplifyPass.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

21

22using namespace llvm;

23

24#define DEBUG_TYPE "instsimplify"

25

26STATISTIC(NumSimplified, "Number of redundant instructions removed");

27

31

32 do {

34

35

37 continue;

38

41

42

43

44 if (!ToSimplify->empty() && !ToSimplify->count(&I))

45 continue;

46

47

51 } else if (I.use_empty()) {

53

54 for (User *U : I.users())

56 I.replaceAllUsesWith(V);

57 ++NumSimplified;

59

62 }

63 }

64 }

66 }

67

68

69

71 Next->clear();

72 } while (!ToSimplify->empty());

73

75}

76

77namespace {

78struct InstSimplifyLegacyPass : public FunctionPass {

79 static char ID;

80 InstSimplifyLegacyPass() : FunctionPass(ID) {

82 }

83

84 void getAnalysisUsage(AnalysisUsage &AU) const override {

86 AU.addRequired();

88 AU.addRequired();

89 }

90

91

93 if (skipFunction(F))

94 return false;

95

96 const DominatorTree *DT =

97 &getAnalysis().getDomTree();

98 const TargetLibraryInfo *TLI =

99 &getAnalysis().getTLI(F);

100 AssumptionCache *AC =

101 &getAnalysis().getAssumptionCache(F);

102 const DataLayout &DL = F.getDataLayout();

103 const SimplifyQuery SQ(DL, TLI, DT, AC);

105 }

106};

107}

108

109char InstSimplifyLegacyPass::ID = 0;

111 "Remove redundant instructions", false, false)

117

118

120 return new InstSimplifyLegacyPass();

121}

122

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static bool runOnFunction(Function &F, bool PostInlining)

static bool runImpl(Function &F, const TargetLowering &TLI, const LibcallLoweringInfo &Libcalls, AssumptionCache *AC)

static bool runImpl(Function &F, const SimplifyQuery &SQ)

Definition InstSimplifyPass.cpp:28

Defines passes for running instruction simplification across chunks of IR.

#define INITIALIZE_PASS_DEPENDENCY(depName)

#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)

#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)

This file defines the SmallPtrSet class.

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

AnalysisUsage & addRequired()

LLVM_ABI void setPreservesCFG()

This function should be called by the pass, iff they do not:

A function analysis which provides an AssumptionCache.

An immutable pass that tracks lazily created AssumptionCache objects.

LLVM Basic Block Representation.

Represents analyses that only rely on functions' control flow.

A parsed version of the target data layout string in and methods for querying it.

Analysis pass which computes a DominatorTree.

Legacy analysis pass which computes a DominatorTree.

LLVM_ABI bool isReachableFromEntry(const Use &U) const

Provide an overload for a Use.

FunctionPass class - This class is used to implement most global optimizations.

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)

Definition InstSimplifyPass.cpp:123

static LLVM_ABI PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalyses & preserveSet()

Mark an analysis set as preserved.

size_type count(ConstPtrType Ptr) const

count - Return 1 if the specified pointer is in the set, 0 otherwise.

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Analysis pass providing the TargetLibraryInfo.

LLVM Value Representation.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())

If the specified value is a trivially dead instruction, delete it.

LLVM_ABI void initializeInstSimplifyLegacyPassPass(PassRegistry &)

LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)

See if we can compute a simplified version of this instruction.

LLVM_ABI bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)

Return true if the result produced by the instruction is not used, and the instruction will return.

FunctionAddr VTableAddr Next

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.

LLVM_ABI FunctionPass * createInstSimplifyLegacyPass()

Definition InstSimplifyPass.cpp:119

void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)

Implement std::swap in terms of BitVector swap.

const TargetLibraryInfo * TLI