[PATCH] D19181: Map Attribute in the C API.

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 07:52:48 PDT 2016


jyknight added a comment.

I'd like to see a //complete// list of the API functions that will be created. Recall the proposal I wrote earlier, which contained declarations that could go in a header. Write one just like that, containing all of the functions you propose to create for attribute access. That is, don't say "Then the same for calls, functions and parameters." or "and there is a plan for accessors" -- that's too vague for me to fully understand your intent.

To maybe help get things going, here's my previous proposal after modifying it to remove AttributeSet (as I'd suggested earlier). Please respond with a counter-proposal along the same lines.

  /* All attribute accessors work on CallInst, InvokeInst, and Function values. Use on other kinds of
   * LLVMValueRef objects is an error. */
  
  typedef unsigned LLVMAttrKind;
  
  /* Returns the number corresponding to a given built-in attribute. */
  LLVMAttrKind LLVMGetAttributeKindForName(const char *Name);
  
  /* In the below APIs, "Index" shall refer either to the parameter number, numbered 1 to N,
     or LLVMAttributeReturnIndex or LLVMAttributeFunctionIndex. */
  enum {
    LLVMAttributeReturnIndex = 0U,
    LLVMAttributeFunctionIndex = ~0U
  };
  
  /* Retrieve the number of attributes in the attribute-set. For use with the 'LLVM*AtIndex' APIs
   * below.*/
  unsigned LLVMNumAttributes(LLVMValueRef AS, unsigned Index);
  
  /* Whether the attr kind of the given attribute is a String, not an LLVMAttrKind enum */
  bool LLVMIsStringAttributeAtIndex(LLVMValueRef AS, unsigned Index, unsigned i);
  
  /* Retrieve the kind of attribute at a given index. Returns 0 on failure, e.g. if that attribute is
   * a string attribute. */
  LLVMAttrKind LLVMGetAttributeKindAtIndex(LLVMValueRef AS, unsigned Index, unsigned i);
  
  /* Retrieve the kind string of a string attribute. Returns NULL on failure, e.g. if that attribute
   * is of an LLVMAttrKind enum */
  char *LLVMGetStringAttributeKindAtIndex(LLVMValueRef AS, unsigned Index, unsigned i);
  
  
  /* Query if a given attribute kind is present */
  LLVMBool LLVMHasAttribute(LLVMValueRef AS, unsigned Index, LLVMAttrKind Kind);
  
  /* Retrieve the value of an integer attribute. Fails if the given kind isn't present or doesn't
   * store an integer. */
  uint64_t LLVMGetIntAttribute(LLVMValueRef AS, unsigned Index, LLVMAttrKind Kind);
  
  /* Retrieve the value of a string attribute; if not present, returns NULL. */
  char *LLVMGetStringAttribute(LLVMValueRef AS, unsigned Index, char *Name);
  
  /* Set/replace attributes. */
  void LLVMSetAttribute(LLVMValueRef AS, unsigned Index, LLVMAttrKind Kind);
  void LLVMSetIntAttribute(LLVMValueRef AS, unsigned Index, LLVMAttrKind Kind, uint64_t Val);
  void LLVMSetStringAttribute(LLVMValueRef AS, char *Name, char *Val);
  
  /* Removing attributes. */
  void LLVMRemoveAttribute(LLVMValueRef AS, unsigned Index, LLVMAttrKind Kind);
  void LLVMRemoveStringAttribute(LLVMValueRef AS, unsigned Index, char *Name);


http://reviews.llvm.org/D19181





More information about the llvm-commits mailing list