1616#include " clang/Basic/Builtins.h"
1717#include " clang/Basic/TargetBuiltins.h"
1818#include " clang/CIR/MissingFeatures.h"
19- #include " llvm/IR/IntrinsicsX86.h"
2019
2120using namespace clang ;
2221using namespace clang ::CIRGen;
@@ -43,6 +42,17 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
4342 // Find out if any arguments are required to be integer constant expressions.
4443 assert (!cir::MissingFeatures::handleBuiltinICEArguments ());
4544
45+ llvm::SmallVector<mlir::Value> ops;
46+
47+ // Find out if any arguments are required to be integer constant expressions.
48+ unsigned iceArguments = 0 ;
49+ ASTContext::GetBuiltinTypeError error;
50+ getContext ().GetBuiltinType (builtinID, error, &iceArguments);
51+ assert (error == ASTContext::GE_None && " Should not codegen an error" );
52+
53+ for (auto [idx, arg] : llvm::enumerate (e->arguments ()))
54+ ops.push_back (emitScalarOrConstFoldImmArg (iceArguments, idx, arg));
55+
4656 switch (builtinID) {
4757 default :
4858 return {};
@@ -63,6 +73,10 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
6373 case X86::BI__builtin_ia32_undef128:
6474 case X86::BI__builtin_ia32_undef256:
6575 case X86::BI__builtin_ia32_undef512:
76+ cgm.errorNYI (e->getSourceRange (),
77+ std::string (" unimplemented X86 builtin call: " ) +
78+ getContext ().BuiltinInfo .getName (builtinID));
79+ return {};
6680 case X86::BI__builtin_ia32_vec_ext_v4hi:
6781 case X86::BI__builtin_ia32_vec_ext_v16qi:
6882 case X86::BI__builtin_ia32_vec_ext_v8hi:
@@ -72,7 +86,22 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
7286 case X86::BI__builtin_ia32_vec_ext_v32qi:
7387 case X86::BI__builtin_ia32_vec_ext_v16hi:
7488 case X86::BI__builtin_ia32_vec_ext_v8si:
75- case X86::BI__builtin_ia32_vec_ext_v4di:
89+ case X86::BI__builtin_ia32_vec_ext_v4di: {
90+ unsigned numElts = cast<cir::VectorType>(ops[0 ].getType ()).getSize ();
91+
92+ uint64_t index =
93+ ops[1 ].getDefiningOp <cir::ConstantOp>().getIntValue ().getZExtValue ();
94+
95+ index &= numElts - 1 ;
96+
97+ cir::ConstantOp indexVal =
98+ builder.getUInt64 (index, getLoc (e->getExprLoc ()));
99+
100+ // These builtins exist so we can ensure the index is an ICE and in range.
101+ // Otherwise we could just do this in the header file.
102+ return cir::VecExtractOp::create (builder, getLoc (e->getExprLoc ()), ops[0 ],
103+ indexVal);
104+ }
76105 case X86::BI__builtin_ia32_vec_set_v4hi:
77106 case X86::BI__builtin_ia32_vec_set_v16qi:
78107 case X86::BI__builtin_ia32_vec_set_v8hi:
0 commit comments