mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-02 07:17:36 +00:00
Move a bit more state over to the LLVMContext.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76533 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -93,16 +93,6 @@ public:
|
|||||||
return Val == V;
|
return Val == V;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getTrue/getFalse - Return the singleton true/false values.
|
|
||||||
static inline ConstantInt *getTrue() {
|
|
||||||
if (TheTrueVal) return TheTrueVal;
|
|
||||||
return CreateTrueFalseVals(true);
|
|
||||||
}
|
|
||||||
static inline ConstantInt *getFalse() {
|
|
||||||
if (TheFalseVal) return TheFalseVal;
|
|
||||||
return CreateTrueFalseVals(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getType - Specialize the getType() method to always return an IntegerType,
|
/// getType - Specialize the getType() method to always return an IntegerType,
|
||||||
/// which reduces the amount of casting needed in parts of the compiler.
|
/// which reduces the amount of casting needed in parts of the compiler.
|
||||||
///
|
///
|
||||||
@@ -200,9 +190,6 @@ public:
|
|||||||
static bool classof(const Value *V) {
|
static bool classof(const Value *V) {
|
||||||
return V->getValueID() == ConstantIntVal;
|
return V->getValueID() == ConstantIntVal;
|
||||||
}
|
}
|
||||||
static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
|
|
||||||
private:
|
|
||||||
static ConstantInt *CreateTrueFalseVals(bool WhichOne);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1149,7 +1149,7 @@ SelectionDAGLowering::EmitBranchForMergedCondition(Value *Cond,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a CaseBlock record representing this branch.
|
// Create a CaseBlock record representing this branch.
|
||||||
CaseBlock CB(ISD::SETEQ, Cond, ConstantInt::getTrue(),
|
CaseBlock CB(ISD::SETEQ, Cond, DAG.getContext()->getConstantIntTrue(),
|
||||||
NULL, TBB, FBB, CurBB);
|
NULL, TBB, FBB, CurBB);
|
||||||
SwitchCases.push_back(CB);
|
SwitchCases.push_back(CB);
|
||||||
}
|
}
|
||||||
@@ -1304,7 +1304,7 @@ void SelectionDAGLowering::visitBr(BranchInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a CaseBlock record representing this branch.
|
// Create a CaseBlock record representing this branch.
|
||||||
CaseBlock CB(ISD::SETEQ, CondVal, ConstantInt::getTrue(),
|
CaseBlock CB(ISD::SETEQ, CondVal, DAG.getContext()->getConstantIntTrue(),
|
||||||
NULL, Succ0MBB, Succ1MBB, CurMBB);
|
NULL, Succ0MBB, Succ1MBB, CurMBB);
|
||||||
// Use visitSwitchCase to actually insert the fast branch sequence for this
|
// Use visitSwitchCase to actually insert the fast branch sequence for this
|
||||||
// cond branch.
|
// cond branch.
|
||||||
@@ -1322,9 +1322,11 @@ void SelectionDAGLowering::visitSwitchCase(CaseBlock &CB) {
|
|||||||
if (CB.CmpMHS == NULL) {
|
if (CB.CmpMHS == NULL) {
|
||||||
// Fold "(X == true)" to X and "(X == false)" to !X to
|
// Fold "(X == true)" to X and "(X == false)" to !X to
|
||||||
// handle common cases produced by branch lowering.
|
// handle common cases produced by branch lowering.
|
||||||
if (CB.CmpRHS == ConstantInt::getTrue() && CB.CC == ISD::SETEQ)
|
if (CB.CmpRHS == DAG.getContext()->getConstantIntTrue() &&
|
||||||
|
CB.CC == ISD::SETEQ)
|
||||||
Cond = CondLHS;
|
Cond = CondLHS;
|
||||||
else if (CB.CmpRHS == ConstantInt::getFalse() && CB.CC == ISD::SETEQ) {
|
else if (CB.CmpRHS == DAG.getContext()->getConstantIntFalse() &&
|
||||||
|
CB.CC == ISD::SETEQ) {
|
||||||
SDValue True = DAG.getConstant(1, CondLHS.getValueType());
|
SDValue True = DAG.getConstant(1, CondLHS.getValueType());
|
||||||
Cond = DAG.getNode(ISD::XOR, dl, CondLHS.getValueType(), CondLHS, True);
|
Cond = DAG.getNode(ISD::XOR, dl, CondLHS.getValueType(), CondLHS, True);
|
||||||
} else
|
} else
|
||||||
|
|||||||
@@ -1690,8 +1690,8 @@ namespace {
|
|||||||
bool isRelatedBy(Value *V1, Value *V2, ICmpInst::Predicate Pred) const {
|
bool isRelatedBy(Value *V1, Value *V2, ICmpInst::Predicate Pred) const {
|
||||||
if (Constant *C1 = dyn_cast<Constant>(V1))
|
if (Constant *C1 = dyn_cast<Constant>(V1))
|
||||||
if (Constant *C2 = dyn_cast<Constant>(V2))
|
if (Constant *C2 = dyn_cast<Constant>(V2))
|
||||||
return ConstantExpr::getCompare(Pred, C1, C2) ==
|
return Context->getConstantExprCompare(Pred, C1, C2) ==
|
||||||
ConstantInt::getTrue();
|
Context->getConstantIntTrue();
|
||||||
|
|
||||||
unsigned n1 = VN.valueNumber(V1, Top);
|
unsigned n1 = VN.valueNumber(V1, Top);
|
||||||
unsigned n2 = VN.valueNumber(V2, Top);
|
unsigned n2 = VN.valueNumber(V2, Top);
|
||||||
@@ -1803,10 +1803,10 @@ namespace {
|
|||||||
// "icmp ult i32 %a, %y" EQ true then %a u< y
|
// "icmp ult i32 %a, %y" EQ true then %a u< y
|
||||||
// etc.
|
// etc.
|
||||||
|
|
||||||
if (Canonical == ConstantInt::getTrue()) {
|
if (Canonical == Context->getConstantIntTrue()) {
|
||||||
add(IC->getOperand(0), IC->getOperand(1), IC->getPredicate(),
|
add(IC->getOperand(0), IC->getOperand(1), IC->getPredicate(),
|
||||||
NewContext);
|
NewContext);
|
||||||
} else if (Canonical == ConstantInt::getFalse()) {
|
} else if (Canonical == Context->getConstantIntFalse()) {
|
||||||
add(IC->getOperand(0), IC->getOperand(1),
|
add(IC->getOperand(0), IC->getOperand(1),
|
||||||
ICmpInst::getInversePredicate(IC->getPredicate()), NewContext);
|
ICmpInst::getInversePredicate(IC->getPredicate()), NewContext);
|
||||||
}
|
}
|
||||||
@@ -1822,11 +1822,11 @@ namespace {
|
|||||||
if (isRelatedBy(True, False, ICmpInst::ICMP_NE)) {
|
if (isRelatedBy(True, False, ICmpInst::ICMP_NE)) {
|
||||||
if (Canonical == VN.canonicalize(True, Top) ||
|
if (Canonical == VN.canonicalize(True, Top) ||
|
||||||
isRelatedBy(Canonical, False, ICmpInst::ICMP_NE))
|
isRelatedBy(Canonical, False, ICmpInst::ICMP_NE))
|
||||||
add(SI->getCondition(), ConstantInt::getTrue(),
|
add(SI->getCondition(), Context->getConstantIntTrue(),
|
||||||
ICmpInst::ICMP_EQ, NewContext);
|
ICmpInst::ICMP_EQ, NewContext);
|
||||||
else if (Canonical == VN.canonicalize(False, Top) ||
|
else if (Canonical == VN.canonicalize(False, Top) ||
|
||||||
isRelatedBy(Canonical, True, ICmpInst::ICMP_NE))
|
isRelatedBy(Canonical, True, ICmpInst::ICMP_NE))
|
||||||
add(SI->getCondition(), ConstantInt::getFalse(),
|
add(SI->getCondition(), Context->getConstantIntFalse(),
|
||||||
ICmpInst::ICMP_EQ, NewContext);
|
ICmpInst::ICMP_EQ, NewContext);
|
||||||
}
|
}
|
||||||
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
|
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
|
||||||
@@ -2050,9 +2050,10 @@ namespace {
|
|||||||
|
|
||||||
ICmpInst::Predicate Pred = IC->getPredicate();
|
ICmpInst::Predicate Pred = IC->getPredicate();
|
||||||
if (isRelatedBy(Op0, Op1, Pred))
|
if (isRelatedBy(Op0, Op1, Pred))
|
||||||
add(IC, ConstantInt::getTrue(), ICmpInst::ICMP_EQ, NewContext);
|
add(IC, Context->getConstantIntTrue(), ICmpInst::ICMP_EQ, NewContext);
|
||||||
else if (isRelatedBy(Op0, Op1, ICmpInst::getInversePredicate(Pred)))
|
else if (isRelatedBy(Op0, Op1, ICmpInst::getInversePredicate(Pred)))
|
||||||
add(IC, ConstantInt::getFalse(), ICmpInst::ICMP_EQ, NewContext);
|
add(IC, Context->getConstantIntFalse(),
|
||||||
|
ICmpInst::ICMP_EQ, NewContext);
|
||||||
|
|
||||||
} else if (SelectInst *SI = dyn_cast<SelectInst>(I)) {
|
} else if (SelectInst *SI = dyn_cast<SelectInst>(I)) {
|
||||||
if (I->getType()->isFPOrFPVector()) return;
|
if (I->getType()->isFPOrFPVector()) return;
|
||||||
@@ -2063,9 +2064,9 @@ namespace {
|
|||||||
// %b EQ %c then %a EQ %b
|
// %b EQ %c then %a EQ %b
|
||||||
|
|
||||||
Value *Canonical = VN.canonicalize(SI->getCondition(), Top);
|
Value *Canonical = VN.canonicalize(SI->getCondition(), Top);
|
||||||
if (Canonical == ConstantInt::getTrue()) {
|
if (Canonical == Context->getConstantIntTrue()) {
|
||||||
add(SI, SI->getTrueValue(), ICmpInst::ICMP_EQ, NewContext);
|
add(SI, SI->getTrueValue(), ICmpInst::ICMP_EQ, NewContext);
|
||||||
} else if (Canonical == ConstantInt::getFalse()) {
|
} else if (Canonical == Context->getConstantIntFalse()) {
|
||||||
add(SI, SI->getFalseValue(), ICmpInst::ICMP_EQ, NewContext);
|
add(SI, SI->getFalseValue(), ICmpInst::ICMP_EQ, NewContext);
|
||||||
} else if (VN.canonicalize(SI->getTrueValue(), Top) ==
|
} else if (VN.canonicalize(SI->getTrueValue(), Top) ==
|
||||||
VN.canonicalize(SI->getFalseValue(), Top)) {
|
VN.canonicalize(SI->getFalseValue(), Top)) {
|
||||||
@@ -2154,8 +2155,8 @@ namespace {
|
|||||||
// the BB as unreachable if so.
|
// the BB as unreachable if so.
|
||||||
if (Constant *CI_L = dyn_cast<Constant>(O.LHS)) {
|
if (Constant *CI_L = dyn_cast<Constant>(O.LHS)) {
|
||||||
if (Constant *CI_R = dyn_cast<Constant>(O.RHS)) {
|
if (Constant *CI_R = dyn_cast<Constant>(O.RHS)) {
|
||||||
if (ConstantExpr::getCompare(O.Op, CI_L, CI_R) ==
|
if (Context->getConstantExprCompare(O.Op, CI_L, CI_R) ==
|
||||||
ConstantInt::getFalse())
|
Context->getConstantIntFalse())
|
||||||
UB.mark(TopBB);
|
UB.mark(TopBB);
|
||||||
|
|
||||||
WorkList.pop_front();
|
WorkList.pop_front();
|
||||||
@@ -2446,6 +2447,8 @@ namespace {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLVMContext *Context = BI.getParent()->getContext();
|
||||||
|
|
||||||
for (DomTreeDFS::Node::iterator I = DTNode->begin(), E = DTNode->end();
|
for (DomTreeDFS::Node::iterator I = DTNode->begin(), E = DTNode->end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
BasicBlock *Dest = (*I)->getBlock();
|
BasicBlock *Dest = (*I)->getBlock();
|
||||||
@@ -2455,7 +2458,7 @@ namespace {
|
|||||||
if (Dest == TrueDest) {
|
if (Dest == TrueDest) {
|
||||||
DOUT << "(" << DTNode->getBlock()->getName() << ") true set:\n";
|
DOUT << "(" << DTNode->getBlock()->getName() << ") true set:\n";
|
||||||
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, Dest);
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, Dest);
|
||||||
VRP.add(ConstantInt::getTrue(), Condition, ICmpInst::ICMP_EQ);
|
VRP.add(Context->getConstantIntTrue(), Condition, ICmpInst::ICMP_EQ);
|
||||||
VRP.solve();
|
VRP.solve();
|
||||||
DEBUG(VN.dump());
|
DEBUG(VN.dump());
|
||||||
DEBUG(IG.dump());
|
DEBUG(IG.dump());
|
||||||
@@ -2463,7 +2466,7 @@ namespace {
|
|||||||
} else if (Dest == FalseDest) {
|
} else if (Dest == FalseDest) {
|
||||||
DOUT << "(" << DTNode->getBlock()->getName() << ") false set:\n";
|
DOUT << "(" << DTNode->getBlock()->getName() << ") false set:\n";
|
||||||
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, Dest);
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, Dest);
|
||||||
VRP.add(ConstantInt::getFalse(), Condition, ICmpInst::ICMP_EQ);
|
VRP.add(Context->getConstantIntFalse(), Condition, ICmpInst::ICMP_EQ);
|
||||||
VRP.solve();
|
VRP.solve();
|
||||||
DEBUG(VN.dump());
|
DEBUG(VN.dump());
|
||||||
DEBUG(IG.dump());
|
DEBUG(IG.dump());
|
||||||
|
|||||||
@@ -169,28 +169,6 @@ ConstantInt::ConstantInt(const IntegerType *Ty, const APInt& V)
|
|||||||
assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type");
|
assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type");
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantInt *ConstantInt::TheTrueVal = 0;
|
|
||||||
ConstantInt *ConstantInt::TheFalseVal = 0;
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
void CleanupTrueFalse(void *) {
|
|
||||||
ConstantInt::ResetTrueFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ManagedCleanup<llvm::CleanupTrueFalse> TrueFalseCleanup;
|
|
||||||
|
|
||||||
ConstantInt *ConstantInt::CreateTrueFalseVals(bool WhichOne) {
|
|
||||||
assert(TheTrueVal == 0 && TheFalseVal == 0);
|
|
||||||
TheTrueVal = getGlobalContext().getConstantInt(Type::Int1Ty, 1);
|
|
||||||
TheFalseVal = getGlobalContext().getConstantInt(Type::Int1Ty, 0);
|
|
||||||
|
|
||||||
// Ensure that llvm_shutdown nulls out TheTrueVal/TheFalseVal.
|
|
||||||
TrueFalseCleanup.Register();
|
|
||||||
|
|
||||||
return WhichOne ? TheTrueVal : TheFalseVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// ConstantFP
|
// ConstantFP
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|||||||
@@ -81,11 +81,15 @@ UndefValue* LLVMContext::getUndef(const Type* Ty) {
|
|||||||
|
|
||||||
// ConstantInt accessors.
|
// ConstantInt accessors.
|
||||||
ConstantInt* LLVMContext::getConstantIntTrue() {
|
ConstantInt* LLVMContext::getConstantIntTrue() {
|
||||||
return ConstantInt::getTrue();
|
assert(this && "Context not initialized!");
|
||||||
|
assert(pImpl && "Context not initialized!");
|
||||||
|
return pImpl->getConstantIntTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantInt* LLVMContext::getConstantIntFalse() {
|
ConstantInt* LLVMContext::getConstantIntFalse() {
|
||||||
return ConstantInt::getFalse();
|
assert(this && "Context not initialized!");
|
||||||
|
assert(pImpl && "Context not initialized!");
|
||||||
|
return pImpl->getConstantIntFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
|
Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
#ifndef LLVM_LLVMCONTEXT_IMPL_H
|
#ifndef LLVM_LLVMCONTEXT_IMPL_H
|
||||||
#define LLVM_LLVMCONTEXT_IMPL_H
|
#define LLVM_LLVMCONTEXT_IMPL_H
|
||||||
|
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/System/RWMutex.h"
|
#include "llvm/System/RWMutex.h"
|
||||||
#include "llvm/ADT/APFloat.h"
|
#include "llvm/ADT/APFloat.h"
|
||||||
#include "llvm/ADT/APInt.h"
|
#include "llvm/ADT/APInt.h"
|
||||||
@@ -100,10 +102,13 @@ class LLVMContextImpl {
|
|||||||
FoldingSet<MDNode> MDNodeSet;
|
FoldingSet<MDNode> MDNodeSet;
|
||||||
|
|
||||||
LLVMContext &Context;
|
LLVMContext &Context;
|
||||||
|
ConstantInt *TheTrueVal;
|
||||||
|
ConstantInt *TheFalseVal;
|
||||||
|
|
||||||
LLVMContextImpl();
|
LLVMContextImpl();
|
||||||
LLVMContextImpl(const LLVMContextImpl&);
|
LLVMContextImpl(const LLVMContextImpl&);
|
||||||
public:
|
public:
|
||||||
LLVMContextImpl(LLVMContext &C) : Context(C) { }
|
LLVMContextImpl(LLVMContext &C) : Context(C), TheTrueVal(0), TheFalseVal(0) {}
|
||||||
|
|
||||||
/// Return a ConstantInt with the specified value and an implied Type. The
|
/// Return a ConstantInt with the specified value and an implied Type. The
|
||||||
/// type is the integer type that corresponds to the bit width of the value.
|
/// type is the integer type that corresponds to the bit width of the value.
|
||||||
@@ -115,6 +120,20 @@ public:
|
|||||||
|
|
||||||
MDNode *getMDNode(Value*const* Vals, unsigned NumVals);
|
MDNode *getMDNode(Value*const* Vals, unsigned NumVals);
|
||||||
|
|
||||||
|
ConstantInt *getConstantIntTrue() {
|
||||||
|
if (TheTrueVal)
|
||||||
|
return TheTrueVal;
|
||||||
|
else
|
||||||
|
return (TheTrueVal = Context.getConstantInt(IntegerType::get(1), 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstantInt *getConstantIntFalse() {
|
||||||
|
if (TheFalseVal)
|
||||||
|
return TheFalseVal;
|
||||||
|
else
|
||||||
|
return (TheFalseVal = Context.getConstantInt(IntegerType::get(1), 0));
|
||||||
|
}
|
||||||
|
|
||||||
void erase(MDString *M);
|
void erase(MDString *M);
|
||||||
void erase(MDNode *M);
|
void erase(MDNode *M);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user