mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-07 11:26:02 +03:00
jit: better module stripping (#2743)
This commit is contained in:
parent
86265da6b0
commit
65337ed170
2 changed files with 56 additions and 0 deletions
|
@ -169,6 +169,22 @@ void iterateFuncInstructions(llvm::Function &func, F &&handler) {
|
||||||
} // for (auto &&bb : fun)
|
} // for (auto &&bb : fun)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
void stripDeclarations(llvm::iterator_range<I> range) {
|
||||||
|
for (auto it = range.begin(); it != range.end();) {
|
||||||
|
auto elem = &(*it);
|
||||||
|
++it;
|
||||||
|
if (elem->isDeclaration() && elem->use_empty()) {
|
||||||
|
elem->eraseFromParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void stripModule(llvm::Module &module) {
|
||||||
|
stripDeclarations(module.functions());
|
||||||
|
stripDeclarations(module.globals());
|
||||||
|
}
|
||||||
|
|
||||||
void fixRtModule(llvm::Module &newModule,
|
void fixRtModule(llvm::Module &newModule,
|
||||||
const decltype(IRState::dynamicCompiledFunctions) &funcs) {
|
const decltype(IRState::dynamicCompiledFunctions) &funcs) {
|
||||||
std::unordered_map<std::string, std::string> thunkVar2func;
|
std::unordered_map<std::string, std::string> thunkVar2func;
|
||||||
|
@ -224,6 +240,8 @@ void fixRtModule(llvm::Module &newModule,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stripModule(newModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeFunctionsTargets(IRState *irs, llvm::Module &module) {
|
void removeFunctionsTargets(IRState *irs, llvm::Module &module) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
// RUN: %ldc -enable-dynamic-compile -run %s
|
// RUN: %ldc -enable-dynamic-compile -run %s
|
||||||
|
|
||||||
|
import std.stdio;
|
||||||
import std.array;
|
import std.array;
|
||||||
import std.string;
|
import std.string;
|
||||||
import ldc.attributes;
|
import ldc.attributes;
|
||||||
|
@ -8,6 +9,7 @@ import ldc.dynamic_compile;
|
||||||
|
|
||||||
__gshared int value = 32;
|
__gshared int value = 32;
|
||||||
|
|
||||||
|
|
||||||
@dynamicCompile int foo()
|
@dynamicCompile int foo()
|
||||||
{
|
{
|
||||||
return 42;
|
return 42;
|
||||||
|
@ -27,6 +29,11 @@ void fun(int function())
|
||||||
fun(&foo);
|
fun(&foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@dynamicCompile int bzz()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
class Foo()
|
class Foo()
|
||||||
{
|
{
|
||||||
@dynamicCompile int foo()
|
@dynamicCompile int foo()
|
||||||
|
@ -35,6 +42,27 @@ class Foo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct UnusedStruct1
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UnusedStruct2
|
||||||
|
{
|
||||||
|
UnusedStruct1 f;
|
||||||
|
int k;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unusedfunc1(UnusedStruct2)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void unusedfunc2(int function())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__gshared int unusedvalue = 32;
|
||||||
|
|
||||||
void main(string[] args)
|
void main(string[] args)
|
||||||
{
|
{
|
||||||
|
@ -44,10 +72,20 @@ void main(string[] args)
|
||||||
{
|
{
|
||||||
if (DumpStage.OriginalModule == stage)
|
if (DumpStage.OriginalModule == stage)
|
||||||
{
|
{
|
||||||
|
write(str);
|
||||||
dump.put(str);
|
dump.put(str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
writeln("===========================================");
|
||||||
compileDynamicCode(settings);
|
compileDynamicCode(settings);
|
||||||
|
writeln("===========================================");
|
||||||
|
|
||||||
assert(0 == count(dump.data, "thunk"));
|
assert(0 == count(dump.data, "thunk"));
|
||||||
|
assert(0 == count(dump.data, "unusedvalue"));
|
||||||
|
assert(0 == count(dump.data, "unusedfunc1"));
|
||||||
|
assert(0 == count(dump.data, "unusedfunc2"));
|
||||||
|
|
||||||
|
// TODO: these symbols is pulled by llvm.ldc.typeinfo
|
||||||
|
//assert(0 == count(dump.data, "UnusedStruct1"));
|
||||||
|
//assert(0 == count(dump.data, "UnusedStruct2"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue