[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 9 07:28:34 PDT 2025
================
@@ -4529,6 +4529,117 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
emitMaster(*this, S);
}
+static Expr *getCapturedExprFromImplicitCastExpr(Expr *Cond) {
+
+ Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+ if (auto *DeclRef = dyn_cast<DeclRefExpr>(SubExpr)) {
+ if (auto *CapturedExprDecl =
+ dyn_cast<OMPCapturedExprDecl>(DeclRef->getDecl())) {
+
+ // Retrieve the initial expression from the captured expression
+ return CapturedExprDecl->getInit();
+ }
+ }
+ return Cond;
+}
+
+static Expr *replaceWithNewTraitsOrDirectCall(Stmt *AssocExpr,
+ CallExpr *ReplacementFunction) {
+ Expr *FinalCall = ReplacementFunction;
+
+ if (BinaryOperator *BinaryCopyOpr = dyn_cast<BinaryOperator>(AssocExpr)) {
+ BinaryCopyOpr->setRHS(FinalCall);
+ return BinaryCopyOpr;
+ }
+
+ return FinalCall;
+}
+
+static void transformCallInStmt(Stmt *StmtP) {
+ if (auto *AssocStmt = dyn_cast<CapturedStmt>(StmtP)) {
+ CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
+
+ // Access AnnotateAttr
+ CallExpr *NewCallExpr = nullptr;
+ for (const auto *attr : CDecl->attrs()) {
+ if (const auto *annotateAttr = llvm::dyn_cast<clang::AnnotateAttr>(attr);
+ annotateAttr &&
+ annotateAttr->getAnnotation() == "NoContextInvariant") {
+ NewCallExpr = llvm::dyn_cast<CallExpr>(*annotateAttr->args_begin());
+ }
+ }
+
+ Stmt *CallExprStmt = CDecl->getBody();
+ Stmt *NewCallExprStmt =
+ replaceWithNewTraitsOrDirectCall(CallExprStmt, NewCallExpr);
+ CDecl->setBody(NewCallExprStmt);
+ }
+}
+
+static void EmitIfElse(CodeGenFunction *CGF, Expr *Condition,
----------------
alexey-bataev wrote:
```suggestion
static void emitIfElse(CodeGenFunction *CGF, Expr *Condition,
```
https://github.com/llvm/llvm-project/pull/131838
More information about the cfe-commits
mailing list