Eugene Zelenko | b1df787 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 1 | //===- Comdat.cpp - Implement Metadata classes ----------------------------===// |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Kleckner | 862ea57 | 2018-03-14 18:33:53 +0000 | [diff] [blame] | 10 | // This file implements the Comdat class (including the C bindings). |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Reid Kleckner | 862ea57 | 2018-03-14 18:33:53 +0000 | [diff] [blame] | 14 | #include "llvm-c/Comdat.h" |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringMap.h" |
Eugene Zelenko | b1df787 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringRef.h" |
Reid Kleckner | 862ea57 | 2018-03-14 18:33:53 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Comdat.h" |
| 18 | #include "llvm/IR/GlobalObject.h" |
| 19 | #include "llvm/IR/Module.h" |
Eugene Zelenko | b1df787 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 20 | |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 23 | Comdat::Comdat(Comdat &&C) : Name(C.Name), SK(C.SK) {} |
| 24 | |
Eugene Zelenko | b1df787 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 25 | Comdat::Comdat() = default; |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 26 | |
| 27 | StringRef Comdat::getName() const { return Name->first(); } |
Reid Kleckner | 862ea57 | 2018-03-14 18:33:53 +0000 | [diff] [blame] | 28 | |
| 29 | LLVMComdatRef LLVMGetOrInsertComdat(LLVMModuleRef M, const char *Name) { |
| 30 | return wrap(unwrap(M)->getOrInsertComdat(Name)); |
| 31 | } |
| 32 | |
| 33 | LLVMComdatRef LLVMGetComdat(LLVMValueRef V) { |
| 34 | GlobalObject *G = unwrap<GlobalObject>(V); |
| 35 | return wrap(G->getComdat()); |
| 36 | } |
| 37 | |
| 38 | void LLVMSetComdat(LLVMValueRef V, LLVMComdatRef C) { |
| 39 | GlobalObject *G = unwrap<GlobalObject>(V); |
| 40 | G->setComdat(unwrap(C)); |
| 41 | } |
| 42 | |
| 43 | LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C) { |
| 44 | switch (unwrap(C)->getSelectionKind()) { |
| 45 | case Comdat::Any: |
| 46 | return LLVMAnyComdatSelectionKind; |
| 47 | case Comdat::ExactMatch: |
| 48 | return LLVMExactMatchComdatSelectionKind; |
| 49 | case Comdat::Largest: |
| 50 | return LLVMLargestComdatSelectionKind; |
| 51 | case Comdat::NoDuplicates: |
| 52 | return LLVMNoDuplicatesComdatSelectionKind; |
| 53 | case Comdat::SameSize: |
| 54 | return LLVMSameSizeComdatSelectionKind; |
| 55 | } |
| 56 | llvm_unreachable("Invalid Comdat SelectionKind!"); |
| 57 | } |
| 58 | |
| 59 | void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind kind) { |
| 60 | Comdat *Cd = unwrap(C); |
| 61 | switch (kind) { |
| 62 | case LLVMAnyComdatSelectionKind: |
| 63 | Cd->setSelectionKind(Comdat::Any); |
| 64 | break; |
| 65 | case LLVMExactMatchComdatSelectionKind: |
| 66 | Cd->setSelectionKind(Comdat::ExactMatch); |
| 67 | break; |
| 68 | case LLVMLargestComdatSelectionKind: |
| 69 | Cd->setSelectionKind(Comdat::Largest); |
| 70 | break; |
| 71 | case LLVMNoDuplicatesComdatSelectionKind: |
| 72 | Cd->setSelectionKind(Comdat::NoDuplicates); |
| 73 | break; |
| 74 | case LLVMSameSizeComdatSelectionKind: |
| 75 | Cd->setSelectionKind(Comdat::SameSize); |
| 76 | break; |
| 77 | } |
| 78 | } |