diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 42ce95347de..93f0a1848d8 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -647,7 +647,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, return true; } - if (isa(Ty) || Ty == Type::getLabelTy(Context)) + if (isa(Ty) || Ty->isLabelTy()) return Error(TyLoc, "invalid type for global variable"); GlobalVariable *GV = 0; @@ -1113,7 +1113,7 @@ bool LLParser::ParseType(PATypeHolder &Result, bool AllowVoid) { if (!UpRefs.empty()) return Error(UpRefs.back().Loc, "invalid unresolved type up reference"); - if (!AllowVoid && Result.get() == Type::getVoidTy(Context)) + if (!AllowVoid && Result.get()->isVoidTy()) return Error(TypeLoc, "void type only allowed for function results"); return false; @@ -1275,9 +1275,9 @@ bool LLParser::ParseTypeRec(PATypeHolder &Result) { // TypeRec ::= TypeRec '*' case lltok::star: - if (Result.get() == Type::getLabelTy(Context)) + if (Result.get()->isLabelTy()) return TokError("basic block pointers are invalid"); - if (Result.get() == Type::getVoidTy(Context)) + if (Result.get()->isVoidTy()) return TokError("pointers to void are invalid; use i8* instead"); if (!PointerType::isValidElementType(Result.get())) return TokError("pointer to this type is invalid"); @@ -1287,9 +1287,9 @@ bool LLParser::ParseTypeRec(PATypeHolder &Result) { // TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*' case lltok::kw_addrspace: { - if (Result.get() == Type::getLabelTy(Context)) + if (Result.get()->isLabelTy()) return TokError("basic block pointers are invalid"); - if (Result.get() == Type::getVoidTy(Context)) + if (Result.get()->isVoidTy()) return TokError("pointers to void are invalid; use i8* instead"); if (!PointerType::isValidElementType(Result.get())) return TokError("pointer to this type is invalid"); @@ -1380,7 +1380,7 @@ bool LLParser::ParseArgumentList(std::vector &ArgList, if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) || ParseOptionalAttrs(Attrs, 0)) return true; - if (ArgTy == Type::getVoidTy(Context)) + if (ArgTy->isVoidTy()) return Error(TypeLoc, "argument can not have void type"); if (Lex.getKind() == lltok::LocalVar || @@ -1406,7 +1406,7 @@ bool LLParser::ParseArgumentList(std::vector &ArgList, if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) || ParseOptionalAttrs(Attrs, 0)) return true; - if (ArgTy == Type::getVoidTy(Context)) + if (ArgTy->isVoidTy()) return Error(TypeLoc, "argument can not have void type"); if (Lex.getKind() == lltok::LocalVar || @@ -1484,7 +1484,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) { if (ParseTypeRec(Result)) return true; ParamsList.push_back(Result); - if (Result == Type::getVoidTy(Context)) + if (Result->isVoidTy()) return Error(EltTyLoc, "struct element can not have void type"); if (!StructType::isValidElementType(Result)) return Error(EltTyLoc, "invalid element type for struct"); @@ -1493,7 +1493,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) { EltTyLoc = Lex.getLoc(); if (ParseTypeRec(Result)) return true; - if (Result == Type::getVoidTy(Context)) + if (Result->isVoidTy()) return Error(EltTyLoc, "struct element can not have void type"); if (!StructType::isValidElementType(Result)) return Error(EltTyLoc, "invalid element type for struct"); @@ -1532,7 +1532,7 @@ bool LLParser::ParseArrayVectorType(PATypeHolder &Result, bool isVector) { PATypeHolder EltTy(Type::getVoidTy(Context)); if (ParseTypeRec(EltTy)) return true; - if (EltTy == Type::getVoidTy(Context)) + if (EltTy->isVoidTy()) return Error(TypeLoc, "array and vector element type cannot be void"); if (ParseToken(isVector ? lltok::greater : lltok::rsquare, @@ -1623,7 +1623,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) { if (Val->getType() == Ty) return Val; - if (Ty == Type::getLabelTy(F.getContext())) + if (Ty->isLabelTy()) P.Error(Loc, "'%" + Name + "' is not a basic block"); else P.Error(Loc, "'%" + Name + "' defined with type '" + @@ -1640,7 +1640,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name, // Otherwise, create a new forward reference for this value and remember it. Value *FwdVal; - if (Ty == Type::getLabelTy(F.getContext())) + if (Ty->isLabelTy()) FwdVal = BasicBlock::Create(F.getContext(), Name, &F); else FwdVal = new Argument(Ty, Name); @@ -1666,7 +1666,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) { if (Val->getType() == Ty) return Val; - if (Ty == Type::getLabelTy(F.getContext())) + if (Ty->isLabelTy()) P.Error(Loc, "'%" + utostr(ID) + "' is not a basic block"); else P.Error(Loc, "'%" + utostr(ID) + "' defined with type '" + @@ -1682,7 +1682,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty, // Otherwise, create a new forward reference for this value and remember it. Value *FwdVal; - if (Ty == Type::getLabelTy(F.getContext())) + if (Ty->isLabelTy()) FwdVal = BasicBlock::Create(F.getContext(), "", &F); else FwdVal = new Argument(Ty); @@ -1697,7 +1697,7 @@ bool LLParser::PerFunctionState::SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc, Instruction *Inst) { // If this instruction has void type, it cannot have a name or ID specified. - if (Inst->getType() == Type::getVoidTy(F.getContext())) { + if (Inst->getType()->isVoidTy()) { if (NameID != -1 || !NameStr.empty()) return P.Error(NameLoc, "instructions returning void cannot have a name"); return false; @@ -2279,7 +2279,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, // The lexer has no type info, so builds all float and double FP constants // as double. Fix this here. Long double does not need this. if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble && - Ty == Type::getFloatTy(Context)) { + Ty->isFloatTy()) { bool Ignored; ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored); @@ -2298,7 +2298,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, return false; case ValID::t_Undef: // FIXME: LabelTy should not be a first-class type. - if ((!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context)) && + if ((!Ty->isFirstClassType() || Ty->isLabelTy()) && !isa(Ty)) return Error(ID.Loc, "invalid type for undef constant"); V = UndefValue::get(Ty); @@ -2310,7 +2310,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, return false; case ValID::t_Zero: // FIXME: LabelTy should not be a first-class type. - if (!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context)) + if (!Ty->isFirstClassType() || Ty->isLabelTy()) return Error(ID.Loc, "invalid type for null constant"); V = Constant::getNullValue(Ty); return false; @@ -2856,7 +2856,7 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB, PATypeHolder Ty(Type::getVoidTy(Context)); if (ParseType(Ty, true /*void allowed*/)) return true; - if (Ty == Type::getVoidTy(Context)) { + if (Ty->isVoidTy()) { if (EatIfPresent(lltok::comma)) if (ParseOptionalCustomMetadata()) return true; Inst = ReturnInst::Create(Context); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index fe0366fb629..50fc78c1c78 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -342,7 +342,7 @@ Value *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) { resize(Idx + 1); if (Value *V = MDValuePtrs[Idx]) { - assert(V->getType() == Type::getMetadataTy(Context) && "Type mismatch in value table!"); + assert(V->getType()->isMetadataTy() && "Type mismatch in value table!"); return V; } @@ -808,7 +808,7 @@ bool BitcodeReader::ParseMetadata() { SmallVector Elts; for (unsigned i = 0; i != Size; i += 2) { const Type *Ty = getTypeByID(Record[i], false); - if (Ty == Type::getMetadataTy(Context)) + if (Ty->isMetadataTy()) Elts.push_back(MDValueList.getValueFwdRef(Record[i+1])); else if (Ty != Type::getVoidTy(Context)) Elts.push_back(ValueList.getValueFwdRef(Record[i+1], Ty)); @@ -967,19 +967,19 @@ bool BitcodeReader::ParseConstants() { case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval] if (Record.empty()) return Error("Invalid FLOAT record"); - if (CurTy == Type::getFloatTy(Context)) + if (CurTy->isFloatTy()) V = ConstantFP::get(Context, APFloat(APInt(32, (uint32_t)Record[0]))); - else if (CurTy == Type::getDoubleTy(Context)) + else if (CurTy->isDoubleTy()) V = ConstantFP::get(Context, APFloat(APInt(64, Record[0]))); - else if (CurTy == Type::getX86_FP80Ty(Context)) { + else if (CurTy->isX86_FP80Ty()) { // Bits are not stored the same way as a normal i80 APInt, compensate. uint64_t Rearrange[2]; Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16); Rearrange[1] = Record[0] >> 48; V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange))); - } else if (CurTy == Type::getFP128Ty(Context)) + } else if (CurTy->isFP128Ty()) V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true)); - else if (CurTy == Type::getPPC_FP128Ty(Context)) + else if (CurTy->isPPC_FP128Ty()) V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]))); else V = UndefValue::get(CurTy); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 5857c5914bb..ae269dfbcce 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -729,18 +729,16 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, } else if (const ConstantFP *CFP = dyn_cast(C)) { Code = bitc::CST_CODE_FLOAT; const Type *Ty = CFP->getType(); - if (Ty == Type::getFloatTy(Ty->getContext()) || - Ty == Type::getDoubleTy(Ty->getContext())) { + if (Ty->isFloatTy() || Ty->isDoubleTy()) { Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue()); - } else if (Ty == Type::getX86_FP80Ty(Ty->getContext())) { + } else if (Ty->isX86_FP80Ty()) { // api needed to prevent premature destruction // bits are not in the same order as a normal i80 APInt, compensate. APInt api = CFP->getValueAPF().bitcastToAPInt(); const uint64_t *p = api.getRawData(); Record.push_back((p[1] << 48) | (p[0] >> 16)); Record.push_back(p[0] & 0xffffLL); - } else if (Ty == Type::getFP128Ty(Ty->getContext()) || - Ty == Type::getPPC_FP128Ty(Ty->getContext())) { + } else if (Ty->isFP128Ty() || Ty->isPPC_FP128Ty()) { APInt api = CFP->getValueAPF().bitcastToAPInt(); const uint64_t *p = api.getRawData(); Record.push_back(p[0]); diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 7e834737f01..500693971c3 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1006,7 +1006,7 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, // precision... LLVMContext &Context = CFP->getContext(); const TargetData *TD = TM.getTargetData(); - if (CFP->getType() == Type::getDoubleTy(Context)) { + if (CFP->getType()->isDoubleTy()) { double Val = CFP->getValueAPF().convertToDouble(); // for comment only uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue(); if (MAI->getData64bitsDirective(AddrSpace)) { @@ -1048,7 +1048,9 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, O << '\n'; } return; - } else if (CFP->getType() == Type::getFloatTy(Context)) { + } + + if (CFP->getType()->isFloatTy()) { float Val = CFP->getValueAPF().convertToFloat(); // for comment only O << MAI->getData32bitsDirective(AddrSpace) << CFP->getValueAPF().bitcastToAPInt().getZExtValue(); @@ -1058,7 +1060,9 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, } O << '\n'; return; - } else if (CFP->getType() == Type::getX86_FP80Ty(Context)) { + } + + if (CFP->getType()->isX86_FP80Ty()) { // all long double variants are printed as hex // api needed to prevent premature destruction APInt api = CFP->getValueAPF().bitcastToAPInt(); @@ -1143,7 +1147,9 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) - TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace); return; - } else if (CFP->getType() == Type::getPPC_FP128Ty(Context)) { + } + + if (CFP->getType()->isPPC_FP128Ty()) { // all long double variants are printed as hex // api needed to prevent premature destruction APInt api = CFP->getValueAPF().bitcastToAPInt(); diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 55a2f700643..3e1ee11b216 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -457,16 +457,15 @@ void ELFWriter::EmitGlobalConstant(const Constant *CV, ELFSection &GblS) { return; } else if (const ConstantFP *CFP = dyn_cast(CV)) { APInt Val = CFP->getValueAPF().bitcastToAPInt(); - if (CFP->getType() == Type::getDoubleTy(CV->getContext())) + if (CFP->getType()->isDoubleTy()) GblS.emitWord64(Val.getZExtValue()); - else if (CFP->getType() == Type::getFloatTy(CV->getContext())) + else if (CFP->getType()->isFloatTy()) GblS.emitWord32(Val.getZExtValue()); - else if (CFP->getType() == Type::getX86_FP80Ty(CV->getContext())) { - unsigned PadSize = - TD->getTypeAllocSize(Type::getX86_FP80Ty(CV->getContext()))- - TD->getTypeStoreSize(Type::getX86_FP80Ty(CV->getContext())); + else if (CFP->getType()->isX86_FP80Ty()) { + unsigned PadSize = TD->getTypeAllocSize(CFP->getType())- + TD->getTypeStoreSize(CFP->getType()); GblS.emitWordFP80(Val.getRawData(), PadSize); - } else if (CFP->getType() == Type::getPPC_FP128Ty(CV->getContext())) + } else if (CFP->getType()->isPPC_FP128Ty()) llvm_unreachable("PPC_FP128Ty global emission not implemented"); return; } else if (const ConstantInt *CI = dyn_cast(CV)) { diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 3d1c22159a5..a3560a77b65 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -239,7 +239,7 @@ void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const { OS << getImm(); break; case MachineOperand::MO_FPImmediate: - if (getFPImm()->getType() == Type::getFloatTy(getFPImm()->getContext())) + if (getFPImm()->getType()->isFloatTy()) OS << getFPImm()->getValueAPF().convertToFloat(); else OS << getFPImm()->getValueAPF().convertToDouble(); diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 335d4deff84..d3430a376a1 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -539,11 +539,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { } case Instruction::UIToFP: { GenericValue GV = getConstantValue(Op0); - if (CE->getType() == Type::getFloatTy(CE->getContext())) + if (CE->getType()->isFloatTy()) GV.FloatVal = float(GV.IntVal.roundToDouble()); - else if (CE->getType() == Type::getDoubleTy(CE->getContext())) + else if (CE->getType()->isDoubleTy()) GV.DoubleVal = GV.IntVal.roundToDouble(); - else if (CE->getType() == Type::getX86_FP80Ty(Op0->getContext())) { + else if (CE->getType()->isX86_FP80Ty()) { const uint64_t zero[] = {0, 0}; APFloat apf = APFloat(APInt(80, 2, zero)); (void)apf.convertFromAPInt(GV.IntVal, @@ -555,11 +555,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { } case Instruction::SIToFP: { GenericValue GV = getConstantValue(Op0); - if (CE->getType() == Type::getFloatTy(CE->getContext())) + if (CE->getType()->isFloatTy()) GV.FloatVal = float(GV.IntVal.signedRoundToDouble()); - else if (CE->getType() == Type::getDoubleTy(CE->getContext())) + else if (CE->getType()->isDoubleTy()) GV.DoubleVal = GV.IntVal.signedRoundToDouble(); - else if (CE->getType() == Type::getX86_FP80Ty(CE->getContext())) { + else if (CE->getType()->isX86_FP80Ty()) { const uint64_t zero[] = { 0, 0}; APFloat apf = APFloat(APInt(80, 2, zero)); (void)apf.convertFromAPInt(GV.IntVal, @@ -573,11 +573,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { case Instruction::FPToSI: { GenericValue GV = getConstantValue(Op0); uint32_t BitWidth = cast(CE->getType())->getBitWidth(); - if (Op0->getType() == Type::getFloatTy(Op0->getContext())) + if (Op0->getType()->isFloatTy()) GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth); - else if (Op0->getType() == Type::getDoubleTy(Op0->getContext())) + else if (Op0->getType()->isDoubleTy()) GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth); - else if (Op0->getType() == Type::getX86_FP80Ty(Op0->getContext())) { + else if (Op0->getType()->isX86_FP80Ty()) { APFloat apf = APFloat(GV.IntVal); uint64_t v; bool ignored; @@ -610,9 +610,9 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { default: llvm_unreachable("Invalid bitcast operand"); case Type::IntegerTyID: assert(DestTy->isFloatingPoint() && "invalid bitcast"); - if (DestTy == Type::getFloatTy(Op0->getContext())) + if (DestTy->isFloatTy()) GV.FloatVal = GV.IntVal.bitsToFloat(); - else if (DestTy == Type::getDoubleTy(DestTy->getContext())) + else if (DestTy->isDoubleTy()) GV.DoubleVal = GV.IntVal.bitsToDouble(); break; case Type::FloatTyID: diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index bb45b2c441b..f8c775ee7c1 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -365,7 +365,7 @@ static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2, } #define IMPLEMENT_UNORDERED(TY, X,Y) \ - if (TY == Type::getFloatTy(Ty->getContext())) { \ + if (TY->isFloatTy()) { \ if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ Dest.IntVal = APInt(1,true); \ return Dest; \ @@ -421,7 +421,7 @@ static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2, static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; - if (Ty == Type::getFloatTy(Ty->getContext())) + if (Ty->isFloatTy()) Dest.IntVal = APInt(1,(Src1.FloatVal == Src1.FloatVal && Src2.FloatVal == Src2.FloatVal)); else @@ -433,7 +433,7 @@ static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; - if (Ty == Type::getFloatTy(Ty->getContext())) + if (Ty->isFloatTy()) Dest.IntVal = APInt(1,(Src1.FloatVal != Src1.FloatVal || Src2.FloatVal != Src2.FloatVal)); else @@ -970,8 +970,7 @@ GenericValue Interpreter::executeZExtInst(Value *SrcVal, const Type *DstTy, GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy, ExecutionContext &SF) { GenericValue Dest, Src = getOperandValue(SrcVal, SF); - assert(SrcVal->getType() == Type::getDoubleTy(SrcVal->getContext()) && - DstTy == Type::getFloatTy(SrcVal->getContext()) && + assert(SrcVal->getType()->isDoubleTy() && DstTy->isFloatTy() && "Invalid FPTrunc instruction"); Dest.FloatVal = (float) Src.DoubleVal; return Dest; @@ -980,8 +979,7 @@ GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy, GenericValue Interpreter::executeFPExtInst(Value *SrcVal, const Type *DstTy, ExecutionContext &SF) { GenericValue Dest, Src = getOperandValue(SrcVal, SF); - assert(SrcVal->getType() == Type::getFloatTy(SrcVal->getContext()) && - DstTy == Type::getDoubleTy(SrcVal->getContext()) && + assert(SrcVal->getType()->isFloatTy() && DstTy->isDoubleTy() && "Invalid FPTrunc instruction"); Dest.DoubleVal = (double) Src.FloatVal; return Dest; @@ -1072,22 +1070,22 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy, assert(isa(SrcTy) && "Invalid BitCast"); Dest.PointerVal = Src.PointerVal; } else if (DstTy->isInteger()) { - if (SrcTy == Type::getFloatTy(SrcVal->getContext())) { + if (SrcTy->isFloatTy()) { Dest.IntVal.zext(sizeof(Src.FloatVal) * CHAR_BIT); Dest.IntVal.floatToBits(Src.FloatVal); - } else if (SrcTy == Type::getDoubleTy(SrcVal->getContext())) { + } else if (SrcTy->isDoubleTy()) { Dest.IntVal.zext(sizeof(Src.DoubleVal) * CHAR_BIT); Dest.IntVal.doubleToBits(Src.DoubleVal); } else if (SrcTy->isInteger()) { Dest.IntVal = Src.IntVal; } else llvm_unreachable("Invalid BitCast"); - } else if (DstTy == Type::getFloatTy(SrcVal->getContext())) { + } else if (DstTy->isFloatTy()) { if (SrcTy->isInteger()) Dest.FloatVal = Src.IntVal.bitsToFloat(); else Dest.FloatVal = Src.FloatVal; - } else if (DstTy == Type::getDoubleTy(SrcVal->getContext())) { + } else if (DstTy->isDoubleTy()) { if (SrcTy->isInteger()) Dest.DoubleVal = Src.IntVal.bitsToDouble(); else diff --git a/lib/Target/ARM/ARMCodeEmitter.cpp b/lib/Target/ARM/ARMCodeEmitter.cpp index 6419b6966cc..0f682e2535e 100644 --- a/lib/Target/ARM/ARMCodeEmitter.cpp +++ b/lib/Target/ARM/ARMCodeEmitter.cpp @@ -460,9 +460,9 @@ void Emitter::emitConstPoolInstruction(const MachineInstr &MI) { uint32_t Val = *(uint32_t*)CI->getValue().getRawData(); emitWordLE(Val); } else if (const ConstantFP *CFP = dyn_cast(CV)) { - if (CFP->getType() == Type::getFloatTy(CFP->getContext())) + if (CFP->getType()->isFloatTy()) emitWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue()); - else if (CFP->getType() == Type::getDoubleTy(CFP->getContext())) + else if (CFP->getType()->isDoubleTy()) emitDWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue()); else { llvm_unreachable("Unable to handle this constantpool entry!"); diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index ef931bd95e7..3401df0c909 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -1058,9 +1058,9 @@ bool X86FastISel::X86SelectSelect(Instruction *I) { bool X86FastISel::X86SelectFPExt(Instruction *I) { // fpext from float to double. if (Subtarget->hasSSE2() && - I->getType() == Type::getDoubleTy(I->getContext())) { + I->getType()->isDoubleTy()) { Value *V = I->getOperand(0); - if (V->getType() == Type::getFloatTy(I->getContext())) { + if (V->getType()->isFloatTy()) { unsigned OpReg = getRegForValue(V); if (OpReg == 0) return false; unsigned ResultReg = createResultReg(X86::FR64RegisterClass); @@ -1075,9 +1075,9 @@ bool X86FastISel::X86SelectFPExt(Instruction *I) { bool X86FastISel::X86SelectFPTrunc(Instruction *I) { if (Subtarget->hasSSE2()) { - if (I->getType() == Type::getFloatTy(I->getContext())) { + if (I->getType()->isFloatTy()) { Value *V = I->getOperand(0); - if (V->getType() == Type::getDoubleTy(I->getContext())) { + if (V->getType()->isDoubleTy()) { unsigned OpReg = getRegForValue(V); if (OpReg == 0) return false; unsigned ResultReg = createResultReg(X86::FR32RegisterClass); @@ -1244,7 +1244,7 @@ bool X86FastISel::X86SelectCall(Instruction *I) { // Handle *simple* calls for now. const Type *RetTy = CS.getType(); EVT RetVT; - if (RetTy == Type::getVoidTy(I->getContext())) + if (RetTy->isVoidTy()) RetVT = MVT::isVoid; else if (!isTypeLegal(RetTy, RetVT, true)) return false; diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index b13138415d0..30cdeee8262 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -38,16 +38,18 @@ STATISTIC(NumMoveToCpy, "Number of memmoves converted to memcpy"); /// true for all i8 values obviously, but is also true for i32 0, i32 -1, /// i16 0xF0F0, double 0.0 etc. If the value can't be handled with a repeated /// byte store (e.g. i16 0x1234), return null. -static Value *isBytewiseValue(Value *V, LLVMContext &Context) { +static Value *isBytewiseValue(Value *V) { + LLVMContext &Context = V->getContext(); + // All byte-wide stores are splatable, even of arbitrary variables. if (V->getType() == Type::getInt8Ty(Context)) return V; // Constant float and double values can be handled as integer values if the // corresponding integer value is "byteable". An important case is 0.0. if (ConstantFP *CFP = dyn_cast(V)) { - if (CFP->getType() == Type::getFloatTy(Context)) + if (CFP->getType()->isFloatTy()) V = ConstantExpr::getBitCast(CFP, Type::getInt32Ty(Context)); - if (CFP->getType() == Type::getDoubleTy(Context)) + if (CFP->getType()->isDoubleTy()) V = ConstantExpr::getBitCast(CFP, Type::getInt64Ty(Context)); // Don't handle long double formats, which have strange constraints. } @@ -349,7 +351,7 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator &BBI) { // Ensure that the value being stored is something that can be memset'able a // byte at a time like "0" or "-1" or any width, as well as things like // 0xA0A0A0A0 and 0.0. - Value *ByteVal = isBytewiseValue(SI->getOperand(0), Context); + Value *ByteVal = isBytewiseValue(SI->getOperand(0)); if (!ByteVal) return false; @@ -390,7 +392,7 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator &BBI) { if (NextStore->isVolatile()) break; // Check to see if this stored value is of the same byte-splattable value. - if (ByteVal != isBytewiseValue(NextStore->getOperand(0), Context)) + if (ByteVal != isBytewiseValue(NextStore->getOperand(0))) break; // Check to see if this store is to a constant offset from the start ptr. diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 2f49d258676..e08bddbe567 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1184,7 +1184,7 @@ void SCCPSolver::visitCallSite(CallSite CS) { if (F == 0 || !F->hasLocalLinkage()) { CallOverdefined: // Void return and not tracking callee, just bail. - if (I->getType() == Type::getVoidTy(I->getContext())) return; + if (I->getType()->isVoidTy()) return; // Otherwise, if we have a single return value case, and if the function is // a declaration, maybe we can constant fold it. @@ -1354,7 +1354,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { // Look for instructions which produce undef values. - if (I->getType() == Type::getVoidTy(F.getContext())) continue; + if (I->getType()->isVoidTy()) continue; LatticeVal &LV = getValueState(I); if (!LV.isUndefined()) continue; @@ -1593,8 +1593,7 @@ bool SCCP::runOnFunction(Function &F) { // for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) { Instruction *Inst = BI++; - if (Inst->getType() == Type::getVoidTy(F.getContext()) || - isa(Inst)) + if (Inst->getType()->isVoidTy() || isa(Inst)) continue; LatticeVal &IV = Values[Inst]; @@ -1769,7 +1768,7 @@ bool IPSCCP::runOnModule(Module &M) { } else { for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) { Instruction *Inst = BI++; - if (Inst->getType() == Type::getVoidTy(M.getContext())) + if (Inst->getType()->isVoidTy()) continue; LatticeVal &IV = Values[Inst]; @@ -1846,7 +1845,7 @@ bool IPSCCP::runOnModule(Module &M) { for (DenseMap::const_iterator I = RV.begin(), E = RV.end(); I != E; ++I) if (!I->second.isOverdefined() && - I->first->getReturnType() != Type::getVoidTy(M.getContext())) { + !I->first->getReturnType()->isVoidTy()) { Function *F = I->first; for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) if (ReturnInst *RI = dyn_cast(BB->getTerminator())) diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 6d069593969..610d874b368 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -1297,8 +1297,7 @@ static void MergeInType(const Type *In, uint64_t Offset, const Type *&VecTy, VecTy = VInTy; return; } - } else if (In == Type::getFloatTy(Context) || - In == Type::getDoubleTy(Context) || + } else if (In->isFloatTy() || In->isDoubleTy() || (isa(In) && In->getPrimitiveSizeInBits() >= 8 && isPowerOf2_32(In->getPrimitiveSizeInBits()))) { // If we're accessing something that could be an element of a vector, see diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 57a7d051e9f..ab458a604e5 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -225,12 +225,12 @@ Value *LibCallOptimization::EmitUnaryFloatFnCall(Value *Op, const char *Name, IRBuilder<> &B, const AttrListPtr &Attrs) { char NameBuffer[20]; - if (Op->getType() != Type::getDoubleTy(*Context)) { + if (!Op->getType()->isDoubleTy()) { // If we need to add a suffix, copy into NameBuffer. unsigned NameLen = strlen(Name); assert(NameLen < sizeof(NameBuffer)-2); memcpy(NameBuffer, Name, NameLen); - if (Op->getType() == Type::getFloatTy(*Context)) + if (Op->getType()->isFloatTy()) NameBuffer[NameLen] = 'f'; // floorf else NameBuffer[NameLen] = 'l'; // floorl @@ -622,7 +622,8 @@ struct StrChrOpt : public LibCallOptimization { if (!TD) return 0; uint64_t Len = GetStringLength(SrcStr); - if (Len == 0 || FT->getParamType(1) != Type::getInt32Ty(*Context)) // memchr needs i32. + if (Len == 0 || + FT->getParamType(1) != Type::getInt32Ty(*Context)) // memchr needs i32. return 0; return EmitMemChr(SrcStr, CI->getOperand(2), // include nul. @@ -1082,15 +1083,15 @@ struct Exp2Opt : public LibCallOptimization { if (LdExpArg) { const char *Name; - if (Op->getType() == Type::getFloatTy(*Context)) + if (Op->getType()->isFloatTy()) Name = "ldexpf"; - else if (Op->getType() == Type::getDoubleTy(*Context)) + else if (Op->getType()->isDoubleTy()) Name = "ldexp"; else Name = "ldexpl"; Constant *One = ConstantFP::get(*Context, APFloat(1.0f)); - if (Op->getType() != Type::getFloatTy(*Context)) + if (!Op->getType()->isFloatTy()) One = ConstantExpr::getFPExtend(One, Op->getType()); Module *M = Caller->getParent(); @@ -1112,13 +1113,13 @@ struct Exp2Opt : public LibCallOptimization { struct UnaryDoubleFPOpt : public LibCallOptimization { virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { const FunctionType *FT = Callee->getFunctionType(); - if (FT->getNumParams() != 1 || FT->getReturnType() != Type::getDoubleTy(*Context) || - FT->getParamType(0) != Type::getDoubleTy(*Context)) + if (FT->getNumParams() != 1 || !FT->getReturnType()->isDoubleTy() || + !FT->getParamType(0)->isDoubleTy()) return 0; // If this is something like 'floor((double)floatval)', convert to floorf. FPExtInst *Cast = dyn_cast(CI->getOperand(1)); - if (Cast == 0 || Cast->getOperand(0)->getType() != Type::getFloatTy(*Context)) + if (Cast == 0 || !Cast->getOperand(0)->getType()->isFloatTy()) return 0; // floor((double)floatval) -> (double)floorf(floatval) @@ -1260,7 +1261,7 @@ struct PrintFOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() < 1 || !isa(FT->getParamType(0)) || !(isa(FT->getReturnType()) || - FT->getReturnType() == Type::getVoidTy(*Context))) + FT->getReturnType()->isVoidTy())) return 0; // Check for a fixed format string. diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 54115494196..c1fcc5f4ed2 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -192,7 +192,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, return UndefValue::get(DestTy); } // No compile-time operations on this type yet. - if (V->getType() == Type::getPPC_FP128Ty(Context) || DestTy == Type::getPPC_FP128Ty(Context)) + if (V->getType()->isPPC_FP128Ty() || DestTy->isPPC_FP128Ty()) return 0; // If the cast operand is a constant expression, there's a few things we can @@ -241,10 +241,10 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, if (ConstantFP *FPC = dyn_cast(V)) { bool ignored; APFloat Val = FPC->getValueAPF(); - Val.convert(DestTy == Type::getFloatTy(Context) ? APFloat::IEEEsingle : - DestTy == Type::getDoubleTy(Context) ? APFloat::IEEEdouble : - DestTy == Type::getX86_FP80Ty(Context) ? APFloat::x87DoubleExtended : - DestTy == Type::getFP128Ty(Context) ? APFloat::IEEEquad : + Val.convert(DestTy->isFloatTy() ? APFloat::IEEEsingle : + DestTy->isDoubleTy() ? APFloat::IEEEdouble : + DestTy->isX86_FP80Ty() ? APFloat::x87DoubleExtended : + DestTy->isFP128Ty() ? APFloat::IEEEquad : APFloat::Bogus, APFloat::rmNearestTiesToEven, &ignored); return ConstantFP::get(Context, Val); @@ -584,7 +584,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, unsigned Opcode, Constant *C1, Constant *C2) { // No compile-time operations on this type yet. - if (C1->getType() == Type::getPPC_FP128Ty(Context)) + if (C1->getType()->isPPC_FP128Ty()) return 0; // Handle UndefValue up front. @@ -1110,7 +1110,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context, "Cannot compare values of different types!"); // No compile-time operations on this type yet. - if (V1->getType() == Type::getPPC_FP128Ty(Context)) + if (V1->getType()->isPPC_FP128Ty()) return FCmpInst::BAD_FCMP_PREDICATE; // Handle degenerate case quickly @@ -1403,7 +1403,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, return UndefValue::get(ResultTy); // No compile-time operations on this type yet. - if (C1->getType() == Type::getPPC_FP128Ty(Context)) + if (C1->getType()->isPPC_FP128Ty()) return 0; // icmp eq/ne(null,GV) -> false/true @@ -1837,7 +1837,8 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context, // This happens with pointers to member functions in C++. if (CE->getOpcode() == Instruction::IntToPtr && NumIdx == 1 && isa(CE->getOperand(0)) && isa(Idxs[0]) && - cast(CE->getType())->getElementType() == Type::getInt8Ty(Context)) { + cast(CE->getType())->getElementType() == + Type::getInt8Ty(Context)) { Constant *Base = CE->getOperand(0); Constant *Offset = Idxs[0]; diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index ba1731d3546..529c45557bc 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -327,16 +327,16 @@ ConstantInt* ConstantInt::get(const IntegerType* Ty, const StringRef& Str, //===----------------------------------------------------------------------===// static const fltSemantics *TypeToFloatSemantics(const Type *Ty) { - if (Ty == Type::getFloatTy(Ty->getContext())) + if (Ty->isFloatTy()) return &APFloat::IEEEsingle; - if (Ty == Type::getDoubleTy(Ty->getContext())) + if (Ty->isDoubleTy()) return &APFloat::IEEEdouble; - if (Ty == Type::getX86_FP80Ty(Ty->getContext())) + if (Ty->isX86_FP80Ty()) return &APFloat::x87DoubleExtended; - else if (Ty == Type::getFP128Ty(Ty->getContext())) + else if (Ty->isFP128Ty()) return &APFloat::IEEEquad; - assert(Ty == Type::getPPC_FP128Ty(Ty->getContext()) && "Unknown FP format"); + assert(Ty->isPPC_FP128Ty() && "Unknown FP format"); return &APFloat::PPCDoubleDouble; } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 4f7c84769b0..257b2495a8a 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -600,12 +600,11 @@ void Verifier::visitFunction(Function &F) { "# formal arguments must match # of arguments for function type!", &F, FT); Assert1(F.getReturnType()->isFirstClassType() || - F.getReturnType()->getTypeID() == Type::VoidTyID || + F.getReturnType()->isVoidTy() || isa(F.getReturnType()), "Functions cannot return aggregate values!", &F); - Assert1(!F.hasStructRetAttr() || - F.getReturnType()->getTypeID() == Type::VoidTyID, + Assert1(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(), "Invalid struct return type!", &F); const AttrListPtr &Attrs = F.getAttributes(); @@ -643,7 +642,7 @@ void Verifier::visitFunction(Function &F) { Assert1(I->getType()->isFirstClassType(), "Function arguments must have first-class types!", I); if (!isLLVMdotName) - Assert2(I->getType() != Type::getMetadataTy(F.getContext()), + Assert2(!I->getType()->isMetadataTy(), "Function takes metadata but isn't an intrinsic", I, &F); } @@ -738,7 +737,7 @@ void Verifier::visitTerminatorInst(TerminatorInst &I) { void Verifier::visitReturnInst(ReturnInst &RI) { Function *F = RI.getParent()->getParent(); unsigned N = RI.getNumOperands(); - if (F->getReturnType()->getTypeID() == Type::VoidTyID) + if (F->getReturnType()->isVoidTy()) Assert2(N == 0, "Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); @@ -1103,7 +1102,7 @@ void Verifier::VerifyCallSite(CallSite CS) { CS.getCalledFunction()->getName().substr(0, 5) != "llvm.") { for (FunctionType::param_iterator PI = FTy->param_begin(), PE = FTy->param_end(); PI != PE; ++PI) - Assert1(PI->get() != Type::getMetadataTy(I->getContext()), + Assert1(!PI->get()->isMetadataTy(), "Function has metadata parameter but isn't an intrinsic", I); } @@ -1329,18 +1328,18 @@ void Verifier::visitInstruction(Instruction &I) { Assert1(BB->getTerminator() == &I, "Terminator not at end of block!", &I); // Check that void typed values don't have names - Assert1(I.getType() != Type::getVoidTy(I.getContext()) || !I.hasName(), + Assert1(!I.getType()->isVoidTy() || !I.hasName(), "Instruction has a name, but provides a void value!", &I); // Check that the return value of the instruction is either void or a legal // value type. - Assert1(I.getType()->getTypeID() == Type::VoidTyID || + Assert1(I.getType()->isVoidTy() || I.getType()->isFirstClassType(), "Instruction returns a non-scalar type!", &I); // Check that the instruction doesn't produce metadata. Calls are already // checked against the callee type. - Assert1(I.getType()->getTypeID() != Type::MetadataTyID || + Assert1(!I.getType()->isMetadataTy() || isa(I) || isa(I), "Invalid use of metadata!", &I);