It's been a year since Tony Stark died trying to save the world. 5 years before that in the MCU timeline, when he jumped into that spaceship bound for Titan, he was desperately hoping to pull it off, one last time. He failed.
But after spending weeks in the empty of space, not knowing if he had lost everything, Stark returned to Earth to his wife. He quit what was left of the Avengers, built a little cabin for himself, had a child, started a family as he had once advised Steve Rogers- 'The simple life'. It was safe. He had everything he wanted.
But the moment he realised there could be a way to bring it all back, he started working on a way to make it possible.
That's just who Tony Stark was. And the Infinity Saga was more or less his story.
It was his capture by The Ten Rings and the daunting realisation that his weapons were being used to kill innocents that led to the birth of Iron Man. And that has been by and large the theme of his entire arc.
Stark was never going to cut the line as Steve Rogers had suggested in The Avengers. Instead, he was laying himself on it so that the other guys could walk away to safety. He took the nuke bound for Manhattan into the wormhole knowing it meant certain death.
Even Ultron's purpose was to save humanity. Now, while it understood that as an immediate call for a metallic evolution, Tony had created him as a shield for the planet so that things like Thanos would never happen.
Sure, he failed and quite spectacularly so but to have the insight to predict something like that, that must be genius.
Which Tony was, but by his own admission, Thanos had been inside his head since that portal closed in on him during Loki's Chittauri invasion.
And you could see that PTSD, that paranoia, the anxiety and everything that came with it. In Iron-Man 3, he could barely sleep and all he wanted to do was perfect the Iron Legion.
When he thought that the Avengers had gone out of hand, and were costing innocent lives, he wanted them to be reigned in by governing bodies.
Sure, all of his decisions had consequences, often more brutal than he would have liked, but this was just a man driven by terrible guilt and trauma, just trying to do the right thing.
If you followed his story closely you could realise that he felt that he should have died in that cave but he didn't and he needed to correct that, by all means. Which is how I assume he knew what to do when Dr Strange looked at him.
He knew it would kill him and yet, one more time, Tony Stark did what only he could, thus proving despite popular sentiments, he did have a heart!.