Skip to content

Commit

Permalink
Revert "Retry "[ProfileData] (llvm) Use Error in InstrProf and Covera…
Browse files Browse the repository at this point in the history
…ge, NFC""

This reverts commit r269491. It triggers warnings with Clang, breaking
builds for -Werror users including several build bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269547 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
chandlerc committed May 14, 2016
1 parent b01d46b commit 2e531af
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 606 deletions.
33 changes: 16 additions & 17 deletions include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>
#include <tuple>

namespace llvm {
namespace coverage {

enum class coveragemap_error {
success = 0,
eof,
Expand All @@ -38,16 +38,13 @@ enum class coveragemap_error {
truncated,
malformed
};
} // end of coverage namespace.
}

class CoverageMapError : public ProfErrorInfoBase<coveragemap_error> {
public:
CoverageMapError(coveragemap_error Err)
: ProfErrorInfoBase<coveragemap_error>(Err) {}

std::string message() const override;
namespace std {
template <>
struct is_error_code_enum<llvm::coverage::coveragemap_error> : std::true_type {
};

} // end of coverage namespace.
}

namespace llvm {
Expand Down Expand Up @@ -268,7 +265,7 @@ class CounterMappingContext {

/// \brief Return the number of times that a region of code associated with
/// this counter was executed.
Expected<int64_t> evaluate(const Counter &C) const;
ErrorOr<int64_t> evaluate(const Counter &C) const;
};

/// \brief Code coverage information for a single function.
Expand Down Expand Up @@ -418,12 +415,12 @@ class CoverageMapping {

public:
/// \brief Load the coverage mapping using the given readers.
static Expected<std::unique_ptr<CoverageMapping>>
static ErrorOr<std::unique_ptr<CoverageMapping>>
load(CoverageMappingReader &CoverageReader,
IndexedInstrProfReader &ProfileReader);

/// \brief Load the coverage mapping from the given files.
static Expected<std::unique_ptr<CoverageMapping>>
static ErrorOr<std::unique_ptr<CoverageMapping>>
load(StringRef ObjectFilename, StringRef ProfileFilename,
StringRef Arch = StringRef());

Expand Down Expand Up @@ -504,13 +501,14 @@ template <class IntPtrT> struct CovMapFunctionRecordV1 {
}
// Return the PGO name of the function */
template <support::endianness Endian>
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
std::error_code getFuncName(InstrProfSymtab &ProfileNames,
StringRef &FuncName) const {
IntPtrT NameRef = getFuncNameRef<Endian>();
uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);
FuncName = ProfileNames.getFuncName(NameRef, NameS);
if (NameS && FuncName.empty())
return make_error<CoverageMapError>(coveragemap_error::malformed);
return Error::success();
return coveragemap_error::malformed;
return std::error_code();
}
};

Expand All @@ -532,10 +530,11 @@ struct CovMapFunctionRecord {
}
// Return the PGO name of the function */
template <support::endianness Endian>
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
std::error_code getFuncName(InstrProfSymtab &ProfileNames,
StringRef &FuncName) const {
uint64_t NameRef = getFuncNameRef<Endian>();
FuncName = ProfileNames.getFuncName(NameRef);
return Error::success();
return std::error_code();
}
};

Expand Down
24 changes: 12 additions & 12 deletions include/llvm/ProfileData/Coverage/CoverageMappingReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CoverageMappingIterator

