18 #include "llvm/Config/config.h"
58 cl::desc(
"Choose what kind of output to generate"),
74 cl::desc(
"Specify the name of the thing to generate"),
83 typedef std::vector<Type*> TypeList;
84 typedef std::map<Type*,std::string> TypeMap;
85 typedef std::map<const Value*,std::string>
ValueMap;
86 typedef std::set<std::string> NameSet;
87 typedef std::set<Type*> TypeSet;
88 typedef std::set<const Value*> ValueSet;
89 typedef std::map<const Value*,std::string> ForwardRefMap;
100 TypeSet DefinedTypes;
101 ValueSet DefinedValues;
102 ForwardRefMap ForwardRefs;
104 unsigned indent_level;
111 virtual const char *getPassName()
const {
return "C++ backend"; }
113 bool runOnModule(
Module &M);
115 void printProgram(
const std::string& fname,
const std::string& modName );
116 void printModule(
const std::string& fname,
const std::string& modName );
117 void printContents(
const std::string& fname,
const std::string& modName );
118 void printFunction(
const std::string& fname,
const std::string& funcName );
119 void printFunctions();
120 void printInline(
const std::string& fname,
const std::string& funcName );
121 void printVariable(
const std::string& fname,
const std::string& varName );
122 void printType(
const std::string& fname,
const std::string& typeName );
124 void error(
const std::string& msg);
128 inline void in() { indent_level++; }
129 inline void out() {
if (indent_level >0) indent_level--; }
136 void printEscapedString(
const std::string& str);
139 std::string getCppName(
Type* val);
140 inline void printCppName(
Type* val);
142 std::string getCppName(
const Value* val);
143 inline void printCppName(
const Value* val);
145 void printAttributes(
const AttributeSet &PAL,
const std::string &name);
146 void printType(
Type* Ty);
147 void printTypes(
const Module* M);
149 void printConstant(
const Constant *CPV);
150 void printConstants(
const Module* M);
156 void printFunctionUses(
const Function *
F);
157 void printFunctionHead(
const Function *
F);
158 void printFunctionBody(
const Function *
F);
159 void printInstruction(
const Instruction *
I,
const std::string& bbname);
160 std::string getOpName(
const Value*);
162 void printModuleBody();
168 if (delta >= 0 || indent_level >=
unsigned(-delta))
169 indent_level += delta;
175 for (
size_t i = 0; i < str.length(); ++i)
176 if (!isalnum(str[i]) && str[i] !=
'_')
193 default:
return "other_";
197 void CppWriter::error(
const std::string& msg) {
210 return "<unknown format in ftostr>";
216 void CppWriter::printCFP(
const ConstantFP *CFP) {
221 Out <<
"ConstantFP::get(mod->getContext(), ";
226 if ((!
strncmp(Buffer,
"0x", 2) ||
231 Out <<
"BitsToDouble(" << Buffer <<
")";
233 Out <<
"BitsToFloat((float)" << Buffer <<
")";
239 while (StrVal[0] ==
' ')
240 StrVal.erase(StrVal.begin());
244 if (((StrVal[0] >=
'0' && StrVal[0] <=
'9') ||
245 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
246 (StrVal[1] >=
'0' && StrVal[1] <=
'9'))) &&
251 Out << StrVal <<
"f";
253 Out <<
"BitsToDouble(0x"
255 <<
"ULL) /* " << StrVal <<
" */";
257 Out <<
"BitsToFloat(0x"
259 bitcastToAPInt().getZExtValue())
260 <<
"U) /* " << StrVal <<
" */";
275 default: Out << cc;
break;
282 Out <<
"GlobalValue::InternalLinkage";
break;
284 Out <<
"GlobalValue::PrivateLinkage";
break;
286 Out <<
"GlobalValue::LinkerPrivateLinkage";
break;
288 Out <<
"GlobalValue::LinkerPrivateWeakLinkage";
break;
290 Out <<
"GlobalValue::AvailableExternallyLinkage ";
break;
292 Out <<
"GlobalValue::LinkOnceAnyLinkage ";
break;
294 Out <<
"GlobalValue::LinkOnceODRLinkage ";
break;
296 Out <<
"GlobalValue::WeakAnyLinkage";
break;
298 Out <<
"GlobalValue::WeakODRLinkage";
break;
300 Out <<
"GlobalValue::AppendingLinkage";
break;
302 Out <<
"GlobalValue::ExternalLinkage";
break;
304 Out <<
"GlobalValue::DLLImportLinkage";
break;
306 Out <<
"GlobalValue::DLLExportLinkage";
break;
308 Out <<
"GlobalValue::ExternalWeakLinkage";
break;
310 Out <<
"GlobalValue::CommonLinkage";
break;
317 Out <<
"GlobalValue::DefaultVisibility";
320 Out <<
"GlobalValue::HiddenVisibility";
323 Out <<
"GlobalValue::ProtectedVisibility";
331 Out <<
"GlobalVariable::NotThreadLocal";
334 Out <<
"GlobalVariable::GeneralDynamicTLSModel";
337 Out <<
"GlobalVariable::LocalDynamicTLSModel";
340 Out <<
"GlobalVariable::InitialExecTLSModel";
343 Out <<
"GlobalVariable::LocalExecTLSModel";
350 void CppWriter::printEscapedString(
const std::string &Str) {
351 for (
unsigned i = 0, e = Str.size(); i != e; ++i) {
352 unsigned char C = Str[i];
353 if (isprint(C) && C !=
'"' && C !=
'\\') {
357 << (char) ((C/16 < 10) ? ( C/16 +
'0') : ( C/16 -10+
'A'))
358 << (
char)(((C&15) < 10) ? ((C&15)+
'0') : ((C&15)-10+
'A'));
363 std::string CppWriter::getCppName(
Type* Ty) {
369 unsigned BitWidth = cast<IntegerType>(Ty)->
getBitWidth();
370 return "IntegerType::get(mod->getContext(), " +
utostr(BitWidth) +
")";
378 error(
"Invalid primitive type");
382 return "Type::getVoidTy(mod->getContext())";
386 TypeMap::iterator
I = TypeNames.find(Ty);
387 if (I != TypeNames.end())
391 const char* prefix = 0;
398 default: prefix =
"OtherTy_";
break;
403 if (
StructType *STy = dyn_cast<StructType>(Ty))
405 name = STy->getName();
408 name =
utostr(uniqueNum++);
410 name = std::string(prefix) + name;
414 return TypeNames[Ty] = name;
417 void CppWriter::printCppName(
Type* Ty) {
418 printEscapedString(getCppName(Ty));
421 std::string CppWriter::getCppName(
const Value* val) {
424 if (I != ValueNames.end() && I->
first == val)
428 name = std::string(
"gvar_") +
430 }
else if (isa<Function>(val)) {
431 name = std::string(
"func_");
432 }
else if (
const Constant* C = dyn_cast<Constant>(val)) {
434 }
else if (
const Argument* Arg = dyn_cast<Argument>(val)) {
436 unsigned argNum = std::distance(Arg->getParent()->arg_begin(),
438 name = std::string(
"arg_") +
utostr(argNum);
439 NameSet::iterator NI = UsedNames.find(name);
440 if (NI != UsedNames.end())
441 name += std::string(
"_") +
utostr(uniqueNum++);
442 UsedNames.insert(name);
443 return ValueNames[val] = name;
453 name +=
utostr(uniqueNum++);
455 NameSet::iterator NI = UsedNames.find(name);
456 if (NI != UsedNames.end())
457 name += std::string(
"_") +
utostr(uniqueNum++);
458 UsedNames.insert(name);
459 return ValueNames[val] = name;
462 void CppWriter::printCppName(
const Value* val) {
463 printEscapedString(getCppName(val));
466 void CppWriter::printAttributes(
const AttributeSet &PAL,
467 const std::string &name) {
468 Out <<
"AttributeSet " << name <<
"_PAL;";
471 Out <<
'{'; in(); nl(Out);
472 Out <<
"SmallVector<AttributeSet, 4> Attrs;"; nl(Out);
473 Out <<
"AttributeSet PAS;"; in(); nl(Out);
477 Out <<
"{"; in(); nl(Out);
478 Out <<
"AttrBuilder B;"; nl(Out);
480 #define HANDLE_ATTR(X) \
481 if (attrs.contains(Attribute::X)) { \
482 Out << "B.addAttribute(Attribute::" #X ");"; nl(Out); \
483 attrs.removeAttribute(Attribute::X); \
516 Out <<
"B.addStackAlignmentAttr(" << attrs.getStackAlignment()<<
')';
521 Out <<
"PAS = AttributeSet::get(mod->getContext(), ";
525 Out << index <<
"U,";
526 Out <<
" B);"; out(); nl(Out);
527 Out <<
"}"; out(); nl(Out);
529 Out <<
"Attrs.push_back(PAS);"; nl(Out);
531 Out << name <<
"_PAL = AttributeSet::get(mod->getContext(), Attrs);";
538 void CppWriter::printType(
Type* Ty) {
544 if (DefinedTypes.find(Ty) != DefinedTypes.end())
548 std::string typeName(getCppName(Ty));
554 Out <<
"std::vector<Type*>" << typeName <<
"_args;";
558 for (; PI != PE; ++PI) {
559 Type* argTy =
static_cast<Type*
>(*PI);
561 std::string argName(getCppName(argTy));
562 Out << typeName <<
"_args.push_back(" << argName;
568 Out <<
"FunctionType* " << typeName <<
" = FunctionType::get(";
569 in(); nl(Out) <<
"/*Result=*/" << retTypeName;
571 nl(Out) <<
"/*Params=*/" << typeName <<
"_args,";
572 nl(Out) <<
"/*isVarArg=*/" << (FT->
isVarArg() ?
"true" :
"false") <<
");";
580 Out <<
"StructType *" << typeName <<
" = mod->getTypeByName(\"";
581 printEscapedString(ST->
getName());
584 Out <<
"if (!" << typeName <<
") {";
586 Out << typeName <<
" = ";
587 Out <<
"StructType::create(mod->getContext(), \"";
588 printEscapedString(ST->
getName());
594 DefinedTypes.insert(Ty);
597 Out <<
"std::vector<Type*>" << typeName <<
"_fields;";
601 for (; EI != EE; ++EI) {
602 Type* fieldTy =
static_cast<Type*
>(*EI);
604 std::string fieldName(getCppName(fieldTy));
605 Out << typeName <<
"_fields.push_back(" << fieldName;
611 Out <<
"StructType *" << typeName <<
" = ";
612 Out <<
"StructType::get(" <<
"mod->getContext(), ";
614 Out <<
"if (" << typeName <<
"->isOpaque()) {";
616 Out << typeName <<
"->setBody(";
619 Out << typeName <<
"_fields, /*isPacked=*/"
620 << (ST->
isPacked() ?
"true" :
"false") <<
");";
632 if (DefinedTypes.find(Ty) == DefinedTypes.end()) {
633 std::string elemName(getCppName(ET));
634 Out <<
"ArrayType* " << typeName <<
" = ArrayType::get("
645 if (DefinedTypes.find(Ty) == DefinedTypes.end()) {
646 std::string elemName(getCppName(ET));
647 Out <<
"PointerType* " << typeName <<
" = PointerType::get("
658 if (DefinedTypes.find(Ty) == DefinedTypes.end()) {
659 std::string elemName(getCppName(ET));
660 Out <<
"VectorType* " << typeName <<
" = VectorType::get("
668 error(
"Invalid TypeID");
672 DefinedTypes.insert(Ty);
678 void CppWriter::printTypes(
const Module* M) {
681 E = TheModule->global_end(); I != E; ++
I) {
682 if (I->hasInitializer())
683 printType(I->getInitializer()->getType());
684 printType(I->getType());
690 printType(FI->getReturnType());
691 printType(FI->getFunctionType());
694 AE = FI->arg_end(); AI != AE; ++AI) {
695 printType(AI->getType());
700 E = FI->end(); BB != E; ++BB) {
701 printType(BB->getType());
704 printType(I->getType());
705 for (
unsigned i = 0; i < I->getNumOperands(); ++i)
706 printType(I->getOperand(i)->getType());
714 void CppWriter::printConstant(
const Constant *CV) {
718 if (isa<GlobalValue>(CV) || ValueNames.find(CV) != ValueNames.end())
721 std::string constName(getCppName(CV));
722 std::string typeName(getCppName(CV->
getType()));
724 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
725 std::string constValue = CI->getValue().toString(10,
true);
726 Out <<
"ConstantInt* " << constName
727 <<
" = ConstantInt::get(mod->getContext(), APInt("
729 <<
", StringRef(\"" << constValue <<
"\"), 10));";
730 }
else if (isa<ConstantAggregateZero>(CV)) {
731 Out <<
"ConstantAggregateZero* " << constName
732 <<
" = ConstantAggregateZero::get(" << typeName <<
");";
733 }
else if (isa<ConstantPointerNull>(CV)) {
734 Out <<
"ConstantPointerNull* " << constName
735 <<
" = ConstantPointerNull::get(" << typeName <<
");";
736 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
737 Out <<
"ConstantFP* " << constName <<
" = ";
740 }
else if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
741 Out <<
"std::vector<Constant*> " << constName <<
"_elems;";
743 unsigned N = CA->getNumOperands();
744 for (
unsigned i = 0; i <
N; ++i) {
745 printConstant(CA->getOperand(i));
746 Out << constName <<
"_elems.push_back("
747 << getCppName(CA->getOperand(i)) <<
");";
750 Out <<
"Constant* " << constName <<
" = ConstantArray::get("
751 << typeName <<
", " << constName <<
"_elems);";
752 }
else if (
const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {
753 Out <<
"std::vector<Constant*> " << constName <<
"_fields;";
755 unsigned N = CS->getNumOperands();
756 for (
unsigned i = 0; i <
N; i++) {
757 printConstant(CS->getOperand(i));
758 Out << constName <<
"_fields.push_back("
759 << getCppName(CS->getOperand(i)) <<
");";
762 Out <<
"Constant* " << constName <<
" = ConstantStruct::get("
763 << typeName <<
", " << constName <<
"_fields);";
764 }
else if (
const ConstantVector *CVec = dyn_cast<ConstantVector>(CV)) {
765 Out <<
"std::vector<Constant*> " << constName <<
"_elems;";
767 unsigned N = CVec->getNumOperands();
768 for (
unsigned i = 0; i <
N; ++i) {
769 printConstant(CVec->getOperand(i));
770 Out << constName <<
"_elems.push_back("
771 << getCppName(CVec->getOperand(i)) <<
");";
774 Out <<
"Constant* " << constName <<
" = ConstantVector::get("
775 << typeName <<
", " << constName <<
"_elems);";
776 }
else if (isa<UndefValue>(CV)) {
777 Out <<
"UndefValue* " << constName <<
" = UndefValue::get("
780 dyn_cast<ConstantDataSequential>(CV)) {
781 if (CDS->isString()) {
782 Out <<
"Constant *" << constName <<
783 " = ConstantDataArray::getString(mod->getContext(), \"";
785 bool nullTerminate =
false;
786 if (Str.
back() == 0) {
788 nullTerminate =
true;
790 printEscapedString(Str);
795 Out <<
"\", false);";
798 Out <<
"std::vector<Constant*> " << constName <<
"_elems;";
800 for (
unsigned i = 0; i != CDS->getNumElements(); ++i) {
801 Constant *Elt = CDS->getElementAsConstant(i);
803 Out << constName <<
"_elems.push_back(" << getCppName(Elt) <<
");";
806 Out <<
"Constant* " << constName;
808 if (isa<ArrayType>(CDS->getType()))
809 Out <<
" = ConstantArray::get(";
811 Out <<
" = ConstantVector::get(";
812 Out << typeName <<
", " << constName <<
"_elems);";
814 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
815 if (CE->getOpcode() == Instruction::GetElementPtr) {
816 Out <<
"std::vector<Constant*> " << constName <<
"_indices;";
818 printConstant(CE->getOperand(0));
819 for (
unsigned i = 1; i < CE->getNumOperands(); ++i ) {
820 printConstant(CE->getOperand(i));
821 Out << constName <<
"_indices.push_back("
822 << getCppName(CE->getOperand(i)) <<
");";
825 Out <<
"Constant* " << constName
826 <<
" = ConstantExpr::getGetElementPtr("
827 << getCppName(CE->getOperand(0)) <<
", "
828 << constName <<
"_indices);";
829 }
else if (CE->isCast()) {
830 printConstant(CE->getOperand(0));
831 Out <<
"Constant* " << constName <<
" = ConstantExpr::getCast(";
832 switch (CE->getOpcode()) {
834 case Instruction::Trunc: Out <<
"Instruction::Trunc";
break;
835 case Instruction::ZExt: Out <<
"Instruction::ZExt";
break;
836 case Instruction::SExt: Out <<
"Instruction::SExt";
break;
837 case Instruction::FPTrunc: Out <<
"Instruction::FPTrunc";
break;
838 case Instruction::FPExt: Out <<
"Instruction::FPExt";
break;
839 case Instruction::FPToUI: Out <<
"Instruction::FPToUI";
break;
840 case Instruction::FPToSI: Out <<
"Instruction::FPToSI";
break;
841 case Instruction::UIToFP: Out <<
"Instruction::UIToFP";
break;
842 case Instruction::SIToFP: Out <<
"Instruction::SIToFP";
break;
843 case Instruction::PtrToInt: Out <<
"Instruction::PtrToInt";
break;
844 case Instruction::IntToPtr: Out <<
"Instruction::IntToPtr";
break;
845 case Instruction::BitCast: Out <<
"Instruction::BitCast";
break;
847 Out <<
", " << getCppName(CE->getOperand(0)) <<
", "
848 << getCppName(CE->getType()) <<
");";
850 unsigned N = CE->getNumOperands();
851 for (
unsigned i = 0; i <
N; ++i ) {
852 printConstant(CE->getOperand(i));
854 Out <<
"Constant* " << constName <<
" = ConstantExpr::";
855 switch (CE->getOpcode()) {
856 case Instruction::Add: Out <<
"getAdd(";
break;
857 case Instruction::FAdd: Out <<
"getFAdd(";
break;
858 case Instruction::Sub: Out <<
"getSub(";
break;
859 case Instruction::FSub: Out <<
"getFSub(";
break;
860 case Instruction::Mul: Out <<
"getMul(";
break;
861 case Instruction::FMul: Out <<
"getFMul(";
break;
862 case Instruction::UDiv: Out <<
"getUDiv(";
break;
863 case Instruction::SDiv: Out <<
"getSDiv(";
break;
864 case Instruction::FDiv: Out <<
"getFDiv(";
break;
865 case Instruction::URem: Out <<
"getURem(";
break;
866 case Instruction::SRem: Out <<
"getSRem(";
break;
867 case Instruction::FRem: Out <<
"getFRem(";
break;
871 case Instruction::ICmp:
872 Out <<
"getICmp(ICmpInst::ICMP_";
873 switch (CE->getPredicate()) {
884 default: error(
"Invalid ICmp Predicate");
887 case Instruction::FCmp:
888 Out <<
"getFCmp(FCmpInst::FCMP_";
889 switch (CE->getPredicate()) {
906 default: error(
"Invalid FCmp Predicate");
909 case Instruction::Shl: Out <<
"getShl(";
break;
910 case Instruction::LShr: Out <<
"getLShr(";
break;
911 case Instruction::AShr: Out <<
"getAShr(";
break;
914 case Instruction::InsertElement: Out <<
"getInsertElement(";
break;
915 case Instruction::ShuffleVector: Out <<
"getShuffleVector(";
break;
917 error(
"Invalid constant expression");
920 Out << getCppName(CE->getOperand(0));
921 for (
unsigned i = 1; i < CE->getNumOperands(); ++i)
922 Out <<
", " << getCppName(CE->getOperand(i));
925 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
926 Out <<
"Constant* " << constName <<
" = ";
927 Out <<
"BlockAddress::get(" << getOpName(BA->getBasicBlock()) <<
");";
929 error(
"Bad Constant");
930 Out <<
"Constant* " << constName <<
" = 0; ";
935 void CppWriter::printConstants(
const Module* M) {
938 E = TheModule->global_end(); I != E; ++
I)
939 if (I->hasInitializer())
940 printConstant(I->getInitializer());
947 E = FI->end(); BB != E; ++BB) {
950 for (
unsigned i = 0; i < I->getNumOperands(); ++i) {
951 if (
Constant* C = dyn_cast<Constant>(I->getOperand(i))) {
961 nl(Out) <<
"// Type Definitions";
967 if (
const Function *
F = dyn_cast<Function>(Init)) {
968 nl(Out)<<
"/ Function Declarations"; nl(Out);
969 printFunctionHead(
F);
970 }
else if (
const GlobalVariable* gv = dyn_cast<GlobalVariable>(Init)) {
971 nl(Out) <<
"// Global Variable Declarations"; nl(Out);
972 printVariableHead(gv);
974 nl(Out) <<
"// Global Variable Definitions"; nl(Out);
975 printVariableBody(gv);
977 nl(Out) <<
"// Constant Definitions"; nl(Out);
984 nl(Out) <<
"GlobalVariable* " << getCppName(GV);
986 Out <<
" = mod->getGlobalVariable(mod->getContext(), ";
987 printEscapedString(GV->
getName());
989 nl(Out) <<
"if (!" << getCppName(GV) <<
") {";
990 in(); nl(Out) << getCppName(GV);
992 Out <<
" = new GlobalVariable(/*Module=*/*mod, ";
993 nl(Out) <<
"/*Type=*/";
996 nl(Out) <<
"/*isConstant=*/" << (GV->
isConstant()?
"true":
"false");
998 nl(Out) <<
"/*Linkage=*/";
1001 nl(Out) <<
"/*Initializer=*/0, ";
1003 Out <<
"// has initializer, specified below";
1005 nl(Out) <<
"/*Name=*/\"";
1006 printEscapedString(GV->
getName());
1012 Out <<
"->setSection(\"";
1024 Out <<
"->setVisibility(";
1031 Out <<
"->setThreadLocalMode(";
1037 out(); Out <<
"}"; nl(Out);
1044 Out <<
"->setInitializer(";
1050 std::string CppWriter::getOpName(
const Value* V) {
1051 if (!isa<Instruction>(V) || DefinedValues.find(V) != DefinedValues.end())
1052 return getCppName(V);
1056 ForwardRefMap::const_iterator I = ForwardRefs.find(V);
1057 if (I != ForwardRefs.end())
1061 std::string result(std::string(
"fwdref_") +
utostr(uniqueNum++));
1066 Out <<
"Argument* " << result <<
" = new Argument("
1067 << getCppName(V->
getType()) <<
");";
1069 ForwardRefs[V] = result;
1078 case Acquire:
return "Acquire";
1079 case Release:
return "Release";
1087 switch (SynchScope) {
1095 void CppWriter::printInstruction(
const Instruction *I,
1096 const std::string& bbname) {
1097 std::string iName(getCppName(I));
1102 std::string* opNames =
new std::string[Ops];
1103 for (
unsigned i = 0; i < Ops; i++)
1108 error(
"Invalid instruction");
1113 Out <<
"ReturnInst::Create(mod->getContext(), "
1114 << (ret->
getReturnValue() ? opNames[0] +
", " :
"") << bbname <<
");";
1117 case Instruction::Br: {
1119 Out <<
"BranchInst::Create(" ;
1121 Out << opNames[2] <<
", "
1122 << opNames[1] <<
", "
1123 << opNames[0] <<
", ";
1126 Out << opNames[0] <<
", ";
1128 error(
"Branch with 2 operands?");
1130 Out << bbname <<
");";
1133 case Instruction::Switch: {
1135 Out <<
"SwitchInst* " << iName <<
" = SwitchInst::Create("
1144 Out << iName <<
"->addCase("
1145 << getOpName(CaseVal) <<
", "
1146 << getOpName(BB) <<
");";
1151 case Instruction::IndirectBr: {
1153 Out <<
"IndirectBrInst *" << iName <<
" = IndirectBrInst::Create("
1157 Out << iName <<
"->addDestination(" << opNames[i] <<
");";
1162 case Instruction::Resume: {
1163 Out <<
"ResumeInst::Create(" << opNames[0] <<
", " << bbname <<
");";
1166 case Instruction::Invoke: {
1168 Out <<
"std::vector<Value*> " << iName <<
"_params;";
1171 Out << iName <<
"_params.push_back("
1176 Out <<
"InvokeInst *" << iName <<
" = InvokeInst::Create("
1180 << iName <<
"_params, \"";
1181 printEscapedString(inv->
getName());
1182 Out <<
"\", " << bbname <<
");";
1183 nl(Out) << iName <<
"->setCallingConv(";
1187 Out << iName <<
"->setAttributes(" << iName <<
"_PAL);";
1191 case Instruction::Unreachable: {
1192 Out <<
"new UnreachableInst("
1193 <<
"mod->getContext(), "
1197 case Instruction::Add:
1198 case Instruction::FAdd:
1199 case Instruction::Sub:
1200 case Instruction::FSub:
1201 case Instruction::Mul:
1202 case Instruction::FMul:
1203 case Instruction::UDiv:
1204 case Instruction::SDiv:
1205 case Instruction::FDiv:
1206 case Instruction::URem:
1207 case Instruction::SRem:
1208 case Instruction::FRem:
1212 case Instruction::Shl:
1213 case Instruction::LShr:
1214 case Instruction::AShr:{
1215 Out <<
"BinaryOperator* " << iName <<
" = BinaryOperator::Create(";
1217 case Instruction::Add: Out <<
"Instruction::Add";
break;
1218 case Instruction::FAdd: Out <<
"Instruction::FAdd";
break;
1219 case Instruction::Sub: Out <<
"Instruction::Sub";
break;
1220 case Instruction::FSub: Out <<
"Instruction::FSub";
break;
1221 case Instruction::Mul: Out <<
"Instruction::Mul";
break;
1222 case Instruction::FMul: Out <<
"Instruction::FMul";
break;
1223 case Instruction::UDiv:Out <<
"Instruction::UDiv";
break;
1224 case Instruction::SDiv:Out <<
"Instruction::SDiv";
break;
1225 case Instruction::FDiv:Out <<
"Instruction::FDiv";
break;
1226 case Instruction::URem:Out <<
"Instruction::URem";
break;
1227 case Instruction::SRem:Out <<
"Instruction::SRem";
break;
1228 case Instruction::FRem:Out <<
"Instruction::FRem";
break;
1232 case Instruction::Shl: Out <<
"Instruction::Shl";
break;
1233 case Instruction::LShr:Out <<
"Instruction::LShr";
break;
1234 case Instruction::AShr:Out <<
"Instruction::AShr";
break;
1235 default: Out <<
"Instruction::BadOpCode";
break;
1237 Out <<
", " << opNames[0] <<
", " << opNames[1] <<
", \"";
1238 printEscapedString(I->
getName());
1239 Out <<
"\", " << bbname <<
");";
1242 case Instruction::FCmp: {
1243 Out <<
"FCmpInst* " << iName <<
" = new FCmpInst(*" << bbname <<
", ";
1244 switch (cast<FCmpInst>(I)->getPredicate()) {
1261 default: Out <<
"FCmpInst::BAD_ICMP_PREDICATE";
break;
1263 Out <<
", " << opNames[0] <<
", " << opNames[1] <<
", \"";
1264 printEscapedString(I->
getName());
1268 case Instruction::ICmp: {
1269 Out <<
"ICmpInst* " << iName <<
" = new ICmpInst(*" << bbname <<
", ";
1270 switch (cast<ICmpInst>(I)->getPredicate()) {
1281 default: Out <<
"ICmpInst::BAD_ICMP_PREDICATE";
break;
1283 Out <<
", " << opNames[0] <<
", " << opNames[1] <<
", \"";
1284 printEscapedString(I->
getName());
1288 case Instruction::Alloca: {
1290 Out <<
"AllocaInst* " << iName <<
" = new AllocaInst("
1293 Out << opNames[0] <<
", ";
1295 printEscapedString(allocaI->
getName());
1296 Out <<
"\", " << bbname <<
");";
1298 nl(Out) << iName <<
"->setAlignment("
1303 const LoadInst* load = cast<LoadInst>(
I);
1304 Out <<
"LoadInst* " << iName <<
" = new LoadInst("
1305 << opNames[0] <<
", \"";
1306 printEscapedString(load->
getName());
1307 Out <<
"\", " << (load->
isVolatile() ?
"true" :
"false" )
1308 <<
", " << bbname <<
");";
1310 nl(Out) << iName <<
"->setAlignment("
1315 nl(Out) << iName <<
"->setAtomic("
1316 << Ordering <<
", " << CrossThread <<
");";
1322 Out <<
"StoreInst* " << iName <<
" = new StoreInst("
1323 << opNames[0] <<
", "
1324 << opNames[1] <<
", "
1326 <<
", " << bbname <<
");";
1328 nl(Out) << iName <<
"->setAlignment("
1333 nl(Out) << iName <<
"->setAtomic("
1334 << Ordering <<
", " << CrossThread <<
");";
1338 case Instruction::GetElementPtr: {
1341 Out <<
"GetElementPtrInst* " << iName <<
" = GetElementPtrInst::Create("
1344 Out <<
", " << opNames[1];
1346 Out <<
"std::vector<Value*> " << iName <<
"_indices;";
1349 Out << iName <<
"_indices.push_back("
1350 << opNames[i] <<
");";
1353 Out <<
"Instruction* " << iName <<
" = GetElementPtrInst::Create("
1354 << opNames[0] <<
", " << iName <<
"_indices";
1357 printEscapedString(gep->
getName());
1358 Out <<
"\", " << bbname <<
");";
1362 const PHINode* phi = cast<PHINode>(
I);
1364 Out <<
"PHINode* " << iName <<
" = PHINode::Create("
1365 << getCppName(phi->
getType()) <<
", "
1367 printEscapedString(phi->
getName());
1368 Out <<
"\", " << bbname <<
");";
1371 Out << iName <<
"->addIncoming("
1378 case Instruction::Trunc:
1379 case Instruction::ZExt:
1380 case Instruction::SExt:
1381 case Instruction::FPTrunc:
1382 case Instruction::FPExt:
1383 case Instruction::FPToUI:
1384 case Instruction::FPToSI:
1385 case Instruction::UIToFP:
1386 case Instruction::SIToFP:
1387 case Instruction::PtrToInt:
1388 case Instruction::IntToPtr:
1389 case Instruction::BitCast: {
1390 const CastInst* cst = cast<CastInst>(
I);
1391 Out <<
"CastInst* " << iName <<
" = new ";
1393 case Instruction::Trunc: Out <<
"TruncInst";
break;
1394 case Instruction::ZExt: Out <<
"ZExtInst";
break;
1395 case Instruction::SExt: Out <<
"SExtInst";
break;
1396 case Instruction::FPTrunc: Out <<
"FPTruncInst";
break;
1397 case Instruction::FPExt: Out <<
"FPExtInst";
break;
1398 case Instruction::FPToUI: Out <<
"FPToUIInst";
break;
1399 case Instruction::FPToSI: Out <<
"FPToSIInst";
break;
1400 case Instruction::UIToFP: Out <<
"UIToFPInst";
break;
1401 case Instruction::SIToFP: Out <<
"SIToFPInst";
break;
1402 case Instruction::PtrToInt: Out <<
"PtrToIntInst";
break;
1403 case Instruction::IntToPtr: Out <<
"IntToPtrInst";
break;
1404 case Instruction::BitCast: Out <<
"BitCastInst";
break;
1407 Out <<
"(" << opNames[0] <<
", "
1408 << getCppName(cst->
getType()) <<
", \"";
1409 printEscapedString(cst->
getName());
1410 Out <<
"\", " << bbname <<
");";
1414 const CallInst* call = cast<CallInst>(
I);
1416 Out <<
"InlineAsm* " << getCppName(ila) <<
" = InlineAsm::get("
1417 << getCppName(ila->getFunctionType()) <<
", \""
1418 << ila->getAsmString() <<
"\", \""
1419 << ila->getConstraintString() <<
"\","
1420 << (ila->hasSideEffects() ?
"true" :
"false") <<
");";
1424 Out <<
"std::vector<Value*> " << iName <<
"_params;";
1427 Out << iName <<
"_params.push_back(" << opNames[i] <<
");";
1430 Out <<
"CallInst* " << iName <<
" = CallInst::Create("
1432 << iName <<
"_params, \"";
1434 Out <<
"CallInst* " << iName <<
" = CallInst::Create("
1437 Out <<
"CallInst* " << iName <<
" = CallInst::Create("
1440 printEscapedString(call->
getName());
1441 Out <<
"\", " << bbname <<
");";
1442 nl(Out) << iName <<
"->setCallingConv(";
1445 nl(Out) << iName <<
"->setTailCall("
1450 Out << iName <<
"->setAttributes(" << iName <<
"_PAL);";
1456 Out <<
"SelectInst* " << getCppName(sel) <<
" = SelectInst::Create(";
1457 Out << opNames[0] <<
", " << opNames[1] <<
", " << opNames[2] <<
", \"";
1458 printEscapedString(sel->
getName());
1459 Out <<
"\", " << bbname <<
");";
1462 case Instruction::UserOp1:
1464 case Instruction::UserOp2: {
1468 case Instruction::VAArg: {
1470 Out <<
"VAArgInst* " << getCppName(va) <<
" = new VAArgInst("
1471 << opNames[0] <<
", " << getCppName(va->
getType()) <<
", \"";
1472 printEscapedString(va->
getName());
1473 Out <<
"\", " << bbname <<
");";
1478 Out <<
"ExtractElementInst* " << getCppName(eei)
1479 <<
" = new ExtractElementInst(" << opNames[0]
1480 <<
", " << opNames[1] <<
", \"";
1481 printEscapedString(eei->
getName());
1482 Out <<
"\", " << bbname <<
");";
1485 case Instruction::InsertElement: {
1487 Out <<
"InsertElementInst* " << getCppName(iei)
1488 <<
" = InsertElementInst::Create(" << opNames[0]
1489 <<
", " << opNames[1] <<
", " << opNames[2] <<
", \"";
1490 printEscapedString(iei->
getName());
1491 Out <<
"\", " << bbname <<
");";
1494 case Instruction::ShuffleVector: {
1496 Out <<
"ShuffleVectorInst* " << getCppName(svi)
1497 <<
" = new ShuffleVectorInst(" << opNames[0]
1498 <<
", " << opNames[1] <<
", " << opNames[2] <<
", \"";
1499 printEscapedString(svi->
getName());
1500 Out <<
"\", " << bbname <<
");";
1503 case Instruction::ExtractValue: {
1505 Out <<
"std::vector<unsigned> " << iName <<
"_indices;";
1508 Out << iName <<
"_indices.push_back("
1512 Out <<
"ExtractValueInst* " << getCppName(evi)
1513 <<
" = ExtractValueInst::Create(" << opNames[0]
1515 << iName <<
"_indices, \"";
1516 printEscapedString(evi->
getName());
1517 Out <<
"\", " << bbname <<
");";
1520 case Instruction::InsertValue: {
1522 Out <<
"std::vector<unsigned> " << iName <<
"_indices;";
1525 Out << iName <<
"_indices.push_back("
1529 Out <<
"InsertValueInst* " << getCppName(ivi)
1530 <<
" = InsertValueInst::Create(" << opNames[0]
1531 <<
", " << opNames[1] <<
", "
1532 << iName <<
"_indices, \"";
1533 printEscapedString(ivi->
getName());
1534 Out <<
"\", " << bbname <<
");";
1537 case Instruction::Fence: {
1541 Out <<
"FenceInst* " << iName
1542 <<
" = new FenceInst(mod->getContext(), "
1543 << Ordering <<
", " << CrossThread <<
", " << bbname
1547 case Instruction::AtomicCmpXchg: {
1551 Out <<
"AtomicCmpXchgInst* " << iName
1552 <<
" = new AtomicCmpXchgInst("
1553 << opNames[0] <<
", " << opNames[1] <<
", " << opNames[2] <<
", "
1554 << Ordering <<
", " << CrossThread <<
", " << bbname
1556 nl(Out) << iName <<
"->setName(\"";
1557 printEscapedString(cxi->
getName());
1561 case Instruction::AtomicRMW: {
1580 Out <<
"AtomicRMWInst* " << iName
1581 <<
" = new AtomicRMWInst("
1582 << Operation <<
", "
1583 << opNames[0] <<
", " << opNames[1] <<
", "
1584 << Ordering <<
", " << CrossThread <<
", " << bbname
1586 nl(Out) << iName <<
"->setName(\"";
1587 printEscapedString(rmwi->
getName());
1591 case Instruction::LandingPad: {
1593 Out <<
"LandingPadInst* " << iName <<
" = LandingPadInst::Create(";
1595 Out <<
", " << opNames[0] <<
", " << lpi->
getNumClauses() <<
", \"";
1596 printEscapedString(lpi->
getName());
1597 Out <<
"\", " << bbname <<
");";
1598 nl(Out) << iName <<
"->setCleanup("
1599 << (lpi->
isCleanup() ?
"true" :
"false")
1602 nl(Out) << iName <<
"->addClause(" << opNames[i+1] <<
");";
1606 DefinedValues.insert(I);
1612 void CppWriter::printFunctionUses(
const Function*
F) {
1613 nl(Out) <<
"// Type Definitions"; nl(Out);
1624 printType(AI->getType());
1642 printType(operand->
getType());
1645 if (
GlobalValue* GV = dyn_cast<GlobalValue>(operand)) {
1649 if (GVar->hasInitializer())
1650 consts.
insert(GVar->getInitializer());
1651 }
else if (
Constant* C = dyn_cast<Constant>(operand)) {
1653 for (
unsigned j = 0; j < C->getNumOperands(); ++j) {
1655 Value* operand = C->getOperand(j);
1656 printType(operand->
getType());
1657 if (
GlobalValue* GV = dyn_cast<GlobalValue>(operand)) {
1661 if (GVar->hasInitializer())
1662 consts.
insert(GVar->getInitializer());
1671 nl(Out) <<
"// Function Declarations"; nl(Out);
1674 if (
Function* Fun = dyn_cast<Function>(*I)) {
1675 if (!is_inline || Fun != F)
1676 printFunctionHead(Fun);
1681 nl(Out) <<
"// Global Variable Declarations"; nl(Out);
1685 printVariableHead(F);
1689 nl(Out) <<
"// Constant Definitions"; nl(Out);
1691 E = consts.
end(); I != E; ++
I) {
1699 nl(Out) <<
"// Global Variable Definitions"; nl(Out);
1703 printVariableBody(GV);
1708 void CppWriter::printFunctionHead(
const Function* F) {
1709 nl(Out) <<
"Function* " << getCppName(F);
1710 Out <<
" = mod->getFunction(\"";
1711 printEscapedString(F->
getName());
1713 nl(Out) <<
"if (!" << getCppName(F) <<
") {";
1714 nl(Out) << getCppName(F);
1716 Out<<
" = Function::Create(";
1718 nl(Out) <<
"/*Linkage=*/";
1721 nl(Out) <<
"/*Name=*/\"";
1722 printEscapedString(F->
getName());
1723 Out <<
"\", mod); " << (F->
isDeclaration()?
"// (external, no body)" :
"");
1726 Out <<
"->setCallingConv(";
1732 Out <<
"->setSection(\"" << F->
getSection() <<
"\");";
1742 Out <<
"->setVisibility(";
1749 Out <<
"->setGC(\"" << F->
getGC() <<
"\");";
1756 Out <<
"->setAttributes(" << getCppName(F) <<
"_PAL);";
1760 void CppWriter::printFunctionBody(
const Function *F) {
1766 ForwardRefs.clear();
1767 DefinedValues.clear();
1772 Out <<
"Function::arg_iterator args = " << getCppName(F)
1773 <<
"->arg_begin();";
1778 Out <<
"Value* " << getCppName(AI) <<
" = args++;";
1780 if (AI->hasName()) {
1781 Out << getCppName(AI) <<
"->setName(\"";
1782 printEscapedString(AI->getName());
1793 std::string bbname(getCppName(BI));
1794 Out <<
"BasicBlock* " << bbname <<
1795 " = BasicBlock::Create(mod->getContext(), \"";
1797 printEscapedString(BI->getName());
1798 Out <<
"\"," << getCppName(BI->getParent()) <<
",0);";
1805 std::string bbname(getCppName(BI));
1806 nl(Out) <<
"// Block " << BI->getName() <<
" (" << bbname <<
")";
1812 printInstruction(I,bbname);
1818 if (!ForwardRefs.empty()) {
1819 nl(Out) <<
"// Resolve Forward References";
1823 while (!ForwardRefs.empty()) {
1824 ForwardRefMap::iterator I = ForwardRefs.begin();
1825 Out << I->second <<
"->replaceAllUsesWith("
1826 << getCppName(I->first) <<
"); delete " << I->second <<
";";
1828 ForwardRefs.erase(I);
1832 void CppWriter::printInline(
const std::string& fname,
1833 const std::string& func) {
1834 const Function* F = TheModule->getFunction(func);
1836 error(std::string(
"Function '") + func +
"' not found in input module");
1840 error(std::string(
"Function '") + func +
"' is external!");
1843 nl(Out) <<
"BasicBlock* " << fname <<
"(Module* mod, Function *"
1845 unsigned arg_count = 1;
1848 Out <<
", Value* arg_" << arg_count++;
1853 printFunctionUses(F);
1854 printFunctionBody(F);
1856 Out <<
"return " << getCppName(F->
begin()) <<
";";
1861 void CppWriter::printModuleBody() {
1863 nl(Out) <<
"// Type Definitions"; nl(Out);
1864 printTypes(TheModule);
1868 nl(Out) <<
"// Function Declarations"; nl(Out);
1871 printFunctionHead(I);
1875 nl(Out) <<
"// Global Variable Declarations\n"; nl(Out);
1877 E = TheModule->global_end(); I != E; ++
I) {
1878 printVariableHead(I);
1884 nl(Out) <<
"// Constant Definitions"; nl(Out);
1885 printConstants(TheModule);
1890 nl(Out) <<
"// Global Variable Definitions"; nl(Out);
1892 E = TheModule->global_end(); I != E; ++
I) {
1893 printVariableBody(I);
1897 nl(Out) <<
"// Function Definitions"; nl(Out);
1900 if (!I->isDeclaration()) {
1901 nl(Out) <<
"// Function: " << I->getName() <<
" (" << getCppName(I)
1905 printFunctionBody(I);
1912 void CppWriter::printProgram(
const std::string& fname,
1913 const std::string& mName) {
1914 Out <<
"#include <llvm/Pass.h>\n";
1915 Out <<
"#include <llvm/PassManager.h>\n";
1917 Out <<
"#include <llvm/ADT/SmallVector.h>\n";
1918 Out <<
"#include <llvm/Analysis/Verifier.h>\n";
1919 Out <<
"#include <llvm/Assembly/PrintModulePass.h>\n";
1920 Out <<
"#include <llvm/IR/BasicBlock.h>\n";
1921 Out <<
"#include <llvm/IR/CallingConv.h>\n";
1922 Out <<
"#include <llvm/IR/Constants.h>\n";
1923 Out <<
"#include <llvm/IR/DerivedTypes.h>\n";
1924 Out <<
"#include <llvm/IR/Function.h>\n";
1925 Out <<
"#include <llvm/IR/GlobalVariable.h>\n";
1926 Out <<
"#include <llvm/IR/InlineAsm.h>\n";
1927 Out <<
"#include <llvm/IR/Instructions.h>\n";
1928 Out <<
"#include <llvm/IR/LLVMContext.h>\n";
1929 Out <<
"#include <llvm/IR/Module.h>\n";
1930 Out <<
"#include <llvm/Support/FormattedStream.h>\n";
1931 Out <<
"#include <llvm/Support/MathExtras.h>\n";
1932 Out <<
"#include <algorithm>\n";
1933 Out <<
"using namespace llvm;\n\n";
1934 Out <<
"Module* " << fname <<
"();\n\n";
1935 Out <<
"int main(int argc, char**argv) {\n";
1936 Out <<
" Module* Mod = " << fname <<
"();\n";
1937 Out <<
" verifyModule(*Mod, PrintMessageAction);\n";
1938 Out <<
" PassManager PM;\n";
1939 Out <<
" PM.add(createPrintModulePass(&outs()));\n";
1940 Out <<
" PM.run(*Mod);\n";
1941 Out <<
" return 0;\n";
1943 printModule(fname,mName);
1946 void CppWriter::printModule(
const std::string& fname,
1947 const std::string& mName) {
1948 nl(Out) <<
"Module* " << fname <<
"() {";
1949 nl(Out,1) <<
"// Module Construction";
1950 nl(Out) <<
"Module* mod = new Module(\"";
1951 printEscapedString(mName);
1952 Out <<
"\", getGlobalContext());";
1953 if (!TheModule->getTargetTriple().empty()) {
1954 nl(Out) <<
"mod->setDataLayout(\"" << TheModule->getDataLayout() <<
"\");";
1956 if (!TheModule->getTargetTriple().empty()) {
1957 nl(Out) <<
"mod->setTargetTriple(\"" << TheModule->getTargetTriple()
1961 if (!TheModule->getModuleInlineAsm().empty()) {
1962 nl(Out) <<
"mod->setModuleInlineAsm(\"";
1963 printEscapedString(TheModule->getModuleInlineAsm());
1969 nl(Out) <<
"return mod;";
1974 void CppWriter::printContents(
const std::string& fname,
1975 const std::string& mName) {
1976 Out <<
"\nModule* " << fname <<
"(Module *mod) {\n";
1977 Out <<
"\nmod->setModuleIdentifier(\"";
1978 printEscapedString(mName);
1981 Out <<
"\nreturn mod;\n";
1985 void CppWriter::printFunction(
const std::string& fname,
1986 const std::string& funcName) {
1987 const Function* F = TheModule->getFunction(funcName);
1989 error(std::string(
"Function '") + funcName +
"' not found in input module");
1992 Out <<
"\nFunction* " << fname <<
"(Module *mod) {\n";
1993 printFunctionUses(F);
1994 printFunctionHead(F);
1995 printFunctionBody(F);
1996 Out <<
"return " << getCppName(F) <<
";\n";
2000 void CppWriter::printFunctions() {
2005 for (; I !=
IE; ++
I) {
2008 std::string name(
"define_");
2010 printFunction(name, func.
getName());
2015 void CppWriter::printVariable(
const std::string& fname,
2016 const std::string& varName) {
2020 error(std::string(
"Variable '") + varName +
"' not found in input module");
2023 Out <<
"\nGlobalVariable* " << fname <<
"(Module *mod) {\n";
2024 printVariableUses(GV);
2025 printVariableHead(GV);
2026 printVariableBody(GV);
2027 Out <<
"return " << getCppName(GV) <<
";\n";
2031 void CppWriter::printType(
const std::string &fname,
2032 const std::string &typeName) {
2033 Type* Ty = TheModule->getTypeByName(typeName);
2035 error(std::string(
"Type '") + typeName +
"' not found in input module");
2038 Out <<
"\nType* " << fname <<
"(Module *mod) {\n";
2040 Out <<
"return " << getCppName(Ty) <<
";\n";
2044 bool CppWriter::runOnModule(
Module &M) {
2048 Out <<
"// Generated by llvm2cpp - DO NOT MODIFY!\n\n";
2051 std::string fname =
FuncName.getValue();
2059 if (tgtname ==
"!bad!") {
2061 tgtname =
"<stdin>";
2065 }
else if (tgtname ==
"!bad!")
2066 error(
"You must use the -for option with -gen-{function,variable,type}");
2071 fname =
"makeLLVMModule";
2072 printProgram(fname,tgtname);
2076 fname =
"makeLLVMModule";
2077 printModule(fname,tgtname);
2081 fname =
"makeLLVMModuleContents";
2082 printContents(fname,tgtname);
2086 fname =
"makeLLVMFunction";
2087 printFunction(fname,tgtname);
2094 fname =
"makeLLVMInline";
2095 printInline(fname,tgtname);
2099 fname =
"makeLLVMVariable";
2100 printVariable(fname,tgtname);
2104 fname =
"makeLLVMType";
2105 printType(fname,tgtname);
2125 PM.add(
new CppWriter(o));
static StringRef ConvertAtomicOrdering(AtomicOrdering Ordering)
const Value * getCalledValue() const
LinkageTypes getLinkage() const
Like Private, but linker removes.
static Type * getDoubleTy(LLVMContext &C)
int sprintf(char *str, const char *format, ...);
AtomicOrdering getOrdering() const
Returns the ordering constraint on this cmpxchg.
Special purpose, only applies to global arrays.
VisibilityTypes getVisibility() const
*p = old <signed v ? old : v
LLVM Argument representation.
uint64_t getZExtValue() const
Get zero extended value.
ThreadLocalMode getThreadLocalMode() const
SynchronizationScope getSynchScope() const
bool isPrimitiveType() const
static const fltSemantics IEEEdouble
The main container class for the LLVM Intermediate Representation.
2: 32-bit floating point type
unsigned getAlignment() const
Same, but only replaced by something equivalent.
unsigned getNumOperands() const
Available for inspection, not emission.
Type::subtype_iterator param_iterator
const char * getGC() const
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
*p = old <unsigned v ? old : v
virtual bool addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out, CodeGenFileType FileType, bool DisableVerify, AnalysisID StartAfter, AnalysisID StopAfter)
0 1 0 0 True if ordered and less than
Like Internal, but omit from symbol table.
ValuesClass< DataType > END_WITH_NULL values(const char *Arg, DataType Val, const char *Desc,...)
void LLVMInitializeCppBackendTarget()
*p = old >unsigned v ? old : v
Externally visible function.
1 1 1 0 True if unordered or not equal
Type * getReturnType() const
unsigned getNumIndices() const
4: 80-bit floating point type (X87)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static std::string ftostr(const APFloat &V)
StringRef drop_back(size_t N=1) const
const Constant * getInitializer() const
*p = old >signed v ? old : v
bool bitwiseIsEqual(const APFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
CallingConv::ID getCallingConv() const
StringRef getName() const
element_iterator element_end() const
bool isArrayAllocation() const
1 0 0 1 True if unordered or equal
static std::string utohexstr(uint64_t X)
static unsigned getOperandNumForIncomingValue(unsigned i)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
Type::subtype_iterator element_iterator
static Type * getFloatTy(LLVMContext &C)
Base class of casting instructions.
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
#define llvm_unreachable(msg)
param_iterator param_end() const
unsigned getNumArgOperands() const
const Value * getCalledValue() const
0 1 0 1 True if ordered and less than or equal
double atof(const char *str);
element_iterator element_begin() const
Type * getAllocatedType() const
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
ID
LLVM Calling Convention Representation.
const std::string & getModuleIdentifier() const
SynchronizationScope getSynchScope() const
static cl::opt< WhatToGenerate > GenerationType("cppgen", cl::Optional, cl::desc("Choose what kind of output to generate"), cl::init(GenProgram), cl::values(clEnumValN(GenProgram,"program","Generate a complete program"), clEnumValN(GenModule,"module","Generate a module definition"), clEnumValN(GenContents,"contents","Generate contents of a module"), clEnumValN(GenFunction,"function","Generate a function definition"), clEnumValN(GenFunctions,"functions","Generate all function definitions"), clEnumValN(GenInline,"inline","Generate an inline function"), clEnumValN(GenVariable,"variable","Generate a variable definition"), clEnumValN(GenType,"type","Generate a type definition"), clEnumValEnd))
static void sanitize(std::string &str)
AtomicOrdering getOrdering() const
Returns the ordering constraint on this RMW.
static cl::opt< std::string > FuncName("cppfname", cl::desc("Specify the name of the generated function"), cl::value_desc("function name"))
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Function to be imported from DLL.
static std::string utostr(uint64_t X, bool isNeg=false)
double convertToDouble() const
unsigned getNumClauses() const
getNumClauses - Get the number of clauses for this landing pad.
unsigned getNumElements() const
Return the number of elements in the Vector type.
Type * getElementType() const
BasicBlock * getNormalDest() const
unsigned getNumIncomingValues() const
static cl::opt< std::string > NameToGenerate("cppfor", cl::Optional, cl::desc("Specify the name of the thing to generate"), cl::init("!bad!"))
10: Arbitrary bit width integers
ExternalWeak linkage description.
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Same, but only replaced by something equivalent.
unsigned getNumSlots() const
Return the number of slots used in this attribute list. This is the number of arguments that have an ...
initializer< Ty > init(const Ty &Val)
unsigned getAlignment() const
* if(!EatIfPresent(lltok::kw_thread_local)) return false
SynchronizationScope getSynchScope() const
LLVM Basic Block Representation.
AttributeSet getSlotAttributes(unsigned Slot) const
Return the attributes at the given slot.
LLVM Constant Representation.
Target TheCppBackendTarget
param_iterator param_begin() const
char back() const
back - Get the last character in the string.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
unsigned getAlignment() const
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
BasicBlock * getIncomingBlock(unsigned i) const
uint64_t getNumElements() const
opStatus convert(const fltSemantics &, roundingMode, bool *)
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
Function to be accessible from DLL.
1 1 1 1 Always true (always folded)
const std::string & getSection() const
LLVMContext & getContext() const
All values hold a context through their type.
1 1 0 1 True if unordered, less than, or equal
CallingConv::ID getCallingConv() const
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
0 0 1 0 True if ordered and greater than
idx_iterator idx_begin() const
BasicBlock * getUnwindDest() const
AtomicOrdering getOrdering() const
Returns the ordering effect of this store.
Class for constant integers.
15: SIMD 'packed' format, or other vector type
1 1 0 0 True if unordered or less than
Keep one copy of function when linking (inline)
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
BinOp getOperation() const
AttributeSet getAttributes() const
Return the attribute list for this Function.
SynchronizationScope getSynchScope() const
bool hasInitializer() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
StringRef getName() const
APInt bitcastToAPInt() const
Value * getCondition() const
const AttributeSet & getAttributes() const
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Like LinkerPrivate, but weak.
PointerType * getType() const
getType - Global values are always pointers.
Value * getArgOperand(unsigned i) const
static const fltSemantics IEEEsingle
const AttributeSet & getAttributes() const
BasicBlock * getDefaultDest() const
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
bool isDeclaration() const
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
unsigned greater or equal
unsigned getAlignment() const
FunctionType * getFunctionType() const
0 1 1 0 True if ordered and operands are unequal
float convertToFloat() const
cl::opt< std::string > StopAfter("stop-after", cl::desc("Stop compilation after a specific pass"), cl::value_desc("pass-name"), cl::init(""))
cl::opt< std::string > StartAfter("start-after", cl::desc("Resume compilation after a specific pass"), cl::value_desc("pass-name"), cl::init(""))
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
cl::opt< TargetMachine::CodeGenFileType > FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile), cl::desc("Choose a file type (not all types are supported by all targets):"), cl::values(clEnumValN(TargetMachine::CGFT_AssemblyFile,"asm","Emit an assembly ('.s') file"), clEnumValN(TargetMachine::CGFT_ObjectFile,"obj","Emit a native object ('.o') file"), clEnumValN(TargetMachine::CGFT_Null,"null","Emit nothing, for performance testing"), clEnumValEnd))
static std::string getTypePrefix(Type *Ty)
1 0 1 0 True if unordered or greater than
unsigned getNumCases() const
const APFloat & getValueAPF() const
bool isExactlyValue(const APFloat &V) const
3: 64-bit floating point type
Type * getReturnType() const
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
const HexagonInstrInfo bool ShouldCombineAggressively switch(MI->getOpcode())
CallingConv::ID getCallingConv() const
static StringRef ConvertAtomicSynchScope(SynchronizationScope SynchScope)
ArgumentListType::const_iterator const_arg_iterator
int strncmp(const char *s1, const char *s2, size_t n);
9: MMX vectors (64 bits, X86 specific)
0 0 1 1 True if ordered and greater than or equal
SynchronizationScope getSynchScope() const
unsigned getNumArgOperands() const
unsigned getNumDestinations() const
bool isEmpty() const
Return true if there are no attributes.
const fltSemantics & getSemantics() const
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
0 0 0 0 Always false (always folded)