mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 07:31:53 +00:00
[IPO/IPCP] Convert to use static functions. NFC.
In preparation for porting this pass to the new PM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268429 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f8e08351d3
commit
692cb17dfd
@ -41,47 +41,14 @@ namespace {
|
||||
}
|
||||
|
||||
bool runOnModule(Module &M) override;
|
||||
private:
|
||||
bool PropagateConstantsIntoArguments(Function &F);
|
||||
bool PropagateConstantReturn(Function &F);
|
||||
};
|
||||
}
|
||||
|
||||
char IPCP::ID = 0;
|
||||
INITIALIZE_PASS(IPCP, "ipconstprop",
|
||||
"Interprocedural constant propagation", false, false)
|
||||
|
||||
ModulePass *llvm::createIPConstantPropagationPass() { return new IPCP(); }
|
||||
|
||||
bool IPCP::runOnModule(Module &M) {
|
||||
if (skipModule(M))
|
||||
return false;
|
||||
|
||||
bool Changed = false;
|
||||
bool LocalChange = true;
|
||||
|
||||
// FIXME: instead of using smart algorithms, we just iterate until we stop
|
||||
// making changes.
|
||||
while (LocalChange) {
|
||||
LocalChange = false;
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||
if (!I->isDeclaration()) {
|
||||
// Delete any klingons.
|
||||
I->removeDeadConstantUsers();
|
||||
if (I->hasLocalLinkage())
|
||||
LocalChange |= PropagateConstantsIntoArguments(*I);
|
||||
Changed |= PropagateConstantReturn(*I);
|
||||
}
|
||||
Changed |= LocalChange;
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
/// PropagateConstantsIntoArguments - Look at all uses of the specified
|
||||
/// function. If all uses are direct call sites, and all pass a particular
|
||||
/// constant in for an argument, propagate that constant in as the argument.
|
||||
///
|
||||
bool IPCP::PropagateConstantsIntoArguments(Function &F) {
|
||||
static bool PropagateConstantsIntoArguments(Function &F) {
|
||||
if (F.arg_empty() || F.use_empty()) return false; // No arguments? Early exit.
|
||||
|
||||
// For each argument, keep track of its constant value and whether it is a
|
||||
@ -160,7 +127,7 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) {
|
||||
// Additionally if a function always returns one of its arguments directly,
|
||||
// callers will be updated to use the value they pass in directly instead of
|
||||
// using the return value.
|
||||
bool IPCP::PropagateConstantReturn(Function &F) {
|
||||
static bool PropagateConstantReturn(Function &F) {
|
||||
if (F.getReturnType()->isVoidTy())
|
||||
return false; // No return value.
|
||||
|
||||
@ -281,3 +248,33 @@ bool IPCP::PropagateConstantReturn(Function &F) {
|
||||
if (MadeChange) ++NumReturnValProped;
|
||||
return MadeChange;
|
||||
}
|
||||
|
||||
char IPCP::ID = 0;
|
||||
INITIALIZE_PASS(IPCP, "ipconstprop",
|
||||
"Interprocedural constant propagation", false, false)
|
||||
|
||||
ModulePass *llvm::createIPConstantPropagationPass() { return new IPCP(); }
|
||||
|
||||
bool IPCP::runOnModule(Module &M) {
|
||||
if (skipModule(M))
|
||||
return false;
|
||||
|
||||
bool Changed = false;
|
||||
bool LocalChange = true;
|
||||
|
||||
// FIXME: instead of using smart algorithms, we just iterate until we stop
|
||||
// making changes.
|
||||
while (LocalChange) {
|
||||
LocalChange = false;
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||
if (!I->isDeclaration()) {
|
||||
// Delete any klingons.
|
||||
I->removeDeadConstantUsers();
|
||||
if (I->hasLocalLinkage())
|
||||
LocalChange |= PropagateConstantsIntoArguments(*I);
|
||||
Changed |= PropagateConstantReturn(*I);
|
||||
}
|
||||
Changed |= LocalChange;
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user