class CoverageMappingReader {
public:
virtual Error readNextRecord(CoverageMappingRecord &Record) = 0;
virtual std::error_code readNextRecord(CoverageMappingRecord &Record) = 0;
CoverageMappingIterator begin() { return CoverageMappingIterator(this); }
CoverageMappingIterator end() { return CoverageMappingIterator(); }
virtual ~CoverageMappingReader() {}
Expand All @@ -82,10 +82,10 @@ class RawCoverageReader {

RawCoverageReader(StringRef Data) : Data(Data) {}

Error readULEB128(uint64_t &Result);
Error readIntMax(uint64_t &Result, uint64_t MaxPlus1);
Error readSize(uint64_t &Result);
Error readString(StringRef &Result);
std::error_code readULEB128(uint64_t &Result);
std::error_code readIntMax(uint64_t &Result, uint64_t MaxPlus1);
std::error_code readSize(uint64_t &Result);
std::error_code readString(StringRef &Result);
};

/// \brief Reader for the raw coverage filenames.
Expand All @@ -100,7 +100,7 @@ class RawCoverageFilenamesReader : public RawCoverageReader {
RawCoverageFilenamesReader(StringRef Data, std::vector<StringRef> &Filenames)
: RawCoverageReader(Data), Filenames(Filenames) {}

Error read();
std::error_code read();
};

/// \brief Reader for the raw coverage mapping data.
Expand All @@ -125,12 +125,12 @@ class RawCoverageMappingReader : public RawCoverageReader {
Filenames(Filenames), Expressions(Expressions),
MappingRegions(MappingRegions) {}

Error read();
std::error_code read();

private:
Error decodeCounter(unsigned Value, Counter &C);
Error readCounter(Counter &C);
Error
std::error_code decodeCounter(unsigned Value, Counter &C);
std::error_code readCounter(Counter &C);
std::error_code
readMappingRegionsSubArray(std::vector<CounterMappingRegion> &MappingRegions,
unsigned InferredFileID, size_t NumFileIDs);
};
Expand Down Expand Up @@ -170,11 +170,11 @@ class BinaryCoverageReader : public CoverageMappingReader {
BinaryCoverageReader() : CurrentRecord(0) {}

public:
static Expected<std::unique_ptr<BinaryCoverageReader>>
static ErrorOr<std::unique_ptr<BinaryCoverageReader>>
create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
StringRef Arch);

Error readNextRecord(CoverageMappingRecord &Record) override;
std::error_code readNextRecord(CoverageMappingRecord &Record) override;
};

} // end namespace coverage
Expand Down
68 changes: 23 additions & 45 deletions include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/ProfileData/ProfileCommon.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MathExtras.h"
#include <cstdint>
Expand Down Expand Up @@ -203,17 +204,20 @@ StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName,
/// third field is the uncompressed strings; otherwise it is the
/// compressed string. When the string compression is off, the
/// second field will have value zero.
Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
bool doCompression, std::string &Result);
std::error_code
collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
bool doCompression, std::string &Result);
/// Produce \c Result string with the same format described above. The input
/// is vector of PGO function name variables that are referenced.
Error collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
std::string &Result, bool doCompression = true);
std::error_code
collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,
std::string &Result, bool doCompression = true);
class InstrProfSymtab;
/// \c NameStrings is a string composed of one of more sub-strings encoded in
/// the format described above. The substrings are seperated by 0 or more zero
/// bytes. This method decodes the string and populates the \c Symtab.
Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab);
std::error_code readPGOFuncNameStrings(StringRef NameStrings,
InstrProfSymtab &Symtab);

