[LLVM][WIP] Introduced heterogenous IR module

This commit is contained in:
Shilei Tian
2021-03-04 22:43:56 -05:00
parent 889da99523
commit af01c4c979
22 changed files with 1184 additions and 231 deletions

View File

@@ -27,6 +27,7 @@
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
@@ -38,6 +39,8 @@
#include <tuple>
#include <utility>
#define DEBUG_TYPE "data-layout"
using namespace llvm;
//===----------------------------------------------------------------------===//
@@ -547,6 +550,51 @@ bool DataLayout::operator==(const DataLayout &Other) const {
return Ret;
}
bool DataLayout::isCompatibleWith(const DataLayout &Other) const {
if (*this == Other)
return true;
bool Partial = BigEndian == Other.BigEndian;
if (StackNaturalAlign.hasValue() && Other.StackNaturalAlign.hasValue())
Partial = Partial && (StackNaturalAlign.getValue() ==
Other.StackNaturalAlign.getValue());
if (FunctionPtrAlign.hasValue() && Other.FunctionPtrAlign.hasValue())
Partial = Partial && (FunctionPtrAlign.getValue() ==
Other.FunctionPtrAlign.getValue());
if (!Partial)
return false;
// Compare the two Alignments. Suppose they're stored w/o any order (O(n^2)).
// Otherwise, this procedure can be optimized to O(n).
for (auto I = Alignments.begin(); I != Alignments.end(); ++I) {
for (auto J = Other.Alignments.begin(); J != Other.Alignments.end(); ++J) {
if (I->AlignType != J->AlignType || I->TypeBitWidth != J->TypeBitWidth)
continue;
// TODO: Do we care about preferred size vs ABI size, or both?
if (!(*I == *J))
return false;
}
}
// Compare pointers. Like before, suppose they're not ordered.
for (auto I = Pointers.begin(); I != Pointers.end(); ++I) {
for (auto J = Other.Pointers.begin(); J != Other.Pointers.end(); ++J) {
if (I->AddressSpace != J->AddressSpace)
continue;
// TODO: Similar question as above
if (!(*I == *J))
return false;
}
}
return true;
}
DataLayout::AlignmentsTy::iterator
DataLayout::findAlignmentLowerBound(AlignTypeEnum AlignType,
uint32_t BitWidth) {