This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Refactor BalancedPartitioning for fixing build failure with MSVC
ClosedPublic

Authored by kamleshbhalui on Jun 19 2023, 10:44 PM.

Details

Summary

Fix build failure on windows system with msvc toolchain

Diff Detail

Event Timeline

kamleshbhalui created this revision.Jun 19 2023, 10:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2023, 10:44 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
kamleshbhalui requested review of this revision.Jun 19 2023, 10:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2023, 10:44 PM

Can you describe how this breaks in your Windows system?

ThreadPool.h ends up including immintrin.h from MSVC after builtin generation in clang and It has definitions for replacing one builtins with another.
Clang maintain a enum for all generated builtin but due to above macro replacement enum ends up having two element with same name and it causes multiple definitions error.
There are some other instances where ThreadPool.h is not included directly(i.e. Debuginfod.h).

ellis added a comment.Jun 20 2023, 6:12 PM

ThreadPool.h ends up including immintrin.h from MSVC after builtin generation in clang and It has definitions for replacing one builtins with another.
Clang maintain a enum for all generated builtin but due to above macro replacement enum ends up having two element with same name and it causes multiple definitions error.
There are some other instances where ThreadPool.h is not included directly(i.e. Debuginfod.h).

I'm not understanding why this change fixes that since we are still including ThreadPool.h in BalancedPartitioning.cpp. This seems like something that should be fixed in ThreadPool.h itself.

llvm/include/llvm/Support/BalancedPartitioning.h
118

Why not keep ThreadPool owned by BPThreadPool? Why make this an alias?

ThreadPool.h ends up including immintrin.h from MSVC after builtin generation in clang and It has definitions for replacing one builtins with another.
Clang maintain a enum for all generated builtin but due to above macro replacement enum ends up having two element with same name and it causes multiple definitions error.
There are some other instances where ThreadPool.h is not included directly(i.e. Debuginfod.h).

I'm not understanding why this change fixes that since we are still including ThreadPool.h in BalancedPartitioning.cpp. This seems like something that should be fixed in ThreadPool.h itself.

Including ThreadPool.h in BalancedPartitioning.cpp is not an issue, issue comes when we include it in BalancedPartitioning.h.

kamleshbhalui added inline comments.Jun 20 2023, 6:32 PM
llvm/include/llvm/Support/BalancedPartitioning.h
118

We do not know complete type of ThreadPool here so we can not do that.

clang-formatted

clang-formatted

ellis added inline comments.Jun 21 2023, 5:55 AM
llvm/lib/Support/BalancedPartitioning.cpp
84

Lets move this line to be inside LLVM_ENABLE_THREADS because it won't be used if it's not enabled.

address comments

clang formatted

kamleshbhalui marked an inline comment as done.Jun 22 2023, 8:34 AM
ellis accepted this revision.Jun 22 2023, 9:20 AM

SGTM

This revision is now accepted and ready to land.Jun 22 2023, 9:20 AM