|
24 | 24 | #include "llvm/IR/GlobalVariable.h"
|
25 | 25 | #include "llvm/IR/IRBuilder.h"
|
26 | 26 | #include "llvm/IR/InlineAsm.h"
|
| 27 | +#include "llvm/IR/Instructions.h" |
27 | 28 | #include "llvm/IR/IntrinsicInst.h"
|
28 | 29 | #include "llvm/IR/LLVMContext.h"
|
29 | 30 | #include "llvm/IR/LegacyPassManager.h"
|
@@ -146,24 +147,10 @@ unsigned LLVMGetMDKindID(const char *Name, unsigned SLen) {
|
146 | 147 | return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
|
147 | 148 | }
|
148 | 149 |
|
149 |
| -unsigned LLVMGetSyncScopeIDInContext(LLVMContextRef C, const char *Name, |
150 |
| - unsigned SLen) { |
| 150 | +unsigned LLVMGetSyncScopeID(LLVMContextRef C, const char *Name, size_t SLen) { |
151 | 151 | return unwrap(C)->getOrInsertSyncScopeID(StringRef(Name, SLen));
|
152 | 152 | }
|
153 | 153 |
|
154 |
| -unsigned LLVMGetSyncScopeID(const char *Name, unsigned SLen) { |
155 |
| - return LLVMGetSyncScopeIDInContext(LLVMGetGlobalContext(), Name, SLen); |
156 |
| -} |
157 |
| - |
158 |
| -const char *LLVMGetSyncScopeName(LLVMContextRef C, unsigned ID, |
159 |
| - unsigned *Length) { |
160 |
| - SmallVector<StringRef> SSNs; |
161 |
| - unwrap(C)->getSyncScopeNames(SSNs); |
162 |
| - StringRef Name = SSNs[ID].empty() ? "system" : SSNs[ID]; |
163 |
| - *Length = Name.size(); |
164 |
| - return Name.data(); |
165 |
| -} |
166 |
| - |
167 | 154 | unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen) {
|
168 | 155 | return Attribute::getAttrKindFromName(StringRef(Name, SLen));
|
169 | 156 | }
|
@@ -4338,11 +4325,6 @@ LLVMValueRef LLVMBuildAtomicRMWSyncScope(LLVMBuilderRef B,
|
4338 | 4325 | LLVMAtomicOrdering ordering,
|
4339 | 4326 | unsigned SSID) {
|
4340 | 4327 | AtomicRMWInst::BinOp intop = mapFromLLVMRMWBinOp(op);
|
4341 |
| - |
4342 |
| - SmallVector<StringRef> SSNs; |
4343 |
| - unwrap(B)->getContext().getSyncScopeNames(SSNs); |
4344 |
| - assert(SSID < SSNs.size() && "Invalid SyncScopeID"); |
4345 |
| - |
4346 | 4328 | return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val),
|
4347 | 4329 | MaybeAlign(),
|
4348 | 4330 | mapFromLLVMOrdering(ordering), SSID));
|
@@ -4386,49 +4368,22 @@ int LLVMGetMaskValue(LLVMValueRef SVInst, unsigned Elt) {
|
4386 | 4368 |
|
4387 | 4369 | int LLVMGetUndefMaskElem(void) { return PoisonMaskElem; }
|
4388 | 4370 |
|
4389 |
| -static unsigned getAtomicSyncScopeID(Value *P) { |
4390 |
| - if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P)) |
4391 |
| - return I->getSyncScopeID(); |
4392 |
| - else if (FenceInst *FI = dyn_cast<FenceInst>(P)) |
4393 |
| - return FI->getSyncScopeID(); |
4394 |
| - else if (StoreInst *SI = dyn_cast<StoreInst>(P)) |
4395 |
| - return SI->getSyncScopeID(); |
4396 |
| - else if (LoadInst *LI = dyn_cast<LoadInst>(P)) |
4397 |
| - return LI->getSyncScopeID(); |
4398 |
| - return cast<AtomicCmpXchgInst>(P)->getSyncScopeID(); |
4399 |
| -} |
4400 |
| - |
4401 | 4371 | LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst) {
|
4402 |
| - Value *P = unwrap(AtomicInst); |
4403 |
| - return getAtomicSyncScopeID(P) == SyncScope::SingleThread; |
| 4372 | + return getAtomicSyncScopeID(unwrap<Instruction>(AtomicInst)).value() == |
| 4373 | + SyncScope::SingleThread; |
4404 | 4374 | }
|
4405 | 4375 |
|
4406 | 4376 | unsigned LLVMGetAtomicSyncScopeID(LLVMValueRef AtomicInst) {
|
4407 |
| - Value *P = unwrap(AtomicInst); |
4408 |
| - return getAtomicSyncScopeID(P); |
4409 |
| -} |
4410 |
| - |
4411 |
| -static void setAtomicSyncScopeID(Value *P, unsigned SSID) { |
4412 |
| - if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P)) |
4413 |
| - return I->setSyncScopeID(SSID); |
4414 |
| - else if (FenceInst *FI = dyn_cast<FenceInst>(P)) |
4415 |
| - return FI->setSyncScopeID(SSID); |
4416 |
| - else if (StoreInst *SI = dyn_cast<StoreInst>(P)) |
4417 |
| - return SI->setSyncScopeID(SSID); |
4418 |
| - else if (LoadInst *LI = dyn_cast<LoadInst>(P)) |
4419 |
| - return LI->setSyncScopeID(SSID); |
4420 |
| - return cast<AtomicCmpXchgInst>(P)->setSyncScopeID(SSID); |
| 4377 | + return getAtomicSyncScopeID(unwrap<Instruction>(AtomicInst)).value(); |
4421 | 4378 | }
|
4422 | 4379 |
|
4423 | 4380 | void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool NewValue) {
|
4424 |
| - Value *P = unwrap(AtomicInst); |
4425 | 4381 | SyncScope::ID SSID = NewValue ? SyncScope::SingleThread : SyncScope::System;
|
4426 |
| - setAtomicSyncScopeID(P, SSID); |
| 4382 | + setAtomicSyncScopeID(unwrap<Instruction>(AtomicInst), SSID); |
4427 | 4383 | }
|
4428 | 4384 |
|
4429 | 4385 | void LLVMSetAtomicSyncScopeID(LLVMValueRef AtomicInst, unsigned SSID) {
|
4430 |
| - Value *P = unwrap(AtomicInst); |
4431 |
| - setAtomicSyncScopeID(P, SSID); |
| 4386 | + setAtomicSyncScopeID(unwrap<Instruction>(AtomicInst), SSID); |
4432 | 4387 | }
|
4433 | 4388 |
|
4434 | 4389 | LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst) {
|
|
0 commit comments