Skip to content

Commit c973ae3

Browse files
committed
llvm20 fixes
1 parent 8f5a2fb commit c973ae3

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/llvm-expand-atomic-modify.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <llvm/IR/InstIterator.h>
1818
#include <llvm/IR/Instructions.h>
1919
#include <llvm/IR/IntrinsicInst.h>
20+
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
2021
#include <llvm/IR/Module.h>
2122
#include <llvm/IR/Operator.h>
2223
#include <llvm/IR/PassManager.h>
@@ -141,12 +142,28 @@ std::pair<Value *, Value *> insertRMWCmpXchgLoop(
141142
}
142143

143144
// from AtomicExpandImpl
144-
struct ReplacementIRBuilder : IRBuilder<InstSimplifyFolder> {
145+
// IRBuilder to be used for replacement atomic instructions.
146+
struct ReplacementIRBuilder
147+
: IRBuilder<InstSimplifyFolder, IRBuilderCallbackInserter> {
148+
MDNode *MMRAMD = nullptr;
149+
145150
// Preserves the DebugLoc from I, and preserves still valid metadata.
151+
// Enable StrictFP builder mode when appropriate.
146152
explicit ReplacementIRBuilder(Instruction *I, const DataLayout &DL)
147-
: IRBuilder(I->getContext(), DL) {
153+
: IRBuilder(I->getContext(), InstSimplifyFolder(DL),
154+
IRBuilderCallbackInserter(
155+
[this](Instruction *I) { addMMRAMD(I); })) {
148156
SetInsertPoint(I);
149157
this->CollectMetadataToCopy(I, {LLVMContext::MD_pcsections});
158+
if (BB->getParent()->getAttributes().hasFnAttr(Attribute::StrictFP))
159+
this->setIsFPConstrained(true);
160+
161+
MMRAMD = I->getMetadata(LLVMContext::MD_mmra);
162+
}
163+
164+
void addMMRAMD(Instruction *I) {
165+
if (canInstructionHaveMMRAs(*I))
166+
I->setMetadata(LLVMContext::MD_mmra, MMRAMD);
150167
}
151168
};
152169

@@ -321,7 +338,6 @@ void expandAtomicModifyToCmpXchg(CallInst &Modify,
321338
Type *Ty = Modify.getFunctionType()->getReturnType()->getStructElementType(0);
322339

323340
ReplacementIRBuilder Builder(&Modify, Modify.getModule()->getDataLayout());
324-
Builder.setIsFPConstrained(Modify.hasFnAttr(Attribute::StrictFP));
325341

326342
CallInst *ModifyOp;
327343
{
@@ -366,7 +382,7 @@ void expandAtomicModifyToCmpXchg(CallInst &Modify,
366382
ModifyOp = cast<CallInst>(ValOp->getUser());
367383
LoadedOp = ValOp;
368384
assert(LoadedOp->get() == RMW);
369-
RMW->moveBefore(ModifyOp); // NewValInst is a user of RMW, and RMW has no other dependants (per patternMatchAtomicRMWOp)
385+
RMW->moveBeforePreserving(ModifyOp->getIterator()); // NewValInst is a user of RMW, and RMW has no other dependants (per patternMatchAtomicRMWOp)
370386
BinOp = false;
371387
if (++attempts > 3)
372388
break;
@@ -383,7 +399,7 @@ void expandAtomicModifyToCmpXchg(CallInst &Modify,
383399
assert(isa<UndefValue>(RMW->getOperand(1))); // RMW was previously being used as the placeholder for Val
384400
Value *Val;
385401
if (ValOp != nullptr) {
386-
RMW->moveBefore(cast<Instruction>(ValOp->getUser())); // ValOp is a user of RMW, and RMW has no other dependants (per patternMatchAtomicRMWOp)
402+
RMW->moveBeforePreserving(cast<Instruction>(ValOp->getUser())->getIterator()); // ValOp is a user of RMW, and RMW has no other dependants (per patternMatchAtomicRMWOp)
387403
Val = ValOp->get();
388404
} else if (RMWOp == AtomicRMWInst::Xchg) {
389405
Val = NewVal;
@@ -411,7 +427,7 @@ void expandAtomicModifyToCmpXchg(CallInst &Modify,
411427
Builder, Ty, Ptr, *Alignment, Ordering, SSID, Modify,
412428
[&](IRBuilderBase &Builder, Value *Loaded) JL_NOTSAFEPOINT {
413429
LoadedOp->set(Loaded);
414-
ModifyOp->moveBefore(*Builder.GetInsertBlock(), Builder.GetInsertPoint());
430+
ModifyOp->moveBeforePreserving(*Builder.GetInsertBlock(), Builder.GetInsertPoint());
415431
return ModifyOp;
416432
},
417433
CreateWeakCmpXchg);

src/subtype.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ typedef struct {
6565
// Most of the complexity is due to the "diagonal rule", requiring us to
6666
// identify which type vars range over only concrete types.
6767
typedef struct jl_varbinding_t {
68-
jl_tvar_t *var;
69-
jl_value_t *lb;
70-
jl_value_t *ub;
68+
jl_tvar_t *var; // store NULL to "delete" this from env (temporarily)
69+
jl_value_t *JL_NONNULL lb;
70+
jl_value_t *JL_NONNULL ub;
7171
int8_t right; // whether this variable came from the right side of `A <: B`
7272
int8_t occurs_inv; // occurs in invariant position
7373
int8_t occurs_cov; // # of occurrences in covariant position
@@ -356,7 +356,7 @@ static void free_stenv(jl_stenv_t *e) JL_NOTSAFEPOINT
356356

357357
static void restore_env(jl_stenv_t *e, jl_savedenv_t *se, int root) JL_NOTSAFEPOINT
358358
{
359-
jl_value_t **roots = NULL;
359+
jl_value_t *JL_NONNULL *roots = NULL;
360360
int nroots = 0;
361361
if (root) {
362362
if (se->gcframe.nroots == JL_GC_ENCODE_PUSHARGS(1)) {

0 commit comments

Comments
 (0)