Move a few more APIs back to 2.5 forms. The only remaining ones left to change back are

metadata related, which I'm waiting on to avoid conflicting with Devang.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77721 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2009-07-31 20:28:14 +00:00
parent 2a29899d74
commit a7235ea724
56 changed files with 350 additions and 399 deletions

View File

@ -856,7 +856,7 @@ the loop again and exiting the loop. Any future code is emitted in the
NamedValues.erase(VarName);
// for expr always returns 0.0.
return TheFunction->getContext().getNullValue(Type::DoubleTy);
return Constant::getNullValue(Type::DoubleTy);
}
</pre>
</div>

View File

@ -1570,7 +1570,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
return TheFunction->getContext().getNullValue(Type::DoubleTy);
return Constant::getNullValue(Type::DoubleTy);
}
Function *PrototypeAST::Codegen() {

View File

@ -1858,7 +1858,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
return TheFunction->getContext().getNullValue(Type::DoubleTy);
return Constant::getNullValue(Type::DoubleTy);
}
Value *VarExprAST::Codegen() {

View File

@ -145,7 +145,7 @@ void BrainF::header(LLVMContext& C) {
//call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0))
{
Constant *zero_32 = C.getNullValue(IntegerType::Int32Ty);
Constant *zero_32 = Constant::getNullValue(IntegerType::Int32Ty);
Constant *gep_params[] = {
zero_32,

View File

@ -856,7 +856,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
return TheFunction->getContext().getNullValue(Type::DoubleTy);
return Constant::getNullValue(Type::DoubleTy);
}
Value *VarExprAST::Codegen() {

View File

@ -135,6 +135,13 @@ public:
"implemented for all constants that have operands!");
assert(0 && "Constants that do not have operands cannot be using 'From'!");
}
static 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
static Constant* getAllOnesValue(const Type* Ty);
};
} // End llvm namespace

View File

@ -65,14 +65,6 @@ public:
LLVMContext();
~LLVMContext();
// 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);
// MDNode accessors
MDNode* getMDNode(Value* const* Vals, unsigned NumVals);

View File

@ -705,13 +705,13 @@ public:
/// CreateIsNull - Return an i1 value testing if \arg Arg is null.
Value *CreateIsNull(Value *Arg, const char *Name = "") {
return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()),
return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
Name);
}
/// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
Value *CreateIsNotNull(Value *Arg, const char *Name = "") {
return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()),
return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
Name);
}

View File

@ -308,8 +308,6 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) {
AliasAnalysis::AliasResult
BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
const Value *V2, unsigned V2Size) {
LLVMContext &Context = V1->getType()->getContext();
// Strip off any constant expression casts if they exist
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V1))
if (CE->isCast() && isa<PointerType>(CE->getOperand(0)->getType()))
@ -394,13 +392,13 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
// the base pointers.
while (isGEP(GEP1->getOperand(0)) &&
GEP1->getOperand(1) ==
Context.getNullValue(GEP1->getOperand(1)->getType()))
Constant::getNullValue(GEP1->getOperand(1)->getType()))
GEP1 = cast<User>(GEP1->getOperand(0));
const Value *BasePtr1 = GEP1->getOperand(0);
while (isGEP(GEP2->getOperand(0)) &&
GEP2->getOperand(1) ==
Context.getNullValue(GEP2->getOperand(1)->getType()))
Constant::getNullValue(GEP2->getOperand(1)->getType()))
GEP2 = cast<User>(GEP2->getOperand(0));
const Value *BasePtr2 = GEP2->getOperand(0);
@ -480,7 +478,7 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
for (unsigned i = 0; i != GEPOperands.size(); ++i)
if (!isa<ConstantInt>(GEPOperands[i]))
GEPOperands[i] =
Context.getNullValue(GEPOperands[i]->getType());
Constant::getNullValue(GEPOperands[i]->getType());
int64_t Offset =
TD->getIndexedOffset(BasePtr->getType(),
&GEPOperands[0],
@ -696,7 +694,7 @@ BasicAliasAnalysis::CheckGEPInstructions(
// TargetData::getIndexedOffset.
for (i = 0; i != MaxOperands; ++i)
if (!isa<ConstantInt>(GEP1Ops[i]))
GEP1Ops[i] = Context.getNullValue(GEP1Ops[i]->getType());
GEP1Ops[i] = Constant::getNullValue(GEP1Ops[i]->getType());
// Okay, now get the offset. This is the relative offset for the full
// instruction.
int64_t Offset1 = TD->getIndexedOffset(GEPPointerTy, GEP1Ops,
@ -740,7 +738,7 @@ BasicAliasAnalysis::CheckGEPInstructions(
const Type *ZeroIdxTy = GEPPointerTy;
for (unsigned i = 0; i != FirstConstantOper; ++i) {
if (!isa<StructType>(ZeroIdxTy))
GEP1Ops[i] = GEP2Ops[i] = Context.getNullValue(Type::Int32Ty);
GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::Int32Ty);
if (const CompositeType *CT = dyn_cast<CompositeType>(ZeroIdxTy))
ZeroIdxTy = CT->getTypeAtIndex(GEP1Ops[i]);
@ -755,7 +753,7 @@ BasicAliasAnalysis::CheckGEPInstructions(
// If they are equal, use a zero index...
if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) {
if (!isa<ConstantInt>(Op1))
GEP1Ops[i] = GEP2Ops[i] = Context.getNullValue(Op1->getType());
GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Op1->getType());
// Otherwise, just keep the constants we have.
} else {
if (Op1) {
@ -800,7 +798,7 @@ BasicAliasAnalysis::CheckGEPInstructions(
return MayAlias; // Be conservative with out-of-range accesses
}
} else { // Conservatively assume the minimum value for this index
GEP2Ops[i] = Context.getNullValue(Op2->getType());
GEP2Ops[i] = Constant::getNullValue(Op2->getType());
}
}
}

View File

@ -215,7 +215,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy,
SmallVector<Constant*, 32> Result;
if (NumDstElt < NumSrcElt) {
// Handle: bitcast (<4 x i32> <i32 0, i32 1, i32 2, i32 3> to <2 x i64>)
Constant *Zero = Context.getNullValue(DstEltTy);
Constant *Zero = Constant::getNullValue(DstEltTy);
unsigned Ratio = NumSrcElt/NumDstElt;
unsigned SrcBitSize = SrcEltTy->getPrimitiveSizeInBits();
unsigned SrcElt = 0;
@ -419,7 +419,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
if (ElemIdx.ult(APInt(ElemIdx.getBitWidth(),
AT->getNumElements()))) {
Constant *Index[] = {
Context.getNullValue(CE->getType()),
Constant::getNullValue(CE->getType()),
ConstantInt::get(Context, ElemIdx)
};
return
@ -486,7 +486,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
// proper extension or truncation.
Constant *C = ConstantExpr::getIntegerCast(CE0->getOperand(0),
IntPtrTy, false);
Constant *NewOps[] = { C, Context.getNullValue(C->getType()) };
Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) };
return ConstantFoldCompareInstOperands(Predicate, NewOps, 2,
Context, TD);
}
@ -496,7 +496,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
if (CE0->getOpcode() == Instruction::PtrToInt &&
CE0->getType() == IntPtrTy) {
Constant *C = CE0->getOperand(0);
Constant *NewOps[] = { C, Context.getNullValue(C->getType()) };
Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) };
// FIXME!
return ConstantFoldCompareInstOperands(Predicate, NewOps, 2,
Context, TD);
@ -543,7 +543,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
ConstantExpr *CE,
LLVMContext &Context) {
if (CE->getOperand(1) != Context.getNullValue(CE->getOperand(1)->getType()))
if (CE->getOperand(1) != Constant::getNullValue(CE->getOperand(1)->getType()))
return 0; // Do not allow stepping over the value!
// Loop over all of the operands, tracking down which value we are
@ -558,7 +558,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
C = CS->getOperand(El);
} else if (isa<ConstantAggregateZero>(C)) {
C = Context.getNullValue(STy->getElementType(El));
C = Constant::getNullValue(STy->getElementType(El));
} else if (isa<UndefValue>(C)) {
C = UndefValue::get(STy->getElementType(El));
} else {
@ -571,7 +571,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
if (ConstantArray *CA = dyn_cast<ConstantArray>(C))
C = CA->getOperand(CI->getZExtValue());
else if (isa<ConstantAggregateZero>(C))
C = Context.getNullValue(ATy->getElementType());
C = Constant::getNullValue(ATy->getElementType());
else if (isa<UndefValue>(C))
C = UndefValue::get(ATy->getElementType());
else
@ -582,7 +582,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
if (ConstantVector *CP = dyn_cast<ConstantVector>(C))
C = CP->getOperand(CI->getZExtValue());
else if (isa<ConstantAggregateZero>(C))
C = Context.getNullValue(PTy->getElementType());
C = Constant::getNullValue(PTy->getElementType());
else if (isa<UndefValue>(C))
C = UndefValue::get(PTy->getElementType());
else
@ -741,7 +741,7 @@ llvm::ConstantFoldCall(Function *F,
if (V >= -0.0)
return ConstantFoldFP(sqrt, V, Ty, Context);
else // Undefined
return Context.getNullValue(Ty);
return Constant::getNullValue(Ty);
}
break;
case 's':

View File

@ -476,7 +476,7 @@ DIFactory::DIFactory(Module &m)
/// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
/// This is only valid when the descriptor is non-null.
Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
if (D.isNull()) return VMContext.getNullValue(EmptyStructPtr);
if (D.isNull()) return llvm::Constant::getNullValue(EmptyStructPtr);
return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr);
}
@ -576,7 +576,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
unsigned RunTimeVer) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_compile_unit),
VMContext.getNullValue(EmptyStructPtr),
llvm::Constant::getNullValue(EmptyStructPtr),
ConstantInt::get(Type::Int32Ty, LangID),
GetStringConstant(Filename),
GetStringConstant(Directory),
@ -737,7 +737,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_subprogram),
VMContext.getNullValue(EmptyStructPtr),
llvm::Constant::getNullValue(EmptyStructPtr),
getCastToEmpty(Context),
GetStringConstant(Name),
GetStringConstant(DisplayName),
@ -769,7 +769,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
bool isDefinition, llvm::GlobalVariable *Val) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_variable),
VMContext.getNullValue(EmptyStructPtr),
llvm::Constant::getNullValue(EmptyStructPtr),
getCastToEmpty(Context),
GetStringConstant(Name),
GetStringConstant(DisplayName),

View File

@ -693,7 +693,7 @@ void Andersens::getMustAliases(Value *P, std::vector<Value*> &RetVals) {
// If the object in the points-to set is the null object, then the null
// pointer is a must alias.
if (Pointee == &GraphNodes[NullObject])
RetVals.push_back(P->getContext().getNullValue(P->getType()));
RetVals.push_back(Constant::getNullValue(P->getType()));
}
}
AliasAnalysis::getMustAliases(P, RetVals);

View File

