Mark code from source to IR

Hi everyone,

I am looking at a way to mark part of a source code for an optimisation pass (or how to transfert information from source code to IR).

I want to work on C / C++ / Objective-c and Swift.

Something like:


//Begin Optimisation
if(i % 2){
printf(“Something”);
}
//End Optimisation

for(int i = 0; i < 10; ++i){
printf(“%d, “, i);
}
printf(”\n”);

I have found several informations here: http://clang-analyzer.llvm.org/annotations.html. I was thinking about using #pragma or annotate attribute but this is not working on Swift.

Does anyone has an hint to begin with?

Greetings,

Johan

Hi,

I am looking at a way to mark part of a source code for an optimisation pass (or how to transfert information from source code to IR).

Does it have to be comments, or could you do something like this?

if (optimize_me(i%2)) {

}

You could look at how __builtin_expect is handled inside the compiler. In lib/Transforms/Scalar/LowerExpectIntrinsic.cpp, branch weight metadata is generated based on that function. You could probably adapt this to generate the metadata that you need.

Best,
Jonas

Hi Jonas,

Does it have to be comments, or could you do something like this?

Not at all, it was just an example, it can pragma or builtin function or anything else.

You could look at how __builtin_expect is handled inside the compiler. In lib/Transforms/Scalar/LowerExpectIntrinsic.cpp, branch weight metadata is generated based on that function. You could probably adapt this to generate the metadata that you need.

I will take a look at it thanks.

Greetings.

Johan