2012-02-18 20:03:15 +08:00
|
|
|
//===-- HexagonISelLowering.h - Hexagon DAG Lowering Interface --*- C++ -*-===//
|
2011-12-13 05:14:40 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the interfaces that Hexagon uses to lower LLVM code into a
|
|
|
|
// selection DAG.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef Hexagon_ISELLOWERING_H
|
|
|
|
#define Hexagon_ISELLOWERING_H
|
|
|
|
|
2012-03-18 02:46:09 +08:00
|
|
|
#include "Hexagon.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/CodeGen/CallingConvLower.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/CallingConv.h"
|
2012-12-04 15:12:27 +08:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace HexagonISD {
|
|
|
|
enum {
|
|
|
|
FIRST_NUMBER = ISD::BUILTIN_OP_END,
|
|
|
|
|
|
|
|
CONST32,
|
|
|
|
CONST32_GP, // For marking data present in GP.
|
2013-03-08 03:10:28 +08:00
|
|
|
CONST32_Int_Real,
|
2012-05-11 04:20:25 +08:00
|
|
|
FCONST32,
|
2011-12-13 05:14:40 +08:00
|
|
|
SETCC,
|
|
|
|
ADJDYNALLOC,
|
|
|
|
ARGEXTEND,
|
|
|
|
|
|
|
|
CMPICC, // Compare two GPR operands, set icc.
|
|
|
|
CMPFCC, // Compare two FP operands, set fcc.
|
|
|
|
BRICC, // Branch to dest on icc condition
|
|
|
|
BRFCC, // Branch to dest on fcc condition
|
|
|
|
SELECT_ICC, // Select between two values using the current ICC flags.
|
|
|
|
SELECT_FCC, // Select between two values using the current FCC flags.
|
|
|
|
|
|
|
|
Hi, Lo, // Hi/Lo operations, typically on a global address.
|
|
|
|
|
|
|
|
FTOI, // FP to Int within a FP register.
|
|
|
|
ITOF, // Int to FP within a FP register.
|
|
|
|
|
|
|
|
CALL, // A call instruction.
|
|
|
|
RET_FLAG, // Return with a flag operand.
|
|
|
|
BR_JT, // Jump table.
|
|
|
|
BARRIER, // Memory barrier.
|
|
|
|
WrapperJT,
|
2012-05-11 04:20:25 +08:00
|
|
|
WrapperCP,
|
2012-12-05 02:05:01 +08:00
|
|
|
WrapperCombineII,
|
|
|
|
WrapperCombineRR,
|
2013-02-04 23:52:56 +08:00
|
|
|
WrapperCombineRI_V4,
|
|
|
|
WrapperCombineIR_V4,
|
2012-12-05 02:05:01 +08:00
|
|
|
WrapperPackhl,
|
|
|
|
WrapperSplatB,
|
|
|
|
WrapperSplatH,
|
|
|
|
WrapperShuffEB,
|
|
|
|
WrapperShuffEH,
|
|
|
|
WrapperShuffOB,
|
|
|
|
WrapperShuffOH,
|
2013-05-02 05:37:34 +08:00
|
|
|
TC_RETURN,
|
|
|
|
EH_RETURN
|
2011-12-13 05:14:40 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class HexagonTargetLowering : public TargetLowering {
|
|
|
|
int VarArgsFrameOffset; // Frame offset to start of varargs area.
|
|
|
|
|
|
|
|
bool CanReturnSmallStruct(const Function* CalleeFn,
|
|
|
|
unsigned& RetSize) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
HexagonTargetMachine &TM;
|
|
|
|
explicit HexagonTargetLowering(HexagonTargetMachine &targetmachine);
|
|
|
|
|
|
|
|
/// IsEligibleForTailCallOptimization - Check whether the call is eligible
|
|
|
|
/// for tail call optimization. Targets which want to do tail call
|
|
|
|
/// optimization should implement this function.
|
|
|
|
bool
|
|
|
|
IsEligibleForTailCallOptimization(SDValue Callee,
|
|
|
|
CallingConv::ID CalleeCC,
|
|
|
|
bool isVarArg,
|
|
|
|
bool isCalleeStructRet,
|
|
|
|
bool isCallerStructRet,
|
|
|
|
const
|
|
|
|
SmallVectorImpl<ISD::OutputArg> &Outs,
|
|
|
|
const SmallVectorImpl<SDValue> &OutVals,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
|
|
|
SelectionDAG& DAG) const;
|
|
|
|
|
|
|
|
virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const;
|
|
|
|
virtual bool isTruncateFree(EVT VT1, EVT VT2) const;
|
|
|
|
|
Refactor isInTailCallPosition handling
This change came about primarily because of two issues in the existing code.
Niether of:
define i64 @test1(i64 %val) {
%in = trunc i64 %val to i32
tail call i32 @ret32(i32 returned %in)
ret i64 %val
}
define i64 @test2(i64 %val) {
tail call i32 @ret32(i32 returned undef)
ret i32 42
}
should be tail calls, and the function sameNoopInput is responsible. The main
problem is that it is completely symmetric in the "tail call" and "ret" value,
but in reality different things are allowed on each side.
For these cases:
1. Any truncation should lead to a larger value being generated by "tail call"
than needed by "ret".
2. Undef should only be allowed as a source for ret, not as a result of the
call.
Along the way I noticed that a mismatch between what this function treats as a
valid truncation and what the backends see can lead to invalid calls as well
(see x86-32 test case).
This patch refactors the code so that instead of being based primarily on
values which it recurses into when necessary, it starts by inspecting the type
and considers each fundamental slot that the backend will see in turn. For
example, given a pathological function that returned {{}, {{}, i32, {}}, i32}
we would consider each "real" i32 in turn, and ask if it passes through
unchanged. This is much closer to what the backend sees as a result of
ComputeValueVTs.
Aside from the bug fixes, this eliminates the recursion that's going on and, I
believe, makes the bulk of the code significantly easier to understand. The
trade-off is the nasty iterators needed to find the real types inside a
returned value.
llvm-svn: 187787
2013-08-06 17:12:35 +08:00
|
|
|
virtual bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const;
|
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
|
|
|
|
virtual const char *getTargetNodeName(unsigned Opcode) const;
|
|
|
|
SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerEH_LABEL(SDValue Op, SelectionDAG &DAG) const;
|
2013-05-02 05:37:34 +08:00
|
|
|
SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
SDValue LowerFormalArguments(SDValue Chain,
|
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
2013-05-25 10:42:55 +08:00
|
|
|
SDLoc dl, SelectionDAG &DAG,
|
2011-12-13 05:14:40 +08:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const;
|
|
|
|
SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const;
|
2013-03-08 03:10:28 +08:00
|
|
|
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2012-05-26 00:35:28 +08:00
|
|
|
SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
2011-12-13 05:14:40 +08:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const;
|
|
|
|
|
|
|
|
SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
|
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
2013-05-25 10:42:55 +08:00
|
|
|
SDLoc dl, SelectionDAG &DAG,
|
2011-12-13 05:14:40 +08:00
|
|
|
SmallVectorImpl<SDValue> &InVals,
|
|
|
|
const SmallVectorImpl<SDValue> &OutVals,
|
|
|
|
SDValue Callee) const;
|
|
|
|
|
|
|
|
SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
|
|
|
|
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
|
|
|
|
SDValue LowerReturn(SDValue Chain,
|
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
|
|
|
const SmallVectorImpl<SDValue> &OutVals,
|
2013-05-25 10:42:55 +08:00
|
|
|
SDLoc dl, SelectionDAG &DAG) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
virtual MachineBasicBlock
|
|
|
|
*EmitInstrWithCustomInserter(MachineInstr *MI,
|
|
|
|
MachineBasicBlock *BB) const;
|
|
|
|
|
|
|
|
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
|
2012-05-11 04:20:25 +08:00
|
|
|
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
|
2013-11-13 09:57:54 +08:00
|
|
|
virtual EVT getSetCCResultType(LLVMContext &C, EVT VT) const {
|
|
|
|
if (!VT.isVector())
|
|
|
|
return MVT::i1;
|
|
|
|
else
|
|
|
|
return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
|
|
|
|
SDValue &Base, SDValue &Offset,
|
|
|
|
ISD::MemIndexedMode &AM,
|
|
|
|
SelectionDAG &DAG) const;
|
|
|
|
|
|
|
|
std::pair<unsigned, const TargetRegisterClass*>
|
|
|
|
getRegForInlineAsmConstraint(const std::string &Constraint,
|
2013-06-23 02:37:38 +08:00
|
|
|
MVT VT) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
// Intrinsics
|
|
|
|
virtual SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op,
|
|
|
|
SelectionDAG &DAG) const;
|
|
|
|
/// isLegalAddressingMode - Return true if the addressing mode represented
|
|
|
|
/// by AM is legal for this target, for a load/store of the specified type.
|
|
|
|
/// The type may be VoidTy, in which case only return true if the addressing
|
|
|
|
/// mode is legal for a load/store of any legal type.
|
|
|
|
/// TODO: Handle pre/postinc as well.
|
|
|
|
virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
|
2012-05-11 04:20:25 +08:00
|
|
|
virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
/// isLegalICmpImmediate - Return true if the specified immediate is legal
|
|
|
|
/// icmp immediate, that is the target has icmp instructions which can
|
|
|
|
/// compare a register against the immediate without having to materialize
|
|
|
|
/// the immediate into a register.
|
|
|
|
virtual bool isLegalICmpImmediate(int64_t Imm) const;
|
|
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // Hexagon_ISELLOWERING_H
|