Skip to content

Commit 1761066

Browse files
authored
[GlobalOpt] Remove Function* argument from tryWidenGlobalArrayAndDests. NFC (#127848)
This is only used to get the Module and the LLVMContext. We can get both of those from the GlobalVariable*.
1 parent c833746 commit 1761066

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ static bool destArrayCanBeWidened(CallInst *CI) {
20642064
return true;
20652065
}
20662066

2067-
static GlobalVariable *widenGlobalVariable(GlobalVariable *OldVar, Function *F,
2067+
static GlobalVariable *widenGlobalVariable(GlobalVariable *OldVar,
20682068
unsigned NumBytesToPad,
20692069
unsigned NumBytesToCopy) {
20702070
if (!OldVar->hasInitializer())
@@ -2083,10 +2083,10 @@ static GlobalVariable *widenGlobalVariable(GlobalVariable *OldVar, Function *F,
20832083
StrData.push_back('\0');
20842084
auto Arr = ArrayRef(StrData.data(), NumBytesToCopy + NumBytesToPad);
20852085
// Create new padded version of global variable.
2086-
Constant *SourceReplace = ConstantDataArray::get(F->getContext(), Arr);
2086+
Constant *SourceReplace = ConstantDataArray::get(OldVar->getContext(), Arr);
20872087
GlobalVariable *NewGV = new GlobalVariable(
2088-
*(F->getParent()), SourceReplace->getType(), true, OldVar->getLinkage(),
2089-
SourceReplace, SourceReplace->getName());
2088+
*(OldVar->getParent()), SourceReplace->getType(), true,
2089+
OldVar->getLinkage(), SourceReplace, SourceReplace->getName());
20902090
// Copy any other attributes from original global variable
20912091
// e.g. unamed_addr
20922092
NewGV->copyAttributesFrom(OldVar);
@@ -2114,13 +2114,13 @@ static void widenDestArray(CallInst *CI, const unsigned NumBytesToPad,
21142114
}
21152115
}
21162116

2117-
static bool tryWidenGlobalArrayAndDests(Function *F, GlobalVariable *SourceVar,
2117+
static bool tryWidenGlobalArrayAndDests(GlobalVariable *SourceVar,
21182118
const unsigned NumBytesToPad,
21192119
const unsigned NumBytesToCopy,
21202120
ConstantInt *BytesToCopyOp,
21212121
ConstantDataArray *SourceDataArray) {
21222122
auto *NewSourceGV =
2123-
widenGlobalVariable(SourceVar, F, NumBytesToPad, NumBytesToCopy);
2123+
widenGlobalVariable(SourceVar, NumBytesToPad, NumBytesToCopy);
21242124
if (!NewSourceGV)
21252125
return false;
21262126

@@ -2158,8 +2158,6 @@ static bool tryWidenGlobalArraysUsedByMemcpy(
21582158
if (!callInstIsMemcpy(CI) || !destArrayCanBeWidened(CI))
21592159
continue;
21602160

2161-
Function *F = CI->getCalledFunction();
2162-
21632161
auto *BytesToCopyOp = dyn_cast<ConstantInt>(CI->getArgOperand(2));
21642162
if (!BytesToCopyOp)
21652163
continue;
@@ -2191,7 +2189,7 @@ static bool tryWidenGlobalArraysUsedByMemcpy(
21912189
.getNumBytesToPadGlobalArray(NumBytesToCopy,
21922190
SourceDataArray->getType());
21932191
if (NumBytesToPad) {
2194-
return tryWidenGlobalArrayAndDests(F, GV, NumBytesToPad, NumBytesToCopy,
2192+
return tryWidenGlobalArrayAndDests(GV, NumBytesToPad, NumBytesToCopy,
21952193
BytesToCopyOp, SourceDataArray);
21962194
}
21972195
}

0 commit comments

Comments
 (0)