Method RegisterName
RegisterName<T>(T, String)
Sets the virtual register name for a value
Declaration
public static T RegisterName<T>(this T value, string name)
where T : Value
Parameters
public static T RegisterName<T>(this T value, string name)
where T : Value
T | value | Value to set register name for |
String | name | Name for the virtual register the value represents |
Returns
T |
|
Type Parameters
T | Type of the value to set the name for |
Remarks
Technically speaking only an Instruction can have register name information. However, since LLVM will perform constant folding in the InstructionBuilder most of the methods in InstructionBuilder return a Value rather than a more specific Instruction. Thus, without this extension method here, code would need to know ahead of time that an actual instruction would be produced then cast the result to an Instruction and then set the debug location. This makes the code rather ugly and tedious to manage. Placing this as a generic extension method ensures that the return type matches the original and no additional casting is needed, which would defeat the purpose of doing this. For Value types that are not instructions this does nothing. This allows for a simpler fluent style of programming where the actual type is retained even in cases where an InstructionBuilder method will always return an actual instruction.
Since the Name property is available on all Values this is slightly redundant. It is useful for maintaining the fluent style of coding along with expressing intent more clearly. (e.g. using this makes it expressly clear that the intent is to set the virtual register name and not the name of a local variable etc...) Using the fluent style allows a significant reduction in the number of overloaded methods in InstructionBuilder to account for all variations with or without a name.