diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
commit | e6d1592492a3a379186bfb02bd0f4eda0669c0d5 (patch) | |
tree | 599ab169a01f1c86eda9adc774edaedde2f2db5b /lib/IR/MDBuilder.cpp | |
parent | 1a56a5ead7a2e84bee8240f5f6b033b5f1707154 (diff) |
Notes
Diffstat (limited to 'lib/IR/MDBuilder.cpp')
-rw-r--r-- | lib/IR/MDBuilder.cpp | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/lib/IR/MDBuilder.cpp b/lib/IR/MDBuilder.cpp index 3fa541f1b535..14bcb3a29b07 100644 --- a/lib/IR/MDBuilder.cpp +++ b/lib/IR/MDBuilder.cpp @@ -1,9 +1,8 @@ //===---- llvm/MDBuilder.cpp - Builder for LLVM metadata ------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -69,9 +68,7 @@ MDNode *MDBuilder::createFunctionEntryCount( Ops.push_back(createConstant(ConstantInt::get(Int64Ty, Count))); if (Imports) { SmallVector<GlobalValue::GUID, 2> OrderID(Imports->begin(), Imports->end()); - std::stable_sort(OrderID.begin(), OrderID.end(), - [] (GlobalValue::GUID A, GlobalValue::GUID B) { - return A < B;}); + llvm::stable_sort(OrderID); for (auto ID : OrderID) Ops.push_back(createConstant(ConstantInt::get(Int64Ty, ID))); } @@ -107,6 +104,52 @@ MDNode *MDBuilder::createCallees(ArrayRef<Function *> Callees) { return MDNode::get(Context, Ops); } +MDNode *MDBuilder::createCallbackEncoding(unsigned CalleeArgNo, + ArrayRef<int> Arguments, + bool VarArgArePassed) { + SmallVector<Metadata *, 4> Ops; + + Type *Int64 = Type::getInt64Ty(Context); + Ops.push_back(createConstant(ConstantInt::get(Int64, CalleeArgNo))); + + for (int ArgNo : Arguments) + Ops.push_back(createConstant(ConstantInt::get(Int64, ArgNo, true))); + + Type *Int1 = Type::getInt1Ty(Context); + Ops.push_back(createConstant(ConstantInt::get(Int1, VarArgArePassed))); + + return MDNode::get(Context, Ops); +} + +MDNode *MDBuilder::mergeCallbackEncodings(MDNode *ExistingCallbacks, + MDNode *NewCB) { + if (!ExistingCallbacks) + return MDNode::get(Context, {NewCB}); + + auto *NewCBCalleeIdxAsCM = cast<ConstantAsMetadata>(NewCB->getOperand(0)); + uint64_t NewCBCalleeIdx = + cast<ConstantInt>(NewCBCalleeIdxAsCM->getValue())->getZExtValue(); + (void)NewCBCalleeIdx; + + SmallVector<Metadata *, 4> Ops; + unsigned NumExistingOps = ExistingCallbacks->getNumOperands(); + Ops.resize(NumExistingOps + 1); + + for (unsigned u = 0; u < NumExistingOps; u++) { + Ops[u] = ExistingCallbacks->getOperand(u); + + auto *OldCBCalleeIdxAsCM = cast<ConstantAsMetadata>(Ops[u]); + uint64_t OldCBCalleeIdx = + cast<ConstantInt>(OldCBCalleeIdxAsCM->getValue())->getZExtValue(); + (void)OldCBCalleeIdx; + assert(NewCBCalleeIdx != OldCBCalleeIdx && + "Cannot map a callback callee index twice!"); + } + + Ops[NumExistingOps] = NewCB; + return MDNode::get(Context, Ops); +} + MDNode *MDBuilder::createAnonymousAARoot(StringRef Name, MDNode *Extra) { // To ensure uniqueness the root node is self-referential. auto Dummy = MDNode::getTemporary(Context, None); |