Tmp commit to save progress
This commit is contained in:
41
cbackend.cpp
41
cbackend.cpp
@@ -392,7 +392,7 @@ namespace {
|
|||||||
// Output all vector constants so they can be accessed with single
|
// Output all vector constants so they can be accessed with single
|
||||||
// vector loads
|
// vector loads
|
||||||
printVectorConstants(F);
|
printVectorConstants(F);
|
||||||
|
|
||||||
printFunction(F);
|
printFunction(F);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -748,10 +748,11 @@ CWriter::printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty, bool isSigned,
|
|||||||
return Out << (isSigned?"":"u") << "int32_t " << NameSoFar;
|
return Out << (isSigned?"":"u") << "int32_t " << NameSoFar;
|
||||||
else if (NumBits <= 64)
|
else if (NumBits <= 64)
|
||||||
return Out << (isSigned?"":"u") << "int64_t "<< NameSoFar;
|
return Out << (isSigned?"":"u") << "int64_t "<< NameSoFar;
|
||||||
else {
|
else if (NumBits <= 128)
|
||||||
assert(NumBits <= 128 && "Bit widths > 128 not implemented yet");
|
|
||||||
return Out << (isSigned?"llvmInt128":"llvmUInt128") << " " << NameSoFar;
|
return Out << (isSigned?"llvmInt128":"llvmUInt128") << " " << NameSoFar;
|
||||||
}
|
else
|
||||||
|
return Out << "iN<" << NumBits << "> " << NameSoFar;
|
||||||
|
|
||||||
}
|
}
|
||||||
case llvm::Type::FloatTyID: return Out << "float " << NameSoFar;
|
case llvm::Type::FloatTyID: return Out << "float " << NameSoFar;
|
||||||
case llvm::Type::DoubleTyID: return Out << "double " << 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";
|
suffix = "i64";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
llvm::report_fatal_error("Only integer types of size 8/16/32/64 are "
|
suffix = "iN";
|
||||||
"supported by the C++ backend.");
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1463,10 +1464,10 @@ void CWriter::printConstant(llvm::Constant *CPV, bool Static) {
|
|||||||
Out << (CI->getZExtValue() ? '1' : '0');
|
Out << (CI->getZExtValue() ? '1' : '0');
|
||||||
else if (Ty == llvm::Type::getInt32Ty(CPV->getContext()))
|
else if (Ty == llvm::Type::getInt32Ty(CPV->getContext()))
|
||||||
Out << CI->getZExtValue() << 'u';
|
Out << CI->getZExtValue() << 'u';
|
||||||
else if (Ty->getPrimitiveSizeInBits() > 32) {
|
else if (Ty == llvm::Type::getInt64Ty(CPV->getContext()))
|
||||||
assert(Ty->getPrimitiveSizeInBits() == 64);
|
|
||||||
Out << CI->getZExtValue() << "ull";
|
Out << CI->getZExtValue() << "ull";
|
||||||
}
|
else if (Ty->getPrimitiveSizeInBits() > 64)
|
||||||
|
llvm::dyn_cast<llvm::Value>(CPV)->printAsOperand(Out, false);
|
||||||
else {
|
else {
|
||||||
Out << "((";
|
Out << "((";
|
||||||
printSimpleType(Out, Ty, false) << ')';
|
printSimpleType(Out, Ty, false) << ')';
|
||||||
@@ -1874,22 +1875,11 @@ std::string CWriter::GetValueName(const llvm::Value *Operand) {
|
|||||||
/// writeInstComputationInline - Emit the computation for the specified
|
/// writeInstComputationInline - Emit the computation for the specified
|
||||||
/// instruction inline, with no destination provided.
|
/// instruction inline, with no destination provided.
|
||||||
void CWriter::writeInstComputationInline(llvm::Instruction &I) {
|
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
|
// 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
|
// 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.
|
// "0" when x and y are true, not "2" for example.
|
||||||
|
Out << "\n/* Tree\n" << I << "\n*/";
|
||||||
|
|
||||||
bool NeedBoolTrunc = false;
|
bool NeedBoolTrunc = false;
|
||||||
if (I.getType() == llvm::Type::getInt1Ty(I.getContext()) &&
|
if (I.getType() == llvm::Type::getInt1Ty(I.getContext()) &&
|
||||||
!llvm::isa<llvm::ICmpInst>(I) && !llvm::isa<llvm::FCmpInst>(I))
|
!llvm::isa<llvm::ICmpInst>(I) && !llvm::isa<llvm::FCmpInst>(I))
|
||||||
@@ -2756,6 +2746,12 @@ void CWriter::printModuleTypes() {
|
|||||||
if (StructTypes.empty() && ArrayTypes.empty())
|
if (StructTypes.empty() && ArrayTypes.empty())
|
||||||
return;
|
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";
|
Out << "/* Structure and array forward declarations */\n";
|
||||||
|
|
||||||
unsigned NextTypeID = 0;
|
unsigned NextTypeID = 0;
|
||||||
@@ -4342,6 +4338,7 @@ void CWriter::writeMemoryAccess(llvm::Value *Operand, llvm::Type *OperandType,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::visitLoadInst(llvm::LoadInst &I) {
|
void CWriter::visitLoadInst(llvm::LoadInst &I) {
|
||||||
|
Out << "\n/* Tree\n" << I << "\n*/";
|
||||||
llvm::VectorType *VT = llvm::dyn_cast<llvm::VectorType>(I.getType());
|
llvm::VectorType *VT = llvm::dyn_cast<llvm::VectorType>(I.getType());
|
||||||
if (VT != NULL) {
|
if (VT != NULL) {
|
||||||
Out << "__load<" << I.getAlignment() << ">(";
|
Out << "__load<" << I.getAlignment() << ">(";
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <limits.h> // INT_MIN
|
#include <limits.h> // INT_MIN
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -94,6 +95,60 @@ typedef int64_t __vec1_i64;
|
|||||||
|
|
||||||
struct __vec16_i32;
|
struct __vec16_i32;
|
||||||
|
|
||||||
|
template <int num_bits>
|
||||||
|
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 <class T>
|
||||||
|
T __cast_bits (T to, __vec16_i32 from) {
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
to.num[i] = from[i] ;
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
/* (iw) actually, this *SHOULD* be the right implementation for a
|
/* (iw) actually, this *SHOULD* be the right implementation for a
|
||||||
vec16_i1: this one is a class that can have a constructor (which
|
vec16_i1: this one is a class that can have a constructor (which
|
||||||
|
|||||||
Reference in New Issue
Block a user