From e3a78ad1504fcdc5668af5230634470bae3cfee4 Mon Sep 17 00:00:00 2001 From: Vsevolod Livinskiy Date: Fri, 13 Feb 2015 16:14:15 +0300 Subject: [PATCH] Tmp commit to save progress --- cbackend.cpp | 41 ++++++++++++++--------------- examples/intrinsics/knc.h | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/cbackend.cpp b/cbackend.cpp index f99c1bfb..1acf512c 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -392,7 +392,7 @@ namespace { // Output all vector constants so they can be accessed with single // vector loads printVectorConstants(F); - + printFunction(F); return false; } @@ -748,10 +748,11 @@ CWriter::printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty, bool isSigned, return Out << (isSigned?"":"u") << "int32_t " << NameSoFar; else if (NumBits <= 64) return Out << (isSigned?"":"u") << "int64_t "<< NameSoFar; - else { - assert(NumBits <= 128 && "Bit widths > 128 not implemented yet"); + else if (NumBits <= 128) return Out << (isSigned?"llvmInt128":"llvmUInt128") << " " << NameSoFar; - } + else + return Out << "iN<" << NumBits << "> " << NameSoFar; + } case llvm::Type::FloatTyID: return Out << "float " << NameSoFar; case llvm::Type::DoubleTyID: return Out << "double " << NameSoFar; @@ -793,8 +794,8 @@ CWriter::printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty, bool isSigned, suffix = "i64"; break; default: - llvm::report_fatal_error("Only integer types of size 8/16/32/64 are " - "supported by the C++ backend."); + suffix = "iN"; + break; } } @@ -1463,10 +1464,10 @@ void CWriter::printConstant(llvm::Constant *CPV, bool Static) { Out << (CI->getZExtValue() ? '1' : '0'); else if (Ty == llvm::Type::getInt32Ty(CPV->getContext())) Out << CI->getZExtValue() << 'u'; - else if (Ty->getPrimitiveSizeInBits() > 32) { - assert(Ty->getPrimitiveSizeInBits() == 64); + else if (Ty == llvm::Type::getInt64Ty(CPV->getContext())) Out << CI->getZExtValue() << "ull"; - } + else if (Ty->getPrimitiveSizeInBits() > 64) + llvm::dyn_cast(CPV)->printAsOperand(Out, false); else { Out << "(("; printSimpleType(Out, Ty, false) << ')'; @@ -1874,22 +1875,11 @@ std::string CWriter::GetValueName(const llvm::Value *Operand) { /// writeInstComputationInline - Emit the computation for the specified /// instruction inline, with no destination provided. void CWriter::writeInstComputationInline(llvm::Instruction &I) { - // We can't currently support integer types other than 1, 8, 16, 32, 64. - // Validate this. - llvm::Type *Ty = I.getType(); - if (Ty->isIntegerTy() && (Ty!=llvm::Type::getInt1Ty(I.getContext()) && - Ty!=llvm::Type::getInt8Ty(I.getContext()) && - Ty!=llvm::Type::getInt16Ty(I.getContext()) && - Ty!=llvm::Type::getInt32Ty(I.getContext()) && - Ty!=llvm::Type::getInt64Ty(I.getContext()))) { - llvm::report_fatal_error("The C backend does not currently support integer " - "types of widths other than 1, 8, 16, 32, 64.\n" - "This is being tracked as PR 4158."); - } - // If this is a non-trivial bool computation, make sure to truncate down to // a 1 bit value. This is important because we want "add i1 x, y" to return // "0" when x and y are true, not "2" for example. + Out << "\n/* Tree\n" << I << "\n*/"; + bool NeedBoolTrunc = false; if (I.getType() == llvm::Type::getInt1Ty(I.getContext()) && !llvm::isa(I) && !llvm::isa(I)) @@ -2756,6 +2746,12 @@ void CWriter::printModuleTypes() { if (StructTypes.empty() && ArrayTypes.empty()) return; + Out << "DEBUG_ME"; + for (llvm::Module::const_global_iterator I = TheModule->global_begin(), E = TheModule->global_end(); + I != E; ++I) { + Out << I << "^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; + } + Out << "/* Structure and array forward declarations */\n"; unsigned NextTypeID = 0; @@ -4342,6 +4338,7 @@ void CWriter::writeMemoryAccess(llvm::Value *Operand, llvm::Type *OperandType, } void CWriter::visitLoadInst(llvm::LoadInst &I) { + Out << "\n/* Tree\n" << I << "\n*/"; llvm::VectorType *VT = llvm::dyn_cast(I.getType()); if (VT != NULL) { Out << "__load<" << I.getAlignment() << ">("; diff --git a/examples/intrinsics/knc.h b/examples/intrinsics/knc.h index a0d072fa..aeba353e 100644 --- a/examples/intrinsics/knc.h +++ b/examples/intrinsics/knc.h @@ -33,6 +33,7 @@ #include // INT_MIN #include +#include #include #include #include @@ -94,6 +95,60 @@ typedef int64_t __vec1_i64; struct __vec16_i32; +template +struct iN { + int length; + int *num; + + iN () { + length = num_bits / (sizeof (int) * 8); + num = (int*) calloc (length, sizeof (int)); + } + + iN (int val) { + length = num_bits / (sizeof (int) * 8); + num = (int*) calloc (length, sizeof (int)); + num [0] = val; + } + + ~iN () { length = 0; free(num); num = NULL;} +/* + iN operator >> (const int rhs) { + iN res; + int cells = rhs / (sizeof(int) * 8); + for (int i = 0; i < (this->length - cells); i++) + res.num[i] = this->num[cells + i]; + return res; + } +*/ + iN operator >> (const iN rhs) { + iN res; + int cells = rhs.num[0] / (sizeof(int) * 8); + for (int i = 0; i < (this->length - cells); i++) + res.num[i] = this->num[cells + i]; + return res; + } +/* + iN& operator= (iN rhs) { + iN swap; + for (int i = 0; i < length; i++) { + swap.num[i] = this->num[i]; + this->num[i] = rhs.num[i]; + rhs.num[i] = swap.num[i]; + } + return *this; + } +*/ + operator uint32_t() { return this->num[0]; } +}; + +template +T __cast_bits (T to, __vec16_i32 from) { + for (int i = 0; i < 16; i++) + to.num[i] = from[i] ; + return to; +} + #if 1 /* (iw) actually, this *SHOULD* be the right implementation for a vec16_i1: this one is a class that can have a constructor (which