I want to make target independent IR with LLVM.
clang -emit-llvm -S source.c -o source.ll
in source.ll
target datalayout = "e-m:e-i64:..."
target triple = "x86_64-pc-linux-gnu"
...
LLVM IR is said to be Target-independent, but the properties of the target are specified in the actual IR file.
How can I create an LLVM IR without this Target property?
Short answer: you cannot
Long answer: target-neutrality is the property of input language, not the LLVM IR. While in theory it is possible to make more or less target-neutral LLVM IR for some inputs it is not possible for C/C++ inputs. I will only mention few things that prevents us from having such LLVM IR:
#ifdef
clauses obviously make resulting IR target-specificsizeof(void*)
. These are target-dependent compile-time constants (yes, there are ways to defer calculation of these constants later on, but this is not something frontends are prepared to deal with, this also hinders many optimizations)struct { int foo; void* bar; }