2009-04-01 21:53:23 +00:00
|
|
|
//===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ADT_TRIPLE_H
|
|
|
|
#define LLVM_ADT_TRIPLE_H
|
|
|
|
|
2011-07-24 20:45:08 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2009-04-01 21:53:23 +00:00
|
|
|
|
2009-08-26 05:00:16 +00:00
|
|
|
// Some system headers or GCC predefined macros conflict with identifiers in
|
|
|
|
// this file. Undefine them here.
|
2013-09-25 17:49:57 +00:00
|
|
|
#undef NetBSD
|
2009-08-26 05:00:16 +00:00
|
|
|
#undef mips
|
|
|
|
#undef sparc
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2013-05-20 23:55:41 +00:00
|
|
|
/// Triple - Helper class for working with autoconf configuration names. For
|
|
|
|
/// historical reasons, we also call these 'triples' (they used to contain
|
|
|
|
/// exactly three fields).
|
2009-04-01 21:53:23 +00:00
|
|
|
///
|
2013-05-20 23:55:41 +00:00
|
|
|
/// Configuration names are strings in the canonical form:
|
2009-04-01 21:53:23 +00:00
|
|
|
/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM
|
|
|
|
/// or
|
|
|
|
/// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
|
|
|
|
///
|
|
|
|
/// This class is used for clients which want to support arbitrary
|
2013-05-20 23:55:41 +00:00
|
|
|
/// configuration names, but also want to implement certain special
|
|
|
|
/// behavior for particular configurations. This class isolates the mapping
|
|
|
|
/// from the components of the configuration name to well known IDs.
|
2009-04-01 21:53:23 +00:00
|
|
|
///
|
2009-08-18 19:26:55 +00:00
|
|
|
/// At its core the Triple class is designed to be a wrapper for a triple
|
2010-08-12 11:31:39 +00:00
|
|
|
/// string; the constructor does not change or normalize the triple string.
|
|
|
|
/// Clients that need to handle the non-canonical triples that users often
|
|
|
|
/// specify should use the normalize method.
|
2009-08-18 19:26:55 +00:00
|
|
|
///
|
2013-05-20 23:55:41 +00:00
|
|
|
/// See autoconf/config.guess for a glimpse into what configuration names
|
|
|
|
/// look like in practice.
|
2009-04-01 21:53:23 +00:00
|
|
|
class Triple {
|
|
|
|
public:
|
|
|
|
enum ArchType {
|
|
|
|
UnknownArch,
|
2010-11-13 04:17:15 +00:00
|
|
|
|
2014-03-28 14:35:30 +00:00
|
|
|
arm, // ARM (little endian): arm, armv.*, xscale
|
|
|
|
armeb, // ARM (big endian): armeb
|
2014-02-24 11:34:50 +00:00
|
|
|
aarch64, // AArch64 (little endian): aarch64
|
|
|
|
aarch64_be, // AArch64 (big endian): 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
|
|
|
bpf, // eBPF or extended BPF or 64-bit BPF (little endian)
|
2014-02-24 11:34:50 +00:00
|
|
|
hexagon, // Hexagon: hexagon
|
|
|
|
mips, // MIPS: mips, mipsallegrex
|
|
|
|
mipsel, // MIPSEL: mipsel, mipsallegrexel
|
|
|
|
mips64, // MIPS64: mips64
|
|
|
|
mips64el, // MIPS64EL: mips64el
|
|
|
|
msp430, // MSP430: msp430
|
|
|
|
ppc, // PPC: powerpc
|
|
|
|
ppc64, // PPC64: powerpc64, ppu
|
|
|
|
ppc64le, // PPC64LE: powerpc64le
|
|
|
|
r600, // R600: AMD GPUs HD2XXX - HD6XXX
|
2015-01-06 18:00:00 +00:00
|
|
|
amdgcn, // AMDGCN: AMD GCN GPUs
|
2014-02-24 11:34:50 +00:00
|
|
|
sparc, // Sparc: sparc
|
|
|
|
sparcv9, // Sparcv9: Sparcv9
|
|
|
|
systemz, // SystemZ: s390x
|
|
|
|
tce, // TCE (http://tce.cs.tut.fi/): tce
|
2014-03-28 14:35:30 +00:00
|
|
|
thumb, // Thumb (little endian): thumb, thumbv.*
|
|
|
|
thumbeb, // Thumb (big endian): thumbeb
|
2014-02-24 11:34:50 +00:00
|
|
|
x86, // X86: i[3-9]86
|
|
|
|
x86_64, // X86-64: amd64, x86_64
|
|
|
|
xcore, // XCore: xcore
|
|
|
|
nvptx, // NVPTX: 32-bit
|
|
|
|
nvptx64, // NVPTX: 64-bit
|
|
|
|
le32, // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten)
|
2014-09-12 17:54:17 +00:00
|
|
|
le64, // le64: generic little-endian 64-bit CPU (PNaCl / Emscripten)
|
2014-09-19 19:52:11 +00:00
|
|
|
amdil, // AMDIL
|
|
|
|
amdil64, // AMDIL with 64-bit pointers
|
|
|
|
hsail, // AMD HSAIL
|
|
|
|
hsail64, // AMD HSAIL with 64-bit pointers
|
2014-02-24 11:34:50 +00:00
|
|
|
spir, // SPIR: standard portable IR for OpenCL 32-bit version
|
2014-07-10 17:26:54 +00:00
|
|
|
spir64, // SPIR: standard portable IR for OpenCL 64-bit version
|
|
|
|
kalimba // Kalimba: generic kalimba
|
2009-04-01 21:53:23 +00:00
|
|
|
};
|
2014-07-18 12:00:48 +00:00
|
|
|
enum SubArchType {
|
|
|
|
NoSubArch,
|
|
|
|
|
|
|
|
ARMSubArch_v8,
|
|
|
|
ARMSubArch_v7,
|
|
|
|
ARMSubArch_v7em,
|
|
|
|
ARMSubArch_v7m,
|
|
|
|
ARMSubArch_v7s,
|
|
|
|
ARMSubArch_v6,
|
|
|
|
ARMSubArch_v6m,
|
2015-03-17 11:55:28 +00:00
|
|
|
ARMSubArch_v6k,
|
2014-07-18 12:00:48 +00:00
|
|
|
ARMSubArch_v6t2,
|
|
|
|
ARMSubArch_v5,
|
|
|
|
ARMSubArch_v5te,
|
2014-09-05 06:46:43 +00:00
|
|
|
ARMSubArch_v4t,
|
|
|
|
|
|
|
|
KalimbaSubArch_v3,
|
|
|
|
KalimbaSubArch_v4,
|
|
|
|
KalimbaSubArch_v5
|
2014-07-18 12:00:48 +00:00
|
|
|
};
|
2009-04-01 21:53:23 +00:00
|
|
|
enum VendorType {
|
|
|
|
UnknownVendor,
|
|
|
|
|
2010-11-13 04:17:15 +00:00
|
|
|
Apple,
|
2011-03-15 21:51:56 +00:00
|
|
|
PC,
|
2012-04-02 18:31:33 +00:00
|
|
|
SCEI,
|
|
|
|
BGP,
|
2012-08-28 02:10:30 +00:00
|
|
|
BGQ,
|
2012-10-12 11:08:57 +00:00
|
|
|
Freescale,
|
2013-06-21 18:51:49 +00:00
|
|
|
IBM,
|
2014-07-09 16:03:10 +00:00
|
|
|
ImaginationTechnologies,
|
2014-07-18 14:28:19 +00:00
|
|
|
MipsTechnologies,
|
2014-07-10 17:26:54 +00:00
|
|
|
NVIDIA,
|
|
|
|
CSR
|
2009-04-01 21:53:23 +00:00
|
|
|
};
|
|
|
|
enum OSType {
|
|
|
|
UnknownOS,
|
|
|
|
|
2015-03-09 18:40:45 +00:00
|
|
|
CloudABI,
|
2009-04-01 21:53:23 +00:00
|
|
|
Darwin,
|
2009-05-22 02:24:11 +00:00
|
|
|
DragonFly,
|
2009-04-01 21:53:23 +00:00
|
|
|
FreeBSD,
|
2011-04-19 20:19:27 +00:00
|
|
|
IOS,
|
2011-07-26 15:30:04 +00:00
|
|
|
KFreeBSD,
|
2009-06-29 13:36:13 +00:00
|
|
|
Linux,
|
2009-11-19 11:59:00 +00:00
|
|
|
Lv2, // PS3
|
2011-04-19 23:34:12 +00:00
|
|
|
MacOSX,
|
2009-07-13 20:22:23 +00:00
|
|
|
NetBSD,
|
2009-07-26 04:23:03 +00:00
|
|
|
OpenBSD,
|
2009-08-18 04:43:27 +00:00
|
|
|
Solaris,
|
2009-10-16 02:06:30 +00:00
|
|
|
Win32,
|
2010-07-07 15:52:27 +00:00
|
|
|
Haiku,
|
2011-07-01 22:41:06 +00:00
|
|
|
Minix,
|
2011-08-18 22:54:21 +00:00
|
|
|
RTEMS,
|
2012-12-04 19:08:43 +00:00
|
|
|
NaCl, // Native Client
|
2012-12-04 18:37:26 +00:00
|
|
|
CNK, // BG/P Compute-Node Kernel
|
2012-10-12 11:08:57 +00:00
|
|
|
Bitrig,
|
2013-06-21 18:51:49 +00:00
|
|
|
AIX,
|
|
|
|
CUDA, // NVIDIA CUDA
|
2014-12-02 16:45:47 +00:00
|
|
|
NVCL, // NVIDIA OpenCL
|
2015-01-25 22:46:59 +00:00
|
|
|
AMDHSA, // AMD HSA Runtime
|
|
|
|
PS4
|
2009-04-01 21:53:23 +00:00
|
|
|
};
|
2010-09-16 08:25:48 +00:00
|
|
|
enum EnvironmentType {
|
2011-01-21 18:25:47 +00:00
|
|
|
UnknownEnvironment,
|
|
|
|
|
|
|
|
GNU,
|
|
|
|
GNUEABI,
|
2012-01-18 23:35:29 +00:00
|
|
|
GNUEABIHF,
|
2013-01-22 18:02:49 +00:00
|
|
|
GNUX32,
|
2014-01-20 12:02:25 +00:00
|
|
|
CODE16,
|
2011-02-01 01:14:13 +00:00
|
|
|
EABI,
|
2013-12-16 18:51:28 +00:00
|
|
|
EABIHF,
|
2012-10-02 18:38:34 +00:00
|
|
|
Android,
|
2014-03-27 22:50:05 +00:00
|
|
|
|
|
|
|
MSVC,
|
|
|
|
Itanium,
|
|
|
|
Cygnus,
|
2014-03-06 20:47:11 +00:00
|
|
|
};
|
|
|
|
enum ObjectFormatType {
|
|
|
|
UnknownObjectFormat,
|
|
|
|
|
|
|
|
COFF,
|
|
|
|
ELF,
|
|
|
|
MachO,
|
2010-09-16 08:25:48 +00:00
|
|
|
};
|
2010-11-13 04:17:15 +00:00
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
private:
|
|
|
|
std::string Data;
|
|
|
|
|
2012-02-21 03:39:36 +00:00
|
|
|
/// The parsed arch type.
|
|
|
|
ArchType Arch;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
2014-07-18 12:00:48 +00:00
|
|
|
/// The parsed subarchitecture type.
|
|
|
|
SubArchType SubArch;
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// The parsed vendor type.
|
2012-02-21 03:39:36 +00:00
|
|
|
VendorType Vendor;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// The parsed OS type.
|
2012-02-21 03:39:36 +00:00
|
|
|
OSType OS;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
2010-09-16 08:25:48 +00:00
|
|
|
/// The parsed Environment type.
|
2012-02-21 03:39:36 +00:00
|
|
|
EnvironmentType Environment;
|
2010-09-16 08:25:48 +00:00
|
|
|
|
2014-03-06 20:47:11 +00:00
|
|
|
/// The object format type.
|
|
|
|
ObjectFormatType ObjectFormat;
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
public:
|
|
|
|
/// @name Constructors
|
|
|
|
/// @{
|
2010-11-13 04:17:15 +00:00
|
|
|
|
2012-02-21 08:31:18 +00:00
|
|
|
/// \brief Default constructor is the same as an empty string and leaves all
|
|
|
|
/// triple fields unknown.
|
2014-03-06 20:47:11 +00:00
|
|
|
Triple() : Data(), Arch(), Vendor(), OS(), Environment(), ObjectFormat() {}
|
2009-04-01 21:53:23 +00:00
|
|
|
|
2012-02-20 00:02:47 +00:00
|
|
|
explicit Triple(const Twine &Str);
|
|
|
|
Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
|
2011-07-24 20:45:08 +00:00
|
|
|
Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
|
2012-02-20 00:02:47 +00:00
|
|
|
const Twine &EnvironmentStr);
|
2010-09-16 08:25:48 +00:00
|
|
|
|
2015-02-13 00:40:41 +00:00
|
|
|
bool operator==(const Triple &Other) const {
|
|
|
|
return Arch == Other.Arch && SubArch == Other.SubArch &&
|
|
|
|
Vendor == Other.Vendor && OS == Other.OS &&
|
|
|
|
Environment == Other.Environment &&
|
|
|
|
ObjectFormat == Other.ObjectFormat;
|
|
|
|
}
|
|
|
|
|
2010-08-12 11:31:39 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Normalization
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// normalize - Turn an arbitrary machine specification into the canonical
|
|
|
|
/// triple form (or something sensible that the Triple class understands if
|
|
|
|
/// nothing better can reasonably be done). In particular, it handles the
|
|
|
|
/// common case in which otherwise valid components are in the wrong order.
|
|
|
|
static std::string normalize(StringRef Str);
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226981 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-24 02:06:09 +00:00
|
|
|
/// \brief Return the normalized form of this triple's string.
|
|
|
|
std::string normalize() const { return normalize(Data); }
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Typed Component Access
|
|
|
|
/// @{
|
2010-11-13 04:17:15 +00:00
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// getArch - Get the parsed architecture type of this triple.
|
2012-02-21 03:39:36 +00:00
|
|
|
ArchType getArch() const { return Arch; }
|
2010-11-13 04:17:15 +00:00
|
|
|
|
2014-07-18 12:00:48 +00:00
|
|
|
/// getSubArch - get the parsed subarchitecture type for this triple.
|
|
|
|
SubArchType getSubArch() const { return SubArch; }
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// getVendor - Get the parsed vendor type of this triple.
|
2012-02-21 03:39:36 +00:00
|
|
|
VendorType getVendor() const { return Vendor; }
|
2010-11-13 04:17:15 +00:00
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// getOS - Get the parsed operating system type of this triple.
|
2012-02-21 03:39:36 +00:00
|
|
|
OSType getOS() const { return OS; }
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// hasEnvironment - Does this triple have the optional environment
|
|
|
|
/// (fourth) component?
|
|
|
|
bool hasEnvironment() const {
|
|
|
|
return getEnvironmentName() != "";
|
|
|
|
}
|
|
|
|
|
2010-09-16 08:25:48 +00:00
|
|
|
/// getEnvironment - Get the parsed environment type of this triple.
|
2012-02-21 03:39:36 +00:00
|
|
|
EnvironmentType getEnvironment() const { return Environment; }
|
2010-09-16 08:25:48 +00:00
|
|
|
|
2014-03-06 20:47:11 +00:00
|
|
|
/// getFormat - Get the object format for this triple.
|
|
|
|
ObjectFormatType getObjectFormat() const { return ObjectFormat; }
|
|
|
|
|
2012-01-29 23:09:12 +00:00
|
|
|
/// getOSVersion - Parse the version number from the OS name component of the
|
|
|
|
/// triple, if present.
|
|
|
|
///
|
|
|
|
/// For example, "fooos1.2.3" would return (1, 2, 3).
|
|
|
|
///
|
|
|
|
/// If an entry is not defined, it will be returned as 0.
|
|
|
|
void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
|
|
|
|
|
|
|
|
/// getOSMajorVersion - Return just the major version number, this is
|
|
|
|
/// specialized because it is a common query.
|
|
|
|
unsigned getOSMajorVersion() const {
|
|
|
|
unsigned Maj, Min, Micro;
|
|
|
|
getOSVersion(Maj, Min, Micro);
|
|
|
|
return Maj;
|
|
|
|
}
|
|
|
|
|
2012-01-31 22:32:29 +00:00
|
|
|
/// getMacOSXVersion - Parse the version number as with getOSVersion and then
|
|
|
|
/// translate generic "darwin" versions to the corresponding OS X versions.
|
|
|
|
/// This may also be called with IOS triples but the OS X version number is
|
|
|
|
/// just set to a constant 10.4.0 in that case. Returns true if successful.
|
|
|
|
bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
|
|
|
|
unsigned &Micro) const;
|
|
|
|
|
2012-05-09 17:23:48 +00:00
|
|
|
/// getiOSVersion - Parse the version number as with getOSVersion. This should
|
|
|
|
/// only be called with IOS triples.
|
|
|
|
void getiOSVersion(unsigned &Major, unsigned &Minor,
|
|
|
|
unsigned &Micro) const;
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Direct Component Access
|
|
|
|
/// @{
|
|
|
|
|
2009-11-11 00:43:14 +00:00
|
|
|
const std::string &str() const { return Data; }
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
const std::string &getTriple() const { return Data; }
|
|
|
|
|
|
|
|
/// getArchName - Get the architecture (first) component of the
|
|
|
|
/// triple.
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef getArchName() const;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// getVendorName - Get the vendor (second) component of the triple.
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef getVendorName() const;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// getOSName - Get the operating system (third) component of the
|
|
|
|
/// triple.
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef getOSName() const;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// getEnvironmentName - Get the optional environment (fourth)
|
|
|
|
/// component of the triple, or "" if empty.
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef getEnvironmentName() const;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// getOSAndEnvironmentName - Get the operating system and optional
|
|
|
|
/// environment components as a single string (separated by a '-'
|
|
|
|
/// if the environment component is present).
|
2009-07-26 03:31:47 +00:00
|
|
|
StringRef getOSAndEnvironmentName() const;
|
2009-04-01 21:53:23 +00:00
|
|
|
|
2012-01-29 23:09:12 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Convenience Predicates
|
|
|
|
/// @{
|
2010-11-13 04:17:15 +00:00
|
|
|
|
2012-01-31 04:52:32 +00:00
|
|
|
/// \brief Test whether the architecture is 64-bit
|
|
|
|
///
|
|
|
|
/// Note that this tests for 64-bit pointer width, and nothing else. Note
|
|
|
|
/// that we intentionally expose only three predicates, 64-bit, 32-bit, and
|
|
|
|
/// 16-bit. The inner details of pointer width for particular architectures
|
|
|
|
/// is not summed up in the triple, and so only a coarse grained predicate
|
|
|
|
/// system is provided.
|
|
|
|
bool isArch64Bit() const;
|
|
|
|
|
|
|
|
/// \brief Test whether the architecture is 32-bit
|
|
|
|
///
|
|
|
|
/// Note that this tests for 32-bit pointer width, and nothing else.
|
|
|
|
bool isArch32Bit() const;
|
|
|
|
|
|
|
|
/// \brief Test whether the architecture is 16-bit
|
|
|
|
///
|
|
|
|
/// Note that this tests for 16-bit pointer width, and nothing else.
|
|
|
|
bool isArch16Bit() const;
|
|
|
|
|
2011-04-19 21:12:05 +00:00
|
|
|
/// isOSVersionLT - Helper function for doing comparisons against version
|
|
|
|
/// numbers included in the target triple.
|
2011-04-19 20:30:10 +00:00
|
|
|
bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
|
|
|
|
unsigned Micro = 0) const {
|
2011-04-19 20:30:07 +00:00
|
|
|
unsigned LHS[3];
|
|
|
|
getOSVersion(LHS[0], LHS[1], LHS[2]);
|
|
|
|
|
|
|
|
if (LHS[0] != Major)
|
|
|
|
return LHS[0] < Major;
|
|
|
|
if (LHS[1] != Minor)
|
|
|
|
return LHS[1] < Minor;
|
|
|
|
if (LHS[2] != Micro)
|
|
|
|
return LHS[1] < Micro;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-13 00:40:41 +00:00
|
|
|
bool isOSVersionLT(const Triple &Other) const {
|
|
|
|
unsigned RHS[3];
|
|
|
|
Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
|
|
|
|
return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
|
|
|
|
}
|
|
|
|
|
2012-02-05 08:26:40 +00:00
|
|
|
/// isMacOSXVersionLT - Comparison function for checking OS X version
|
|
|
|
/// compatibility, which handles supporting skewed version numbering schemes
|
|
|
|
/// used by the "darwin" triples.
|
|
|
|
unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
|
2012-07-18 23:58:37 +00:00
|
|
|
unsigned Micro = 0) const {
|
2012-02-05 08:26:40 +00:00
|
|
|
assert(isMacOSX() && "Not an OS X triple!");
|
|
|
|
|
|
|
|
// If this is OS X, expect a sane version number.
|
|
|
|
if (getOS() == Triple::MacOSX)
|
|
|
|
return isOSVersionLT(Major, Minor, Micro);
|
|
|
|
|
|
|
|
// Otherwise, compare to the "Darwin" number.
|
|
|
|
assert(Major == 10 && "Unexpected major version");
|
|
|
|
return isOSVersionLT(Minor + 4, Micro, 0);
|
|
|
|
}
|
|
|
|
|
2011-04-20 00:14:25 +00:00
|
|
|
/// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
|
2011-04-19 20:30:10 +00:00
|
|
|
/// "darwin" and "osx" as OS X triples.
|
2011-04-20 00:14:25 +00:00
|
|
|
bool isMacOSX() const {
|
2011-04-19 23:55:20 +00:00
|
|
|
return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
|
2011-04-19 20:30:10 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 22:38:19 +00:00
|
|
|
/// Is this an iOS triple.
|
|
|
|
bool isiOS() const {
|
|
|
|
return getOS() == Triple::IOS;
|
|
|
|
}
|
|
|
|
|
2011-04-19 21:12:05 +00:00
|
|
|
/// isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
|
|
|
|
bool isOSDarwin() const {
|
2013-01-30 22:38:19 +00:00
|
|
|
return isMacOSX() || isiOS();
|
2011-04-19 21:12:05 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 19:12:10 +00:00
|
|
|
bool isOSNetBSD() const {
|
|
|
|
return getOS() == Triple::NetBSD;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isOSOpenBSD() const {
|
|
|
|
return getOS() == Triple::OpenBSD;
|
|
|
|
}
|
|
|
|
|
2014-05-08 13:00:15 +00:00
|
|
|
bool isOSFreeBSD() const {
|
|
|
|
return getOS() == Triple::FreeBSD;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:47:28 +00:00
|
|
|
bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
|
|
|
|
|
2014-11-22 19:12:10 +00:00
|
|
|
bool isOSSolaris() const {
|
|
|
|
return getOS() == Triple::Solaris;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isOSBitrig() const {
|
|
|
|
return getOS() == Triple::Bitrig;
|
|
|
|
}
|
|
|
|
|
2014-03-27 22:50:05 +00:00
|
|
|
bool isWindowsMSVCEnvironment() const {
|
|
|
|
return getOS() == Triple::Win32 &&
|
|
|
|
(getEnvironment() == Triple::UnknownEnvironment ||
|
|
|
|
getEnvironment() == Triple::MSVC);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isKnownWindowsMSVCEnvironment() const {
|
|
|
|
return getOS() == Triple::Win32 && getEnvironment() == Triple::MSVC;
|
|
|
|
}
|
|
|
|
|
2014-06-06 22:46:18 +00:00
|
|
|
bool isWindowsItaniumEnvironment() const {
|
|
|
|
return getOS() == Triple::Win32 && getEnvironment() == Triple::Itanium;
|
|
|
|
}
|
|
|
|
|
2014-03-27 22:50:05 +00:00
|
|
|
bool isWindowsCygwinEnvironment() const {
|
2014-08-09 23:12:20 +00:00
|
|
|
return getOS() == Triple::Win32 && getEnvironment() == Triple::Cygnus;
|
2014-03-27 22:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isWindowsGNUEnvironment() const {
|
2014-08-09 23:12:20 +00:00
|
|
|
return getOS() == Triple::Win32 && getEnvironment() == Triple::GNU;
|
2014-03-27 22:50:05 +00:00
|
|
|
}
|
|
|
|
|
2012-02-05 08:26:40 +00:00
|
|
|
/// \brief Tests for either Cygwin or MinGW OS
|
|
|
|
bool isOSCygMing() const {
|
2014-03-27 22:50:05 +00:00
|
|
|
return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment();
|
2012-02-05 08:26:40 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 21:53:33 +00:00
|
|
|
/// \brief Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
|
|
|
|
bool isOSMSVCRT() const {
|
2014-11-19 21:55:31 +00:00
|
|
|
return isWindowsMSVCEnvironment() || isWindowsGNUEnvironment() ||
|
|
|
|
isWindowsItaniumEnvironment();
|
2013-08-21 21:53:33 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 20:23:14 +00:00
|
|
|
/// \brief Tests whether the OS is Windows.
|
2011-04-19 21:12:05 +00:00
|
|
|
bool isOSWindows() const {
|
2015-02-04 23:17:19 +00:00
|
|
|
return getOS() == Triple::Win32;
|
2011-04-19 21:12:05 +00:00
|
|
|
}
|
|
|
|
|
2012-12-07 00:01:53 +00:00
|
|
|
/// \brief Tests whether the OS is NaCl (Native Client)
|
|
|
|
bool isOSNaCl() const {
|
|
|
|
return getOS() == Triple::NaCl;
|
|
|
|
}
|
|
|
|
|
2013-08-29 20:23:14 +00:00
|
|
|
/// \brief Tests whether the OS is Linux.
|
|
|
|
bool isOSLinux() const {
|
|
|
|
return getOS() == Triple::Linux;
|
|
|
|
}
|
|
|
|
|
2012-02-05 08:26:40 +00:00
|
|
|
/// \brief Tests whether the OS uses the ELF binary format.
|
|
|
|
bool isOSBinFormatELF() const {
|
2014-03-06 20:47:11 +00:00
|
|
|
return getObjectFormat() == Triple::ELF;
|
2012-02-05 08:26:40 +00:00
|
|
|
}
|
2011-04-19 20:30:10 +00:00
|
|
|
|
2012-02-05 08:26:40 +00:00
|
|
|
/// \brief Tests whether the OS uses the COFF binary format.
|
|
|
|
bool isOSBinFormatCOFF() const {
|
2014-03-06 20:47:11 +00:00
|
|
|
return getObjectFormat() == Triple::COFF;
|
2012-02-05 08:26:40 +00:00
|
|
|
}
|
2011-04-19 20:30:10 +00:00
|
|
|
|
2012-02-05 08:26:40 +00:00
|
|
|
/// \brief Tests whether the environment is MachO.
|
2013-12-10 16:57:43 +00:00
|
|
|
bool isOSBinFormatMachO() const {
|
2014-03-06 20:47:11 +00:00
|
|
|
return getObjectFormat() == Triple::MachO;
|
2011-04-19 20:30:10 +00:00
|
|
|
}
|
2011-07-02 00:19:55 +00:00
|
|
|
|
2015-01-25 22:46:59 +00:00
|
|
|
/// \brief Tests whether the target is the PS4 CPU
|
|
|
|
bool isPS4CPU() const {
|
|
|
|
return getArch() == Triple::x86_64 &&
|
|
|
|
getVendor() == Triple::SCEI &&
|
|
|
|
getOS() == Triple::PS4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Tests whether the target is the PS4 platform
|
|
|
|
bool isPS4() const {
|
|
|
|
return getVendor() == Triple::SCEI &&
|
|
|
|
getOS() == Triple::PS4;
|
|
|
|
}
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Mutators
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// setArch - Set the architecture (first) component of the triple
|
|
|
|
/// to a known type.
|
|
|
|
void setArch(ArchType Kind);
|
|
|
|
|
|
|
|
/// setVendor - Set the vendor (second) component of the triple to a
|
|
|
|
/// known type.
|
|
|
|
void setVendor(VendorType Kind);
|
|
|
|
|
|
|
|
/// setOS - Set the operating system (third) component of the triple
|
|
|
|
/// to a known type.
|
|
|
|
void setOS(OSType Kind);
|
|
|
|
|
2010-09-16 08:25:48 +00:00
|
|
|
/// setEnvironment - Set the environment (fourth) component of the triple
|
|
|
|
/// to a known type.
|
|
|
|
void setEnvironment(EnvironmentType Kind);
|
|
|
|
|
2014-03-06 20:47:11 +00:00
|
|
|
/// setObjectFormat - Set the object file format
|
|
|
|
void setObjectFormat(ObjectFormatType Kind);
|
|
|
|
|
2012-09-13 12:34:29 +00:00
|
|
|
/// setTriple - Set all components to the new triple \p Str.
|
2009-07-26 03:31:47 +00:00
|
|
|
void setTriple(const Twine &Str);
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// setArchName - Set the architecture (first) component of the
|
|
|
|
/// triple by name.
|
2009-11-06 10:58:06 +00:00
|
|
|
void setArchName(StringRef Str);
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// setVendorName - Set the vendor (second) component of the triple
|
|
|
|
/// by name.
|
2009-11-06 10:58:06 +00:00
|
|
|
void setVendorName(StringRef Str);
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// setOSName - Set the operating system (third) component of the
|
|
|
|
/// triple by name.
|
2009-11-06 10:58:06 +00:00
|
|
|
void setOSName(StringRef Str);
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// setEnvironmentName - Set the optional environment (fourth)
|
|
|
|
/// component of the triple by name.
|
2009-11-06 10:58:06 +00:00
|
|
|
void setEnvironmentName(StringRef Str);
|
2009-04-01 21:53:23 +00:00
|
|
|
|
|
|
|
/// setOSAndEnvironmentName - Set the operating system and optional
|
|
|
|
/// environment components with a single string.
|
2009-11-06 10:58:06 +00:00
|
|
|
void setOSAndEnvironmentName(StringRef Str);
|
2009-04-01 21:53:23 +00:00
|
|
|
|
2012-02-06 20:46:33 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Helpers to build variants of a particular triple.
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// \brief Form a triple with a 32-bit variant of the current architecture.
|
|
|
|
///
|
|
|
|
/// This can be used to move across "families" of architectures where useful.
|
|
|
|
///
|
|
|
|
/// \returns A new triple with a 32-bit architecture or an unknown
|
|
|
|
/// architecture if no such variant can be found.
|
|
|
|
llvm::Triple get32BitArchVariant() const;
|
|
|
|
|
|
|
|
/// \brief Form a triple with a 64-bit variant of the current architecture.
|
|
|
|
///
|
|
|
|
/// This can be used to move across "families" of architectures where useful.
|
|
|
|
///
|
|
|
|
/// \returns A new triple with a 64-bit architecture or an unknown
|
|
|
|
/// architecture if no such variant can be found.
|
|
|
|
llvm::Triple get64BitArchVariant() const;
|
|
|
|
|
2014-07-11 21:44:54 +00:00
|
|
|
/// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
|
|
|
|
///
|
|
|
|
/// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
|
|
|
|
/// string then the triple's arch name is used.
|
|
|
|
const char* getARMCPUForArch(StringRef Arch = StringRef()) const;
|
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Static helpers for IDs.
|
|
|
|
/// @{
|
|
|
|
|
2012-09-13 12:34:29 +00:00
|
|
|
/// getArchTypeName - Get the canonical name for the \p Kind architecture.
|
2009-04-01 21:53:23 +00:00
|
|
|
static const char *getArchTypeName(ArchType Kind);
|
|
|
|
|
2012-09-13 12:34:29 +00:00
|
|
|
/// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
|
2009-08-24 09:53:06 +00:00
|
|
|
/// architecture. This is the prefix used by the architecture specific
|
|
|
|
/// builtins, and is suitable for passing to \see
|
|
|
|
/// Intrinsic::getIntrinsicForGCCBuiltin().
|
|
|
|
///
|
|
|
|
/// \return - The architecture prefix, or 0 if none is defined.
|
|
|
|
static const char *getArchTypePrefix(ArchType Kind);
|
|
|
|
|
2012-09-13 12:34:29 +00:00
|
|
|
/// getVendorTypeName - Get the canonical name for the \p Kind vendor.
|
2009-04-01 21:53:23 +00:00
|
|
|
static const char *getVendorTypeName(VendorType Kind);
|
|
|
|
|
2012-09-13 12:34:29 +00:00
|
|
|
/// getOSTypeName - Get the canonical name for the \p Kind operating system.
|
2009-04-01 21:53:23 +00:00
|
|
|
static const char *getOSTypeName(OSType Kind);
|
|
|
|
|
2012-09-13 12:34:29 +00:00
|
|
|
/// getEnvironmentTypeName - Get the canonical name for the \p Kind
|
2010-09-16 08:25:48 +00:00
|
|
|
/// environment.
|
|
|
|
static const char *getEnvironmentTypeName(EnvironmentType Kind);
|
|
|
|
|
2009-09-08 23:32:51 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Static helpers for converting alternate architecture names.
|
|
|
|
/// @{
|
|
|
|
|
2009-08-03 04:03:51 +00:00
|
|
|
/// getArchTypeForLLVMName - The canonical type for the given LLVM
|
|
|
|
/// architecture name (e.g., "x86").
|
2009-11-06 10:58:06 +00:00
|
|
|
static ArchType getArchTypeForLLVMName(StringRef Str);
|
2009-08-03 04:03:51 +00:00
|
|
|
|
2009-04-01 21:53:23 +00:00
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|