4b1988cd9ec5f0a0ea634d15a370cf5194fd9169
[oota-llvm.git] / lib / Analysis / DIBuilder.cpp
1 //===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
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 the DIBuilder.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Analysis/DIBuilder.h"
15 #include "llvm/Analysis/DebugInfo.h"
16 #include "llvm/Constants.h"
17 #include "llvm/IntrinsicInst.h"
18 #include "llvm/Module.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/Support/Dwarf.h"
21
22 using namespace llvm;
23 using namespace llvm::dwarf;
24
25 static Constant *GetTagConstant(LLVMContext &VMContext, unsigned Tag) {
26   assert((Tag & LLVMDebugVersionMask) == 0 &&
27          "Tag too large for debug encoding!");
28   return ConstantInt::get(Type::getInt32Ty(VMContext), Tag | LLVMDebugVersion);
29 }
30
31 DIBuilder::DIBuilder(Module &m)
32   : M(m), VMContext(M.getContext()), TheCU(0), DeclareFn(0), ValueFn(0) {}
33
34 /// CreateCompileUnit - A CompileUnit provides an anchor for all debugging
35 /// information generated during this instance of compilation.
36 void DIBuilder::CreateCompileUnit(unsigned Lang, StringRef Filename, 
37                                   StringRef Directory, StringRef Producer, 
38                                   bool isOptimized, StringRef Flags, 
39                                   unsigned RunTimeVer) {
40   Value *Elts[] = {
41     GetTagConstant(VMContext, dwarf::DW_TAG_compile_unit),
42     llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
43     ConstantInt::get(Type::getInt32Ty(VMContext), Lang),
44     MDString::get(VMContext, Filename),
45     MDString::get(VMContext, Directory),
46     MDString::get(VMContext, Producer),
47     // Deprecate isMain field.
48     ConstantInt::get(Type::getInt1Ty(VMContext), true), // isMain
49     ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
50     MDString::get(VMContext, Flags),
51     ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
52   };
53   TheCU = DICompileUnit(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
54 }
55
56 /// CreateFile - Create a file descriptor to hold debugging information
57 /// for a file.
58 DIFile DIBuilder::CreateFile(StringRef Filename, StringRef Directory) {
59   assert(TheCU && "Unable to create DW_TAG_file_type without CompileUnit");
60   Value *Elts[] = {
61     GetTagConstant(VMContext, dwarf::DW_TAG_file_type),
62     MDString::get(VMContext, Filename),
63     MDString::get(VMContext, Directory),
64     TheCU
65   };
66   return DIFile(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
67 }
68
69 /// CreateEnumerator - Create a single enumerator value.
70 DIEnumerator DIBuilder::CreateEnumerator(StringRef Name, uint64_t Val) {
71   Value *Elts[] = {
72     GetTagConstant(VMContext, dwarf::DW_TAG_enumerator),
73     MDString::get(VMContext, Name),
74     ConstantInt::get(Type::getInt64Ty(VMContext), Val)
75   };
76   return DIEnumerator(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
77 }
78
79 /// CreateBasicType - Create debugging information entry for a basic 
80 /// type, e.g 'char'.
81 DIType DIBuilder::CreateBasicType(StringRef Name, uint64_t SizeInBits, 
82                                   uint64_t AlignInBits,
83                                   unsigned Encoding) {
84   // Basic types are encoded in DIBasicType format. Line number, filename,
85   // offset and flags are always empty here.
86   Value *Elts[] = {
87     GetTagConstant(VMContext, dwarf::DW_TAG_base_type),
88     TheCU,
89     MDString::get(VMContext, Name),
90     NULL, // Filename
91     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
92     ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
93     ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
94     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
95     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags;
96     ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
97   };
98   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
99 }
100
101 /// CreateQaulifiedType - Create debugging information entry for a qualified
102 /// type, e.g. 'const int'.
103 DIType DIBuilder::CreateQualifiedType(unsigned Tag, DIType FromTy) {
104   // Qualified types are encoded in DIDerivedType format.
105   Value *Elts[] = {
106     GetTagConstant(VMContext, Tag),
107     TheCU,
108     MDString::get(VMContext, StringRef()), // Empty name.
109     NULL, // Filename
110     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
111     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
112     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
113     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
114     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
115     FromTy
116   };
117   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
118 }
119
120 /// CreatePointerType - Create debugging information entry for a pointer.
121 DIType DIBuilder::CreatePointerType(DIType PointeeTy, uint64_t SizeInBits,
122                                     uint64_t AlignInBits, StringRef Name) {
123   // Pointer types are encoded in DIDerivedType format.
124   Value *Elts[] = {
125     GetTagConstant(VMContext, dwarf::DW_TAG_pointer_type),
126     TheCU,
127     MDString::get(VMContext, Name),
128     NULL, // Filename
129     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
130     ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
131     ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
132     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
133     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
134     PointeeTy
135   };
136   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
137 }
138
139 /// CreateReferenceType - Create debugging information entry for a reference.
140 DIType DIBuilder::CreateReferenceType(DIType RTy) {
141   // References are encoded in DIDerivedType format.
142   Value *Elts[] = {
143     GetTagConstant(VMContext, dwarf::DW_TAG_reference_type),
144     TheCU,
145     NULL, // Name
146     NULL, // Filename
147     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
148     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
149     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
150     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
151     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
152     RTy
153   };
154   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
155 }
156
157 /// CreateTypedef - Create debugging information entry for a typedef.
158 DIType DIBuilder::CreateTypedef(DIType Ty, StringRef Name, DIFile File,
159                                 unsigned LineNo) {
160   // typedefs are encoded in DIDerivedType format.
161   assert(Ty.Verify() && "Invalid typedef type!");
162   Value *Elts[] = {
163     GetTagConstant(VMContext, dwarf::DW_TAG_typedef),
164     Ty.getContext(),
165     MDString::get(VMContext, Name),
166     File,
167     ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
168     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
169     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
170     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
171     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
172     Ty
173   };
174   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
175 }
176
177 /// CreateFriend - Create debugging information entry for a 'friend'.
178 DIType DIBuilder::CreateFriend(DIType Ty, DIType FriendTy) {
179   // typedefs are encoded in DIDerivedType format.
180   assert(Ty.Verify() && "Invalid type!");
181   assert(FriendTy.Verify() && "Invalid friend type!");
182   Value *Elts[] = {
183     GetTagConstant(VMContext, dwarf::DW_TAG_friend),
184     Ty,
185     NULL, // Name
186     Ty.getFile(),
187     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
188     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
189     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
190     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset
191     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags
192     FriendTy
193   };
194   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
195 }
196
197 /// CreateInheritance - Create debugging information entry to establish
198 /// inheritnace relationship between two types.
199 DIType DIBuilder::CreateInheritance(DIType Ty, DIType BaseTy, 
200                                     uint64_t BaseOffset, unsigned Flags) {
201   // TAG_inheritance is encoded in DIDerivedType format.
202   Value *Elts[] = {
203     GetTagConstant(VMContext, dwarf::DW_TAG_inheritance),
204     Ty,
205     NULL, // Name
206     NULL, // File
207     ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Line
208     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Size
209     ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Align
210     ConstantInt::get(Type::getInt64Ty(VMContext), BaseOffset),
211     ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
212     BaseTy
213   };
214   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
215 }
216
217 /// CreateMemberType - Create debugging information entry for a member.
218 DIType DIBuilder::CreateMemberType(StringRef Name, 
219                                    DIFile File, unsigned LineNumber, 
220                                    uint64_t SizeInBits, uint64_t AlignInBits,
221                                    uint64_t OffsetInBits, unsigned Flags, 
222                                    DIType Ty) {
223   // TAG_member is encoded in DIDerivedType format.
224   Value *Elts[] = {
225     GetTagConstant(VMContext, dwarf::DW_TAG_member),
226     File, // Or TheCU ? Ty ?
227     MDString::get(VMContext, Name),
228     File,
229     ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
230     ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
231     ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
232     ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
233     ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
234     Ty
235   };
236   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
237 }
238
239 /// CreateStructType - Create debugging information entry for a struct.
240 DIType DIBuilder::CreateStructType(DIDescriptor Context, StringRef Name, DIFile F,
241                                    unsigned LineNumber, uint64_t SizeInBits,
242                                    uint64_t AlignInBits, unsigned Flags,
243                                    DIArray Elements, unsigned RunTimeLang) {
244  // TAG_structure_type is encoded in DICompositeType format.
245   Value *Elts[] = {
246     GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
247     Context,
248     MDString::get(VMContext, Name),
249     F,
250     ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
251     ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
252     ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
253     ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
254     llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
255     Elements,
256     ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
257     llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
258   };
259   return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
260 }
261
262
263 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
264 DIType DIBuilder::CreateArtificialType(DIType Ty) {
265   if (Ty.isArtificial())
266     return Ty;
267
268   SmallVector<Value *, 9> Elts;
269   MDNode *N = Ty;
270   assert (N && "Unexpected input DIType!");
271   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
272     if (Value *V = N->getOperand(i))
273       Elts.push_back(V);
274     else
275       Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
276   }
277
278   unsigned CurFlags = Ty.getFlags();
279   CurFlags = CurFlags | DIType::FlagArtificial;
280
281   // Flags are stored at this slot.
282   Elts[8] =  ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
283
284   return DIType(MDNode::get(VMContext, Elts.data(), Elts.size()));
285 }
286
287 /// CreateTemporaryType - Create a temporary forward-declared type.
288 DIType DIBuilder::CreateTemporaryType() {
289   // Give the temporary MDNode a tag. It doesn't matter what tag we
290   // use here as long as DIType accepts it.
291   Value *Elts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
292   MDNode *Node = MDNode::getTemporary(VMContext, Elts, array_lengthof(Elts));
293   return DIType(Node);
294 }
295
296 /// CreateTemporaryType - Create a temporary forward-declared type.
297 DIType DIBuilder::CreateTemporaryType(DIFile F) {
298   // Give the temporary MDNode a tag. It doesn't matter what tag we
299   // use here as long as DIType accepts it.
300   Value *Elts[] = {
301     GetTagConstant(VMContext, DW_TAG_base_type),
302     F.getCompileUnit(),
303     NULL,
304     F
305   };
306   MDNode *Node = MDNode::getTemporary(VMContext, Elts, array_lengthof(Elts));
307   return DIType(Node);
308 }
309
310 /// GetOrCreateArray - Get a DIArray, create one if required.
311 DIArray DIBuilder::GetOrCreateArray(Value *const *Elements, unsigned NumElements) {
312   if (NumElements == 0) {
313     Value *Null = llvm::Constant::getNullValue(Type::getInt32Ty(VMContext));
314     return DIArray(MDNode::get(VMContext, &Null, 1));
315   }
316   return DIArray(MDNode::get(VMContext, Elements, NumElements));
317 }
318
319 /// CreateGlobalVariable - Create a new descriptor for the specified global.
320 DIGlobalVariable DIBuilder::
321 CreateGlobalVariable(StringRef Name, 
322                      StringRef LinkageName, DIFile F, unsigned LineNumber, 
323                      DIType Ty, bool isLocalToUnit, llvm::Value *Val) {
324   Value *Elts[] = {
325     GetTagConstant(VMContext, dwarf::DW_TAG_variable),
326     llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
327     TheCU,
328     MDString::get(VMContext, Name),
329     MDString::get(VMContext, Name),
330     MDString::get(VMContext, LinkageName),
331     F,
332     ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
333     Ty,
334     ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
335     ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
336     Val
337   };
338   MDNode *Node = MDNode::get(VMContext, &Elts[0], array_lengthof(Elts));
339   // Create a named metadata so that we do not lose this mdnode.
340   NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
341   NMD->addOperand(Node);
342   return DIGlobalVariable(Node);
343 }
344
345 /// CreateStaticVariable - Create a new descriptor for the specified static
346 /// variable.
347 DIGlobalVariable DIBuilder::
348 CreateStaticVariable(DIDescriptor Context, StringRef Name, 
349                      StringRef LinkageName, DIFile F, unsigned LineNumber, 
350                      DIType Ty, bool isLocalToUnit, llvm::Value *Val) {
351   Value *Elts[] = {
352     GetTagConstant(VMContext, dwarf::DW_TAG_variable),
353     llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
354     Context,
355     MDString::get(VMContext, Name),
356     MDString::get(VMContext, Name),
357     MDString::get(VMContext, LinkageName),
358     F,
359     ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
360     Ty,
361     ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
362     ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
363     Val
364   };
365   MDNode *Node = MDNode::get(VMContext, &Elts[0], array_lengthof(Elts));
366   // Create a named metadata so that we do not lose this mdnode.
367   NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
368   NMD->addOperand(Node);
369   return DIGlobalVariable(Node);
370 }
371
372 /// CreateVariable - Create a new descriptor for the specified variable.
373 DIVariable DIBuilder::CreateLocalVariable(unsigned Tag, DIDescriptor Scope,
374                                           StringRef Name, DIFile File,
375                                           unsigned LineNo, DIType Ty, 
376                                           bool AlwaysPreserve, unsigned Flags) {
377   Value *Elts[] = {
378     GetTagConstant(VMContext, Tag),
379     Scope,
380     MDString::get(VMContext, Name),
381     File,
382     ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
383     Ty,
384     ConstantInt::get(Type::getInt32Ty(VMContext), Flags)
385   };
386   MDNode *Node = MDNode::get(VMContext, &Elts[0], array_lengthof(Elts));
387   if (AlwaysPreserve) {
388     // The optimizer may remove local variable. If there is an interest
389     // to preserve variable info in such situation then stash it in a
390     // named mdnode.
391     DISubprogram Fn(getDISubprogram(Scope));
392     StringRef FName = "fn";
393     if (Fn.getFunction())
394       FName = Fn.getFunction()->getName();
395     char One = '\1';
396     if (FName.startswith(StringRef(&One, 1)))
397       FName = FName.substr(1);
398     NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, FName);
399     FnLocals->addOperand(Node);
400   }
401   return DIVariable(Node);
402 }
403
404 /// CreateComplexVariable - Create a new descriptor for the specified variable
405 /// which has a complex address expression for its address.
406 DIVariable DIBuilder::CreateComplexVariable(unsigned Tag, DIDescriptor Scope,
407                                             StringRef Name, DIFile F,
408                                             unsigned LineNo,
409                                             DIType Ty, Value *const *Addr,
410                                             unsigned NumAddr) {
411   SmallVector<Value *, 15> Elts;
412   Elts.push_back(GetTagConstant(VMContext, Tag));
413   Elts.push_back(Scope);
414   Elts.push_back(MDString::get(VMContext, Name));
415   Elts.push_back(F);
416   Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), LineNo));
417   Elts.push_back(Ty);
418   Elts.append(Addr, Addr+NumAddr);
419
420   return DIVariable(MDNode::get(VMContext, Elts.data(), Elts.size()));
421 }
422
423
424 /// CreateNameSpace - This creates new descriptor for a namespace
425 /// with the specified parent scope.
426 DINameSpace DIBuilder::CreateNameSpace(DIDescriptor Scope, StringRef Name,
427                                        DIFile File, unsigned LineNo) {
428   Value *Elts[] = {
429     GetTagConstant(VMContext, dwarf::DW_TAG_namespace),
430     Scope,
431     MDString::get(VMContext, Name),
432     File,
433     ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
434   };
435   return DINameSpace(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
436 }
437
438 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
439 Instruction *DIBuilder::InsertDeclare(Value *Storage, DIVariable VarInfo,
440                                       Instruction *InsertBefore) {
441   assert(Storage && "no storage passed to dbg.declare");
442   assert(VarInfo.Verify() && "empty DIVariable passed to dbg.declare");
443   if (!DeclareFn)
444     DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
445
446   Value *Args[] = { MDNode::get(Storage->getContext(), &Storage, 1), VarInfo };
447   return CallInst::Create(DeclareFn, Args, Args+2, "", InsertBefore);
448 }
449
450 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
451 Instruction *DIBuilder::InsertDeclare(Value *Storage, DIVariable VarInfo,
452                                       BasicBlock *InsertAtEnd) {
453   assert(Storage && "no storage passed to dbg.declare");
454   assert(VarInfo.Verify() && "invalid DIVariable passed to dbg.declare");
455   if (!DeclareFn)
456     DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
457
458   Value *Args[] = { MDNode::get(Storage->getContext(), &Storage, 1), VarInfo };
459
460   // If this block already has a terminator then insert this intrinsic
461   // before the terminator.
462   if (TerminatorInst *T = InsertAtEnd->getTerminator())
463     return CallInst::Create(DeclareFn, Args, Args+2, "", T);
464   else
465     return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);
466 }
467
468 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
469 Instruction *DIBuilder::InsertDbgValueIntrinsic(Value *V, uint64_t Offset,
470                                                 DIVariable VarInfo,
471                                                 Instruction *InsertBefore) {
472   assert(V && "no value passed to dbg.value");
473   assert(VarInfo.Verify() && "invalid DIVariable passed to dbg.value");
474   if (!ValueFn)
475     ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
476
477   Value *Args[] = { MDNode::get(V->getContext(), &V, 1),
478                     ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
479                     VarInfo };
480   return CallInst::Create(ValueFn, Args, Args+3, "", InsertBefore);
481 }
482
483 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
484 Instruction *DIBuilder::InsertDbgValueIntrinsic(Value *V, uint64_t Offset,
485                                                 DIVariable VarInfo,
486                                                 BasicBlock *InsertAtEnd) {
487   assert(V && "no value passed to dbg.value");
488   assert(VarInfo.Verify() && "invalid DIVariable passed to dbg.value");
489   if (!ValueFn)
490     ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
491
492   Value *Args[] = { MDNode::get(V->getContext(), &V, 1),
493                     ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
494                     VarInfo };
495   return CallInst::Create(ValueFn, Args, Args+3, "", InsertAtEnd);
496 }
497