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,18 @@ 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+ }
56+
4657 switch (builtinID) {
4758 default :
4859 return {};
@@ -63,6 +74,10 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
6374 case X86::BI__builtin_ia32_undef128:
6475 case X86::BI__builtin_ia32_undef256:
6576 case X86::BI__builtin_ia32_undef512:
77+ cgm.errorNYI (e->getSourceRange (),
78+ std::string (" unimplemented X86 builtin call: " ) +
79+ getContext ().BuiltinInfo .getName (builtinID));
80+ return {};
6681 case X86::BI__builtin_ia32_vec_ext_v4hi:
6782 case X86::BI__builtin_ia32_vec_ext_v16qi:
6883 case X86::BI__builtin_ia32_vec_ext_v8hi:
@@ -72,7 +87,24 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
7287 case X86::BI__builtin_ia32_vec_ext_v32qi:
7388 case X86::BI__builtin_ia32_vec_ext_v16hi:
7489 case X86::BI__builtin_ia32_vec_ext_v8si:
75- case X86::BI__builtin_ia32_vec_ext_v4di:
90+ case X86::BI__builtin_ia32_vec_ext_v4di: {
91+ unsigned NumElts = cast<cir::VectorType>(ops[0 ].getType ()).getSize ();
92+
93+ uint64_t index =
94+ ops[1 ].getDefiningOp <cir::ConstantOp>().getIntValue ().getZExtValue ();
95+
96+ index &= NumElts - 1 ;
97+
98+ auto indexAttr = cir::IntAttr::get (
99+ cir::IntType::get (&getMLIRContext (), 64 , false ), index);
100+ auto indexVal =
101+ cir::ConstantOp::create (builder, getLoc (e->getExprLoc ()), indexAttr);
102+
103+ // These builtins exist so we can ensure the index is an ICE and in range.
104+ // Otherwise we could just do this in the header file.
105+ return cir::VecExtractOp::create (builder, getLoc (e->getExprLoc ()), ops[0 ],
106+ indexVal);
107+ }
76108 case X86::BI__builtin_ia32_vec_set_v4hi:
77109 case X86::BI__builtin_ia32_vec_set_v16qi:
78110 case X86::BI__builtin_ia32_vec_set_v8hi:
0 commit comments