sys/logging.hpp
sys/default_path.cpp
sys/default_path.hpp
+ ir/ir_context.cpp
+ ir/ir_context.hpp
ir/ir_unit.cpp
ir/ir_unit.hpp
ir/ir_constant.cpp
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+#include "ir_context.hpp"
+#include "ir_unit.hpp"
+
+namespace gbe
+{
+ Context::Context(Unit &unit) : unit(unit), fn(NULL), bb(NULL) {}
+ void Context::startFunction(const std::string &name) {
+ Function *fn = unit.newFunction(name);
+ if (UNLIKELY(fn == NULL))
+ throw std::exception("Function " + name " already defined");
+ fnStack.push_back(fn);
+ }
+} /* namespace gbe */
+
#ifndef __GBE_IR_CONTEXT_HPP__
#define __GBE_IR_CONTEXT_HPP__
+#include "ir_instruction.hpp"
+#include "ir_function.hpp"
+#include "ir_register.hpp"
+#include "sys/vector.hpp"
+
namespace gbe
{
+ // We compile a unit
+ class Unit;
+
/*! A context allows an easy creation of the functions (instruction stream and
* the set of immediates and registers needed for it) and constant arrays
*/
class Context
{
-
+ public:
+ /*! Create a new context for this unit */
+ Context(Unit &unit);
+ /*! Create a new function "name" */
+ void startFunction(const std::string &name);
+ /*! Close the function */
+ void endFunction(void);
+ /*! Create a new register for the given type */
+ RegisterIndex reg(Register::Family type);
+ /*! Append a new input register for the function */
+ void input(RegisterIndex reg);
+ /*! Append a new output register for the function */
+ void output(RegisterIndex reg);
+ /*! Append a new tuple */
+ template <typename... Args>
+ INLINE TupleIndex tuple(Args...args) {
+ if (UNLIKELY(fn == NULL))
+ throw std::exception("Tuple not defined in a function");
+ fn->file.append(args...);
+ }
+ private:
+ Unit &unit; //!< A unit is associated to a contect
+ Function *fn; //!< Current function we are processing
+ Function::BasicBlock *bb; //!< Current basic block we are filling
+ vector<Function*> fnStack;//!< Stack of functions still to finish
};
} /* namespace gbe */
namespace gbe
{
Function::Function(void) {}
+ Function::~Function(void) {
+ for (auto it = bb.begin(); it != bb.end(); ++it) GBE_DELETE(*it);
+ }
} /* namespace gbe */
public:
/*! Create an empty function */
Function(void);
+ /*! Release everything *including* the basic block pointers */
+ ~Function(void);
/*! Function basic blocks really belong to a function since:
* 1 - registers used in the basic blocks belongs to the function register
}
private:
- vector<uint16> input; //!< Input registers of the function
- vector<uint16> output; //!< Output registers of the function
- vector<Value> value; //!< All immediate values stored in the function
- vector<BasicBlock> insn; //!< All the basic blocks one after the others
- RegisterFile file; //!< All the registers used in the instructions
+ friend class Context; //!< Can freely modify a function
+ vector<RegisterIndex> input; //!< Input registers of the function
+ vector<RegisterIndex> output; //!< Output registers of the function
+ vector<BasicBlock*> labels; //!< Each label points to a basic block
+ vector<Value> value; //!< All immediate values stored in the function
+ vector<BasicBlock*> bb; //!< All the basic blocks one after the others
+ RegisterFile file; //!< All the registers used in the instructions
};
} /* namespace gbe */
}
// BRA
- Instruction bra(RegisterIndex dst, LabelIndex labelIndex) {
+ Instruction bra(LabelIndex labelIndex) {
internal::BranchInstruction insn(labelIndex);
return *reinterpret_cast<Instruction*>(&insn);
}
- Instruction bra(RegisterIndex dst, LabelIndex labelIndex, RegisterIndex pred) {
+ Instruction bra(LabelIndex labelIndex, RegisterIndex pred) {
internal::BranchInstruction insn(labelIndex, pred);
return *reinterpret_cast<Instruction*>(&insn);
}
return this->getSrc(fn, 0);
}
/*! Return the predicate register index (if predicated) */
- Register getPredicateIndex(const Function &fn) const {
+ RegisterIndex getPredicateIndex(const Function &fn) const {
assert(this->isPredicated() == true);
return this->getSrcIndex(fn, 0);
}
/// All emission functions
///////////////////////////////////////////////////////////////////////////
+ /*! mov.type dst src */
Instruction mov(Type type, RegisterIndex dst, RegisterIndex src);
+ /*! cos.type dst src */
Instruction cos(Type type, RegisterIndex dst, RegisterIndex src);
+ /*! sin.type dst src */
Instruction sin(Type type, RegisterIndex dst, RegisterIndex src);
+ /*! tan.type dst src */
Instruction tan(Type type, RegisterIndex dst, RegisterIndex src);
+ /*! log.type dst src */
Instruction log(Type type, RegisterIndex dst, RegisterIndex src);
+ /*! sqr.type dst src */
Instruction sqr(Type type, RegisterIndex dst, RegisterIndex src);
+ /*! rsq.type dst src */
Instruction rsq(Type type, RegisterIndex dst, RegisterIndex src);
+ /*! pow.type dst src0 src1 */
Instruction pow(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! mul.type dst src0 src1 */
Instruction mul(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! add.type dst src0 src1 */
Instruction add(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! sub.type dst src0 src1 */
Instruction sub(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! div.type dst src0 src1 */
Instruction div(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! rem.type dst src0 src1 */
Instruction rem(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! shl.type dst src0 src1 */
Instruction shl(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! shr.type dst src0 src1 */
Instruction shr(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! asr.type dst src0 src1 */
Instruction asr(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! bsf.type dst src0 src1 */
Instruction bsf(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! bsb.type dst src0 src1 */
Instruction bsb(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! or.type dst src0 src1 */
Instruction or$(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! xor.type dst src0 src1 */
Instruction xor$(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! and.type dst src0 src1 */
Instruction and$(Type type, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
+ /*! mad.type dst {src0, src1, src2} == src */
Instruction mad(Type type, RegisterIndex dst, TupleIndex src);
+ /*! cvt.{dstType <- srcType} dst src */
Instruction cvt(Type dstType, Type srcType, RegisterIndex dst, RegisterIndex src0, RegisterIndex src1);
- Instruction bra(RegisterIndex dst, LabelIndex labelIndex);
- Instruction bra(RegisterIndex dst, LabelIndex labelIndex, RegisterIndex pred);
+ /*! bra labelIndex */
+ Instruction bra(LabelIndex labelIndex);
+ /*! (pred) bra labelIndex */
+ Instruction bra(LabelIndex labelIndex, RegisterIndex pred);
+ /*! loadi.type dst value */
Instruction loadi(Type type, RegisterIndex dst, ValueIndex value);
+ /*! load.type.space {dst1,...,dst_valueNum} offset value */
Instruction load(Type type, TupleIndex dst, RegisterIndex offset, MemorySpace space, uint16 valueNum);
+ /*! store.type.space offset {src1,...,src_valueNum} value */
Instruction store(Type type, TupleIndex src, RegisterIndex offset, MemorySpace space, uint16 valueNum);
+ /*! fence.space */
Instruction fence(MemorySpace space);
+ /*! label labelIndex */
Instruction label(LabelIndex labelIndex);
} /* namespace gbe */
class Register
{
public:
+ /*! Register family */
+ enum Family : uint8 {
+ BOOL = 0,
+ BYTE = 1,
+ WORD = 2,
+ DWORD = 3,
+ QWORD = 4
+ };
/*! Build a register. All fields will be immutable */
- INLINE Register(uint8 type = 0) : type(type) {}
+ INLINE Register(Family family = DWORD) : family(family) {}
/*! Copy constructor */
- INLINE Register(const Register &other) : type(other.type) {}
+ INLINE Register(const Register &other) : family(other.family) {}
/*! Copy operator */
INLINE Register &operator= (const Register &other) {
- this->type = other.type;
+ this->family = other.family;
return *this;
}
/*! Nothing really happens here */
INLINE ~Register(void) {}
- /*! Register type */
- enum {
- BOOL = 0,
- BYTE = 1,
- WORD = 2,
- DWORD = 3,
- QWORD = 4
- };
- uint8 type;
+ Family family;
GBE_CLASS(Register);
};
{
public:
/*! Return the index of a newly allocated register register */
- INLINE RegisterIndex append(uint32 type) {
+ INLINE RegisterIndex append(Register::Family family) {
const uint32 index = regs.size();
- const Register reg(type);
+ const Register reg(family);
assert(index <= MAX_INDEX);
regs.push_back(reg);
return index;
template <typename First, typename... Rest>
INLINE TupleIndex appendTuple(First first, Rest... rest) {
const TupleIndex index = regTuples.size();
+ assert(first < regs.size());
regTuples.push_back(first);
appendTuple(rest...);
return index;
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+#ifndef __GBE_EXCEPTION_HPP__
+#define __GBE_EXCEPTION_HPP__
+
+#endif /* __GBE_EXCEPTION_HPP__ */
+