<commit_before>.. _ir-values:

======
Values
======

.. currentmodule:: llvmlite.ir


.. contents::
   :local:
   :depth: 1

A :ref:`module` consists mostly of values.

.. data:: Undefined

   An undefined value, mapping to LLVM's ``undef``.


.. class:: Value

   The base class for all IR values.


.. class:: Constant(typ, constant)

   A literal value.

   * *typ* is the type of the represented value---a
     :class:`~llvmlite.ir.Type` instance.

   * *constant* is the Python value to be represented.

   Which Python types are allowed for *constant* depends on *typ*:

   * All types accept :data:`Undefined` and convert it to
     LLVM's ``undef``.

   * All types accept ``None`` and convert it to LLVM's
     ``zeroinitializer``.

   * :class:`IntType` accepts any Python integer or boolean.

   * :class:`FloatType` and :class:`DoubleType` accept any
     Python real number.

   * Aggregate types---array and structure types---accept a
     sequence of Python values corresponding to the type's
     element types.

   * :class:`ArrayType` accepts a single :class:`bytearray`
     instance to initialize the array from a string of bytes.
     This is useful for character constants.

   .. classmethod:: literal_array(elements)

      An alternate constructor for constant arrays.

      * *elements* is a sequence of values, :class:`Constant` or
        otherwise.
      * All *elements* must have the same type.
      * Returns a constant array containing the *elements*, in
        order.

   .. classmethod:: literal_struct(elements)

      An alternate constructor for constant structs.

      * *elements* is a sequence of values, :class:`Constant` or
        otherwise. Returns a constant struct containing the
        *elements* in order.

      * .. method:: bitcast(typ)

           Convert this pointer constant to a constant of the
           given pointer type.

      * .. method:: gep(indices)

           Compute the address of the inner element given by the
           sequence of *indices*. The constant must have a pointer
           type.

      * .. method:: inttoptr(typ)

           Convert this integer constant to a constant of the
           given pointer type.

      NOTE: You cannot define constant functions. Use a
      :ref:`function declaration` instead.

.. class:: Argument

   One of a function's arguments. Arguments have the
   :meth:`add_attribute` method.

   .. method:: add_attribute(attr)

      Add an argument attribute to this argument. *attr* is a
      Python string.
<commit_msg>Fix incorrect hierarchy in the documentation for ir.Constant.<commit_after>.. _ir-values:

======
Values
======

.. currentmodule:: llvmlite.ir


.. contents::
   :local:
   :depth: 1

A :ref:`module` consists mostly of values.

.. data:: Undefined

   An undefined value, mapping to LLVM's ``undef``.


.. class:: Value

   The base class for all IR values.


.. class:: Constant(typ, constant)

   A literal value.

   * *typ* is the type of the represented value---a
     :class:`~llvmlite.ir.Type` instance.

   * *constant* is the Python value to be represented.

   Which Python types are allowed for *constant* depends on *typ*:

   * All types accept :data:`Undefined` and convert it to
     LLVM's ``undef``.

   * All types accept ``None`` and convert it to LLVM's
     ``zeroinitializer``.

   * :class:`IntType` accepts any Python integer or boolean.

   * :class:`FloatType` and :class:`DoubleType` accept any
     Python real number.

   * Aggregate types---array and structure types---accept a
     sequence of Python values corresponding to the type's
     element types.

   * :class:`ArrayType` accepts a single :class:`bytearray`
     instance to initialize the array from a string of bytes.
     This is useful for character constants.

   .. classmethod:: literal_array(elements)

      An alternate constructor for constant arrays.

      * *elements* is a sequence of values, :class:`Constant` or
        otherwise.
      * All *elements* must have the same type.
      * Returns a constant array containing the *elements*, in
        order.

   .. classmethod:: literal_struct(elements)

      An alternate constructor for constant structs.

      * *elements* is a sequence of values, :class:`Constant` or
        otherwise. Returns a constant struct containing the
        *elements* in order.

   .. method:: bitcast(typ)

      Convert this pointer constant to a constant of the
      given pointer type.

   .. method:: gep(indices)

      Compute the address of the inner element given by the
      sequence of *indices*. The constant must have a pointer
      type.

   .. method:: inttoptr(typ)

      Convert this integer constant to a constant of the
      given pointer type.

   NOTE: You cannot define constant functions. Use a
   :ref:`function declaration` instead.

.. class:: Argument

   One of a function's arguments. Arguments have the
   :meth:`add_attribute` method.

   .. method:: add_attribute(attr)

      Add an argument attribute to this argument. *attr* is a
      Python string.

{'fraction_non_alphanumeric': 0.09479700433582972, 'fraction_numerical': 0.00039416633819471815, 'mean_word_length': 2.707085463842221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6522852', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1310, 'n_words': 579}