Hello!
I am trying to dynamically detect parallelism in a swift program. for that, I am trying to instrument the llvm ir emitted by the front end of the compiler and I instrument it with calls to a runtime library. every time a read to a memory location occurs or a write, a call to the runtime happens with the address and the name of this variable. this way I can gather information about variable dependencies at runtime.
this works well for C/C++ programs. I have notice one problem in my approach when it comes to swift and its datatypes however.
I am using swift 5.1 and ran into the following issue(for me)
var ar = [1, 2, 3, 4, 5, 8];
var temp = 0;
temp = ar[0]
so what would happen in C/C++ with any standard library is that I would get the address of the array at index 0 and then I would see a load and store instruction in the LLVM IR. with swift however, there is a call to the standard library but instead of returning an address, it returns the element at that index by itself. so this dependency could not be detected by my approach.
%16 = call swiftcc i64 @"$sSayxSicigSi_Tg5"(i64 0, %Ts28__ContiguousArrayStorageBaseC* %13)
%._value6 = getelementptr inbounds %TSi, %TSi* %2, i32 0, i32 0
store i64 %16, i64* %._value6, align 8
%._value7 = getelementptr inbounds %TSi, %TSi* %2, i32 0, i32 0
%17 = load i64, i64* %._value7, align 8
%temp._value8 = getelementptr inbounds %TSi, %TSi* %temp, i32 0, i32 0
store i64 %17, i64* %temp._value8, align 8
swift makes a call to the stdlib subscript function which then calls get element returns the element from the underlying buffer.
can I do this some way?