Skip to content

Commit 393d166

Browse files
resolve review fee feedback
1 parent c30a699 commit 393d166

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

compiler-rt/include/profile/InstrProfData.inc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumBitmapBytes, \
106106
INSTR_PROF_VTABLE_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), \
107107
VTableNameHash, ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
108108
IndexedInstrProf::ComputeHash(PGOVTableName)))
109-
INSTR_PROF_VTABLE_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
109+
INSTR_PROF_VTABLE_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx), \
110110
VTablePointer, VTableAddr)
111111
INSTR_PROF_VTABLE_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), VTableSize, \
112112
ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
@@ -210,18 +210,16 @@ VALUE_PROF_KIND(IPVK_MemOPSize, 1, "memory intrinsic functions size")
210210
/* For virtual table address profiling, the address point of the virtual table
211211
* (i.e., the address contained in objects pointing to a virtual table) are
212212
* profiled. Note this may not be the address of the per C++ class virtual table
213-
* object (e.g., there might be an offset).
213+
* object (e.g., there might be an offset).
214214
*
215215
* The profiled addresses are stored in raw profile, together with the following
216216
* two types of information.
217217
* 1. The (starting and ending) addresses of per C++ class virtual table objects.
218218
* 2. The (compressed) virtual table object names.
219219
* RawInstrProfReader converts profiled virtual table addresses to virtual table
220-
* objects' MD5 hash.
220+
* objects' MD5 hash.
221221
*/
222-
VALUE_PROF_KIND(IPVK_VTableTarget, 2, "The address of the compatible vtable (i.e., "
223-
"there is an offset from this address to a C++ "
224-
"class virtual table global variable.)")
222+
VALUE_PROF_KIND(IPVK_VTableTarget, 2, "The profiled address point of the vtable")
225223
/* These two kinds must be the last to be
226224
* declared. This is to make sure the string
227225
* array created with the template can be

compiler-rt/lib/profile/InstrProfilingBuffer.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ COMPILER_RT_VISIBILITY
6565
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
6666
const __llvm_profile_data *End) {
6767
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
68+
// `sizeof(__llvm_profile_data) - 1` is required in the numerator when
69+
// [Begin, End] represents an inclusive range.
70+
// For ELF, [Begin, End) represents the address of linker-inserted
71+
// symbols `__start__<elf-section>` and `__stop_<elf-section>`.
72+
// Thereby, `End` is one byte past the inclusive range, and
73+
// `sizeof(__llvm_profile_data) - 1` is not necessary in the numerator to get
74+
// the correct number of profile data.
75+
// FIXME: Consider removing `sizeof(__llvm_profile_data) - 1` if this is true
76+
// across platforms.
6877
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) /
6978
sizeof(__llvm_profile_data);
7079
}
@@ -75,11 +84,18 @@ uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
7584
return __llvm_profile_get_num_data(Begin, End) * sizeof(__llvm_profile_data);
7685
}
7786

87+
// Counts the number of `VTableProfData` elements within the range of [Begin,
88+
// End). Caller should guarantee that End points to one byte past the inclusive
89+
// range.
90+
// FIXME: Add a compiler-rt test to make sure the number of vtables in the
91+
// raw profile is the same as the number of vtable elements in the instrumented
92+
// binary.
7893
COMPILER_RT_VISIBILITY
7994
uint64_t __llvm_profile_get_num_vtable(const VTableProfData *Begin,
8095
const VTableProfData *End) {
96+
// Convert pointers to intptr_t to use integer arithmetic.
8197
intptr_t EndI = (intptr_t)End, BeginI = (intptr_t)Begin;
82-
return (EndI + sizeof(VTableProfData) - 1 - BeginI) / sizeof(VTableProfData);
98+
return (EndI - BeginI) / sizeof(VTableProfData);
8399
}
84100

85101
COMPILER_RT_VISIBILITY
@@ -241,7 +257,7 @@ COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal(
241257
// Set virtual table arguments to NULL since they are not supported yet.
242258
return lprofWriteDataImpl(
243259
&BufferWriter, DataBegin, DataEnd, CountersBegin, CountersEnd,
244-
BitmapBegin, BitmapEnd, 0 /* VPDataReader */, NamesBegin, NamesEnd,
245-
NULL /* VTableBegin */, NULL /* VTableEnd */, NULL /* VNamesBegin */,
246-
NULL /* VNamesEnd */, 0 /* SkipNameDataWrite */);
260+
BitmapBegin, BitmapEnd, /*VPDataReader=*/0, NamesBegin, NamesEnd,
261+
/*VTableBegin=*/NULL, /*VTableEnd=*/NULL, /*VNamesBegin=*/NULL,
262+
/*VNamesEnd=*/NULL, /*SkipNameDataWrite=*/0);
247263
}

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,22 @@ INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumBitmapBytes, \
9494
#undef INSTR_PROF_DATA
9595
/* INSTR_PROF_DATA end. */
9696

