From 45ccae5b7d658e9948f3cdfc8f06facaca536e1f Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Tue, 28 Feb 2006 20:15:07 +0000 Subject: [PATCH] Add const, volatile, restrict support. Add array of debug descriptor support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26428 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineDebugInfo.h | 18 +++++-- lib/CodeGen/DwarfWriter.cpp | 3 ++ lib/CodeGen/MachineDebugInfo.cpp | 69 +++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/include/llvm/CodeGen/MachineDebugInfo.h b/include/llvm/CodeGen/MachineDebugInfo.h index b51ea646898..5cbd93ac839 100644 --- a/include/llvm/CodeGen/MachineDebugInfo.h +++ b/include/llvm/CodeGen/MachineDebugInfo.h @@ -66,7 +66,10 @@ enum { DI_TAG_basictype, DI_TAG_typedef, DI_TAG_pointer, - DI_TAG_reference + DI_TAG_reference, + DI_TAG_const, + DI_TAG_volatile, + DI_TAG_restrict }; //===----------------------------------------------------------------------===// @@ -90,6 +93,7 @@ public: virtual void Apply(std::string &Field) = 0; virtual void Apply(DebugInfoDesc *&Field) = 0; virtual void Apply(GlobalVariable *&Field) = 0; + virtual void Apply(std::vector &Field) = 0; }; //===----------------------------------------------------------------------===// @@ -148,7 +152,6 @@ public: #endif }; - //===----------------------------------------------------------------------===// /// AnchorDesc - Descriptors of this class act as markers for identifying /// descriptors of certain groups. @@ -371,7 +374,16 @@ public: static bool classof(const DerivedTypeDesc *) { return true; } static bool classof(const DebugInfoDesc *D) { unsigned T = D->getTag(); - return T == DI_TAG_typedef || T == DI_TAG_pointer || T == DI_TAG_reference; + switch (T) { + case DI_TAG_typedef: + case DI_TAG_pointer: + case DI_TAG_reference: + case DI_TAG_const: + case DI_TAG_volatile: + case DI_TAG_restrict: + return true; + default: return false; + } } /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc. diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp index d08e7779724..41e539b52df 100644 --- a/lib/CodeGen/DwarfWriter.cpp +++ b/lib/CodeGen/DwarfWriter.cpp @@ -1075,6 +1075,9 @@ DIE *DwarfWriter::NewType(CompileUnit *Unit, TypeDesc *TyDesc) { case DI_TAG_typedef: T = DW_TAG_typedef; break; case DI_TAG_pointer: T = DW_TAG_pointer_type; break; case DI_TAG_reference: T = DW_TAG_reference_type; break; + case DI_TAG_const: T = DW_TAG_const_type; break; + case DI_TAG_volatile: T = DW_TAG_volatile_type; break; + case DI_TAG_restrict: T = DW_TAG_restrict_type; break; default: assert( 0 && "Unknown tag on derived type"); } diff --git a/lib/CodeGen/MachineDebugInfo.cpp b/lib/CodeGen/MachineDebugInfo.cpp index 72da0a04060..e4702ed1bef 100644 --- a/lib/CodeGen/MachineDebugInfo.cpp +++ b/lib/CodeGen/MachineDebugInfo.cpp @@ -202,6 +202,9 @@ public: virtual void Apply(std::string &Field) { ++Count; } virtual void Apply(DebugInfoDesc *&Field) { ++Count; } virtual void Apply(GlobalVariable *&Field) { ++Count; } + virtual void Apply(std::vector &Field) { + ++Count; + } }; //===----------------------------------------------------------------------===// @@ -251,6 +254,17 @@ public: Constant *C = CI->getOperand(I++); Field = getGlobalVariable(C); } + virtual void Apply(std::vector &Field) { + Constant *C = CI->getOperand(I++); + GlobalVariable *GV = getGlobalVariable(C); + ConstantArray *CA = cast(GV->getInitializer()); + Field.resize(0); + for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) { + GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); + DebugInfoDesc *DE = DR.Deserialize(GVE); + Field.push_back(DE); + } + } }; //===----------------------------------------------------------------------===// @@ -310,6 +324,22 @@ public: Elements.push_back(ConstantPointerNull::get(EmptyTy)); } } + virtual void Apply(std::vector &Field) { + const PointerType *EmptyTy = SR.getEmptyStructPtrType(); + unsigned N = Field.size(); + ArrayType *AT = ArrayType::get(EmptyTy, N); + std::vector ArrayElements; + + for (unsigned i = 0, N = Field.size(); i < N; ++i) { + GlobalVariable *GVE = SR.Serialize(Field[i]); + Constant *CE = ConstantExpr::getCast(GVE, EmptyTy); + ArrayElements.push_back(cast(CE)); + } + + Constant *CA = ConstantArray::get(AT, ArrayElements); + Constant *CAE = ConstantExpr::getCast(CA, EmptyTy); + Elements.push_back(CAE); + } }; //===----------------------------------------------------------------------===// @@ -353,6 +383,10 @@ public: const PointerType *EmptyTy = SR.getEmptyStructPtrType(); Fields.push_back(EmptyTy); } + virtual void Apply(std::vector &Field) { + const PointerType *EmptyTy = SR.getEmptyStructPtrType(); + Fields.push_back(EmptyTy); + } }; //===----------------------------------------------------------------------===// @@ -409,6 +443,27 @@ public: Constant *C = CI->getOperand(I++); IsValid = IsValid && isGlobalVariable(C); } + virtual void Apply(std::vector &Field) { + Constant *C = CI->getOperand(I++); + IsValid = IsValid && isGlobalVariable(C); + if (!IsValid) return; + + GlobalVariable *GV = getGlobalVariable(C); + IsValid = IsValid && GV && GV->hasInitializer(); + if (!IsValid) return; + + ConstantArray *CA = dyn_cast(GV->getInitializer()); + IsValid = IsValid && CA; + if (!IsValid) return; + + for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) { + IsValid = IsValid && isGlobalVariable(CA->getOperand(i)); + if (!IsValid) return; + + GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); + VR.Verify(GVE); + } + } }; @@ -430,9 +485,12 @@ DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) { case DI_TAG_global_variable: return new GlobalVariableDesc(); case DI_TAG_subprogram: return new SubprogramDesc(); case DI_TAG_basictype: return new BasicTypeDesc(); - case DI_TAG_typedef: return new DerivedTypeDesc(DI_TAG_typedef); - case DI_TAG_pointer: return new DerivedTypeDesc(DI_TAG_pointer); - case DI_TAG_reference: return new DerivedTypeDesc(DI_TAG_reference); + case DI_TAG_typedef: + case DI_TAG_pointer: + case DI_TAG_reference: + case DI_TAG_const: + case DI_TAG_volatile: + case DI_TAG_restrict: return new DerivedTypeDesc(Tag); default: break; } return NULL; @@ -639,8 +697,7 @@ DerivedTypeDesc::DerivedTypeDesc(unsigned T) : TypeDesc(T) , FromType(NULL) { - assert((T == DI_TAG_typedef || T == DI_TAG_pointer || T == DI_TAG_reference)&& - "Unknown derived type."); + assert(classof((const DebugInfoDesc *)this) && "Unknown derived type."); } /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc. @@ -777,6 +834,8 @@ void SubprogramDesc::dump() { } #endif +//===----------------------------------------------------------------------===// + DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { return Deserialize(getGlobalVariable(V)); }