r188258 - Add XCore target

Evgeniy Stepanov eugeni.stepanov at gmail.com
Tue Aug 13 06:16:17 PDT 2013


> %ap
Please don't use named (as well as numbered) identifiers in lit tests.
They are fragile and can be stripped in optimized builds.


On Tue, Aug 13, 2013 at 1:43 PM, Robert Lytton <robert at xmos.com> wrote:
> Author: rlytton
> Date: Tue Aug 13 04:43:10 2013
> New Revision: 188258
>
> URL: http://llvm.org/viewvc/llvm-project?rev=188258&view=rev
> Log:
> Add XCore target
>
> Added:
>     cfe/trunk/include/clang/Basic/BuiltinsXCore.def
>     cfe/trunk/test/CodeGen/xcore-abi.c
>     cfe/trunk/test/Driver/xcore-opts.c
> Modified:
>     cfe/trunk/include/clang/Basic/TargetBuiltins.h
>     cfe/trunk/lib/Basic/Targets.cpp
>     cfe/trunk/lib/CodeGen/TargetInfo.cpp
>     cfe/trunk/lib/Driver/Tools.cpp
>     cfe/trunk/test/Preprocessor/init.c
>     cfe/trunk/test/Preprocessor/stdint.c
>
> Added: cfe/trunk/include/clang/Basic/BuiltinsXCore.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsXCore.def?rev=188258&view=auto
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/BuiltinsXCore.def (added)
> +++ cfe/trunk/include/clang/Basic/BuiltinsXCore.def Tue Aug 13 04:43:10 2013
> @@ -0,0 +1,22 @@
> +//===--- BuiltinsXCore.def - XCore Builtin function database ----*- C++ -*-===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file defines the XCore-specific builtin function database.  Users of
> +// this file must define the BUILTIN macro to make use of this information.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +// The format of this database matches clang/Basic/Builtins.def.
> +
> +BUILTIN(__builtin_bitrev, "UiUi", "nc")
> +BUILTIN(__builtin_getid, "Si", "nc")
> +BUILTIN(__builtin_getps, "UiUi", "n")
> +BUILTIN(__builtin_setps, "vUiUi", "n")
> +
> +#undef BUILTIN
>
> Modified: cfe/trunk/include/clang/Basic/TargetBuiltins.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetBuiltins.h?rev=188258&r1=188257&r2=188258&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/TargetBuiltins.h (original)
> +++ cfe/trunk/include/clang/Basic/TargetBuiltins.h Tue Aug 13 04:43:10 2013
> @@ -131,6 +131,16 @@ namespace clang {
>          LastTSBuiltin
>      };
>    }
> +
> +  /// \brief XCore builtins
> +  namespace XCore {
> +    enum {
> +        LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
> +#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
> +#include "clang/Basic/BuiltinsXCore.def"
> +        LastTSBuiltin
> +    };
> +  }
>  } // end namespace clang.
>
>  #endif
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=188258&r1=188257&r2=188258&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Tue Aug 13 04:43:10 2013
> @@ -5138,6 +5138,64 @@ namespace {
>    };
>  }
>
> +namespace {
> +class XCoreTargetInfo : public TargetInfo {
> +  static const Builtin::Info BuiltinInfo[];
> +public:
> +  XCoreTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
> +    BigEndian = false;
> +    NoAsmVariants = true;
> +    LongLongAlign = 32;
> +    SuitableAlign = 32;
> +    DoubleAlign = LongDoubleAlign = 32;
> +    UseZeroLengthBitfieldAlignment = true;
> +    DescriptionString = "e-p:32:32:32-a0:0:32-n32"
> +                        "-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32"
> +                        "-f16:16:32-f32:32:32-f64:32:32";
> +  }
> +  virtual void getTargetDefines(const LangOptions &Opts,
> +                                MacroBuilder &Builder) const {
> +    Builder.defineMacro("__XS1B__");
> +  }
> +  virtual void getTargetBuiltins(const Builtin::Info *&Records,
> +                                 unsigned &NumRecords) const {
> +    Records = BuiltinInfo;
> +    NumRecords = clang::XCore::LastTSBuiltin-Builtin::FirstTSBuiltin;
> +  }
> +  virtual BuiltinVaListKind getBuiltinVaListKind() const {
> +    return TargetInfo::VoidPtrBuiltinVaList;
> +  }
> +  virtual const char *getClobbers() const {
> +    return "";
> +  }
> +  virtual void getGCCRegNames(const char * const *&Names,
> +                              unsigned &NumNames) const {
> +    static const char * const GCCRegNames[] = {
> +      "r0",   "r1",   "r2",   "r3",   "r4",   "r5",   "r6",   "r7",
> +      "r8",   "r9",   "r10",  "r11",  "cp",   "dp",   "sp",   "lr"
> +    };
> +    Names = GCCRegNames;
> +    NumNames = llvm::array_lengthof(GCCRegNames);
> +  }
> +  virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
> +                                unsigned &NumAliases) const {
> +    Aliases = NULL;
> +    NumAliases = 0;
> +  }
> +  virtual bool validateAsmConstraint(const char *&Name,
> +                                     TargetInfo::ConstraintInfo &Info) const {
> +    return false;
> +  }
> +};
> +
> +const Builtin::Info XCoreTargetInfo::BuiltinInfo[] = {
> +#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
> +#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
> +                                              ALL_LANGUAGES },
> +#include "clang/Basic/BuiltinsXCore.def"
> +};
> +} // end anonymous namespace.
> +
>
>  //===----------------------------------------------------------------------===//
>  // Driver code
> @@ -5150,6 +5208,9 @@ static TargetInfo *AllocateTarget(const
>    default:
>      return NULL;
>
> +  case llvm::Triple::xcore:
> +    return new XCoreTargetInfo(Triple);
> +
>    case llvm::Triple::hexagon:
>      return new HexagonTargetInfo(Triple);
>
>
> Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=188258&r1=188257&r2=188258&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue Aug 13 04:43:10 2013
> @@ -5366,6 +5366,22 @@ public:
>  } // end anonymous namespace
>
>
> +//===----------------------------------------------------------------------===//
> +// Xcore ABI Implementation
> +//===----------------------------------------------------------------------===//
> +namespace {
> +class XcoreTargetCodeGenInfo : public TargetCodeGenInfo {
> +public:
> +  XcoreTargetCodeGenInfo(CodeGenTypes &CGT)
> +    :TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
> +};
> +} // end anonymous namespace
> +
> +
> +//===----------------------------------------------------------------------===//
> +// Driver code
> +//===----------------------------------------------------------------------===//
> +
>  const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
>    if (TheTargetCodeGenInfo)
>      return *TheTargetCodeGenInfo;
> @@ -5474,5 +5490,8 @@ const TargetCodeGenInfo &CodeGenModule::
>      return *(TheTargetCodeGenInfo = new HexagonTargetCodeGenInfo(Types));
>    case llvm::Triple::sparcv9:
>      return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
> +  case llvm::Triple::xcore:
> +    return *(TheTargetCodeGenInfo = new XcoreTargetCodeGenInfo(Types));
> +
>    }
>  }
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=188258&r1=188257&r2=188258&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Tue Aug 13 04:43:10 2013
> @@ -552,10 +552,21 @@ static bool isSignedCharDefault(const ll
>
>    case llvm::Triple::ppc64le:
>    case llvm::Triple::systemz:
> +  case llvm::Triple::xcore:
>      return false;
>    }
>  }
>
> +static bool isNoCommonDefault(const llvm::Triple &Triple) {
> +  switch (Triple.getArch()) {
> +  default:
> +    return false;
> +
> +  case llvm::Triple::xcore:
> +    return true;
> +  }
> +}
> +
>  // Handle -mfpu=.
>  //
>  // FIXME: Centralize feature selection, defaulting shouldn't be also in the
> @@ -1761,6 +1772,9 @@ static bool shouldUseFramePointer(const
>          return false;
>    }
>
> +  if (Triple.getArch() == llvm::Triple::xcore)
> +    return false;
> +
>    return true;
>  }
>
> @@ -1780,6 +1794,9 @@ static bool shouldUseLeafFramePointer(co
>          return false;
>    }
>
> +  if (Triple.getArch() == llvm::Triple::xcore)
> +    return false;
> +
>    return true;
>  }
>
> @@ -3200,7 +3217,7 @@ void Clang::ConstructJob(Compilation &C,
>      CmdArgs.push_back("-fpack-struct=1");
>    }
>
> -  if (KernelOrKext) {
> +  if (KernelOrKext || isNoCommonDefault(getToolChain().getTriple())) {
>      if (!Args.hasArg(options::OPT_fcommon))
>        CmdArgs.push_back("-fno-common");
>      Args.ClaimAllArgs(options::OPT_fno_common);
>
> Added: cfe/trunk/test/CodeGen/xcore-abi.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/xcore-abi.c?rev=188258&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/xcore-abi.c (added)
> +++ cfe/trunk/test/CodeGen/xcore-abi.c Tue Aug 13 04:43:10 2013
> @@ -0,0 +1,35 @@
> +// RUN: %clang -target xcore -O1 -o - -emit-llvm -S %s | FileCheck %s
> +
> +// CHECK: target datalayout = "e-p:32:32:32-a0:0:32-n32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f16:16:32-f32:32:32-f64:32:32"
> +// CHECK: target triple = "xcore"
> +
> +#include <stdarg.h>
> +struct x { int a; };
> +void testva (int n, ...) {
> +  va_list ap;
> +  // CHECK: %ap = alloca i8*, align 4
> +
> +  char* v1 = va_arg (ap, char*);
> +  // CHECK: %0 = va_arg i8** %ap, i8*
> +
> +  int v2 = va_arg (ap, int);
> +  // CHECK: %1 = va_arg i8** %ap, i32
> +
> +  long long int v3 = va_arg (ap, long long int);
> +  // CHECK: %2 = va_arg i8** %ap, i64
> +
> +  //struct x t = va_arg (ap, struct x);
> +  //cannot compile aggregate va_arg expressions yet
> +}
> +
> +void testbuiltin (void) {
> +// CHECK: %0 = tail call i32 @llvm.xcore.getid()
> +// CHECK: %1 = tail call i32 @llvm.xcore.getps(i32 %0)
> +// CHECK: %2 = tail call i32 @llvm.xcore.bitrev(i32 %1)
> +// CHECK: tail call void @llvm.xcore.setps(i32 %0, i32 %2)
> +  int i = __builtin_getid();
> +  unsigned int ui = __builtin_getps(i);
> +  ui = __builtin_bitrev(ui);
> +  __builtin_setps(i,ui);
> +
> +}
>
> Added: cfe/trunk/test/Driver/xcore-opts.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/xcore-opts.c?rev=188258&view=auto
> ==============================================================================
> --- cfe/trunk/test/Driver/xcore-opts.c (added)
> +++ cfe/trunk/test/Driver/xcore-opts.c Tue Aug 13 04:43:10 2013
> @@ -0,0 +1,15 @@
> +// RUN: %clang -target xcore -O1 -o - -emit-llvm -S %s | FileCheck %s
> +
> +// CHECK: @g1 = global
> +int g1;
> +// CHECK: @g2 = common global i32 0, align 4
> +int g2 __attribute__((common));
> +
> +// CHECK: define zeroext i8 @testchar()
> +// CHECK: ret i8 -1
> +char testchar (void) {
> +  return (char)-1;
> +}
> +
> +// CHECK: "no-frame-pointer-elim"="false"
> +// CHECK: "no-frame-pointer-elim-non-leaf"="false"
>
> Modified: cfe/trunk/test/Preprocessor/init.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=188258&r1=188257&r2=188258&view=diff
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/init.c (original)
> +++ cfe/trunk/test/Preprocessor/init.c Tue Aug 13 04:43:10 2013
> @@ -2946,3 +2946,6 @@
>  // ANDROID: __ANDROID__ 1
>  // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd < /dev/null | FileCheck -check-prefix PPC64-FREEBSD %s
>  // PPC64-FREEBSD-NOT: #define __LONG_DOUBLE_128__ 1
> +//
> +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=xcore-none-none < /dev/null | FileCheck -check-prefix XCORE %s
> +// XCORE:#define __XS1B__ 1
>
> Modified: cfe/trunk/test/Preprocessor/stdint.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/stdint.c?rev=188258&r1=188257&r2=188258&view=diff
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/stdint.c (original)
> +++ cfe/trunk/test/Preprocessor/stdint.c Tue Aug 13 04:43:10 2013
> @@ -963,6 +963,114 @@
>  // I386_MINGW32:WCHAR_MIN_ 0U
>  //
>  //
> +// RUN: %clang_cc1 -E -ffreestanding -triple=xcore-none-none %s | FileCheck -check-prefix XCORE %s
> +//
> +// XCORE:typedef signed long long int int64_t;
> +// XCORE:typedef unsigned long long int uint64_t;
> +// XCORE:typedef int64_t int_least64_t;
> +// XCORE:typedef uint64_t uint_least64_t;
> +// XCORE:typedef int64_t int_fast64_t;
> +// XCORE:typedef uint64_t uint_fast64_t;
> +//
> +// XCORE:typedef signed int int32_t;
> +// XCORE:typedef unsigned int uint32_t;
> +// XCORE:typedef int32_t int_least32_t;
> +// XCORE:typedef uint32_t uint_least32_t;
> +// XCORE:typedef int32_t int_fast32_t;
> +// XCORE:typedef uint32_t uint_fast32_t;
> +//
> +// XCORE:typedef signed short int16_t;
> +// XCORE:typedef unsigned short uint16_t;
> +// XCORE:typedef int16_t int_least16_t;
> +// XCORE:typedef uint16_t uint_least16_t;
> +// XCORE:typedef int16_t int_fast16_t;
> +// XCORE:typedef uint16_t uint_fast16_t;
> +//
> +// XCORE:typedef signed char int8_t;
> +// XCORE:typedef unsigned char uint8_t;
> +// XCORE:typedef int8_t int_least8_t;
> +// XCORE:typedef uint8_t uint_least8_t;
> +// XCORE:typedef int8_t int_fast8_t;
> +// XCORE:typedef uint8_t uint_fast8_t;
> +//
> +// XCORE:typedef int32_t intptr_t;
> +// XCORE:typedef uint32_t uintptr_t;
> +//
> +// XCORE:typedef long long int intmax_t;
> +// XCORE:typedef long long unsigned int uintmax_t;
> +//
> +// XCORE:INT8_MAX_ 127
> +// XCORE:INT8_MIN_ (-127 -1)
> +// XCORE:UINT8_MAX_ 255
> +// XCORE:INT_LEAST8_MIN_ (-127 -1)
> +// XCORE:INT_LEAST8_MAX_ 127
> +// XCORE:UINT_LEAST8_MAX_ 255
> +// XCORE:INT_FAST8_MIN_ (-127 -1)
> +// XCORE:INT_FAST8_MAX_ 127
> +// XCORE:UINT_FAST8_MAX_ 255
> +//
> +// XCORE:INT16_MAX_ 32767
> +// XCORE:INT16_MIN_ (-32767 -1)
> +// XCORE:UINT16_MAX_ 65535
> +// XCORE:INT_LEAST16_MIN_ (-32767 -1)
> +// XCORE:INT_LEAST16_MAX_ 32767
> +// XCORE:UINT_LEAST16_MAX_ 65535
> +// XCORE:INT_FAST16_MIN_ (-32767 -1)
> +// XCORE:INT_FAST16_MAX_ 32767
> +// XCORE:UINT_FAST16_MAX_ 65535
> +//
> +// XCORE:INT32_MAX_ 2147483647
> +// XCORE:INT32_MIN_ (-2147483647 -1)
> +// XCORE:UINT32_MAX_ 4294967295U
> +// XCORE:INT_LEAST32_MIN_ (-2147483647 -1)
> +// XCORE:INT_LEAST32_MAX_ 2147483647
> +// XCORE:UINT_LEAST32_MAX_ 4294967295U
> +// XCORE:INT_FAST32_MIN_ (-2147483647 -1)
> +// XCORE:INT_FAST32_MAX_ 2147483647
> +// XCORE:UINT_FAST32_MAX_ 4294967295U
> +//
> +// XCORE:INT64_MAX_ 9223372036854775807LL
> +// XCORE:INT64_MIN_ (-9223372036854775807LL -1)
> +// XCORE:UINT64_MAX_ 18446744073709551615ULL
> +// XCORE:INT_LEAST64_MIN_ (-9223372036854775807LL -1)
> +// XCORE:INT_LEAST64_MAX_ 9223372036854775807LL
> +// XCORE:UINT_LEAST64_MAX_ 18446744073709551615ULL
> +// XCORE:INT_FAST64_MIN_ (-9223372036854775807LL -1)
> +// XCORE:INT_FAST64_MAX_ 9223372036854775807LL
> +// XCORE:UINT_FAST64_MAX_ 18446744073709551615ULL
> +//
> +// XCORE:INTPTR_MIN_ (-2147483647 -1)
> +// XCORE:INTPTR_MAX_ 2147483647
> +// XCORE:UINTPTR_MAX_ 4294967295U
> +// XCORE:PTRDIFF_MIN_ (-2147483647 -1)
> +// XCORE:PTRDIFF_MAX_ 2147483647
> +// XCORE:SIZE_MAX_ 4294967295U
> +//
> +// XCORE:INTMAX_MIN_ (-9223372036854775807LL -1)
> +// XCORE:INTMAX_MAX_ 9223372036854775807LL
> +// XCORE:UINTMAX_MAX_ 18446744073709551615ULL
> +//
> +// XCORE:SIG_ATOMIC_MIN_ (-2147483647 -1)
> +// XCORE:SIG_ATOMIC_MAX_ 2147483647
> +// XCORE:WINT_MIN_ (-2147483647 -1)
> +// XCORE:WINT_MAX_ 2147483647
> +//
> +// XCORE:WCHAR_MAX_ 2147483647
> +// XCORE:WCHAR_MIN_ (-2147483647 -1)
> +//
> +// XCORE:INT8_C_(0) 0
> +// XCORE:UINT8_C_(0) 0U
> +// XCORE:INT16_C_(0) 0
> +// XCORE:UINT16_C_(0) 0U
> +// XCORE:INT32_C_(0) 0
> +// XCORE:UINT32_C_(0) 0U
> +// XCORE:INT64_C_(0) 0LL
> +// XCORE:UINT64_C_(0) 0ULL
> +//
> +// XCORE:INTMAX_C_(0) 0LL
> +// XCORE:UINTMAX_C_(0) 0ULL
> +//
> +//
>  // stdint.h forms several macro definitions by pasting together identifiers
>  // to form names (eg. int32_t is formed from int ## 32 ## _t). The following
>  // case tests that these joining operations are performed correctly even if
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list