Skip to content

Commit

Permalink
Merge pull request #38092 from JuliaLang/vc/llvm12
Browse files Browse the repository at this point in the history
[LLVM] Update to API changes in LLVM 12
  • Loading branch information
vchuravy authored Oct 21, 2020
2 parents 7ac9ac3 + 5f7d06a commit e3da30c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/abi_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ Type *get_llvm_vectype(jl_datatype_t *dt) const
assert(nfields > 0);
if (nfields < 2)
return nullptr;
#if JL_LLVM_VERSION >= 120000
static Type *T_vec64 = FixedVectorType::get(T_int32, 2);
static Type *T_vec128 = FixedVectorType::get(T_int32, 4);
#else
static Type *T_vec64 = VectorType::get(T_int32, 2);
static Type *T_vec128 = VectorType::get(T_int32, 4);
#endif
Type *lltype;
// Short vector should be either 8 bytes or 16 bytes.
// Note that there are only two distinct fundamental types for
Expand Down
4 changes: 4 additions & 0 deletions src/abi_ppc64le.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret) const override
jl_datatype_t *vecty = (jl_datatype_t*)jl_field_type(ty0, 0);
assert(jl_is_datatype(vecty) && vecty->name == jl_vecelement_typename);
Type *ety = bitstype_to_llvm(jl_tparam0(vecty));
#if JL_LLVM_VERSION >= 120000
Type *vty = FixedVectorType::get(ety, jl_datatype_nfields(ty0));
#else
Type *vty = VectorType::get(ety, jl_datatype_nfields(ty0));
#endif
return ArrayType::get(vty, hfa);
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,12 @@ static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, jl_value_t *jt, jl_
// and always end with an Int8 (selector byte).
// We may need to insert padding first to get to the right offset
if (al > MAX_ALIGN) {
Type *AlignmentType = ArrayType::get(VectorType::get(T_int8, al), 0);
Type *AlignmentType;
#if JL_LLVM_VERSION >= 120000
AlignmentType = ArrayType::get(FixedVectorType::get(T_int8, al), 0);
#else
AlignmentType = ArrayType::get(VectorType::get(T_int8, al), 0);
#endif
latypes.push_back(AlignmentType);
al = MAX_ALIGN;
}
Expand Down Expand Up @@ -664,7 +669,11 @@ static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, jl_value_t *jt, jl_
}
else if (isarray && !type_is_ghost(lasttype)) {
if (isTuple && isvector && jl_special_vector_alignment(ntypes, jlasttype) != 0)
#if JL_LLVM_VERSION >= 120000
struct_decl = FixedVectorType::get(lasttype, ntypes);
#else
struct_decl = VectorType::get(lasttype, ntypes);
#endif
else if (isTuple || !llvmcall)
struct_decl = ArrayType::get(lasttype, ntypes);
else
Expand Down Expand Up @@ -1364,8 +1373,15 @@ std::vector<unsigned> first_ptr(Type *T)
uint64_t num_elements;
if (auto *AT = dyn_cast<ArrayType>(T))
num_elements = AT->getNumElements();
else
num_elements = cast<VectorType>(T)->getNumElements();
else {
VectorType *VT = cast<VectorType>(T);
#if JL_LLVM_VERSION >= 120000
ElementCount EC = VT->getElementCount();
num_elements = EC.getKnownMinValue();
#else
num_elements = VT->getNumElements();
#endif
}
if (num_elements == 0)
return {};
}
Expand Down
24 changes: 24 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
// for configuration options
#include <llvm/Support/PrettyStackTrace.h>
#include <llvm/Support/CommandLine.h>
#if JL_LLVM_VERSION >= 120000
#include <llvm/Support/Process.h>
#endif

#include <llvm/IR/InlineAsm.h>
#if defined(_CPU_ARM_) || defined(_CPU_AARCH64_)
Expand Down Expand Up @@ -7643,7 +7646,24 @@ extern "C" void jl_init_llvm(void)
const char *const argv_avoidsfb[] = {"", "-x86-disable-avoid-SFB"}; // llvm bug 41629, see https://gist.github.com/vtjnash/192cab72a6cfc00256ff118238163b55
cl::ParseCommandLineOptions(sizeof(argv_avoidsfb)/sizeof(argv_avoidsfb[0]), argv_avoidsfb, "disable-avoidsfb\n");
#endif
#if JL_LLVM_VERSION >= 120000
// https://reviews.llvm.org/rGc068e9c8c123e7f8c8f3feb57245a012ccd09ccf
Optional<std::string> envValue = sys::Process::GetEnv("JULIA_LLVM_ARGS");
if (envValue) {
SmallVector<const char *, 20> newArgv;
BumpPtrAllocator A;
StringSaver Saver(A);
newArgv.push_back(Saver.save("Julia").data());

// Parse the value of the environment variable into a "command line"
// and hand it off to ParseCommandLineOptions().
cl::TokenizeGNUCommandLine(*envValue, Saver, newArgv);
int newArgc = static_cast<int>(newArgv.size());
cl::ParseCommandLineOptions(newArgc, &newArgv[0]);
}
#else
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");
#endif

// if the patch adding this option has been applied, lower its limit to provide
// better DAGCombiner performance.
Expand Down Expand Up @@ -7682,7 +7702,11 @@ extern "C" void jl_init_llvm(void)
// This is the only way I can find to print the help message once.
// It'll be nice if we can iterate through the features and print our own help
// message...
#if JL_LLVM_VERSION >= 120000
MSTI->setDefaultFeatures("help", "", "");
#else
MSTI->setDefaultFeatures("help", "");
#endif
}
}
// Package up features to be passed to target/subtarget
Expand Down

0 comments on commit e3da30c

Please sign in to comment.