Skip to content

Commit 93c0ded

Browse files
feedback
1 parent 26d8914 commit 93c0ded

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ struct MissingFeatures {
271271
static bool insertBuiltinUnpredictable() { return false; }
272272
static bool instrumentation() { return false; }
273273
static bool intrinsics() { return false; }
274+
static bool intrinsicElementTypeSupport() {return false; }
274275
static bool isMemcpyEquivalentSpecialMember() { return false; }
275276
static bool isTrivialCtorOrDtor() { return false; }
276277
static bool lambdaCaptures() { return false; }

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,32 @@ static int64_t getIntValueFromConstOp(mlir::Value val) {
2626
return val.getDefiningOp<cir::ConstantOp>().getIntValue().getSExtValue();
2727
}
2828

29-
static mlir::Value emitClFlush(CIRGenFunction& cgf,
30-
const CallExpr* e,
31-
mlir::Value& op) {
32-
mlir::Type voidTy = cir::VoidType::get(&cgf.getMLIRContext());
33-
mlir::Location location = cgf.getLoc(e->getExprLoc());
34-
return cir::LLVMIntrinsicCallOp::create(
35-
cgf.getBuilder(), location,
36-
cgf.getBuilder().getStringAttr("x86.sse2.clflush"), voidTy, op)
29+
static mlir::Value emitClFlush(CIRGenFunction &cgf, const CallExpr *e,
30+
mlir::Value &op) {
31+
mlir::Type voidTy = cir::VoidType::get(&cgf.getMLIRContext());
32+
mlir::Location location = cgf.getLoc(e->getExprLoc());
33+
return cir::LLVMIntrinsicCallOp::create(
34+
cgf.getBuilder(), location,
35+
cgf.getBuilder().getStringAttr("x86.sse2.clflush"), voidTy, op)
3736
.getResult();
3837
}
3938

40-
static mlir::Value emitPrefetch(CIRGenFunction& cgf,
41-
const CallExpr* e,
42-
mlir::Value& addr,
43-
int64_t hint) {
44-
CIRGenBuilderTy& builder = cgf.getBuilder();
45-
mlir::Type voidTy = cir::VoidType::get(&cgf.getMLIRContext());
46-
mlir::Type sInt32Ty = cir::IntType::get(&cgf.getMLIRContext(), 32, true);
47-
mlir::Value address = builder.createPtrBitcast(addr, voidTy);
39+
static mlir::Value emitPrefetch(CIRGenFunction &cgf, const CallExpr *e,
40+
mlir::Value &addr, int64_t hint) {
41+
CIRGenBuilderTy &builder = cgf.getBuilder();
4842
mlir::Location location = cgf.getLoc(e->getExprLoc());
49-
mlir::Value rw =
50-
cir::ConstantOp::create(builder, location,
51-
cir::IntAttr::get(sInt32Ty, (hint >> 2) & 0x1));
52-
mlir::Value locality =
53-
cir::ConstantOp::create(builder, location,
54-
cir::IntAttr::get(sInt32Ty, hint & 0x3));
55-
mlir::Value data = cir::ConstantOp::create(builder, location,
56-
cir::IntAttr::get(sInt32Ty, 1));
43+
mlir::Type voidTy = builder.getVoidTy();
44+
mlir::Value address = builder.createPtrBitcast(addr, voidTy);
45+
mlir::Value rw = builder.getSignedInt(location, (hint >> 2) & 0x1, 32);
46+
mlir::Value locality = builder.getSignedInt(location, hint & 0x3, 32);
47+
mlir::Value data = builder.getSignedInt(location, 1, 32);
5748

5849
return cir::LLVMIntrinsicCallOp::create(
59-
builder, location,
60-
builder.getStringAttr("prefetch"), voidTy,
50+
builder, location, builder.getStringAttr("prefetch"), voidTy,
6151
mlir::ValueRange{address, rw, locality, data})
6252
.getResult();
6353
}
6454

65-
6655
mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
6756
const CallExpr *e) {
6857
if (builtinID == Builtin::BI__builtin_cpu_is) {
@@ -90,14 +79,14 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
9079

9180
// `ICEArguments` is a bitmap indicating whether the argument at the i-th bit
9281
// is required to be a constant integer expression.
93-
unsigned ICEArguments = 0;
82+
unsigned iceArguments = 0;
9483
ASTContext::GetBuiltinTypeError error;
95-
getContext().GetBuiltinType(builtinID, error, &ICEArguments);
84+
getContext().GetBuiltinType(builtinID, error, &iceArguments);
9685
assert(error == ASTContext::GE_None && "Error while getting builtin type.");
9786

9887
const unsigned numArgs = e->getNumArgs();
9988
for (unsigned i = 0; i != numArgs; i++) {
100-
ops.push_back(emitScalarOrConstFoldImmArg(ICEArguments, i, e));
89+
ops.push_back(emitScalarOrConstFoldImmArg(iceArguments, i, e));
10190
}
10291

10392
switch (builtinID) {

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,24 @@ static mlir::LLVM::CallIntrinsicOp replaceOpWithCallLLVMIntrinsicOp(
321321
}
322322

323323
mlir::LogicalResult CIRToLLVMLLVMIntrinsicCallOpLowering::matchAndRewrite(
324-
cir::LLVMIntrinsicCallOp op,
325-
OpAdaptor adaptor,
324+
cir::LLVMIntrinsicCallOp op, OpAdaptor adaptor,
326325
mlir::ConversionPatternRewriter &rewriter) const {
327326
mlir::Type llvmResTy =
328327
getTypeConverter()->convertType(op->getResultTypes()[0]);
329328
if (!llvmResTy)
330329
return op.emitError("expected LLVM result type");
331330
StringRef name = op.getIntrinsicName();
331+
332+
// Some LLVM intrinsics require ElementType attribute to be attached to
333+
// the argument of pointer type. That prevents us from generating LLVM IR
334+
// because from LLVM dialect, we have LLVM IR like the below which fails
335+
// LLVM IR verification.
336+
// %3 = call i64 @llvm.aarch64.ldxr.p0(ptr %2)
337+
// The expected LLVM IR should be like
338+
// %3 = call i64 @llvm.aarch64.ldxr.p0(ptr elementtype(i32) %2)
339+
// TODO(cir): MLIR LLVM dialect should handle this part as CIR has no way
340+
// to set LLVM IR attribute.
341+
assert(!cir::MissingFeatures::intrinsicElementTypeSupport());
332342
replaceOpWithCallLLVMIntrinsicOp(rewriter, op, "llvm." + name, llvmResTy,
333343
adaptor.getOperands());
334344
return mlir::success();

clang/test/CIR/CodeGen/X86/sse2-builtins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ void test_mm_clflush(void* A) {
1818
// CIR-LABEL: test_mm_clflush
1919
// LLVM-LABEL: teh
2020
_mm_clflush(A);
21-
// CIR-CHECK: {{%.*}} = cir.llvm.intrinsic "x86.sse2.clflush" {{%.*}} : (!cir.ptr<!void>) -> !void
21+
// CIR-CHECK: {{%.*}} = cir.call_llvm_intrinsic "x86.sse2.clflush" {{%.*}} : (!cir.ptr<!void>) -> !void
2222
// LLVM-CHECK: call void @llvm.x86.sse2.clflush(ptr {{%.*}})
2323
}

0 commit comments

Comments
 (0)