From: Lu Weining Date: Thu, 10 Feb 2022 09:12:09 +0000 (+0000) Subject: [LoongArch 3/6] Add target stub for LoongArch X-Git-Tag: upstream/15.0.7~17080 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=444c6d261a913bc4f05ac166357af8afa584da73;p=platform%2Fupstream%2Fllvm.git [LoongArch 3/6] Add target stub for LoongArch This patch registers the 'loongarch32' and 'loongarch64' targets. Also adds a simple testcase to check the output of llc --vesion containing the targets. Differential revision: https://reviews.llvm.org/D115860 --- diff --git a/llvm/lib/Target/LoongArch/CMakeLists.txt b/llvm/lib/Target/LoongArch/CMakeLists.txt new file mode 100644 index 0000000..254320f --- /dev/null +++ b/llvm/lib/Target/LoongArch/CMakeLists.txt @@ -0,0 +1,24 @@ +add_llvm_component_group(LoongArch) + +add_llvm_target(LoongArchCodeGen + LoongArchTargetMachine.cpp + + LINK_COMPONENTS + Analysis + AsmPrinter + CodeGen + Core + MC + LoongArchDesc + LoongArchInfo + SelectionDAG + Support + Target + GlobalISel + + ADD_TO_COMPONENT + LoongArch + ) + +add_subdirectory(MCTargetDesc) +add_subdirectory(TargetInfo) diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp new file mode 100644 index 0000000..66507b4 --- /dev/null +++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp @@ -0,0 +1,52 @@ +//===-- LoongArchTargetMachine.cpp - Define TargetMachine for LoongArch ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Implements the info about LoongArch target spec. +// +//===----------------------------------------------------------------------===// + +#include "LoongArchTargetMachine.h" +#include "TargetInfo/LoongArchTargetInfo.h" +#include "llvm/MC/TargetRegistry.h" + +using namespace llvm; + +#define DEBUG_TYPE "loongarch" + +extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLoongArchTarget() { + // Register the target. + RegisterTargetMachine X(getTheLoongArch32Target()); + RegisterTargetMachine Y(getTheLoongArch64Target()); +} + +// FIXME: This is just a placeholder to make current commit buildable. Body of +// this function will be filled in later commits. +static std::string computeDataLayout(const Triple &TT) { + std::string Ret; + Ret += "e"; + return Ret; +} + +static Reloc::Model getEffectiveRelocModel(const Triple &TT, + Optional RM) { + if (!RM.hasValue()) + return Reloc::Static; + return *RM; +} + +LoongArchTargetMachine::LoongArchTargetMachine( + const Target &T, const Triple &TT, StringRef CPU, StringRef FS, + const TargetOptions &Options, Optional RM, + Optional CM, CodeGenOpt::Level OL, bool JIT) + : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options, + getEffectiveRelocModel(TT, RM), + getEffectiveCodeModel(CM, CodeModel::Small), OL) { + initAsmInfo(); +} + +LoongArchTargetMachine::~LoongArchTargetMachine() = default; diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.h b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.h new file mode 100644 index 0000000..31c78ee --- /dev/null +++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.h @@ -0,0 +1,33 @@ +//=- LoongArchTargetMachine.h - Define TargetMachine for LoongArch -*- C++ -*-// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares the LoongArch specific subclass of TargetMachine. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHTARGETMACHINE_H +#define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHTARGETMACHINE_H + +#include "llvm/Target/TargetMachine.h" + +namespace llvm { + +class LoongArchTargetMachine : public LLVMTargetMachine { + +public: + LoongArchTargetMachine(const Target &T, const Triple &TT, StringRef CPU, + StringRef FS, const TargetOptions &Options, + Optional RM, + Optional CM, CodeGenOpt::Level OL, + bool JIT); + ~LoongArchTargetMachine() override; +}; + +} // end namespace llvm + +#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHTARGETMACHINE_H diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/LoongArch/MCTargetDesc/CMakeLists.txt new file mode 100644 index 0000000..27d5940 --- /dev/null +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/CMakeLists.txt @@ -0,0 +1,11 @@ +add_llvm_component_library(LLVMLoongArchDesc + LoongArchMCTargetDesc.cpp + + LINK_COMPONENTS + MC + LoongArchInfo + Support + + ADD_TO_COMPONENT + LoongArch + ) diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp new file mode 100644 index 0000000..4d9735e --- /dev/null +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp @@ -0,0 +1,17 @@ +//===-- LoongArchMCTargetDesc.cpp - LoongArch Target Descriptions ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file provides LoongArch specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/Compiler.h" + +// FIXME: This is just a placeholder to make current commit buildable. Body of +// this function will be filled in later commits. +extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLoongArchTargetMC() {} diff --git a/llvm/lib/Target/LoongArch/TargetInfo/CMakeLists.txt b/llvm/lib/Target/LoongArch/TargetInfo/CMakeLists.txt new file mode 100644 index 0000000..f53ddba --- /dev/null +++ b/llvm/lib/Target/LoongArch/TargetInfo/CMakeLists.txt @@ -0,0 +1,9 @@ +add_llvm_component_library(LLVMLoongArchInfo + LoongArchTargetInfo.cpp + + LINK_COMPONENTS + Support + + ADD_TO_COMPONENT + LoongArch + ) diff --git a/llvm/lib/Target/LoongArch/TargetInfo/LoongArchTargetInfo.cpp b/llvm/lib/Target/LoongArch/TargetInfo/LoongArchTargetInfo.cpp new file mode 100644 index 0000000..64b1a5b --- /dev/null +++ b/llvm/lib/Target/LoongArch/TargetInfo/LoongArchTargetInfo.cpp @@ -0,0 +1,30 @@ +//===-- LoongArchTargetInfo.cpp - LoongArch Target Implementation ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "TargetInfo/LoongArchTargetInfo.h" +#include "llvm/MC/TargetRegistry.h" +using namespace llvm; + +Target &llvm::getTheLoongArch32Target() { + static Target TheLoongArch32Target; + return TheLoongArch32Target; +} + +Target &llvm::getTheLoongArch64Target() { + static Target TheLoongArch64Target; + return TheLoongArch64Target; +} + +extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLoongArchTargetInfo() { + RegisterTarget X( + getTheLoongArch32Target(), "loongarch32", "LoongArch (32-bit)", + "LoongArch"); + RegisterTarget Y( + getTheLoongArch64Target(), "loongarch64", "LoongArch (64-bit)", + "LoongArch"); +} diff --git a/llvm/lib/Target/LoongArch/TargetInfo/LoongArchTargetInfo.h b/llvm/lib/Target/LoongArch/TargetInfo/LoongArchTargetInfo.h new file mode 100644 index 0000000..6fc13d5 --- /dev/null +++ b/llvm/lib/Target/LoongArch/TargetInfo/LoongArchTargetInfo.h @@ -0,0 +1,21 @@ +//===-- LoongArchTargetInfo.h - LoongArch Target Implementation -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_LOONGARCH_TARGETINFO_LOONGARCHTARGETINFO_H +#define LLVM_LIB_TARGET_LOONGARCH_TARGETINFO_LOONGARCHTARGETINFO_H + +namespace llvm { + +class Target; + +Target &getTheLoongArch32Target(); +Target &getTheLoongArch64Target(); + +} // namespace llvm + +#endif // LLVM_LIB_TARGET_LOONGARCH_TARGETINFO_LOONGARCHTARGETINFO_H diff --git a/llvm/test/CodeGen/LoongArch/lit.local.cfg b/llvm/test/CodeGen/LoongArch/lit.local.cfg new file mode 100644 index 0000000..2b5a489 --- /dev/null +++ b/llvm/test/CodeGen/LoongArch/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'LoongArch' in config.root.targets: + config.unsupported = True diff --git a/llvm/test/CodeGen/LoongArch/target_support.ll b/llvm/test/CodeGen/LoongArch/target_support.ll new file mode 100644 index 0000000..528cdfa --- /dev/null +++ b/llvm/test/CodeGen/LoongArch/target_support.ll @@ -0,0 +1,3 @@ +; RUN: llc --version | FileCheck %s +; CHECK: loongarch32 - LoongArch (32-bit) +; CHECK: loongarch64 - LoongArch (64-bit)