[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #131838)
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 30 06:29:25 PDT 2025
================
@@ -4529,6 +4529,191 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
emitMaster(*this, S);
}
+static Expr *replaceWithNewTraitsOrDirectCall(CapturedDecl *CDecl,
+ Expr *NewExpr) {
+ Expr *CurrentCallExpr = nullptr;
+ Stmt *CallExprStmt = CDecl->getBody();
+
+ if (BinaryOperator *BinaryCopyOpr = dyn_cast<BinaryOperator>(CallExprStmt)) {
+ CurrentCallExpr = BinaryCopyOpr->getRHS();
+ BinaryCopyOpr->setRHS(NewExpr);
+ } else {
+ CurrentCallExpr = dyn_cast<Expr>(CallExprStmt);
+ CDecl->setBody(NewExpr);
+ }
+
+ return CurrentCallExpr;
+}
+
+static Expr *transformCallInStmt(Stmt *StmtP, bool NoContext = false) {
+ Expr *CurrentExpr = nullptr;
+ if (auto *CptStmt = dyn_cast<CapturedStmt>(StmtP)) {
+ CapturedDecl *CDecl = CptStmt->getCapturedDecl();
+
+ CallExpr *NewCallExpr = nullptr;
+ for (const auto *attr : CDecl->attrs()) {
+ if (NoContext) {
+ if (const auto *annotateAttr =
+ llvm::dyn_cast<clang::AnnotateAttr>(attr);
+ annotateAttr && annotateAttr->getAnnotation() == "NoContextAttr") {
+ NewCallExpr = llvm::dyn_cast<CallExpr>(*annotateAttr->args_begin());
+ }
+ } else {
+ if (const auto *annotateAttr =
+ llvm::dyn_cast<clang::AnnotateAttr>(attr);
+ annotateAttr && annotateAttr->getAnnotation() == "NoVariantsAttr") {
+ NewCallExpr = llvm::dyn_cast<CallExpr>(*annotateAttr->args_begin());
+ }
+ }
+ }
+
+ CurrentExpr = replaceWithNewTraitsOrDirectCall(CDecl, NewCallExpr);
+ }
+ return CurrentExpr;
+}
+
+// emitIfElse is used for the following conditions:
+//
+// NoVariants = 0 && NoContext = 1
+// if (Condition_NoContext) {
+// foo_variant2(); // Present in AnnotationAttr
+// } else {
+// foo_variant();
+// }
+//
+// NoVariants = 1 && NoContext = 0
+// if (Condition_NoVariants) {
+// foo();
+// } else {
+// foo_variant();
+// }
+//
+// NoVariants = 1 && NoContext = 1
+// if (Condition_NoVariants) { // ==> label if.then.NoVariants
+// foo();
+// } else { // ==> label else.NoVariants
+// if (Condition_NoContext) { // ==> label if.then.NoContext
+// foo_variant2(); // Present in AnnotationAttr
+// } else { // ==> label else
+// foo_variant();
+// }
+// }
+//
+static void emitIfElse(CodeGenFunction *CGF, Stmt *AssociatedStmt,
----------------
alexey-bataev wrote:
Try to add tests with classes, which evaluate to boolean, and create immediate class instance and see, that the destructors are called correctly
https://github.com/llvm/llvm-project/pull/131838
More information about the cfe-commits
mailing list