mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
There's an issue with LLVM metadata support; it triggers an assert when trying
to generate asm for code with metadata globals. This new pass is used as a workaround: it strips metadata from the module before it reaches the code generator. Obviously, this is disabled if LLVM doesn't support metadata.
This commit is contained in:
@@ -50,6 +50,12 @@ disableGCToStack("disable-gc2stack",
|
||||
cl::desc("Disable promotion of GC allocations to stack memory in -O<N>"),
|
||||
cl::ZeroOrMore);
|
||||
|
||||
// Not recommended; metadata currently triggers an assert in the backend...
|
||||
static cl::opt<bool>
|
||||
disableStripMetaData("disable-strip-metadata",
|
||||
cl::desc("Disable default metadata stripping (not recommended)"),
|
||||
cl::ZeroOrMore);
|
||||
|
||||
static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser>
|
||||
enableInlining("inlining",
|
||||
cl::desc("(*) Enable function inlining in -O<N>"),
|
||||
@@ -137,6 +143,13 @@ static void addPassesForOptLevel(PassManager& pm) {
|
||||
pm.add(createCFGSimplificationPass());
|
||||
}
|
||||
}
|
||||
#ifdef USE_METADATA
|
||||
if (!disableStripMetaData) {
|
||||
// This one is purposely not disabled by disableLangSpecificPasses
|
||||
// because the code generator will assert if it's not used.
|
||||
pm.add(createStripMetaData());
|
||||
}
|
||||
#endif
|
||||
|
||||
// -O3
|
||||
if (optimizeLevel >= 3)
|
||||
@@ -181,8 +194,18 @@ static void addPassesForOptLevel(PassManager& pm) {
|
||||
// Returns true if any optimization passes were invoked.
|
||||
bool ldc_optimize_module(llvm::Module* m)
|
||||
{
|
||||
if (!optimize())
|
||||
if (!optimize()) {
|
||||
#ifdef USE_METADATA
|
||||
if (!disableStripMetaData) {
|
||||
// This one always needs to run if metadata is generated, because
|
||||
// the code generator will assert if it's not used.
|
||||
ModulePass* stripMD = createStripMetaData();
|
||||
stripMD->runOnModule(*m);
|
||||
delete stripMD;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
PassManager pm;
|
||||
pm.add(new TargetData(m));
|
||||
|
||||
Reference in New Issue
Block a user