Skip to content

Commit 064859b

Browse files
kaz7Simon Moll
authored andcommitted
[VE] Minimal codegen for empty functions
Summary: This patch implements minimal VE code generation for empty function bodies (no args, no value return). Contents * empty function code generation test. * Minimal function prologue & epilogue emission * Instruction formats and instruction definitions as far as required for the empty function prologue & epilogue. * I64 register class definitions. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D72598
1 parent be8f217 commit 064859b

37 files changed

+2581
-18
lines changed

llvm/lib/Target/VE/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
set(LLVM_TARGET_DEFINITIONS VE.td)
22

3+
tablegen(LLVM VEGenRegisterInfo.inc -gen-register-info)
4+
tablegen(LLVM VEGenInstrInfo.inc -gen-instr-info)
5+
tablegen(LLVM VEGenAsmWriter.inc -gen-asm-writer)
6+
tablegen(LLVM VEGenDAGISel.inc -gen-dag-isel)
7+
tablegen(LLVM VEGenSubtargetInfo.inc -gen-subtarget)
8+
tablegen(LLVM VEGenCallingConv.inc -gen-callingconv)
9+
add_public_tablegen_target(VECommonTableGen)
10+
311
add_llvm_target(VECodeGen
12+
VEAsmPrinter.cpp
13+
VEFrameLowering.cpp
14+
VEISelDAGToDAG.cpp
15+
VEISelLowering.cpp
16+
VEInstrInfo.cpp
17+
VEMCInstLower.cpp
18+
VERegisterInfo.cpp
19+
VESubtarget.cpp
420
VETargetMachine.cpp
521
)
622