enum InstrProfValueKind : uint32_t {
#define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
Expand Down Expand Up @@ -280,25 +284,6 @@ inline std::error_code make_error_code(instrprof_error E) {
return std::error_code(static_cast<int>(E), instrprof_category());
}

class InstrProfError : public ProfErrorInfoBase<instrprof_error> {
public:
InstrProfError(instrprof_error Err)
: ProfErrorInfoBase<instrprof_error>(Err) {}

std::string message() const override;

/// Consume an Error and return the raw enum value contained within it. The
/// Error must either be a success value, or contain a single InstrProfError.
static instrprof_error take(Error E) {
auto Err = instrprof_error::success;
handleAllErrors(std::move(E), [&Err](const InstrProfError &IPE) {
assert(Err == instrprof_error::success && "Multiple errors encountered");
Err = IPE.get();
});
return Err;
}
};

class SoftInstrProfErrors {
/// Count the number of soft instrprof_errors encountered and keep track of
/// the first such error for reporting purposes.
Expand All @@ -324,11 +309,6 @@ class SoftInstrProfErrors {
NumCountMismatches(0), NumCounterOverflows(0),
NumValueSiteCountMismatches(0) {}

~SoftInstrProfErrors() {
assert(FirstError == instrprof_error::success &&
"Unchecked soft error encountered");
}

/// Track a soft error (\p IE) and increment its associated counter.
void addError(instrprof_error IE);

Expand All @@ -346,15 +326,8 @@ class SoftInstrProfErrors {
return NumValueSiteCountMismatches;
}

/// Return the first encountered error and reset FirstError to a success
/// value.
Error takeError() {
if (FirstError == instrprof_error::success)
return Error::success();
auto E = make_error<InstrProfError>(FirstError);
FirstError = instrprof_error::success;
return E;
}
/// Return an error code for the first encountered error.
std::error_code getError() const { return make_error_code(FirstError); }
};

namespace object {
Expand Down Expand Up @@ -399,14 +372,14 @@ class InstrProfSymtab {
/// only initialize the symtab with reference to the data and
/// the section base address. The decompression will be delayed
/// until before it is used. See also \c create(StringRef) method.
Error create(object::SectionRef &Section);
std::error_code create(object::SectionRef &Section);
/// This interface is used by reader of CoverageMapping test
/// format.
inline Error create(StringRef D, uint64_t BaseAddr);
inline std::error_code create(StringRef D, uint64_t BaseAddr);
/// \c NameStrings is a string composed of one of more sub-strings
/// encoded in the format described in \c collectPGOFuncNameStrings.
/// This method is a wrapper to \c readPGOFuncNameStrings method.
inline Error create(StringRef NameStrings);
inline std::error_code create(StringRef NameStrings);
/// A wrapper interface to populate the PGO symtab with functions
/// decls from module \c M. This interface is used by transformation
/// passes such as indirect function call promotion. Variable \c InLTO
Expand Down Expand Up @@ -451,13 +424,13 @@ class InstrProfSymtab {
inline StringRef getNameData() const { return Data; }
};

Error InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {
std::error_code InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {
Data = D;
Address = BaseAddr;
return Error::success();
return std::error_code();
}

Error InstrProfSymtab::create(StringRef NameStrings) {
std::error_code InstrProfSymtab::create(StringRef NameStrings) {
return readPGOFuncNameStrings(NameStrings, *this);
}

Expand Down Expand Up @@ -599,7 +572,7 @@ struct InstrProfRecord {
}

/// Get the error contained within the record's soft error counter.
Error takeError() { return SIPE.takeError(); }
std::error_code getError() const { return SIPE.getError(); }

private:
std::vector<InstrProfValueSiteRecord> IndirectCallSites;
Expand Down Expand Up @@ -917,4 +890,9 @@ struct Header {

} // end namespace llvm

namespace std {
template <>
struct is_error_code_enum<llvm::instrprof_error> : std::true_type {};
}

#endif // LLVM_PROFILEDATA_INSTRPROF_H
7 changes: 4 additions & 3 deletions include/llvm/ProfileData/InstrProfData.inc
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,16 @@ typedef struct ValueProfData {
static std::unique_ptr<ValueProfData>
serializeFrom(const InstrProfRecord &Record);
/*!
* Check the integrity of the record.
* Check the integrity of the record. Return the error code when
* an error is detected, otherwise return instrprof_error::success.
*/
Error checkIntegrity();
instrprof_error checkIntegrity();
/*!
* Return a pointer to \c ValueProfileData instance ready to be read.
* All data in the instance are properly byte swapped. The input
* data is assumed to be in little endian order.
*/
static Expected<std::unique_ptr<ValueProfData>>
static ErrorOr<std::unique_ptr<ValueProfData>>
getValueProfData(const unsigned char *SrcBuffer,
const unsigned char *const SrcBufferEnd,
support::endianness SrcDataEndianness);
Expand Down
Loading

0 comments on commit 2e531af

Please sign in to comment.