Skip to content

Commit 557e716

Browse files
committed
Implement a subset of builtin_cpu_supports() features
1 parent 1c2b79a commit 557e716

File tree

9 files changed

+356
-39
lines changed

9 files changed

+356
-39
lines changed

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,19 @@ ArrayRef<Builtin::Info> PPCTargetInfo::getTargetBuiltins() const {
897897
}
898898

899899
bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
900+
llvm::Triple Triple = getTriple();
901+
if (Triple.isOSAIX()) {
902+
#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP, \
903+
VALUE) \
904+
.Case(NAME, true)
905+
return llvm::StringSwitch<bool>(FeatureStr)
906+
#include "llvm/TargetParser/PPCTargetParser.def"
907+
.Default(false);
908+
}
909+
910+
assert(Triple.isOSLinux() &&
911+
"__builtin_cpu_supports() is only supported for AIX and Linux.");
912+
900913
#define PPC_LNX_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, true)
901914
return llvm::StringSwitch<bool>(FeatureStr)
902915
#include "llvm/TargetParser/PPCTargetParser.def"
@@ -906,7 +919,7 @@ bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
906919
bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
907920
llvm::Triple Triple = getTriple();
908921
if (Triple.isOSAIX()) {
909-
#define PPC_AIX_CPU(NAME, SUPPORT, INDEX, OP, VALUE) .Case(NAME, true)
922+
#define PPC_AIX_CPU(NAME, SUPPORT_METHOD, INDEX, OP, VALUE) .Case(NAME, true)
910923
return llvm::StringSwitch<bool>(CPUName)
911924
#include "llvm/TargetParser/PPCTargetParser.def"
912925
.Default(false);

clang/lib/Basic/Targets/PPC.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,14 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
364364
// have Glibc since it is Glibc that provides the HWCAP[2] in the auxv.
365365
static constexpr int MINIMUM_AIX_OS_MAJOR = 7;
366366
static constexpr int MINIMUM_AIX_OS_MINOR = 2;
367-
bool supportsCpuSupports() const override { return getTriple().isOSGlibc(); }
367+
bool supportsCpuSupports() const override {
368+
llvm::Triple Triple = getTriple();
369+
// AIX 7.2 is the minimum requirement to support __builtin_cpu_supports().
370+
return Triple.isOSGlibc() ||
371+
(Triple.isOSAIX() &&
372+
!Triple.isOSVersionLT(MINIMUM_AIX_OS_MAJOR, MINIMUM_AIX_OS_MINOR));
373+
}
374+
368375
bool supportsCpuIs() const override {
369376
llvm::Triple Triple = getTriple();
370377
// AIX 7.2 is the minimum requirement to support __builtin_cpu_is().

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16570,32 +16570,72 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
1657016570

1657116571
#include "llvm/TargetParser/PPCTargetParser.def"
1657216572
auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx,
16573-
unsigned CompOp,
16573+
unsigned Mask, unsigned CompOp,
1657416574
unsigned OpValue) -> Value * {
1657516575
if (SupportMethod == AIX_BUILTIN_PPC_FALSE)
1657616576
return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
1657716577

1657816578
if (SupportMethod == AIX_BUILTIN_PPC_TRUE)
1657916579
return llvm::ConstantInt::getTrue(ConvertType(E->getType()));
1658016580

16581-
assert(SupportMethod <= USE_SYS_CONF && "Invalid value for SupportMethod.");
16582-
assert((CompOp == COMP_EQ) && "Only equal comparisons are supported.");
16581+
assert(SupportMethod <= SYS_CALL && "Invalid value for SupportMethod.");
16582+
16583+
llvm::Value *FieldValue = nullptr;
16584+
if (SupportMethod == USE_SYS_CONF) {
16585+
llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
16586+
llvm::Constant *SysConf =
16587+
CGM.CreateRuntimeVariable(STy, "_system_configuration");
16588+
16589+
// Grab the appropriate field from _system_configuration.
16590+
llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0),
16591+
ConstantInt::get(Int32Ty, FieldIdx)};
16592+
16593+
FieldValue = Builder.CreateGEP(STy, SysConf, Idxs);
16594+
FieldValue = Builder.CreateAlignedLoad(Int32Ty, FieldValue,
16595+
CharUnits::fromQuantity(4));
16596+
} else if (SupportMethod == SYS_CALL) {
16597+
llvm::FunctionType *FTy =
16598+
llvm::FunctionType::get(Int64Ty, Int32Ty, false);
16599+
llvm::FunctionCallee Func =
16600+
CGM.CreateRuntimeFunction(FTy, "getsystemcfg");
16601+
16602+
FieldValue =
16603+
Builder.CreateCall(Func, {ConstantInt::get(Int32Ty, FieldIdx)});
16604+
}
16605+
assert((FieldValue != nullptr) &&
16606+
"SupportMethod value is not defined in PPCTargetParser.def.");
16607+
16608+
if (Mask)
16609+
FieldValue = Builder.CreateAnd(FieldValue, Mask);
1658316610

