Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes required for Solang #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace clang {
namespace targets {

class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
bool HasSolanaFeature = false;
static const Builtin::Info BuiltinInfo[];

public:
Expand All @@ -34,21 +35,20 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
IntMaxType = SignedLong;
Int64Type = SignedLong;
RegParmMax = 5;
auto isSolana = false;
for (auto& it : Opts.FeaturesAsWritten) {
if (it == "+solana") {
isSolana = true;
HasSolanaFeature = true;
break;
}
}
if (Triple.getArch() == llvm::Triple::bpfeb) {
if (isSolana) {
if (HasSolanaFeature) {
resetDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128");
} else {
resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
}
} else {
if (isSolana) {
if (HasSolanaFeature) {
resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
} else {
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
Expand Down Expand Up @@ -112,6 +112,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
StringRef CPUName(Name);
return isValidCPUName(CPUName);
}

bool hasExtIntType() const override { return HasSolanaFeature; }
};
} // namespace targets
} // namespace clang
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CodeGen/ext-int-cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// RUN: %clang_cc1 -triple arm64_32-apple-ios -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
// RUN: %clang_cc1 -triple arm64_32-apple-ios -target-abi darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64DARWIN
// RUN: %clang_cc1 -triple arm -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=ARM
// RUN: %clang_cc1 -triple bpf -target-feature +solana -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=BPF

// Make sure 128 and 64 bit versions are passed like integers, and that >128
// is passed indirectly.
Expand Down Expand Up @@ -59,6 +60,7 @@ void ParamPassing(_ExtInt(129) a, _ExtInt(128) b, _ExtInt(64) c) {}
// AARCH64: define void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128 %{{.+}}, i64 %{{.+}})
// AARCH64DARWIN: define void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128 %{{.+}}, i64 %{{.+}})
// ARM: define arm_aapcscc void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128* byval(i128) align 8 %{{.+}}, i64 %{{.+}})
// BPF: define void @ParamPassing(i129* byval(i129) align 8 %{{.+}}, i128 %{{.+}}, i64 %{{.+}})

void ParamPassing2(_ExtInt(129) a, _ExtInt(127) b, _ExtInt(63) c) {}
// LIN64: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i64 %{{.+}}, i64 %{{.+}}, i64 %{{.+}})
Expand Down Expand Up @@ -88,6 +90,7 @@ void ParamPassing2(_ExtInt(129) a, _ExtInt(127) b, _ExtInt(63) c) {}
// AARCH64: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127 %{{.+}}, i63 %{{.+}})
// AARCH64DARWIN: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127 %{{.+}}, i63 %{{.+}})
// ARM: define arm_aapcscc void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127* byval(i127) align 8 %{{.+}}, i63 %{{.+}})
// BPF: define void @ParamPassing2(i129* byval(i129) align 8 %{{.+}}, i127 %{{.+}}, i63 %{{.+}})

// Make sure we follow the signext rules for promotable integer types.
void ParamPassing3(_ExtInt(15) a, _ExtInt(31) b) {}
Expand Down Expand Up @@ -118,6 +121,7 @@ void ParamPassing3(_ExtInt(15) a, _ExtInt(31) b) {}
// AARCH64: define void @ParamPassing3(i15 %{{.+}}, i31 %{{.+}})
// AARCH64DARWIN: define void @ParamPassing3(i15 signext %{{.+}}, i31 signext %{{.+}})
// ARM: define arm_aapcscc void @ParamPassing3(i15 signext %{{.+}}, i31 signext %{{.+}})
// BPF: define void @ParamPassing3(i15 signext %{{.+}}, i31 signext %{{.+}})

_ExtInt(63) ReturnPassing(){}
// LIN64: define i64 @ReturnPassing(
Expand Down Expand Up @@ -147,6 +151,7 @@ _ExtInt(63) ReturnPassing(){}
// AARCH64: define i63 @ReturnPassing(
// AARCH64DARWIN: define i63 @ReturnPassing(
// ARM: define arm_aapcscc i63 @ReturnPassing(
// BPF: define i63 @ReturnPassing(

_ExtInt(64) ReturnPassing2(){}
// LIN64: define i64 @ReturnPassing2(
Expand Down Expand Up @@ -176,6 +181,7 @@ _ExtInt(64) ReturnPassing2(){}
// AARCH64: define i64 @ReturnPassing2(
// AARCH64DARWIN: define i64 @ReturnPassing2(
// ARM: define arm_aapcscc i64 @ReturnPassing2(
// BPF: define i64 @ReturnPassing2(

_ExtInt(127) ReturnPassing3(){}
// LIN64: define { i64, i64 } @ReturnPassing3(
Expand Down Expand Up @@ -207,6 +213,7 @@ _ExtInt(127) ReturnPassing3(){}
// AARCH64: define i127 @ReturnPassing3(
// AARCH64DARWIN: define i127 @ReturnPassing3(
// ARM: define arm_aapcscc void @ReturnPassing3(i127* noalias sret
// BPF: define i127 @ReturnPassing3(

_ExtInt(128) ReturnPassing4(){}
// LIN64: define { i64, i64 } @ReturnPassing4(
Expand Down Expand Up @@ -236,6 +243,7 @@ _ExtInt(128) ReturnPassing4(){}
// AARCH64: define i128 @ReturnPassing4(
// AARCH64DARWIN: define i128 @ReturnPassing4(
// ARM: define arm_aapcscc void @ReturnPassing4(i128* noalias sret
// BPF: define i128 @ReturnPassing4(

_ExtInt(129) ReturnPassing5(){}
// LIN64: define void @ReturnPassing5(i129* noalias sret
Expand Down Expand Up @@ -265,6 +273,7 @@ _ExtInt(129) ReturnPassing5(){}
// AARCH64: define void @ReturnPassing5(i129* noalias sret
// AARCH64DARWIN: define void @ReturnPassing5(i129* noalias sret
// ARM: define arm_aapcscc void @ReturnPassing5(i129* noalias sret
// BPF: define void @ReturnPassing5(i129* noalias sret

// SparcV9 is odd in that it has a return-size limit of 256, not 128 or 64
// like other platforms, so test to make sure this behavior will still work.
Expand Down
7 changes: 0 additions & 7 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,13 +1110,6 @@ Optional<std::string> getReproduceFile(const opt::InputArgList &args) {
void LinkerDriver::link(ArrayRef<const char *> argsArr) {
ScopedTimer rootTimer(Timer::root());

// Needed for LTO.
InitializeAllTargetInfos();
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmParsers();
InitializeAllAsmPrinters();

// If the first command line argument is "/lib", link.exe acts like lib.exe.
// We call our own implementation of lib.exe that understands bitcode files.
if (argsArr.size() > 1 && StringRef(argsArr[1]).equals_lower("/lib")) {
Expand Down
12 changes: 0 additions & 12 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,6 @@ void LinkerDriver::addLibrary(StringRef name) {
error("unable to find library -l" + name);
}

// This function is called on startup. We need this for LTO since
// LTO calls LLVM functions to compile bitcode files to native code.
// Technically this can be delayed until we read bitcode files, but
// we don't bother to do lazily because the initialization is fast.
static void initLLVM() {
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
}

// Some command line options or some combinations of them are not allowed.
// This function checks for such errors.
static void checkOptions() {
Expand Down Expand Up @@ -518,7 +507,6 @@ void LinkerDriver::main(ArrayRef<const char *> argsArr) {
{
llvm::TimeTraceScope timeScope("ExecuteLinker");

initLLVM();
createFiles(args);
if (errorCount())
return;
Expand Down
13 changes: 13 additions & 0 deletions lld/tools/lld/lld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/TargetSelect.h"
#include <cstdlib>

using namespace lld;
Expand Down Expand Up @@ -136,10 +137,22 @@ static Flavor parseFlavor(std::vector<const char *> &v) {
// and we use it to detect whether we are running tests or not.
static bool canExitEarly() { return StringRef(getenv("LLD_IN_TEST")) != "1"; }

// This function is called on startup. We need this for LTO since
// LTO calls LLVM functions to compile bitcode files to native code.
// Technically this can be delayed until we read bitcode files, but
// we don't bother to do lazily because the initialization is fast.
static void initLLVM() {
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
}

dmakarov marked this conversation as resolved.
Show resolved Hide resolved
/// Universal linker main(). This linker emulates the gnu, darwin, or
/// windows linker based on the argv[0] or -flavor option.
int main(int argc, const char **argv) {
InitLLVM x(argc, argv);
initLLVM();

std::vector<const char *> args(argv, argv + argc);
switch (parseFlavor(args)) {
Expand Down
13 changes: 0 additions & 13 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ enum {
#undef OPTION
};

// This function is called on startup. We need this for LTO since
// LTO calls LLVM functions to compile bitcode files to native code.
// Technically this can be delayed until we read bitcode files, but
// we don't bother to do lazily because the initialization is fast.
static void initLLVM() {
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
}

class LinkerDriver {
public:
void link(ArrayRef<const char *> argsArr);
Expand Down Expand Up @@ -94,7 +83,6 @@ bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stdoutOS,
config = make<Configuration>();
symtab = make<SymbolTable>();

initLLVM();
LinkerDriver().link(args);

// Exit immediately if we don't need to return to the caller.
Expand Down Expand Up @@ -568,7 +556,6 @@ static void createSyntheticSymbols() {
make<SyntheticFunction>(nullSignature, "__wasm_apply_relocs"));
}


if (config->isPic) {
WasmSym::stackPointer = createUndefinedGlobal(
"__stack_pointer",
Expand Down