Since no one seems to have a good solution to my problem, I will talk about my own inconvenient approach to solving this problem. MetaData nodes created by LLVM contain information about specific types and variables of code. However, there is no information about which generated IR variables correspond to those source code variables. LLVM simply associates the metadata information of the IR instructions with the corresponding source locations (rows and columns). This makes sense because the main purpose of LLVM metadata is not debugging, but debugging.
However, the information contained is not useless. My solution to these problems is to use clang AST to parse the source code. Here we get information about which variable is accessed, in which place of the source. Thus, to obtain information about the identifiers of the source variable during the LLVM IR toolkit, we just need to match the source locations with the identifiers of the source variables during the analysis of the clang AST analysis. As a second step, we carry out infrared devices using our previously collected information. When we come across a store or load statement in IR, we search the node metadata for that statement for the corresponding source location. Because we have mapped source locations to source variable identifiers, we can now easily access the source variable identifier of an IR instruction.
So why am I not just using clang AST to define storages and variable loads? Because excellent reading and writing to the AST is not an easy task. AST can easily tell you that a variable is available, but depends on whether the available variable is being read or written. Therefore, I would have to look at each operation / operator to determine whether a variable is written or read, or both. In this regard, LLVM is much simpler, lower level and, as a result, less error prone. Moreover, the actual hardware (inserting a speech code) is much more complicated in AST than in LLVM. For these two reasons, I think the combination of Clang AST and LLVM IR is the best solution for my problem.
source share