mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-29 10:32:47 +00:00
fold PHI nodes in SizeOffsetEvaluator whenever possible.
Unfortunately this change requires the cache map to hold WeakVHs instead git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159667 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
44d5c06488
commit
0dff532fce
@ -22,6 +22,7 @@
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
#include "llvm/Support/InstVisitor.h"
|
||||
#include "llvm/Support/TargetFolder.h"
|
||||
#include "llvm/Support/ValueHandle.h"
|
||||
|
||||
namespace llvm {
|
||||
class CallInst;
|
||||
@ -195,7 +196,8 @@ class ObjectSizeOffsetEvaluator
|
||||
: public InstVisitor<ObjectSizeOffsetEvaluator, SizeOffsetEvalType> {
|
||||
|
||||
typedef IRBuilder<true, TargetFolder> BuilderTy;
|
||||
typedef DenseMap<const Value*, SizeOffsetEvalType> CacheMapTy;
|
||||
typedef std::pair<WeakVH, WeakVH> WeakEvalType;
|
||||
typedef DenseMap<const Value*, WeakEvalType> CacheMapTy;
|
||||
typedef SmallPtrSet<const Value*, 8> PtrSetTy;
|
||||
|
||||
const TargetData *TD;
|
||||
@ -216,19 +218,19 @@ public:
|
||||
ObjectSizeOffsetEvaluator(const TargetData *TD, LLVMContext &Context);
|
||||
SizeOffsetEvalType compute(Value *V);
|
||||
|
||||
bool knownSize(SizeOffsetEvalType &SizeOffset) {
|
||||
bool knownSize(SizeOffsetEvalType SizeOffset) {
|
||||
return SizeOffset.first;
|
||||
}
|
||||
|
||||
bool knownOffset(SizeOffsetEvalType &SizeOffset) {
|
||||
bool knownOffset(SizeOffsetEvalType SizeOffset) {
|
||||
return SizeOffset.second;
|
||||
}
|
||||
|
||||
bool anyKnown(SizeOffsetEvalType &SizeOffset) {
|
||||
bool anyKnown(SizeOffsetEvalType SizeOffset) {
|
||||
return knownSize(SizeOffset) || knownOffset(SizeOffset);
|
||||
}
|
||||
|
||||
bool bothKnown(SizeOffsetEvalType &SizeOffset) {
|
||||
bool bothKnown(SizeOffsetEvalType SizeOffset) {
|
||||
return knownSize(SizeOffset) && knownOffset(SizeOffset);
|
||||
}
|
||||
|
||||
|
@ -682,7 +682,19 @@ SizeOffsetEvalType ObjectSizeOffsetEvaluator::visitPHINode(PHINode &PHI) {
|
||||
SizePHI->addIncoming(EdgeData.first, PHI.getIncomingBlock(i));
|
||||
OffsetPHI->addIncoming(EdgeData.second, PHI.getIncomingBlock(i));
|
||||
}
|
||||
return std::make_pair(SizePHI, OffsetPHI);
|
||||
|
||||
Value *Size = SizePHI, *Offset = OffsetPHI, *Tmp;
|
||||
if ((Tmp = SizePHI->hasConstantValue())) {
|
||||
Size = Tmp;
|
||||
SizePHI->replaceAllUsesWith(Size);
|
||||
SizePHI->eraseFromParent();
|
||||
}
|
||||
if ((Tmp = OffsetPHI->hasConstantValue())) {
|
||||
Offset = Tmp;
|
||||
OffsetPHI->replaceAllUsesWith(Offset);
|
||||
OffsetPHI->eraseFromParent();
|
||||
}
|
||||
return std::make_pair(Size, Offset);
|
||||
}
|
||||
|
||||
SizeOffsetEvalType ObjectSizeOffsetEvaluator::visitSelectInst(SelectInst &I) {
|
||||
|
Loading…
Reference in New Issue
Block a user