Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / IR / Comdat.cpp
blob2cd6db913621b6727bdf5399135949b6076feefb
1 //===- Comdat.cpp - Implement Metadata classes ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Comdat class (including the C bindings).
11 //===----------------------------------------------------------------------===//
13 #include "llvm-c/Comdat.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "llvm/ADT/StringMapEntry.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/IR/Comdat.h"
18 #include "llvm/IR/GlobalObject.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/IR/Value.h"
22 using namespace llvm;
24 Comdat::Comdat(Comdat &&C) : Name(C.Name), SK(C.SK) {}
26 Comdat::Comdat() = default;
28 StringRef Comdat::getName() const { return Name->first(); }
30 void Comdat::addUser(GlobalObject *GO) { Users.insert(GO); }
32 void Comdat::removeUser(GlobalObject *GO) { Users.erase(GO); }
34 LLVMComdatRef LLVMGetOrInsertComdat(LLVMModuleRef M, const char *Name) {
35 return wrap(unwrap(M)->getOrInsertComdat(Name));
38 LLVMComdatRef LLVMGetComdat(LLVMValueRef V) {
39 GlobalObject *G = unwrap<GlobalObject>(V);
40 return wrap(G->getComdat());
43 void LLVMSetComdat(LLVMValueRef V, LLVMComdatRef C) {
44 GlobalObject *G = unwrap<GlobalObject>(V);
45 G->setComdat(unwrap(C));
48 LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C) {
49 switch (unwrap(C)->getSelectionKind()) {
50 case Comdat::Any:
51 return LLVMAnyComdatSelectionKind;
52 case Comdat::ExactMatch:
53 return LLVMExactMatchComdatSelectionKind;
54 case Comdat::Largest:
55 return LLVMLargestComdatSelectionKind;
56 case Comdat::NoDeduplicate:
57 return LLVMNoDeduplicateComdatSelectionKind;
58 case Comdat::SameSize:
59 return LLVMSameSizeComdatSelectionKind;
61 llvm_unreachable("Invalid Comdat SelectionKind!");
64 void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind kind) {
65 Comdat *Cd = unwrap(C);
66 switch (kind) {
67 case LLVMAnyComdatSelectionKind:
68 Cd->setSelectionKind(Comdat::Any);
69 break;
70 case LLVMExactMatchComdatSelectionKind:
71 Cd->setSelectionKind(Comdat::ExactMatch);
72 break;
73 case LLVMLargestComdatSelectionKind:
74 Cd->setSelectionKind(Comdat::Largest);
75 break;
76 case LLVMNoDeduplicateComdatSelectionKind:
77 Cd->setSelectionKind(Comdat::NoDeduplicate);
78 break;
79 case LLVMSameSizeComdatSelectionKind:
80 Cd->setSelectionKind(Comdat::SameSize);
81 break;