blob: f377d67b66f7606be0ee3c2fb0709ba027756010 [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
Chris Lattneradc101b2002-10-29 17:37:48 +000018// External object describing the machine instructions
19// Initialized only when the TargetMachine class is created
20// and reset when that class is destroyed.
21//
Chris Lattner08084142003-01-13 00:26:36 +000022const TargetInstrDescriptor* TargetInstrDescriptors = 0;
Chris Lattner93fa7052002-10-28 23:55:33 +000023
24
Chris Lattner08084142003-01-13 00:26:36 +000025TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
26 unsigned DescSize,
27 unsigned NumRealOpCodes)
Chris Lattner047bbaf2002-10-29 15:45:20 +000028 : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000029 // FIXME: TargetInstrDescriptors should not be global
30 assert(TargetInstrDescriptors == NULL && desc != NULL);
31 TargetInstrDescriptors = desc; // initialize global variable
32}
33
Chris Lattner08084142003-01-13 00:26:36 +000034TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner93fa7052002-10-28 23:55:33 +000035 TargetInstrDescriptors = NULL; // reset global variable
36}
37
Chris Lattner08084142003-01-13 00:26:36 +000038bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
39 int64_t intValue) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000040 // 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
Chris Lattner08084142003-01-13 00:26:36 +000058bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000059 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
60 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
61}