[clang] [CIR][X86] Add support for `cpuid`/`cpuidex` (PR #173197)
Roberto Turrado Camblor via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 7 14:31:34 PST 2026
https://github.com/rturrado updated https://github.com/llvm/llvm-project/pull/173197
>From 412f88f726643427c3be6137028d4938878d3ef3 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Fri, 19 Dec 2025 21:02:27 +0100
Subject: [PATCH 1/5] [CIR][X86] Add support for cpuid/cpuidex
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 27 +++++++
clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp | 12 +++-
.../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 70 +++++++++++++++++++
3 files changed, 108 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 7e7424fd71878..7d05fce0fdf09 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -5762,4 +5762,31 @@ def CIR_BlockAddressOp : CIR_Op<"block_address", [Pure]> {
}];
}
+//===----------------------------------------------------------------------===//
+// CpuIdOp
+//===----------------------------------------------------------------------===//
+
+def CIR_CpuIdOp : CIR_Op<"cpuid"> {
+ let summary = "Get information about the CPU";
+ let description = [{
+ The `cir.cpuid` operation takes a base pointer to an array of 4 integers, a
+ function ID and a sub-function ID. The array of 4 integers is filled with
+ different information about the processor.
+
+ Example:
+
+ ```mlir
+ cir.cpuid %basePtr, %funcId, %subFuncId
+ : (!cir.ptr<!cir.array<4 x !s32i>>, !s32i, !s32i)
+ ```
+ }];
+
+ let arguments =
+ (ins Arg<CIR_PtrToArray, "array address", [MemWrite]>:$basePtr,
+ CIR_SInt32:$funcId, CIR_SInt32:$subFuncId);
+ // TODO: remove once we can return an optional mlir::Value from
+ // emitX86BuiltinExpr
+ let results = (outs CIR_VectorType:$result);
+}
+
#endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index 1c87e945de846..bf9810eff498d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -25,6 +25,7 @@
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "clang/CIR/MissingFeatures.h"
#include "llvm/ADT/Sequence.h"
+#include "llvm/IR/InlineAsm.h"
#include "llvm/Support/ErrorHandling.h"
#include <string>
@@ -1835,7 +1836,16 @@ CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr) {
case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
case X86::BI__builtin_ia32_cvtneps2bf16_512_mask:
case X86::BI__cpuid:
- case X86::BI__cpuidex:
+ case X86::BI__cpuidex: {
+ mlir::Location loc = getLoc(expr->getExprLoc());
+ mlir::Type i32Ty = builder.getSInt32Ty();
+ mlir::Value subFuncId = builtinID == X86::BI__cpuidex
+ ? ops[2]
+ : builder.getConstInt(loc, sInt32Ty, 0);
+ cir::CpuIdOp::create(builder, loc, i32Ty, /*basePtr=*/ops[0],
+ /*funcId=*/ops[1], /*subFuncId=*/subFuncId);
+ return mlir::Value{};
+ }
case X86::BI__emul:
case X86::BI__emulu:
case X86::BI__mulh:
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index eb0a219f18618..24924085ea9ea 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -4193,6 +4193,76 @@ mlir::LogicalResult CIRToLLVMAwaitOpLowering::matchAndRewrite(
return mlir::failure();
}
+mlir::LogicalResult CIRToLLVMCpuIdOpLowering::matchAndRewrite(
+ cir::CpuIdOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ mlir::Type i32Ty = rewriter.getI32Type();
+ mlir::Type i64Ty = rewriter.getI64Type();
+ mlir::Type i32PtrTy = mlir::LLVM::LLVMPointerType::get(i32Ty.getContext(), 0);
+
+ mlir::Type cpuidRetTy = mlir::LLVM::LLVMStructType::getLiteral(
+ rewriter.getContext(), {i32Ty, i32Ty, i32Ty, i32Ty});
+
+ mlir::Value funcId = adaptor.getFuncId();
+ mlir::Value subFuncId = adaptor.getSubFuncId();
+ mlir::StringAttr opNameAttr = op->getAttrOfType<mlir::StringAttr>("name");
+ if (!opNameAttr)
+ return mlir::failure();
+ if (opNameAttr.getValue() == "cpuid")
+ subFuncId = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(), i32Ty, 0);
+ std::vector operands{funcId, subFuncId};
+
+ StringRef asmString, constraints;
+ mlir::ModuleOp moduleOp = op->getParentOfType<mlir::ModuleOp>();
+ mlir::StringAttr tripleAttr =
+ moduleOp->getAttrOfType<mlir::StringAttr>("llvm.target_triple");
+ if (!tripleAttr)
+ return mlir::failure();
+ llvm::Triple triple(tripleAttr.getValue().str());
+ if (triple.getArch() == llvm::Triple::x86) {
+ asmString = "cpuid";
+ constraints = "={ax},={bx},={cx},={dx},{ax},{cx}";
+ } else {
+ // x86-64 uses %rbx as the base register, so preserve it.
+ asmString = "xchgq %rbx, ${1:q}\n"
+ "cpuid\n"
+ "xchgq %rbx, ${1:q}";
+ constraints = "={ax},=r,={cx},={dx},0,2";
+ }
+
+ mlir::Value inlineAsm =
+ mlir::LLVM::InlineAsmOp::create(
+ rewriter, op.getLoc(), cpuidRetTy, mlir::ValueRange(operands),
+ rewriter.getStringAttr(asmString),
+ rewriter.getStringAttr(constraints),
+ /*has_side_effects=*/mlir::UnitAttr{},
+ /*is_align_stack=*/mlir::UnitAttr{},
+ /*tail_call_kind=*/mlir::LLVM::TailCallKindAttr{},
+ /*asm_dialect=*/mlir::LLVM::AsmDialectAttr{},
+ /*operand_attrs=*/mlir::ArrayAttr{})
+ .getResult(0);
+
+ mlir::Value basePtr = adaptor.getBasePtr();
+
+ mlir::DataLayout layout(op->getParentOfType<mlir::ModuleOp>());
+ unsigned alignment = layout.getTypeABIAlignment(i32Ty);
+ for (unsigned i = 0; i < 4; i++) {
+ mlir::Value extracted =
+ mlir::LLVM::ExtractValueOp::create(rewriter, op.getLoc(), inlineAsm, i)
+ .getResult();
+ mlir::Value index = mlir::LLVM::ConstantOp::create(
+ rewriter, op.getLoc(), i64Ty, rewriter.getI64IntegerAttr(i));
+ llvm::SmallVector<mlir::Value, 1> gepIndices = {index};
+ mlir::Value storePtr = mlir::LLVM::GEPOp::create(
+ rewriter, op.getLoc(), i32PtrTy, i32Ty, basePtr,
+ gepIndices, mlir::LLVM::GEPNoWrapFlags::none)
+ .getResult();
+ mlir::LLVM::StoreOp::create(rewriter, op.getLoc(), extracted, storePtr,
+ alignment);
+ }
+ return mlir::success();
+}
+
std::unique_ptr<mlir::Pass> createConvertCIRToLLVMPass() {
return std::make_unique<ConvertCIRToLLVMPass>();
}
>From b0bd92f704dde29fe1fec1e8666aa0319118ae80 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Thu, 25 Dec 2025 19:32:54 +0100
Subject: [PATCH 2/5] Address review comments from Lancern
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 18 ++++++++++-----
clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp | 5 ++++-
clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 22 +++++++++++++++++++
.../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 19 +++++-----------
4 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 7d05fce0fdf09..3c5957ec200d7 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -5769,9 +5769,16 @@ def CIR_BlockAddressOp : CIR_Op<"block_address", [Pure]> {
def CIR_CpuIdOp : CIR_Op<"cpuid"> {
let summary = "Get information about the CPU";
let description = [{
- The `cir.cpuid` operation takes a base pointer to an array of 4 integers, a
- function ID and a sub-function ID. The array of 4 integers is filled with
- different information about the processor.
+ The `cir.cpuid` operation retrieves different types of CPU information and
+ stores it in an array of 4 integers.
+
+ This operation takes 3 arguments: `basePtr`, a pointer to an array of 4
+ integers; `funcID`, an integer determining what type of information to be
+ retrieved (for instance, basic information, processor information and
+ features, or cache/TLB information); and `subFuncId`, an integer that adds
+ more detail about what information is requested.
+
+ As a result, the array of 4 integers is filled with the requested information.
Example:
@@ -5784,9 +5791,8 @@ def CIR_CpuIdOp : CIR_Op<"cpuid"> {
let arguments =
(ins Arg<CIR_PtrToArray, "array address", [MemWrite]>:$basePtr,
CIR_SInt32:$funcId, CIR_SInt32:$subFuncId);
- // TODO: remove once we can return an optional mlir::Value from
- // emitX86BuiltinExpr
- let results = (outs CIR_VectorType:$result);
+
+ let hasVerifier = 1;
}
#endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index bf9810eff498d..4f90b6727d80f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -25,7 +25,6 @@
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "clang/CIR/MissingFeatures.h"
#include "llvm/ADT/Sequence.h"
-#include "llvm/IR/InlineAsm.h"
#include "llvm/Support/ErrorHandling.h"
#include <string>
@@ -1835,6 +1834,10 @@ CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr) {
case X86::BI__builtin_ia32_cvtneps2bf16_128_mask:
case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
case X86::BI__builtin_ia32_cvtneps2bf16_512_mask:
+ cgm.errorNYI(expr->getSourceRange(),
+ std::string("unimplemented X86 builtin call: ") +
+ getContext().BuiltinInfo.getName(builtinID));
+ return mlir::Value{};
case X86::BI__cpuid:
case X86::BI__cpuidex: {
mlir::Location loc = getLoc(expr->getExprLoc());
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 95fc3afffb156..16139b527fefc 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -3488,6 +3488,28 @@ static mlir::ParseResult parseTryHandlerRegions(
return mlir::success();
}
+//===----------------------------------------------------------------------===//
+// CpuIdOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult cir::CpuIdOp::verify() {
+ auto basePtrTy = mlir::dyn_cast<cir::PointerType>(getBasePtr().getType());
+ if (!basePtrTy)
+ return mlir::failure();
+
+ auto arrayTy = mlir::dyn_cast<cir::ArrayType>(basePtrTy.getPointee());
+ if (!arrayTy)
+ return mlir::failure();
+ if (arrayTy.getSize() != 4)
+ return emitOpError() << "base pointer must point to an array of size 4";
+
+ auto intTy = mlir::dyn_cast<cir::IntType>(arrayTy.getElementType());
+ if (!intTy || !intTy.isSigned() || intTy.getWidth() != 32)
+ return emitOpError() << "base pointer must point to an array of !s32i";
+
+ return mlir::success();
+}
+
//===----------------------------------------------------------------------===//
// TableGen'd op method definitions
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 24924085ea9ea..1dbac4b9e1511 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -12,6 +12,7 @@
#include "LowerToLLVM.h"
+#include <array>
#include <deque>
#include <optional>
@@ -4205,21 +4206,11 @@ mlir::LogicalResult CIRToLLVMCpuIdOpLowering::matchAndRewrite(
mlir::Value funcId = adaptor.getFuncId();
mlir::Value subFuncId = adaptor.getSubFuncId();
- mlir::StringAttr opNameAttr = op->getAttrOfType<mlir::StringAttr>("name");
- if (!opNameAttr)
- return mlir::failure();
- if (opNameAttr.getValue() == "cpuid")
- subFuncId = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(), i32Ty, 0);
- std::vector operands{funcId, subFuncId};
+ std::array<mlir::Value, 2> operands{funcId, subFuncId};
StringRef asmString, constraints;
- mlir::ModuleOp moduleOp = op->getParentOfType<mlir::ModuleOp>();
- mlir::StringAttr tripleAttr =
- moduleOp->getAttrOfType<mlir::StringAttr>("llvm.target_triple");
- if (!tripleAttr)
- return mlir::failure();
- llvm::Triple triple(tripleAttr.getValue().str());
- if (triple.getArch() == llvm::Triple::x86) {
+ if (const llvm::Triple &triple = lowerMod->getTarget().getTriple();
+ triple.getArch() == llvm::Triple::x86) {
asmString = "cpuid";
constraints = "={ax},={bx},={cx},={dx},{ax},{cx}";
} else {
@@ -4260,6 +4251,8 @@ mlir::LogicalResult CIRToLLVMCpuIdOpLowering::matchAndRewrite(
mlir::LLVM::StoreOp::create(rewriter, op.getLoc(), extracted, storePtr,
alignment);
}
+
+ rewriter.eraseOp(op);
return mlir::success();
}
>From 53c91793e9ff843832070081ca4d80c82d223902 Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Wed, 7 Jan 2026 23:08:06 +0100
Subject: [PATCH 3/5] Fix cpuid/cpuidex builtin implementation
These builtins do not return anything, so the first parameter is the first operand.
---
clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index 4f90b6727d80f..1921defb5e408 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -1841,11 +1841,10 @@ CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr) {
case X86::BI__cpuid:
case X86::BI__cpuidex: {
mlir::Location loc = getLoc(expr->getExprLoc());
- mlir::Type i32Ty = builder.getSInt32Ty();
mlir::Value subFuncId = builtinID == X86::BI__cpuidex
? ops[2]
: builder.getConstInt(loc, sInt32Ty, 0);
- cir::CpuIdOp::create(builder, loc, i32Ty, /*basePtr=*/ops[0],
+ cir::CpuIdOp::create(builder, loc, /*basePtr=*/ops[0],
/*funcId=*/ops[1], /*subFuncId=*/subFuncId);
return mlir::Value{};
}
>From 77a6b1cd1473cd19c002154703f56a55de8253ba Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Wed, 7 Jan 2026 23:16:09 +0100
Subject: [PATCH 4/5] Change CIR_CpuIdOp to accept a pointer as first operand
Arrays are usually decayed to pointers. By not restricting basePtr to be exactly a pointer to an array of 4 signed integers, we allow passing a pointer to signed integer. Extra verifications are already done at the verifier.
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 8 +++++---
clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 14 ++++++++------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 3c5957ec200d7..d21022233d1e2 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -5780,16 +5780,18 @@ def CIR_CpuIdOp : CIR_Op<"cpuid"> {
As a result, the array of 4 integers is filled with the requested information.
+ Note that, since arrays usually decay to pointers, `basePtr` is expected to be
+ just a pointer to integer. Extra verifications are done at the verifier.
+
Example:
```mlir
- cir.cpuid %basePtr, %funcId, %subFuncId
- : (!cir.ptr<!cir.array<4 x !s32i>>, !s32i, !s32i)
+ cir.cpuid %basePtr, %funcId, %subFuncId : (!cir.ptr<!s32i>, !s32i, !s32i)
```
}];
let arguments =
- (ins Arg<CIR_PtrToArray, "array address", [MemWrite]>:$basePtr,
+ (ins Arg<CIR_PointerType, "array address", [MemWrite]>:$basePtr,
CIR_SInt32:$funcId, CIR_SInt32:$subFuncId);
let hasVerifier = 1;
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 16139b527fefc..dda995e5ba7dd 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -3497,13 +3497,15 @@ LogicalResult cir::CpuIdOp::verify() {
if (!basePtrTy)
return mlir::failure();
- auto arrayTy = mlir::dyn_cast<cir::ArrayType>(basePtrTy.getPointee());
- if (!arrayTy)
- return mlir::failure();
- if (arrayTy.getSize() != 4)
- return emitOpError() << "base pointer must point to an array of size 4";
+ mlir::Type type = basePtrTy.getPointee();
+
+ // basePtr points to an array of size at least 4
+ auto arrayTy = mlir::dyn_cast<cir::ArrayType>(type);
+ if (arrayTy && (arrayTy.getSize() < 4))
+ return emitOpError() << "base pointer must point to an array of size at least 4";
- auto intTy = mlir::dyn_cast<cir::IntType>(arrayTy.getElementType());
+ // Array decay: basePtr points to !s32i
+ auto intTy = mlir::dyn_cast<cir::IntType>(type);
if (!intTy || !intTy.isSigned() || intTy.getWidth() != 32)
return emitOpError() << "base pointer must point to an array of !s32i";
>From 5fc902a9bb5a02aa579d3307be1a1cfb7266294a Mon Sep 17 00:00:00 2001
From: rturrado <rturrado at gmail.com>
Date: Wed, 7 Jan 2026 23:30:24 +0100
Subject: [PATCH 5/5] Add cpuid-builtins.c test
---
clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 3 +-
.../CIR/CodeGenBuiltins/X86/cpuid-builtins.c | 31 +++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CIR/CodeGenBuiltins/X86/cpuid-builtins.c
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index dda995e5ba7dd..562326b2f60bd 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -3502,7 +3502,8 @@ LogicalResult cir::CpuIdOp::verify() {
// basePtr points to an array of size at least 4
auto arrayTy = mlir::dyn_cast<cir::ArrayType>(type);
if (arrayTy && (arrayTy.getSize() < 4))
- return emitOpError() << "base pointer must point to an array of size at least 4";
+ return emitOpError()
+ << "base pointer must point to an array of size at least 4";
// Array decay: basePtr points to !s32i
auto intTy = mlir::dyn_cast<cir::IntType>(type);
diff --git a/clang/test/CIR/CodeGenBuiltins/X86/cpuid-builtins.c b/clang/test/CIR/CodeGenBuiltins/X86/cpuid-builtins.c
new file mode 100644
index 0000000000000..5012fe2331baa
--- /dev/null
+++ b/clang/test/CIR/CodeGenBuiltins/X86/cpuid-builtins.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-extensions -Wno-implicit-function-declaration -fclangir -emit-cir -o %t.cir -Wall -Werror %s
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+
+#pragma intrinsic(__cpuid)
+
+void test__cpuid_with_array_decayed_to_pointer(int cpuInfo[4], int function_id) {
+ __cpuid(cpuInfo, function_id);
+}
+// CIR-LABEL: __cpuid_with_array_decayed_to_pointer
+// CIR: %[[CPUINFO_PTR:.*]] = cir.alloca !cir.ptr<!s32i>
+// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR: {{.*}}cir.cpuid{{.*}}(%{{.*}}, %{{.*}}, %[[ZERO]]) : (!cir.ptr<!s32i>, !s32i, !s32i)
+
+void test__cpuid_with_array(int function_id) {
+ int cpuInfo[4];
+ __cpuid(cpuInfo, function_id);
+}
+// CIR-LABEL: __cpuid_with_array
+// CIR: %[[CPUINFO_PTR:.*]] = cir.alloca !cir.array<!s32i x 4>
+// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR: {{.*}}cir.cpuid{{.*}}(%{{.*}}, %{{.*}}, %[[ZERO]]) : (!cir.ptr<!s32i>, !s32i, !s32i)
+
+#pragma intrinsic(__cpuidex)
+
+void test__cpuidex(int cpuInfo[4], int function_id, int subfunction_id) {
+ __cpuidex(cpuInfo, function_id, subfunction_id);
+}
+// CIR-LABEL: __cpuidex
+// CIR: %[[SUBFUNCTION_ID_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["subfunction_id"
+// CIR: %[[SUBFUNCTION_ID:.*]] = cir.load {{.*}} %[[SUBFUNCTION_ID_PTR]]
+// CIR: {{.*}}cir.cpuid{{.*}}(%{{.*}}, %{{.*}}, %[[SUBFUNCTION_ID]]) : (!cir.ptr<!s32i>, !s32i, !s32i)
More information about the cfe-commits
mailing list