X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTableGen%2FRecord.cpp;h=cb21be7b7627ae17100ec3ae432c497bd711e3ac;hb=2b861c3a24fa299d6b8a2d5097114c1000354bee;hp=a43665bcd85df2f9cd719b9c407ccda2db9d5e0f;hpb=abe43b546b084ff1071ea77e1736010427678ea5;p=oota-llvm.git diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index a43665bcd85..cb21be7b762 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -101,22 +101,35 @@ bool RecTy::baseClassOf(const RecTy *RHS) const{ } Init *BitRecTy::convertValue(BitsInit *BI) { - if (BI->getNumBits() != 1) return 0; // Only accept if just one bit! + if (BI->getNumBits() != 1) return nullptr; // Only accept if just one bit! return BI->getBit(0); } Init *BitRecTy::convertValue(IntInit *II) { int64_t Val = II->getValue(); - if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit! + if (Val != 0 && Val != 1) return nullptr; // Only accept 0 or 1 for a bit! return BitInit::get(Val != 0); } Init *BitRecTy::convertValue(TypedInit *VI) { RecTy *Ty = VI->getType(); - if (isa(Ty) || isa(Ty) || isa(Ty)) + if (isa(Ty)) return VI; // Accept variable if it is already of bit type! - return 0; + if (auto *BitsTy = dyn_cast(Ty)) + // Accept only bits<1> expression. + return BitsTy->getNumBits() == 1 ? VI : nullptr; + // Ternary !if can be converted to bit, but only if both sides are + // convertible to a bit. + if (TernOpInit *TOI = dyn_cast(VI)) { + if (TOI->getOpcode() != TernOpInit::TernaryOp::IF) + return nullptr; + if (!TOI->getMHS()->convertInitializerTo(BitRecTy::get()) || + !TOI->getRHS()->convertInitializerTo(BitRecTy::get())) + return nullptr; + return TOI; + } + return nullptr; } bool BitRecTy::baseClassOf(const RecTy *RHS) const{ @@ -151,7 +164,7 @@ Init *BitsRecTy::convertValue(UnsetInit *UI) { } Init *BitsRecTy::convertValue(BitInit *UI) { - if (Size != 1) return 0; // Can only convert single bit. + if (Size != 1) return nullptr; // Can only convert single bit. return BitsInit::get(UI); } @@ -170,7 +183,7 @@ Init *BitsRecTy::convertValue(IntInit *II) { int64_t Value = II->getValue(); // Make sure this bitfield is large enough to hold the integer value. if (!canFitInBitfield(Value, Size)) - return 0; + return nullptr; SmallVector NewBits(Size); @@ -184,7 +197,7 @@ Init *BitsRecTy::convertValue(BitsInit *BI) { // If the number of bits is right, return it. Otherwise we need to expand or // truncate. if (BI->getNumBits() == Size) return BI; - return 0; + return nullptr; } Init *BitsRecTy::convertValue(TypedInit *VI) { @@ -199,7 +212,7 @@ Init *BitsRecTy::convertValue(TypedInit *VI) { return BitsInit::get(NewBits); } - return 0; + return nullptr; } bool BitsRecTy::baseClassOf(const RecTy *RHS) const{ @@ -219,7 +232,7 @@ Init *IntRecTy::convertValue(BitsInit *BI) { if (BitInit *Bit = dyn_cast(BI->getBit(i))) { Result |= Bit->getValue() << i; } else { - return 0; + return nullptr; } return IntInit::get(Result); } @@ -227,7 +240,7 @@ Init *IntRecTy::convertValue(BitsInit *BI) { Init *IntRecTy::convertValue(TypedInit *TI) { if (TI->getType()->typeIsConvertibleTo(this)) return TI; // Accept variable if already of the right type! - return 0; + return nullptr; } bool IntRecTy::baseClassOf(const RecTy *RHS) const{ @@ -238,7 +251,7 @@ bool IntRecTy::baseClassOf(const RecTy *RHS) const{ Init *StringRecTy::convertValue(UnOpInit *BO) { if (BO->getOpcode() == UnOpInit::CAST) { Init *L = BO->getOperand()->convertInitializerTo(this); - if (L == 0) return 0; + if (!L) return nullptr; if (L != BO->getOperand()) return UnOpInit::get(UnOpInit::CAST, L, new StringRecTy); return BO; @@ -251,7 +264,7 @@ Init *StringRecTy::convertValue(BinOpInit *BO) { if (BO->getOpcode() == BinOpInit::STRCONCAT) { Init *L = BO->getLHS()->convertInitializerTo(this); Init *R = BO->getRHS()->convertInitializerTo(this); - if (L == 0 || R == 0) return 0; + if (!L || !R) return nullptr; if (L != BO->getLHS() || R != BO->getRHS()) return BinOpInit::get(BinOpInit::STRCONCAT, L, R, new StringRecTy); return BO; @@ -264,7 +277,7 @@ Init *StringRecTy::convertValue(BinOpInit *BO) { Init *StringRecTy::convertValue(TypedInit *TI) { if (isa(TI->getType())) return TI; // Accept variable if already of the right type! - return 0; + return nullptr; } std::string ListRecTy::getAsString() const { @@ -280,10 +293,10 @@ Init *ListRecTy::convertValue(ListInit *LI) { if (Init *CI = LI->getElement(i)->convertInitializerTo(Ty)) Elements.push_back(CI); else - return 0; + return nullptr; if (!isa(LI->getType())) - return 0; + return nullptr; return ListInit::get(Elements, this); } @@ -293,7 +306,7 @@ Init *ListRecTy::convertValue(TypedInit *TI) { if (ListRecTy *LRT = dyn_cast(TI->getType())) if (LRT->getElementType()->typeIsConvertibleTo(getElementType())) return TI; - return 0; + return nullptr; } bool ListRecTy::baseClassOf(const RecTy *RHS) const{ @@ -305,30 +318,30 @@ bool ListRecTy::baseClassOf(const RecTy *RHS) const{ Init *DagRecTy::convertValue(TypedInit *TI) { if (TI->getType()->typeIsConvertibleTo(this)) return TI; - return 0; + return nullptr; } Init *DagRecTy::convertValue(UnOpInit *BO) { if (BO->getOpcode() == UnOpInit::CAST) { Init *L = BO->getOperand()->convertInitializerTo(this); - if (L == 0) return 0; + if (!L) return nullptr; if (L != BO->getOperand()) return UnOpInit::get(UnOpInit::CAST, L, new DagRecTy); return BO; } - return 0; + return nullptr; } Init *DagRecTy::convertValue(BinOpInit *BO) { if (BO->getOpcode() == BinOpInit::CONCAT) { Init *L = BO->getLHS()->convertInitializerTo(this); Init *R = BO->getRHS()->convertInitializerTo(this); - if (L == 0 || R == 0) return 0; + if (!L || !R) return nullptr; if (L != BO->getLHS() || R != BO->getRHS()) return BinOpInit::get(BinOpInit::CONCAT, L, R, new DagRecTy); return BO; } - return 0; + return nullptr; } RecordRecTy *RecordRecTy::get(Record *R) { @@ -342,7 +355,7 @@ std::string RecordRecTy::getAsString() const { Init *RecordRecTy::convertValue(DefInit *DI) { // Ensure that DI is a subclass of Rec. if (!DI->getDef()->isSubClassOf(Rec)) - return 0; + return nullptr; return DI; } @@ -352,7 +365,7 @@ Init *RecordRecTy::convertValue(TypedInit *TI) { if (RRT->getRecord()->isSubClassOf(getRecord()) || RRT->getRecord() == getRecord()) return TI; - return 0; + return nullptr; } bool RecordRecTy::baseClassOf(const RecTy *RHS) const{ @@ -391,7 +404,7 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) { ++i) { RecordRecTy *SuperRecTy1 = RecordRecTy::get(*i); RecTy *NewType1 = resolveTypes(SuperRecTy1, T2); - if (NewType1 != 0) { + if (NewType1) { if (NewType1 != SuperRecTy1) { delete SuperRecTy1; } @@ -409,7 +422,7 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) { ++i) { RecordRecTy *SuperRecTy2 = RecordRecTy::get(*i); RecTy *NewType2 = resolveTypes(T1, SuperRecTy2); - if (NewType2 != 0) { + if (NewType2) { if (NewType2 != SuperRecTy2) { delete SuperRecTy2; } @@ -417,7 +430,7 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) { } } } - return 0; + return nullptr; } @@ -462,7 +475,7 @@ BitsInit *BitsInit::get(ArrayRef Range) { FoldingSetNodeID ID; ProfileBitsInit(ID, Range); - void *IP = 0; + void *IP = nullptr; if (BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP)) return I; @@ -482,7 +495,7 @@ BitsInit::convertInitializerBitRange(const std::vector &Bits) const { for (unsigned i = 0, e = Bits.size(); i != e; ++i) { if (Bits[i] >= getNumBits()) - return 0; + return nullptr; NewBits[i] = getBit(Bits[i]); } return BitsInit::get(NewBits); @@ -516,8 +529,8 @@ Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const { bool Changed = false; SmallVector NewBits(getNumBits()); - Init *CachedInit = 0; - Init *CachedBitVar = 0; + Init *CachedInit = nullptr; + Init *CachedBitVar = nullptr; bool CachedBitVarChanged = false; for (unsigned i = 0, e = getNumBits(); i != e; ++i) { @@ -590,7 +603,7 @@ IntInit::convertInitializerBitRange(const std::vector &Bits) const { for (unsigned i = 0, e = Bits.size(); i != e; ++i) { if (Bits[i] >= 64) - return 0; + return nullptr; NewBits[i] = BitInit::get(Value & (INT64_C(1) << Bits[i])); } @@ -623,18 +636,18 @@ static void ProfileListInit(FoldingSetNodeID &ID, ListInit *ListInit::get(ArrayRef Range, RecTy *EltTy) { typedef FoldingSet Pool; static Pool ThePool; + static std::vector> TheActualPool; - // Just use the FoldingSetNodeID to compute a hash. Use a DenseMap - // for actual storage. FoldingSetNodeID ID; ProfileListInit(ID, Range, EltTy); - void *IP = 0; + void *IP = nullptr; if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP)) return I; ListInit *I = new ListInit(Range, EltTy); ThePool.InsertNode(I, IP); + TheActualPool.push_back(std::unique_ptr(I)); return I; } @@ -651,7 +664,7 @@ ListInit::convertInitListSlice(const std::vector &Elements) const { std::vector Vals; for (unsigned i = 0, e = Elements.size(); i != e; ++i) { if (Elements[i] >= getSize()) - return 0; + return nullptr; Vals.push_back(getElement(Elements[i])); } return ListInit::get(Vals, getType()); @@ -660,7 +673,7 @@ ListInit::convertInitListSlice(const std::vector &Elements) const { Record *ListInit::getElementAsRecord(unsigned i) const { assert(i < Values.size() && "List element index out of range!"); DefInit *DI = dyn_cast(Values[i]); - if (DI == 0) + if (!DI) PrintFatalError("Expected record in list!"); return DI->getDef(); } @@ -690,14 +703,14 @@ Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) const { Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV, unsigned Elt) const { if (Elt >= getSize()) - return 0; // Out of range reference. + return nullptr; // Out of range reference. Init *E = getElement(Elt); // If the element is set to some value, or if we are resolving a reference // to a specific variable and that variable is explicitly unset, then // replace the VarListElementInit with it. if (IRV || !isa(E)) return E; - return 0; + return nullptr; } std::string ListInit::getAsString() const { @@ -714,7 +727,7 @@ Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV, Init *Resolved = resolveReferences(R, IRV); OpInit *OResolved = dyn_cast(Resolved); if (OResolved) { - Resolved = OResolved->Fold(&R, 0); + Resolved = OResolved->Fold(&R, nullptr); } if (Resolved != this) { @@ -728,7 +741,7 @@ Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV, } } - return 0; + return nullptr; } Init *OpInit::getBit(unsigned Bit) const { @@ -811,20 +824,14 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { } case HEAD: { if (ListInit *LHSl = dyn_cast(LHS)) { - if (LHSl->getSize() == 0) { - assert(0 && "Empty list in car"); - return 0; - } + assert(LHSl->getSize() != 0 && "Empty list in car"); return LHSl->getElement(0); } break; } case TAIL: { if (ListInit *LHSl = dyn_cast(LHS)) { - if (LHSl->getSize() == 0) { - assert(0 && "Empty list in cdr"); - return 0; - } + assert(LHSl->getSize() != 0 && "Empty list in cdr"); // Note the +1. We can't just pass the result of getValues() // directly. ArrayRef::iterator begin = LHSl->getValues().begin()+1; @@ -862,8 +869,8 @@ Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) const { Init *lhs = LHS->resolveReferences(R, RV); if (LHS != lhs) - return (UnOpInit::get(getOpcode(), lhs, getType()))->Fold(&R, 0); - return Fold(&R, 0); + return (UnOpInit::get(getOpcode(), lhs, getType()))->Fold(&R, nullptr); + return Fold(&R, nullptr); } std::string UnOpInit::getAsString() const { @@ -902,7 +909,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { if (LHSs && RHSs) { DefInit *LOp = dyn_cast(LHSs->getOperator()); DefInit *ROp = dyn_cast(RHSs->getOperator()); - if (LOp == 0 || ROp == 0 || LOp->getDef() != ROp->getDef()) + if (!LOp || !ROp || LOp->getDef() != ROp->getDef()) PrintFatalError("Concated Dag operators do not match!"); std::vector Args; std::vector ArgNames; @@ -918,6 +925,18 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { } break; } + case LISTCONCAT: { + ListInit *LHSs = dyn_cast(LHS); + ListInit *RHSs = dyn_cast(RHS); + if (LHSs && RHSs) { + std::vector Args; + Args.insert(Args.end(), LHSs->begin(), LHSs->end()); + Args.insert(Args.end(), RHSs->begin(), RHSs->end()); + return ListInit::get( + Args, static_cast(LHSs->getType())->getElementType()); + } + break; + } case STRCONCAT: { StringInit *LHSs = dyn_cast(LHS); StringInit *RHSs = dyn_cast(RHS); @@ -946,17 +965,21 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { break; } case ADD: + case AND: case SHL: case SRA: case SRL: { - IntInit *LHSi = dyn_cast(LHS); - IntInit *RHSi = dyn_cast(RHS); + IntInit *LHSi = + dyn_cast_or_null(LHS->convertInitializerTo(IntRecTy::get())); + IntInit *RHSi = + dyn_cast_or_null(RHS->convertInitializerTo(IntRecTy::get())); if (LHSi && RHSi) { int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue(); int64_t Result; switch (getOpcode()) { default: llvm_unreachable("Bad opcode!"); case ADD: Result = LHSv + RHSv; break; + case AND: Result = LHSv & RHSv; break; case SHL: Result = LHSv << RHSv; break; case SRA: Result = LHSv >> RHSv; break; case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break; @@ -974,8 +997,8 @@ Init *BinOpInit::resolveReferences(Record &R, const RecordVal *RV) const { Init *rhs = RHS->resolveReferences(R, RV); if (LHS != lhs || RHS != rhs) - return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0); - return Fold(&R, 0); + return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))->Fold(&R,nullptr); + return Fold(&R, nullptr); } std::string BinOpInit::getAsString() const { @@ -983,10 +1006,12 @@ std::string BinOpInit::getAsString() const { switch (Opc) { case CONCAT: Result = "!con"; break; case ADD: Result = "!add"; break; + case AND: Result = "!and"; break; case SHL: Result = "!shl"; break; case SRA: Result = "!sra"; break; case SRL: Result = "!srl"; break; case EQ: Result = "!eq"; break; + case LISTCONCAT: Result = "!listconcat"; break; case STRCONCAT: Result = "!strconcat"; break; } return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")"; @@ -1031,11 +1056,7 @@ static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg, if (TArg && TArg->getType()->getAsString() == "dag") { Init *Result = ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass); - if (Result != 0) { - return Result; - } else { - return 0; - } + return Result; } for (int i = 0; i < RHSo->getNumOperands(); ++i) { @@ -1044,7 +1065,7 @@ static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg, if (RHSoo) { Init *Result = EvaluateOperation(RHSoo, LHS, Arg, Type, CurRec, CurMultiClass); - if (Result != 0) { + if (Result) { NewOperands.push_back(Result); } else { NewOperands.push_back(Arg); @@ -1059,10 +1080,7 @@ static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg, // Now run the operator and use its result as the new leaf const OpInit *NewOp = RHSo->clone(NewOperands); Init *NewVal = NewOp->Fold(CurRec, CurMultiClass); - if (NewVal != NewOp) - return NewVal; - - return 0; + return (NewVal != NewOp) ? NewVal : nullptr; } static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, @@ -1086,7 +1104,7 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, Init *Val = MHSd->getOperator(); Init *Result = EvaluateOperation(RHSo, LHS, Val, Type, CurRec, CurMultiClass); - if (Result != 0) { + if (Result) { Val = Result; } @@ -1100,7 +1118,7 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, // Process args Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type, CurRec, CurMultiClass); - if (Result != 0) { + if (Result) { Arg = Result; } @@ -1138,7 +1156,7 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, return ListInit::get(NewList, MHSl->getType()); } } - return 0; + return nullptr; } Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { @@ -1195,7 +1213,7 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { case FOREACH: { Init *Result = ForeachHelper(LHS, MHS, RHS, getType(), CurRec, CurMultiClass); - if (Result != 0) { + if (Result) { return Result; } break; @@ -1227,16 +1245,16 @@ Init *TernOpInit::resolveReferences(Record &R, IntInit *Value = dyn_cast(lhs); if (Init *I = lhs->convertInitializerTo(IntRecTy::get())) Value = dyn_cast(I); - if (Value != 0) { + if (Value) { // Short-circuit if (Value->getValue()) { Init *mhs = MHS->resolveReferences(R, RV); return (TernOpInit::get(getOpcode(), lhs, mhs, - RHS, getType()))->Fold(&R, 0); + RHS, getType()))->Fold(&R, nullptr); } else { Init *rhs = RHS->resolveReferences(R, RV); return (TernOpInit::get(getOpcode(), lhs, MHS, - rhs, getType()))->Fold(&R, 0); + rhs, getType()))->Fold(&R, nullptr); } } } @@ -1246,8 +1264,8 @@ Init *TernOpInit::resolveReferences(Record &R, if (LHS != lhs || MHS != mhs || RHS != rhs) return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, - getType()))->Fold(&R, 0); - return Fold(&R, 0); + getType()))->Fold(&R, nullptr); + return Fold(&R, nullptr); } std::string TernOpInit::getAsString() const { @@ -1265,19 +1283,19 @@ RecTy *TypedInit::getFieldType(const std::string &FieldName) const { if (RecordRecTy *RecordType = dyn_cast(getType())) if (RecordVal *Field = RecordType->getRecord()->getValue(FieldName)) return Field->getType(); - return 0; + return nullptr; } Init * TypedInit::convertInitializerBitRange(const std::vector &Bits) const { BitsRecTy *T = dyn_cast(getType()); - if (T == 0) return 0; // Cannot subscript a non-bits variable. + if (!T) return nullptr; // Cannot subscript a non-bits variable. unsigned NumBits = T->getNumBits(); SmallVector NewBits(Bits.size()); for (unsigned i = 0, e = Bits.size(); i != e; ++i) { if (Bits[i] >= NumBits) - return 0; + return nullptr; NewBits[i] = VarBitInit::get(const_cast(this), Bits[i]); } @@ -1287,7 +1305,7 @@ TypedInit::convertInitializerBitRange(const std::vector &Bits) const { Init * TypedInit::convertInitListSlice(const std::vector &Elements) const { ListRecTy *T = dyn_cast(getType()); - if (T == 0) return 0; // Cannot subscript a non-list variable. + if (!T) return nullptr; // Cannot subscript a non-list variable. if (Elements.size() == 1) return VarListElementInit::get(const_cast(this), Elements[0]); @@ -1332,8 +1350,8 @@ Init *VarInit::getBit(unsigned Bit) const { Init *VarInit::resolveListElementReference(Record &R, const RecordVal *IRV, unsigned Elt) const { - if (R.isTemplateArg(getNameInit())) return 0; - if (IRV && IRV->getNameInit() != getNameInit()) return 0; + if (R.isTemplateArg(getNameInit())) return nullptr; + if (IRV && IRV->getNameInit() != getNameInit()) return nullptr; RecordVal *RV = R.getValue(getNameInit()); assert(RV && "Reference to a non-existent variable?"); @@ -1345,14 +1363,14 @@ Init *VarInit::resolveListElementReference(Record &R, } if (Elt >= LI->getSize()) - return 0; // Out of range reference. + return nullptr; // Out of range reference. Init *E = LI->getElement(Elt); // If the element is set to some value, or if we are resolving a reference // to a specific variable and that variable is explicitly unset, then // replace the VarListElementInit with it. if (IRV || !isa(E)) return E; - return 0; + return nullptr; } @@ -1360,7 +1378,7 @@ RecTy *VarInit::getFieldType(const std::string &FieldName) const { if (RecordRecTy *RTy = dyn_cast(getType())) if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName)) return RV->getType(); - return 0; + return nullptr; } Init *VarInit::getFieldInit(Record &R, const RecordVal *RV, @@ -1368,15 +1386,15 @@ Init *VarInit::getFieldInit(Record &R, const RecordVal *RV, if (isa(getType())) if (const RecordVal *Val = R.getValue(VarName)) { if (RV != Val && (RV || isa(Val->getValue()))) - return 0; + return nullptr; Init *TheInit = Val->getValue(); assert(TheInit != this && "Infinite loop detected!"); if (Init *I = TheInit->getFieldInit(R, RV, FieldName)) return I; else - return 0; + return nullptr; } - return 0; + return nullptr; } /// resolveReferences - This method is used by classes that refer to other @@ -1386,7 +1404,7 @@ Init *VarInit::getFieldInit(Record &R, const RecordVal *RV, /// Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) const { if (RecordVal *Val = R.getValue(VarName)) - if (RV == Val || (RV == 0 && !isa(Val->getValue()))) + if (RV == Val || (!RV && !isa(Val->getValue()))) return Val->getValue(); return const_cast(this); } @@ -1462,7 +1480,7 @@ Init *VarListElementInit:: resolveListElementReference(Record &R, return Result; } - return 0; + return nullptr; } DefInit *DefInit::get(Record *R) { @@ -1472,7 +1490,7 @@ DefInit *DefInit::get(Record *R) { RecTy *DefInit::getFieldType(const std::string &FieldName) const { if (const RecordVal *RV = Def->getValue(FieldName)) return RV->getType(); - return 0; + return nullptr; } Init *DefInit::getFieldInit(Record &R, const RecordVal *RV, @@ -1507,7 +1525,7 @@ Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) const { if (Init *ListVal = Rec->getFieldInit(R, RV, FieldName)) if (ListInit *LI = dyn_cast(ListVal)) { - if (Elt >= LI->getSize()) return 0; + if (Elt >= LI->getSize()) return nullptr; Init *E = LI->getElement(Elt); // If the element is set to some value, or if we are resolving a @@ -1516,7 +1534,7 @@ Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV, if (RV || !isa(E)) return E; } - return 0; + return nullptr; } Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const { @@ -1560,7 +1578,7 @@ DagInit::get(Init *V, const std::string &VN, FoldingSetNodeID ID; ProfileDagInit(ID, V, VN, ArgRange, NameRange); - void *IP = 0; + void *IP = nullptr; if (DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP)) return I; @@ -1784,7 +1802,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) { /// Init *Record::getValueInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); return R->getValue(); @@ -1797,7 +1815,7 @@ Init *Record::getValueInit(StringRef FieldName) const { /// std::string Record::getValueAsString(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); @@ -1813,7 +1831,7 @@ std::string Record::getValueAsString(StringRef FieldName) const { /// BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); @@ -1829,7 +1847,7 @@ BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const { /// ListInit *Record::getValueAsListInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); @@ -1864,7 +1882,7 @@ Record::getValueAsListOfDefs(StringRef FieldName) const { /// int64_t Record::getValueAsInt(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); @@ -1918,7 +1936,7 @@ Record::getValueAsListOfStrings(StringRef FieldName) const { /// Record *Record::getValueAsDef(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); @@ -1934,7 +1952,7 @@ Record *Record::getValueAsDef(StringRef FieldName) const { /// bool Record::getValueAsBit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n"); @@ -1946,7 +1964,7 @@ bool Record::getValueAsBit(StringRef FieldName) const { bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName.str() + "'!\n"); @@ -1967,7 +1985,7 @@ bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const { /// DagInit *Record::getValueAsDag(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); - if (R == 0 || R->getValue() == 0) + if (!R || !R->getValue()) PrintFatalError(getLoc(), "Record `" + getName() + "' does not have a field named `" + FieldName + "'!\n");