return "Success";
case instrprof_error::eof:
return "End of File";
+ case instrprof_error::unrecognized_format:
+ return "Unrecognized instrumentation profile encoding format";
case instrprof_error::bad_magic:
- return "Invalid profile data (bad magic)";
+ return "Invalid instrumentation profile data (bad magic)";
case instrprof_error::bad_header:
- return "Invalid profile data (file header is corrupt)";
+ return "Invalid instrumentation profile data (file header is corrupt)";
case instrprof_error::unsupported_version:
- return "Unsupported profiling format version";
+ return "Unsupported instrumentation profile format version";
case instrprof_error::unsupported_hash_type:
- return "Unsupported profiling hash";
+ return "Unsupported instrumentation profile hash type";
case instrprof_error::too_large:
return "Too much profile data";
case instrprof_error::truncated:
return "Truncated profile data";
case instrprof_error::malformed:
- return "Malformed profile data";
+ return "Malformed instrumentation profile data";
case instrprof_error::unknown_function:
return "No profile data available for function";
case instrprof_error::hash_mismatch:
}
}
-template <class T> static T swapToHostOrder(T v, support::endianness Orig) {
- if (Orig == getHostEndianness())
- return v;
- sys::swapByteOrder<T>(v);
- return v;
+template <class T>
+static T swapToHostOrder(const unsigned char *&D, support::endianness Orig) {
+ using namespace support;
+ if (Orig == little)
+ return endian::readNext<T, little, unaligned>(D);
+ else
+ return endian::readNext<T, big, unaligned>(D);
}
// For writing/serializing, Old is the host endianness, and New is
}
}
-static ValueProfData *AllocValueProfData(uint32_t TotalSize) {
- void *RawMem = ::operator new(TotalSize);
- ValueProfData *VPDMem = new (RawMem) ValueProfData();
- return VPDMem;
+static std::unique_ptr<ValueProfData> AllocValueProfData(uint32_t TotalSize) {
+ return std::unique_ptr<ValueProfData>(new (::operator new(TotalSize))
+ ValueProfData());
}
std::unique_ptr<ValueProfData>
ValueProfData::serializeFrom(const InstrProfRecord &Record) {
uint32_t TotalSize = getSize(Record);
- std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize));
+ std::unique_ptr<ValueProfData> VPD = AllocValueProfData(TotalSize);
VPD->TotalSize = TotalSize;
VPD->NumValueKinds = Record.getNumValueKinds();
if (D + sizeof(ValueProfData) > BufferEnd)
return instrprof_error::truncated;
- uint32_t TotalSize = swapToHostOrder<uint32_t>(
- reinterpret_cast<const uint32_t *>(D)[0], Endianness);
- uint32_t NumValueKinds = swapToHostOrder<uint32_t>(
- reinterpret_cast<const uint32_t *>(D)[1], Endianness);
+ const unsigned char *Header = D;
+ uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);
+ uint32_t NumValueKinds = swapToHostOrder<uint32_t>(Header, Endianness);
if (D + TotalSize > BufferEnd)
return instrprof_error::too_large;
if (TotalSize % sizeof(uint64_t))
return instrprof_error::malformed;
- std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize));
+ std::unique_ptr<ValueProfData> VPD = AllocValueProfData(TotalSize);
memcpy(VPD.get(), D, TotalSize);
// Byte swap.
return instrprof_error::malformed;
}
- D += TotalSize;
return std::move(VPD);
}