mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-18 01:17:46 +00:00
Move more functionality over to LLVMContext.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75497 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
69fbc7f477
commit
73c6b7127a
@ -60,11 +60,6 @@ protected:
|
||||
|
||||
void destroyConstantImpl();
|
||||
public:
|
||||
/// Static constructor to get a '-1' constant. This supports integers and
|
||||
/// vectors.
|
||||
///
|
||||
static Constant *getAllOnesValue(const Type *Ty);
|
||||
|
||||
/// isNullValue - Return true if this is the value that would be returned by
|
||||
/// getNullValue.
|
||||
virtual bool isNullValue() const = 0;
|
||||
|
@ -227,11 +227,6 @@ public:
|
||||
return Val.getLimitedValue(Limit);
|
||||
}
|
||||
|
||||
/// @returns the value for an integer constant of the given type that has all
|
||||
/// its bits set to true.
|
||||
/// @brief Get the all ones value
|
||||
static ConstantInt *getAllOnesValue(const Type *Ty);
|
||||
|
||||
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
|
||||
static inline bool classof(const ConstantInt *) { return true; }
|
||||
static bool classof(const Value *V) {
|
||||
@ -487,11 +482,6 @@ public:
|
||||
inline const VectorType *getType() const {
|
||||
return reinterpret_cast<const VectorType*>(Value::getType());
|
||||
}
|
||||
|
||||
/// @returns the value for a vector integer constant of the given type that
|
||||
/// has all its bits set to true.
|
||||
/// @brief Get the all ones value
|
||||
static ConstantVector *getAllOnesValue(const VectorType *Ty);
|
||||
|
||||
/// isNullValue - Return true if this is the value that would be returned by
|
||||
/// getNullValue. This always returns false because zero vectors are always
|
||||
@ -702,7 +692,6 @@ public:
|
||||
/// ConstantExpr::get* - Return some common constants without having to
|
||||
/// specify the full Instruction::OPCODE identifier.
|
||||
///
|
||||
static Constant *getNot(Constant *C);
|
||||
static Constant *getAdd(Constant *C1, Constant *C2);
|
||||
static Constant *getFAdd(Constant *C1, Constant *C2);
|
||||
static Constant *getSub(Constant *C1, Constant *C2);
|
||||
|
@ -214,9 +214,11 @@ public:
|
||||
static BinaryOperator *CreateFNeg(LLVMContext &Context,
|
||||
Value *Op, const std::string &Name,
|
||||
BasicBlock *InsertAtEnd);
|
||||
static BinaryOperator *CreateNot(Value *Op, const std::string &Name = "",
|
||||
static BinaryOperator *CreateNot(LLVMContext &Context,
|
||||
Value *Op, const std::string &Name = "",
|
||||
Instruction *InsertBefore = 0);
|
||||
static BinaryOperator *CreateNot(Value *Op, const std::string &Name,
|
||||
static BinaryOperator *CreateNot(LLVMContext &Context,
|
||||
Value *Op, const std::string &Name,
|
||||
BasicBlock *InsertAtEnd);
|
||||
|
||||
/// isNeg, isFNeg, isNot - Check if the given Value is a
|
||||
|
@ -58,6 +58,10 @@ public:
|
||||
|
||||
// Constant accessors
|
||||
Constant* getNullValue(const Type* Ty);
|
||||
|
||||
/// @returns the value for an integer constant of the given type that has all
|
||||
/// its bits set to true.
|
||||
/// @brief Get the all ones value
|
||||
Constant* getAllOnesValue(const Type* Ty);
|
||||
|
||||
// UndefValue accessors
|
||||
@ -73,7 +77,6 @@ public:
|
||||
ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
|
||||
ConstantInt* getConstantInt(const APInt& V);
|
||||
Constant* getConstantInt(const Type* Ty, const APInt& V);
|
||||
ConstantInt* getConstantIntAllOnesValue(const Type* Ty);
|
||||
|
||||
// ConstantPointerNull accessors
|
||||
ConstantPointerNull* getConstantPointerNull(const PointerType* T);
|
||||
@ -188,7 +191,6 @@ public:
|
||||
const std::vector<Constant*>& V);
|
||||
Constant* getConstantVector(const std::vector<Constant*>& V);
|
||||
Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
|
||||
ConstantVector* getConstantVectorAllOnesValue(const VectorType* Ty);
|
||||
|
||||
// MDNode accessors
|
||||
MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
|
||||
|
@ -311,17 +311,17 @@ public:
|
||||
Value *CreateNeg(Value *V, const char *Name = "") {
|
||||
if (Constant *VC = dyn_cast<Constant>(V))
|
||||
return Folder.CreateNeg(VC);
|
||||
return Insert(BinaryOperator::CreateNeg(getGlobalContext(), V), Name);
|
||||
return Insert(BinaryOperator::CreateNeg(Context, V), Name);
|
||||
}
|
||||
Value *CreateFNeg(Value *V, const char *Name = "") {
|
||||
if (Constant *VC = dyn_cast<Constant>(V))
|
||||
return Folder.CreateFNeg(VC);
|
||||
return Insert(BinaryOperator::CreateFNeg(getGlobalContext(), V), Name);
|
||||
return Insert(BinaryOperator::CreateFNeg(Context, V), Name);
|
||||
}
|
||||
Value *CreateNot(Value *V, const char *Name = "") {
|
||||
if (Constant *VC = dyn_cast<Constant>(V))
|
||||
return Folder.CreateNot(VC);
|
||||
return Insert(BinaryOperator::CreateNot(V), Name);
|
||||
return Insert(BinaryOperator::CreateNot(Context, V), Name);
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
@ -2067,17 +2067,20 @@ const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V) {
|
||||
|
||||
const Type *Ty = V->getType();
|
||||
Ty = getEffectiveSCEVType(Ty);
|
||||
return getMulExpr(V, getConstant(ConstantInt::getAllOnesValue(Ty)));
|
||||
return getMulExpr(V,
|
||||
getConstant(cast<ConstantInt>(Context->getAllOnesValue(Ty))));
|
||||
}
|
||||
|
||||
/// getNotSCEV - Return a SCEV corresponding to ~V = -1-V
|
||||
const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) {
|
||||
if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
|
||||
return getConstant(cast<ConstantInt>(ConstantExpr::getNot(VC->getValue())));
|
||||
return getConstant(
|
||||
cast<ConstantInt>(Context->getConstantExprNot(VC->getValue())));
|
||||
|
||||
const Type *Ty = V->getType();
|
||||
Ty = getEffectiveSCEVType(Ty);
|
||||
const SCEV *AllOnes = getConstant(ConstantInt::getAllOnesValue(Ty));
|
||||
const SCEV *AllOnes =
|
||||
getConstant(cast<ConstantInt>(Context->getAllOnesValue(Ty)));
|
||||
return getMinusSCEV(AllOnes, V);
|
||||
}
|
||||
|
||||
|
@ -2314,7 +2314,7 @@ MachineInstr* X86InstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
|
||||
const VectorType *Ty = VectorType::get(Type::Int32Ty, 4);
|
||||
Constant *C = LoadMI->getOpcode() == X86::V_SET0 ?
|
||||
MF.getFunction()->getContext()->getNullValue(Ty) :
|
||||
ConstantVector::getAllOnesValue(Ty);
|
||||
MF.getFunction()->getContext()->getAllOnesValue(Ty);
|
||||
unsigned CPI = MCP.getConstantPoolIndex(C, 16);
|
||||
|
||||
// Create operands to load from the constant pool entry.
|
||||
|
@ -891,7 +891,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
|
||||
case ICmpInst::ICMP_ULE:
|
||||
case ICmpInst::ICMP_SLE:
|
||||
case ICmpInst::ICMP_EQ:
|
||||
LV = BinaryOperator::CreateNot(LV, "notinit", CI);
|
||||
LV = BinaryOperator::CreateNot(*Context, LV, "notinit", CI);
|
||||
break;
|
||||
case ICmpInst::ICMP_NE:
|
||||
case ICmpInst::ICMP_UGE:
|
||||
|
@ -2107,7 +2107,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
||||
ZI->getOperand(0)->getType() == Type::Int1Ty)
|
||||
return SelectInst::Create(ZI->getOperand(0),
|
||||
Context->getNullValue(I.getType()),
|
||||
Context->getConstantIntAllOnesValue(I.getType()));
|
||||
Context->getAllOnesValue(I.getType()));
|
||||
}
|
||||
|
||||
if (isa<PHINode>(LHS))
|
||||
@ -2485,7 +2485,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
if (ConstantInt *C = dyn_cast<ConstantInt>(Op0)) {
|
||||
// Replace (-1 - A) with (~A)...
|
||||
if (C->isAllOnesValue())
|
||||
return BinaryOperator::CreateNot(Op1);
|
||||
return BinaryOperator::CreateNot(*Context, Op1);
|
||||
|
||||
// C - ~X == X + (1+C)
|
||||
Value *X = 0;
|
||||
@ -2567,7 +2567,8 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
Value *OtherOp = Op1I->getOperand(Op1I->getOperand(0) == Op0);
|
||||
|
||||
Value *NewNot =
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(OtherOp, "B.not"), I);
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(*Context,
|
||||
OtherOp, "B.not"), I);
|
||||
return BinaryOperator::CreateAnd(Op0, NewNot);
|
||||
}
|
||||
|
||||
@ -3219,7 +3220,7 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) {
|
||||
if (RHSI->getOpcode() == Instruction::Shl &&
|
||||
isa<ConstantInt>(RHSI->getOperand(0))) {
|
||||
if (cast<ConstantInt>(RHSI->getOperand(0))->getValue().isPowerOf2()) {
|
||||
Constant *N1 = Context->getConstantIntAllOnesValue(I.getType());
|
||||
Constant *N1 = Context->getAllOnesValue(I.getType());
|
||||
Value *Add = InsertNewInstBefore(BinaryOperator::CreateAdd(RHSI, N1,
|
||||
"tmp"), I);
|
||||
return BinaryOperator::CreateAnd(Op0, Add);
|
||||
@ -4128,7 +4129,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
||||
Instruction *Or = BinaryOperator::CreateOr(Op0NotVal, Op1NotVal,
|
||||
I.getName()+".demorgan");
|
||||
InsertNewInstBefore(Or, I);
|
||||
return BinaryOperator::CreateNot(Or);
|
||||
return BinaryOperator::CreateNot(*Context, Or);
|
||||
}
|
||||
|
||||
{
|
||||
@ -4174,7 +4175,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
||||
std::swap(A, B);
|
||||
}
|
||||
if (A == Op0) { // A&(A^B) -> A & ~B
|
||||
Instruction *NotB = BinaryOperator::CreateNot(B, "tmp");
|
||||
Instruction *NotB = BinaryOperator::CreateNot(*Context, B, "tmp");
|
||||
InsertNewInstBefore(NotB, I);
|
||||
return BinaryOperator::CreateAnd(A, NotB);
|
||||
}
|
||||
@ -4902,7 +4903,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||
if (A && isOnlyUse(Op0) && isOnlyUse(Op1)) {
|
||||
Value *And = InsertNewInstBefore(BinaryOperator::CreateAnd(A, B,
|
||||
I.getName()+".demorgan"), I);
|
||||
return BinaryOperator::CreateNot(And);
|
||||
return BinaryOperator::CreateNot(*Context, And);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5056,7 +5057,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
if (dyn_castNotVal(Op0I->getOperand(1), Context)) Op0I->swapOperands();
|
||||
if (Value *Op0NotVal = dyn_castNotVal(Op0I->getOperand(0), Context)) {
|
||||
Instruction *NotY =
|
||||
BinaryOperator::CreateNot(Op0I->getOperand(1),
|
||||
BinaryOperator::CreateNot(*Context, Op0I->getOperand(1),
|
||||
Op0I->getOperand(1)->getName()+".not");
|
||||
InsertNewInstBefore(NotY, I);
|
||||
if (Op0I->getOpcode() == Instruction::And)
|
||||
@ -5202,7 +5203,8 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
std::swap(A, B);
|
||||
if (B == Op1) { // (A|B)^B == A & ~B
|
||||
Instruction *NotB =
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(Op1, "tmp"), I);
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(*Context,
|
||||
Op1, "tmp"), I);
|
||||
return BinaryOperator::CreateAnd(A, NotB);
|
||||
}
|
||||
} else if (match(Op0I, m_Xor(m_Specific(Op1), m_Value(B)), *Context)) {
|
||||
@ -5216,7 +5218,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
if (B == Op1 && // (B&A)^A == ~B & A
|
||||
!isa<ConstantInt>(Op1)) { // Canonical form is (B&C)^C
|
||||
Instruction *N =
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(A, "tmp"), I);
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(*Context, A, "tmp"), I);
|
||||
return BinaryOperator::CreateAnd(N, Op1);
|
||||
}
|
||||
}
|
||||
@ -6006,7 +6008,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
case ICmpInst::ICMP_EQ: { // icmp eq i1 A, B -> ~(A^B)
|
||||
Instruction *Xor = BinaryOperator::CreateXor(Op0, Op1, I.getName()+"tmp");
|
||||
InsertNewInstBefore(Xor, I);
|
||||
return BinaryOperator::CreateNot(Xor);
|
||||
return BinaryOperator::CreateNot(*Context, Xor);
|
||||
}
|
||||
case ICmpInst::ICMP_NE: // icmp eq i1 A, B -> A^B
|
||||
return BinaryOperator::CreateXor(Op0, Op1);
|
||||
@ -6015,7 +6017,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
std::swap(Op0, Op1); // Change icmp ugt -> icmp ult
|
||||
// FALL THROUGH
|
||||
case ICmpInst::ICMP_ULT:{ // icmp ult i1 A, B -> ~A & B
|
||||
Instruction *Not = BinaryOperator::CreateNot(Op0, I.getName()+"tmp");
|
||||
Instruction *Not = BinaryOperator::CreateNot(*Context,
|
||||
Op0, I.getName()+"tmp");
|
||||
InsertNewInstBefore(Not, I);
|
||||
return BinaryOperator::CreateAnd(Not, Op1);
|
||||
}
|
||||
@ -6023,7 +6026,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
std::swap(Op0, Op1); // Change icmp sgt -> icmp slt
|
||||
// FALL THROUGH
|
||||
case ICmpInst::ICMP_SLT: { // icmp slt i1 A, B -> A & ~B
|
||||
Instruction *Not = BinaryOperator::CreateNot(Op1, I.getName()+"tmp");
|
||||
Instruction *Not = BinaryOperator::CreateNot(*Context,
|
||||
Op1, I.getName()+"tmp");
|
||||
InsertNewInstBefore(Not, I);
|
||||
return BinaryOperator::CreateAnd(Not, Op0);
|
||||
}
|
||||
@ -6031,7 +6035,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
std::swap(Op0, Op1); // Change icmp uge -> icmp ule
|
||||
// FALL THROUGH
|
||||
case ICmpInst::ICMP_ULE: { // icmp ule i1 A, B -> ~A | B
|
||||
Instruction *Not = BinaryOperator::CreateNot(Op0, I.getName()+"tmp");
|
||||
Instruction *Not = BinaryOperator::CreateNot(*Context,
|
||||
Op0, I.getName()+"tmp");
|
||||
InsertNewInstBefore(Not, I);
|
||||
return BinaryOperator::CreateOr(Not, Op1);
|
||||
}
|
||||
@ -6039,7 +6044,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
std::swap(Op0, Op1); // Change icmp sge -> icmp sle
|
||||
// FALL THROUGH
|
||||
case ICmpInst::ICMP_SLE: { // icmp sle i1 A, B -> A | ~B
|
||||
Instruction *Not = BinaryOperator::CreateNot(Op1, I.getName()+"tmp");
|
||||
Instruction *Not = BinaryOperator::CreateNot(*Context,
|
||||
Op1, I.getName()+"tmp");
|
||||
InsertNewInstBefore(Not, I);
|
||||
return BinaryOperator::CreateOr(Not, Op0);
|
||||
}
|
||||
@ -6168,7 +6174,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
// (x <u 2147483648) -> (x >s -1) -> true if sign bit clear
|
||||
if (CI->isMinValue(true))
|
||||
return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0,
|
||||
Context->getConstantIntAllOnesValue(Op0->getType()));
|
||||
Context->getAllOnesValue(Op0->getType()));
|
||||
}
|
||||
break;
|
||||
case ICmpInst::ICMP_UGT:
|
||||
@ -7298,7 +7304,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
|
||||
if (isSignedExt) {
|
||||
// We're performing an unsigned comp with a sign extended value.
|
||||
// This is true if the input is >= 0. [aka >s -1]
|
||||
Constant *NegOne = Context->getConstantIntAllOnesValue(SrcTy);
|
||||
Constant *NegOne = Context->getAllOnesValue(SrcTy);
|
||||
Result = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_SGT,
|
||||
LHSCIOp, NegOne, ICI.getName()), ICI);
|
||||
} else {
|
||||
@ -7317,7 +7323,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
|
||||
"ICmp should be folded!");
|
||||
if (Constant *CI = dyn_cast<Constant>(Result))
|
||||
return ReplaceInstUsesWith(ICI, Context->getConstantExprNot(CI));
|
||||
return BinaryOperator::CreateNot(Result);
|
||||
return BinaryOperator::CreateNot(*Context, Result);
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitShl(BinaryOperator &I) {
|
||||
@ -8718,7 +8724,7 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
|
||||
// Canonicalize sign-extend from i1 to a select.
|
||||
if (Src->getType() == Type::Int1Ty)
|
||||
return SelectInst::Create(Src,
|
||||
Context->getConstantIntAllOnesValue(CI.getType()),
|
||||
Context->getAllOnesValue(CI.getType()),
|
||||
Context->getNullValue(CI.getType()));
|
||||
|
||||
// See if the value being truncated is already sign extended. If so, just
|
||||
@ -9373,7 +9379,7 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI,
|
||||
true/*SExt*/, "tmp", ICI);
|
||||
|
||||
if (Pred == ICmpInst::ICMP_SGT)
|
||||
In = InsertNewInstBefore(BinaryOperator::CreateNot(In,
|
||||
In = InsertNewInstBefore(BinaryOperator::CreateNot(*Context, In,
|
||||
In->getName()+".not"), *ICI);
|
||||
|
||||
return ReplaceInstUsesWith(SI, In);
|
||||
@ -9438,7 +9444,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
} else {
|
||||
// Change: A = select B, false, C --> A = and !B, C
|
||||
Value *NotCond =
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(CondVal,
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(*Context, CondVal,
|
||||
"not."+CondVal->getName()), SI);
|
||||
return BinaryOperator::CreateAnd(NotCond, FalseVal);
|
||||
}
|
||||
@ -9449,7 +9455,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
} else {
|
||||
// Change: A = select B, C, true --> A = or !B, C
|
||||
Value *NotCond =
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(CondVal,
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(*Context, CondVal,
|
||||
"not."+CondVal->getName()), SI);
|
||||
return BinaryOperator::CreateOr(NotCond, TrueVal);
|
||||
}
|
||||
@ -9472,7 +9478,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
} else if (TrueValC->isZero() && FalseValC->getValue() == 1) {
|
||||
// select C, 0, 1 -> zext !C to int
|
||||
Value *NotCond =
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(CondVal,
|
||||
InsertNewInstBefore(BinaryOperator::CreateNot(*Context, CondVal,
|
||||
"not."+CondVal->getName()), SI);
|
||||
return CastInst::Create(Instruction::ZExt, NotCond, SI.getType());
|
||||
}
|
||||
|
@ -1754,7 +1754,7 @@ namespace {
|
||||
switch (BO->getOpcode()) {
|
||||
case Instruction::And: {
|
||||
// "and i32 %a, %b" EQ -1 then %a EQ -1 and %b EQ -1
|
||||
ConstantInt *CI = ConstantInt::getAllOnesValue(Ty);
|
||||
ConstantInt *CI = cast<ConstantInt>(Context->getAllOnesValue(Ty));
|
||||
if (Canonical == CI) {
|
||||
add(CI, Op0, ICmpInst::ICMP_EQ, NewContext);
|
||||
add(CI, Op1, ICmpInst::ICMP_EQ, NewContext);
|
||||
@ -1892,7 +1892,7 @@ namespace {
|
||||
|
||||
Constant *Zero = Context->getNullValue(Ty);
|
||||
Constant *One = ConstantInt::get(Ty, 1);
|
||||
ConstantInt *AllOnes = ConstantInt::getAllOnesValue(Ty);
|
||||
ConstantInt *AllOnes = cast<ConstantInt>(Context->getAllOnesValue(Ty));
|
||||
|
||||
switch (Opcode) {
|
||||
default: break;
|
||||
|
@ -201,7 +201,7 @@ static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
|
||||
static Instruction *LowerNegateToMultiply(Instruction *Neg,
|
||||
std::map<AssertingVH<>, unsigned> &ValueRankMap,
|
||||
LLVMContext *Context) {
|
||||
Constant *Cst = Context->getConstantIntAllOnesValue(Neg->getType());
|
||||
Constant *Cst = Context->getAllOnesValue(Neg->getType());
|
||||
|
||||
Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg);
|
||||
ValueRankMap.erase(Neg);
|
||||
@ -626,7 +626,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
|
||||
return Context->getNullValue(X->getType());
|
||||
} else if (Opcode == Instruction::Or) { // ...|X|~X = -1
|
||||
++NumAnnihil;
|
||||
return Context->getConstantIntAllOnesValue(X->getType());
|
||||
return Context->getAllOnesValue(X->getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -814,10 +814,10 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
|
||||
if (I.getOpcode() == Instruction::And)
|
||||
markConstant(IV, &I, Context->getNullValue(I.getType()));
|
||||
else if (const VectorType *PT = dyn_cast<VectorType>(I.getType()))
|
||||
markConstant(IV, &I, Context->getConstantVectorAllOnesValue(PT));
|
||||
markConstant(IV, &I, Context->getAllOnesValue(PT));
|
||||
else
|
||||
markConstant(IV, &I,
|
||||
Context->getConstantIntAllOnesValue(I.getType()));
|
||||
Context->getAllOnesValue(I.getType()));
|
||||
return;
|
||||
} else {
|
||||
if (I.getOpcode() == Instruction::And) {
|
||||
@ -1388,9 +1388,9 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
|
||||
// undef | X -> -1. X could be -1.
|
||||
if (const VectorType *PTy = dyn_cast<VectorType>(ITy))
|
||||
markForcedConstant(LV, I,
|
||||
Context->getConstantVectorAllOnesValue(PTy));
|
||||
Context->getAllOnesValue(PTy));
|
||||
else
|
||||
markForcedConstant(LV, I, Context->getConstantIntAllOnesValue(ITy));
|
||||
markForcedConstant(LV, I, Context->getAllOnesValue(ITy));
|
||||
return true;
|
||||
|
||||
case Instruction::SDiv:
|
||||
|
@ -1225,7 +1225,7 @@ struct VISIBILITY_HIDDEN AbsOpt : public LibCallOptimization {
|
||||
// abs(x) -> x >s -1 ? x : -x
|
||||
Value *Op = CI->getOperand(1);
|
||||
Value *Pos = B.CreateICmpSGT(Op,
|
||||
Context->getConstantIntAllOnesValue(Op->getType()),
|
||||
Context->getAllOnesValue(Op->getType()),
|
||||
"ispos");
|
||||
Value *Neg = B.CreateNeg(Op, "neg");
|
||||
return B.CreateSelect(Pos, Op, Neg);
|
||||
|
@ -1570,7 +1570,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
|
||||
// If we need to invert the condition in the pred block to match, do so now.
|
||||
if (InvertPredCond) {
|
||||
Value *NewCond =
|
||||
BinaryOperator::CreateNot(PBI->getCondition(),
|
||||
BinaryOperator::CreateNot(*BI->getParent()->getContext(),
|
||||
PBI->getCondition(),
|
||||
PBI->getCondition()->getName()+".not", PBI);
|
||||
PBI->setCondition(NewCond);
|
||||
BasicBlock *OldTrue = PBI->getSuccessor(0);
|
||||
@ -1726,12 +1727,12 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
||||
// Make sure we get to CommonDest on True&True directions.
|
||||
Value *PBICond = PBI->getCondition();
|
||||
if (PBIOp)
|
||||
PBICond = BinaryOperator::CreateNot(PBICond,
|
||||
PBICond = BinaryOperator::CreateNot(*Context, PBICond,
|
||||
PBICond->getName()+".not",
|
||||
PBI);
|
||||
Value *BICond = BI->getCondition();
|
||||
if (BIOp)
|
||||
BICond = BinaryOperator::CreateNot(BICond,
|
||||
BICond = BinaryOperator::CreateNot(*Context, BICond,
|
||||
BICond->getName()+".not",
|
||||
PBI);
|
||||
// Merge the conditions.
|
||||
|
@ -128,31 +128,6 @@ bool Constant::ContainsRelocations(unsigned Kind) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
Constant *Constant::getAllOnesValue(const Type *Ty) {
|
||||
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
|
||||
return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
|
||||
return ConstantVector::getAllOnesValue(cast<VectorType>(Ty));
|
||||
}
|
||||
|
||||
// Static constructor to create an integral constant with all bits set
|
||||
ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {
|
||||
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
|
||||
return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @returns the value for a vector integer constant of the given type that
|
||||
/// has all its bits set to true.
|
||||
/// @brief Get the all ones value
|
||||
ConstantVector *ConstantVector::getAllOnesValue(const VectorType *Ty) {
|
||||
std::vector<Constant*> Elts;
|
||||
Elts.resize(Ty->getNumElements(),
|
||||
ConstantInt::getAllOnesValue(Ty->getElementType()));
|
||||
assert(Elts[0] && "Not a vector integer type!");
|
||||
return cast<ConstantVector>(ConstantVector::get(Elts));
|
||||
}
|
||||
|
||||
|
||||
/// getVectorElements - This method, which is only valid on constant of vector
|
||||
/// type, returns the elements of the vector in the specified smallvector.
|
||||
/// This handles breaking down a vector undef into undef elements, etc. For
|
||||
@ -797,12 +772,6 @@ const SmallVector<unsigned, 4> &ConstantExpr::getIndices() const {
|
||||
return cast<InsertValueConstantExpr>(this)->Indices;
|
||||
}
|
||||
|
||||
Constant *ConstantExpr::getNot(Constant *C) {
|
||||
assert(C->getType()->isIntOrIntVector() &&
|
||||
"Cannot NOT a nonintegral value!");
|
||||
return get(Instruction::Xor, C,
|
||||
Constant::getAllOnesValue(C->getType()));
|
||||
}
|
||||
Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2) {
|
||||
return get(Instruction::Add, C1, C2);
|
||||
}
|
||||
|
@ -1669,30 +1669,32 @@ BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
|
||||
Op->getType(), Name, InsertAtEnd);
|
||||
}
|
||||
|
||||
BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
|
||||
BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
|
||||
Value *Op, const std::string &Name,
|
||||
Instruction *InsertBefore) {
|
||||
Constant *C;
|
||||
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
|
||||
C = ConstantInt::getAllOnesValue(PTy->getElementType());
|
||||
C = Context.getAllOnesValue(PTy->getElementType());
|
||||
C = ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), C));
|
||||
} else {
|
||||
C = ConstantInt::getAllOnesValue(Op->getType());
|
||||
C = Context.getAllOnesValue(Op->getType());
|
||||
}
|
||||
|
||||
return new BinaryOperator(Instruction::Xor, Op, C,
|
||||
Op->getType(), Name, InsertBefore);
|
||||
}
|
||||
|
||||
BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
|
||||
BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
|
||||
Value *Op, const std::string &Name,
|
||||
BasicBlock *InsertAtEnd) {
|
||||
Constant *AllOnes;
|
||||
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
|
||||
// Create a vector of all ones values.
|
||||
Constant *Elt = ConstantInt::getAllOnesValue(PTy->getElementType());
|
||||
Constant *Elt = Context.getAllOnesValue(PTy->getElementType());
|
||||
AllOnes =
|
||||
ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), Elt));
|
||||
} else {
|
||||
AllOnes = ConstantInt::getAllOnesValue(Op->getType());
|
||||
AllOnes = Context.getAllOnesValue(Op->getType());
|
||||
}
|
||||
|
||||
return new BinaryOperator(Instruction::Xor, Op, AllOnes,
|
||||
|
@ -64,7 +64,14 @@ Constant* LLVMContext::getNullValue(const Type* Ty) {
|
||||
}
|
||||
|
||||
Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
|
||||
return Constant::getAllOnesValue(Ty);
|
||||
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
|
||||
return getConstantInt(APInt::getAllOnesValue(ITy->getBitWidth()));
|
||||
|
||||
std::vector<Constant*> Elts;
|
||||
const VectorType* VTy = cast<VectorType>(Ty);
|
||||
Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
|
||||
assert(Elts[0] && "Not a vector integer type!");
|
||||
return cast<ConstantVector>(getConstantVector(Elts));
|
||||
}
|
||||
|
||||
// UndefValue accessors.
|
||||
@ -105,11 +112,6 @@ Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
|
||||
return ConstantInt::get(Ty, V);
|
||||
}
|
||||
|
||||
ConstantInt* LLVMContext::getConstantIntAllOnesValue(const Type* Ty) {
|
||||
return ConstantInt::getAllOnesValue(Ty);
|
||||
}
|
||||
|
||||
|
||||
// ConstantPointerNull accessors.
|
||||
ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
|
||||
return ConstantPointerNull::get(T);
|
||||
@ -285,7 +287,9 @@ Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
|
||||
}
|
||||
|
||||
Constant* LLVMContext::getConstantExprNot(Constant* C) {
|
||||
return ConstantExpr::getNot(C);
|
||||
assert(C->getType()->isIntOrIntVector() &&
|
||||
"Cannot NOT a nonintegral value!");
|
||||
return getConstantExpr(Instruction::Xor, C, getAllOnesValue(C->getType()));
|
||||
}
|
||||
|
||||
Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
|
||||
@ -464,11 +468,6 @@ Constant* LLVMContext::getConstantVector(Constant* const* Vals,
|
||||
return ConstantVector::get(Vals, NumVals);
|
||||
}
|
||||
|
||||
ConstantVector* LLVMContext::getConstantVectorAllOnesValue(
|
||||
const VectorType* Ty) {
|
||||
return ConstantVector::getAllOnesValue(Ty);
|
||||
}
|
||||
|
||||
// MDNode accessors
|
||||
MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
|
||||
return MDNode::get(Vals, NumVals);
|
||||
|
Loading…
Reference in New Issue
Block a user