NaplesPUCallingConv.td

From NaplesPU Documentation
Revision as of 11:21, 28 September 2017 by Catello (talk | contribs)
Jump to: navigation, search

This file describes the conventions to use when a function is called, such as how to pass the arguments and how to return the function results.

Arguments passing

The nu+ architecture natively supports 32-bit scalar integers (i32), 64-bit scalar integers (i64), 32-bit vector integers (v16i32), 64-bit vector integers (v8i64), 32-bit scalar floating-point (f32), 64-bit scalar floating-point (f64), 32-bit vector floating-point (v16f32) and 64-bit vector floating-point (v8f32).

The convention is to use the first eight register to pass arguments of the types listed above. For example, given the function foo

void foo (int a, long long int b, vec16f32 c);

the variable a will be passed using the register s0, b using s2_s3 and c will be stored in v0. If there are no registers available the variables will be passed using the stack.

The non-native data-types are passed the same way as the native ones, however they are first extended to the nearest native data-type then they are passed using the convention discussed before.

The description is done defining the class CC_NuPlus32 and using the tablegen classes contained in "compiler/include/llvm/Target/TargetCallingConv.td". The most used are CCIfType, CCPromoteToType, CCAssignToReg, CCAssignToStack and CCIfNotVarArg.

The following code shows how the conventions for the i8, i16, i32 and f32 are described.

...
CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
...
CCIfNotVarArg<CCIfType<[i32, f32], CCAssignToReg<[S0, S1, S2, S3, S4, S5, S6, S7]>>>,
...
CCIfType<[i32, f32], CCAssignToStack<4, 4>>,
...

Note that the registers in "CCAssignToReg" are the same defined in NuPlusRegisterInfo.td.

Results returning

The results of a function are passed using the first five registers. Like the arguments passed, the results must be of a native data-type, the non-native ones are first converted to the nearest native data-type.

The conventions are described defining the class RetCC_NuPlus32 and using the tablegen classes contained in "compiler/include/llvm/Target/TargetCallingConv.td", similarly as they are used in Arguments passing.