llvm.org GIT mirror llvm / e149e99
OCaml parameter attribute bindings from PR2752. Incomplete, but better than nothing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71081 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 11 years ago
6 changed file(s) with 148 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
6161 let cold = 9
6262 let x86_stdcall = 64
6363 let x86_fastcall = 65
64 end
65
66 module Attribute = struct
67 type t =
68 | Zext
69 | Sext
70 | Noreturn
71 | Inreg
72 | Structret
73 | Nounwind
74 | Noalias
75 | Byval
76 | Nest
77 | Readnone
78 | Readonly
6479 end
6580
6681 module Icmp = struct
417432 let fold_right_functions f m init =
418433 fold_right_function_range f (function_end m) (At_start m) init
419434
420 (* TODO: param attrs *)
435 external add_function_attr : llvalue -> Attribute.t -> unit
436 = "llvm_add_function_attr"
437 external remove_function_attr : llvalue -> Attribute.t -> unit
438 = "llvm_remove_function_attr"
421439
422440 (*--... Operations on params ...............................................--*)
423441 external params : llvalue -> llvalue array = "llvm_params"
467485
468486 let fold_right_params f fn init =
469487 fold_right_param_range f init (param_end fn) (At_start fn)
488
489 external add_param_attr : llvalue -> Attribute.t -> unit
490 = "llvm_add_param_attr"
491 external remove_param_attr : llvalue -> Attribute.t -> unit
492 = "llvm_remove_param_attr"
493 external set_param_alignment : llvalue -> int -> unit
494 = "llvm_set_param_alignment"
470495
471496 (*--... Operations on basic blocks .........................................--*)
472497 external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue"
585610 = "llvm_instruction_call_conv"
586611 external set_instruction_call_conv: int -> llvalue -> unit
587612 = "llvm_set_instruction_call_conv"
613 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
614 = "llvm_add_instruction_param_attr"
615 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
616 = "llvm_remove_instruction_param_attr"
588617
589618 (*--... Operations on call instructions (only) .............................--*)
590619 external is_tail_call : llvalue -> bool = "llvm_is_tail_call"
108108 convention from C. *)
109109 val x86_fastcall : int (** [x86_fastcall] is the familiar fastcall calling
110110 convention from C. *)
111 end
112
113 module Attribute : sig
114 type t =
115 | Zext
116 | Sext
117 | Noreturn
118 | Inreg
119 | Structret
120 | Nounwind
121 | Noalias
122 | Byval
123 | Nest
124 | Readnone
125 | Readonly
111126 end
112127
113128 (** The predicate for an integer comparison ([icmp]) instruction.
930945 [gc]. See the method [llvm::Function::setGC]. *)
931946 external set_gc : string option -> llvalue -> unit = "llvm_set_gc"
932947
948 (** [add_function_attr f a] adds attribute [a] to the return type of function
949 [f]. *)
950 external add_function_attr : llvalue -> Attribute.t -> unit
951 = "llvm_add_function_attr"
952
953 (** [remove_function_attr f a] removes attribute [a] from the return type of
954 function [f]. *)
955 external remove_function_attr : llvalue -> Attribute.t -> unit
956 = "llvm_remove_function_attr"
933957
934958 (** {7 Operations on params} *)
935959
9831007 [b1,...,bN] are the parameters of function [fn]. Tail recursive. *)
9841008 val fold_right_params : (llvalue -> 'a -> 'a) -> llvalue -> 'a -> 'a
9851009
1010 (** [add_param p a] adds attribute [a] to parameter [p]. *)
1011 external add_param_attr : llvalue -> Attribute.t -> unit = "llvm_add_param_attr"
1012
1013 (** [remove_param_attr p a] removes attribute [a] from parameter [p]. *)
1014 external remove_param_attr : llvalue -> Attribute.t -> unit
1015 = "llvm_remove_param_attr"
1016
1017 (** [set_param_alignment p a] set the alignment of parameter [p] to [a]. *)
1018 external set_param_alignment : llvalue -> int -> unit
1019 = "llvm_set_param_alignment"
9861020
9871021 (** {7 Operations on basic blocks} *)
9881022
11251159 and [llvm::InvokeInst::setCallingConv]. *)
11261160 external set_instruction_call_conv: int -> llvalue -> unit
11271161 = "llvm_set_instruction_call_conv"
1162
1163 (** [add_instruction_param_attr ci i a] adds attribute [a] to the [i]th
1164 parameter of the call or invoke instruction [ci]. [i]=0 denotes the return
1165 value. *)
1166 external add_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1167 = "llvm_add_instruction_param_attr"
1168
1169 (** [remove_instruction_param_attr ci i a] removes attribute [a] from the
1170 [i]th parameter of the call or invoke instruction [ci]. [i]=0 denotes the
1171 return value. *)
1172 external remove_instruction_param_attr : llvalue -> int -> Attribute.t -> unit
1173 = "llvm_remove_instruction_param_attr"
11281174
11291175 (** {Operations on call instructions (only)} *)
11301176
664664 return Val_unit;
665665 }
666666
667 /* llvalue -> Attribute.t -> unit */
668 CAMLprim value llvm_add_function_attr(LLVMValueRef Arg, value PA) {
669 LLVMAddFunctionAttr(Arg, 1<
670 return Val_unit;
671 }
672
673 /* llvalue -> Attribute.t -> unit */
674 CAMLprim value llvm_remove_function_attr(LLVMValueRef Arg, value PA) {
675 LLVMRemoveFunctionAttr(Arg, 1<
676 return Val_unit;
677 }
667678 /*--... Operations on parameters ...........................................--*/
668679
669680 DEFINE_ITERATORS(param, Param, LLVMValueRef, LLVMValueRef, LLVMGetParamParent)
680691 return Params;
681692 }
682693
694 /* llvalue -> Attribute.t -> unit */
695 CAMLprim value llvm_add_param_attr(LLVMValueRef Arg, value PA) {
696 LLVMAddAttribute(Arg, 1<
697 return Val_unit;
698 }
699
700 /* llvalue -> Attribute.t -> unit */
701 CAMLprim value llvm_remove_param_attr(LLVMValueRef Arg, value PA) {
702 LLVMRemoveAttribute(Arg, 1<
703 return Val_unit;
704 }
705
706 /* llvalue -> int -> unit */
707 CAMLprim value llvm_set_param_alignment(LLVMValueRef Arg, value align) {
708 LLVMSetParamAlignment(Arg, Int_val(align));
709 return Val_unit;
710 }
711
683712 /*--... Operations on basic blocks .........................................--*/
684713
685714 DEFINE_ITERATORS(
729758 /* int -> llvalue -> unit */
730759 CAMLprim value llvm_set_instruction_call_conv(value CC, LLVMValueRef Inst) {
731760 LLVMSetInstructionCallConv(Inst, Int_val(CC));
761 return Val_unit;
762 }
763
764 /* llvalue -> int -> Attribute.t -> unit */
765 CAMLprim value llvm_add_instruction_param_attr(LLVMValueRef Instr,
766 value index,
767 value PA) {
768 LLVMAddInstrAttribute(Instr, Int_val(index), 1<
769 return Val_unit;
770 }
771
772 /* llvalue -> int -> Attribute.t -> unit */
773 CAMLprim value llvm_remove_instruction_param_attr(LLVMValueRef Instr,
774 value index,
775 value PA) {
776 LLVMRemoveInstrAttribute(Instr, Int_val(index), 1<
732777 return Val_unit;
733778 }
734779
503503 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
504504 const char *LLVMGetGC(LLVMValueRef Fn);
505505 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
506 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
507 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
506508
507509 /* Operations on parameters */
508510 unsigned LLVMCountParams(LLVMValueRef Fn);
775775 F->clearGC();
776776 }
777777
778 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
779 Function *Func = unwrap(Fn);
780 const AttrListPtr PAL = Func->getAttributes();
781 const AttrListPtr PALnew = PAL.addAttr(0, PA);
782 Func->setAttributes(PALnew);
783 }
784
785 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
786 Function *Func = unwrap(Fn);
787 const AttrListPtr PAL = Func->getAttributes();
788 const AttrListPtr PALnew = PAL.removeAttr(0, PA);
789 Func->setAttributes(PALnew);
790 }
791
778792 /*--.. Operations on parameters ............................................--*/
779793
780794 unsigned LLVMCountParams(LLVMValueRef FnRef) {
625625 let p2 = param f 1 in
626626 set_value_name "One" p1;
627627 set_value_name "Two" p2;
628
628 add_param_attr p1 Attribute.Sext;
629 add_param_attr p2 Attribute.Noalias;
630 remove_param_attr p2 Attribute.Noalias;
631 add_function_attr f Attribute.Nounwind;
632 add_function_attr f Attribute.Noreturn;
633 remove_function_attr f Attribute.Noreturn;
634
629635 insist (Before p1 = param_begin f);
630636 insist (Before p2 = param_succ p1);
631637 insist (At_end f = param_succ p2);
987993 insist (not (is_tail_call ci));
988994 set_tail_call true ci;
989995 insist (is_tail_call ci);
996 add_instruction_param_attr ci 0 Attribute.Nounwind;
997 add_instruction_param_attr ci 1 Attribute.Sext;
998 add_instruction_param_attr ci 2 Attribute.Noalias;
999 remove_instruction_param_attr ci 2 Attribute.Noalias;
9901000
9911001 let inst46 = build_icmp Icmp.Eq p1 p2 "Inst46" atentry in
9921002 ignore (build_select inst46 p1 p2 "Inst47" atentry);