Vuo  0.3
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Static Public Member Functions | List of all members
VuoCompilerCodeGenUtilities Class Reference

Description

Handy methods for generating code.

Static Public Member Functions

static GlobalVariable * generateAllocationForSemaphore (Module *module, string identifier)
 Generates code that allocates a dispatch_semaphore_t.
 
static void generateInitializationForSemaphore (Module *module, BasicBlock *block, GlobalVariable *semaphoreVariable, int initialValue=1)
 Generates code that initializes a dispatch_semaphore_t.
 
static void generateWaitForSemaphore (Module *module, BasicBlock *block, GlobalVariable *semaphoreVariable, dispatch_time_t timeout=DISPATCH_TIME_FOREVER)
 Generates code that waits for and claims a dispatch_semaphore_t.
 
static void generateSignalForSemaphore (Module *module, BasicBlock *block, GlobalVariable *semaphoreVariable)
 Generates code that releases a dispatch_semaphore_t.
 
static GlobalVariable * generateAllocationForDispatchGroup (Module *module, string identifier)
 Generates code that allocates a dispatch_group_t.
 
static void generateInitializationForDispatchGroup (Module *module, BasicBlock *block, GlobalVariable *dispatchGroupVariable)
 Generates code that initializes a dispatch_group_t.
 
static void generateSubmissionForDispatchGroup (Module *module, BasicBlock *block, GlobalVariable *dispatchGroupVariable, Function *workerFunction, Value *contextValue)
 Generates code that submits a function for asynchronous execution on the global dispatch queue and associates the function with a dispatch_group_t.
 
static void generateWaitForDispatchGroup (Module *module, BasicBlock *block, GlobalVariable *dispatchGroupVariable, dispatch_time_t timeout=DISPATCH_TIME_FOREVER)
 Generates code that waits on a dispatch_group_t.
 
static GlobalVariable * generateAllocationForDispatchQueue (Module *module, string identifier)
 Generates code that allocates a dispatch_queue_t.
 
static void generateInitializationForDispatchQueue (Module *module, BasicBlock *block, GlobalVariable *dispatchQueueVariable)
 Generates code that initializes a dispatch_queue_t.
 
static void generateSubmissionToDispatchQueue (Module *module, BasicBlock *block, GlobalVariable *dispatchQueueVariable, Function *workerFunction, Value *contextValue)
 Generates code that submits a function for asynchronous execution on a dispatch queue.
 
static void generateFinalizationForDispatchObject (Module *module, BasicBlock *block, GlobalVariable *dispatchObjectVariable)
 Generates code that finalizes a dispatch_object_t (dispatch_queue_t, dispatch_group_t, dispatch_semaphore_t, etc.).
 
static Value * generatePointerToValue (BasicBlock *block, Value *value)
 Generates code that creates a pointer to value (on the stack), and returns the pointer.
 
static Constant * generatePointerToConstantString (Module *module, string stringValue, string globalVariableName="")
 Generates code that creates a global string variable, initialized to the given value, and returns a pointer to it.
 
static Constant * generatePointerToConstantArrayOfStrings (Module *module, vector< string > stringValues)
 Generates code that creates a global array-of-strings variable, initialized to the given values, and returns a pointer to it.
 
static void generateStringMatchingCode (Module *module, Function *function, BasicBlock *initialBlock, BasicBlock *finalBlock, Value *inputStringValue, map< string, pair< BasicBlock *, BasicBlock * > > blocksForString)
 Generates a series of if-else statements for testing if an input string is equal to any of a set of constant strings, and executing the corresponding block of code if it is.
 
static Value * generateMemoryAllocation (Module *module, BasicBlock *block, Type *elementType, Value *elementCountValue)
 Generates code that dynamically allocates memory for an array.
 
static Type * getParameterTypeBeforeLowering (Function *function, int parameterIndex, Module *module, string typeName)
 Guesses the type that the function parameter had in the source code, before it was possibly converted ("lowered") to some other type by Clang/LLVM when the module was compiled.
 
static Value * convertArgumentToParameterType (Value *argument, Function *function, int parameterIndex, Value **secondArgument, Module *module, BasicBlock *block)
 If needed, generates code to convert the argument to the (possibly "lowered") type(s) of the function parameter(s).
 
static Value * convertReturnValueToExpectedType (Value *returnValue, Type *expectedType, BasicBlock *block)
 If needed, generates code to convert the return value from its (possibly "lowered") type to the expected type.
 
