llvm-c++-api

LLVM. How to access to struct fields based on their names?

时间秒杀一切 提交于 2019-11-30 10:00:53
I have little example code in C++: struct RecordTest { int value1; int value2; }; void test() { RecordTest rt; rt.value1 = 15; rt.value2 = 75; } and LLVM 3.4 IR for it: %struct.RecordTest = type { i32, i32 } ; Function Attrs: nounwind define void @_Z4testv() #0 { entry: %rt = alloca %struct.RecordTest, align 4 %value1 = getelementptr inbounds %struct.RecordTest* %rt, i32 0, i32 0 store i32 15, i32* %value1, align 4 %value2 = getelementptr inbounds %struct.RecordTest* %rt, i32 0, i32 1 store i32 75, i32* %value2, align 4 ret void } and a pretty easy question: How can I access to RecordTest

Adding Metadata to Instructions in LLVM IR

血红的双手。 提交于 2019-11-28 21:16:14
问题 First up, I am a newbie to LLVM passes. I am trying to add metadata to instructions in LLVM after a transformation pass (with the C++ API). I intend to store this information for use by another tool in a tool chain. I have two questions regarding this. I expect the information I store as metadata to feed into another tool which works on the LLVM IR. So is metadata a good idea ? I intend to store strings as metadata with some instructions. If metadata is the right way to go here, I need some