|
8 | 8 | #include "llvm/IR/Intrinsics.h"
|
9 | 9 | #include "llvm/IR/IntrinsicsARM.h"
|
10 | 10 | #include "llvm/IR/Mangler.h"
|
| 11 | +#if LLVM_VERSION_GE(16, 0) |
| 12 | +#include "llvm/IR/ModRef.h" |
| 13 | +#endif |
11 | 14 | #include "llvm/Object/Archive.h"
|
12 | 15 | #include "llvm/Object/COFFImportFile.h"
|
13 | 16 | #include "llvm/Object/ObjectFile.h"
|
@@ -213,8 +216,6 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
|
213 | 216 | return Attribute::ReturnsTwice;
|
214 | 217 | case ReadNone:
|
215 | 218 | return Attribute::ReadNone;
|
216 |
| - case InaccessibleMemOnly: |
217 |
| - return Attribute::InaccessibleMemOnly; |
218 | 219 | case SanitizeHWAddress:
|
219 | 220 | return Attribute::SanitizeHWAddress;
|
220 | 221 | case WillReturn:
|
@@ -379,6 +380,43 @@ extern "C" LLVMAttributeRef LLVMRustCreateAllocKindAttr(LLVMContextRef C, uint64
|
379 | 380 | #endif
|
380 | 381 | }
|
381 | 382 |
|
| 383 | +// Simplified representation of `MemoryEffects` across the FFI boundary. |
| 384 | +// |
| 385 | +// Each variant corresponds to one of the static factory methods on `MemoryEffects`. |
| 386 | +enum class LLVMRustMemoryEffects { |
| 387 | + None, |
| 388 | + ReadOnly, |
| 389 | + InaccessibleMemOnly, |
| 390 | +}; |
| 391 | + |
| 392 | +extern "C" LLVMAttributeRef LLVMRustCreateMemoryEffectsAttr(LLVMContextRef C, |
| 393 | + LLVMRustMemoryEffects Effects) { |
| 394 | +#if LLVM_VERSION_GE(16, 0) |
| 395 | + switch (Effects) { |
| 396 | + case LLVMRustMemoryEffects::None: |
| 397 | + return wrap(Attribute::getWithMemoryEffects(*unwrap(C), MemoryEffects::none())); |
| 398 | + case LLVMRustMemoryEffects::ReadOnly: |
| 399 | + return wrap(Attribute::getWithMemoryEffects(*unwrap(C), MemoryEffects::readOnly())); |
| 400 | + case LLVMRustMemoryEffects::InaccessibleMemOnly: |
| 401 | + return wrap(Attribute::getWithMemoryEffects(*unwrap(C), |
| 402 | + MemoryEffects::inaccessibleMemOnly())); |
| 403 | + default: |
| 404 | + report_fatal_error("bad MemoryEffects."); |
| 405 | + } |
| 406 | +#else |
| 407 | + switch (Effects) { |
| 408 | + case LLVMRustMemoryEffects::None: |
| 409 | + return wrap(Attribute::get(*unwrap(C), Attribute::ReadNone)); |
| 410 | + case LLVMRustMemoryEffects::ReadOnly: |
| 411 | + return wrap(Attribute::get(*unwrap(C), Attribute::ReadOnly)); |
| 412 | + case LLVMRustMemoryEffects::InaccessibleMemOnly: |
| 413 | + return wrap(Attribute::get(*unwrap(C), Attribute::InaccessibleMemOnly)); |
| 414 | + default: |
| 415 | + report_fatal_error("bad MemoryEffects."); |
| 416 | + } |
| 417 | +#endif |
| 418 | +} |
| 419 | + |
382 | 420 | // Enable a fast-math flag
|
383 | 421 | //
|
384 | 422 | // https://llvm.org/docs/LangRef.html#fast-math-flags
|
|
0 commit comments