Tony knows he is going to die, and also knows that is the only way to end the game. ;)
He understands this when he looks at Doctor Strange.
He realises that this is the only one possible winning scenario Doctor Strange saw when he travelled to the future 4 million times.
And he realises that Doctor Strange gave up the time stone to save his life because Tony Stark was the only one who could do the snap by sacrificing himself (when he said: "we are now in the end game").
Also, when Tony Stark checks in with Doctor Strange during Endgame, asking if this was it, if they were in the reality where everyone survives, Doctor Strange's cryptic reply -- "If I tell you, it won’t happen" -- is a big hint to Tony's role. Tony would have to sacrifice his life, to miss out on his daughter's future. But after meeting up with his father in the past, it seems like he knows he wants to be the kind of man who put others before himself.
And so he does it, he sacrifices himself: He knows what will happen and he is at peace with it.
Evidence for this:
This is supported by the writers Christopher Markus and Stephen McFeely in this interview. In their own words:
“The only way this works is if Tony dies. If you go back and watch Infinity War, when [Strange] says ‘one,’ Benedict … is just choked on emotion. Now that you know the end, go back and watch that moment. He means, ‘You’re going to have to die, Tony.'”
Even the director Joe Russo says in this interview:
"And you know, I think again, as a father, it’s very difficult to watch a character like that have to make a decision, knowing that he has to give up his life at the cost of his daughter losing a father and his wife losing a husband."