-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[MC] Add support for -mcpu=native. #159414
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# RUN: llvm-mc -filetype=obj -o %t -mcpu=native %s 2> %t.stderr | ||
# RUN: FileCheck --allow-empty %s < %t.stderr | ||
|
||
# CHECK-NOT: {{.+}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,14 +459,26 @@ int main(int argc, char **argv) { | |
MAI->setCommentColumn(CommentColumn); | ||
|
||
// Package up features to be passed to target/subtarget | ||
SubtargetFeatures Features; | ||
std::string FeaturesStr; | ||
|
||
// Replace -mcpu=native with Host CPU and features. | ||
if (MCPU == "native") { | ||
MCPU = std::string(llvm::sys::getHostCPUName()); | ||
|
||
llvm::StringMap<bool> TargetFeatures = llvm::sys::getHostCPUFeatures(); | ||
for (auto const &[FeatureName, IsSupported] : TargetFeatures) | ||
Features.AddFeature(FeatureName, IsSupported); | ||
} | ||
|
||
// Handle features passed to target/subtarget. | ||
if (MAttrs.size()) { | ||
SubtargetFeatures Features; | ||
for (unsigned i = 0; i != MAttrs.size(); ++i) | ||
Features.AddFeature(MAttrs[i]); | ||
FeaturesStr = Features.getString(); | ||
} | ||
|
||
FeaturesStr = Features.getString(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to pass call getHostCPUFeatures too and pass that information to MAttr? I know on X86, getHostCPUName can return "haswell" on Pentium CPUs that don't support AVX2, but use the haswell microarchitecture. "haswell" implies AVX2. getHostCPUFeatures will return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, that's a good point. It doesn't look like X86 supports I do see that clang/lib/Driver/ToolChains/Arch/X86.cpp:
I don't have a strong opinion here, but do have a strong opinion that MC needs to support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clang does use getHostCPUFeatures with -mcpu=native. I wrote the code originally. It's here.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that fixme is maybe saying we shouldn't call getHostCPU if you explicitly pass --target=x86_64 on a non-x86 machine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry I meant -march=native. For all intents and purpose -march on X86 is -mcpu. I've been on RISC-V for too long now so I my brain thinks -mcpu. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Latest patch addresses this. I think it's best to allow the command line -mattr's to override the default with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree. |
||
std::unique_ptr<MCSubtargetInfo> STI( | ||
TheTarget->createMCSubtargetInfo(TheTriple, MCPU, FeaturesStr)); | ||
assert(STI && "Unable to create subtarget info!"); | ||
|
Uh oh!
There was an error while loading. Please reload this page.