This is an archive of the discontinued LLVM Phabricator instance.

[RFC] Port tools/timeit.c for Windows
Needs ReviewPublic

Authored by omjavaid on Jun 19 2023, 4:07 AM.

Details

Summary

This patch implements timeit timing tool found at tools/timeit.c for Windows.
It is required for compile time and run time calculations by the llvm-testsuite.

At this moment llvm testsuite tests can not be compiled with clang-cl MSVC combination
however we have also made required modifications to the cmake files to enable building
timeit on windows with clang-cl/cl.

In developer console with MSVC following command can be used to successfully build this code:
set CC=c:\\work\\llvm-dev\\build\\bin\\clang-cl.exe
set CXX=c:\\work\\llvm-dev\\build\\bin\\clang-cl.exe
cmake -G Ninja -DTEST_SUITE_SUBDIRS= ..\\llvm-test-suite

Diff Detail

Event Timeline

omjavaid created this revision.Jun 19 2023, 4:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2023, 4:07 AM
omjavaid requested review of this revision.Jun 19 2023, 4:07 AM
omjavaid updated this revision to Diff 541933.Jul 19 2023, 3:30 AM
omjavaid edited the summary of this revision. (Show Details)
omjavaid added reviewers: mstorsjo, thieta, ddunbar.

This update fixes some bugs after testing.

This looks mostly ok to me, a couple details for discussion mostly.

cmake/modules/Host.cmake
3

Hmm, I somewhat dislike having to hardcode defaults like this, but this probably is a better default (for both mingw and msvc/clang-cl environments) than cc on Windows anyway, so I guess it's fine - and it can be overridden with options.

tools/timeit.c
18

Please include windows.h with a lowercase w. The Windows SDK itself doesn't use upper/lowercase consistently, so it cannot be used unless case insensitivity is handled somehow, and mingw headers use a lowercase spelling of this (and most other headers) - which matters when compiling with mingw on a case sensitive filesystem.

85

Hmm, if this normally is a typedef, we can't use #ifndef to check for its existence - which is why you need the surrounding #ifdef _WIN32. On the other hand, if a windows toolchain would have such a typedef (mingw doesn't seem to have it though), this #ifndef wouldn't really help either. So I would maybe suggest just keeping the outer #ifdef _WIN32 and don't pretend the #ifndef rlim_t helps.

128

This initialization can have race conditions, but if we're in a single-threaded program, this could be fine. In C++ we could use the threadsafe init of static variables to help here, but I see this program is C. So I guess this is fine, but a comment pointing out the unsafety could be good.

769

The difference between the unix and windows codepath here feels a bit asymetrical. Could we have the corresponding windows code (currently within execute_target_process) here within the execute function, to get more similarity between the two cases?