mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-29 14:40:40 +03:00
Drop support for LLVM < 3.5
This allows to clean up the code a little.
This commit is contained in:
parent
8eab25f2fa
commit
60d676e2a1
57 changed files with 35 additions and 1019 deletions
|
@ -12,68 +12,39 @@
|
|||
|
||||
bool AttrBuilder::hasAttributes() const
|
||||
{
|
||||
#if LDC_LLVM_VER >= 302
|
||||
return attrs.hasAttributes();
|
||||
#else
|
||||
return attrs.Raw() != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AttrBuilder::contains(A attribute) const
|
||||
{
|
||||
#if LDC_LLVM_VER >= 303
|
||||
return attrs.contains(attribute);
|
||||
#elif LDC_LLVM_VER == 302
|
||||
return attrs.hasAttribute(attribute);
|
||||
#else
|
||||
return (attrs & attribute).Raw() != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
AttrBuilder& AttrBuilder::clear()
|
||||
{
|
||||
#if LDC_LLVM_VER >= 302
|
||||
attrs.clear();
|
||||
#else
|
||||
attrs = A(0);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
AttrBuilder& AttrBuilder::add(A attribute)
|
||||
{
|
||||
#if LDC_LLVM_VER >= 302
|
||||
// never set 'None' explicitly
|
||||
if (attribute)
|
||||
attrs.addAttribute(attribute);
|
||||
#else
|
||||
attrs |= attribute;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
AttrBuilder& AttrBuilder::remove(A attribute)
|
||||
{
|
||||
#if LDC_LLVM_VER >= 302
|
||||
// never remove 'None' explicitly
|
||||
if (attribute)
|
||||
attrs.removeAttribute(attribute);
|
||||
#else
|
||||
attrs &= ~attribute;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
AttrBuilder& AttrBuilder::merge(const AttrBuilder& other)
|
||||
{
|
||||
#if LDC_LLVM_VER >= 303
|
||||
attrs.merge(other.attrs);
|
||||
#elif LDC_LLVM_VER == 302
|
||||
AttrBuilder mutableCopy = other;
|
||||
attrs.addAttributes(llvm::Attributes::get(gIR->context(), mutableCopy.attrs));
|
||||
#else
|
||||
attrs |= other.attrs;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -82,29 +53,9 @@ AttrSet AttrSet::extractFunctionAndReturnAttributes(const llvm::Function* functi
|
|||
{
|
||||
AttrSet set;
|
||||
|
||||
#if LDC_LLVM_VER >= 303
|
||||
NativeSet old = function->getAttributes();
|
||||
llvm::AttributeSet existingAttrs[] = { old.getFnAttributes(), old.getRetAttributes() };
|
||||
set.entries = llvm::AttributeSet::get(gIR->context(), existingAttrs);
|
||||
#else
|
||||
unsigned fnIndex = ~0u;
|
||||
unsigned retIndex = 0;
|
||||
|
||||
#if LDC_LLVM_VER == 302
|
||||
#define ADD_ATTRIBS(i, a) \
|
||||
if (a.Raw()) \
|
||||
set.entries[i].attrs.addAttributes(a);
|
||||
#else
|
||||
#define ADD_ATTRIBS(i, a) \
|
||||
if (a.Raw()) \
|
||||
set.entries[i].attrs = a;
|
||||
#endif
|
||||
|
||||
ADD_ATTRIBS(fnIndex, function->getAttributes().getFnAttributes());
|
||||
ADD_ATTRIBS(retIndex, function->getAttributes().getRetAttributes());
|
||||
|
||||
#undef ADD_ATTRIBS
|
||||
#endif
|
||||
|
||||
return set;
|
||||
}
|
||||
|
@ -113,50 +64,15 @@ AttrSet& AttrSet::add(unsigned index, const AttrBuilder& builder)
|
|||
{
|
||||
if (builder.hasAttributes())
|
||||
{
|
||||
#if LDC_LLVM_VER >= 303
|
||||
AttrBuilder mutableBuilderCopy = builder;
|
||||
llvm::AttributeSet as = llvm::AttributeSet::get(
|
||||
gIR->context(), index, mutableBuilderCopy.attrs);
|
||||
entries = entries.addAttributes(gIR->context(), index, as);
|
||||
#else
|
||||
entries[index].merge(builder);
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
AttrSet::NativeSet AttrSet::toNativeSet() const
|
||||
{
|
||||
#if LDC_LLVM_VER >= 303
|
||||
return entries;
|
||||
#else
|
||||
if (entries.empty())
|
||||
return NativeSet();
|
||||
|
||||
std::vector<llvm::AttributeWithIndex> attrsWithIndex;
|
||||
attrsWithIndex.reserve(entries.size());
|
||||
|
||||
typedef std::map<unsigned, AttrBuilder>::const_iterator I;
|
||||
for (I it = entries.begin(); it != entries.end(); ++it)
|
||||
{
|
||||
unsigned index = it->first;
|
||||
const AttrBuilder& builder = it->second;
|
||||
if (!builder.hasAttributes())
|
||||
continue;
|
||||
|
||||
#if LDC_LLVM_VER == 302
|
||||
AttrBuilder mutableBuilderCopy = builder;
|
||||
attrsWithIndex.push_back(llvm::AttributeWithIndex::get(index,
|
||||
llvm::Attributes::get(gIR->context(), mutableBuilderCopy.attrs)));
|
||||
#else
|
||||
attrsWithIndex.push_back(llvm::AttributeWithIndex::get(index, builder.attrs));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER == 302
|
||||
return NativeSet::get(gIR->context(), attrsWithIndex);
|
||||
#else
|
||||
return NativeSet::get(attrsWithIndex.begin(), attrsWithIndex.end());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue