本文整理汇总了C++中MDString类的典型用法代码示例。如果您正苦于以下问题:C++ MDString类的具体用法?C++ MDString怎么用?C++ MDString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MDString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseType
map<string, Variable*>* IRParser::parseParameters(Module* module){
map<string, Variable*>* parameters = new map<string, Variable*>();
NamedMDNode* inputsMD = module->getNamedMetadata(IRConstant::KEY_PARAMETERS);
if (inputsMD != NULL){
for (unsigned i = 0, e = inputsMD->getNumOperands(); i != e; ++i) {
//Parse a parameter
MDNode* parameterNode = cast<MDNode>(inputsMD->getOperand(i));
MDNode* details = cast<MDNode>(parameterNode->getOperand(0));
MDString* nameMD = cast<MDString>(details->getOperand(0));
Type* type = parseType(cast<MDNode>(parameterNode->getOperand(1)));
GlobalVariable* variable = cast<GlobalVariable>(parameterNode->getOperand(2));
//Parse create parameter
StateVar* parameter = new StateVar(type, nameMD->getString(), false, variable);
parameters->insert(pair<string, Variable*>(nameMD->getString(), parameter));
}
}
return parameters;
}
示例2: assert
/// \brief Find string metadata for loop
///
/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
/// operand or null otherwise. If the string metadata is not found return
/// Optional's not-a-value.
Optional<const MDOperand *> llvm::findStringMetadataForLoop(Loop *TheLoop,
StringRef Name) {
MDNode *LoopID = TheLoop->getLoopID();
// Return none if LoopID is false.
if (!LoopID)
return None;
// First operand should refer to the loop id itself.
assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
assert(LoopID->getOperand(0) == LoopID && "invalid loop id");
// Iterate over LoopID operands and look for MDString Metadata
for (unsigned i = 1, e = LoopID->getNumOperands(); i < e; ++i) {
MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
if (!MD)
continue;
MDString *S = dyn_cast<MDString>(MD->getOperand(0));
if (!S)
continue;
// Return true if MDString holds expected MetaData.
if (Name.equals(S->getString()))
switch (MD->getNumOperands()) {
case 1:
return nullptr;
case 2:
return &MD->getOperand(1);
default:
llvm_unreachable("loop metadata has 0 or 1 operand");
}
}
return None;
}
示例3: DPNMoC
MoC* IRParser::parseMoC(Module* module){
NamedMDNode* mocKeyMD = module->getNamedMetadata(IRConstant::KEY_MOC);
if (mocKeyMD == NULL) {
return new DPNMoC(actor);
}
//Parse MoC type
MDNode* node = mocKeyMD->getOperand(0);
MDString* name = cast<MDString>(node->getOperand(0));
StringRef nameStr = name->getString();
if (nameStr == "SDF"){
return parseCSDF(cast<MDNode>(node->getOperand(1)));
}else if(nameStr == "CSDF"){
return parseCSDF(cast<MDNode>(node->getOperand(1)));
}else if(nameStr == "QuasiStatic"){
return parseQSDF(node);
}else if(nameStr == "KPN"){
return new KPNMoC(actor);
}else if(nameStr == "DPN"){
return new DPNMoC(actor);
}
cerr << "Unsupported type of MoC" << endl;
exit(1);
}
示例4: OS
/// parseMetadata - Parse metadata from the module
void LTOModule::parseMetadata() {
raw_string_ostream OS(LinkerOpts);
// Linker Options
if (NamedMDNode *LinkerOptions =
getModule().getNamedMetadata("llvm.linker.options")) {
for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
MDNode *MDOptions = LinkerOptions->getOperand(i);
for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
OS << " " << MDOption->getString();
}
}
}
// Globals - we only need to do this for COFF.
const Triple TT(_target->getTargetTriple());
if (!TT.isOSBinFormatCOFF())
return;
Mangler M;
for (const NameAndAttributes &Sym : _symbols) {
if (!Sym.symbol)
continue;
emitLinkerFlagsForGlobalCOFF(OS, Sym.symbol, TT, M);
}
// Add other interesting metadata here.
}
示例5: mangleName
std::string GCOVProfiler::mangleName(const DICompileUnit *CU,
const char *NewStem) {
if (NamedMDNode *GCov = M->getNamedMetadata("llvm.gcov")) {
for (int i = 0, e = GCov->getNumOperands(); i != e; ++i) {
MDNode *N = GCov->getOperand(i);
if (N->getNumOperands() != 2) continue;
MDString *GCovFile = dyn_cast<MDString>(N->getOperand(0));
MDNode *CompileUnit = dyn_cast<MDNode>(N->getOperand(1));
if (!GCovFile || !CompileUnit) continue;
if (CompileUnit == CU) {
SmallString<128> Filename = GCovFile->getString();
sys::path::replace_extension(Filename, NewStem);
return Filename.str();
}
}
}
SmallString<128> Filename = CU->getFilename();
sys::path::replace_extension(Filename, NewStem);
StringRef FName = sys::path::filename(Filename);
SmallString<128> CurPath;
if (sys::fs::current_path(CurPath)) return FName;
sys::path::append(CurPath, FName);
return CurPath.str();
}
示例6: getBodyFunction
Action* IRParser::getAction(llvm::MDNode* node) {
Value* idValue = node->getOperand(0);
if (idValue == NULL){
map<Function*, Action*>::iterator it;
// Action has not tag, find it by its function name
Function* function = getBodyFunction(node);
it = untaggedActions.find(function);
return it->second;
}
//Get identifiers of action tag
map<std::string, Action*>::iterator it;
ActionTag tag;
MDNode* idNode = cast<MDNode>(idValue);
for (unsigned i = 0, e = idNode->getNumOperands(); i != e; ++i){
MDString* tagMD = cast<MDString>(idNode->getOperand(i));
tag.add(tagMD->getString());
}
it = actions.find(tag.getIdentifier());
return it->second;
}
示例7: parseMetadata
/// parseMetadata - Parse metadata from the module
void LTOModule::parseMetadata() {
// Linker Options
if (Metadata *Val = getModule().getModuleFlag("Linker Options")) {
MDNode *LinkerOptions = cast<MDNode>(Val);
for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
// FIXME: Make StringSet::insert match Self-Associative Container
// requirements, returning <iter,bool> rather than bool, and use that
// here.
StringRef Op =
_linkeropt_strings.insert(MDOption->getString()).first->first();
StringRef DepLibName = _target->getSubtargetImpl()
->getTargetLowering()
->getObjFileLowering()
.getDepLibFromLinkerOpt(Op);
if (!DepLibName.empty())
_deplibs.push_back(DepLibName.data());
else if (!Op.empty())
_linkeropts.push_back(Op.data());
}
}
}
// Add other interesting metadata here.
}
示例8: emitModuleFlags
void TargetLoweringObjectFileCOFF::
emitModuleFlags(MCStreamer &Streamer,
ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
Mangler &Mang, const TargetMachine &TM) const {
MDNode *LinkerOptions = nullptr;
// Look for the "Linker Options" flag, since it's the only one we support.
for (ArrayRef<Module::ModuleFlagEntry>::iterator
i = ModuleFlags.begin(), e = ModuleFlags.end(); i != e; ++i) {
const Module::ModuleFlagEntry &MFE = *i;
StringRef Key = MFE.Key->getString();
Metadata *Val = MFE.Val;
if (Key == "Linker Options") {
LinkerOptions = cast<MDNode>(Val);
break;
}
}
if (!LinkerOptions)
return;
// Emit the linker options to the linker .drectve section. According to the
// spec, this section is a space-separated string containing flags for linker.
const MCSection *Sec = getDrectveSection();
Streamer.SwitchSection(Sec);
for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
// Lead with a space for consistency with our dllexport implementation.
std::string Directive(" ");
Directive.append(MDOption->getString());
Streamer.EmitBytes(Directive);
}
}
}
示例9: assert
MDNode *llvm::findOptionMDForLoopID(MDNode *LoopID, StringRef Name) {
// No loop metadata node, no loop properties.
if (!LoopID)
return nullptr;
// First operand should refer to the metadata node itself, for legacy reasons.
assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
assert(LoopID->getOperand(0) == LoopID && "invalid loop id");
// Iterate over the metdata node operands and look for MDString metadata.
for (unsigned i = 1, e = LoopID->getNumOperands(); i < e; ++i) {
MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
if (!MD || MD->getNumOperands() < 1)
continue;
MDString *S = dyn_cast<MDString>(MD->getOperand(0));
if (!S)
continue;
// Return the operand node if MDString holds expected metadata.
if (Name.equals(S->getString()))
return MD;
}
// Loop property not found.
return nullptr;
}
示例10: sd_getStringFromMDTuple
static inline SDBuildCHA::vtbl_name_t
sd_getStringFromMDTuple(const MDOperand& op) {
MDString* mds = dyn_cast_or_null<MDString>(op.get());
assert(mds);
return mds->getString().str();
}
示例11: OS
/// parseMetadata - Parse metadata from the module
void LTOModule::parseMetadata() {
raw_string_ostream OS(LinkerOpts);
// Linker Options
if (Metadata *Val = getModule().getModuleFlag("Linker Options")) {
MDNode *LinkerOptions = cast<MDNode>(Val);
for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
OS << " " << MDOption->getString();
}
}
}
// Globals
Mangler Mang;
for (const NameAndAttributes &Sym : _symbols) {
if (!Sym.symbol)
continue;
_target->getObjFileLowering()->emitLinkerFlagsForGlobal(OS, Sym.symbol,
Mang);
}
// Add other interesting metadata here.
}
示例12: getSummaryFromMD
// Parse an MDTuple representing detailed summary.
static bool getSummaryFromMD(MDTuple *MD, SummaryEntryVector &Summary) {
if (!MD || MD->getNumOperands() != 2)
return false;
MDString *KeyMD = dyn_cast<MDString>(MD->getOperand(0));
if (!KeyMD || !KeyMD->getString().equals("DetailedSummary"))
return false;
MDTuple *EntriesMD = dyn_cast<MDTuple>(MD->getOperand(1));
if (!EntriesMD)
return false;
for (auto &&MDOp : EntriesMD->operands()) {
MDTuple *EntryMD = dyn_cast<MDTuple>(MDOp);
if (!EntryMD || EntryMD->getNumOperands() != 3)
return false;
ConstantAsMetadata *Op0 =
dyn_cast<ConstantAsMetadata>(EntryMD->getOperand(0));
ConstantAsMetadata *Op1 =
dyn_cast<ConstantAsMetadata>(EntryMD->getOperand(1));
ConstantAsMetadata *Op2 =
dyn_cast<ConstantAsMetadata>(EntryMD->getOperand(2));
if (!Op0 || !Op1 || !Op2)
return false;
Summary.emplace_back(cast<ConstantInt>(Op0->getValue())->getZExtValue(),
cast<ConstantInt>(Op1->getValue())->getZExtValue(),
cast<ConstantInt>(Op2->getValue())->getZExtValue());
}
return true;
}
示例13: categorizeModuleFlagNodes
/// categorizeModuleFlagNodes -
bool ModuleLinker::
categorizeModuleFlagNodes(const NamedMDNode *ModFlags,
DenseMap<MDString*, MDNode*> &ErrorNode,
DenseMap<MDString*, MDNode*> &WarningNode,
DenseMap<MDString*, MDNode*> &OverrideNode,
DenseMap<MDString*,
SmallSetVector<MDNode*, 8> > &RequireNodes,
SmallSetVector<MDString*, 16> &SeenIDs) {
bool HasErr = false;
for (unsigned I = 0, E = ModFlags->getNumOperands(); I != E; ++I) {
MDNode *Op = ModFlags->getOperand(I);
assert(Op->getNumOperands() == 3 && "Invalid module flag metadata!");
assert(isa<ConstantInt>(Op->getOperand(0)) &&
"Module flag's first operand must be an integer!");
assert(isa<MDString>(Op->getOperand(1)) &&
"Module flag's second operand must be an MDString!");
ConstantInt *Behavior = cast<ConstantInt>(Op->getOperand(0));
MDString *ID = cast<MDString>(Op->getOperand(1));
Value *Val = Op->getOperand(2);
switch (Behavior->getZExtValue()) {
default:
assert(false && "Invalid behavior in module flag metadata!");
break;
case Module::Error: {
MDNode *&ErrNode = ErrorNode[ID];
if (!ErrNode) ErrNode = Op;
if (ErrNode->getOperand(2) != Val)
HasErr = emitError("linking module flags '" + ID->getString() +
"': IDs have conflicting values");
break;
}
case Module::Warning: {
MDNode *&WarnNode = WarningNode[ID];
if (!WarnNode) WarnNode = Op;
if (WarnNode->getOperand(2) != Val)
errs() << "WARNING: linking module flags '" << ID->getString()
<< "': IDs have conflicting values";
break;
}
case Module::Require: RequireNodes[ID].insert(Op); break;
case Module::Override: {
MDNode *&OvrNode = OverrideNode[ID];
if (!OvrNode) OvrNode = Op;
if (OvrNode->getOperand(2) != Val)
HasErr = emitError("linking module flags '" + ID->getString() +
"': IDs have conflicting override values");
break;
}
}
SeenIDs.insert(ID);
}
return HasErr;
}
示例14: isKeyValuePair
// Check if an MDTuple represents a (Key, Val) pair.
static bool isKeyValuePair(MDTuple *MD, const char *Key, const char *Val) {
if (!MD || MD->getNumOperands() != 2)
return false;
MDString *KeyMD = dyn_cast<MDString>(MD->getOperand(0));
MDString *ValMD = dyn_cast<MDString>(MD->getOperand(1));
if (!KeyMD || !ValMD)
return false;
if (!KeyMD->getString().equals(Key) || !ValMD->getString().equals(Val))
return false;
return true;
}
示例15: parsePort
Port* IRParser::parsePort(MDNode* node){
//Get port property
Type* type = (Type*)parseType(cast<MDNode>(node->getOperand(0)));
MDString* name = cast<MDString>(node->getOperand(1));
GlobalVariable* var = cast<GlobalVariable>(node->getOperand(2));
//Create the new port
Port* newPort = new Port(name->getString(), (IntegerType*)type, actor);
newPort->setPtrVar(new Variable(type, name->getString(), true, true, var));
return newPort;
}