diff --git a/bolt/BinaryFunction.h b/bolt/BinaryFunction.h index c88d5a665a11..86237bd98c21 100644 --- a/bolt/BinaryFunction.h +++ b/bolt/BinaryFunction.h @@ -105,22 +105,22 @@ private: /// Release storage used by instructions. BinaryFunction &clearInstructions() { - std::map TempMap; + InstrMapType TempMap; Instructions.swap(TempMap); return *this; } /// Release storage used by instructions. BinaryFunction &clearLabels() { - std::map TempMap; + LabelsMapType TempMap; Labels.swap(TempMap); return *this; } /// Release memory taken by local branch info. BinaryFunction &clearLocalBranches() { - std::vector> TempVector; - LocalBranches.swap(TempVector); + LocalBranchesListType TempList; + LocalBranches.swap(TempList); return *this; } @@ -129,19 +129,26 @@ private: return *this; } -public: - std::vector> LocalBranches; + /// Storage for all local branches in the function (non-fall-throughs). + using LocalBranchesListType = std::vector>; + LocalBranchesListType LocalBranches; - std::map Labels; + /// Map offset in the function to a local label. + using LabelsMapType = std::map; + LabelsMapType Labels; /// Temporary holder of instructions before CFG is constructed. - std::map Instructions; + /// Map offset in the function to MCInst. + using InstrMapType = std::map; + InstrMapType Instructions; // Blocks are kept sorted in the layout order. If we need to change the // layout, the terminating instructions need to be modified. - typedef std::vector BasicBlockListType; + using BasicBlockListType = std::vector; BasicBlockListType BasicBlocks; +public: + typedef BasicBlockListType::iterator iterator; typedef BasicBlockListType::const_iterator const_iterator; typedef std::reverse_iterator const_reverse_iterator; diff --git a/bolt/llvm-flo.cpp b/bolt/llvm-flo.cpp index 90ea3f03d77c..06cbcb27395d 100644 --- a/bolt/llvm-flo.cpp +++ b/bolt/llvm-flo.cpp @@ -99,12 +99,10 @@ static void report_error(StringRef Message, std::error_code EC) { exit(1); } -static void error(std::error_code EC) { +static void check_error(std::error_code EC, StringRef Message) { if (!EC) return; - - errs() << ToolName << ": error reading file: " << EC.message() << ".\n"; - exit(1); + report_error(Message, EC); } template @@ -298,7 +296,7 @@ static void OptimizeFile(ELFObjectFileBase *File, const DataReader &DR) { continue; ErrorOr Name = Symbol.getName(); - error(Name.getError()); + check_error(Name.getError(), "cannot get symbol name"); if (Symbol.getType() == SymbolRef::ST_File) { // Could be used for local symbol disambiguation. @@ -307,7 +305,7 @@ static void OptimizeFile(ELFObjectFileBase *File, const DataReader &DR) { } ErrorOr AddressOrErr = Symbol.getAddress(); - error(AddressOrErr.getError()); + check_error(AddressOrErr.getError(), "cannot get symbol address"); uint64_t Address = *AddressOrErr; if (Address == 0) { if (Symbol.getType() == SymbolRef::ST_Function) @@ -339,7 +337,7 @@ static void OptimizeFile(ELFObjectFileBase *File, const DataReader &DR) { continue; ErrorOr SectionOrErr = Symbol.getSection(); - error(SectionOrErr.getError()); + check_error(SectionOrErr.getError(), "cannot get symbol section"); section_iterator Section = *SectionOrErr; if (Section == File->section_end()) { // Could be an absolute symbol. Could record for pretty printing. @@ -403,7 +401,8 @@ static void OptimizeFile(ELFObjectFileBase *File, const DataReader &DR) { } StringRef SectionContents; - error(Section.getContents(SectionContents)); + check_error(Section.getContents(SectionContents), + "cannot get section contents"); assert(SectionContents.size() == Section.getSize() && "section size mismatch"); @@ -460,22 +459,18 @@ static void OptimizeFile(ELFObjectFileBase *File, const DataReader &DR) { } std::error_code EC; + + // This is an object file, which we keep for debugging purposes. + // Once we decide it's useless, we should create it in memory. std::unique_ptr Out = llvm::make_unique(OutputFilename + ".o", - EC,sys::fs::F_None); - - if (EC) { - // FIXME: handle error - return; - } + EC, sys::fs::F_None); + check_error(EC, "cannot create output object file"); std::unique_ptr RealOut = llvm::make_unique(OutputFilename, EC, sys::fs::F_None, 0777); - if (EC) { - // FIXME: handle error - return; - } + check_error(EC, "cannot create output executable file"); // Copy input file. RealOut->os() << File->getData(); @@ -565,11 +560,7 @@ static void OptimizeFile(ELFObjectFileBase *File, const DataReader &DR) { MemoryBuffer::getMemBuffer(BOS->str(), "in-memory object file", false); ErrorOr> ObjOrErr = object::ObjectFile::createObjectFile(ObjectMemBuffer->getMemBufferRef()); - - if (std::error_code EC = ObjOrErr.getError()) { - report_error(InputFilename, EC); - return; - } + check_error(ObjOrErr.getError(), "error creating in-memory object"); std::unique_ptr EFMM(new ExecutableFileMemoryManager());