16584-
llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
16585-
llvm::Constant *SysConf =
16586-
CGM.CreateRuntimeVariable(STy, "_system_configuration");
16611+
CmpInst::Predicate PreOp;
16612+
switch (CompOp) {
16613+
case COMP_EQ:
16614+
PreOp = ICmpInst::ICMP_EQ;
16615+
break;
16616+
case COMP_GT:
16617+
PreOp = ICmpInst::ICMP_UGT;
16618+
break;
16619+
case COMP_GE:
16620+
PreOp = ICmpInst::ICMP_UGE;
16621+
break;
16622+
case COMP_NE:
16623+
PreOp = ICmpInst::ICMP_NE;
16624+
break;
16625+
default:
16626+
llvm_unreachable(
16627+
"Compare type does not match types defined in PPCTargetParser.def!");
16628+
}
1658716629

16588-
// Grab the appropriate field from _system_configuration.
16589-
llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0),
16590-
ConstantInt::get(Int32Ty, FieldIdx)};
16630+
llvm::Type *ValueType = FieldValue->getType();
16631+
bool IsValueType64Bit = ValueType->isIntegerTy(64);
16632+
assert(
16633+
(IsValueType64Bit || ValueType->isIntegerTy(32)) &&
16634+
"Only 32/64-bit integers are supported in GenAIXPPCBuiltinCpuExpr().");
1659116635

16592-
llvm::Value *FieldValue = Builder.CreateGEP(STy, SysConf, Idxs);
16593-
FieldValue = Builder.CreateAlignedLoad(Int32Ty, FieldValue,
16594-
CharUnits::fromQuantity(4));
16595-
assert(FieldValue->getType()->isIntegerTy(32) &&
16596-
"Only 32-bit integers are supported in GenAIXPPCBuiltinCpuExpr().");
16597-
return Builder.CreateICmp(ICmpInst::ICMP_EQ, FieldValue,
16598-
ConstantInt::get(Int32Ty, OpValue));
16636+
return Builder.CreateICmp(
16637+
PreOp, FieldValue,
16638+
ConstantInt::get(IsValueType64Bit ? Int64Ty : Int32Ty, OpValue));
1659916639
};
1660016640

