diff options
author | Craig Topper <craig.topper@intel.com> | 2017-07-08 05:16:13 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2017-07-08 05:16:13 +0000 |
commit | bb8c799e1a9699ef3ef8ee1b6ea7da5ca42102fb (patch) | |
tree | 4838abcf7a282c46287b5c1e339174ad4a8fba13 /llvm/lib/Support/Host.cpp | |
parent | 433c2f08599eab3a3756646b65b17c1315e9fde3 (diff) | |
download | bcm5719-llvm-bb8c799e1a9699ef3ef8ee1b6ea7da5ca42102fb.tar.gz bcm5719-llvm-bb8c799e1a9699ef3ef8ee1b6ea7da5ca42102fb.zip |
[X86] Cleanup some CPUID usage in getAvailableFeatures.
We should make sure leaf 1 is available before accessing it. Same with leaf 0x80000001.
llvm-svn: 307462
Diffstat (limited to 'llvm/lib/Support/Host.cpp')
-rw-r--r-- | llvm/lib/Support/Host.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index 31d43fed193..0b5a5c1a33f 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -987,8 +987,14 @@ static unsigned getAvailableFeatures(unsigned int ECX, unsigned int EDX, Features |= (HasAVX512Save << FEATURE_AVX512SAVE); Features |= (HasADX << FEATURE_ADX); - getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); - Features |= (((EDX >> 29) & 0x1) << FEATURE_EM64T); + unsigned MaxExtLevel; + getX86CpuIDAndInfo(0x80000000, &MaxExtLevel, &EBX, &ECX, &EDX); + + bool HasExtLeaf1 = MaxExtLevel >= 0x80000001 && + !getX86CpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX); + if (HasExtLeaf1) + Features |= (((EDX >> 29) & 0x1) << FEATURE_EM64T); + return Features; } @@ -1004,10 +1010,9 @@ StringRef sys::getHostCPUName() { if(!isCpuIdSupported()) return "generic"; #endif - if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX)) - return "generic"; - if (getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX)) + if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX) || MaxLeaf < 1) return "generic"; + getX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX); unsigned Brand_id = EBX & 0xff; unsigned Family = 0, Model = 0; |