In some cases (as illustrated in the unittest), lineno can be less than the heade_lineno because the function body are included from some other files. In this case, offset will be negative. This patch makes clang still able to match the profile to IR in this situation.
Diff Detail
Event Timeline
lib/Transforms/IPO/SampleProfile.cpp | ||
---|---|---|
233 | Could you factor out this offset computation and add a comment? It's not immediately obvious why the code is doing this saturation and it's used in several places. Also, what's guaranteeing that the saturation will be done on 16 bits? |
lib/Transforms/IPO/SampleProfile.cpp | ||
---|---|---|
233–235 | Done. In create_llvm_prof, offset is only encoded in 16 bits. |
LGTM with the additional check. Thanks.
lib/Transforms/IPO/SampleProfile.cpp | ||
---|---|---|
185 | I would now assert that this is the case (ie, L - H fits in 16 bits). It's true that most input will come straight out of create_llvm_prof, but not all of it will. In particular, the offsets in the input profiles are specified to be 32-bit unsigned integers. Alternatively, we could assert this in ProfileData/SampleProfReader.cpp itself. This needs to be done in all 3 readers. Perhaps that's a better place to assert this. | |
233–235 | Sure, but we're sufficiently removed from create_llvm_prof here that it makes sense to remind the user :) |
lib/Transforms/IPO/SampleProfile.cpp | ||
---|---|---|
185 | Added sanity check for LineLocation in text and binary reader. For gcov reader, the reader itself use bit operation to set LineLocation, which ensures that it's always within 16 bits. |
Update the discriminator assignment algorithm.
- If a scope has already been assigned a discriminator, do not reassign a nested discriminator for it.
- If the file and line both match, even if the column does not match, we should assign a new discriminator for the stmt.
supposed to create a new patch... please ignore the previous update sent.
new patch created in http://reviews.llvm.org/D14181
I would now assert that this is the case (ie, L - H fits in 16 bits). It's true that most input will come straight out of create_llvm_prof, but not all of it will. In particular, the offsets in the input profiles are specified to be 32-bit unsigned integers.
Alternatively, we could assert this in ProfileData/SampleProfReader.cpp itself. This needs to be done in all 3 readers. Perhaps that's a better place to assert this.