blob: 5dca701be8e7dd33d86f09a1ef21751746eaa6fd [file] [log] [blame]
Chris Lattnera187ed92002-11-17 22:53:03 +00001//===-- MachineInstrInfo.cpp - Target Instruction Information -------------===//
Chris Lattner93fa7052002-10-28 23:55:33 +00002//
Chris Lattner93fa7052002-10-28 23:55:33 +00003//
4//===----------------------------------------------------------------------===//
5
6#include "llvm/Target/MachineInstrInfo.h"
Chris Lattnera187ed92002-11-17 22:53:03 +00007#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner93fa7052002-10-28 23:55:33 +00008#include "llvm/Constant.h"
9#include "llvm/DerivedTypes.h"
10
Chris Lattneradc101b2002-10-29 17:37:48 +000011// External object describing the machine instructions
12// Initialized only when the TargetMachine class is created
13// and reset when that class is destroyed.
14//
15const MachineInstrDescriptor* TargetInstrDescriptors = 0;
16
Chris Lattner93fa7052002-10-28 23:55:33 +000017//---------------------------------------------------------------------------
18// class MachineInstructionInfo
19// Interface to description of machine instructions
20//---------------------------------------------------------------------------
21
22
Chris Lattner047bbaf2002-10-29 15:45:20 +000023MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc,
Chris Lattner93fa7052002-10-28 23:55:33 +000024 unsigned DescSize,
25 unsigned NumRealOpCodes)
Chris Lattner047bbaf2002-10-29 15:45:20 +000026 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000027 // FIXME: TargetInstrDescriptors should not be global
28 assert(TargetInstrDescriptors == NULL && desc != NULL);
29 TargetInstrDescriptors = desc; // initialize global variable
30}
31
32MachineInstrInfo::~MachineInstrInfo() {
33 TargetInstrDescriptors = NULL; // reset global variable
34}
35
Chris Lattnera187ed92002-11-17 22:53:03 +000036void MachineInstrInfo::print(const MachineInstr *MI, std::ostream &O) const {
37 O << *MI;
38}
Chris Lattner93fa7052002-10-28 23:55:33 +000039
40bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
41 int64_t intValue) const {
42 // First, check if opCode has an immed field.
43 bool isSignExtended;
44 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
45 if (maxImmedValue != 0)
46 {
47 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
48 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
49 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
50
51 // Now check if the constant fits
52 if (intValue <= (int64_t) maxImmedValue &&
53 intValue >= -((int64_t) maxImmedValue+1))
54 return true;
55 }
56
57 return false;
58}
59
60bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
61 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
62 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
63}