2018-12-31 22:47:31 -05:00
|
|
|
#ifndef TDL_INCLUDE_IR_INSTRUCTIONS_H
|
|
|
|
#define TDL_INCLUDE_IR_INSTRUCTIONS_H
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
#include <vector>
|
2018-12-31 22:47:31 -05:00
|
|
|
#include "value.h"
|
2019-01-02 01:06:43 -05:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2018-12-31 22:47:31 -05:00
|
|
|
|
|
|
|
namespace tdl{
|
|
|
|
namespace ir{
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
class basic_block;
|
2018-12-31 22:47:31 -05:00
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// instruction classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class instruction: public user{
|
2019-01-02 14:37:14 -05:00
|
|
|
protected:
|
2019-01-02 01:06:43 -05:00
|
|
|
// constructors
|
2019-01-02 14:37:14 -05:00
|
|
|
instruction(type *ty, unsigned num_ops, instruction *next = nullptr);
|
|
|
|
|
|
|
|
public:
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
// parent
|
|
|
|
const basic_block *get_parent() const { return parent_;}
|
|
|
|
basic_block *get_parent() { return parent_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
basic_block *parent_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// phi_node classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-12-31 22:47:31 -05:00
|
|
|
class phi_node: public instruction{
|
2019-01-02 01:06:43 -05:00
|
|
|
private:
|
|
|
|
phi_node(type *ty, unsigned num_reserved);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void add_incoming(value *x, basic_block *bb);
|
2018-12-31 22:47:31 -05:00
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
// Factory methods
|
|
|
|
static phi_node* create(type *ty, unsigned num_reserved);
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned num_reserved_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// binary_operator classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-12-31 22:47:31 -05:00
|
|
|
class binary_operator: public instruction{
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
typedef llvm::BinaryOperator::BinaryOps op_t;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Constructors
|
|
|
|
binary_operator(op_t op, value *lhs, value *rhs, type *ty, const std::string &name, instruction *next);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Get operand
|
|
|
|
op_t get_op() const { return op_; }
|
|
|
|
|
|
|
|
// Factory methods
|
|
|
|
static binary_operator *create(op_t op, value *lhs, value *rhs,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static binary_operator *create_fneg(value *arg, const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static binary_operator *create_neg(value *arg, const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static binary_operator *create_not(value *arg, const std::string &name = "", instruction *next = nullptr);
|
2018-12-31 22:47:31 -05:00
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
op_t op_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// cmp_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class cmp_inst: public instruction{
|
|
|
|
public:
|
|
|
|
typedef llvm::CmpInst::Predicate pred_t;
|
2019-01-02 14:37:14 -05:00
|
|
|
using pcmp = llvm::CmpInst;
|
|
|
|
|
|
|
|
private:
|
|
|
|
type* make_cmp_result_type(type *ty);
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
protected:
|
2019-01-02 14:37:14 -05:00
|
|
|
cmp_inst(pred_t pred, value *lhs, value *rhs, const std::string &name, instruction *next);
|
|
|
|
|
|
|
|
static bool is_fp_predicate(pred_t pred);
|
|
|
|
static bool is_int_predicate(pred_t pred);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
pred_t pred_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class icmp_inst: public cmp_inst{
|
2019-01-02 14:37:14 -05:00
|
|
|
using cmp_inst::cmp_inst;
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
static icmp_inst* create(pred_t pred, value *lhs, value *rhs,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
class fcmp_inst: public cmp_inst{
|
2019-01-02 14:37:14 -05:00
|
|
|
using cmp_inst::cmp_inst;
|
|
|
|
|
2019-01-02 01:06:43 -05:00
|
|
|
public:
|
|
|
|
static fcmp_inst* create(pred_t pred, value *lhs, value *rhs,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// cast_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class cast_inst: public instruction{
|
|
|
|
public:
|
|
|
|
typedef llvm::CastInst::CastOps op_t;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Constructors
|
|
|
|
cast_inst(op_t op, value *arg, type *ty, const std::string &name, instruction *next);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Factory methods
|
|
|
|
static cast_inst *create(op_t op, value *arg, type *ty,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static cast_inst *create_integer_cast(value *arg, type *ty, bool is_signed,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
op_t op_;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// terminator_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class terminator_inst: public instruction{
|
|
|
|
public:
|
|
|
|
};
|
|
|
|
|
|
|
|
class return_inst: public instruction{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// branch_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class branch_inst: public instruction{
|
|
|
|
public:
|
|
|
|
static branch_inst* create(basic_block *dest,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
static branch_inst* create(value *cond, basic_block *if_dest, basic_block *else_dest,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// getelementptr_inst classes
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class getelementptr_inst: public instruction{
|
|
|
|
public:
|
|
|
|
static getelementptr_inst* create(value *ptr, const std::vector<value*> &idx,
|
|
|
|
const std::string &name = "", instruction *next = nullptr);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-12-31 22:47:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|