Skip to content

Commit

Permalink
Merge pull request #91 from frasercrmck/fix-llvm-17
Browse files Browse the repository at this point in the history
[compiler] Update to build with LLVM 17
  • Loading branch information
frasercrmck authored Aug 15, 2023
2 parents bf66284 + 57954e9 commit 262e155
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#ifndef MULTI_LLVM_CREATION_APIS_HELPER_H_INCLUDED
#define MULTI_LLVM_CREATION_APIS_HELPER_H_INCLUDED

#include <llvm/ADT/None.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Instructions.h>
Expand Down
18 changes: 7 additions & 11 deletions modules/compiler/multi_llvm/include/multi_llvm/opaque_pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@

#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Type.h>
#include <multi_llvm/llvm_version.h>

namespace multi_llvm {
inline bool isOpaquePointerTy(llvm::Type *Ty) {
if (auto *PTy = llvm::dyn_cast<llvm::PointerType>(Ty)) {
return PTy->isOpaque();
}
return false;
}

inline bool isOpaqueOrPointeeTypeMatches(llvm::PointerType *PTy, llvm::Type *) {
(void)PTy;
#if LLVM_VERSION_LESS(17, 0)
assert(PTy->isOpaque() && "No support for typed pointers in LLVM 15+");
#endif
return true;
}

inline llvm::Type *getPtrElementType(llvm::PointerType *PTy) {
if (PTy->isOpaque()) {
return nullptr;
}
assert(false && "No support for typed pointers");
(void)PTy;
#if LLVM_VERSION_LESS(17, 0)
assert(PTy->isOpaque() && "No support for typed pointers in LLVM 15+");
#endif
return nullptr;
}

Expand Down
1 change: 0 additions & 1 deletion modules/compiler/source/base/source/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
#include <llvm/Transforms/IPO/ForceFunctionAttrs.h>
#include <llvm/Transforms/IPO/GlobalDCE.h>
#include <llvm/Transforms/IPO/Inliner.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Transforms/Scalar/ADCE.h>
#include <llvm/Transforms/Scalar/BDCE.h>
#include <llvm/Transforms/Scalar/DCE.h>
Expand Down
2 changes: 2 additions & 0 deletions modules/compiler/tools/muxc/muxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ Expected<std::unique_ptr<Module>> driver::convertInputToIR() {
->getLLVMContext()
: LLVMCtx.get();
assert(LLVMContextToUse && "Missing LLVM Context");
#if LLVM_VERSION_LESS(17, 0)
LLVMContextToUse->setOpaquePointers(true);
#endif

// Assume that .bc and .ll files are already IR unless told otherwise.
if (InputLanguage == "ir" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <llvm/IR/DerivedTypes.h>
#include <llvm/Support/Casting.h>
#include <llvm/Transforms/Utils/ValueMapper.h>
#include <multi_llvm/llvm_version.h>
#include <multi_llvm/vector_type_helper.h>

namespace compiler {
Expand Down Expand Up @@ -56,11 +57,13 @@ class StructTypeRemapper final : public llvm::ValueMapTypeRemapper {
return newStructType;
}
} else if (auto *ptrType = llvm::dyn_cast<llvm::PointerType>(srcType)) {
#if LLVM_VERSION_LESS(17, 0)
// Nominally support opaque pointer remapping from LLVM 13 onwards.
if (ptrType->isOpaque()) {
return srcType;
}
assert(ptrType->isOpaque() && "Can only remap opaque pointers");
#endif
return srcType;
} else if (auto *arrayType = llvm::dyn_cast<llvm::ArrayType>(srcType)) {
auto *arrayElementType = arrayType->getElementType();
Expand Down
1 change: 1 addition & 0 deletions modules/compiler/utils/source/builtin_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <compiler/utils/metadata.h>
#include <compiler/utils/pass_functions.h>
#include <compiler/utils/scheduling.h>
#include <llvm/ADT/StringExtras.h>
#include <llvm/ADT/StringSwitch.h>

using namespace llvm;
Expand Down
12 changes: 6 additions & 6 deletions modules/compiler/utils/source/mangling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ bool NameMangler::mangleType(raw_ostream &O, Type *Ty, TypeQualifiers Quals,
} else if (Ty->isPointerTy()) {
PointerType *PtrTy = cast<PointerType>(Ty);
unsigned AddressSpace = PtrTy->getAddressSpace();
if (PtrTy->isOpaque()) {
O << "u3ptr";
manglePointerQuals(O, Qual, AddressSpace);
return true;
}
return false;
#if LLVM_VERSION_LESS(17, 0)
assert(PtrTy->isOpaque() && "No support for typed pointers past LLVM 15");
#endif
O << "u3ptr";
manglePointerQuals(O, Qual, AddressSpace);
return true;
#if LLVM_VERSION_GREATER_EQUAL(17, 0)
} else if (Ty->isTargetExtTy()) {
if (auto Name = mangleBuiltinType(Ty)) {
Expand Down
11 changes: 7 additions & 4 deletions modules/compiler/vecz/source/transform/builtin_inlining_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@ static Value *emitBuiltinMemSet(Function *F, IRBuilder<> &B,
}

Value *DstPtr = Args[0];
auto *DstPtrTy = cast<PointerType>(DstPtr->getType());

Type *Int8Ty = B.getInt8Ty();

#if LLVM_VERSION_LESS(17, 0)
auto *DstPtrTy = cast<PointerType>(DstPtr->getType());
// FIXME: We implicitly assume pointers to i8 by doing byte-wise stores,
// below. See CA-4331.
if (!DstPtrTy->isOpaque() &&
multi_llvm::getPtrElementType(DstPtrTy) != Int8Ty) {
return nullptr;
}
#endif

Value *StoredValue = Args[1];
bool IsVolatile = (Args.back() == ConstantInt::getTrue(Context));
Expand Down Expand Up @@ -210,11 +212,11 @@ static Value *emitBuiltinMemCpy(Function *F, IRBuilder<> &B,

Value *DstPtr = Args[0];
Value *SrcPtr = Args[1];
Type *Int8Ty = B.getInt8Ty();

#if LLVM_VERSION_LESS(17, 0)
auto *DstPtrTy = cast<PointerType>(DstPtr->getType());
auto *SrcPtrTy = cast<PointerType>(DstPtr->getType());

Type *Int8Ty = B.getInt8Ty();
// FIXME: We implicitly assume pointers to i8 by doing byte-wise loads and
// stores, below. See CA-4331.
if ((!DstPtrTy->isOpaque() &&
Expand All @@ -223,6 +225,7 @@ static Value *emitBuiltinMemCpy(Function *F, IRBuilder<> &B,
multi_llvm::getPtrElementType(SrcPtrTy) != Int8Ty))) {
return nullptr;
}
#endif

bool IsVolatile = (Args.back() == ConstantInt::getTrue(Context));
llvm::StoreInst *MC = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions modules/compiler/vecz/tools/source/veczc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ int main(const int argc, const char *const argv[]) {

llvm::SMDiagnostic err;
llvm::LLVMContext context;
#if LLVM_VERSION_LESS(17, 0)
context.setOpaquePointers(true);
#endif

std::unique_ptr<llvm::Module> module =
llvm::parseIRFile(InputFilename, err, context);
Expand Down

0 comments on commit 262e155

Please sign in to comment.