2005-01-07 08:44:53 +01:00
|
|
|
//===-- TargetLowering.cpp - Implement the TargetLowering class -----------===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2005-01-07 08:44:53 +01: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 00:55:34 +02:00
|
|
|
//
|
2005-01-07 08:44:53 +01: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 02:10:58 +01:00
|
|
|
: TM(tm), TD(TM.getTargetData()), ValueTypeActions(0) {
|
2005-01-07 08:44:53 +01:00
|
|
|
assert(ISD::BUILTIN_OP_END <= 128 &&
|
|
|
|
"Fixed size array in TargetLowering is not large enough!");
|
2005-01-16 08:28:11 +01:00
|
|
|
// All operations default to being supported.
|
|
|
|
memset(OpActions, 0, sizeof(OpActions));
|
2005-01-07 08:44:53 +01:00
|
|
|
|
|
|
|
IsLittleEndian = TD.isLittleEndian();
|
2005-01-17 00:59:48 +01:00
|
|
|
ShiftAmountTy = SetCCResultTy = PointerTy = getValueType(TD.getIntPtrType());
|
2005-01-19 04:36:14 +01:00
|
|
|
ShiftAmtHandling = Undefined;
|
2005-01-07 08:44:53 +01:00
|
|
|
memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
|
2005-08-27 21:09:02 +02:00
|
|
|
maxStoresPerMemSet = maxStoresPerMemCpy = maxStoresPerMemMove = 8;
|
|
|
|
allowUnalignedMemoryAccesses = false;
|
2005-09-28 00:13:56 +02:00
|
|
|
UseUnderscoreSetJmpLongJmp = false;
|
2005-10-21 02:02:42 +02:00
|
|
|
IntDivIsCheap = false;
|
|
|
|
Pow2DivIsCheap = false;
|
2005-01-07 08:44:53 +01:00
|
|
|
}
|
|
|
|
|
2005-01-16 08:28:11 +01:00
|
|
|
TargetLowering::~TargetLowering() {}
|
|
|
|
|
2005-01-16 02:10:58 +01: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 08:28:11 +01:00
|
|
|
static void SetValueTypeAction(MVT::ValueType VT,
|
|
|
|
TargetLowering::LegalizeAction Action,
|
2005-01-16 02:10:58 +01:00
|
|
|
TargetLowering &TLI,
|
|
|
|
MVT::ValueType *TransformToType,
|
2005-11-29 06:45:29 +01:00
|
|
|
unsigned long long &ValueTypeActions) {
|
|
|
|
ValueTypeActions |= (unsigned long long)Action << (VT*2);
|
2005-01-16 08:28:11 +01:00
|
|
|
if (Action == TargetLowering::Promote) {
|
2005-01-16 02:10:58 +01:00
|
|
|
MVT::ValueType PromoteTo;
|
|
|
|
if (VT == MVT::f32)
|
|
|
|
PromoteTo = MVT::f64;
|
|
|
|
else {
|
|
|
|
unsigned LargerReg = VT+1;
|
2005-08-24 18:34:12 +02:00
|
|
|
while (!TLI.isTypeLegal((MVT::ValueType)LargerReg)) {
|
2005-01-16 02:10:58 +01: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 08:28:11 +01:00
|
|
|
} else if (Action == TargetLowering::Expand) {
|
2005-11-22 02:29:36 +01:00
|
|
|
assert((VT == MVT::Vector || MVT::isInteger(VT)) && VT > MVT::i8 &&
|
2005-01-16 02:10:58 +01: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 08:44:53 +01: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 06:45:29 +01:00
|
|
|
assert(MVT::LAST_VALUETYPE <= 32 &&
|
2005-01-16 02:10:58 +01:00
|
|
|
"Too many value types for ValueTypeActions to hold!");
|
|
|
|
|
2005-01-07 08:44:53 +01:00
|
|
|
// Everything defaults to one.
|
|
|
|
for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i)
|
|
|
|
NumElementsForVT[i] = 1;
|
2005-04-22 00:55:34 +02:00
|
|
|
|
2005-01-07 08:44:53 +01: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 02:10:58 +01: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 08:28:11 +01:00
|
|
|
SetValueTypeAction((MVT::ValueType)IntReg, Expand, *this, TransformToType,
|
2005-01-16 02:10:58 +01:00
|
|
|
ValueTypeActions);
|
2005-08-24 18:34:12 +02:00
|
|
|
else if (!isTypeLegal((MVT::ValueType)IntReg))
|
2005-01-16 02:10:58 +01:00
|
|
|
// Otherwise, if we don't have native support, we must promote to a
|
|
|
|
// larger type.
|
2005-01-16 08:28:11 +01:00
|
|
|
SetValueTypeAction((MVT::ValueType)IntReg, Promote, *this,
|
|
|
|
TransformToType, ValueTypeActions);
|
2005-01-16 02:20:18 +01:00
|
|
|
else
|
|
|
|
TransformToType[(MVT::ValueType)IntReg] = (MVT::ValueType)IntReg;
|
2005-04-22 00:55:34 +02:00
|
|
|
|
2005-01-16 02:10:58 +01:00
|
|
|
// If the target does not have native support for F32, promote it to F64.
|
2005-08-24 18:34:12 +02:00
|
|
|
if (!isTypeLegal(MVT::f32))
|
2005-01-16 08:28:11 +01:00
|
|
|
SetValueTypeAction(MVT::f32, Promote, *this,
|
|
|
|
TransformToType, ValueTypeActions);
|
2005-01-16 02:20:18 +01:00
|
|
|
else
|
|
|
|
TransformToType[MVT::f32] = MVT::f32;
|
2005-11-22 02:29:36 +01:00
|
|
|
|
|
|
|
// Set MVT::Vector to always be Expanded
|
|
|
|
SetValueTypeAction(MVT::Vector, Expand, *this, TransformToType,
|
|
|
|
ValueTypeActions);
|
2005-01-16 02:20:18 +01:00
|
|
|
|
2005-08-24 18:34:12 +02:00
|
|
|
assert(isTypeLegal(MVT::f64) && "Target does not support FP?");
|
2005-01-16 02:20:18 +01:00
|
|
|
TransformToType[MVT::f64] = MVT::f64;
|
2005-01-16 02:10:58 +01:00
|
|
|
}
|
2005-01-16 08:28:11 +01:00
|
|
|
|
2005-12-20 07:22:03 +01:00
|
|
|
const char *TargetLowering::getTargetNodeName(unsigned Opcode) const {
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-12-22 00:05:39 +01:00
|
|
|
|
2005-12-22 00:14:54 +01:00
|
|
|
bool TargetLowering::isMaskedValueZeroForTargetNode(const SDOperand &Op,
|
|
|
|
uint64_t Mask) const {
|
2005-12-22 00:05:39 +01:00
|
|
|
return false;
|
|
|
|
}
|