blob: aa94fbc2ae6ae10147d56bcb23bb85be99f92b1e [file] [log] [blame]
Chris Lattner08084142003-01-13 00:26:36 +00001//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
Chris Lattner93fa7052002-10-28 23:55:33 +00002//
Chris Lattner93fa7052002-10-28 23:55:33 +00003//
4//===----------------------------------------------------------------------===//
5
Chris Lattner3501fea2003-01-14 22:00:31 +00006#include "llvm/Target/TargetInstrInfo.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//
Chris Lattner08084142003-01-13 00:26:36 +000015const TargetInstrDescriptor* TargetInstrDescriptors = 0;
Chris Lattner93fa7052002-10-28 23:55:33 +000016
17
Chris Lattner08084142003-01-13 00:26:36 +000018TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
19 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
Chris Lattner08084142003-01-13 00:26:36 +000027TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner93fa7052002-10-28 23:55:33 +000028 TargetInstrDescriptors = NULL; // reset global variable
29}
30
Chris Lattner08084142003-01-13 00:26:36 +000031bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
32 int64_t intValue) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000033 // First, check if opCode has an immed field.
34 bool isSignExtended;
35 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
36 if (maxImmedValue != 0)
37 {
38 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
39 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
40 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
41
42 // Now check if the constant fits
43 if (intValue <= (int64_t) maxImmedValue &&
44 intValue >= -((int64_t) maxImmedValue+1))
45 return true;
46 }
47
48 return false;
49}
50
Chris Lattner08084142003-01-13 00:26:36 +000051bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000052 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
53 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
54}