[llvm-dev] How to understand LLVM-C API? (original) (raw)
Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 18 11:19:17 PST 2019
- Previous message: [llvm-dev] How to understand LLVM-C API?
- Next message: [llvm-dev] LLVM Weekly - #268, February 18th 2019
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, 18 Feb 2019 at 08:53, Peng Yu via llvm-dev <llvm-dev at lists.llvm.org> wrote:
How can a value replace an instruction?
This API doesn't remove (or really touch) the instruction itself, just any other instructions that use its output. And because of the way the class hierarchy works, any Instruction is already a Value, representing its result.
In IR we write (for example):
%val = add i32 %l, %r
%val1 = mul i32 %val, 42
but the assignment is just a notational convenience to help us read. What's really happening is that the first operand of the "mul" is a pointer to the "add" instruction itself, casted to a Value *.
That API takes a Value because you might want to replace all uses with something else (most likely a Constant, but perhaps a Global). That wouldn't work if you could only replace uses with another instruction.
Cheers.
Tim.
- Previous message: [llvm-dev] How to understand LLVM-C API?
- Next message: [llvm-dev] LLVM Weekly - #268, February 18th 2019
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]