1660116641
switch (BuiltinID) {
@@ -16607,15 +16647,15 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
1660716647
llvm::Triple Triple = getTarget().getTriple();
1660816648

1660916649
if (Triple.isOSAIX()) {
16610-
unsigned IsCpuSupport, FieldIdx, CompareOp, CpuIdValue;
16650+
unsigned SupportMethod, FieldIdx, CompareOp, CpuIdValue;
1661116651
typedef std::tuple<unsigned, unsigned, unsigned, unsigned> CPUType;
16612-
std::tie(IsCpuSupport, FieldIdx, CompareOp, CpuIdValue) =
16652+
std::tie(SupportMethod, FieldIdx, CompareOp, CpuIdValue) =
1661316653
static_cast<CPUType>(StringSwitch<CPUType>(CPUStr)
16614-
#define PPC_AIX_CPU(NAME, SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE) \
16615-
.Case(NAME, {SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE})
16654+
#define PPC_AIX_CPU(NAME, SUPPORT_METHOD, INDEX, COMPARE_OP, VALUE) \
16655+
.Case(NAME, {SUPPORT_METHOD, INDEX, COMPARE_OP, VALUE})
1661616656
#include "llvm/TargetParser/PPCTargetParser.def"
1661716657
);
16618-
return GenAIXPPCBuiltinCpuExpr(IsCpuSupport, FieldIdx, CompareOp,
16658+
return GenAIXPPCBuiltinCpuExpr(SupportMethod, FieldIdx, 0, CompareOp,
1661916659
CpuIdValue);
1662016660
}
1662116661

@@ -16633,10 +16673,28 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
1663316673
llvm::ConstantInt::get(Int32Ty, NumCPUID));
1663416674
}
1663516675
case Builtin::BI__builtin_cpu_supports: {
16636-
unsigned FeatureWord;
16637-
unsigned BitMask;
16676+
llvm::Triple Triple = getTarget().getTriple();
1663816677
const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts();
1663916678
StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
16679+
if (Triple.isOSAIX()) {
16680+
unsigned SupportMethod, FieldIdx, Mask, CompOp, Value;
16681+
typedef std::tuple<unsigned, unsigned, unsigned, unsigned, unsigned>
16682+
CPUSupportType;
16683+
std::tie(SupportMethod, FieldIdx, Mask, CompOp, Value) =
16684+
static_cast<CPUSupportType>(StringSwitch<CPUSupportType>(CPUStr)
16685+
#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP, \
16686+
VALUE) \
16687+
.Case(NAME, {SUPPORT_METHOD, INDEX, MASK, COMP_OP, VALUE})
16688+
#include "llvm/TargetParser/PPCTargetParser.def"
16689+
);
16690+
return GenAIXPPCBuiltinCpuExpr(SupportMethod, FieldIdx, Mask, CompOp,
16691+
Value);
16692+
}
16693+
16694+
assert(Triple.isOSLinux() &&
16695+
"__builtin_cpu_supports() is only supported for AIX and Linux.");
16696+
unsigned FeatureWord;
16697+
unsigned BitMask;
1664016698
std::tie(FeatureWord, BitMask) =
1664116699
StringSwitch<std::pair<unsigned, unsigned>>(CPUStr)
1664216700
#define PPC_LNX_FEATURE(Name, Description, EnumName, Bitmask, FA_WORD) \

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,10 +2162,8 @@ static bool SemaBuiltinCpu(Sema &S, const TargetInfo &TI, CallExpr *TheCall,
21622162
if (!SupportsBI(&TI) && SupportsBI(AuxTI))
21632163
TheTI = AuxTI;
21642164

2165-
if (IsCPUSupports && !TheTI->supportsCpuSupports())
2166-
return S.Diag(TheCall->getBeginLoc(), diag::err_builtin_target_unsupported)
2167-
<< SourceRange(TheCall->getBeginLoc(), TheCall->getEndLoc());
2168-
if (!IsCPUSupports && !TheTI->supportsCpuIs())
2165+
if ((!IsCPUSupports && !TheTI->supportsCpuIs()) ||
2166+
(IsCPUSupports && !TheTI->supportsCpuSupports()))
21692167
return S.Diag(TheCall->getBeginLoc(),
21702168
TI.getTriple().isOSAIX()
21712169
? diag::err_builtin_aix_os_unsupported

clang/test/CodeGen/aix-builtin-cpu-is.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
// CHECK-NEXT: ret i32 0
5858
// CHECK-NEXT: }
5959

60-
// CHECKOP: @_system_configuration = external global { i32, i32, i32 }
60+
// CHECKOP: @_system_configuration = external global { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i32, i32, i32, i32, i64, i64, i64, i64, i32, i32, i32, i32, i32, i32, i64, i32, i8, i8, i8, i8, i32, i32, i16, i16, [3 x i32], i32 }
6161
// CHECKOP: define i32 @main() #0 {
6262
// CHECKOP-NEXT: entry:
6363
// CHECKOP-NEXT: %retval = alloca i32, align 4
6464
// CHECKOP-NEXT: store i32 0, ptr %retval, align 4
65-
// CHECKOP-NEXT: %0 = load i32, ptr getelementptr inbounds ({ i32, i32, i32 }, ptr @_system_configuration, i32 0, i32 1), align 4
65+
// CHECKOP-NEXT: %0 = load i32, ptr getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i32, i32, i32, i32, i64, i64, i64, i64, i32, i32, i32, i32, i32, i32, i64, i32, i8, i8, i8, i8, i32, i32, i16, i16, [3 x i32], i32 }, ptr @_system_configuration, i32 0, i32 1), align 4
6666
// CHECKOP-NEXT: %1 = icmp eq i32 %0, [[VALUE]]
6767
// CHECKOP-NEXT: %conv = zext i1 %1 to i32
6868
// CHECKOP-NEXT: ret i32 %conv
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// RUN: echo "int main() { return __builtin_cpu_supports(\"4xxmac\");}" > %t.c
2+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
3+
4+
// RUN: echo "int main() { return __builtin_cpu_supports(\"altivec\");}" > %t.c
5+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=46 -DOP=ugt -DBIT=i32 -DVALUE=0 \
6+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
7+
8+
// RUN: echo "int main() { return __builtin_cpu_supports(\"booke\");}" > %t.c
9+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
10+
11+
// RUN: echo "int main() { return __builtin_cpu_supports(\"cellbe\");}" > %t.c
12+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
13+
14+
// RUN: echo "int main() { return __builtin_cpu_supports(\"darn\");}" > %t.c
15+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=1 -DOP=uge -DBIT=i32 -DVALUE=262144 \
16+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
17+
18+
// RUN: echo "int main() { return __builtin_cpu_supports(\"efpdouble\");}" > %t.c
19+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
20+
21+
// RUN: echo "int main() { return __builtin_cpu_supports(\"efpsingle\");}" > %t.c
22+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
23+
24+
// RUN: echo "int main() { return __builtin_cpu_supports(\"pa6t\");}" > %t.c
25+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
26+
27+
// RUN: echo "int main() { return __builtin_cpu_supports(\"fpu\");}" > %t.c
28+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
29+
30+
// RUN: echo "int main() { return __builtin_cpu_supports(\"htm\");}" > %t.c
31+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=1 -DOP=ugt -DLABLE=59 -DBIT=i64 -DVALUE=0 \
32+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCALL
33+
34+
// RUN: echo "int main() { return __builtin_cpu_supports(\"mma\");}" > %t.c
35+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=1 -DOP=ugt -DLABLE=62 -DBIT=i64 -DVALUE=0 \
36+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCALL
37+
38+
// RUN: echo "int main() { return __builtin_cpu_supports(\"mmu\");}" > %t.c
39+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
40+
41+
// RUN: echo "int main() { return __builtin_cpu_supports(\"arch_2_05\");}" > %t.c
42+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
43+
44+
// RUN: echo "int main() { return __builtin_cpu_supports(\"arch_2_06\");}" > %t.c
45+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=1 -DOP=uge -DBIT=i32 -DVALUE=32768 \
46+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
47+
48+
// RUN: echo "int main() { return __builtin_cpu_supports(\"arch_2_07\");}" > %t.c
49+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=1 -DOP=uge -DBIT=i32 -DVALUE=65536 \
50+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
51+
52+
// RUN: echo "int main() { return __builtin_cpu_supports(\"arch_3_00\");}" > %t.c
53+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=1 -DOP=uge -DBIT=i32 -DVALUE=131072 \
54+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
55+
56+
// RUN: echo "int main() { return __builtin_cpu_supports(\"arch_3_1\");}" > %t.c
57+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=1 -DOP=uge -DBIT=i32 -DVALUE=262144 \
58+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
59+
60+
// RUN: echo "int main() { return __builtin_cpu_supports(\"dfp\");}" > %t.c
61+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=53 -DOP=ne -DBIT=i32 -DVALUE=0 \
62+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
63+
64+
// RUN: echo "int main() { return __builtin_cpu_supports(\"power4\");}" > %t.c
65+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
66+
67+
// RUN: echo "int main() { return __builtin_cpu_supports(\"power5\");}" > %t.c
68+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
69+
70+
// RUN: echo "int main() { return __builtin_cpu_supports(\"power5+\");}" > %t.c
71+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
72+
73+
// RUN: echo "int main() { return __builtin_cpu_supports(\"power6x\");}" > %t.c
74+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
75+
76+
// RUN: echo "int main() { return __builtin_cpu_supports(\"ppc32\");}" > %t.c
77+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
78+
79+
// RUN: echo "int main() { return __builtin_cpu_supports(\"ppc601\");}" > %t.c
80+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
81+
82+
// RUN: echo "int main() { return __builtin_cpu_supports(\"ppc64\");}" > %t.c
83+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
84+
85+
// RUN: echo "int main() { return __builtin_cpu_supports(\"ppcle\");}" > %t.c
86+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
87+
88+
// RUN: echo "int main() { return __builtin_cpu_supports(\"smt\");}" > %t.c
89+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=44 -DMASK=3 -DOP=eq -DBIT=i32 -DVALUE=3 \
90+
// RUN: --check-prefixes=CHECKOP,OPMASK,SYSCONF
91+
92+
// RUN: echo "int main() { return __builtin_cpu_supports(\"spe\");}" > %t.c
93+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=0 %s
94+
95+
// RUN: echo "int main() { return __builtin_cpu_supports(\"true_le\");}" > %t.c
96+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck -DBOOL=1 %s
97+
98+
// RUN: echo "int main() { return __builtin_cpu_supports(\"ucache\");}" > %t.c
99+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=5 -DMASK=2 -DOP=eq -DBIT=i32 -DVALUE=2 \
100+
// RUN: --check-prefixes=CHECKOP,OPMASK,SYSCONF
101+
102+
// RUN: echo "int main() { return __builtin_cpu_supports(\"vsx\");}" > %t.c
103+
// RUN: %clang_cc1 -triple powerpc-ibm-aix7.2.0.0 -emit-llvm -o - %t.c | FileCheck %s -DPOS=46 -DOP=ugt -DBIT=i32 -DVALUE=1 \
104+
// RUN: --check-prefixes=CHECKOP,OPRT,SYSCONF
105+
106+
// CHECK: define i32 @main() #0 {
107+
// CHECK-NEXT: entry:
108+
// CHECK-NEXT: %retval = alloca i32, align 4
109+
// CHECK-NEXT: store i32 0, ptr %retval, align 4
110+
// CHECK-NEXT: ret i32 [[BOOL]]
111+
// CHECK-NEXT: }
112+
113+
// SYSCONF: @_system_configuration = external global { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i32, i32, i32, i32, i64, i64, i64, i64, i32, i32, i32, i32, i32, i32, i64, i32, i8, i8, i8, i8, i32, i32, i16, i16, [3 x i32], i32 }
114+
115+
// CHECKOP: define i32 @main() #0 {
116+
// CHECKOP-NEXT: entry:
117+
// CHECKOP-NEXT: %retval = alloca i32, align 4
118+
// CHECKOP-NEXT: store i32 0, ptr %retval, align 4
119+
120+
// SYSCONF-NEXT: %0 = load i32, ptr getelementptr inbounds ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i32, i32, i32, i32, i64, i64, i64, i64, i32, i32, i32, i32, i32, i32, i64, i32, i8, i8, i8, i8, i32, i32, i16, i16, [3 x i32], i32 }, ptr @_system_configuration, i32 0, i32 [[POS]]), align 4
121+
// SYSCALL-NEXT: %0 = call i64 @getsystemcfg(i32 [[LABLE]])
122+
123+
// OPRT-NEXT: %1 = icmp [[OP]] [[BIT]] %0, [[VALUE]]
124+
// OPRT-NEXT: %conv = zext i1 %1 to i32
125+
126+
// OPMASK-NEXT: %1 = and i32 %0, [[MASK]]
127+
// OPMASK-NEXT: %2 = icmp [[OP]] i32 %1, [[VALUE]]
128+
// OPMASK-NEXT: %conv = zext i1 %2 to i32
129+
130+
// CHECKOP-NEXT: ret i32 %conv
131+
// CHECKOP-NEXT: }
132+
133+
// SYSCALL: declare i64 @getsystemcfg(i32)
134+
135+

0 commit comments

Comments
 (0)