Skip to content

Commit fdb8e58

Browse files
committed
[Xtensa] Initial support of the ALU operations.
Initial codegen support for simple ALU operations. Added basic implementation of the TargetFrameLowering, CallingConv, TargetLowering, SelectionDAGISel etc.
1 parent f01b6ca commit fdb8e58

28 files changed

+1351
-12
lines changed

llvm/lib/Target/Xtensa/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ 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)
8+
tablegen(LLVM XtensaGenDAGISel.inc -gen-dag-isel)
79
tablegen(LLVM XtensaGenDisassemblerTables.inc -gen-disassembler)
810
tablegen(LLVM XtensaGenInstrInfo.inc -gen-instr-info)
911
tablegen(LLVM XtensaGenMCCodeEmitter.inc -gen-emitter)
@@ -13,13 +15,22 @@ tablegen(LLVM XtensaGenSubtargetInfo.inc -gen-subtarget)
1315
add_public_tablegen_target(XtensaCommonTableGen)
1416

1517
add_llvm_target(XtensaCodeGen
18+
XtensaAsmPrinter.cpp
19+
XtensaFrameLowering.cpp
20+
XtensaInstrInfo.cpp
21+
XtensaISelDAGToDAG.cpp
22+
XtensaISelLowering.cpp
23+
XtensaMCInstLower.cpp
24+
XtensaRegisterInfo.cpp
25+
XtensaSubtarget.cpp
1626
XtensaTargetMachine.cpp
1727

1828
LINK_COMPONENTS
1929
AsmPrinter
2030
CodeGen
2131
Core
2232
MC
33+
SelectionDAG
2334
Support
2435
Target
2536
XtensaDesc

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaAsmBackend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
8484
unsigned Kind = Fixup.getKind();
8585
switch (Kind) {
8686
default:
87-
llvm_unreachable("Unknown fixup kind!");
87+
report_fatal_error("Unknown fixup kind!");
8888
case FK_Data_1:
8989
case FK_Data_2:
9090
case FK_Data_4:

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void XtensaInstPrinter::printBranchTarget(const MCInst *MI, int OpNum,
102102
} else if (MC.isExpr())
103103
MC.getExpr()->print(OS, &MAI, true);
104104
else
105-
llvm_unreachable("Invalid operand");
105+
report_fatal_error("Invalid operand");
106106
}
107107

108108
void XtensaInstPrinter::printJumpTarget(const MCInst *MI, int OpNum,
@@ -117,7 +117,7 @@ void XtensaInstPrinter::printJumpTarget(const MCInst *MI, int OpNum,
117117
} else if (MC.isExpr())
118118
MC.getExpr()->print(OS, &MAI, true);
119119
else
120-
llvm_unreachable("Invalid operand");
120+
report_fatal_error("Invalid operand");
121121
;
122122
}
123123

@@ -133,7 +133,7 @@ void XtensaInstPrinter::printCallOperand(const MCInst *MI, int OpNum,
133133
} else if (MC.isExpr())
134134
MC.getExpr()->print(OS, &MAI, true);
135135
else
136-
llvm_unreachable("Invalid operand");
136+
report_fatal_error("Invalid operand");
137137
}
138138

139139
void XtensaInstPrinter::printL32RTarget(const MCInst *MI, int OpNum,
@@ -151,7 +151,7 @@ void XtensaInstPrinter::printL32RTarget(const MCInst *MI, int OpNum,
151151
} else if (MC.isExpr())
152152
MC.getExpr()->print(O, &MAI, true);
153153
else
154-
llvm_unreachable("Invalid operand");
154+
report_fatal_error("Invalid operand");
155155
}
156156

