This revision was automatically updated to reflect the committed changes. Closed by commit rL291082: Add AVR target and toolchain to Clang (authored by dylanmckay).
Changed prior to commit: https://reviews.llvm.org/D27123?vs=80721&id=83191#toc Repository: rL LLVM https://reviews.llvm.org/D27123 Files: cfe/trunk/lib/Basic/Targets.cpp cfe/trunk/lib/Driver/Driver.cpp cfe/trunk/lib/Driver/ToolChains.cpp cfe/trunk/lib/Driver/ToolChains.h cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/lib/Driver/Tools.h cfe/trunk/test/Driver/avr-toolchain.c cfe/trunk/test/Preprocessor/init.c
Index: cfe/trunk/lib/Driver/ToolChains.h =================================================================== --- cfe/trunk/lib/Driver/ToolChains.h +++ cfe/trunk/lib/Driver/ToolChains.h @@ -1349,6 +1349,16 @@ SanitizerMask getSupportedSanitizers() const override; }; +class LLVM_LIBRARY_VISIBILITY AVRToolChain : public Generic_ELF { +protected: + Tool *buildLinker() const override; +public: + AVRToolChain(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args); + bool IsIntegratedAssemblerDefault() const override { return true; } +}; + + } // end namespace toolchains } // end namespace driver } // end namespace clang Index: cfe/trunk/lib/Driver/Tools.h =================================================================== --- cfe/trunk/lib/Driver/Tools.h +++ cfe/trunk/lib/Driver/Tools.h @@ -990,6 +990,19 @@ } // end namespace NVPTX +namespace AVR { +class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool { +public: + Linker(const ToolChain &TC) : GnuTool("AVR::Linker", "avr-ld", TC) {} + bool hasIntegratedCPP() const override { return false; } + bool isLinkJob() const override { return true; } + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; +}; +} // end namespace AVR + } // end namespace tools } // end namespace driver } // end namespace clang Index: cfe/trunk/lib/Driver/ToolChains.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains.cpp +++ cfe/trunk/lib/Driver/ToolChains.cpp @@ -5318,3 +5318,12 @@ Res |= SanitizerKind::SafeStack; return Res; } + +/// AVR Toolchain +AVRToolChain::AVRToolChain(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args) + : Generic_ELF(D, Triple, Args) { } +Tool *AVRToolChain::buildLinker() const { + return new tools::AVR::Linker(*this); +} +// End AVR Index: cfe/trunk/lib/Driver/Tools.cpp =================================================================== --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -12191,3 +12191,19 @@ const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary")); C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); } + +void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + + std::string Linker = getToolChain().GetProgramPath(getShortName()); + ArgStringList CmdArgs; + AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), + CmdArgs, Inputs)); +} +// AVR tools end. Index: cfe/trunk/lib/Driver/Driver.cpp =================================================================== --- cfe/trunk/lib/Driver/Driver.cpp +++ cfe/trunk/lib/Driver/Driver.cpp @@ -3764,6 +3764,9 @@ case llvm::Triple::wasm64: TC = new toolchains::WebAssembly(*this, Target, Args); break; + case llvm::Triple::avr: + TC = new toolchains::AVRToolChain(*this, Target, Args); + break; default: if (Target.getVendor() == llvm::Triple::Myriad) TC = new toolchains::MyriadToolChain(*this, Target, Args); Index: cfe/trunk/lib/Basic/Targets.cpp =================================================================== --- cfe/trunk/lib/Basic/Targets.cpp +++ cfe/trunk/lib/Basic/Targets.cpp @@ -8385,6 +8385,97 @@ } }; + +// AVR Target +class AVRTargetInfo : public TargetInfo { +public: + AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &) + : TargetInfo(Triple) { + TLSSupported = false; + PointerWidth = 16; + PointerAlign = 8; + IntWidth = 16; + IntAlign = 8; + LongWidth = 32; + LongAlign = 8; + LongLongWidth = 64; + LongLongAlign = 8; + SuitableAlign = 8; + DefaultAlignForAttributeAligned = 8; + HalfWidth = 16; + HalfAlign = 8; + FloatWidth = 32; + FloatAlign = 8; + DoubleWidth = 32; + DoubleAlign = 8; + DoubleFormat = &llvm::APFloat::IEEEsingle(); + LongDoubleWidth = 32; + LongDoubleAlign = 8; + LongDoubleFormat = &llvm::APFloat::IEEEsingle(); + SizeType = UnsignedInt; + PtrDiffType = SignedInt; + IntPtrType = SignedInt; + Char16Type = UnsignedInt; + WCharType = SignedInt; + WIntType = SignedInt; + Char32Type = UnsignedLong; + SigAtomicType = SignedChar; + resetDataLayout("e-p:16:16:16-i8:8:8-i16:16:16-i32:32:32-i64:64:64" + "-f32:32:32-f64:64:64-n8"); + } + void getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const override { + Builder.defineMacro("__AVR__"); + } + ArrayRef<Builtin::Info> getTargetBuiltins() const override { + return None; + } + BuiltinVaListKind getBuiltinVaListKind() const override { + return TargetInfo::VoidPtrBuiltinVaList; + } + const char *getClobbers() const override { + return ""; + } + ArrayRef<const char *> getGCCRegNames() const override { + static const char * const GCCRegNames[] = { + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "X", "Y", "Z", "SP" + }; + return llvm::makeArrayRef(GCCRegNames); + } + ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override { + return None; + } + ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override { + static const TargetInfo::AddlRegName AddlRegNames[] = { + { { "r26", "r27"}, 26 }, + { { "r28", "r29"}, 27 }, + { { "r30", "r31"}, 28 }, + { { "SPL", "SPH"}, 29 }, + }; + return llvm::makeArrayRef(AddlRegNames); + } + bool validateAsmConstraint(const char *&Name, + TargetInfo::ConstraintInfo &Info) const override { + return false; + } + IntType getIntTypeByWidth(unsigned BitWidth, + bool IsSigned) const final { + // AVR prefers int for 16-bit integers. + return BitWidth == 16 ? (IsSigned ? SignedInt : UnsignedInt) + : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned); + } + IntType getLeastIntTypeByWidth(unsigned BitWidth, + bool IsSigned) const final { + // AVR uses int for int_least16_t and int_fast16_t. + return BitWidth == 16 + ? (IsSigned ? SignedInt : UnsignedInt) + : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned); + } +}; + } // end anonymous namespace //===----------------------------------------------------------------------===// @@ -8507,6 +8598,8 @@ return new ARMbeTargetInfo(Triple, Opts); } + case llvm::Triple::avr: + return new AVRTargetInfo(Triple, Opts); case llvm::Triple::bpfeb: case llvm::Triple::bpfel: return new BPFTargetInfo(Triple, Opts); Index: cfe/trunk/test/Preprocessor/init.c =================================================================== --- cfe/trunk/test/Preprocessor/init.c +++ cfe/trunk/test/Preprocessor/init.c @@ -9189,3 +9189,174 @@ // RUN: %clang_cc1 -E -dM -ffreestanding -triple x86_64-windows-cygnus < /dev/null | FileCheck -match-full-lines -check-prefix CYGWIN-X64 %s // CYGWIN-X64: #define __USER_LABEL_PREFIX__ +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=avr \ +// RUN: < /dev/null \ +// RUN: | FileCheck -match-full-lines -check-prefix=AVR %s +// +// AVR:#define __ATOMIC_ACQUIRE 2 +// AVR:#define __ATOMIC_ACQ_REL 4 +// AVR:#define __ATOMIC_CONSUME 1 +// AVR:#define __ATOMIC_RELAXED 0 +// AVR:#define __ATOMIC_RELEASE 3 +// AVR:#define __ATOMIC_SEQ_CST 5 +// AVR:#define __AVR__ 1 +// AVR:#define __BIGGEST_ALIGNMENT__ 1 +// AVR:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +// AVR:#define __CHAR16_TYPE__ unsigned int +// AVR:#define __CHAR32_TYPE__ long unsigned int +// AVR:#define __CHAR_BIT__ 8 +// AVR:#define __DBL_DECIMAL_DIG__ 9 +// AVR:#define __DBL_DENORM_MIN__ 1.40129846e-45 +// AVR:#define __DBL_DIG__ 6 +// AVR:#define __DBL_EPSILON__ 1.19209290e-7 +// AVR:#define __DBL_HAS_DENORM__ 1 +// AVR:#define __DBL_HAS_INFINITY__ 1 +// AVR:#define __DBL_HAS_QUIET_NAN__ 1 +// AVR:#define __DBL_MANT_DIG__ 24 +// AVR:#define __DBL_MAX_10_EXP__ 38 +// AVR:#define __DBL_MAX_EXP__ 128 +// AVR:#define __DBL_MAX__ 3.40282347e+38 +// AVR:#define __DBL_MIN_10_EXP__ (-37) +// AVR:#define __DBL_MIN_EXP__ (-125) +// AVR:#define __DBL_MIN__ 1.17549435e-38 +// AVR:#define __FINITE_MATH_ONLY__ 0 +// AVR:#define __FLT_DECIMAL_DIG__ 9 +// AVR:#define __FLT_DENORM_MIN__ 1.40129846e-45F +// AVR:#define __FLT_DIG__ 6 +// AVR:#define __FLT_EPSILON__ 1.19209290e-7F +// AVR:#define __FLT_EVAL_METHOD__ 0 +// AVR:#define __FLT_HAS_DENORM__ 1 +// AVR:#define __FLT_HAS_INFINITY__ 1 +// AVR:#define __FLT_HAS_QUIET_NAN__ 1 +// AVR:#define __FLT_MANT_DIG__ 24 +// AVR:#define __FLT_MAX_10_EXP__ 38 +// AVR:#define __FLT_MAX_EXP__ 128 +// AVR:#define __FLT_MAX__ 3.40282347e+38F +// AVR:#define __FLT_MIN_10_EXP__ (-37) +// AVR:#define __FLT_MIN_EXP__ (-125) +// AVR:#define __FLT_MIN__ 1.17549435e-38F +// AVR:#define __FLT_RADIX__ 2 +// AVR:#define __GCC_ATOMIC_BOOL_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_CHAR_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_INT_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_LONG_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_POINTER_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_SHORT_LOCK_FREE 1 +// AVR:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +// AVR:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 1 +// AVR:#define __GXX_ABI_VERSION 1002 +// AVR:#define __INT16_C_SUFFIX__ +// AVR:#define __INT16_MAX__ 32767 +// AVR:#define __INT16_TYPE__ short +// AVR:#define __INT32_C_SUFFIX__ L +// AVR:#define __INT32_MAX__ 2147483647L +// AVR:#define __INT32_TYPE__ long int +// AVR:#define __INT64_C_SUFFIX__ LL +// AVR:#define __INT64_MAX__ 9223372036854775807LL +// AVR:#define __INT64_TYPE__ long long int +// AVR:#define __INT8_C_SUFFIX__ +// AVR:#define __INT8_MAX__ 127 +// AVR:#define __INT8_TYPE__ signed char +// AVR:#define __INTMAX_C_SUFFIX__ LL +// AVR:#define __INTMAX_MAX__ 9223372036854775807LL +// AVR:#define __INTMAX_TYPE__ long long int +// AVR:#define __INTPTR_MAX__ 32767 +// AVR:#define __INTPTR_TYPE__ int +// AVR:#define __INT_FAST16_MAX__ 32767 +// AVR:#define __INT_FAST16_TYPE__ int +// AVR:#define __INT_FAST32_MAX__ 2147483647L +// AVR:#define __INT_FAST32_TYPE__ long int +// AVR:#define __INT_FAST64_MAX__ 9223372036854775807LL +// AVR:#define __INT_FAST64_TYPE__ long long int +// AVR:#define __INT_FAST8_MAX__ 127 +// AVR:#define __INT_FAST8_TYPE__ signed char +// AVR:#define __INT_LEAST16_MAX__ 32767 +// AVR:#define __INT_LEAST16_TYPE__ int +// AVR:#define __INT_LEAST32_MAX__ 2147483647L +// AVR:#define __INT_LEAST32_TYPE__ long int +// AVR:#define __INT_LEAST64_MAX__ 9223372036854775807LL +// AVR:#define __INT_LEAST64_TYPE__ long long int +// AVR:#define __INT_LEAST8_MAX__ 127 +// AVR:#define __INT_LEAST8_TYPE__ signed char +// AVR:#define __INT_MAX__ 32767 +// AVR:#define __LDBL_DECIMAL_DIG__ 9 +// AVR:#define __LDBL_DENORM_MIN__ 1.40129846e-45L +// AVR:#define __LDBL_DIG__ 6 +// AVR:#define __LDBL_EPSILON__ 1.19209290e-7L +// AVR:#define __LDBL_HAS_DENORM__ 1 +// AVR:#define __LDBL_HAS_INFINITY__ 1 +// AVR:#define __LDBL_HAS_QUIET_NAN__ 1 +// AVR:#define __LDBL_MANT_DIG__ 24 +// AVR:#define __LDBL_MAX_10_EXP__ 38 +// AVR:#define __LDBL_MAX_EXP__ 128 +// AVR:#define __LDBL_MAX__ 3.40282347e+38L +// AVR:#define __LDBL_MIN_10_EXP__ (-37) +// AVR:#define __LDBL_MIN_EXP__ (-125) +// AVR:#define __LDBL_MIN__ 1.17549435e-38L +// AVR:#define __LONG_LONG_MAX__ 9223372036854775807LL +// AVR:#define __LONG_MAX__ 2147483647L +// AVR:#define __NO_INLINE__ 1 +// AVR:#define __ORDER_BIG_ENDIAN__ 4321 +// AVR:#define __ORDER_LITTLE_ENDIAN__ 1234 +// AVR:#define __ORDER_PDP_ENDIAN__ 3412 +// AVR:#define __PRAGMA_REDEFINE_EXTNAME 1 +// AVR:#define __PTRDIFF_MAX__ 32767 +// AVR:#define __PTRDIFF_TYPE__ int +// AVR:#define __SCHAR_MAX__ 127 +// AVR:#define __SHRT_MAX__ 32767 +// AVR:#define __SIG_ATOMIC_MAX__ 127 +// AVR:#define __SIG_ATOMIC_WIDTH__ 8 +// AVR:#define __SIZEOF_DOUBLE__ 4 +// AVR:#define __SIZEOF_FLOAT__ 4 +// AVR:#define __SIZEOF_INT__ 2 +// AVR:#define __SIZEOF_LONG_DOUBLE__ 4 +// AVR:#define __SIZEOF_LONG_LONG__ 8 +// AVR:#define __SIZEOF_LONG__ 4 +// AVR:#define __SIZEOF_POINTER__ 2 +// AVR:#define __SIZEOF_PTRDIFF_T__ 2 +// AVR:#define __SIZEOF_SHORT__ 2 +// AVR:#define __SIZEOF_SIZE_T__ 2 +// AVR:#define __SIZEOF_WCHAR_T__ 2 +// AVR:#define __SIZEOF_WINT_T__ 2 +// AVR:#define __SIZE_MAX__ 65535U +// AVR:#define __SIZE_TYPE__ unsigned int +// AVR:#define __STDC__ 1 +// AVR:#define __UINT16_MAX__ 65535U +// AVR:#define __UINT16_TYPE__ unsigned short +// AVR:#define __UINT32_C_SUFFIX__ UL +// AVR:#define __UINT32_MAX__ 4294967295UL +// AVR:#define __UINT32_TYPE__ long unsigned int +// AVR:#define __UINT64_C_SUFFIX__ ULL +// AVR:#define __UINT64_MAX__ 18446744073709551615ULL +// AVR:#define __UINT64_TYPE__ long long unsigned int +// AVR:#define __UINT8_C_SUFFIX__ +// AVR:#define __UINT8_MAX__ 255 +// AVR:#define __UINT8_TYPE__ unsigned char +// AVR:#define __UINTMAX_C_SUFFIX__ ULL +// AVR:#define __UINTMAX_MAX__ 18446744073709551615ULL +// AVR:#define __UINTMAX_TYPE__ long long unsigned int +// AVR:#define __UINTPTR_MAX__ 65535U +// AVR:#define __UINTPTR_TYPE__ unsigned int +// AVR:#define __UINT_FAST16_MAX__ 65535U +// AVR:#define __UINT_FAST16_TYPE__ unsigned int +// AVR:#define __UINT_FAST32_MAX__ 4294967295UL +// AVR:#define __UINT_FAST32_TYPE__ long unsigned int +// AVR:#define __UINT_FAST64_MAX__ 18446744073709551615ULL +// AVR:#define __UINT_FAST64_TYPE__ long long unsigned int +// AVR:#define __UINT_FAST8_MAX__ 255 +// AVR:#define __UINT_FAST8_TYPE__ unsigned char +// AVR:#define __UINT_LEAST16_MAX__ 65535U +// AVR:#define __UINT_LEAST16_TYPE__ unsigned int +// AVR:#define __UINT_LEAST32_MAX__ 4294967295UL +// AVR:#define __UINT_LEAST32_TYPE__ long unsigned int +// AVR:#define __UINT_LEAST64_MAX__ 18446744073709551615ULL +// AVR:#define __UINT_LEAST64_TYPE__ long long unsigned int +// AVR:#define __UINT_LEAST8_MAX__ 255 +// AVR:#define __UINT_LEAST8_TYPE__ unsigned char +// AVR:#define __USER_LABEL_PREFIX__ +// AVR:#define __WCHAR_MAX__ 32767 +// AVR:#define __WCHAR_TYPE__ int +// AVR:#define __WINT_TYPE__ int Index: cfe/trunk/test/Driver/avr-toolchain.c =================================================================== --- cfe/trunk/test/Driver/avr-toolchain.c +++ cfe/trunk/test/Driver/avr-toolchain.c @@ -0,0 +1,4 @@ +// A basic clang -cc1 command-line. + +// RUN: %clang %s -### -target avr 2>&1 | FileCheck -check-prefix=CC1 %s +// CC1: clang{{.*}} "-cc1" "-triple" "avr"
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits