2016-11-25 3 views
0

Je suis assez nouveau avec LLVM et ayant du mal à creuser profondément dans la ligne IR suivante:Obtenez les arguments d'une fonction dans bitcasts dans les appels, LLVM

%call2 = call float bitcast (float (float, i32*)* @function to float (float, i32 addrspace(1)*)*)(float %11, i32 addrspace(1)* %arrayidx) 

Ce que je dois extraire de c'est la ligne du type des arguments de la fonction (ie, (float% 11, i32 addrspace (1) *% arrayidx))

J'ai essayé ce qui suit, et j'ai joué un peu avec ConstExpr, mais je n'arrive pas à extraire ça addrspace (1)

for (Function::iterator block = F.begin(), blockEnd = F.end(); block != blockEnd; ++block) { 
    for (BasicBlock::iterator inst = block->begin(), instEnd = block->end(); inst != instEnd; ++inst) { 
    if (CallInst *call = dyn_cast<CallInst>(inst)) { 
     Function *calledFunction = call->getCalledFunction(); 
     if (calledFunction == NULL) { // Called function is wrapped in a bitcast 
     Value* v = call->getCalledValue(); 
     calledFunction = dyn_cast<Function>(v->stripPointerCasts()); 
     FunctionType *ft = calledFunction->getFunctionType(); // This gives me the type "from" (the args without addrspace(1) 
     for(Function::arg_iterator arg = calledFunction->arg_begin(), marg_end = calledFunction->arg_end(); arg != marg_end ; arg++){ 
     Type *argTy = arg->getType(); 
     if (PointerType *ptrTy = dyn_cast<PointerType>(argTy)) { 
      if(ptrTy->getAddressSpace() !=0) 
      ... 
      } 
     } 
     } 
    } 
    } 
} 

Le code ci-dessus me donne les types (float, i32 *) et non (float, i32 addrspace (1) *)

Une aide s'il vous plaît?

Répondre

1

LLVM ir

%call2 = call float bitcast (float (float, i32*)* @function to float (float, i32 addrspace(1)*)*)(float %11, i32 addrspace(1)* %arrayidx) 

est coulée type float fonction (float, i32 *) flotter (flotteur, i32 ajouter (1) *) et de l'appeler avec l'argument (% 11,% arrayidx). Si vous voulez les types d'arguments, vous pouvez le vérifier en utilisant callInst :: getArgOperand pour obtenir des arguments dans l'instruction d'appel elle-même.

for (Function::iterator block = F.begin(), blockEnd = F.end(); block != blockEnd; ++block) { 
    for (BasicBlock::iterator inst = block->begin(), instEnd = block->end(); inst != instEnd; ++inst) { 
     if (CallInst *call = dyn_cast<CallInst>(inst)) { 
       Value *val11 = call->getArgOperand(0); 
       Value *valarrayIdx = call->getArgOperand(1); 

       Type *val11ty = val11->getType(); // this should be of float 
       Type *valarrayIdx = valarrayIdx->getType(); // this should be of i32 address(1)* 
      } 
     } 
    } 

CallInst :: getCalledFunction vous donnera la fonction. pour plus d'informations, vous pouvez passer par http://llvm.org/docs/doxygen/html/classllvm_1_1CallInst.html

+0

Excellent! Maintenant, cela a du sens. Je vous remercie. Savez-vous aussi comment je peux obtenir l'argument de retour? (% call2 dans ce cas) Je ne trouve rien qui soit lié à l'argument return d'un callinst dans http://llvm.org/docs/doxygen/html/classllvm_1_1CallInst.html – Shervin

+2

@Shervin Le 'CallInst' lui-même est un' Value' qui correspond à la valeur de retour. –