@ -2100,7 +2100,7 @@ const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V) {
const Type *Ty = V->getType();
Ty = getEffectiveSCEVType(Ty);
return getMulExpr(V,
getConstant(cast<ConstantInt>(getContext().getAllOnesValue(Ty))));
getConstant(cast<ConstantInt>(Constant::getAllOnesValue(Ty))));
}
/// getNotSCEV - Return a SCEV corresponding to ~V = -1-V
@ -2112,7 +2112,7 @@ const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) {
const Type *Ty = V->getType();
Ty = getEffectiveSCEVType(Ty);
const SCEV *AllOnes =
getConstant(cast<ConstantInt>(getContext().getAllOnesValue(Ty)));
getConstant(cast<ConstantInt>(Constant::getAllOnesValue(Ty)));
return getMinusSCEV(AllOnes, V);
}
@ -3479,10 +3479,10 @@ GetAddressedElementFromGlobal(LLVMContext &Context, GlobalVariable *GV,
} else if (isa<ConstantAggregateZero>(Init)) {
if (const StructType *STy = dyn_cast<StructType>(Init->getType())) {
assert(Idx < STy->getNumElements() && "Bad struct index!");
Init = Context.getNullValue(STy->getElementType(Idx));
Init = Constant::getNullValue(STy->getElementType(Idx));
} else if (const ArrayType *ATy = dyn_cast<ArrayType>(Init->getType())) {
if (Idx >= ATy->getNumElements()) return 0; // Bogus program
Init = Context.getNullValue(ATy->getElementType());
Init = Constant::getNullValue(ATy->getElementType());
} else {
llvm_unreachable("Unknown constant aggregate type!");
}

View File

@ -285,7 +285,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
Ops = NewOps;
AnyNonZeroIndices |= !ScaledOps.empty();
Value *Scaled = ScaledOps.empty() ?
getContext().getNullValue(Ty) :
Constant::getNullValue(Ty) :
expandCodeFor(SE.getAddExpr(ScaledOps), Ty);
GepIndices.push_back(Scaled);
@ -401,7 +401,7 @@ Value *SCEVExpander::visitMulExpr(const SCEVMulExpr *S) {
// -1 * ... ---> 0 - ...
if (FirstOp == 1)
V = InsertBinop(Instruction::Sub, getContext().getNullValue(Ty), V);
V = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), V);
return V;
}
@ -523,7 +523,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
BasicBlock *Preheader = L->getLoopPreheader();
PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
InsertedValues.insert(PN);
PN->addIncoming(getContext().getNullValue(Ty), Preheader);
PN->addIncoming(Constant::getNullValue(Ty), Preheader);
pred_iterator HPI = pred_begin(Header);
assert(HPI != pred_end(Header) && "Loop with zero preds???");

View File

@ -917,7 +917,7 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
idx_begin,
idx_end));
else if (isa<ConstantAggregateZero>(V))
return Context.getNullValue(ExtractValueInst::getIndexedType(PTy,
return Constant::getNullValue(ExtractValueInst::getIndexedType(PTy,
idx_begin,
idx_end));
else if (Constant *C = dyn_cast<Constant>(V)) {

View File

@ -2211,7 +2211,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
// FIXME: LabelTy should not be a first-class type.
if (!Ty->isFirstClassType() || Ty == Type::LabelTy)
return Error(ID.Loc, "invalid type for null constant");
V = Context.getNullValue(Ty);
V = Constant::getNullValue(Ty);
return false;
case ValID::t_Constant:
if (ID.ConstantVal->getType() != Ty)

View File

@ -898,7 +898,7 @@ bool BitcodeReader::ParseConstants() {
CurTy = TypeList[Record[0]];
continue; // Skip the ValueList manipulation.
case bitc::CST_CODE_NULL: // NULL
V = Context.getNullValue(CurTy);
V = Constant::getNullValue(CurTy);
break;
case bitc::CST_CODE_INTEGER: // INTEGER: [intval]
if (!isa<IntegerType>(CurTy) || Record.empty())
@ -993,7 +993,7 @@ bool BitcodeReader::ParseConstants() {
std::vector<Constant*> Elts;
for (unsigned i = 0; i != Size; ++i)
Elts.push_back(ConstantInt::get(EltTy, Record[i]));
Elts.push_back(Context.getNullValue(EltTy));
Elts.push_back(Constant::getNullValue(EltTy));
V = ConstantArray::get(ATy, Elts);
break;
}

View File

@ -346,7 +346,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
}
case Intrinsic::sigsetjmp:
if (CI->getType() != Type::VoidTy)
CI->replaceAllUsesWith(Context.getNullValue(CI->getType()));
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
break;
case Intrinsic::longjmp: {
@ -393,7 +393,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
"save" : "restore") << " intrinsic.\n";
Warned = true;
if (Callee->getIntrinsicID() == Intrinsic::stacksave)
CI->replaceAllUsesWith(Context.getNullValue(CI->getType()));
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
break;
}
@ -428,7 +428,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
case Intrinsic::eh_exception:
case Intrinsic::eh_selector_i32:
case Intrinsic::eh_selector_i64:
CI->replaceAllUsesWith(Context.getNullValue(CI->getType()));
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
break;
case Intrinsic::eh_typeid_for_i32:

View File

@ -92,7 +92,7 @@ unsigned FastISel::getRegForValue(Value *V) {
} else if (isa<ConstantPointerNull>(V)) {
// Translate this as an integer zero so that it can be
// local-CSE'd with actual integer zeros.
Reg = getRegForValue(V->getContext().getNullValue(TD.getIntPtrType()));
Reg = getRegForValue(Constant::getNullValue(TD.getIntPtrType()));
} else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF);
@ -481,7 +481,7 @@ bool FastISel::SelectCall(User *I) {
UpdateValueMap(I, ResultReg);
} else {
unsigned ResultReg =
getRegForValue(I->getContext().getNullValue(I->getType()));
getRegForValue(Constant::getNullValue(I->getType()));
UpdateValueMap(I, ResultReg);
}
return true;

View File

@ -294,10 +294,10 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) {
// linkage!
Head = new GlobalVariable(M, StackEntryPtrTy, false,
GlobalValue::LinkOnceAnyLinkage,
M.getContext().getNullValue(StackEntryPtrTy),
Constant::getNullValue(StackEntryPtrTy),
"llvm_gc_root_chain");
} else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
Head->setInitializer(M.getContext().getNullValue(StackEntryPtrTy));
Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);
}

View File

@ -68,7 +68,7 @@ bool UnreachableBlockElim::runOnFunction(Function &F) {
BasicBlock *BB = I;
DeadBlocks.push_back(BB);
while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
PN->replaceAllUsesWith(F.getContext().getNullValue(PN->getType()));
PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
BB->getInstList().pop_front();
}
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)

View File

@ -1108,8 +1108,6 @@ static bool LinkAppendingVars(Module *M,
std::string *ErrorMsg) {
if (AppendingVars.empty()) return false; // Nothing to do.
LLVMContext &Context = M->getContext();
// Loop over the multimap of appending vars, processing any variables with the
// same name, forming a new appending global variable with both of the
// initializers merged together, then rewrite references to the old variables
@ -1169,7 +1167,7 @@ static bool LinkAppendingVars(Module *M,
Inits.push_back(I->getOperand(i));
} else {
assert(isa<ConstantAggregateZero>(G1->getInitializer()));
Constant *CV = Context.getNullValue(T1->getElementType());
Constant *CV = Constant::getNullValue(T1->getElementType());
for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i)
Inits.push_back(CV);
}
@ -1178,7 +1176,7 @@ static bool LinkAppendingVars(Module *M,
Inits.push_back(I->getOperand(i));
} else {
assert(isa<ConstantAggregateZero>(G2->getInitializer()));
Constant *CV = Context.getNullValue(T2->getElementType());
Constant *CV = Constant::getNullValue(T2->getElementType());
for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i)
Inits.push_back(CV);
}

View File

@ -1236,7 +1236,7 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
Out << '{';
if (AT->getNumElements()) {
Out << ' ';
Constant *CZ = CPV->getContext().getNullValue(AT->getElementType());
Constant *CZ = Constant::getNullValue(AT->getElementType());
printConstant(CZ, Static);
for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) {
Out << ", ";
@ -1261,7 +1261,7 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
assert(isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV));
const VectorType *VT = cast<VectorType>(CPV->getType());
Out << "{ ";
Constant *CZ = CPV->getContext().getNullValue(VT->getElementType());
Constant *CZ = Constant::getNullValue(VT->getElementType());
printConstant(CZ, Static);
for (unsigned i = 1, e = VT->getNumElements(); i != e; ++i) {
Out << ", ";
@ -1283,12 +1283,10 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
Out << '{';
if (ST->getNumElements()) {
Out << ' ';
printConstant(
CPV->getContext().getNullValue(ST->getElementType(0)), Static);
printConstant(Constant::getNullValue(ST->getElementType(0)), Static);
for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) {
Out << ", ";
printConstant(
CPV->getContext().getNullValue(ST->getElementType(i)), Static);
printConstant(Constant::getNullValue(ST->getElementType(i)), Static);
}
}
Out << " }";

View File

