[clang] [llvm] [AIX] Lower intrinsic __builtin_cpu_is into AIX platform-specific code. (PR #80069)

Amy Kwan via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 16 11:05:01 PST 2024


================
@@ -16542,12 +16542,62 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
 
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
 
+#include "llvm/TargetParser/PPCTargetParser.def"
+  // This lambda function converts builtin_cpu_is() into directly
+  // returning true or false, or it gets and checks the information from the
+  // kernel variable _system_configuration fromr the AIX OS.
+  auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx,
+                                     unsigned CompOp,
+                                     unsigned OpValue) -> Value * {
+    if (SupportMethod == AIX_BUILTIN_PPC_FALSE)
+      return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
+
+    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 supports 32-bit integer in the GenAIXPPCBuiltinCpuExpr.");
----------------
amy-kwan wrote:

```suggestion
           "Only 32-bit integers are supported the GenAIXPPCBuiltinCpuExpr().");
```
I think this may be clearer.

https://github.com/llvm/llvm-project/pull/80069


More information about the cfe-commits mailing list