diff options
author | Stephen Hines <srhines@google.com> | 2015-03-23 12:10:34 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2015-03-23 12:10:34 -0700 |
commit | ebe69fe11e48d322045d5949c83283927a0d790b (patch) | |
tree | c92f1907a6b8006628a4b01615f38264d29834ea /lib/TableGen | |
parent | b7d2e72b02a4cb8034f32f8247a2558d2434e121 (diff) | |
download | external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.zip external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.gz external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.bz2 |
Update aosp/master LLVM for rebase to r230699.
Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9
Diffstat (limited to 'lib/TableGen')
-rw-r--r-- | lib/TableGen/CMakeLists.txt | 3 | ||||
-rw-r--r-- | lib/TableGen/Main.cpp | 7 | ||||
-rw-r--r-- | lib/TableGen/Record.cpp | 4 | ||||
-rw-r--r-- | lib/TableGen/TGParser.cpp | 180 | ||||
-rw-r--r-- | lib/TableGen/TGParser.h | 2 |
5 files changed, 86 insertions, 110 deletions
diff --git a/lib/TableGen/CMakeLists.txt b/lib/TableGen/CMakeLists.txt index fb70218..9333b65 100644 --- a/lib/TableGen/CMakeLists.txt +++ b/lib/TableGen/CMakeLists.txt @@ -7,4 +7,7 @@ add_llvm_library(LLVMTableGen TableGenBackend.cpp TGLexer.cpp TGParser.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/TableGen ) diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index 2578cc2..c440451 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -64,11 +64,8 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) { return 1; } DepOut.os() << OutputFilename << ":"; - const TGLexer::DependenciesMapTy &Dependencies = Parser.getDependencies(); - for (TGLexer::DependenciesMapTy::const_iterator I = Dependencies.begin(), - E = Dependencies.end(); - I != E; ++I) { - DepOut.os() << " " << I->first; + for (const auto &Dep : Parser.getDependencies()) { + DepOut.os() << ' ' << Dep.first; } DepOut.os() << "\n"; DepOut.keep(); diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 34e3ab4..4ae9903 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -812,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); @@ -1629,7 +1629,7 @@ std::string DagInit::getAsString() const { std::string Result = "(" + Val->getAsString(); if (!ValName.empty()) Result += ":" + ValName; - if (Args.size()) { + if (!Args.empty()) { Result += " " + Args[0]->getAsString(); if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0]; for (unsigned i = 1, e = Args.size(); i != e; ++i) { diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index 4d4bbe9..44f6a6e 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -224,7 +224,7 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC, if (AddValue(CurRec, SubMultiClass.RefRange.Start, SMCVals[i])) return true; - int newDefStart = CurMC->DefPrototypes.size(); + unsigned newDefStart = CurMC->DefPrototypes.size(); // Add all of the defs in the subclass into the current multiclass. for (MultiClass::RecordVector::const_iterator i = SMC->DefPrototypes.begin(), @@ -239,7 +239,7 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC, if (AddValue(NewDef.get(), SubMultiClass.RefRange.Start, MCVals[i])) return true; - CurMC->DefPrototypes.push_back(NewDef.release()); + CurMC->DefPrototypes.push_back(std::move(NewDef)); } const std::vector<Init *> &SMCTArgs = SMC->Rec.getTemplateArgs(); @@ -269,14 +269,9 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC, // If a value is specified for this template arg, set it in the // new defs now. - for (MultiClass::RecordVector::iterator j = - CurMC->DefPrototypes.begin() + newDefStart, - jend = CurMC->DefPrototypes.end(); - j != jend; - ++j) { - Record *Def = *j; - - if (SetValue(Def, SubMultiClass.RefRange.Start, SMCTArgs[i], + for (const auto &Def : + makeArrayRef(CurMC->DefPrototypes).slice(newDefStart)) { + if (SetValue(Def.get(), SubMultiClass.RefRange.Start, SMCTArgs[i], std::vector<unsigned>(), SubMultiClass.TemplateArgs[i])) return true; @@ -340,26 +335,20 @@ bool TGParser::ProcessForeachDefs(Record *CurRec, SMLoc Loc, IterSet &IterVals){ // This is the bottom of the recursion. We have all of the iterator values // for this point in the iteration space. Instantiate a new record to // reflect this combination of values. - Record *IterRec = new Record(*CurRec); + auto IterRec = make_unique<Record>(*CurRec); // Set the iterator values now. for (unsigned i = 0, e = IterVals.size(); i != e; ++i) { VarInit *IterVar = IterVals[i].IterVar; TypedInit *IVal = dyn_cast<TypedInit>(IterVals[i].IterValue); - if (!IVal) { - Error(Loc, "foreach iterator value is untyped"); - delete IterRec; - return true; - } + if (!IVal) + return Error(Loc, "foreach iterator value is untyped"); IterRec->addValue(RecordVal(IterVar->getName(), IVal->getType(), false)); - if (SetValue(IterRec, Loc, IterVar->getName(), - std::vector<unsigned>(), IVal)) { - Error(Loc, "when instantiating this def"); - delete IterRec; - return true; - } + if (SetValue(IterRec.get(), Loc, IterVar->getName(), + std::vector<unsigned>(), IVal)) + return Error(Loc, "when instantiating this def"); // Resolve it next. IterRec->resolveReferencesTo(IterRec->getValue(IterVar->getName())); @@ -370,17 +359,15 @@ bool TGParser::ProcessForeachDefs(Record *CurRec, SMLoc Loc, IterSet &IterVals){ if (Records.getDef(IterRec->getNameInitAsString())) { // If this record is anonymous, it's no problem, just generate a new name - if (IterRec->isAnonymous()) - IterRec->setName(GetNewAnonymousName()); - else { - Error(Loc, "def already exists: " + IterRec->getNameInitAsString()); - delete IterRec; - return true; - } + if (!IterRec->isAnonymous()) + return Error(Loc, "def already exists: " +IterRec->getNameInitAsString()); + + IterRec->setName(GetNewAnonymousName()); } - Records.addDef(IterRec); - IterRec->resolveReferences(); + Record *IterRecSave = IterRec.get(); // Keep a copy before release. + Records.addDef(std::move(IterRec)); + IterRecSave->resolveReferences(); return false; } @@ -398,8 +385,7 @@ static bool isObjectStart(tgtok::TokKind K) { /// GetNewAnonymousName - Generate a unique anonymous name that can be used as /// an identifier. std::string TGParser::GetNewAnonymousName() { - unsigned Tmp = AnonCounter++; // MSVC2012 ICEs without this. - return "anonymous_" + utostr(Tmp); + return "anonymous_" + utostr(AnonCounter++); } /// ParseObjectName - If an object name is specified, return it. Otherwise, @@ -467,7 +453,7 @@ MultiClass *TGParser::ParseMultiClassID() { return nullptr; } - MultiClass *Result = MultiClasses[Lex.getCurStrVal()]; + MultiClass *Result = MultiClasses[Lex.getCurStrVal()].get(); if (!Result) TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'"); @@ -1247,26 +1233,26 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, SMLoc EndLoc = Lex.getLoc(); // Create the new record, set it as CurRec temporarily. - Record *NewRec = new Record(GetNewAnonymousName(), NameLoc, Records, - /*IsAnonymous=*/true); + auto NewRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), NameLoc, + Records, /*IsAnonymous=*/true); + Record *NewRec = NewRecOwner.get(); // Keep a copy since we may release. SubClassReference SCRef; SCRef.RefRange = SMRange(NameLoc, EndLoc); SCRef.Rec = Class; SCRef.TemplateArgs = ValueList; // Add info about the subclass to NewRec. - if (AddSubClass(NewRec, SCRef)) { - delete NewRec; + if (AddSubClass(NewRec, SCRef)) return nullptr; - } + if (!CurMultiClass) { NewRec->resolveReferences(); - Records.addDef(NewRec); + Records.addDef(std::move(NewRecOwner)); } else { // This needs to get resolved once the multiclass template arguments are // known before any use. NewRec->setResolveFirst(true); // Otherwise, we're inside a multiclass, add it to the multiclass. - CurMultiClass->DefPrototypes.push_back(NewRec); + CurMultiClass->DefPrototypes.push_back(std::move(NewRecOwner)); // Copy the template arguments for the multiclass into the def. const std::vector<Init *> &TArgs = @@ -1689,7 +1675,7 @@ std::vector<Init*> TGParser::ParseValueList(Record *CurRec, Record *ArgsRec, unsigned int ArgN = 0; if (ArgsRec && !EltTy) { const std::vector<Init *> &TArgs = ArgsRec->getTemplateArgs(); - if (!TArgs.size()) { + if (TArgs.empty()) { TokError("template argument provided to non-template class"); return std::vector<Init*>(); } @@ -2036,27 +2022,23 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) { Lex.Lex(); // Eat the 'def' token. // Parse ObjectName and make a record for it. - Record *CurRec; - bool CurRecOwnershipTransferred = false; + std::unique_ptr<Record> CurRecOwner; Init *Name = ParseObjectName(CurMultiClass); if (Name) - CurRec = new Record(Name, DefLoc, Records); + CurRecOwner = make_unique<Record>(Name, DefLoc, Records); else - CurRec = new Record(GetNewAnonymousName(), DefLoc, Records, - /*IsAnonymous=*/true); + CurRecOwner = llvm::make_unique<Record>(GetNewAnonymousName(), DefLoc, + Records, /*IsAnonymous=*/true); + Record *CurRec = CurRecOwner.get(); // Keep a copy since we may release. if (!CurMultiClass && Loops.empty()) { // Top-level def definition. // Ensure redefinition doesn't happen. - if (Records.getDef(CurRec->getNameInitAsString())) { - Error(DefLoc, "def '" + CurRec->getNameInitAsString() - + "' already defined"); - delete CurRec; - return true; - } - Records.addDef(CurRec); - CurRecOwnershipTransferred = true; + if (Records.getDef(CurRec->getNameInitAsString())) + return Error(DefLoc, "def '" + CurRec->getNameInitAsString()+ + "' already defined"); + Records.addDef(std::move(CurRecOwner)); if (ParseObjectBody(CurRec)) return true; @@ -2066,24 +2048,17 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) { // before this object, instantiated prior to defs derived from this object, // and this available for indirect name resolution when defs derived from // this object are instantiated. - if (ParseObjectBody(CurRec)) { - delete CurRec; + if (ParseObjectBody(CurRec)) return true; - } // Otherwise, a def inside a multiclass, add it to the multiclass. for (unsigned i = 0, e = CurMultiClass->DefPrototypes.size(); i != e; ++i) if (CurMultiClass->DefPrototypes[i]->getNameInit() - == CurRec->getNameInit()) { - Error(DefLoc, "def '" + CurRec->getNameInitAsString() + - "' already defined in this multiclass!"); - delete CurRec; - return true; - } - CurMultiClass->DefPrototypes.push_back(CurRec); - CurRecOwnershipTransferred = true; + == CurRec->getNameInit()) + return Error(DefLoc, "def '" + CurRec->getNameInitAsString() + + "' already defined in this multiclass!"); + CurMultiClass->DefPrototypes.push_back(std::move(CurRecOwner)); } else if (ParseObjectBody(CurRec)) { - delete CurRec; return true; } @@ -2109,15 +2084,10 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) { } if (ProcessForeachDefs(CurRec, DefLoc)) { - Error(DefLoc, - "Could not process loops for def" + CurRec->getNameInitAsString()); - if (!CurRecOwnershipTransferred) - delete CurRec; - return true; + return Error(DefLoc, "Could not process loops for def" + + CurRec->getNameInitAsString()); } - if (!CurRecOwnershipTransferred) - delete CurRec; return false; } @@ -2193,8 +2163,10 @@ bool TGParser::ParseClass() { + "' already defined"); } else { // If this is the first reference to this class, create and add it. - CurRec = new Record(Lex.getCurStrVal(), Lex.getLoc(), Records); - Records.addClass(CurRec); + auto NewRec = + llvm::make_unique<Record>(Lex.getCurStrVal(), Lex.getLoc(), Records); + CurRec = NewRec.get(); + Records.addClass(std::move(NewRec)); } Lex.Lex(); // eat the name. @@ -2312,11 +2284,14 @@ bool TGParser::ParseMultiClass() { return TokError("expected identifier after multiclass for name"); std::string Name = Lex.getCurStrVal(); - if (MultiClasses.count(Name)) + auto Result = + MultiClasses.insert(std::make_pair(Name, + llvm::make_unique<MultiClass>(Name, Lex.getLoc(),Records))); + + if (!Result.second) return TokError("multiclass '" + Name + "' already defined"); - CurMultiClass = MultiClasses[Name] = new MultiClass(Name, - Lex.getLoc(), Records); + CurMultiClass = Result.first->second.get(); Lex.Lex(); // Eat the identifier. // If there are template args, parse them. @@ -2352,25 +2327,24 @@ bool TGParser::ParseMultiClass() { if (Lex.getCode() != tgtok::l_brace) { if (!inherits) return TokError("expected '{' in multiclass definition"); - else if (Lex.getCode() != tgtok::semi) + if (Lex.getCode() != tgtok::semi) return TokError("expected ';' in multiclass definition"); - else - Lex.Lex(); // eat the ';'. + Lex.Lex(); // eat the ';'. } else { if (Lex.Lex() == tgtok::r_brace) // eat the '{'. return TokError("multiclass must contain at least one def"); while (Lex.getCode() != tgtok::r_brace) { switch (Lex.getCode()) { - default: - return TokError("expected 'let', 'def' or 'defm' in multiclass body"); - case tgtok::Let: - case tgtok::Def: - case tgtok::Defm: - case tgtok::Foreach: - if (ParseObject(CurMultiClass)) - return true; - break; + default: + return TokError("expected 'let', 'def' or 'defm' in multiclass body"); + case tgtok::Let: + case tgtok::Def: + case tgtok::Defm: + case tgtok::Foreach: + if (ParseObject(CurMultiClass)) + return true; + break; } } Lex.Lex(); // eat the '}'. @@ -2416,22 +2390,21 @@ InstantiateMulticlassDef(MultiClass &MC, // Make a trail of SMLocs from the multiclass instantiations. SmallVector<SMLoc, 4> Locs(1, DefmPrefixRange.Start); Locs.append(DefProto->getLoc().begin(), DefProto->getLoc().end()); - Record *CurRec = new Record(DefName, Locs, Records, IsAnonymous); + auto CurRec = make_unique<Record>(DefName, Locs, Records, IsAnonymous); SubClassReference Ref; Ref.RefRange = DefmPrefixRange; Ref.Rec = DefProto; - AddSubClass(CurRec, Ref); + AddSubClass(CurRec.get(), Ref); // Set the value for NAME. We don't resolve references to it 'til later, // though, so that uses in nested multiclass names don't get // confused. - if (SetValue(CurRec, Ref.RefRange.Start, "NAME", std::vector<unsigned>(), - DefmPrefix)) { + if (SetValue(CurRec.get(), Ref.RefRange.Start, "NAME", + std::vector<unsigned>(), DefmPrefix)) { Error(DefmPrefixRange.Start, "Could not resolve " + CurRec->getNameInitAsString() + ":NAME to '" + DefmPrefix->getAsUnquotedString() + "'"); - delete CurRec; return nullptr; } @@ -2463,14 +2436,17 @@ InstantiateMulticlassDef(MultiClass &MC, Error(DefmPrefixRange.Start, "def '" + CurRec->getNameInitAsString() + "' already defined, instantiating defm with subdef '" + DefProto->getNameInitAsString() + "'"); - delete CurRec; return nullptr; } - Records.addDef(CurRec); + Record *CurRecSave = CurRec.get(); // Keep a copy before we release. + Records.addDef(std::move(CurRec)); + return CurRecSave; } - return CurRec; + // FIXME This is bad but the ownership transfer to caller is pretty messy. + // The unique_ptr in this function at least protects the exits above. + return CurRec.release(); } bool TGParser::ResolveMulticlassDefArgs(MultiClass &MC, @@ -2526,7 +2502,7 @@ bool TGParser::ResolveMulticlassDef(MultiClass &MC, == CurRec->getNameInit()) return Error(DefmPrefixLoc, "defm '" + CurRec->getNameInitAsString() + "' already defined in this multiclass!"); - CurMultiClass->DefPrototypes.push_back(CurRec); + CurMultiClass->DefPrototypes.push_back(std::unique_ptr<Record>(CurRec)); // Copy the template arguments for the multiclass into the new def. const std::vector<Init *> &TA = @@ -2576,7 +2552,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { // To instantiate a multiclass, we need to first get the multiclass, then // instantiate each def contained in the multiclass with the SubClassRef // template parameters. - MultiClass *MC = MultiClasses[Ref.Rec->getName()]; + MultiClass *MC = MultiClasses[Ref.Rec->getName()].get(); assert(MC && "Didn't lookup multiclass correctly?"); std::vector<Init*> &TemplateVals = Ref.TemplateArgs; @@ -2588,7 +2564,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { // Loop over all the def's in the multiclass, instantiating each one. for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) { - Record *DefProto = MC->DefPrototypes[i]; + Record *DefProto = MC->DefPrototypes[i].get(); Record *CurRec = InstantiateMulticlassDef(*MC, DefProto, DefmPrefix, SMRange(DefmLoc, diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h index 79994cb..22a00e5 100644 --- a/lib/TableGen/TGParser.h +++ b/lib/TableGen/TGParser.h @@ -55,7 +55,7 @@ namespace llvm { class TGParser { TGLexer Lex; std::vector<std::vector<LetRecord> > LetStack; - std::map<std::string, MultiClass*> MultiClasses; + std::map<std::string, std::unique_ptr<MultiClass>> MultiClasses; /// Loops - Keep track of any foreach loops we are within. /// |