Questions tagged [llvm-codegen]

Questions about how LLVM generates machine code from LLVM-IR or high-level languages. If you are asking about a specific CPU architecture, please also add that corresponding tag (e.g. `x86`).

LLVM's main use is to generate (CPU dependent) machine code from LLVM-IR. This LLVM-IR is often generated by a compiler of a high-level language (e.g. clang++ for C++ code or rustc for Rust code). This tag hosts all questions about the translation of LLVM-IR or high-level languages to machine code. Example: "How is a 128-bit LLVM integer implemented on 64-bit hardware?"

45 questions
2
votes
0 answers

What are code models and how do they affect code generation?

In rustc, there are 4 code models. You can see the list by typing rustc --print code-models: Available code models: small kernel medium large What do they mean?
William Taylor
  • 549
  • 3
  • 22
2
votes
3 answers

What optimization techniques are applied to Rust code that sums up a simple arithmetic sequence?

The code is naive: use std::time; fn main() { const NUM_LOOP: u64 = std::u64::MAX; let mut sum = 0u64; let now = time::Instant::now(); for i in 0..NUM_LOOP { sum += i; } let d = now.elapsed(); println!("{}",…
Sanhu Li
  • 402
  • 5
  • 11
2
votes
1 answer

What LLVM passes are performed on emitted LLVM IR?

If I compile with cargo rustc -- --emit=llvm-ir the compiler will emit LLVM IR. Here are the LLVM passes that Rust uses. What LLVM passes, if any, have been performed on the emitted IR? Is there any way to specify what passes you would like…
HiDefender
  • 2,088
  • 2
  • 14
  • 31
1
vote
0 answers

Selection DAG from LLVM IR?

I have fetched LLVM-IR via clang -S -emit-llvm demo.c where demo.c is as follows int demo(int a, int b){ int c = a+b; return c; } The IR looks like define dso_local i32 @demo(i32 %0, i32 %1) #0 { %3 = alloca i32, align 4 %4 = alloca i32, align…
pralay das
  • 11
  • 1
1
vote
1 answer

LLVM-C creating object file results in: "TargetMachine can't emit a file of this type"

Trying to generate a very simple object file with LLVM-C. Unfortunately I'm still stuck on "TargetMachine can't emit a file of this type" tried reordering code and various things for CPU (x64-64, generic and LLVMGetHostCPUName()). Clearly something…
Mirks
  • 116
  • 1
  • 5
1
vote
2 answers

Statically scheduling OOO processors

The LLVM MISched instruction scheduler uses declarative TableGen descriptions of the processor functional units, pipelines and latencies. Imagine trying to determine the equivalent of the coding guidelines from Intel's Optimization Reference Manual…
Olsonist
  • 2,051
  • 1
  • 20
  • 35
1
vote
0 answers

LLVM creating executable code from C/C++ builder

I have get an example llvm code from here. This code has some problems that I fixed them too. At this point, all it does is to dump the translated IR code. What I am after is to create an executable from my C++ code without calling llvm-as/llc/clang…
ar2015
  • 5,558
  • 8
  • 53
  • 110
1
vote
0 answers

Error invoking LLVM CodeGen pass using clang: Trying to construct TargetPassConfig without a target machine

I have been trying to invoke my out-of-tree LLVM Function pass using clang (opt is not an option. Works fine with opt btw): clang -std=c99 -m64 -c -o file.o -DSPEC -DNDEBUG -Ispec_qsort -DSPEC_AUTO_SUPPRESS_OPENMP -g -march=native …
sk10
  • 73
  • 1
  • 8
1
vote
0 answers

Get Size of LLVM Type / "Dereference" Type

This question is quite similar to this one, but I am not realy sure how to get the size in the following situation: I have a Pointer type, e.g. i32*. Now I would like to get the size of the 'pointed-to' type, so i32 (aka 4). Right now I am using the…
mame98
  • 1,271
  • 12
  • 26
1
vote
1 answer

How to map multiple same type loops under a function to the generated basic block in LLVM IR?

If the loops are of the different type then I can easily identify them with the name but if there are multiple same type loops (say 5 while loops), how can I identify what basic block in the LLVM IR corresponds to which loop in the source…
Sanjit Kumar Mishra
  • 1,153
  • 13
  • 32
0
votes
0 answers

how to integrate new custom backend in the LLVM

Is there any good understable resources for a beginner, which will demonstrate clearly (exact path) from scratch how to integrate new custom backend from LLVM-IR? I have read Creating an LLVM Backend for the Cpu0 Architecture but I have found , it…
pralay das
  • 11
  • 1
0
votes
1 answer

LLVM C-API Lifecycles of core objects

I've started playing with LLVM, making a pet language. I'm using the C-API. I have a parser and basic AST, but I am at a bit of a road block with LLVM. The following is a minified version of my code to illustrate my current issue: #include…
0
votes
1 answer

x86_64 incorrect calling convention when calling function

I'm relatively new to LLVM, and I'm attempting to generate LLVM IR that calls a C function (growDictionary). This is on x86_64 Linux, using llvm 12: $ llc-12 --version Ubuntu LLVM version 12.0.1 Optimized build. Default target:…
Tudor Bosman
  • 61
  • 1
  • 5
0
votes
0 answers

Emitting Object Code In Memory With LLVM's C API

I'm using the LLVM-C API for a compiler project and need to emit object code from IR to an in memory buffer. I'm aware the JIT can do this, but the resulting code will be executed many times with different arguments so statically compiling once…
muke
  • 306
  • 2
  • 11
-6
votes
2 answers

Why is swapping elements of a []float64 in Go faster than swapping elements of a Vec in Rust?

I have two (equivalent?) programs, one in Go the other in Rust. The average execution time is: Go ~169ms Rust ~201ms Go package main import ( "fmt" "time" ) func main() { work := []float64{0.00, 1.00} start := time.Now() …
Kyle
  • 11
  • 2
1 2
3