@ -272,7 +272,7 @@ bool X86FastISel::X86FastEmitStore(MVT VT, Value *Val,
const X86AddressMode &AM) {
// Handle 'null' like i32/i64 0.
if (isa<ConstantPointerNull>(Val))
Val = Val->getContext().getNullValue(TD.getIntPtrType());
Val = Constant::getNullValue(TD.getIntPtrType());
// If this is a store of a simple constant, fold the constant into the store.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
@ -672,7 +672,7 @@ bool X86FastISel::X86FastEmitCompare(Value *Op0, Value *Op1, MVT VT) {
// Handle 'null' like i32/i64 0.
if (isa<ConstantPointerNull>(Op1))
Op1 = Op0->getContext().getNullValue(TD.getIntPtrType());
Op1 = Constant::getNullValue(TD.getIntPtrType());
// We have two options: compare with register or immediate. If the RHS of
// the compare is an immediate that we can fold into this compare, use

View File

@ -2297,8 +2297,8 @@ MachineInstr* X86InstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
MachineConstantPool &MCP = *MF.getConstantPool();
const VectorType *Ty = VectorType::get(Type::Int32Ty, 4);
Constant *C = LoadMI->getOpcode() == X86::V_SET0 ?
MF.getFunction()->getContext().getNullValue(Ty) :
MF.getFunction()->getContext().getAllOnesValue(Ty);
Constant::getNullValue(Ty) :
Constant::getAllOnesValue(Ty);
unsigned CPI = MCP.getConstantPoolIndex(C, 16);
// Create operands to load from the constant pool entry.

View File

@ -576,7 +576,6 @@ Function *ArgPromotion::DoPromotion(Function *F,
AttributesVec.push_back(AttributeWithIndex::get(~0, attrs));
const Type *RetTy = FTy->getReturnType();
LLVMContext &Context = RetTy->getContext();
// Work around LLVM bug PR56: the CWriter cannot emit varargs functions which
// have zero fixed arguments.
@ -681,7 +680,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
}
if (ExtraArgHack)
Args.push_back(Context.getNullValue(Type::Int32Ty));
Args.push_back(Constant::getNullValue(Type::Int32Ty));
// Push any varargs arguments on the list
for (; AI != CS.arg_end(); ++AI, ++ArgIndex) {
@ -845,7 +844,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Notify the alias analysis implementation that we inserted a new argument.
if (ExtraArgHack)
AA.copyValue(Context.getNullValue(Type::Int32Ty), NF->arg_begin());
AA.copyValue(Constant::getNullValue(Type::Int32Ty), NF->arg_begin());
// Tell the alias analysis that the old function is about to disappear.

View File

@ -601,8 +601,6 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
const Type *NRetTy = NULL;
unsigned RetCount = NumRetVals(F);
LLVMContext &Context = RetTy->getContext();
// -1 means unused, other numbers are the new index
SmallVector<int, 5> NewRetIdxs(RetCount, -1);
std::vector<const Type*> RetTypes;
@ -797,7 +795,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
} else if (New->getType() == Type::VoidTy) {
// Our return value has uses, but they will get removed later on.
// Replace by null for now.
Call->replaceAllUsesWith(Context.getNullValue(Call->getType()));
Call->replaceAllUsesWith(Constant::getNullValue(Call->getType()));
} else {
assert(isa<StructType>(RetTy) &&
"Return type changed, but not into a void. The old return type"
@ -860,7 +858,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
} else {
// If this argument is dead, replace any uses of it with null constants
// (these are guaranteed to become unused later on).
I->replaceAllUsesWith(Context.getNullValue(I->getType()));
I->replaceAllUsesWith(Constant::getNullValue(I->getType()));
}
// If we change the return value of the function we must rewrite any return

View File

@ -261,10 +261,10 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx,
} else if (isa<ConstantAggregateZero>(Agg)) {
if (const StructType *STy = dyn_cast<StructType>(Agg->getType())) {
if (IdxV < STy->getNumElements())
return Context.getNullValue(STy->getElementType(IdxV));
return Constant::getNullValue(STy->getElementType(IdxV));
} else if (const SequentialType *STy =
dyn_cast<SequentialType>(Agg->getType())) {
return Context.getNullValue(STy->getElementType());
return Constant::getNullValue(STy->getElementType());
}
} else if (isa<UndefValue>(Agg)) {
if (const StructType *STy = dyn_cast<StructType>(Agg->getType())) {
@ -550,7 +550,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
DOUT << "PERFORMING GLOBAL SRA ON: " << *GV;
Constant *NullInt = Context.getNullValue(Type::Int32Ty);
Constant *NullInt = Constant::getNullValue(Type::Int32Ty);
// Loop over all of the uses of the global, replacing the constantexpr geps,
// with smaller constantexpr geps or direct references.
@ -828,10 +828,10 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
Type *NewTy = ArrayType::get(MI->getAllocatedType(),
NElements->getZExtValue());
MallocInst *NewMI =
new MallocInst(NewTy, Context.getNullValue(Type::Int32Ty),
new MallocInst(NewTy, Constant::getNullValue(Type::Int32Ty),
MI->getAlignment(), MI->getName(), MI);
Value* Indices[2];
Indices[0] = Indices[1] = Context.getNullValue(Type::Int32Ty);
Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2,
NewMI->getName()+".el0", MI);
MI->replaceAllUsesWith(NewGEP);
@ -1187,7 +1187,7 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser,
Context);
Value *New = new ICmpInst(SCI, SCI->getPredicate(), NPtr,
Context.getNullValue(NPtr->getType()),
Constant::getNullValue(NPtr->getType()),
SCI->getName());
SCI->replaceAllUsesWith(New);
SCI->eraseFromParent();
@ -1286,7 +1286,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
GlobalVariable *NGV =
new GlobalVariable(*GV->getParent(),
PFieldTy, false, GlobalValue::InternalLinkage,
Context.getNullValue(PFieldTy),
Constant::getNullValue(PFieldTy),
GV->getName() + ".f" + Twine(FieldNo), GV,
GV->isThreadLocal());
FieldGlobals.push_back(NGV);
@ -1312,7 +1312,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
Value *RunningOr = 0;
for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) {
Value *Cond = new ICmpInst(MI, ICmpInst::ICMP_EQ, FieldMallocs[i],
Context.getNullValue(FieldMallocs[i]->getType()),
Constant::getNullValue(FieldMallocs[i]->getType()),
"isnull");
if (!RunningOr)
RunningOr = Cond; // First seteq
@ -1339,7 +1339,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal,
Context.getNullValue(GVVal->getType()),
Constant::getNullValue(GVVal->getType()),
"tmp");
BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent());
BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent());
@ -1347,7 +1347,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// Fill in FreeBlock.
new FreeInst(GVVal, FreeBlock);
new StoreInst(Context.getNullValue(GVVal->getType()), FieldGlobals[i],
new StoreInst(Constant::getNullValue(GVVal->getType()), FieldGlobals[i],
FreeBlock);
BranchInst::Create(NextBlock, FreeBlock);
@ -1387,7 +1387,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// Insert a store of null into each global.
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
const PointerType *PT = cast<PointerType>(FieldGlobals[i]->getType());
Constant *Null = Context.getNullValue(PT->getElementType());
Constant *Null = Constant::getNullValue(PT->getElementType());
new StoreInst(Null, FieldGlobals[i], SI);
}
// Erase the original store.
@ -1958,7 +1958,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
} else {
const Type *FTy = FunctionType::get(Type::VoidTy, false);
const PointerType *PFTy = PointerType::getUnqual(FTy);
CSVals[1] = Context.getNullValue(PFTy);
CSVals[1] = Constant::getNullValue(PFTy);
CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
}
CAList.push_back(ConstantStruct::get(CSVals));
@ -2053,7 +2053,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
Elts.push_back(cast<Constant>(*i));
} else if (isa<ConstantAggregateZero>(Init)) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
Elts.push_back(Context.getNullValue(STy->getElementType(i)));
Elts.push_back(Constant::getNullValue(STy->getElementType(i)));
} else if (isa<UndefValue>(Init)) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
Elts.push_back(UndefValue::get(STy->getElementType(i)));
@ -2080,7 +2080,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i)
Elts.push_back(cast<Constant>(*i));
} else if (isa<ConstantAggregateZero>(Init)) {
Constant *Elt = Context.getNullValue(ATy->getElementType());
Constant *Elt = Constant::getNullValue(ATy->getElementType());
Elts.assign(ATy->getNumElements(), Elt);
} else if (isa<UndefValue>(Init)) {
Constant *Elt = UndefValue::get(ATy->getElementType());
@ -2369,7 +2369,7 @@ static bool EvaluateStaticConstructor(Function *F) {
// silly, e.g. storing the address of the alloca somewhere and using it
// later. Since this is undefined, we'll just make it be null.
if (!Tmp->use_empty())
Tmp->replaceAllUsesWith(F->getContext().getNullValue(Tmp->getType()));
Tmp->replaceAllUsesWith(Constant::getNullValue(Tmp->getType()));
delete Tmp;
}

View File

@ -427,7 +427,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
PHINode* PHI = PHINode::Create(Type::Int32Ty, "SetJmpReturn", Inst);
// Coming from a call to setjmp, the return is 0.
PHI->addIncoming(Inst->getContext().getNullValue(Type::Int32Ty), ABlock);
PHI->addIncoming(Constant::getNullValue(Type::Int32Ty), ABlock);
// Add the case for this setjmp's number...
SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func));

View File

@ -66,7 +66,7 @@ bool FunctionProfiler::runOnModule(Module &M) {
const Type *ATy = ArrayType::get(Type::Int32Ty, NumFunctions);
GlobalVariable *Counters =
new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
M.getContext().getNullValue(ATy), "FuncProfCounters");
Constant::getNullValue(ATy), "FuncProfCounters");
// Instrument all of the functions...
unsigned i = 0;
@ -111,7 +111,7 @@ bool BlockProfiler::runOnModule(Module &M) {
const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks);
GlobalVariable *Counters =
new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
M.getContext().getNullValue(ATy), "BlockProfCounters");
Constant::getNullValue(ATy), "BlockProfCounters");
// Instrument all of the blocks...
unsigned i = 0;

View File

@ -67,7 +67,7 @@ bool EdgeProfiler::runOnModule(Module &M) {
const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges);
GlobalVariable *Counters =
new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
M.getContext().getNullValue(ATy), "EdgeProfCounters");
Constant::getNullValue(ATy), "EdgeProfCounters");
// Instrument all of the edges...
unsigned i = 0;

View File

