[cfe-dev] Implementing front-end of a user-directed optimization

Probir Roy via cfe-dev cfe-dev at lists.llvm.org
Tue Jun 23 12:13:29 PDT 2020


I was able to add attributes to AST. However, I am currently stuck in
code generation. I am trying to add meta-data to the AttributedStmt
but I am not sure how to do it.

For now, I have generated the following AttributedStmt in AST:

|   |-AttributedStmt 0x5630129efcc8 <<invalid sloc>, line:12:16>
|   | |-MyCustomAttr 0x5630129efc90 <line:11:9, col:38> Implicit Call foo foo2
|   | `-BinaryOperator 0x5630129efc70 <line:12:2, col:16> 'int' '='
|   |   |-DeclRefExpr 0x5630129efb78 <col:2> 'int' lvalue Var
0x5630129ef9d8 'c2' 'int'
|   |   `-CallExpr 0x5630129efc10 <col:7, col:16> 'int'
|   |     |-ImplicitCastExpr 0x5630129efbf8 <col:7> 'int (*)(int,
int)' <FunctionToPointerDecay>
|   |     | `-DeclRefExpr 0x5630129efb98 <col:7> 'int (int, int)'
Function 0x5630129ef5a0 'foo2' 'int (int, int)'
|   |     |-ImplicitCastExpr 0x5630129efc40 <col:12> 'int' <LValueToRValue>
|   |     | `-DeclRefExpr 0x5630129efbb8 <col:12> 'int' lvalue Var
0x5630129ef8d8 'a' 'int'
|   |     `-ImplicitCastExpr 0x5630129efc58 <col:15> 'int' <LValueToRValue>
|   |       `-DeclRefExpr 0x5630129efbd8 <col:15> 'int' lvalue Var
0x5630129ef958 'b' 'int'

Now, I want to add some metadata to these enclosed attributed
statements and generate IR. I understand that I can use setMetadata
for adding metadata to an instruction.
For the above case, should I create a new block with the attributed
statements and then add meta-data to the block? How can I create a new
block with the attributed statement?
Can you please provide some directions/example code on how to add
metadata to the "attributed" statements?

Here is the example code and generated AST:
https://gist.github.com/proywm/a8c47bc8b863a782d4201499f2aae2a1

-- 
Probir Roy


More information about the cfe-dev mailing list