blob: a3131bb319f556766df98d3dd8a16c87eaca655d [file] [log] [blame]
Chris Lattner08084142003-01-13 00:26:36 +00001//===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner93fa7052002-10-28 23:55:33 +00009//
Chris Lattner93fa7052002-10-28 23:55:33 +000010//
11//===----------------------------------------------------------------------===//
12
Chris Lattner3501fea2003-01-14 22:00:31 +000013#include "llvm/Target/TargetInstrInfo.h"
Chris Lattnera187ed92002-11-17 22:53:03 +000014#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner93fa7052002-10-28 23:55:33 +000015#include "llvm/Constant.h"
16#include "llvm/DerivedTypes.h"
17
Brian Gaeked0fde302003-11-11 22:41:34 +000018namespace llvm {
19
Chris Lattneradc101b2002-10-29 17:37:48 +000020// External object describing the machine instructions
21// Initialized only when the TargetMachine class is created
22// and reset when that class is destroyed.
23//
Chris Lattner08084142003-01-13 00:26:36 +000024const TargetInstrDescriptor* TargetInstrDescriptors = 0;
Chris Lattner93fa7052002-10-28 23:55:33 +000025
Chris Lattner08084142003-01-13 00:26:36 +000026TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
27 unsigned DescSize,
28 unsigned NumRealOpCodes)
Chris Lattner047bbaf2002-10-29 15:45:20 +000029 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000030 // FIXME: TargetInstrDescriptors should not be global
Brian Gaeke0f5918a2004-01-15 18:15:58 +000031 assert(TargetInstrDescriptors == NULL && desc != NULL
32 && "TargetMachine data structure corrupt; maybe you tried to create another TargetMachine? (only one may exist in a program)");
Chris Lattner93fa7052002-10-28 23:55:33 +000033 TargetInstrDescriptors = desc; // initialize global variable
34}
35
Chris Lattner08084142003-01-13 00:26:36 +000036TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner93fa7052002-10-28 23:55:33 +000037 TargetInstrDescriptors = NULL; // reset global variable
38}
39
Chris Lattner08084142003-01-13 00:26:36 +000040bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
41 int64_t intValue) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000042 // 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
Chris Lattner08084142003-01-13 00:26:36 +000060bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000061 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
62 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
63}
Brian Gaeked0fde302003-11-11 22:41:34 +000064
65} // End llvm namespace