[InstCombine] Signed saturation patterns
[llvm-core.git] / bindings / go / llvm / IRBindings.cpp
blob5b84f482b16b761e58f8a0469ed4e954a0d067ba
1 //===- IRBindings.cpp - Additional bindings for ir ------------------------===//
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 defines additional C bindings for the ir component.
11 //===----------------------------------------------------------------------===//
13 #include "IRBindings.h"
14 #include "llvm/IR/Attributes.h"
15 #include "llvm/IR/DebugLoc.h"
16 #include "llvm/IR/DebugInfoMetadata.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/IRBuilder.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/Module.h"
22 using namespace llvm;
24 LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef C) {
25 return wrap(ConstantAsMetadata::get(unwrap<Constant>(C)));
28 LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen) {
29 return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
32 LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
33 unsigned Count) {
34 return wrap(
35 MDNode::get(*unwrap(C), ArrayRef<Metadata *>(unwrap(MDs), Count)));
38 void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
39 LLVMMetadataRef Val) {
40 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
41 if (!N)
42 return;
43 if (!Val)
44 return;
45 N->addOperand(unwrap<MDNode>(Val));
48 void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) {
49 MDNode *N = MD ? unwrap<MDNode>(MD) : nullptr;
50 unwrap<Instruction>(Inst)->setMetadata(KindID, N);
53 void LLVMGoSetCurrentDebugLocation(LLVMBuilderRef Bref, unsigned Line,
54 unsigned Col, LLVMMetadataRef Scope,
55 LLVMMetadataRef InlinedAt) {
56 unwrap(Bref)->SetCurrentDebugLocation(
57 DebugLoc::get(Line, Col, Scope ? unwrap<MDNode>(Scope) : nullptr,
58 InlinedAt ? unwrap<MDNode>(InlinedAt) : nullptr));
61 LLVMDebugLocMetadata LLVMGoGetCurrentDebugLocation(LLVMBuilderRef Bref) {
62 const auto& Loc = unwrap(Bref)->getCurrentDebugLocation();
63 const auto* InlinedAt = Loc.getInlinedAt();
64 const LLVMDebugLocMetadata md{
65 Loc.getLine(),
66 Loc.getCol(),
67 wrap(Loc.getScope()),
68 InlinedAt == nullptr ? nullptr : wrap(InlinedAt->getRawInlinedAt()),
70 return md;