[LLVMdev] [Help] How can we call an object's virtual function inside IR?

Gyounghwa Kim gyounghwakim at gmail.com
Tue Jan 5 02:35:50 PST 2010


Dear experts,

I am learning llvm by reading documents and have a question to ask.

The following is the example of code generation that I created.

[[a [10.00]] > [3.00]]
; ModuleID = 'ExprF'

define i1 @expr(double* %record) {
entry:
        %0 = getelementptr double* %record, i32 0               ;
<double*> [#uses=1]
        %1 = load double* %0            ; <double> [#uses=1]
        %2 = frem double %1, 1.000000e+01               ; <double> [#uses=1]
        %3 = fcmp ogt double %2, 3.000000e+00           ; <i1> [#uses=1]
        ret i1 %3
}

Now, I would like to change the type of the argument from double * to
a pointer to an object ( C++ class ) like ClassA * %record, and inside
the function body, I would like to call the virtual functions of the
ClassA %record object to get the value
for the evaluation. As far as I understand, we can get the members of
a struct from getElementPtr function, but is it possible
to call a virtual function of an object to get the value?

Could you explain on how to do this?

Thank you very much for your help in advance. :)

Best regards,

Gyounghwa Kim



More information about the llvm-dev mailing list