A source code can be directly converted to machine code (100000). Then why do we need to convert it to IR (Intermediate Representation) assembly language?
What are the Pros and Cons if I cannot directly convert into machine language?
A source code can be directly converted to machine code (100000). Then why do we need to convert it to IR (Intermediate Representation) assembly language?
What are the Pros and Cons if I cannot directly convert into machine language?
Then why do we need to convert it to IR (Intermediate Representation) assembly language?
You don't.
Text representations of IR exist for the purposes of debugging compiler internals. (Compilers normally transform through some internal representations, usually some form of SSA, while optimizing the logic of your program into efficient asm and then machine code.) See Disable all optimization options in GCC.
And for LLVM especially, IR is useful as a platform-neutral asm-like language that's useful for JIT compiling. Your portable application can generate LLVM-IR, and feed that to LLVM to get optimize machine code for whatever platform it's running on.
Or for an ahead-of-time compiler for a new language, it means you don't have to write an optimizing compiler that goes straight from source to machine code for every possible platform. So you get portability to multiple targets, and most importantly you get an optimizing back-end while only having to write a front-end that emits simple un-optimized LLVM-IR.
Writing an optimizing compiler is hard, but at least somewhat optimized machine code is basically necessary if you want anyone to use it for real work. See Why are there so few C compilers?
TL:DR; an IR makes it possible for one optimizing back-end to be used for many front-ends for different languages.