97+
/* For a virtual table object, record the name hash to associate profiled
98+
* addresses with global variables, and record {starting address, size in bytes}
99+
* to map the profiled virtual table (which usually have an offset from the
100+
* starting address) back to a virtual table object. */
97101
#ifndef INSTR_PROF_VTABLE_DATA
98102
#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Initializer)
99103
#else
100104
#define INSTR_PROF_VTABLE_DATA_DEFINED
101105
#endif
102-
INSTR_PROF_VTABLE_DATA(
103-
const uint64_t, llvm::Type::getInt64Ty(Ctx), VTableNameHash,
104-
ConstantInt::get(llvm::Type::getInt64Ty(Ctx),
105-
IndexedInstrProf::ComputeHash(PGOVTableName)))
106-
INSTR_PROF_VTABLE_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx),
106+
INSTR_PROF_VTABLE_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), \
107+
VTableNameHash, ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
108+
IndexedInstrProf::ComputeHash(PGOVTableName)))
109+
INSTR_PROF_VTABLE_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx), \
107110
VTablePointer, VTableAddr)
108-
INSTR_PROF_VTABLE_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), VTableSize,
109-
ConstantInt::get(llvm::Type::getInt32Ty(Ctx),
111+
INSTR_PROF_VTABLE_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), VTableSize, \
112+
ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
110113
VTableSizeVal))
111114
#undef INSTR_PROF_VTABLE_DATA
112115
/* INSTR_PROF_VTABLE_DATA end. */
@@ -204,7 +207,19 @@ VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
204207
VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0, "indirect call target")
205208
/* For memory intrinsic functions size profiling. */
206209
VALUE_PROF_KIND(IPVK_MemOPSize, 1, "memory intrinsic functions size")
207-
VALUE_PROF_KIND(IPVK_VTableTarget, 2, "vtable target")
210+
/* For virtual table address profiling, the address point of the virtual table
211+
* (i.e., the address contained in objects pointing to a virtual table) are
212+
* profiled. Note this may not be the address of the per C++ class virtual table
213+
* object (e.g., there might be an offset).
214+
*
215+
* The profiled addresses are stored in raw profile, together with the following
216+
* two types of information.
217+
* 1. The (starting and ending) addresses of per C++ class virtual table objects.
218+
* 2. The (compressed) virtual table object names.
219+
* RawInstrProfReader converts profiled virtual table addresses to virtual table
220+
* objects' MD5 hash.
221+
*/
222+
VALUE_PROF_KIND(IPVK_VTableTarget, 2, "The profiled address point of the vtable")
208223
/* These two kinds must be the last to be
209224
* declared. This is to make sure the string
210225
* array created with the template can be

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,11 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
609609

610610
uint64_t VTableNamesSectionStart = OS.tell();
611611

612-
// Use an empty string as compressed vtable names and get the necessary
613-
// profile format change in place for version 12.
612+
// Use a dummy (and uncompressed) string as compressed vtable names and get
613+
// the necessary profile format change in place for version 12.
614614
// TODO: Store the list of vtable names in InstrProfWriter and use the
615615
// real compressed name.
616-
std::string CompressedVTableNames;
616+
std::string CompressedVTableNames = "VTableNames";
617617

618618
uint64_t CompressedStringLen = CompressedVTableNames.length();
619619

0 commit comments

Comments
 (0)