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

Fix stdio.h include problem #414

Merged
merged 4 commits into from Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/tcwrapper.cpp
Expand Up @@ -961,12 +961,12 @@ static void optimizemodule(TerraTarget *TT, llvm::Module *M) {

ErikMcClure marked this conversation as resolved.
Show resolved Hide resolved
for (llvm::Module::iterator it = M->begin(), end = M->end(); it != end; ++it) {
llvm::Function *fn = &*it;
if (fn->hasAvailableExternallyLinkage()) {
if (fn->hasAvailableExternallyLinkage() ||
fn->getLinkage() == llvm::GlobalValue::LinkOnceODRLinkage) {
fn->setLinkage(llvm::GlobalValue::WeakODRLinkage);
} else if (fn->getLinkage() == llvm::GlobalValue::LinkOnceAnyLinkage) {
fn->setLinkage(llvm::GlobalValue::WeakAnyLinkage);
}
#ifdef _WIN32 // On windows, the optimizer will delete LinkOnce functions that are unused
usedArray.push_back(fn);
#endif
#if LLVM_VERSION >= 35
if (fn->hasDLLImportStorageClass()) // clear dll import linkage because it messes
// up the jit on window
Expand All @@ -978,18 +978,6 @@ static void optimizemodule(TerraTarget *TT, llvm::Module *M) {
#endif
}

if (usedArray.size() > 0) {
auto *i8PtrType = llvm::Type::getInt8PtrTy(M->getContext());
for (auto &elem : usedArray)
elem = llvm::ConstantExpr::getBitCast(elem, i8PtrType);

auto *arrayType = llvm::ArrayType::get(i8PtrType, usedArray.size());
auto *llvmUsed = new llvm::GlobalVariable(
*M, arrayType, false, llvm::GlobalValue::AppendingLinkage,
llvm::ConstantArray::get(arrayType, usedArray), "llvm.used");
llvmUsed->setSection("llvm.metadata");
}

M->setTargetTriple(
TT->Triple); // suppress warning that occur due to unmatched os versions
PassManager opt;
Expand Down Expand Up @@ -1109,9 +1097,14 @@ int include_c(lua_State *L) {

#ifdef _WIN32
args.push_back("-fms-extensions");
args.push_back("-fms-volatile");
args.push_back("-fms-compatibility");
args.push_back("-fms-compatibility-version=18");
args.push_back("-Wno-ignored-attributes");
args.push_back("-flto-visibility-public-std");
args.push_back("--dependent-lib=msvcrt");
args.push_back("-fdiagnostics-format");
args.push_back("msvc");
#endif

for (int i = 0; i < N; i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/tllvmutil.cpp
Expand Up @@ -261,6 +261,8 @@ struct CopyConnectedComponent : public ValueMaterializer {
newfn = Function::Create(fn->getFunctionType(), fn->getLinkage(),
fn->getName(), dest);
newfn->copyAttributesFrom(fn);
newfn->setComdat(
fn->getComdat()); // copyAttributesFrom does not copy comdats
}
if (!fn->isDeclaration() && newfn->isDeclaration() && copyGlobal(fn, data)) {
for (Function::arg_iterator II = newfn->arg_begin(), I = fn->arg_begin(),
Expand Down
11 changes: 5 additions & 6 deletions tests/benchmark_fannkuchredux.t
Expand Up @@ -6,11 +6,10 @@

]]

local C = {
printf = terralib.externfunction("printf", terralib.types.funcpointer(rawstring,int,true)),
exit = terralib.externfunction("exit", int -> {}),
atoi = terralib.externfunction("atoi", rawstring -> int)
}
C = terralib.includecstring [[
#include<stdio.h>
#include<stdlib.h>
]]

-- this depends highly on the platform. It might be faster to use
-- char type on 32-bit systems; it might be faster to use unsigned.
Expand Down Expand Up @@ -147,7 +146,7 @@ end))
local N = assert(tonumber((...) or 10))
doit(N)
if jit.os == "Windows" then
terralib.saveobj("benchmark_fannkuchredux.exe", { main = main }, {"\\legacy_stdio_definitions.lib"})
terralib.saveobj("benchmark_fannkuchredux.exe", { main = main })
os.execute("benchmark_fannkuchredux.exe "..N)
else
terralib.saveobj("benchmark_fannkuchredux", { main = main })
Expand Down
5 changes: 2 additions & 3 deletions tests/benchmark_nbody.t
Expand Up @@ -2,11 +2,10 @@ local C = terralib.includecstring[[

#include <math.h>
#include <stdlib.h>
#include <stdio.h>

]]

C.printf = terralib.externfunction("printf", terralib.types.funcpointer(rawstring,int,true))

pi = 3.141592653589793
solar_mass = (4 * pi * pi)
days_per_year = 365.24
Expand Down Expand Up @@ -144,7 +143,7 @@ if jit.os ~= "Windows" then
terralib.saveobj("benchmark_nbody",{ main = main }, {"-lm"} )
os.execute("./benchmark_nbody "..tostring(N))
else
terralib.saveobj("benchmark_nbody.exe",{ main = main }, {"\\legacy_stdio_definitions.lib"} )
terralib.saveobj("benchmark_nbody.exe",{ main = main } )
os.execute("benchmark_nbody.exe "..tostring(N))
end

6 changes: 0 additions & 6 deletions tests/run
Expand Up @@ -6,12 +6,6 @@ local lscmd
if ffi.os == "Windows" then
lscmd = "cmd /c dir /b /s"

-- FIXME: https://github.com/zdevito/terra/issues/401
table.insert(skip, "class2.t")
table.insert(skip, "stdio.t")
table.insert(skip, "speed.t")
table.insert(skip, "benchmark_nbody.t")
table.insert(skip, "benchmark_fannkuchredux.t")
-- Disabled due to non-deterministic failures on certain branches: https://github.com/zdevito/terra/issues/404
table.insert(skip, "leaktest.t")
else
Expand Down
4 changes: 2 additions & 2 deletions tests/speed.t
@@ -1,7 +1,7 @@
local C = terralib.includecstring [[
#include <stdlib.h>
#include <stdio.h>
]]
C.printf = terralib.externfunction("printf", terralib.types.funcpointer(rawstring,int,true))

terra doit(N : int64)
var cur,last = 1ULL,1ULL
Expand All @@ -27,4 +27,4 @@ local test = require("test")
print(what())
print(test.time( function() doit:compile() end))
print(test.time( function() doit(100000000) end))
print(test.time( function() terralib.saveobj("speed",{main = main}, (jit.os == "Windows" and {"\\legacy_stdio_definitions.lib"} or nil)) end))
print(test.time( function() terralib.saveobj("speed",{main = main}) end))