Skip to content

Commit 8b56cbb

Browse files
authored
[SYCL][NFC] Simplify CodeGen for Intel FPGA function attributes (#3637)
This patch adds cast<> instead of dyn_cast<> + assert() and auto instead of Attribute Name for SYCL function attributes below: SYCLIntelNoGlobalWorkOffsetAttr SYCLIntelMaxGlobalWorkDimAttr SYCLIntelNumSimdWorkItemsAttr SYCLIntelSchedulerTargetFmaxMhzAttr IntelReqdSubGroupSizeAttr Signed-off-by: Soumi Manna <soumi.manna@intel.com>
1 parent 87dbcd2 commit 8b56cbb

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

+9-20
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,7 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
657657
// To support the SYCL 2020 spelling with no propagation, only emit for
658658
// kernel-or-device when that spelling, fall-back to old behavior.
659659
if (ReqSubGroup && (IsKernelOrDevice || !ReqSubGroup->isSYCL2020Spelling())) {
660-
const auto *CE = dyn_cast<ConstantExpr>(ReqSubGroup->getValue());
661-
assert(CE && "Not an integer constant expression");
660+
const auto *CE = cast<ConstantExpr>(ReqSubGroup->getValue());
662661
Optional<llvm::APSInt> ArgVal = CE->getResultAsAPSInt();
663662
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
664663
Builder.getInt32(ArgVal->getSExtValue()))};
@@ -705,32 +704,26 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
705704
llvm::MDNode::get(Context, AttrMDArgs));
706705
}
707706

708-
if (const SYCLIntelNumSimdWorkItemsAttr *A =
709-
FD->getAttr<SYCLIntelNumSimdWorkItemsAttr>()) {
710-
const auto *CE = dyn_cast<ConstantExpr>(A->getValue());
711-
assert(CE && "Not an integer constant expression");
707+
if (const auto *A = FD->getAttr<SYCLIntelNumSimdWorkItemsAttr>()) {
708+
const auto *CE = cast<ConstantExpr>(A->getValue());
712709
Optional<llvm::APSInt> ArgVal = CE->getResultAsAPSInt();
713710
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
714711
Builder.getInt32(ArgVal->getSExtValue()))};
715712
Fn->setMetadata("num_simd_work_items",
716713
llvm::MDNode::get(Context, AttrMDArgs));
717714
}
718715

719-
if (const SYCLIntelSchedulerTargetFmaxMhzAttr *A =
720-
FD->getAttr<SYCLIntelSchedulerTargetFmaxMhzAttr>()) {
721-
const auto *CE = dyn_cast<ConstantExpr>(A->getValue());
722-
assert(CE && "Not an integer constant expression");
716+
if (const auto *A = FD->getAttr<SYCLIntelSchedulerTargetFmaxMhzAttr>()) {
717+
const auto *CE = cast<ConstantExpr>(A->getValue());
723718
Optional<llvm::APSInt> ArgVal = CE->getResultAsAPSInt();
724719
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
725720
Builder.getInt32(ArgVal->getSExtValue()))};
726721
Fn->setMetadata("scheduler_target_fmax_mhz",
727722
llvm::MDNode::get(Context, AttrMDArgs));
728723
}
729724

730-
if (const SYCLIntelMaxGlobalWorkDimAttr *A =
731-
FD->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
732-
const auto *CE = dyn_cast<ConstantExpr>(A->getValue());
733-
assert(CE && "Not an integer constant expression");
725+
if (const auto *A = FD->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
726+
const auto *CE = cast<ConstantExpr>(A->getValue());
734727
Optional<llvm::APSInt> ArgVal = CE->getResultAsAPSInt();
735728
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
736729
Builder.getInt32(ArgVal->getSExtValue()))};
@@ -760,12 +753,8 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
760753
llvm::MDNode::get(Context, AttrMDArgs));
761754
}
762755

763-
if (const SYCLIntelNoGlobalWorkOffsetAttr *A =
764-
FD->getAttr<SYCLIntelNoGlobalWorkOffsetAttr>()) {
765-
const Expr *Arg = A->getValue();
766-
assert(Arg && "Got an unexpected null argument");
767-
const auto *CE = dyn_cast<ConstantExpr>(Arg);
768-
assert(CE && "Not an integer constant expression");
756+
if (const auto *A = FD->getAttr<SYCLIntelNoGlobalWorkOffsetAttr>()) {
757+
const auto *CE = cast<ConstantExpr>(A->getValue());
769758
Optional<llvm::APSInt> ArgVal = CE->getResultAsAPSInt();
770759
if (ArgVal->getBoolValue())
771760
Fn->setMetadata("no_global_work_offset", llvm::MDNode::get(Context, {}));

0 commit comments

Comments
 (0)