[LLVMdev] How to properly use copyValue?
Nick Lewycky
nicholas at mxc.ca
Sat Feb 4 22:22:01 PST 2012
Ryan Taylor wrote:
> Nick,
> First, thanks for responding. Secondly, I just want to create an exact
> copy of an already exisitng Value, this should be pretty simple to do
> but I'm unclear on how to do this?
> For example, PHINode::getIncomingValue (unsigned) returns a "Value"
> and I want to make a copy of that Value. Is there some other way to do
> this other than copyValue() that I'm missing?
There is no copy instruction in llvm, but you can fake one up with a
bitcast.
Nick
>
> On Sat, Feb 4, 2012 at 3:23 PM, Nick Lewycky <nicholas at mxc.ca
> <mailto:nicholas at mxc.ca>> wrote:
>
> 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