~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/VMCore/ValueTypes.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//===----------- ValueTypes.cpp - Implementation of EVT methods -----------===//
2
 
//
3
 
//                     The LLVM Compiler Infrastructure
4
 
//
5
 
// This file is distributed under the University of Illinois Open Source
6
 
// License. See LICENSE.TXT for details.
7
 
//
8
 
//===----------------------------------------------------------------------===//
9
 
//
10
 
// This file implements methods in the CodeGen/ValueTypes.h header.
11
 
//
12
 
//===----------------------------------------------------------------------===//
13
 
 
14
 
#include "llvm/ADT/StringExtras.h"
15
 
#include "llvm/CodeGen/ValueTypes.h"
16
 
#include "llvm/LLVMContext.h"
17
 
#include "llvm/Type.h"
18
 
#include "llvm/DerivedTypes.h"
19
 
#include "llvm/Support/ErrorHandling.h"
20
 
using namespace llvm;
21
 
 
22
 
EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
23
 
  EVT VT;
24
 
  VT.LLVMTy = IntegerType::get(Context, BitWidth);
25
 
  assert(VT.isExtended() && "Type is not extended!");
26
 
  return VT;
27
 
}
28
 
 
29
 
EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
30
 
                             unsigned NumElements) {
31
 
  EVT ResultVT;
32
 
  ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
33
 
  assert(ResultVT.isExtended() && "Type is not extended!");
34
 
  return ResultVT;
35
 
}
36
 
 
37
 
bool EVT::isExtendedFloatingPoint() const {
38
 
  assert(isExtended() && "Type is not extended!");
39
 
  return LLVMTy->isFPOrFPVectorTy();
40
 
}
41
 
 
42
 
bool EVT::isExtendedInteger() const {
43
 
  assert(isExtended() && "Type is not extended!");
44
 
  return LLVMTy->isIntOrIntVectorTy();
45
 
}
46
 
 
47
 
bool EVT::isExtendedVector() const {
48
 
  assert(isExtended() && "Type is not extended!");
49
 
  return LLVMTy->isVectorTy();
50
 
}
51
 
 
52
 
bool EVT::isExtended64BitVector() const {
53
 
  return isExtendedVector() && getSizeInBits() == 64;
54
 
}
55
 
 
56
 
bool EVT::isExtended128BitVector() const {
57
 
  return isExtendedVector() && getSizeInBits() == 128;
58
 
}
59
 
 
60
 
bool EVT::isExtended256BitVector() const {
61
 
  return isExtendedVector() && getSizeInBits() == 256;
62
 
}
63
 
 
64
 
bool EVT::isExtended512BitVector() const {
65
 
  return isExtendedVector() && getSizeInBits() == 512;
66
 
}
67
 
 
68
 
EVT EVT::getExtendedVectorElementType() const {
69
 
  assert(isExtended() && "Type is not extended!");
70
 
  return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
71
 
}
72
 
 
73
 
unsigned EVT::getExtendedVectorNumElements() const {
74
 
  assert(isExtended() && "Type is not extended!");
75
 
  return cast<VectorType>(LLVMTy)->getNumElements();
76
 
}
77
 
 
78
 
