Skip to content

Commit 1b09d0c

Browse files
author
Simon Moll
committed
[VE] VECustomDAG builder class
VECustomDAG's functions simplify emitting VE custom ISD nodes. The class is just a stub now. We add more functions, in particular for the VP->VVP->VE lowering, to VECustomDAG as we build up vector isel. Reviewed By: kaz7 Differential Revision: https://reviews.llvm.org/D116103
1 parent 43994e9 commit 1b09d0c

File tree

4 files changed

+116
-16
lines changed

4 files changed

+116
-16
lines changed

llvm/lib/Target/VE/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_public_tablegen_target(VECommonTableGen)
1616
add_llvm_target(VECodeGen
1717
LVLGen.cpp
1818
VEAsmPrinter.cpp
19+
VECustomDAG.cpp
1920
VEFrameLowering.cpp
2021
VEISelDAGToDAG.cpp
2122
VEISelLowering.cpp

llvm/lib/Target/VE/VECustomDAG.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===-- VECustomDAG.h - VE Custom DAG Nodes ------------*- 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 defines the interfaces that VE uses to lower LLVM code into a
10+
// selection DAG.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "VECustomDAG.h"
15+
16+
#ifndef DEBUG_TYPE
17+
#define DEBUG_TYPE "vecustomdag"
18+
#endif
19+
20+
namespace llvm {
21+
22+
SDValue VECustomDAG::getConstant(uint64_t Val, EVT VT, bool IsTarget,
23+
bool IsOpaque) const {
24+
return DAG.getConstant(Val, DL, VT, IsTarget, IsOpaque);
25+
}
26+
27+
} // namespace llvm

llvm/lib/Target/VE/VECustomDAG.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===------------ VECustomDAG.h - VE Custom DAG Nodes -----------*- 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 defines the helper functions that VE uses to lower LLVM code into a
10+
// selection DAG. For example, hiding SDLoc, and easy to use SDNodeFlags.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_LIB_TARGET_VE_VECUSTOMDAG_H
15+
#define LLVM_LIB_TARGET_VE_VECUSTOMDAG_H
16+
17+
#include "VE.h"
18+
#include "VEISelLowering.h"
19+
#include "llvm/CodeGen/SelectionDAG.h"
20+
#include "llvm/CodeGen/TargetLowering.h"
21+
22+
namespace llvm {
23+
24+
class VECustomDAG {
25+
SelectionDAG &DAG;
26+
SDLoc DL;
27+
28+
public:
29+
SelectionDAG *getDAG() const { return &DAG; }
30+
31+
VECustomDAG(SelectionDAG &DAG, SDLoc DL) : DAG(DAG), DL(DL) {}
32+
33+
VECustomDAG(SelectionDAG &DAG, SDValue WhereOp) : DAG(DAG), DL(WhereOp) {}
34+
35+
VECustomDAG(SelectionDAG &DAG, const SDNode *WhereN) : DAG(DAG), DL(WhereN) {}
36+
37+
/// getNode {
38+
SDValue getNode(unsigned OC, SDVTList VTL, ArrayRef<SDValue> OpV,
39+
Optional<SDNodeFlags> Flags = None) const {
40+
auto N = DAG.getNode(OC, DL, VTL, OpV);
41+
if (Flags)
42+
N->setFlags(*Flags);
43+
return N;
44+
}
45+
46+
SDValue getNode(unsigned OC, ArrayRef<EVT> ResVT, ArrayRef<SDValue> OpV,
47+
Optional<SDNodeFlags> Flags = None) const {
48+
auto N = DAG.getNode(OC, DL, ResVT, OpV);
49+
if (Flags)
50+
N->setFlags(*Flags);
51+
return N;
52+
}
53+
54+
SDValue getNode(unsigned OC, EVT ResVT, ArrayRef<SDValue> OpV,
55+
Optional<SDNodeFlags> Flags = None) const {
56+
auto N = DAG.getNode(OC, DL, ResVT, OpV);
57+
if (Flags)
58+
N->setFlags(*Flags);
59+
return N;
60+
}
61+
62+
SDValue getUNDEF(EVT VT) const { return DAG.getUNDEF(VT); }
63+
/// } getNode
64+
65+
SDValue getConstant(uint64_t Val, EVT VT, bool IsTarget = false,
66+
bool IsOpaque = false) const;
67+
};
68+
69+
} // namespace llvm
70+
71+
#endif // LLVM_LIB_TARGET_VE_VECUSTOMDAG_H

llvm/lib/Target/VE/VEISelLowering.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "VECustomDAG.h"
1415
#include "VEISelLowering.h"
1516
#include "MCTargetDesc/VEMCExpr.h"
1617
#include "VEInstrBuilder.h"
@@ -1640,28 +1641,28 @@ static SDValue getSplatValue(SDNode *N) {
16401641

16411642
SDValue VETargetLowering::lowerBUILD_VECTOR(SDValue Op,
16421643
SelectionDAG &DAG) const {
1643-
SDLoc DL(Op);
1644+
VECustomDAG CDAG(DAG, Op);
16441645
unsigned NumEls = Op.getValueType().getVectorNumElements();
16451646
MVT ElemVT = Op.getSimpleValueType().getVectorElementType();
16461647

16471648
// If there is just one element, expand to INSERT_VECTOR_ELT.
16481649
unsigned UniqueIdx;
16491650
if (getUniqueInsertion(Op.getNode(), UniqueIdx)) {
1650-
SDValue AccuV = DAG.getUNDEF(Op.getValueType());
1651+
SDValue AccuV = CDAG.getUNDEF(Op.getValueType());
16511652
auto ElemV = Op->getOperand(UniqueIdx);
1652-
SDValue IdxV = DAG.getConstant(UniqueIdx, DL, MVT::i64);
1653-
return DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, Op.getValueType(), AccuV,
1654-
ElemV, IdxV);
1653+
SDValue IdxV = CDAG.getConstant(UniqueIdx, MVT::i64);
1654+
return CDAG.getNode(ISD::INSERT_VECTOR_ELT, Op.getValueType(),
1655+
{AccuV, ElemV, IdxV});
16551656
}
16561657

16571658
// Else emit a broadcast.
16581659
if (SDValue ScalarV = getSplatValue(Op.getNode())) {
16591660
// lower to VEC_BROADCAST
16601661
MVT LegalResVT = MVT::getVectorVT(ElemVT, 256);
16611662

1662-
auto AVL = DAG.getConstant(NumEls, DL, MVT::i32);
1663-
return DAG.getNode(VEISD::VEC_BROADCAST, DL, LegalResVT, Op.getOperand(0),
1664-
AVL);
1663+
auto AVL = CDAG.getConstant(NumEls, MVT::i32);
1664+
return CDAG.getNode(VEISD::VEC_BROADCAST, LegalResVT,
1665+
{Op.getOperand(0), AVL});
16651666
}
16661667

16671668
// Expand
@@ -2691,7 +2692,7 @@ SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const {
26912692
const bool FromVP = ISD::isVPOpcode(Opcode);
26922693

26932694
// The representative and legalized vector type of this operation.
2694-
SDLoc DL(Op);
2695+
VECustomDAG CDAG(DAG, Op);
26952696
MVT MaskVT = MVT::v256i1; // TODO: packed mode.
26962697
EVT OpVecVT = Op.getValueType();
26972698
EVT LegalVecVT = getTypeToTransformTo(*DAG.getContext(), OpVecVT);
@@ -2708,10 +2709,10 @@ SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const {
27082709

27092710
} else {
27102711
// Materialize the VL parameter.
2711-
AVL = DAG.getConstant(OpVecVT.getVectorNumElements(), DL, MVT::i32);
2712-
SDValue ConstTrue = DAG.getConstant(1, DL, MVT::i32);
2713-
Mask = DAG.getNode(VEISD::VEC_BROADCAST, DL, MaskVT,
2714-
ConstTrue); // emit a VEISD::VEC_BROADCAST here.
2712+
AVL = CDAG.getConstant(OpVecVT.getVectorNumElements(), MVT::i32);
2713+
SDValue ConstTrue = CDAG.getConstant(1, MVT::i32);
2714+
Mask = CDAG.getNode(VEISD::VEC_BROADCAST, MaskVT,
2715+
ConstTrue); // emit a VEISD::VEC_BROADCAST here.
27152716
}
27162717

27172718
// Categories we are interested in.
@@ -2727,13 +2728,13 @@ SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const {
27272728

27282729
if (IsBinaryOp) {
27292730
assert(LegalVecVT.isSimple());
2730-
return DAG.getNode(VVPOpcode, DL, LegalVecVT, Op->getOperand(0),
2731-
Op->getOperand(1), Mask, AVL);
2731+
return CDAG.getNode(VVPOpcode, LegalVecVT,
2732+
{Op->getOperand(0), Op->getOperand(1), Mask, AVL});
27322733
} else if (VVPOpcode == VEISD::VVP_SELECT) {
27332734
auto Mask = Op->getOperand(0);
27342735
auto OnTrue = Op->getOperand(1);
27352736
auto OnFalse = Op->getOperand(2);
2736-
return DAG.getNode(VVPOpcode, DL, LegalVecVT, OnTrue, OnFalse, Mask, AVL);
2737+
return CDAG.getNode(VVPOpcode, LegalVecVT, {OnTrue, OnFalse, Mask, AVL});
27372738
}
27382739
llvm_unreachable("lowerToVVP called for unexpected SDNode.");
27392740
}

0 commit comments

Comments
 (0)