diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 0c66acd981ca..a2674b8e11b5 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -54,6 +54,14 @@ static void DefineStd(MacroBuilder &Builder, StringRef MacroName, Builder.defineMacro("__" + MacroName + "__"); } +static void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, + bool Tuning = true) { + Builder.defineMacro("__" + CPUName); + Builder.defineMacro("__" + CPUName + "__"); + if (Tuning) + Builder.defineMacro("__tune_" + CPUName + "__"); +} + //===----------------------------------------------------------------------===// // Defines specific to certain operating systems. //===----------------------------------------------------------------------===// @@ -1850,9 +1858,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, case CK_WinChipC6: case CK_WinChip2: case CK_C3: - Builder.defineMacro("__i486"); - Builder.defineMacro("__i486__"); - Builder.defineMacro("__tune_i486__"); + defineCPUMacros(Builder, "i486"); break; case CK_PentiumMMX: Builder.defineMacro("__pentium_mmx__"); @@ -1860,12 +1866,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, // Fallthrough case CK_i586: case CK_Pentium: - Builder.defineMacro("__i586"); - Builder.defineMacro("__i586__"); - Builder.defineMacro("__tune_i586__"); - Builder.defineMacro("__pentium"); - Builder.defineMacro("__pentium__"); - Builder.defineMacro("__tune_pentium__"); + defineCPUMacros(Builder, "i586"); + defineCPUMacros(Builder, "pentium"); break; case CK_Pentium3: case CK_Pentium3M: @@ -1889,35 +1891,25 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, break; case CK_Pentium4: case CK_Pentium4M: - Builder.defineMacro("__pentium4"); - Builder.defineMacro("__pentium4__"); - Builder.defineMacro("__tune_pentium4__"); + defineCPUMacros(Builder, "pentium4"); break; case CK_Yonah: case CK_Prescott: case CK_Nocona: - Builder.defineMacro("__nocona"); - Builder.defineMacro("__nocona__"); - Builder.defineMacro("__tune_nocona__"); + defineCPUMacros(Builder, "nocona"); break; case CK_Core2: case CK_Penryn: - Builder.defineMacro("__core2"); - Builder.defineMacro("__core2__"); - Builder.defineMacro("__tune_core2__"); + defineCPUMacros(Builder, "core2"); break; case CK_Atom: - Builder.defineMacro("__atom"); - Builder.defineMacro("__atom__"); - Builder.defineMacro("__tune_atom__"); + defineCPUMacros(Builder, "atom"); break; case CK_Corei7: case CK_Corei7AVX: case CK_CoreAVXi: case CK_CoreAVX2: - Builder.defineMacro("__corei7"); - Builder.defineMacro("__corei7__"); - Builder.defineMacro("__tune_corei7__"); + defineCPUMacros(Builder, "corei7"); break; case CK_K6_2: Builder.defineMacro("__k6_2__"); @@ -1933,18 +1925,14 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, } // Fallthrough case CK_K6: - Builder.defineMacro("__k6"); - Builder.defineMacro("__k6__"); - Builder.defineMacro("__tune_k6__"); + defineCPUMacros(Builder, "k6"); break; case CK_Athlon: case CK_AthlonThunderbird: case CK_Athlon4: case CK_AthlonXP: case CK_AthlonMP: - Builder.defineMacro("__athlon"); - Builder.defineMacro("__athlon__"); - Builder.defineMacro("__tune_athlon__"); + defineCPUMacros(Builder, "athlon"); if (SSELevel != NoSSE) { Builder.defineMacro("__athlon_sse__"); Builder.defineMacro("__tune_athlon_sse__"); @@ -1958,29 +1946,19 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, case CK_Athlon64: case CK_Athlon64SSE3: case CK_AthlonFX: - Builder.defineMacro("__k8"); - Builder.defineMacro("__k8__"); - Builder.defineMacro("__tune_k8__"); + defineCPUMacros(Builder, "k8"); break; case CK_AMDFAM10: - Builder.defineMacro("__amdfam10"); - Builder.defineMacro("__amdfam10__"); - Builder.defineMacro("__tune_amdfam10__"); + defineCPUMacros(Builder, "amdfam10"); break; case CK_BDVER1: - Builder.defineMacro("__bdver1"); - Builder.defineMacro("__bdver1__"); - Builder.defineMacro("__tune__bdver1__"); + defineCPUMacros(Builder, "bdver1"); break; case CK_BDVER2: - Builder.defineMacro("__bdver2"); - Builder.defineMacro("__bdver2__"); - Builder.defineMacro("__tune__bdver2__"); + defineCPUMacros(Builder, "bdver2"); break; case CK_Geode: - Builder.defineMacro("__geode"); - Builder.defineMacro("__geode__"); - Builder.defineMacro("__tune_geode__"); + defineCPUMacros(Builder, "geode"); break; }