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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
|
|
|
|
#define LLVM_LIB_TARGET_HEXAGON_HEXAGONISELLOWERING_H
|
2011-12-13 05:14:40 +08:00
|
|
|
|
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 {
|
2014-12-09 05:19:18 +08:00
|
|
|
|
|
|
|
// Return true when the given node fits in a positive half word.
|
|
|
|
bool isPositiveHalfWord(SDNode *N);
|
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
namespace HexagonISD {
|
2015-05-08 05:33:59 +08:00
|
|
|
enum NodeType : unsigned {
|
2015-04-23 05:17:00 +08:00
|
|
|
OP_BEGIN = ISD::BUILTIN_OP_END,
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-04-23 05:17:00 +08:00
|
|
|
CONST32 = OP_BEGIN,
|
2011-12-13 05:14:40 +08:00
|
|
|
CONST32_GP, // For marking data present in GP.
|
2012-05-11 04:20:25 +08:00
|
|
|
FCONST32,
|
2015-04-23 00:43:53 +08:00
|
|
|
ALLOCA,
|
2011-12-13 05:14:40 +08:00
|
|
|
ARGEXTEND,
|
|
|
|
|
2015-03-11 04:04:44 +08:00
|
|
|
PIC_ADD,
|
|
|
|
AT_GOT,
|
|
|
|
AT_PCREL,
|
|
|
|
|
2015-01-17 01:05:27 +08:00
|
|
|
CALLv3, // A V3+ call instruction.
|
|
|
|
CALLv3nr, // A V3+ call instruction that doesn't return.
|
|
|
|
CALLR,
|
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
RET_FLAG, // Return with a flag operand.
|
2015-03-20 00:33:08 +08:00
|
|
|
BR_JT, // Branch through jump table.
|
|
|
|
BARRIER, // Memory barrier.
|
|
|
|
JT, // Jump table.
|
|
|
|
CP, // Constant pool.
|
2015-04-23 05:17:00 +08:00
|
|
|
|
2015-01-08 04:07:28 +08:00
|
|
|
POPCOUNT,
|
2014-12-06 02:24:06 +08:00
|
|
|
COMBINE,
|
2015-03-10 02:34:05 +08:00
|
|
|
PACKHL,
|
2015-03-20 00:33:08 +08:00
|
|
|
VSPLATB,
|
|
|
|
VSPLATH,
|
|
|
|
SHUFFEB,
|
|
|
|
SHUFFEH,
|
|
|
|
SHUFFOB,
|
|
|
|
SHUFFOH,
|
|
|
|
VSXTBH,
|
|
|
|
VSXTBW,
|
|
|
|
VSRAW,
|
|
|
|
VSRAH,
|
|
|
|
VSRLW,
|
|
|
|
VSRLH,
|
|
|
|
VSHLW,
|
|
|
|
VSHLH,
|
|
|
|
VCMPBEQ,
|
|
|
|
VCMPBGT,
|
|
|
|
VCMPBGTU,
|
|
|
|
VCMPHEQ,
|
|
|
|
VCMPHGT,
|
|
|
|
VCMPHGTU,
|
|
|
|
VCMPWEQ,
|
|
|
|
VCMPWGT,
|
|
|
|
VCMPWGTU,
|
2015-04-23 05:17:00 +08:00
|
|
|
|
|
|
|
INSERT,
|
|
|
|
INSERTRP,
|
|
|
|
EXTRACTU,
|
|
|
|
EXTRACTURP,
|
2013-05-02 05:37:34 +08:00
|
|
|
TC_RETURN,
|
2015-01-07 03:03:20 +08:00
|
|
|
EH_RETURN,
|
2015-04-23 05:17:00 +08:00
|
|
|
DCFETCH,
|
|
|
|
|
|
|
|
OP_END
|
2011-12-13 05:14:40 +08:00
|
|
|
};
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-02-03 06:11:36 +08:00
|
|
|
class HexagonSubtarget;
|
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
class HexagonTargetLowering : public TargetLowering {
|
|
|
|
int VarArgsFrameOffset; // Frame offset to start of varargs area.
|
|
|
|
|
2015-04-23 05:17:00 +08:00
|
|
|
bool CanReturnSmallStruct(const Function* CalleeFn, unsigned& RetSize)
|
|
|
|
const;
|
2015-03-20 00:33:08 +08:00
|
|
|
void promoteLdStType(EVT VT, EVT PromotedLdStVT);
|
2015-04-23 05:17:00 +08:00
|
|
|
const HexagonTargetMachine &HTM;
|
|
|
|
const HexagonSubtarget &Subtarget;
|
2015-03-20 00:33:08 +08:00
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
public:
|
2015-02-03 06:11:36 +08:00
|
|
|
explicit HexagonTargetLowering(const TargetMachine &TM,
|
2015-04-23 05:17:00 +08:00
|
|
|
const HexagonSubtarget &ST);
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
/// IsEligibleForTailCallOptimization - Check whether the call is eligible
|
|
|
|
/// for tail call optimization. Targets which want to do tail call
|
|
|
|
/// optimization should implement this function.
|
2015-04-23 05:17:00 +08:00
|
|
|
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;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
|
|
|
|
bool isTruncateFree(EVT VT1, EVT VT2) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
|
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
|
|
|
|
2015-03-20 00:33:08 +08:00
|
|
|
// Should we expand the build vector with shuffles?
|
|
|
|
bool shouldExpandBuildVectorWithShuffles(EVT VT,
|
2015-04-23 05:17:00 +08:00
|
|
|
unsigned DefinedValues) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-03-20 00:33:08 +08:00
|
|
|
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
|
2014-04-29 15:58:16 +08:00
|
|
|
const char *getTargetNodeName(unsigned Opcode) const override;
|
2015-03-20 00:33:08 +08:00
|
|
|
SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerEXTRACT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerINSERT_VECTOR(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
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;
|
2015-04-23 05:17:00 +08:00
|
|
|
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
|
|
|
|
bool isVarArg, const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc dl,
|
|
|
|
SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
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,
|
2015-04-23 05:17:00 +08:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
|
2015-04-23 05:17:00 +08:00
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc dl,
|
|
|
|
SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals,
|
|
|
|
const SmallVectorImpl<SDValue> &OutVals, SDValue Callee) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-03-20 00:33:08 +08:00
|
|
|
SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerCTPOP(SDValue Op, SelectionDAG &DAG) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
|
|
|
|
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
|
2015-03-20 00:33:08 +08:00
|
|
|
SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-04-23 05:17:00 +08:00
|
|
|
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv,
|
|
|
|
bool isVarArg, const SmallVectorImpl<ISD::OutputArg> &Outs,
|
|
|
|
const SmallVectorImpl<SDValue> &OutVals, SDLoc dl,
|
|
|
|
SelectionDAG &DAG) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-04-23 05:17:00 +08:00
|
|
|
bool mayBeEmittedAsTailCall(CallInst *CI) const override;
|
|
|
|
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr *MI,
|
|
|
|
MachineBasicBlock *BB) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-04-23 05:17:00 +08:00
|
|
|
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
|
2015-07-09 10:09:04 +08:00
|
|
|
EVT getSetCCResultType(const DataLayout &, LLVMContext &C,
|
|
|
|
EVT VT) const override {
|
2013-11-13 09:57:54 +08:00
|
|
|
if (!VT.isVector())
|
|
|
|
return MVT::i1;
|
|
|
|
else
|
|
|
|
return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
|
|
|
|
SDValue &Base, SDValue &Offset,
|
|
|
|
ISD::MemIndexedMode &AM,
|
|
|
|
SelectionDAG &DAG) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-02-27 06:38:43 +08:00
|
|
|
std::pair<unsigned, const TargetRegisterClass *>
|
|
|
|
getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
|
2015-07-06 03:29:18 +08:00
|
|
|
StringRef Constraint, MVT VT) const override;
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-07-06 03:29:18 +08:00
|
|
|
unsigned
|
|
|
|
getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
|
2015-03-17 22:37:39 +08:00
|
|
|
if (ConstraintCode == "o")
|
|
|
|
return InlineAsm::Constraint_o;
|
|
|
|
else if (ConstraintCode == "v")
|
|
|
|
return InlineAsm::Constraint_v;
|
|
|
|
return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
|
2015-03-16 21:13:41 +08:00
|
|
|
}
|
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
// Intrinsics
|
2014-04-29 15:58:16 +08:00
|
|
|
SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
|
2011-12-13 05:14:40 +08:00
|
|
|
/// 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.
|
2015-07-09 10:09:40 +08:00
|
|
|
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
|
|
|
|
Type *Ty, unsigned AS) const override;
|
2014-04-29 15:58:16 +08:00
|
|
|
bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
|
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.
|
2014-04-29 15:58:16 +08:00
|
|
|
bool isLegalICmpImmediate(int64_t Imm) const override;
|
2015-07-09 22:51:21 +08:00
|
|
|
|
|
|
|
// Handling of atomic RMW instructions.
|
|
|
|
Value *emitLoadLinked(IRBuilder<> &Builder, Value *Addr,
|
|
|
|
AtomicOrdering Ord) const override;
|
|
|
|
Value *emitStoreConditional(IRBuilder<> &Builder, Value *Val,
|
|
|
|
Value *Addr, AtomicOrdering Ord) const override;
|
2015-09-12 01:08:28 +08:00
|
|
|
AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
|
2015-07-09 22:51:21 +08:00
|
|
|
bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
|
2015-09-12 01:08:17 +08:00
|
|
|
AtomicExpansionKind
|
|
|
|
shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override {
|
|
|
|
return AtomicExpansionKind::LLSC;
|
2015-07-09 22:51:21 +08:00
|
|
|
}
|
2011-12-13 05:14:40 +08:00
|
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // Hexagon_ISELLOWERING_H
|