Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get annotations for a specific function, traverse the entry BasicBlock of the function to find its calls to the <code>@llvm.var.annotation</code> intrinsic, as follows:</p> <pre><code>Module *module; [...] std::string getGlobalVariableString(std::string name) { // assumption: the zeroth operand of a Value::GlobalVariableVal is the actual Value Value *v = module-&gt;getNamedValue(name)-&gt;getOperand(0); if(v-&gt;getValueID() == Value::ConstantArrayVal) { ConstantArray *ca = (ConstantArray *)v; return ca-&gt;getAsString(); } return ""; } void dumpFunctionArgAnnotations(std::string funcName) { std::map&lt;Value *,Argument*&gt; mapValueToArgument; Function *func = module-&gt;getFunction(funcName); if(!func) { std::cout &lt;&lt; "no function by that name.\n"; return; } std::cout &lt;&lt; funcName &lt;&lt; "() ====================\n"; // assumption: @llvm.var.annotation calls are always in the function's entry block. BasicBlock *b = &amp;func-&gt;getEntryBlock(); // run through entry block first to build map of pointers to arguments for(BasicBlock::iterator it = b-&gt;begin();it!=b-&gt;end();++it) { Instruction *inst = it; if(inst-&gt;getOpcode()!=Instruction::Store) continue; // `store` operands: http://llvm.org/docs/LangRef.html#i_store mapValueToArgument[inst-&gt;getOperand(1)] = (Argument *)inst-&gt;getOperand(0); } // run through entry block a second time, to associate annotations with arguments for(BasicBlock::iterator it = b-&gt;begin();it!=b-&gt;end();++it) { Instruction *inst = it; if(inst-&gt;getOpcode()!=Instruction::Call) continue; // assumption: Instruction::Call's operands are the function arguments, followed by the function name Value *calledFunction = inst-&gt;getOperand(inst-&gt;getNumOperands()-1); if(calledFunction-&gt;getName().str() != "llvm.var.annotation") continue; // `llvm.var.annotation` operands: http://llvm.org/docs/LangRef.html#int_var_annotation Value *annotatedValue = inst-&gt;getOperand(0); if(annotatedValue-&gt;getValueID() != Value::InstructionVal + Instruction::BitCast) continue; Argument *a = mapValueToArgument[annotatedValue-&gt;getUnderlyingObject()]; if(!a) continue; Value *annotation = inst-&gt;getOperand(1); if(annotation-&gt;getValueID() != Value::ConstantExprVal) continue; ConstantExpr *ce = (ConstantExpr *)annotation; if(ce-&gt;getOpcode() != Instruction::GetElementPtr) continue; // `ConstantExpr` operands: http://llvm.org/docs/LangRef.html#constantexprs Value *gv = ce-&gt;getOperand(0); if(gv-&gt;getValueID() != Value::GlobalVariableVal) continue; std::cout &lt;&lt; " argument " &lt;&lt; a-&gt;getType()-&gt;getDescription() &lt;&lt; " " &lt;&lt; a-&gt;getName().str() &lt;&lt; " has annotation \"" &lt;&lt; getGlobalVariableString(gv-&gt;getName().str()) &lt;&lt; "\"\n"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload