[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)
Amy Kwan via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 12:13:01 PST 2024
================
@@ -16542,12 +16542,64 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
Intrinsic::ID ID = Intrinsic::not_intrinsic;
+ // The lambda function converts builtin_cpu_is function into directly
+ // returning false or true, or it gets and checks the information from the
+ // kernel variable _system_configuration for AIX OS.
+
+#include "llvm/TargetParser/PPCTargetParser.def"
+ auto ConvBuiltinCpu = [&](unsigned SupportMagic, unsigned FieldIdx,
+ unsigned CompOp, unsigned OpValue) -> Value * {
+ if (SupportMagic == AIX_BUILTIN_PPC_FALSE)
+ return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
+
+ if (SupportMagic == AIX_BUILTIN_PPC_TRUE)
+ return llvm::ConstantInt::getTrue(ConvertType(E->getType()));
+
+ assert(SupportMagic <= SYS_CONF && "Invalid value for SupportMagic.");
+ 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((CompOp == COMP_EQ) && "Only equal comparisons are supported!");
+
+ assert(FieldValue->getType()->isIntegerTy(32) &&
+ "Only supports 32-bit integer in the GetOpRes.");
+
+ 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 ConvBuiltinCpu(IsCpuSupport, FieldIdx, CompareOp, CpuIdValue);
+ }
+
+ assert(Triple.isOSLinux() && "Triple for AIX OS has already been checked; "
+ "it must be Linux OS here.");
----------------
amy-kwan wrote:
Comment should be updated to something like:
```
__builtin_cpu_is() is only supported for AIX and Linux.
```
For here and on line 915 on `PPC.cpp`.
https://github.com/llvm/llvm-project/pull/80069
More information about the llvm-commits
mailing list