[SystemZ] Fix compile time regression in adjustInliningThreshold(). (… · llvm/llvm-project@02afcbf (original) (raw)

`@@ -18,6 +18,7 @@

`

18

18

`#include "llvm/CodeGen/BasicTTIImpl.h"

`

19

19

`#include "llvm/CodeGen/TargetLowering.h"

`

20

20

`#include "llvm/IR/DerivedTypes.h"

`

``

21

`+

#include "llvm/IR/InstIterator.h"

`

21

22

`#include "llvm/IR/IntrinsicInst.h"

`

22

23

`#include "llvm/IR/Intrinsics.h"

`

23

24

`#include "llvm/Support/Debug.h"

`

`@@ -80,7 +81,6 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {

`

80

81

`const Function *Callee = CB->getCalledFunction();

`

81

82

`if (!Callee)

`

82

83

`return 0;

`

83

``

`-

const Module *M = Caller->getParent();

`

84

84

``

85

85

`// Increase the threshold if an incoming argument is used only as a memcpy

`

86

86

`// source.

`

`@@ -92,25 +92,37 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {

`

92

92

` }

`

93

93

` }

`

94

94

``

95

``

`-

// Give bonus for globals used much in both caller and callee.

`

96

``

`-

std::set<const GlobalVariable *> CalleeGlobals;

`

97

``

`-

std::set<const GlobalVariable *> CallerGlobals;

`

98

``

`-

for (const GlobalVariable &Global : M->globals())

`

99

``

`-

for (const User *U : Global.users())

`

100

``

`-

if (const Instruction *User = dyn_cast(U)) {

`

101

``

`-

if (User->getParent()->getParent() == Callee)

`

102

``

`-

CalleeGlobals.insert(&Global);

`

103

``

`-

if (User->getParent()->getParent() == Caller)

`

104

``

`-

CallerGlobals.insert(&Global);

`

``

95

`+

// Give bonus for globals used much in both caller and a relatively small

`

``

96

`+

// callee.

`

``

97

`+

unsigned InstrCount = 0;

`

``

98

`+

SmallDenseMap<const Value *, unsigned> Ptr2NumUses;

`

``

99

`+

for (auto &I : instructions(Callee)) {

`

``

100

`+

if (++InstrCount == 200) {

`

``

101

`+

Ptr2NumUses.clear();

`

``

102

`+

break;

`

``

103

`+

}

`

``

104

`+

if (const auto *SI = dyn_cast(&I)) {

`

``

105

`+

if (!SI->isVolatile())

`

``

106

`+

if (auto *GV = dyn_cast(SI->getPointerOperand()))

`

``

107

`+

Ptr2NumUses[GV]++;

`

``

108

`+

} else if (const auto *LI = dyn_cast(&I)) {

`

``

109

`+

if (!LI->isVolatile())

`

``

110

`+

if (auto *GV = dyn_cast(LI->getPointerOperand()))

`

``

111

`+

Ptr2NumUses[GV]++;

`

``

112

`+

} else if (const auto *GEP = dyn_cast(&I)) {

`

``

113

`+

if (auto *GV = dyn_cast(GEP->getPointerOperand())) {

`

``

114

`+

unsigned NumStores = 0, NumLoads = 0;

`

``

115

`+

countNumMemAccesses(GEP, NumStores, NumLoads, Callee);

`

``

116

`+

Ptr2NumUses[GV] += NumLoads + NumStores;

`

105

117

` }

`

106

``

`-

for (auto *GV : CalleeGlobals)

`

107

``

`-

if (CallerGlobals.count(GV)) {

`

108

``

`-

unsigned CalleeStores = 0, CalleeLoads = 0;

`

``

118

`+

}

`

``

119

`+

}

`

``

120

+

``

121

`+

for (auto [Ptr, NumCalleeUses] : Ptr2NumUses)

`

``

122

`+

if (NumCalleeUses > 10) {

`

109

123

`unsigned CallerStores = 0, CallerLoads = 0;

`

110

``

`-

countNumMemAccesses(GV, CalleeStores, CalleeLoads, Callee);

`

111

``

`-

countNumMemAccesses(GV, CallerStores, CallerLoads, Caller);

`

112

``

`-

if ((CalleeStores + CalleeLoads) > 10 &&

`

113

``

`-

(CallerStores + CallerLoads) > 10) {

`

``

124

`+

countNumMemAccesses(Ptr, CallerStores, CallerLoads, Caller);

`

``

125

`+

if (CallerStores + CallerLoads > 10) {

`

114

126

` Bonus = 1000;

`

115

127

`break;

`

116

128

` }

`