23+
add_subdirectory(InstPrinter)
724
add_subdirectory(TargetInfo)
825
add_subdirectory(MCTargetDesc)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_llvm_component_library(LLVMVEAsmPrinter
2+
VEInstPrinter.cpp
3+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;===- ./lib/Target/VE/InstPrinter/LLVMBuild.txt ----------------*- Conf -*--===;
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 is an LLVMBuild description file for the components in this subdirectory.
10+
;
11+
; For more information on the LLVMBuild system, please see:
12+
;
13+
; http://llvm.org/docs/LLVMBuild.html
14+
;
15+
;===------------------------------------------------------------------------===;
16+
17+
[component_0]
18+
type = Library
19+
name = VEAsmPrinter
20+
parent = VE
21+
required_libraries = MC Support
22+
add_to_library_groups = VE
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//===-- VEInstPrinter.cpp - Convert VE MCInst to assembly syntax -----------==//
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 class prints an VE MCInst to a .s file.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "VEInstPrinter.h"
14+
#include "VE.h"
15+
#include "llvm/MC/MCExpr.h"
16+
#include "llvm/MC/MCInst.h"
17+
#include "llvm/MC/MCRegisterInfo.h"
18+
#include "llvm/MC/MCSubtargetInfo.h"
19+
#include "llvm/MC/MCSymbol.h"
20+
#include "llvm/Support/raw_ostream.h"
21+
22+
using namespace llvm;
23+
24+
#define DEBUG_TYPE "ve-asmprinter"
25+
26+
// The generated AsmMatcher VEGenAsmWriter uses "VE" as the target
27+
// namespace.
28+
namespace llvm {
29+
namespace VE {
30+
using namespace VE;
31+
}
32+
} // namespace llvm
33+
34+
#define GET_INSTRUCTION_NAME
35+
#define PRINT_ALIAS_INSTR
36+
#include "VEGenAsmWriter.inc"
37+
38+
void VEInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
39+
OS << '%' << StringRef(getRegisterName(RegNo)).lower();
40+
}
41+
42+
void VEInstPrinter::printInst(const MCInst *MI, uint64_t Address,
43+
StringRef Annot, const MCSubtargetInfo &STI,
44+
raw_ostream &OS) {
45+
if (!printAliasInstr(MI, STI, OS))
46+
printInstruction(MI, Address, STI, OS);
47+
printAnnotation(OS, Annot);
48+
}
49+
50+
void VEInstPrinter::printOperand(const MCInst *MI, int opNum,
51+
const MCSubtargetInfo &STI, raw_ostream &O) {
52+
const MCOperand &MO = MI->getOperand(opNum);
53+
54+
if (MO.isReg()) {
55+
printRegName(O, MO.getReg());
56+
return;
57+
}
58+
59+
if (MO.isImm()) {
60+
switch (MI->getOpcode()) {
61+
default:
62+
// Expects signed 32bit literals
63+
assert(isInt<32>(MO.getImm()) && "Immediate too large");
64+
int32_t TruncatedImm = static_cast<int32_t>(MO.getImm());
65+
O << TruncatedImm;
66+
return;
67+
}
68+
}
69+
70+
assert(MO.isExpr() && "Unknown operand kind in printOperand");
71+
MO.getExpr()->print(O, &MAI);
72+
}
73+
74+
void VEInstPrinter::printMemASXOperand(const MCInst *MI, int opNum,
75+
const MCSubtargetInfo &STI,
76+
raw_ostream &O, const char *Modifier) {
77+
// If this is an ADD operand, emit it like normal operands.
78+
if (Modifier && !strcmp(Modifier, "arith")) {
79+
printOperand(MI, opNum, STI, O);
80+
O << ", ";
81+
printOperand(MI, opNum + 1, STI, O);
82+
return;
83+
}
84+
85+
const MCOperand &MO = MI->getOperand(opNum + 1);
86+
if (!MO.isImm() || MO.getImm() != 0) {
87+
printOperand(MI, opNum + 1, STI, O);
88+
}
89+
O << "(,";
90+
printOperand(MI, opNum, STI, O);
91+
O << ")";
92+
}
93+
94+
void VEInstPrinter::printMemASOperand(const MCInst *MI, int opNum,
95+
const MCSubtargetInfo &STI,
96+
raw_ostream &O, const char *Modifier) {
97+
// If this is an ADD operand, emit it like normal operands.
98+
if (Modifier && !strcmp(Modifier, "arith")) {
99+
printOperand(MI, opNum, STI, O);
100+
O << ", ";
101+
printOperand(MI, opNum + 1, STI, O);
102+
return;
103+
}
104+
105+
const MCOperand &MO = MI->getOperand(opNum + 1);
106+
if (!MO.isImm() || MO.getImm() != 0) {
107+
printOperand(MI, opNum + 1, STI, O);
108+
}
109+
O << "(";
110+
printOperand(MI, opNum, STI, O);
111+
O << ")";
112+
}
113+
114+
void VEInstPrinter::printCCOperand(const MCInst *MI, int opNum,
115+
const MCSubtargetInfo &STI, raw_ostream &O) {
116+
int CC = (int)MI->getOperand(opNum).getImm();
117+
O << VECondCodeToString((VECC::CondCodes)CC);
118+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===-- VEInstPrinter.h - Convert VE MCInst to assembly syntax ------------===//
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 class prints an VE MCInst to a .s file.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_VE_INSTPRINTER_VEINSTPRINTER_H
14+
#define LLVM_LIB_TARGET_VE_INSTPRINTER_VEINSTPRINTER_H
15+
16+
#include "llvm/MC/MCInstPrinter.h"
17+
18+
namespace llvm {
19+
20+
class VEInstPrinter : public MCInstPrinter {
21+
public:
22+
VEInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
23+
const MCRegisterInfo &MRI)
24+
: MCInstPrinter(MAI, MII, MRI) {}
25+
26+
void printRegName(raw_ostream &OS, unsigned RegNo) const override;
27+
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
28+
const MCSubtargetInfo &STI, raw_ostream &OS) override;
29+
30+
// Autogenerated by tblgen.
31+
bool printAliasInstr(const MCInst *, const MCSubtargetInfo &, raw_ostream &);
32+
void printInstruction(const MCInst *, uint64_t, const MCSubtargetInfo &,
33+
raw_ostream &);
34+
static const char *getRegisterName(unsigned RegNo);
35+
36+
void printOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI,
37+
raw_ostream &OS);
38+
void printMemASXOperand(const MCInst *MI, int opNum,
39+
const MCSubtargetInfo &STI, raw_ostream &OS,
40+
const char *Modifier = nullptr);
41+
void printMemASOperand(const MCInst *MI, int opNum,
42+
const MCSubtargetInfo &STI, raw_ostream &OS,
43+
const char *Modifier = nullptr);
44+
void printCCOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI,
45+
raw_ostream &OS);
46+
};
47+
} // namespace llvm
48+
49+
#endif

