-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm][ctx_profile] Add the llvm.instrprof.callsite
intrinsic
#89939
Conversation
(Tracking Issue: llvm#89287, RFC referenced there)
@llvm/pr-subscribers-llvm-ir Author: Mircea Trofin (mtrofin) ChangesAdd the callsite intrinsic. Structurally, it is very similar to the counter intrinsics, hence the inheritance relationship. We can probably rename later (Tracking Issue: #89287, RFC referenced there) Full diff: https://github.com/llvm/llvm-project/pull/89939.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h
index 4f22720f1c558d..8a137ffe28b9f8 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -1435,6 +1435,7 @@ class InstrProfInstBase : public IntrinsicInst {
case Intrinsic::instrprof_cover:
case Intrinsic::instrprof_increment:
case Intrinsic::instrprof_increment_step:
+ case Intrinsic::instrprof_callsite:
case Intrinsic::instrprof_timestamp:
case Intrinsic::instrprof_value_profile:
return true;
@@ -1519,6 +1520,21 @@ class InstrProfIncrementInstStep : public InstrProfIncrementInst {
}
};
+/// This represents the llvm.instrprof.increment intrinsic.
+/// It is structurally like the increment or step counters, hence the
+/// inheritance relationship, albeit somewhat tenuous (it's not 'counting' per
+/// se)
+class InstrProfCallsite : public InstrProfCntrInstBase {
+public:
+ static bool classof(const IntrinsicInst *I) {
+ return I->getIntrinsicID() == Intrinsic::instrprof_callsite;
+ }
+ static bool classof(const Value *V) {
+ return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
+ }
+ Value *getCallee() const;
+};
+
/// This represents the llvm.instrprof.timestamp intrinsic.
class InstrProfTimestampInst : public InstrProfCntrInstBase {
public:
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 1d20f7e1b19854..a14e9dedef8c9e 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -914,6 +914,11 @@ def int_instrprof_increment_step : Intrinsic<[],
[llvm_ptr_ty, llvm_i64_ty,
llvm_i32_ty, llvm_i32_ty, llvm_i64_ty]>;
+// Callsite instrumentation for contextual profiling
+def int_instrprof_callsite : Intrinsic<[],
+ [llvm_ptr_ty, llvm_i64_ty,
+ llvm_i32_ty, llvm_i32_ty, llvm_ptr_ty]>;
+
// A timestamp for instrumentation based profiling.
def int_instrprof_timestamp : Intrinsic<[], [llvm_ptr_ty, llvm_i64_ty,
llvm_i32_ty, llvm_i32_ty]>;
diff --git a/llvm/unittests/IR/IntrinsicsTest.cpp b/llvm/unittests/IR/IntrinsicsTest.cpp
index 3fa4b2cf73b6be..dddd2f73d4446b 100644
--- a/llvm/unittests/IR/IntrinsicsTest.cpp
+++ b/llvm/unittests/IR/IntrinsicsTest.cpp
@@ -81,6 +81,7 @@ TEST_F(IntrinsicsTest, InstrProfInheritance) {
__ISA(InstrProfCoverInst, InstrProfCntrInstBase);
__ISA(InstrProfIncrementInst, InstrProfCntrInstBase);
__ISA(InstrProfIncrementInstStep, InstrProfIncrementInst);
+ __ISA(InstrProfCallsite, InstrProfCntrInstBase);
__ISA(InstrProfTimestampInst, InstrProfCntrInstBase);
__ISA(InstrProfValueProfileInst, InstrProfCntrInstBase);
__ISA(InstrProfMCDCBitmapInstBase, InstrProfInstBase);
@@ -94,6 +95,7 @@ TEST_F(IntrinsicsTest, InstrProfInheritance) {
{Intrinsic::instrprof_cover, isInstrProfCoverInst},
{Intrinsic::instrprof_increment, isInstrProfIncrementInst},
{Intrinsic::instrprof_increment_step, isInstrProfIncrementInstStep},
+ {Intrinsic::instrprof_callsite, isInstrProfCallsite},
{Intrinsic::instrprof_mcdc_condbitmap_update,
isInstrProfMCDCCondBitmapUpdate},
{Intrinsic::instrprof_mcdc_parameters,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update the docs?
llvm-project/llvm/docs/LangRef.rst
Lines 14142 to 14143 in 7c0da79
'``llvm.instrprof.timestamp``' Intrinsic | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
llvm/include/llvm/IR/IntrinsicInst.h
Outdated
@@ -1519,6 +1520,21 @@ class InstrProfIncrementInstStep : public InstrProfIncrementInst { | |||
} | |||
}; | |||
|
|||
/// This represents the llvm.instrprof.increment intrinsic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This represents the llvm.instrprof.increment intrinsic. | |
/// This represents the llvm.instrprof.callsite intrinsic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - thanks for the catch!
done. I'll also update the docs again once the ctx lowering pass is in, because the other intrinsics' docs are too specific. The doc for this one can become more precise at that point, too. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
llvm/docs/LangRef.rst
Outdated
|
||
Arguments: | ||
"""""""""" | ||
The first 3 arguments are similar to ``llvm.instrprof.increment``. The indexing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have this documentation stand alone and describe the parameters here instead of relying on the reader to go look up the documentation of the llvm.instrprof.increment
intrinsic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the style of the rest of the documentation, see the intrinsics above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should take the opportunity to improve instead of following what exists. I think it's low overhead to include it in here inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - I meant it as the typical pattern for this type of thing, didn't want to type that: either we fix the rest, too (separate change); or we think this is actually a good think for some reason (and then that separate change can be rejected). Either way, seems like a separate change.
Overview: | ||
""""""""" | ||
|
||
The '``llvm.instrprof.callsite``' intrinsic should be emitted before a callsite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"should be emitted" -> can you specify under what modes this intrinsic is emitted (or is it always as this statement implies)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update this after I introduce the pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a FIXME? Same for the other one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
||
Semantics: | ||
"""""""""" | ||
This is lowered by contextual profiling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand this a bit to spell out how it is used (apart from just mentioning contextual profiling) like how it should be lowered, does it modify program behaviour, should it be treated as immovable by optimizations, when it should be ignored by backends and so on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, I will need to update after I land the lowering pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
llvm/lib/IR/IntrinsicInst.cpp
Outdated
@@ -291,6 +291,8 @@ Value *InstrProfIncrementInst::getStep() const { | |||
return ConstantInt::get(Type::getInt64Ty(Context), 1); | |||
} | |||
|
|||
Value *InstrProfCallsite::getCallee() const { return getArgOperand(4); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need a check like L286 in getStep
above to get the callee? If not can you add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, because nothing stops someone from reinterpret_cast
-ing. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, with some minor nits.
Overview: | ||
""""""""" | ||
|
||
The '``llvm.instrprof.callsite``' intrinsic should be emitted before a callsite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a FIXME? Same for the other one.
llvm/docs/LangRef.rst
Outdated
|
||
Arguments: | ||
"""""""""" | ||
The first 3 arguments are similar to ``llvm.instrprof.increment``. The indexing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should take the opportunity to improve instead of following what exists. I think it's low overhead to include it in here inline.
Add the callsite intrinsic.
Structurally, it is very similar to the counter intrinsics, hence the inheritance relationship. We can probably rename
InstrProfCntrInstBase
toInstrProfIndexedBase
later - because the "counting" aspect is really left to derived types ofInstrProfCntrInstBase
, and it only concerns itself with the index aspect (which is what we care about forcallsite
, too)(Tracking Issue: #89287, RFC referenced there)