Skip to content

Commit 3a0dff0

Browse files
committed
[Xtensa] Implement base CallConvention.
Implement base Calling Convention functionality. Implement stack load/store register operations.
1 parent c89d511 commit 3a0dff0

15 files changed

+719
-7
lines changed

llvm/lib/Target/Xtensa/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(LLVM_TARGET_DEFINITIONS Xtensa.td)
44

55
tablegen(LLVM XtensaGenAsmMatcher.inc -gen-asm-matcher)
66
tablegen(LLVM XtensaGenAsmWriter.inc -gen-asm-writer)
7+
tablegen(LLVM XtensaGenCallingConv.inc -gen-callingconv)
78
tablegen(LLVM XtensaGenDAGISel.inc -gen-dag-isel)
89
tablegen(LLVM XtensaGenDisassemblerTables.inc -gen-disassembler)
910
tablegen(LLVM XtensaGenInstrInfo.inc -gen-instr-info)
@@ -22,6 +23,7 @@ add_llvm_target(XtensaCodeGen
2223
XtensaRegisterInfo.cpp
2324
XtensaSubtarget.cpp
2425
XtensaTargetMachine.cpp
26+
XtensaUtils.cpp
2527

2628
LINK_COMPONENTS
2729
AsmPrinter

llvm/lib/Target/Xtensa/Xtensa.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def : Proc<"generic", []>;
3535

3636
include "XtensaRegisterInfo.td"
3737

38+
//===----------------------------------------------------------------------===//
39+
// Calling Convention Description
40+
//===----------------------------------------------------------------------===//
41+
42+
include "XtensaCallingConv.td"
43+
3844
//===----------------------------------------------------------------------===//
3945
// Instruction Descriptions
4046
//===----------------------------------------------------------------------===//
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===- XtensaCallingConv.td - Xtensa Calling Conventions -*- tablegen ---*-===//
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+
// This describes the calling conventions for the Xtensa ABI.
9+
//===----------------------------------------------------------------------===//
10+
11+
//===----------------------------------------------------------------------===//
12+
// Xtensa return value calling convention
13+
//===----------------------------------------------------------------------===//
14+
def RetCC_Xtensa : CallingConv<[
15+
CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
16+
CCIfType<[f32], CCBitConvertToType<i32>>,
17+
18+
// First two return values go in a2, a3, a4, a5
19+
CCIfType<[i32], CCAssignToReg<[A2, A3, A4, A5]>>,
20+
CCIfType<[i64], CCAssignToRegWithShadow<[A2, A4], [A3, A5]>>
21+
]>;
22+
23+
//===----------------------------------------------------------------------===//
24+
// Callee-saved register lists.
25+
//===----------------------------------------------------------------------===//
26+
27+
def CSR_Xtensa : CalleeSavedRegs<(add A0, A12, A13, A14, A15)>;

llvm/lib/Target/Xtensa/XtensaISelDAGToDAG.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
#include "Xtensa.h"
1414
#include "XtensaTargetMachine.h"
15+
#include "XtensaUtils.h"
1516
#include "llvm/CodeGen/MachineFunction.h"
1617
#include "llvm/CodeGen/MachineRegisterInfo.h"
1718
#include "llvm/CodeGen/SelectionDAGISel.h"
19+
#include "llvm/IR/DiagnosticInfo.h"
1820
#include "llvm/Support/Debug.h"
1921
#include "llvm/Support/raw_ostream.h"
2022

@@ -37,9 +39,57 @@ class XtensaDAGToDAGISel : public SelectionDAGISel {
3739

3840
void Select(SDNode *Node) override;
3941

42+
// For load/store instructions generate (base+offset) pair from
43+
// memory address. The offset must be a multiple of scale argument.
4044
bool selectMemRegAddr(SDValue Addr, SDValue &Base, SDValue &Offset,
4145
int Scale) {
42-
report_fatal_error("MemReg address is not implemented yet");
46+
EVT ValTy = Addr.getValueType();
47+
48+
// if Address is FI, get the TargetFrameIndex.
49+
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
50+
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
51+
Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), ValTy);
52+
53+
return true;
54+
}
55+
56+
if (TM.isPositionIndependent()) {
57+
DiagnosticInfoUnsupported Diag(CurDAG->getMachineFunction().getFunction(),
58+
"PIC relocations are not supported ",
59+
Addr.getDebugLoc());
60+
CurDAG->getContext()->diagnose(Diag);
61+
}
62+
63+
if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
64+
Addr.getOpcode() == ISD::TargetGlobalAddress))
65+
return false;
66+
67+
// Addresses of the form FI+const
68+
bool Valid = false;
69+
if (CurDAG->isBaseWithConstantOffset(Addr)) {
70+
ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
71+
int64_t OffsetVal = CN->getSExtValue();
72+
73+
Valid = isValidAddrOffset(Scale, OffsetVal);
74+
75+
if (Valid) {
76+
// If the first operand is a FI, get the TargetFI Node
77+
if (FrameIndexSDNode *FIN =
78+
dyn_cast<FrameIndexSDNode>(Addr.getOperand(0)))
79+
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
80+
else
81+
Base = Addr.getOperand(0);
82+
83+
Offset =
84+
CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(Addr), ValTy);
85+
return true;
86+
}
87+
}
88+
89+
// Last case
90+
Base = Addr;
91+
Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), Addr.getValueType());
92+
return true;
4393
}
4494

4595
bool selectMemRegAddrISH1(SDValue Addr, SDValue &Base, SDValue &Offset) {

0 commit comments

Comments
 (0)