X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTableGen%2FRecord.cpp;h=cb21be7b7627ae17100ec3ae432c497bd711e3ac;hb=7ce4ac12fc5b0522c5adae6abdd0d8bb552f6ef1;hp=9b65adcf85e5ee70ef05566a11f22a9e2904d1be;hpb=d04a8d4b33ff316ca4cf961e06c9e312eff8e64f;p=oota-llvm.git diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 9b65adcf85e..cb21be7b762 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -95,27 +95,49 @@ ListRecTy *RecTy::getListTy() { return ListTy; } -Init *BitRecTy::convertValue(BitsInit *BI) { - if (BI->getNumBits() != 1) return 0; // Only accept if just one bit! - return BI->getBit(0); +bool RecTy::baseClassOf(const RecTy *RHS) const{ + assert (RHS && "NULL pointer"); + return Kind == RHS->getRecTyKind(); } -bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const { - return RHS->getNumBits() == 1; +Init *BitRecTy::convertValue(BitsInit *BI) { + 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{ + if(RecTy::baseClassOf(RHS) || getRecTyKind() == IntRecTyKind) + return true; + if(const BitsRecTy *BitsTy = dyn_cast(RHS)) + return BitsTy->getNumBits() == 1; + return false; } BitsRecTy *BitsRecTy::get(unsigned Sz) { @@ -142,8 +164,8 @@ Init *BitsRecTy::convertValue(UnsetInit *UI) { } Init *BitsRecTy::convertValue(BitInit *UI) { - if (Size != 1) return 0; // Can only convert single bit. - return BitsInit::get(UI); + if (Size != 1) return nullptr; // Can only convert single bit. + return BitsInit::get(UI); } /// canFitInBitfield - Return true if the number of bits is large enough to hold @@ -161,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); @@ -175,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) { @@ -190,7 +212,14 @@ Init *BitsRecTy::convertValue(TypedInit *VI) { return BitsInit::get(NewBits); } - return 0; + return nullptr; +} + +bool BitsRecTy::baseClassOf(const RecTy *RHS) const{ + if (RecTy::baseClassOf(RHS)) //argument and the receiver are the same type + return cast(RHS)->Size == Size; + RecTyKind kind = RHS->getRecTyKind(); + return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind); } Init *IntRecTy::convertValue(BitInit *BI) { @@ -203,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); } @@ -211,13 +240,18 @@ 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{ + RecTyKind kind = RHS->getRecTyKind(); + return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind; } 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; @@ -230,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; @@ -243,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 { @@ -259,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); } @@ -272,36 +306,42 @@ 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{ + if(const ListRecTy* ListTy = dyn_cast(RHS)) + return ListTy->getElementType()->typeIsConvertibleTo(Ty); + return false; } 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) { @@ -315,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; } @@ -325,16 +365,20 @@ Init *RecordRecTy::convertValue(TypedInit *TI) { if (RRT->getRecord()->isSubClassOf(getRecord()) || RRT->getRecord() == getRecord()) return TI; - return 0; + return nullptr; } -bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const { - if (Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec)) +bool RecordRecTy::baseClassOf(const RecTy *RHS) const{ + const RecordRecTy *RTy = dyn_cast(RHS); + if (!RTy) + return false; + + if (Rec == RTy->getRecord() || RTy->getRecord()->isSubClassOf(Rec)) return true; const std::vector &SC = Rec->getSuperClasses(); for (unsigned i = 0, e = SC.size(); i != e; ++i) - if (RHS->getRecord()->isSubClassOf(SC[i])) + if (RTy->getRecord()->isSubClassOf(SC[i])) return true; return false; @@ -360,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; } @@ -378,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; } @@ -386,7 +430,7 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) { } } } - return 0; + return nullptr; } @@ -431,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; @@ -451,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); @@ -485,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) { @@ -526,9 +570,23 @@ Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const { return const_cast(this); } +namespace { + template + class Pool : public T { + public: + ~Pool(); + }; + template + Pool::~Pool() { + for (typename T::iterator I = this->begin(), E = this->end(); I != E; ++I) { + typename T::value_type &Item = *I; + delete Item.second; + } + } +} + IntInit *IntInit::get(int64_t V) { - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; IntInit *&I = ThePool[V]; if (!I) I = new IntInit(V); @@ -545,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])); } @@ -555,8 +613,7 @@ IntInit::convertInitializerBitRange(const std::vector &Bits) const { void StringInit::anchor() { } StringInit *StringInit::get(StringRef V) { - typedef StringMap Pool; - static Pool ThePool; + static Pool > ThePool; StringInit *&I = ThePool[V]; if (!I) I = new StringInit(V); @@ -579,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; } @@ -607,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()); @@ -616,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(); } @@ -646,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 { @@ -670,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) { @@ -684,7 +741,7 @@ Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV, } } - return 0; + return nullptr; } Init *OpInit::getBit(unsigned Bit) const { @@ -695,9 +752,7 @@ Init *OpInit::getBit(unsigned Bit) const { UnOpInit *UnOpInit::get(UnaryOp opc, Init *lhs, RecTy *Type) { typedef std::pair, RecTy *> Key; - - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; Key TheKey(std::make_pair(std::make_pair(opc, lhs), Type)); @@ -769,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; @@ -820,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 { @@ -842,8 +891,7 @@ BinOpInit *BinOpInit::get(BinaryOp opc, Init *lhs, RecTy * > Key; - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; Key TheKey(std::make_pair(std::make_pair(std::make_pair(opc, lhs), rhs), Type)); @@ -861,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; @@ -877,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); @@ -904,16 +964,22 @@ 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; @@ -931,18 +997,21 @@ 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 { std::string Result; 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() + ")"; @@ -987,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) { @@ -1000,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); @@ -1015,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, @@ -1042,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; } @@ -1056,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; } @@ -1094,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 { @@ -1151,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; @@ -1183,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); } } } @@ -1202,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 { @@ -1221,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]); } @@ -1243,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]); @@ -1264,8 +1326,7 @@ VarInit *VarInit::get(const std::string &VN, RecTy *T) { VarInit *VarInit::get(Init *VN, RecTy *T) { typedef std::pair Key; - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; Key TheKey(std::make_pair(T, VN)); @@ -1289,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?"); @@ -1302,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; } @@ -1317,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, @@ -1325,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 @@ -1343,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); } @@ -1419,7 +1480,7 @@ Init *VarListElementInit:: resolveListElementReference(Record &R, return Result; } - return 0; + return nullptr; } DefInit *DefInit::get(Record *R) { @@ -1429,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, @@ -1464,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 @@ -1473,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 { @@ -1491,11 +1552,9 @@ Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const { return const_cast(this); } -void ProfileDagInit(FoldingSetNodeID &ID, - Init *V, - const std::string &VN, - ArrayRef ArgRange, - ArrayRef NameRange) { +static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, const std::string &VN, + ArrayRef ArgRange, + ArrayRef NameRange) { ID.AddPointer(V); ID.AddString(VN); @@ -1519,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; @@ -1743,9 +1802,9 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); return R->getValue(); } @@ -1756,14 +1815,14 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (StringInit *SI = dyn_cast(R->getValue())) return SI->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a string initializer!"); + FieldName + "' does not have a string initializer!"); } /// getValueAsBitsInit - This method looks up the specified field and returns @@ -1772,14 +1831,14 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (BitsInit *BI = dyn_cast(R->getValue())) return BI; PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a BitsInit initializer!"); + FieldName + "' does not have a BitsInit initializer!"); } /// getValueAsListInit - This method looks up the specified field and returns @@ -1788,14 +1847,14 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (ListInit *LI = dyn_cast(R->getValue())) return LI; PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a list initializer!"); + FieldName + "' does not have a list initializer!"); } /// getValueAsListOfDefs - This method looks up the specified field and returns @@ -1811,7 +1870,7 @@ Record::getValueAsListOfDefs(StringRef FieldName) const { Defs.push_back(DI->getDef()); } else { PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' list is not entirely DefInit!"); + FieldName + "' list is not entirely DefInit!"); } } return Defs; @@ -1823,14 +1882,14 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (IntInit *II = dyn_cast(R->getValue())) return II->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have an int initializer!"); + FieldName + "' does not have an int initializer!"); } /// getValueAsListOfInts - This method looks up the specified field and returns @@ -1846,7 +1905,7 @@ Record::getValueAsListOfInts(StringRef FieldName) const { Ints.push_back(II->getValue()); } else { PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a list of ints initializer!"); + FieldName + "' does not have a list of ints initializer!"); } } return Ints; @@ -1865,7 +1924,7 @@ Record::getValueAsListOfStrings(StringRef FieldName) const { Strings.push_back(II->getValue()); } else { PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a list of strings initializer!"); + FieldName + "' does not have a list of strings initializer!"); } } return Strings; @@ -1877,14 +1936,14 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (DefInit *DI = dyn_cast(R->getValue())) return DI->getDef(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a def initializer!"); + FieldName + "' does not have a def initializer!"); } /// getValueAsBit - This method looks up the specified field and returns its @@ -1893,19 +1952,19 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (BitInit *BI = dyn_cast(R->getValue())) return BI->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a bit initializer!"); + FieldName + "' does not have a bit initializer!"); } 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"); @@ -1917,7 +1976,7 @@ bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const { if (BitInit *BI = dyn_cast(R->getValue())) return BI->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a bit initializer!"); + FieldName + "' does not have a bit initializer!"); } /// getValueAsDag - This method looks up the specified field and returns its @@ -1926,14 +1985,14 @@ 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.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (DagInit *DI = dyn_cast(R->getValue())) return DI; PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a dag initializer!"); + FieldName + "' does not have a dag initializer!"); }