Would LLVM be adapted to express and do some kind of function "partial evaluation", like having a function of 2 arguments, and when a value of one of the 2 parameter is known, the function could be specialized to produce as result a more efficient new function that would take one 1 parameter. I was told that the "ReplaceAllUsesWith" operation could be possibly used for that purpose. Is there any example of this technique I could look at?
Thanks in advance.
LLVM has direct API support for this.
1. Compile your generic function to LLVM bytecode.
2. In the code that does the specialization, create a new Function object
with just the new set of arguments (the specialized arguments should
not be created).
3. Create a DenseMap<const Value*, Value*> ValueMap object. Populate it
with mappings from the generic function's arguments to either the new
functions arguments (if they are not specialized) or the constants you
want to specialize the argument to.
4. Call the CloneAndPruneFunctionInto function
(llvm/Transforms/Utils/Cloning.h) passing in the new empty
(destination) function, the generic "source" function, and your value
5. Run any other optimizations that you want over the new function.