[PATCH] D116161: [Clang] Add an overload for emitUnaryBuiltin.
Jun Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 28 00:26:17 PST 2021
junaire updated this revision to Diff 396380.
junaire added a comment.
In order to use `emitUnaryBuiltin` in other cases, I changed the function interface.
This allows us to use it in all `Builder.CreateUnaryIntrinsic()` cases, but will make
the function body very small.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116161/new/
https://reviews.llvm.org/D116161
Files:
clang/lib/CodeGen/CGBuiltin.cpp
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -541,6 +541,11 @@
return CGF.Builder.CreateCall(F, Src0);
}
+static Value *emitUnaryBuiltin(CodeGenFunction &CGF, llvm::Value *V,
+ unsigned IntrinsicID, llvm::StringRef Name) {
+ return CGF.Builder.CreateUnaryIntrinsic(IntrinsicID, V, nullptr, Name);
+}
+
// Emit an intrinsic that has 2 operands of the same type as its result.
static Value *emitBinaryBuiltin(CodeGenFunction &CGF,
const CallExpr *E,
@@ -3128,18 +3133,15 @@
Result = Builder.CreateBinaryIntrinsic(
llvm::Intrinsic::abs, Op0, Builder.getFalse(), nullptr, "elt.abs");
else
- Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, nullptr,
- "elt.abs");
- return RValue::get(Result);
- }
+ Result = emitUnaryBuiltin(*this, Op0, llvm::Intrinsic::fabs, "elt.abs");
- case Builtin::BI__builtin_elementwise_ceil: {
- Value *Op0 = EmitScalarExpr(E->getArg(0));
- Value *Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::ceil, Op0,
- nullptr, "elt.ceil");
return RValue::get(Result);
}
+ case Builtin::BI__builtin_elementwise_ceil:
+ return RValue::get(emitUnaryBuiltin(*this, EmitScalarExpr(E->getArg(0)),
+ llvm::Intrinsic::ceil, "elt.ceil"));
+
case Builtin::BI__builtin_elementwise_max: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
Value *Op1 = EmitScalarExpr(E->getArg(1));
@@ -3186,10 +3188,9 @@
return llvm::Intrinsic::vector_reduce_fmax;
};
Value *Op0 = EmitScalarExpr(E->getArg(0));
- Value *Result = Builder.CreateUnaryIntrinsic(
- GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()), Op0, nullptr,
- "rdx.min");
- return RValue::get(Result);
+ return RValue::get(emitUnaryBuiltin(
+ *this, Op0, GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()),
+ "rd.min"));
}
case Builtin::BI__builtin_reduce_min: {
@@ -3205,18 +3206,15 @@
return llvm::Intrinsic::vector_reduce_fmin;
};
Value *Op0 = EmitScalarExpr(E->getArg(0));
- Value *Result = Builder.CreateUnaryIntrinsic(
- GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()), Op0, nullptr,
- "rdx.min");
- return RValue::get(Result);
+ return RValue::get(emitUnaryBuiltin(
+ *this, Op0, GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()),
+ "rd.min"));
}
- case Builtin::BI__builtin_reduce_xor: {
- Value *Op0 = EmitScalarExpr(E->getArg(0));
- Value *Result = Builder.CreateUnaryIntrinsic(
- llvm::Intrinsic::vector_reduce_xor, Op0, nullptr, "rdx.xor");
- return RValue::get(Result);
- }
+ case Builtin::BI__builtin_reduce_xor:
+ return RValue::get(emitUnaryBuiltin(*this, EmitScalarExpr(E->getArg(0)),
+ llvm::Intrinsic::vector_reduce_xor,
+ "rdx.xor"));
case Builtin::BI__builtin_matrix_transpose: {
const auto *MatrixTy = E->getArg(0)->getType()->getAs<ConstantMatrixType>();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116161.396380.patch
Type: text/x-patch
Size: 3316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211228/d86bd681/attachment.bin>
More information about the cfe-commits
mailing list