blob: 115f2c2a7c353bb06fe5c4e4eac0c06190630451 [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
Chris Lattneradc101b2002-10-29 17:37:48 +000012// External object describing the machine instructions
13// Initialized only when the TargetMachine class is created
14// and reset when that class is destroyed.
15//
16const MachineInstrDescriptor* TargetInstrDescriptors = 0;
17
Chris Lattner93fa7052002-10-28 23:55:33 +000018//---------------------------------------------------------------------------
19// class MachineInstructionInfo
20// Interface to description of machine instructions
21//---------------------------------------------------------------------------
22
23
Chris Lattner047bbaf2002-10-29 15:45:20 +000024MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc,
Chris Lattner93fa7052002-10-28 23:55:33 +000025 unsigned DescSize,
26 unsigned NumRealOpCodes)
Chris Lattner047bbaf2002-10-29 15:45:20 +000027 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000028 // FIXME: TargetInstrDescriptors should not be global
29 assert(TargetInstrDescriptors == NULL && desc != NULL);
30 TargetInstrDescriptors = desc; // initialize global variable
31}
32
33MachineInstrInfo::~MachineInstrInfo() {
34 TargetInstrDescriptors = NULL; // reset global variable
35}
36
37
38bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
39 int64_t intValue) const {
40 // First, check if opCode has an immed field.
41 bool isSignExtended;
42 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
43 if (maxImmedValue != 0)
44 {
45 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
46 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
47 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
48
49 // Now check if the constant fits
50 if (intValue <= (int64_t) maxImmedValue &&
51 intValue >= -((int64_t) maxImmedValue+1))
52 return true;
53 }
54
55 return false;
56}
57
58bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
59 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
60 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
61}