[cfe-dev] StructTypes to Metadata

Михаил neonomaly.x at gmail.com
Wed May 2 10:08:38 PDT 2012


I've tried to export inheritance of CXX classes into Metadata:
!ISPDIL_INH_<class or struct name> = {!0}
!0 = {!metadata <one of parent>, !metadata <another parent>}

For achieving this I've changed ConvertRecordDeclType in CodeGenTypes.cpp:

llvm::StructType *CodeGenTypes::ConvertRecordDeclType(const RecordDecl *RD) {
  // TagDecl's are not necessarily unique, instead use the (clang)
  // type connected to the decl.
  const Type *Key = Context.getTagDeclType(RD).getTypePtr();

  llvm::StructType *&Entry = RecordDeclTypes[Key];

  // If we don't have a StructType at all yet, create the forward declaration.
  if (Entry == 0) {
    Entry = llvm::StructType::create(getLLVMContext());
    addRecordTypeName(RD, Entry, "");
  llvm::StructType *Ty = Entry;
  // If this is still a forward declaration, or the LLVM type is already
  // complete, there's nothing more to do.
  RD = RD->getDefinition();
  if (RD == 0 || !RD->isCompleteDefinition() || !Ty->isOpaque())
    return Ty;
  // If converting this type would cause us to infinitely loop, don't do it!
  if (!isSafeToConvert(RD, *this)) {
    return Ty;

  // Okay, this is a definition of a type.  Compile the implementation now.
  bool InsertResult = RecordsBeingLaidOut.insert(Key); (void)InsertResult;
  assert(InsertResult && "Recursively compiling a struct?");
  // Force conversion of non-virtual base classes recursively.

  if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
	std::vector<llvm::StructType *> parentsForISPDIL;
    for (CXXRecordDecl::base_class_const_iterator i = CRD->bases_begin(), e = CRD->bases_end(); i != e; ++i) {
      if (i->isVirtual()) continue;

    // ISPDIL inheritance import

    std::vector<llvm::Value*> parents;
    for (std::vector<llvm::StructType*>::iterator p = parentsForISPDIL.begin(); p!=parentsForISPDIL.end(); p++) {
  	  parents.push_back(llvm::MDString::get(Ty->getContext(), (*p)->getName()));

    llvm::MDNode* Node = llvm::MDNode::get(Ty->getContext(), parents);
    llvm::NamedMDNode* NMD = TheModule.getOrInsertNamedMetadata(std::string("ISPDIL_INH_").append(Ty->getName()));


  // Layout fields.
  CGRecordLayout *Layout = ComputeRecordLayout(RD, Ty);
  CGRecordLayouts[Key] = Layout;

  // We're done laying out this struct.
  bool EraseResult = RecordsBeingLaidOut.erase(Key); (void)EraseResult;
  assert(EraseResult && "struct not in RecordsBeingLaidOut set?");
  // If this struct blocked a FunctionType conversion, then recompute whatever
  // was derived from that.
  // FIXME: This is hugely overconservative.
  if (SkippedLayout)
  // If we're done converting the outer-most record, then convert any deferred
  // structs as well.
  if (RecordsBeingLaidOut.empty())
    while (!DeferredRecords.empty())

  return Ty;

But with that patch I haven't some classes from Module in my Metadata in one cases and I have some names in my metadata but module haven't StructTypes according this names. 

How can I solve my problem correctly? Thanks!

Yours sincerely,
Kadysev Mikhail

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120502/7c8ac828/attachment.html>

More information about the cfe-dev mailing list