2014-10-16 22:48:02 +00:00
|
|
|
//===- IRBindings.cpp - Additional bindings for ir ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines additional C bindings for the ir component.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "IRBindings.h"
|
|
|
|
#include "llvm/IR/Attributes.h"
|
2014-12-13 02:25:49 +00:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
2014-10-16 22:48:02 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2014-12-13 02:25:49 +00:00
|
|
|
#include "llvm/IR/IRBuilder.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2014-10-16 22:48:02 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
void LLVMAddFunctionAttr2(LLVMValueRef Fn, uint64_t PA) {
|
|
|
|
Function *Func = unwrap<Function>(Fn);
|
|
|
|
const AttributeSet PAL = Func->getAttributes();
|
|
|
|
AttrBuilder B(PA);
|
|
|
|
const AttributeSet PALnew =
|
|
|
|
PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex,
|
|
|
|
AttributeSet::get(Func->getContext(),
|
|
|
|
AttributeSet::FunctionIndex, B));
|
|
|
|
Func->setAttributes(PALnew);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMGetFunctionAttr2(LLVMValueRef Fn) {
|
|
|
|
Function *Func = unwrap<Function>(Fn);
|
|
|
|
const AttributeSet PAL = Func->getAttributes();
|
|
|
|
return PAL.Raw(AttributeSet::FunctionIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMRemoveFunctionAttr2(LLVMValueRef Fn, uint64_t PA) {
|
|
|
|
Function *Func = unwrap<Function>(Fn);
|
|
|
|
const AttributeSet PAL = Func->getAttributes();
|
|
|
|
AttrBuilder B(PA);
|
|
|
|
const AttributeSet PALnew =
|
|
|
|
PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex,
|
|
|
|
AttributeSet::get(Func->getContext(),
|
|
|
|
AttributeSet::FunctionIndex, B));
|
|
|
|
Func->setAttributes(PALnew);
|
|
|
|
}
|
2014-12-13 02:25:49 +00:00
|
|
|
|
2014-12-13 02:25:57 +00:00
|
|
|
LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef C) {
|
|
|
|
return wrap(ConstantAsMetadata::get(unwrap<Constant>(C)));
|
|
|
|
}
|
|
|
|
|
2014-12-13 02:25:49 +00:00
|
|
|
LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen) {
|
|
|
|
return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
|
|
|
|
unsigned Count) {
|
|
|
|
return wrap(
|
|
|
|
MDNode::get(*unwrap(C), ArrayRef<Metadata *>(unwrap(MDs), Count)));
|
|
|
|
}
|
|
|
|
|
2014-12-13 02:25:54 +00:00
|
|
|
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
|
|
|
|
unsigned Count) {
|
2015-01-19 21:30:18 +00:00
|
|
|
return wrap(MDTuple::getTemporary(*unwrap(C),
|
|
|
|
ArrayRef<Metadata *>(unwrap(MDs), Count))
|
|
|
|
.release());
|
2014-12-13 02:25:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 02:25:49 +00:00
|
|
|
void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
|
|
|
|
LLVMMetadataRef Val) {
|
|
|
|
NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
|
|
|
|
if (!N)
|
|
|
|
return;
|
|
|
|
if (!Val)
|
|
|
|
return;
|
|
|
|
N->addOperand(unwrap<MDNode>(Val));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) {
|
|
|
|
MDNode *N = MD ? unwrap<MDNode>(MD) : nullptr;
|
|
|
|
unwrap<Instruction>(Inst)->setMetadata(KindID, N);
|
|
|
|
}
|
|
|
|
|
2014-12-13 02:25:51 +00:00
|
|
|
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
|
2015-03-05 22:55:38 +00:00
|
|
|
auto *Node = unwrap<MDNode>(MD);
|
|
|
|
Node->replaceAllUsesWith(unwrap<Metadata>(New));
|
2014-12-13 02:25:51 +00:00
|
|
|
MDNode::deleteTemporary(Node);
|
|
|
|
}
|
|
|
|
|
2014-12-13 02:25:49 +00:00
|
|
|
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
|
|
|
|
unsigned Col, LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef InlinedAt) {
|
|
|
|
unwrap(Bref)->SetCurrentDebugLocation(
|
|
|
|
DebugLoc::get(Line, Col, Scope ? unwrap<MDNode>(Scope) : nullptr,
|
|
|
|
InlinedAt ? unwrap<MDNode>(InlinedAt) : nullptr));
|
|
|
|
}
|