[clang] [llvm] [Clang][PowerPC] Add DMF crypto builtins for extended mnemonics (PR #185961)

Lei Huang via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 09:24:43 PDT 2026


================
@@ -1160,14 +1151,89 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
       Value *Acc = Builder.CreateLoad(Addr);
       CallOps.push_back(Acc);
     }
-    if (BuiltinID == PPC::BI__builtin_dmmr ||
-        BuiltinID == PPC::BI__builtin_dmxor ||
-        BuiltinID == PPC::BI__builtin_disassemble_dmr ||
+    if (BuiltinID == PPC::BI__builtin_mma_dmmr ||
+        BuiltinID == PPC::BI__builtin_mma_dmxor ||
+        BuiltinID == PPC::BI__builtin_mma_disassemble_dmr ||
         BuiltinID == PPC::BI__builtin_mma_dmsha2hash) {
       Address Addr = EmitPointerWithAlignment(E->getArg(1));
       Ops[1] = Builder.CreateLoad(Addr);
     }
-    if (BuiltinID == PPC::BI__builtin_disassemble_dmr)
+    if (BuiltinID == PPC::BI__builtin_dmsha256hash ||
+        BuiltinID == PPC::BI__builtin_dmsha512hash) {
+      Address Addr = EmitPointerWithAlignment(E->getArg(1));
+      Ops[1] = Builder.CreateLoad(Addr);
+      int Imm = (BuiltinID == PPC::BI__builtin_dmsha256hash) ? 0 : 1;
+      Ops.push_back(llvm::ConstantInt::get(Int32Ty, Imm));
+    }
+    if (BuiltinID == PPC::BI__builtin_dmsha3dw ||
+        BuiltinID == PPC::BI__builtin_dmcryshash) {
+      int Imm = (BuiltinID == PPC::BI__builtin_dmsha3dw) ? 0 : 12;
+      Ops.push_back(llvm::ConstantInt::get(Int32Ty, Imm));
+    }
+    if (BuiltinID == PPC::BI__builtin_dmxxsha3512pad ||
+        BuiltinID == PPC::BI__builtin_dmxxsha3384pad ||
+        BuiltinID == PPC::BI__builtin_dmxxsha3256pad ||
+        BuiltinID == PPC::BI__builtin_dmxxsha3224pad ||
+        BuiltinID == PPC::BI__builtin_dmxxshake256pad ||
+        BuiltinID == PPC::BI__builtin_dmxxshake128pad ||
+        BuiltinID == PPC::BI__builtin_dmxxsha384512pad ||
+        BuiltinID == PPC::BI__builtin_dmxxsha224256pad) {
+      int ID, BL;
+      bool hasE;
+      switch (BuiltinID) {
+      case PPC::BI__builtin_dmxxsha3512pad:
+        ID = 0;
+        BL = 0;
+        hasE = true;
+        break;
+      case PPC::BI__builtin_dmxxsha3384pad:
+        ID = 0;
+        BL = 1;
+        hasE = true;
+        break;
+      case PPC::BI__builtin_dmxxsha3256pad:
+        ID = 0;
+        BL = 2;
+        hasE = true;
+        break;
+      case PPC::BI__builtin_dmxxsha3224pad:
+        ID = 0;
+        BL = 3;
+        hasE = true;
+        break;
+      case PPC::BI__builtin_dmxxshake256pad:
+        ID = 1;
+        BL = 0;
+        hasE = true;
+        break;
+      case PPC::BI__builtin_dmxxshake128pad:
+        ID = 1;
+        BL = 1;
+        hasE = true;
+        break;
+      case PPC::BI__builtin_dmxxsha384512pad:
+        ID = 2;
+        BL = 0;
----------------
lei137 wrote:

I think it'll be easier to read if you break this up to handle "hasE=false" builtins in a separate if block:
```
if ( BuiltinID == PPC::BI__builtin_dmxxsha384512pad ||
      BuiltinID == PPC::BI__builtin_dmxxsha224256pad) {
   int Imm = (BuiltinID == PPC::BI__builtin_dmxxsha384512pad) ? 2 : 3;
   Ops.push_back(ConstantInt::get(Int32Ty, ID));
   Ops.push_back(ConstantInt::get(Int32Ty, 0));
   Ops.push_back(ConstantInt::get(Int32Ty, 0));
}
```

Then `Value *E_val = Ops[2];` can be placed at the top of the remaining `hasE=true` builtins to clearly show it's being saved for all the  builtins and location shifted at the end.

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


More information about the cfe-commits mailing list