Equivalent #include for LLVM IR

I found myself with a fairly large number of useful functions and constants written in LLVM IR. I can use this pseudo library by combining it with a manual IR interface, provided that the specified manual IR starts with a potentially long list of announcements. I know that IR is not necessarily intended as a general-purpose programming language to write material.

This is very similar to writing multiple C functions to a single file, and then reusing them wherever they are used. In C, this works using #include and header files. It's not perfect, but it beats repetition of prototypes.

What is the least unpleasant way to achieve something similar in IR? This is only necessary in order to type material again and again (which I am doing now in copy and paste mode) and use cat as a step of custom assembly.

Thank!

+4
source share
2 answers

Unfortunately, there is no such thing in LLVM IR.

LLVM IR is not intended for a large number of hand-written. Therefore, it does not have a mechanism #include. The work of processing this kind of material gets to the compiler using the LLVM API.

, , , , , - , , .

+1

llvm-link IR .

, .

// file : f1.ll
; Function Attrs: nounwind readnone
define i32 @f1(i32 %a) #0 {
entry:
  ret i32 %a
}

// file : f2.ll
; Function Attrs: nounwind
define i32 @f2(i32 %a) #0 {
entry:
%call = tail call i32 @f1(i32 %a) #2
 ret i32 %call
}

llvm-link f1.ll f2.ll -S -o ffinal.ll

ffinal.ll -.

0

Source: https://habr.com/ru/post/1685523/


All Articles