diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-22 01:03:57 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-22 01:03:57 -0600 |
commit | efda1444166c8d4f8dd7d7b085868f1596b3b9fb (patch) | |
tree | 6ea0d275467b65c15956af7913a70991a3a957e3 | |
parent | bc796e8d5a10352941d606df516f976b15fb32fc (diff) | |
download | chill-efda1444166c8d4f8dd7d7b085868f1596b3b9fb.tar.gz chill-efda1444166c8d4f8dd7d7b085868f1596b3b9fb.tar.bz2 chill-efda1444166c8d4f8dd7d7b085868f1596b3b9fb.zip |
more clang hack
-rw-r--r-- | include/chill_ast.hh | 4 | ||||
-rwxr-xr-x | include/ir_clang.hh | 11 | ||||
-rw-r--r-- | include/ir_code.hh | 136 | ||||
-rw-r--r-- | src/chill_ast.cc | 4 | ||||
-rw-r--r-- | src/chillmodule.cc | 1 | ||||
-rwxr-xr-x | src/ir_clang.cc | 13 |
6 files changed, 121 insertions, 48 deletions
diff --git a/include/chill_ast.hh b/include/chill_ast.hh index 0803254..a0cfe2d 100644 --- a/include/chill_ast.hh +++ b/include/chill_ast.hh @@ -726,8 +726,8 @@ public: //TODO hide data, set/get type and alias chillAST_TypedefDecl(); - chillAST_TypedefDecl(char *t, char *nt, chillAST_node *p); - chillAST_TypedefDecl(char *t, char *nt, char *a, chillAST_node *par); + chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *p); + chillAST_TypedefDecl(char *t, const char *nt, char *a, chillAST_node *par); const char* getUnderlyingType() { fprintf(stderr, "TypedefDecl getUnderLyingType()\n"); return underlyingtype; }; //virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; }; // ?? diff --git a/include/ir_clang.hh b/include/ir_clang.hh index 7c3d451..50fb5dd 100755 --- a/include/ir_clang.hh +++ b/include/ir_clang.hh @@ -31,10 +31,7 @@ #include "chill_ast.hh" -// using namespace clang; // NEVER EVER do this in a header file -// using namespace clang::driver; // NEVER EVER do this in a header file - -extern std::vector<chillAST_VarDecl *> VariableDeclarations; // a global. TODO +extern std::vector<chillAST_VarDecl *> VariableDeclarations; // a global. TODO typedef llvm::SmallVector<clang::Stmt *, 16> StmtList; // TODO delete @@ -350,7 +347,7 @@ private: clang::DiagnosticOptions *diagnosticOptions; clang::TextDiagnosticPrinter *pTextDiagnosticPrinter; - clang::DiagnosticIDs *diagID ; + llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID ; clang::DiagnosticsEngine *diagnosticsEngine; clang::CompilerInstance *Clang; clang::Preprocessor *preprocessor; @@ -365,7 +362,7 @@ private: clang::LangOptions *languageOptions; clang::HeaderSearchOptions *headerSearchOptions; //clang::HeaderSearch *headerSearch; - clang::TargetOptions *targetOptions; + std::shared_ptr<clang::TargetOptions> targetOptions; clang::TargetInfo *pTargetInfo; clang::PreprocessorOptions *preprocessorOptions; clang::FrontendOptions *frontendOptions; @@ -449,7 +446,7 @@ public: clang::ASTContext *getASTContext() { return astContext_; } ; clang::SourceManager *getASTSourceManager() { return sourceManager; } ; - IR_clangCode(const char *filename, char *proc_name); + IR_clangCode(const char *filename, const char *proc_name); ~IR_clangCode(); IR_ScalarSymbol *CreateScalarSymbol(const IR_Symbol *sym, int i); diff --git a/include/ir_code.hh b/include/ir_code.hh index 0946610..850bcc3 100644 --- a/include/ir_code.hh +++ b/include/ir_code.hh @@ -280,54 +280,92 @@ public: // memory_type is for differentiating the location of where the new memory is allocated. // this is useful for processors with heterogeneous memory hierarchy. virtual IR_ScalarSymbol *CreateScalarSymbol(const IR_Symbol *sym, int memory_type) = 0; - virtual IR_ScalarSymbol *CreateScalarSymbol(IR_CONSTANT_TYPE type, int memory_type, std::string name="" ) =0; + virtual IR_ScalarSymbol *CreateScalarSymbol(IR_CONSTANT_TYPE type, int memory_type, std::string name="" ) { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outputRepr *> &size, int memory_type) = 0; virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *type, - std::vector<omega::CG_outputRepr *> &size_repr) =0; + std::vector<omega::CG_outputRepr *> &size_repr) { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual IR_PointerSymbol *CreatePointerSymbol(const IR_Symbol *sym, - std::vector<omega::CG_outputRepr *> &size_repr) =0; + std::vector<omega::CG_outputRepr *> &size_repr) { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual IR_PointerSymbol *CreatePointerSymbol(const IR_CONSTANT_TYPE type, std::vector<omega::CG_outputRepr *> &size_repr, - std::string name="") =0; + std::string name="") { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual IR_PointerSymbol *CreatePointerSymbol(omega::CG_outputRepr *type, - std::vector<omega::CG_outputRepr *> &size_repr) =0; + std::vector<omega::CG_outputRepr *> &size_repr) { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual IR_ScalarRef *CreateScalarRef(const IR_ScalarSymbol *sym) = 0; virtual IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index) = 0; virtual omega::CG_outputRepr* CreateArrayRefRepr(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index) { - //IR_ArrayRef *AR = CreateArrayRef(sym, index); - //return new omega::CG_outputRepr(AR); - fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); return NULL; } virtual IR_PointerArrayRef *CreatePointerArrayRef( IR_PointerSymbol *sym, - std::vector<omega::CG_outputRepr *> &index) =0; + std::vector<omega::CG_outputRepr *> &index) { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual int ArrayIndexStartAt() {return 0;} - virtual void CreateDefineMacro(std::string s,std::string args, omega::CG_outputRepr *repr) = 0; - virtual void CreateDefineMacro(std::string s,std::string args, std::string repr) = 0; + virtual void CreateDefineMacro(std::string s,std::string args, omega::CG_outputRepr *repr) { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + } + virtual void CreateDefineMacro(std::string s,std::string args, std::string repr) { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + } virtual void CreateDefineMacro(std::string s, std::vector<std::string> args,omega::CG_outputRepr *repr) {}; // TODO make pure virtual - virtual omega::CG_outputRepr *CreateArrayType(IR_CONSTANT_TYPE type, omega::CG_outputRepr* size)=0; - virtual omega::CG_outputRepr *CreatePointerType(IR_CONSTANT_TYPE type)=0; - virtual omega::CG_outputRepr *CreatePointerType(omega::CG_outputRepr *type)=0; - virtual omega::CG_outputRepr *CreateScalarType(IR_CONSTANT_TYPE type)=0; + virtual omega::CG_outputRepr *CreateArrayType(IR_CONSTANT_TYPE type, omega::CG_outputRepr* size){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual omega::CG_outputRepr *CreatePointerType(IR_CONSTANT_TYPE type){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual omega::CG_outputRepr *CreatePointerType(omega::CG_outputRepr *type){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual omega::CG_outputRepr *CreateScalarType(IR_CONSTANT_TYPE type){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } // Array references should be returned in their accessing order. // e.g. s1: A[i] = A[i-1] // s2: B[C[i]] = D[i] + E[i] // return A[i-1], A[i], D[i], E[i], C[i], B[C[i]] in this order. virtual std::vector<IR_ArrayRef *> FindArrayRef(const omega::CG_outputRepr *repr) const = 0; - virtual std::vector<IR_PointerArrayRef *> FindPointerArrayRef(const omega::CG_outputRepr *repr) const = 0 ; + virtual std::vector<IR_PointerArrayRef *> FindPointerArrayRef(const omega::CG_outputRepr *repr) const{ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return std::vector<IR_PointerArrayRef *>(); + } virtual std::vector<IR_ScalarRef *> FindScalarRef(const omega::CG_outputRepr *repr) const = 0; - virtual bool parent_is_array(IR_ArrayRef *a)=0; + virtual bool parent_is_array(IR_ArrayRef *a){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return false; + } // If there is no sub structure interesting inside the block, return empty, // so we know when to stop looking inside. @@ -338,7 +376,10 @@ public: virtual IR_Block *MergeNeighboringControlStructures(const std::vector<IR_Control *> &controls) const = 0; virtual IR_Block *GetCode() const = 0; - virtual IR_Control *GetCode(omega::CG_outputRepr *code) const = 0; + virtual IR_Control *GetCode(omega::CG_outputRepr *code) const { + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual void ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) = 0; virtual void ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) = 0; @@ -349,22 +390,57 @@ public: // Manu:: Added functions required for reduction operation // virtual omega::CG_outputRepr * FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) = 0; - virtual bool FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) = 0; - virtual void printStmt(const omega::CG_outputRepr *repr) = 0; - virtual int getStmtType(const omega::CG_outputRepr *repr) = 0; - virtual IR_OPERATION_TYPE getReductionOp(const omega::CG_outputRepr *repr) = 0; - virtual IR_Control * FromForStmt(const omega::CG_outputRepr *repr) = 0; + virtual bool FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual void printStmt(const omega::CG_outputRepr *repr){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + } + virtual int getStmtType(const omega::CG_outputRepr *repr){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return 0; + } + virtual IR_OPERATION_TYPE getReductionOp(const omega::CG_outputRepr *repr){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return IR_OP_MINUS; + } + virtual IR_Control * FromForStmt(const omega::CG_outputRepr *repr){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } // Manu:: Added functions for scalar expansion - virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *size, const IR_Symbol *sym) = 0; - virtual bool ReplaceRHSExpression(omega::CG_outputRepr *code, IR_Ref *ref) = 0; - virtual omega::CG_outputRepr * GetRHSExpression(omega::CG_outputRepr *code) = 0; - virtual omega::CG_outputRepr * GetLHSExpression(omega::CG_outputRepr *code) = 0; + virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *size, const IR_Symbol *sym){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual bool ReplaceRHSExpression(omega::CG_outputRepr *code, IR_Ref *ref){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual omega::CG_outputRepr * GetRHSExpression(omega::CG_outputRepr *code){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual omega::CG_outputRepr * GetLHSExpression(omega::CG_outputRepr *code){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual omega::CG_outputRepr *CreateMalloc(const IR_CONSTANT_TYPE type, std::string lhs, - omega::CG_outputRepr * size_repr)=0; + omega::CG_outputRepr * size_repr){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } virtual omega::CG_outputRepr *CreateMalloc(omega::CG_outputRepr *type, std::string variable, - omega::CG_outputRepr * size_repr)=0; - virtual omega::CG_outputRepr *CreateFree(omega::CG_outputRepr * exp)=0; + omega::CG_outputRepr * size_repr){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } + virtual omega::CG_outputRepr *CreateFree(omega::CG_outputRepr * exp){ + fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n"); + return NULL; + } //void Dump() { ocg_->Dump(); }; //--------------------------------------------------------------------------- diff --git a/src/chill_ast.cc b/src/chill_ast.cc index 93afd97..978e303 100644 --- a/src/chill_ast.cc +++ b/src/chill_ast.cc @@ -603,7 +603,7 @@ chillAST_TypedefDecl::chillAST_TypedefDecl() { }; -chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, char *nt, chillAST_node *par) { +chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *par) { //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s, newtype %s )\n", t, nt); underlyingtype = strdup(t); newtype = strdup(nt); @@ -619,7 +619,7 @@ chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, char *nt, chillAST_node *par }; -chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, char *a, char *p, chillAST_node *par) { +chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chillAST_node *par) { underlyingtype = strdup(t); //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s )\n", underlyingtype); newtype = strdup(a); // the new named type ?? diff --git a/src/chillmodule.cc b/src/chillmodule.cc index 291cb51..fa6e001 100644 --- a/src/chillmodule.cc +++ b/src/chillmodule.cc @@ -80,6 +80,7 @@ static void init_loop(int loop_num_start, int loop_num_end) { } else { if (ir_code == NULL) { + ir_code = new IR_clangCode(source_filename.c_str(),procedure_name.c_str()); IR_Block *block = ir_code->GetCode(); ir_controls = ir_code->FindOneLevelControlStructure(block); for (int i = 0; i < ir_controls.size(); i++) { diff --git a/src/ir_clang.cc b/src/ir_clang.cc index ba11ac5..0157436 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -1973,8 +1973,7 @@ aClangCompiler::aClangCompiler( char *filename ) { pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter(llvm::errs(), diagnosticOptions); // private member of aClangCompiler //llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs()); - diagID = new clang::DiagnosticIDs(); // private member of IR_clangCode_Global_Init - + //clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); diagnosticsEngine = new clang::DiagnosticsEngine(diagID, diagnosticOptions, pTextDiagnosticPrinter); @@ -2004,10 +2003,10 @@ aClangCompiler::aClangCompiler( char *filename ) { //TargetInfo *TI = TargetInfo::CreateTargetInfo( Clang->getDiagnostics(), TO); // the above causes core dumps, because clang is stupid and frees the target multiple times, corrupting memory - const std::shared_ptr<clang::TargetOptions> to = std::make_shared<clang::TargetOptions>(); + targetOptions = std::make_shared<clang::TargetOptions>(); targetOptions->Triple = llvm::sys::getDefaultTargetTriple(); - TargetInfo *pti = TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),to); + TargetInfo *pti = TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),targetOptions); Clang->setTarget(pti); @@ -2225,7 +2224,7 @@ IR_clangCode_Global_Init::~IR_clangCode_Global_Init() // Class: IR_clangCode // ---------------------------------------------------------------------------- -IR_clangCode::IR_clangCode(const char *fname, char *proc_name): IR_Code() { +IR_clangCode::IR_clangCode(const char *fname, const char *proc_name): IR_Code() { fprintf(stderr, "\nIR_xxxxCode::IR_xxxxCode()\n\n"); //fprintf(stderr, "IR_clangCode::IR_clangCode( filename %s, procedure %s )\n", filename, proc_name); @@ -2234,7 +2233,7 @@ IR_clangCode::IR_clangCode(const char *fname, char *proc_name): IR_Code() { int argc = 2; char *argv[2]; - argv[0] = "chill"; + argv[0] = strdup("chill"); argv[1] = strdup(filename); // use clang to parse the input file ? (or is that already done?) @@ -2253,7 +2252,7 @@ IR_clangCode::IR_clangCode(const char *fname, char *proc_name): IR_Code() { pInstance->setCurrentFunction( NULL ); // we have no function AST yet entire_file_AST = Clang->entire_file_AST; // ugly that same name, different classes - chillAST_FunctionDecl *localFD = Clang->findprocedurebyname( proc_name ); // stored locally + chillAST_FunctionDecl *localFD = Clang->findprocedurebyname( strdup(proc_name) ); // stored locally //fprintf(stderr, "back from findprocedurebyname( %s )\n", proc_name ); //localFD->print(); |