blob: ae29c54a4fe15273ba6aa4abc10c58ef716253a8 [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
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//
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 +000031void TargetInstrInfo::print(const MachineInstr *MI, std::ostream &O,
32 const TargetMachine &TM) const {
Chris Lattner3b493942002-11-17 23:22:03 +000033 MI->print(O, TM);
Chris Lattnera187ed92002-11-17 22:53:03 +000034}
Chris Lattner93fa7052002-10-28 23:55:33 +000035
Chris Lattner08084142003-01-13 00:26:36 +000036bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
37 int64_t intValue) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000038 // First, check if opCode has an immed field.
39 bool isSignExtended;
40 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
41 if (maxImmedValue != 0)
42 {
43 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
44 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
45 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
46
47 // Now check if the constant fits
48 if (intValue <= (int64_t) maxImmedValue &&
49 intValue >= -((int64_t) maxImmedValue+1))
50 return true;
51 }
52
53 return false;
54}
55
Chris Lattner08084142003-01-13 00:26:36 +000056bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000057 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
58 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
59}