[LLVMdev] How to properly use copyValue?
Nick Lewycky
nicholas at mxc.ca
Sat Feb 4 12:23:40 PST 2012
Ryan Taylor wrote:
> Since there are no constructors for Value, how do you properly insert a
> new Value?
Value is a pure base. If you want to construct a new Value, then you
want to construct a global variable or instruction or argument or
something in particular.
> If I create a pointer Value *newValue and then call
> AA.copyValue(oldValue, newValue), this does not work, since newValue is
> not allocated.
AA.copyValue is used to tell the AliasAnalysis that a transformation is
replacing the instruction in oldValue with newValue, so AA should update
its internal tables. (Note that BasicAA and TBAA don't have internal
tables, so the function is a no-op.)
As to your original question, if you need to copy a value, some types
have copy methods such as Instruction::clone(). For BasicBlocks,
Functions and Modules, there's the Cloning interface in
llvm/Transforms/Utils/Cloning.h. Constants not in the GlobalValue
hierarchy are impossible to make copies of as they are designed to be
pointer-comparable and permitting copies would break that.
Inserting is a separate issue. Supposing you create a new instruction
using "BO = BinaryOperator::createAdd(X, Y);" you then need to insert it
using BO->insertBefore or BO->insertAfter.
Nick
More information about the llvm-dev
mailing list