2009-04-01 21:53:23 +00:00
|
|
|
//===--- Triple.cpp - Target triple helper class --------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ADT/Triple.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2009-10-06 21:45:26 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-02-12 09:27:38 +00:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2012-01-20 21:51:11 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-04-02 01:11:37 +00:00
|
|
|
#include <cstring>
|
2009-04-01 21:53:23 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
const char *Triple::getArchTypeName(ArchType Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case UnknownArch: return "unknown";
|
2010-12-17 02:10:59 +00:00
|
|
|
|
2014-02-24 11:34:50 +00:00
|
|
|
case aarch64: return "aarch64";
|
|
|
|
case aarch64_be: return "aarch64_be";
|
|
|
|
case arm: return "arm";
|
2014-03-28 14:35:30 +00:00
|
|
|
case armeb: return "armeb";
|
BPF backend
Summary:
V8->V9:
- cleanup tests
V7->V8:
- addressed feedback from David:
- switched to range-based 'for' loops
- fixed formatting of tests
V6->V7:
- rebased and adjusted AsmPrinter args
- CamelCased .td, fixed formatting, cleaned up names, removed unused patterns
- diffstat: 3 files changed, 203 insertions(+), 227 deletions(-)
V5->V6:
- addressed feedback from Chandler:
- reinstated full verbose standard banner in all files
- fixed variables that were not in CamelCase
- fixed names of #ifdef in header files
- removed redundant braces in if/else chains with single statements
- fixed comments
- removed trailing empty line
- dropped debug annotations from tests
- diffstat of these changes:
46 files changed, 456 insertions(+), 469 deletions(-)
V4->V5:
- fix setLoadExtAction() interface
- clang-formated all where it made sense
V3->V4:
- added CODE_OWNERS entry for BPF backend
V2->V3:
- fix metadata in tests
V1->V2:
- addressed feedback from Tom and Matt
- removed top level change to configure (now everything via 'experimental-backend')
- reworked error reporting via DiagnosticInfo (similar to R600)
- added few more tests
- added cmake build
- added Triple::bpf
- tested on linux and darwin
V1 cover letter:
---------------------
recently linux gained "universal in-kernel virtual machine" which is called
eBPF or extended BPF. The name comes from "Berkeley Packet Filter", since
new instruction set is based on it.
This patch adds a new backend that emits extended BPF instruction set.
The concept and development are covered by the following articles:
http://lwn.net/Articles/599755/
http://lwn.net/Articles/575531/
http://lwn.net/Articles/603983/
http://lwn.net/Articles/606089/
http://lwn.net/Articles/612878/
One of use cases: dtrace/systemtap alternative.
bpf syscall manpage:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b4fc1a460f3017e958e6a8ea560ea0afd91bf6fe
instruction set description and differences vs classic BPF:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/filter.txt
Short summary of instruction set:
- 64-bit registers
R0 - return value from in-kernel function, and exit value for BPF program
R1 - R5 - arguments from BPF program to in-kernel function
R6 - R9 - callee saved registers that in-kernel function will preserve
R10 - read-only frame pointer to access stack
- two-operand instructions like +, -, *, mov, load/store
- implicit prologue/epilogue (invisible stack pointer)
- no floating point, no simd
Short history of extended BPF in kernel:
interpreter in 3.15, x64 JIT in 3.16, arm64 JIT, verifier, bpf syscall in 3.18, more to come in the future.
It's a very small and simple backend.
There is no support for global variables, arbitrary function calls, floating point, varargs,
exceptions, indirect jumps, arbitrary pointer arithmetic, alloca, etc.
From C front-end point of view it's very restricted. It's done on purpose, since kernel
rejects all programs that it cannot prove safe. It rejects programs with loops
and with memory accesses via arbitrary pointers. When kernel accepts the program it is
guaranteed that program will terminate and will not crash the kernel.
This patch implements all 'must have' bits. There are several things on TODO list,
so this is not the end of development.
Most of the code is a boiler plate code, copy-pasted from other backends.
Only odd things are lack or < and <= instructions, specialized load_byte intrinsics
and 'compare and goto' as single instruction.
Current instruction set is fixed, but more instructions can be added in the future.
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subscribers: majnemer, chandlerc, echristo, joerg, pete, rengolin, kristof.beyls, arsenm, t.p.northover, tstellarAMD, aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D6494
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 17:51:26 +00:00
|
|
|
case bpf: return "bpf";
|
2014-02-24 11:34:50 +00:00
|
|
|
case hexagon: return "hexagon";
|
|
|
|
case mips: return "mips";
|
|
|
|
case mipsel: return "mipsel";
|
|
|
|
case mips64: return "mips64";
|
|
|
|
case mips64el: return "mips64el";
|
|
|
|
case msp430: return "msp430";
|
|
|
|
case ppc64: return "powerpc64";
|
|
|
|
case ppc64le: return "powerpc64le";
|
|
|
|
case ppc: return "powerpc";
|
|
|
|
case r600: return "r600";
|
2015-01-06 18:00:00 +00:00
|
|
|
case amdgcn: return "amdgcn";
|
2014-02-24 11:34:50 +00:00
|
|
|
case sparc: return "sparc";
|
|
|
|
case sparcv9: return "sparcv9";
|
|
|
|
case systemz: return "s390x";
|
|
|
|
case tce: return "tce";
|
|
|
|
case thumb: return "thumb";
|
2014-03-28 14:35:30 +00:00
|
|
|
case thumbeb: return "thumbeb";
|
2014-02-24 11:34:50 +00:00
|
|
|
case x86: return "i386";
|
|
|
|
case x86_64: return "x86_64";
|
|
|
|
case xcore: return "xcore";
|
|
|
|
case nvptx: return "nvptx";
|
|
|
|
case nvptx64: return "nvptx64";
|
|
|
|
case le32: return "le32";
|
2014-09-12 17:54:17 +00:00
|
|
|
case le64: return "le64";
|
2014-02-24 11:34:50 +00:00
|
|
|
case amdil: return "amdil";
|
2014-09-19 19:52:11 +00:00
|
|
|
case amdil64: return "amdil64";
|
|
|
|
case hsail: return "hsail";
|
|
|
|
case hsail64: return "hsail64";
|
2014-02-24 11:34:50 +00:00
|
|
|
case spir: return "spir";
|
|
|
|
case spir64: return "spir64";
|
2014-07-10 17:26:54 +00:00
|
|
|
case kalimba: return "kalimba";
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 21:51:11 +00:00
|
|
|
llvm_unreachable("Invalid ArchType!");
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-24 09:53:06 +00:00
|
|
|
const char *Triple::getArchTypePrefix(ArchType Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
2014-04-07 04:17:22 +00:00
|
|
|
return nullptr;
|
2009-08-24 09:53:06 +00:00
|
|
|
|
2014-02-24 11:34:50 +00:00
|
|
|
case aarch64:
|
|
|
|
case aarch64_be: return "aarch64";
|
2013-01-31 12:12:40 +00:00
|
|
|
|
2009-08-24 09:53:06 +00:00
|
|
|
case arm:
|
2014-03-28 14:35:30 +00:00
|
|
|
case armeb:
|
|
|
|
case thumb:
|
|
|
|
case thumbeb: return "arm";
|
2009-08-24 09:53:06 +00:00
|
|
|
|
|
|
|
case ppc64:
|
2013-07-26 01:35:43 +00:00
|
|
|
case ppc64le:
|
2014-02-24 11:34:50 +00:00
|
|
|
case ppc: return "ppc";
|
2009-08-24 09:53:06 +00:00
|
|
|
|
2012-06-28 19:09:53 +00:00
|
|
|
case mips:
|
|
|
|
case mipsel:
|
|
|
|
case mips64:
|
2014-02-24 11:34:50 +00:00
|
|
|
case mips64el: return "mips";
|
2012-06-28 19:09:53 +00:00
|
|
|
|
2014-02-24 11:34:50 +00:00
|
|
|
case hexagon: return "hexagon";
|
2011-12-12 21:14:40 +00:00
|
|
|
|
2015-01-06 18:00:00 +00:00
|
|
|
case amdgcn:
|
|
|
|
case r600: return "amdgpu";
|
2012-03-09 10:09:36 +00:00
|
|
|
|
BPF backend
Summary:
V8->V9:
- cleanup tests
V7->V8:
- addressed feedback from David:
- switched to range-based 'for' loops
- fixed formatting of tests
V6->V7:
- rebased and adjusted AsmPrinter args
- CamelCased .td, fixed formatting, cleaned up names, removed unused patterns
- diffstat: 3 files changed, 203 insertions(+), 227 deletions(-)
V5->V6:
- addressed feedback from Chandler:
- reinstated full verbose standard banner in all files
- fixed variables that were not in CamelCase
- fixed names of #ifdef in header files
- removed redundant braces in if/else chains with single statements
- fixed comments
- removed trailing empty line
- dropped debug annotations from tests
- diffstat of these changes:
46 files changed, 456 insertions(+), 469 deletions(-)
V4->V5:
- fix setLoadExtAction() interface
- clang-formated all where it made sense
V3->V4:
- added CODE_OWNERS entry for BPF backend
V2->V3:
- fix metadata in tests
V1->V2:
- addressed feedback from Tom and Matt
- removed top level change to configure (now everything via 'experimental-backend')
- reworked error reporting via DiagnosticInfo (similar to R600)
- added few more tests
- added cmake build
- added Triple::bpf
- tested on linux and darwin
V1 cover letter:
---------------------
recently linux gained "universal in-kernel virtual machine" which is called
eBPF or extended BPF. The name comes from "Berkeley Packet Filter", since
new instruction set is based on it.
This patch adds a new backend that emits extended BPF instruction set.
The concept and development are covered by the following articles:
http://lwn.net/Articles/599755/
http://lwn.net/Articles/575531/
http://lwn.net/Articles/603983/
http://lwn.net/Articles/606089/
http://lwn.net/Articles/612878/
One of use cases: dtrace/systemtap alternative.
bpf syscall manpage:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b4fc1a460f3017e958e6a8ea560ea0afd91bf6fe
instruction set description and differences vs classic BPF:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/filter.txt
Short summary of instruction set:
- 64-bit registers
R0 - return value from in-kernel function, and exit value for BPF program
R1 - R5 - arguments from BPF program to in-kernel function
R6 - R9 - callee saved registers that in-kernel function will preserve
R10 - read-only frame pointer to access stack
- two-operand instructions like +, -, *, mov, load/store
- implicit prologue/epilogue (invisible stack pointer)
- no floating point, no simd
Short history of extended BPF in kernel:
interpreter in 3.15, x64 JIT in 3.16, arm64 JIT, verifier, bpf syscall in 3.18, more to come in the future.
It's a very small and simple backend.
There is no support for global variables, arbitrary function calls, floating point, varargs,
exceptions, indirect jumps, arbitrary pointer arithmetic, alloca, etc.
From C front-end point of view it's very restricted. It's done on purpose, since kernel
rejects all programs that it cannot prove safe. It rejects programs with loops
and with memory accesses via arbitrary pointers. When kernel accepts the program it is
guaranteed that program will terminate and will not crash the kernel.
This patch implements all 'must have' bits. There are several things on TODO list,
so this is not the end of development.
Most of the code is a boiler plate code, copy-pasted from other backends.
Only odd things are lack or < and <= instructions, specialized load_byte intrinsics
and 'compare and goto' as single instruction.
Current instruction set is fixed, but more instructions can be added in the future.
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subscribers: majnemer, chandlerc, echristo, joerg, pete, rengolin, kristof.beyls, arsenm, t.p.northover, tstellarAMD, aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D6494
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 17:51:26 +00:00
|
|
|
case bpf: return "bpf";
|
|
|
|
|
2010-02-04 06:34:01 +00:00
|
|
|
case sparcv9:
|
2014-02-24 11:34:50 +00:00
|
|
|
case sparc: return "sparc";
|
2009-08-24 09:53:06 +00:00
|
|
|
|
2014-02-24 11:34:50 +00:00
|
|
|
case systemz: return "systemz";
|
2013-05-03 11:05:17 +00:00
|
|
|
|
2009-08-24 09:53:06 +00:00
|
|
|
case x86:
|
2014-02-24 11:34:50 +00:00
|
|
|
case x86_64: return "x86";
|
2010-09-07 18:14:24 +00:00
|
|
|
|
2014-02-24 11:34:50 +00:00
|
|
|
case xcore: return "xcore";
|
2010-09-07 18:14:24 +00:00
|
|
|
|
2014-02-24 11:34:50 +00:00
|
|
|
case nvptx: return "nvptx";
|
|
|
|
case nvptx64: return "nvptx";
|
2014-03-29 10:18:08 +00:00
|
|
|
|
2014-02-24 11:34:50 +00:00
|
|
|
case le32: return "le32";
|
2014-09-12 17:54:17 +00:00
|
|
|
case le64: return "le64";
|
2014-09-19 19:52:11 +00:00
|
|
|
|
|
|
|
case amdil:
|
|
|
|
case amdil64: return "amdil";
|
|
|
|
|
|
|
|
case hsail:
|
|
|
|
case hsail64: return "hsail";
|
|
|
|
|
|
|
|
case spir:
|
2014-02-24 11:34:50 +00:00
|
|
|
case spir64: return "spir";
|
2014-07-10 17:26:54 +00:00
|
|
|
case kalimba: return "kalimba";
|
2009-08-24 09:53:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
const char *Triple::getVendorTypeName(VendorType Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case UnknownVendor: return "unknown";
|
|
|
|
|
|
|
|
case Apple: return "apple";
|
2009-08-14 18:48:13 +00:00
|
|
|
case PC: return "pc";
|
2011-03-15 21:51:56 +00:00
|
|
|
case SCEI: return "scei";
|
2012-04-02 18:31:33 +00:00
|
|
|
case BGP: return "bgp";
|
|
|
|
case BGQ: return "bgq";
|
2012-08-28 02:10:30 +00:00
|
|
|
case Freescale: return "fsl";
|
2012-10-12 11:08:57 +00:00
|
|
|
case IBM: return "ibm";
|
2014-07-09 16:03:10 +00:00
|
|
|
case ImaginationTechnologies: return "img";
|
2014-07-18 14:28:19 +00:00
|
|
|
case MipsTechnologies: return "mti";
|
2013-06-21 18:51:49 +00:00
|
|
|
case NVIDIA: return "nvidia";
|
2014-07-10 17:26:54 +00:00
|
|
|
case CSR: return "csr";
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 21:51:11 +00:00
|
|
|
llvm_unreachable("Invalid VendorType!");
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Triple::getOSTypeName(OSType Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case UnknownOS: return "unknown";
|
|
|
|
|
2015-03-09 18:40:45 +00:00
|
|
|
case CloudABI: return "cloudabi";
|
2009-04-01 21:53:23 +00:00
|
|
|
case Darwin: return "darwin";
|
2009-05-22 02:24:11 +00:00
|
|
|
case DragonFly: return "dragonfly";
|
2009-04-01 21:53:23 +00:00
|
|
|
case FreeBSD: return "freebsd";
|
2011-04-19 20:19:27 +00:00
|
|
|
case IOS: return "ios";
|
2011-07-26 15:30:04 +00:00
|
|
|
case KFreeBSD: return "kfreebsd";
|
2009-04-01 21:53:23 +00:00
|
|
|
case Linux: return "linux";
|
2009-11-19 11:59:00 +00:00
|
|
|
case Lv2: return "lv2";
|
2011-04-19 23:34:12 +00:00
|
|
|
case MacOSX: return "macosx";
|
2009-07-13 20:22:23 +00:00
|
|
|
case NetBSD: return "netbsd";
|
2009-06-29 13:36:13 +00:00
|
|
|
case OpenBSD: return "openbsd";
|
2009-08-18 04:43:27 +00:00
|
|
|
case Solaris: return "solaris";
|
2014-03-27 22:50:05 +00:00
|
|
|
case Win32: return "windows";
|
2009-10-16 02:06:30 +00:00
|
|
|
case Haiku: return "haiku";
|
2010-07-07 15:52:27 +00:00
|
|
|
case Minix: return "minix";
|
2011-07-01 22:41:06 +00:00
|
|
|
case RTEMS: return "rtems";
|
2012-12-04 18:37:26 +00:00
|
|
|
case NaCl: return "nacl";
|
2012-04-02 18:31:33 +00:00
|
|
|
case CNK: return "cnk";
|
2012-08-06 20:52:18 +00:00
|
|
|
case Bitrig: return "bitrig";
|
2012-10-12 11:08:57 +00:00
|
|
|
case AIX: return "aix";
|
2013-06-21 18:51:49 +00:00
|
|
|
case CUDA: return "cuda";
|
|
|
|
case NVCL: return "nvcl";
|
2014-12-02 16:45:47 +00:00
|
|
|
case AMDHSA: return "amdhsa";
|
2015-01-25 22:46:59 +00:00
|
|
|
case PS4: return "ps4";
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 21:51:11 +00:00
|
|
|
llvm_unreachable("Invalid OSType");
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 08:25:48 +00:00
|
|
|
const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case UnknownEnvironment: return "unknown";
|
2011-01-21 18:25:47 +00:00
|
|
|
case GNU: return "gnu";
|
2012-01-18 23:35:29 +00:00
|
|
|
case GNUEABIHF: return "gnueabihf";
|
2011-01-21 18:25:47 +00:00
|
|
|
case GNUEABI: return "gnueabi";
|
2013-01-22 18:02:49 +00:00
|
|
|
case GNUX32: return "gnux32";
|
2014-01-20 12:02:25 +00:00
|
|
|
case CODE16: return "code16";
|
2011-01-21 18:25:47 +00:00
|
|
|
case EABI: return "eabi";
|
2013-12-16 18:51:28 +00:00
|
|
|
case EABIHF: return "eabihf";
|
2012-09-02 09:29:46 +00:00
|
|
|
case Android: return "android";
|
2014-03-27 22:50:05 +00:00
|
|
|
case MSVC: return "msvc";
|
|
|
|
case Itanium: return "itanium";
|
|
|
|
case Cygnus: return "cygnus";
|
2010-09-16 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-20 21:51:11 +00:00
|
|
|
llvm_unreachable("Invalid EnvironmentType!");
|
2010-09-16 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
|
2012-02-12 09:27:38 +00:00
|
|
|
return StringSwitch<Triple::ArchType>(Name)
|
2013-01-31 12:12:40 +00:00
|
|
|
.Case("aarch64", aarch64)
|
2014-02-24 11:34:50 +00:00
|
|
|
.Case("aarch64_be", aarch64_be)
|
2014-07-23 12:32:47 +00:00
|
|
|
.Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
|
2012-02-12 09:27:38 +00:00
|
|
|
.Case("arm", arm)
|
2014-03-28 14:35:30 +00:00
|
|
|
.Case("armeb", armeb)
|
BPF backend
Summary:
V8->V9:
- cleanup tests
V7->V8:
- addressed feedback from David:
- switched to range-based 'for' loops
- fixed formatting of tests
V6->V7:
- rebased and adjusted AsmPrinter args
- CamelCased .td, fixed formatting, cleaned up names, removed unused patterns
- diffstat: 3 files changed, 203 insertions(+), 227 deletions(-)
V5->V6:
- addressed feedback from Chandler:
- reinstated full verbose standard banner in all files
- fixed variables that were not in CamelCase
- fixed names of #ifdef in header files
- removed redundant braces in if/else chains with single statements
- fixed comments
- removed trailing empty line
- dropped debug annotations from tests
- diffstat of these changes:
46 files changed, 456 insertions(+), 469 deletions(-)
V4->V5:
- fix setLoadExtAction() interface
- clang-formated all where it made sense
V3->V4:
- added CODE_OWNERS entry for BPF backend
V2->V3:
- fix metadata in tests
V1->V2:
- addressed feedback from Tom and Matt
- removed top level change to configure (now everything via 'experimental-backend')
- reworked error reporting via DiagnosticInfo (similar to R600)
- added few more tests
- added cmake build
- added Triple::bpf
- tested on linux and darwin
V1 cover letter:
---------------------
recently linux gained "universal in-kernel virtual machine" which is called
eBPF or extended BPF. The name comes from "Berkeley Packet Filter", since
new instruction set is based on it.
This patch adds a new backend that emits extended BPF instruction set.
The concept and development are covered by the following articles:
http://lwn.net/Articles/599755/
http://lwn.net/Articles/575531/
http://lwn.net/Articles/603983/
http://lwn.net/Articles/606089/
http://lwn.net/Articles/612878/
One of use cases: dtrace/systemtap alternative.
bpf syscall manpage:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b4fc1a460f3017e958e6a8ea560ea0afd91bf6fe
instruction set description and differences vs classic BPF:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/filter.txt
Short summary of instruction set:
- 64-bit registers
R0 - return value from in-kernel function, and exit value for BPF program
R1 - R5 - arguments from BPF program to in-kernel function
R6 - R9 - callee saved registers that in-kernel function will preserve
R10 - read-only frame pointer to access stack
- two-operand instructions like +, -, *, mov, load/store
- implicit prologue/epilogue (invisible stack pointer)
- no floating point, no simd
Short history of extended BPF in kernel:
interpreter in 3.15, x64 JIT in 3.16, arm64 JIT, verifier, bpf syscall in 3.18, more to come in the future.
It's a very small and simple backend.
There is no support for global variables, arbitrary function calls, floating point, varargs,
exceptions, indirect jumps, arbitrary pointer arithmetic, alloca, etc.
From C front-end point of view it's very restricted. It's done on purpose, since kernel
rejects all programs that it cannot prove safe. It rejects programs with loops
and with memory accesses via arbitrary pointers. When kernel accepts the program it is
guaranteed that program will terminate and will not crash the kernel.
This patch implements all 'must have' bits. There are several things on TODO list,
so this is not the end of development.
Most of the code is a boiler plate code, copy-pasted from other backends.
Only odd things are lack or < and <= instructions, specialized load_byte intrinsics
and 'compare and goto' as single instruction.
Current instruction set is fixed, but more instructions can be added in the future.
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subscribers: majnemer, chandlerc, echristo, joerg, pete, rengolin, kristof.beyls, arsenm, t.p.northover, tstellarAMD, aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D6494
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 17:51:26 +00:00
|
|
|
.Case("bpf", bpf)
|
2012-02-12 09:27:38 +00:00
|
|
|
.Case("mips", mips)
|
|
|
|
.Case("mipsel", mipsel)
|
|
|
|
.Case("mips64", mips64)
|
|
|
|
.Case("mips64el", mips64el)
|
|
|
|
.Case("msp430", msp430)
|
|
|
|
.Case("ppc64", ppc64)
|
|
|
|
.Case("ppc32", ppc)
|
|
|
|
.Case("ppc", ppc)
|
2013-07-26 01:35:43 +00:00
|
|
|
.Case("ppc64le", ppc64le)
|
2012-03-09 10:09:36 +00:00
|
|
|
.Case("r600", r600)
|
2015-01-06 18:00:00 +00:00
|
|
|
.Case("amdgcn", amdgcn)
|
2012-02-12 09:27:38 +00:00
|
|
|
.Case("hexagon", hexagon)
|
|
|
|
.Case("sparc", sparc)
|
|
|
|
.Case("sparcv9", sparcv9)
|
2013-05-03 11:05:17 +00:00
|
|
|
.Case("systemz", systemz)
|
2012-02-12 09:27:38 +00:00
|
|
|
.Case("tce", tce)
|
|
|
|
.Case("thumb", thumb)
|
2014-03-28 14:35:30 +00:00
|
|
|
.Case("thumbeb", thumbeb)
|
2012-02-12 09:27:38 +00:00
|
|
|
.Case("x86", x86)
|
|
|
|
.Case("x86-64", x86_64)
|
|
|
|
.Case("xcore", xcore)
|
2012-05-04 20:18:50 +00:00
|
|
|
.Case("nvptx", nvptx)
|
|
|
|
.Case("nvptx64", nvptx64)
|
2012-02-12 09:27:38 +00:00
|
|
|
.Case("le32", le32)
|
2014-09-12 17:54:17 +00:00
|
|
|
.Case("le64", le64)
|
2012-02-12 09:27:38 +00:00
|
|
|
.Case("amdil", amdil)
|
2014-09-19 19:52:11 +00:00
|
|
|
.Case("amdil64", amdil64)
|
|
|
|
.Case("hsail", hsail)
|
|
|
|
.Case("hsail64", hsail64)
|
2012-10-01 17:01:31 +00:00
|
|
|
.Case("spir", spir)
|
2012-11-15 10:35:47 +00:00
|
|
|
.Case("spir64", spir64)
|
2014-07-10 17:26:54 +00:00
|
|
|
.Case("kalimba", kalimba)
|
2012-02-12 09:27:38 +00:00
|
|
|
.Default(UnknownArch);
|
2009-08-03 04:03:51 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 14:08:57 +00:00
|
|
|
static Triple::ArchType parseARMArch(StringRef ArchName) {
|
|
|
|
size_t offset = StringRef::npos;
|
|
|
|
Triple::ArchType arch = Triple::UnknownArch;
|
|
|
|
bool isThumb = ArchName.startswith("thumb");
|
|
|
|
|
|
|
|
if (ArchName.equals("arm"))
|
|
|
|
return Triple::arm;
|
|
|
|
if (ArchName.equals("armeb"))
|
|
|
|
return Triple::armeb;
|
|
|
|
if (ArchName.equals("thumb"))
|
|
|
|
return Triple::thumb;
|
|
|
|
if (ArchName.equals("thumbeb"))
|
|
|
|
return Triple::thumbeb;
|
|
|
|
if (ArchName.equals("arm64") || ArchName.equals("aarch64"))
|
|
|
|
return Triple::aarch64;
|
|
|
|
if (ArchName.equals("aarch64_be"))
|
|
|
|
return Triple::aarch64_be;
|
|
|
|
|
|
|
|
if (ArchName.startswith("armv")) {
|
|
|
|
offset = 3;
|
2015-01-26 11:41:48 +00:00
|
|
|
if (ArchName.endswith("eb")) {
|
|
|
|
arch = Triple::armeb;
|
|
|
|
ArchName = ArchName.substr(0, ArchName.size() - 2);
|
|
|
|
} else
|
|
|
|
arch = Triple::arm;
|
2014-11-17 14:08:57 +00:00
|
|
|
} else if (ArchName.startswith("armebv")) {
|
|
|
|
offset = 5;
|
|
|
|
arch = Triple::armeb;
|
|
|
|
} else if (ArchName.startswith("thumbv")) {
|
|
|
|
offset = 5;
|
2015-01-26 11:41:48 +00:00
|
|
|
if (ArchName.endswith("eb")) {
|
|
|
|
arch = Triple::thumbeb;
|
|
|
|
ArchName = ArchName.substr(0, ArchName.size() - 2);
|
|
|
|
} else
|
|
|
|
arch = Triple::thumb;
|
2014-11-17 14:08:57 +00:00
|
|
|
} else if (ArchName.startswith("thumbebv")) {
|
|
|
|
offset = 7;
|
|
|
|
arch = Triple::thumbeb;
|
|
|
|
}
|
|
|
|
return StringSwitch<Triple::ArchType>(ArchName.substr(offset))
|
|
|
|
.Cases("v2", "v2a", isThumb ? Triple::UnknownArch : arch)
|
|
|
|
.Cases("v3", "v3m", isThumb ? Triple::UnknownArch : arch)
|
|
|
|
.Cases("v4", "v4t", arch)
|
|
|
|
.Cases("v5", "v5e", "v5t", "v5te", "v5tej", arch)
|
2015-02-10 15:15:08 +00:00
|
|
|
.Cases("v6", "v6j", "v6k", "v6m", "v6sm", arch)
|
2014-11-17 14:08:57 +00:00
|
|
|
.Cases("v6t2", "v6z", "v6zk", arch)
|
|
|
|
.Cases("v7", "v7a", "v7em", "v7l", arch)
|
|
|
|
.Cases("v7m", "v7r", "v7s", arch)
|
|
|
|
.Cases("v8", "v8a", arch)
|
2015-03-26 17:05:54 +00:00
|
|
|
.Cases("v8.1", "v8.1a", arch)
|
2014-11-17 14:08:57 +00:00
|
|
|
.Default(Triple::UnknownArch);
|
|
|
|
}
|
|
|
|
|
2012-02-21 08:53:32 +00:00
|
|
|
static Triple::ArchType parseArch(StringRef ArchName) {
|
2015-01-26 11:41:48 +00:00
|
|
|
Triple::ArchType ARMArch(parseARMArch(ArchName));
|
|
|
|
|
2012-02-21 08:53:32 +00:00
|
|
|
return StringSwitch<Triple::ArchType>(ArchName)
|
|
|
|
.Cases("i386", "i486", "i586", "i686", Triple::x86)
|
|
|
|
// FIXME: Do we need to support these?
|
|
|
|
.Cases("i786", "i886", "i986", Triple::x86)
|
2013-11-16 00:52:57 +00:00
|
|
|
.Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Case("powerpc", Triple::ppc)
|
|
|
|
.Cases("powerpc64", "ppu", Triple::ppc64)
|
2013-07-26 01:35:43 +00:00
|
|
|
.Case("powerpc64le", Triple::ppc64le)
|
2014-11-17 14:08:57 +00:00
|
|
|
.Case("xscale", Triple::arm)
|
2015-01-26 11:41:48 +00:00
|
|
|
.Case("xscaleeb", Triple::armeb)
|
|
|
|
.StartsWith("arm", ARMArch)
|
|
|
|
.StartsWith("thumb", ARMArch)
|
|
|
|
.StartsWith("aarch64", ARMArch)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Case("msp430", Triple::msp430)
|
|
|
|
.Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
|
2012-02-22 11:32:54 +00:00
|
|
|
.Cases("mipsel", "mipsallegrexel", Triple::mipsel)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Cases("mips64", "mips64eb", Triple::mips64)
|
|
|
|
.Case("mips64el", Triple::mips64el)
|
2012-03-09 10:09:36 +00:00
|
|
|
.Case("r600", Triple::r600)
|
2015-01-06 18:00:00 +00:00
|
|
|
.Case("amdgcn", Triple::amdgcn)
|
BPF backend
Summary:
V8->V9:
- cleanup tests
V7->V8:
- addressed feedback from David:
- switched to range-based 'for' loops
- fixed formatting of tests
V6->V7:
- rebased and adjusted AsmPrinter args
- CamelCased .td, fixed formatting, cleaned up names, removed unused patterns
- diffstat: 3 files changed, 203 insertions(+), 227 deletions(-)
V5->V6:
- addressed feedback from Chandler:
- reinstated full verbose standard banner in all files
- fixed variables that were not in CamelCase
- fixed names of #ifdef in header files
- removed redundant braces in if/else chains with single statements
- fixed comments
- removed trailing empty line
- dropped debug annotations from tests
- diffstat of these changes:
46 files changed, 456 insertions(+), 469 deletions(-)
V4->V5:
- fix setLoadExtAction() interface
- clang-formated all where it made sense
V3->V4:
- added CODE_OWNERS entry for BPF backend
V2->V3:
- fix metadata in tests
V1->V2:
- addressed feedback from Tom and Matt
- removed top level change to configure (now everything via 'experimental-backend')
- reworked error reporting via DiagnosticInfo (similar to R600)
- added few more tests
- added cmake build
- added Triple::bpf
- tested on linux and darwin
V1 cover letter:
---------------------
recently linux gained "universal in-kernel virtual machine" which is called
eBPF or extended BPF. The name comes from "Berkeley Packet Filter", since
new instruction set is based on it.
This patch adds a new backend that emits extended BPF instruction set.
The concept and development are covered by the following articles:
http://lwn.net/Articles/599755/
http://lwn.net/Articles/575531/
http://lwn.net/Articles/603983/
http://lwn.net/Articles/606089/
http://lwn.net/Articles/612878/
One of use cases: dtrace/systemtap alternative.
bpf syscall manpage:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b4fc1a460f3017e958e6a8ea560ea0afd91bf6fe
instruction set description and differences vs classic BPF:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/filter.txt
Short summary of instruction set:
- 64-bit registers
R0 - return value from in-kernel function, and exit value for BPF program
R1 - R5 - arguments from BPF program to in-kernel function
R6 - R9 - callee saved registers that in-kernel function will preserve
R10 - read-only frame pointer to access stack
- two-operand instructions like +, -, *, mov, load/store
- implicit prologue/epilogue (invisible stack pointer)
- no floating point, no simd
Short history of extended BPF in kernel:
interpreter in 3.15, x64 JIT in 3.16, arm64 JIT, verifier, bpf syscall in 3.18, more to come in the future.
It's a very small and simple backend.
There is no support for global variables, arbitrary function calls, floating point, varargs,
exceptions, indirect jumps, arbitrary pointer arithmetic, alloca, etc.
From C front-end point of view it's very restricted. It's done on purpose, since kernel
rejects all programs that it cannot prove safe. It rejects programs with loops
and with memory accesses via arbitrary pointers. When kernel accepts the program it is
guaranteed that program will terminate and will not crash the kernel.
This patch implements all 'must have' bits. There are several things on TODO list,
so this is not the end of development.
Most of the code is a boiler plate code, copy-pasted from other backends.
Only odd things are lack or < and <= instructions, specialized load_byte intrinsics
and 'compare and goto' as single instruction.
Current instruction set is fixed, but more instructions can be added in the future.
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subscribers: majnemer, chandlerc, echristo, joerg, pete, rengolin, kristof.beyls, arsenm, t.p.northover, tstellarAMD, aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D6494
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 17:51:26 +00:00
|
|
|
.Case("bpf", Triple::bpf)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Case("hexagon", Triple::hexagon)
|
2013-05-03 11:05:17 +00:00
|
|
|
.Case("s390x", Triple::systemz)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Case("sparc", Triple::sparc)
|
2013-05-14 17:47:27 +00:00
|
|
|
.Cases("sparcv9", "sparc64", Triple::sparcv9)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Case("tce", Triple::tce)
|
|
|
|
.Case("xcore", Triple::xcore)
|
2012-05-04 20:18:50 +00:00
|
|
|
.Case("nvptx", Triple::nvptx)
|
|
|
|
.Case("nvptx64", Triple::nvptx64)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Case("le32", Triple::le32)
|
2014-09-12 17:54:17 +00:00
|
|
|
.Case("le64", Triple::le64)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Case("amdil", Triple::amdil)
|
2014-09-19 19:52:11 +00:00
|
|
|
.Case("amdil64", Triple::amdil64)
|
|
|
|
.Case("hsail", Triple::hsail)
|
|
|
|
.Case("hsail64", Triple::hsail64)
|
2012-10-01 17:01:31 +00:00
|
|
|
.Case("spir", Triple::spir)
|
2012-11-15 10:35:47 +00:00
|
|
|
.Case("spir64", Triple::spir64)
|
2014-09-05 06:46:43 +00:00
|
|
|
.StartsWith("kalimba", Triple::kalimba)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Default(Triple::UnknownArch);
|
2010-08-12 11:31:39 +00:00
|
|
|
}
|
2009-08-18 19:26:55 +00:00
|
|
|
|
2012-02-21 08:53:32 +00:00
|
|
|
static Triple::VendorType parseVendor(StringRef VendorName) {
|
|
|
|
return StringSwitch<Triple::VendorType>(VendorName)
|
|
|
|
.Case("apple", Triple::Apple)
|
|
|
|
.Case("pc", Triple::PC)
|
|
|
|
.Case("scei", Triple::SCEI)
|
2012-04-02 18:31:33 +00:00
|
|
|
.Case("bgp", Triple::BGP)
|
|
|
|
.Case("bgq", Triple::BGQ)
|
2012-08-28 02:10:30 +00:00
|
|
|
.Case("fsl", Triple::Freescale)
|
2012-10-12 11:08:57 +00:00
|
|
|
.Case("ibm", Triple::IBM)
|
2014-07-09 16:03:10 +00:00
|
|
|
.Case("img", Triple::ImaginationTechnologies)
|
2014-07-18 14:28:19 +00:00
|
|
|
.Case("mti", Triple::MipsTechnologies)
|
2013-06-21 18:51:49 +00:00
|
|
|
.Case("nvidia", Triple::NVIDIA)
|
2014-07-10 17:26:54 +00:00
|
|
|
.Case("csr", Triple::CSR)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Default(Triple::UnknownVendor);
|
2010-08-12 11:31:39 +00:00
|
|
|
}
|
2009-04-01 21:53:23 +00:00
|
|
|
|
2012-02-21 08:53:32 +00:00
|
|
|
static Triple::OSType parseOS(StringRef OSName) {
|
|
|
|
return StringSwitch<Triple::OSType>(OSName)
|
2015-03-09 18:40:45 +00:00
|
|
|
.StartsWith("cloudabi", Triple::CloudABI)
|
2012-02-21 08:53:32 +00:00
|
|
|
.StartsWith("darwin", Triple::Darwin)
|
|
|
|
.StartsWith("dragonfly", Triple::DragonFly)
|
|
|
|
.StartsWith("freebsd", Triple::FreeBSD)
|
|
|
|
.StartsWith("ios", Triple::IOS)
|
|
|
|
.StartsWith("kfreebsd", Triple::KFreeBSD)
|
|
|
|
.StartsWith("linux", Triple::Linux)
|
|
|
|
.StartsWith("lv2", Triple::Lv2)
|
|
|
|
.StartsWith("macosx", Triple::MacOSX)
|
|
|
|
.StartsWith("netbsd", Triple::NetBSD)
|
|
|
|
.StartsWith("openbsd", Triple::OpenBSD)
|
|
|
|
.StartsWith("solaris", Triple::Solaris)
|
|
|
|
.StartsWith("win32", Triple::Win32)
|
2014-03-27 22:50:05 +00:00
|
|
|
.StartsWith("windows", Triple::Win32)
|
2012-02-21 08:53:32 +00:00
|
|
|
.StartsWith("haiku", Triple::Haiku)
|
|
|
|
.StartsWith("minix", Triple::Minix)
|
|
|
|
.StartsWith("rtems", Triple::RTEMS)
|
2012-12-04 18:37:26 +00:00
|
|
|
.StartsWith("nacl", Triple::NaCl)
|
2012-04-02 18:31:33 +00:00
|
|
|
.StartsWith("cnk", Triple::CNK)
|
2012-08-06 20:52:18 +00:00
|
|
|
.StartsWith("bitrig", Triple::Bitrig)
|
2012-10-12 11:08:57 +00:00
|
|
|
.StartsWith("aix", Triple::AIX)
|
2013-06-21 18:51:49 +00:00
|
|
|
.StartsWith("cuda", Triple::CUDA)
|
|
|
|
.StartsWith("nvcl", Triple::NVCL)
|
2014-12-02 16:45:47 +00:00
|
|
|
.StartsWith("amdhsa", Triple::AMDHSA)
|
2015-01-25 22:46:59 +00:00
|
|
|
.StartsWith("ps4", Triple::PS4)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Default(Triple::UnknownOS);
|
2010-08-12 11:31:39 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 08:53:32 +00:00
|
|
|
static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
|
|
|
|
return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
|
2013-12-16 18:51:28 +00:00
|
|
|
.StartsWith("eabihf", Triple::EABIHF)
|
2012-02-21 08:53:32 +00:00
|
|
|
.StartsWith("eabi", Triple::EABI)
|
|
|
|
.StartsWith("gnueabihf", Triple::GNUEABIHF)
|
|
|
|
.StartsWith("gnueabi", Triple::GNUEABI)
|
2013-01-22 18:02:49 +00:00
|
|
|
.StartsWith("gnux32", Triple::GNUX32)
|
2014-01-20 12:02:25 +00:00
|
|
|
.StartsWith("code16", Triple::CODE16)
|
2012-02-21 08:53:32 +00:00
|
|
|
.StartsWith("gnu", Triple::GNU)
|
2012-09-02 09:29:46 +00:00
|
|
|
.StartsWith("android", Triple::Android)
|
2014-03-27 22:50:05 +00:00
|
|
|
.StartsWith("msvc", Triple::MSVC)
|
|
|
|
.StartsWith("itanium", Triple::Itanium)
|
|
|
|
.StartsWith("cygnus", Triple::Cygnus)
|
2012-02-21 08:53:32 +00:00
|
|
|
.Default(Triple::UnknownEnvironment);
|
2010-09-16 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 20:47:11 +00:00
|
|
|
static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
|
|
|
|
return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
|
|
|
|
.EndsWith("coff", Triple::COFF)
|
|
|
|
.EndsWith("elf", Triple::ELF)
|
|
|
|
.EndsWith("macho", Triple::MachO)
|
|
|
|
.Default(Triple::UnknownObjectFormat);
|
|
|
|
}
|
|
|
|
|
2014-07-18 12:00:48 +00:00
|
|
|
static Triple::SubArchType parseSubArch(StringRef SubArchName) {
|
2015-01-26 11:41:48 +00:00
|
|
|
if (SubArchName.endswith("eb"))
|
|
|
|
SubArchName = SubArchName.substr(0, SubArchName.size() - 2);
|
|
|
|
|
2014-07-18 12:00:48 +00:00
|
|
|
return StringSwitch<Triple::SubArchType>(SubArchName)
|
2015-03-26 17:05:54 +00:00
|
|
|
.EndsWith("v8.1a", Triple::ARMSubArch_v8_1a)
|
2014-07-18 12:00:48 +00:00
|
|
|
.EndsWith("v8", Triple::ARMSubArch_v8)
|
|
|
|
.EndsWith("v8a", Triple::ARMSubArch_v8)
|
|
|
|
.EndsWith("v7", Triple::ARMSubArch_v7)
|
|
|
|
.EndsWith("v7a", Triple::ARMSubArch_v7)
|
|
|
|
.EndsWith("v7em", Triple::ARMSubArch_v7em)
|
|
|
|
.EndsWith("v7l", Triple::ARMSubArch_v7)
|
|
|
|
.EndsWith("v7m", Triple::ARMSubArch_v7m)
|
|
|
|
.EndsWith("v7r", Triple::ARMSubArch_v7)
|
|
|
|
.EndsWith("v7s", Triple::ARMSubArch_v7s)
|
|
|
|
.EndsWith("v6", Triple::ARMSubArch_v6)
|
|
|
|
.EndsWith("v6m", Triple::ARMSubArch_v6m)
|
2015-02-10 15:15:08 +00:00
|
|
|
.EndsWith("v6sm", Triple::ARMSubArch_v6m)
|
2015-03-17 11:55:28 +00:00
|
|
|
.EndsWith("v6k", Triple::ARMSubArch_v6k)
|
2014-07-18 12:00:48 +00:00
|
|
|
.EndsWith("v6t2", Triple::ARMSubArch_v6t2)
|
|
|
|
.EndsWith("v5", Triple::ARMSubArch_v5)
|
|
|
|
.EndsWith("v5e", Triple::ARMSubArch_v5)
|
|
|
|
.EndsWith("v5t", Triple::ARMSubArch_v5)
|
|
|
|
.EndsWith("v5te", Triple::ARMSubArch_v5te)
|
|
|
|
.EndsWith("v4t", Triple::ARMSubArch_v4t)
|
2014-09-05 06:46:43 +00:00
|
|
|
.EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
|
|
|
|
.EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
|
|
|
|
.EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
|
2014-07-18 12:00:48 +00:00
|
|
|
.Default(Triple::NoSubArch);
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:47:11 +00:00
|
|
|
static const char *getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case Triple::UnknownObjectFormat: return "";
|
|
|
|
case Triple::COFF: return "coff";
|
|
|
|
case Triple::ELF: return "elf";
|
|
|
|
case Triple::MachO: return "macho";
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown object format type");
|
|
|
|
}
|
|
|
|
|
|
|
|
static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
|
2015-03-18 22:19:16 +00:00
|
|
|
switch (T.getArch()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case Triple::hexagon:
|
|
|
|
case Triple::mips:
|
|
|
|
case Triple::mipsel:
|
|
|
|
case Triple::mips64:
|
|
|
|
case Triple::mips64el:
|
|
|
|
case Triple::r600:
|
|
|
|
case Triple::amdgcn:
|
|
|
|
case Triple::sparc:
|
|
|
|
case Triple::sparcv9:
|
|
|
|
case Triple::systemz:
|
|
|
|
case Triple::xcore:
|
2015-03-19 02:40:56 +00:00
|
|
|
case Triple::ppc64le:
|
|
|
|
return Triple::ELF;
|
|
|
|
|
|
|
|
case Triple::ppc:
|
|
|
|
case Triple::ppc64:
|
|
|
|
if (T.isOSDarwin())
|
|
|
|
return Triple::MachO;
|
2015-03-18 22:19:16 +00:00
|
|
|
return Triple::ELF;
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:47:11 +00:00
|
|
|
if (T.isOSDarwin())
|
|
|
|
return Triple::MachO;
|
|
|
|
else if (T.isOSWindows())
|
|
|
|
return Triple::COFF;
|
|
|
|
return Triple::ELF;
|
|
|
|
}
|
|
|
|
|
2012-02-20 00:02:47 +00:00
|
|
|
/// \brief Construct a triple from the string representation provided.
|
|
|
|
///
|
2012-02-21 08:31:18 +00:00
|
|
|
/// This stores the string representation and parses the various pieces into
|
|
|
|
/// enum members.
|
2012-02-21 03:39:36 +00:00
|
|
|
Triple::Triple(const Twine &Str)
|
|
|
|
: Data(Str.str()),
|
2012-02-21 08:53:32 +00:00
|
|
|
Arch(parseArch(getArchName())),
|
2014-07-18 12:00:48 +00:00
|
|
|
SubArch(parseSubArch(getArchName())),
|
2012-02-21 08:53:32 +00:00
|
|
|
Vendor(parseVendor(getVendorName())),
|
|
|
|
OS(parseOS(getOSName())),
|
2014-03-06 20:47:11 +00:00
|
|
|
Environment(parseEnvironment(getEnvironmentName())),
|
|
|
|
ObjectFormat(parseFormat(getEnvironmentName())) {
|
|
|
|
if (ObjectFormat == Triple::UnknownObjectFormat)
|
|
|
|
ObjectFormat = getDefaultFormat(*this);
|
2012-02-21 03:39:36 +00:00
|
|
|
}
|
2012-02-20 00:02:47 +00:00
|
|
|
|
|
|
|
/// \brief Construct a triple from string representations of the architecture,
|
|
|
|
/// vendor, and OS.
|
|
|
|
///
|
2012-02-21 08:31:18 +00:00
|
|
|
/// This joins each argument into a canonical string representation and parses
|
|
|
|
/// them into enum members. It leaves the environment unknown and omits it from
|
|
|
|
/// the string representation.
|
2012-02-20 00:02:47 +00:00
|
|
|
Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
|
|
|
|
: Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
|
2012-02-21 08:53:32 +00:00
|
|
|
Arch(parseArch(ArchStr.str())),
|
2014-07-18 12:00:48 +00:00
|
|
|
SubArch(parseSubArch(ArchStr.str())),
|
2012-02-21 08:53:32 +00:00
|
|
|
Vendor(parseVendor(VendorStr.str())),
|
|
|
|
OS(parseOS(OSStr.str())),
|
2014-03-06 20:47:11 +00:00
|
|
|
Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
|
|
|
|
ObjectFormat = getDefaultFormat(*this);
|
2012-02-20 00:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Construct a triple from string representations of the architecture,
|
|
|
|
/// vendor, OS, and environment.
|
|
|
|
///
|
2012-02-21 08:31:18 +00:00
|
|
|
/// This joins each argument into a canonical string representation and parses
|
|
|
|
/// them into enum members.
|
2012-02-20 00:02:47 +00:00
|
|
|
Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
|
|
|
|
const Twine &EnvironmentStr)
|
|
|
|
: Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
|
|
|
|
EnvironmentStr).str()),
|
2012-02-21 08:53:32 +00:00
|
|
|
Arch(parseArch(ArchStr.str())),
|
2014-07-18 12:00:48 +00:00
|
|
|
SubArch(parseSubArch(ArchStr.str())),
|
2012-02-21 08:53:32 +00:00
|
|
|
Vendor(parseVendor(VendorStr.str())),
|
|
|
|
OS(parseOS(OSStr.str())),
|
2014-03-06 20:47:11 +00:00
|
|
|
Environment(parseEnvironment(EnvironmentStr.str())),
|
|
|
|
ObjectFormat(parseFormat(EnvironmentStr.str())) {
|
|
|
|
if (ObjectFormat == Triple::UnknownObjectFormat)
|
|
|
|
ObjectFormat = getDefaultFormat(*this);
|
2012-02-20 00:02:47 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 11:31:39 +00:00
|
|
|
std::string Triple::normalize(StringRef Str) {
|
2014-08-09 23:12:20 +00:00
|
|
|
bool IsMinGW32 = false;
|
|
|
|
bool IsCygwin = false;
|
|
|
|
|
2010-08-12 11:31:39 +00:00
|
|
|
// Parse into components.
|
|
|
|
SmallVector<StringRef, 4> Components;
|
2012-02-21 09:12:48 +00:00
|
|
|
Str.split(Components, "-");
|
2010-08-12 11:31:39 +00:00
|
|
|
|
|
|
|
// If the first component corresponds to a known architecture, preferentially
|
|
|
|
// use it for the architecture. If the second component corresponds to a
|
|
|
|
// known vendor, preferentially use it for the vendor, etc. This avoids silly
|
|
|
|
// component movement when a component parses as (eg) both a valid arch and a
|
|
|
|
// valid os.
|
|
|
|
ArchType Arch = UnknownArch;
|
|
|
|
if (Components.size() > 0)
|
2012-02-21 08:53:32 +00:00
|
|
|
Arch = parseArch(Components[0]);
|
2010-08-12 11:31:39 +00:00
|
|
|
VendorType Vendor = UnknownVendor;
|
|
|
|
if (Components.size() > 1)
|
2012-02-21 08:53:32 +00:00
|
|
|
Vendor = parseVendor(Components[1]);
|
2010-08-12 11:31:39 +00:00
|
|
|
OSType OS = UnknownOS;
|
2014-08-09 23:12:20 +00:00
|
|
|
if (Components.size() > 2) {
|
2012-02-21 08:53:32 +00:00
|
|
|
OS = parseOS(Components[2]);
|
2014-08-09 23:12:20 +00:00
|
|
|
IsCygwin = Components[2].startswith("cygwin");
|
|
|
|
IsMinGW32 = Components[2].startswith("mingw");
|
|
|
|
}
|
2010-09-16 08:25:48 +00:00
|
|
|
EnvironmentType Environment = UnknownEnvironment;
|
|
|
|
if (Components.size() > 3)
|
2012-02-21 08:53:32 +00:00
|
|
|
Environment = parseEnvironment(Components[3]);
|
2014-03-06 20:47:11 +00:00
|
|
|
ObjectFormatType ObjectFormat = UnknownObjectFormat;
|
2014-03-30 07:19:31 +00:00
|
|
|
if (Components.size() > 4)
|
|
|
|
ObjectFormat = parseFormat(Components[4]);
|
2010-08-12 11:31:39 +00:00
|
|
|
|
|
|
|
// Note which components are already in their final position. These will not
|
|
|
|
// be moved.
|
2010-09-16 08:25:48 +00:00
|
|
|
bool Found[4];
|
2010-08-12 11:31:39 +00:00
|
|
|
Found[0] = Arch != UnknownArch;
|
|
|
|
Found[1] = Vendor != UnknownVendor;
|
|
|
|
Found[2] = OS != UnknownOS;
|
2010-09-16 08:25:48 +00:00
|
|
|
Found[3] = Environment != UnknownEnvironment;
|
2010-08-12 11:31:39 +00:00
|
|
|
|
|
|
|
// If they are not there already, permute the components into their canonical
|
|
|
|
// positions by seeing if they parse as a valid architecture, and if so moving
|
|
|
|
// the component to the architecture position etc.
|
2010-09-16 08:25:48 +00:00
|
|
|
for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
|
2010-08-12 11:31:39 +00:00
|
|
|
if (Found[Pos])
|
|
|
|
continue; // Already in the canonical position.
|
|
|
|
|
|
|
|
for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
|
|
|
|
// Do not reparse any components that already matched.
|
2010-09-16 08:25:48 +00:00
|
|
|
if (Idx < array_lengthof(Found) && Found[Idx])
|
2010-08-12 11:31:39 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Does this component parse as valid for the target position?
|
|
|
|
bool Valid = false;
|
|
|
|
StringRef Comp = Components[Idx];
|
|
|
|
switch (Pos) {
|
2012-02-07 05:05:23 +00:00
|
|
|
default: llvm_unreachable("unexpected component type!");
|
2010-08-12 11:31:39 +00:00
|
|
|
case 0:
|
2012-02-21 08:53:32 +00:00
|
|
|
Arch = parseArch(Comp);
|
2010-08-12 11:31:39 +00:00
|
|
|
Valid = Arch != UnknownArch;
|
|
|
|
break;
|
|
|
|
case 1:
|
2012-02-21 08:53:32 +00:00
|
|
|
Vendor = parseVendor(Comp);
|
2010-08-12 11:31:39 +00:00
|
|
|
Valid = Vendor != UnknownVendor;
|
|
|
|
break;
|
|
|
|
case 2:
|
2012-02-21 08:53:32 +00:00
|
|
|
OS = parseOS(Comp);
|
2014-08-09 23:12:20 +00:00
|
|
|
IsCygwin = Comp.startswith("cygwin");
|
|
|
|
IsMinGW32 = Comp.startswith("mingw");
|
|
|
|
Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
|
2010-08-12 11:31:39 +00:00
|
|
|
break;
|
2010-09-16 08:25:48 +00:00
|
|
|
case 3:
|
2012-02-21 08:53:32 +00:00
|
|
|
Environment = parseEnvironment(Comp);
|
2010-09-16 08:25:48 +00:00
|
|
|
Valid = Environment != UnknownEnvironment;
|
2014-03-06 20:47:11 +00:00
|
|
|
if (!Valid) {
|
|
|
|
ObjectFormat = parseFormat(Comp);
|
|
|
|
Valid = ObjectFormat != UnknownObjectFormat;
|
|
|
|
}
|
2010-09-16 08:25:48 +00:00
|
|
|
break;
|
2010-08-12 11:31:39 +00:00
|
|
|
}
|
|
|
|
if (!Valid)
|
|
|
|
continue; // Nope, try the next component.
|
|
|
|
|
|
|
|
// Move the component to the target position, pushing any non-fixed
|
|
|
|
// components that are in the way to the right. This tends to give
|
|
|
|
// good results in the common cases of a forgotten vendor component
|
|
|
|
// or a wrongly positioned environment.
|
|
|
|
if (Pos < Idx) {
|
|
|
|
// Insert left, pushing the existing components to the right. For
|
|
|
|
// example, a-b-i386 -> i386-a-b when moving i386 to the front.
|
|
|
|
StringRef CurrentComponent(""); // The empty component.
|
|
|
|
// Replace the component we are moving with an empty component.
|
|
|
|
std::swap(CurrentComponent, Components[Idx]);
|
|
|
|
// Insert the component being moved at Pos, displacing any existing
|
|
|
|
// components to the right.
|
|
|
|
for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
|
|
|
|
// Skip over any fixed components.
|
2012-02-21 09:29:14 +00:00
|
|
|
while (i < array_lengthof(Found) && Found[i])
|
|
|
|
++i;
|
2010-08-12 11:31:39 +00:00
|
|
|
// Place the component at the new position, getting the component
|
|
|
|
// that was at this position - it will be moved right.
|
|
|
|
std::swap(CurrentComponent, Components[i]);
|
|
|
|
}
|
|
|
|
} else if (Pos > Idx) {
|
|
|
|
// Push right by inserting empty components until the component at Idx
|
|
|
|
// reaches the target position Pos. For example, pc-a -> -pc-a when
|
|
|
|
// moving pc to the second position.
|
|
|
|
do {
|
|
|
|
// Insert one empty component at Idx.
|
|
|
|
StringRef CurrentComponent(""); // The empty component.
|
2011-02-02 10:08:38 +00:00
|
|
|
for (unsigned i = Idx; i < Components.size();) {
|
2010-08-12 11:31:39 +00:00
|
|
|
// Place the component at the new position, getting the component
|
|
|
|
// that was at this position - it will be moved right.
|
|
|
|
std::swap(CurrentComponent, Components[i]);
|
|
|
|
// If it was placed on top of an empty component then we are done.
|
|
|
|
if (CurrentComponent.empty())
|
|
|
|
break;
|
2011-02-02 10:08:38 +00:00
|
|
|
// Advance to the next component, skipping any fixed components.
|
2011-02-05 18:19:35 +00:00
|
|
|
while (++i < array_lengthof(Found) && Found[i])
|
|
|
|
;
|
2010-08-12 11:31:39 +00:00
|
|
|
}
|
|
|
|
// The last component was pushed off the end - append it.
|
|
|
|
if (!CurrentComponent.empty())
|
|
|
|
Components.push_back(CurrentComponent);
|
|
|
|
|
|
|
|
// Advance Idx to the component's new position.
|
2012-02-21 09:29:14 +00:00
|
|
|
while (++Idx < array_lengthof(Found) && Found[Idx])
|
|
|
|
;
|
2010-08-12 11:31:39 +00:00
|
|
|
} while (Idx < Pos); // Add more until the final position is reached.
|
|
|
|
}
|
|
|
|
assert(Pos < Components.size() && Components[Pos] == Comp &&
|
|
|
|
"Component moved wrong!");
|
|
|
|
Found[Pos] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case logic goes here. At this point Arch, Vendor and OS have the
|
|
|
|
// correct values for the computed components.
|
|
|
|
|
2014-03-27 22:50:05 +00:00
|
|
|
if (OS == Triple::Win32) {
|
|
|
|
Components.resize(4);
|
|
|
|
Components[2] = "windows";
|
2014-03-30 07:19:31 +00:00
|
|
|
if (Environment == UnknownEnvironment) {
|
2014-03-31 16:34:41 +00:00
|
|
|
if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
|
2014-03-30 07:19:31 +00:00
|
|
|
Components[3] = "msvc";
|
|
|
|
else
|
|
|
|
Components[3] = getObjectFormatTypeName(ObjectFormat);
|
|
|
|
}
|
2014-08-09 23:12:20 +00:00
|
|
|
} else if (IsMinGW32) {
|
2014-03-27 22:50:05 +00:00
|
|
|
Components.resize(4);
|
|
|
|
Components[2] = "windows";
|
2014-03-31 16:34:41 +00:00
|
|
|
Components[3] = "gnu";
|
2014-08-09 23:12:20 +00:00
|
|
|
} else if (IsCygwin) {
|
2014-03-27 22:50:05 +00:00
|
|
|
Components.resize(4);
|
|
|
|
Components[2] = "windows";
|
|
|
|
Components[3] = "cygnus";
|
|
|
|
}
|
2014-08-09 23:12:20 +00:00
|
|
|
if (IsMinGW32 || IsCygwin ||
|
2014-03-31 16:34:41 +00:00
|
|
|
(OS == Triple::Win32 && Environment != UnknownEnvironment)) {
|
|
|
|
if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
|
|
|
|
Components.resize(5);
|
|
|
|
Components[4] = getObjectFormatTypeName(ObjectFormat);
|
|
|
|
}
|
|
|
|
}
|
2014-03-27 22:50:05 +00:00
|
|
|
|
2010-08-12 11:31:39 +00:00
|
|
|
// Stick the corrected components back together to form the normalized string.
|
|
|
|
std::string Normalized;
|
|
|
|
for (unsigned i = 0, e = Components.size(); i != e; ++i) {
|
|
|
|
if (i) Normalized += '-';
|
|
|
|
Normalized += Components[i];
|
|
|
|
}
|
|
|
|
return Normalized;
|
|
|
|
}
|
|
|
|
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef Triple::getArchName() const {
|
|
|
|
return StringRef(Data).split('-').first; // Isolate first component
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef Triple::getVendorName() const {
|
|
|
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
|
|
|
return Tmp.split('-').first; // Isolate second component
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef Triple::getOSName() const {
|
|
|
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
|
|
|
Tmp = Tmp.split('-').second; // Strip second component
|
|
|
|
return Tmp.split('-').first; // Isolate third component
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef Triple::getEnvironmentName() const {
|
|
|
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
|
|
|
Tmp = Tmp.split('-').second; // Strip second component
|
|
|
|
return Tmp.split('-').second; // Strip third component
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef Triple::getOSAndEnvironmentName() const {
|
|
|
|
StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
|
|
|
|
return Tmp.split('-').second; // Strip second component
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-12 06:19:40 +00:00
|
|
|
static unsigned EatNumber(StringRef &Str) {
|
|
|
|
assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
|
2011-04-19 20:24:34 +00:00
|
|
|
unsigned Result = 0;
|
2010-12-17 02:10:59 +00:00
|
|
|
|
2011-04-19 20:24:34 +00:00
|
|
|
do {
|
|
|
|
// Consume the leading digit.
|
2009-08-12 06:19:40 +00:00
|
|
|
Result = Result*10 + (Str[0] - '0');
|
2011-04-19 20:24:34 +00:00
|
|
|
|
2009-08-12 06:19:40 +00:00
|
|
|
// Eat the digit.
|
|
|
|
Str = Str.substr(1);
|
2011-04-19 20:24:34 +00:00
|
|
|
} while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
|
2010-12-17 02:10:59 +00:00
|
|
|
|
2009-08-12 06:19:40 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2011-04-19 20:24:34 +00:00
|
|
|
void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
|
|
|
|
unsigned &Micro) const {
|
2009-08-12 06:19:40 +00:00
|
|
|
StringRef OSName = getOSName();
|
|
|
|
|
2015-03-03 18:23:51 +00:00
|
|
|
// For Android, we care about the Android version rather than the Linux
|
|
|
|
// version.
|
|
|
|
if (getEnvironment() == Android) {
|
|
|
|
OSName = getEnvironmentName().substr(strlen("android"));
|
|
|
|
if (OSName.startswith("eabi"))
|
|
|
|
OSName = OSName.substr(strlen("eabi"));
|
|
|
|
}
|
|
|
|
|
2011-04-19 20:24:34 +00:00
|
|
|
// Assume that the OS portion of the triple starts with the canonical name.
|
|
|
|
StringRef OSTypeName = getOSTypeName(getOS());
|
|
|
|
if (OSName.startswith(OSTypeName))
|
|
|
|
OSName = OSName.substr(OSTypeName.size());
|
2010-12-17 02:10:59 +00:00
|
|
|
|
2011-04-19 20:24:34 +00:00
|
|
|
// Any unset version defaults to 0.
|
|
|
|
Major = Minor = Micro = 0;
|
2010-12-17 02:10:59 +00:00
|
|
|
|
2011-04-19 20:24:34 +00:00
|
|
|
// Parse up to three components.
|
|
|
|
unsigned *Components[3] = { &Major, &Minor, &Micro };
|
|
|
|
for (unsigned i = 0; i != 3; ++i) {
|
|
|
|
if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
|
|
|
|
break;
|
2010-12-17 02:10:59 +00:00
|
|
|
|
2011-04-19 20:24:34 +00:00
|
|
|
// Consume the leading number.
|
|
|
|
*Components[i] = EatNumber(OSName);
|
2009-08-12 06:19:40 +00:00
|
|
|
|
2011-04-19 20:24:34 +00:00
|
|
|
// Consume the separator, if present.
|
|
|
|
if (OSName.startswith("."))
|
|
|
|
OSName = OSName.substr(1);
|
|
|
|
}
|
2009-08-12 06:19:40 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 22:32:29 +00:00
|
|
|
bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
|
|
|
|
unsigned &Micro) const {
|
|
|
|
getOSVersion(Major, Minor, Micro);
|
|
|
|
|
|
|
|
switch (getOS()) {
|
2012-02-07 05:05:23 +00:00
|
|
|
default: llvm_unreachable("unexpected OS for Darwin triple");
|
2012-01-31 22:32:29 +00:00
|
|
|
case Darwin:
|
|
|
|
// Default to darwin8, i.e., MacOSX 10.4.
|
|
|
|
if (Major == 0)
|
|
|
|
Major = 8;
|
|
|
|
// Darwin version numbers are skewed from OS X versions.
|
|
|
|
if (Major < 4)
|
|
|
|
return false;
|
|
|
|
Micro = 0;
|
|
|
|
Minor = Major - 4;
|
|
|
|
Major = 10;
|
|
|
|
break;
|
|
|
|
case MacOSX:
|
|
|
|
// Default to 10.4.
|
|
|
|
if (Major == 0) {
|
|
|
|
Major = 10;
|
|
|
|
Minor = 4;
|
|
|
|
}
|
|
|
|
if (Major != 10)
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case IOS:
|
|
|
|
// Ignore the version from the triple. This is only handled because the
|
|
|
|
// the clang driver combines OS X and IOS support into a common Darwin
|
|
|
|
// toolchain that wants to know the OS X version number even when targeting
|
|
|
|
// IOS.
|
|
|
|
Major = 10;
|
|
|
|
Minor = 4;
|
|
|
|
Micro = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-09 17:23:48 +00:00
|
|
|
void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
|
|
|
|
unsigned &Micro) const {
|
|
|
|
switch (getOS()) {
|
|
|
|
default: llvm_unreachable("unexpected OS for Darwin triple");
|
|
|
|
case Darwin:
|
|
|
|
case MacOSX:
|
|
|
|
// Ignore the version from the triple. This is only handled because the
|
|
|
|
// the clang driver combines OS X and IOS support into a common Darwin
|
|
|
|
// toolchain that wants to know the iOS version number even when targeting
|
|
|
|
// OS X.
|
2013-12-10 11:53:16 +00:00
|
|
|
Major = 5;
|
2012-05-09 17:23:48 +00:00
|
|
|
Minor = 0;
|
|
|
|
Micro = 0;
|
2012-05-09 17:38:47 +00:00
|
|
|
break;
|
2012-05-09 17:23:48 +00:00
|
|
|
case IOS:
|
|
|
|
getOSVersion(Major, Minor, Micro);
|
2014-03-29 10:18:08 +00:00
|
|
|
// Default to 5.0 (or 7.0 for arm64).
|
2012-05-09 18:23:00 +00:00
|
|
|
if (Major == 0)
|
2014-07-23 12:32:47 +00:00
|
|
|
Major = (getArch() == aarch64) ? 7 : 5;
|
2012-05-09 17:23:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-26 03:31:47 +00:00
|
|
|
void Triple::setTriple(const Twine &Str) {
|
2012-02-21 03:39:36 +00:00
|
|
|
*this = Triple(Str);
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Triple::setArch(ArchType Kind) {
|
|
|
|
setArchName(getArchTypeName(Kind));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Triple::setVendor(VendorType Kind) {
|
|
|
|
setVendorName(getVendorTypeName(Kind));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Triple::setOS(OSType Kind) {
|
|
|
|
setOSName(getOSTypeName(Kind));
|
|
|
|
}
|
|
|
|
|
2010-09-16 08:25:48 +00:00
|
|
|
void Triple::setEnvironment(EnvironmentType Kind) {
|
2015-02-13 22:05:50 +00:00
|
|
|
if (ObjectFormat == getDefaultFormat(*this))
|
|
|
|
return setEnvironmentName(getEnvironmentTypeName(Kind));
|
|
|
|
|
|
|
|
setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
|
|
|
|
getObjectFormatTypeName(ObjectFormat)).str());
|
2010-09-16 08:25:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 20:47:11 +00:00
|
|
|
void Triple::setObjectFormat(ObjectFormatType Kind) {
|
2014-03-31 16:34:41 +00:00
|
|
|
if (Environment == UnknownEnvironment)
|
|
|
|
return setEnvironmentName(getObjectFormatTypeName(Kind));
|
|
|
|
|
2014-07-08 14:55:06 +00:00
|
|
|
setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
|
|
|
|
getObjectFormatTypeName(Kind)).str());
|
2014-03-06 20:47:11 +00:00
|
|
|
}
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
void Triple::setArchName(StringRef Str) {
|
2009-10-06 21:45:26 +00:00
|
|
|
// Work around a miscompilation bug for Twines in gcc 4.0.3.
|
|
|
|
SmallString<64> Triple;
|
|
|
|
Triple += Str;
|
|
|
|
Triple += "-";
|
|
|
|
Triple += getVendorName();
|
|
|
|
Triple += "-";
|
|
|
|
Triple += getOSAndEnvironmentName();
|
2015-03-18 10:17:07 +00:00
|
|
|
setTriple(Triple);
|
2009-04-01 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
void Triple::setVendorName(StringRef Str) {
|
2009-04-01 21:53:23 +00:00
|
|
|
setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
|
|
|
|
}
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
void Triple::setOSName(StringRef Str) {
|
2009-04-01 21:53:23 +00:00
|
|
|
if (hasEnvironment())
|
|
|
|
setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
|
|
|
|
"-" + getEnvironmentName());
|
|
|
|
else
|
|
|
|
setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
|
|
|
|
}
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
void Triple::setEnvironmentName(StringRef Str) {
|
|
|
|
setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
|
2009-04-01 21:53:23 +00:00
|
|
|
"-" + Str);
|
|
|
|
}
|
|
|
|
|
2009-11-06 10:58:06 +00:00
|
|
|
void Triple::setOSAndEnvironmentName(StringRef Str) {
|
2009-04-01 21:53:23 +00:00
|
|
|
setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
|
|
|
|
}
|
2012-01-31 04:52:32 +00:00
|
|
|
|
|
|
|
static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
|
|
|
|
switch (Arch) {
|
|
|
|
case llvm::Triple::UnknownArch:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case llvm::Triple::msp430:
|
|
|
|
return 16;
|
|
|
|
|
|
|
|
case llvm::Triple::arm:
|
2014-03-28 14:35:30 +00:00
|
|
|
case llvm::Triple::armeb:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::hexagon:
|
|
|
|
case llvm::Triple::le32:
|
|
|
|
case llvm::Triple::mips:
|
|
|
|
case llvm::Triple::mipsel:
|
2012-05-04 20:18:50 +00:00
|
|
|
case llvm::Triple::nvptx:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::ppc:
|
2012-03-09 10:09:36 +00:00
|
|
|
case llvm::Triple::r600:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::sparc:
|
|
|
|
case llvm::Triple::tce:
|
|
|
|
case llvm::Triple::thumb:
|
2014-03-28 14:35:30 +00:00
|
|
|
case llvm::Triple::thumbeb:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::xcore:
|
2014-09-19 19:52:11 +00:00
|
|
|
case llvm::Triple::amdil:
|
|
|
|
case llvm::Triple::hsail:
|
2012-11-15 10:35:47 +00:00
|
|
|
case llvm::Triple::spir:
|
2014-07-10 17:26:54 +00:00
|
|
|
case llvm::Triple::kalimba:
|
2012-01-31 04:52:32 +00:00
|
|
|
return 32;
|
|
|
|
|
2013-01-31 12:12:40 +00:00
|
|
|
case llvm::Triple::aarch64:
|
2014-02-24 11:34:50 +00:00
|
|
|
case llvm::Triple::aarch64_be:
|
2015-01-06 18:00:00 +00:00
|
|
|
case llvm::Triple::amdgcn:
|
BPF backend
Summary:
V8->V9:
- cleanup tests
V7->V8:
- addressed feedback from David:
- switched to range-based 'for' loops
- fixed formatting of tests
V6->V7:
- rebased and adjusted AsmPrinter args
- CamelCased .td, fixed formatting, cleaned up names, removed unused patterns
- diffstat: 3 files changed, 203 insertions(+), 227 deletions(-)
V5->V6:
- addressed feedback from Chandler:
- reinstated full verbose standard banner in all files
- fixed variables that were not in CamelCase
- fixed names of #ifdef in header files
- removed redundant braces in if/else chains with single statements
- fixed comments
- removed trailing empty line
- dropped debug annotations from tests
- diffstat of these changes:
46 files changed, 456 insertions(+), 469 deletions(-)
V4->V5:
- fix setLoadExtAction() interface
- clang-formated all where it made sense
V3->V4:
- added CODE_OWNERS entry for BPF backend
V2->V3:
- fix metadata in tests
V1->V2:
- addressed feedback from Tom and Matt
- removed top level change to configure (now everything via 'experimental-backend')
- reworked error reporting via DiagnosticInfo (similar to R600)
- added few more tests
- added cmake build
- added Triple::bpf
- tested on linux and darwin
V1 cover letter:
---------------------
recently linux gained "universal in-kernel virtual machine" which is called
eBPF or extended BPF. The name comes from "Berkeley Packet Filter", since
new instruction set is based on it.
This patch adds a new backend that emits extended BPF instruction set.
The concept and development are covered by the following articles:
http://lwn.net/Articles/599755/
http://lwn.net/Articles/575531/
http://lwn.net/Articles/603983/
http://lwn.net/Articles/606089/
http://lwn.net/Articles/612878/
One of use cases: dtrace/systemtap alternative.
bpf syscall manpage:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b4fc1a460f3017e958e6a8ea560ea0afd91bf6fe
instruction set description and differences vs classic BPF:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/filter.txt
Short summary of instruction set:
- 64-bit registers
R0 - return value from in-kernel function, and exit value for BPF program
R1 - R5 - arguments from BPF program to in-kernel function
R6 - R9 - callee saved registers that in-kernel function will preserve
R10 - read-only frame pointer to access stack
- two-operand instructions like +, -, *, mov, load/store
- implicit prologue/epilogue (invisible stack pointer)
- no floating point, no simd
Short history of extended BPF in kernel:
interpreter in 3.15, x64 JIT in 3.16, arm64 JIT, verifier, bpf syscall in 3.18, more to come in the future.
It's a very small and simple backend.
There is no support for global variables, arbitrary function calls, floating point, varargs,
exceptions, indirect jumps, arbitrary pointer arithmetic, alloca, etc.
From C front-end point of view it's very restricted. It's done on purpose, since kernel
rejects all programs that it cannot prove safe. It rejects programs with loops
and with memory accesses via arbitrary pointers. When kernel accepts the program it is
guaranteed that program will terminate and will not crash the kernel.
This patch implements all 'must have' bits. There are several things on TODO list,
so this is not the end of development.
Most of the code is a boiler plate code, copy-pasted from other backends.
Only odd things are lack or < and <= instructions, specialized load_byte intrinsics
and 'compare and goto' as single instruction.
Current instruction set is fixed, but more instructions can be added in the future.
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subscribers: majnemer, chandlerc, echristo, joerg, pete, rengolin, kristof.beyls, arsenm, t.p.northover, tstellarAMD, aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D6494
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 17:51:26 +00:00
|
|
|
case llvm::Triple::bpf:
|
2014-09-12 17:54:17 +00:00
|
|
|
case llvm::Triple::le64:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::mips64:
|
|
|
|
case llvm::Triple::mips64el:
|
2012-05-04 20:18:50 +00:00
|
|
|
case llvm::Triple::nvptx64:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::ppc64:
|
2013-07-26 01:35:43 +00:00
|
|
|
case llvm::Triple::ppc64le:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::sparcv9:
|
2013-05-03 11:05:17 +00:00
|
|
|
case llvm::Triple::systemz:
|
2012-01-31 04:52:32 +00:00
|
|
|
case llvm::Triple::x86_64:
|
2014-09-19 19:52:11 +00:00
|
|
|
case llvm::Triple::amdil64:
|
|
|
|
case llvm::Triple::hsail64:
|
2012-11-15 10:35:47 +00:00
|
|
|
case llvm::Triple::spir64:
|
2012-01-31 04:52:32 +00:00
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid architecture value");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Triple::isArch64Bit() const {
|
|
|
|
return getArchPointerBitWidth(getArch()) == 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Triple::isArch32Bit() const {
|
|
|
|
return getArchPointerBitWidth(getArch()) == 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Triple::isArch16Bit() const {
|
|
|
|
return getArchPointerBitWidth(getArch()) == 16;
|
|
|
|
}
|
2012-02-06 20:46:33 +00:00
|
|
|
|
|
|
|
Triple Triple::get32BitArchVariant() const {
|
|
|
|
Triple T(*this);
|
|
|
|
switch (getArch()) {
|
|
|
|
case Triple::UnknownArch:
|
2013-01-31 12:12:40 +00:00
|
|
|
case Triple::aarch64:
|
2014-02-24 11:34:50 +00:00
|
|
|
case Triple::aarch64_be:
|
2015-01-06 18:00:00 +00:00
|
|
|
case Triple::amdgcn:
|
BPF backend
Summary:
V8->V9:
- cleanup tests
V7->V8:
- addressed feedback from David:
- switched to range-based 'for' loops
- fixed formatting of tests
V6->V7:
- rebased and adjusted AsmPrinter args
- CamelCased .td, fixed formatting, cleaned up names, removed unused patterns
- diffstat: 3 files changed, 203 insertions(+), 227 deletions(-)
V5->V6:
- addressed feedback from Chandler:
- reinstated full verbose standard banner in all files
- fixed variables that were not in CamelCase
- fixed names of #ifdef in header files
- removed redundant braces in if/else chains with single statements
- fixed comments
- removed trailing empty line
- dropped debug annotations from tests
- diffstat of these changes:
46 files changed, 456 insertions(+), 469 deletions(-)
V4->V5:
- fix setLoadExtAction() interface
- clang-formated all where it made sense
V3->V4:
- added CODE_OWNERS entry for BPF backend
V2->V3:
- fix metadata in tests
V1->V2:
- addressed feedback from Tom and Matt
- removed top level change to configure (now everything via 'experimental-backend')
- reworked error reporting via DiagnosticInfo (similar to R600)
- added few more tests
- added cmake build
- added Triple::bpf
- tested on linux and darwin
V1 cover letter:
---------------------
recently linux gained "universal in-kernel virtual machine" which is called
eBPF or extended BPF. The name comes from "Berkeley Packet Filter", since
new instruction set is based on it.
This patch adds a new backend that emits extended BPF instruction set.
The concept and development are covered by the following articles:
http://lwn.net/Articles/599755/
http://lwn.net/Articles/575531/
http://lwn.net/Articles/603983/
http://lwn.net/Articles/606089/
http://lwn.net/Articles/612878/
One of use cases: dtrace/systemtap alternative.
bpf syscall manpage:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b4fc1a460f3017e958e6a8ea560ea0afd91bf6fe
instruction set description and differences vs classic BPF:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/filter.txt
Short summary of instruction set:
- 64-bit registers
R0 - return value from in-kernel function, and exit value for BPF program
R1 - R5 - arguments from BPF program to in-kernel function
R6 - R9 - callee saved registers that in-kernel function will preserve
R10 - read-only frame pointer to access stack
- two-operand instructions like +, -, *, mov, load/store
- implicit prologue/epilogue (invisible stack pointer)
- no floating point, no simd
Short history of extended BPF in kernel:
interpreter in 3.15, x64 JIT in 3.16, arm64 JIT, verifier, bpf syscall in 3.18, more to come in the future.
It's a very small and simple backend.
There is no support for global variables, arbitrary function calls, floating point, varargs,
exceptions, indirect jumps, arbitrary pointer arithmetic, alloca, etc.
From C front-end point of view it's very restricted. It's done on purpose, since kernel
rejects all programs that it cannot prove safe. It rejects programs with loops
and with memory accesses via arbitrary pointers. When kernel accepts the program it is
guaranteed that program will terminate and will not crash the kernel.
This patch implements all 'must have' bits. There are several things on TODO list,
so this is not the end of development.
Most of the code is a boiler plate code, copy-pasted from other backends.
Only odd things are lack or < and <= instructions, specialized load_byte intrinsics
and 'compare and goto' as single instruction.
Current instruction set is fixed, but more instructions can be added in the future.
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subscribers: majnemer, chandlerc, echristo, joerg, pete, rengolin, kristof.beyls, arsenm, t.p.northover, tstellarAMD, aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D6494
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 17:51:26 +00:00
|
|
|
case Triple::bpf:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::msp430:
|
2013-05-03 11:05:17 +00:00
|
|
|
case Triple::systemz:
|
2013-07-26 01:35:43 +00:00
|
|
|
case Triple::ppc64le:
|
2012-02-06 20:46:33 +00:00
|
|
|
T.setArch(UnknownArch);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Triple::amdil:
|
2014-09-19 19:52:11 +00:00
|
|
|
case Triple::hsail:
|
2012-10-01 17:01:31 +00:00
|
|
|
case Triple::spir:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::arm:
|
2014-03-28 14:35:30 +00:00
|
|
|
case Triple::armeb:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::hexagon:
|
2014-07-10 17:26:54 +00:00
|
|
|
case Triple::kalimba:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::le32:
|
|
|
|
case Triple::mips:
|
|
|
|
case Triple::mipsel:
|
2012-05-04 20:18:50 +00:00
|
|
|
case Triple::nvptx:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::ppc:
|
2012-03-09 10:09:36 +00:00
|
|
|
case Triple::r600:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::sparc:
|
|
|
|
case Triple::tce:
|
|
|
|
case Triple::thumb:
|
2014-03-28 14:35:30 +00:00
|
|
|
case Triple::thumbeb:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::x86:
|
|
|
|
case Triple::xcore:
|
|
|
|
// Already 32-bit.
|
|
|
|
break;
|
|
|
|
|
2014-09-12 17:54:17 +00:00
|
|
|
case Triple::le64: T.setArch(Triple::le32); break;
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::mips64: T.setArch(Triple::mips); break;
|
|
|
|
case Triple::mips64el: T.setArch(Triple::mipsel); break;
|
2012-05-04 20:18:50 +00:00
|
|
|
case Triple::nvptx64: T.setArch(Triple::nvptx); break;
|
2014-03-09 23:17:28 +00:00
|
|
|
case Triple::ppc64: T.setArch(Triple::ppc); break;
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::sparcv9: T.setArch(Triple::sparc); break;
|
|
|
|
case Triple::x86_64: T.setArch(Triple::x86); break;
|
2014-09-19 19:52:11 +00:00
|
|
|
case Triple::amdil64: T.setArch(Triple::amdil); break;
|
|
|
|
case Triple::hsail64: T.setArch(Triple::hsail); break;
|
2012-11-15 10:35:47 +00:00
|
|
|
case Triple::spir64: T.setArch(Triple::spir); break;
|
2012-02-06 20:46:33 +00:00
|
|
|
}
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
|
|
|
Triple Triple::get64BitArchVariant() const {
|
|
|
|
Triple T(*this);
|
|
|
|
switch (getArch()) {
|
|
|
|
case Triple::UnknownArch:
|
2014-03-30 07:25:23 +00:00
|
|
|
case Triple::arm:
|
2014-03-28 14:35:30 +00:00
|
|
|
case Triple::armeb:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::hexagon:
|
2014-07-10 17:26:54 +00:00
|
|
|
case Triple::kalimba:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::msp430:
|
2012-03-09 10:09:36 +00:00
|
|
|
case Triple::r600:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::tce:
|
|
|
|
case Triple::thumb:
|
2014-03-28 14:35:30 +00:00
|
|
|
case Triple::thumbeb:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::xcore:
|
|
|
|
T.setArch(UnknownArch);
|
|
|
|
break;
|
|
|
|
|
2013-01-31 12:12:40 +00:00
|
|
|
case Triple::aarch64:
|
2014-02-24 11:34:50 +00:00
|
|
|
case Triple::aarch64_be:
|
BPF backend
Summary:
V8->V9:
- cleanup tests
V7->V8:
- addressed feedback from David:
- switched to range-based 'for' loops
- fixed formatting of tests
V6->V7:
- rebased and adjusted AsmPrinter args
- CamelCased .td, fixed formatting, cleaned up names, removed unused patterns
- diffstat: 3 files changed, 203 insertions(+), 227 deletions(-)
V5->V6:
- addressed feedback from Chandler:
- reinstated full verbose standard banner in all files
- fixed variables that were not in CamelCase
- fixed names of #ifdef in header files
- removed redundant braces in if/else chains with single statements
- fixed comments
- removed trailing empty line
- dropped debug annotations from tests
- diffstat of these changes:
46 files changed, 456 insertions(+), 469 deletions(-)
V4->V5:
- fix setLoadExtAction() interface
- clang-formated all where it made sense
V3->V4:
- added CODE_OWNERS entry for BPF backend
V2->V3:
- fix metadata in tests
V1->V2:
- addressed feedback from Tom and Matt
- removed top level change to configure (now everything via 'experimental-backend')
- reworked error reporting via DiagnosticInfo (similar to R600)
- added few more tests
- added cmake build
- added Triple::bpf
- tested on linux and darwin
V1 cover letter:
---------------------
recently linux gained "universal in-kernel virtual machine" which is called
eBPF or extended BPF. The name comes from "Berkeley Packet Filter", since
new instruction set is based on it.
This patch adds a new backend that emits extended BPF instruction set.
The concept and development are covered by the following articles:
http://lwn.net/Articles/599755/
http://lwn.net/Articles/575531/
http://lwn.net/Articles/603983/
http://lwn.net/Articles/606089/
http://lwn.net/Articles/612878/
One of use cases: dtrace/systemtap alternative.
bpf syscall manpage:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b4fc1a460f3017e958e6a8ea560ea0afd91bf6fe
instruction set description and differences vs classic BPF:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/filter.txt
Short summary of instruction set:
- 64-bit registers
R0 - return value from in-kernel function, and exit value for BPF program
R1 - R5 - arguments from BPF program to in-kernel function
R6 - R9 - callee saved registers that in-kernel function will preserve
R10 - read-only frame pointer to access stack
- two-operand instructions like +, -, *, mov, load/store
- implicit prologue/epilogue (invisible stack pointer)
- no floating point, no simd
Short history of extended BPF in kernel:
interpreter in 3.15, x64 JIT in 3.16, arm64 JIT, verifier, bpf syscall in 3.18, more to come in the future.
It's a very small and simple backend.
There is no support for global variables, arbitrary function calls, floating point, varargs,
exceptions, indirect jumps, arbitrary pointer arithmetic, alloca, etc.
From C front-end point of view it's very restricted. It's done on purpose, since kernel
rejects all programs that it cannot prove safe. It rejects programs with loops
and with memory accesses via arbitrary pointers. When kernel accepts the program it is
guaranteed that program will terminate and will not crash the kernel.
This patch implements all 'must have' bits. There are several things on TODO list,
so this is not the end of development.
Most of the code is a boiler plate code, copy-pasted from other backends.
Only odd things are lack or < and <= instructions, specialized load_byte intrinsics
and 'compare and goto' as single instruction.
Current instruction set is fixed, but more instructions can be added in the future.
Signed-off-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Subscribers: majnemer, chandlerc, echristo, joerg, pete, rengolin, kristof.beyls, arsenm, t.p.northover, tstellarAMD, aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D6494
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 17:51:26 +00:00
|
|
|
case Triple::bpf:
|
2014-09-12 17:54:17 +00:00
|
|
|
case Triple::le64:
|
2014-09-19 19:52:11 +00:00
|
|
|
case Triple::amdil64:
|
2015-01-06 18:00:00 +00:00
|
|
|
case Triple::amdgcn:
|
2014-09-19 19:52:11 +00:00
|
|
|
case Triple::hsail64:
|
|
|
|
case Triple::spir64:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::mips64:
|
|
|
|
case Triple::mips64el:
|
2012-05-04 20:18:50 +00:00
|
|
|
case Triple::nvptx64:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::ppc64:
|
2013-07-26 01:35:43 +00:00
|
|
|
case Triple::ppc64le:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::sparcv9:
|
2013-05-03 11:05:17 +00:00
|
|
|
case Triple::systemz:
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::x86_64:
|
|
|
|
// Already 64-bit.
|
|
|
|
break;
|
|
|
|
|
2014-09-12 17:54:17 +00:00
|
|
|
case Triple::le32: T.setArch(Triple::le64); break;
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::mips: T.setArch(Triple::mips64); break;
|
|
|
|
case Triple::mipsel: T.setArch(Triple::mips64el); break;
|
2012-05-04 20:18:50 +00:00
|
|
|
case Triple::nvptx: T.setArch(Triple::nvptx64); break;
|
2012-02-06 20:46:33 +00:00
|
|
|
case Triple::ppc: T.setArch(Triple::ppc64); break;
|
|
|
|
case Triple::sparc: T.setArch(Triple::sparcv9); break;
|
|
|
|
case Triple::x86: T.setArch(Triple::x86_64); break;
|
2014-09-19 19:52:11 +00:00
|
|
|
case Triple::amdil: T.setArch(Triple::amdil64); break;
|
|
|
|
case Triple::hsail: T.setArch(Triple::hsail64); break;
|
2012-11-15 10:35:47 +00:00
|
|
|
case Triple::spir: T.setArch(Triple::spir64); break;
|
2012-02-06 20:46:33 +00:00
|
|
|
}
|
|
|
|
return T;
|
|
|
|
}
|
2014-07-11 21:44:54 +00:00
|
|
|
|
|
|
|
// FIXME: tblgen this.
|
|
|
|
const char *Triple::getARMCPUForArch(StringRef MArch) const {
|
|
|
|
if (MArch.empty())
|
|
|
|
MArch = getArchName();
|
|
|
|
|
|
|
|
switch (getOS()) {
|
2014-09-09 17:47:24 +00:00
|
|
|
case llvm::Triple::FreeBSD:
|
2014-07-11 21:44:54 +00:00
|
|
|
case llvm::Triple::NetBSD:
|
|
|
|
if (MArch == "armv6")
|
|
|
|
return "arm1176jzf-s";
|
|
|
|
break;
|
|
|
|
case llvm::Triple::Win32:
|
|
|
|
// FIXME: this is invalid for WindowsCE
|
|
|
|
return "cortex-a9";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *result = nullptr;
|
|
|
|
size_t offset = StringRef::npos;
|
|
|
|
if (MArch.startswith("arm"))
|
|
|
|
offset = 3;
|
|
|
|
if (MArch.startswith("thumb"))
|
|
|
|
offset = 5;
|
|
|
|
if (offset != StringRef::npos && MArch.substr(offset, 2) == "eb")
|
|
|
|
offset += 2;
|
2015-01-26 11:41:48 +00:00
|
|
|
if (MArch.endswith("eb"))
|
|
|
|
MArch = MArch.substr(0, MArch.size() - 2);
|
2014-07-11 21:44:54 +00:00
|
|
|
if (offset != StringRef::npos)
|
|
|
|
result = llvm::StringSwitch<const char *>(MArch.substr(offset))
|
|
|
|
.Cases("v2", "v2a", "arm2")
|
|
|
|
.Case("v3", "arm6")
|
|
|
|
.Case("v3m", "arm7m")
|
|
|
|
.Case("v4", "strongarm")
|
|
|
|
.Case("v4t", "arm7tdmi")
|
|
|
|
.Cases("v5", "v5t", "arm10tdmi")
|
|
|
|
.Cases("v5e", "v5te", "arm1022e")
|
|
|
|
.Case("v5tej", "arm926ej-s")
|
2015-03-17 11:55:28 +00:00
|
|
|
.Case("v6", "arm1136jf-s")
|
2014-07-11 21:44:54 +00:00
|
|
|
.Case("v6j", "arm1136j-s")
|
2015-03-17 11:55:28 +00:00
|
|
|
.Cases("v6k", "v6z", "v6zk", "arm1176jzf-s")
|
2014-07-11 21:44:54 +00:00
|
|
|
.Case("v6t2", "arm1156t2-s")
|
2015-02-10 15:15:08 +00:00
|
|
|
.Cases("v6m", "v6-m", "v6sm", "v6s-m", "cortex-m0")
|
2014-07-11 21:44:54 +00:00
|
|
|
.Cases("v7", "v7a", "v7-a", "v7l", "v7-l", "cortex-a8")
|
|
|
|
.Cases("v7s", "v7-s", "swift")
|
|
|
|
.Cases("v7r", "v7-r", "cortex-r4")
|
|
|
|
.Cases("v7m", "v7-m", "cortex-m3")
|
|
|
|
.Cases("v7em", "v7e-m", "cortex-m4")
|
|
|
|
.Cases("v8", "v8a", "v8-a", "cortex-a53")
|
2015-03-26 17:05:54 +00:00
|
|
|
.Cases("v8.1a", "v8.1-a", "generic-armv8.1-a")
|
2014-07-11 21:44:54 +00:00
|
|
|
.Default(nullptr);
|
|
|
|
else
|
|
|
|
result = llvm::StringSwitch<const char *>(MArch)
|
|
|
|
.Case("ep9312", "ep9312")
|
|
|
|
.Case("iwmmxt", "iwmmxt")
|
|
|
|
.Case("xscale", "xscale")
|
|
|
|
.Default(nullptr);
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// If all else failed, return the most base CPU with thumb interworking
|
|
|
|
// supported by LLVM.
|
|
|
|
// FIXME: Should warn once that we're falling back.
|
|
|
|
switch (getOS()) {
|
|
|
|
case llvm::Triple::NetBSD:
|
|
|
|
switch (getEnvironment()) {
|
|
|
|
case llvm::Triple::GNUEABIHF:
|
|
|
|
case llvm::Triple::GNUEABI:
|
|
|
|
case llvm::Triple::EABIHF:
|
|
|
|
case llvm::Triple::EABI:
|
|
|
|
return "arm926ej-s";
|
|
|
|
default:
|
|
|
|
return "strongarm";
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
switch (getEnvironment()) {
|
|
|
|
case llvm::Triple::EABIHF:
|
|
|
|
case llvm::Triple::GNUEABIHF:
|
|
|
|
return "arm1176jzf-s";
|
|
|
|
default:
|
|
|
|
return "arm7tdmi";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|