Questions tagged [llvm]

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. The llvm tag is mostly for writing C++ code (or another language via the C bindings) to interface with the LLVM library, not about any of the (growing amount of) tools that have LLVM under the hood. See the `llvm-codegen` tag for questions about machine code generated by LLVM.

Welcome to the LLVM Project.

The LLVM Core libraries provide a modern source- and target-independent optimizer, along with code generation support for many popular CPUs (as well as some less common ones!).

These libraries are built around a well specified code representation known as the LLVM intermediate representation ("LLVM IR").

The LLVM Core libraries are well documented, and it is particularly easy to invent your own language (or port an existing compiler) to use LLVM as an optimizer and code generator.

As much as everything else, LLVM has a broad and friendly community of people who are interested in building great low-level tools. If you are interested in getting involved, a good first place is to skim the LLVM Blog and to sign up for the LLVM Developer mailing list.

What not to ask: user-level questions about XCode are off-topic, please only use the tag for those. The tag is mostly for writing C++ code (or another language via the C bindings) to interface with the LLVM library, not about any of the (growing amount of) tools that have LLVM under the hood.

Books

6394 questions
17
votes
2 answers

Why does the Rust compiler not reuse the memory on the stack after an object is moved?

I thought that once an object is moved, the memory occupied by it on the stack can be reused for other purpose. However, the minimal example below shows the opposite. #[inline(never)] fn consume_string(s: String) { drop(s); } fn main() { …
Zhiyao
  • 4,152
  • 2
  • 12
  • 21
17
votes
3 answers

How to build LLVM (clang,clang++) for Apple M1?

I am trying to build LLVM compilers so that I can enable OpenMP on the Apple M1. I am using the LLVM development tree, (since I saw some OpenMP runtime go into that for this recently). I have ended up with this script to invoke cmake: # Xcode,…
Jim Cownie
  • 2,409
  • 1
  • 11
  • 20
17
votes
1 answer

LLVM assembly: assign integer constant to register

I'm writing a compiler that uses LLVM as a backend, and my compiler generates the following LLVM assembly code @0 = private constant [25 x i8] c"Hello World to %dntegers\00" declare void @printf (i8*, i32) define void @main () { %1 =…
Mildred
  • 3,887
  • 4
  • 36
  • 44
17
votes
1 answer

How to emit debug information through LLVMs C bindings?

I'm currently toying around with a simple LLVM frontend written in Rust. I'm now trying to emit debug information. How can I emit this debug information (source locations and variables) through the C bindings? Is it even possible? Do I need to…
dotjpg3141
  • 305
  • 1
  • 10
17
votes
2 answers

LLVM IR alloca instruction

I want to design a IR (like LLVM IR) for my toy compiler and I don't know what is the purpose of the alloca instruction in further analysis. In which optimizations alloca informations are used?
temp01m7
  • 183
  • 1
  • 1
  • 5
17
votes
4 answers

What versions of gcc, llvm and clang are in XCode 4?

For some reason, this information is difficult to come by. We'd like to start using some of the C++0x features that are available in most compilers. But we are held back a bit by XCode 3, since it only provides GCC 4.2 and LLVM 1.5. All of the…
leedm777
  • 23,444
  • 10
  • 58
  • 87
17
votes
5 answers

How to install LLVM for Mac?

How do I install LLVM on macOS Sierra? I've tried brew install llvm but when trying to use an llvm command like lli I get a command not found error.
user12345
  • 173
  • 1
  • 1
  • 5
17
votes
2 answers

Xcode 8 with "Release: Fastest, Smallest [-Os]" have some weird issue and not functional well in some case

I have 1 target in my project and have 3 build configuration Debug Production & Release While I am running my app with debug or production configuration and its working fine with no issues at all, but when I change my build configuration to release…
CodeChanger
  • 7,953
  • 5
  • 49
  • 80
17
votes
1 answer

Running GHC's LLVM output through the LLVM bitcode linker first

I want to be able to call LLVM code from Haskell without the overhead of a full function call. For example: -- Main.hs -- {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE GHCForeignImportPrim #-} {-# LANGUAGE…
Clinton
  • 22,361
  • 15
  • 67
  • 163
17
votes
3 answers

How to make llvm .bc file executable?

I have created a toy language that generates IR code and writes that code to a binary file with WriteBitcodeToFile (the C API). The result is a my-file.bc file. In this file I have defined a main() function that takes no arguments and returns an…
Fredrik Andersson
  • 3,567
  • 3
  • 19
  • 21
17
votes
5 answers

Any tutorial for embedding Clang as script interpreter into C++ Code?

I have no experience with llvm or clang, yet. From what I read clang is said to be easily embeddable Wikipedia-Clang, however, I did not find any tutorials about how to achieve this. So is it possible to provide the user of a c++ application with…
FFox
  • 1,550
  • 2
  • 17
  • 26
17
votes
2 answers

Xcode "Message from debugger: got unexpected response to k packet: OK"

I got this message when testing my app on simulator: Message from debugger: got unexpected response to k packet: OK What does it mean and is my app in any sort of danger? Using Xcode 6.4 & 7.2
noobsmcgoobs
  • 2,716
  • 5
  • 32
  • 52
17
votes
1 answer

How to detect -stdlib=libc++ in the preprocessor?

I think this is part of the problem at No type named 'unique_ptr' in namespace 'std' when compiling under LLVM/Clang. According to Marshall Clow, I can detect -stdlib=libc++ via _LIBCPP_VERSION: If you're writing cross-platform code, sometimes you…
jww
  • 97,681
  • 90
  • 411
  • 885
17
votes
3 answers

Linking LLVM JIT Code to Static LLVM Libraries?

I'm in the process of implementing a cross-platform (Mac OS X, Windows, and Linux) application which will do lots of CPU intensive analysis of financial data. The bulk of the analysis engine will be written in C++ for speed reasons, with a…
inflector
  • 363
  • 3
  • 12
17
votes
3 answers

What effect does #define X X have in C?

In the source code of stdbool.h in LLVM project, it reads: /* Don't define bool, true, and false in C++, except as a GNU extension. */ #ifndef __cplusplus #define bool _Bool #define true 1 #define false 0 #elif defined(__GNUC__) &&…
Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52