OpenASIP  2.0
TCEISelLowering.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file TCETargetLowering.h
26  *
27  * Declaration of TCETargetLowering class.
28  *
29  * @author Veli-Pekka J��skel�inen 2007 (vjaaskel-no.spam-cs.tut.fi)
30  * @author Mikael Lepist� 2009 (mikael.lepisto-no.spam-tut.fi)
31  */
32 
33 #ifndef TCE_TARGET_LOWERING_H
34 #define TCE_TARGET_LOWERING_H
35 
36 #include <llvm/CodeGen/TargetLowering.h>
37 #include "TCEPlugin.hh"
38 #include "TCESubtarget.hh"
39 #include "tce_config.h"
40 #include "TCEString.hh"
41 #include <map>
42 #include <iostream>
43 
44 namespace TCEISD {
45  enum {
46  FIRST_NUMBER = llvm::ISD::BUILTIN_OP_END,
55 
59 
60  Hi, Lo, // Hi/Lo operations, typically on a global address.
61 
62  FTOI, // FP to Int within a FP register.
63  ITOF, // Int to FP within a FP register.
64 
65  CALL, // A call instruction.
66  RET_FLAG , // Return with a flag operand.
71  };
72 }
73 
74 namespace llvm {
75 
76 #define SDLOC_PARAM_TYPE const SDLoc&
77 
78  class TCETargetMachine;
79 
80  /**
81  * Lowers LLVM code to SelectionDAG for the TCE backend.
82  */
83  class TCETargetLowering : public llvm::TargetLowering {
84  mutable int VarArgsFrameOffset; // Frame offset to start of varargs area.
85  public:
86  TCETargetLowering(TargetMachine &TM, const TCESubtarget &subt);
87 
88  virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
89  virtual SDValue PerformDAGCombine(
90  SDNode *N, DAGCombinerInfo &DCI) const override;
91 
92  int getVarArgsFrameOffset() const /* override */ { return VarArgsFrameOffset; }
93 
94  virtual const char* getTargetNodeName(unsigned opcode) const override;
95 
96  ConstraintType getConstraintType(StringRef Constraint) const override;
97  std::pair<unsigned, const TargetRegisterClass *>
98  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
99  StringRef Constraint, MVT VT) const override;
100 
102  SDValue Op,
103  std::string& Constraint,
104  std::vector<SDValue>& Ops,
105  SelectionDAG& DAG) const override;
106 
107  //TODO: this is from some old version - which?
108  std::vector<unsigned>
109  getRegClassForInlineAsmConstraint(const std::string &Constraint,
110  EVT VT) const;
111  virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
112 
113  /// getFunctionAlignment - Return the Log2 alignment of this function.
114 
115  virtual SDValue
116  LowerFormalArguments(SDValue Chain,
117  CallingConv::ID CallConv,
118  bool isVarArg,
119  const SmallVectorImpl<ISD::InputArg> &Ins,
120  SDLOC_PARAM_TYPE dl, SelectionDAG &DAG,
121  SmallVectorImpl<SDValue> &InVals) const override;
122 
123  SDValue LowerTRAP(SDValue Op, SelectionDAG &DAG) const;
124  SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
125  SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
126  SDValue LowerConstant(SDValue Op, SelectionDAG &DAG) const;
127  SDValue LowerBuildVector(SDValue Op, SelectionDAG &DAG) const;
128  SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
129  SDValue LowerShift(SDValue op, SelectionDAG& dag) const;
131  SDValue Op, MVT newElementVT, int elemCount, SelectionDAG &DAG) const;
132  SDValue lowerHWLoops(SDValue op, SelectionDAG &dag) const;
133 
134  SDValue lowerExtOrBoolLoad(SDValue op, SelectionDAG& DAG) const;
135 
136  std::pair<int, TCEString> getConstShiftNodeAndTCEOP(SDValue op) const;
137 
138  virtual SDValue
139  LowerCall(TargetLowering::CallLoweringInfo &CLI,
140  SmallVectorImpl<SDValue> &InVals) const override;
141 
142  virtual SDValue
143  LowerReturn(SDValue Chain,
144  CallingConv::ID CallConv, bool isVarArg,
145  const SmallVectorImpl<ISD::OutputArg> &Outs,
146  const SmallVectorImpl<SDValue> &OutVals,
147  SDLOC_PARAM_TYPE dl, SelectionDAG &DAG) const override;
148 
149  bool isConstantOrUndefBuild(const SDNode& node) const;
150  bool canEncodeConstantOperands(const SDNode& node) const;
151  bool canEncodeImmediate(const ConstantSDNode& node) const;
152 
153  bool shouldLoadFromConstantPool(unsigned addressSpace) const;
154 
155 // virtual bool allowsMisalignedMemoryAccesses(EVT VT, unsigned as, unsigned align, MachineMemOperand::Flags flags, bool* ) const override;
156  // We can ignore the bitwidth differences between the pointers
157  // for now. It's the programmer's responsibility to ensure they
158  // fit.
159  // ----------------------------------------------------
160  //
161  // Below here TCE specific stuff is added, which is not copied from Sparc
162  //
163  // ----------------------------------------------------
164 
165  SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
166 
167  static bool isBroadcast(SDNode *n);
168 
169  private:
170 
171  bool hasI1RegisterClass() const;
172 
173  /// Tells if the target machine has boolean register file.
174  bool hasI1RC_ = false;
175 
177 
178  /// Predicates to tell whenever the addresses belonging to a address
179  /// space should be loaded from constant pool instead of immediates.
180  /// Address space as index maps to the predicate.
181  std::map<unsigned, bool> loadGAFromConstantPool_;
182 
183  const TargetRegisterClass*
185  const TargetRegisterInfo* TRI, MVT VT) const;
186 
187  /// Implementation generated to Backend.inc from TDGenSIMD.cc.
189 
190  /// Implementation generated to Backend.inc from TDGenSIMD.cc.
191  std::pair<unsigned, const TargetRegisterClass *>
192  associatedVectorRegClass(const EVT &vt) const;
193 
194  /// Implementation generated to Backend.inc from TDGenSIMD.cc.
195  virtual llvm::EVT getSetCCResultVT(const EVT &VT) const;
196 
197  /// Implementation generated to Backend.inc from TDGenSIMD.cc.
198  void addVectorLowerings();
199 
200  public:
201  llvm::EVT getSetCCResultType(
202  const DataLayout &DL, LLVMContext &Context,
203  EVT VT) const override;
204 
205  virtual bool isFPImmLegal(
206  const APFloat& apf, EVT VT, bool forCodeSize) const override;
207 
208  SDValue ExpandLibCall(
209  RTLIB::Libcall LC, SDNode *Node, bool isSigned, SelectionDAG &DAG)
210  const;
211 
212  void ReplaceNodeResults(SDNode * node,
213  SmallVectorImpl< SDValue > &,
214  SelectionDAG &) const override;
215 
216  };
217 }
218 
219 #endif
TCEISD::SELECT_F64
@ SELECT_F64
Definition: TCEISelLowering.hh:54
llvm::TCETargetLowering::PerformDAGCombine
virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
Definition: TCEISelLowering.cc:1441
llvm::TCETargetLowering::LowerVASTART
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:1160
llvm
Definition: InlineAsmParser.hh:49
TCEISD::SELECT_I8
@ SELECT_I8
Definition: TCEISelLowering.hh:48
TCEISD::SELECT_F32
@ SELECT_F32
Definition: TCEISelLowering.hh:53
TCEISD::FIRST_NUMBER
@ FIRST_NUMBER
Definition: TCEISelLowering.hh:46
TCEISD::SRA_Const
@ SRA_Const
Definition: TCEISelLowering.hh:68
llvm::TCETargetLowering::LowerBlockAddress
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:956
llvm::TCETargetLowering::LowerAsmOperandForConstraint
void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
Definition: TCEISelLowering.cc:1620
TCEISD::SELECT_I64
@ SELECT_I64
Definition: TCEISelLowering.hh:51
llvm::TCETargetLowering::isConstantOrUndefBuild
bool isConstantOrUndefBuild(const SDNode &node) const
Definition: TCEISelLowering.cc:1679
llvm::TCESubtarget
Definition: TCESubtarget.hh:56
llvm::TCETargetLowering::getSetCCResultType
llvm::EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Definition: TCEISelLowering.cc:1183
TCEISD::Hi
@ Hi
Definition: TCEISelLowering.hh:60
llvm::TCETargetLowering::isFPImmLegal
virtual bool isFPImmLegal(const APFloat &apf, EVT VT, bool forCodeSize) const override
Definition: TCEISelLowering.cc:1773
llvm::TCETargetLowering::LowerFormalArguments
virtual SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, SDLOC_PARAM_TYPE dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
getFunctionAlignment - Return the Log2 alignment of this function.
Definition: TCEISelLowering.cc:145
llvm::TCETargetLowering::lowerExtOrBoolLoad
SDValue lowerExtOrBoolLoad(SDValue op, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:1982
llvm::TCETargetLowering::LowerConstant
SDValue LowerConstant(SDValue Op, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:985
TCEISD::SHL_Const
@ SHL_Const
Definition: TCEISelLowering.hh:70
llvm::TCETargetLowering::LowerBuildVector
SDValue LowerBuildVector(SDValue Op, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:1033
llvm::TCETargetLowering::isBroadcast
static bool isBroadcast(SDNode *n)
Definition: TCEISelLowering.cc:1782
TCEISD::RET_FLAG
@ RET_FLAG
Definition: TCEISelLowering.hh:66
TCEString.hh
llvm::TCETargetLowering::LowerShift
SDValue LowerShift(SDValue op, SelectionDAG &dag) const
Definition: TCEISelLowering.cc:1274
llvm::TCETargetLowering::addVectorRegisterClasses
void addVectorRegisterClasses()
Implementation generated to Backend.inc from TDGenSIMD.cc.
TCEISD::CALL
@ CALL
Definition: TCEISelLowering.hh:65
llvm::TCETargetLowering::LowerTRAP
SDValue LowerTRAP(SDValue Op, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:893
llvm::TCETargetLowering::LowerReturn
virtual SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, SDLOC_PARAM_TYPE dl, SelectionDAG &DAG) const override
Definition: TCEISelLowering.cc:97
llvm::TCETargetLowering::LowerINLINEASM
SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const
llvm::TCETargetLowering::canEncodeImmediate
bool canEncodeImmediate(const ConstantSDNode &node) const
Definition: TCEISelLowering.cc:1709
TCEISD::Lo
@ Lo
Definition: TCEISelLowering.hh:60
TCEISD::SELECT_I32
@ SELECT_I32
Definition: TCEISelLowering.hh:50
llvm::TCETargetLowering::TCETargetLowering
TCETargetLowering(TargetMachine &TM, const TCESubtarget &subt)
Definition: TCEISelLowering.cc:528
llvm::TCETargetLowering::associatedVectorRegClass
std::pair< unsigned, const TargetRegisterClass * > associatedVectorRegClass(const EVT &vt) const
Implementation generated to Backend.inc from TDGenSIMD.cc.
llvm::TCETargetLowering::addVectorLowerings
void addVectorLowerings()
Implementation generated to Backend.inc from TDGenSIMD.cc.
llvm::TCETargetLowering::isOffsetFoldingLegal
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Definition: TCEISelLowering.cc:1661
TCEISD::SELECT_I1
@ SELECT_I1
Definition: TCEISelLowering.hh:47
llvm::TCETargetLowering::ExpandLibCall
SDValue ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:1803
llvm::TCETargetLowering::getRegClassForInlineAsmConstraint
std::vector< unsigned > getRegClassForInlineAsmConstraint(const std::string &Constraint, EVT VT) const
Definition: TCEISelLowering.cc:1644
llvm::TCETargetLowering::getVectorRegClassForInlineAsmConstraint
const TargetRegisterClass * getVectorRegClassForInlineAsmConstraint(const TargetRegisterInfo *TRI, MVT VT) const
Definition: TCEISelLowering.cc:1519
llvm::TCETargetLowering::tm_
TCETargetMachine & tm_
Definition: TCEISelLowering.hh:176
llvm::TCETargetLowering::loadGAFromConstantPool_
std::map< unsigned, bool > loadGAFromConstantPool_
Predicates to tell whenever the addresses belonging to a address space should be loaded from constant...
Definition: TCEISelLowering.hh:181
llvm::TCETargetLowering::lowerHWLoops
SDValue lowerHWLoops(SDValue op, SelectionDAG &dag) const
Definition: TCEISelLowering.cc:1340
llvm::TCETargetLowering::ReplaceNodeResults
void ReplaceNodeResults(SDNode *node, SmallVectorImpl< SDValue > &, SelectionDAG &) const override
Definition: TCEISelLowering.cc:1860
llvm::TCETargetLowering::LowerCall
virtual SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
Definition: TCEISelLowering.cc:323
TCEISD
Definition: TCEISelLowering.hh:44
TCEISD::CONST_POOL
@ CONST_POOL
Definition: TCEISelLowering.hh:56
TCEISD::BLOCK_ADDR
@ BLOCK_ADDR
Definition: TCEISelLowering.hh:58
llvm::TCETargetLowering::getRegForInlineAsmConstraint
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Definition: TCEISelLowering.cc:1544
llvm::TCETargetLowering
Definition: TCEISelLowering.hh:83
TCEISD::SELECT_F16
@ SELECT_F16
Definition: TCEISelLowering.hh:52
llvm::TCETargetLowering::getSetCCResultVT
virtual llvm::EVT getSetCCResultVT(const EVT &VT) const
Implementation generated to Backend.inc from TDGenSIMD.cc.
TCEPlugin.hh
llvm::TCETargetLowering::LowerOperation
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
Definition: TCEISelLowering.cc:1414
TCEISD::SRL_Const
@ SRL_Const
Definition: TCEISelLowering.hh:69
TCEISD::SELECT_I16
@ SELECT_I16
Definition: TCEISelLowering.hh:49
llvm::TCETargetLowering::getTargetNodeName
virtual const char * getTargetNodeName(unsigned opcode) const override
Definition: TCEISelLowering.cc:873
llvm::TCETargetLowering::getConstraintType
ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target.
Definition: TCEISelLowering.cc:1508
llvm::TCETargetMachine
Definition: TCETargetMachine.hh:106
llvm::TCETargetLowering::hasI1RegisterClass
bool hasI1RegisterClass() const
Definition: TCEISelLowering.cc:1756
llvm::TCETargetLowering::canEncodeConstantOperands
bool canEncodeConstantOperands(const SDNode &node) const
Definition: TCEISelLowering.cc:1694
llvm::TCETargetLowering::getVarArgsFrameOffset
int getVarArgsFrameOffset() const
Definition: TCEISelLowering.hh:92
llvm::TCETargetLowering::getConstShiftNodeAndTCEOP
std::pair< int, TCEString > getConstShiftNodeAndTCEOP(SDValue op) const
Definition: TCEISelLowering.cc:1260
TCEISD::FTOI
@ FTOI
Definition: TCEISelLowering.hh:62
TCEISD::RET_FLAG_old
@ RET_FLAG_old
Definition: TCEISelLowering.hh:67
llvm::TCETargetLowering::LowerBuildBooleanVectorVector
SDValue LowerBuildBooleanVectorVector(SDValue Op, MVT newElementVT, int elemCount, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:1004
llvm::TCETargetLowering::hasI1RC_
bool hasI1RC_
Tells if the target machine has boolean register file.
Definition: TCEISelLowering.hh:174
TCEISD::ITOF
@ ITOF
Definition: TCEISelLowering.hh:63
llvm::TCETargetLowering::VarArgsFrameOffset
int VarArgsFrameOffset
Definition: TCEISelLowering.hh:84
llvm::TCETargetLowering::shouldLoadFromConstantPool
bool shouldLoadFromConstantPool(unsigned addressSpace) const
Definition: TCEISelLowering.cc:1742
TCESubtarget.hh
SDLOC_PARAM_TYPE
#define SDLOC_PARAM_TYPE
Definition: TCEISelLowering.hh:76
llvm::TCETargetLowering::LowerGLOBALADDRESS
SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const
Definition: TCEISelLowering.cc:923
TCEISD::GLOBAL_ADDR
@ GLOBAL_ADDR
Definition: TCEISelLowering.hh:57