25 void ValueMapTypeRemapper::anchor() {}
26 void ValueMaterializer::anchor() {}
44 if (isa<GlobalValue>(V))
45 return VM[V] = const_cast<Value*>(V);
47 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
51 NewTy = cast<FunctionType>(TypeMapper->
remapType(NewTy));
53 if (NewTy != IA->getFunctionType())
54 V =
InlineAsm::get(NewTy, IA->getAsmString(), IA->getConstraintString(),
55 IA->hasSideEffects(), IA->isAlignStack());
58 return VM[V] =
const_cast<Value*
>(V);
61 if (
const auto *MDV = dyn_cast<MetadataAsValue>(V)) {
62 const Metadata *MD = MDV->getMetadata();
66 return VM[V] =
const_cast<Value *
>(V);
68 auto *MappedMD =
MapMetadata(MD, VM, Flags, TypeMapper, Materializer);
70 return VM[V] =
const_cast<Value *
>(V);
88 cast<Function>(
MapValue(BA->getFunction(), VM,
Flags, TypeMapper, Materializer));
90 Flags, TypeMapper, Materializer));
97 Value *Mapped =
nullptr;
98 for (; OpNo != NumOperands; ++OpNo) {
100 Mapped =
MapValue(Op, VM, Flags, TypeMapper, Materializer);
101 if (Mapped != C)
break;
111 if (OpNo == NumOperands && NewTy == C->
getType())
118 for (
unsigned j = 0; j != OpNo; ++j)
122 if (OpNo != NumOperands) {
126 for (++OpNo; OpNo != NumOperands; ++OpNo)
128 Flags, TypeMapper, Materializer));
132 return VM[V] = CE->getWithOperands(Ops, NewTy);
133 if (isa<ConstantArray>(C))
135 if (isa<ConstantStruct>(C))
137 if (isa<ConstantVector>(C))
140 if (isa<UndefValue>(C))
142 if (isa<ConstantAggregateZero>(C))
144 assert(isa<ConstantPointerNull>(C));
150 VM.
MD()[Key].reset(Val);
196 "Expected nodes to match");
197 assert(OldNode->
isResolved() &&
"Expected resolved node");
198 assert(!NewNode->
isUniqued() &&
"Expected non-uniqued node");
202 bool AnyChanged =
false;
206 "Expected old operands to already be in place");
209 TypeMapper, Materializer);
227 assert(Node->
isDistinct() &&
"Expected distinct node");
230 remap(Node, NewMD, Cycles, VM, Flags, TypeMapper, Materializer);
233 for (
Metadata *Op : NewMD->operands())
234 if (
auto *Node = dyn_cast_or_null<MDNode>(Op))
249 assert(Node->
isUniqued() &&
"Expected uniqued node");
252 auto ClonedMD = Node->
clone();
253 if (!
remap(Node, ClonedMD.
get(), Cycles, VM,
Flags, TypeMapper, Materializer))
271 if (isa<MDString>(MD))
274 if (isa<ConstantAsMetadata>(MD))
278 if (
const auto *VMD = dyn_cast<ValueAsMetadata>(MD)) {
280 MapValue(VMD->getValue(), VM,
Flags, TypeMapper, Materializer);
281 if (VMD->getValue() == MappedV ||
297 const MDNode *Node = cast<MDNode>(MD);
301 if (Flags & RF_NoModuleLevelChanges)
305 assert(Node->
isResolved() &&
"Unexpected unresolved node");
308 return mapDistinctNode(Node, Cycles, VM, Flags, TypeMapper, Materializer);
310 return mapUniquedNode(Node, Cycles, VM, Flags, TypeMapper, Materializer);
321 if (NewMD && NewMD != MD) {
322 if (
auto *
N = dyn_cast<MDNode>(NewMD))
323 if (!
N->isResolved())
327 if (!
N->isResolved())
331 assert(Cycles.
empty() &&
"Expected no unresolved cycles");
340 return cast<MDNode>(
MapMetadata(static_cast<const Metadata *>(MD), VM, Flags,
341 TypeMapper, Materializer));
358 "Referenced value not in value map!");
362 if (
PHINode *PN = dyn_cast<PHINode>(I)) {
363 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
367 PN->setIncomingBlock(i, cast<BasicBlock>(V));
370 "Referenced block not in value map!");
401 if (
auto *AI = dyn_cast<AllocaInst>(I))
402 AI->setAllocatedType(TypeMapper->
remapType(AI->getAllocatedType()));
403 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(I)) {
404 GEP->setSourceElementType(
406 GEP->setResultElementType(
void push_back(const T &Elt)
static bool remap(const MDNode *OldNode, MDNode *NewNode, SmallVectorImpl< MDNode * > &Cycles, ValueToValueMapTy &VM, RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer)
Remap nodes.
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
unsigned getNumParams() const
getNumParams - Return the number of fixed parameters this function type requires. ...
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
static Metadata * mapDistinctNode(const MDNode *Node, SmallVectorImpl< MDNode * > &Cycles, ValueToValueMapTy &VM, RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer)
Map a distinct MDNode.
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
static ConstantAggregateZero * get(Type *Ty)
ArrayRef< Type * > params() const
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
getAllMetadata - Get all metadata attached to this Instruction.
void reserve(size_type N)
static Metadata * mapToSelf(ValueToValueMapTy &VM, const Metadata *MD)
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithDistinct(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a distinct one.
BlockAddress - The address of a basic block.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static Constant * get(ArrayRef< Constant * > V)
static Metadata * MapMetadataImpl(const Metadata *MD, SmallVectorImpl< MDNode * > &Cycles, ValueToValueMapTy &VM, RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer)
ConstantExpr - a constant value that is initialized with an expression using other constant values...
FunctionType - Class to represent function types.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
iterator find(const KeyT &Val)
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
RF_NoModuleLevelChanges - If this flag is set, the remapper knows that only local values within a fun...
RF_IgnoreMissingEntries - If this flag is set, the remapper ignores entries that are not in the value...
ValueMaterializer - This is a class that can be implemented by clients to materialize Values on deman...
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static ConstantPointerNull * get(PointerType *T)
get() - Static factory methods - Return objects of the specified value
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
static BlockAddress * get(Function *F, BasicBlock *BB)
get - Return a BlockAddress for the specified function and basic block.
This is an important base class in LLVM.
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Value * getOperand(unsigned i) const
static Constant * get(StructType *T, ArrayRef< Constant * > V)
virtual Value * materializeValueFor(Value *V)=0
materializeValueFor - The client should implement this method if they want to generate a mapped Value...
TempMDNode clone() const
Create a (temporary) clone of this.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
RemapFlags
RemapFlags - These are flags that the value mapping APIs allow.
LLVMContext & getContext() const
All values hold a context through their type.
void setMetadata(unsigned KindID, MDNode *Node)
setMetadata - Set the metadata of the specified kind to the specified node.
const MDOperand & getOperand(unsigned I) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
RemapInstruction - Convert the instruction operands from referencing the current values into those sp...
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
ValueMapTypeRemapper - This is a class that can be implemented by clients to remap types when cloning...
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static Metadata * mapToMetadata(ValueToValueMapTy &VM, const Metadata *Key, Metadata *Val)
static Metadata * mapMetadataOp(Metadata *Op, SmallVectorImpl< MDNode * > &Cycles, ValueToValueMapTy &VM, RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer)
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
LLVM Value Representation.
static Metadata * mapUniquedNode(const MDNode *Node, SmallVectorImpl< MDNode * > &Cycles, ValueToValueMapTy &VM, RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer)
Map a uniqued MDNode.
virtual Type * remapType(Type *SrcTy)=0
remapType - The client should implement this method if they want to remap types while mapping values...
bool isResolved() const
Check if node is fully resolved.