[clang] [CIR][X86] Add support for `cpuid`/`cpuidex` (PR #173197)
Roberto Turrado Camblor via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 10 09:57:59 PST 2026
================
@@ -3565,6 +3565,31 @@ cir::EhTypeIdOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
return success();
}
+//===----------------------------------------------------------------------===//
+// CpuIdOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult cir::CpuIdOp::verify() {
+ auto basePtrTy = mlir::dyn_cast<cir::PointerType>(getBasePtr().getType());
+ if (!basePtrTy)
+ return mlir::failure();
+
+ 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";
+
+ // Array decay: basePtr points to !s32i
----------------
rturrado wrote:
Just out of curiosity, why the `(int *)&cpuInfo` instead of just `cpuInfo` in the example above? Wouldn't the former pass a pointer to the `cpuInfo` stack variable to `__cpuid`, while the latter would pass a pointer to the array of 4 ints reserved by `malloc` in the heap?
https://github.com/llvm/llvm-project/pull/173197
More information about the cfe-commits
mailing list