Skip to content

Commit 529e247

Browse files
authored
Merge pull request #683 from JuliaLLVM/tb/value-mapping
Value maps, and mapping values and metadata with them
2 parents 137be18 + 1f1e717 commit 529e247

15 files changed

Lines changed: 2408 additions & 85 deletions

File tree

‎deps/LLVMExtra/include/LLVMExtra.h‎

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,82 @@ typedef enum {
137137
LLVMCloneFunctionChangeTypeDifferentModule = 2,
138138
LLVMCloneFunctionChangeTypeClonedModule = 3
139139
} LLVMCloneFunctionChangeType;
140-
void LLVMCloneFunctionInto(LLVMValueRef NewFunc, LLVMValueRef OldFunc,
141-
LLVMValueRef *ValueMap, unsigned ValueMapElements,
142-
LLVMCloneFunctionChangeType Changes, const char *NameSuffix,
143-
LLVMTypeRef (*TypeMapper)(LLVMTypeRef, void *),
144-
void *TypeMapperData,
145-
LLVMValueRef (*Materializer)(LLVMValueRef, void *),
146-
void *MaterializerData);
140+
141+
// A map from values and metadata to their replacements, like ValueToValueMapTy, which is
142+
// used and extended by the value mapper and when cloning functions. Entries follow their key
143+
// when it is replaced (RAUW), and are removed when it is deleted.
144+
typedef struct LLVMOpaqueValueMap *LLVMValueMapRef;
145+
LLVMValueMapRef LLVMExtraCreateValueMap(void);
146+
void LLVMExtraDisposeValueMap(LLVMValueMapRef VM);
147+
// the entries whose value is not null (values are tracked, and become null when deleted)
148+
size_t LLVMExtraValueMapGetNumEntries(LLVMValueMapRef VM);
149+
void LLVMExtraValueMapGetEntries(LLVMValueMapRef VM, LLVMValueRef *Keys,
150+
LLVMValueRef *Values);
151+
// NULL if Key is not mapped
152+
LLVMValueRef LLVMExtraValueMapLookup(LLVMValueMapRef VM, LLVMValueRef Key);
153+
void LLVMExtraValueMapSet(LLVMValueMapRef VM, LLVMValueRef Key, LLVMValueRef Val);
154+
LLVMBool LLVMExtraValueMapErase(LLVMValueMapRef VM, LLVMValueRef Key);
155+
void LLVMExtraValueMapClear(LLVMValueMapRef VM);
156+
// the metadata part of the map
157+
size_t LLVMExtraValueMapGetNumMetadataEntries(LLVMValueMapRef VM);
158+
void LLVMExtraValueMapGetMetadataEntries(LLVMValueMapRef VM, LLVMMetadataRef *Keys,
159+
LLVMMetadataRef *Values);
160+
LLVMMetadataRef LLVMExtraValueMapLookupMetadata(LLVMValueMapRef VM, LLVMMetadataRef Key);
161+
void LLVMExtraValueMapSetMetadata(LLVMValueMapRef VM, LLVMMetadataRef Key,
162+
LLVMMetadataRef Val);
163+
LLVMBool LLVMExtraValueMapEraseMetadata(LLVMValueMapRef VM, LLVMMetadataRef Key);
164+
165+
// Flags for the value mapper (RemapFlags), to be combined with a bitwise or.
166+
typedef enum {
167+
LLVMRemapFlagsNone = 0,
168+
LLVMRemapFlagsNoModuleLevelChanges = 1,
169+
LLVMRemapFlagsIgnoreMissingLocals = 2,
170+
LLVMRemapFlagsReuseAndMutateDistinctMDs = 4,
171+
LLVMRemapFlagsNullMapMissingGlobalValues = 8
172+
} LLVMRemapFlags;
173+
174+
// Map a value or metadata using a value map, which is extended with the mappings that are
175+
// made, like MapValue and MapMetadata. The type mapper and the materializer are optional
176+
// callbacks: the type mapper returns the type to use for a type, and the materializer a
177+
// value to map a value to, or NULL to have the value mapper map it. The result is NULL if
178+
// the value cannot be mapped (depending on the flags).
179+
LLVMValueRef LLVMExtraMapValue(LLVMValueRef V, LLVMValueMapRef VM, unsigned Flags,
180+
LLVMTypeRef (*TypeMapper)(LLVMTypeRef, void *),
181+
void *TypeMapperData,
182+
LLVMValueRef (*Materializer)(LLVMValueRef, void *),
183+
void *MaterializerData);
184+
LLVMMetadataRef LLVMExtraMapMetadata(LLVMMetadataRef MD, LLVMValueMapRef VM, unsigned Flags,
185+
LLVMTypeRef (*TypeMapper)(LLVMTypeRef, void *),
186+
void *TypeMapperData,
187+
LLVMValueRef (*Materializer)(LLVMValueRef, void *),
188+
void *MaterializerData);
189+
190+
// Clone the body of OldFunc into NewFunc, like CloneFunctionInto, using and extending the
191+
// value map VM (which must map the arguments of OldFunc).
192+
void LLVMExtraCloneFunctionInto(LLVMValueRef NewFunc, LLVMValueRef OldFunc,
193+
LLVMValueMapRef VM, LLVMCloneFunctionChangeType Changes,
194+
const char *NameSuffix,
195+
LLVMTypeRef (*TypeMapper)(LLVMTypeRef, void *),
196+
void *TypeMapperData,
197+
LLVMValueRef (*Materializer)(LLVMValueRef, void *),
198+
void *MaterializerData);
199+
200+
// Prepare mapping a value or metadata, or cloning a function, with a value map and type
201+
// mapper: call the type mapper on every type that the operation will map (so that a type
202+
// mapper that fails can do so before anything is mapped), and remove the entries for
203+
// deleted values that the operation would look up (the value mapper expects every entry to
204+
// have a value). The type mapper may be NULL.
205+
void LLVMExtraPrepareMapValue(LLVMValueRef V, LLVMValueMapRef VM,
206+
LLVMTypeRef (*TypeMapper)(LLVMTypeRef, void *),
207+
void *TypeMapperData);
208+
void LLVMExtraPrepareMapMetadata(LLVMMetadataRef MD, LLVMValueMapRef VM,
209+
LLVMTypeRef (*TypeMapper)(LLVMTypeRef, void *),
210+
void *TypeMapperData);
211+
void LLVMExtraPrepareCloneFunctionInto(LLVMValueRef OldFunc, LLVMValueMapRef VM,
212+
LLVMCloneFunctionChangeType Changes,
213+
LLVMTypeRef (*TypeMapper)(LLVMTypeRef, void *),
214+
void *TypeMapperData);
215+
147216
LLVMBasicBlockRef LLVMCloneBasicBlock(LLVMBasicBlockRef BB, const char *NameSuffix,
148217
LLVMValueRef *ValueMap, unsigned ValueMapElements,
149218
LLVMValueRef F);

0 commit comments

Comments
 (0)