mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Fix a few more places where TargetData/TargetLibraryInfo is not being passed.
Add FIXMEs to places that are non-trivial to fix. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145661 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7636bf6530
commit
aab8e28d5e
@ -20,12 +20,14 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Constant;
|
class Constant;
|
||||||
class TargetData;
|
class TargetData;
|
||||||
|
class TargetLibraryInfo;
|
||||||
class Value;
|
class Value;
|
||||||
|
|
||||||
/// LazyValueInfo - This pass computes, caches, and vends lazy value constraint
|
/// LazyValueInfo - This pass computes, caches, and vends lazy value constraint
|
||||||
/// information.
|
/// information.
|
||||||
class LazyValueInfo : public FunctionPass {
|
class LazyValueInfo : public FunctionPass {
|
||||||
class TargetData *TD;
|
class TargetData *TD;
|
||||||
|
class TargetLibraryInfo *TLI;
|
||||||
void *PImpl;
|
void *PImpl;
|
||||||
LazyValueInfo(const LazyValueInfo&); // DO NOT IMPLEMENT.
|
LazyValueInfo(const LazyValueInfo&); // DO NOT IMPLEMENT.
|
||||||
void operator=(const LazyValueInfo&); // DO NOT IMPLEMENT.
|
void operator=(const LazyValueInfo&); // DO NOT IMPLEMENT.
|
||||||
@ -68,9 +70,7 @@ public:
|
|||||||
|
|
||||||
// Implementation boilerplate.
|
// Implementation boilerplate.
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
||||||
AU.setPreservesAll();
|
|
||||||
}
|
|
||||||
virtual void releaseMemory();
|
virtual void releaseMemory();
|
||||||
virtual bool runOnFunction(Function &F);
|
virtual bool runOnFunction(Function &F);
|
||||||
};
|
};
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetLibraryInfo.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "llvm/Support/ConstantRange.h"
|
#include "llvm/Support/ConstantRange.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
@ -33,7 +34,10 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
char LazyValueInfo::ID = 0;
|
char LazyValueInfo::ID = 0;
|
||||||
INITIALIZE_PASS(LazyValueInfo, "lazy-value-info",
|
INITIALIZE_PASS_BEGIN(LazyValueInfo, "lazy-value-info",
|
||||||
|
"Lazy Value Information Analysis", false, true)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)
|
||||||
|
INITIALIZE_PASS_END(LazyValueInfo, "lazy-value-info",
|
||||||
"Lazy Value Information Analysis", false, true)
|
"Lazy Value Information Analysis", false, true)
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -207,7 +211,7 @@ public:
|
|||||||
|
|
||||||
// Unless we can prove that the two Constants are different, we must
|
// Unless we can prove that the two Constants are different, we must
|
||||||
// move to overdefined.
|
// move to overdefined.
|
||||||
// FIXME: use TargetData for smarter constant folding.
|
// FIXME: use TargetData/TargetLibraryInfo for smarter constant folding.
|
||||||
if (ConstantInt *Res = dyn_cast<ConstantInt>(
|
if (ConstantInt *Res = dyn_cast<ConstantInt>(
|
||||||
ConstantFoldCompareInstOperands(CmpInst::ICMP_NE,
|
ConstantFoldCompareInstOperands(CmpInst::ICMP_NE,
|
||||||
getConstant(),
|
getConstant(),
|
||||||
@ -233,7 +237,7 @@ public:
|
|||||||
|
|
||||||
// Unless we can prove that the two Constants are different, we must
|
// Unless we can prove that the two Constants are different, we must
|
||||||
// move to overdefined.
|
// move to overdefined.
|
||||||
// FIXME: use TargetData for smarter constant folding.
|
// FIXME: use TargetData/TargetLibraryInfo for smarter constant folding.
|
||||||
if (ConstantInt *Res = dyn_cast<ConstantInt>(
|
if (ConstantInt *Res = dyn_cast<ConstantInt>(
|
||||||
ConstantFoldCompareInstOperands(CmpInst::ICMP_NE,
|
ConstantFoldCompareInstOperands(CmpInst::ICMP_NE,
|
||||||
getNotConstant(),
|
getNotConstant(),
|
||||||
@ -1009,10 +1013,17 @@ bool LazyValueInfo::runOnFunction(Function &F) {
|
|||||||
getCache(PImpl).clear();
|
getCache(PImpl).clear();
|
||||||
|
|
||||||
TD = getAnalysisIfAvailable<TargetData>();
|
TD = getAnalysisIfAvailable<TargetData>();
|
||||||
|
TLI = &getAnalysis<TargetLibraryInfo>();
|
||||||
|
|
||||||
// Fully lazy.
|
// Fully lazy.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LazyValueInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
|
AU.setPreservesAll();
|
||||||
|
AU.addRequired<TargetLibraryInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
void LazyValueInfo::releaseMemory() {
|
void LazyValueInfo::releaseMemory() {
|
||||||
// If the cache was allocated, free it.
|
// If the cache was allocated, free it.
|
||||||
if (PImpl) {
|
if (PImpl) {
|
||||||
@ -1061,7 +1072,8 @@ LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
|
|||||||
// If we know the value is a constant, evaluate the conditional.
|
// If we know the value is a constant, evaluate the conditional.
|
||||||
Constant *Res = 0;
|
Constant *Res = 0;
|
||||||
if (Result.isConstant()) {
|
if (Result.isConstant()) {
|
||||||
Res = ConstantFoldCompareInstOperands(Pred, Result.getConstant(), C, TD);
|
Res = ConstantFoldCompareInstOperands(Pred, Result.getConstant(), C, TD,
|
||||||
|
TLI);
|
||||||
if (ConstantInt *ResCI = dyn_cast<ConstantInt>(Res))
|
if (ConstantInt *ResCI = dyn_cast<ConstantInt>(Res))
|
||||||
return ResCI->isZero() ? False : True;
|
return ResCI->isZero() ? False : True;
|
||||||
return Unknown;
|
return Unknown;
|
||||||
@ -1102,13 +1114,15 @@ LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
|
|||||||
if (Pred == ICmpInst::ICMP_EQ) {
|
if (Pred == ICmpInst::ICMP_EQ) {
|
||||||
// !C1 == C -> false iff C1 == C.
|
// !C1 == C -> false iff C1 == C.
|
||||||
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
|
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
|
||||||
Result.getNotConstant(), C, TD);
|
Result.getNotConstant(), C, TD,
|
||||||
|
TLI);
|
||||||
if (Res->isNullValue())
|
if (Res->isNullValue())
|
||||||
return False;
|
return False;
|
||||||
} else if (Pred == ICmpInst::ICMP_NE) {
|
} else if (Pred == ICmpInst::ICMP_NE) {
|
||||||
// !C1 != C -> true iff C1 == C.
|
// !C1 != C -> true iff C1 == C.
|
||||||
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
|
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
|
||||||
Result.getNotConstant(), C, TD);
|
Result.getNotConstant(), C, TD,
|
||||||
|
TLI);
|
||||||
if (Res->isNullValue())
|
if (Res->isNullValue())
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
@ -622,7 +622,7 @@ Value *Lint::findValueImpl(Value *V, bool OffsetOk,
|
|||||||
if (Value *W = SimplifyInstruction(Inst, TD, TLI, DT))
|
if (Value *W = SimplifyInstruction(Inst, TD, TLI, DT))
|
||||||
return findValueImpl(W, OffsetOk, Visited);
|
return findValueImpl(W, OffsetOk, Visited);
|
||||||
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
|
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
|
||||||
if (Value *W = ConstantFoldConstantExpression(CE, TD))
|
if (Value *W = ConstantFoldConstantExpression(CE, TD, TLI))
|
||||||
if (W != V)
|
if (W != V)
|
||||||
return findValueImpl(W, OffsetOk, Visited);
|
return findValueImpl(W, OffsetOk, Visited);
|
||||||
}
|
}
|
||||||
|
@ -2591,7 +2591,7 @@ const SCEV *ScalarEvolution::getSizeOfExpr(Type *AllocTy) {
|
|||||||
|
|
||||||
Constant *C = ConstantExpr::getSizeOf(AllocTy);
|
Constant *C = ConstantExpr::getSizeOf(AllocTy);
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
||||||
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD))
|
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD, TLI))
|
||||||
C = Folded;
|
C = Folded;
|
||||||
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(AllocTy));
|
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(AllocTy));
|
||||||
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
||||||
@ -2600,7 +2600,7 @@ const SCEV *ScalarEvolution::getSizeOfExpr(Type *AllocTy) {
|
|||||||
const SCEV *ScalarEvolution::getAlignOfExpr(Type *AllocTy) {
|
const SCEV *ScalarEvolution::getAlignOfExpr(Type *AllocTy) {
|
||||||
Constant *C = ConstantExpr::getAlignOf(AllocTy);
|
Constant *C = ConstantExpr::getAlignOf(AllocTy);
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
||||||
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD))
|
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD, TLI))
|
||||||
C = Folded;
|
C = Folded;
|
||||||
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(AllocTy));
|
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(AllocTy));
|
||||||
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
||||||
@ -2617,7 +2617,7 @@ const SCEV *ScalarEvolution::getOffsetOfExpr(StructType *STy,
|
|||||||
|
|
||||||
Constant *C = ConstantExpr::getOffsetOf(STy, FieldNo);
|
Constant *C = ConstantExpr::getOffsetOf(STy, FieldNo);
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
||||||
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD))
|
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD, TLI))
|
||||||
C = Folded;
|
C = Folded;
|
||||||
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(STy));
|
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(STy));
|
||||||
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
||||||
@ -2627,7 +2627,7 @@ const SCEV *ScalarEvolution::getOffsetOfExpr(Type *CTy,
|
|||||||
Constant *FieldNo) {
|
Constant *FieldNo) {
|
||||||
Constant *C = ConstantExpr::getOffsetOf(CTy, FieldNo);
|
Constant *C = ConstantExpr::getOffsetOf(CTy, FieldNo);
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
||||||
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD))
|
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD, TLI))
|
||||||
C = Folded;
|
C = Folded;
|
||||||
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(CTy));
|
Type *Ty = getEffectiveSCEVType(PointerType::getUnqual(CTy));
|
||||||
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
return getTruncateOrZeroExtend(getSCEV(C), Ty);
|
||||||
@ -4807,7 +4807,7 @@ static Constant *EvaluateExpression(Value *V, const Loop *L,
|
|||||||
|
|
||||||
if (CmpInst *CI = dyn_cast<CmpInst>(I))
|
if (CmpInst *CI = dyn_cast<CmpInst>(I))
|
||||||
return ConstantFoldCompareInstOperands(CI->getPredicate(), Operands[0],
|
return ConstantFoldCompareInstOperands(CI->getPredicate(), Operands[0],
|
||||||
Operands[1], TD);
|
Operands[1], TD, TLI);
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||||
if (!LI->isVolatile())
|
if (!LI->isVolatile())
|
||||||
return ConstantFoldLoadFromConstPtr(Operands[0], TD);
|
return ConstantFoldLoadFromConstPtr(Operands[0], TD);
|
||||||
@ -5172,7 +5172,8 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
|
|||||||
Constant *C = 0;
|
Constant *C = 0;
|
||||||
if (const CmpInst *CI = dyn_cast<CmpInst>(I))
|
if (const CmpInst *CI = dyn_cast<CmpInst>(I))
|
||||||
C = ConstantFoldCompareInstOperands(CI->getPredicate(),
|
C = ConstantFoldCompareInstOperands(CI->getPredicate(),
|
||||||
Operands[0], Operands[1], TD);
|
Operands[0], Operands[1], TD,
|
||||||
|
TLI);
|
||||||
else if (const LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
else if (const LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||||
if (!LI->isVolatile())
|
if (!LI->isVolatile())
|
||||||
C = ConstantFoldLoadFromConstPtr(Operands[0], TD);
|
C = ConstantFoldLoadFromConstPtr(Operands[0], TD);
|
||||||
|
@ -350,6 +350,7 @@ static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) {
|
|||||||
// and will invalidate our notion of what Init is.
|
// and will invalidate our notion of what Init is.
|
||||||
Constant *SubInit = 0;
|
Constant *SubInit = 0;
|
||||||
if (!isa<ConstantExpr>(GEP->getOperand(0))) {
|
if (!isa<ConstantExpr>(GEP->getOperand(0))) {
|
||||||
|
// FIXME: use TargetData/TargetLibraryInfo for smarter constant folding.
|
||||||
ConstantExpr *CE =
|
ConstantExpr *CE =
|
||||||
dyn_cast_or_null<ConstantExpr>(ConstantFoldInstruction(GEP));
|
dyn_cast_or_null<ConstantExpr>(ConstantFoldInstruction(GEP));
|
||||||
if (Init && CE && CE->getOpcode() == Instruction::GetElementPtr)
|
if (Init && CE && CE->getOpcode() == Instruction::GetElementPtr)
|
||||||
@ -833,6 +834,7 @@ static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV) {
|
|||||||
static void ConstantPropUsersOf(Value *V) {
|
static void ConstantPropUsersOf(Value *V) {
|
||||||
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; )
|
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; )
|
||||||
if (Instruction *I = dyn_cast<Instruction>(*UI++))
|
if (Instruction *I = dyn_cast<Instruction>(*UI++))
|
||||||
|
// FIXME: use TargetData/TargetLibraryInfo for smarter constant folding.
|
||||||
if (Constant *NewC = ConstantFoldInstruction(I)) {
|
if (Constant *NewC = ConstantFoldInstruction(I)) {
|
||||||
I->replaceAllUsesWith(NewC);
|
I->replaceAllUsesWith(NewC);
|
||||||
|
|
||||||
@ -1936,7 +1938,8 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
|
|||||||
if (GV->hasInitializer())
|
if (GV->hasInitializer())
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(GV->getInitializer())) {
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(GV->getInitializer())) {
|
||||||
TargetData *TD = getAnalysisIfAvailable<TargetData>();
|
TargetData *TD = getAnalysisIfAvailable<TargetData>();
|
||||||
Constant *New = ConstantFoldConstantExpression(CE, TD);
|
TargetLibraryInfo *TLI = &getAnalysis<TargetLibraryInfo>();
|
||||||
|
Constant *New = ConstantFoldConstantExpression(CE, TD, TLI);
|
||||||
if (New && New != CE)
|
if (New && New != CE)
|
||||||
GV->setInitializer(New);
|
GV->setInitializer(New);
|
||||||
}
|
}
|
||||||
@ -2542,7 +2545,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
|||||||
|
|
||||||
if (!CurInst->use_empty()) {
|
if (!CurInst->use_empty()) {
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(InstResult))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(InstResult))
|
||||||
InstResult = ConstantFoldConstantExpression(CE, TD);
|
InstResult = ConstantFoldConstantExpression(CE, TD, TLI);
|
||||||
|
|
||||||
Values[CurInst] = InstResult;
|
Values[CurInst] = InstResult;
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,8 @@ public:
|
|||||||
|
|
||||||
TargetData *getTargetData() const { return TD; }
|
TargetData *getTargetData() const { return TD; }
|
||||||
|
|
||||||
|
TargetLibraryInfo *getTargetLibraryInfo() const { return TLI; }
|
||||||
|
|
||||||
// Visitation implementation - Implement instruction combining for different
|
// Visitation implementation - Implement instruction combining for different
|
||||||
// instruction types. The semantics are as follows:
|
// instruction types. The semantics are as follows:
|
||||||
// Return Value:
|
// Return Value:
|
||||||
|
@ -284,7 +284,7 @@ FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV,
|
|||||||
|
|
||||||
// Find out if the comparison would be true or false for the i'th element.
|
// Find out if the comparison would be true or false for the i'th element.
|
||||||
Constant *C = ConstantFoldCompareInstOperands(ICI.getPredicate(), Elt,
|
Constant *C = ConstantFoldCompareInstOperands(ICI.getPredicate(), Elt,
|
||||||
CompareRHS, TD);
|
CompareRHS, TD, TLI);
|
||||||
// If the result is undef for this element, ignore it.
|
// If the result is undef for this element, ignore it.
|
||||||
if (isa<UndefValue>(C)) {
|
if (isa<UndefValue>(C)) {
|
||||||
// Extend range state machines to cover this element in case there is an
|
// Extend range state machines to cover this element in case there is an
|
||||||
|
@ -282,7 +282,8 @@ Instruction *InstCombiner::FoldSelectIntoOp(SelectInst &SI, Value *TrueVal,
|
|||||||
/// SimplifyWithOpReplaced - See if V simplifies when its operand Op is
|
/// SimplifyWithOpReplaced - See if V simplifies when its operand Op is
|
||||||
/// replaced with RepOp.
|
/// replaced with RepOp.
|
||||||
static Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
|
static Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
|
||||||
const TargetData *TD) {
|
const TargetData *TD,
|
||||||
|
const TargetLibraryInfo *TLI) {
|
||||||
// Trivial replacement.
|
// Trivial replacement.
|
||||||
if (V == Op)
|
if (V == Op)
|
||||||
return RepOp;
|
return RepOp;
|
||||||
@ -294,17 +295,19 @@ static Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
|
|||||||
// If this is a binary operator, try to simplify it with the replaced op.
|
// If this is a binary operator, try to simplify it with the replaced op.
|
||||||
if (BinaryOperator *B = dyn_cast<BinaryOperator>(I)) {
|
if (BinaryOperator *B = dyn_cast<BinaryOperator>(I)) {
|
||||||
if (B->getOperand(0) == Op)
|
if (B->getOperand(0) == Op)
|
||||||
return SimplifyBinOp(B->getOpcode(), RepOp, B->getOperand(1), TD);
|
return SimplifyBinOp(B->getOpcode(), RepOp, B->getOperand(1), TD, TLI);
|
||||||
if (B->getOperand(1) == Op)
|
if (B->getOperand(1) == Op)
|
||||||
return SimplifyBinOp(B->getOpcode(), B->getOperand(0), RepOp, TD);
|
return SimplifyBinOp(B->getOpcode(), B->getOperand(0), RepOp, TD, TLI);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same for CmpInsts.
|
// Same for CmpInsts.
|
||||||
if (CmpInst *C = dyn_cast<CmpInst>(I)) {
|
if (CmpInst *C = dyn_cast<CmpInst>(I)) {
|
||||||
if (C->getOperand(0) == Op)
|
if (C->getOperand(0) == Op)
|
||||||
return SimplifyCmpInst(C->getPredicate(), RepOp, C->getOperand(1), TD);
|
return SimplifyCmpInst(C->getPredicate(), RepOp, C->getOperand(1), TD,
|
||||||
|
TLI);
|
||||||
if (C->getOperand(1) == Op)
|
if (C->getOperand(1) == Op)
|
||||||
return SimplifyCmpInst(C->getPredicate(), C->getOperand(0), RepOp, TD);
|
return SimplifyCmpInst(C->getPredicate(), C->getOperand(0), RepOp, TD,
|
||||||
|
TLI);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We could hand off more cases to instsimplify here.
|
// TODO: We could hand off more cases to instsimplify here.
|
||||||
@ -330,7 +333,7 @@ static Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
|
|||||||
return ConstantFoldLoadFromConstPtr(ConstOps[0], TD);
|
return ConstantFoldLoadFromConstPtr(ConstOps[0], TD);
|
||||||
|
|
||||||
return ConstantFoldInstOperands(I->getOpcode(), I->getType(),
|
return ConstantFoldInstOperands(I->getOpcode(), I->getType(),
|
||||||
ConstOps, TD);
|
ConstOps, TD, TLI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,18 +482,18 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI,
|
|||||||
// arms of the select. See if substituting this value into the arm and
|
// arms of the select. See if substituting this value into the arm and
|
||||||
// simplifying the result yields the same value as the other arm.
|
// simplifying the result yields the same value as the other arm.
|
||||||
if (Pred == ICmpInst::ICMP_EQ) {
|
if (Pred == ICmpInst::ICMP_EQ) {
|
||||||
if (SimplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, TD) == TrueVal ||
|
if (SimplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, TD, TLI) == TrueVal ||
|
||||||
SimplifyWithOpReplaced(FalseVal, CmpRHS, CmpLHS, TD) == TrueVal)
|
SimplifyWithOpReplaced(FalseVal, CmpRHS, CmpLHS, TD, TLI) == TrueVal)
|
||||||
return ReplaceInstUsesWith(SI, FalseVal);
|
return ReplaceInstUsesWith(SI, FalseVal);
|
||||||
if (SimplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, TD) == FalseVal ||
|
if (SimplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, TD, TLI) == FalseVal ||
|
||||||
SimplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, TD) == FalseVal)
|
SimplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, TD, TLI) == FalseVal)
|
||||||
return ReplaceInstUsesWith(SI, FalseVal);
|
return ReplaceInstUsesWith(SI, FalseVal);
|
||||||
} else if (Pred == ICmpInst::ICMP_NE) {
|
} else if (Pred == ICmpInst::ICMP_NE) {
|
||||||
if (SimplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, TD) == FalseVal ||
|
if (SimplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, TD, TLI) == FalseVal ||
|
||||||
SimplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, TD) == FalseVal)
|
SimplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, TD, TLI) == FalseVal)
|
||||||
return ReplaceInstUsesWith(SI, TrueVal);
|
return ReplaceInstUsesWith(SI, TrueVal);
|
||||||
if (SimplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, TD) == TrueVal ||
|
if (SimplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, TD, TLI) == TrueVal ||
|
||||||
SimplifyWithOpReplaced(FalseVal, CmpRHS, CmpLHS, TD) == TrueVal)
|
SimplifyWithOpReplaced(FalseVal, CmpRHS, CmpLHS, TD, TLI) == TrueVal)
|
||||||
return ReplaceInstUsesWith(SI, TrueVal);
|
return ReplaceInstUsesWith(SI, TrueVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,8 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
V = IC.Builder->CreateLShr(C, NumBits);
|
V = IC.Builder->CreateLShr(C, NumBits);
|
||||||
// If we got a constantexpr back, try to simplify it with TD info.
|
// If we got a constantexpr back, try to simplify it with TD info.
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
|
||||||
V = ConstantFoldConstantExpression(CE, IC.getTargetData());
|
V = ConstantFoldConstantExpression(CE, IC.getTargetData(),
|
||||||
|
IC.getTargetLibraryInfo());
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1849,7 +1849,7 @@ static bool AddReachableCodeToWorklist(BasicBlock *BB,
|
|||||||
|
|
||||||
Constant*& FoldRes = FoldedConstants[CE];
|
Constant*& FoldRes = FoldedConstants[CE];
|
||||||
if (!FoldRes)
|
if (!FoldRes)
|
||||||
FoldRes = ConstantFoldConstantExpression(CE, TD);
|
FoldRes = ConstantFoldConstantExpression(CE, TD, TLI);
|
||||||
if (!FoldRes)
|
if (!FoldRes)
|
||||||
FoldRes = CE;
|
FoldRes = CE;
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include "llvm/Transforms/Utils/SSAUpdater.h"
|
#include "llvm/Transforms/Utils/SSAUpdater.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetLibraryInfo.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/DenseSet.h"
|
#include "llvm/ADT/DenseSet.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
@ -75,6 +76,7 @@ namespace {
|
|||||||
///
|
///
|
||||||
class JumpThreading : public FunctionPass {
|
class JumpThreading : public FunctionPass {
|
||||||
TargetData *TD;
|
TargetData *TD;
|
||||||
|
TargetLibraryInfo *TLI;
|
||||||
LazyValueInfo *LVI;
|
LazyValueInfo *LVI;
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
SmallPtrSet<BasicBlock*, 16> LoopHeaders;
|
SmallPtrSet<BasicBlock*, 16> LoopHeaders;
|
||||||
@ -107,6 +109,7 @@ namespace {
|
|||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.addRequired<LazyValueInfo>();
|
AU.addRequired<LazyValueInfo>();
|
||||||
AU.addPreserved<LazyValueInfo>();
|
AU.addPreserved<LazyValueInfo>();
|
||||||
|
AU.addRequired<TargetLibraryInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindLoopHeaders(Function &F);
|
void FindLoopHeaders(Function &F);
|
||||||
@ -133,6 +136,7 @@ char JumpThreading::ID = 0;
|
|||||||
INITIALIZE_PASS_BEGIN(JumpThreading, "jump-threading",
|
INITIALIZE_PASS_BEGIN(JumpThreading, "jump-threading",
|
||||||
"Jump Threading", false, false)
|
"Jump Threading", false, false)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LazyValueInfo)
|
INITIALIZE_PASS_DEPENDENCY(LazyValueInfo)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)
|
||||||
INITIALIZE_PASS_END(JumpThreading, "jump-threading",
|
INITIALIZE_PASS_END(JumpThreading, "jump-threading",
|
||||||
"Jump Threading", false, false)
|
"Jump Threading", false, false)
|
||||||
|
|
||||||
@ -144,6 +148,7 @@ FunctionPass *llvm::createJumpThreadingPass() { return new JumpThreading(); }
|
|||||||
bool JumpThreading::runOnFunction(Function &F) {
|
bool JumpThreading::runOnFunction(Function &F) {
|
||||||
DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n");
|
DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n");
|
||||||
TD = getAnalysisIfAvailable<TargetData>();
|
TD = getAnalysisIfAvailable<TargetData>();
|
||||||
|
TLI = &getAnalysis<TargetLibraryInfo>();
|
||||||
LVI = &getAnalysis<LazyValueInfo>();
|
LVI = &getAnalysis<LazyValueInfo>();
|
||||||
|
|
||||||
FindLoopHeaders(F);
|
FindLoopHeaders(F);
|
||||||
@ -674,7 +679,7 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
|
|||||||
// Run constant folding to see if we can reduce the condition to a simple
|
// Run constant folding to see if we can reduce the condition to a simple
|
||||||
// constant.
|
// constant.
|
||||||
if (Instruction *I = dyn_cast<Instruction>(Condition)) {
|
if (Instruction *I = dyn_cast<Instruction>(Condition)) {
|
||||||
Value *SimpleVal = ConstantFoldInstruction(I, TD);
|
Value *SimpleVal = ConstantFoldInstruction(I, TD, TLI);
|
||||||
if (SimpleVal) {
|
if (SimpleVal) {
|
||||||
I->replaceAllUsesWith(SimpleVal);
|
I->replaceAllUsesWith(SimpleVal);
|
||||||
I->eraseFromParent();
|
I->eraseFromParent();
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include "llvm/Transforms/Utils/SSAUpdater.h"
|
#include "llvm/Transforms/Utils/SSAUpdater.h"
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetLibraryInfo.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
@ -84,6 +86,7 @@ namespace {
|
|||||||
AU.addPreserved<AliasAnalysis>();
|
AU.addPreserved<AliasAnalysis>();
|
||||||
AU.addPreserved("scalar-evolution");
|
AU.addPreserved("scalar-evolution");
|
||||||
AU.addPreservedID(LoopSimplifyID);
|
AU.addPreservedID(LoopSimplifyID);
|
||||||
|
AU.addRequired<TargetLibraryInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool doFinalization() {
|
bool doFinalization() {
|
||||||
@ -96,6 +99,9 @@ namespace {
|
|||||||
LoopInfo *LI; // Current LoopInfo
|
LoopInfo *LI; // Current LoopInfo
|
||||||
DominatorTree *DT; // Dominator Tree for the current Loop.
|
DominatorTree *DT; // Dominator Tree for the current Loop.
|
||||||
|
|
||||||
|
TargetData *TD; // TargetData for constant folding.
|
||||||
|
TargetLibraryInfo *TLI; // TargetLibraryInfo for constant folding.
|
||||||
|
|
||||||
// State that is updated as we process loops.
|
// State that is updated as we process loops.
|
||||||
bool Changed; // Set to true when we change anything.
|
bool Changed; // Set to true when we change anything.
|
||||||
BasicBlock *Preheader; // The preheader block of the current loop...
|
BasicBlock *Preheader; // The preheader block of the current loop...
|
||||||
@ -177,6 +183,7 @@ INITIALIZE_PASS_BEGIN(LICM, "licm", "Loop Invariant Code Motion", false, false)
|
|||||||
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
|
INITIALIZE_PASS_DEPENDENCY(DominatorTree)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
|
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||||
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)
|
||||||
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
||||||
INITIALIZE_PASS_END(LICM, "licm", "Loop Invariant Code Motion", false, false)
|
INITIALIZE_PASS_END(LICM, "licm", "Loop Invariant Code Motion", false, false)
|
||||||
|
|
||||||
@ -194,6 +201,9 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
AA = &getAnalysis<AliasAnalysis>();
|
AA = &getAnalysis<AliasAnalysis>();
|
||||||
DT = &getAnalysis<DominatorTree>();
|
DT = &getAnalysis<DominatorTree>();
|
||||||
|
|
||||||
|
TD = getAnalysisIfAvailable<TargetData>();
|
||||||
|
TLI = &getAnalysis<TargetLibraryInfo>();
|
||||||
|
|
||||||
CurAST = new AliasSetTracker(*AA);
|
CurAST = new AliasSetTracker(*AA);
|
||||||
// Collect Alias info from subloops.
|
// Collect Alias info from subloops.
|
||||||
for (Loop::iterator LoopItr = L->begin(), LoopItrE = L->end();
|
for (Loop::iterator LoopItr = L->begin(), LoopItrE = L->end();
|
||||||
@ -333,7 +343,7 @@ void LICM::HoistRegion(DomTreeNode *N) {
|
|||||||
// Try constant folding this instruction. If all the operands are
|
// Try constant folding this instruction. If all the operands are
|
||||||
// constants, it is technically hoistable, but it would be better to just
|
// constants, it is technically hoistable, but it would be better to just
|
||||||
// fold it.
|
// fold it.
|
||||||
if (Constant *C = ConstantFoldInstruction(&I)) {
|
if (Constant *C = ConstantFoldInstruction(&I, TD, TLI)) {
|
||||||
DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n');
|
DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n');
|
||||||
CurAST->copyValue(&I, C);
|
CurAST->copyValue(&I, C);
|
||||||
CurAST->deleteValue(&I);
|
CurAST->deleteValue(&I);
|
||||||
|
Loading…
Reference in New Issue
Block a user