@@ -1609,10 +1609,33 @@ namespace {
1609
1609
PoolIdx = jl_options.opt_level ;
1610
1610
}
1611
1611
assert (PoolIdx < N && " Invalid optimization level for compiler!" );
1612
- return orc::SimpleCompiler (****TMs[PoolIdx])(M);
1612
+
1613
+ auto TM = **TMs[PoolIdx];
1614
+ if (M.getDataLayout ().isDefault ())
1615
+ M.setDataLayout ((*TM)->createDataLayout ());
1616
+
1617
+ SmallVector<char , 0 > ObjBufferSV;
1618
+ {
1619
+ raw_svector_ostream ObjStream (ObjBufferSV);
1620
+ legacy::PassManager PM;
1621
+ MCContext *Ctx;
1622
+ if ((*TM)->addPassesToEmitMC (PM, Ctx, ObjStream))
1623
+ return make_error<StringError>(" Target does not support MC emission" ,
1624
+ inconvertibleErrorCode ());
1625
+ PM.run (M);
1626
+ }
1627
+
1628
+ // OrcJIT requires that all modules / files have unique names:
1629
+ // https://llvm.org/doxygen/namespacellvm_1_1orc.html#a1f5a1bc60c220cdccbab0f26b2a425e1
1630
+ auto name = (M.getModuleIdentifier () + " -jitted-" +
1631
+ Twine (jl_atomic_fetch_add_relaxed (&bufcounter, 1 )))
1632
+ .str ();
1633
+ return std::make_unique<SmallVectorMemoryBuffer>(std::move (ObjBufferSV), name,
1634
+ false );
1613
1635
}
1614
1636
1615
1637
std::array<std::unique_ptr<JuliaOJIT::ResourcePool<std::unique_ptr<TargetMachine>>>, N> TMs;
1638
+ _Atomic (size_t ) bufcounter{0 };
1616
1639
};
1617
1640
}
1618
1641
@@ -2133,11 +2156,6 @@ Error JuliaOJIT::addExternalModule(orc::JITDylib &JD, orc::ThreadSafeModule TSM,
2133
2156
2134
2157
Error JuliaOJIT::addObjectFile (orc::JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
2135
2158
assert (Obj && " Can not add null object" );
2136
- // OrcJIT requires that all modules / files have unique names:
2137
- // https://llvm.org/doxygen/namespacellvm_1_1orc.html#a1f5a1bc60c220cdccbab0f26b2a425e1
2138
- // so we have to force a copy here
2139
- std::string Name = (" jitted-" + Twine (jl_atomic_fetch_add_relaxed (&jitcounter, 1 ))).str ();
2140
- Obj = Obj->getMemBufferCopy (Obj->getBuffer (), Name);
2141
2159
return ObjectLayer.add (JD.getDefaultResourceTracker (), std::move (Obj));
2142
2160
}
2143
2161
0 commit comments