-
Notifications
You must be signed in to change notification settings - Fork 28
Adding a new intrinsic function
Jeff Bush edited this page Sep 29, 2015
·
3 revisions
Adding a new intrinsic/built-in function that is accessible from C/C++ requires four steps:
-
Add a definition for the function to NyuziToolchain/tools/clang/include/clang/Basic/BuiltinsNyuzi.def, for example:
BUILTIN(__builtin_nyuzi_read_control_reg, "ii", "n")
-
Open NyuziToolchain/tools/clang/lib/CodeGen/CGBuiltin.cpp and look at the function CodeGenFunction::EmitNyuziBuiltinExpr. Add an entry to the switch statement:
switch (BuiltinID) { case Nyuzi::BI__builtin_nyuzi_read_control_reg: F = CGM.getIntrinsic(Intrinsic::nyuzi_read_control_reg); break;
-
Edit NyuziToolchain/include/llvm/IR/IntrinsicsNyuzi.td and add a definition of the intrinsic to the LLVM backend
def int_nyuzi_read_control_reg : Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [], "llvm.nyuzi.__builtin_nyuzi_read_control_reg">;
-
Add a pattern to the instruction table NyuziToolchain/lib/Target/Nyuzi/NyuziInstrInfo.td
def READ_CONTROL_REG : FormatMInst< (outs GPR32:$dest), (ins i32imm:$cr), "getcr $dest, $cr", [(set i32:$dest, (int_nyuzi_read_control_reg imm:$cr))], ...