This is an archive of the discontinued LLVM Phabricator instance.

[X86] Support __SSC_MARK(const int)
AbandonedPublic

Authored by xiangzhangllvm on Aug 19 2021, 7:28 PM.

Details

Summary

There are some users want to use __SSC_MARK for special use.
But They don't want to use #include xxx in they program.

So Support SSC_MARK(const int) as X86 builtin function.

Diff Detail

Event Timeline

xiangzhangllvm requested review of this revision.Aug 19 2021, 7:28 PM
xiangzhangllvm created this revision.

Hello, @erichkeane , the patch is small and clear, and due to it changes at FE, could you help review ? Thanks a lot!

pengfei added inline comments.Aug 23 2021, 1:25 AM
clang/include/clang/Basic/BuiltinsX86.def
36

It seems using upper case letters discords current naming conversions. May be better to define __builtin_ssc_mark here and add Builder.defineMacro("__SSC_MARK", "__builtin_ssc_mark") in X86.cpp.

xiangzhangllvm added inline comments.Aug 23 2021, 1:40 AM
clang/include/clang/Basic/BuiltinsX86.def
36

Thanks, but I prefer current simple way, no touch BE code, there is no naming conversions def that built must start with __builtin and low case string.

erichkeane added inline comments.Aug 23 2021, 6:12 AM
clang/include/clang/Basic/BuiltinsX86.def
36

I very much agree with @pengfei. Builtins need to be named with __builtin and be lower case. If we want to provide a macro to be source compatible that is fine.

xiangzhangllvm added inline comments.Aug 23 2021, 5:17 PM
clang/include/clang/Basic/BuiltinsX86.def
36

There are no this rule for __builtin, for special builtin they can be directly use their original name,
For example : _mm_prefetch, _BitScanForward64, _InterlockedCompareExchange128 ...
and also ease to find the other example for other Targets.

pengfei added inline comments.Aug 23 2021, 5:55 PM
clang/include/clang/Basic/BuiltinsX86.def
36

These builtins are all Windows related, see comments "FIXME: _mm_prefetch must be a built-in because it takes a compile-time constant doesn't work in the presence of re-declaration of _mm_prefetch for windows."
These just illustrate we should follow the __builtin rule if no particular reason.
By the way, X86.cpp is a FE file. Adding a macro isn't much complicated. PPC uses a lot of macro define in this way: https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/PPC.cpp#L91

xiangzhangllvm added inline comments.Aug 23 2021, 6:57 PM
clang/include/clang/Basic/BuiltinsX86.def
36

1st I don't find such rule, even in the most basic builtin def file clang/include/clang/Basic/Builtins.def there are also lots example not follow such "rule"

2nd I don't understand what that the benefit (expect add the code in llvm) if we add a Macro which we not for other use in compiler. PPC's way is not an good example. and _mm_prefetch's comments just show why it is not normal function or Macro.

craig.topper added inline comments.Aug 23 2021, 7:19 PM
clang/lib/CodeGen/CGBuiltin.cpp
12562

Wasn't EmitScalarExpr already called for it? I think you just need Ops[0] here. You might need that to get the forced constant evaluation that was done based on ICEArguments earlier too.

xiangzhangllvm marked an inline comment as done.Aug 23 2021, 10:22 PM
xiangzhangllvm added inline comments.
clang/lib/CodeGen/CGBuiltin.cpp
12562

Good catch! It has called in line 12477, thanks very much!

erichkeane requested changes to this revision.Aug 24 2021, 6:00 AM
erichkeane added inline comments.
clang/include/clang/Basic/BuiltinsX86.def
36

The ONLY reason we skip the __builtin rule (which YES, is a rule), is when it is to match the GCC/MSVC builtin behavior that has been under a different name for a long time.

This revision now requires changes to proceed.Aug 24 2021, 6:00 AM
aaron.ballman added inline comments.
clang/include/clang/Basic/BuiltinsX86.def
36

