--- /dev/null
+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)
--- /dev/null
+//===-- 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<LoongArchTargetMachine> X(getTheLoongArch32Target());
+ RegisterTargetMachine<LoongArchTargetMachine> 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<Reloc::Model> 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<Reloc::Model> RM,
+ Optional<CodeModel::Model> 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;
--- /dev/null
+//=- 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<Reloc::Model> RM,
+ Optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
+ bool JIT);
+ ~LoongArchTargetMachine() override;
+};
+
+} // end namespace llvm
+
+#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHTARGETMACHINE_H
--- /dev/null
+add_llvm_component_library(LLVMLoongArchDesc
+ LoongArchMCTargetDesc.cpp
+
+ LINK_COMPONENTS
+ MC
+ LoongArchInfo
+ Support
+
+ ADD_TO_COMPONENT
+ LoongArch
+ )
--- /dev/null
+//===-- 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() {}
--- /dev/null
+add_llvm_component_library(LLVMLoongArchInfo
+ LoongArchTargetInfo.cpp
+
+ LINK_COMPONENTS
+ Support
+
+ ADD_TO_COMPONENT
+ LoongArch
+ )
--- /dev/null
+//===-- 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<Triple::loongarch32, /*HasJIT=*/false> X(
+ getTheLoongArch32Target(), "loongarch32", "LoongArch (32-bit)",
+ "LoongArch");
+ RegisterTarget<Triple::loongarch64, /*HasJIT=*/false> Y(
+ getTheLoongArch64Target(), "loongarch64", "LoongArch (64-bit)",
+ "LoongArch");
+}
--- /dev/null
+//===-- 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
--- /dev/null
+if not 'LoongArch' in config.root.targets:
+ config.unsupported = True
--- /dev/null
+; RUN: llc --version | FileCheck %s
+; CHECK: loongarch32 - LoongArch (32-bit)
+; CHECK: loongarch64 - LoongArch (64-bit)