blob: a911116f7bcf673318a6e73fba714c482b311b6f [file] [log] [blame]
Chris Lattner93fa7052002-10-28 23:55:33 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
2//
3// This file describes the general parts of a Target machine.
4// This file also implements MachineInstrInfo and MachineCacheInfo.
5//
6//===----------------------------------------------------------------------===//
7
8#include "llvm/Target/MachineInstrInfo.h"
9#include "llvm/Constant.h"
10#include "llvm/DerivedTypes.h"
11
12//---------------------------------------------------------------------------
13// class MachineInstructionInfo
14// Interface to description of machine instructions
15//---------------------------------------------------------------------------
16
17
Chris Lattner047bbaf2002-10-29 15:45:20 +000018MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc,
Chris Lattner93fa7052002-10-28 23:55:33 +000019 unsigned DescSize,
20 unsigned NumRealOpCodes)
Chris Lattner047bbaf2002-10-29 15:45:20 +000021 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000022 // FIXME: TargetInstrDescriptors should not be global
23 assert(TargetInstrDescriptors == NULL && desc != NULL);
24 TargetInstrDescriptors = desc; // initialize global variable
25}
26
27MachineInstrInfo::~MachineInstrInfo() {
28 TargetInstrDescriptors = NULL; // reset global variable
29}
30
31
32bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
33 int64_t intValue) const {
34 // First, check if opCode has an immed field.
35 bool isSignExtended;
36 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
37 if (maxImmedValue != 0)
38 {
39 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
40 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
41 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
42
43 // Now check if the constant fits
44 if (intValue <= (int64_t) maxImmedValue &&
45 intValue >= -((int64_t) maxImmedValue+1))
46 return true;
47 }
48
49 return false;
50}
51
52bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
53 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
54 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
55}