unsigned EVT::getExtendedSizeInBits() const {
79
 
  assert(isExtended() && "Type is not extended!");
80
 
  if (const IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
81
 
    return ITy->getBitWidth();
82
 
  if (const VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
83
 
    return VTy->getBitWidth();
84
 
  assert(false && "Unrecognized extended type!");
85
 
  return 0; // Suppress warnings.
86
 
}
87
 
 
88
 
/// getEVTString - This function returns value type as a string, e.g. "i32".
89
 
std::string EVT::getEVTString() const {
90
 
  switch (V.SimpleTy) {
91
 
  default:
92
 
    if (isVector())
93
 
      return "v" + utostr(getVectorNumElements()) +
94
 
             getVectorElementType().getEVTString();
95
 
    if (isInteger())
96
 
      return "i" + utostr(getSizeInBits());
97
 
    llvm_unreachable("Invalid EVT!");
98
 
    return "?";
99
 
  case MVT::i1:      return "i1";
100
 
  case MVT::i8:      return "i8";
101
 
  case MVT::i16:     return "i16";
102
 
  case MVT::i32:     return "i32";
103
 
  case MVT::i64:     return "i64";
104
 
  case MVT::i128:    return "i128";
105
 
  case MVT::f32:     return "f32";
106
 
  case MVT::f64:     return "f64";
107
 
  case MVT::f80:     return "f80";
108
 
  case MVT::f128:    return "f128";
109
 
  case MVT::ppcf128: return "ppcf128";
110
 
  case MVT::isVoid:  return "isVoid";
111
 
  case MVT::Other:   return "ch";
112
 
  case MVT::Flag:    return "flag";
113
 
  case MVT::v2i8:    return "v2i8";
114
 
  case MVT::v4i8:    return "v4i8";
115
 
  case MVT::v8i8:    return "v8i8";
116
 
  case MVT::v16i8:   return "v16i8";
117
 
  case MVT::v32i8:   return "v32i8";
118
 
  case MVT::v2i16:   return "v2i16";
119
 
  case MVT::v4i16:   return "v4i16";
120
 
  case MVT::v8i16:   return "v8i16";
121
 
  case MVT::v16i16:  return "v16i16";
122
 
  case MVT::v2i32:   return "v2i32";
123
 
  case MVT::v4i32:   return "v4i32";
124
 
  case MVT::v8i32:   return "v8i32";
125
 
  case MVT::v1i64:   return "v1i64";
126
 
  case MVT::v2i64:   return "v2i64";
127
 
  case MVT::v4i64:   return "v4i64";
128
 
  case MVT::v8i64:   return "v8i64";
129
 
  case MVT::v2f32:   return "v2f32";
130
 
  case MVT::v4f32:   return "v4f32";
131
 
  case MVT::v8f32:   return "v8f32";
132
 
  case MVT::v2f64:   return "v2f64";
133
 
  case MVT::v4f64:   return "v4f64";
134
 
  case MVT::Metadata:return "Metadata";
135
 
  }
136
 
}
137
 
 
138
 
/// getTypeForEVT - This method returns an LLVM type corresponding to the
139
 
/// specified EVT.  For integer types, this returns an unsigned type.  Note
140
 
/// that this will abort for types that cannot be represented.
141
 
const Type *EVT::getTypeForEVT(LLVMContext &Context) const {
142
 
  switch (V.SimpleTy) {
143
 
  default:
144
 
    assert(isExtended() && "Type is not extended!");
145
 
    return LLVMTy;
146
 
  case MVT::isVoid:  return Type::getVoidTy(Context);
147
 
  case MVT::i1:      return Type::getInt1Ty(Context);
148
 
  case MVT::i8:      return Type::getInt8Ty(Context);
149
 
  case MVT::i16:     return Type::getInt16Ty(Context);
150
 
  case MVT::i32:     return Type::getInt32Ty(Context);
151
 
  case MVT::i64:     return Type::getInt64Ty(Context);
152
 
  case MVT::i128:    return IntegerType::get(Context, 128);
153
 
  case MVT::f32:     return Type::getFloatTy(Context);
154
 
  case MVT::f64:     return Type::getDoubleTy(Context);
155
 
  case MVT::f80:     return Type::getX86_FP80Ty(Context);
156
 
  case MVT::f128:    return Type::getFP128Ty(Context);
157
 
  case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
158
 
  case MVT::v2i8:    return VectorType::get(Type::getInt8Ty(Context), 2);
159
 
  case MVT::v4i8:    return VectorType::get(Type::getInt8Ty(Context), 4);
160
 
  case MVT::v8i8:    return VectorType::get(Type::getInt8Ty(Context), 8);
161
 
  case MVT::v16i8:   return VectorType::get(Type::getInt8Ty(Context), 16);
162
 
  case MVT::v32i8:   return VectorType::get(Type::getInt8Ty(Context), 32);
163
 
  case MVT::v2i16:   return VectorType::get(Type::getInt16Ty(Context), 2);
164
 
  case MVT::v4i16:   return VectorType::get(Type::getInt16Ty(Context), 4);
165
 
  case MVT::v8i16:   return VectorType::get(Type::getInt16Ty(Context), 8);
166
 
  case MVT::v16i16:  return VectorType::get(Type::getInt16Ty(Context), 16);
167
 
  case MVT::v2i32:   return VectorType::get(Type::getInt32Ty(Context), 2);
168
 
  case MVT::v4i32:   return VectorType::get(Type::getInt32Ty(Context), 4);
169
 
  case MVT::v8i32:   return VectorType::get(Type::getInt32Ty(Context), 8);
170
 
  case MVT::v1i64:   return VectorType::get(Type::getInt64Ty(Context), 1);
171
 
  case MVT::v2i64:   return VectorType::get(Type::getInt64Ty(Context), 2);
172
 
  case MVT::v4i64:   return VectorType::get(Type::getInt64Ty(Context), 4);
173
 
  case MVT::v8i64:   return VectorType::get(Type::getInt64Ty(Context), 8);
174
 
  case MVT::v2f32:   return VectorType::get(Type::getFloatTy(Context), 2);
175
 
  case MVT::v4f32:   return VectorType::get(Type::getFloatTy(Context), 4);
176
 
  case MVT::v8f32:   return VectorType::get(Type::getFloatTy(Context), 8);
177
 
  case MVT::v2f64:   return VectorType::get(Type::getDoubleTy(Context), 2);
178
 
  case MVT::v4f64:   return VectorType::get(Type::getDoubleTy(Context), 4); 
179
 
  case MVT::Metadata: return Type::getMetadataTy(Context);
180
 
 }
181
 
}
182
 
 
183
 
/// getEVT - Return the value type corresponding to the specified type.  This
184
 
/// returns all pointers as MVT::iPTR.  If HandleUnknown is true, unknown types
185
 
/// are returned as Other, otherwise they are invalid.
186
 
EVT EVT::getEVT(const Type *Ty, bool HandleUnknown){
187
 
  switch (Ty->getTypeID()) {
188
 
  default:
189
 
    if (HandleUnknown) return MVT(MVT::Other);
190
 
    llvm_unreachable("Unknown type!");
191
 
    return MVT::isVoid;
192
 
  case Type::VoidTyID:
193
 
    return MVT::isVoid;
194
 
  case Type::IntegerTyID:
195
 
    return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
196
 
  case Type::FloatTyID:     return MVT(MVT::f32);
197
 
  case Type::DoubleTyID:    return MVT(MVT::f64);
198
 
  case Type::X86_FP80TyID:  return MVT(MVT::f80);
199
 
  case Type::FP128TyID:     return MVT(MVT::f128);
200
 
  case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
201
 
  case Type::PointerTyID:   return MVT(MVT::iPTR);
202
 
  case Type::VectorTyID: {
203
 
    const VectorType *VTy = cast<VectorType>(Ty);
204
 
    return getVectorVT(Ty->getContext(), getEVT(VTy->getElementType(), false),
205
 
                       VTy->getNumElements());
206
 
  }
207
 
  }
208
 
}