1 //=- LoongArchISelLowering.cpp - LoongArch DAG Lowering Implementation  ---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interfaces that LoongArch uses to lower LLVM code into
10 // a selection DAG.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "LoongArchISelLowering.h"
15 #include "LoongArch.h"
16 #include "LoongArchMachineFunctionInfo.h"
17 #include "LoongArchRegisterInfo.h"
18 #include "LoongArchSubtarget.h"
19 #include "LoongArchTargetMachine.h"
20 #include "llvm/ADT/Statistic.h"
21 #include "llvm/Support/Debug.h"
22 
23 using namespace llvm;
24 
25 #define DEBUG_TYPE "loongarch-isel-lowering"
26 
27 LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
28                                                  const LoongArchSubtarget &STI)
29     : TargetLowering(TM), Subtarget(STI) {
30 
31   MVT GRLenVT = Subtarget.getGRLenVT();
32   // Set up the register classes.
33   addRegisterClass(GRLenVT, &LoongArch::GPRRegClass);
34 
35   // TODO: add necessary setOperationAction calls later.
36 
37   // Compute derived properties from the register classes.
38   computeRegisterProperties(STI.getRegisterInfo());
39 
40   setStackPointerRegisterToSaveRestore(LoongArch::R3);
41 
42   // Function alignments.
43   const Align FunctionAlignment(4);
44   setMinFunctionAlignment(FunctionAlignment);
45 }
46