static Value * callFunctionWithStructReturn (Function *function, vector< Value * > args, BasicBlock *block)
 Generates a call to the function, whose first parameter is assumed to have LLVM's sret attribute.
 
static bool isFunctionReturningStructViaParameter (Function *function)
 Returns true if the function's first parameter has LLVM's sret attribute, or in other words, LLVM has transformed struct MyType foo(...) to void foo(struct MyType *, ...).
 
static Function * getStrcmpFunction (Module *module)
 Returns a Function reference, generating code for the declaration if needed.
 
static Function * getMallocFunction (Module *module)
 
static Function * getInitializeReferenceCountsFunction (Module *module)
 
static Function * getFinalizeReferenceCountsFunction (Module *module)
 
static Function * getVuoRetainFunction (Module *module)
 
static Function * getVuoReleaseFunction (Module *module)
 
static StructType * getDispatchObjectType (Module *module)
 

Member Function Documentation

Value * VuoCompilerCodeGenUtilities::convertArgumentToParameterType ( Value *  argument,
Function *  function,
int  parameterIndex,
Value **  secondArgument,
Module *  module,
BasicBlock *  block 
)
static

If needed, generates code to convert the argument to the (possibly "lowered") type(s) of the function parameter(s).

Parameters
argumentThe argument to be converted.
functionThe function the argument is being passed to.
parameterIndexThe index of the first (and possibly only) function parameter corresponding to argument.
[out]secondArgumentPointer to the second converted argument, to be passed to the second function parameter corresponding to argument. If none, pass NULL.
moduleThe module in which to generate code.
blockThe block in which to generate code.
Returns
The first converted argument, to be passed to the first (and possibly only) function parameter corresponding to argument. May be the same as argument.
GlobalVariable * VuoCompilerCodeGenUtilities::generateAllocationForDispatchGroup ( Module *  module,
string  identifier 
)
static

Generates code that allocates a dispatch_group_t.

Parameters
identifierThe variable name to use for the dispatch_group_t variable.
Returns
The dispatch_group_t variable.
GlobalVariable * VuoCompilerCodeGenUtilities::generateAllocationForDispatchQueue ( Module *  module,
string  identifier 
)
static

Generates code that allocates a dispatch_queue_t.

Parameters
identifierThe variable name to use for the dispatch_queue_t variable.
Returns
The dispatch_queue_t variable.
GlobalVariable * VuoCompilerCodeGenUtilities::generateAllocationForSemaphore ( Module *  module,
string  identifier 
)
static

Generates code that allocates a dispatch_semaphore_t.

Parameters
identifierThe variable name to use for the dispatch_semaphore_t variable.
Returns
The dispatch_semaphore_t variable.
Value * VuoCompilerCodeGenUtilities::generateMemoryAllocation ( Module *  module,
BasicBlock *  block,
Type *  elementType,
Value *  elementCountValue 
)
static

Generates code that dynamically allocates memory for an array.

Parameters
elementTypeThe type of each array element.
elementCountValueThe number of array elements. Assumed to have type integer.
Returns
A value pointing to the address of the memory.
void VuoCompilerCodeGenUtilities::generateStringMatchingCode ( Module *  module,
Function *  function,
BasicBlock *  initialBlock,
BasicBlock *  finalBlock,
Value *  inputStringValue,
map< string, pair< BasicBlock *, BasicBlock * > >  blocksForString 
)
static

Generates a series of if-else statements for testing if an input string is equal to any of a set of constant strings, and executing the corresponding block of code if it is.

Assumes that none of the blocks passed to this function contain branch instructions. (This function appends branch instructions to all but the final block.)

Example:

if (! strcmp(inputString, string0)) // blockForString[string0] else if (! strcmp(inputString, string1)) // blockForString[string1] ...

Parameters
initialBlockThe block to which the first if-statement will be appended.
finalBlockThe block following the if-else statements.
inputStringValueThe string to compare in each if-statement.
blocksForStringFor each key string, the first block and last block to execute if the input string matches that string. The caller is responsible for branching (directly or indirectly) from the first to the last block.
Type * VuoCompilerCodeGenUtilities::getParameterTypeBeforeLowering ( Function *  function,
int  parameterIndex,
Module *  module,
string  typeName 
)
static

Guesses the type that the function parameter had in the source code, before it was possibly converted ("lowered") to some other type by Clang/LLVM when the module was compiled.

(For example, a struct whose members are all floats may be lowered to a vector of floats.)


The documentation for this class was generated from the following files: