[cfe-commits] r80064 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/virt.cpp

John McCall rjmccall at apple.com
Tue Aug 25 19:23:06 PDT 2009


Mike Stump wrote:
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Aug 25 20:54:35 2009
> @@ -932,17 +937,17 @@
>      SeenVBase.clear();
>    }
>  
> -  inline uint32_t nottoobig(uint64_t t) {
> -    assert(t < (uint32_t)-1ULL || "vtable too big");
> +  inline Index_t nottoobig(uint64_t t) {
> +    assert(t < (Index_t)-1ULL || "vtable too big");
>      return t;
>    }
>   

This seems to be basically dead.  If it isn't, you should probably use
numeric_limits<Index_t>::max() from <limits>.

> +class VtableInfo {
> +public:
> +  typedef VtableBuilder::Index_t Index_t;
> +private:
> +  CodeGenModule &CGM;  // Per-module state.
> +  /// Index_t - Vtable index type.
> +  typedef llvm::DenseMap<const CXXMethodDecl *, Index_t> ElTy;
> +  typedef llvm::DenseMap<const CXXRecordDecl *, ElTy *> MapTy;
> +  // FIXME: Move to Context.
> +  static MapTy IndexFor;
> +public:
> +  VtableInfo(CodeGenModule &cgm) : CGM(cgm) { }
> +  void register_index(const CXXRecordDecl *RD, const ElTy &e) {
> +    assert(IndexFor.find(RD) == IndexFor.end() || "Don't compute vtbl twice");
>   

&&

> +    // We own a copy of this, it will go away shortly.
> +    new ElTy (e);
> +    IndexFor[RD] = new ElTy (e);
> +  }
> +  Index_t lookup(const CXXMethodDecl *MD) {
> +    const CXXRecordDecl *RD = MD->getParent();
> +    MapTy::iterator I = IndexFor.find(RD);
> +    if (I == IndexFor.end()) {
> +      std::vector<llvm::Constant *> methods;
> +      VtableBuilder b(methods, RD, CGM);
> +      b.GenerateVtableForBase(RD, true, false, 0, false);
> +      b.GenerateVtableForVBases(RD, RD);
> +      register_index(RD, b.getIndex());
> +      I = IndexFor.find(RD);
> +    }
> +    assert(I->second->find(MD)!=I->second->end() || "Can't find vtable index");
>   

&&

Also, awesome, we have virtual dispatch.

John.



More information about the cfe-commits mailing list