157157
void XtensaInstPrinter::printImm8_AsmOperand(const MCInst *MI, int OpNum,

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ XtensaMCCodeEmitter::getCallEncoding(const MCInst &MI, unsigned int OpNum,
203203
if (MO.isImm()) {
204204
int32_t Res = MO.getImm();
205205
if (Res & 0x3) {
206-
llvm_unreachable("Unexpected operand value!");
206+
report_fatal_error("Unexpected operand value!");
207207
}
208208
Res >>= 2;
209209
return Res;
@@ -396,7 +396,7 @@ XtensaMCCodeEmitter::getB4constOpValue(const MCInst &MI, unsigned OpNo,
396396
Res = 15;
397397
break;
398398
default:
399-
llvm_unreachable("Unexpected operand value!");
399+
report_fatal_error("Unexpected operand value!");
400400
}
401401

402402
return Res;
@@ -446,7 +446,7 @@ XtensaMCCodeEmitter::getB4constuOpValue(const MCInst &MI, unsigned OpNo,
446446
Res = 15;
447447
break;
448448
default:
449-
llvm_unreachable("Unexpected operand value!");
449+
report_fatal_error("Unexpected operand value!");
450450
}
451451

452452
return Res;

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ XtensaMCExpr::VariantKind XtensaMCExpr::getVariantKindForName(StringRef name) {
5858
StringRef XtensaMCExpr::getVariantKindName(VariantKind Kind) {
5959
switch (Kind) {
6060
default:
61-
llvm_unreachable("Invalid ELF symbol kind");
61+
report_fatal_error("Invalid ELF symbol kind");
6262
}
6363
}

llvm/lib/Target/Xtensa/Xtensa.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- Xtensa.h - Top-level interface for Xtensa representation -*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
//
11+
// This file contains the entry points for global functions defined in
12+
// the LLVM Xtensa back-end.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#ifndef LLVM_LIB_TARGET_XTENSA_XTENSA_H
17+
#define LLVM_LIB_TARGET_XTENSA_XTENSA_H
18+
19+
#include "MCTargetDesc/XtensaMCTargetDesc.h"
20+
#include "llvm/PassRegistry.h"
21+
#include "llvm/Support/CodeGen.h"
22+
23+
namespace llvm {
24+
class XtensaTargetMachine;
25+
class FunctionPass;
26+
27+
FunctionPass *createXtensaISelDag(XtensaTargetMachine &TM,
28+
CodeGenOptLevel OptLevel);
29+
} // namespace llvm
30+
#endif // LLVM_LIB_TARGET_XTENSA_XTENSA_H

llvm/lib/Target/Xtensa/Xtensa.td

+6
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
//===----------------------------------------------------------------------===//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===- XtensaAsmPrinter.cpp Xtensa LLVM Assembly Printer ------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
//
11+
// This file contains a printer that converts from our internal representation
12+
// of machine-dependent LLVM code to GAS-format Xtensa assembly language.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include "XtensaAsmPrinter.h"
17+
#include "TargetInfo/XtensaTargetInfo.h"
18+
#include "XtensaMCInstLower.h"
19+
#include "llvm/BinaryFormat/ELF.h"
20+
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
21+
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
22+
#include "llvm/MC/MCExpr.h"
23+
#include "llvm/MC/MCSectionELF.h"
24+
#include "llvm/MC/MCStreamer.h"
25+
#include "llvm/MC/MCSymbol.h"
26+
#include "llvm/MC/MCSymbolELF.h"
27+
#include "llvm/MC/TargetRegistry.h"
28+
29+
using namespace llvm;
30+
31+
void XtensaAsmPrinter::emitInstruction(const MachineInstr *MI) {
32+
XtensaMCInstLower Lower(MF->getContext(), *this);
33+
MCInst LoweredMI;
34+
Lower.lower(MI, LoweredMI);
35+
EmitToStreamer(*OutStreamer, LoweredMI);
36+
}
37+
38+
// Force static initialization.
39+
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXtensaAsmPrinter() {
40+
RegisterAsmPrinter<XtensaAsmPrinter> A(getTheXtensaTarget());
41+
}
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===- XtensaAsmPrinter.h - Xtensa LLVM Assembly Printer --------*- C++-*--===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
//
11+
// Xtensa Assembly printer class.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_LIB_TARGET_XTENSA_XTENSAASMPRINTER_H
16+
#define LLVM_LIB_TARGET_XTENSA_XTENSAASMPRINTER_H
17+
18+
#include "XtensaTargetMachine.h"
19+
#include "llvm/CodeGen/AsmPrinter.h"
20+
#include "llvm/Support/Compiler.h"
21+
22+
namespace llvm {
23+
class MCStreamer;
24+
class MachineBasicBlock;
25+
class MachineInstr;
26+
class Module;
27+
class raw_ostream;
28+
29+
class LLVM_LIBRARY_VISIBILITY XtensaAsmPrinter : public AsmPrinter {
30+
const MCSubtargetInfo *STI;
31+
32+
public:
33+
explicit XtensaAsmPrinter(TargetMachine &TM,
34+
std::unique_ptr<MCStreamer> Streamer)
35+
: AsmPrinter(TM, std::move(Streamer)), STI(TM.getMCSubtargetInfo()) {}
36+
37+
StringRef getPassName() const override { return "Xtensa Assembly Printer"; }
38+
void emitInstruction(const MachineInstr *MI) override;
39+
};
40+
} // end namespace llvm
41+
42+
#endif /* LLVM_LIB_TARGET_XTENSA_XTENSAASMPRINTER_H */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- XtensaCallingConv.td - Xtensa Calling Conventions -*- tablegen ---*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
// This describes the calling conventions for the Xtensa ABI.
11+
//===----------------------------------------------------------------------===//
12+
13+
//===----------------------------------------------------------------------===//
14+
// Xtensa return value calling convention
15+
//===----------------------------------------------------------------------===//
16+
def RetCC_Xtensa : CallingConv<[
17+
CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
18+
CCIfType<[f32], CCBitConvertToType<i32>>,
19+
20+
// First two return values go in a2, a3, a4, a5
21+
CCIfType<[i32], CCAssignToReg<[A2, A3, A4, A5]>>,
22+
CCIfType<[f32], CCAssignToReg<[A2, A3, A4, A5]>>,
23+
CCIfType<[i64], CCAssignToRegWithShadow<[A2, A4], [A3, A5]>>
24+
]>;
25+
26+
//===----------------------------------------------------------------------===//
27+
// Callee-saved register lists.
28+
//===----------------------------------------------------------------------===//
29+
30+
def CSR_Xtensa : CalleeSavedRegs<(add A0, A12, A13, A14, A15)>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===- XtensaFrameLowering.cpp - Xtensa Frame Information -----------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===----------------------------------------------------------------------===//
10+
//
11+
// This file contains the Xtensa implementation of TargetFrameLowering class.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "XtensaFrameLowering.h"
16+
#include "XtensaInstrInfo.h"
17+
#include "XtensaSubtarget.h"
18+
#include "llvm/CodeGen/MachineFrameInfo.h"
19+
#include "llvm/CodeGen/MachineInstrBuilder.h"
20+
#include "llvm/CodeGen/MachineModuleInfo.h"
21+
#include "llvm/CodeGen/MachineRegisterInfo.h"
22+
#include "llvm/CodeGen/RegisterScavenging.h"
23+
#include "llvm/IR/Function.h"
24+
25+
using namespace llvm;
26+
27+
XtensaFrameLowering::XtensaFrameLowering()
28+
: TargetFrameLowering(TargetFrameLowering::StackGrowsDown, Align(4), 0,
29+
Align(4)) {}
30+
31+
// hasFP - Return true if the specified function should have a dedicated frame
32+
// pointer register. This is true if the function has variable sized allocas or
33+
// if frame pointer elimination is disabled.
34+
bool XtensaFrameLowering::hasFP(const MachineFunction &MF) const {
35+
const MachineFrameInfo &MFI = MF.getFrameInfo();
36+
return MF.getTarget().Options.DisableFramePointerElim(MF) ||
37+
MFI.hasVarSizedObjects();
38+
}
39+
40+
void XtensaFrameLowering::emitPrologue(MachineFunction &MF,
41+
MachineBasicBlock &MBB) const {}
42+
43+
void XtensaFrameLowering::emitEpilogue(MachineFunction &MF,
44+
MachineBasicBlock &MBB) const {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===- XtensaFrameLowering.h - Define frame lowering for Xtensa --*- C++ -*-==//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6+
// See https://llvm.org/LICENSE.txt for license information.
7+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
//
9+
//===-----------------------------------------------------------------------==//
10+
11+
#ifndef LLVM_LIB_TARGET_XTENSA_XTENSAFRAMELOWERING_H
12+
#define LLVM_LIB_TARGET_XTENSA_XTENSAFRAMELOWERING_H
13+
14+
#include "llvm/CodeGen/TargetFrameLowering.h"
15+
16+
namespace llvm {
17+
class XtensaTargetMachine;
18+
class XtensaSubtarget;
19+
20+
class XtensaFrameLowering : public TargetFrameLowering {
21+
public:
22+
XtensaFrameLowering();
23+
24+
bool hasFP(const MachineFunction &MF) const override;
25+
26+
/// emitProlog/emitEpilog - These methods insert prolog and epilog code into
27+
/// the function.
28+
void emitPrologue(MachineFunction &, MachineBasicBlock &) const override;
29+
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
30+
};
31+
32+
} // namespace llvm
33+
34+
#endif /* LLVM_LIB_TARGET_XTENSA_XTENSAFRAMELOWERING_H */

0 commit comments

Comments
 (0)