00001 //===-- codegen/DomainView.h ---------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 #ifndef COMMA_CODEGEN_DOMAINVIEW_HDR_GUARD 00010 #define COMMA_CODEGEN_DOMAINVIEW_HDR_GUARD 00011 00012 #include "comma/codegen/CodeGen.h" 00013 #include "llvm/Support/IRBuilder.h" 00014 00015 namespace comma { 00016 00017 class CommaRT; 00018 00019 class DomainView { 00020 00021 public: 00022 DomainView(CommaRT &CRT); 00023 00024 void init(); 00025 00026 enum FieldId { 00027 Instance, 00028 Index 00029 }; 00030 00032 const std::string &getTypeName() const { return theTypeName; } 00033 00035 const llvm::StructType *getType() const; 00036 00038 const llvm::PointerType *getPointerTypeTo() const; 00039 00041 llvm::Value *loadInstance(llvm::IRBuilder<> &builder, 00042 llvm::Value *DView) const; 00043 00045 llvm::Value *loadIndex(llvm::IRBuilder<> &builder, llvm::Value *View) const; 00046 00049 llvm::Value *downcast(llvm::IRBuilder<> &builder, 00050 llvm::Value *view, 00051 unsigned sigIndex) const; 00052 00053 template <FieldId F> 00054 struct FieldIdTraits { 00055 typedef const llvm::PointerType FieldType; 00056 }; 00057 00058 template <FieldId F> 00059 typename FieldIdTraits<F>::FieldType *getFieldType() const; 00060 00061 private: 00062 CommaRT &CRT; 00063 CodeGen &CG; 00064 const llvm::TargetData &TD; 00065 00067 static const std::string theTypeName; 00068 00070 llvm::PATypeHolder theType; 00071 }; 00072 00073 00074 //===----------------------------------------------------------------------===// 00075 // DomainView::FieldIdTraits specializations for the various fields within a 00076 // domain_view. 00077 00078 template <> 00079 struct DomainView::FieldIdTraits<DomainView::Index> { 00080 typedef const llvm::IntegerType FieldType; 00081 }; 00082 00083 //===----------------------------------------------------------------------===// 00084 // DomainView::getFieldType specializations for each field in a domain_view. 00085 00086 template <> inline 00087 DomainView::FieldIdTraits<DomainView::Instance>::FieldType * 00088 DomainView::getFieldType<DomainView::Instance>() const { 00089 typedef DomainView::FieldIdTraits<DomainView::Instance>::FieldType FTy; 00090 return llvm::cast<FTy>(getType()->getElementType(Instance)); 00091 } 00092 00093 template <> inline 00094 DomainView::FieldIdTraits<DomainView::Index>::FieldType * 00095 DomainView::getFieldType<DomainView::Index>() const { 00096 typedef DomainView::FieldIdTraits<DomainView::Index>::FieldType FTy; 00097 return llvm::cast<FTy>(getType()->getElementType(Index)); 00098 } 00099 00100 } // end comma namespace. 00101 00102 #endif