aaron.ballman added a comment.

Thank you for this!



================
Comment at: clang/include/clang/Basic/AttrDocs.td:1773
 
-At the moment the attributes only have effect when used in an ``if``, ``else``,
-or ``switch`` statement.
+Below some usage examples likelihood attributes and their effect:
 
----------------
How about: `Below are some example usages of the likelihood attributes and 
their effects:`


================
Comment at: clang/include/clang/Basic/AttrDocs.td:1854
+  for(int i = 0; i != size; ++i) [[likely]] {
+    ...               // The loop the likely path of execution
+  }
----------------
The loop the likely -> The loop is the likely

Also, mentioning that this applies to range-based for loops may not be a bad 
thing either.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:1861
+
+  do [[unlikely]] {   // The loop will always iterate once
+    ...               // The likelihood attribute affects the likelihood of the
----------------
Oye, I don't know how I feel about this. According to the standard 
(http://eel.is/c++draft/stmt.pre#1), the unlikely attribute appertains to the 
compound statement, not the expression within the while loop and that compound 
statement is required to be entered at least once so this just feels really 
unintuitive to me. WDYT?


================
Comment at: clang/include/clang/Basic/AttrDocs.td:1866
+  while(true) [[unlikely]] {
+    ...               // The attribute has no effect
+  }                   // Clang elides comparison and generates an infinite loop
----------------
This is a bit of an edge case where I can't tell whether we should or should 
not diagnose. On the one hand, the user wrote something and we think it's 
meaningless, which we would usually diagnose as being an ignored attribute so 
the user can maybe react to it. On the other hand, "has no effect" is perhaps 
not the same as "ignored", as with `i + 0` (it's not really ignored but you 
would expect it to have no effect either).


================
Comment at: clang/include/clang/Basic/AttrDocs.td:1867
+    ...               // The attribute has no effect
+  }                   // Clang elides comparison and generates an infinite loop
+
----------------
elides comparison -> elides the comparison


================
Comment at: clang/include/clang/Basic/AttrDocs.td:1871
+    ...               // The attribute has no effect
+  } while(0);         // Clang elides comparison and generates no loop
+
----------------
elides comparison -> elides the comparison


================
Comment at: clang/lib/CodeGen/CodeGenFunction.h:1410
 
+  /// Calculate the branch weight for PGO data or the likelihood attribe.
+  /// The function tries to get the weight of \ref createProfileWeightsForLoop.
----------------
attribe -> attribute


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89899/new/

https://reviews.llvm.org/D89899

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to