blob: efcf9db4eb7ee997dc523796981e108ab3e9aff0 [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,
Chris Lattnerdce363d2004-02-29 06:31:44 +000027 unsigned numOpcodes)
28 : desc(Desc), NumOpcodes(numOpcodes) {
Chris Lattner93fa7052002-10-28 23:55:33 +000029 // FIXME: TargetInstrDescriptors should not be global
Brian Gaeke0f5918a2004-01-15 18:15:58 +000030 assert(TargetInstrDescriptors == NULL && desc != NULL
31 && "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 +000032 TargetInstrDescriptors = desc; // initialize global variable
33}
34
Chris Lattner08084142003-01-13 00:26:36 +000035TargetInstrInfo::~TargetInstrInfo() {
Chris Lattner93fa7052002-10-28 23:55:33 +000036 TargetInstrDescriptors = NULL; // reset global variable
37}
38
Chris Lattner08084142003-01-13 00:26:36 +000039bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
40 int64_t intValue) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000041 // First, check if opCode has an immed field.
42 bool isSignExtended;
43 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
44 if (maxImmedValue != 0)
45 {
46 // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
47 // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
48 // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
49
50 // Now check if the constant fits
51 if (intValue <= (int64_t) maxImmedValue &&
52 intValue >= -((int64_t) maxImmedValue+1))
53 return true;
54 }
55
56 return false;
57}
58
Chris Lattner08084142003-01-13 00:26:36 +000059bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
Chris Lattner93fa7052002-10-28 23:55:33 +000060 assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
61 return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
62}
Brian Gaeked0fde302003-11-11 22:41:34 +000063
64} // End llvm namespace