xref: /llvm-project/llvm/lib/Target/TargetMachine.cpp (revision 1680fb1617681ab0a6d43ab0c94dfd8bde739f08)
1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
2 //
3 // This file describes the general parts of a Target machine.
4 // This file also implements the InstInfo interface as well...
5 //
6 //===----------------------------------------------------------------------===//
7 
8 #include "llvm/Target/InstInfo.h"
9 #include "llvm/DerivedTypes.h"
10 
11 //---------------------------------------------------------------------------
12 // class TargetMachine
13 //
14 // Purpose:
15 //   Machine description.
16 //
17 //---------------------------------------------------------------------------
18 
19 // function TargetMachine::findOptimalStorageSize
20 //
21 // Purpose:
22 //   This default implementation assumes that all sub-word data items use
23 //   space equal to optSizeForSubWordData, and all other primitive data
24 //   items use space according to the type.
25 //
26 unsigned int TargetMachine::findOptimalStorageSize(const Type* ty) const {
27   switch(ty->getPrimitiveID()) {
28   case Type::BoolTyID:
29   case Type::UByteTyID:
30   case Type::SByteTyID:
31   case Type::UShortTyID:
32   case Type::ShortTyID:
33     return optSizeForSubWordData;
34 
35   default:
36     return DataLayout.getTypeSize(ty);
37   }
38 }
39 
40 
41 //---------------------------------------------------------------------------
42 // class MachineInstructionInfo
43 //	Interface to description of machine instructions
44 //---------------------------------------------------------------------------
45 
46 
47 /*ctor*/
48 MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc,
49 				   unsigned int _descSize,
50 				   unsigned int _numRealOpCodes)
51   : desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
52 {
53   // FIXME: TargetInstrDescriptors should not be global
54   assert(TargetInstrDescriptors == NULL && desc != NULL);
55   TargetInstrDescriptors = desc;	// initialize global variable
56 }
57 
58 
59 MachineInstrInfo::~MachineInstrInfo() {
60   TargetInstrDescriptors = NULL;	// reset global variable
61 }
62 
63 
64 bool
65 MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
66 					   int64_t intValue) const
67 {
68   // First, check if opCode has an immed field.
69   bool isSignExtended;
70   uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
71   if (maxImmedValue != 0) {
72     // Now check if the constant fits
73     if (intValue <= (int64_t) maxImmedValue &&
74 	intValue >= -((int64_t) maxImmedValue+1))
75       return true;
76   }
77 
78   return false;
79 }
80