LLVM: lib/CodeGen/DroppedVariableStatsMIR.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

16

17using namespace llvm;

18

21 if (PassID == "Debug Variable Analysis")

22 return;

24 return runOnMachineFunction(MF, true);

25}

26

29 if (PassID == "Debug Variable Analysis")

30 return;

31 runOnMachineFunction(MF, false);

32 calculateDroppedVarStatsOnMachineFunction(MF, PassID, MF->getName().str());

34}

35

36void DroppedVariableStatsMIR::runOnMachineFunction(const MachineFunction *MF,

37 bool Before) {

39 auto FuncName = MF->getName();

40 MFunc = MF;

41 run(DebugVariables, FuncName, Before);

42}

43

44void DroppedVariableStatsMIR::calculateDroppedVarStatsOnMachineFunction(

46 MFunc = MF;

51 "MachineFunction", Func);

52}

53

54void DroppedVariableStatsMIR::visitEveryInstruction(

57 unsigned PrevDroppedCount = DroppedCount;

58 const DIScope *DbgValScope = std::get<0>(Var);

59 for (const auto &MBB : *MFunc) {

60 for (const auto &MI : MBB) {

61 if (MI.isDebugInstr()) {

62 auto *DbgLoc = MI.getDebugLoc().get();

63 if (!DbgLoc)

64 continue;

65

66 auto *Scope = DbgLoc->getScope();

67 if (updateDroppedCount(DbgLoc, Scope, DbgValScope, InlinedAtsMap, Var,

68 DroppedCount))

69 break;

70 }

71 }

72 if (PrevDroppedCount != DroppedCount) {

73 PrevDroppedCount = DroppedCount;

74 break;

75 }

76 }

77}

78

79void DroppedVariableStatsMIR::visitEveryDebugRecord(

82 StringRef FuncName, bool Before) {

83 for (const auto &MBB : *MFunc) {

84 for (const auto &MI : MBB) {

85 if (MI.isDebugValueLike()) {

86 auto *DbgVar = MI.getDebugVariable();

87 if (!DbgVar)

88 continue;

89 auto DbgLoc = MI.getDebugLoc();

91 FuncName, Before);

92 }

93 }

94 }

95}

===- DroppedVariableStatsMIR.h - Opt Diagnostics -*- C++ -*----------—===//

Implements a dense probed hash-table based set.

void runBeforePass(StringRef PassID, MachineFunction *MF)

Definition DroppedVariableStatsMIR.cpp:19

void runAfterPass(StringRef PassID, MachineFunction *MF)

Definition DroppedVariableStatsMIR.cpp:27

LLVM_ABI void calculateDroppedStatsAndPrint(DebugVariables &DbgVariables, StringRef FuncName, StringRef PassID, StringRef FuncOrModName, StringRef PassLevel, const Function *Func)

Calculate the number of dropped variables in an llvm::Function or llvm::MachineFunction and print the...

LLVM_ABI bool updateDroppedCount(DILocation *DbgLoc, const DIScope *Scope, const DIScope *DbgValScope, DenseMap< VarID, DILocation * > &InlinedAtsMap, VarID Var, unsigned &DroppedCount)

Check if a Var has been dropped or is a false positive.

LLVM_ABI void populateVarIDSetAndInlinedMap(const DILocalVariable *DbgVar, DebugLoc DbgLoc, DenseSet< VarID > &VarIDSet, DenseMap< StringRef, DenseMap< VarID, DILocation * > > &InlinedAtsMap, StringRef FuncName, bool Before)

Populate the VarIDSet and InlinedAtMap with the relevant information needed for before and after pass...

SmallVector< DenseMap< const Function *, DebugVariables > > DebugVariablesStack

A stack of a DenseMap, that maps DebugVariables for every pass to an llvm::Function.

LLVM_ABI void run(DebugVariables &DbgVariables, StringRef FuncName, bool Before)

Run code to populate relevant data structures over an llvm::Function or llvm::MachineFunction.

const BasicBlock & back() const

StringRef getName() const

getName - Return the name of the corresponding LLVM function.

Function & getFunction()

Return the LLVM function that this machine code represents.

StringRef - Represent a constant reference to a string, i.e.

std::string str() const

str - Get the contents as an std::string.

Scope

Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...

This is an optimization pass for GlobalISel generic memory operations.

std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID

A unique key that represents a debug variable.