From 1bf3e58c89e0451d87c33959f6fe6fe52f234673 Mon Sep 17 00:00:00 2001 From: Jon Humphreys Date: Tue, 22 Jul 2014 17:28:59 -0500 Subject: [PATCH] Added C6000 LLVM target specialization files. --- configure | 2 + lib/Target/C6000/C6000.h | 29 ++++++ lib/Target/C6000/C6000TargetMachine.cpp | 85 +++++++++++++++++ lib/Target/C6000/C6000TargetMachine.h | 42 +++++++++ lib/Target/C6000/C6000TargetTransformInfo.cpp | 91 +++++++++++++++++++ lib/Target/C6000/LLVMBuild.txt | 35 +++++++ .../C6000/MCTargetDesc/C6000MCTargetDesc.cpp | 18 ++++ .../C6000/MCTargetDesc/C6000MCTargetDesc.h | 24 +++++ lib/Target/C6000/MCTargetDesc/LLVMBuild.txt | 23 +++++ lib/Target/C6000/MCTargetDesc/Makefile | 16 ++++ lib/Target/C6000/Makefile | 18 ++++ .../C6000/TargetInfo/C6000TargetInfo.cpp | 20 ++++ lib/Target/C6000/TargetInfo/LLVMBuild.txt | 23 +++++ lib/Target/C6000/TargetInfo/Makefile | 15 +++ lib/Target/LLVMBuild.txt | 2 +- 15 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 lib/Target/C6000/C6000.h create mode 100644 lib/Target/C6000/C6000TargetMachine.cpp create mode 100644 lib/Target/C6000/C6000TargetMachine.h create mode 100644 lib/Target/C6000/C6000TargetTransformInfo.cpp create mode 100644 lib/Target/C6000/LLVMBuild.txt create mode 100644 lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.cpp create mode 100644 lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.h create mode 100644 lib/Target/C6000/MCTargetDesc/LLVMBuild.txt create mode 100644 lib/Target/C6000/MCTargetDesc/Makefile create mode 100644 lib/Target/C6000/Makefile create mode 100644 lib/Target/C6000/TargetInfo/C6000TargetInfo.cpp create mode 100644 lib/Target/C6000/TargetInfo/LLVMBuild.txt create mode 100644 lib/Target/C6000/TargetInfo/Makefile diff --git a/configure b/configure index e72c11d43c..50b0912b43 100755 --- a/configure +++ b/configure @@ -5340,6 +5340,7 @@ case "$enableval" in mips64) TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;; mips64el) TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;; xcore) TARGETS_TO_BUILD="XCore $TARGETS_TO_BUILD" ;; + c6000) TARGETS_TO_BUILD="C6000 $TARGETS_TO_BUILD" ;; msp430) TARGETS_TO_BUILD="MSP430 $TARGETS_TO_BUILD" ;; cpp) TARGETS_TO_BUILD="CppBackend $TARGETS_TO_BUILD" ;; hexagon) TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;; @@ -5355,6 +5356,7 @@ case "$enableval" in ARM) TARGETS_TO_BUILD="ARM $TARGETS_TO_BUILD" ;; Mips) TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;; XCore) TARGETS_TO_BUILD="XCore $TARGETS_TO_BUILD" ;; + c6000) TARGETS_TO_BUILD="C6000 $TARGETS_TO_BUILD" ;; MSP430) TARGETS_TO_BUILD="MSP430 $TARGETS_TO_BUILD" ;; Hexagon) TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;; NVPTX) TARGETS_TO_BUILD="NVPTX $TARGETS_TO_BUILD" ;; diff --git a/lib/Target/C6000/C6000.h b/lib/Target/C6000/C6000.h new file mode 100644 index 0000000000..cb38d7869c --- /dev/null +++ b/lib/Target/C6000/C6000.h @@ -0,0 +1,29 @@ +//==-- C6000.h - Top-level interface for MSP430 representation ---*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the entry points for global functions defined in +// the LLVM C6000 backend. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TARGET_C6000_H +#define LLVM_TARGET_C6000_H + +#include "MCTargetDesc/C6000MCTargetDesc.h" +#include "llvm/Target/TargetMachine.h" + +namespace llvm { + +class C6000TargetMachine; + +/// \brief Creates an C6000-specific Target Transformation Info pass. +ImmutablePass *createC6000TargetTransformInfoPass(const C6000TargetMachine *TM); +} // end namespace llvm; + +#endif diff --git a/lib/Target/C6000/C6000TargetMachine.cpp b/lib/Target/C6000/C6000TargetMachine.cpp new file mode 100644 index 0000000000..391c09d728 --- /dev/null +++ b/lib/Target/C6000/C6000TargetMachine.cpp @@ -0,0 +1,85 @@ +//===-- C6000TargetMachine.cpp - Define TargetMachine for C6000 -----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// +//===----------------------------------------------------------------------===// + +#include "C6000.h" +#include "C6000TargetMachine.h" +#include "llvm/CodeGen/Passes.h" +#include "llvm/PassManager.h" +#include "llvm/Support/TargetRegistry.h" +using namespace llvm; + +extern "C" void LLVMInitializeC6000Target() { + // Register the target. + RegisterTargetMachine X(TheC6000Target); +} + +static std::string computeDataLayout() { + // TODO: for now, assume little endian + std::string Ret = "e-m:e"; + + // 32bit pointers. + Ret += "-p:32:32"; + + // Alignments for 64 bit integers. + Ret += "-i64:64"; + + // Alignments for 128 bit and above vectors is 64 + Ret += "-v128:64:128"; + + // 32 bit ints + // 64 bit aligned stack + Ret += "-n32-S64"; + + return Ret; +} + +/// C6000TargetMachine ctor +/// +C6000TargetMachine::C6000TargetMachine(const Target &T, StringRef TT, + StringRef CPU, StringRef FS, + const TargetOptions &Options, + Reloc::Model RM, CodeModel::Model CM, + CodeGenOpt::Level OL) + : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), + DL(computeDataLayout()) +{ +} + +//===----------------------------------------------------------------------===// +// C6000 Analysis Pass Setup +//===----------------------------------------------------------------------===// + +void C6000TargetMachine::addAnalysisPasses(PassManagerBase &PM) { + // Add first the target-independent BasicTTI pass, then our C6000 pass. This + // allows the C6000 pass to delegate to the target independent layer when + // appropriate. + PM.add(createBasicTargetTransformInfoPass(this)); + PM.add(createC6000TargetTransformInfoPass(this)); +} + +namespace { +/// C6000 Code Generator Pass Configuration Options. +class C6000PassConfig : public TargetPassConfig { +public: + C6000PassConfig(C6000TargetMachine *TM, PassManagerBase &PM) + : TargetPassConfig(TM, PM) {} + + C6000TargetMachine &getC6000TargetMachine() const { + return getTM(); + } +}; +} // namespace + +TargetPassConfig *C6000TargetMachine::createPassConfig(PassManagerBase &PM) { + return new C6000PassConfig(this, PM); +} + diff --git a/lib/Target/C6000/C6000TargetMachine.h b/lib/Target/C6000/C6000TargetMachine.h new file mode 100644 index 0000000000..61ad01bdd5 --- /dev/null +++ b/lib/Target/C6000/C6000TargetMachine.h @@ -0,0 +1,42 @@ +//===-- C6000TargetMachine.h - Define TargetMachine for C6000 ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file declares the C6000 specific subclass of TargetMachine. +// +//===----------------------------------------------------------------------===// + +#ifndef C6000TARGETMACHINE_H +#define C6000TARGETMACHINE_H + +#include "llvm/IR/DataLayout.h" +#include "llvm/Target/TargetFrameLowering.h" +#include "llvm/Target/TargetMachine.h" + +namespace llvm { + +class C6000TargetMachine : public LLVMTargetMachine { + const DataLayout DL; // Calculates type size & alignment +public: + C6000TargetMachine(const Target &T, StringRef TT, + StringRef CPU, StringRef FS, const TargetOptions &Options, + Reloc::Model RM, CodeModel::Model CM, + CodeGenOpt::Level OL); + + const DataLayout *getDataLayout() const override { return &DL; } + + /// \brief Register C6000 analysis passes with a pass manager. + void addAnalysisPasses(PassManagerBase &PM) override; + + // Pass Pipeline Configuration + TargetPassConfig *createPassConfig(PassManagerBase &PM) override; +}; + +} // end namespace llvm + +#endif diff --git a/lib/Target/C6000/C6000TargetTransformInfo.cpp b/lib/Target/C6000/C6000TargetTransformInfo.cpp new file mode 100644 index 0000000000..3aea8033f9 --- /dev/null +++ b/lib/Target/C6000/C6000TargetTransformInfo.cpp @@ -0,0 +1,91 @@ +//===-- C6000TargetTransformInfo.cpp - C6000 specific TTI pass ------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// This file implements a TargetTransformInfo analysis pass specific to the +/// C6000 target machine. It uses the target's detailed information to provide +/// more precise answers to certain TTI queries, while letting the target +/// independent and default TTI implementations handle the rest. +/// +//===----------------------------------------------------------------------===// + +#include "C6000.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/Support/Debug.h" +#include "llvm/Target/CostTable.h" +#include "llvm/Target/TargetLowering.h" +using namespace llvm; + +#define DEBUG_TYPE "c6000tti" + +// Declare the pass initialization routine locally as target-specific passes +// don't have a target-wide initialization entry point, and so we rely on the +// pass constructor initialization. +namespace llvm { +void initializeC6000TTIPass(PassRegistry &); +} + +namespace { +class C6000TTI final : public ImmutablePass, public TargetTransformInfo { + public: + C6000TTI() : ImmutablePass(ID) { + llvm_unreachable("This pass cannot be directly constructed"); + } + + C6000TTI(const C6000TargetMachine *TM) + : ImmutablePass(ID) { + initializeC6000TTIPass(*PassRegistry::getPassRegistry()); + } + + void initializePass() override { + pushTTIStack(this); + } + + void getAnalysisUsage(AnalysisUsage &AU) const override { + TargetTransformInfo::getAnalysisUsage(AU); + } + + /// Pass identification. + static char ID; + + /// Provide necessary pointer adjustments for the two base classes. + void *getAdjustedAnalysisPointer(const void *ID) override { + if (ID == &TargetTransformInfo::ID) + return (TargetTransformInfo*)this; + return this; + } + + /// \name Vector TTI Implementations + /// @{ + + unsigned getNumberOfRegisters(bool Vector) const override { + if (Vector) + return 16; + + return 64; + } + + unsigned getRegisterBitWidth(bool Vector) const override { + return 32; + } + + unsigned getMaximumUnrollFactor() const override { + return 4; + } +}; + +} // end anonymous namespace + +INITIALIZE_AG_PASS(C6000TTI, TargetTransformInfo, "c6000tti", + "C6000 Target Transform Info", true, true, false) +char C6000TTI::ID = 0; + +ImmutablePass * +llvm::createC6000TargetTransformInfoPass(const C6000TargetMachine *TM) { + return new C6000TTI(TM); +} diff --git a/lib/Target/C6000/LLVMBuild.txt b/lib/Target/C6000/LLVMBuild.txt new file mode 100644 index 0000000000..c4e72cbf0d --- /dev/null +++ b/lib/Target/C6000/LLVMBuild.txt @@ -0,0 +1,35 @@ +;===- ./lib/Target/C6000/LLVMBuild.txt -------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[common] +subdirectories = MCTargetDesc TargetInfo + +[component_0] +type = TargetGroup +name = C6000 +parent = Target +has_asmparser = 0 +has_asmprinter = 0 +has_disassembler = 0 +has_jit = 0 + +[component_1] +type = Library +name = C6000CodeGen +parent = C6000 +required_libraries = Core Support Target C6000Desc C6000Info +add_to_library_groups = C6000 diff --git a/lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.cpp b/lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.cpp new file mode 100644 index 0000000000..0276c107bd --- /dev/null +++ b/lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.cpp @@ -0,0 +1,18 @@ +//===-- C6000MCTargetDesc.cpp - C6000 Target Descriptions -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides C6000 specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#include "C6000MCTargetDesc.h" +using namespace llvm; + +extern "C" void LLVMInitializeC6000TargetMC() { +} diff --git a/lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.h b/lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.h new file mode 100644 index 0000000000..eaefd658f1 --- /dev/null +++ b/lib/Target/C6000/MCTargetDesc/C6000MCTargetDesc.h @@ -0,0 +1,24 @@ +//===-- C6000MCTargetDesc.h - C6000 Target Descriptions ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides C6000 specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#ifndef C6000MCTARGETDESC_H +#define C6000MCTARGETDESC_H + +namespace llvm { +class Target; + +extern Target TheC6000Target; + +} // End llvm namespace + +#endif diff --git a/lib/Target/C6000/MCTargetDesc/LLVMBuild.txt b/lib/Target/C6000/MCTargetDesc/LLVMBuild.txt new file mode 100644 index 0000000000..22a0b16383 --- /dev/null +++ b/lib/Target/C6000/MCTargetDesc/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/Target/C6000/MCTargetDesc/LLVMBuild.txt ------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = C6000Desc +parent = C6000 +required_libraries = MC C6000Info +add_to_library_groups = C6000 diff --git a/lib/Target/C6000/MCTargetDesc/Makefile b/lib/Target/C6000/MCTargetDesc/Makefile new file mode 100644 index 0000000000..ec506e361f --- /dev/null +++ b/lib/Target/C6000/MCTargetDesc/Makefile @@ -0,0 +1,16 @@ +##===- lib/Target/C6000/TargetDesc/Makefile ----------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../../.. +LIBRARYNAME = LLVMC6000Desc + +# Hack: we need to include 'main' target directory to grab private headers +CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/.. + +include $(LEVEL)/Makefile.common diff --git a/lib/Target/C6000/Makefile b/lib/Target/C6000/Makefile new file mode 100644 index 0000000000..b97dc99790 --- /dev/null +++ b/lib/Target/C6000/Makefile @@ -0,0 +1,18 @@ +##===- lib/Target/C6000/Makefile ---------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../.. +LIBRARYNAME = LLVMC6000CodeGen +TARGET = C6000 + +# Make sure that tblgen is run, first thing. +BUILT_SOURCES = +DIRS = TargetInfo MCTargetDesc + +include $(LEVEL)/Makefile.common diff --git a/lib/Target/C6000/TargetInfo/C6000TargetInfo.cpp b/lib/Target/C6000/TargetInfo/C6000TargetInfo.cpp new file mode 100644 index 0000000000..6f32e94662 --- /dev/null +++ b/lib/Target/C6000/TargetInfo/C6000TargetInfo.cpp @@ -0,0 +1,20 @@ +//===-- C6000TargetInfo.cpp - C6000 Target Implementation -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "C6000.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/TargetRegistry.h" +using namespace llvm; + +Target llvm::TheC6000Target; + +extern "C" void LLVMInitializeC6000TargetInfo() { + RegisterTarget + X(TheC6000Target, "c6000", "C6000"); +} diff --git a/lib/Target/C6000/TargetInfo/LLVMBuild.txt b/lib/Target/C6000/TargetInfo/LLVMBuild.txt new file mode 100644 index 0000000000..104606c3ae --- /dev/null +++ b/lib/Target/C6000/TargetInfo/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/Target/C6000/TargetInfo/LLVMBuild.txt --------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = C6000Info +parent = C6000 +required_libraries = Support +add_to_library_groups = C6000 diff --git a/lib/Target/C6000/TargetInfo/Makefile b/lib/Target/C6000/TargetInfo/Makefile new file mode 100644 index 0000000000..23de731e66 --- /dev/null +++ b/lib/Target/C6000/TargetInfo/Makefile @@ -0,0 +1,15 @@ +##===- lib/Target/C6000/TargetInfo/Makefile ----------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../../../.. +LIBRARYNAME = LLVMC6000Info + +# Hack: we need to include 'main' target directory to grab private headers +CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/.. + +include $(LEVEL)/Makefile.common diff --git a/lib/Target/LLVMBuild.txt b/lib/Target/LLVMBuild.txt index 27d76bf890..5a20429842 100644 --- a/lib/Target/LLVMBuild.txt +++ b/lib/Target/LLVMBuild.txt @@ -16,7 +16,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = ARM AArch64 CppBackend Hexagon MSP430 NVPTX Mips PowerPC R600 Sparc SystemZ X86 XCore +subdirectories = ARM AArch64 CppBackend Hexagon MSP430 NVPTX Mips PowerPC R600 Sparc SystemZ X86 XCore C6000 ; This is a special group whose required libraries are extended (by llvm-build) ; with the best execution engine (the native JIT, if available, or the -- 2.26.2