llvm/lib/Target/VE/LLVMBuild.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
;===------------------------------------------------------------------------===;
1616

1717
[common]
18-
subdirectories = MCTargetDesc TargetInfo
18+
subdirectories = InstPrinter MCTargetDesc TargetInfo
1919

2020
[component_0]
2121
type = TargetGroup
2222
name = VE
2323
parent = Target
2424
has_asmparser = 0
25-
has_asmprinter = 0
25+
has_asmprinter = 1
2626

2727
[component_1]
2828
type = Library
2929
name = VECodeGen
3030
parent = VE
31-
required_libraries = Analysis AsmPrinter CodeGen Core MC SelectionDAG
31+
required_libraries = Analysis AsmPrinter CodeGen Core
32+
MC SelectionDAG VEAsmPrinter
3233
VEDesc VEInfo Support Target
3334
add_to_library_groups = VE
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
add_llvm_library(LLVMVEDesc
1+
add_llvm_component_library(LLVMVEDesc
2+
VEMCAsmInfo.cpp
23
VEMCTargetDesc.cpp
4+
VETargetStreamer.cpp
35
)

llvm/lib/Target/VE/MCTargetDesc/LLVMBuild.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
type = Library
1919
name = VEDesc
2020
parent = VE
21-
required_libraries = MC VEInfo Support
21+
required_libraries = MC VEAsmPrinter VEInfo Support
2222
add_to_library_groups = VE
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===- VEMCAsmInfo.cpp - VE asm properties --------------------------------===//
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 contains the declarations of the VEMCAsmInfo properties.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "VEMCAsmInfo.h"
14+
#include "llvm/ADT/Triple.h"
15+
#include "llvm/BinaryFormat/Dwarf.h"
16+
#include "llvm/MC/MCExpr.h"
17+
#include "llvm/MC/MCStreamer.h"
18+
#include "llvm/MC/MCTargetOptions.h"
19+
20+
using namespace llvm;
21+
22+
void VEELFMCAsmInfo::anchor() {}
23+
24+
VEELFMCAsmInfo::VEELFMCAsmInfo(const Triple &TheTriple) {
25+
26+
CodePointerSize = CalleeSaveStackSlotSize = 8;
27+
MaxInstLength = MinInstAlignment = 8;
28+
29+
// VE uses ".*byte" directive for unaligned data.
30+
Data8bitsDirective = "\t.byte\t";
31+
Data16bitsDirective = "\t.2byte\t";
32+
Data32bitsDirective = "\t.4byte\t";
33+
Data64bitsDirective = "\t.8byte\t";
34+
35+
// Uses '.section' before '.bss' directive. VE requires this although
36+
// assembler manual says sinple '.bss' is supported.
37+
UsesELFSectionDirectiveForBSS = true;
38+
39+
SupportsDebugInformation = true;
40+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===- VEMCAsmInfo.h - VE asm properties -----------------------*- C++ -*--===//
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 contains the declaration of the VEMCAsmInfo class.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_VE_MCTARGETDESC_VEMCASMINFO_H
14+
#define LLVM_LIB_TARGET_VE_MCTARGETDESC_VEMCASMINFO_H
15+
16+
#include "llvm/MC/MCAsmInfoELF.h"
17+
18+
namespace llvm {
19+
20+
class Triple;
21+
22+
class VEELFMCAsmInfo : public MCAsmInfoELF {
23+
void anchor() override;
24+
25+
public:
26+
explicit VEELFMCAsmInfo(const Triple &TheTriple);
27+
};
28+
29+
} // namespace llvm
30+
31+
#endif // LLVM_LIB_TARGET_VE_MCTARGETDESC_VEMCASMINFO_H

0 commit comments

Comments
 (0)