"llvm/git@repo.hca.bsc.es:rferrer/llvm-epi-0.8.git" did not exist on "ca9e0e83b30ccff770e832e08ba540f1b4735a43"
Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
<< " double least significant word " << Val << '\n';
} else {
O << TAI->getData32bitsDirective() << unsigned(i)
<< '\t' << TAI->getCommentString()
<< " double least significant word " << Val << '\n';
O << TAI->getData32bitsDirective() << unsigned(i >> 32)
<< '\t' << TAI->getCommentString()
<< " double most significant word " << Val << '\n';
}
return;
} else if (CFP->getType() == Type::FloatTy) {
float Val = CFP->getValueAPF().convertToFloat(); // for comment only
O << TAI->getData32bitsDirective()
<< CFP->getValueAPF().bitcastToAPInt().getZExtValue()
<< '\t' << TAI->getCommentString() << " float " << Val << '\n';
return;
} else if (CFP->getType() == Type::X86_FP80Ty) {
// all long double variants are printed as hex
// api needed to prevent premature destruction
APInt api = CFP->getValueAPF().bitcastToAPInt();
const uint64_t *p = api.getRawData();
// Convert to double so we can print the approximate val as a comment.
APFloat DoubleVal = CFP->getValueAPF();
bool ignored;
DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
&ignored);
if (TD->isBigEndian()) {
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
<< '\t' << TAI->getCommentString()
<< " long double most significant halfword of ~"
<< DoubleVal.convertToDouble() << '\n';
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
<< '\t' << TAI->getCommentString()
<< " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
<< '\t' << TAI->getCommentString()
<< " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0])
<< '\t' << TAI->getCommentString()
<< " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[1])
<< '\t' << TAI->getCommentString()
<< " long double least significant halfword\n";
} else {
O << TAI->getData16bitsDirective() << uint16_t(p[1])
<< '\t' << TAI->getCommentString()
<< " long double least significant halfword of ~"
<< DoubleVal.convertToDouble() << '\n';
O << TAI->getData16bitsDirective() << uint16_t(p[0])
<< '\t' << TAI->getCommentString()
<< " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
<< '\t' << TAI->getCommentString()
<< " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
<< '\t' << TAI->getCommentString()
<< " long double next halfword\n";
O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
<< '\t' << TAI->getCommentString()
<< " long double most significant halfword\n";
}
EmitZeros(TD->getABITypeSize(Type::X86_FP80Ty) -
TD->getTypeStoreSize(Type::X86_FP80Ty));
return;
} else if (CFP->getType() == Type::PPC_FP128Ty) {
// all long double variants are printed as hex
// api needed to prevent premature destruction
APInt api = CFP->getValueAPF().bitcastToAPInt();
const uint64_t *p = api.getRawData();
if (TD->isBigEndian()) {
O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
<< '\t' << TAI->getCommentString()
<< " long double most significant word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[0])
<< '\t' << TAI->getCommentString()
<< " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
<< '\t' << TAI->getCommentString()
<< " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[1])
<< '\t' << TAI->getCommentString()
<< " long double least significant word\n";
} else {
O << TAI->getData32bitsDirective() << uint32_t(p[1])
<< '\t' << TAI->getCommentString()
<< " long double least significant word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
<< '\t' << TAI->getCommentString()
<< " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[0])
<< '\t' << TAI->getCommentString()
<< " long double next word\n";
O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
<< '\t' << TAI->getCommentString()
<< " long double most significant word\n";
}
return;
} else assert(0 && "Floating point constant type not handled");
}
void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI) {
const TargetData *TD = TM.getTargetData();
unsigned BitWidth = CI->getBitWidth();
assert(isPowerOf2_32(BitWidth) &&
"Non-power-of-2-sized integers not handled!");
// We don't expect assemblers to support integer data directives
// for more than 64 bits, so we emit the data in at most 64-bit
// quantities at a time.
const uint64_t *RawData = CI->getValue().getRawData();
for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
uint64_t Val;
if (TD->isBigEndian())
Val = RawData[e - i - 1];
else
Val = RawData[i];
if (TAI->getData64bitsDirective())
O << TAI->getData64bitsDirective() << Val << '\n';
else if (TD->isBigEndian()) {
O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
<< '\t' << TAI->getCommentString()
<< " Double-word most significant word " << Val << '\n';
O << TAI->getData32bitsDirective() << unsigned(Val)
<< '\t' << TAI->getCommentString()
<< " Double-word least significant word " << Val << '\n';
} else {
O << TAI->getData32bitsDirective() << unsigned(Val)
<< '\t' << TAI->getCommentString()
<< " Double-word least significant word " << Val << '\n';
O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
<< '\t' << TAI->getCommentString()
<< " Double-word most significant word " << Val << '\n';
}
}
}
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
const TargetData *TD = TM.getTargetData();
const Type *type = CV->getType();
unsigned Size = TD->getABITypeSize(type);
return;
} else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
EmitGlobalConstantArray(CVA);
return;
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
EmitGlobalConstantStruct(CVS);
return;
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
EmitGlobalConstantFP(CFP);
return;
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
// Small integers are handled below; large integers are handled here.
if (Size > 4) {
EmitGlobalConstantLargeInt(CI);
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
EmitGlobalConstantVector(CP);
return;
printDataDirective(type);
EmitConstantValueOnly(CV);
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
SmallString<40> S;
CI->getValue().toStringUnsigned(S, 16);
O << "\t\t\t" << TAI->getCommentString() << " 0x" << S.c_str();
}
O << '\n';
void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
// Target doesn't support this yet!
abort();
}
/// PrintSpecial - Print information related to the specified machine instr
/// that is independent of the operand, and may be independent of the instr
/// itself. This can be useful for portably encoding the comment character
/// or other bits of target-specific knowledge into the asmstrings. The
/// syntax used is ${:comment}. Targets can override this to add support
/// for their own strange codes.
void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) {
if (!strcmp(Code, "private")) {
O << TAI->getPrivateGlobalPrefix();
} else if (!strcmp(Code, "comment")) {
O << TAI->getCommentString();
} else if (!strcmp(Code, "uid")) {
// Assign a unique ID to this machine instruction.
static const MachineInstr *LastMI = 0;
static unsigned Counter = 0U-1;
// Comparing the address of MI isn't sufficient, because machineinstrs may
// be allocated to the same address across functions.
const Function *ThisF = MI->getParent()->getParent()->getFunction();
// If this is a new machine instruction, bump the counter.
if (LastMI != MI || F != ThisF) {
++Counter;
LastMI = MI;
F = ThisF;
O << Counter;
} else {
Bill Wendling
committed
cerr << "Unknown special formatter '" << Code
<< "' for machine instr: " << *MI;
exit(1);
}
}
/// printInlineAsm - This method formats and prints the specified machine
/// instruction that is an inline asm.
void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
unsigned NumOperands = MI->getNumOperands();
// Count the number of register definitions.
unsigned NumDefs = 0;
for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
assert(NumDefs != NumOperands-1 && "No asm string?");
assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
// Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
// If this asmstr is empty, just print the #APP/#NOAPP markers.
// These are useful to see where empty asm's wound up.
if (AsmStr[0] == 0) {
O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << '\n';
return;
}
O << TAI->getInlineAsmStart() << "\n\t";
// The variant of the current asmprinter.
int AsmPrinterVariant = TAI->getAssemblerDialect();
int CurVariant = -1; // The number of the {.|.|.} region we are in.
const char *LastEmitted = AsmStr; // One past the last character emitted.
while (*LastEmitted) {
switch (*LastEmitted) {
default: {
// Not a special case, emit the string section literally.
const char *LiteralEnd = LastEmitted+1;
while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
*LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
++LiteralEnd;
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
O.write(LastEmitted, LiteralEnd-LastEmitted);
LastEmitted = LiteralEnd;
break;
}
case '\n':
++LastEmitted; // Consume newline character.
O << '\n'; // Indent code with newline.
case '$': {
++LastEmitted; // Consume '$' character.
bool Done = true;
// Handle escapes.
switch (*LastEmitted) {
default: Done = false; break;
case '$': // $$ -> $
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
O << '$';
++LastEmitted; // Consume second '$' character.
break;
case '(': // $( -> same as GCC's { character.
++LastEmitted; // Consume '(' character.
if (CurVariant != -1) {
Bill Wendling
committed
cerr << "Nested variants found in inline asm string: '"
<< AsmStr << "'\n";
exit(1);
}
CurVariant = 0; // We're in the first variant now.
break;
case '|':
++LastEmitted; // consume '|' character.
if (CurVariant == -1)
O << '|'; // this is gcc's behavior for | outside a variant
else
++CurVariant; // We're in the next variant.
break;
case ')': // $) -> same as GCC's } char.
++LastEmitted; // consume ')' character.
if (CurVariant == -1)
O << '}'; // this is gcc's behavior for } outside a variant
else
CurVariant = -1;
break;
}
if (Done) break;
bool HasCurlyBraces = false;
if (*LastEmitted == '{') { // ${variable}
++LastEmitted; // Consume '{' character.
HasCurlyBraces = true;
}
const char *IDStart = LastEmitted;
char *IDEnd;
long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
Bill Wendling
committed
cerr << "Bad $ operand number in inline asm string: '"
<< AsmStr << "'\n";
exit(1);
}
LastEmitted = IDEnd;
char Modifier[2] = { 0, 0 };
if (HasCurlyBraces) {
// If we have curly braces, check for a modifier character. This
// supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
if (*LastEmitted == ':') {
++LastEmitted; // Consume ':' character.
if (*LastEmitted == 0) {
Bill Wendling
committed
cerr << "Bad ${:} expression in inline asm string: '"
<< AsmStr << "'\n";
exit(1);
}
Modifier[0] = *LastEmitted;
++LastEmitted; // Consume modifier character.
}
if (*LastEmitted != '}') {
Bill Wendling
committed
cerr << "Bad ${} expression in inline asm string: '"
<< AsmStr << "'\n";
exit(1);
}
++LastEmitted; // Consume '}' character.
}
if ((unsigned)Val >= NumOperands-1) {
Bill Wendling
committed
cerr << "Invalid $ operand number in inline asm string: '"
<< AsmStr << "'\n";
exit(1);
}
// Okay, we finally have a value number. Ask the target to print this
// operand!
if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
unsigned OpNo = 1;
// Scan to find the machine operand number for the operand.
for (; Val; --Val) {
if (OpNo >= MI->getNumOperands()) break;
unsigned OpFlags = MI->getOperand(OpNo).getImm();
OpNo += (OpFlags >> 3) + 1;
}
if (OpNo >= MI->getNumOperands()) {
Error = true;
unsigned OpFlags = MI->getOperand(OpNo).getImm();
++OpNo; // Skip over the ID number.
if (Modifier[0]=='l') // labels are target independent
printBasicBlockLabel(MI->getOperand(OpNo).getMBB(),
Evan Cheng
committed
false, false, false);
else {
AsmPrinter *AP = const_cast<AsmPrinter*>(this);
if ((OpFlags & 7) == 4) {
Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
Modifier[0] ? Modifier : 0);
} else {
Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
Modifier[0] ? Modifier : 0);
}
}
if (Error) {
Bill Wendling
committed
cerr << "Invalid operand found in inline asm: '"
<< AsmStr << "'\n";
MI->dump();
exit(1);
}
}
break;
}
}
}
O << "\n\t" << TAI->getInlineAsmEnd() << '\n';
}
/// printImplicitDef - This method prints the specified machine instruction
/// that is an implicit def.
void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
O << '\t' << TAI->getCommentString() << " implicit-def: "
<< TRI->getAsmName(MI->getOperand(0).getReg()) << '\n';
}
/// printLabel - This method prints a local label used by debug and
/// exception handling tables.
void AsmPrinter::printLabel(const MachineInstr *MI) const {
printLabel(MI->getOperand(0).getImm());
Evan Cheng
committed
void AsmPrinter::printLabel(unsigned Id) const {
O << TAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
Evan Cheng
committed
}
Evan Cheng
committed
/// printDeclare - This method prints a local variable declaration used by
/// debug tables.
Evan Cheng
committed
/// FIXME: It doesn't really print anything rather it inserts a DebugVariable
/// entry into dwarf table.
Evan Cheng
committed
void AsmPrinter::printDeclare(const MachineInstr *MI) const {
Evan Cheng
committed
int FI = MI->getOperand(0).getIndex();
GlobalValue *GV = MI->getOperand(1).getGlobal();
MMI->RecordVariable(GV, FI);
Evan Cheng
committed
}
/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
/// instruction, using the specified assembler variant. Targets should
/// overried this to format as appropriate.
bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant, const char *ExtraCode) {
// Target doesn't support this yet!
return true;
bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant,
const char *ExtraCode) {
// Target doesn't support this yet!
return true;
}
/// printBasicBlockLabel - This method prints the label for the specified
/// MachineBasicBlock
void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
Evan Cheng
committed
bool printAlign,
bool printColon,
bool printComment) const {
Evan Cheng
committed
if (printAlign) {
unsigned Align = MBB->getAlignment();
if (Align)
EmitAlignment(Log2_32(Align));
}
O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << '_'
if (printColon)
O << ':';
if (printComment && MBB->getBasicBlock())
O << '\t' << TAI->getCommentString() << ' '
<< MBB->getBasicBlock()->getNameStart();
}
/// printPICJumpTableSetLabel - This method prints a set label for the
/// specified MachineBasicBlock for a jumptable entry.
void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
const MachineBasicBlock *MBB) const {
if (!TAI->getSetDirective())
return;
O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
Evan Cheng
committed
printBasicBlockLabel(MBB, false, false, false);
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << uid << '\n';
}
void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
const MachineBasicBlock *MBB) const {
if (!TAI->getSetDirective())
return;
O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
<< getFunctionNumber() << '_' << uid << '_' << uid2
<< "_set_" << MBB->getNumber() << ',';
Evan Cheng
committed
printBasicBlockLabel(MBB, false, false, false);
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << uid << '_' << uid2 << '\n';
/// printDataDirective - This method prints the asm directive for the
/// specified type.
void AsmPrinter::printDataDirective(const Type *type) {
const TargetData *TD = TM.getTargetData();
switch (type->getTypeID()) {
case Type::IntegerTyID: {
unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
if (BitWidth <= 8)
O << TAI->getData8bitsDirective();
else if (BitWidth <= 16)
O << TAI->getData16bitsDirective();
else if (BitWidth <= 32)
O << TAI->getData32bitsDirective();
else if (BitWidth <= 64) {
assert(TAI->getData64bitsDirective() &&
"Target cannot handle 64-bit constant exprs!");
O << TAI->getData64bitsDirective();
} else {
assert(0 && "Target cannot handle given data directive width!");
break;
case Type::PointerTyID:
if (TD->getPointerSize() == 8) {
assert(TAI->getData64bitsDirective() &&
"Target cannot handle 64-bit pointer exprs!");
O << TAI->getData64bitsDirective();
}
break;
case Type::FloatTyID: case Type::DoubleTyID:
case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
assert (0 && "Should have already output floating point constant.");
default:
assert (0 && "Can't handle printing this type of thing");
break;
}
}
void AsmPrinter::printSuffixedName(const char *Name, const char *Suffix,
const char *Prefix) {
O << '\"';
O << TAI->getPrivateGlobalPrefix();
if (Prefix) O << Prefix;
if (Name[0]=='\"')
O << '\"';
if (Name[0]=='\"')
O << Name[1];
O << Name;
O << Suffix;
if (Name[0]=='\"')
O << '\"';
void AsmPrinter::printSuffixedName(const std::string &Name, const char* Suffix) {
printSuffixedName(Name.c_str(), Suffix);
}
Anton Korobeynikov
committed
void AsmPrinter::printVisibility(const std::string& Name,
unsigned Visibility) const {
if (Visibility == GlobalValue::HiddenVisibility) {
if (const char *Directive = TAI->getHiddenDirective())
O << Directive << Name << '\n';
} else if (Visibility == GlobalValue::ProtectedVisibility) {
if (const char *Directive = TAI->getProtectedDirective())
O << Directive << Name << '\n';
}
}
Gordon Henriksen
committed
void AsmPrinter::printOffset(int64_t Offset) const {
if (Offset > 0)
O << '+' << Offset;
else if (Offset < 0)
O << Offset;
}
GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
if (!S->usesMetadata())
Gordon Henriksen
committed
return 0;
gcp_iterator GCPI = GCMetadataPrinters.find(S);
Gordon Henriksen
committed
if (GCPI != GCMetadataPrinters.end())
return GCPI->second;
const char *Name = S->getName().c_str();
Gordon Henriksen
committed
for (GCMetadataPrinterRegistry::iterator
I = GCMetadataPrinterRegistry::begin(),
E = GCMetadataPrinterRegistry::end(); I != E; ++I)
if (strcmp(Name, I->getName()) == 0) {
GCMetadataPrinter *GMP = I->instantiate();
GMP->S = S;
GCMetadataPrinters.insert(std::make_pair(S, GMP));
return GMP;
Gordon Henriksen
committed
}
cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";