1 //===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/CodeGen/MachineDebugInfo.h"
12 #include "llvm/Constants.h"
13 #include "llvm/CodeGen/MachineLocation.h"
14 #include "llvm/DerivedTypes.h"
15 #include "llvm/GlobalVariable.h"
16 #include "llvm/Intrinsics.h"
17 #include "llvm/Instructions.h"
18 #include "llvm/Module.h"
19 #include "llvm/Support/Dwarf.h"
24 using namespace llvm::dwarf;
26 // Handle the Pass registration stuff necessary to use TargetData's.
28 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
31 //===----------------------------------------------------------------------===//
33 /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the
34 /// specified value in their initializer somewhere.
36 getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) {
37 // Scan though value users.
38 for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
39 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) {
40 // If the user is a GlobalVariable then add to result.
42 } else if (Constant *C = dyn_cast<Constant>(*I)) {
43 // If the user is a constant variable then scan its users
44 getGlobalVariablesUsing(C, Result);
49 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
50 /// named GlobalVariable.
51 static std::vector<GlobalVariable*>
52 getGlobalVariablesUsing(Module &M, const std::string &RootName) {
53 std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria.
55 std::vector<const Type*> FieldTypes;
56 FieldTypes.push_back(Type::UIntTy);
57 FieldTypes.push_back(Type::UIntTy);
59 // Get the GlobalVariable root.
60 GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
61 StructType::get(FieldTypes));
63 // If present and linkonce then scan for users.
64 if (UseRoot && UseRoot->hasLinkOnceLinkage()) {
65 getGlobalVariablesUsing(UseRoot, Result);
71 /// isStringValue - Return true if the given value can be coerced to a string.
73 static bool isStringValue(Value *V) {
74 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
75 if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
76 ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
77 return Init->isString();
79 } else if (Constant *C = dyn_cast<Constant>(V)) {
80 if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
81 return isStringValue(GV);
82 else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
83 if (CE->getOpcode() == Instruction::GetElementPtr) {
84 if (CE->getNumOperands() == 3 &&
85 cast<Constant>(CE->getOperand(1))->isNullValue() &&
86 isa<ConstantInt>(CE->getOperand(2))) {
87 return isStringValue(CE->getOperand(0));
95 /// getGlobalVariable - Return either a direct or cast Global value.
97 static GlobalVariable *getGlobalVariable(Value *V) {
98 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
100 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
101 if (CE->getOpcode() == Instruction::Cast) {
102 return dyn_cast<GlobalVariable>(CE->getOperand(0));
108 /// isGlobalVariable - Return true if the given value can be coerced to a
110 static bool isGlobalVariable(Value *V) {
111 if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) {
113 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
114 if (CE->getOpcode() == Instruction::Cast) {
115 return isa<GlobalVariable>(CE->getOperand(0));
121 /// getUIntOperand - Return ith operand if it is an unsigned integer.
123 static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) {
124 // Make sure the GlobalVariable has an initializer.
125 if (!GV->hasInitializer()) return NULL;
127 // Get the initializer constant.
128 ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer());
129 if (!CI) return NULL;
131 // Check if there is at least i + 1 operands.
132 unsigned N = CI->getNumOperands();
133 if (i >= N) return NULL;
136 return dyn_cast<ConstantUInt>(CI->getOperand(i));
138 //===----------------------------------------------------------------------===//
140 /// ApplyToFields - Target the visitor to each field of the debug information
142 void DIVisitor::ApplyToFields(DebugInfoDesc *DD) {
143 DD->ApplyToFields(this);
146 //===----------------------------------------------------------------------===//
147 /// DICountVisitor - This DIVisitor counts all the fields in the supplied debug
148 /// the supplied DebugInfoDesc.
149 class DICountVisitor : public DIVisitor {
151 unsigned Count; // Running count of fields.
154 DICountVisitor() : DIVisitor(), Count(0) {}
157 unsigned getCount() const { return Count; }
159 /// Apply - Count each of the fields.
161 virtual void Apply(int &Field) { ++Count; }
162 virtual void Apply(unsigned &Field) { ++Count; }
163 virtual void Apply(int64_t &Field) { ++Count; }
164 virtual void Apply(uint64_t &Field) { ++Count; }
165 virtual void Apply(bool &Field) { ++Count; }
166 virtual void Apply(std::string &Field) { ++Count; }
167 virtual void Apply(DebugInfoDesc *&Field) { ++Count; }
168 virtual void Apply(GlobalVariable *&Field) { ++Count; }
169 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
174 //===----------------------------------------------------------------------===//
175 /// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the
176 /// supplied DebugInfoDesc.
177 class DIDeserializeVisitor : public DIVisitor {
179 DIDeserializer &DR; // Active deserializer.
180 unsigned I; // Current operand index.
181 ConstantStruct *CI; // GlobalVariable constant initializer.
184 DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV)
188 , CI(cast<ConstantStruct>(GV->getInitializer()))
191 /// Apply - Set the value of each of the fields.
193 virtual void Apply(int &Field) {
194 Constant *C = CI->getOperand(I++);
195 Field = cast<ConstantSInt>(C)->getValue();
197 virtual void Apply(unsigned &Field) {
198 Constant *C = CI->getOperand(I++);
199 Field = cast<ConstantUInt>(C)->getValue();
201 virtual void Apply(int64_t &Field) {
202 Constant *C = CI->getOperand(I++);
203 Field = cast<ConstantSInt>(C)->getValue();
205 virtual void Apply(uint64_t &Field) {
206 Constant *C = CI->getOperand(I++);
207 Field = cast<ConstantUInt>(C)->getValue();
209 virtual void Apply(bool &Field) {
210 Constant *C = CI->getOperand(I++);
211 Field = cast<ConstantBool>(C)->getValue();
213 virtual void Apply(std::string &Field) {
214 Constant *C = CI->getOperand(I++);
215 Field = C->getStringValue();
217 virtual void Apply(DebugInfoDesc *&Field) {
218 Constant *C = CI->getOperand(I++);
219 Field = DR.Deserialize(C);
221 virtual void Apply(GlobalVariable *&Field) {
222 Constant *C = CI->getOperand(I++);
223 Field = getGlobalVariable(C);
225 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
226 Constant *C = CI->getOperand(I++);
227 GlobalVariable *GV = getGlobalVariable(C);
229 // Have to be able to deal with the empty array case (zero initializer)
230 if (!GV->hasInitializer()) return;
231 if (ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer())) {
232 for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) {
233 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
234 DebugInfoDesc *DE = DR.Deserialize(GVE);
241 //===----------------------------------------------------------------------===//
242 /// DISerializeVisitor - This DIVisitor serializes all the fields in
243 /// the supplied DebugInfoDesc.
244 class DISerializeVisitor : public DIVisitor {
246 DISerializer &SR; // Active serializer.
247 std::vector<Constant*> &Elements; // Element accumulator.
250 DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E)
256 /// Apply - Set the value of each of the fields.
258 virtual void Apply(int &Field) {
259 Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
261 virtual void Apply(unsigned &Field) {
262 Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
264 virtual void Apply(int64_t &Field) {
265 Elements.push_back(ConstantSInt::get(Type::LongTy, Field));
267 virtual void Apply(uint64_t &Field) {
268 Elements.push_back(ConstantUInt::get(Type::ULongTy, Field));
270 virtual void Apply(bool &Field) {
271 Elements.push_back(ConstantBool::get(Field));
273 virtual void Apply(std::string &Field) {
274 Elements.push_back(SR.getString(Field));
276 virtual void Apply(DebugInfoDesc *&Field) {
277 GlobalVariable *GV = NULL;
279 // If non-NULL then convert to global.
280 if (Field) GV = SR.Serialize(Field);
282 // FIXME - At some point should use specific type.
283 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
286 // Set to pointer to global.
287 Elements.push_back(ConstantExpr::getCast(GV, EmptyTy));
290 Elements.push_back(ConstantPointerNull::get(EmptyTy));
293 virtual void Apply(GlobalVariable *&Field) {
294 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
296 Elements.push_back(ConstantExpr::getCast(Field, EmptyTy));
298 Elements.push_back(ConstantPointerNull::get(EmptyTy));
301 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
302 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
303 unsigned N = Field.size();
304 ArrayType *AT = ArrayType::get(EmptyTy, N);
305 std::vector<Constant *> ArrayElements;
307 for (unsigned i = 0, N = Field.size(); i < N; ++i) {
308 GlobalVariable *GVE = SR.Serialize(Field[i]);
309 Constant *CE = ConstantExpr::getCast(GVE, EmptyTy);
310 ArrayElements.push_back(cast<Constant>(CE));
313 Constant *CA = ConstantArray::get(AT, ArrayElements);
314 GlobalVariable *CAGV = new GlobalVariable(AT, true,
315 GlobalValue::InternalLinkage,
316 CA, "llvm.dbg.array",
318 CAGV->setSection("llvm.metadata");
319 Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy);
320 Elements.push_back(CAE);
324 //===----------------------------------------------------------------------===//
325 /// DIGetTypesVisitor - This DIVisitor gathers all the field types in
326 /// the supplied DebugInfoDesc.
327 class DIGetTypesVisitor : public DIVisitor {
329 DISerializer &SR; // Active serializer.
330 std::vector<const Type*> &Fields; // Type accumulator.
333 DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F)
339 /// Apply - Set the value of each of the fields.
341 virtual void Apply(int &Field) {
342 Fields.push_back(Type::IntTy);
344 virtual void Apply(unsigned &Field) {
345 Fields.push_back(Type::UIntTy);
347 virtual void Apply(int64_t &Field) {
348 Fields.push_back(Type::LongTy);
350 virtual void Apply(uint64_t &Field) {
351 Fields.push_back(Type::ULongTy);
353 virtual void Apply(bool &Field) {
354 Fields.push_back(Type::BoolTy);
356 virtual void Apply(std::string &Field) {
357 Fields.push_back(SR.getStrPtrType());
359 virtual void Apply(DebugInfoDesc *&Field) {
360 // FIXME - At some point should use specific type.
361 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
362 Fields.push_back(EmptyTy);
364 virtual void Apply(GlobalVariable *&Field) {
365 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
366 Fields.push_back(EmptyTy);
368 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
369 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
370 Fields.push_back(EmptyTy);
374 //===----------------------------------------------------------------------===//
375 /// DIVerifyVisitor - This DIVisitor verifies all the field types against
376 /// a constant initializer.
377 class DIVerifyVisitor : public DIVisitor {
379 DIVerifier &VR; // Active verifier.
380 bool IsValid; // Validity status.
381 unsigned I; // Current operand index.
382 ConstantStruct *CI; // GlobalVariable constant initializer.
385 DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV)
390 , CI(cast<ConstantStruct>(GV->getInitializer()))
395 bool isValid() const { return IsValid; }
397 /// Apply - Set the value of each of the fields.
399 virtual void Apply(int &Field) {
400 Constant *C = CI->getOperand(I++);
401 IsValid = IsValid && isa<ConstantInt>(C);
403 virtual void Apply(unsigned &Field) {
404 Constant *C = CI->getOperand(I++);
405 IsValid = IsValid && isa<ConstantInt>(C);
407 virtual void Apply(int64_t &Field) {
408 Constant *C = CI->getOperand(I++);
409 IsValid = IsValid && isa<ConstantInt>(C);
411 virtual void Apply(uint64_t &Field) {
412 Constant *C = CI->getOperand(I++);
413 IsValid = IsValid && isa<ConstantInt>(C);
415 virtual void Apply(bool &Field) {
416 Constant *C = CI->getOperand(I++);
417 IsValid = IsValid && isa<ConstantBool>(C);
419 virtual void Apply(std::string &Field) {
420 Constant *C = CI->getOperand(I++);
421 IsValid = IsValid && (!C || isStringValue(C));
423 virtual void Apply(DebugInfoDesc *&Field) {
424 // FIXME - Prepare the correct descriptor.
425 Constant *C = CI->getOperand(I++);
426 IsValid = IsValid && isGlobalVariable(C);
428 virtual void Apply(GlobalVariable *&Field) {
429 Constant *C = CI->getOperand(I++);
430 IsValid = IsValid && isGlobalVariable(C);
432 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
433 Constant *C = CI->getOperand(I++);
434 IsValid = IsValid && isGlobalVariable(C);
435 if (!IsValid) return;
437 GlobalVariable *GV = getGlobalVariable(C);
438 IsValid = IsValid && GV && GV->hasInitializer();
439 if (!IsValid) return;
441 ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer());
442 IsValid = IsValid && CA;
443 if (!IsValid) return;
445 for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) {
446 IsValid = IsValid && isGlobalVariable(CA->getOperand(i));
447 if (!IsValid) return;
449 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
456 //===----------------------------------------------------------------------===//
458 /// TagFromGlobal - Returns the tag number from a debug info descriptor
459 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
460 unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) {
461 ConstantUInt *C = getUIntOperand(GV, 0);
462 return C ? ((unsigned)C->getValue() & tag_mask) : (unsigned)DW_TAG_invalid;
465 /// VersionFromGlobal - Returns the version number from a debug info
466 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
468 unsigned DebugInfoDesc::VersionFromGlobal(GlobalVariable *GV) {
469 ConstantUInt *C = getUIntOperand(GV, 0);
470 return C ? ((unsigned)C->getValue() >> version_shift) :
471 (unsigned)DW_TAG_invalid;
474 /// DescFactory - Create an instance of debug info descriptor based on Tag.
475 /// Return NULL if not a recognized Tag.
476 DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
478 case DW_TAG_anchor: return new AnchorDesc();
479 case DW_TAG_compile_unit: return new CompileUnitDesc();
480 case DW_TAG_variable: return new GlobalVariableDesc();
481 case DW_TAG_subprogram: return new SubprogramDesc();
482 case DW_TAG_lexical_block: return new BlockDesc();
483 case DW_TAG_base_type: return new BasicTypeDesc();
485 case DW_TAG_pointer_type:
486 case DW_TAG_reference_type:
487 case DW_TAG_const_type:
488 case DW_TAG_volatile_type:
489 case DW_TAG_restrict_type:
490 case DW_TAG_member: return new DerivedTypeDesc(Tag);
491 case DW_TAG_array_type:
492 case DW_TAG_structure_type:
493 case DW_TAG_union_type:
494 case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag);
495 case DW_TAG_subrange_type: return new SubrangeDesc();
496 case DW_TAG_enumerator: return new EnumeratorDesc();
497 case DW_TAG_return_variable:
498 case DW_TAG_arg_variable:
499 case DW_TAG_auto_variable: return new VariableDesc(Tag);
505 /// getLinkage - get linkage appropriate for this type of descriptor.
507 GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const {
508 return GlobalValue::InternalLinkage;
511 /// ApplyToFields - Target the vistor to the fields of the descriptor.
513 void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) {
517 //===----------------------------------------------------------------------===//
519 AnchorDesc::AnchorDesc()
520 : DebugInfoDesc(DW_TAG_anchor)
523 AnchorDesc::AnchorDesc(AnchoredDesc *D)
524 : DebugInfoDesc(DW_TAG_anchor)
525 , AnchorTag(D->getTag())
528 // Implement isa/cast/dyncast.
529 bool AnchorDesc::classof(const DebugInfoDesc *D) {
530 return D->getTag() == DW_TAG_anchor;
533 /// getLinkage - get linkage appropriate for this type of descriptor.
535 GlobalValue::LinkageTypes AnchorDesc::getLinkage() const {
536 return GlobalValue::LinkOnceLinkage;
539 /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc.
541 void AnchorDesc::ApplyToFields(DIVisitor *Visitor) {
542 DebugInfoDesc::ApplyToFields(Visitor);
544 Visitor->Apply(AnchorTag);
547 /// getDescString - Return a string used to compose global names and labels. A
548 /// A global variable name needs to be defined for each debug descriptor that is
549 /// anchored. NOTE: that each global variable named here also needs to be added
550 /// to the list of names left external in the internalizer.
551 /// ExternalNames.insert("llvm.dbg.compile_units");
552 /// ExternalNames.insert("llvm.dbg.global_variables");
553 /// ExternalNames.insert("llvm.dbg.subprograms");
554 const char *AnchorDesc::getDescString() const {
556 case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString;
557 case DW_TAG_variable: return GlobalVariableDesc::AnchorString;
558 case DW_TAG_subprogram: return SubprogramDesc::AnchorString;
562 assert(0 && "Tag does not have a case for anchor string");
566 /// getTypeString - Return a string used to label this descriptors type.
568 const char *AnchorDesc::getTypeString() const {
569 return "llvm.dbg.anchor.type";
573 void AnchorDesc::dump() {
574 std::cerr << getDescString() << " "
575 << "Version(" << getVersion() << "), "
576 << "Tag(" << getTag() << "), "
577 << "AnchorTag(" << AnchorTag << ")\n";
581 //===----------------------------------------------------------------------===//
583 AnchoredDesc::AnchoredDesc(unsigned T)
588 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
590 void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) {
591 DebugInfoDesc::ApplyToFields(Visitor);
593 DebugInfoDesc *Tmp = Anchor;
595 Anchor = (AnchorDesc*)Tmp;
598 //===----------------------------------------------------------------------===//
600 CompileUnitDesc::CompileUnitDesc()
601 : AnchoredDesc(DW_TAG_compile_unit)
608 // Implement isa/cast/dyncast.
609 bool CompileUnitDesc::classof(const DebugInfoDesc *D) {
610 return D->getTag() == DW_TAG_compile_unit;
613 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
615 void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) {
616 AnchoredDesc::ApplyToFields(Visitor);
618 Visitor->Apply(Language);
619 Visitor->Apply(FileName);
620 Visitor->Apply(Directory);
621 Visitor->Apply(Producer);
624 /// getDescString - Return a string used to compose global names and labels.
626 const char *CompileUnitDesc::getDescString() const {
627 return "llvm.dbg.compile_unit";
630 /// getTypeString - Return a string used to label this descriptors type.
632 const char *CompileUnitDesc::getTypeString() const {
633 return "llvm.dbg.compile_unit.type";
636 /// getAnchorString - Return a string used to label this descriptor's anchor.
638 const char *CompileUnitDesc::AnchorString = "llvm.dbg.compile_units";
639 const char *CompileUnitDesc::getAnchorString() const {
644 void CompileUnitDesc::dump() {
645 std::cerr << getDescString() << " "
646 << "Version(" << getVersion() << "), "
647 << "Tag(" << getTag() << "), "
648 << "Anchor(" << getAnchor() << "), "
649 << "Language(" << Language << "), "
650 << "FileName(\"" << FileName << "\"), "
651 << "Directory(\"" << Directory << "\"), "
652 << "Producer(\"" << Producer << "\")\n";
656 //===----------------------------------------------------------------------===//
658 TypeDesc::TypeDesc(unsigned T)
669 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
671 void TypeDesc::ApplyToFields(DIVisitor *Visitor) {
672 DebugInfoDesc::ApplyToFields(Visitor);
674 Visitor->Apply(Context);
675 Visitor->Apply(Name);
676 DebugInfoDesc* Tmp = File;
678 File = (CompileUnitDesc*)Tmp;
679 Visitor->Apply(Line);
680 Visitor->Apply(Size);
681 Visitor->Apply(Align);
682 Visitor->Apply(Offset);
685 /// getDescString - Return a string used to compose global names and labels.
687 const char *TypeDesc::getDescString() const {
688 return "llvm.dbg.type";
691 /// getTypeString - Return a string used to label this descriptor's type.
693 const char *TypeDesc::getTypeString() const {
694 return "llvm.dbg.type.type";
698 void TypeDesc::dump() {
699 std::cerr << getDescString() << " "
700 << "Version(" << getVersion() << "), "
701 << "Tag(" << getTag() << "), "
702 << "Context(" << Context << "), "
703 << "Name(\"" << Name << "\"), "
704 << "File(" << File << "), "
705 << "Line(" << Line << "), "
706 << "Size(" << Size << "), "
707 << "Align(" << Align << "), "
708 << "Offset(" << Offset << ")\n";
712 //===----------------------------------------------------------------------===//
714 BasicTypeDesc::BasicTypeDesc()
715 : TypeDesc(DW_TAG_base_type)
719 // Implement isa/cast/dyncast.
720 bool BasicTypeDesc::classof(const DebugInfoDesc *D) {
721 return D->getTag() == DW_TAG_base_type;
724 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
726 void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) {
727 TypeDesc::ApplyToFields(Visitor);
729 Visitor->Apply(Encoding);
732 /// getDescString - Return a string used to compose global names and labels.
734 const char *BasicTypeDesc::getDescString() const {
735 return "llvm.dbg.basictype";
738 /// getTypeString - Return a string used to label this descriptor's type.
740 const char *BasicTypeDesc::getTypeString() const {
741 return "llvm.dbg.basictype.type";
745 void BasicTypeDesc::dump() {
746 std::cerr << getDescString() << " "
747 << "Version(" << getVersion() << "), "
748 << "Tag(" << getTag() << "), "
749 << "Context(" << getContext() << "), "
750 << "Name(\"" << getName() << "\"), "
751 << "Size(" << getSize() << "), "
752 << "Encoding(" << Encoding << ")\n";
756 //===----------------------------------------------------------------------===//
758 DerivedTypeDesc::DerivedTypeDesc(unsigned T)
763 // Implement isa/cast/dyncast.
764 bool DerivedTypeDesc::classof(const DebugInfoDesc *D) {
765 unsigned T = D->getTag();
768 case DW_TAG_pointer_type:
769 case DW_TAG_reference_type:
770 case DW_TAG_const_type:
771 case DW_TAG_volatile_type:
772 case DW_TAG_restrict_type:
780 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
782 void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) {
783 TypeDesc::ApplyToFields(Visitor);
785 DebugInfoDesc* Tmp = FromType;
787 FromType = (TypeDesc*)Tmp;
790 /// getDescString - Return a string used to compose global names and labels.
792 const char *DerivedTypeDesc::getDescString() const {
793 return "llvm.dbg.derivedtype";
796 /// getTypeString - Return a string used to label this descriptor's type.
798 const char *DerivedTypeDesc::getTypeString() const {
799 return "llvm.dbg.derivedtype.type";
803 void DerivedTypeDesc::dump() {
804 std::cerr << getDescString() << " "
805 << "Version(" << getVersion() << "), "
806 << "Tag(" << getTag() << "), "
807 << "Context(" << getContext() << "), "
808 << "Name(\"" << getName() << "\"), "
809 << "Size(" << getSize() << "), "
810 << "File(" << getFile() << "), "
811 << "Line(" << getLine() << "), "
812 << "FromType(" << FromType << ")\n";
816 //===----------------------------------------------------------------------===//
818 CompositeTypeDesc::CompositeTypeDesc(unsigned T)
824 // Implement isa/cast/dyncast.
825 bool CompositeTypeDesc::classof(const DebugInfoDesc *D) {
826 unsigned T = D->getTag();
828 case DW_TAG_array_type:
829 case DW_TAG_structure_type:
830 case DW_TAG_union_type:
831 case DW_TAG_enumeration_type:
838 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
840 void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) {
841 DerivedTypeDesc::ApplyToFields(Visitor);
843 Visitor->Apply(IsVector);
844 Visitor->Apply(Elements);
847 /// getDescString - Return a string used to compose global names and labels.
849 const char *CompositeTypeDesc::getDescString() const {
850 return "llvm.dbg.compositetype";
853 /// getTypeString - Return a string used to label this descriptor's type.
855 const char *CompositeTypeDesc::getTypeString() const {
856 return "llvm.dbg.compositetype.type";
860 void CompositeTypeDesc::dump() {
861 std::cerr << getDescString() << " "
862 << "Version(" << getVersion() << "), "
863 << "Tag(" << getTag() << "), "
864 << "Context(" << getContext() << "), "
865 << "Name(\"" << getName() << "\"), "
866 << "Size(" << getSize() << "), "
867 << "File(" << getFile() << "), "
868 << "Line(" << getLine() << "), "
869 << "FromType(" << getFromType() << "), "
870 << "Elements.size(" << Elements.size() << ")\n";
874 //===----------------------------------------------------------------------===//
876 SubrangeDesc::SubrangeDesc()
877 : DebugInfoDesc(DW_TAG_subrange_type)
882 // Implement isa/cast/dyncast.
883 bool SubrangeDesc::classof(const DebugInfoDesc *D) {
884 return D->getTag() == DW_TAG_subrange_type;
887 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
889 void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) {
890 DebugInfoDesc::ApplyToFields(Visitor);
896 /// getDescString - Return a string used to compose global names and labels.
898 const char *SubrangeDesc::getDescString() const {
899 return "llvm.dbg.subrange";
902 /// getTypeString - Return a string used to label this descriptor's type.
904 const char *SubrangeDesc::getTypeString() const {
905 return "llvm.dbg.subrange.type";
909 void SubrangeDesc::dump() {
910 std::cerr << getDescString() << " "
911 << "Version(" << getVersion() << "), "
912 << "Tag(" << getTag() << "), "
913 << "Lo(" << Lo << "), "
914 << "Hi(" << Hi << ")\n";
918 //===----------------------------------------------------------------------===//
920 EnumeratorDesc::EnumeratorDesc()
921 : DebugInfoDesc(DW_TAG_enumerator)
926 // Implement isa/cast/dyncast.
927 bool EnumeratorDesc::classof(const DebugInfoDesc *D) {
928 return D->getTag() == DW_TAG_enumerator;
931 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
933 void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) {
934 DebugInfoDesc::ApplyToFields(Visitor);
936 Visitor->Apply(Name);
937 Visitor->Apply(Value);
940 /// getDescString - Return a string used to compose global names and labels.
942 const char *EnumeratorDesc::getDescString() const {
943 return "llvm.dbg.enumerator";
946 /// getTypeString - Return a string used to label this descriptor's type.
948 const char *EnumeratorDesc::getTypeString() const {
949 return "llvm.dbg.enumerator.type";
953 void EnumeratorDesc::dump() {
954 std::cerr << getDescString() << " "
955 << "Version(" << getVersion() << "), "
956 << "Tag(" << getTag() << "), "
957 << "Name(" << Name << "), "
958 << "Value(" << Value << ")\n";
962 //===----------------------------------------------------------------------===//
964 VariableDesc::VariableDesc(unsigned T)
973 // Implement isa/cast/dyncast.
974 bool VariableDesc::classof(const DebugInfoDesc *D) {
975 unsigned T = D->getTag();
977 case DW_TAG_auto_variable:
978 case DW_TAG_arg_variable:
979 case DW_TAG_return_variable:
986 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
988 void VariableDesc::ApplyToFields(DIVisitor *Visitor) {
989 DebugInfoDesc::ApplyToFields(Visitor);
991 Visitor->Apply(Context);
992 Visitor->Apply(Name);
993 DebugInfoDesc* Tmp1 = File;
994 Visitor->Apply(Tmp1);
995 File = (CompileUnitDesc*)Tmp1;
996 Visitor->Apply(Line);
997 DebugInfoDesc* Tmp2 = TyDesc;
998 Visitor->Apply(Tmp2);
999 TyDesc = (TypeDesc*)Tmp2;
1002 /// getDescString - Return a string used to compose global names and labels.
1004 const char *VariableDesc::getDescString() const {
1005 return "llvm.dbg.variable";
1008 /// getTypeString - Return a string used to label this descriptor's type.
1010 const char *VariableDesc::getTypeString() const {
1011 return "llvm.dbg.variable.type";
1015 void VariableDesc::dump() {
1016 std::cerr << getDescString() << " "
1017 << "Version(" << getVersion() << "), "
1018 << "Tag(" << getTag() << "), "
1019 << "Context(" << Context << "), "
1020 << "Name(\"" << Name << "\"), "
1021 << "File(" << File << "), "
1022 << "Line(" << Line << "), "
1023 << "TyDesc(" << TyDesc << ")\n";
1027 //===----------------------------------------------------------------------===//
1029 GlobalDesc::GlobalDesc(unsigned T)
1037 , IsDefinition(false)
1040 /// ApplyToFields - Target the visitor to the fields of the global.
1042 void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
1043 AnchoredDesc::ApplyToFields(Visitor);
1045 Visitor->Apply(Context);
1046 Visitor->Apply(Name);
1047 DebugInfoDesc* Tmp1 = File;
1048 Visitor->Apply(Tmp1);
1049 File = (CompileUnitDesc*)Tmp1;
1050 Visitor->Apply(Line);
1051 DebugInfoDesc* Tmp2 = TyDesc;
1052 Visitor->Apply(Tmp2);
1053 TyDesc = (TypeDesc*)Tmp2;
1054 Visitor->Apply(IsStatic);
1055 Visitor->Apply(IsDefinition);
1058 //===----------------------------------------------------------------------===//
1060 GlobalVariableDesc::GlobalVariableDesc()
1061 : GlobalDesc(DW_TAG_variable)
1065 // Implement isa/cast/dyncast.
1066 bool GlobalVariableDesc::classof(const DebugInfoDesc *D) {
1067 return D->getTag() == DW_TAG_variable;
1070 /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc.
1072 void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
1073 GlobalDesc::ApplyToFields(Visitor);
1075 Visitor->Apply(Global);
1078 /// getDescString - Return a string used to compose global names and labels.
1080 const char *GlobalVariableDesc::getDescString() const {
1081 return "llvm.dbg.global_variable";
1084 /// getTypeString - Return a string used to label this descriptors type.
1086 const char *GlobalVariableDesc::getTypeString() const {
1087 return "llvm.dbg.global_variable.type";
1090 /// getAnchorString - Return a string used to label this descriptor's anchor.
1092 const char *GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables";
1093 const char *GlobalVariableDesc::getAnchorString() const {
1094 return AnchorString;
1098 void GlobalVariableDesc::dump() {
1099 std::cerr << getDescString() << " "
1100 << "Version(" << getVersion() << "), "
1101 << "Tag(" << getTag() << "), "
1102 << "Anchor(" << getAnchor() << "), "
1103 << "Name(\"" << getName() << "\"), "
1104 << "File(" << getFile() << "),"
1105 << "Line(" << getLine() << "),"
1106 << "Type(\"" << getType() << "\"), "
1107 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1108 << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
1109 << "Global(" << Global << ")\n";
1113 //===----------------------------------------------------------------------===//
1115 SubprogramDesc::SubprogramDesc()
1116 : GlobalDesc(DW_TAG_subprogram)
1119 // Implement isa/cast/dyncast.
1120 bool SubprogramDesc::classof(const DebugInfoDesc *D) {
1121 return D->getTag() == DW_TAG_subprogram;
1124 /// ApplyToFields - Target the visitor to the fields of the
1126 void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
1127 GlobalDesc::ApplyToFields(Visitor);
1130 /// getDescString - Return a string used to compose global names and labels.
1132 const char *SubprogramDesc::getDescString() const {
1133 return "llvm.dbg.subprogram";
1136 /// getTypeString - Return a string used to label this descriptors type.
1138 const char *SubprogramDesc::getTypeString() const {
1139 return "llvm.dbg.subprogram.type";
1142 /// getAnchorString - Return a string used to label this descriptor's anchor.
1144 const char *SubprogramDesc::AnchorString = "llvm.dbg.subprograms";
1145 const char *SubprogramDesc::getAnchorString() const {
1146 return AnchorString;
1150 void SubprogramDesc::dump() {
1151 std::cerr << getDescString() << " "
1152 << "Version(" << getVersion() << "), "
1153 << "Tag(" << getTag() << "), "
1154 << "Anchor(" << getAnchor() << "), "
1155 << "Name(\"" << getName() << "\"), "
1156 << "File(" << getFile() << "),"
1157 << "Line(" << getLine() << "),"
1158 << "Type(\"" << getType() << "\"), "
1159 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1160 << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
1164 //===----------------------------------------------------------------------===//
1166 BlockDesc::BlockDesc()
1167 : DebugInfoDesc(DW_TAG_lexical_block)
1171 // Implement isa/cast/dyncast.
1172 bool BlockDesc::classof(const DebugInfoDesc *D) {
1173 return D->getTag() == DW_TAG_lexical_block;
1176 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
1178 void BlockDesc::ApplyToFields(DIVisitor *Visitor) {
1179 DebugInfoDesc::ApplyToFields(Visitor);
1181 Visitor->Apply(Context);
1184 /// getDescString - Return a string used to compose global names and labels.
1186 const char *BlockDesc::getDescString() const {
1187 return "llvm.dbg.block";
1190 /// getTypeString - Return a string used to label this descriptors type.
1192 const char *BlockDesc::getTypeString() const {
1193 return "llvm.dbg.block.type";
1197 void BlockDesc::dump() {
1198 std::cerr << getDescString() << " "
1199 << "Version(" << getVersion() << "), "
1200 << "Tag(" << getTag() << "),"
1201 << "Context(" << Context << ")\n";
1205 //===----------------------------------------------------------------------===//
1207 DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
1208 return Deserialize(getGlobalVariable(V));
1210 DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
1212 if (!GV) return NULL;
1214 // Check to see if it has been already deserialized.
1215 DebugInfoDesc *&Slot = GlobalDescs[GV];
1216 if (Slot) return Slot;
1218 // Get the Tag from the global.
1219 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1221 // Create an empty instance of the correct sort.
1222 Slot = DebugInfoDesc::DescFactory(Tag);
1224 // If not a user defined descriptor.
1226 // Deserialize the fields.
1227 DIDeserializeVisitor DRAM(*this, GV);
1228 DRAM.ApplyToFields(Slot);
1234 //===----------------------------------------------------------------------===//
1236 /// getStrPtrType - Return a "sbyte *" type.
1238 const PointerType *DISerializer::getStrPtrType() {
1239 // If not already defined.
1241 // Construct the pointer to signed bytes.
1242 StrPtrTy = PointerType::get(Type::SByteTy);
1248 /// getEmptyStructPtrType - Return a "{ }*" type.
1250 const PointerType *DISerializer::getEmptyStructPtrType() {
1251 // If not already defined.
1252 if (!EmptyStructPtrTy) {
1253 // Construct the empty structure type.
1254 const StructType *EmptyStructTy =
1255 StructType::get(std::vector<const Type*>());
1256 // Construct the pointer to empty structure type.
1257 EmptyStructPtrTy = PointerType::get(EmptyStructTy);
1260 return EmptyStructPtrTy;
1263 /// getTagType - Return the type describing the specified descriptor (via tag.)
1265 const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
1266 // Attempt to get the previously defined type.
1267 StructType *&Ty = TagTypes[DD->getTag()];
1269 // If not already defined.
1271 // Set up fields vector.
1272 std::vector<const Type*> Fields;
1273 // Get types of fields.
1274 DIGetTypesVisitor GTAM(*this, Fields);
1275 GTAM.ApplyToFields(DD);
1277 // Construct structured type.
1278 Ty = StructType::get(Fields);
1280 // Register type name with module.
1281 M->addTypeName(DD->getTypeString(), Ty);
1287 /// getString - Construct the string as constant string global.
1289 Constant *DISerializer::getString(const std::string &String) {
1290 // Check string cache for previous edition.
1291 Constant *&Slot = StringCache[String];
1292 // Return Constant if previously defined.
1293 if (Slot) return Slot;
1294 // If empty string then use a sbyte* null instead.
1295 if (String.empty()) {
1296 Slot = ConstantPointerNull::get(getStrPtrType());
1298 // Construct string as an llvm constant.
1299 Constant *ConstStr = ConstantArray::get(String);
1300 // Otherwise create and return a new string global.
1301 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
1302 GlobalVariable::InternalLinkage,
1303 ConstStr, "str", M);
1304 StrGV->setSection("llvm.metadata");
1305 // Convert to generic string pointer.
1306 Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
1312 /// Serialize - Recursively cast the specified descriptor into a GlobalVariable
1313 /// so that it can be serialized to a .bc or .ll file.
1314 GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
1315 // Check if the DebugInfoDesc is already in the map.
1316 GlobalVariable *&Slot = DescGlobals[DD];
1318 // See if DebugInfoDesc exists, if so return prior GlobalVariable.
1319 if (Slot) return Slot;
1321 // Get the type associated with the Tag.
1322 const StructType *Ty = getTagType(DD);
1324 // Create the GlobalVariable early to prevent infinite recursion.
1325 GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(),
1326 NULL, DD->getDescString(), M);
1327 GV->setSection("llvm.metadata");
1329 // Insert new GlobalVariable in DescGlobals map.
1332 // Set up elements vector
1333 std::vector<Constant*> Elements;
1335 DISerializeVisitor SRAM(*this, Elements);
1336 SRAM.ApplyToFields(DD);
1338 // Set the globals initializer.
1339 GV->setInitializer(ConstantStruct::get(Ty, Elements));
1344 //===----------------------------------------------------------------------===//
1346 /// Verify - Return true if the GlobalVariable appears to be a valid
1347 /// serialization of a DebugInfoDesc.
1348 bool DIVerifier::Verify(Value *V) {
1349 return !V || Verify(getGlobalVariable(V));
1351 bool DIVerifier::Verify(GlobalVariable *GV) {
1353 if (!GV) return true;
1355 // Check prior validity.
1356 unsigned &ValiditySlot = Validity[GV];
1358 // If visited before then use old state.
1359 if (ValiditySlot) return ValiditySlot == Valid;
1361 // Assume validity for the time being (recursion.)
1362 ValiditySlot = Valid;
1364 // Make sure the global is internal or link once (anchor.)
1365 if (GV->getLinkage() != GlobalValue::InternalLinkage &&
1366 GV->getLinkage() != GlobalValue::LinkOnceLinkage) {
1367 ValiditySlot = Invalid;
1372 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1374 // Check for user defined descriptors.
1375 if (Tag == DW_TAG_invalid) return true;
1377 // Construct an empty DebugInfoDesc.
1378 DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag);
1380 // Allow for user defined descriptors.
1381 if (!DD) return true;
1383 // Get the initializer constant.
1384 ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer());
1386 // Get the operand count.
1387 unsigned N = CI->getNumOperands();
1389 // Get the field count.
1390 unsigned &CountSlot = Counts[Tag];
1392 // Check the operand count to the field count
1393 DICountVisitor CTAM;
1394 CTAM.ApplyToFields(DD);
1395 CountSlot = CTAM.getCount();
1398 // Field count must be at most equal operand count.
1399 if (CountSlot > N) {
1401 ValiditySlot = Invalid;
1405 // Check each field for valid type.
1406 DIVerifyVisitor VRAM(*this, GV);
1407 VRAM.ApplyToFields(DD);
1409 // Release empty DebugInfoDesc.
1412 // If fields are not valid.
1413 if (!VRAM.isValid()) {
1414 ValiditySlot = Invalid;
1421 //===----------------------------------------------------------------------===//
1423 DebugScope::~DebugScope() {
1424 for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i];
1425 for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j];
1428 //===----------------------------------------------------------------------===//
1430 MachineDebugInfo::MachineDebugInfo()
1442 MachineDebugInfo::~MachineDebugInfo() {
1446 /// doInitialization - Initialize the debug state for a new module.
1448 bool MachineDebugInfo::doInitialization() {
1452 /// doFinalization - Tear down the debug state after completion of a module.
1454 bool MachineDebugInfo::doFinalization() {
1458 /// BeginFunction - Begin gathering function debug information.
1460 void MachineDebugInfo::BeginFunction(MachineFunction *MF) {
1464 /// MachineDebugInfo::EndFunction - Discard function debug information.
1466 void MachineDebugInfo::EndFunction() {
1467 // Clean up scope information.
1474 // Clean up frame info.
1475 for (unsigned i = 0, N = FrameMoves.size(); i < N; ++i) delete FrameMoves[i];
1479 /// getDescFor - Convert a Value to a debug information descriptor.
1481 // FIXME - use new Value type when available.
1482 DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) {
1483 return DR.Deserialize(V);
1486 /// Verify - Verify that a Value is debug information descriptor.
1488 bool MachineDebugInfo::Verify(Value *V) {
1489 return VR.Verify(V);
1492 /// AnalyzeModule - Scan the module for global debug information.
1494 void MachineDebugInfo::AnalyzeModule(Module &M) {
1495 SetupCompileUnits(M);
1498 /// SetupCompileUnits - Set up the unique vector of compile units.
1500 void MachineDebugInfo::SetupCompileUnits(Module &M) {
1501 std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M);
1503 for (unsigned i = 0, N = CU.size(); i < N; i++) {
1504 CompileUnits.insert(CU[i]);
1508 /// getCompileUnits - Return a vector of debug compile units.
1510 const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{
1511 return CompileUnits;
1514 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1515 /// named GlobalVariable.
1516 std::vector<GlobalVariable*>
1517 MachineDebugInfo::getGlobalVariablesUsing(Module &M,
1518 const std::string &RootName) {
1519 return ::getGlobalVariablesUsing(M, RootName);
1522 /// RecordLabel - Records location information and associates it with a
1523 /// debug label. Returns a unique label ID used to generate a label and
1524 /// provide correspondence to the source line list.
1525 unsigned MachineDebugInfo::RecordLabel(unsigned Line, unsigned Column,
1527 unsigned ID = NextLabelID();
1528 Lines.push_back(new SourceLineInfo(Line, Column, Source, ID));
1532 /// RecordSource - Register a source file with debug info. Returns an source
1534 unsigned MachineDebugInfo::RecordSource(const std::string &Directory,
1535 const std::string &Source) {
1536 unsigned DirectoryID = Directories.insert(Directory);
1537 return SourceFiles.insert(SourceFileInfo(DirectoryID, Source));
1539 unsigned MachineDebugInfo::RecordSource(const CompileUnitDesc *CompileUnit) {
1540 return RecordSource(CompileUnit->getDirectory(),
1541 CompileUnit->getFileName());
1544 /// RecordRegionStart - Indicate the start of a region.
1546 unsigned MachineDebugInfo::RecordRegionStart(Value *V) {
1547 // FIXME - need to be able to handle split scopes because of bb cloning.
1548 DebugInfoDesc *ScopeDesc = DR.Deserialize(V);
1549 DebugScope *Scope = getOrCreateScope(ScopeDesc);
1550 unsigned ID = NextLabelID();
1551 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
1555 /// RecordRegionEnd - Indicate the end of a region.
1557 unsigned MachineDebugInfo::RecordRegionEnd(Value *V) {
1558 // FIXME - need to be able to handle split scopes because of bb cloning.
1559 DebugInfoDesc *ScopeDesc = DR.Deserialize(V);
1560 DebugScope *Scope = getOrCreateScope(ScopeDesc);
1561 unsigned ID = NextLabelID();
1562 Scope->setEndLabelID(ID);
1566 /// RecordVariable - Indicate the declaration of a local variable.
1568 void MachineDebugInfo::RecordVariable(Value *V, unsigned FrameIndex) {
1569 VariableDesc *VD = cast<VariableDesc>(DR.Deserialize(V));
1570 DebugScope *Scope = getOrCreateScope(VD->getContext());
1571 DebugVariable *DV = new DebugVariable(VD, FrameIndex);
1572 Scope->AddVariable(DV);
1575 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1577 DebugScope *MachineDebugInfo::getOrCreateScope(DebugInfoDesc *ScopeDesc) {
1578 DebugScope *&Slot = ScopeMap[ScopeDesc];
1580 // FIXME - breaks down when the context is an inlined function.
1581 DebugInfoDesc *ParentDesc = NULL;
1582 if (BlockDesc *Block = dyn_cast<BlockDesc>(ScopeDesc)) {
1583 ParentDesc = Block->getContext();
1585 DebugScope *Parent = ParentDesc ? getOrCreateScope(ParentDesc) : NULL;
1586 Slot = new DebugScope(Parent, ScopeDesc);
1588 Parent->AddScope(Slot);
1589 } else if (RootScope) {
1590 // FIXME - Add inlined function scopes to the root so we can delete
1591 // them later. Long term, handle inlined functions properly.
1592 RootScope->AddScope(Slot);
1594 // First function is top level function.