1# The document describes a format of an intrinsics configuration file 2 3An intrinsics config is a YAML file consisting of the following main elements: 4 5- intrinsics_namespace 6- intrinsics 7 8(see [irtoc/intrinsics.yaml](../irtoc/intrinsics.yaml) as an example) 9 10## intrinsics_namespace 11 12C++ namespace used for intrinsics located in this file. 13 14Example: ```intrinsics_namespace: irtoc``` 15 16## intrinsics 17 18A sequence of configuration records (one per intrinsic). 19A record starts with ```- name: name_of_intrinsic``` and typically includes the following properties: 20 21 - [class_name](#class_name) 22 - [method_name](#method_name) 23 - [space](#space) 24 - [static](#static) 25 - [codegen_arch](#codegen_arch) 26 - [codegen_func](#codegen_func) 27 - [codegen_virt](#codegen_virt) 28 - [llvm_codegen_func](#llvm_codegen_func) 29 - [signature](#signature) 30 - [impl](#impl) 31 - [clear_flags](#clear_flags) 32 - [set_flags](#set_flags) 33 - [safe_intrinsic](#safe_intrinsic) 34 - [description](#description) 35 36### class_name 37 38A name of a class to which a corresponding method will be attributed to. 39 40Example: ```class_name: Irtoc``` 41 42### method_name 43 44A name of a method. Usually both [class_name](#class_name) and [method_name](#method_name) are used 45to form ```class_name::method_name```, which corresponds to a particular plugin (language) implementation 46(e.g. ArkTS plugin: ```std.math.ETSGLOBAL::sin```). 47 48In case of Irtoc intrinsics [method_name](#method_name) should be empty. 49 50Example: ```method_name: sin``` 51 52### space 53 54This property used to group intrinsics and control which intrinsics are loaded during startup. 55By default only ```core``` space is loaded. 56 57Example: ```space: core``` 58 59### static 60 61If it is set to ```true```, then there will be no implicit ```this``` argument passed to the intrinsic. 62By default it is ```false```. 63 64### codegen_func 65 66A name of a codegen method emitting a corresponding FastPath call (e.g. Irtoc implementation) 67or encoding the intrinsic explicitly by means of an arch-specific encoder. 68The method declaration is autogenerated, but you have to provide its definition (implementation). 69Depending on specified [space](#space) (and [class_name](#class_name) in some situations) 70a method definition should be placed into the corresponding plugin-specific codegen file, e.g.: 71 72```space: core``` - [compiler/optimizer/code_generator/codegen.cpp](../compiler/optimizer/code_generator/codegen.cpp) 73```space: core``` and ```class_name: Irtoc``` - [irtoc/backend/compiler/codegen_fastpath.cpp](../irtoc/backend/compiler/codegen_fastpath.cpp) 74```space: ets``` - [plugins/ets/compiler/codegen_intrinsics_ets.cpp](../plugins/ets/compiler/codegen_intrinsics_ets.cpp) 75 76Example: ```codegen_func: EmitSlowPathEntryIntrinsic``` 77 78### codegen_virt 79 80If it is set to ```true```, then the method will be declared as ```virtual```. 81This allows overriding the method in classes inherited from ```Codegen``` (e.g. ```CodegenFastPath```). 82 83By default it is ```false```. 84 85Note, that this property has an effect iff [codegen_func](#codegen_func) is specified. 86 87### codegen_arch 88 89A list of supported target architectures. 90 91Example: ```codegen_arch: [amd64, arm64, arm32]``` 92 93Note, that this property has an effect iff [codegen_func](#codegen_func) is specified. 94 95### llvm_codegen_func 96 97A name of LLVMIrConstructor method lowering the intrinsic to a corresponding LLVM IR 98(see [libllvmbackend/lowering/llvm_ir_constructor.cpp](../libllvmbackend/lowering/llvm_ir_constructor.cpp)) 99 100Example: ```llvm_codegen_func: EmitSlowPathEntry``` 101 102### signature 103 104This property represents method signature, which consists of the following entries: 105- ```ret:``` - method return type 106- ```args:``` - method argument types 107 108Example: 109``` 110signature: 111 ret: void* 112 args: [ u16, u16* ] 113``` 114 115For a list of possible type values see ```get_type_for_cpp()``` in [irtoc/lang/instructions.rb](../irtoc/lang/instructions.rb) 116Note that currently Irtoc intrinsics' signatures are not checked and used for code generation, 117but it is recommended to provide a correct one (for reference). 118 119### impl 120 121A full name of a corresponging C++ function implementing the intrinsic. 122 123Example: ```ark::ets::intrinsics::StdCoreDoubleIsFinite``` 124 125### set_flags 126 127A list of flags, which will be explicitly set for the intrinsic. 128Possible flag values and their meaning are listed in [compiler/optimize/ir/instructions.yaml](../compiler/optimize/ir/instructions.yaml) 129 130Example: ```set_flags: [require_state, can_throw, heap_inv]``` 131 132See ```opcode: Intrinsic``` in [compiler/optimizer/ir/instructions.yaml](../compiler/optimizer/ir/instructions.yaml) for a list of flags, 133which are set by default. 134 135### clear_flags 136 137A list of flags, which will be explicitly cleared for the intrinsic. 138Possible flag values and their meaning are listed in [compiler/optimize/ir/instructions.yaml](../compiler/optimize/ir/instructions.yaml) 139 140Example: ```clear_flags: [require_state, can_throw, heap_inv]``` 141 142### safe_intrinsic 143 144If it is set to ```true```, then the following *unsafe* flags will be cleared: 145```no_dce, no_hoist, no_cse, barrier, require_state, runtime_call, heap_inv, can_throw``` 146 147*Unsafe* means that an intrinsic may violate the conditions, which are necessary 148to correctly perform some compiler optimizing transformations. 149 150### description 151 152It is just a description. 153