Are integer types primitive?

The LLVM docs seem to indicate that integer types are considered primitive, however looking at the code I see FirstDerivedTyID = IntegerTyID, implying that integers are derived rather than primitive. Should the docs be updated?

So, I did a quick experiment with the following patch:

diff --git a/include/llvm/IR/Type.h b/include/llvm/IR/Type.h
index 1bf8789…16bd376 100644
— a/include/llvm/IR/Type.h
+++ b/include/llvm/IR/Type.h
@@ -73,8 +73,8 @@ public:
VectorTyID, ///< 15: SIMD ‘packed’ format, or other vector type

NumTypeIDs, // Must remain as last defined ID

  • LastPrimitiveTyID = X86_MMXTyID,
  • FirstDerivedTyID = IntegerTyID
  • LastPrimitiveTyID = IntegerTyID,
  • FirstDerivedTyID = FunctionTyID
    };

private:

‘ninja check-all’ passes. The only users of isPrimitiveType also check isIntegerTy.

Originally, the distinguishing feature of “primitive” types was that they were enumerable and not parameterized on anything.

Then we moved to arbitrary bit-width integers types to generalize things significantly (the right move IMO).

Thus, integers were no longer technically primitive types, and their categorization in code has changed to reflect this.

But that doesn’t make any sense. The documentation for primitive types also is still written in a way that would include integers.

I think we just need a new distinguishing criteria for primitive versus derived types, and (to me) one immediately presents itself. Derived types are types composed of some other LLVM type(s) and additional information. Primitive types are not decomposable into any other LLVM type. Thus, pointers, arrays, vectors, and structures are derived from other LLVM types, while integers are primitive types and just happen to be parameterized on a specific bitwidth.

If others agree, we should update both code and documentation to consistently document this distinction. Doing so would also require auditing all uses of the primitive information. I suspect there may be a few other places that should be clarified besides the one Joey points out.

CC-ing Chris as this is really his call.
-Chandler

Originally, the distinguishing feature of "primitive" types was that they were enumerable and not parameterized on anything.

Right.

Then we moved to arbitrary bit-width integers types to generalize things significantly (the right move IMO).

Right.

Thus, integers were no longer technically primitive types, and their categorization in code has changed to reflect this.

Right.

But that doesn't make *any sense*. The documentation for primitive types also is still written in a way that would include integers.

What purpose does the notion of "primitive" types serve anymore? Why don't we just abolish that from the lexicon and from the code?

-Chris

What purpose does the notion of "primitive" types serve anymore? Why don't we just abolish that from the lexicon and from the code?

Hi Chris,

The attached patch removes it from Type.h and updates the last users.
Is that what you were looking for?

Cheers,
Rafael

t.patch (6.6 KB)

Yep, LGTM. It would also be nice to remove the mention from LangRef.

-Chris

I updated the LangRef and committed as r196661.

Cheers,
Rafael

Thanks Rafael!

-Chris