223 changes: 158 additions & 65 deletions llvm/include/llvm/IR/Instructions.h

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions llvm/include/llvm/IR/LLVMContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ class LLVMContext {
/// custom metadata IDs registered in this LLVMContext.
void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;

/// getOperandBundleTags - Populate client supplied SmallVector with the
/// bundle tags registered in this LLVMContext. The bundle tags are ordered
/// by increasing bundle IDs.
/// \see LLVMContext::getOperandBundleTagID
void getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const;

/// getOperandBundleTagID - Maps a bundle tag to an integer ID. Every bundle
/// tag registered with an LLVMContext has an unique ID.
uint32_t getOperandBundleTagID(StringRef Tag) const;

typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
unsigned LocCookie);
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/IR/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ class Module {
/// registered in this LLVMContext.
void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;

/// Populate client supplied SmallVector with the bundle tags registered in
/// this LLVMContext. The bundle tags are ordered by increasing bundle IDs.
/// \see LLVMContext::getOperandBundleTagID
void getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const;

/// Return the type with the specified name, or null if there is none by that
/// name.
StructType *getTypeByName(StringRef Name) const;
Expand Down
25 changes: 21 additions & 4 deletions llvm/lib/IR/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ CallInst::~CallInst() {
}

void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
const Twine &NameStr) {
ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
this->FTy = FTy;
assert(getNumOperands() == Args.size() + 1 && "NumOperands not set up?");
assert(getNumOperands() == Args.size() + CountBundleInputs(Bundles) + 1 &&
"NumOperands not set up?");
Op<-1>() = Func;

#ifndef NDEBUG
Expand All @@ -243,6 +244,11 @@ void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
#endif

std::copy(Args.begin(), Args.end(), op_begin());

auto It = populateBundleOperandInfos(Bundles, Args.size());
(void)It;
assert(It + 1 == op_end() && "Should add up!");

setName(NameStr);
}

Expand Down Expand Up @@ -284,8 +290,10 @@ CallInst::CallInst(const CallInst &CI)
AttributeList(CI.AttributeList), FTy(CI.FTy) {
setTailCallKind(CI.getTailCallKind());
setCallingConv(CI.getCallingConv());

std::copy(CI.op_begin(), CI.op_end(), op_begin());
std::copy(CI.bundle_op_info_begin(), CI.bundle_op_info_end(),
bundle_op_info_begin());
SubclassOptionalData = CI.SubclassOptionalData;
}

Expand Down Expand Up @@ -499,10 +507,12 @@ Instruction* CallInst::CreateFree(Value* Source, BasicBlock *InsertAtEnd) {

void InvokeInst::init(FunctionType *FTy, Value *Fn, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr) {
this->FTy = FTy;

assert(getNumOperands() == 3 + Args.size() && "NumOperands not set up?");
assert(getNumOperands() == 3 + Args.size() + CountBundleInputs(Bundles) &&
"NumOperands not set up?");
Op<-3>() = Fn;
Op<-2>() = IfNormal;
Op<-1>() = IfException;
Expand All @@ -519,6 +529,11 @@ void InvokeInst::init(FunctionType *FTy, Value *Fn, BasicBlock *IfNormal,
#endif

std::copy(Args.begin(), Args.end(), op_begin());

auto It = populateBundleOperandInfos(Bundles, Args.size());
(void)It;
assert(It + 3 == op_end() && "Should add up!");

setName(NameStr);
}

Expand All @@ -530,6 +545,8 @@ InvokeInst::InvokeInst(const InvokeInst &II)
AttributeList(II.AttributeList), FTy(II.FTy) {
setCallingConv(II.getCallingConv());
std::copy(II.op_begin(), II.op_end(), op_begin());
std::copy(II.bundle_op_info_begin(), II.bundle_op_info_end(),
bundle_op_info_begin());
SubclassOptionalData = II.SubclassOptionalData;
}

Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/IR/LLVMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,11 @@ void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
E = pImpl->CustomMDKindNames.end(); I != E; ++I)
Names[I->second] = I->first();
}

void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
pImpl->getOperandBundleTags(Tags);
}

uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const {
return pImpl->getOperandBundleTagID(Tag);
}
17 changes: 17 additions & 0 deletions llvm/lib/IR/LLVMContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ unsigned MDNodeOpsKey::calculateHash(ArrayRef<Metadata *> Ops) {
return hash_combine_range(Ops.begin(), Ops.end());
}

StringMapEntry<uint32_t> *LLVMContextImpl::getOrInsertBundleTag(StringRef Tag) {
uint32_t NewIdx = BundleTagCache.size();
return &*(BundleTagCache.insert(std::make_pair(Tag, NewIdx)).first);
}

void LLVMContextImpl::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
Tags.resize(BundleTagCache.size());
for (const auto &T : BundleTagCache)
Tags[T.second] = T.first();
}

uint32_t LLVMContextImpl::getOperandBundleTagID(StringRef Tag) const {
auto I = BundleTagCache.find(Tag);
assert(I != BundleTagCache.end() && "Unknown tag!");
return I->second;
}

// ConstantsContext anchors
void UnaryConstantExpr::anchor() { }

Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/IR/LLVMContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,16 @@ class LLVMContextImpl {
int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);

/// \brief A set of interned tags for operand bundles. The StringMap maps
/// bundle tags to their IDs.
///
/// \see LLVMContext::getOperandBundleTagID
StringMap<uint32_t> BundleTagCache;

StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
uint32_t getOperandBundleTagID(StringRef Tag) const;

LLVMContextImpl(LLVMContext &C);
~LLVMContextImpl();

Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/IR/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ void Module::getMDKindNames(SmallVectorImpl<StringRef> &Result) const {
return Context.getMDKindNames(Result);
}

void Module::getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const {
return Context.getOperandBundleTags(Result);
}

//===----------------------------------------------------------------------===//
// Methods for easy access to the functions in the module.
Expand Down