[lang][codegen] added basic attribute support
This commit is contained in:
@@ -19,10 +19,6 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
# Gather headers for cmake-based IDEs
|
||||
file( GLOB_RECURSE ALL_SRC *.cpp *.hpp *.h *.py CMakeLists*)
|
||||
add_custom_target( ALL SOURCES ${ALL_SRC} )
|
||||
|
||||
# Compiler flags
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS} -std=c++11")
|
||||
|
@@ -667,7 +667,7 @@ public:
|
||||
void SetOffset(int offset) { offset_ = offset; }
|
||||
Declaration* Decl() { return decl_; }
|
||||
void SetDecl(Declaration* decl) { decl_ = decl; }
|
||||
|
||||
const AttrList& GetAttrList() const { return attrList_; }
|
||||
unsigned char BitFieldBegin() const { return bitFieldBegin_; }
|
||||
unsigned char BitFieldEnd() const { return bitFieldBegin_ + bitFieldWidth_; }
|
||||
unsigned char BitFieldWidth() const { return bitFieldWidth_; }
|
||||
@@ -723,7 +723,7 @@ private:
|
||||
bool anonymous_;
|
||||
long id_ {0};
|
||||
|
||||
ASTNode::AttrList attrList_;
|
||||
AttrList attrList_;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -15,6 +15,7 @@ class module;
|
||||
class type;
|
||||
class context;
|
||||
class builder;
|
||||
class attribute;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -32,7 +33,7 @@ using LocationList = std::vector<std::string>;
|
||||
using StaticInitList = std::vector<StaticInitializer>;
|
||||
|
||||
// Error
|
||||
inline void should_not_happen() { assert(false); }
|
||||
inline void should_not_happen() { throw std::runtime_error("should not happen"); }
|
||||
inline void error_not_implemented() { throw std::runtime_error("not implemented"); }
|
||||
|
||||
class Generator: public Visitor {
|
||||
@@ -81,6 +82,9 @@ public:
|
||||
void Gen(ir::module *mod);
|
||||
|
||||
protected:
|
||||
// Triton-IR attributes
|
||||
ir::attribute GenIRAttr(ASTNode::Attr attr);
|
||||
|
||||
// Triton-IR values
|
||||
ir::value* GenAssignOp(Expr* lvalue, ir::value* rhs);
|
||||
ir::value* GenBroadcastOp(ir::value* src, ir::type* dst_ty);
|
||||
|
@@ -354,6 +354,8 @@ void Generator::VisitFuncDef(FuncDef* funcDef) {
|
||||
for(Object* obj: type->Params()){
|
||||
std::string name = obj->Name();
|
||||
args[i]->set_name(name);
|
||||
for(ASTNode::Attr attr: obj->GetAttrList())
|
||||
fn->add_attr(i, GenIRAttr(attr));
|
||||
mod_->set_value(name, nullptr, args[i]);
|
||||
mod_->get_scope().types[name] = args[i]->get_type();
|
||||
i++;
|
||||
@@ -436,6 +438,28 @@ ir::value* Generator::GenCastOp(ir::value* src, ir::type* dst_ty) {
|
||||
return GenNumcastOp(GenBroadcastOp(src, dst_ty), dst_ty);
|
||||
}
|
||||
|
||||
// Triton-IR Attr
|
||||
ir::attribute Generator::GenIRAttr(ASTNode::Attr attr) {
|
||||
if(attr.name == "multiple_of") {
|
||||
VisitExpr(attr.vals[0]);
|
||||
auto cst = dynamic_cast<ir::constant_int*>(ret_);
|
||||
if(!cst) should_not_happen();
|
||||
return ir::attribute(ir::multiple_of, cst->get_value());
|
||||
}
|
||||
if(attr.name == "aligned") {
|
||||
VisitExpr(attr.vals[0]);
|
||||
auto cst = dynamic_cast<ir::constant_int*>(ret_);
|
||||
return ir::attribute(ir::aligned, cst->get_value());
|
||||
}
|
||||
if(attr.name == "noalias")
|
||||
return ir::attribute(ir::noalias);
|
||||
if(attr.name == "readonly")
|
||||
return ir::attribute(ir::readonly);
|
||||
if(attr.name == "writeonly")
|
||||
return ir::attribute(ir::writeonly);
|
||||
should_not_happen();
|
||||
}
|
||||
|
||||
// Triton-IR Types
|
||||
ir::type* Generator::GenIRType(::Type* type, ir::context& ctx) {
|
||||
if(auto T = type->ToVoid())
|
||||
|
Reference in New Issue
Block a user