FWIW, I strongly agree that the builtin should be following typical naming conventions and use a macro if you want to spell it differently. (I happen to also be pretty unmotivated by the use case of users who don't want to #include a header file but still use the functionality from the header, so another alternative I could live with would be to not add this builtin at all.)

There are some users want to use __SSC_MARK for special use.
But They don't want to use #include xxx in they program.

Aaron said:

so another alternative I could live with would be to not add this builtin at all.)

This is a great point, the justification of "some users dont' want to use #include doesn't seem motivating to me at all. I recognize that ICC automatically includes intrin headers, but the Clang project decided years ago to not follow that on that path and implement these things in the intrinsic headers.

This is a change that doesn't belong in the frontend. I was mildly convinced as a builtin to support this (by an appropriate name), but the more I look at it, the more I realize that the code to generate the IR for this is so incredibly better done as an intrinsic entry.

So in summary: I am thoroughly convinced to reject this as a frontend change unless there is a distinct technical reason (besides "users don't want to #include").

There are some users want to use __SSC_MARK for special use.
But They don't want to use #include xxx in they program.

Aaron said:

so another alternative I could live with would be to not add this builtin at all.)

This is a great point, the justification of "some users dont' want to use #include doesn't seem motivating to me at all. I recognize that ICC automatically includes intrin headers, but the Clang project decided years ago to not follow that on that path and implement these things in the intrinsic headers.

This is a change that doesn't belong in the frontend. I was mildly convinced as a builtin to support this (by an appropriate name), but the more I look at it, the more I realize that the code to generate the IR for this is so incredibly better done as an intrinsic entry.

So in summary: I am thoroughly convinced to reject this as a frontend change unless there is a distinct technical reason (besides "users don't want to #include").

I'm not sure icc automatically includes intrinsic headers. I couldn't prove that on godbolt. It still required me to include xmmintrin.h or similar. The intrinsic functions aren't in the header, but maybe it detects that the file was included? The definition for the __m128i and similar types used by the intrinsics is in the header.

__SSC_MARK is supported by icc without a header. I'm not sure where it is documented so I don't know if it has a defined header a user could include.

There are some users want to use __SSC_MARK for special use.
But They don't want to use #include xxx in they program.

Aaron said:

so another alternative I could live with would be to not add this builtin at all.)

This is a great point, the justification of "some users dont' want to use #include doesn't seem motivating to me at all. I recognize that ICC automatically includes intrin headers, but the Clang project decided years ago to not follow that on that path and implement these things in the intrinsic headers.

This is a change that doesn't belong in the frontend. I was mildly convinced as a builtin to support this (by an appropriate name), but the more I look at it, the more I realize that the code to generate the IR for this is so incredibly better done as an intrinsic entry.

So in summary: I am thoroughly convinced to reject this as a frontend change unless there is a distinct technical reason (besides "users don't want to #include").

I'm not sure icc automatically includes intrinsic headers. I couldn't prove that on godbolt. It still required me to include xmmintrin.h or similar. The intrinsic functions aren't in the header, but maybe it detects that the file was included? The definition for the __m128i and similar types used by the intrinsics is in the header.

__SSC_MARK is supported by icc without a header. I'm not sure where it is documented so I don't know if it has a defined header a user could include.

Right, ICC has some funny-business going on with the intrinsic headers that are a little odd. We recognize/generate many of them without needing to do the #include, so it isn't really ACTUALLY automatically including the intrinsic headers, it is just automatically including a large subset of the intrinsics.

xiangzhangllvm marked an inline comment as done.Aug 24 2021, 6:07 PM

1st, I am not clear about "how ICC automatically including the intrinsic headers", But I did a try that first delete the intrinsic head file which def the SSC_MARK from ICC project, then I build SSC_MARK code with ICC, it still passed. I think if it "automatically including the intrinsic headers" it should be fail.

The ONLY reason we skip the __builtin rule (which YES, is a rule), is when it is to match the GCC/MSVC builtin behavior that has been under a different name for a long time.

2nd, I begin to agree this point, I do same check for builtins in clang/Basic/Builtins.def with GCC (include libxxx in gcc source), that matches erich's point.

implement with #include headfile at https://reviews.llvm.org/D108682
Thanks for all your careful review and discussion.

xiangzhangllvm abandoned this revision.Aug 25 2021, 6:40 PM