-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AIX] Lower intrinsic __builtin_cpu_is into AIX platform-specific code. #80069
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 all commits
a82a60e
6dfd528
e0eb549
e019084
7ebb81a
a33b383
1bc9e3c
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 |
---|---|---|
|
@@ -16542,12 +16542,59 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, | |
|
||
Intrinsic::ID ID = Intrinsic::not_intrinsic; | ||
|
||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
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. This is getting a bit tangled. Can you please provide two static functions: 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 the function is too short, It not worth to have a two separate static functions. and I reorganize the code in other way. |
||
auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx, | ||
unsigned CompOp, | ||
unsigned OpValue) -> Value * { | ||
if (SupportMethod == AIX_BUILTIN_PPC_FALSE) | ||
return llvm::ConstantInt::getFalse(ConvertType(E->getType())); | ||
diggerlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (SupportMethod == AIX_BUILTIN_PPC_TRUE) | ||
return llvm::ConstantInt::getTrue(ConvertType(E->getType())); | ||
|
||
assert(SupportMethod <= USE_SYS_CONF && "Invalid value for SupportMethod."); | ||
assert((CompOp == COMP_EQ) && "Only equal comparisons are supported."); | ||
|
||
llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE); | ||
llvm::Constant *SysConf = | ||
CGM.CreateRuntimeVariable(STy, "_system_configuration"); | ||
|
||
// Grab the appropriate field from _system_configuration. | ||
llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0), | ||
ConstantInt::get(Int32Ty, FieldIdx)}; | ||
|
||
llvm::Value *FieldValue = Builder.CreateGEP(STy, SysConf, Idxs); | ||
FieldValue = Builder.CreateAlignedLoad(Int32Ty, FieldValue, | ||
CharUnits::fromQuantity(4)); | ||
assert(FieldValue->getType()->isIntegerTy(32) && | ||
"Only 32-bit integers are supported in GenAIXPPCBuiltinCpuExpr()."); | ||
return Builder.CreateICmp(ICmpInst::ICMP_EQ, FieldValue, | ||
ConstantInt::get(Int32Ty, OpValue)); | ||
}; | ||
|
||
switch (BuiltinID) { | ||
default: return nullptr; | ||
|
||
case Builtin::BI__builtin_cpu_is: { | ||
const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts(); | ||
StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString(); | ||
llvm::Triple Triple = getTarget().getTriple(); | ||
|
||
if (Triple.isOSAIX()) { | ||
unsigned IsCpuSupport, FieldIdx, CompareOp, CpuIdValue; | ||
typedef std::tuple<unsigned, unsigned, unsigned, unsigned> CPUType; | ||
std::tie(IsCpuSupport, FieldIdx, CompareOp, CpuIdValue) = | ||
static_cast<CPUType>(StringSwitch<CPUType>(CPUStr) | ||
#define PPC_AIX_CPU(NAME, SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE) \ | ||
.Case(NAME, {SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE}) | ||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
); | ||
return GenAIXPPCBuiltinCpuExpr(IsCpuSupport, FieldIdx, CompareOp, | ||
CpuIdValue); | ||
} | ||
|
||
assert(Triple.isOSLinux() && | ||
"__builtin_cpu_is() is only supported for AIX and Linux."); | ||
unsigned NumCPUID = StringSwitch<unsigned>(CPUStr) | ||
#define PPC_LNX_CPU(Name, NumericID) .Case(Name, NumericID) | ||
#include "llvm/TargetParser/PPCTargetParser.def" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// RUN: echo "int main() { return __builtin_cpu_is(\"ppc970\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"ppc-cell-be\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"ppca2\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"ppc405\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"ppc440\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"ppc464\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"ppc476\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power4\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power5\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power5+\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power6\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power6x\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power7\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DVALUE=32768 \ | ||
// RUN: --check-prefix=CHECKOP | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power8\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DVALUE=65536 \ | ||
// RUN: --check-prefix=CHECKOP | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power9\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DVALUE=131072\ | ||
// RUN: --check-prefix=CHECKOP | ||
|
||
// RUN: echo "int main() { return __builtin_cpu_is(\"power10\");}" > %t.c | ||
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DVALUE=262144 \ | ||
// RUN: --check-prefix=CHECKOP | ||
|
||
// CHECK: define i32 @main() #0 { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: %retval = alloca i32, align 4 | ||
// CHECK-NEXT: store i32 0, ptr %retval, align 4 | ||
// CHECK-NEXT: ret i32 0 | ||
// CHECK-NEXT: } | ||
|
||
// CHECKOP: @_system_configuration = external global { i32, i32, i32 } | ||
// CHECKOP: define i32 @main() #0 { | ||
// CHECKOP-NEXT: entry: | ||
// CHECKOP-NEXT: %retval = alloca i32, align 4 | ||
// CHECKOP-NEXT: store i32 0, ptr %retval, align 4 | ||
// CHECKOP-NEXT: %0 = load i32, ptr getelementptr inbounds ({ i32, i32, i32 }, ptr @_system_configuration, i32 0, i32 1), align 4 | ||
amy-kwan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECKOP-NEXT: %1 = icmp eq i32 %0, [[VALUE]] | ||
// CHECKOP-NEXT: %conv = zext i1 %1 to i32 | ||
// CHECKOP-NEXT: ret i32 %conv | ||
// CHECKOP-NEXT: } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -triple powerpc-ibm-aix7.1.0.0 -verify %s | ||
|
||
int main(void) { | ||
if (__builtin_cpu_is("power8")) // expected-error {{this builtin is available only on AIX 7.2 and later operating systems}} | ||
return 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,4 +126,61 @@ PPC_LNX_CPU("power10",47) | |
#undef PPC_LNX_DEFINE_OFFSETS | ||
#undef PPC_LNX_FEATURE | ||
#undef PPC_LNX_CPU | ||
|
||
// Definition of the following values are found in the AIX header | ||
// file: </usr/include/sys/systemcfg.h>. | ||
#ifndef AIX_POWERPC_USE_SYS_CONF | ||
#define AIX_POWERPC_USE_SYS_CONF | ||
#define AIX_SYSCON_IMPL_IDX 1 | ||
#define AIX_PPC7_VALUE 0x00008000 | ||
#define AIX_PPC8_VALUE 0x00010000 | ||
#define AIX_PPC9_VALUE 0x00020000 | ||
#define AIX_PPC10_VALUE 0x00040000 | ||
|
||
// Supported SUPPORT_METHOD values. | ||
#define AIX_BUILTIN_PPC_TRUE 1 | ||
lei137 marked this conversation as resolved.
Show resolved
Hide resolved
lei137 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#define AIX_BUILTIN_PPC_FALSE 0 | ||
#define USE_SYS_CONF 2 | ||
|
||
// Supported COMPARE_OP values. | ||
#define COMP_EQ 0 | ||
lei137 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#endif | ||
|
||
// The value of SUPPORT_METHOD can be AIX_BUILTIN_PPC_TRUE, | ||
// AIX_BUILTIN_PPC_FALSE, or USE_SYS_CONF. | ||
// When the value of SUPPORT_METHOD is USE_SYS_CONF, the return value | ||
// depends on the result of comparing the data member of | ||
// _system_configuration specified by INDEX with a certain value. | ||
|
||
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. Remove this new line, to clearly show that the comment is applicable to this define specifically. 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 this new line should still be removed. 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. agreed |
||
#ifndef PPC_AIX_CPU | ||
#define PPC_AIX_CPU(NAME, SUPPORT_METHOD, INDEX, COMPARE_OP, VALUE) | ||
#endif | ||
|
||
// __builtin_cpu_is() is supported only on Power7 and up. | ||
PPC_AIX_CPU("power4",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("ppc970",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("power5",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("power5+",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("power6",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("ppc-cell-be",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("power6x",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("ppca2",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("ppc405",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("ppc440",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("ppc464",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("ppc476",AIX_BUILTIN_PPC_FALSE,0,0,0) | ||
PPC_AIX_CPU("power7",USE_SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC7_VALUE) | ||
PPC_AIX_CPU("power8",USE_SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC8_VALUE) | ||
PPC_AIX_CPU("power9",USE_SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC9_VALUE) | ||
PPC_AIX_CPU("power10",USE_SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC10_VALUE) | ||
#undef PPC_AIX_CPU | ||
|
||
// PPC_SYSTEMCONFIG_TYPE defines the IR data structure of kernel variable | ||
// `_system_configuration`, that is found in the AIX OS header file: </usr/include/sys/systemcfg.h>. | ||
#ifndef PPC_SYSTEMCONFIG_TYPE | ||
lei137 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#define PPC_SYSTEMCONFIG_TYPE \ | ||
Int32Ty, Int32Ty, Int32Ty | ||
#endif | ||
|
||
#endif // !PPC_TGT_PARSER_UNDEF_MACROS |
Uh oh!
There was an error while loading. Please reload this page.