diff options
author | Erich Keane <erich.keane@intel.com> | 2018-11-01 12:50:37 +0000 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2018-11-01 12:50:37 +0000 |
commit | 44731c530088704f091448429043136c81334f25 (patch) | |
tree | 4a725b05ce45f3075dac5ab7fdc87c79f9a26b51 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 4fbf1ab1650e835c15b36c468b628d3e891c60d2 (diff) | |
download | bcm5719-llvm-44731c530088704f091448429043136c81334f25.tar.gz bcm5719-llvm-44731c530088704f091448429043136c81334f25.zip |
CPU-Dispatch-- Fix conflict between 'generic' and 'pentium'
When a dispatch function was being emitted that had both a generic and a
pentium configuration listed, we would assert. This is because neither
configuration has any 'features' associated with it so they were both
considered the 'default' version. 'pentium' lacks any features because
we implement it in terms of __builtin_cpu_supports (instead of Intel
proprietary checks), which is unable to decern between the two.
The fix for this is to omit the 'generic' version from the dispatcher if
both are present. This permits existing code to compile, and still will
choose the 'best' version available (since 'pentium' is technically
better than 'generic').
Change-Id: I4b69f3e0344e74cbdbb04497845d5895dd05fda0
llvm-svn: 345826
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 9c4b097c5d6..227b8833342 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2583,6 +2583,22 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) { return CodeGenFunction::GetX86CpuSupportsMask(LHS.Conditions.Features) > CodeGenFunction::GetX86CpuSupportsMask(RHS.Conditions.Features); }); + + // If the list contains multiple 'default' versions, such as when it contains + // 'pentium' and 'generic', don't emit the call to the generic one (since we + // always run on at least a 'pentium'). We do this by deleting the 'least + // advanced' (read, lowest mangling letter). + while (Options.size() > 1 && + CodeGenFunction::GetX86CpuSupportsMask( + (Options.end() - 2)->Conditions.Features) == 0) { + StringRef LHSName = (Options.end() - 2)->Function->getName(); + StringRef RHSName = (Options.end() - 1)->Function->getName(); + if (LHSName.compare(RHSName) < 0) + Options.erase(Options.end() - 2); + else + Options.erase(Options.end() - 1); + } + CodeGenFunction CGF(*this); CGF.EmitMultiVersionResolver(ResolverFunc, Options); } |