blob: 681993a5d4a70c907b6ebd3c9c3e6047371c2353 [file] [log] [blame]
Anders Carlsson3b1d57b2008-01-26 01:36:00 +00001//===--- CGExprConstant.cpp - Emit LLVM Code from Constant Expressions ----===//
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 contains code to emit Constant Expr nodes as LLVM code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CodeGenFunction.h"
15#include "CodeGenModule.h"
16#include "clang/AST/AST.h"
17#include "llvm/Constants.h"
18#include "llvm/Function.h"
19#include "llvm/GlobalVariable.h"
20#include "llvm/Support/Compiler.h"
Eli Friedmana8234002008-05-30 10:24:46 +000021#include "llvm/Target/TargetData.h"
Anders Carlsson3b1d57b2008-01-26 01:36:00 +000022using namespace clang;
23using namespace CodeGen;
24
25namespace {
Anders Carlsson84005b42008-01-26 04:30:23 +000026class VISIBILITY_HIDDEN ConstExprEmitter :
27 public StmtVisitor<ConstExprEmitter, llvm::Constant*> {
Anders Carlsson3b1d57b2008-01-26 01:36:00 +000028 CodeGenModule &CGM;
Lauro Ramos Venancio81373352008-02-26 21:41:45 +000029 CodeGenFunction *CGF;
Anders Carlsson3b1d57b2008-01-26 01:36:00 +000030public:
Lauro Ramos Venancio81373352008-02-26 21:41:45 +000031 ConstExprEmitter(CodeGenModule &cgm, CodeGenFunction *cgf)
32 : CGM(cgm), CGF(cgf) {
Anders Carlsson3b1d57b2008-01-26 01:36:00 +000033 }
34
35 //===--------------------------------------------------------------------===//
36 // Visitor Methods
37 //===--------------------------------------------------------------------===//
38
39 llvm::Constant *VisitStmt(Stmt *S) {
40 CGM.WarnUnsupported(S, "constant expression");
Chris Lattner98be4942008-03-05 18:54:05 +000041 QualType T = cast<Expr>(S)->getType();
42 return llvm::UndefValue::get(CGM.getTypes().ConvertType(T));
Anders Carlsson3b1d57b2008-01-26 01:36:00 +000043 }
44
45 llvm::Constant *VisitParenExpr(ParenExpr *PE) {
46 return Visit(PE->getSubExpr());
47 }
48
49 // Leaves
50 llvm::Constant *VisitIntegerLiteral(const IntegerLiteral *E) {
51 return llvm::ConstantInt::get(E->getValue());
52 }
53 llvm::Constant *VisitFloatingLiteral(const FloatingLiteral *E) {
Chris Lattner59138ba2008-04-20 00:45:53 +000054 return llvm::ConstantFP::get(E->getValue());
Anders Carlsson3b1d57b2008-01-26 01:36:00 +000055 }
56 llvm::Constant *VisitCharacterLiteral(const CharacterLiteral *E) {
57 return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
58 }
59 llvm::Constant *VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
60 return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
61 }
Chris Lattner13fd7e52008-06-21 21:44:18 +000062 llvm::Constant *VisitObjCStringLiteral(const ObjCStringLiteral *E) {
63 return CGM.getObjCRuntime()->GenerateConstantString(
64 E->getString()->getStrData(), E->getString()->getByteLength());
65 }
Anders Carlsson3b1d57b2008-01-26 01:36:00 +000066
67 llvm::Constant *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
68 return Visit(E->getInitializer());
69 }
70
71 llvm::Constant *VisitCastExpr(const CastExpr* E) {
72 llvm::Constant *C = Visit(E->getSubExpr());
73
74 return EmitConversion(C, E->getSubExpr()->getType(), E->getType());
75 }
Devang Pateleae15602008-02-05 02:39:50 +000076
Chris Lattner04421082008-04-08 04:40:51 +000077 llvm::Constant *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
78 return Visit(DAE->getExpr());
79 }
80
Eli Friedmana8234002008-05-30 10:24:46 +000081 llvm::Constant *EmitArrayInitialization(InitListExpr *ILE) {
Eli Friedman4d1c0182008-02-21 17:45:41 +000082 std::vector<llvm::Constant*> Elts;
Eli Friedmana8234002008-05-30 10:24:46 +000083 const llvm::ArrayType *AType =
84 cast<llvm::ArrayType>(ConvertType(ILE->getType()));
Eli Friedman4d1c0182008-02-21 17:45:41 +000085 unsigned NumInitElements = ILE->getNumInits();
86 // FIXME: Check for wide strings
87 if (NumInitElements > 0 && isa<StringLiteral>(ILE->getInit(0)) &&
88 ILE->getType()->getAsArrayType()->getElementType()->isCharType())
89 return Visit(ILE->getInit(0));
Devang Pateleae15602008-02-05 02:39:50 +000090 const llvm::Type *ElemTy = AType->getElementType();
91 unsigned NumElements = AType->getNumElements();
92
93 // Initialising an array requires us to automatically
94 // initialise any elements that have not been initialised explicitly
95 unsigned NumInitableElts = std::min(NumInitElements, NumElements);
96
97 // Copy initializer elements.
98 unsigned i = 0;
Eli Friedmana04a1532008-05-30 19:58:50 +000099 bool RewriteType = false;
Devang Pateleae15602008-02-05 02:39:50 +0000100 for (; i < NumInitableElts; ++i) {
Devang Pateleae15602008-02-05 02:39:50 +0000101 llvm::Constant *C = Visit(ILE->getInit(i));
Eli Friedmana04a1532008-05-30 19:58:50 +0000102 RewriteType |= (C->getType() != ElemTy);
Devang Pateleae15602008-02-05 02:39:50 +0000103 Elts.push_back(C);
104 }
Eli Friedmana04a1532008-05-30 19:58:50 +0000105
Devang Pateleae15602008-02-05 02:39:50 +0000106 // Initialize remaining array elements.
107 for (; i < NumElements; ++i)
108 Elts.push_back(llvm::Constant::getNullValue(ElemTy));
109
Eli Friedmana04a1532008-05-30 19:58:50 +0000110 if (RewriteType) {
111 // FIXME: Try to avoid packing the array
112 std::vector<const llvm::Type*> Types;
113 for (unsigned i = 0; i < Elts.size(); ++i)
114 Types.push_back(Elts[i]->getType());
115 const llvm::StructType *SType = llvm::StructType::get(Types, true);
116 return llvm::ConstantStruct::get(SType, Elts);
117 }
118
Devang Pateleae15602008-02-05 02:39:50 +0000119 return llvm::ConstantArray::get(AType, Elts);
120 }
121
Eli Friedmana8234002008-05-30 10:24:46 +0000122 void InsertBitfieldIntoStruct(std::vector<llvm::Constant*>& Elts,
123 FieldDecl* Field, Expr* E) {
124 // Calculate the value to insert
125 llvm::Constant *C = Visit(E);
126 llvm::ConstantInt *CI = dyn_cast<llvm::ConstantInt>(C);
127 if (!CI) {
128 CGM.WarnUnsupported(E, "bitfield initialization");
129 return;
130 }
131 llvm::APInt V = CI->getValue();
Devang Pateleae15602008-02-05 02:39:50 +0000132
Eli Friedmana8234002008-05-30 10:24:46 +0000133 // Calculate information about the relevant field
134 const llvm::Type* Ty = CI->getType();
135 unsigned size = CGM.getTypes().getTargetData().getTypeStoreSizeInBits(Ty);
136 unsigned fieldOffset = CGM.getTypes().getLLVMFieldNo(Field) * size;
137 CodeGenTypes::BitFieldInfo bitFieldInfo =
138 CGM.getTypes().getBitFieldInfo(Field);
139 fieldOffset += bitFieldInfo.Begin;
140
141 // Find where to start the insertion
142 // FIXME: This is O(n^2) in the number of bit-fields!
143 // FIXME: This won't work if the struct isn't completely packed!
144 unsigned offset = 0, i = 0;
145 while (offset < (fieldOffset & -8))
146 offset += CGM.getTypes().getTargetData().getTypeStoreSizeInBits(Elts[i++]->getType());
147
Daniel Dunbar1f3846e2008-07-17 21:07:48 +0000148 // Promote the size of V if necessary
149 // FIXME: This should never occur, but currently it can because
150 // initializer constants are cast to bool, and because clang is
151 // not enforcing bitfield width limits.
152 if (bitFieldInfo.Size > V.getBitWidth())
153 V.zext(bitFieldInfo.Size);
154
Eli Friedmana8234002008-05-30 10:24:46 +0000155 // Insert the bits into the struct
156 // FIXME: This algorthm is only correct on X86!
157 // FIXME: THis algorthm assumes bit-fields only have byte-size elements!
158 unsigned bitsToInsert = bitFieldInfo.Size;
159 unsigned curBits = std::min(8 - (fieldOffset & 7), bitsToInsert);
160 unsigned byte = V.getLoBits(curBits).getZExtValue() << (fieldOffset & 7);
161 do {
162 llvm::Constant* byteC = llvm::ConstantInt::get(llvm::Type::Int8Ty, byte);
163 Elts[i] = llvm::ConstantExpr::getOr(Elts[i], byteC);
164 ++i;
165 V = V.lshr(curBits);
166 bitsToInsert -= curBits;
167
168 if (!bitsToInsert)
169 break;
170
171 curBits = bitsToInsert > 8 ? 8 : bitsToInsert;
172 byte = V.getLoBits(curBits).getZExtValue();
173 } while (true);
174 }
175
176 llvm::Constant *EmitStructInitialization(InitListExpr *ILE) {
177 const llvm::StructType *SType =
178 cast<llvm::StructType>(ConvertType(ILE->getType()));
Eli Friedman017cbdf2008-05-20 00:11:07 +0000179 RecordDecl *RD = ILE->getType()->getAsRecordType()->getDecl();
Devang Pateleae15602008-02-05 02:39:50 +0000180 std::vector<llvm::Constant*> Elts;
Devang Pateleae15602008-02-05 02:39:50 +0000181
Eli Friedman017cbdf2008-05-20 00:11:07 +0000182 // Initialize the whole structure to zero.
183 for (unsigned i = 0; i < SType->getNumElements(); ++i) {
Devang Pateleae15602008-02-05 02:39:50 +0000184 const llvm::Type *FieldTy = SType->getElementType(i);
185 Elts.push_back(llvm::Constant::getNullValue(FieldTy));
186 }
Eli Friedman017cbdf2008-05-20 00:11:07 +0000187
188 // Copy initializer elements. Skip padding fields.
189 unsigned EltNo = 0; // Element no in ILE
190 int FieldNo = 0; // Field no in RecordDecl
Eli Friedmana04a1532008-05-30 19:58:50 +0000191 bool RewriteType = false;
Eli Friedman017cbdf2008-05-20 00:11:07 +0000192 while (EltNo < ILE->getNumInits() && FieldNo < RD->getNumMembers()) {
193 FieldDecl* curField = RD->getMember(FieldNo);
194 FieldNo++;
195 if (!curField->getIdentifier())
196 continue;
197
Eli Friedman017cbdf2008-05-20 00:11:07 +0000198 if (curField->isBitField()) {
Eli Friedmana8234002008-05-30 10:24:46 +0000199 InsertBitfieldIntoStruct(Elts, curField, ILE->getInit(EltNo));
Eli Friedman017cbdf2008-05-20 00:11:07 +0000200 } else {
Eli Friedmana04a1532008-05-30 19:58:50 +0000201 unsigned FieldNo = CGM.getTypes().getLLVMFieldNo(curField);
202 llvm::Constant* C = Visit(ILE->getInit(EltNo));
203 RewriteType |= (C->getType() != Elts[FieldNo]->getType());
204 Elts[FieldNo] = C;
Eli Friedman017cbdf2008-05-20 00:11:07 +0000205 }
206 EltNo++;
207 }
208
Eli Friedmana04a1532008-05-30 19:58:50 +0000209 if (RewriteType) {
210 // FIXME: Make this work for non-packed structs
211 assert(SType->isPacked() && "Cannot recreate unpacked structs");
212 std::vector<const llvm::Type*> Types;
213 for (unsigned i = 0; i < Elts.size(); ++i)
214 Types.push_back(Elts[i]->getType());
215 SType = llvm::StructType::get(Types, true);
216 }
217
Devang Pateleae15602008-02-05 02:39:50 +0000218 return llvm::ConstantStruct::get(SType, Elts);
219 }
220
Eli Friedmana8234002008-05-30 10:24:46 +0000221 llvm::Constant *EmitUnionInitialization(InitListExpr *ILE) {
Eli Friedmana8234002008-05-30 10:24:46 +0000222 RecordDecl *RD = ILE->getType()->getAsRecordType()->getDecl();
223 const llvm::Type *Ty = ConvertType(ILE->getType());
224
225 // Find the field decl we're initializing, if any
226 int FieldNo = 0; // Field no in RecordDecl
Eli Friedmanc55f98d2008-06-06 20:12:37 +0000227 FieldDecl* curField = 0;
228 while (FieldNo < RD->getNumMembers()) {
Eli Friedmana8234002008-05-30 10:24:46 +0000229 curField = RD->getMember(FieldNo);
230 FieldNo++;
Eli Friedmanc55f98d2008-06-06 20:12:37 +0000231 if (curField->getIdentifier())
232 break;
233 }
Eli Friedmana8234002008-05-30 10:24:46 +0000234
Eli Friedmanc55f98d2008-06-06 20:12:37 +0000235 if (!curField || !curField->getIdentifier() || ILE->getNumInits() == 0)
Eli Friedmana8234002008-05-30 10:24:46 +0000236 return llvm::Constant::getNullValue(Ty);
237
238 if (curField->isBitField()) {
239 // Create a dummy struct for bit-field insertion
240 unsigned NumElts = CGM.getTargetData().getABITypeSize(Ty) / 8;
241 llvm::Constant* NV = llvm::Constant::getNullValue(llvm::Type::Int8Ty);
242 std::vector<llvm::Constant*> Elts(NumElts, NV);
243
244 InsertBitfieldIntoStruct(Elts, curField, ILE->getInit(0));
245 const llvm::ArrayType *RetTy =
246 llvm::ArrayType::get(NV->getType(), NumElts);
247 return llvm::ConstantArray::get(RetTy, Elts);
248 }
249
250 llvm::Constant *C = Visit(ILE->getInit(0));
251
252 // Build a struct with the union sub-element as the first member,
253 // and padded to the appropriate size
254 std::vector<llvm::Constant*> Elts;
255 std::vector<const llvm::Type*> Types;
256 Elts.push_back(C);
257 Types.push_back(C->getType());
258 unsigned CurSize = CGM.getTargetData().getTypeStoreSize(C->getType());
259 unsigned TotalSize = CGM.getTargetData().getTypeStoreSize(Ty);
260 while (CurSize < TotalSize) {
261 Elts.push_back(llvm::Constant::getNullValue(llvm::Type::Int8Ty));
262 Types.push_back(llvm::Type::Int8Ty);
263 CurSize++;
264 }
265
266 // This always generates a packed struct
267 // FIXME: Try to generate an unpacked struct when we can
268 llvm::StructType* STy = llvm::StructType::get(Types, true);
269 return llvm::ConstantStruct::get(STy, Elts);
270 }
271
272 llvm::Constant *EmitVectorInitialization(InitListExpr *ILE) {
273 const llvm::VectorType *VType =
274 cast<llvm::VectorType>(ConvertType(ILE->getType()));
Eli Friedmancfb313b2008-05-30 12:02:14 +0000275 const llvm::Type *ElemTy = VType->getElementType();
276 std::vector<llvm::Constant*> Elts;
Devang Pateleae15602008-02-05 02:39:50 +0000277 unsigned NumElements = VType->getNumElements();
Eli Friedmancfb313b2008-05-30 12:02:14 +0000278 unsigned NumInitElements = ILE->getNumInits();
Devang Pateleae15602008-02-05 02:39:50 +0000279
Eli Friedmancfb313b2008-05-30 12:02:14 +0000280 unsigned NumInitableElts = std::min(NumInitElements, NumElements);
281
Devang Pateleae15602008-02-05 02:39:50 +0000282 // Copy initializer elements.
283 unsigned i = 0;
Eli Friedmancfb313b2008-05-30 12:02:14 +0000284 for (; i < NumInitableElts; ++i) {
Devang Pateleae15602008-02-05 02:39:50 +0000285 llvm::Constant *C = Visit(ILE->getInit(i));
Devang Pateleae15602008-02-05 02:39:50 +0000286 Elts.push_back(C);
287 }
288
Eli Friedmancfb313b2008-05-30 12:02:14 +0000289 for (; i < NumElements; ++i)
290 Elts.push_back(llvm::Constant::getNullValue(ElemTy));
291
Devang Pateleae15602008-02-05 02:39:50 +0000292 return llvm::ConstantVector::get(VType, Elts);
293 }
294
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000295 llvm::Constant *VisitInitListExpr(InitListExpr *ILE) {
Eli Friedmana8234002008-05-30 10:24:46 +0000296 if (ILE->getType()->isScalarType()) {
297 // We have a scalar in braces. Just use the first element.
298 if (ILE->getNumInits() > 0)
Anders Carlssonf6884ac2008-01-29 01:15:48 +0000299 return Visit(ILE->getInit(0));
Eli Friedmana8234002008-05-30 10:24:46 +0000300
301 const llvm::Type* RetTy = CGM.getTypes().ConvertType(ILE->getType());
302 return llvm::Constant::getNullValue(RetTy);
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000303 }
Devang Patel47fb6972008-01-29 23:23:18 +0000304
Eli Friedmana8234002008-05-30 10:24:46 +0000305 if (ILE->getType()->isArrayType())
306 return EmitArrayInitialization(ILE);
Devang Patel47fb6972008-01-29 23:23:18 +0000307
Eli Friedmana8234002008-05-30 10:24:46 +0000308 if (ILE->getType()->isStructureType())
309 return EmitStructInitialization(ILE);
310
311 if (ILE->getType()->isUnionType())
312 return EmitUnionInitialization(ILE);
313
314 if (ILE->getType()->isVectorType())
315 return EmitVectorInitialization(ILE);
316
Devang Pateleae15602008-02-05 02:39:50 +0000317 assert(0 && "Unable to handle InitListExpr");
Chris Lattner2b94fe32008-03-01 08:45:05 +0000318 // Get rid of control reaches end of void function warning.
319 // Not reached.
320 return 0;
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000321 }
Eli Friedman3b707e72008-02-21 17:57:49 +0000322
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000323 llvm::Constant *VisitImplicitCastExpr(ImplicitCastExpr *ICExpr) {
Eli Friedman3b707e72008-02-21 17:57:49 +0000324 Expr* SExpr = ICExpr->getSubExpr();
325 QualType SType = SExpr->getType();
326 llvm::Constant *C; // the intermediate expression
327 QualType T; // the type of the intermediate expression
328 if (SType->isArrayType()) {
329 // Arrays decay to a pointer to the first element
330 // VLAs would require special handling, but they can't occur here
331 C = EmitLValue(SExpr);
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000332 llvm::Constant *Idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000333 llvm::Constant *Ops[] = {Idx0, Idx0};
334 C = llvm::ConstantExpr::getGetElementPtr(C, Ops, 2);
Eli Friedman3b707e72008-02-21 17:57:49 +0000335
336 QualType ElemType = SType->getAsArrayType()->getElementType();
337 T = CGM.getContext().getPointerType(ElemType);
338 } else if (SType->isFunctionType()) {
339 // Function types decay to a pointer to the function
340 C = EmitLValue(SExpr);
341 T = CGM.getContext().getPointerType(SType);
342 } else {
343 C = Visit(SExpr);
344 T = SType;
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000345 }
Eli Friedman3b707e72008-02-21 17:57:49 +0000346
347 // Perform the conversion; note that an implicit cast can both promote
348 // and convert an array/function
349 return EmitConversion(C, T, ICExpr->getType());
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000350 }
Eli Friedman3b707e72008-02-21 17:57:49 +0000351
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000352 llvm::Constant *VisitStringLiteral(StringLiteral *E) {
353 const char *StrData = E->getStrData();
354 unsigned Len = E->getByteLength();
Chris Lattnera7ad98f2008-02-11 00:02:17 +0000355 assert(!E->getType()->isPointerType() && "Strings are always arrays");
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000356
357 // Otherwise this must be a string initializing an array in a static
358 // initializer. Don't emit it as the address of the string, emit the string
359 // data itself as an inline array.
360 const ConstantArrayType *CAT = E->getType()->getAsConstantArrayType();
361 assert(CAT && "String isn't pointer or array!");
362
363 std::string Str(StrData, StrData + Len);
364 // Null terminate the string before potentially truncating it.
365 // FIXME: What about wchar_t strings?
366 Str.push_back(0);
367
368 uint64_t RealLen = CAT->getSize().getZExtValue();
369 // String or grow the initializer to the required size.
370 if (RealLen != Str.size())
371 Str.resize(RealLen);
372
373 return llvm::ConstantArray::get(Str, false);
374 }
375
376 llvm::Constant *VisitDeclRefExpr(DeclRefExpr *E) {
377 const ValueDecl *Decl = E->getDecl();
Anders Carlssona3881fc2008-01-29 01:28:48 +0000378 if (const EnumConstantDecl *EC = dyn_cast<EnumConstantDecl>(Decl))
379 return llvm::ConstantInt::get(EC->getInitVal());
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000380 assert(0 && "Unsupported decl ref type!");
381 return 0;
382 }
383
384 llvm::Constant *VisitSizeOfAlignOfTypeExpr(const SizeOfAlignOfTypeExpr *E) {
385 return EmitSizeAlignOf(E->getArgumentType(), E->getType(), E->isSizeOf());
386 }
387
388 // Unary operators
389 llvm::Constant *VisitUnaryPlus(const UnaryOperator *E) {
390 return Visit(E->getSubExpr());
391 }
392 llvm::Constant *VisitUnaryMinus(const UnaryOperator *E) {
393 return llvm::ConstantExpr::getNeg(Visit(E->getSubExpr()));
394 }
395 llvm::Constant *VisitUnaryNot(const UnaryOperator *E) {
396 return llvm::ConstantExpr::getNot(Visit(E->getSubExpr()));
397 }
398 llvm::Constant *VisitUnaryLNot(const UnaryOperator *E) {
399 llvm::Constant *SubExpr = Visit(E->getSubExpr());
400
401 if (E->getSubExpr()->getType()->isRealFloatingType()) {
402 // Compare against 0.0 for fp scalars.
403 llvm::Constant *Zero = llvm::Constant::getNullValue(SubExpr->getType());
404 SubExpr = llvm::ConstantExpr::getFCmp(llvm::FCmpInst::FCMP_UEQ, SubExpr,
405 Zero);
406 } else {
407 assert((E->getSubExpr()->getType()->isIntegerType() ||
408 E->getSubExpr()->getType()->isPointerType()) &&
409 "Unknown scalar type to convert");
410 // Compare against an integer or pointer null.
411 llvm::Constant *Zero = llvm::Constant::getNullValue(SubExpr->getType());
412 SubExpr = llvm::ConstantExpr::getICmp(llvm::ICmpInst::ICMP_EQ, SubExpr,
413 Zero);
414 }
415
416 return llvm::ConstantExpr::getZExt(SubExpr, ConvertType(E->getType()));
417 }
418 llvm::Constant *VisitUnarySizeOf(const UnaryOperator *E) {
419 return EmitSizeAlignOf(E->getSubExpr()->getType(), E->getType(), true);
420 }
421 llvm::Constant *VisitUnaryAlignOf(const UnaryOperator *E) {
422 return EmitSizeAlignOf(E->getSubExpr()->getType(), E->getType(), false);
423 }
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000424 llvm::Constant *VisitUnaryAddrOf(const UnaryOperator *E) {
425 return EmitLValue(E->getSubExpr());
426 }
Anders Carlsson5a1deb82008-01-29 15:56:48 +0000427 llvm::Constant *VisitUnaryOffsetOf(const UnaryOperator *E) {
428 int64_t Val = E->evaluateOffsetOf(CGM.getContext());
429
430 assert(E->getType()->isIntegerType() && "Result type must be an integer!");
431
Chris Lattner98be4942008-03-05 18:54:05 +0000432 uint32_t ResultWidth =
433 static_cast<uint32_t>(CGM.getContext().getTypeSize(E->getType()));
Anders Carlsson5a1deb82008-01-29 15:56:48 +0000434 return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
435 }
Eli Friedmanbc5ed6e2008-05-29 11:22:45 +0000436
437 llvm::Constant *VisitUnaryExtension(const UnaryOperator *E) {
438 return Visit(E->getSubExpr());
439 }
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000440
Anders Carlssonce6237e2008-01-29 01:33:32 +0000441 // Binary operators
442 llvm::Constant *VisitBinOr(const BinaryOperator *E) {
443 llvm::Constant *LHS = Visit(E->getLHS());
444 llvm::Constant *RHS = Visit(E->getRHS());
445
446 return llvm::ConstantExpr::getOr(LHS, RHS);
447 }
Anders Carlsson7be3d012008-02-05 20:54:21 +0000448 llvm::Constant *VisitBinSub(const BinaryOperator *E) {
449 llvm::Constant *LHS = Visit(E->getLHS());
450 llvm::Constant *RHS = Visit(E->getRHS());
451
452 if (!isa<llvm::PointerType>(RHS->getType())) {
453 // pointer - int
454 if (isa<llvm::PointerType>(LHS->getType())) {
455 llvm::Constant *Idx = llvm::ConstantExpr::getNeg(RHS);
456
457 return llvm::ConstantExpr::getGetElementPtr(LHS, &Idx, 1);
458 }
459
460 // int - int
461 return llvm::ConstantExpr::getSub(LHS, RHS);
462 }
Nuno Lopes77e1dfc2008-06-06 16:41:08 +0000463
464 assert(isa<llvm::PointerType>(LHS->getType()));
465
466 const llvm::Type *ResultType = ConvertType(E->getType());
467 const QualType Type = E->getLHS()->getType();
468 const QualType ElementType = Type->getAsPointerType()->getPointeeType();
469
470 LHS = llvm::ConstantExpr::getPtrToInt(LHS, ResultType);
471 RHS = llvm::ConstantExpr::getPtrToInt(RHS, ResultType);
472
473 llvm::Constant *sub = llvm::ConstantExpr::getSub(LHS, RHS);
474 llvm::Constant *size = EmitSizeAlignOf(ElementType, E->getType(), true);
475 return llvm::ConstantExpr::getSDiv(sub, size);
Anders Carlsson7be3d012008-02-05 20:54:21 +0000476 }
477
478 llvm::Constant *VisitBinShl(const BinaryOperator *E) {
479 llvm::Constant *LHS = Visit(E->getLHS());
480 llvm::Constant *RHS = Visit(E->getRHS());
Anders Carlssonce6237e2008-01-29 01:33:32 +0000481
Anders Carlsson7be3d012008-02-05 20:54:21 +0000482 // LLVM requires the LHS and RHS to be the same type: promote or truncate the
483 // RHS to the same size as the LHS.
484 if (LHS->getType() != RHS->getType())
485 RHS = llvm::ConstantExpr::getIntegerCast(RHS, LHS->getType(), false);
486
487 return llvm::ConstantExpr::getShl(LHS, RHS);
488 }
489
490 llvm::Constant *VisitBinMul(const BinaryOperator *E) {
491 llvm::Constant *LHS = Visit(E->getLHS());
492 llvm::Constant *RHS = Visit(E->getRHS());
493
494 return llvm::ConstantExpr::getMul(LHS, RHS);
495 }
496
497 llvm::Constant *VisitBinDiv(const BinaryOperator *E) {
498 llvm::Constant *LHS = Visit(E->getLHS());
499 llvm::Constant *RHS = Visit(E->getRHS());
500
501 if (LHS->getType()->isFPOrFPVector())
502 return llvm::ConstantExpr::getFDiv(LHS, RHS);
503 else if (E->getType()->isUnsignedIntegerType())
504 return llvm::ConstantExpr::getUDiv(LHS, RHS);
505 else
506 return llvm::ConstantExpr::getSDiv(LHS, RHS);
507 }
508
509 llvm::Constant *VisitBinAdd(const BinaryOperator *E) {
510 llvm::Constant *LHS = Visit(E->getLHS());
511 llvm::Constant *RHS = Visit(E->getRHS());
512
513 if (!E->getType()->isPointerType())
514 return llvm::ConstantExpr::getAdd(LHS, RHS);
515
Anders Carlsson87a98752008-02-06 07:23:14 +0000516 llvm::Constant *Ptr, *Idx;
517 if (isa<llvm::PointerType>(LHS->getType())) { // pointer + int
518 Ptr = LHS;
519 Idx = RHS;
520 } else { // int + pointer
521 Ptr = RHS;
522 Idx = LHS;
523 }
524
525 return llvm::ConstantExpr::getGetElementPtr(Ptr, &Idx, 1);
Anders Carlsson7be3d012008-02-05 20:54:21 +0000526 }
527
528 llvm::Constant *VisitBinAnd(const BinaryOperator *E) {
529 llvm::Constant *LHS = Visit(E->getLHS());
530 llvm::Constant *RHS = Visit(E->getRHS());
531
532 return llvm::ConstantExpr::getAnd(LHS, RHS);
533 }
Eli Friedmanbc5ed6e2008-05-29 11:22:45 +0000534
Eli Friedmanb8965962008-05-29 15:17:49 +0000535 llvm::Constant *EmitCmp(const BinaryOperator *E,
536 llvm::CmpInst::Predicate SignedPred,
537 llvm::CmpInst::Predicate UnsignedPred,
538 llvm::CmpInst::Predicate FloatPred) {
Eli Friedmanbc5ed6e2008-05-29 11:22:45 +0000539 llvm::Constant *LHS = Visit(E->getLHS());
540 llvm::Constant *RHS = Visit(E->getRHS());
Eli Friedmanb8965962008-05-29 15:17:49 +0000541 llvm::Constant *Result;
542 if (LHS->getType()->isInteger() ||
543 isa<llvm::PointerType>(LHS->getType())) {
544 if (E->getLHS()->getType()->isSignedIntegerType())
545 Result = llvm::ConstantExpr::getICmp(SignedPred, LHS, RHS);
546 else
547 Result = llvm::ConstantExpr::getICmp(UnsignedPred, LHS, RHS);
548 } else if (LHS->getType()->isFloatingPoint()) {
549 Result = llvm::ConstantExpr::getFCmp(FloatPred, LHS, RHS);
550 } else {
551 CGM.WarnUnsupported(E, "constant expression");
552 Result = llvm::ConstantInt::getFalse();
553 }
Eli Friedmanbc5ed6e2008-05-29 11:22:45 +0000554
555 const llvm::Type* ResultType = ConvertType(E->getType());
Eli Friedmanbc5ed6e2008-05-29 11:22:45 +0000556 return llvm::ConstantExpr::getZExtOrBitCast(Result, ResultType);
557 }
558
Eli Friedmanb8965962008-05-29 15:17:49 +0000559 llvm::Constant *VisitBinNE(const BinaryOperator *E) {
560 return EmitCmp(E, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_NE,
561 llvm::CmpInst::FCMP_ONE);
562 }
563
564 llvm::Constant *VisitBinEQ(const BinaryOperator *E) {
565 return EmitCmp(E, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_EQ,
566 llvm::CmpInst::FCMP_OEQ);
567 }
568
569 llvm::Constant *VisitBinLT(const BinaryOperator *E) {
570 return EmitCmp(E, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_ULT,
571 llvm::CmpInst::FCMP_OLT);
572 }
573
574 llvm::Constant *VisitBinLE(const BinaryOperator *E) {
575 return EmitCmp(E, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_ULE,
576 llvm::CmpInst::FCMP_OLE);
577 }
578
579 llvm::Constant *VisitBinGT(const BinaryOperator *E) {
580 return EmitCmp(E, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_UGT,
581 llvm::CmpInst::FCMP_OGT);
582 }
583
584 llvm::Constant *VisitBinGE(const BinaryOperator *E) {
585 return EmitCmp(E, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGE,
586 llvm::CmpInst::FCMP_OGE);
587 }
588
Eli Friedmanbc5ed6e2008-05-29 11:22:45 +0000589 llvm::Constant *VisitConditionalOperator(const ConditionalOperator *E) {
590 llvm::Constant *Cond = Visit(E->getCond());
591 llvm::Constant *CondVal = EmitConversionToBool(Cond, E->getType());
592 llvm::ConstantInt *CondValInt = dyn_cast<llvm::ConstantInt>(CondVal);
593 if (!CondValInt) {
594 CGM.WarnUnsupported(E, "constant expression");
595 return llvm::Constant::getNullValue(ConvertType(E->getType()));
596 }
597 if (CondValInt->isOne()) {
598 if (E->getLHS())
599 return Visit(E->getLHS());
600 return Cond;
601 }
602
603 return Visit(E->getRHS());
604 }
Anders Carlsson7be3d012008-02-05 20:54:21 +0000605
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000606 // Utility methods
607 const llvm::Type *ConvertType(QualType T) {
608 return CGM.getTypes().ConvertType(T);
609 }
610
611 llvm::Constant *EmitConversionToBool(llvm::Constant *Src, QualType SrcType) {
612 assert(SrcType->isCanonical() && "EmitConversion strips typedefs");
613
614 if (SrcType->isRealFloatingType()) {
615 // Compare against 0.0 for fp scalars.
616 llvm::Constant *Zero = llvm::Constant::getNullValue(Src->getType());
617 return llvm::ConstantExpr::getFCmp(llvm::FCmpInst::FCMP_UNE, Src, Zero);
618 }
619
620 assert((SrcType->isIntegerType() || SrcType->isPointerType()) &&
621 "Unknown scalar type to convert");
622
623 // Compare against an integer or pointer null.
624 llvm::Constant *Zero = llvm::Constant::getNullValue(Src->getType());
625 return llvm::ConstantExpr::getICmp(llvm::ICmpInst::ICMP_NE, Src, Zero);
626 }
627
628 llvm::Constant *EmitConversion(llvm::Constant *Src, QualType SrcType,
629 QualType DstType) {
Chris Lattnerd394cc62008-07-26 22:39:33 +0000630 SrcType = CGM.getContext().getCanonicalType(SrcType);
631 DstType = CGM.getContext().getCanonicalType(DstType);
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000632 if (SrcType == DstType) return Src;
633
634 // Handle conversions to bool first, they are special: comparisons against 0.
635 if (DstType->isBooleanType())
636 return EmitConversionToBool(Src, SrcType);
637
638 const llvm::Type *DstTy = ConvertType(DstType);
639
640 // Ignore conversions like int -> uint.
641 if (Src->getType() == DstTy)
642 return Src;
643
644 // Handle pointer conversions next: pointers can only be converted to/from
645 // other pointers and integers.
Eli Friedmanc53296e2008-06-07 17:27:51 +0000646 if (isa<llvm::PointerType>(DstTy)) {
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000647 // The source value may be an integer, or a pointer.
648 if (isa<llvm::PointerType>(Src->getType()))
649 return llvm::ConstantExpr::getBitCast(Src, DstTy);
Anders Carlsson84005b42008-01-26 04:30:23 +0000650 assert(SrcType->isIntegerType() &&"Not ptr->ptr or int->ptr conversion?");
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000651 return llvm::ConstantExpr::getIntToPtr(Src, DstTy);
652 }
653
Eli Friedmanc53296e2008-06-07 17:27:51 +0000654 if (isa<llvm::PointerType>(Src->getType())) {
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000655 // Must be an ptr to int cast.
656 assert(isa<llvm::IntegerType>(DstTy) && "not ptr->int?");
657 return llvm::ConstantExpr::getPtrToInt(Src, DstTy);
658 }
659
660 // A scalar source can be splatted to a vector of the same element type
661 if (isa<llvm::VectorType>(DstTy) && !isa<VectorType>(SrcType)) {
662 const llvm::VectorType *VT = cast<llvm::VectorType>(DstTy);
663 assert((VT->getElementType() == Src->getType()) &&
664 "Vector element type must match scalar type to splat.");
665 unsigned NumElements = DstType->getAsVectorType()->getNumElements();
666 llvm::SmallVector<llvm::Constant*, 16> Elements;
667 for (unsigned i = 0; i < NumElements; i++)
668 Elements.push_back(Src);
669
670 return llvm::ConstantVector::get(&Elements[0], NumElements);
671 }
672
673 if (isa<llvm::VectorType>(Src->getType()) ||
674 isa<llvm::VectorType>(DstTy)) {
675 return llvm::ConstantExpr::getBitCast(Src, DstTy);
676 }
677
678 // Finally, we have the arithmetic types: real int/float.
679 if (isa<llvm::IntegerType>(Src->getType())) {
680 bool InputSigned = SrcType->isSignedIntegerType();
681 if (isa<llvm::IntegerType>(DstTy))
682 return llvm::ConstantExpr::getIntegerCast(Src, DstTy, InputSigned);
683 else if (InputSigned)
684 return llvm::ConstantExpr::getSIToFP(Src, DstTy);
685 else
686 return llvm::ConstantExpr::getUIToFP(Src, DstTy);
687 }
688
689 assert(Src->getType()->isFloatingPoint() && "Unknown real conversion");
690 if (isa<llvm::IntegerType>(DstTy)) {
691 if (DstType->isSignedIntegerType())
692 return llvm::ConstantExpr::getFPToSI(Src, DstTy);
693 else
694 return llvm::ConstantExpr::getFPToUI(Src, DstTy);
695 }
696
697 assert(DstTy->isFloatingPoint() && "Unknown real conversion");
698 if (DstTy->getTypeID() < Src->getType()->getTypeID())
699 return llvm::ConstantExpr::getFPTrunc(Src, DstTy);
700 else
701 return llvm::ConstantExpr::getFPExtend(Src, DstTy);
702 }
703
704 llvm::Constant *EmitSizeAlignOf(QualType TypeToSize,
705 QualType RetType, bool isSizeOf) {
706 std::pair<uint64_t, unsigned> Info =
Chris Lattner98be4942008-03-05 18:54:05 +0000707 CGM.getContext().getTypeInfo(TypeToSize);
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000708
709 uint64_t Val = isSizeOf ? Info.first : Info.second;
710 Val /= 8; // Return size in bytes, not bits.
711
712 assert(RetType->isIntegerType() && "Result type must be an integer!");
713
Chris Lattner98be4942008-03-05 18:54:05 +0000714 uint32_t ResultWidth =
715 static_cast<uint32_t>(CGM.getContext().getTypeSize(RetType));
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000716 return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
717 }
Anders Carlsson84005b42008-01-26 04:30:23 +0000718
719 llvm::Constant *EmitLValue(Expr *E) {
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000720 switch (E->getStmtClass()) {
Eli Friedman546d94c2008-02-11 00:23:10 +0000721 default: break;
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000722 case Expr::ParenExprClass:
723 // Elide parenthesis
724 return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
725 case Expr::CompoundLiteralExprClass: {
726 // Note that due to the nature of compound literals, this is guaranteed
727 // to be the only use of the variable, so we just generate it here.
Anders Carlsson84005b42008-01-26 04:30:23 +0000728 CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(E);
729 llvm::Constant* C = Visit(CLE->getInitializer());
Chris Lattnera7ad98f2008-02-11 00:02:17 +0000730 C = new llvm::GlobalVariable(C->getType(),E->getType().isConstQualified(),
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000731 llvm::GlobalValue::InternalLinkage,
732 C, ".compoundliteral", &CGM.getModule());
733 return C;
Anders Carlsson84005b42008-01-26 04:30:23 +0000734 }
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000735 case Expr::DeclRefExprClass: {
Anders Carlsson84005b42008-01-26 04:30:23 +0000736 ValueDecl *Decl = cast<DeclRefExpr>(E)->getDecl();
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000737 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl))
Daniel Dunbarbd012ff2008-07-29 23:18:29 +0000738 return CGM.GetAddrOfFunction(FD);
Steve Naroff248a7532008-04-15 22:42:06 +0000739 if (const VarDecl* VD = dyn_cast<VarDecl>(Decl)) {
740 if (VD->isFileVarDecl())
Daniel Dunbarbd012ff2008-07-29 23:18:29 +0000741 return CGM.GetAddrOfGlobalVar(VD);
Steve Naroff248a7532008-04-15 22:42:06 +0000742 else if (VD->isBlockVarDecl()) {
743 assert(CGF && "Can't access static local vars without CGF");
744 return CGF->GetAddrOfStaticLocalVar(VD);
745 }
Lauro Ramos Venancio81373352008-02-26 21:41:45 +0000746 }
Eli Friedman546d94c2008-02-11 00:23:10 +0000747 break;
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000748 }
749 case Expr::MemberExprClass: {
Anders Carlsson84005b42008-01-26 04:30:23 +0000750 MemberExpr* ME = cast<MemberExpr>(E);
Anders Carlsson84005b42008-01-26 04:30:23 +0000751 llvm::Constant *Base;
752 if (ME->isArrow())
753 Base = Visit(ME->getBase());
754 else
755 Base = EmitLValue(ME->getBase());
Lauro Ramos Venancio5bfe18c2008-01-30 21:23:20 +0000756
757 unsigned FieldNumber = CGM.getTypes().getLLVMFieldNo(ME->getMemberDecl());
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000758 llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
759 llvm::Constant *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
760 FieldNumber);
761 llvm::Value *Ops[] = {Zero, Idx};
762 return llvm::ConstantExpr::getGetElementPtr(Base, Ops, 2);
763 }
764 case Expr::ArraySubscriptExprClass: {
Anders Carlsson84005b42008-01-26 04:30:23 +0000765 ArraySubscriptExpr* ASExpr = cast<ArraySubscriptExpr>(E);
766 llvm::Constant *Base = Visit(ASExpr->getBase());
767 llvm::Constant *Index = Visit(ASExpr->getIdx());
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000768 assert(!ASExpr->getBase()->getType()->isVectorType() &&
769 "Taking the address of a vector component is illegal!");
770 return llvm::ConstantExpr::getGetElementPtr(Base, &Index, 1);
771 }
772 case Expr::StringLiteralClass: {
Anders Carlsson84005b42008-01-26 04:30:23 +0000773 StringLiteral *String = cast<StringLiteral>(E);
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000774 assert(!String->isWide() && "Cannot codegen wide strings yet");
Anders Carlsson84005b42008-01-26 04:30:23 +0000775 const char *StrData = String->getStrData();
776 unsigned Len = String->getByteLength();
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000777
Anders Carlsson84005b42008-01-26 04:30:23 +0000778 return CGM.GetAddrOfConstantString(std::string(StrData, StrData + Len));
779 }
780 case Expr::UnaryOperatorClass: {
781 UnaryOperator *Exp = cast<UnaryOperator>(E);
782 switch (Exp->getOpcode()) {
Eli Friedman546d94c2008-02-11 00:23:10 +0000783 default: break;
784 case UnaryOperator::Extension:
Anders Carlsson84005b42008-01-26 04:30:23 +0000785 // Extension is just a wrapper for expressions
786 return EmitLValue(Exp->getSubExpr());
787 case UnaryOperator::Real:
788 case UnaryOperator::Imag: {
789 // The address of __real or __imag is just a GEP off the address
790 // of the internal expression
791 llvm::Constant* C = EmitLValue(Exp->getSubExpr());
792 llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
793 llvm::Constant *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000794 Exp->getOpcode() == UnaryOperator::Imag);
Anders Carlsson84005b42008-01-26 04:30:23 +0000795 llvm::Value *Ops[] = {Zero, Idx};
796 return llvm::ConstantExpr::getGetElementPtr(C, Ops, 2);
797 }
798 case UnaryOperator::Deref:
799 // The address of a deref is just the value of the expression
800 return Visit(Exp->getSubExpr());
801 }
Eli Friedman546d94c2008-02-11 00:23:10 +0000802 break;
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000803 }
Eli Friedman546d94c2008-02-11 00:23:10 +0000804 }
805 CGM.WarnUnsupported(E, "constant l-value expression");
806 llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
807 return llvm::UndefValue::get(Ty);
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000808 }
Anders Carlssone3d3b7d2008-01-26 02:08:50 +0000809
810};
811
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000812} // end anonymous namespace.
813
814
Lauro Ramos Venancio81373352008-02-26 21:41:45 +0000815llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
Chris Lattner96196622008-07-26 22:37:01 +0000816 CodeGenFunction *CGF) {
817 QualType type = Context.getCanonicalType(E->getType());
Eli Friedman7dfa6392008-06-01 15:31:44 +0000818
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000819 if (type->isIntegerType()) {
Chris Lattner98be4942008-03-05 18:54:05 +0000820 llvm::APSInt Value(static_cast<uint32_t>(Context.getTypeSize(type)));
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000821 if (E->isIntegerConstantExpr(Value, Context)) {
822 return llvm::ConstantInt::get(Value);
823 }
824 }
Eli Friedman7dfa6392008-06-01 15:31:44 +0000825
826 llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E));
827 if (C->getType() == llvm::Type::Int1Ty) {
828 const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType());
829 C = llvm::ConstantExpr::getZExt(C, BoolTy);
830 }
831 return C;
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000832}