Many literary devices fall under the category of "figure of speech," which previous Educators have identified in preceding answers. This answer will call attention to those figures of speech in "If" which are commonly understood maxims or scenarios in English-speaking culture. There are indeed certain tropes which we turn to time and again to make meaningful comparisons to real life phenomena.
First, let's consider the idea of something which is "broken" and must be "rebuilt." When some kind of tragedy occurs, a person or object is not necessarily literally broken, but it is a common metaphor we use to conceptualize the process of solving a problem. Kipling writes: "Or watch the things you gave your life to, broken, / And stoop and build ’em up with worn-out tools." Life delivers trials time and time again that must be coped with. Despite the fact that you and your resources, your "tools," may be "worn-out," you must never give up. In the face of yet another problem, you still must "stoop and build 'em up."
In the following stanza, Kipling employs the trope of gambling to teach several lessons. The first four lines read:
If you can make one heap of all your winningsAnd risk it on one turn of pitch-and-toss,And lose, and start again at your beginningsAnd never breathe a word about your loss;
This poem refers to commonplace ideas and behaviors: rebuilding what is broken, gambling and losing with grace, and positioning oneself between the most and least powerful members of society. All of these figures of speech ("Tools," "pitch-and-toss," "Kings") help to achieve a special tone in this poem: namely, the instructive lecturing of a loving father. It is fitting that fathers are known, in part, for delivering cliche moral speeches, because that is essentially what Kipling does here. It is simply far more poetic than the average "dad speech."
Metaphor A simile is a comparison using the words “like” or “as,” but a metaphor is a more direct comparison. For example, “If you can keep your head” is a metaphor. You can’t actually lose your head!
If you can make one heap of all your winnings And risk it on one turn of pitch-and-toss, (lines 17-18)
In these lines, life is compared to games. You don’t actually have winnings in life, and this is not a literal pitch and toss. It’s a metaphor for risk.
Personification is when something that is not human is described as if it was human.
If you can dream - and not make dreams your master; If you can think - and not make thoughts your aim; If you can meet with triumph and disaster And treat those two imposters just the same; (lines 9-12)
Triumph and disaster are concepts, and they are described as human, given human qualities like that ability to master you.
Rhyme is one of a poet’s most powerful tools. When used well, it creates a rhythmic, songlike quality.
If you can trust yourself when all men doubt you, But make allowance for their doubting too; If you can wait and not be tired by waiting, Or, being lied about, don't deal in lies, Or, being hated, don't give way to hating, And yet don't look too good, nor talk too wise (lines 3-8)
In this case, rhyming the lines in a distinct pattern creates a rhythm that makes the poem songlike, and adds to a sense of fun and wonder.
"If" is a whole series of metaphors. Rudyard Kipling uses a whole series of examples to illustrate the qualities he feels his "son" or any other person should exhibit if s/he aspires to true, mature leadership.
Metaphors "show how two things that are not alike in most ways are similar in one important way." Looking at the poem, Kipling sets up his examples of qualities by explaining what the positive action should be in the face of others doing to opposite.
If you can meet with triumph and disaster And treat those two imposters just the same
Most individuals would react differently if they triumphed in a situation that if the same situation ended in disaster. Kipling is counseling his son that the reaction should be the same in either case, that the results are "imposters" - not as important as the action of doing something to advance the situation at hand.
You might want to think about the use of personification in this famous poem. Let us remember that personification is the attributing of human qualities to inanimate objects, and there is one clear instance of this in the poem. Consider the following quote:
If you can fill the unforgiving minuteWith sixty seconds' worth of distance run,
Note the way that the minute is described as "unforgiving," which is of course, literally impossible, as time is an inanimate object, but it here serves to emphasise the feat of being able to run for a span of time even though it is hard work.
Also, note the way that apostrophe is used to refer to Triumph and Disaster:
If you can meet with Triumph and DisasterAnd treat those two impostors just the same;
Triumph and Disaster are refered to and made out to be human characters, as they are described as being "two impostors just the same," just more individuals that can be met along the path of life and need to be encountered and surpassed.