diff options
Diffstat (limited to 'lib/TableGen/Record.cpp')
-rw-r--r-- | lib/TableGen/Record.cpp | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 0f40904ae919..3a2ae96340c3 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -114,8 +114,21 @@ Init *BitRecTy::convertValue(IntInit *II) { Init *BitRecTy::convertValue(TypedInit *VI) { RecTy *Ty = VI->getType(); - if (isa<BitRecTy>(Ty) || isa<BitsRecTy>(Ty) || isa<IntRecTy>(Ty)) + if (isa<BitRecTy>(Ty)) return VI; // Accept variable if it is already of bit type! + if (auto *BitsTy = dyn_cast<BitsRecTy>(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<TernOpInit>(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; } @@ -799,7 +812,7 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { return VarInit::get(MCName, RV->getType()); } } - + assert(CurRec && "NULL pointer"); if (Record *D = (CurRec->getRecords()).getDef(Name)) return DefInit::get(D); @@ -952,6 +965,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { break; } case ADD: + case AND: case SHL: case SRA: case SRL: { @@ -965,6 +979,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { 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; @@ -991,6 +1006,7 @@ 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; @@ -1692,13 +1708,6 @@ const std::string &Record::getName() const { } void Record::setName(Init *NewName) { - if (TrackedRecords.getDef(Name->getAsUnquotedString()) == this) { - TrackedRecords.removeDef(Name->getAsUnquotedString()); - TrackedRecords.addDef(this); - } else if (TrackedRecords.getClass(Name->getAsUnquotedString()) == this) { - TrackedRecords.removeClass(Name->getAsUnquotedString()); - TrackedRecords.addClass(this); - } // Otherwise this isn't yet registered. Name = NewName; checkName(); // DO NOT resolve record values to the name at this point because @@ -1998,16 +2007,14 @@ void RecordKeeper::dump() const { errs() << *this; } raw_ostream &llvm::operator<<(raw_ostream &OS, const RecordKeeper &RK) { OS << "------------- Classes -----------------\n"; - const std::map<std::string, Record*> &Classes = RK.getClasses(); - for (std::map<std::string, Record*>::const_iterator I = Classes.begin(), - E = Classes.end(); I != E; ++I) - OS << "class " << *I->second; + const auto &Classes = RK.getClasses(); + for (const auto &C : Classes) + OS << "class " << *C.second; OS << "------------- Defs -----------------\n"; - const std::map<std::string, Record*> &Defs = RK.getDefs(); - for (std::map<std::string, Record*>::const_iterator I = Defs.begin(), - E = Defs.end(); I != E; ++I) - OS << "def " << *I->second; + const auto &Defs = RK.getDefs(); + for (const auto &D : Defs) + OS << "def " << *D.second; return OS; } @@ -2022,10 +2029,9 @@ RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const { PrintFatalError("ERROR: Couldn't find the `" + ClassName + "' class!\n"); std::vector<Record*> Defs; - for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(), - E = getDefs().end(); I != E; ++I) - if (I->second->isSubClassOf(Class)) - Defs.push_back(I->second); + for (const auto &D : getDefs()) + if (D.second->isSubClassOf(Class)) + Defs.push_back(D.second.get()); return Defs; } |