diff --git a/INSTALL.md b/INSTALL.md index 9580ebc52..036a9e6a8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,11 +1,11 @@ # Dependencies -## Ubuntu 20.04: +## Ubuntu 22.04: ```shell sudo apt update sudo apt install \ - clang-12 \ + clang-15 \ cmake \ curl \ flex \ @@ -17,9 +17,10 @@ sudo apt install \ libjemalloc-dev \ libmpfr-dev \ libyaml-dev \ - lld-12 \ - llvm-12-tools \ + lld-15 \ + llvm-15-tools \ maven \ + openjdk-17-jdk \ pkg-config \ python3 \ python3-pip \ diff --git a/cmake/FindLLVM.cmake b/cmake/FindLLVM.cmake index ed6ab39c2..e2db90498 100644 --- a/cmake/FindLLVM.cmake +++ b/cmake/FindLLVM.cmake @@ -8,21 +8,9 @@ if (NOT LLVM_FOUND) find_package(LLVM 15 QUIET CONFIG) endif() -if (NOT LLVM_FOUND) - find_package(LLVM 14 QUIET CONFIG) -endif() - -if (NOT LLVM_FOUND) - find_package(LLVM 13 QUIET CONFIG) -endif() - -if (NOT LLVM_FOUND) - find_package(LLVM 12 QUIET CONFIG) -endif() - message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -if (${LLVM_PACKAGE_VERSION} VERSION_LESS 12) - message(FATAL_ERROR "LLVM 12 or newer is required") +if (${LLVM_PACKAGE_VERSION} VERSION_LESS 15) + message(FATAL_ERROR "LLVM 15 or newer is required") endif() find_program(OPT opt diff --git a/default.nix b/default.nix index bfea9ee0e..970efeef5 100644 --- a/default.nix +++ b/default.nix @@ -36,7 +36,7 @@ let # Avoid spurious rebuilds by ignoring files that don't affect the build. mavenix = import sources."mavenix" { inherit (prev) pkgs; }; in { - llvm-version = 13; + llvm-version = 15; llvm-backend-build-type = cmakeBuildType; inherit (mavenix) buildMaven; mavenix-cli = mavenix.cli; diff --git a/flake.nix b/flake.nix index cbe8bb301..7d66221ac 100644 --- a/flake.nix +++ b/flake.nix @@ -97,7 +97,7 @@ builtins.listToAttrs (lib.imap0 (i: v: { name = "check_${toString i}"; value = v; }) checks); matrix = builtins.listToAttrs (lib.forEach (lib.cartesianProductOfSets { - llvm-version = [12 13 14 15 16]; + llvm-version = [15 16]; build-type = ["Debug" "Release" "RelWithDebInfo" "FastBuild" "GcStats"]; }) ( args: @@ -116,15 +116,15 @@ llvm-backend-release = llvm-backend-16-Release.llvm-backend; }; checks = listToChecks [ - # Check that the backend compiles on each supported version of LLVM, - # but don't run the test suite on all possible configurations. - llvm-backend-12-FastBuild.llvm-backend - llvm-backend-13-FastBuild.llvm-backend - llvm-backend-14-FastBuild.llvm-backend - llvm-backend-15-FastBuild.llvm-backend + llvm-backend-16-Debug.llvm-backend + llvm-backend-16-Release.llvm-backend + llvm-backend-16-RelWithDebInfo.llvm-backend + llvm-backend-16-GcStats.llvm-backend + + llvm-backend-15-FastBuild.integration-tests llvm-backend-16-FastBuild.integration-tests ]; - devShells.default = llvm-backend-15-FastBuild.devShell; + devShells.default = llvm-backend-16-FastBuild.devShell; }) // { # non-system suffixed items should go here overlays.default = llvm-backend-overlay; diff --git a/include/kllvm/codegen/Util.h b/include/kllvm/codegen/Util.h index 1709364d0..66edab848 100644 --- a/include/kllvm/codegen/Util.h +++ b/include/kllvm/codegen/Util.h @@ -16,24 +16,19 @@ namespace kllvm { // one does not yet exist llvm::Function *koreHeapAlloc(std::string name, llvm::Module *module); -// If Value is an instance of llvm::Function, cast and return. Otherwise, print -// errors and abort. -llvm::Function *castToFunctionOrAbort(llvm::Value *value); - // getOrInsertFunction on module, aborting on failure template -static llvm::Function *getOrInsertFunction(llvm::Module *module, Ts... Args) { - llvm::Value *callee; - auto ret = module->getOrInsertFunction(Args...); -#if LLVM_VERSION_MAJOR >= 9 - callee = ret.getCallee(); -#else - callee = ret; -#endif - return castToFunctionOrAbort(callee); -} +llvm::Function *getOrInsertFunction(llvm::Module *module, Ts... Args) { + auto callee = module->getOrInsertFunction(Args...).getCallee(); + auto func = llvm::dyn_cast(callee); -llvm::StructType *getTypeByName(llvm::Module *module, std::string name); + if (!func) { + func->print(llvm::errs()); + abort(); + } + + return func; +} } // namespace kllvm diff --git a/lib/codegen/ApplyPasses.cpp b/lib/codegen/ApplyPasses.cpp index 470a5cd05..36a44cb70 100644 --- a/lib/codegen/ApplyPasses.cpp +++ b/lib/codegen/ApplyPasses.cpp @@ -2,14 +2,6 @@ #include "runtime/header.h" -#if LLVM_VERSION_MAJOR >= 14 -#include -#else -#include -#endif - -#include - #if LLVM_VERSION_MAJOR >= 17 #include #include @@ -18,6 +10,8 @@ #include #endif +#include +#include #include #include #include @@ -68,19 +62,11 @@ void apply_kllvm_opt_passes(llvm::Module &mod) { } void generate_object_file(llvm::Module &mod, llvm::raw_ostream &os) { - // The frame-pointer retention code in LLVM 12 and older is tied strongly to - // the actual command-line flag used to specify it for code generation, rather - // than being decoupled as it is in 13 and newer. Because LLVM 12 will be - // deprecated for our purposes sooner rather than later, and is not the - // default version for packaged versions of K, we simply disable the FP - // feature. -#if LLVM_VERSION_MAJOR > 12 if (KeepFramePointer) { mod.setFramePointer(FramePointerKind::All); } else { mod.setFramePointer(FramePointerKind::None); } -#endif auto triple = BACKEND_TARGET_TRIPLE; mod.setTargetTriple(triple); diff --git a/lib/codegen/CreateStaticTerm.cpp b/lib/codegen/CreateStaticTerm.cpp index 4f824df97..b7d37ebff 100644 --- a/lib/codegen/CreateStaticTerm.cpp +++ b/lib/codegen/CreateStaticTerm.cpp @@ -45,8 +45,8 @@ llvm::Constant *CreateStaticTerm::notInjectionCase( if (!globalVar->hasInitializer()) { std::vector blockVals; - llvm::StructType *BlockHeaderType - = getTypeByName(Module, BLOCKHEADER_STRUCT); + llvm::StructType *BlockHeaderType = llvm::StructType::getTypeByName( + Module->getContext(), BLOCKHEADER_STRUCT); uint64_t headerVal = getBlockHeaderVal(Module, symbol, BlockType) | NOT_YOUNG_OBJECT_BIT; llvm::Constant *BlockHeader = llvm::ConstantStruct::get( @@ -79,7 +79,8 @@ llvm::Constant *CreateStaticTerm::notInjectionCase( = {llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), 0)}; return llvm::ConstantExpr::getBitCast( llvm::ConstantExpr::getInBoundsGetElementPtr(BlockType, globalVar, Idxs), - llvm::PointerType::getUnqual(getTypeByName(Module, BLOCK_STRUCT))); + llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(Module->getContext(), BLOCK_STRUCT))); } std::pair @@ -97,7 +98,8 @@ CreateStaticTerm::operator()(KOREPattern *pattern) { false); } if (symbol->getArguments().empty()) { - llvm::StructType *BlockType = getTypeByName(Module, BLOCK_STRUCT); + llvm::StructType *BlockType + = llvm::StructType::getTypeByName(Module->getContext(), BLOCK_STRUCT); llvm::Constant *Cast = llvm::ConstantExpr::getIntToPtr( llvm::ConstantInt::get( llvm::Type::getInt64Ty(Ctx), @@ -144,7 +146,8 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { assert(false && "cannot create tokens of collection category"); case SortCategory::Int: { llvm::Constant *global = Module->getOrInsertGlobal( - "int_" + contents, getTypeByName(Module, INT_WRAPPER_STRUCT)); + "int_" + contents, llvm::StructType::getTypeByName( + Module->getContext(), INT_WRAPPER_STRUCT)); llvm::GlobalVariable *globalVar = llvm::dyn_cast(global); if (!globalVar->hasInitializer()) { @@ -168,7 +171,8 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { limbsVar->setInitializer( llvm::ConstantArray::get(limbsType, allocdLimbs)); llvm::Constant *hdr = llvm::ConstantStruct::get( - getTypeByName(Module, BLOCKHEADER_STRUCT), + llvm::StructType::getTypeByName( + Module->getContext(), BLOCKHEADER_STRUCT), llvm::ConstantInt::get( llvm::Type::getInt64Ty(Ctx), sizeof(mpz_hdr) - sizeof(blockheader) | NOT_YOUNG_OBJECT_BIT)); @@ -178,9 +182,12 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { numLimbs, llvm::ConstantInt::getSigned(llvm::Type::getInt32Ty(Ctx), sign)); globalVar->setInitializer(llvm::ConstantStruct::get( - getTypeByName(Module, INT_WRAPPER_STRUCT), hdr, + llvm::StructType::getTypeByName( + Module->getContext(), INT_WRAPPER_STRUCT), + hdr, llvm::ConstantStruct::get( - getTypeByName(Module, INT_STRUCT), numLimbs, mp_size, + llvm::StructType::getTypeByName(Module->getContext(), INT_STRUCT), + numLimbs, mp_size, llvm::ConstantExpr::getPointerCast( limbsVar, llvm::Type::getInt64PtrTy(Ctx))))); mpz_clear(value); @@ -189,11 +196,14 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { = {llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), 0), llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), 1)}; return llvm::ConstantExpr::getInBoundsGetElementPtr( - getTypeByName(Module, INT_WRAPPER_STRUCT), globalVar, Idxs); + llvm::StructType::getTypeByName( + Module->getContext(), INT_WRAPPER_STRUCT), + globalVar, Idxs); } case SortCategory::Float: { llvm::Constant *global = Module->getOrInsertGlobal( - "float_" + contents, getTypeByName(Module, FLOAT_WRAPPER_STRUCT)); + "float_" + contents, llvm::StructType::getTypeByName( + Module->getContext(), FLOAT_WRAPPER_STRUCT)); llvm::GlobalVariable *globalVar = llvm::dyn_cast(global); if (!globalVar->hasInitializer()) { @@ -245,7 +255,8 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { limbsVar->setInitializer( llvm::ConstantArray::get(limbsType, allocdLimbs)); llvm::Constant *hdr = llvm::ConstantStruct::get( - getTypeByName(Module, BLOCKHEADER_STRUCT), + llvm::StructType::getTypeByName( + Module->getContext(), BLOCKHEADER_STRUCT), llvm::ConstantInt::get( llvm::Type::getInt64Ty(Ctx), (sizeof(floating_hdr) - sizeof(blockheader)) @@ -265,9 +276,13 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { // assuming that the host and target have the same arch, but since we // don't yet support cross compiling anyway, that's a safe assumption. globalVar->setInitializer(llvm::ConstantStruct::get( - getTypeByName(Module, FLOAT_WRAPPER_STRUCT), hdr, + llvm::StructType::getTypeByName( + Module->getContext(), FLOAT_WRAPPER_STRUCT), + hdr, llvm::ConstantStruct::get( - getTypeByName(Module, FLOAT_STRUCT), expbits, + llvm::StructType::getTypeByName( + Module->getContext(), FLOAT_STRUCT), + expbits, llvm::ConstantStruct::getAnon( {mpfr_prec, mpfr_sign, mpfr_exp, llvm::ConstantExpr::getPointerCast( @@ -278,7 +293,9 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { = {llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), 0), llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), 1)}; return llvm::ConstantExpr::getInBoundsGetElementPtr( - getTypeByName(Module, FLOAT_WRAPPER_STRUCT), globalVar, Idxs); + llvm::StructType::getTypeByName( + Module->getContext(), FLOAT_WRAPPER_STRUCT), + globalVar, Idxs); } case SortCategory::StringBuffer: assert(false && "not implemented yet: tokens"); @@ -296,15 +313,16 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { case SortCategory::Symbol: { llvm::StructType *StringType = llvm::StructType::get( Ctx, - {getTypeByName(Module, BLOCKHEADER_STRUCT), + {llvm::StructType::getTypeByName( + Module->getContext(), BLOCKHEADER_STRUCT), llvm::ArrayType::get(llvm::Type::getInt8Ty(Ctx), contents.size())}); llvm::Constant *global = Module->getOrInsertGlobal("token_" + escape(contents), StringType); llvm::GlobalVariable *globalVar = llvm::dyn_cast(global); if (!globalVar->hasInitializer()) { - llvm::StructType *BlockHeaderType - = getTypeByName(Module, BLOCKHEADER_STRUCT); + llvm::StructType *BlockHeaderType = llvm::StructType::getTypeByName( + Module->getContext(), BLOCKHEADER_STRUCT); // this object does not live on the young generation, so we need to set // the correct gc bit. llvm::Constant *BlockHeader = llvm::ConstantStruct::get( @@ -316,8 +334,8 @@ CreateStaticTerm::createToken(ValueType sort, std::string contents) { llvm::ConstantDataArray::getString(Ctx, contents, false))); } return llvm::ConstantExpr::getPointerCast( - global, - llvm::PointerType::getUnqual(getTypeByName(Module, BLOCK_STRUCT))); + global, llvm::PointerType::getUnqual(llvm::StructType::getTypeByName( + Module->getContext(), BLOCK_STRUCT))); } case SortCategory::Uncomputed: abort(); } diff --git a/lib/codegen/CreateTerm.cpp b/lib/codegen/CreateTerm.cpp index 08781e993..3b205fa6b 100644 --- a/lib/codegen/CreateTerm.cpp +++ b/lib/codegen/CreateTerm.cpp @@ -174,27 +174,36 @@ llvm::Type *getParamType(ValueType sort, llvm::Module *Module) { } llvm::StructType *getBlockType(llvm::Module *Module) { - return getTypeByName(Module, BLOCK_STRUCT); + return llvm::StructType::getTypeByName(Module->getContext(), BLOCK_STRUCT); } llvm::Type *getValueType(ValueType sort, llvm::Module *Module) { switch (sort.cat) { - case SortCategory::Map: return getTypeByName(Module, MAP_STRUCT); - case SortCategory::RangeMap: return getTypeByName(Module, RANGEMAP_STRUCT); - case SortCategory::List: return getTypeByName(Module, LIST_STRUCT); - case SortCategory::Set: return getTypeByName(Module, SET_STRUCT); + case SortCategory::Map: + return llvm::StructType::getTypeByName(Module->getContext(), MAP_STRUCT); + case SortCategory::RangeMap: + return llvm::StructType::getTypeByName( + Module->getContext(), RANGEMAP_STRUCT); + case SortCategory::List: + return llvm::StructType::getTypeByName(Module->getContext(), LIST_STRUCT); + case SortCategory::Set: + return llvm::StructType::getTypeByName(Module->getContext(), SET_STRUCT); case SortCategory::Int: - return llvm::PointerType::getUnqual(getTypeByName(Module, INT_STRUCT)); + return llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(Module->getContext(), INT_STRUCT)); case SortCategory::Float: - return llvm::PointerType::getUnqual(getTypeByName(Module, FLOAT_STRUCT)); + return llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(Module->getContext(), FLOAT_STRUCT)); case SortCategory::StringBuffer: - return llvm::PointerType::getUnqual(getTypeByName(Module, BUFFER_STRUCT)); + return llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(Module->getContext(), BUFFER_STRUCT)); case SortCategory::Bool: return llvm::Type::getInt1Ty(Module->getContext()); case SortCategory::MInt: return llvm::IntegerType::get(Module->getContext(), sort.bits); case SortCategory::Symbol: case SortCategory::Variable: - return llvm::PointerType::getUnqual(getTypeByName(Module, BLOCK_STRUCT)); + return llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(Module->getContext(), BLOCK_STRUCT)); case SortCategory::Uncomputed: abort(); } } @@ -202,7 +211,8 @@ llvm::Type *getValueType(ValueType sort, llvm::Module *Module) { llvm::StructType *getBlockType( llvm::Module *Module, KOREDefinition *definition, const KORESymbol *symbol) { - llvm::StructType *BlockHeaderType = getTypeByName(Module, BLOCKHEADER_STRUCT); + llvm::StructType *BlockHeaderType = llvm::StructType::getTypeByName( + Module->getContext(), BLOCKHEADER_STRUCT); llvm::ArrayType *EmptyArrayType = llvm::ArrayType::get(llvm::Type::getInt64Ty(Module->getContext()), 0); llvm::SmallVector Types; @@ -229,7 +239,8 @@ uint64_t getBlockHeaderVal( llvm::Value *getBlockHeader( llvm::Module *Module, KOREDefinition *definition, const KORESymbol *symbol, llvm::Type *BlockType) { - llvm::StructType *BlockHeaderType = getTypeByName(Module, BLOCKHEADER_STRUCT); + llvm::StructType *BlockHeaderType = llvm::StructType::getTypeByName( + Module->getContext(), BLOCKHEADER_STRUCT); uint64_t headerVal = getBlockHeaderVal(Module, symbol, BlockType); return llvm::ConstantStruct::get( BlockHeaderType, @@ -773,14 +784,8 @@ llvm::Value *CreateTerm::createFunctionCall( call->setCallingConv(llvm::CallingConv::Tail); } if (sret) { -#if LLVM_VERSION_MAJOR >= 12 llvm::Attribute sretAttr = llvm::Attribute::get(Ctx, llvm::Attribute::StructRet, sretType); -#else - (void)sretType; - llvm::Attribute sretAttr - = llvm::Attribute::get(Ctx, llvm::Attribute::StructRet); -#endif func->arg_begin()->addAttr(sretAttr); call->addParamAttr(0, sretAttr); return AllocSret; @@ -837,8 +842,8 @@ llvm::Value *CreateTerm::notInjectionCase( new llvm::StoreInst(ChildValue, ChildPtr, CurrentBlock); } - auto BlockPtr - = llvm::PointerType::getUnqual(getTypeByName(Module, BLOCK_STRUCT)); + auto BlockPtr = llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(Module->getContext(), BLOCK_STRUCT)); auto bitcast = new llvm::BitCastInst(Block, BlockPtr, "", CurrentBlock); if (symbolDecl->getAttributes().count("binder")) { auto call = llvm::CallInst::Create( @@ -1356,9 +1361,12 @@ llvm::Type *getArgType(ValueType cat, llvm::Module *mod) { case SortCategory::Set: { return getValueType(cat, mod); } - case SortCategory::Int: return getTypeByName(mod, INT_STRUCT); - case SortCategory::Float: return getTypeByName(mod, FLOAT_STRUCT); - case SortCategory::StringBuffer: return getTypeByName(mod, BUFFER_STRUCT); + case SortCategory::Int: + return llvm::StructType::getTypeByName(mod->getContext(), INT_STRUCT); + case SortCategory::Float: + return llvm::StructType::getTypeByName(mod->getContext(), FLOAT_STRUCT); + case SortCategory::StringBuffer: + return llvm::StructType::getTypeByName(mod->getContext(), BUFFER_STRUCT); case SortCategory::Symbol: case SortCategory::Variable: { return getBlockType(mod); diff --git a/lib/codegen/Debug.cpp b/lib/codegen/Debug.cpp index d3fba88cb..52057ed69 100644 --- a/lib/codegen/Debug.cpp +++ b/lib/codegen/Debug.cpp @@ -69,14 +69,9 @@ void initDebugFunction( return; auto Unit = Dbg->createFile(DbgFile->getFilename(), DbgFile->getDirectory()); llvm::DIScope *FContext = Unit; -#if LLVM_VERSION_MAJOR >= 8 DbgSP = Dbg->createFunction( FContext, name, name, Unit, DbgLine, type, DbgLine, llvm::DINode::DIFlags::FlagZero, llvm::DISubprogram::SPFlagDefinition); -#else - DbgSP = Dbg->createFunction( - FContext, name, name, Unit, DbgLine, type, false, true, DbgLine); -#endif func->setSubprogram(DbgSP); } diff --git a/lib/codegen/Decision.cpp b/lib/codegen/Decision.cpp index c29b08697..9e2779a2f 100644 --- a/lib/codegen/Decision.cpp +++ b/lib/codegen/Decision.cpp @@ -266,8 +266,9 @@ void SwitchNode::codegen(Decision *d) { binding.first.substr(0, max_name_length), d->CurrentBlock); break; } - auto BlockPtr = llvm::PointerType::getUnqual( - getTypeByName(d->Module, BLOCK_STRUCT)); + auto BlockPtr + = llvm::PointerType::getUnqual(llvm::StructType::getTypeByName( + d->Module->getContext(), BLOCK_STRUCT)); if (symbolDecl->getAttributes().count("binder")) { if (offset == 0) { Renamed = llvm::CallInst::Create( @@ -492,7 +493,8 @@ void MakeIteratorNode::codegen(Decision *d) { llvm::Value *arg = d->load(std::make_pair(collection, collectionType)); args.push_back(arg); types.push_back(arg->getType()); - llvm::Type *sretType = getTypeByName(d->Module, "iter"); + llvm::Type *sretType + = llvm::StructType::getTypeByName(d->Module->getContext(), "iter"); llvm::Value *AllocSret = allocateTerm(sretType, d->CurrentBlock, "koreAllocAlwaysGC"); AllocSret->setName(name.substr(0, max_name_length)); @@ -504,13 +506,8 @@ void MakeIteratorNode::codegen(Decision *d) { llvm::Function *func = getOrInsertFunction(d->Module, hookName, funcType); auto call = llvm::CallInst::Create(func, args, "", d->CurrentBlock); setDebugLoc(call); -#if __clang_major__ >= 12 llvm::Attribute sretAttr = llvm::Attribute::get(d->Ctx, llvm::Attribute::StructRet, sretType); -#else - llvm::Attribute sretAttr - = llvm::Attribute::get(d->Ctx, llvm::Attribute::StructRet); -#endif func->arg_begin()->addAttr(sretAttr); call->addParamAttr(0, sretAttr); d->store(std::make_pair(name, type), AllocSret); @@ -777,8 +774,8 @@ void abortWhenStuck( symbol = d->getAllSymbols().at(Out.str()); auto BlockType = getBlockType(Module, d, symbol); llvm::Value *Ptr; - auto BlockPtr - = llvm::PointerType::getUnqual(getTypeByName(Module, BLOCK_STRUCT)); + auto BlockPtr = llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(Module->getContext(), BLOCK_STRUCT)); if (symbol->getArguments().empty()) { Ptr = llvm::ConstantExpr::getIntToPtr( llvm::ConstantInt::get( @@ -953,7 +950,8 @@ std::pair, llvm::BasicBlock *> stepFunctionHeader( case SortCategory::Int: case SortCategory::Float: elements.push_back(llvm::ConstantStruct::get( - getTypeByName(module, LAYOUTITEM_STRUCT), + llvm::StructType::getTypeByName( + module->getContext(), LAYOUTITEM_STRUCT), llvm::ConstantInt::get( llvm::Type::getInt64Ty(module->getContext()), i++ * 8), llvm::ConstantInt::get( @@ -967,7 +965,9 @@ std::pair, llvm::BasicBlock *> stepFunctionHeader( } auto layoutArr = llvm::ConstantArray::get( llvm::ArrayType::get( - getTypeByName(module, LAYOUTITEM_STRUCT), elements.size()), + llvm::StructType::getTypeByName( + module->getContext(), LAYOUTITEM_STRUCT), + elements.size()), elements); auto layout = module->getOrInsertGlobal( "layout_item_rule_" + std::to_string(ordinal), layoutArr->getType()); @@ -976,8 +976,9 @@ std::pair, llvm::BasicBlock *> stepFunctionHeader( if (!globalVar->hasInitializer()) { globalVar->setInitializer(layoutArr); } - auto ptrTy = llvm::PointerType::getUnqual( - llvm::ArrayType::get(getTypeByName(module, LAYOUTITEM_STRUCT), 0)); + auto ptrTy = llvm::PointerType::getUnqual(llvm::ArrayType::get( + llvm::StructType::getTypeByName(module->getContext(), LAYOUTITEM_STRUCT), + 0)); auto koreCollect = getOrInsertFunction( module, "koreCollect", llvm::FunctionType::get( diff --git a/lib/codegen/DecisionParser.cpp b/lib/codegen/DecisionParser.cpp index 56078f6a1..864d21805 100644 --- a/lib/codegen/DecisionParser.cpp +++ b/lib/codegen/DecisionParser.cpp @@ -218,8 +218,9 @@ class DTPreprocessor { return MakeIteratorNode::Create( name, type, name + "_iter", - llvm::PointerType::getUnqual(getTypeByName(mod, "iter")), function, - child); + llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(mod->getContext(), "iter")), + function, child); } DecisionNode *iterNext(yaml_node_t *node) { @@ -231,7 +232,9 @@ class DTPreprocessor { auto child = (*this)(get(node, "next")); return IterNextNode::Create( - iterator, llvm::PointerType::getUnqual(getTypeByName(mod, "iter")), + iterator, + llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(mod->getContext(), "iter")), name, type, function, child); } diff --git a/lib/codegen/EmitConfigParser.cpp b/lib/codegen/EmitConfigParser.cpp index 18f7044e2..d8341440f 100644 --- a/lib/codegen/EmitConfigParser.cpp +++ b/lib/codegen/EmitConfigParser.cpp @@ -237,7 +237,8 @@ static std::pair getHeader( static void emitGetBlockHeaderForSymbol(KOREDefinition *def, llvm::Module *mod) { emitDataForSymbol( - "getBlockHeaderForSymbol", getTypeByName(mod, BLOCKHEADER_STRUCT), + "getBlockHeaderForSymbol", + llvm::StructType::getTypeByName(mod->getContext(), BLOCKHEADER_STRUCT), getForwardDecl(BLOCKHEADER_STRUCT), def, mod, false, getHeader); } @@ -564,7 +565,8 @@ static void emitGetToken(KOREDefinition *definition, llvm::Module *module) { break; } case SortCategory::Float: { - llvm::Type *Float = getTypeByName(module, FLOAT_STRUCT); + llvm::Type *Float + = llvm::StructType::getTypeByName(module->getContext(), FLOAT_STRUCT); llvm::Value *Term = allocateTerm(Float, CaseBlock, "koreAllocFloating"); llvm::Function *InitFloat = getOrInsertFunction( module, "init_float", llvm::Type::getVoidTy(Ctx), @@ -599,7 +601,8 @@ static void emitGetToken(KOREDefinition *definition, llvm::Module *module) { phiStr->addIncoming(func->arg_begin() + 2, CaseBlock); phiStr->addIncoming(Pruned, IfIsPlus); CaseBlock = ElseNoPlus; - llvm::Type *Int = getTypeByName(module, INT_STRUCT); + llvm::Type *Int + = llvm::StructType::getTypeByName(module->getContext(), INT_STRUCT); llvm::Value *Term = allocateTerm(Int, CaseBlock, "koreAllocInteger"); llvm::Function *MpzInitSet = getOrInsertFunction( module, "__gmpz_init_set_str", llvm::Type::getInt32Ty(Ctx), @@ -628,7 +631,8 @@ static void emitGetToken(KOREDefinition *definition, llvm::Module *module) { } CurrentBlock->setName("symbol"); CurrentBlock->insertInto(func); - auto StringType = getTypeByName(module, STRING_STRUCT); + auto StringType + = llvm::StructType::getTypeByName(module->getContext(), STRING_STRUCT); auto Len = llvm::BinaryOperator::Create( llvm::Instruction::Add, func->arg_begin() + 1, llvm::ConstantExpr::getSizeOf(StringType), "", CurrentBlock); @@ -1137,12 +1141,17 @@ static llvm::Constant *getLayoutData( module, BlockType, i++); //llvm::ConstantExpr::getOffsetOf(BlockType, i++); elements.push_back(llvm::ConstantStruct::get( - getTypeByName(module, LAYOUTITEM_STRUCT), offset, + llvm::StructType::getTypeByName( + module->getContext(), LAYOUTITEM_STRUCT), + offset, llvm::ConstantInt::get( llvm::Type::getInt16Ty(Ctx), (int)cat.cat + cat.bits))); } auto Arr = llvm::ConstantArray::get( - llvm::ArrayType::get(getTypeByName(module, LAYOUTITEM_STRUCT), len), + llvm::ArrayType::get( + llvm::StructType::getTypeByName( + module->getContext(), LAYOUTITEM_STRUCT), + len), elements); auto global = module->getOrInsertGlobal( "layout_item_" + std::to_string(layout), Arr->getType()); @@ -1156,14 +1165,15 @@ static llvm::Constant *getLayoutData( auto Ptr = llvm::ConstantExpr::getInBoundsGetElementPtr( Arr->getType(), globalVar, indices); std::string name = "layout_" + std::to_string(layout); - auto global2 - = module->getOrInsertGlobal(name, getTypeByName(module, LAYOUT_STRUCT)); + auto global2 = module->getOrInsertGlobal( + name, + llvm::StructType::getTypeByName(module->getContext(), LAYOUT_STRUCT)); llvm::GlobalVariable *globalVar2 = llvm::dyn_cast(global2); initDebugGlobal(name, getForwardDecl(LAYOUT_STRUCT), globalVar2); if (!globalVar2->hasInitializer()) { globalVar2->setInitializer(llvm::ConstantStruct::get( - getTypeByName(module, LAYOUT_STRUCT), + llvm::StructType::getTypeByName(module->getContext(), LAYOUT_STRUCT), llvm::ConstantInt::get(llvm::Type::getInt8Ty(Ctx), len), Ptr)); } return globalVar2; @@ -1180,7 +1190,8 @@ static void emitLayouts(KOREDefinition *definition, llvm::Module *module) { auto func = llvm::dyn_cast(getOrInsertFunction( module, "getLayoutData", llvm::FunctionType::get( - llvm::PointerType::getUnqual(getTypeByName(module, LAYOUT_STRUCT)), + llvm::PointerType::getUnqual(llvm::StructType::getTypeByName( + module->getContext(), LAYOUT_STRUCT)), argTypes, false))); initDebugFunction( "getLayoutData", "getLayoutData", @@ -1194,7 +1205,8 @@ static void emitLayouts(KOREDefinition *definition, llvm::Module *module) { auto Switch = llvm::SwitchInst::Create( func->arg_begin(), stuck, layouts.size(), EntryBlock); auto Phi = llvm::PHINode::Create( - llvm::PointerType::getUnqual(getTypeByName(module, LAYOUT_STRUCT)), + llvm::PointerType::getUnqual( + llvm::StructType::getTypeByName(module->getContext(), LAYOUT_STRUCT)), layouts.size(), "phi", MergeBlock); for (auto iter = layouts.begin(); iter != layouts.end(); ++iter) { auto entry = *iter; diff --git a/lib/codegen/Util.cpp b/lib/codegen/Util.cpp index a4f198758..3e92c520f 100644 --- a/lib/codegen/Util.cpp +++ b/lib/codegen/Util.cpp @@ -22,23 +22,4 @@ llvm::Function *koreHeapAlloc(std::string name, llvm::Module *module) { return getOrInsertFunction(module, name, allocType); } -llvm::Function *castToFunctionOrAbort(llvm::Value *value) { - llvm::Function *func = llvm::dyn_cast(value); - if (!func) { - value->print(llvm::errs()); - abort(); - } - return func; -} - -llvm::StructType *getTypeByName(llvm::Module *module, std::string name) { - llvm::StructType *t; -#if LLVM_VERSION_MAJOR >= 12 - t = llvm::StructType::getTypeByName(module->getContext(), name); -#else - t = module->getTypeByName(name); -#endif - return t; -} - } // namespace kllvm