@@ -3557,8 +3557,6 @@ void EventAPICallRule::handleEventElapsedTime(bool IsAssigned) {
35573557 if (DpctGlobalInfo::getEnablepProfilingFlag ()) {
35583558 // Option '--enable-profiling' is enabled
35593559 auto StmtStrArg0 = getStmtSpelling (TimeElapsedCE->getArg (0 ));
3560- auto StmtStrArg1 = getStmtSpelling (TimeElapsedCE->getArg (1 ));
3561- auto StmtStrArg2 = getStmtSpelling (TimeElapsedCE->getArg (2 ));
35623560
35633561 std::ostringstream Repl;
35643562 std::string Assginee = " *(" + StmtStrArg0 + " )" ;
@@ -3567,10 +3565,27 @@ void EventAPICallRule::handleEventElapsedTime(bool IsAssigned) {
35673565 Assginee = getStmtSpelling (UO->getSubExpr ());
35683566 }
35693567
3570- auto StartTimeStr = StmtStrArg1 + " ->get_profiling_info<"
3571- " sycl::info::event_profiling::command_start>()" ;
3572- auto StopTimeStr = StmtStrArg2 + " ->get_profiling_info<"
3573- " sycl::info::event_profiling::command_end>()" ;
3568+ const auto *StartArg = TimeElapsedCE->getArg (1 )->IgnoreImpCasts ();
3569+ const auto *EndArg = TimeElapsedCE->getArg (2 )->IgnoreImpCasts ();
3570+
3571+ ExprAnalysis EAForStartArg (StartArg);
3572+ ExprAnalysis EAForEndArg (EndArg);
3573+
3574+ auto StartArgRepl = EAForStartArg.getReplacedString ();
3575+ auto EndArgRepl = EAForEndArg.getReplacedString ();
3576+
3577+ if (isa<CStyleCastExpr>(StartArg) || isa<CXXReinterpretCastExpr>(StartArg))
3578+ StartArgRepl = " (" + StartArgRepl + " )" ;
3579+
3580+ if (isa<CStyleCastExpr>(EndArg) || isa<CXXReinterpretCastExpr>(EndArg))
3581+ EndArgRepl = " (" + EndArgRepl + " )" ;
3582+
3583+ auto StartTimeStr = StartArgRepl +
3584+ " ->get_profiling_info<"
3585+ " sycl::info::event_profiling::command_start>()" ;
3586+ auto StopTimeStr = EndArgRepl +
3587+ " ->get_profiling_info<"
3588+ " sycl::info::event_profiling::command_end>()" ;
35743589
35753590 Repl << Assginee << " = ("
35763591 << StopTimeStr << " - " << StartTimeStr << " ) / 1000000.0f" ;
0 commit comments