mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-02 08:46:23 +00:00
Implement constant propogation of PHI instructions like this:
X = phi(0, 0, 0) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2543 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0651a9d207
commit
54753e2790
@ -5,7 +5,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ConstantHandling.h"
|
||||
#include "llvm/Instruction.h"
|
||||
#include "llvm/iPHINode.h"
|
||||
#include <cmath>
|
||||
|
||||
AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
|
||||
@ -15,6 +15,22 @@ AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
|
||||
// If successful, the constant result is returned, if not, null is returned.
|
||||
//
|
||||
Constant *ConstantFoldInstruction(Instruction *I) {
|
||||
if (PHINode *PN = dyn_cast<PHINode>(I)) {
|
||||
if (PN->getNumIncomingValues() == 0)
|
||||
return Constant::getNullValue(PN->getType());
|
||||
|
||||
Constant *Result = dyn_cast<Constant>(PN->getIncomingValue(0));
|
||||
if (Result == 0) return 0;
|
||||
|
||||
// Handle PHI nodes specially here...
|
||||
for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i)
|
||||
if (PN->getIncomingValue(i) != Result)
|
||||
return 0; // Not all the same incoming constants...
|
||||
|
||||
// If we reach here, all incoming values are the same constant.
|
||||
return Result;
|
||||
}
|
||||
|
||||
Constant *Op0 = 0;
|
||||
Constant *Op1 = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user