2005-01-07 15:44:53 +08:00
|
|
|
//===-- TargetLowering.cpp - Implement the TargetLowering class -----------===//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2005-01-07 15:44:53 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2005-01-07 15:44:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements the TargetLowering class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
TargetLowering::TargetLowering(TargetMachine &tm)
|
2005-01-16 09:10:58 +08:00
|
|
|
: TM(tm), TD(TM.getTargetData()), ValueTypeActions(0) {
|
2005-01-07 15:44:53 +08:00
|
|
|
assert(ISD::BUILTIN_OP_END <= 128 &&
|
|
|
|
"Fixed size array in TargetLowering is not large enough!");
|
2005-01-16 15:28:11 +08:00
|
|
|
// All operations default to being supported.
|
|
|
|
memset(OpActions, 0, sizeof(OpActions));
|
2005-01-07 15:44:53 +08:00
|
|
|
|
|
|
|
IsLittleEndian = TD.isLittleEndian();
|
2005-01-17 07:59:48 +08:00
|
|
|
ShiftAmountTy = SetCCResultTy = PointerTy = getValueType(TD.getIntPtrType());
|
2005-01-19 11:36:14 +08:00
|
|
|
ShiftAmtHandling = Undefined;
|
2005-01-07 15:44:53 +08:00
|
|
|
memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
|
2005-08-28 03:09:02 +08:00
|
|
|
maxStoresPerMemSet = maxStoresPerMemCpy = maxStoresPerMemMove = 8;
|
|
|
|
allowUnalignedMemoryAccesses = false;
|
2005-09-28 06:13:56 +08:00
|
|
|
UseUnderscoreSetJmpLongJmp = false;
|
2005-10-21 08:02:42 +08:00
|
|
|
IntDivIsCheap = false;
|
|
|
|
Pow2DivIsCheap = false;
|
2005-01-07 15:44:53 +08:00
|
|
|
}
|
|
|
|
|
2005-01-16 15:28:11 +08:00
|
|
|
TargetLowering::~TargetLowering() {}
|
|
|
|
|
2005-01-16 09:10:58 +08:00
|
|
|
/// setValueTypeAction - Set the action for a particular value type. This
|
|
|
|
/// assumes an action has not already been set for this value type.
|
2005-01-16 15:28:11 +08:00
|
|
|
static void SetValueTypeAction(MVT::ValueType VT,
|
|
|
|
TargetLowering::LegalizeAction Action,
|
2005-01-16 09:10:58 +08:00
|
|
|
TargetLowering &TLI,
|
|
|
|
MVT::ValueType *TransformToType,
|
2005-11-29 13:45:29 +08:00
|
|
|
unsigned long long &ValueTypeActions) {
|
|
|
|
ValueTypeActions |= (unsigned long long)Action << (VT*2);
|
2005-01-16 15:28:11 +08:00
|
|
|
if (Action == TargetLowering::Promote) {
|
2005-01-16 09:10:58 +08:00
|
|
|
MVT::ValueType PromoteTo;
|
|
|
|
if (VT == MVT::f32)
|
|
|
|
PromoteTo = MVT::f64;
|
|
|
|
else {
|
|
|
|
unsigned LargerReg = VT+1;
|
2005-08-25 00:34:12 +08:00
|
|
|
while (!TLI.isTypeLegal((MVT::ValueType)LargerReg)) {
|
2005-01-16 09:10:58 +08:00
|
|
|
++LargerReg;
|
|
|
|
assert(MVT::isInteger((MVT::ValueType)LargerReg) &&
|
|
|
|
"Nothing to promote to??");
|
|
|
|
}
|
|
|
|
PromoteTo = (MVT::ValueType)LargerReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(MVT::isInteger(VT) == MVT::isInteger(PromoteTo) &&
|
|
|
|
MVT::isFloatingPoint(VT) == MVT::isFloatingPoint(PromoteTo) &&
|
|
|
|
"Can only promote from int->int or fp->fp!");
|
|
|
|
assert(VT < PromoteTo && "Must promote to a larger type!");
|
|
|
|
TransformToType[VT] = PromoteTo;
|
2005-01-16 15:28:11 +08:00
|
|
|
} else if (Action == TargetLowering::Expand) {
|
2005-11-22 09:29:36 +08:00
|
|
|
assert((VT == MVT::Vector || MVT::isInteger(VT)) && VT > MVT::i8 &&
|
2005-01-16 09:10:58 +08:00
|
|
|
"Cannot expand this type: target must support SOME integer reg!");
|
|
|
|
// Expand to the next smaller integer type!
|
|
|
|
TransformToType[VT] = (MVT::ValueType)(VT-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-07 15:44:53 +08:00
|
|
|
/// computeRegisterProperties - Once all of the register classes are added,
|
|
|
|
/// this allows us to compute derived properties we expose.
|
|
|
|
void TargetLowering::computeRegisterProperties() {
|
2005-11-29 13:45:29 +08:00
|
|
|
assert(MVT::LAST_VALUETYPE <= 32 &&
|
2005-01-16 09:10:58 +08:00
|
|
|
"Too many value types for ValueTypeActions to hold!");
|
|
|
|
|
2005-01-07 15:44:53 +08:00
|
|
|
// Everything defaults to one.
|
|
|
|
for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i)
|
|
|
|
NumElementsForVT[i] = 1;
|
2005-04-22 06:55:34 +08:00
|
|
|
|
2005-01-07 15:44:53 +08:00
|
|
|
// Find the largest integer register class.
|
|
|
|
unsigned LargestIntReg = MVT::i128;
|
|
|
|
for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg)
|
|
|
|
assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
|
|
|
|
|
|
|
|
// Every integer value type larger than this largest register takes twice as
|
|
|
|
// many registers to represent as the previous ValueType.
|
|
|
|
unsigned ExpandedReg = LargestIntReg; ++LargestIntReg;
|
|
|
|
for (++ExpandedReg; MVT::isInteger((MVT::ValueType)ExpandedReg);++ExpandedReg)
|
|
|
|
NumElementsForVT[ExpandedReg] = 2*NumElementsForVT[ExpandedReg-1];
|
|
|
|
|
2005-01-16 09:10:58 +08:00
|
|
|
// Inspect all of the ValueType's possible, deciding how to process them.
|
|
|
|
for (unsigned IntReg = MVT::i1; IntReg <= MVT::i128; ++IntReg)
|
|
|
|
// If we are expanding this type, expand it!
|
|
|
|
if (getNumElements((MVT::ValueType)IntReg) != 1)
|
2005-01-16 15:28:11 +08:00
|
|
|
SetValueTypeAction((MVT::ValueType)IntReg, Expand, *this, TransformToType,
|
2005-01-16 09:10:58 +08:00
|
|
|
ValueTypeActions);
|
2005-08-25 00:34:12 +08:00
|
|
|
else if (!isTypeLegal((MVT::ValueType)IntReg))
|
2005-01-16 09:10:58 +08:00
|
|
|
// Otherwise, if we don't have native support, we must promote to a
|
|
|
|
// larger type.
|
2005-01-16 15:28:11 +08:00
|
|
|
SetValueTypeAction((MVT::ValueType)IntReg, Promote, *this,
|
|
|
|
TransformToType, ValueTypeActions);
|
2005-01-16 09:20:18 +08:00
|
|
|
else
|
|
|
|
TransformToType[(MVT::ValueType)IntReg] = (MVT::ValueType)IntReg;
|
2005-04-22 06:55:34 +08:00
|
|
|
|
2005-01-16 09:10:58 +08:00
|
|
|
// If the target does not have native support for F32, promote it to F64.
|
2005-08-25 00:34:12 +08:00
|
|
|
if (!isTypeLegal(MVT::f32))
|
2005-01-16 15:28:11 +08:00
|
|
|
SetValueTypeAction(MVT::f32, Promote, *this,
|
|
|
|
TransformToType, ValueTypeActions);
|
2005-01-16 09:20:18 +08:00
|
|
|
else
|
|
|
|
TransformToType[MVT::f32] = MVT::f32;
|
2005-11-22 09:29:36 +08:00
|
|
|
|
|
|
|
// Set MVT::Vector to always be Expanded
|
|
|
|
SetValueTypeAction(MVT::Vector, Expand, *this, TransformToType,
|
|
|
|
ValueTypeActions);
|
2005-01-16 09:20:18 +08:00
|
|
|
|
2005-08-25 00:34:12 +08:00
|
|
|
assert(isTypeLegal(MVT::f64) && "Target does not support FP?");
|
2005-01-16 09:20:18 +08:00
|
|
|
TransformToType[MVT::f64] = MVT::f64;
|
2005-01-16 09:10:58 +08:00
|
|
|
}
|
2005-01-16 15:28:11 +08:00
|
|
|
|
2005-12-20 14:22:03 +08:00
|
|
|
const char *TargetLowering::getTargetNodeName(unsigned Opcode) const {
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-12-22 07:05:39 +08:00
|
|
|
|
2005-12-22 07:14:54 +08:00
|
|
|
bool TargetLowering::isMaskedValueZeroForTargetNode(const SDOperand &Op,
|
|
|
|
uint64_t Mask) const {
|
2005-12-22 07:05:39 +08:00
|
|
|
return false;
|
|
|
|
}
|