Skip to content

Commit 79dca16

Browse files
committed
llvm: add support for LLVM16/17 (#503)
Summary: Pull Request resolved: #503 The internal build is moving to LLVM-17 from LLVM-15. For our code there are two required changes to get it building: a header has been renamed and the signature of a function has changed. Checked which LLVM major version these changes apply in and both are 16, macro gated accordingly so we maintain compatibility with both LLVM-15 and LLVM-17. Both versions build internally. Differential Revision: D61268962
1 parent ed5fcfe commit 79dca16

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

oi/OICompiler.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <clang/Lex/PreprocessorOptions.h>
2828
#include <glog/logging.h>
2929
#include <llvm/ADT/SmallVector.h>
30-
#include <llvm/ADT/Triple.h>
3130
#include <llvm/ADT/Twine.h>
3231
#include <llvm/Demangle/Demangle.h>
3332
#include <llvm/ExecutionEngine/ExecutionEngine.h>
@@ -38,6 +37,12 @@
3837
#include <llvm/Support/TargetSelect.h>
3938
#include <llvm/Support/raw_os_ostream.h>
4039

40+
#if LLVM_VERSION_MAJOR <= 15
41+
#include <llvm/ADT/Triple.h>
42+
#else
43+
#include <llvm/TargetParser/Triple.h>
44+
#endif
45+
4146
#include <array>
4247
#include <boost/range/combine.hpp>
4348
#include <boost/scope_exit.hpp>
@@ -135,6 +140,13 @@ OICompiler::Disassembler::operator()() {
135140
* allocate memory and prepare the relocation.
136141
*/
137142
class OIMemoryManager : public RTDyldMemoryManager {
143+
private:
144+
#if LLVM_VERSION_MAJOR <= 15
145+
using ReserveAllocationSpaceAlignTy = uint32_t;
146+
#else
147+
using ReserveAllocationSpaceAlignTy = llvm::Align;
148+
#endif
149+
138150
public:
139151
struct Slab {
140152
private:
@@ -244,8 +256,13 @@ class OIMemoryManager : public RTDyldMemoryManager {
244256
bool needsToReserveAllocationSpace(void) override {
245257
return true;
246258
}
247-
void reserveAllocationSpace(
248-
uintptr_t, uint32_t, uintptr_t, uint32_t, uintptr_t, uint32_t) override;
259+
260+
void reserveAllocationSpace(uintptr_t,
261+
ReserveAllocationSpaceAlignTy,
262+
uintptr_t,
263+
ReserveAllocationSpaceAlignTy,
264+
uintptr_t,
265+
ReserveAllocationSpaceAlignTy) override;
249266

250267
uint8_t* allocateCodeSection(uintptr_t,
251268
unsigned,
@@ -281,12 +298,17 @@ class OIMemoryManager : public RTDyldMemoryManager {
281298
}
282299
};
283300

284-
void OIMemoryManager::reserveAllocationSpace(uintptr_t codeSize,
285-
uint32_t codeAlign,
286-
uintptr_t roDataSize,
287-
uint32_t roDataAlign,
288-
uintptr_t rwDataSize,
289-
uint32_t rwDataAlign) {
301+
void OIMemoryManager::reserveAllocationSpace(
302+
uintptr_t codeSize,
303+
ReserveAllocationSpaceAlignTy codeAlignIn,
304+
uintptr_t roDataSize,
305+
ReserveAllocationSpaceAlignTy roDataAlignIn,
306+
uintptr_t rwDataSize,
307+
ReserveAllocationSpaceAlignTy rwDataAlignIn) {
308+
llvm::Align codeAlign{codeAlignIn};
309+
llvm::Align roDataAlign{roDataAlignIn};
310+
llvm::Align rwDataAlign{rwDataAlignIn};
311+
290312
/*
291313
* It looks like the sizes given to us already take into account the
292314
* alignment restrictions the different type of sections may have. Aligning
@@ -295,9 +317,10 @@ void OIMemoryManager::reserveAllocationSpace(uintptr_t codeSize,
295317
uint64_t totalSz = alignTo((codeSize + roDataSize + rwDataSize), 1024);
296318

297319
VLOG(1) << "reserveAllocationSpace: codesize " << codeSize << " codeAlign "
298-
<< codeAlign << " roDataSize " << roDataSize << " roDataAlign "
299-
<< roDataAlign << " rwDataSize " << rwDataSize << " rwDataAlign "
300-
<< rwDataAlign << " (Total Size: " << totalSz << ")";
320+
<< codeAlign.value() << " roDataSize " << roDataSize
321+
<< " roDataAlign " << roDataAlign.value() << " rwDataSize "
322+
<< rwDataSize << " rwDataAlign " << rwDataAlign.value()
323+
<< " (Total Size: " << totalSz << ")";
301324

302325
Slabs.emplace_back(totalSz, codeSize, roDataSize + rwDataSize + 128);
303326

0 commit comments

Comments
 (0)