@ -23,7 +23,6 @@
void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
GlobalValue *Array) {
LLVMContext &Context = MainFn->getContext();
const Type *ArgVTy =
PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty));
const PointerType *UIntPtr = PointerType::getUnqual(Type::Int32Ty);
@ -35,15 +34,15 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
// This could force argc and argv into programs that wouldn't otherwise have
// them, but instead we just pass null values in.
std::vector<Value*> Args(4);
Args[0] = Context.getNullValue(Type::Int32Ty);
Args[1] = Context.getNullValue(ArgVTy);
Args[0] = Constant::getNullValue(Type::Int32Ty);
Args[1] = Constant::getNullValue(ArgVTy);
// Skip over any allocas in the entry block.
BasicBlock *Entry = MainFn->begin();
BasicBlock::iterator InsertPos = Entry->begin();
while (isa<AllocaInst>(InsertPos)) ++InsertPos;
std::vector<Constant*> GEPIndices(2, Context.getNullValue(Type::Int32Ty));
std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::Int32Ty));
unsigned NumElements = 0;
if (Array) {
Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0],
@ -101,8 +100,6 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
GlobalValue *CounterArray) {
LLVMContext &Context = BB->getContext();
// Insert the increment after any alloca or PHI instructions...
BasicBlock::iterator InsertPos = BB->getFirstNonPHI();
while (isa<AllocaInst>(InsertPos))
@ -110,7 +107,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
Indices[0] = Context.getNullValue(Type::Int32Ty);
Indices[0] = Constant::getNullValue(Type::Int32Ty);
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
Constant *ElementPtr =
ConstantExpr::getGetElementPtr(CounterArray, &Indices[0],

View File

@ -350,7 +350,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
Indices[0] = BB->getContext().getNullValue(Type::Int32Ty);
Indices[0] = Constant::getNullValue(Type::Int32Ty);
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
Constant *ElementPtr =ConstantExpr::getGetElementPtr(CounterArray,
&Indices[0], 2);

View File

@ -560,8 +560,6 @@ static bool IsNonLocalValue(Value *V, BasicBlock *BB) {
bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
const Type *AccessTy,
DenseMap<Value*,Value*> &SunkAddrs) {
LLVMContext &Context = MemoryInst->getContext();
// Figure out what addressing mode will be built up for this operation.
SmallVector<Instruction*, 16> AddrModeInsts;
ExtAddrMode AddrMode = AddressingModeMatcher::Match(Addr, AccessTy,MemoryInst,
@ -658,7 +656,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
}
if (Result == 0)
SunkAddr = Context.getNullValue(Addr->getType());
SunkAddr = Constant::getNullValue(Addr->getType());
else
SunkAddr = new IntToPtrInst(Result, Addr->getType(), "sunkaddr",InsertPt);
}

View File

@ -857,7 +857,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// If all of the demanded bits in the inputs are known zeros, return zero.
if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask)
return Context->getNullValue(VTy);
return Constant::getNullValue(VTy);
} else if (I->getOpcode() == Instruction::Or) {
// We can simplify (X|Y) -> X or Y in the user's context if we know that
@ -926,7 +926,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// If all of the demanded bits in the inputs are known zeros, return zero.
if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask)
return Context->getNullValue(VTy);
return Constant::getNullValue(VTy);
// If the RHS is a constant, see if we can simplify it.
if (ShrinkDemandedConstant(I, 1, DemandedMask & ~LHSKnownZero, Context))
@ -1470,7 +1470,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
return 0;
const Type *EltTy = cast<VectorType>(V->getType())->getElementType();
Constant *Zero = Context->getNullValue(EltTy);
Constant *Zero = Constant::getNullValue(EltTy);
Constant *Undef = UndefValue::get(EltTy);
std::vector<Constant*> Elts;
for (unsigned i = 0; i != VWidth; ++i) {
@ -1808,7 +1808,7 @@ static Instruction *AssociativeOpt(BinaryOperator &Root, const Functor &F,
// Make what used to be the LHS of the root be the user of the root...
Value *ExtraOperand = TmpLHSI->getOperand(1);
if (&Root == TmpLHSI) {
Root.replaceAllUsesWith(Context->getNullValue(TmpLHSI->getType()));
Root.replaceAllUsesWith(Constant::getNullValue(TmpLHSI->getType()));
return 0;
}
Root.replaceAllUsesWith(TmpLHSI); // Users now use TmpLHSI
@ -2187,7 +2187,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// X + ~X --> -1 since ~X = -X-1
if (dyn_castNotVal(LHS, Context) == RHS ||
dyn_castNotVal(RHS, Context) == LHS)
return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
// (A & C1)+(B & C2) --> (A & C1)|(B & C2) iff C1&C2 == 0
@ -2417,7 +2417,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
if (Op0 == Op1) // sub X, X -> 0
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// If this is a 'B = x-(-A)', change to B = x+A...
if (Value *V = dyn_castNegVal(Op1, Context))
@ -2623,7 +2623,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
Value *Op0 = I.getOperand(0);
if (isa<UndefValue>(I.getOperand(1))) // undef * X -> 0
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// Simplify mul instructions with a constant RHS...
if (Constant *Op1 = dyn_cast<Constant>(I.getOperand(1))) {
@ -2904,7 +2904,7 @@ Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) {
if (isa<UndefValue>(Op0)) {
if (Op0->getType()->isFPOrFPVector())
return ReplaceInstUsesWith(I, Op0);
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
// X / undef -> undef
@ -2952,7 +2952,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
if (ConstantInt *LHSRHS = dyn_cast<ConstantInt>(LHS->getOperand(1))) {
if (MultiplyOverflows(RHS, LHSRHS,
I.getOpcode()==Instruction::SDiv, Context))
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
else
return BinaryOperator::Create(I.getOpcode(), LHS->getOperand(0),
ConstantExpr::getMul(RHS, LHSRHS));
@ -2971,7 +2971,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
// 0 / X == 0, we don't need to preserve faults!
if (ConstantInt *LHS = dyn_cast<ConstantInt>(Op0))
if (LHS->equalsInt(0))
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// It can't be division by zero, hence it must be division by one.
if (I.getType() == Type::Int1Ty)
@ -3007,7 +3007,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
Value *IC = InsertNewInstBefore(new ICmpInst(*Context,
ICmpInst::ICMP_ULT, Op0, C),
I);
return SelectInst::Create(IC, Context->getNullValue(I.getType()),
return SelectInst::Create(IC, Constant::getNullValue(I.getType()),
ConstantInt::get(I.getType(), 1));
}
}
@ -3108,7 +3108,7 @@ Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) {
if (isa<UndefValue>(Op0)) { // undef % X -> 0
if (I.getType()->isFPOrFPVector())
return ReplaceInstUsesWith(I, Op0); // X % undef -> undef (could be SNaN)
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
if (isa<UndefValue>(Op1))
return ReplaceInstUsesWith(I, Op1); // X % undef -> undef
@ -3133,7 +3133,7 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) {
// 0 % X == 0 for integer, we don't need to preserve faults!
if (Constant *LHS = dyn_cast<Constant>(Op0))
if (LHS->isNullValue())
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
// X % 0 == undef, we don't need to preserve faults!
@ -3141,7 +3141,7 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) {
return ReplaceInstUsesWith(I, UndefValue::get(I.getType()));
if (RHS->equalsInt(1)) // X % 1 == 0
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
if (SelectInst *SI = dyn_cast<SelectInst>(Op0I)) {
@ -3181,7 +3181,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->getAllOnesValue(I.getType());
Constant *N1 = Constant::getAllOnesValue(I.getType());
Value *Add = InsertNewInstBefore(BinaryOperator::CreateAdd(RHSI, N1,
"tmp"), I);
return BinaryOperator::CreateAnd(Op0, Add);
@ -4008,7 +4008,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
if (isa<UndefValue>(Op1)) // X & undef -> 0
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// and X, X = X
if (Op0 == Op1)
@ -4101,7 +4101,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
// (1 >> x) & 1 --> zext(x == 0)
if (AndRHSMask == 1 && Op0LHS == AndRHS) {
Instruction *NewICmp = new ICmpInst(*Context, ICmpInst::ICMP_EQ,
Op0RHS, Context->getNullValue(I.getType()));
Op0RHS, Constant::getNullValue(I.getType()));
InsertNewInstBefore(NewICmp, I);
return new ZExtInst(NewICmp, I.getType());
}
@ -4159,7 +4159,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
Value *Op1NotVal = dyn_castNotVal(Op1, Context);
if (Op0NotVal == Op1 || Op1NotVal == Op0) // A & ~A == ~A & A == 0
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// (~A & ~B) == (~(A | B)) - De Morgan's Law
if (Op0NotVal && Op1NotVal && isOnlyUse(Op0) && isOnlyUse(Op1)) {
@ -4733,7 +4733,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
if (isa<UndefValue>(Op1)) // X | undef -> -1
return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
// or X, X = X
if (Op0 == Op1)
@ -4934,14 +4934,14 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
if (match(Op0, m_Not(m_Value(A)), *Context)) { // ~A | Op1
if (A == Op1) // ~A | A == -1
return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
} else {
A = 0;
}
// Note, A is still live here!
if (match(Op1, m_Not(m_Value(B)), *Context)) { // Op0 | ~B
if (Op0 == B)
return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
// (~A | ~B) == (~(A & B)) - De Morgan's Law
if (A && isOnlyUse(Op0) && isOnlyUse(Op1)) {
@ -5019,14 +5019,14 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (isa<UndefValue>(Op0))
// Handle undef ^ undef -> 0 special case. This is a common
// idiom (misuse).
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Op1); // X ^ undef -> undef
}
// xor X, X = 0, even if X is nested in a sequence of Xor's.
if (Instruction *Result = AssociativeOpt(I, XorSelf(Op1), Context)) {
assert(Result == &I && "AssociativeOpt didn't work?"); Result=Result;
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
// See if we can simplify any instructions used by the instruction whose sole
@ -5148,11 +5148,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (Value *X = dyn_castNotVal(Op0, Context)) // ~A ^ A == -1
if (X == Op1)
return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
if (Value *X = dyn_castNotVal(Op1, Context)) // A ^ ~A == -1
if (X == Op0)
return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1);
@ -5378,7 +5378,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
gep_type_iterator GTI = gep_type_begin(GEP);
const Type *IntPtrTy = TD.getIntPtrType();
LLVMContext *Context = IC.getContext();
Value *Result = Context->getNullValue(IntPtrTy);
Value *Result = Constant::getNullValue(IntPtrTy);
// Build a mask for high order bits.
unsigned IntPtrWidth = TD.getPointerSizeInBits();
@ -5578,7 +5578,7 @@ Instruction *InstCombiner::FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
if (Offset == 0)
Offset = EmitGEPOffset(GEPLHS, I, *this);
return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond), Offset,
Context->getNullValue(Offset->getType()));
Constant::getNullValue(Offset->getType()));
} else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {
// If the base pointers are different, but the indices are the same, just
// compare the base pointer.
@ -5892,7 +5892,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
case FCmpInst::FCMP_UNE: // True if unordered or not equal
// Canonicalize these to be 'fcmp uno %X, 0.0'.
I.setPredicate(FCmpInst::FCMP_UNO);
I.setOperand(1, Context->getNullValue(Op0->getType()));
I.setOperand(1, Constant::getNullValue(Op0->getType()));
return &I;
case FCmpInst::FCMP_ORD: // True if ordered (no nans)
@ -5901,7 +5901,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
case FCmpInst::FCMP_OLE: // True if ordered and less than or equal
// Canonicalize these to be 'fcmp ord %X, 0.0'.
I.setPredicate(FCmpInst::FCMP_ORD);
I.setOperand(1, Context->getNullValue(Op0->getType()));
I.setOperand(1, Constant::getNullValue(Op0->getType()));
return &I;
}
}
@ -6165,7 +6165,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->getAllOnesValue(Op0->getType()));
Constant::getAllOnesValue(Op0->getType()));
}
break;
case ICmpInst::ICMP_UGT:
@ -6184,7 +6184,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// (x >u 2147483647) -> (x <s 0) -> true if sign bit set
if (CI->isMaxValue(true))
return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Op0,
Context->getNullValue(Op0->getType()));
Constant::getNullValue(Op0->getType()));
}
break;
case ICmpInst::ICMP_SLT:
@ -6292,7 +6292,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
}
if (isAllZeros)
return new ICmpInst(*Context, I.getPredicate(), LHSI->getOperand(0),
Context->getNullValue(LHSI->getOperand(0)->getType()));
Constant::getNullValue(LHSI->getOperand(0)->getType()));
}
break;
@ -6472,7 +6472,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (A == Op1 || B == Op1) { // (A^B) == A -> B == 0
Value *OtherVal = A == Op1 ? B : A;
return new ICmpInst(*Context, I.getPredicate(), OtherVal,
Context->getNullValue(A->getType()));
Constant::getNullValue(A->getType()));
}
if (match(Op1, m_Xor(m_Value(C), m_Value(D)), *Context)) {
@ -6500,18 +6500,18 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// A == (A^B) -> B == 0
Value *OtherVal = A == Op0 ? B : A;
return new ICmpInst(*Context, I.getPredicate(), OtherVal,
Context->getNullValue(A->getType()));
Constant::getNullValue(A->getType()));
}
// (A-B) == A -> B == 0
if (match(Op0, m_Sub(m_Specific(Op1), m_Value(B)), *Context))
return new ICmpInst(*Context, I.getPredicate(), B,
Context->getNullValue(B->getType()));
Constant::getNullValue(B->getType()));
// A == (A-B) -> B == 0
if (match(Op1, m_Sub(m_Specific(Op0), m_Value(B)), *Context))
return new ICmpInst(*Context, I.getPredicate(), B,
Context->getNullValue(B->getType()));
Constant::getNullValue(B->getType()));
// (X&Z) == (Y&Z) -> (X^Y) & Z == 0
if (Op0->hasOneUse() && Op1->hasOneUse() &&
@ -6533,7 +6533,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
Op1 = InsertNewInstBefore(BinaryOperator::CreateXor(X, Y, "tmp"), I);
Op1 = InsertNewInstBefore(BinaryOperator::CreateAnd(Op1, Z, "tmp"), I);
I.setOperand(0, Op1);
I.setOperand(1, Context->getNullValue(Op1->getType()));
I.setOperand(1, Constant::getNullValue(Op1->getType()));
return &I;
}
}
@ -6956,7 +6956,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
return new ICmpInst(*Context,
TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
And, Context->getNullValue(And->getType()));
And, Constant::getNullValue(And->getType()));
}
break;
}
@ -7079,7 +7079,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
BO->getName());
InsertNewInstBefore(NewRem, ICI);
return new ICmpInst(*Context, ICI.getPredicate(), NewRem,
Context->getNullValue(BO->getType()));
Constant::getNullValue(BO->getType()));
}
}
break;
@ -7146,12 +7146,12 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
if (RHS == BOC && RHSV.isPowerOf2())
return new ICmpInst(*Context, isICMP_NE ? ICmpInst::ICMP_EQ :
ICmpInst::ICMP_NE, LHSI,
Context->getNullValue(RHS->getType()));
Constant::getNullValue(RHS->getType()));
// Replace (and X, (1 << size(X)-1) != 0) with x s< 0
if (BOC->getValue().isSignBit()) {
Value *X = BO->getOperand(0);
Constant *Zero = Context->getNullValue(X->getType());
Constant *Zero = Constant::getNullValue(X->getType());
ICmpInst::Predicate pred = isICMP_NE ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
return new ICmpInst(*Context, pred, X, Zero);
@ -7295,7 +7295,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->getAllOnesValue(SrcTy);
Constant *NegOne = Constant::getAllOnesValue(SrcTy);
Result = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_SGT,
LHSCIOp, NegOne, ICI.getName()), ICI);
} else {
@ -7355,21 +7355,21 @@ Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) {
// shl X, 0 == X and shr X, 0 == X
// shl 0, X == 0 and shr 0, X == 0
if (Op1 == Context->getNullValue(Op1->getType()) ||
Op0 == Context->getNullValue(Op0->getType()))
if (Op1 == Constant::getNullValue(Op1->getType()) ||
Op0 == Constant::getNullValue(Op0->getType()))
return ReplaceInstUsesWith(I, Op0);
if (isa<UndefValue>(Op0)) {
if (I.getOpcode() == Instruction::AShr) // undef >>s X -> undef
return ReplaceInstUsesWith(I, Op0);
else // undef << X -> 0, undef >>u X -> 0
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
if (isa<UndefValue>(Op1)) {
if (I.getOpcode() == Instruction::AShr) // X >>s undef -> X
return ReplaceInstUsesWith(I, Op0);
else // X << undef, X >>u undef -> 0
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
// See if we can fold away this shift.
@ -7401,7 +7401,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
//
if (Op1->uge(TypeBits)) {
if (I.getOpcode() != Instruction::AShr)
return ReplaceInstUsesWith(I, Context->getNullValue(Op0->getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType()));
else {
I.setOperand(1, ConstantInt::get(I.getType(), TypeBits-1));
return &I;
@ -7629,7 +7629,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
// saturates.
if (AmtSum >= TypeBits) {
if (I.getOpcode() != Instruction::AShr)
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
AmtSum = TypeBits-1; // Saturate to 31 for i32 ashr.
}
@ -7638,7 +7638,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
} else if (ShiftOp->getOpcode() == Instruction::LShr &&
I.getOpcode() == Instruction::AShr) {
if (AmtSum >= TypeBits)
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
// ((X >>u C1) >>s C2) -> (X >>u (C1+C2)) since C1 != 0.
return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum));
@ -8477,7 +8477,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
if (DestBitWidth == 1) {
Constant *One = ConstantInt::get(Src->getType(), 1);
Src = InsertNewInstBefore(BinaryOperator::CreateAnd(Src, One, "tmp"), CI);
Value *Zero = Context->getNullValue(Src->getType());
Value *Zero = Constant::getNullValue(Src->getType());
return new ICmpInst(*Context, ICmpInst::ICMP_NE, Src, Zero);
}
@ -8492,7 +8492,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
APInt Mask(APInt::getLowBitsSet(SrcBitWidth, ShAmt).shl(DestBitWidth));
if (MaskedValueIsZero(ShiftOp, Mask)) {
if (ShAmt >= DestBitWidth) // All zeros.
return ReplaceInstUsesWith(CI, Context->getNullValue(Ty));
return ReplaceInstUsesWith(CI, Constant::getNullValue(Ty));
// Okay, we can shrink this. Truncate the input, then return a new
// shift.
@ -8699,8 +8699,8 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
// Canonicalize sign-extend from i1 to a select.
if (Src->getType() == Type::Int1Ty)
return SelectInst::Create(Src,
Context->getAllOnesValue(CI.getType()),
Context->getNullValue(CI.getType()));
Constant::getAllOnesValue(CI.getType()),
Constant::getNullValue(CI.getType()));
// See if the value being truncated is already sign extended. If so, just
// eliminate the trunc/sext pair.
@ -8970,7 +8970,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
// If the source and destination are pointers, and this cast is equivalent
// to a getelementptr X, 0, 0, 0... turn it into the appropriate gep.
// This can enhance SROA and other transforms that want type-safe pointers.
Constant *ZeroUInt = Context->getNullValue(Type::Int32Ty);
Constant *ZeroUInt = Constant::getNullValue(Type::Int32Ty);
unsigned NumZeros = 0;
while (SrcElTy != DstElTy &&
isa<CompositeType>(SrcElTy) && !isa<PointerType>(SrcElTy) &&
@ -8996,7 +8996,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
Value *Elem = InsertCastBefore(Instruction::BitCast, Src,
DestVTy->getElementType(), CI);
return InsertElementInst::Create(UndefValue::get(DestTy), Elem,
Context->getNullValue(Type::Int32Ty));
Constant::getNullValue(Type::Int32Ty));
}
// FIXME: Canonicalize bitcast(insertelement) -> insertelement(bitcast)
}
@ -9006,7 +9006,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
if (SrcVTy->getNumElements() == 1) {
if (!isa<VectorType>(DestTy)) {
Instruction *Elem =
ExtractElementInst::Create(Src, Context->getNullValue(Type::Int32Ty));
ExtractElementInst::Create(Src, Constant::getNullValue(Type::Int32Ty));
InsertNewInstBefore(Elem, CI);
return CastInst::Create(Instruction::BitCast, Elem, DestTy);
}
@ -9086,9 +9086,9 @@ static Constant *GetSelectFoldableConstant(Instruction *I,
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
return Context->getNullValue(I->getType());
return Constant::getNullValue(I->getType());
case Instruction::And:
return Context->getAllOnesValue(I->getType());
return Constant::getAllOnesValue(I->getType());
case Instruction::Mul:
return ConstantInt::get(I->getType(), 1);
}
@ -9743,7 +9743,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
InsertNewInstBefore(new StoreInst(L, Dest, false, DstAlign), *MI);
// Set the size of the copy to 0, it will be deleted on the next iteration.
MI->setOperand(3, Context->getNullValue(MemOpLength->getType()));
MI->setOperand(3, Constant::getNullValue(MemOpLength->getType()));
return MI;
}
@ -9782,7 +9782,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
Dest, false, Alignment), *MI);
// Set the size of the copy to 0, it will be deleted on the next iteration.
MI->setLength(Context->getNullValue(LenC->getType()));
MI->setLength(Constant::getNullValue(LenC->getType()));
return MI;
}
@ -10259,7 +10259,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
// If the function takes more arguments than the call was taking, add them
// now...
for (unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i)
Args.push_back(Context->getNullValue(FT->getParamType(i)));
Args.push_back(Constant::getNullValue(FT->getParamType(i)));
// If we are removing arguments to the function, emit an obnoxious warning...
if (FT->getNumParams() < NumActualArgs) {
@ -11092,9 +11092,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// With: T = long A+B; gep %P, T, ...
//
Value *Sum, *SO1 = SrcGEPOperands.back(), *GO1 = GEP.getOperand(1);
if (SO1 == Context->getNullValue(SO1->getType())) {
if (SO1 == Constant::getNullValue(SO1->getType())) {
Sum = GO1;
} else if (GO1 == Context->getNullValue(GO1->getType())) {
} else if (GO1 == Constant::getNullValue(GO1->getType())) {
Sum = SO1;
} else {
// If they aren't the same type, convert both to an integer of the
@ -11227,7 +11227,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()) ==
TD->getTypeAllocSize(ResElTy)) {
Value *Idx[2];
Idx[0] = Context->getNullValue(Type::Int32Ty);
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = GEP.getOperand(1);
GetElementPtrInst *NewGEP =
GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName());
@ -11291,7 +11291,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// Insert the new GEP instruction.
Value *Idx[2];
Idx[0] = Context->getNullValue(Type::Int32Ty);
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = NewIdx;
Instruction *NewGEP =
GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName());
@ -11388,7 +11388,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// Now that I is pointing to the first non-allocation-inst in the block,
// insert our getelementptr instruction...
//
Value *NullIdx = Context->getNullValue(Type::Int32Ty);
Value *NullIdx = Constant::getNullValue(Type::Int32Ty);
Value *Idx[2];
Idx[0] = NullIdx;
Idx[1] = NullIdx;
@ -11400,7 +11400,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// allocation.
return ReplaceInstUsesWith(AI, V);
} else if (isa<UndefValue>(AI.getArraySize())) {
return ReplaceInstUsesWith(AI, Context->getNullValue(AI.getType()));
return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
}
}
@ -11409,7 +11409,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// Note that we only do this for alloca's, because malloc should allocate
// and return a unique pointer, even for a zero byte allocation.
if (TD->getTypeAllocSize(AI.getAllocatedType()) == 0)
return ReplaceInstUsesWith(AI, Context->getNullValue(AI.getType()));
return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
// If the alignment is 0 (unspecified), assign it the preferred alignment.
if (AI.getAlignment() == 0)
@ -11521,7 +11521,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI,
if (Constant *CSrc = dyn_cast<Constant>(CastOp))
if (ASrcTy->getNumElements() != 0) {
Value *Idxs[2];
Idxs[0] = Idxs[1] = Context->getNullValue(Type::Int32Ty);
Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty);
CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2);
SrcTy = cast<PointerType>(CastOp->getType());
SrcPTy = SrcTy->getElementType();
@ -11588,7 +11588,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
// an unreachable instruction directly because we cannot modify the
// CFG.
new StoreInst(UndefValue::get(LI.getType()),
Context->getNullValue(Op->getType()), &LI);
Constant::getNullValue(Op->getType()), &LI);
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
}
@ -11602,7 +11602,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
// this code is not reachable. We do this instead of inserting an
// unreachable instruction directly because we cannot modify the CFG.
new StoreInst(UndefValue::get(LI.getType()),
Context->getNullValue(Op->getType()), &LI);
Constant::getNullValue(Op->getType()), &LI);
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
@ -11626,7 +11626,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
// an unreachable instruction directly because we cannot modify the
// CFG.
new StoreInst(UndefValue::get(LI.getType()),
Context->getNullValue(Op->getType()), &LI);
Constant::getNullValue(Op->getType()), &LI);
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
@ -11642,7 +11642,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op->getUnderlyingObject())){
if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
if (GV->getInitializer()->isNullValue())
return ReplaceInstUsesWith(LI, Context->getNullValue(LI.getType()));
return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType()));
else if (isa<UndefValue>(GV->getInitializer()))
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
@ -11694,7 +11694,6 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
User *CI = cast<User>(SI.getOperand(1));
Value *CastOp = CI->getOperand(0);
LLVMContext *Context = IC.getContext();
const Type *DestPTy = cast<PointerType>(CI->getType())->getElementType();
const PointerType *SrcTy = dyn_cast<PointerType>(CastOp->getType());
@ -11716,7 +11715,7 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
// constants.
if (isa<ArrayType>(SrcPTy) || isa<StructType>(SrcPTy)) {
// Index through pointer.
Constant *Zero = Context->getNullValue(Type::Int32Ty);
Constant *Zero = Constant::getNullValue(Type::Int32Ty);
NewGEPIndices.push_back(Zero);
while (1) {
@ -12190,7 +12189,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
return ReplaceInstUsesWith(EV, UndefValue::get(EV.getType()));
if (isa<ConstantAggregateZero>(C))
return ReplaceInstUsesWith(EV, Context->getNullValue(EV.getType()));
return ReplaceInstUsesWith(EV, Constant::getNullValue(EV.getType()));
if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) {
// Extract the element indexed by the first index out of the constant
@ -12337,7 +12336,7 @@ static Value *FindScalarElement(Value *V, unsigned EltNo,
if (isa<UndefValue>(V))
return UndefValue::get(PTy->getElementType());
else if (isa<ConstantAggregateZero>(V))
return Context->getNullValue(PTy->getElementType());
return Constant::getNullValue(PTy->getElementType());
else if (ConstantVector *CP = dyn_cast<ConstantVector>(V))
return CP->getOperand(EltNo);
else if (InsertElementInst *III = dyn_cast<InsertElementInst>(V)) {
@ -12377,7 +12376,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
// If vector val is constant 0, replace extract with scalar 0.
if (isa<ConstantAggregateZero>(EI.getOperand(0)))
return ReplaceInstUsesWith(EI, Context->getNullValue(EI.getType()));
return ReplaceInstUsesWith(EI, Constant::getNullValue(EI.getType()));
if (ConstantVector *C = dyn_cast<ConstantVector>(EI.getOperand(0))) {
// If vector val is constant with all elements the same, replace EI with

View File

@ -1577,9 +1577,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride,
BasicBlock *LatchBlock = L->getLoopLatch();
Instruction *IVIncInsertPt = LatchBlock->getTerminator();
LLVMContext &Context = Preheader->getContext();
Value *CommonBaseV = Context.getNullValue(ReplacedTy);
Value *CommonBaseV = Constant::getNullValue(ReplacedTy);
const SCEV *RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy);
IVExpr ReuseIV(SE->getIntegerSCEV(0, Type::Int32Ty),

View File

@ -1761,7 +1761,7 @@ namespace {
switch (BO->getOpcode()) {
case Instruction::And: {
// "and i32 %a, %b" EQ -1 then %a EQ -1 and %b EQ -1
ConstantInt *CI = cast<ConstantInt>(Context->getAllOnesValue(Ty));
ConstantInt *CI = cast<ConstantInt>(Constant::getAllOnesValue(Ty));
if (Canonical == CI) {
add(CI, Op0, ICmpInst::ICMP_EQ, NewContext);
add(CI, Op1, ICmpInst::ICMP_EQ, NewContext);
@ -1769,7 +1769,7 @@ namespace {
} break;
case Instruction::Or: {
// "or i32 %a, %b" EQ 0 then %a EQ 0 and %b EQ 0
Constant *Zero = Context->getNullValue(Ty);
Constant *Zero = Constant::getNullValue(Ty);
if (Canonical == Zero) {
add(Zero, Op0, ICmpInst::ICMP_EQ, NewContext);
add(Zero, Op1, ICmpInst::ICMP_EQ, NewContext);
@ -1793,10 +1793,10 @@ namespace {
}
if (Canonical == LHS) {
if (isa<ConstantInt>(Canonical))
add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_EQ,
add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ,
NewContext);
} else if (isRelatedBy(LHS, Canonical, ICmpInst::ICMP_NE)) {
add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_NE,
add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_NE,
NewContext);
}
} break;
@ -1841,10 +1841,10 @@ namespace {
}
// TODO: The GEPI indices are all zero. Copy from definition to operand,
// jumping the type plane as needed.
if (isRelatedBy(GEPI, Context->getNullValue(GEPI->getType()),
if (isRelatedBy(GEPI, Constant::getNullValue(GEPI->getType()),
ICmpInst::ICMP_NE)) {
Value *Ptr = GEPI->getPointerOperand();
add(Ptr, Context->getNullValue(Ptr->getType()), ICmpInst::ICMP_NE,
add(Ptr, Constant::getNullValue(Ptr->getType()), ICmpInst::ICMP_NE,
NewContext);
}
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
@ -1898,9 +1898,9 @@ namespace {
const Type *Ty = BO->getType();
assert(!Ty->isFPOrFPVector() && "Float in work queue!");
Constant *Zero = Context->getNullValue(Ty);
Constant *Zero = Constant::getNullValue(Ty);
Constant *One = ConstantInt::get(Ty, 1);
ConstantInt *AllOnes = cast<ConstantInt>(Context->getAllOnesValue(Ty));
ConstantInt *AllOnes = cast<ConstantInt>(Constant::getAllOnesValue(Ty));
switch (Opcode) {
default: break;
@ -2121,9 +2121,9 @@ namespace {
// TODO: The GEPI indices are all zero. Copy from operand to definition,
// jumping the type plane as needed.
Value *Ptr = GEPI->getPointerOperand();
if (isRelatedBy(Ptr, Context->getNullValue(Ptr->getType()),
if (isRelatedBy(Ptr, Constant::getNullValue(Ptr->getType()),
ICmpInst::ICMP_NE)) {
add(GEPI, Context->getNullValue(GEPI->getType()), ICmpInst::ICMP_NE,
add(GEPI, Constant::getNullValue(GEPI->getType()), ICmpInst::ICMP_NE,
NewContext);
}
}
@ -2515,7 +2515,7 @@ namespace {
void PredicateSimplifier::Forwards::visitAllocaInst(AllocaInst &AI) {
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &AI);
VRP.add(AI.getContext().getNullValue(AI.getType()),
VRP.add(Constant::getNullValue(AI.getType()),
&AI, ICmpInst::ICMP_NE);
VRP.solve();
}
@ -2526,7 +2526,7 @@ namespace {
if (isa<Constant>(Ptr)) return;
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &LI);
VRP.add(LI.getContext().getNullValue(Ptr->getType()),
VRP.add(Constant::getNullValue(Ptr->getType()),
Ptr, ICmpInst::ICMP_NE);
VRP.solve();
}
@ -2536,7 +2536,7 @@ namespace {
if (isa<Constant>(Ptr)) return;
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI);
VRP.add(SI.getContext().getNullValue(Ptr->getType()),
VRP.add(Constant::getNullValue(Ptr->getType()),
Ptr, ICmpInst::ICMP_NE);
VRP.solve();
}
@ -2574,7 +2574,7 @@ namespace {
case Instruction::SDiv: {
Value *Divisor = BO.getOperand(1);
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
VRP.add(BO.getContext().getNullValue(Divisor->getType()),
VRP.add(Constant::getNullValue(Divisor->getType()),
Divisor, ICmpInst::ICMP_NE);
VRP.solve();
break;

View File

@ -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 = Neg->getContext().getAllOnesValue(Neg->getType());
Constant *Cst = Constant::getAllOnesValue(Neg->getType());
Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg);
ValueRankMap.erase(Neg);
@ -563,8 +563,6 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
bool IterateOptimization = false;
if (Ops.size() == 1) return Ops[0].Op;
LLVMContext &Context = I->getContext();
unsigned Opcode = I->getOpcode();
if (Constant *V1 = dyn_cast<Constant>(Ops[Ops.size()-2].Op))
@ -626,10 +624,10 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
if (FoundX != i) {
if (Opcode == Instruction::And) { // ...&X&~X = 0
++NumAnnihil;
return Context.getNullValue(X->getType());
return Constant::getNullValue(X->getType());
} else if (Opcode == Instruction::Or) { // ...|X|~X = -1
++NumAnnihil;
return Context.getAllOnesValue(X->getType());
return Constant::getAllOnesValue(X->getType());
}
}
}
@ -648,7 +646,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
assert(Opcode == Instruction::Xor);
if (e == 2) {
++NumAnnihil;
return Context.getNullValue(Ops[0].Op->getType());
return Constant::getNullValue(Ops[0].Op->getType());
}
// ... X^X -> ...
Ops.erase(Ops.begin()+i, Ops.begin()+i+2);
@ -673,7 +671,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
// Remove X and -X from the operand list.
if (Ops.size() == 2) {
++NumAnnihil;
return Context.getNullValue(X->getType());
return Constant::getNullValue(X->getType());
} else {
Ops.erase(Ops.begin()+i);
if (i < FoundX)

View File

@ -69,7 +69,7 @@ namespace {
CastInst *AllocaInsertionPoint =
CastInst::Create(Instruction::BitCast,
F.getContext().getNullValue(Type::Int32Ty), Type::Int32Ty,
Constant::getNullValue(Type::Int32Ty), Type::Int32Ty,
"reg2mem alloca point", I);
// Find the escaped instructions. But don't create stack slots for

View File

@ -813,12 +813,12 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
if (NonOverdefVal->isUndefined()) {
// Could annihilate value.
if (I.getOpcode() == Instruction::And)
markConstant(IV, &I, Context->getNullValue(I.getType()));
markConstant(IV, &I, Constant::getNullValue(I.getType()));
else if (const VectorType *PT = dyn_cast<VectorType>(I.getType()))
markConstant(IV, &I, Context->getAllOnesValue(PT));
markConstant(IV, &I, Constant::getAllOnesValue(PT));
else
markConstant(IV, &I,
Context->getAllOnesValue(I.getType()));
Constant::getAllOnesValue(I.getType()));
return;
} else {
if (I.getOpcode() == Instruction::And) {
@ -1134,7 +1134,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) {
if (isa<ConstantPointerNull>(Ptr) &&
cast<PointerType>(Ptr->getType())->getAddressSpace() == 0) {
// load null -> null
markConstant(IV, &I, Context->getNullValue(I.getType()));
markConstant(IV, &I, Constant::getNullValue(I.getType()));
return;
}
@ -1376,22 +1376,22 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// to be handled here, because we don't know whether the top part is 1's
// or 0's.
assert(Op0LV.isUndefined());
markForcedConstant(LV, I, Context->getNullValue(ITy));
markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::Mul:
case Instruction::And:
// undef * X -> 0. X could be zero.
// undef & X -> 0. X could be zero.
markForcedConstant(LV, I, Context->getNullValue(ITy));
markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::Or:
// undef | X -> -1. X could be -1.
if (const VectorType *PTy = dyn_cast<VectorType>(ITy))
markForcedConstant(LV, I,
Context->getAllOnesValue(PTy));
Constant::getAllOnesValue(PTy));
else
markForcedConstant(LV, I, Context->getAllOnesValue(ITy));
markForcedConstant(LV, I, Constant::getAllOnesValue(ITy));
return true;
case Instruction::SDiv:
@ -1404,7 +1404,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// undef / X -> 0. X could be maxint.
// undef % X -> 0. X could be 1.
markForcedConstant(LV, I, Context->getNullValue(ITy));
markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::AShr:
@ -1425,7 +1425,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// X >> undef -> 0. X could be 0.
// X << undef -> 0. X could be 0.
markForcedConstant(LV, I, Context->getNullValue(ITy));
markForcedConstant(LV, I, Constant::getNullValue(ITy));
return true;
case Instruction::Select:
// undef ? X : Y -> X or Y. There could be commonality between X/Y.

View File

@ -329,7 +329,6 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
std::vector<AllocationInst*> &WorkList) {
DOUT << "Found inst to SROA: " << *AI;
SmallVector<AllocaInst*, 32> ElementAllocas;
LLVMContext &Context = AI->getContext();
if (const StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
ElementAllocas.reserve(ST->getNumContainedTypes());
for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i) {
@ -418,7 +417,7 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
// expanded itself once the worklist is rerun.
//
SmallVector<Value*, 8> NewArgs;
NewArgs.push_back(Context.getNullValue(Type::Int32Ty));
NewArgs.push_back(Constant::getNullValue(Type::Int32Ty));
NewArgs.append(GEPI->op_begin()+3, GEPI->op_end());
RepValue = GetElementPtrInst::Create(AllocaToUse, NewArgs.begin(),
NewArgs.end(), "", GEPI);
@ -512,7 +511,6 @@ static bool AllUsersAreLoads(Value *Ptr) {
///
void SROA::isSafeUseOfAllocation(Instruction *User, AllocationInst *AI,
AllocaInfo &Info) {
LLVMContext &Context = User->getContext();
if (BitCastInst *C = dyn_cast<BitCastInst>(User))
return isSafeUseOfBitCastedAllocation(C, AI, Info);
@ -532,7 +530,7 @@ void SROA::isSafeUseOfAllocation(Instruction *User, AllocationInst *AI,
// The GEP is not safe to transform if not of the form "GEP <ptr>, 0, <cst>".
if (I == E ||
I.getOperand() != Context.getNullValue(I.getOperand()->getType())) {
I.getOperand() != Constant::getNullValue(I.getOperand()->getType())) {
return MarkUnsafe(Info);
}
@ -766,7 +764,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
const Type *BytePtrTy = MI->getRawDest()->getType();
bool SROADest = MI->getRawDest() == BCInst;
Constant *Zero = Context.getNullValue(Type::Int32Ty);
Constant *Zero = Constant::getNullValue(Type::Int32Ty);
for (unsigned i = 0, e = NewElts.size(); i != e; ++i) {
// If this is a memcpy/memmove, emit a GEP of the other element address.
@ -821,7 +819,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
Constant *StoreVal;
if (ConstantInt *CI = dyn_cast<ConstantInt>(MI->getOperand(2))) {
if (CI->isZero()) {
StoreVal = Context.getNullValue(EltTy); // 0.0, null, 0, <0,0>
StoreVal = Constant::getNullValue(EltTy); // 0.0, null, 0, <0,0>
} else {
// If EltTy is a vector type, get the element type.
const Type *ValTy = EltTy->getScalarType();
@ -1041,10 +1039,8 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI,
ArrayEltBitOffset = TD->getTypeAllocSizeInBits(ArrayEltTy);
}
LLVMContext &Context = LI->getContext();
Value *ResultVal =
Context.getNullValue(IntegerType::get(AllocaSizeBits));
Constant::getNullValue(IntegerType::get(AllocaSizeBits));
for (unsigned i = 0, e = NewElts.size(); i != e; ++i) {
// Load the value from the alloca. If the NewElt is an aggregate, cast
@ -1189,10 +1185,8 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) {
if (isa<ConstantInt>(I.getOperand()))
return;
LLVMContext &Context = GEPI->getContext();
if (NumElements == 1) {
GEPI->setOperand(2, Context.getNullValue(Type::Int32Ty));
GEPI->setOperand(2, Constant::getNullValue(Type::Int32Ty));
return;
}
@ -1200,11 +1194,11 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) {
// All users of the GEP must be loads. At each use of the GEP, insert
// two loads of the appropriate indexed GEP and select between them.
Value *IsOne = new ICmpInst(GEPI, ICmpInst::ICMP_NE, I.getOperand(),
Context.getNullValue(I.getOperand()->getType()),
Constant::getNullValue(I.getOperand()->getType()),
"isone");
// Insert the new GEP instructions, which are properly indexed.
SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end());
Indices[1] = Context.getNullValue(Type::Int32Ty);
Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0),
Indices.begin(),
Indices.end(),

View File

@ -679,7 +679,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization {
uint64_t i = 0;
while (1) {
if (i == Str.size()) // Didn't find the char. strchr returns null.
return Context->getNullValue(CI->getType());
return Constant::getNullValue(CI->getType());
// Did we find our match?
if (Str[i] == CharValue)
break;
@ -918,7 +918,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization {
Value *LHS = CI->getOperand(1), *RHS = CI->getOperand(2);
if (LHS == RHS) // memcmp(s,s,x) -> 0
return Context->getNullValue(CI->getType());
return Constant::getNullValue(CI->getType());
// Make sure we have a constant length.
ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getOperand(3));
@ -926,7 +926,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization {
uint64_t Len = LenC->getZExtValue();
if (Len == 0) // memcmp(s1,s2,0) -> 0
return Context->getNullValue(CI->getType());
return Constant::getNullValue(CI->getType());
if (Len == 1) { // memcmp(S1,S2,1) -> *LHS - *RHS
Value *LHSV = B.CreateLoad(CastToCStr(LHS, B), "lhsv");
@ -1163,7 +1163,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization {
// Constant fold.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
if (CI->getValue() == 0) // ffs(0) -> 0.
return Context->getNullValue(CI->getType());
return Constant::getNullValue(CI->getType());
return ConstantInt::get(Type::Int32Ty, // ffs(c) -> cttz(c)+1
CI->getValue().countTrailingZeros()+1);
}
@ -1176,7 +1176,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization {
V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp");
V = B.CreateIntCast(V, Type::Int32Ty, false, "tmp");
Value *Cond = B.CreateICmpNE(Op, Context->getNullValue(ArgType), "tmp");
Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType), "tmp");
return B.CreateSelect(Cond, V, ConstantInt::get(Type::Int32Ty, 0));
}
};
@ -1235,7 +1235,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->getAllOnesValue(Op->getType()),
Constant::getAllOnesValue(Op->getType()),
"ispos");
Value *Neg = B.CreateNeg(Op, "neg");
return B.CreateSelect(Pos, Op, Neg);
@ -1371,7 +1371,7 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization {
Value *Ptr = CastToCStr(CI->getOperand(1), B);
B.CreateStore(V, Ptr);
Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::Int32Ty, 1), "nul");
B.CreateStore(Context->getNullValue(Type::Int8Ty), Ptr);
B.CreateStore(Constant::getNullValue(Type::Int8Ty), Ptr);
return ConstantInt::get(CI->getType(), 1);
}

View File

@ -252,8 +252,7 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
// Create a value to return... if the function doesn't return null...
if (BB->getParent()->getReturnType() != Type::VoidTy)
RetVal = TI->getContext().getNullValue(
BB->getParent()->getReturnType());
RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
// Create the return...
NewTI = ReturnInst::Create(RetVal);

View File

@ -239,8 +239,6 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
DOUT << "inputs: " << inputs.size() << "\n";
DOUT << "outputs: " << outputs.size() << "\n";
LLVMContext &Context = header->getContext();
// This function returns unsigned, outputs will go back by reference.
switch (NumExitBlocks) {
case 0:
@ -304,7 +302,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
Value *RewriteVal;
if (AggregateArgs) {
Value *Idx[2];
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP =
@ -352,8 +350,6 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
void CodeExtractor::
emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Values &inputs, Values &outputs) {
LLVMContext &Context = codeReplacer->getContext();
// Emit a call to the new function, passing in: *pointer to struct (if
// aggregating parameters), or plan inputs and allocated memory for outputs
std::vector<Value*> params, StructValues, ReloadOutputs;
@ -394,7 +390,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *Idx[2];
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
@ -420,7 +416,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Value *Output = 0;
if (AggregateArgs) {
Value *Idx[2];
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
GetElementPtrInst *GEP
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
@ -442,7 +438,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Now we can emit a switch statement using the call as a value.
SwitchInst *TheSwitch =
SwitchInst::Create(Context.getNullValue(Type::Int16Ty),
SwitchInst::Create(Constant::getNullValue(Type::Int16Ty),
codeReplacer, 0, codeReplacer);
// Since there may be multiple exits from the original region, make the new
@ -521,7 +517,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (DominatesDef) {
if (AggregateArgs) {
Value *Idx[2];
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
@ -559,7 +555,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
} else {
// Otherwise we must have code extracted an unwind or something, just
// return whatever we want.
ReturnInst::Create(Context.getNullValue(OldFnRetTy), TheSwitch);
ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch);
}
TheSwitch->eraseFromParent();

View File

@ -103,8 +103,6 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
bool Changed = false;
assert(MallocFunc && FreeFunc && "Pass not initialized!");
LLVMContext &Context = BB.getContext();
BasicBlock::InstListType &BBIL = BB.getInstList();
const TargetData &TD = getAnalysis<TargetData>();
@ -156,7 +154,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
if (MCall->getType() != Type::VoidTy)
MCast = new BitCastInst(MCall, MI->getType(), "", I);
else
MCast = Context.getNullValue(MI->getType());
MCast = Constant::getNullValue(MI->getType());
// Replace all uses of the old malloc inst with the cast inst
MI->replaceAllUsesWith(MCast);

View File

@ -115,8 +115,6 @@ FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) {
// doInitialization - Make sure that there is a prototype for abort in the
// current module.
bool LowerInvoke::doInitialization(Module &M) {
LLVMContext &Context = M.getContext();
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
AbortMessage = 0;
if (ExpensiveEHSupport) {
@ -143,7 +141,7 @@ bool LowerInvoke::doInitialization(Module &M) {
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
JBListHead = new GlobalVariable(M, PtrJBList, false,
GlobalValue::LinkOnceAnyLinkage,
Context.getNullValue(PtrJBList),
Constant::getNullValue(PtrJBList),
"llvm.sjljeh.jblist");
}
@ -177,8 +175,6 @@ bool LowerInvoke::doInitialization(Module &M) {
}
void LowerInvoke::createAbortMessage(Module *M) {
LLVMContext &Context = M->getContext();
if (ExpensiveEHSupport) {
// The abort message for expensive EH support tells the user that the
// program 'unwound' without an 'invoke' instruction.
@ -189,7 +185,7 @@ void LowerInvoke::createAbortMessage(Module *M) {
GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg");
std::vector<Constant*> GEPIdx(2, Context.getNullValue(Type::Int32Ty));
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
} else {
// The abort message for cheap EH support tells the user that EH is not
@ -202,7 +198,7 @@ void LowerInvoke::createAbortMessage(Module *M) {
GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg");
std::vector<Constant*> GEPIdx(2, Context.getNullValue(Type::Int32Ty));
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
}
}
@ -223,7 +219,6 @@ void LowerInvoke::writeAbortMessage(Instruction *IB) {
}
bool LowerInvoke::insertCheapEHSupport(Function &F) {
LLVMContext &Context = F.getContext();
bool Changed = false;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
@ -256,7 +251,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
// Insert a return instruction. This really should be a "barrier", as it
// is unreachable.
ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 :
Context.getNullValue(F.getReturnType()), UI);
Constant::getNullValue(F.getReturnType()), UI);
// Remove the unwind instruction now.
BB->getInstList().erase(UI);
@ -271,7 +266,6 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
AllocaInst *InvokeNum,
SwitchInst *CatchSwitch) {
LLVMContext &Context = II->getContext();
ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo);
// If the unwind edge has phi nodes, split the edge.
@ -291,7 +285,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
BasicBlock::iterator NI = II->getNormalDest()->getFirstNonPHI();
// nonvolatile.
new StoreInst(Context.getNullValue(Type::Int32Ty), InvokeNum, false, NI);
new StoreInst(Constant::getNullValue(Type::Int32Ty), InvokeNum, false, NI);
// Add a switch case to our unwind block.
CatchSwitch->addCase(InvokeNoC, II->getUnwindDest());
@ -433,8 +427,6 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
std::vector<UnwindInst*> Unwinds;
std::vector<InvokeInst*> Invokes;
LLVMContext &Context = F.getContext();
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
// Remember all return instructions in case we insert an invoke into this
@ -482,7 +474,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
"jblink", F.begin()->begin());
std::vector<Value*> Idx;
Idx.push_back(Context.getNullValue(Type::Int32Ty));
Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"OldBuf",
@ -535,7 +527,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Compare the return value to zero.
Value *IsNormal = new ICmpInst(EntryBB->getTerminator(),
ICmpInst::ICMP_EQ, SJRet,
Context.getNullValue(SJRet->getType()),
Constant::getNullValue(SJRet->getType()),
"notunwind");
// Nuke the uncond branch.
EntryBB->getTerminator()->eraseFromParent();
@ -569,14 +561,14 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Load the JBList, if it's null, then there was no catch!
Value *NotNull = new ICmpInst(*UnwindHandler, ICmpInst::ICMP_NE, BufPtr,
Context.getNullValue(BufPtr->getType()),
Constant::getNullValue(BufPtr->getType()),
"notnull");
BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler);
// Create the block to do the longjmp.
// Get a pointer to the jmpbuf and longjmp.
std::vector<Value*> Idx;
Idx.push_back(Context.getNullValue(Type::Int32Ty));
Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
UnwindBlock);

View File

@ -103,13 +103,13 @@ static Constant *FoldBitCast(LLVMContext &Context,
if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy))
if (PTy->getAddressSpace() == DPTy->getAddressSpace()) {
SmallVector<Value*, 8> IdxList;
IdxList.push_back(Context.getNullValue(Type::Int32Ty));
IdxList.push_back(Constant::getNullValue(Type::Int32Ty));
const Type *ElTy = PTy->getElementType();
while (ElTy != DPTy->getElementType()) {
if (const StructType *STy = dyn_cast<StructType>(ElTy)) {
if (STy->getNumElements() == 0) break;
ElTy = STy->getElementType(0);
IdxList.push_back(Context.getNullValue(Type::Int32Ty));
IdxList.push_back(Constant::getNullValue(Type::Int32Ty));
} else if (const SequentialType *STy =
dyn_cast<SequentialType>(ElTy)) {
if (isa<PointerType>(ElTy)) break; // Can't index into pointers!
@ -134,7 +134,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
SrcTy = NULL;
// First, check for null. Undef is already handled.
if (isa<ConstantAggregateZero>(V))
return Context.getNullValue(DestTy);
return Constant::getNullValue(DestTy);
if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
return BitCastConstantVector(Context, CV, DestPTy);
@ -186,7 +186,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
// [us]itofp(undef) = 0, because the result value is bounded.
if (opc == Instruction::ZExt || opc == Instruction::SExt ||
opc == Instruction::UIToFP || opc == Instruction::SIToFP)
return Context.getNullValue(DestTy);
return Constant::getNullValue(DestTy);
return UndefValue::get(DestTy);
}
// No compile-time operations on this type yet.
@ -337,7 +337,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context,
if (isa<UndefValue>(Val)) // ee(undef, x) -> undef
return UndefValue::get(cast<VectorType>(Val->getType())->getElementType());
if (Val->isNullValue()) // ee(zero, x) -> zero
return Context.getNullValue(
return Constant::getNullValue(
cast<VectorType>(Val->getType())->getElementType());
if (const ConstantVector *CVal = dyn_cast<ConstantVector>(Val)) {
@ -389,7 +389,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
Ops.reserve(numOps);
for (unsigned i = 0; i < numOps; ++i) {
const Constant *Op =
(idxVal == i) ? Elt : Context.getNullValue(Elt->getType());
(idxVal == i) ? Elt : Constant::getNullValue(Elt->getType());
Ops.push_back(const_cast<Constant*>(Op));
}
return ConstantVector::get(Ops);
@ -418,7 +418,7 @@ static Constant *GetVectorElement(LLVMContext &Context, const Constant *C,
const Type *EltTy = cast<VectorType>(C->getType())->getElementType();
if (isa<ConstantAggregateZero>(C))
return Context.getNullValue(EltTy);
return Constant::getNullValue(EltTy);
if (isa<UndefValue>(C))
return UndefValue::get(EltTy);
return 0;
@ -477,7 +477,7 @@ Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context,
if (isa<ConstantAggregateZero>(Agg)) // ev(0, x) -> 0
return
Context.getNullValue(ExtractValueInst::getIndexedType(Agg->getType(),
Constant::getNullValue(ExtractValueInst::getIndexedType(Agg->getType(),
Idxs,
Idxs + NumIdx));
@ -542,9 +542,9 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
const Constant *Op =
(*Idxs == i) ?
ConstantFoldInsertValueInstruction(Context,
Context.getNullValue(MemberTy),
Constant::getNullValue(MemberTy),
Val, Idxs+1, NumIdx-1) :
Context.getNullValue(MemberTy);
Constant::getNullValue(MemberTy);
Ops[i] = const_cast<Constant*>(Op);
}
if (isa<StructType>(AggTy))
@ -590,29 +590,29 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
// Handle undef ^ undef -> 0 special case. This is a common
// idiom (misuse).
return Context.getNullValue(C1->getType());
return Constant::getNullValue(C1->getType());
// Fallthrough
case Instruction::Add:
case Instruction::Sub:
return UndefValue::get(C1->getType());
case Instruction::Mul:
case Instruction::And:
return Context.getNullValue(C1->getType());
return Constant::getNullValue(C1->getType());
case Instruction::UDiv:
case Instruction::SDiv:
case Instruction::URem:
case Instruction::SRem:
if (!isa<UndefValue>(C2)) // undef / X -> 0
return Context.getNullValue(C1->getType());
return Constant::getNullValue(C1->getType());
return const_cast<Constant*>(C2); // X / undef -> undef
case Instruction::Or: // X | undef -> -1
if (const VectorType *PTy = dyn_cast<VectorType>(C1->getType()))
return Context.getAllOnesValue(PTy);
return Context.getAllOnesValue(C1->getType());
return Constant::getAllOnesValue(PTy);
return Constant::getAllOnesValue(C1->getType());
case Instruction::LShr:
if (isa<UndefValue>(C2) && isa<UndefValue>(C1))
return const_cast<Constant*>(C1); // undef lshr undef -> undef
return Context.getNullValue(C1->getType()); // X lshr undef -> 0
return Constant::getNullValue(C1->getType()); // X lshr undef -> 0
// undef lshr X -> 0
case Instruction::AShr:
if (!isa<UndefValue>(C2))
@ -623,7 +623,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
return const_cast<Constant*>(C1); // X ashr undef --> X
case Instruction::Shl:
// undef << X -> 0 or X << undef -> 0
return Context.getNullValue(C1->getType());
return Constant::getNullValue(C1->getType());
}
}
@ -651,7 +651,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
case Instruction::URem:
case Instruction::SRem:
if (CI2->equalsInt(1))
return Context.getNullValue(CI2->getType()); // X % 1 == 0
return Constant::getNullValue(CI2->getType()); // X % 1 == 0
if (CI2->equalsInt(0))
return UndefValue::get(CI2->getType()); // X % 0 == undef
break;
@ -688,7 +688,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
// If checking bits we know are clear, return zero.
if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
return Context.getNullValue(CI2->getType());
return Constant::getNullValue(CI2->getType());
}
}
}
@ -824,144 +824,144 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
break;
case Instruction::Add:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getAdd(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::FAdd:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getFAdd(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::Sub:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getSub(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::FSub:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getFSub(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::Mul:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getMul(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::FMul:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getFMul(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::UDiv:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getUDiv(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::SDiv:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getSDiv(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::FDiv:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getFDiv(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::URem:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getURem(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::SRem:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getSRem(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::FRem:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getFRem(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::And:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getAnd(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::Or:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getOr(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::Xor:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getXor(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::LShr:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getLShr(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::AShr:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getAShr(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
case Instruction::Shl:
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy);
C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy);
C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(ConstantExpr::getShl(const_cast<Constant*>(C1),
const_cast<Constant*>(C2)));
}
@ -1236,7 +1236,7 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context,
if (CE1->getOpcode() == Instruction::ZExt) isSigned = false;
if (CE1->getOpcode() == Instruction::SExt) isSigned = true;
return evaluateICmpRelation(Context, CE1Op0,
Context.getNullValue(CE1Op0->getType()),
Constant::getNullValue(CE1Op0->getType()),
sgnd);
}
@ -1379,10 +1379,10 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
// Fold FCMP_FALSE/FCMP_TRUE unconditionally.
if (pred == FCmpInst::FCMP_FALSE)
return Context.getNullValue(ResultTy);
return Constant::getNullValue(ResultTy);
if (pred == FCmpInst::FCMP_TRUE)
return Context.getAllOnesValue(ResultTy);
return Constant::getAllOnesValue(ResultTy);
// Handle some degenerate cases first
if (isa<UndefValue>(C1) || isa<UndefValue>(C2))

View File

@ -43,6 +43,48 @@ using namespace llvm;
// Becomes a no-op when multithreading is disabled.
ManagedStatic<sys::SmartRWMutex<true> > ConstantsLock;
// Constructor to create a '0' constant of arbitrary type...
static const uint64_t zero[2] = {0, 0};
Constant* Constant::getNullValue(const Type* Ty) {
switch (Ty->getTypeID()) {
case Type::IntegerTyID:
return ConstantInt::get(Ty, 0);
case Type::FloatTyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0)));
case Type::DoubleTyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0)));
case Type::X86_FP80TyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero)));
case Type::FP128TyID:
return ConstantFP::get(Ty->getContext(),
APFloat(APInt(128, 2, zero), true));
case Type::PPC_FP128TyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero)));
case Type::PointerTyID:
return ConstantPointerNull::get(cast<PointerType>(Ty));
case Type::StructTyID:
case Type::ArrayTyID:
case Type::VectorTyID:
return ConstantAggregateZero::get(Ty);
default:
// Function, Label, or Opaque type?
assert(!"Cannot create a null constant of that type!");
return 0;
}
}
Constant* Constant::getAllOnesValue(const Type* Ty) {
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
return ConstantInt::get(Ty->getContext(),
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>(ConstantVector::get(Elts));
}
void Constant::destroyConstantImpl() {
// When a Constant is destroyed, there may be lingering
// references to the constant by other constants in the constant pool. These
@ -148,7 +190,7 @@ void Constant::getVectorElements(LLVMContext &Context,
const VectorType *VT = cast<VectorType>(getType());
if (isa<ConstantAggregateZero>(this)) {
Elts.assign(VT->getNumElements(),
Context.getNullValue(VT->getElementType()));
Constant::getNullValue(VT->getElementType()));
return;
}
@ -296,14 +338,13 @@ Constant* ConstantFP::get(const Type* Ty, double V) {
ConstantFP* ConstantFP::getNegativeZero(const Type* Ty) {
LLVMContext &Context = Ty->getContext();
APFloat apf = cast <ConstantFP>(Context.getNullValue(Ty))->getValueAPF();
APFloat apf = cast <ConstantFP>(Constant::getNullValue(Ty))->getValueAPF();
apf.changeSign();
return get(Context, apf);
}
Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) {
LLVMContext &Context = Ty->getContext();
if (const VectorType *PTy = dyn_cast<VectorType>(Ty))
if (PTy->getElementType()->isFloatingPoint()) {
std::vector<Constant*> zeros(PTy->getNumElements(),
@ -314,7 +355,7 @@ Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) {
if (Ty->isFloatingPoint())
return getNegativeZero(Ty);
return Context.getNullValue(Ty);
return Constant::getNullValue(Ty);
}
@ -1751,18 +1792,16 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
Constant* ConstantExpr::getSizeOf(const Type* Ty) {
// sizeof is implemented as: (i64) gep (Ty*)null, 1
// Note that a non-inbounds gep is used, as null isn't within any object.
LLVMContext &Context = Ty->getContext();
Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1);
Constant *GEP = getGetElementPtr(
Context.getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1);
Constant::getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1);
return getCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
}
Constant* ConstantExpr::getAlignOf(const Type* Ty) {
LLVMContext &Context = Ty->getContext();
// alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
const Type *AligningTy = StructType::get(Type::Int8Ty, Ty, NULL);
Constant *NullPtr = Context.getNullValue(AligningTy->getPointerTo());
Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo());
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
Constant *One = ConstantInt::get(Type::Int32Ty, 1);
Constant *Indices[2] = { Zero, One };
@ -2029,8 +2068,7 @@ Constant* ConstantExpr::getFNeg(Constant* C) {
Constant* ConstantExpr::getNot(Constant* C) {
assert(C->getType()->isIntOrIntVector() &&
"Cannot NOT a nonintegral value!");
LLVMContext &Context = C->getType()->getContext();
return get(Instruction::Xor, C, Context.getAllOnesValue(C->getType()));
return get(Instruction::Xor, C, Constant::getAllOnesValue(C->getType()));
}
Constant* ConstantExpr::getAdd(Constant* C1, Constant* C2) {

View File

@ -327,11 +327,11 @@ LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
/*--.. Operations on constants of any type .................................--*/
LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
return wrap(getGlobalContext().getNullValue(unwrap(Ty)));
return wrap(Constant::getNullValue(unwrap(Ty)));
}
LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
return wrap(getGlobalContext().getAllOnesValue(unwrap(Ty)));
return wrap(Constant::getAllOnesValue(unwrap(Ty)));
}
LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {

View File

@ -1613,11 +1613,11 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
Instruction *InsertBefore) {
Constant *C;
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
C = Context.getAllOnesValue(PTy->getElementType());
C = Constant::getAllOnesValue(PTy->getElementType());
C = ConstantVector::get(
std::vector<Constant*>(PTy->getNumElements(), C));
} else {
C = Context.getAllOnesValue(Op->getType());
C = Constant::getAllOnesValue(Op->getType());
}
return new BinaryOperator(Instruction::Xor, Op, C,
@ -1630,11 +1630,11 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
Constant *AllOnes;
if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
// Create a vector of all ones values.
Constant *Elt = Context.getAllOnesValue(PTy->getElementType());
Constant *Elt = Constant::getAllOnesValue(PTy->getElementType());
AllOnes = ConstantVector::get(
std::vector<Constant*>(PTy->getNumElements(), Elt));
} else {
AllOnes = Context.getAllOnesValue(Op->getType());
AllOnes = Constant::getAllOnesValue(Op->getType());
}
return new BinaryOperator(Instruction::Xor, Op, AllOnes,

View File

@ -32,49 +32,6 @@ LLVMContext& llvm::getGlobalContext() {
LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
LLVMContext::~LLVMContext() { delete pImpl; }
// Constant accessors
// Constructor to create a '0' constant of arbitrary type...
static const uint64_t zero[2] = {0, 0};
Constant* LLVMContext::getNullValue(const Type* Ty) {
switch (Ty->getTypeID()) {
case Type::IntegerTyID:
return ConstantInt::get(Ty, 0);
case Type::FloatTyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0)));
case Type::DoubleTyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0)));
case Type::X86_FP80TyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero)));
case Type::FP128TyID:
return ConstantFP::get(Ty->getContext(),
APFloat(APInt(128, 2, zero), true));
case Type::PPC_FP128TyID:
return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero)));
case Type::PointerTyID:
return ConstantPointerNull::get(cast<PointerType>(Ty));
case Type::StructTyID:
case Type::ArrayTyID:
case Type::VectorTyID:
return ConstantAggregateZero::get(Ty);
default:
// Function, Label, or Opaque type?
assert(!"Cannot create a null constant of that type!");
return 0;
}
}
Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
return ConstantInt::get(*this, 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>(ConstantVector::get(Elts));
}
// MDNode accessors
MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
return pImpl->getMDNode(Vals, NumVals);

View File

@ -298,8 +298,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
if (isa<StructType>(BBTerm->getType()))
BBTerm->replaceAllUsesWith(UndefValue::get(BBTerm->getType()));
else if (BB->getTerminator()->getType() != Type::VoidTy)
BBTerm->replaceAllUsesWith(
BD.getContext().getNullValue(BBTerm->getType()));
BBTerm->replaceAllUsesWith(Constant::getNullValue(BBTerm->getType()));
// Replace the old terminator instruction.
BB->getInstList().pop_back();

View File

@ -74,7 +74,7 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I,
if (isa<StructType>(TheInst->getType()))
TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType()));
else if (TheInst->getType() != Type::VoidTy)
TheInst->replaceAllUsesWith(Context.getNullValue(TheInst->getType()));
TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType()));
// Remove the instruction from the program.
TheInst->getParent()->getInstList().erase(TheInst);

View File

@ -650,8 +650,6 @@ bool BugDriver::debugMiscompilation() {
///
static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
Module *Safe) {
LLVMContext &Context = BD.getContext();
// Clean up the modules, removing extra cruft that we don't need anymore...
Test = BD.performFinalCleanups(Test);
@ -723,7 +721,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// sbyte* so it matches the signature of the resolver function.
// GetElementPtr *funcName, ulong 0, ulong 0
std::vector<Constant*> GEPargs(2, Context.getNullValue(Type::Int32Ty));
std::vector<Constant*> GEPargs(2, Constant::getNullValue(Type::Int32Ty));
Value *GEP =
ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2);
std::vector<Value*> ResolverArgs;

View File

@ -60,7 +60,7 @@ namespace {
for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
if (CallInst *CI = dyn_cast<CallInst>(I)) {
if (!CI->use_empty())
CI->replaceAllUsesWith(BB.getContext().getNullValue(CI->getType()));
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
CI->getParent()->getInstList().erase(CI);
break;
}

View File

@ -295,7 +295,7 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
private:
virtual void deleted() {
getValPtr()->replaceAllUsesWith(Context->getNullValue(Type::Int32Ty));
getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::Int32Ty));
setValPtr(NULL);
}
virtual void allUsesReplacedWith(Value *new_value) {