| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | #include "LLVMWrapper.h" |
| 2 | 2 | #include "llvm/ADT/Statistic.h" |
| 3 | #include "llvm/Bitcode/BitcodeWriter.h" |
| 3 | 4 | #include "llvm/IR/DebugInfoMetadata.h" |
| 4 | 5 | #include "llvm/IR/DiagnosticHandler.h" |
| 5 | 6 | #include "llvm/IR/DiagnosticInfo.h" |
| ... | ... | @@ -11,17 +12,16 @@ |
| 11 | 12 | #include "llvm/IR/LLVMRemarkStreamer.h" |
| 12 | 13 | #include "llvm/IR/Mangler.h" |
| 13 | 14 | #include "llvm/IR/Value.h" |
| 14 | | #include "llvm/Remarks/RemarkStreamer.h" |
| 15 | | #include "llvm/Remarks/RemarkSerializer.h" |
| 16 | | #include "llvm/Remarks/RemarkFormat.h" |
| 17 | | #include "llvm/Support/ToolOutputFile.h" |
| 18 | | #include "llvm/Support/ModRef.h" |
| 19 | 15 | #include "llvm/Object/Archive.h" |
| 20 | 16 | #include "llvm/Object/COFFImportFile.h" |
| 21 | 17 | #include "llvm/Object/ObjectFile.h" |
| 22 | 18 | #include "llvm/Pass.h" |
| 23 | | #include "llvm/Bitcode/BitcodeWriter.h" |
| 19 | #include "llvm/Remarks/RemarkFormat.h" |
| 20 | #include "llvm/Remarks/RemarkSerializer.h" |
| 21 | #include "llvm/Remarks/RemarkStreamer.h" |
| 22 | #include "llvm/Support/ModRef.h" |
| 24 | 23 | #include "llvm/Support/Signals.h" |
| 24 | #include "llvm/Support/ToolOutputFile.h" |
| 25 | 25 | |
| 26 | 26 | #include <iostream> |
| 27 | 27 | |
| ... | ... | @@ -71,12 +71,12 @@ static LLVM_THREAD_LOCAL char *LastError; |
| 71 | 71 | // Custom error handler for fatal LLVM errors. |
| 72 | 72 | // |
| 73 | 73 | // Notably it exits the process with code 101, unlike LLVM's default of 1. |
| 74 | | static void FatalErrorHandler(void *UserData, |
| 75 | | const char* Reason, |
| 74 | static void FatalErrorHandler(void *UserData, const char *Reason, |
| 76 | 75 | bool GenCrashDiag) { |
| 77 | 76 | // Once upon a time we emitted "LLVM ERROR:" specifically to mimic LLVM. Then, |
| 78 | | // we developed crater and other tools which only expose logs, not error codes. |
| 79 | | // Use a more greppable prefix that will still match the "LLVM ERROR:" prefix. |
| 77 | // we developed crater and other tools which only expose logs, not error |
| 78 | // codes. Use a more greppable prefix that will still match the "LLVM ERROR:" |
| 79 | // prefix. |
| 80 | 80 | std::cerr << "rustc-LLVM ERROR: " << Reason << std::endl; |
| 81 | 81 | |
| 82 | 82 | // Since this error handler exits the process, we have to run any cleanup that |
| ... | ... | @@ -99,8 +99,7 @@ static void FatalErrorHandler(void *UserData, |
| 99 | 99 | // |
| 100 | 100 | // It aborts the process without any further allocations, similar to LLVM's |
| 101 | 101 | // default except that may be configured to `throw std::bad_alloc()` instead. |
| 102 | | static void BadAllocErrorHandler(void *UserData, |
| 103 | | const char* Reason, |
| 102 | static void BadAllocErrorHandler(void *UserData, const char *Reason, |
| 104 | 103 | bool GenCrashDiag) { |
| 105 | 104 | const char *OOM = "rustc-LLVM ERROR: out of memory\n"; |
| 106 | 105 | (void)!::write(2, OOM, strlen(OOM)); |
| ... | ... | @@ -190,7 +189,8 @@ static CallInst::TailCallKind fromRust(LLVMRustTailCallKind Kind) { |
| 190 | 189 | } |
| 191 | 190 | } |
| 192 | 191 | |
| 193 | | extern "C" void LLVMRustSetTailCallKind(LLVMValueRef Call, LLVMRustTailCallKind TCK) { |
| 192 | extern "C" void LLVMRustSetTailCallKind(LLVMValueRef Call, |
| 193 | LLVMRustTailCallKind TCK) { |
| 194 | 194 | unwrap<CallInst>(Call)->setTailCallKind(fromRust(TCK)); |
| 195 | 195 | } |
| 196 | 196 | |
| ... | ... | @@ -201,12 +201,13 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M, |
| 201 | 201 | return wrap(unwrap(M) |
| 202 | 202 | ->getOrInsertFunction(StringRef(Name, NameLen), |
| 203 | 203 | unwrap<FunctionType>(FunctionTy)) |
| 204 | | .getCallee() |
| 205 | | ); |
| 204 | .getCallee()); |
| 206 | 205 | } |
| 207 | 206 | |
| 208 | | extern "C" LLVMValueRef |
| 209 | | LLVMRustGetOrInsertGlobal(LLVMModuleRef M, const char *Name, size_t NameLen, LLVMTypeRef Ty) { |
| 207 | extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M, |
| 208 | const char *Name, |
| 209 | size_t NameLen, |
| 210 | LLVMTypeRef Ty) { |
| 210 | 211 | Module *Mod = unwrap(M); |
| 211 | 212 | auto NameRef = StringRef(Name, NameLen); |
| 212 | 213 | |
| ... | ... | @@ -221,13 +222,10 @@ LLVMRustGetOrInsertGlobal(LLVMModuleRef M, const char *Name, size_t NameLen, LLV |
| 221 | 222 | return wrap(GV); |
| 222 | 223 | } |
| 223 | 224 | |
| 224 | | extern "C" LLVMValueRef |
| 225 | | LLVMRustInsertPrivateGlobal(LLVMModuleRef M, LLVMTypeRef Ty) { |
| 226 | | return wrap(new GlobalVariable(*unwrap(M), |
| 227 | | unwrap(Ty), |
| 228 | | false, |
| 229 | | GlobalValue::PrivateLinkage, |
| 230 | | nullptr)); |
| 225 | extern "C" LLVMValueRef LLVMRustInsertPrivateGlobal(LLVMModuleRef M, |
| 226 | LLVMTypeRef Ty) { |
| 227 | return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false, |
| 228 | GlobalValue::PrivateLinkage, nullptr)); |
| 231 | 229 | } |
| 232 | 230 | |
| 233 | 231 | static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) { |
| ... | ... | @@ -326,8 +324,9 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) { |
| 326 | 324 | report_fatal_error("bad AttributeKind"); |
| 327 | 325 | } |
| 328 | 326 | |
| 329 | | template<typename T> static inline void AddAttributes(T *t, unsigned Index, |
| 330 | | LLVMAttributeRef *Attrs, size_t AttrsLen) { |
| 327 | template <typename T> |
| 328 | static inline void AddAttributes(T *t, unsigned Index, LLVMAttributeRef *Attrs, |
| 329 | size_t AttrsLen) { |
| 331 | 330 | AttributeList PAL = t->getAttributes(); |
| 332 | 331 | auto B = AttrBuilder(t->getContext()); |
| 333 | 332 | for (LLVMAttributeRef Attr : ArrayRef<LLVMAttributeRef>(Attrs, AttrsLen)) |
| ... | ... | @@ -337,19 +336,22 @@ template<typename T> static inline void AddAttributes(T *t, unsigned Index, |
| 337 | 336 | } |
| 338 | 337 | |
| 339 | 338 | extern "C" void LLVMRustAddFunctionAttributes(LLVMValueRef Fn, unsigned Index, |
| 340 | | LLVMAttributeRef *Attrs, size_t AttrsLen) { |
| 339 | LLVMAttributeRef *Attrs, |
| 340 | size_t AttrsLen) { |
| 341 | 341 | Function *F = unwrap<Function>(Fn); |
| 342 | 342 | AddAttributes(F, Index, Attrs, AttrsLen); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | | extern "C" void LLVMRustAddCallSiteAttributes(LLVMValueRef Instr, unsigned Index, |
| 346 | | LLVMAttributeRef *Attrs, size_t AttrsLen) { |
| 345 | extern "C" void LLVMRustAddCallSiteAttributes(LLVMValueRef Instr, |
| 346 | unsigned Index, |
| 347 | LLVMAttributeRef *Attrs, |
| 348 | size_t AttrsLen) { |
| 347 | 349 | CallBase *Call = unwrap<CallBase>(Instr); |
| 348 | 350 | AddAttributes(Call, Index, Attrs, AttrsLen); |
| 349 | 351 | } |
| 350 | 352 | |
| 351 | | extern "C" LLVMAttributeRef LLVMRustCreateAttrNoValue(LLVMContextRef C, |
| 352 | | LLVMRustAttribute RustAttr) { |
| 353 | extern "C" LLVMAttributeRef |
| 354 | LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttribute RustAttr) { |
| 353 | 355 | return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr))); |
| 354 | 356 | } |
| 355 | 357 | |
| ... | ... | @@ -363,30 +365,36 @@ extern "C" LLVMAttributeRef LLVMRustCreateDereferenceableAttr(LLVMContextRef C, |
| 363 | 365 | return wrap(Attribute::getWithDereferenceableBytes(*unwrap(C), Bytes)); |
| 364 | 366 | } |
| 365 | 367 | |
| 366 | | extern "C" LLVMAttributeRef LLVMRustCreateDereferenceableOrNullAttr(LLVMContextRef C, |
| 367 | | uint64_t Bytes) { |
| 368 | extern "C" LLVMAttributeRef |
| 369 | LLVMRustCreateDereferenceableOrNullAttr(LLVMContextRef C, uint64_t Bytes) { |
| 368 | 370 | return wrap(Attribute::getWithDereferenceableOrNullBytes(*unwrap(C), Bytes)); |
| 369 | 371 | } |
| 370 | 372 | |
| 371 | | extern "C" LLVMAttributeRef LLVMRustCreateByValAttr(LLVMContextRef C, LLVMTypeRef Ty) { |
| 373 | extern "C" LLVMAttributeRef LLVMRustCreateByValAttr(LLVMContextRef C, |
| 374 | LLVMTypeRef Ty) { |
| 372 | 375 | return wrap(Attribute::getWithByValType(*unwrap(C), unwrap(Ty))); |
| 373 | 376 | } |
| 374 | 377 | |
| 375 | | extern "C" LLVMAttributeRef LLVMRustCreateStructRetAttr(LLVMContextRef C, LLVMTypeRef Ty) { |
| 378 | extern "C" LLVMAttributeRef LLVMRustCreateStructRetAttr(LLVMContextRef C, |
| 379 | LLVMTypeRef Ty) { |
| 376 | 380 | return wrap(Attribute::getWithStructRetType(*unwrap(C), unwrap(Ty))); |
| 377 | 381 | } |
| 378 | 382 | |
| 379 | | extern "C" LLVMAttributeRef LLVMRustCreateElementTypeAttr(LLVMContextRef C, LLVMTypeRef Ty) { |
| 383 | extern "C" LLVMAttributeRef LLVMRustCreateElementTypeAttr(LLVMContextRef C, |
| 384 | LLVMTypeRef Ty) { |
| 380 | 385 | return wrap(Attribute::get(*unwrap(C), Attribute::ElementType, unwrap(Ty))); |
| 381 | 386 | } |
| 382 | 387 | |
| 383 | | extern "C" LLVMAttributeRef LLVMRustCreateUWTableAttr(LLVMContextRef C, bool Async) { |
| 388 | extern "C" LLVMAttributeRef LLVMRustCreateUWTableAttr(LLVMContextRef C, |
| 389 | bool Async) { |
| 384 | 390 | return wrap(Attribute::getWithUWTableKind( |
| 385 | 391 | *unwrap(C), Async ? UWTableKind::Async : UWTableKind::Sync)); |
| 386 | 392 | } |
| 387 | 393 | |
| 388 | | extern "C" LLVMAttributeRef LLVMRustCreateAllocSizeAttr(LLVMContextRef C, uint32_t ElementSizeArg) { |
| 389 | | return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg, std::nullopt)); |
| 394 | extern "C" LLVMAttributeRef |
| 395 | LLVMRustCreateAllocSizeAttr(LLVMContextRef C, uint32_t ElementSizeArg) { |
| 396 | return wrap(Attribute::getWithAllocSizeArgs(*unwrap(C), ElementSizeArg, |
| 397 | std::nullopt)); |
| 390 | 398 | } |
| 391 | 399 | |
| 392 | 400 | // These values **must** match ffi::AllocKindFlags. |
| ... | ... | @@ -403,12 +411,15 @@ enum class LLVMRustAllocKindFlags : uint64_t { |
| 403 | 411 | Aligned = 1 << 5, |
| 404 | 412 | }; |
| 405 | 413 | |
| 406 | | static LLVMRustAllocKindFlags operator&(LLVMRustAllocKindFlags A, LLVMRustAllocKindFlags B) { |
| 414 | static LLVMRustAllocKindFlags operator&(LLVMRustAllocKindFlags A, |
| 415 | LLVMRustAllocKindFlags B) { |
| 407 | 416 | return static_cast<LLVMRustAllocKindFlags>(static_cast<uint64_t>(A) & |
| 408 | | static_cast<uint64_t>(B)); |
| 417 | static_cast<uint64_t>(B)); |
| 409 | 418 | } |
| 410 | 419 | |
| 411 | | static bool isSet(LLVMRustAllocKindFlags F) { return F != LLVMRustAllocKindFlags::Unknown; } |
| 420 | static bool isSet(LLVMRustAllocKindFlags F) { |
| 421 | return F != LLVMRustAllocKindFlags::Unknown; |
| 422 | } |
| 412 | 423 | |
| 413 | 424 | static llvm::AllocFnKind allocKindFromRust(LLVMRustAllocKindFlags F) { |
| 414 | 425 | llvm::AllocFnKind AFK = llvm::AllocFnKind::Unknown; |
| ... | ... | @@ -433,40 +444,47 @@ static llvm::AllocFnKind allocKindFromRust(LLVMRustAllocKindFlags F) { |
| 433 | 444 | return AFK; |
| 434 | 445 | } |
| 435 | 446 | |
| 436 | | extern "C" LLVMAttributeRef LLVMRustCreateAllocKindAttr(LLVMContextRef C, uint64_t AllocKindArg) { |
| 437 | | return wrap(Attribute::get(*unwrap(C), Attribute::AllocKind, |
| 438 | | static_cast<uint64_t>(allocKindFromRust(static_cast<LLVMRustAllocKindFlags>(AllocKindArg))))); |
| 447 | extern "C" LLVMAttributeRef LLVMRustCreateAllocKindAttr(LLVMContextRef C, |
| 448 | uint64_t AllocKindArg) { |
| 449 | return wrap( |
| 450 | Attribute::get(*unwrap(C), Attribute::AllocKind, |
| 451 | static_cast<uint64_t>(allocKindFromRust( |
| 452 | static_cast<LLVMRustAllocKindFlags>(AllocKindArg))))); |
| 439 | 453 | } |
| 440 | 454 | |
| 441 | 455 | // Simplified representation of `MemoryEffects` across the FFI boundary. |
| 442 | 456 | // |
| 443 | | // Each variant corresponds to one of the static factory methods on `MemoryEffects`. |
| 457 | // Each variant corresponds to one of the static factory methods on |
| 458 | // `MemoryEffects`. |
| 444 | 459 | enum class LLVMRustMemoryEffects { |
| 445 | 460 | None, |
| 446 | 461 | ReadOnly, |
| 447 | 462 | InaccessibleMemOnly, |
| 448 | 463 | }; |
| 449 | 464 | |
| 450 | | extern "C" LLVMAttributeRef LLVMRustCreateMemoryEffectsAttr(LLVMContextRef C, |
| 451 | | LLVMRustMemoryEffects Effects) { |
| 465 | extern "C" LLVMAttributeRef |
| 466 | LLVMRustCreateMemoryEffectsAttr(LLVMContextRef C, |
| 467 | LLVMRustMemoryEffects Effects) { |
| 452 | 468 | switch (Effects) { |
| 453 | | case LLVMRustMemoryEffects::None: |
| 454 | | return wrap(Attribute::getWithMemoryEffects(*unwrap(C), MemoryEffects::none())); |
| 455 | | case LLVMRustMemoryEffects::ReadOnly: |
| 456 | | return wrap(Attribute::getWithMemoryEffects(*unwrap(C), MemoryEffects::readOnly())); |
| 457 | | case LLVMRustMemoryEffects::InaccessibleMemOnly: |
| 458 | | return wrap(Attribute::getWithMemoryEffects(*unwrap(C), |
| 459 | | MemoryEffects::inaccessibleMemOnly())); |
| 460 | | default: |
| 461 | | report_fatal_error("bad MemoryEffects."); |
| 462 | | } |
| 463 | | } |
| 464 | | |
| 465 | | // Enable all fast-math flags, including those which will cause floating-point operations |
| 466 | | // to return poison for some well-defined inputs. This function can only be used to build |
| 467 | | // unsafe Rust intrinsics. That unsafety does permit additional optimizations, but at the |
| 468 | | // time of writing, their value is not well-understood relative to those enabled by |
| 469 | | // LLVMRustSetAlgebraicMath. |
| 469 | case LLVMRustMemoryEffects::None: |
| 470 | return wrap( |
| 471 | Attribute::getWithMemoryEffects(*unwrap(C), MemoryEffects::none())); |
| 472 | case LLVMRustMemoryEffects::ReadOnly: |
| 473 | return wrap( |
| 474 | Attribute::getWithMemoryEffects(*unwrap(C), MemoryEffects::readOnly())); |
| 475 | case LLVMRustMemoryEffects::InaccessibleMemOnly: |
| 476 | return wrap(Attribute::getWithMemoryEffects( |
| 477 | *unwrap(C), MemoryEffects::inaccessibleMemOnly())); |
| 478 | default: |
| 479 | report_fatal_error("bad MemoryEffects."); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | // Enable all fast-math flags, including those which will cause floating-point |
| 484 | // operations to return poison for some well-defined inputs. This function can |
| 485 | // only be used to build unsafe Rust intrinsics. That unsafety does permit |
| 486 | // additional optimizations, but at the time of writing, their value is not |
| 487 | // well-understood relative to those enabled by LLVMRustSetAlgebraicMath. |
| 470 | 488 | // |
| 471 | 489 | // https://llvm.org/docs/LangRef.html#fast-math-flags |
| 472 | 490 | extern "C" void LLVMRustSetFastMath(LLVMValueRef V) { |
| ... | ... | @@ -475,14 +493,12 @@ extern "C" void LLVMRustSetFastMath(LLVMValueRef V) { |
| 475 | 493 | } |
| 476 | 494 | } |
| 477 | 495 | |
| 478 | | // Enable fast-math flags which permit algebraic transformations that are not allowed by |
| 479 | | // IEEE floating point. For example: |
| 480 | | // a + (b + c) = (a + b) + c |
| 481 | | // and |
| 482 | | // a / b = a * (1 / b) |
| 483 | | // Note that this does NOT enable any flags which can cause a floating-point operation on |
| 484 | | // well-defined inputs to return poison, and therefore this function can be used to build |
| 485 | | // safe Rust intrinsics (such as fadd_algebraic). |
| 496 | // Enable fast-math flags which permit algebraic transformations that are not |
| 497 | // allowed by IEEE floating point. For example: a + (b + c) = (a + b) + c and a |
| 498 | // / b = a * (1 / b) Note that this does NOT enable any flags which can cause a |
| 499 | // floating-point operation on well-defined inputs to return poison, and |
| 500 | // therefore this function can be used to build safe Rust intrinsics (such as |
| 501 | // fadd_algebraic). |
| 486 | 502 | // |
| 487 | 503 | // https://llvm.org/docs/LangRef.html#fast-math-flags |
| 488 | 504 | extern "C" void LLVMRustSetAlgebraicMath(LLVMValueRef V) { |
| ... | ... | @@ -497,9 +513,9 @@ extern "C" void LLVMRustSetAlgebraicMath(LLVMValueRef V) { |
| 497 | 513 | // Enable the reassoc fast-math flag, allowing transformations that pretend |
| 498 | 514 | // floating-point addition and multiplication are associative. |
| 499 | 515 | // |
| 500 | | // Note that this does NOT enable any flags which can cause a floating-point operation on |
| 501 | | // well-defined inputs to return poison, and therefore this function can be used to build |
| 502 | | // safe Rust intrinsics (such as fadd_algebraic). |
| 516 | // Note that this does NOT enable any flags which can cause a floating-point |
| 517 | // operation on well-defined inputs to return poison, and therefore this |
| 518 | // function can be used to build safe Rust intrinsics (such as fadd_algebraic). |
| 503 | 519 | // |
| 504 | 520 | // https://llvm.org/docs/LangRef.html#fast-math-flags |
| 505 | 521 | extern "C" void LLVMRustSetAllowReassoc(LLVMValueRef V) { |
| ... | ... | @@ -547,11 +563,10 @@ LLVMRustInlineAsm(LLVMTypeRef Ty, char *AsmString, size_t AsmStringLen, |
| 547 | 563 | char *Constraints, size_t ConstraintsLen, |
| 548 | 564 | LLVMBool HasSideEffects, LLVMBool IsAlignStack, |
| 549 | 565 | LLVMRustAsmDialect Dialect, LLVMBool CanThrow) { |
| 550 | | return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), |
| 551 | | StringRef(AsmString, AsmStringLen), |
| 552 | | StringRef(Constraints, ConstraintsLen), |
| 553 | | HasSideEffects, IsAlignStack, |
| 554 | | fromRust(Dialect), CanThrow)); |
| 566 | return wrap(InlineAsm::get( |
| 567 | unwrap<FunctionType>(Ty), StringRef(AsmString, AsmStringLen), |
| 568 | StringRef(Constraints, ConstraintsLen), HasSideEffects, IsAlignStack, |
| 569 | fromRust(Dialect), CanThrow)); |
| 555 | 570 | } |
| 556 | 571 | |
| 557 | 572 | extern "C" bool LLVMRustInlineAsmVerify(LLVMTypeRef Ty, char *Constraints, |
| ... | ... | @@ -705,19 +720,22 @@ enum class LLVMRustDISPFlags : uint32_t { |
| 705 | 720 | |
| 706 | 721 | inline LLVMRustDISPFlags operator&(LLVMRustDISPFlags A, LLVMRustDISPFlags B) { |
| 707 | 722 | return static_cast<LLVMRustDISPFlags>(static_cast<uint32_t>(A) & |
| 708 | | static_cast<uint32_t>(B)); |
| 723 | static_cast<uint32_t>(B)); |
| 709 | 724 | } |
| 710 | 725 | |
| 711 | 726 | inline LLVMRustDISPFlags operator|(LLVMRustDISPFlags A, LLVMRustDISPFlags B) { |
| 712 | 727 | return static_cast<LLVMRustDISPFlags>(static_cast<uint32_t>(A) | |
| 713 | | static_cast<uint32_t>(B)); |
| 728 | static_cast<uint32_t>(B)); |
| 714 | 729 | } |
| 715 | 730 | |
| 716 | | inline LLVMRustDISPFlags &operator|=(LLVMRustDISPFlags &A, LLVMRustDISPFlags B) { |
| 731 | inline LLVMRustDISPFlags &operator|=(LLVMRustDISPFlags &A, |
| 732 | LLVMRustDISPFlags B) { |
| 717 | 733 | return A = A | B; |
| 718 | 734 | } |
| 719 | 735 | |
| 720 | | inline bool isSet(LLVMRustDISPFlags F) { return F != LLVMRustDISPFlags::SPFlagZero; } |
| 736 | inline bool isSet(LLVMRustDISPFlags F) { |
| 737 | return F != LLVMRustDISPFlags::SPFlagZero; |
| 738 | } |
| 721 | 739 | |
| 722 | 740 | inline LLVMRustDISPFlags virtuality(LLVMRustDISPFlags F) { |
| 723 | 741 | return static_cast<LLVMRustDISPFlags>(static_cast<uint32_t>(F) & 0x3); |
| ... | ... | @@ -761,7 +779,8 @@ enum class LLVMRustDebugEmissionKind { |
| 761 | 779 | DebugDirectivesOnly, |
| 762 | 780 | }; |
| 763 | 781 | |
| 764 | | static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind) { |
| 782 | static DICompileUnit::DebugEmissionKind |
| 783 | fromRust(LLVMRustDebugEmissionKind Kind) { |
| 765 | 784 | switch (Kind) { |
| 766 | 785 | case LLVMRustDebugEmissionKind::NoDebug: |
| 767 | 786 | return DICompileUnit::DebugEmissionKind::NoDebug; |
| ... | ... | @@ -777,12 +796,13 @@ static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind) |
| 777 | 796 | } |
| 778 | 797 | |
| 779 | 798 | enum class LLVMRustDebugNameTableKind { |
| 780 | | Default, |
| 781 | | GNU, |
| 782 | | None, |
| 799 | Default, |
| 800 | GNU, |
| 801 | None, |
| 783 | 802 | }; |
| 784 | 803 | |
| 785 | | static DICompileUnit::DebugNameTableKind fromRust(LLVMRustDebugNameTableKind Kind) { |
| 804 | static DICompileUnit::DebugNameTableKind |
| 805 | fromRust(LLVMRustDebugNameTableKind Kind) { |
| 786 | 806 | switch (Kind) { |
| 787 | 807 | case LLVMRustDebugNameTableKind::Default: |
| 788 | 808 | return DICompileUnit::DebugNameTableKind::Default; |
| ... | ... | @@ -827,22 +847,18 @@ extern "C" uint32_t LLVMRustVersionMinor() { return LLVM_VERSION_MINOR; } |
| 827 | 847 | |
| 828 | 848 | extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; } |
| 829 | 849 | |
| 830 | | extern "C" void LLVMRustAddModuleFlagU32( |
| 831 | | LLVMModuleRef M, |
| 832 | | Module::ModFlagBehavior MergeBehavior, |
| 833 | | const char *Name, |
| 834 | | uint32_t Value) { |
| 850 | extern "C" void LLVMRustAddModuleFlagU32(LLVMModuleRef M, |
| 851 | Module::ModFlagBehavior MergeBehavior, |
| 852 | const char *Name, uint32_t Value) { |
| 835 | 853 | unwrap(M)->addModuleFlag(MergeBehavior, Name, Value); |
| 836 | 854 | } |
| 837 | 855 | |
| 838 | 856 | extern "C" void LLVMRustAddModuleFlagString( |
| 839 | | LLVMModuleRef M, |
| 840 | | Module::ModFlagBehavior MergeBehavior, |
| 841 | | const char *Name, |
| 842 | | const char *Value, |
| 843 | | size_t ValueLen) { |
| 844 | | unwrap(M)->addModuleFlag(MergeBehavior, Name, |
| 845 | | MDString::get(unwrap(M)->getContext(), StringRef(Value, ValueLen))); |
| 857 | LLVMModuleRef M, Module::ModFlagBehavior MergeBehavior, const char *Name, |
| 858 | const char *Value, size_t ValueLen) { |
| 859 | unwrap(M)->addModuleFlag( |
| 860 | MergeBehavior, Name, |
| 861 | MDString::get(unwrap(M)->getContext(), StringRef(Value, ValueLen))); |
| 846 | 862 | } |
| 847 | 863 | |
| 848 | 864 | extern "C" bool LLVMRustHasModuleFlag(LLVMModuleRef M, const char *Name, |
| ... | ... | @@ -850,8 +866,8 @@ extern "C" bool LLVMRustHasModuleFlag(LLVMModuleRef M, const char *Name, |
| 850 | 866 | return unwrap(M)->getModuleFlag(StringRef(Name, Len)) != nullptr; |
| 851 | 867 | } |
| 852 | 868 | |
| 853 | | extern "C" void LLVMRustGlobalAddMetadata( |
| 854 | | LLVMValueRef Global, unsigned Kind, LLVMMetadataRef MD) { |
| 869 | extern "C" void LLVMRustGlobalAddMetadata(LLVMValueRef Global, unsigned Kind, |
| 870 | LLVMMetadataRef MD) { |
| 855 | 871 | unwrap<GlobalObject>(Global)->addMetadata(Kind, *unwrap<MDNode>(MD)); |
| 856 | 872 | } |
| 857 | 873 | |
| ... | ... | @@ -870,33 +886,29 @@ extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) { |
| 870 | 886 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit( |
| 871 | 887 | LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMMetadataRef FileRef, |
| 872 | 888 | const char *Producer, size_t ProducerLen, bool isOptimized, |
| 873 | | const char *Flags, unsigned RuntimeVer, |
| 874 | | const char *SplitName, size_t SplitNameLen, |
| 875 | | LLVMRustDebugEmissionKind Kind, |
| 876 | | uint64_t DWOId, bool SplitDebugInlining, |
| 877 | | LLVMRustDebugNameTableKind TableKind) { |
| 889 | const char *Flags, unsigned RuntimeVer, const char *SplitName, |
| 890 | size_t SplitNameLen, LLVMRustDebugEmissionKind Kind, uint64_t DWOId, |
| 891 | bool SplitDebugInlining, LLVMRustDebugNameTableKind TableKind) { |
| 878 | 892 | auto *File = unwrapDI<DIFile>(FileRef); |
| 879 | 893 | |
| 880 | | return wrap(Builder->createCompileUnit(Lang, File, StringRef(Producer, ProducerLen), |
| 881 | | isOptimized, Flags, RuntimeVer, |
| 882 | | StringRef(SplitName, SplitNameLen), |
| 883 | | fromRust(Kind), DWOId, SplitDebugInlining, |
| 884 | | false, fromRust(TableKind))); |
| 894 | return wrap(Builder->createCompileUnit( |
| 895 | Lang, File, StringRef(Producer, ProducerLen), isOptimized, Flags, |
| 896 | RuntimeVer, StringRef(SplitName, SplitNameLen), fromRust(Kind), DWOId, |
| 897 | SplitDebugInlining, false, fromRust(TableKind))); |
| 885 | 898 | } |
| 886 | 899 | |
| 887 | | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile( |
| 888 | | LLVMRustDIBuilderRef Builder, |
| 889 | | const char *Filename, size_t FilenameLen, |
| 890 | | const char *Directory, size_t DirectoryLen, LLVMRustChecksumKind CSKind, |
| 891 | | const char *Checksum, size_t ChecksumLen) { |
| 900 | extern "C" LLVMMetadataRef |
| 901 | LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename, |
| 902 | size_t FilenameLen, const char *Directory, |
| 903 | size_t DirectoryLen, LLVMRustChecksumKind CSKind, |
| 904 | const char *Checksum, size_t ChecksumLen) { |
| 892 | 905 | |
| 893 | 906 | std::optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind); |
| 894 | 907 | std::optional<DIFile::ChecksumInfo<StringRef>> CSInfo{}; |
| 895 | 908 | if (llvmCSKind) |
| 896 | 909 | CSInfo.emplace(*llvmCSKind, StringRef{Checksum, ChecksumLen}); |
| 897 | 910 | return wrap(Builder->createFile(StringRef(Filename, FilenameLen), |
| 898 | | StringRef(Directory, DirectoryLen), |
| 899 | | CSInfo)); |
| 911 | StringRef(Directory, DirectoryLen), CSInfo)); |
| 900 | 912 | } |
| 901 | 913 | |
| 902 | 914 | extern "C" LLVMMetadataRef |
| ... | ... | @@ -907,63 +919,59 @@ LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder, |
| 907 | 919 | } |
| 908 | 920 | |
| 909 | 921 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction( |
| 910 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 911 | | const char *Name, size_t NameLen, |
| 912 | | const char *LinkageName, size_t LinkageNameLen, |
| 913 | | LLVMMetadataRef File, unsigned LineNo, |
| 914 | | LLVMMetadataRef Ty, unsigned ScopeLine, LLVMRustDIFlags Flags, |
| 915 | | LLVMRustDISPFlags SPFlags, LLVMValueRef MaybeFn, LLVMMetadataRef TParam, |
| 916 | | LLVMMetadataRef Decl) { |
| 922 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 923 | size_t NameLen, const char *LinkageName, size_t LinkageNameLen, |
| 924 | LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 925 | unsigned ScopeLine, LLVMRustDIFlags Flags, LLVMRustDISPFlags SPFlags, |
| 926 | LLVMValueRef MaybeFn, LLVMMetadataRef TParam, LLVMMetadataRef Decl) { |
| 917 | 927 | DITemplateParameterArray TParams = |
| 918 | 928 | DITemplateParameterArray(unwrap<MDTuple>(TParam)); |
| 919 | 929 | DISubprogram::DISPFlags llvmSPFlags = fromRust(SPFlags); |
| 920 | 930 | DINode::DIFlags llvmFlags = fromRust(Flags); |
| 921 | 931 | DISubprogram *Sub = Builder->createFunction( |
| 922 | | unwrapDI<DIScope>(Scope), |
| 923 | | StringRef(Name, NameLen), |
| 924 | | StringRef(LinkageName, LinkageNameLen), |
| 925 | | unwrapDI<DIFile>(File), LineNo, |
| 926 | | unwrapDI<DISubroutineType>(Ty), ScopeLine, llvmFlags, |
| 927 | | llvmSPFlags, TParams, unwrapDIPtr<DISubprogram>(Decl)); |
| 932 | unwrapDI<DIScope>(Scope), StringRef(Name, NameLen), |
| 933 | StringRef(LinkageName, LinkageNameLen), unwrapDI<DIFile>(File), LineNo, |
| 934 | unwrapDI<DISubroutineType>(Ty), ScopeLine, llvmFlags, llvmSPFlags, |
| 935 | TParams, unwrapDIPtr<DISubprogram>(Decl)); |
| 928 | 936 | if (MaybeFn) |
| 929 | 937 | unwrap<Function>(MaybeFn)->setSubprogram(Sub); |
| 930 | 938 | return wrap(Sub); |
| 931 | 939 | } |
| 932 | 940 | |
| 933 | 941 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMethod( |
| 934 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 935 | | const char *Name, size_t NameLen, |
| 936 | | const char *LinkageName, size_t LinkageNameLen, |
| 937 | | LLVMMetadataRef File, unsigned LineNo, |
| 938 | | LLVMMetadataRef Ty, LLVMRustDIFlags Flags, |
| 939 | | LLVMRustDISPFlags SPFlags, LLVMMetadataRef TParam) { |
| 942 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 943 | size_t NameLen, const char *LinkageName, size_t LinkageNameLen, |
| 944 | LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 945 | LLVMRustDIFlags Flags, LLVMRustDISPFlags SPFlags, LLVMMetadataRef TParam) { |
| 940 | 946 | DITemplateParameterArray TParams = |
| 941 | 947 | DITemplateParameterArray(unwrap<MDTuple>(TParam)); |
| 942 | 948 | DISubprogram::DISPFlags llvmSPFlags = fromRust(SPFlags); |
| 943 | 949 | DINode::DIFlags llvmFlags = fromRust(Flags); |
| 944 | 950 | DISubprogram *Sub = Builder->createMethod( |
| 945 | | unwrapDI<DIScope>(Scope), |
| 946 | | StringRef(Name, NameLen), |
| 947 | | StringRef(LinkageName, LinkageNameLen), |
| 948 | | unwrapDI<DIFile>(File), LineNo, |
| 949 | | unwrapDI<DISubroutineType>(Ty), |
| 950 | | 0, 0, nullptr, // VTable params aren't used |
| 951 | unwrapDI<DIScope>(Scope), StringRef(Name, NameLen), |
| 952 | StringRef(LinkageName, LinkageNameLen), unwrapDI<DIFile>(File), LineNo, |
| 953 | unwrapDI<DISubroutineType>(Ty), 0, 0, |
| 954 | nullptr, // VTable params aren't used |
| 951 | 955 | llvmFlags, llvmSPFlags, TParams); |
| 952 | 956 | return wrap(Sub); |
| 953 | 957 | } |
| 954 | 958 | |
| 955 | | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateBasicType( |
| 956 | | LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen, |
| 957 | | uint64_t SizeInBits, unsigned Encoding) { |
| 958 | | return wrap(Builder->createBasicType(StringRef(Name, NameLen), SizeInBits, Encoding)); |
| 959 | extern "C" LLVMMetadataRef |
| 960 | LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name, |
| 961 | size_t NameLen, uint64_t SizeInBits, |
| 962 | unsigned Encoding) { |
| 963 | return wrap( |
| 964 | Builder->createBasicType(StringRef(Name, NameLen), SizeInBits, Encoding)); |
| 959 | 965 | } |
| 960 | 966 | |
| 961 | | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTypedef( |
| 962 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen, |
| 963 | | LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope) { |
| 967 | extern "C" LLVMMetadataRef |
| 968 | LLVMRustDIBuilderCreateTypedef(LLVMRustDIBuilderRef Builder, |
| 969 | LLVMMetadataRef Type, const char *Name, |
| 970 | size_t NameLen, LLVMMetadataRef File, |
| 971 | unsigned LineNo, LLVMMetadataRef Scope) { |
| 964 | 972 | return wrap(Builder->createTypedef( |
| 965 | | unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File), |
| 966 | | LineNo, unwrapDIPtr<DIScope>(Scope))); |
| 973 | unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File), |
| 974 | LineNo, unwrapDIPtr<DIScope>(Scope))); |
| 967 | 975 | } |
| 968 | 976 | |
| 969 | 977 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType( |
| ... | ... | @@ -971,118 +979,98 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType( |
| 971 | 979 | uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, |
| 972 | 980 | const char *Name, size_t NameLen) { |
| 973 | 981 | return wrap(Builder->createPointerType(unwrapDI<DIType>(PointeeTy), |
| 974 | | SizeInBits, AlignInBits, |
| 975 | | AddressSpace, |
| 982 | SizeInBits, AlignInBits, AddressSpace, |
| 976 | 983 | StringRef(Name, NameLen))); |
| 977 | 984 | } |
| 978 | 985 | |
| 979 | 986 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStructType( |
| 980 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 981 | | const char *Name, size_t NameLen, |
| 982 | | LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, |
| 983 | | uint32_t AlignInBits, LLVMRustDIFlags Flags, |
| 984 | | LLVMMetadataRef DerivedFrom, LLVMMetadataRef Elements, |
| 985 | | unsigned RunTimeLang, LLVMMetadataRef VTableHolder, |
| 986 | | const char *UniqueId, size_t UniqueIdLen) { |
| 987 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 988 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
| 989 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMRustDIFlags Flags, |
| 990 | LLVMMetadataRef DerivedFrom, LLVMMetadataRef Elements, unsigned RunTimeLang, |
| 991 | LLVMMetadataRef VTableHolder, const char *UniqueId, size_t UniqueIdLen) { |
| 987 | 992 | return wrap(Builder->createStructType( |
| 988 | 993 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 989 | | unwrapDI<DIFile>(File), LineNumber, |
| 990 | | SizeInBits, AlignInBits, fromRust(Flags), unwrapDI<DIType>(DerivedFrom), |
| 994 | unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits, |
| 995 | fromRust(Flags), unwrapDI<DIType>(DerivedFrom), |
| 991 | 996 | DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang, |
| 992 | 997 | unwrapDI<DIType>(VTableHolder), StringRef(UniqueId, UniqueIdLen))); |
| 993 | 998 | } |
| 994 | 999 | |
| 995 | 1000 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart( |
| 996 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 997 | | const char *Name, size_t NameLen, |
| 998 | | LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, |
| 999 | | uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMMetadataRef Discriminator, |
| 1000 | | LLVMMetadataRef Elements, const char *UniqueId, size_t UniqueIdLen) { |
| 1001 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1002 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
| 1003 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMRustDIFlags Flags, |
| 1004 | LLVMMetadataRef Discriminator, LLVMMetadataRef Elements, |
| 1005 | const char *UniqueId, size_t UniqueIdLen) { |
| 1001 | 1006 | return wrap(Builder->createVariantPart( |
| 1002 | 1007 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1003 | | unwrapDI<DIFile>(File), LineNumber, |
| 1004 | | SizeInBits, AlignInBits, fromRust(Flags), unwrapDI<DIDerivedType>(Discriminator), |
| 1005 | | DINodeArray(unwrapDI<MDTuple>(Elements)), StringRef(UniqueId, UniqueIdLen))); |
| 1008 | unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits, |
| 1009 | fromRust(Flags), unwrapDI<DIDerivedType>(Discriminator), |
| 1010 | DINodeArray(unwrapDI<MDTuple>(Elements)), |
| 1011 | StringRef(UniqueId, UniqueIdLen))); |
| 1006 | 1012 | } |
| 1007 | 1013 | |
| 1008 | 1014 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMemberType( |
| 1009 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 1010 | | const char *Name, size_t NameLen, |
| 1011 | | LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, |
| 1015 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1016 | size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, |
| 1012 | 1017 | uint32_t AlignInBits, uint64_t OffsetInBits, LLVMRustDIFlags Flags, |
| 1013 | 1018 | LLVMMetadataRef Ty) { |
| 1014 | | return wrap(Builder->createMemberType(unwrapDI<DIDescriptor>(Scope), |
| 1015 | | StringRef(Name, NameLen), |
| 1016 | | unwrapDI<DIFile>(File), LineNo, |
| 1017 | | SizeInBits, AlignInBits, OffsetInBits, |
| 1018 | | fromRust(Flags), unwrapDI<DIType>(Ty))); |
| 1019 | return wrap(Builder->createMemberType( |
| 1020 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1021 | unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits, OffsetInBits, |
| 1022 | fromRust(Flags), unwrapDI<DIType>(Ty))); |
| 1019 | 1023 | } |
| 1020 | 1024 | |
| 1021 | 1025 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType( |
| 1022 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 1023 | | const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, |
| 1024 | | uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMValueRef Discriminant, |
| 1026 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1027 | size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, |
| 1028 | uint32_t AlignInBits, uint64_t OffsetInBits, LLVMValueRef Discriminant, |
| 1025 | 1029 | LLVMRustDIFlags Flags, LLVMMetadataRef Ty) { |
| 1026 | | llvm::ConstantInt* D = nullptr; |
| 1030 | llvm::ConstantInt *D = nullptr; |
| 1027 | 1031 | if (Discriminant) { |
| 1028 | 1032 | D = unwrap<llvm::ConstantInt>(Discriminant); |
| 1029 | 1033 | } |
| 1030 | | return wrap(Builder->createVariantMemberType(unwrapDI<DIDescriptor>(Scope), |
| 1031 | | StringRef(Name, NameLen), |
| 1032 | | unwrapDI<DIFile>(File), LineNo, |
| 1033 | | SizeInBits, AlignInBits, OffsetInBits, D, |
| 1034 | | fromRust(Flags), unwrapDI<DIType>(Ty))); |
| 1034 | return wrap(Builder->createVariantMemberType( |
| 1035 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1036 | unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits, OffsetInBits, D, |
| 1037 | fromRust(Flags), unwrapDI<DIType>(Ty))); |
| 1035 | 1038 | } |
| 1036 | 1039 | |
| 1037 | 1040 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType( |
| 1038 | | LLVMRustDIBuilderRef Builder, |
| 1039 | | LLVMMetadataRef Scope, |
| 1040 | | const char *Name, |
| 1041 | | size_t NameLen, |
| 1042 | | LLVMMetadataRef File, |
| 1043 | | unsigned LineNo, |
| 1044 | | LLVMMetadataRef Ty, |
| 1045 | | LLVMRustDIFlags Flags, |
| 1046 | | LLVMValueRef val, |
| 1047 | | uint32_t AlignInBits |
| 1048 | | ) { |
| 1041 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1042 | size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 1043 | LLVMRustDIFlags Flags, LLVMValueRef val, uint32_t AlignInBits) { |
| 1049 | 1044 | return wrap(Builder->createStaticMemberType( |
| 1050 | | unwrapDI<DIDescriptor>(Scope), |
| 1051 | | StringRef(Name, NameLen), |
| 1052 | | unwrapDI<DIFile>(File), |
| 1053 | | LineNo, |
| 1054 | | unwrapDI<DIType>(Ty), |
| 1055 | | fromRust(Flags), |
| 1056 | | unwrap<llvm::ConstantInt>(val), |
| 1045 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1046 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), fromRust(Flags), |
| 1047 | unwrap<llvm::ConstantInt>(val), |
| 1057 | 1048 | #if LLVM_VERSION_GE(18, 0) |
| 1058 | | llvm::dwarf::DW_TAG_member, |
| 1049 | llvm::dwarf::DW_TAG_member, |
| 1059 | 1050 | #endif |
| 1060 | | AlignInBits |
| 1061 | | )); |
| 1051 | AlignInBits)); |
| 1062 | 1052 | } |
| 1063 | 1053 | |
| 1064 | | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateLexicalBlock( |
| 1065 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 1066 | | LLVMMetadataRef File, unsigned Line, unsigned Col) { |
| 1054 | extern "C" LLVMMetadataRef |
| 1055 | LLVMRustDIBuilderCreateLexicalBlock(LLVMRustDIBuilderRef Builder, |
| 1056 | LLVMMetadataRef Scope, LLVMMetadataRef File, |
| 1057 | unsigned Line, unsigned Col) { |
| 1067 | 1058 | return wrap(Builder->createLexicalBlock(unwrapDI<DIDescriptor>(Scope), |
| 1068 | 1059 | unwrapDI<DIFile>(File), Line, Col)); |
| 1069 | 1060 | } |
| 1070 | 1061 | |
| 1071 | | extern "C" LLVMMetadataRef |
| 1072 | | LLVMRustDIBuilderCreateLexicalBlockFile(LLVMRustDIBuilderRef Builder, |
| 1073 | | LLVMMetadataRef Scope, |
| 1074 | | LLVMMetadataRef File) { |
| 1062 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateLexicalBlockFile( |
| 1063 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File) { |
| 1075 | 1064 | return wrap(Builder->createLexicalBlockFile(unwrapDI<DIDescriptor>(Scope), |
| 1076 | 1065 | unwrapDI<DIFile>(File))); |
| 1077 | 1066 | } |
| 1078 | 1067 | |
| 1079 | 1068 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable( |
| 1080 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Context, |
| 1081 | | const char *Name, size_t NameLen, |
| 1082 | | const char *LinkageName, size_t LinkageNameLen, |
| 1083 | | LLVMMetadataRef File, unsigned LineNo, |
| 1084 | | LLVMMetadataRef Ty, bool IsLocalToUnit, LLVMValueRef V, |
| 1085 | | LLVMMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) { |
| 1069 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name, |
| 1070 | size_t NameLen, const char *LinkageName, size_t LinkageNameLen, |
| 1071 | LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, |
| 1072 | bool IsLocalToUnit, LLVMValueRef V, LLVMMetadataRef Decl = nullptr, |
| 1073 | uint32_t AlignInBits = 0) { |
| 1086 | 1074 | llvm::GlobalVariable *InitVal = cast<llvm::GlobalVariable>(unwrap(V)); |
| 1087 | 1075 | |
| 1088 | 1076 | llvm::DIExpression *InitExpr = nullptr; |
| ... | ... | @@ -1095,14 +1083,13 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable( |
| 1095 | 1083 | FPVal->getValueAPF().bitcastToAPInt().getZExtValue()); |
| 1096 | 1084 | } |
| 1097 | 1085 | |
| 1098 | | llvm::DIGlobalVariableExpression *VarExpr = Builder->createGlobalVariableExpression( |
| 1099 | | unwrapDI<DIDescriptor>(Context), StringRef(Name, NameLen), |
| 1100 | | StringRef(LinkageName, LinkageNameLen), |
| 1101 | | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit, |
| 1102 | | /* isDefined */ true, |
| 1103 | | InitExpr, unwrapDIPtr<MDNode>(Decl), |
| 1104 | | /* templateParams */ nullptr, |
| 1105 | | AlignInBits); |
| 1086 | llvm::DIGlobalVariableExpression *VarExpr = |
| 1087 | Builder->createGlobalVariableExpression( |
| 1088 | unwrapDI<DIDescriptor>(Context), StringRef(Name, NameLen), |
| 1089 | StringRef(LinkageName, LinkageNameLen), unwrapDI<DIFile>(File), |
| 1090 | LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit, |
| 1091 | /* isDefined */ true, InitExpr, unwrapDIPtr<MDNode>(Decl), |
| 1092 | /* templateParams */ nullptr, AlignInBits); |
| 1106 | 1093 | |
| 1107 | 1094 | InitVal->setMetadata("dbg", VarExpr); |
| 1108 | 1095 | |
| ... | ... | @@ -1111,20 +1098,19 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable( |
| 1111 | 1098 | |
| 1112 | 1099 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable( |
| 1113 | 1100 | LLVMRustDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Scope, |
| 1114 | | const char *Name, size_t NameLen, |
| 1115 | | LLVMMetadataRef File, unsigned LineNo, |
| 1101 | const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, |
| 1116 | 1102 | LLVMMetadataRef Ty, bool AlwaysPreserve, LLVMRustDIFlags Flags, |
| 1117 | 1103 | unsigned ArgNo, uint32_t AlignInBits) { |
| 1118 | 1104 | if (Tag == 0x100) { // DW_TAG_auto_variable |
| 1119 | 1105 | return wrap(Builder->createAutoVariable( |
| 1120 | 1106 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1121 | | unwrapDI<DIFile>(File), LineNo, |
| 1122 | | unwrapDI<DIType>(Ty), AlwaysPreserve, fromRust(Flags), AlignInBits)); |
| 1107 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), AlwaysPreserve, |
| 1108 | fromRust(Flags), AlignInBits)); |
| 1123 | 1109 | } else { |
| 1124 | 1110 | return wrap(Builder->createParameterVariable( |
| 1125 | 1111 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), ArgNo, |
| 1126 | | unwrapDI<DIFile>(File), LineNo, |
| 1127 | | unwrapDI<DIType>(Ty), AlwaysPreserve, fromRust(Flags))); |
| 1112 | unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), AlwaysPreserve, |
| 1113 | fromRust(Flags))); |
| 1128 | 1114 | } |
| 1129 | 1115 | } |
| 1130 | 1116 | |
| ... | ... | @@ -1157,9 +1143,9 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( |
| 1157 | 1143 | LLVMBasicBlockRef InsertAtEnd) { |
| 1158 | 1144 | auto Result = Builder->insertDeclare( |
| 1159 | 1145 | unwrap(V), unwrap<DILocalVariable>(VarInfo), |
| 1160 | | Builder->createExpression(llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)), |
| 1161 | | DebugLoc(cast<MDNode>(unwrap(DL))), |
| 1162 | | unwrap(InsertAtEnd)); |
| 1146 | Builder->createExpression( |
| 1147 | llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)), |
| 1148 | DebugLoc(cast<MDNode>(unwrap(DL))), unwrap(InsertAtEnd)); |
| 1163 | 1149 | #if LLVM_VERSION_GE(19, 0) |
| 1164 | 1150 | return wrap(Result.get<llvm::Instruction *>()); |
| 1165 | 1151 | #else |
| ... | ... | @@ -1170,21 +1156,20 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( |
| 1170 | 1156 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator( |
| 1171 | 1157 | LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen, |
| 1172 | 1158 | const uint64_t Value[2], unsigned SizeInBits, bool IsUnsigned) { |
| 1173 | | return wrap(Builder->createEnumerator(StringRef(Name, NameLen), |
| 1159 | return wrap(Builder->createEnumerator( |
| 1160 | StringRef(Name, NameLen), |
| 1174 | 1161 | APSInt(APInt(SizeInBits, ArrayRef<uint64_t>(Value, 2)), IsUnsigned))); |
| 1175 | 1162 | } |
| 1176 | 1163 | |
| 1177 | 1164 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType( |
| 1178 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 1179 | | const char *Name, size_t NameLen, |
| 1180 | | LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, |
| 1181 | | uint32_t AlignInBits, LLVMMetadataRef Elements, |
| 1165 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1166 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
| 1167 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef Elements, |
| 1182 | 1168 | LLVMMetadataRef ClassTy, bool IsScoped) { |
| 1183 | 1169 | return wrap(Builder->createEnumerationType( |
| 1184 | 1170 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1185 | | unwrapDI<DIFile>(File), LineNumber, |
| 1186 | | SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)), |
| 1187 | | unwrapDI<DIType>(ClassTy), |
| 1171 | unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits, |
| 1172 | DINodeArray(unwrapDI<MDTuple>(Elements)), unwrapDI<DIType>(ClassTy), |
| 1188 | 1173 | #if LLVM_VERSION_GE(18, 0) |
| 1189 | 1174 | /* RunTimeLang */ 0, |
| 1190 | 1175 | #endif |
| ... | ... | @@ -1192,39 +1177,38 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType( |
| 1192 | 1177 | } |
| 1193 | 1178 | |
| 1194 | 1179 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType( |
| 1195 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 1196 | | const char *Name, size_t NameLen, |
| 1197 | | LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, |
| 1198 | | uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMMetadataRef Elements, |
| 1199 | | unsigned RunTimeLang, const char *UniqueId, size_t UniqueIdLen) { |
| 1180 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1181 | size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |
| 1182 | uint64_t SizeInBits, uint32_t AlignInBits, LLVMRustDIFlags Flags, |
| 1183 | LLVMMetadataRef Elements, unsigned RunTimeLang, const char *UniqueId, |
| 1184 | size_t UniqueIdLen) { |
| 1200 | 1185 | return wrap(Builder->createUnionType( |
| 1201 | | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), unwrapDI<DIFile>(File), |
| 1202 | | LineNumber, SizeInBits, AlignInBits, fromRust(Flags), |
| 1203 | | DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang, |
| 1186 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1187 | unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits, |
| 1188 | fromRust(Flags), DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang, |
| 1204 | 1189 | StringRef(UniqueId, UniqueIdLen))); |
| 1205 | 1190 | } |
| 1206 | 1191 | |
| 1207 | 1192 | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter( |
| 1208 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 1209 | | const char *Name, size_t NameLen, LLVMMetadataRef Ty) { |
| 1193 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, |
| 1194 | size_t NameLen, LLVMMetadataRef Ty) { |
| 1210 | 1195 | bool IsDefault = false; // FIXME: should we ever set this true? |
| 1211 | 1196 | return wrap(Builder->createTemplateTypeParameter( |
| 1212 | | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), unwrapDI<DIType>(Ty), IsDefault)); |
| 1197 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), |
| 1198 | unwrapDI<DIType>(Ty), IsDefault)); |
| 1213 | 1199 | } |
| 1214 | 1200 | |
| 1215 | | extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateNameSpace( |
| 1216 | | LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, |
| 1217 | | const char *Name, size_t NameLen, bool ExportSymbols) { |
| 1201 | extern "C" LLVMMetadataRef |
| 1202 | LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder, |
| 1203 | LLVMMetadataRef Scope, const char *Name, |
| 1204 | size_t NameLen, bool ExportSymbols) { |
| 1218 | 1205 | return wrap(Builder->createNameSpace( |
| 1219 | | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), ExportSymbols |
| 1220 | | )); |
| 1206 | unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), ExportSymbols)); |
| 1221 | 1207 | } |
| 1222 | 1208 | |
| 1223 | | extern "C" void |
| 1224 | | LLVMRustDICompositeTypeReplaceArrays(LLVMRustDIBuilderRef Builder, |
| 1225 | | LLVMMetadataRef CompositeTy, |
| 1226 | | LLVMMetadataRef Elements, |
| 1227 | | LLVMMetadataRef Params) { |
| 1209 | extern "C" void LLVMRustDICompositeTypeReplaceArrays( |
| 1210 | LLVMRustDIBuilderRef Builder, LLVMMetadataRef CompositeTy, |
| 1211 | LLVMMetadataRef Elements, LLVMMetadataRef Params) { |
| 1228 | 1212 | DICompositeType *Tmp = unwrapDI<DICompositeType>(CompositeTy); |
| 1229 | 1213 | Builder->replaceArrays(Tmp, DINodeArray(unwrap<MDTuple>(Elements)), |
| 1230 | 1214 | DINodeArray(unwrap<MDTuple>(Params))); |
| ... | ... | @@ -1235,9 +1219,8 @@ LLVMRustDIBuilderCreateDebugLocation(unsigned Line, unsigned Column, |
| 1235 | 1219 | LLVMMetadataRef ScopeRef, |
| 1236 | 1220 | LLVMMetadataRef InlinedAt) { |
| 1237 | 1221 | MDNode *Scope = unwrapDIPtr<MDNode>(ScopeRef); |
| 1238 | | DILocation *Loc = DILocation::get( |
| 1239 | | Scope->getContext(), Line, Column, Scope, |
| 1240 | | unwrapDIPtr<MDNode>(InlinedAt)); |
| 1222 | DILocation *Loc = DILocation::get(Scope->getContext(), Line, Column, Scope, |
| 1223 | unwrapDIPtr<MDNode>(InlinedAt)); |
| 1241 | 1224 | return wrap(Loc); |
| 1242 | 1225 | } |
| 1243 | 1226 | |
| ... | ... | @@ -1258,8 +1241,7 @@ extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) { |
| 1258 | 1241 | unwrap<llvm::Type>(Ty)->print(OS); |
| 1259 | 1242 | } |
| 1260 | 1243 | |
| 1261 | | extern "C" void LLVMRustWriteValueToString(LLVMValueRef V, |
| 1262 | | RustStringRef Str) { |
| 1244 | extern "C" void LLVMRustWriteValueToString(LLVMValueRef V, RustStringRef Str) { |
| 1263 | 1245 | auto OS = RawRustStringOstream(Str); |
| 1264 | 1246 | if (!V) { |
| 1265 | 1247 | OS << "(null)"; |
| ... | ... | @@ -1281,7 +1263,7 @@ extern "C" void LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef Str) { |
| 1281 | 1263 | |
| 1282 | 1264 | extern "C" void LLVMRustUnpackOptimizationDiagnostic( |
| 1283 | 1265 | LLVMDiagnosticInfoRef DI, RustStringRef PassNameOut, |
| 1284 | | LLVMValueRef *FunctionOut, unsigned* Line, unsigned* Column, |
| 1266 | LLVMValueRef *FunctionOut, unsigned *Line, unsigned *Column, |
| 1285 | 1267 | RustStringRef FilenameOut, RustStringRef MessageOut) { |
| 1286 | 1268 | // Undefined to call this not on an optimization diagnostic! |
| 1287 | 1269 | llvm::DiagnosticInfoOptimizationBase *Opt = |
| ... | ... | @@ -1304,17 +1286,15 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic( |
| 1304 | 1286 | } |
| 1305 | 1287 | |
| 1306 | 1288 | enum class LLVMRustDiagnosticLevel { |
| 1307 | | Error, |
| 1308 | | Warning, |
| 1309 | | Note, |
| 1310 | | Remark, |
| 1289 | Error, |
| 1290 | Warning, |
| 1291 | Note, |
| 1292 | Remark, |
| 1311 | 1293 | }; |
| 1312 | 1294 | |
| 1313 | | extern "C" void |
| 1314 | | LLVMRustUnpackInlineAsmDiagnostic(LLVMDiagnosticInfoRef DI, |
| 1315 | | LLVMRustDiagnosticLevel *LevelOut, |
| 1316 | | uint64_t *CookieOut, |
| 1317 | | LLVMTwineRef *MessageOut) { |
| 1295 | extern "C" void LLVMRustUnpackInlineAsmDiagnostic( |
| 1296 | LLVMDiagnosticInfoRef DI, LLVMRustDiagnosticLevel *LevelOut, |
| 1297 | uint64_t *CookieOut, LLVMTwineRef *MessageOut) { |
| 1318 | 1298 | // Undefined to call this not on an inline assembly diagnostic! |
| 1319 | 1299 | llvm::DiagnosticInfoInlineAsm *IA = |
| 1320 | 1300 | static_cast<llvm::DiagnosticInfoInlineAsm *>(unwrap(DI)); |
| ... | ... | @@ -1323,20 +1303,20 @@ LLVMRustUnpackInlineAsmDiagnostic(LLVMDiagnosticInfoRef DI, |
| 1323 | 1303 | *MessageOut = wrap(&IA->getMsgStr()); |
| 1324 | 1304 | |
| 1325 | 1305 | switch (IA->getSeverity()) { |
| 1326 | | case DS_Error: |
| 1327 | | *LevelOut = LLVMRustDiagnosticLevel::Error; |
| 1328 | | break; |
| 1329 | | case DS_Warning: |
| 1330 | | *LevelOut = LLVMRustDiagnosticLevel::Warning; |
| 1331 | | break; |
| 1332 | | case DS_Note: |
| 1333 | | *LevelOut = LLVMRustDiagnosticLevel::Note; |
| 1334 | | break; |
| 1335 | | case DS_Remark: |
| 1336 | | *LevelOut = LLVMRustDiagnosticLevel::Remark; |
| 1337 | | break; |
| 1338 | | default: |
| 1339 | | report_fatal_error("Invalid LLVMRustDiagnosticLevel value!"); |
| 1306 | case DS_Error: |
| 1307 | *LevelOut = LLVMRustDiagnosticLevel::Error; |
| 1308 | break; |
| 1309 | case DS_Warning: |
| 1310 | *LevelOut = LLVMRustDiagnosticLevel::Warning; |
| 1311 | break; |
| 1312 | case DS_Note: |
| 1313 | *LevelOut = LLVMRustDiagnosticLevel::Note; |
| 1314 | break; |
| 1315 | case DS_Remark: |
| 1316 | *LevelOut = LLVMRustDiagnosticLevel::Remark; |
| 1317 | break; |
| 1318 | default: |
| 1319 | report_fatal_error("Invalid LLVMRustDiagnosticLevel value!"); |
| 1340 | 1320 | } |
| 1341 | 1321 | } |
| 1342 | 1322 | |
| ... | ... | @@ -1454,61 +1434,61 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) { |
| 1454 | 1434 | return LLVMBFloatTypeKind; |
| 1455 | 1435 | case Type::X86_AMXTyID: |
| 1456 | 1436 | return LLVMX86_AMXTypeKind; |
| 1457 | | default: |
| 1458 | | { |
| 1459 | | std::string error; |
| 1460 | | auto stream = llvm::raw_string_ostream(error); |
| 1461 | | stream << "Rust does not support the TypeID: " << unwrap(Ty)->getTypeID() |
| 1462 | | << " for the type: " << *unwrap(Ty); |
| 1463 | | stream.flush(); |
| 1464 | | report_fatal_error(error.c_str()); |
| 1465 | | } |
| 1437 | default: { |
| 1438 | std::string error; |
| 1439 | auto stream = llvm::raw_string_ostream(error); |
| 1440 | stream << "Rust does not support the TypeID: " << unwrap(Ty)->getTypeID() |
| 1441 | << " for the type: " << *unwrap(Ty); |
| 1442 | stream.flush(); |
| 1443 | report_fatal_error(error.c_str()); |
| 1444 | } |
| 1466 | 1445 | } |
| 1467 | 1446 | } |
| 1468 | 1447 | |
| 1469 | 1448 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef) |
| 1470 | 1449 | |
| 1471 | | extern "C" LLVMSMDiagnosticRef LLVMRustGetSMDiagnostic( |
| 1472 | | LLVMDiagnosticInfoRef DI, unsigned *Cookie) { |
| 1473 | | llvm::DiagnosticInfoSrcMgr *SM = static_cast<llvm::DiagnosticInfoSrcMgr *>(unwrap(DI)); |
| 1450 | extern "C" LLVMSMDiagnosticRef LLVMRustGetSMDiagnostic(LLVMDiagnosticInfoRef DI, |
| 1451 | unsigned *Cookie) { |
| 1452 | llvm::DiagnosticInfoSrcMgr *SM = |
| 1453 | static_cast<llvm::DiagnosticInfoSrcMgr *>(unwrap(DI)); |
| 1474 | 1454 | *Cookie = SM->getLocCookie(); |
| 1475 | 1455 | return wrap(&SM->getSMDiag()); |
| 1476 | 1456 | } |
| 1477 | 1457 | |
| 1478 | | extern "C" bool LLVMRustUnpackSMDiagnostic(LLVMSMDiagnosticRef DRef, |
| 1479 | | RustStringRef MessageOut, |
| 1480 | | RustStringRef BufferOut, |
| 1481 | | LLVMRustDiagnosticLevel* LevelOut, |
| 1482 | | unsigned* LocOut, |
| 1483 | | unsigned* RangesOut, |
| 1484 | | size_t* NumRanges) { |
| 1485 | | SMDiagnostic& D = *unwrap(DRef); |
| 1458 | extern "C" bool |
| 1459 | LLVMRustUnpackSMDiagnostic(LLVMSMDiagnosticRef DRef, RustStringRef MessageOut, |
| 1460 | RustStringRef BufferOut, |
| 1461 | LLVMRustDiagnosticLevel *LevelOut, unsigned *LocOut, |
| 1462 | unsigned *RangesOut, size_t *NumRanges) { |
| 1463 | SMDiagnostic &D = *unwrap(DRef); |
| 1486 | 1464 | auto MessageOS = RawRustStringOstream(MessageOut); |
| 1487 | 1465 | MessageOS << D.getMessage(); |
| 1488 | 1466 | |
| 1489 | 1467 | switch (D.getKind()) { |
| 1490 | | case SourceMgr::DK_Error: |
| 1491 | | *LevelOut = LLVMRustDiagnosticLevel::Error; |
| 1492 | | break; |
| 1493 | | case SourceMgr::DK_Warning: |
| 1494 | | *LevelOut = LLVMRustDiagnosticLevel::Warning; |
| 1495 | | break; |
| 1496 | | case SourceMgr::DK_Note: |
| 1497 | | *LevelOut = LLVMRustDiagnosticLevel::Note; |
| 1498 | | break; |
| 1499 | | case SourceMgr::DK_Remark: |
| 1500 | | *LevelOut = LLVMRustDiagnosticLevel::Remark; |
| 1501 | | break; |
| 1502 | | default: |
| 1503 | | report_fatal_error("Invalid LLVMRustDiagnosticLevel value!"); |
| 1468 | case SourceMgr::DK_Error: |
| 1469 | *LevelOut = LLVMRustDiagnosticLevel::Error; |
| 1470 | break; |
| 1471 | case SourceMgr::DK_Warning: |
| 1472 | *LevelOut = LLVMRustDiagnosticLevel::Warning; |
| 1473 | break; |
| 1474 | case SourceMgr::DK_Note: |
| 1475 | *LevelOut = LLVMRustDiagnosticLevel::Note; |
| 1476 | break; |
| 1477 | case SourceMgr::DK_Remark: |
| 1478 | *LevelOut = LLVMRustDiagnosticLevel::Remark; |
| 1479 | break; |
| 1480 | default: |
| 1481 | report_fatal_error("Invalid LLVMRustDiagnosticLevel value!"); |
| 1504 | 1482 | } |
| 1505 | 1483 | |
| 1506 | 1484 | if (D.getLoc() == SMLoc()) |
| 1507 | 1485 | return false; |
| 1508 | 1486 | |
| 1509 | 1487 | const SourceMgr &LSM = *D.getSourceMgr(); |
| 1510 | | const MemoryBuffer *LBuf = LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc())); |
| 1511 | | LLVMRustStringWriteImpl(BufferOut, LBuf->getBufferStart(), LBuf->getBufferSize()); |
| 1488 | const MemoryBuffer *LBuf = |
| 1489 | LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc())); |
| 1490 | LLVMRustStringWriteImpl(BufferOut, LBuf->getBufferStart(), |
| 1491 | LBuf->getBufferSize()); |
| 1512 | 1492 | |
| 1513 | 1493 | *LocOut = D.getLoc().getPointer() - LBuf->getBufferStart(); |
| 1514 | 1494 | |
| ... | ... | @@ -1525,7 +1505,8 @@ extern "C" bool LLVMRustUnpackSMDiagnostic(LLVMSMDiagnosticRef DRef, |
| 1525 | 1505 | extern "C" OperandBundleDef *LLVMRustBuildOperandBundleDef(const char *Name, |
| 1526 | 1506 | LLVMValueRef *Inputs, |
| 1527 | 1507 | unsigned NumInputs) { |
| 1528 | | return new OperandBundleDef(Name, ArrayRef<Value*>(unwrap(Inputs), NumInputs)); |
| 1508 | return new OperandBundleDef(Name, |
| 1509 | ArrayRef<Value *>(unwrap(Inputs), NumInputs)); |
| 1529 | 1510 | } |
| 1530 | 1511 | |
| 1531 | 1512 | extern "C" void LLVMRustFreeOperandBundleDef(OperandBundleDef *Bundle) { |
| ... | ... | @@ -1533,8 +1514,9 @@ extern "C" void LLVMRustFreeOperandBundleDef(OperandBundleDef *Bundle) { |
| 1533 | 1514 | } |
| 1534 | 1515 | |
| 1535 | 1516 | // OpBundlesIndirect is an array of pointers (*not* a pointer to an array). |
| 1536 | | extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, |
| 1537 | | LLVMValueRef *Args, unsigned NumArgs, |
| 1517 | extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1518 | LLVMValueRef Fn, LLVMValueRef *Args, |
| 1519 | unsigned NumArgs, |
| 1538 | 1520 | OperandBundleDef **OpBundlesIndirect, |
| 1539 | 1521 | unsigned NumOpBundles) { |
| 1540 | 1522 | Value *Callee = unwrap(Fn); |
| ... | ... | @@ -1547,17 +1529,19 @@ extern "C" LLVMValueRef LLVMRustBuildCall(LLVMBuilderRef B, LLVMTypeRef Ty, LLVM |
| 1547 | 1529 | OpBundles.push_back(*OpBundlesIndirect[i]); |
| 1548 | 1530 | } |
| 1549 | 1531 | |
| 1550 | | return wrap(unwrap(B)->CreateCall( |
| 1551 | | FTy, Callee, ArrayRef<Value*>(unwrap(Args), NumArgs), |
| 1552 | | ArrayRef<OperandBundleDef>(OpBundles))); |
| 1532 | return wrap(unwrap(B)->CreateCall(FTy, Callee, |
| 1533 | ArrayRef<Value *>(unwrap(Args), NumArgs), |
| 1534 | ArrayRef<OperandBundleDef>(OpBundles))); |
| 1553 | 1535 | } |
| 1554 | 1536 | |
| 1555 | | extern "C" LLVMValueRef LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M) { |
| 1537 | extern "C" LLVMValueRef |
| 1538 | LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M) { |
| 1556 | 1539 | return wrap(llvm::Intrinsic::getDeclaration( |
| 1557 | 1540 | unwrap(M), llvm::Intrinsic::instrprof_increment)); |
| 1558 | 1541 | } |
| 1559 | 1542 | |
| 1560 | | extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) { |
| 1543 | extern "C" LLVMValueRef |
| 1544 | LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) { |
| 1561 | 1545 | #if LLVM_VERSION_GE(18, 0) |
| 1562 | 1546 | return wrap(llvm::Intrinsic::getDeclaration( |
| 1563 | 1547 | unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters)); |
| ... | ... | @@ -1566,7 +1550,8 @@ extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRe |
| 1566 | 1550 | #endif |
| 1567 | 1551 | } |
| 1568 | 1552 | |
| 1569 | | extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) { |
| 1553 | extern "C" LLVMValueRef |
| 1554 | LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) { |
| 1570 | 1555 | #if LLVM_VERSION_GE(18, 0) |
| 1571 | 1556 | return wrap(llvm::Intrinsic::getDeclaration( |
| 1572 | 1557 | unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update)); |
| ... | ... | @@ -1575,7 +1560,8 @@ extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModu |
| 1575 | 1560 | #endif |
| 1576 | 1561 | } |
| 1577 | 1562 | |
| 1578 | | extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) { |
| 1563 | extern "C" LLVMValueRef |
| 1564 | LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) { |
| 1579 | 1565 | #if LLVM_VERSION_GE(18, 0) |
| 1580 | 1566 | return wrap(llvm::Intrinsic::getDeclaration( |
| 1581 | 1567 | unwrap(M), llvm::Intrinsic::instrprof_mcdc_condbitmap_update)); |
| ... | ... | @@ -1584,32 +1570,31 @@ extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRe |
| 1584 | 1570 | #endif |
| 1585 | 1571 | } |
| 1586 | 1572 | |
| 1587 | | extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B, |
| 1588 | | LLVMValueRef Dst, unsigned DstAlign, |
| 1589 | | LLVMValueRef Src, unsigned SrcAlign, |
| 1590 | | LLVMValueRef Size, bool IsVolatile) { |
| 1591 | | return wrap(unwrap(B)->CreateMemCpy( |
| 1592 | | unwrap(Dst), MaybeAlign(DstAlign), |
| 1593 | | unwrap(Src), MaybeAlign(SrcAlign), |
| 1594 | | unwrap(Size), IsVolatile)); |
| 1573 | extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst, |
| 1574 | unsigned DstAlign, LLVMValueRef Src, |
| 1575 | unsigned SrcAlign, |
| 1576 | LLVMValueRef Size, |
| 1577 | bool IsVolatile) { |
| 1578 | return wrap(unwrap(B)->CreateMemCpy(unwrap(Dst), MaybeAlign(DstAlign), |
| 1579 | unwrap(Src), MaybeAlign(SrcAlign), |
| 1580 | unwrap(Size), IsVolatile)); |
| 1595 | 1581 | } |
| 1596 | 1582 | |
| 1597 | | extern "C" LLVMValueRef LLVMRustBuildMemMove(LLVMBuilderRef B, |
| 1598 | | LLVMValueRef Dst, unsigned DstAlign, |
| 1599 | | LLVMValueRef Src, unsigned SrcAlign, |
| 1600 | | LLVMValueRef Size, bool IsVolatile) { |
| 1601 | | return wrap(unwrap(B)->CreateMemMove( |
| 1602 | | unwrap(Dst), MaybeAlign(DstAlign), |
| 1603 | | unwrap(Src), MaybeAlign(SrcAlign), |
| 1604 | | unwrap(Size), IsVolatile)); |
| 1583 | extern "C" LLVMValueRef |
| 1584 | LLVMRustBuildMemMove(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign, |
| 1585 | LLVMValueRef Src, unsigned SrcAlign, LLVMValueRef Size, |
| 1586 | bool IsVolatile) { |
| 1587 | return wrap(unwrap(B)->CreateMemMove(unwrap(Dst), MaybeAlign(DstAlign), |
| 1588 | unwrap(Src), MaybeAlign(SrcAlign), |
| 1589 | unwrap(Size), IsVolatile)); |
| 1605 | 1590 | } |
| 1606 | 1591 | |
| 1607 | | extern "C" LLVMValueRef LLVMRustBuildMemSet(LLVMBuilderRef B, |
| 1608 | | LLVMValueRef Dst, unsigned DstAlign, |
| 1609 | | LLVMValueRef Val, |
| 1610 | | LLVMValueRef Size, bool IsVolatile) { |
| 1611 | | return wrap(unwrap(B)->CreateMemSet( |
| 1612 | | unwrap(Dst), unwrap(Val), unwrap(Size), MaybeAlign(DstAlign), IsVolatile)); |
| 1592 | extern "C" LLVMValueRef LLVMRustBuildMemSet(LLVMBuilderRef B, LLVMValueRef Dst, |
| 1593 | unsigned DstAlign, LLVMValueRef Val, |
| 1594 | LLVMValueRef Size, |
| 1595 | bool IsVolatile) { |
| 1596 | return wrap(unwrap(B)->CreateMemSet(unwrap(Dst), unwrap(Val), unwrap(Size), |
| 1597 | MaybeAlign(DstAlign), IsVolatile)); |
| 1613 | 1598 | } |
| 1614 | 1599 | |
| 1615 | 1600 | // OpBundlesIndirect is an array of pointers (*not* a pointer to an array). |
| ... | ... | @@ -1630,7 +1615,7 @@ LLVMRustBuildInvoke(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, |
| 1630 | 1615 | } |
| 1631 | 1616 | |
| 1632 | 1617 | return wrap(unwrap(B)->CreateInvoke(FTy, Callee, unwrap(Then), unwrap(Catch), |
| 1633 | | ArrayRef<Value*>(unwrap(Args), NumArgs), |
| 1618 | ArrayRef<Value *>(unwrap(Args), NumArgs), |
| 1634 | 1619 | ArrayRef<OperandBundleDef>(OpBundles), |
| 1635 | 1620 | Name)); |
| 1636 | 1621 | } |
| ... | ... | @@ -1647,7 +1632,7 @@ LLVMRustBuildCallBr(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, |
| 1647 | 1632 | FunctionType *FTy = unwrap<FunctionType>(Ty); |
| 1648 | 1633 | |
| 1649 | 1634 | // FIXME: Is there a way around this? |
| 1650 | | std::vector<BasicBlock*> IndirectDestsUnwrapped; |
| 1635 | std::vector<BasicBlock *> IndirectDestsUnwrapped; |
| 1651 | 1636 | IndirectDestsUnwrapped.reserve(NumIndirectDests); |
| 1652 | 1637 | for (unsigned i = 0; i < NumIndirectDests; ++i) { |
| 1653 | 1638 | IndirectDestsUnwrapped.push_back(unwrap(IndirectDests[i])); |
| ... | ... | @@ -1660,12 +1645,11 @@ LLVMRustBuildCallBr(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, |
| 1660 | 1645 | OpBundles.push_back(*OpBundlesIndirect[i]); |
| 1661 | 1646 | } |
| 1662 | 1647 | |
| 1663 | | return wrap(unwrap(B)->CreateCallBr( |
| 1664 | | FTy, Callee, unwrap(DefaultDest), |
| 1665 | | ArrayRef<BasicBlock*>(IndirectDestsUnwrapped), |
| 1666 | | ArrayRef<Value*>(unwrap(Args), NumArgs), |
| 1667 | | ArrayRef<OperandBundleDef>(OpBundles), |
| 1668 | | Name)); |
| 1648 | return wrap( |
| 1649 | unwrap(B)->CreateCallBr(FTy, Callee, unwrap(DefaultDest), |
| 1650 | ArrayRef<BasicBlock *>(IndirectDestsUnwrapped), |
| 1651 | ArrayRef<Value *>(unwrap(Args), NumArgs), |
| 1652 | ArrayRef<OperandBundleDef>(OpBundles), Name)); |
| 1669 | 1653 | } |
| 1670 | 1654 | |
| 1671 | 1655 | extern "C" void LLVMRustPositionBuilderAtStart(LLVMBuilderRef B, |
| ... | ... | @@ -1765,28 +1749,30 @@ extern "C" void LLVMRustSetLinkage(LLVMValueRef V, |
| 1765 | 1749 | } |
| 1766 | 1750 | |
| 1767 | 1751 | extern "C" bool LLVMRustConstIntGetZExtValue(LLVMValueRef CV, uint64_t *value) { |
| 1768 | | auto C = unwrap<llvm::ConstantInt>(CV); |
| 1769 | | if (C->getBitWidth() > 64) |
| 1770 | | return false; |
| 1771 | | *value = C->getZExtValue(); |
| 1772 | | return true; |
| 1752 | auto C = unwrap<llvm::ConstantInt>(CV); |
| 1753 | if (C->getBitWidth() > 64) |
| 1754 | return false; |
| 1755 | *value = C->getZExtValue(); |
| 1756 | return true; |
| 1773 | 1757 | } |
| 1774 | 1758 | |
| 1775 | | // Returns true if both high and low were successfully set. Fails in case constant wasn’t any of |
| 1776 | | // the common sizes (1, 8, 16, 32, 64, 128 bits) |
| 1777 | | extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *high, uint64_t *low) |
| 1778 | | { |
| 1779 | | auto C = unwrap<llvm::ConstantInt>(CV); |
| 1780 | | if (C->getBitWidth() > 128) { return false; } |
| 1781 | | APInt AP; |
| 1782 | | if (sext) { |
| 1783 | | AP = C->getValue().sext(128); |
| 1784 | | } else { |
| 1785 | | AP = C->getValue().zext(128); |
| 1786 | | } |
| 1787 | | *low = AP.getLoBits(64).getZExtValue(); |
| 1788 | | *high = AP.getHiBits(64).getZExtValue(); |
| 1789 | | return true; |
| 1759 | // Returns true if both high and low were successfully set. Fails in case |
| 1760 | // constant wasn’t any of the common sizes (1, 8, 16, 32, 64, 128 bits) |
| 1761 | extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, |
| 1762 | uint64_t *high, uint64_t *low) { |
| 1763 | auto C = unwrap<llvm::ConstantInt>(CV); |
| 1764 | if (C->getBitWidth() > 128) { |
| 1765 | return false; |
| 1766 | } |
| 1767 | APInt AP; |
| 1768 | if (sext) { |
| 1769 | AP = C->getValue().sext(128); |
| 1770 | } else { |
| 1771 | AP = C->getValue().zext(128); |
| 1772 | } |
| 1773 | *low = AP.getLoBits(64).getZExtValue(); |
| 1774 | *high = AP.getHiBits(64).getZExtValue(); |
| 1775 | return true; |
| 1790 | 1776 | } |
| 1791 | 1777 | |
| 1792 | 1778 | enum class LLVMRustVisibility { |
| ... | ... | @@ -1836,8 +1822,7 @@ struct LLVMRustModuleBuffer { |
| 1836 | 1822 | std::string data; |
| 1837 | 1823 | }; |
| 1838 | 1824 | |
| 1839 | | extern "C" LLVMRustModuleBuffer* |
| 1840 | | LLVMRustModuleBufferCreate(LLVMModuleRef M) { |
| 1825 | extern "C" LLVMRustModuleBuffer *LLVMRustModuleBufferCreate(LLVMModuleRef M) { |
| 1841 | 1826 | auto Ret = std::make_unique<LLVMRustModuleBuffer>(); |
| 1842 | 1827 | { |
| 1843 | 1828 | auto OS = raw_string_ostream(Ret->data); |
| ... | ... | @@ -1846,30 +1831,26 @@ LLVMRustModuleBufferCreate(LLVMModuleRef M) { |
| 1846 | 1831 | return Ret.release(); |
| 1847 | 1832 | } |
| 1848 | 1833 | |
| 1849 | | extern "C" void |
| 1850 | | LLVMRustModuleBufferFree(LLVMRustModuleBuffer *Buffer) { |
| 1834 | extern "C" void LLVMRustModuleBufferFree(LLVMRustModuleBuffer *Buffer) { |
| 1851 | 1835 | delete Buffer; |
| 1852 | 1836 | } |
| 1853 | 1837 | |
| 1854 | | extern "C" const void* |
| 1838 | extern "C" const void * |
| 1855 | 1839 | LLVMRustModuleBufferPtr(const LLVMRustModuleBuffer *Buffer) { |
| 1856 | 1840 | return Buffer->data.data(); |
| 1857 | 1841 | } |
| 1858 | 1842 | |
| 1859 | | extern "C" size_t |
| 1860 | | LLVMRustModuleBufferLen(const LLVMRustModuleBuffer *Buffer) { |
| 1843 | extern "C" size_t LLVMRustModuleBufferLen(const LLVMRustModuleBuffer *Buffer) { |
| 1861 | 1844 | return Buffer->data.length(); |
| 1862 | 1845 | } |
| 1863 | 1846 | |
| 1864 | | extern "C" uint64_t |
| 1865 | | LLVMRustModuleCost(LLVMModuleRef M) { |
| 1847 | extern "C" uint64_t LLVMRustModuleCost(LLVMModuleRef M) { |
| 1866 | 1848 | auto f = unwrap(M)->functions(); |
| 1867 | 1849 | return std::distance(std::begin(f), std::end(f)); |
| 1868 | 1850 | } |
| 1869 | 1851 | |
| 1870 | | extern "C" void |
| 1871 | | LLVMRustModuleInstructionStats(LLVMModuleRef M, RustStringRef Str) |
| 1872 | | { |
| 1852 | extern "C" void LLVMRustModuleInstructionStats(LLVMModuleRef M, |
| 1853 | RustStringRef Str) { |
| 1873 | 1854 | auto OS = RawRustStringOstream(Str); |
| 1874 | 1855 | auto JOS = llvm::json::OStream(OS); |
| 1875 | 1856 | auto Module = unwrap(M); |
| ... | ... | @@ -1881,41 +1862,45 @@ LLVMRustModuleInstructionStats(LLVMModuleRef M, RustStringRef Str) |
| 1881 | 1862 | } |
| 1882 | 1863 | |
| 1883 | 1864 | // Vector reductions: |
| 1884 | | extern "C" LLVMValueRef |
| 1885 | | LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) { |
| 1886 | | return wrap(unwrap(B)->CreateFAddReduce(unwrap(Acc),unwrap(Src))); |
| 1887 | | } |
| 1888 | | extern "C" LLVMValueRef |
| 1889 | | LLVMRustBuildVectorReduceFMul(LLVMBuilderRef B, LLVMValueRef Acc, LLVMValueRef Src) { |
| 1890 | | return wrap(unwrap(B)->CreateFMulReduce(unwrap(Acc),unwrap(Src))); |
| 1891 | | } |
| 1892 | | extern "C" LLVMValueRef |
| 1893 | | LLVMRustBuildVectorReduceAdd(LLVMBuilderRef B, LLVMValueRef Src) { |
| 1894 | | return wrap(unwrap(B)->CreateAddReduce(unwrap(Src))); |
| 1895 | | } |
| 1896 | | extern "C" LLVMValueRef |
| 1897 | | LLVMRustBuildVectorReduceMul(LLVMBuilderRef B, LLVMValueRef Src) { |
| 1898 | | return wrap(unwrap(B)->CreateMulReduce(unwrap(Src))); |
| 1899 | | } |
| 1900 | | extern "C" LLVMValueRef |
| 1901 | | LLVMRustBuildVectorReduceAnd(LLVMBuilderRef B, LLVMValueRef Src) { |
| 1902 | | return wrap(unwrap(B)->CreateAndReduce(unwrap(Src))); |
| 1903 | | } |
| 1904 | | extern "C" LLVMValueRef |
| 1905 | | LLVMRustBuildVectorReduceOr(LLVMBuilderRef B, LLVMValueRef Src) { |
| 1906 | | return wrap(unwrap(B)->CreateOrReduce(unwrap(Src))); |
| 1907 | | } |
| 1908 | | extern "C" LLVMValueRef |
| 1909 | | LLVMRustBuildVectorReduceXor(LLVMBuilderRef B, LLVMValueRef Src) { |
| 1910 | | return wrap(unwrap(B)->CreateXorReduce(unwrap(Src))); |
| 1911 | | } |
| 1912 | | extern "C" LLVMValueRef |
| 1913 | | LLVMRustBuildVectorReduceMin(LLVMBuilderRef B, LLVMValueRef Src, bool IsSigned) { |
| 1914 | | return wrap(unwrap(B)->CreateIntMinReduce(unwrap(Src), IsSigned)); |
| 1915 | | } |
| 1916 | | extern "C" LLVMValueRef |
| 1917 | | LLVMRustBuildVectorReduceMax(LLVMBuilderRef B, LLVMValueRef Src, bool IsSigned) { |
| 1918 | | return wrap(unwrap(B)->CreateIntMaxReduce(unwrap(Src), IsSigned)); |
| 1865 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceFAdd(LLVMBuilderRef B, |
| 1866 | LLVMValueRef Acc, |
| 1867 | LLVMValueRef Src) { |
| 1868 | return wrap(unwrap(B)->CreateFAddReduce(unwrap(Acc), unwrap(Src))); |
| 1869 | } |
| 1870 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceFMul(LLVMBuilderRef B, |
| 1871 | LLVMValueRef Acc, |
| 1872 | LLVMValueRef Src) { |
| 1873 | return wrap(unwrap(B)->CreateFMulReduce(unwrap(Acc), unwrap(Src))); |
| 1874 | } |
| 1875 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceAdd(LLVMBuilderRef B, |
| 1876 | LLVMValueRef Src) { |
| 1877 | return wrap(unwrap(B)->CreateAddReduce(unwrap(Src))); |
| 1878 | } |
| 1879 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceMul(LLVMBuilderRef B, |
| 1880 | LLVMValueRef Src) { |
| 1881 | return wrap(unwrap(B)->CreateMulReduce(unwrap(Src))); |
| 1882 | } |
| 1883 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceAnd(LLVMBuilderRef B, |
| 1884 | LLVMValueRef Src) { |
| 1885 | return wrap(unwrap(B)->CreateAndReduce(unwrap(Src))); |
| 1886 | } |
| 1887 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceOr(LLVMBuilderRef B, |
| 1888 | LLVMValueRef Src) { |
| 1889 | return wrap(unwrap(B)->CreateOrReduce(unwrap(Src))); |
| 1890 | } |
| 1891 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceXor(LLVMBuilderRef B, |
| 1892 | LLVMValueRef Src) { |
| 1893 | return wrap(unwrap(B)->CreateXorReduce(unwrap(Src))); |
| 1894 | } |
| 1895 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceMin(LLVMBuilderRef B, |
| 1896 | LLVMValueRef Src, |
| 1897 | bool IsSigned) { |
| 1898 | return wrap(unwrap(B)->CreateIntMinReduce(unwrap(Src), IsSigned)); |
| 1899 | } |
| 1900 | extern "C" LLVMValueRef LLVMRustBuildVectorReduceMax(LLVMBuilderRef B, |
| 1901 | LLVMValueRef Src, |
| 1902 | bool IsSigned) { |
| 1903 | return wrap(unwrap(B)->CreateIntMaxReduce(unwrap(Src), IsSigned)); |
| 1919 | 1904 | } |
| 1920 | 1905 | extern "C" LLVMValueRef |
| 1921 | 1906 | LLVMRustBuildVectorReduceFMin(LLVMBuilderRef B, LLVMValueRef Src, bool NoNaN) { |
| ... | ... | @@ -1930,32 +1915,28 @@ LLVMRustBuildVectorReduceFMax(LLVMBuilderRef B, LLVMValueRef Src, bool NoNaN) { |
| 1930 | 1915 | return wrap(I); |
| 1931 | 1916 | } |
| 1932 | 1917 | |
| 1933 | | extern "C" LLVMValueRef |
| 1934 | | LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) { |
| 1935 | | return wrap(unwrap(B)->CreateMinNum(unwrap(LHS),unwrap(RHS))); |
| 1918 | extern "C" LLVMValueRef LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, |
| 1919 | LLVMValueRef RHS) { |
| 1920 | return wrap(unwrap(B)->CreateMinNum(unwrap(LHS), unwrap(RHS))); |
| 1936 | 1921 | } |
| 1937 | | extern "C" LLVMValueRef |
| 1938 | | LLVMRustBuildMaxNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) { |
| 1939 | | return wrap(unwrap(B)->CreateMaxNum(unwrap(LHS),unwrap(RHS))); |
| 1922 | extern "C" LLVMValueRef LLVMRustBuildMaxNum(LLVMBuilderRef B, LLVMValueRef LHS, |
| 1923 | LLVMValueRef RHS) { |
| 1924 | return wrap(unwrap(B)->CreateMaxNum(unwrap(LHS), unwrap(RHS))); |
| 1940 | 1925 | } |
| 1941 | 1926 | |
| 1942 | 1927 | // This struct contains all necessary info about a symbol exported from a DLL. |
| 1943 | 1928 | struct LLVMRustCOFFShortExport { |
| 1944 | | const char* name; |
| 1929 | const char *name; |
| 1945 | 1930 | bool ordinal_present; |
| 1946 | 1931 | // The value of `ordinal` is only meaningful if `ordinal_present` is true. |
| 1947 | 1932 | uint16_t ordinal; |
| 1948 | 1933 | }; |
| 1949 | 1934 | |
| 1950 | 1935 | // Machine must be a COFF machine type, as defined in PE specs. |
| 1951 | | extern "C" LLVMRustResult LLVMRustWriteImportLibrary( |
| 1952 | | const char* ImportName, |
| 1953 | | const char* Path, |
| 1954 | | const LLVMRustCOFFShortExport* Exports, |
| 1955 | | size_t NumExports, |
| 1956 | | uint16_t Machine, |
| 1957 | | bool MinGW) |
| 1958 | | { |
| 1936 | extern "C" LLVMRustResult |
| 1937 | LLVMRustWriteImportLibrary(const char *ImportName, const char *Path, |
| 1938 | const LLVMRustCOFFShortExport *Exports, |
| 1939 | size_t NumExports, uint16_t Machine, bool MinGW) { |
| 1959 | 1940 | std::vector<llvm::object::COFFShortExport> ConvertedExports; |
| 1960 | 1941 | ConvertedExports.reserve(NumExports); |
| 1961 | 1942 | |
| ... | ... | @@ -1963,27 +1944,24 @@ extern "C" LLVMRustResult LLVMRustWriteImportLibrary( |
| 1963 | 1944 | bool ordinal_present = Exports[i].ordinal_present; |
| 1964 | 1945 | uint16_t ordinal = ordinal_present ? Exports[i].ordinal : 0; |
| 1965 | 1946 | ConvertedExports.push_back(llvm::object::COFFShortExport{ |
| 1966 | | Exports[i].name, // Name |
| 1967 | | std::string{}, // ExtName |
| 1968 | | std::string{}, // SymbolName |
| 1969 | | std::string{}, // AliasTarget |
| 1947 | Exports[i].name, // Name |
| 1948 | std::string{}, // ExtName |
| 1949 | std::string{}, // SymbolName |
| 1950 | std::string{}, // AliasTarget |
| 1970 | 1951 | #if LLVM_VERSION_GE(19, 0) |
| 1971 | | std::string{}, // ExportAs |
| 1952 | std::string{}, // ExportAs |
| 1972 | 1953 | #endif |
| 1973 | | ordinal, // Ordinal |
| 1974 | | ordinal_present, // Noname |
| 1975 | | false, // Data |
| 1976 | | false, // Private |
| 1977 | | false // Constant |
| 1954 | ordinal, // Ordinal |
| 1955 | ordinal_present, // Noname |
| 1956 | false, // Data |
| 1957 | false, // Private |
| 1958 | false // Constant |
| 1978 | 1959 | }); |
| 1979 | 1960 | } |
| 1980 | 1961 | |
| 1981 | 1962 | auto Error = llvm::object::writeImportLibrary( |
| 1982 | | ImportName, |
| 1983 | | Path, |
| 1984 | | ConvertedExports, |
| 1985 | | static_cast<llvm::COFF::MachineTypes>(Machine), |
| 1986 | | MinGW); |
| 1963 | ImportName, Path, ConvertedExports, |
| 1964 | static_cast<llvm::COFF::MachineTypes>(Machine), MinGW); |
| 1987 | 1965 | if (Error) { |
| 1988 | 1966 | std::string errorString; |
| 1989 | 1967 | auto stream = llvm::raw_string_ostream(errorString); |
| ... | ... | @@ -2019,27 +1997,23 @@ using LLVMDiagnosticHandlerTy = DiagnosticHandler::DiagnosticHandlerTy; |
| 2019 | 1997 | // the RemarkPasses array specifies individual passes for which remarks will be |
| 2020 | 1998 | // enabled. |
| 2021 | 1999 | // |
| 2022 | | // If RemarkFilePath is not NULL, optimization remarks will be streamed directly into this file, |
| 2023 | | // bypassing the diagnostics handler. |
| 2000 | // If RemarkFilePath is not NULL, optimization remarks will be streamed directly |
| 2001 | // into this file, bypassing the diagnostics handler. |
| 2024 | 2002 | extern "C" void LLVMRustContextConfigureDiagnosticHandler( |
| 2025 | 2003 | LLVMContextRef C, LLVMDiagnosticHandlerTy DiagnosticHandlerCallback, |
| 2026 | 2004 | void *DiagnosticHandlerContext, bool RemarkAllPasses, |
| 2027 | | const char * const * RemarkPasses, size_t RemarkPassesLen, |
| 2028 | | const char * RemarkFilePath, |
| 2029 | | bool PGOAvailable |
| 2030 | | ) { |
| 2005 | const char *const *RemarkPasses, size_t RemarkPassesLen, |
| 2006 | const char *RemarkFilePath, bool PGOAvailable) { |
| 2031 | 2007 | |
| 2032 | 2008 | class RustDiagnosticHandler final : public DiagnosticHandler { |
| 2033 | 2009 | public: |
| 2034 | 2010 | RustDiagnosticHandler( |
| 2035 | | LLVMDiagnosticHandlerTy DiagnosticHandlerCallback, |
| 2036 | | void *DiagnosticHandlerContext, |
| 2037 | | bool RemarkAllPasses, |
| 2038 | | std::vector<std::string> RemarkPasses, |
| 2039 | | std::unique_ptr<ToolOutputFile> RemarksFile, |
| 2040 | | std::unique_ptr<llvm::remarks::RemarkStreamer> RemarkStreamer, |
| 2041 | | std::unique_ptr<LLVMRemarkStreamer> LlvmRemarkStreamer |
| 2042 | | ) |
| 2011 | LLVMDiagnosticHandlerTy DiagnosticHandlerCallback, |
| 2012 | void *DiagnosticHandlerContext, bool RemarkAllPasses, |
| 2013 | std::vector<std::string> RemarkPasses, |
| 2014 | std::unique_ptr<ToolOutputFile> RemarksFile, |
| 2015 | std::unique_ptr<llvm::remarks::RemarkStreamer> RemarkStreamer, |
| 2016 | std::unique_ptr<LLVMRemarkStreamer> LlvmRemarkStreamer) |
| 2043 | 2017 | : DiagnosticHandlerCallback(DiagnosticHandlerCallback), |
| 2044 | 2018 | DiagnosticHandlerContext(DiagnosticHandlerContext), |
| 2045 | 2019 | RemarkAllPasses(RemarkAllPasses), |
| ... | ... | @@ -2049,11 +2023,13 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler( |
| 2049 | 2023 | LlvmRemarkStreamer(std::move(LlvmRemarkStreamer)) {} |
| 2050 | 2024 | |
| 2051 | 2025 | virtual bool handleDiagnostics(const DiagnosticInfo &DI) override { |
| 2052 | | // If this diagnostic is one of the optimization remark kinds, we can check if it's enabled |
| 2053 | | // before emitting it. This can avoid many short-lived allocations when unpacking the |
| 2054 | | // diagnostic and converting its various C++ strings into rust strings. |
| 2055 | | // FIXME: some diagnostic infos still allocate before we get here, and avoiding that would be |
| 2056 | | // good in the future. That will require changing a few call sites in LLVM. |
| 2026 | // If this diagnostic is one of the optimization remark kinds, we can |
| 2027 | // check if it's enabled before emitting it. This can avoid many |
| 2028 | // short-lived allocations when unpacking the diagnostic and converting |
| 2029 | // its various C++ strings into rust strings. |
| 2030 | // FIXME: some diagnostic infos still allocate before we get here, and |
| 2031 | // avoiding that would be good in the future. That will require changing a |
| 2032 | // few call sites in LLVM. |
| 2057 | 2033 | if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) { |
| 2058 | 2034 | if (OptDiagBase->isEnabled()) { |
| 2059 | 2035 | if (this->LlvmRemarkStreamer) { |
| ... | ... | @@ -2109,16 +2085,15 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler( |
| 2109 | 2085 | bool RemarkAllPasses = false; |
| 2110 | 2086 | std::vector<std::string> RemarkPasses; |
| 2111 | 2087 | |
| 2112 | | // Since LlvmRemarkStreamer contains a pointer to RemarkStreamer, the ordering of the three |
| 2113 | | // members below is important. |
| 2088 | // Since LlvmRemarkStreamer contains a pointer to RemarkStreamer, the |
| 2089 | // ordering of the three members below is important. |
| 2114 | 2090 | std::unique_ptr<ToolOutputFile> RemarksFile; |
| 2115 | 2091 | std::unique_ptr<llvm::remarks::RemarkStreamer> RemarkStreamer; |
| 2116 | 2092 | std::unique_ptr<LLVMRemarkStreamer> LlvmRemarkStreamer; |
| 2117 | 2093 | }; |
| 2118 | 2094 | |
| 2119 | 2095 | std::vector<std::string> Passes; |
| 2120 | | for (size_t I = 0; I != RemarkPassesLen; ++I) |
| 2121 | | { |
| 2096 | for (size_t I = 0; I != RemarkPassesLen; ++I) { |
| 2122 | 2097 | Passes.push_back(RemarkPasses[I]); |
| 2123 | 2098 | } |
| 2124 | 2099 | |
| ... | ... | @@ -2135,13 +2110,10 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler( |
| 2135 | 2110 | |
| 2136 | 2111 | std::error_code EC; |
| 2137 | 2112 | RemarkFile = std::make_unique<ToolOutputFile>( |
| 2138 | | RemarkFilePath, |
| 2139 | | EC, |
| 2140 | | llvm::sys::fs::OF_TextWithCRLF |
| 2141 | | ); |
| 2113 | RemarkFilePath, EC, llvm::sys::fs::OF_TextWithCRLF); |
| 2142 | 2114 | if (EC) { |
| 2143 | 2115 | std::string Error = std::string("Cannot create remark file: ") + |
| 2144 | | toString(errorCodeToError(EC)); |
| 2116 | toString(errorCodeToError(EC)); |
| 2145 | 2117 | report_fatal_error(Twine(Error)); |
| 2146 | 2118 | } |
| 2147 | 2119 | |
| ... | ... | @@ -2149,28 +2121,22 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler( |
| 2149 | 2121 | RemarkFile->keep(); |
| 2150 | 2122 | |
| 2151 | 2123 | auto RemarkSerializer = remarks::createRemarkSerializer( |
| 2152 | | llvm::remarks::Format::YAML, |
| 2153 | | remarks::SerializerMode::Separate, |
| 2154 | | RemarkFile->os() |
| 2155 | | ); |
| 2156 | | if (Error E = RemarkSerializer.takeError()) |
| 2157 | | { |
| 2158 | | std::string Error = std::string("Cannot create remark serializer: ") + toString(std::move(E)); |
| 2124 | llvm::remarks::Format::YAML, remarks::SerializerMode::Separate, |
| 2125 | RemarkFile->os()); |
| 2126 | if (Error E = RemarkSerializer.takeError()) { |
| 2127 | std::string Error = std::string("Cannot create remark serializer: ") + |
| 2128 | toString(std::move(E)); |
| 2159 | 2129 | report_fatal_error(Twine(Error)); |
| 2160 | 2130 | } |
| 2161 | | RemarkStreamer = std::make_unique<llvm::remarks::RemarkStreamer>(std::move(*RemarkSerializer)); |
| 2131 | RemarkStreamer = std::make_unique<llvm::remarks::RemarkStreamer>( |
| 2132 | std::move(*RemarkSerializer)); |
| 2162 | 2133 | LlvmRemarkStreamer = std::make_unique<LLVMRemarkStreamer>(*RemarkStreamer); |
| 2163 | 2134 | } |
| 2164 | 2135 | |
| 2165 | 2136 | unwrap(C)->setDiagnosticHandler(std::make_unique<RustDiagnosticHandler>( |
| 2166 | | DiagnosticHandlerCallback, |
| 2167 | | DiagnosticHandlerContext, |
| 2168 | | RemarkAllPasses, |
| 2169 | | Passes, |
| 2170 | | std::move(RemarkFile), |
| 2171 | | std::move(RemarkStreamer), |
| 2172 | | std::move(LlvmRemarkStreamer) |
| 2173 | | )); |
| 2137 | DiagnosticHandlerCallback, DiagnosticHandlerContext, RemarkAllPasses, |
| 2138 | Passes, std::move(RemarkFile), std::move(RemarkStreamer), |
| 2139 | std::move(LlvmRemarkStreamer))); |
| 2174 | 2140 | } |
| 2175 | 2141 | |
| 2176 | 2142 | extern "C" void LLVMRustGetMangledName(LLVMValueRef V, RustStringRef Str) { |
| ... | ... | @@ -2180,14 +2146,14 @@ extern "C" void LLVMRustGetMangledName(LLVMValueRef V, RustStringRef Str) { |
| 2180 | 2146 | } |
| 2181 | 2147 | |
| 2182 | 2148 | extern "C" int32_t LLVMRustGetElementTypeArgIndex(LLVMValueRef CallSite) { |
| 2183 | | auto *CB = unwrap<CallBase>(CallSite); |
| 2184 | | switch (CB->getIntrinsicID()) { |
| 2185 | | case Intrinsic::arm_ldrex: |
| 2186 | | return 0; |
| 2187 | | case Intrinsic::arm_strex: |
| 2188 | | return 1; |
| 2189 | | } |
| 2190 | | return -1; |
| 2149 | auto *CB = unwrap<CallBase>(CallSite); |
| 2150 | switch (CB->getIntrinsicID()) { |
| 2151 | case Intrinsic::arm_ldrex: |
| 2152 | return 0; |
| 2153 | case Intrinsic::arm_strex: |
| 2154 | return 1; |
| 2155 | } |
| 2156 | return -1; |
| 2191 | 2157 | } |
| 2192 | 2158 | |
| 2193 | 2159 | extern "C" bool LLVMRustIsBitcode(char *ptr, size_t len) { |
| ... | ... | @@ -2214,10 +2180,10 @@ extern "C" bool LLVMRustLLVMHasZstdCompressionForDebugSymbols() { |
| 2214 | 2180 | } |
| 2215 | 2181 | |
| 2216 | 2182 | // Operations on composite constants. |
| 2217 | | // These are clones of LLVM api functions that will become available in future releases. |
| 2218 | | // They can be removed once Rust's minimum supported LLVM version supports them. |
| 2219 | | // See https://github.com/rust-lang/rust/issues/121868 |
| 2220 | | // See https://llvm.org/doxygen/group__LLVMCCoreValueConstantComposite.html |
| 2183 | // These are clones of LLVM api functions that will become available in future |
| 2184 | // releases. They can be removed once Rust's minimum supported LLVM version |
| 2185 | // supports them. See https://github.com/rust-lang/rust/issues/121868 See |
| 2186 | // https://llvm.org/doxygen/group__LLVMCCoreValueConstantComposite.html |
| 2221 | 2187 | |
| 2222 | 2188 | // FIXME: Remove when Rust's minimum supported LLVM version reaches 19. |
| 2223 | 2189 | // https://github.com/llvm/llvm-project/commit/e1405e4f71c899420ebf8262d5e9745598419df8 |
| ... | ... | @@ -2226,6 +2192,7 @@ extern "C" LLVMValueRef LLVMConstStringInContext2(LLVMContextRef C, |
| 2226 | 2192 | const char *Str, |
| 2227 | 2193 | size_t Length, |
| 2228 | 2194 | bool DontNullTerminate) { |
| 2229 | | return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length), !DontNullTerminate)); |
| 2195 | return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length), |
| 2196 | !DontNullTerminate)); |
| 2230 | 2197 | } |
| 2231 | 2198 | #endif |