From 16c4189f16e9be3c70822c308331c7328de2978f Mon Sep 17 00:00:00 2001 From: arti Date: Tue, 10 Nov 2026 17:18:55 +0000 Subject: [PATCH] llvm: add tms34010 triple, clang target info, and target skeleton --- patches/llvm/0001-triple.patch | 66 ++++++++ patches/llvm/0002-target-skeleton.patch | 196 ++++++++++++++++++++++++ patches/llvm/0003-clang-target.patch | 178 +++++++++++++++++++++ scripts/export-patches.sh | 25 +++ 4 files changed, 465 insertions(+) create mode 100644 patches/llvm/0001-triple.patch create mode 100644 patches/llvm/0002-target-skeleton.patch create mode 100644 patches/llvm/0003-clang-target.patch create mode 100755 scripts/export-patches.sh diff --git a/patches/llvm/0001-triple.patch b/patches/llvm/0001-triple.patch new file mode 100644 index 0000000..cee6e51 --- /dev/null +++ b/patches/llvm/0001-triple.patch @@ -0,0 +1,66 @@ +diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h +index c5af23252..05b5a0d36 100644 +--- a/llvm/include/llvm/TargetParser/Triple.h ++++ b/llvm/include/llvm/TargetParser/Triple.h +@@ -89,6 +89,7 @@ public: + tcele, + // OpenASIP (http://openasip.org) / little endian 64b targets: tcele + tcele64, ++ tms34010, // TMS34010: 32-bit bit-addressed + thumb, // Thumb (little endian): thumb, thumbv.* + thumbeb, // Thumb (big endian): thumbeb + x86, // X86: i[3-9]86 +diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp +index 2e4fe7ce7..186f37fd6 100644 +--- a/llvm/lib/TargetParser/Triple.cpp ++++ b/llvm/lib/TargetParser/Triple.cpp +@@ -146,6 +146,8 @@ StringRef Triple::getArchTypeName(ArchType Kind) { + return "tcele"; + case tcele64: + return "tcele64"; ++ case tms34010: ++ return "tms34010"; + case thumb: + return "thumb"; + case thumbeb: +@@ -391,6 +393,8 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) { + return "kalimba"; + case lanai: + return "lanai"; ++ case tms34010: ++ return "tms"; + case shave: + return "shave"; + case wasm32: +@@ -539,6 +543,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { + .Case("tce", tce) + .Case("tcele", tcele) + .Case("tcele64", tcele64) ++ .Case("tms34010", tms34010) + .Case("thumb", thumb) + .Case("thumbeb", thumbeb) + .Case("x86", x86) +@@ -692,6 +697,7 @@ Triple::ArchType Triple::parseArch(StringRef ArchName) { + .Case("tce", Triple::tce) + .Case("tcele", Triple::tcele) + .Case("tcele64", Triple::tcele64) ++ .Case("tms34010", Triple::tms34010) + .Case("xcore", Triple::xcore) + .Case("nvptx", Triple::nvptx) + .Case("nvptx64", Triple::nvptx64) +@@ -1047,6 +1053,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { + case Triple::tce: + case Triple::tcele: + case Triple::tcele64: ++ case Triple::tms34010: + case Triple::thumbeb: + case Triple::ve: + case Triple::xcore: +@@ -1793,6 +1800,7 @@ unsigned Triple::getArchPointerBitWidth(llvm::Triple::ArchType Arch) { + case llvm::Triple::hsail: + case llvm::Triple::kalimba: + case llvm::Triple::lanai: ++ case llvm::Triple::tms34010: + case llvm::Triple::loongarch32: + case llvm::Triple::m68k: + case llvm::Triple::mips: diff --git a/patches/llvm/0002-target-skeleton.patch b/patches/llvm/0002-target-skeleton.patch new file mode 100644 index 0000000..e0593d0 --- /dev/null +++ b/patches/llvm/0002-target-skeleton.patch @@ -0,0 +1,196 @@ +diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt +index c1e375b88..8eaaccbab 100644 +--- a/llvm/CMakeLists.txt ++++ b/llvm/CMakeLists.txt +@@ -620,6 +620,7 @@ set(LLVM_ALL_TARGETS + Sparc + SPIRV + SystemZ ++ TMS34010 + VE + WebAssembly + X86 +diff --git a/llvm/lib/Target/TMS34010/CMakeLists.txt b/llvm/lib/Target/TMS34010/CMakeLists.txt +new file mode 100644 +index 000000000..9fecaf723 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/CMakeLists.txt +@@ -0,0 +1,18 @@ ++add_llvm_component_group(TMS34010) ++ ++add_llvm_target(TMS34010CodeGen ++ TMS34010TargetMachine.cpp ++ ++ LINK_COMPONENTS ++ Core ++ MC ++ Support ++ Target ++ TargetParser ++ ++ ADD_TO_COMPONENT ++ TMS34010 ++ ) ++ ++add_subdirectory(MCTargetDesc) ++add_subdirectory(TargetInfo) +diff --git a/llvm/lib/Target/TMS34010/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/TMS34010/MCTargetDesc/CMakeLists.txt +new file mode 100644 +index 000000000..f3bac206e +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/MCTargetDesc/CMakeLists.txt +@@ -0,0 +1,11 @@ ++add_llvm_component_library(LLVMTMS34010Desc ++ TMS34010MCTargetDesc.cpp ++ ++ LINK_COMPONENTS ++ MC ++ Support ++ TMS34010Info ++ ++ ADD_TO_COMPONENT ++ TMS34010 ++ ) +diff --git a/llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCTargetDesc.cpp b/llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCTargetDesc.cpp +new file mode 100644 +index 000000000..113bb7b77 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCTargetDesc.cpp +@@ -0,0 +1,12 @@ ++//===-- TMS34010MCTargetDesc.cpp - TMS34010 MC descriptions ---------------===// ++#include "TMS34010MCTargetDesc.h" ++#include "llvm/Support/Compiler.h" ++ ++extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void ++LLVMInitializeTMS34010TargetMC() {} ++extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void ++LLVMInitializeTMS34010AsmPrinter() {} ++extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void ++LLVMInitializeTMS34010AsmParser() {} ++extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void ++LLVMInitializeTMS34010Disassembler() {} +diff --git a/llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCTargetDesc.h b/llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCTargetDesc.h +new file mode 100644 +index 000000000..70e035b24 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCTargetDesc.h +@@ -0,0 +1,9 @@ ++//===-- TMS34010MCTargetDesc.h - TMS34010 MC descriptions -------*- C++ -*-===// ++#ifndef LLVM_LIB_TARGET_TMS34010_MCTARGETDESC_TMS34010MCTARGETDESC_H ++#define LLVM_LIB_TARGET_TMS34010_MCTARGETDESC_TMS34010MCTARGETDESC_H ++ ++namespace llvm { ++class Target; ++} // namespace llvm ++ ++#endif +diff --git a/llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp b/llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp +new file mode 100644 +index 000000000..d2f39e236 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp +@@ -0,0 +1,25 @@ ++//===-- TMS34010TargetMachine.cpp - TMS34010 target machine ---------------===// ++#include "TMS34010TargetMachine.h" ++#include "TargetInfo/TMS34010TargetInfo.h" ++#include "llvm/MC/TargetRegistry.h" ++#include "llvm/Support/Compiler.h" ++using namespace llvm; ++ ++static const char *const TMS34010DataLayout = ++ "e-m:e-p:32:16-i8:8-i16:16-i32:16-i64:16-f32:16-f64:16-n8:16:32"; ++ ++TMS34010TargetMachine::TMS34010TargetMachine( ++ const Target &T, const Triple &TT, StringRef CPU, StringRef FS, ++ const TargetOptions &Options, std::optional RM, ++ std::optional CM, CodeGenOptLevel OL, bool JIT) ++ : TargetMachine(T, TMS34010DataLayout, TT, CPU, FS, Options) { ++ (void)RM; ++ (void)CM; ++ (void)OL; ++ (void)JIT; ++} ++ ++extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void ++LLVMInitializeTMS34010Target() { ++ RegisterTargetMachine X(getTheTMS34010Target()); ++} +diff --git a/llvm/lib/Target/TMS34010/TMS34010TargetMachine.h b/llvm/lib/Target/TMS34010/TMS34010TargetMachine.h +new file mode 100644 +index 000000000..8504946e4 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/TMS34010TargetMachine.h +@@ -0,0 +1,19 @@ ++//===-- TMS34010TargetMachine.h - TMS34010 target machine -------*- C++ -*-===// ++#ifndef LLVM_LIB_TARGET_TMS34010_TMS34010TARGETMACHINE_H ++#define LLVM_LIB_TARGET_TMS34010_TMS34010TARGETMACHINE_H ++ ++#include "llvm/Target/TargetMachine.h" ++#include ++ ++namespace llvm { ++class TMS34010TargetMachine : public TargetMachine { ++public: ++ TMS34010TargetMachine(const Target &T, const Triple &TT, StringRef CPU, ++ StringRef FS, const TargetOptions &Options, ++ std::optional RM, ++ std::optional CM, CodeGenOptLevel OL, ++ bool JIT); ++}; ++} // namespace llvm ++ ++#endif +diff --git a/llvm/lib/Target/TMS34010/TargetInfo/CMakeLists.txt b/llvm/lib/Target/TMS34010/TargetInfo/CMakeLists.txt +new file mode 100644 +index 000000000..e360f4260 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/TargetInfo/CMakeLists.txt +@@ -0,0 +1,10 @@ ++add_llvm_component_library(LLVMTMS34010Info ++ TMS34010TargetInfo.cpp ++ ++ LINK_COMPONENTS ++ MC ++ Support ++ ++ ADD_TO_COMPONENT ++ TMS34010 ++ ) +diff --git a/llvm/lib/Target/TMS34010/TargetInfo/TMS34010TargetInfo.cpp b/llvm/lib/Target/TMS34010/TargetInfo/TMS34010TargetInfo.cpp +new file mode 100644 +index 000000000..f31a51aa5 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/TargetInfo/TMS34010TargetInfo.cpp +@@ -0,0 +1,16 @@ ++//===-- TMS34010TargetInfo.cpp - TMS34010 target registration -------------===// ++#include "TMS34010TargetInfo.h" ++#include "llvm/MC/TargetRegistry.h" ++#include "llvm/Support/Compiler.h" ++using namespace llvm; ++ ++Target &llvm::getTheTMS34010Target() { ++ static Target TheTMS34010Target; ++ return TheTMS34010Target; ++} ++ ++extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void ++LLVMInitializeTMS34010TargetInfo() { ++ RegisterTarget X( ++ getTheTMS34010Target(), "tms34010", "TMS34010", "TMS34010"); ++} +diff --git a/llvm/lib/Target/TMS34010/TargetInfo/TMS34010TargetInfo.h b/llvm/lib/Target/TMS34010/TargetInfo/TMS34010TargetInfo.h +new file mode 100644 +index 000000000..9b7795174 +--- /dev/null ++++ b/llvm/lib/Target/TMS34010/TargetInfo/TMS34010TargetInfo.h +@@ -0,0 +1,10 @@ ++//===-- TMS34010TargetInfo.h - TMS34010 target registration ------*- C++ -*-===// ++#ifndef LLVM_LIB_TARGET_TMS34010_TARGETINFO_TMS34010TARGETINFO_H ++#define LLVM_LIB_TARGET_TMS34010_TARGETINFO_TMS34010TARGETINFO_H ++ ++namespace llvm { ++class Target; ++Target &getTheTMS34010Target(); ++} // namespace llvm ++ ++#endif diff --git a/patches/llvm/0003-clang-target.patch b/patches/llvm/0003-clang-target.patch new file mode 100644 index 0000000..8aa7e0b --- /dev/null +++ b/patches/llvm/0003-clang-target.patch @@ -0,0 +1,178 @@ +diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt +index 21851e79b..6acfba039 100644 +--- a/clang/lib/Basic/CMakeLists.txt ++++ b/clang/lib/Basic/CMakeLists.txt +@@ -116,6 +116,7 @@ add_clang_library(clangBasic + Targets/SPIR.cpp + Targets/Sparc.cpp + Targets/SystemZ.cpp ++ Targets/TMS34010.cpp + Targets/TCE.cpp + Targets/VE.cpp + Targets/WebAssembly.cpp +diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp +index 8c01cfca8..d5c7eae92 100644 +--- a/clang/lib/Basic/Targets.cpp ++++ b/clang/lib/Basic/Targets.cpp +@@ -34,6 +34,7 @@ + #include "Targets/SPIR.h" + #include "Targets/Sparc.h" + #include "Targets/SystemZ.h" ++#include "Targets/TMS34010.h" + #include "Targets/TCE.h" + #include "Targets/VE.h" + #include "Targets/WebAssembly.h" +@@ -284,6 +285,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, + case llvm::Triple::msp430: + return std::make_unique(Triple, Opts); + ++ case llvm::Triple::tms34010: ++ return std::make_unique(Triple, Opts); ++ + case llvm::Triple::mips: + switch (os) { + case llvm::Triple::Linux: +diff --git a/clang/lib/Basic/Targets/TMS34010.cpp b/clang/lib/Basic/Targets/TMS34010.cpp +new file mode 100644 +index 000000000..97a30856c +--- /dev/null ++++ b/clang/lib/Basic/Targets/TMS34010.cpp +@@ -0,0 +1,68 @@ ++//===--- TMS34010.cpp - Implement TMS34010 target feature support ---------===// ++#include "TMS34010.h" ++#include "clang/Basic/MacroBuilder.h" ++ ++using namespace clang; ++using namespace clang::targets; ++ ++TMS34010TargetInfo::TMS34010TargetInfo(const llvm::Triple &Triple, ++ const TargetOptions &) ++ : TargetInfo(Triple) { ++ TLSSupported = false; ++ ShortWidth = 16; ++ ShortAlign = 16; ++ IntWidth = 32; ++ IntAlign = 16; ++ LongWidth = 32; ++ LongAlign = 16; ++ LongLongWidth = 64; ++ LongLongAlign = 16; ++ FloatWidth = 32; ++ FloatAlign = 16; ++ DoubleWidth = 64; ++ DoubleAlign = 16; ++ LongDoubleWidth = 64; ++ LongDoubleAlign = 16; ++ PointerWidth = 32; ++ PointerAlign = 16; ++ BoolWidth = 8; ++ BoolAlign = 8; ++ SuitableAlign = 16; ++ WCharType = SignedInt; ++ WIntType = SignedInt; ++ SizeType = UnsignedInt; ++ PtrDiffType = SignedInt; ++ IntPtrType = SignedInt; ++ IntMaxType = SignedLongLong; ++ Int64Type = SignedLongLong; ++ SigAtomicType = SignedInt; ++ resetDataLayout( ++ "e-m:e-p:32:16-i8:8-i16:16-i32:16-i64:16-f32:16-f64:16-n8:16:32"); ++} ++ ++void TMS34010TargetInfo::getTargetDefines(const LangOptions &Opts, ++ MacroBuilder &Builder) const { ++ (void)Opts; ++ Builder.defineMacro("__tms34010__"); ++ Builder.defineMacro("__TMS34010__"); ++ Builder.defineMacro("__CHAR_BIT__", "8"); ++ Builder.defineMacro("__SIZEOF_POINTER__", "4"); ++ Builder.defineMacro("__ILP32__", "1"); ++} ++ ++void TMS34010TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts, ++ const TargetInfo *Aux) { ++ (void)Diags; ++ (void)Aux; ++ Opts.PackStruct = 1; ++} ++ ++ArrayRef TMS34010TargetInfo::getGCCRegNames() const { ++ static const char *const Names[] = { ++ "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", ++ "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", ++ "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", ++ "b8", "b9", "b10", "b11", "b12", "b13", "b14", "b15", ++ }; ++ return Names; ++} +diff --git a/clang/lib/Basic/Targets/TMS34010.h b/clang/lib/Basic/Targets/TMS34010.h +new file mode 100644 +index 000000000..31349d09a +--- /dev/null ++++ b/clang/lib/Basic/Targets/TMS34010.h +@@ -0,0 +1,54 @@ ++//===--- TMS34010.h - Declare TMS34010 target feature support ---*- C++ -*-===// ++#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_TMS34010_H ++#define LLVM_CLANG_LIB_BASIC_TARGETS_TMS34010_H ++ ++#include "clang/Basic/TargetInfo.h" ++#include "clang/Basic/TargetOptions.h" ++#include "llvm/Support/Compiler.h" ++#include "llvm/TargetParser/Triple.h" ++ ++namespace clang { ++namespace targets { ++ ++class LLVM_LIBRARY_VISIBILITY TMS34010TargetInfo : public TargetInfo { ++public: ++ TMS34010TargetInfo(const llvm::Triple &Triple, const TargetOptions &); ++ ++ void getTargetDefines(const LangOptions &Opts, ++ MacroBuilder &Builder) const override; ++ ++ void adjust(DiagnosticsEngine &Diags, LangOptions &Opts, ++ const TargetInfo *Aux) override; ++ ++ bool hasFeature(StringRef Feature) const override { ++ return Feature == "tms34010"; ++ } ++ ++ llvm::SmallVector getTargetBuiltins() const override { ++ return {}; ++ } ++ ++ BuiltinVaListKind getBuiltinVaListKind() const override { ++ return CharPtrBuiltinVaList; ++ } ++ ++ bool validateAsmConstraint(const char *&Name, ++ TargetInfo::ConstraintInfo &info) const override { ++ (void)Name; ++ (void)info; ++ return false; ++ } ++ ++ std::string_view getClobbers() const override { return ""; } ++ ++ ArrayRef getGCCRegNames() const override; ++ ++ ArrayRef getGCCRegAliases() const override { ++ return {}; ++ } ++}; ++ ++} // namespace targets ++} // namespace clang ++ ++#endif +diff --git a/clang/test/CodeGen/TMS34010/triple.c b/clang/test/CodeGen/TMS34010/triple.c +new file mode 100644 +index 000000000..23e587996 +--- /dev/null ++++ b/clang/test/CodeGen/TMS34010/triple.c +@@ -0,0 +1,4 @@ ++// RUN: %clang_cc1 -triple tms34010-unknown-none -ffreestanding -emit-llvm -o - %s | FileCheck %s ++// CHECK: target datalayout = "e-m:e-p:32:16-i8:8-i16:16-i32:16-i64:16-f32:16-f64:16-n8:16:32" ++// CHECK: target triple = "tms34010-unknown-none" ++int add(int a, int b) { return a + b; } diff --git a/scripts/export-patches.sh b/scripts/export-patches.sh new file mode 100755 index 0000000..5b6838d --- /dev/null +++ b/scripts/export-patches.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Export the TMS34010 fork delta as a patch series against the pinned tag. +set -eu +SRC=${LLVM_SRC:-build/llvm-src} +TAG=llvmorg-23.1.5 +OUT=${1:-patches/llvm} +mkdir -p "$OUT" + +# git diff ignores untracked files; make new files visible to it. +git -C "$SRC" add -N llvm/lib/Target/TMS34010 clang/lib/Basic/Targets/TMS34010.h clang/lib/Basic/Targets/TMS34010.cpp clang/test/CodeGen/TMS34010 2>/dev/null || true + +git -C "$SRC" diff "$TAG" -- \ + llvm/include/llvm/TargetParser llvm/lib/TargetParser \ + > "$OUT/0001-triple.patch" +git -C "$SRC" diff "$TAG" -- \ + llvm/lib/Target/TMS34010 llvm/lib/Target/CMakeLists.txt llvm/CMakeLists.txt \ + > "$OUT/0002-target-skeleton.patch" +git -C "$SRC" diff "$TAG" -- \ + clang/lib/Basic/Targets clang/lib/Basic/Targets.cpp \ + clang/lib/Basic/CMakeLists.txt clang/test/CodeGen/TMS34010 \ + > "$OUT/0003-clang-target.patch" +git -C "$SRC" diff "$TAG" -- clang/lib/CodeGen/CGExprScalar.cpp \ + > "$OUT/0004-clang-ptrdiff.patch" + +find "$OUT" -type f -empty -delete