Code Monkey home page Code Monkey logo

patmos-llvm-project's Introduction

The LLVM Compiler Infrastructure

This directory and its sub-directories contain source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.

The README briefly describes how to get started with building LLVM. For more information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.

Getting Started with the LLVM System

Taken from https://llvm.org/docs/GettingStarted.html.

Overview

Welcome to the LLVM project!

The LLVM project has multiple components. The core of the project is itself called "LLVM". This contains all of the tools, libraries, and header files needed to process intermediate representations and converts it into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer. It also contains basic regression tests.

C-like languages use the Clang front end. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.

Other components include: the libc++ C++ standard library, the LLD linker, and more.

Getting the Source Code and Building LLVM

The LLVM Getting Started documentation may be out of date. The Clang Getting Started page might have more accurate information.

This is an example work-flow and configuration to get and build the LLVM source:

  1. Checkout LLVM (including related sub-projects like Clang):

    • git clone https://github.com/llvm/llvm-project.git

    • Or, on windows, git clone --config core.autocrlf=false https://github.com/llvm/llvm-project.git

  2. Configure and build LLVM and Clang:

    • cd llvm-project

    • mkdir build

    • cd build

    • cmake -G <generator> [options] ../llvm

      Some common build system generators are:

      • Ninja --- for generating Ninja build files. Most llvm developers use Ninja.
      • Unix Makefiles --- for generating make-compatible parallel makefiles.
      • Visual Studio --- for generating Visual Studio projects and solutions.
      • Xcode --- for generating Xcode projects.

      Some Common options:

      • -DLLVM_ENABLE_PROJECTS='...' --- semicolon-separated list of the LLVM sub-projects you'd like to additionally build. Can include any of: clang, clang-tools-extra, libcxx, libcxxabi, libunwind, lldb, compiler-rt, lld, polly, or debuginfo-tests.

        For example, to build LLVM, Clang, libcxx, and libcxxabi, use -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi".

      • -DCMAKE_INSTALL_PREFIX=directory --- Specify for directory the full path name of where you want the LLVM tools and libraries to be installed (default /usr/local).

      • -DCMAKE_BUILD_TYPE=type --- Valid options for type are Debug, Release, RelWithDebInfo, and MinSizeRel. Default is Debug.

      • -DLLVM_ENABLE_ASSERTIONS=On --- Compile with assertion checks enabled (default is Yes for Debug builds, No for all other build types).

    • cmake --build . [-- [options] <target>] or your build system specified above directly.

      • The default target (i.e. ninja or make) will build all of LLVM.

      • The check-all target (i.e. ninja check-all) will run the regression tests to ensure everything is in working order.

      • CMake will generate targets for each tool and library, and most LLVM sub-projects generate their own check-<project> target.

      • Running a serial build will be slow. To improve speed, try running a parallel build. That's done by default in Ninja; for make, use the option -j NNN, where NNN is the number of parallel jobs, e.g. the number of CPUs you have.

    • For more information see CMake

Consult the Getting Started with LLVM page for detailed information on configuring and compiling LLVM. You can visit Directory Layout to learn about the layout of the source code tree.

patmos-llvm-project's People

Contributors

akyrtzi avatar arsenm avatar chandlerc avatar chapuni avatar d0k avatar ddunbar avatar douggregor avatar dwblaikie avatar echristo avatar eefriedman avatar ericwf avatar espindola avatar isanbard avatar kcc avatar labath avatar lattner avatar majnemer avatar maskray avatar nico avatar pcc avatar resistor avatar rksimon avatar rnk avatar rotateright avatar rui314 avatar stoklund avatar tkremenek avatar tobiasgrosser avatar topperc avatar zygoloid avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

patmos-llvm-project's Issues

Single-path: wrong compilation for nested loops breaking out of outer loop

Any code that has a nested loop where the inner loop breaks out of the outer loop, compiles wrong using single-path code.
The code could look something like this:

outer:
while(..) {
  while(..) {
    ..
    if(..) {
      break outer;
    }
  }
}

An example program that exhibits this problem is the Dijkstra program from the tacle benchmark.

The problem is caused by the way predicate register allocation is performed. In RAInfo, when a loop is encountered, all predicates are spilled such that the loop has all predicate register available for it single-path code. However, this doesn't account for cases as the above, since the inner loop would need to edit the outer loop's predicate to be able to disable it when the break happens. In the current implementation, the break assumes the outer loop's predicate is in a register, which it never is.

There are 2 possible solutions:

  1. Fix it in-place by taking this case into account. This would probably require significant reimplementation to remove the whole-sale spilling before each loop and edit the register allocation to no longer work on the FCFG only but also take inner loops into account (currently, register allocation ignores inner loops because the whole-sale spilling is assumed).
  2. We don't fix it in-place but instead defer a fix to when we move the single-path transformation to before register allocation. This would allow us to offload predicate register allocation to LLVM entirely, which would fix this issue as a by-product.

Unbounded modulo operand

Using the modulo operand is the likely reason for bugs with some programs as we do not have a customized version of it. It results in platin failures and single-path failures because it has an unbounded loop.

This issue tracks fixing this. The best solution is providing our own modulo function in Compiler-RT (umodXi3).

Single-path: Optimize block placement

In Single-Path/SPScope.cpp, the order of blocks is decided by getBlocksTopoOrd. While this is a valid order, it is not always optimial, since there is no guarantee that the produced topological order minimizes the highest number of live predicates.

We should therefore implement a better block order algorithm that tries to minimize the highest number of live predicates. This should produce faster code, since less instructions are then needed for loading/spilling from the stack.

Additionally, the current topological sort is not deterministic (given the same program, the sort might be different for different compilations) probably because std::maps are used, whose keys are block addresses that change with every compile.
The new algorithm should be deterministic to make debugging easier.

Compile for Patmos

The compiler in the current version does not compile the C code in the Patmos hardware. Example issues:

error: unknown argument: ‘-mpatmos-disable-vliw’

        : “$r1”, “$r2", “$r3”,          \
         ^
ethlib/tte.c:484:3: error: unknown register name ‘$r1’ in asm

Cannot divide 64-bit values in Platin

Trying to divide uint64_t will result in Platin complaining there is an unbounded loop.

Example program:

#include <stdio.h> 
#include <stdint.h>
#include <inttypes.h>

uint32_t test_fn (uint32_t x, uint32_t y)  __attribute__ ((noinline));

int main () {
	uint32_t x, y;
	scanf("%" SCNd32 "\n", &x);
	scanf("%" SCNd32 "\n", &y);
	printf("%d\n", (int) test_fn(x, y));
	return 0;
}

uint32_t test_fn (uint32_t x, uint32_t y) {
	return x / y;
}

Trying to analyze the resulting binary for WCET of test_fn will make Platin complain.

Looking into compiler-rt, I see that there is a dedicated function for 32-bit division in the Patmos builtins, but not for 64-bit.
This means the default one is used, which of-course doesn't include loop bounds.

Solution is to implement 64-bit division for Patmos in compile-rt such that it works out of the box.

Issue with the _start

I get following error:

/tmp/hello2-588b69.bc.o:/tmp/hello2-81e00f.opt.bc:function _start: error: undefined reference to '_loader_baseaddr'
/tmp/hello2-588b69.bc.o:/tmp/hello2-81e00f.opt.bc:function _start: error: undefined reference to '_loader_off'
patmos-clang-3.4: error: link  via llvm-link, opt and llc command failed with exit code 1 (use -v to see invocation)

I can provide a .zip file with the code that leads to this issue. But maybe someone has seen this before.

LLVM: make program tests return i8

All program tests under llvm/test/CodeGen/Patmos/programs currently return i32.
This is not optimal, since (on at least Linux) that returned values is truncated by the terminal into only 8 bits.
Because of this, all tests are designed to return values between 0 and 255 to ensure sensible return codes to be checked.

We should change the setup such that all tests return i8.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.