// http://llvm.org/docs/LangRef.html#fptoui-to-instr
// keywords: conversion; unary; instr

.type FPToUIInstruction <: symbol
.decl fptoui_instr(instr:FPToUIInstruction)

instr(v) :- fptoui_instr(v).

.decl fptoui_instr_from_operand(instr:FPToUIInstruction, val:Operand)
.decl fptoui_instr_to_type(instr:FPToUIInstruction, type:Type)


// Helper predicate

.decl fptoui_instr_from_type(instr:FPToUIInstruction, type:Type)

fptoui_instr_from_type(Instr, Type) :-
   fptoui_instr_from_operand(Instr, Operand),
   operand_has_type(Operand, Type).


//-------------------------------------------------------------------
// [Constraints]
//
// 1) The ‘fptoui‘ instr takes:
//      (i)  a value to cast, which must be a scalar or vector
//           floating point value,
//      (ii) and a type to cast it to, which must be an integer
//           type.
//
// 2) If the value to be casted is a vector floating point type:
//      (i)  the type must be a vector integer type,
//      (ii) with the same number of elements.
//-------------------------------------------------------------------

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   fptoui_instr(Instr),
   !fptoui_instr_from_operand(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   fptoui_instr(Instr),
   !fptoui_instr_to_type(Instr, _).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   fptoui_instr(Instr),
   fptoui_instr_to_type(Instr, Type),
   !instr_returns_type(Instr, Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   fptoui_instr(Instr),
   fptoui_instr_from_type(Instr, Type),
   !fp_type(Type),
   !fp_vector_type(Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   fptoui_instr(Instr),
   fptoui_instr_to_type(Instr, Type),
   !integer_type(Type),
   !integer_vector_type(Type).

schema_invalid_instr(Instr, __FILE__, __LINE__) :-
   schema_sanity(),
   fptoui_instr(Instr),
   fptoui_instr_from_type(Instr, FromType),
   fptoui_instr_to_type(Instr, ToType),
   !vector_compatible_types(FromType, ToType).
