blob: 9de5d3426f0b252d0314227deddd50d91d0bfa4b [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- CodeGenModule.cpp - Emit LLVM Code from ASTs for a Module --------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This coordinates the per-module state used while generating code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CodeGenModule.h"
15#include "CodeGenFunction.h"
16#include "clang/AST/ASTContext.h"
17#include "clang/AST/Decl.h"
Chris Lattner2c8569d2007-12-02 07:19:18 +000018#include "clang/Basic/Diagnostic.h"
Chris Lattner45e8cbd2007-11-28 05:34:05 +000019#include "clang/Basic/LangOptions.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "clang/Basic/TargetInfo.h"
Chris Lattner8f32f712007-07-14 00:23:28 +000021#include "llvm/Constants.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000022#include "llvm/DerivedTypes.h"
Chris Lattnerbef20ac2007-08-31 04:31:45 +000023#include "llvm/Module.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000024#include "llvm/Intrinsics.h"
Christopher Lambce39faa2007-12-02 08:49:54 +000025#include <algorithm>
Reid Spencer5f016e22007-07-11 17:01:13 +000026using namespace clang;
27using namespace CodeGen;
28
29
Chris Lattner45e8cbd2007-11-28 05:34:05 +000030CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
Chris Lattnerfb97b032007-12-02 01:40:18 +000031 llvm::Module &M, const llvm::TargetData &TD,
32 Diagnostic &diags)
33 : Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags),
Devang Patel7a4718e2007-10-31 20:01:01 +000034 Types(C, M, TD), MemCpyFn(0), CFConstantStringClassRef(0) {}
Reid Spencer5f016e22007-07-11 17:01:13 +000035
Chris Lattner2c8569d2007-12-02 07:19:18 +000036/// WarnUnsupported - Print out a warning that codegen doesn't support the
37/// specified stmt yet.
38void CodeGenModule::WarnUnsupported(const Stmt *S, const char *Type) {
39 unsigned DiagID = getDiags().getCustomDiagID(Diagnostic::Warning,
40 "cannot codegen this %0 yet");
41 SourceRange Range = S->getSourceRange();
42 std::string Msg = Type;
Ted Kremenek9c728dc2007-12-12 22:39:36 +000043 getDiags().Report(Context.getFullLoc(S->getLocStart()), DiagID,
Ted Kremenek7a9d49f2007-12-11 21:27:55 +000044 &Msg, 1, &Range, 1);
Chris Lattner2c8569d2007-12-02 07:19:18 +000045}
Chris Lattner58c3f9e2007-12-02 06:27:33 +000046
Chris Lattnerc6fdc342008-01-12 07:05:38 +000047/// WarnUnsupported - Print out a warning that codegen doesn't support the
48/// specified decl yet.
49void CodeGenModule::WarnUnsupported(const Decl *D, const char *Type) {
50 unsigned DiagID = getDiags().getCustomDiagID(Diagnostic::Warning,
51 "cannot codegen this %0 yet");
52 std::string Msg = Type;
53 getDiags().Report(Context.getFullLoc(D->getLocation()), DiagID,
54 &Msg, 1);
55}
56
Chris Lattner58c3f9e2007-12-02 06:27:33 +000057/// ReplaceMapValuesWith - This is a really slow and bad function that
58/// searches for any entries in GlobalDeclMap that point to OldVal, changing
59/// them to point to NewVal. This is badbadbad, FIXME!
60void CodeGenModule::ReplaceMapValuesWith(llvm::Constant *OldVal,
61 llvm::Constant *NewVal) {
62 for (llvm::DenseMap<const Decl*, llvm::Constant*>::iterator
63 I = GlobalDeclMap.begin(), E = GlobalDeclMap.end(); I != E; ++I)
64 if (I->second == OldVal) I->second = NewVal;
65}
66
67
Chris Lattner9cd4fe42007-12-02 07:09:19 +000068llvm::Constant *CodeGenModule::GetAddrOfFunctionDecl(const FunctionDecl *D,
69 bool isDefinition) {
70 // See if it is already in the map. If so, just return it.
Reid Spencer5f016e22007-07-11 17:01:13 +000071 llvm::Constant *&Entry = GlobalDeclMap[D];
72 if (Entry) return Entry;
73
Chris Lattner9cd4fe42007-12-02 07:09:19 +000074 const llvm::Type *Ty = getTypes().ConvertType(D->getType());
75
76 // Check to see if the function already exists.
77 llvm::Function *F = getModule().getFunction(D->getName());
78 const llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
79
80 // If it doesn't already exist, just create and return an entry.
81 if (F == 0) {
Reid Spencer5f016e22007-07-11 17:01:13 +000082 // FIXME: param attributes for sext/zext etc.
83 return Entry = new llvm::Function(FTy, llvm::Function::ExternalLinkage,
84 D->getName(), &getModule());
85 }
86
Chris Lattner9cd4fe42007-12-02 07:09:19 +000087 // If the pointer type matches, just return it.
Christopher Lambddc23f32007-12-17 01:11:20 +000088 llvm::Type *PFTy = llvm::PointerType::getUnqual(Ty);
Chris Lattner9cd4fe42007-12-02 07:09:19 +000089 if (PFTy == F->getType()) return Entry = F;
Chris Lattnerfafad832007-12-02 06:30:46 +000090
Chris Lattner9cd4fe42007-12-02 07:09:19 +000091 // If this isn't a definition, just return it casted to the right type.
92 if (!isDefinition)
93 return Entry = llvm::ConstantExpr::getBitCast(F, PFTy);
94
95 // Otherwise, we have a definition after a prototype with the wrong type.
96 // F is the Function* for the one with the wrong type, we must make a new
97 // Function* and update everything that used F (a declaration) with the new
98 // Function* (which will be a definition).
99 //
100 // This happens if there is a prototype for a function (e.g. "int f()") and
101 // then a definition of a different type (e.g. "int f(int x)"). Start by
102 // making a new function of the correct type, RAUW, then steal the name.
103 llvm::Function *NewFn = new llvm::Function(FTy,
104 llvm::Function::ExternalLinkage,
105 "", &getModule());
106 NewFn->takeName(F);
107
108 // Replace uses of F with the Function we will endow with a body.
109 llvm::Constant *NewPtrForOldDecl =
110 llvm::ConstantExpr::getBitCast(NewFn, F->getType());
111 F->replaceAllUsesWith(NewPtrForOldDecl);
112
113 // FIXME: Update the globaldeclmap for the previous decl of this name. We
114 // really want a way to walk all of these, but we don't have it yet. This
115 // is incredibly slow!
116 ReplaceMapValuesWith(F, NewPtrForOldDecl);
117
118 // Ok, delete the old function now, which is dead.
119 assert(F->isDeclaration() && "Shouldn't replace non-declaration");
120 F->eraseFromParent();
121
122 // Return the new function which has the right type.
123 return Entry = NewFn;
124}
125
Chris Lattnerc4b23a52008-02-05 06:37:34 +0000126static bool IsZeroElementArray(const llvm::Type *Ty) {
127 if (const llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(Ty))
128 return ATy->getNumElements() == 0;
129 return false;
130}
131
Chris Lattner2b9d2ca2007-12-18 08:16:44 +0000132llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
133 bool isDefinition) {
134 assert(D->hasGlobalStorage() && "Not a global variable");
135
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000136 // See if it is already in the map.
137 llvm::Constant *&Entry = GlobalDeclMap[D];
138 if (Entry) return Entry;
139
Christopher Lambebb97e92008-02-04 02:31:56 +0000140 QualType ASTTy = D->getType();
141 const llvm::Type *Ty = getTypes().ConvertTypeForMem(ASTTy);
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000142
143 // Check to see if the global already exists.
Chris Lattner49573782008-02-02 04:43:11 +0000144 llvm::GlobalVariable *GV = getModule().getGlobalVariable(D->getName(), true);
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000145
146 // If it doesn't already exist, just create and return an entry.
147 if (GV == 0) {
148 return Entry = new llvm::GlobalVariable(Ty, false,
149 llvm::GlobalValue::ExternalLinkage,
Christopher Lambebb97e92008-02-04 02:31:56 +0000150 0, D->getName(), &getModule(), 0,
151 ASTTy.getAddressSpace());
Chris Lattnerfafad832007-12-02 06:30:46 +0000152 }
153
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000154 // If the pointer type matches, just return it.
Christopher Lambddc23f32007-12-17 01:11:20 +0000155 llvm::Type *PTy = llvm::PointerType::getUnqual(Ty);
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000156 if (PTy == GV->getType()) return Entry = GV;
157
158 // If this isn't a definition, just return it casted to the right type.
159 if (!isDefinition)
160 return Entry = llvm::ConstantExpr::getBitCast(GV, PTy);
161
162
163 // Otherwise, we have a definition after a prototype with the wrong type.
164 // GV is the GlobalVariable* for the one with the wrong type, we must make a
165 /// new GlobalVariable* and update everything that used GV (a declaration)
166 // with the new GlobalVariable* (which will be a definition).
167 //
168 // This happens if there is a prototype for a global (e.g. "extern int x[];")
169 // and then a definition of a different type (e.g. "int x[10];"). Start by
170 // making a new global of the correct type, RAUW, then steal the name.
171 llvm::GlobalVariable *NewGV =
172 new llvm::GlobalVariable(Ty, false, llvm::GlobalValue::ExternalLinkage,
Christopher Lambebb97e92008-02-04 02:31:56 +0000173 0, D->getName(), &getModule(), 0,
174 ASTTy.getAddressSpace());
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000175 NewGV->takeName(GV);
176
177 // Replace uses of GV with the globalvalue we will endow with a body.
178 llvm::Constant *NewPtrForOldDecl =
179 llvm::ConstantExpr::getBitCast(NewGV, GV->getType());
180 GV->replaceAllUsesWith(NewPtrForOldDecl);
181
182 // FIXME: Update the globaldeclmap for the previous decl of this name. We
183 // really want a way to walk all of these, but we don't have it yet. This
184 // is incredibly slow!
185 ReplaceMapValuesWith(GV, NewPtrForOldDecl);
186
Chris Lattnerc4b23a52008-02-05 06:37:34 +0000187 // Verify that GV was a declaration or something like x[] which turns into
188 // [0 x type].
189 assert((GV->isDeclaration() ||
190 IsZeroElementArray(GV->getType()->getElementType())) &&
191 "Shouldn't replace non-declaration");
192
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000193 // Ok, delete the old global now, which is dead.
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000194 GV->eraseFromParent();
195
196 // Return the new global which has the right type.
197 return Entry = NewGV;
Reid Spencer5f016e22007-07-11 17:01:13 +0000198}
199
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000200
Chris Lattner88a69ad2007-07-13 05:13:43 +0000201void CodeGenModule::EmitFunction(const FunctionDecl *FD) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000202 // If this is not a prototype, emit the body.
203 if (FD->getBody())
204 CodeGenFunction(*this).GenerateCode(FD);
205}
206
Anders Carlsson3b1d57b2008-01-26 01:36:00 +0000207llvm::Constant *CodeGenModule::EmitGlobalInit(const Expr *Expr) {
208 return EmitConstantExpr(Expr);
Devang Patel9e32d4b2007-10-30 21:27:20 +0000209}
210
Chris Lattner88a69ad2007-07-13 05:13:43 +0000211void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000212 // If this is just a forward declaration of the variable, don't emit it now,
213 // allow it to be emitted lazily on its first use.
Chris Lattner88a69ad2007-07-13 05:13:43 +0000214 if (D->getStorageClass() == VarDecl::Extern && D->getInit() == 0)
215 return;
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000216
217 // Get the global, forcing it to be a direct reference.
218 llvm::GlobalVariable *GV =
Chris Lattner2b9d2ca2007-12-18 08:16:44 +0000219 cast<llvm::GlobalVariable>(GetAddrOfGlobalVar(D, true));
Chris Lattner9cd4fe42007-12-02 07:09:19 +0000220
221 // Convert the initializer, or use zero if appropriate.
Chris Lattner8f32f712007-07-14 00:23:28 +0000222 llvm::Constant *Init = 0;
223 if (D->getInit() == 0) {
Chris Lattner88a69ad2007-07-13 05:13:43 +0000224 Init = llvm::Constant::getNullValue(GV->getType()->getElementType());
Chris Lattner8f32f712007-07-14 00:23:28 +0000225 } else if (D->getType()->isIntegerType()) {
Hartmut Kaiser7b660002007-10-17 15:00:17 +0000226 llvm::APSInt Value(static_cast<uint32_t>(
Chris Lattner47f7dbf2007-09-04 02:34:27 +0000227 getContext().getTypeSize(D->getInit()->getType(), SourceLocation())));
Chris Lattner590b6642007-07-15 23:26:56 +0000228 if (D->getInit()->isIntegerConstantExpr(Value, Context))
Chris Lattner8f32f712007-07-14 00:23:28 +0000229 Init = llvm::ConstantInt::get(Value);
230 }
Devang Patel8e53e722007-10-26 16:31:40 +0000231
Devang Patel9e32d4b2007-10-30 21:27:20 +0000232 if (!Init)
Oliver Hunt28247232007-12-02 00:11:25 +0000233 Init = EmitGlobalInit(D->getInit());
Devang Patel8e53e722007-10-26 16:31:40 +0000234
Chris Lattnerf89dfb22007-12-10 00:05:55 +0000235 assert(GV->getType()->getElementType() == Init->getType() &&
236 "Initializer codegen type mismatch!");
Chris Lattner88a69ad2007-07-13 05:13:43 +0000237 GV->setInitializer(Init);
238
239 // Set the llvm linkage type as appropriate.
240 // FIXME: This isn't right. This should handle common linkage and other
241 // stuff.
242 switch (D->getStorageClass()) {
243 case VarDecl::Auto:
244 case VarDecl::Register:
245 assert(0 && "Can't have auto or register globals");
246 case VarDecl::None:
247 case VarDecl::Extern:
Steve Naroffd6326c62008-01-25 22:14:40 +0000248 case VarDecl::PrivateExtern:
Chris Lattner88a69ad2007-07-13 05:13:43 +0000249 // todo: common
250 break;
251 case VarDecl::Static:
252 GV->setLinkage(llvm::GlobalVariable::InternalLinkage);
253 break;
254 }
255}
Reid Spencer5f016e22007-07-11 17:01:13 +0000256
Chris Lattner32b266c2007-07-14 00:16:50 +0000257/// EmitGlobalVarDeclarator - Emit all the global vars attached to the specified
258/// declarator chain.
259void CodeGenModule::EmitGlobalVarDeclarator(const FileVarDecl *D) {
260 for (; D; D = cast_or_null<FileVarDecl>(D->getNextDeclarator()))
261 EmitGlobalVar(D);
262}
Reid Spencer5f016e22007-07-11 17:01:13 +0000263
Chris Lattnerbef20ac2007-08-31 04:31:45 +0000264/// getBuiltinLibFunction
265llvm::Function *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) {
Chris Lattner1426fec2007-12-13 00:38:03 +0000266 if (BuiltinID > BuiltinFunctions.size())
267 BuiltinFunctions.resize(BuiltinID);
Chris Lattnerbef20ac2007-08-31 04:31:45 +0000268
Chris Lattner1426fec2007-12-13 00:38:03 +0000269 // Cache looked up functions. Since builtin id #0 is invalid we don't reserve
270 // a slot for it.
271 assert(BuiltinID && "Invalid Builtin ID");
272 llvm::Function *&FunctionSlot = BuiltinFunctions[BuiltinID-1];
Chris Lattnerbef20ac2007-08-31 04:31:45 +0000273 if (FunctionSlot)
274 return FunctionSlot;
275
276 assert(Context.BuiltinInfo.isLibFunction(BuiltinID) && "isn't a lib fn");
277
278 // Get the name, skip over the __builtin_ prefix.
279 const char *Name = Context.BuiltinInfo.GetName(BuiltinID)+10;
280
281 // Get the type for the builtin.
282 QualType Type = Context.BuiltinInfo.GetBuiltinType(BuiltinID, Context);
283 const llvm::FunctionType *Ty =
284 cast<llvm::FunctionType>(getTypes().ConvertType(Type));
285
286 // FIXME: This has a serious problem with code like this:
287 // void abs() {}
288 // ... __builtin_abs(x);
289 // The two versions of abs will collide. The fix is for the builtin to win,
290 // and for the existing one to be turned into a constantexpr cast of the
291 // builtin. In the case where the existing one is a static function, it
292 // should just be renamed.
Chris Lattnerc5e940f2007-08-31 04:44:06 +0000293 if (llvm::Function *Existing = getModule().getFunction(Name)) {
294 if (Existing->getFunctionType() == Ty && Existing->hasExternalLinkage())
295 return FunctionSlot = Existing;
296 assert(Existing == 0 && "FIXME: Name collision");
297 }
Chris Lattnerbef20ac2007-08-31 04:31:45 +0000298
299 // FIXME: param attributes for sext/zext etc.
300 return FunctionSlot = new llvm::Function(Ty, llvm::Function::ExternalLinkage,
301 Name, &getModule());
302}
303
Chris Lattner7acda7c2007-12-18 00:25:38 +0000304llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,
305 unsigned NumTys) {
306 return llvm::Intrinsic::getDeclaration(&getModule(),
307 (llvm::Intrinsic::ID)IID, Tys, NumTys);
308}
Chris Lattnerbef20ac2007-08-31 04:31:45 +0000309
Reid Spencer5f016e22007-07-11 17:01:13 +0000310llvm::Function *CodeGenModule::getMemCpyFn() {
311 if (MemCpyFn) return MemCpyFn;
312 llvm::Intrinsic::ID IID;
Chris Lattnerd2d2a112007-07-14 01:29:45 +0000313 uint64_t Size; unsigned Align;
Ted Kremenek9c728dc2007-12-12 22:39:36 +0000314 Context.Target.getPointerInfo(Size, Align, FullSourceLoc());
Chris Lattnerd2d2a112007-07-14 01:29:45 +0000315 switch (Size) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000316 default: assert(0 && "Unknown ptr width");
317 case 32: IID = llvm::Intrinsic::memcpy_i32; break;
318 case 64: IID = llvm::Intrinsic::memcpy_i64; break;
319 }
Chris Lattner7acda7c2007-12-18 00:25:38 +0000320 return MemCpyFn = getIntrinsic(IID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000321}
Anders Carlssonc9e20912007-08-21 00:21:21 +0000322
Chris Lattner7acda7c2007-12-18 00:25:38 +0000323
Chris Lattnerbef20ac2007-08-31 04:31:45 +0000324llvm::Constant *CodeGenModule::
325GetAddrOfConstantCFString(const std::string &str) {
Anders Carlssonc9e20912007-08-21 00:21:21 +0000326 llvm::StringMapEntry<llvm::Constant *> &Entry =
327 CFConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
328
329 if (Entry.getValue())
330 return Entry.getValue();
331
332 std::vector<llvm::Constant*> Fields;
333
334 if (!CFConstantStringClassRef) {
335 const llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);
336 Ty = llvm::ArrayType::get(Ty, 0);
337
338 CFConstantStringClassRef =
339 new llvm::GlobalVariable(Ty, false,
340 llvm::GlobalVariable::ExternalLinkage, 0,
341 "__CFConstantStringClassReference",
342 &getModule());
343 }
344
345 // Class pointer.
346 llvm::Constant *Zero = llvm::Constant::getNullValue(llvm::Type::Int32Ty);
347 llvm::Constant *Zeros[] = { Zero, Zero };
348 llvm::Constant *C =
349 llvm::ConstantExpr::getGetElementPtr(CFConstantStringClassRef, Zeros, 2);
350 Fields.push_back(C);
351
352 // Flags.
353 const llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);
354 Fields.push_back(llvm::ConstantInt::get(Ty, 1992));
355
356 // String pointer.
357 C = llvm::ConstantArray::get(str);
358 C = new llvm::GlobalVariable(C->getType(), true,
359 llvm::GlobalValue::InternalLinkage,
360 C, ".str", &getModule());
361
362 C = llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2);
363 Fields.push_back(C);
364
365 // String length.
366 Ty = getTypes().ConvertType(getContext().LongTy);
367 Fields.push_back(llvm::ConstantInt::get(Ty, str.length()));
368
369 // The struct.
370 Ty = getTypes().ConvertType(getContext().getCFConstantStringType());
371 C = llvm::ConstantStruct::get(cast<llvm::StructType>(Ty), Fields);
Anders Carlsson0c678292007-11-01 00:41:52 +0000372 llvm::GlobalVariable *GV =
373 new llvm::GlobalVariable(C->getType(), true,
374 llvm::GlobalVariable::InternalLinkage,
375 C, "", &getModule());
376 GV->setSection("__DATA,__cfstring");
377 Entry.setValue(GV);
378 return GV;
Anders Carlssonc9e20912007-08-21 00:21:21 +0000379}
Chris Lattner45e8cbd2007-11-28 05:34:05 +0000380
381/// GenerateWritableString -- Creates storage for a string literal
382static llvm::Constant *GenerateStringLiteral(const std::string &str,
383 bool constant,
Chris Lattner2c8569d2007-12-02 07:19:18 +0000384 CodeGenModule &CGM) {
Chris Lattner45e8cbd2007-11-28 05:34:05 +0000385 // Create Constant for this string literal
386 llvm::Constant *C=llvm::ConstantArray::get(str);
387
388 // Create a global variable for this string
389 C = new llvm::GlobalVariable(C->getType(), constant,
390 llvm::GlobalValue::InternalLinkage,
Chris Lattner2c8569d2007-12-02 07:19:18 +0000391 C, ".str", &CGM.getModule());
Chris Lattner45e8cbd2007-11-28 05:34:05 +0000392 llvm::Constant *Zero = llvm::Constant::getNullValue(llvm::Type::Int32Ty);
393 llvm::Constant *Zeros[] = { Zero, Zero };
394 C = llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2);
395 return C;
396}
397
398/// CodeGenModule::GetAddrOfConstantString -- returns a pointer to the first
399/// element of a character array containing the literal.
400llvm::Constant *CodeGenModule::GetAddrOfConstantString(const std::string &str) {
401 // Don't share any string literals if writable-strings is turned on.
402 if (Features.WritableStrings)
403 return GenerateStringLiteral(str, false, *this);
404
405 llvm::StringMapEntry<llvm::Constant *> &Entry =
406 ConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
407
408 if (Entry.getValue())
409 return Entry.getValue();
410
411 // Create a global variable for this.
412 llvm::Constant *C = GenerateStringLiteral(str, true, *this);
413 Entry.setValue(C);
414 return C;
415}