X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FUtils%2FSpecialCaseList.cpp;h=3d76a17abd904967da32ce7002375e9eb88d0c23;hb=bdd9df49fc747e4068cc6ef4dc6b9e0497dda49c;hp=5400bcd60bfe3ccdc3ee35055c990cde2668f14e;hpb=655abf57edcc9954428ac405905005f82091add5;p=oota-llvm.git diff --git a/lib/Transforms/Utils/SpecialCaseList.cpp b/lib/Transforms/Utils/SpecialCaseList.cpp index 5400bcd60bf..3d76a17abd9 100644 --- a/lib/Transforms/Utils/SpecialCaseList.cpp +++ b/lib/Transforms/Utils/SpecialCaseList.cpp @@ -15,9 +15,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Utils/SpecialCaseList.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/IR/DerivedTypes.h" @@ -27,8 +26,8 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Regex.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" #include +#include #include namespace llvm { @@ -42,7 +41,7 @@ struct SpecialCaseList::Entry { StringSet<> Strings; Regex *RegEx; - Entry() : RegEx(0) {} + Entry() : RegEx(nullptr) {} bool match(StringRef Query) const { return Strings.count(Query) || (RegEx && RegEx->match(Query)); @@ -55,20 +54,21 @@ SpecialCaseList *SpecialCaseList::create( const StringRef Path, std::string &Error) { if (Path.empty()) return new SpecialCaseList(); - OwningPtr File; - if (error_code EC = MemoryBuffer::getFile(Path, File)) { + ErrorOr> FileOrErr = + MemoryBuffer::getFile(Path); + if (std::error_code EC = FileOrErr.getError()) { Error = (Twine("Can't open file '") + Path + "': " + EC.message()).str(); - return 0; + return nullptr; } - return create(File.get(), Error); + return create(FileOrErr.get().get(), Error); } SpecialCaseList *SpecialCaseList::create( const MemoryBuffer *MB, std::string &Error) { - OwningPtr SCL(new SpecialCaseList()); + std::unique_ptr SCL(new SpecialCaseList()); if (!SCL->parse(MB, Error)) - return 0; - return SCL.take(); + return nullptr; + return SCL.release(); } SpecialCaseList *SpecialCaseList::createOrDie(const StringRef Path) { @@ -169,18 +169,12 @@ SpecialCaseList::~SpecialCaseList() { } } -bool SpecialCaseList::findCategory(const Function &F, - StringRef &Category) const { - return findCategory(*F.getParent(), Category) || - findCategory("fun", F.getName(), Category); -} - bool SpecialCaseList::isIn(const Function& F, const StringRef Category) const { return isIn(*F.getParent(), Category) || inSectionCategory("fun", F.getName(), Category); } -static StringRef GetGVTypeString(const GlobalVariable &G) { +static StringRef GetGlobalTypeString(const GlobalValue &G) { // Types of GlobalVariables are always pointer types. Type *GType = G.getType()->getElementType(); // For now we support blacklisting struct types only. @@ -191,46 +185,29 @@ static StringRef GetGVTypeString(const GlobalVariable &G) { return ""; } -bool SpecialCaseList::findCategory(const GlobalVariable &G, - StringRef &Category) const { - return findCategory(*G.getParent(), Category) || - findCategory("global", G.getName(), Category) || - findCategory("type", GetGVTypeString(G), Category); -} - bool SpecialCaseList::isIn(const GlobalVariable &G, const StringRef Category) const { return isIn(*G.getParent(), Category) || inSectionCategory("global", G.getName(), Category) || - inSectionCategory("type", GetGVTypeString(G), Category); + inSectionCategory("type", GetGlobalTypeString(G), Category); } -bool SpecialCaseList::findCategory(const Module &M, StringRef &Category) const { - return findCategory("src", M.getModuleIdentifier(), Category); +bool SpecialCaseList::isIn(const GlobalAlias &GA, + const StringRef Category) const { + if (isIn(*GA.getParent(), Category)) + return true; + + if (isa(GA.getType()->getElementType())) + return inSectionCategory("fun", GA.getName(), Category); + + return inSectionCategory("global", GA.getName(), Category) || + inSectionCategory("type", GetGlobalTypeString(GA), Category); } bool SpecialCaseList::isIn(const Module &M, const StringRef Category) const { return inSectionCategory("src", M.getModuleIdentifier(), Category); } -bool SpecialCaseList::findCategory(const StringRef Section, - const StringRef Query, - StringRef &Category) const { - StringMap >::const_iterator I = Entries.find(Section); - if (I == Entries.end()) return false; - - for (StringMap::const_iterator II = I->second.begin(), - IE = I->second.end(); - II != IE; ++II) { - if (II->getValue().match(Query)) { - Category = II->first(); - return true; - } - } - - return false; -} - bool SpecialCaseList::inSectionCategory(const StringRef Section, const StringRef Query, const StringRef Category) const {