Path: blob/main/contrib/llvm-project/llvm/lib/IR/Comdat.cpp
35233 views
//===- Comdat.cpp - Implement Metadata classes ----------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the Comdat class (including the C bindings).9//10//===----------------------------------------------------------------------===//1112#include "llvm-c/Comdat.h"13#include "llvm/ADT/SmallPtrSet.h"14#include "llvm/ADT/StringMapEntry.h"15#include "llvm/ADT/StringRef.h"16#include "llvm/IR/Comdat.h"17#include "llvm/IR/GlobalObject.h"18#include "llvm/IR/Module.h"19#include "llvm/IR/Value.h"2021using namespace llvm;2223Comdat::Comdat(Comdat &&C) : Name(C.Name), SK(C.SK) {}2425Comdat::Comdat() = default;2627StringRef Comdat::getName() const { return Name->first(); }2829void Comdat::addUser(GlobalObject *GO) { Users.insert(GO); }3031void Comdat::removeUser(GlobalObject *GO) { Users.erase(GO); }3233LLVMComdatRef LLVMGetOrInsertComdat(LLVMModuleRef M, const char *Name) {34return wrap(unwrap(M)->getOrInsertComdat(Name));35}3637LLVMComdatRef LLVMGetComdat(LLVMValueRef V) {38GlobalObject *G = unwrap<GlobalObject>(V);39return wrap(G->getComdat());40}4142void LLVMSetComdat(LLVMValueRef V, LLVMComdatRef C) {43GlobalObject *G = unwrap<GlobalObject>(V);44G->setComdat(unwrap(C));45}4647LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C) {48switch (unwrap(C)->getSelectionKind()) {49case Comdat::Any:50return LLVMAnyComdatSelectionKind;51case Comdat::ExactMatch:52return LLVMExactMatchComdatSelectionKind;53case Comdat::Largest:54return LLVMLargestComdatSelectionKind;55case Comdat::NoDeduplicate:56return LLVMNoDeduplicateComdatSelectionKind;57case Comdat::SameSize:58return LLVMSameSizeComdatSelectionKind;59}60llvm_unreachable("Invalid Comdat SelectionKind!");61}6263void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind kind) {64Comdat *Cd = unwrap(C);65switch (kind) {66case LLVMAnyComdatSelectionKind:67Cd->setSelectionKind(Comdat::Any);68break;69case LLVMExactMatchComdatSelectionKind:70Cd->setSelectionKind(Comdat::ExactMatch);71break;72case LLVMLargestComdatSelectionKind:73Cd->setSelectionKind(Comdat::Largest);74break;75case LLVMNoDeduplicateComdatSelectionKind:76Cd->setSelectionKind(Comdat::NoDeduplicate);77break;78case LLVMSameSizeComdatSelectionKind:79Cd->setSelectionKind(Comdat::SameSize);80break;81}82}838485