LLVM 19.0.0git
Comdat.cpp
Go to the documentation of this file.
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).
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm-c/Comdat.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/IR/Comdat.h"
19#include "llvm/IR/Module.h"
20#include "llvm/IR/Value.h"
21
22using namespace llvm;
23
24Comdat::Comdat(Comdat &&C) : Name(C.Name), SK(C.SK) {}
25
26Comdat::Comdat() = default;
27
28StringRef Comdat::getName() const { return Name->first(); }
29
30void Comdat::addUser(GlobalObject *GO) { Users.insert(GO); }
31
32void Comdat::removeUser(GlobalObject *GO) { Users.erase(GO); }
33
35 return wrap(unwrap(M)->getOrInsertComdat(Name));
36}
37
39 GlobalObject *G = unwrap<GlobalObject>(V);
40 return wrap(G->getComdat());
41}
42
44 GlobalObject *G = unwrap<GlobalObject>(V);
45 G->setComdat(unwrap(C));
46}
47
49 switch (unwrap(C)->getSelectionKind()) {
50 case Comdat::Any:
54 case Comdat::Largest:
60 }
61 llvm_unreachable("Invalid Comdat SelectionKind!");
62}
63
65 Comdat *Cd = unwrap(C);
66 switch (kind) {
69 break;
72 break;
75 break;
78 break;
81 break;
82 }
83}
This file defines the StringMapEntry class - it is intended to be a low dependency implementation det...
std::string Name
#define G(x, y, z)
Definition: MD5.cpp:56
Module.h This file contains the declarations for the Module class.
This file defines the SmallPtrSet class.
StringRef getName() const
Definition: Comdat.cpp:28
@ Largest
The linker will choose the largest COMDAT.
Definition: Comdat.h:38
@ SameSize
The data referenced by the COMDAT must be the same size.
Definition: Comdat.h:40
@ Any
The linker may choose any COMDAT.
Definition: Comdat.h:36
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:39
@ ExactMatch
The data referenced by the COMDAT must be the same.
Definition: Comdat.h:37
void setSelectionKind(SelectionKind Val)
Definition: Comdat.h:47
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C)
Definition: Comdat.cpp:48
LLVMComdatRef LLVMGetOrInsertComdat(LLVMModuleRef M, const char *Name)
Return the Comdat in the module with the specified name.
Definition: Comdat.cpp:34
void LLVMSetComdat(LLVMValueRef V, LLVMComdatRef C)
Assign the Comdat to the given global object.
Definition: Comdat.cpp:43
void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind Kind)
Definition: Comdat.cpp:64
LLVMComdatSelectionKind
Definition: Comdat.h:29
LLVMComdatRef LLVMGetComdat(LLVMValueRef V)
Get the Comdat assigned to the given global object.
Definition: Comdat.cpp:38
@ LLVMLargestComdatSelectionKind
The linker will choose the largest COMDAT.
Definition: Comdat.h:33
@ LLVMSameSizeComdatSelectionKind
The data referenced by the COMDAT must be the same size.
Definition: Comdat.h:36
@ LLVMExactMatchComdatSelectionKind
The data referenced by the COMDAT must be the same.
Definition: Comdat.h:31
@ LLVMAnyComdatSelectionKind
The linker may choose any COMDAT.
Definition: Comdat.h:30
@ LLVMNoDeduplicateComdatSelectionKind
No deduplication is performed.
Definition: Comdat.h:35
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
struct LLVMComdat * LLVMComdatRef
Definition: Types.h:155
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:303
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:298