All Questions
76 questions
0
votes
3
answers
144
views
When inlining a C function, can an optimizing compiler dereference a pointer more times than explicitly written in the source code?
Consider the following code:
int y = 1;
int* p = &y;
inline int f(int x) {
return x + x;
}
int g(void) {
return f(*p);
}
In this code, there is one explicit dereference.
Is a C compiler ...
1
vote
1
answer
134
views
What is the reasoning behind this boilerplate start-up code?
Here's a snippet from disassembled output of a simple program with gcc on Linux:
400478: ff 15 6a 0b 20 00 callq *0x200b6a(%rip) # 600fe8 <__libc_start_main@GLIBC_2.2.5>
...
1
vote
0
answers
58
views
Unknown type name ‘Node’ in the parser file. (Yacc program)
I've been working on a Yacc program (parser.y) to develop a small compiler that handles arithmetic operations. I'm using Yacc (Bison) and Lex tools to generate the parser and lexical analyzer, ...
2
votes
0
answers
138
views
Write a gcc plugin that inserts macros at the beginning of each function
I understand that I can use __cyg_profile_func_enter and -finstrument-functions to insert code, but is it possible to insert macros by writing a gcc plugin?
Is there any documentation or possibly an ...
2
votes
3
answers
501
views
Why do compilers perform aliasing if it slows runtime performance?
I've been learning C and computer science topics out of pure interest and it's led me to becoming interested in compilers. Everything I've read tells me that aliasing results in slower assembly output ...
1
vote
0
answers
119
views
Why does the compiler need the intermediate representations for link time optimization?
My professor mentioned that gcc can be run with -flto. I am wondering why the intermediary (GIMPLE in GCC case) are needed.
Why is the assembly not sufficient?
He mentioned that this allows the ...
1
vote
0
answers
192
views
Why "a==b" in C is compiled to "xor; j; sltu" in assembly? - Why instruction after unconditional jump? [duplicate]
I want to see how == is compiled in C. Thus I try a simple code:
#include <stdio.h>
int f(int a,int b) {
return a==b; // NOTE THIS
}
int main(void) {
int a,b,c;
scanf("%d"...
3
votes
1
answer
110
views
Why most compilers can't do modulus calculation combination optimization?
unsigned long f1(unsigned long num) {
if (num % 5L == 0 && num % 3L == 0) { return 1000; }
return 0;
}
unsigned long f2(unsigned long num) {
if (num % 15L == 0) { return 1000; }
...
4
votes
1
answer
423
views
How to make change gcc calling convention
Hi I would like to tell gcc how to call functions, for example:
__mycall void my_function(arg1) {
do_something(arg1)
}
__mycall:
move $a0, (the first argument)
...
1
vote
1
answer
178
views
Is it possible to generate ansi C functions with type information for a moving GC implementation?
I am wondering what methods there are to add typing information to generated C methods. I'm transpiling a higher-level programming language to C and I'd like to add a moving garbage collector. However ...
1
vote
1
answer
500
views
Modify AST tree in C and compile the new AST tree
What I want to do is
1. Parse C code to generate AST
2. Modify the AST
3. Compile the new AST without changing the .c source file.
Is there any tool I can use to do this? If not, is there any tool I ...
1
vote
1
answer
346
views
Building gcc plugin for windows on linux
Try to build the following gcc plugin on linux for windows with mingw cross compiler. The plugins are from the built avr compiler also for windows. Adapted the following plugin https://github.com/...
2
votes
1
answer
1k
views
How to construct a data dependence graph from Assembly code
I would like to know if there is any existing tools that can construct a data dependence graph, starting from an assembly piece of code?
My objective is: starting from a set of assembly instructions (...
1
vote
0
answers
464
views
Subroutine reordering, reducing TLB misses
Let's say I have an algorithm which would optimize subroutine ordering, in hopes to reduce TLB misses.
How would one be able actually to reorder subroutines at run-time in gcc compiler? So far I ...
1
vote
1
answer
495
views
C compiler reference implementation
There are multiple languages that have a reference implementation of their compiler/libraries, but why doesn't C have a reference implementation?
I know that GCC and glibc are used extensively and ...