[llvm] [LoongArch][GlobalISel] Adding initial GlobalISel infrastructure (PR #76912)

Lu Weining via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 00:41:54 PST 2024


================
@@ -0,0 +1,104 @@
+//===-- LoongArchInstructionSelector.cpp -------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// This file implements the targeting of the InstructionSelector class for
+/// LoongArch.
+/// \todo This should be generated by TableGen.
+//===----------------------------------------------------------------------===//
+
+#include "LoongArchRegisterBankInfo.h"
+#include "LoongArchSubtarget.h"
+#include "LoongArchTargetMachine.h"
+#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
+#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
+#include "llvm/IR/IntrinsicsLoongArch.h"
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "loongarch-isel"
+
+using namespace llvm;
+
+#define GET_GLOBALISEL_PREDICATE_BITSET
+#include "LoongArchGenGlobalISel.inc"
+#undef GET_GLOBALISEL_PREDICATE_BITSET
+
+namespace {
+
+class LoongArchInstructionSelector : public InstructionSelector {
+public:
+  LoongArchInstructionSelector(const LoongArchTargetMachine &TM,
+                               const LoongArchSubtarget &STI,
+                               const LoongArchRegisterBankInfo &RBI);
+
+  bool select(MachineInstr &I) override;
+  static const char *getName() { return DEBUG_TYPE; }
+
+private:
+  bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
+
+  const LoongArchSubtarget &STI;
+  const LoongArchInstrInfo &TII;
+  const LoongArchRegisterInfo &TRI;
+  const LoongArchRegisterBankInfo &RBI;
+
+  // FIXME: This is necessary because DAGISel uses "Subtarget->" and GlobalISel
+  // uses "STI." in the code generated by TableGen. We need to unify the name of
+  // Subtarget variable.
+  const LoongArchSubtarget *Subtarget = &STI;
----------------
SixWeining wrote:

Is this variable `Subtarget` necessary?

https://github.com/llvm/llvm-project/pull/76912


More information about the llvm-commits mailing list