1*06f32e7eSjoerg //===- Comdat.cpp - Implement Metadata classes ----------------------------===// 2*06f32e7eSjoerg // 3*06f32e7eSjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*06f32e7eSjoerg // See https://llvm.org/LICENSE.txt for license information. 5*06f32e7eSjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*06f32e7eSjoerg // 7*06f32e7eSjoerg //===----------------------------------------------------------------------===// 8*06f32e7eSjoerg // 9*06f32e7eSjoerg // This file implements the Comdat class (including the C bindings). 10*06f32e7eSjoerg // 11*06f32e7eSjoerg //===----------------------------------------------------------------------===// 12*06f32e7eSjoerg 13*06f32e7eSjoerg #include "llvm-c/Comdat.h" 14*06f32e7eSjoerg #include "llvm/ADT/StringMap.h" 15*06f32e7eSjoerg #include "llvm/ADT/StringRef.h" 16*06f32e7eSjoerg #include "llvm/IR/Comdat.h" 17*06f32e7eSjoerg #include "llvm/IR/GlobalObject.h" 18*06f32e7eSjoerg #include "llvm/IR/Module.h" 19*06f32e7eSjoerg 20*06f32e7eSjoerg using namespace llvm; 21*06f32e7eSjoerg Comdat(Comdat && C)22*06f32e7eSjoergComdat::Comdat(Comdat &&C) : Name(C.Name), SK(C.SK) {} 23*06f32e7eSjoerg 24*06f32e7eSjoerg Comdat::Comdat() = default; 25*06f32e7eSjoerg getName() const26*06f32e7eSjoergStringRef Comdat::getName() const { return Name->first(); } 27*06f32e7eSjoerg LLVMGetOrInsertComdat(LLVMModuleRef M,const char * Name)28*06f32e7eSjoergLLVMComdatRef LLVMGetOrInsertComdat(LLVMModuleRef M, const char *Name) { 29*06f32e7eSjoerg return wrap(unwrap(M)->getOrInsertComdat(Name)); 30*06f32e7eSjoerg } 31*06f32e7eSjoerg LLVMGetComdat(LLVMValueRef V)32*06f32e7eSjoergLLVMComdatRef LLVMGetComdat(LLVMValueRef V) { 33*06f32e7eSjoerg GlobalObject *G = unwrap<GlobalObject>(V); 34*06f32e7eSjoerg return wrap(G->getComdat()); 35*06f32e7eSjoerg } 36*06f32e7eSjoerg LLVMSetComdat(LLVMValueRef V,LLVMComdatRef C)37*06f32e7eSjoergvoid LLVMSetComdat(LLVMValueRef V, LLVMComdatRef C) { 38*06f32e7eSjoerg GlobalObject *G = unwrap<GlobalObject>(V); 39*06f32e7eSjoerg G->setComdat(unwrap(C)); 40*06f32e7eSjoerg } 41*06f32e7eSjoerg LLVMGetComdatSelectionKind(LLVMComdatRef C)42*06f32e7eSjoergLLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C) { 43*06f32e7eSjoerg switch (unwrap(C)->getSelectionKind()) { 44*06f32e7eSjoerg case Comdat::Any: 45*06f32e7eSjoerg return LLVMAnyComdatSelectionKind; 46*06f32e7eSjoerg case Comdat::ExactMatch: 47*06f32e7eSjoerg return LLVMExactMatchComdatSelectionKind; 48*06f32e7eSjoerg case Comdat::Largest: 49*06f32e7eSjoerg return LLVMLargestComdatSelectionKind; 50*06f32e7eSjoerg case Comdat::NoDuplicates: 51*06f32e7eSjoerg return LLVMNoDuplicatesComdatSelectionKind; 52*06f32e7eSjoerg case Comdat::SameSize: 53*06f32e7eSjoerg return LLVMSameSizeComdatSelectionKind; 54*06f32e7eSjoerg } 55*06f32e7eSjoerg llvm_unreachable("Invalid Comdat SelectionKind!"); 56*06f32e7eSjoerg } 57*06f32e7eSjoerg LLVMSetComdatSelectionKind(LLVMComdatRef C,LLVMComdatSelectionKind kind)58*06f32e7eSjoergvoid LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind kind) { 59*06f32e7eSjoerg Comdat *Cd = unwrap(C); 60*06f32e7eSjoerg switch (kind) { 61*06f32e7eSjoerg case LLVMAnyComdatSelectionKind: 62*06f32e7eSjoerg Cd->setSelectionKind(Comdat::Any); 63*06f32e7eSjoerg break; 64*06f32e7eSjoerg case LLVMExactMatchComdatSelectionKind: 65*06f32e7eSjoerg Cd->setSelectionKind(Comdat::ExactMatch); 66*06f32e7eSjoerg break; 67*06f32e7eSjoerg case LLVMLargestComdatSelectionKind: 68*06f32e7eSjoerg Cd->setSelectionKind(Comdat::Largest); 69*06f32e7eSjoerg break; 70*06f32e7eSjoerg case LLVMNoDuplicatesComdatSelectionKind: 71*06f32e7eSjoerg Cd->setSelectionKind(Comdat::NoDuplicates); 72*06f32e7eSjoerg break; 73*06f32e7eSjoerg case LLVMSameSizeComdatSelectionKind: 74*06f32e7eSjoerg Cd->setSelectionKind(Comdat::SameSize); 75*06f32e7eSjoerg break; 76*06f32e7eSjoerg } 77*06f32e7eSjoerg } 78