mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 23:20:40 +03:00
Fix StringRef conversion for LLVM 11 (777180a32b61070a10dd330b4f038bf24e916af1) (#3305)
This commit is contained in:
parent
97e0d978ee
commit
0a007a55f8
13 changed files with 31 additions and 28 deletions
|
@ -96,7 +96,7 @@ bool ConfigFile::locate(std::string &pathstr) {
|
||||||
{ \
|
{ \
|
||||||
sys::path::append(p, filename); \
|
sys::path::append(p, filename); \
|
||||||
if (sys::fs::exists(p.str())) { \
|
if (sys::fs::exists(p.str())) { \
|
||||||
pathstr = p.str(); \
|
pathstr = {p.data(), p.size()}; \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,29 +37,29 @@ const string &exe_path::getExePath() {
|
||||||
|
|
||||||
string exe_path::getBinDir() {
|
string exe_path::getBinDir() {
|
||||||
assert(!exePath.empty());
|
assert(!exePath.empty());
|
||||||
return path::parent_path(exePath);
|
return string(path::parent_path(exePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
string exe_path::getBaseDir() {
|
string exe_path::getBaseDir() {
|
||||||
string binDir = getBinDir();
|
string binDir = getBinDir();
|
||||||
assert(!binDir.empty());
|
assert(!binDir.empty());
|
||||||
return path::parent_path(binDir);
|
return string(path::parent_path(binDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
string exe_path::getLibDir() {
|
string exe_path::getLibDir() {
|
||||||
llvm::SmallString<128> r(getBaseDir());
|
llvm::SmallString<128> r(getBaseDir());
|
||||||
path::append(r, "lib" LDC_LIBDIR_SUFFIX);
|
path::append(r, "lib" LDC_LIBDIR_SUFFIX);
|
||||||
return r.str();
|
return {r.data(), r.size()};
|
||||||
}
|
}
|
||||||
|
|
||||||
string exe_path::prependBinDir(const llvm::Twine &suffix) {
|
string exe_path::prependBinDir(const llvm::Twine &suffix) {
|
||||||
llvm::SmallString<128> r(getBinDir());
|
llvm::SmallString<128> r(getBinDir());
|
||||||
path::append(r, suffix);
|
path::append(r, suffix);
|
||||||
return r.str();
|
return {r.data(), r.size()};
|
||||||
}
|
}
|
||||||
|
|
||||||
string exe_path::prependLibDir(const llvm::Twine &suffix) {
|
string exe_path::prependLibDir(const llvm::Twine &suffix) {
|
||||||
llvm::SmallString<128> r(getLibDir());
|
llvm::SmallString<128> r(getLibDir());
|
||||||
path::append(r, suffix);
|
path::append(r, suffix);
|
||||||
return r.str();
|
return {r.data(), r.size()};
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,7 @@ void appendFullLibPathCandidates(std::vector<std::string> &paths,
|
||||||
for (const char *dir : ConfigFile::instance.libDirs()) {
|
for (const char *dir : ConfigFile::instance.libDirs()) {
|
||||||
llvm::SmallString<128> candidate(dir);
|
llvm::SmallString<128> candidate(dir);
|
||||||
llvm::sys::path::append(candidate, filename);
|
llvm::sys::path::append(candidate, filename);
|
||||||
paths.push_back(candidate.str());
|
paths.emplace_back(candidate.data(), candidate.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// for backwards compatibility
|
// for backwards compatibility
|
||||||
|
@ -310,7 +310,7 @@ void ArgsBuilder::addASanLinkFlags(const llvm::Triple &triple) {
|
||||||
// Add the path to the resource dir to rpath to support using the shared
|
// Add the path to the resource dir to rpath to support using the shared
|
||||||
// lib from the default location without copying.
|
// lib from the default location without copying.
|
||||||
args.push_back("-rpath");
|
args.push_back("-rpath");
|
||||||
args.push_back(llvm::sys::path::parent_path(filepath));
|
args.push_back(std::string(llvm::sys::path::parent_path(filepath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -508,7 +508,7 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
args.push_back("-o");
|
args.push_back("-o");
|
||||||
args.push_back(outputPath);
|
args.push_back(std::string(outputPath));
|
||||||
|
|
||||||
addSanitizers(*global.params.targetTriple);
|
addSanitizers(*global.params.targetTriple);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ void addLibIfFound(std::vector<std::string> &args, const llvm::Twine &name) {
|
||||||
llvm::SmallString<128> candidate(dir);
|
llvm::SmallString<128> candidate(dir);
|
||||||
llvm::sys::path::append(candidate, name);
|
llvm::sys::path::append(candidate, name);
|
||||||
if (llvm::sys::fs::exists(candidate)) {
|
if (llvm::sys::fs::exists(candidate)) {
|
||||||
args.push_back(candidate.str());
|
args.emplace_back(candidate.data(), candidate.size());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ static std::string getOutputName() {
|
||||||
auto EC = llvm::sys::fs::createTemporaryFile(
|
auto EC = llvm::sys::fs::createTemporaryFile(
|
||||||
result, extension ? extension : "", tempFilename);
|
result, extension ? extension : "", tempFilename);
|
||||||
if (!EC)
|
if (!EC)
|
||||||
result = tempFilename.str();
|
result = {tempFilename.data(), tempFilename.size()};
|
||||||
} else if (extension) {
|
} else if (extension) {
|
||||||
result += '.';
|
result += '.';
|
||||||
result += extension;
|
result += extension;
|
||||||
|
|
|
@ -109,7 +109,7 @@ void printVersion(llvm::raw_ostream &OS) {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
OS << " Default target: " << llvm::sys::getDefaultTargetTriple() << "\n";
|
OS << " Default target: " << llvm::sys::getDefaultTargetTriple() << "\n";
|
||||||
std::string CPU = llvm::sys::getHostCPUName();
|
std::string CPU(llvm::sys::getHostCPUName());
|
||||||
if (CPU == "generic" || env::has("SOURCE_DATE_EPOCH")) {
|
if (CPU == "generic" || env::has("SOURCE_DATE_EPOCH")) {
|
||||||
// Env variable SOURCE_DATE_EPOCH indicates that a reproducible build is
|
// Env variable SOURCE_DATE_EPOCH indicates that a reproducible build is
|
||||||
// wanted. Don't print the actual host CPU in such an environment to aid
|
// wanted. Don't print the actual host CPU in such an environment to aid
|
||||||
|
@ -564,7 +564,7 @@ void fixupUClibcEnv() {
|
||||||
llvm::Triple triple(mTargetTriple);
|
llvm::Triple triple(mTargetTriple);
|
||||||
if (triple.getEnvironmentName().find("uclibc") != 0)
|
if (triple.getEnvironmentName().find("uclibc") != 0)
|
||||||
return;
|
return;
|
||||||
std::string envName = triple.getEnvironmentName();
|
std::string envName(triple.getEnvironmentName());
|
||||||
envName.replace(0, 6, "gnu");
|
envName.replace(0, 6, "gnu");
|
||||||
triple.setEnvironmentName(envName);
|
triple.setEnvironmentName(envName);
|
||||||
mTargetTriple = triple.normalize();
|
mTargetTriple = triple.normalize();
|
||||||
|
|
|
@ -162,7 +162,7 @@ static std::string getX86TargetCPU(const llvm::Triple &triple) {
|
||||||
static std::string getARMTargetCPU(const llvm::Triple &triple) {
|
static std::string getARMTargetCPU(const llvm::Triple &triple) {
|
||||||
auto defaultCPU = llvm::ARM::getDefaultCPU(triple.getArchName());
|
auto defaultCPU = llvm::ARM::getDefaultCPU(triple.getArchName());
|
||||||
if (!defaultCPU.empty())
|
if (!defaultCPU.empty())
|
||||||
return defaultCPU;
|
return std::string(defaultCPU);
|
||||||
|
|
||||||
// Return the most base CPU with thumb interworking supported by LLVM.
|
// Return the most base CPU with thumb interworking supported by LLVM.
|
||||||
return (triple.getEnvironment() == llvm::Triple::GNUEABIHF) ? "arm1176jzf-s"
|
return (triple.getEnvironment() == llvm::Triple::GNUEABIHF) ? "arm1176jzf-s"
|
||||||
|
@ -172,7 +172,7 @@ static std::string getARMTargetCPU(const llvm::Triple &triple) {
|
||||||
static std::string getAArch64TargetCPU(const llvm::Triple &triple) {
|
static std::string getAArch64TargetCPU(const llvm::Triple &triple) {
|
||||||
auto defaultCPU = llvm::AArch64::getDefaultCPU(triple.getArchName());
|
auto defaultCPU = llvm::AArch64::getDefaultCPU(triple.getArchName());
|
||||||
if (!defaultCPU.empty())
|
if (!defaultCPU.empty())
|
||||||
return defaultCPU;
|
return std::string(defaultCPU);
|
||||||
|
|
||||||
return "generic";
|
return "generic";
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,7 +362,7 @@ void writeModule(llvm::Module *m, const char *filename) {
|
||||||
llvm::SmallString<128> buffer(filename);
|
llvm::SmallString<128> buffer(filename);
|
||||||
llvm::sys::path::replace_extension(buffer,
|
llvm::sys::path::replace_extension(buffer,
|
||||||
llvm::StringRef(ext.ptr, ext.length));
|
llvm::StringRef(ext.ptr, ext.length));
|
||||||
return buffer.str();
|
return {buffer.data(), buffer.size()};
|
||||||
};
|
};
|
||||||
|
|
||||||
// write LLVM bitcode
|
// write LLVM bitcode
|
||||||
|
@ -433,7 +433,7 @@ void writeModule(llvm::Module *m, const char *filename) {
|
||||||
if (!global.params.output_s) {
|
if (!global.params.output_s) {
|
||||||
llvm::SmallString<16> buffer;
|
llvm::SmallString<16> buffer;
|
||||||
llvm::sys::fs::createUniqueFile("ldc-%%%%%%%.s", buffer);
|
llvm::sys::fs::createUniqueFile("ldc-%%%%%%%.s", buffer);
|
||||||
spath = buffer.str();
|
spath = {buffer.data(), buffer.size()};
|
||||||
} else {
|
} else {
|
||||||
spath = replaceExtensionWith(global.s_ext);
|
spath = replaceExtensionWith(global.s_ext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "dmd/root/ctfloat.h"
|
#include "dmd/root/ctfloat.h"
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
|
#include "llvm/Support/Error.h"
|
||||||
|
|
||||||
using llvm::APFloat;
|
using llvm::APFloat;
|
||||||
|
|
||||||
|
|
|
@ -204,10 +204,13 @@ void fixRtModule(llvm::Module &newModule,
|
||||||
// function, ignore
|
// function, ignore
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
assert(!contains(thunkVar2func, it.second.thunkVar->getName()));
|
assert(
|
||||||
thunkVar2func.insert({it.second.thunkVar->getName(), it.first->getName()});
|
!contains(thunkVar2func, std::string(it.second.thunkVar->getName())));
|
||||||
thunkFun2func.insert({it.second.thunkFunc->getName(), it.first->getName()});
|
thunkVar2func.emplace(std::string(it.second.thunkVar->getName()),
|
||||||
externalFuncs.insert(it.first->getName());
|
it.first->getName());
|
||||||
|
thunkFun2func.emplace(std::string(it.second.thunkFunc->getName()),
|
||||||
|
it.first->getName());
|
||||||
|
externalFuncs.insert(std::string(it.first->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace call to thunks in jitted code with direct calls to functions
|
// Replace call to thunks in jitted code with direct calls to functions
|
||||||
|
@ -216,7 +219,7 @@ void fixRtModule(llvm::Module &newModule,
|
||||||
for (auto &op : instr.operands()) {
|
for (auto &op : instr.operands()) {
|
||||||
auto val = op.get();
|
auto val = op.get();
|
||||||
if (auto callee = llvm::dyn_cast<llvm::Function>(val)) {
|
if (auto callee = llvm::dyn_cast<llvm::Function>(val)) {
|
||||||
auto it = thunkFun2func.find(callee->getName());
|
auto it = thunkFun2func.find(std::string(callee->getName()));
|
||||||
if (thunkFun2func.end() != it) {
|
if (thunkFun2func.end() != it) {
|
||||||
auto realFunc = newModule.getFunction(it->second);
|
auto realFunc = newModule.getFunction(it->second);
|
||||||
assert(nullptr != realFunc);
|
assert(nullptr != realFunc);
|
||||||
|
@ -257,14 +260,14 @@ void removeFunctionsTargets(IRState *irs, llvm::Module &module) {
|
||||||
std::unordered_map<std::string, IrFunction *> funcMap;
|
std::unordered_map<std::string, IrFunction *> funcMap;
|
||||||
for (auto &&fun : irs->targetCpuOrFeaturesOverridden) {
|
for (auto &&fun : irs->targetCpuOrFeaturesOverridden) {
|
||||||
assert(nullptr != fun);
|
assert(nullptr != fun);
|
||||||
funcMap.insert({fun->getLLVMFunc()->getName(), fun});
|
funcMap.emplace(std::string(fun->getLLVMFunc()->getName()), fun);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &&fun : module.functions()) {
|
for (auto &&fun : module.functions()) {
|
||||||
// Remove 'target-cpu' and 'target-features' attributes from all
|
// Remove 'target-cpu' and 'target-features' attributes from all
|
||||||
// functions except when they are set explicitly by user.
|
// functions except when they are set explicitly by user.
|
||||||
// They will be set again by jitting lib to jit host values
|
// They will be set again by jitting lib to jit host values
|
||||||
auto it = funcMap.find(fun.getName());
|
auto it = funcMap.find(std::string(fun.getName()));
|
||||||
if (funcMap.end() != it) {
|
if (funcMap.end() != it) {
|
||||||
auto irFunc = it->second;
|
auto irFunc = it->second;
|
||||||
if (!irFunc->targetCpuOverridden) {
|
if (!irFunc->targetCpuOverridden) {
|
||||||
|
|
|
@ -196,7 +196,7 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
|
||||||
std::unique_ptr<llvm::Module> m =
|
std::unique_ptr<llvm::Module> m =
|
||||||
llvm::parseAssemblyString(stream.str().c_str(), err, gIR->context());
|
llvm::parseAssemblyString(stream.str().c_str(), err, gIR->context());
|
||||||
|
|
||||||
std::string errstr = err.getMessage();
|
std::string errstr(err.getMessage());
|
||||||
if (!errstr.empty()) {
|
if (!errstr.empty()) {
|
||||||
error(tinst->loc,
|
error(tinst->loc,
|
||||||
"can't parse inline LLVM IR:\n`%s`\n%s\n%s\nThe input string "
|
"can't parse inline LLVM IR:\n`%s`\n%s\n%s\nThe input string "
|
||||||
|
|
|
@ -310,7 +310,7 @@ void applyAttrTarget(StructLiteralExp *sle, llvm::Function *func,
|
||||||
|
|
||||||
if (func->hasFnAttribute("target-features")) {
|
if (func->hasFnAttribute("target-features")) {
|
||||||
auto attr = func->getFnAttribute("target-features");
|
auto attr = func->getFnAttribute("target-features");
|
||||||
features.push_back(attr.getValueAsString());
|
features.push_back(std::string(attr.getValueAsString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::SmallVector<llvm::StringRef, 4> fragments;
|
llvm::SmallVector<llvm::StringRef, 4> fragments;
|
||||||
|
|
|
@ -92,8 +92,7 @@ void enumModules(const RtCompileModuleList *modlist_head,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string decorate(const std::string &name,
|
std::string decorate(llvm::StringRef name, const llvm::DataLayout &datalayout) {
|
||||||
const llvm::DataLayout &datalayout) {
|
|
||||||
assert(!name.empty());
|
assert(!name.empty());
|
||||||
llvm::SmallVector<char, 64> ret;
|
llvm::SmallVector<char, 64> ret;
|
||||||
llvm::Mangler::getNameWithPrefix(ret, name, datalayout);
|
llvm::Mangler::getNameWithPrefix(ret, name, datalayout);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue