-bool X86SharedAsmPrinter::doFinalization(Module &M) {
- // Note: this code is not shared by the Intel printer as it is too different
- // from how MASM does things. When making changes here don't forget to look
- // at X86IntelAsmPrinter::doFinalization().
- const TargetData *TD = TM.getTargetData();
-
- // Print out module-level global variables here.
- for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
- I != E; ++I) {
- if (!I->hasInitializer() && !I->hasExternalWeakLinkage())
- continue; // External global require no code
-
- // Check to see if this is a special global used by LLVM, if so, emit it.
- if (EmitSpecialLLVMGlobal(I))
- continue;
-
- std::string name = Mang->getValueName(I);
- Constant *C = I->getInitializer();
- unsigned Size = TD->getTypeSize(C->getType());
- unsigned Align = TD->getPreferredAlignmentLog(I);
-
- if (C->isNullValue() && /* FIXME: Verify correct */
- !I->hasSection() &&
- (I->hasInternalLinkage() || I->hasWeakLinkage() ||
- I->hasLinkOnceLinkage() ||
- (Subtarget->isTargetDarwin() &&
- I->hasExternalLinkage()))) {
- if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
- if (I->hasExternalLinkage()) {
- O << "\t.globl\t" << name << "\n";
- O << "\t.zerofill __DATA__, __common, " << name << ", "
- << Size << ", " << Align;
- } else {
- SwitchToDataSection(TAI->getDataSection(), I);
- if (TAI->getLCOMMDirective() != NULL) {
- if (I->hasInternalLinkage()) {
- O << TAI->getLCOMMDirective() << name << "," << Size;
- if (Subtarget->isTargetDarwin())
- O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
- } else
- O << TAI->getCOMMDirective() << name << "," << Size;
- } else {
- if (!Subtarget->isTargetCygwin()) {
- if (I->hasInternalLinkage())
- O << "\t.local\t" << name << "\n";
- }
- O << TAI->getCOMMDirective() << name << "," << Size;
- if (TAI->getCOMMDirectiveTakesAlignment())
- O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
- }
- }
- O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
- } else {
- switch (I->getLinkage()) {
- case GlobalValue::ExternalWeakLinkage:
- if (Subtarget->isTargetDarwin()) {
- assert(0 && "External weak linkage for Darwin not implemented yet");
- } else if (Subtarget->isTargetCygwin()) {
- // There is no external weak linkage on Mingw32 platform.
- // Defaulting just to external
- O << "\t.globl " << name << "\n";
- } else {
- O << "\t.weak " << name << "\n";
- break;
- }
- case GlobalValue::LinkOnceLinkage:
- case GlobalValue::WeakLinkage:
- if (Subtarget->isTargetDarwin()) {
- O << "\t.globl " << name << "\n"
- << "\t.weak_definition " << name << "\n";
- SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
- } else if (Subtarget->isTargetCygwin()) {
- std::string SectionName(".section\t.data$linkonce." +
- name +
- ",\"aw\"");
- SwitchToDataSection(SectionName.c_str(), I);
- O << "\t.globl " << name << "\n"
- << "\t.linkonce same_size\n";
- } else {
- std::string SectionName("\t.section\t.llvm.linkonce.d." +
- name +
- ",\"aw\",@progbits");
- SwitchToDataSection(SectionName.c_str(), I);
- O << "\t.weak " << name << "\n";
- }
- break;
- case GlobalValue::AppendingLinkage:
- // FIXME: appending linkage variables should go into a section of
- // their name or something. For now, just emit them as external.
- case GlobalValue::DLLExportLinkage:
- DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
- // FALL THROUGH
- case GlobalValue::ExternalLinkage:
- // If external or appending, declare as a global symbol
- O << "\t.globl " << name << "\n";
- // FALL THROUGH
- case GlobalValue::InternalLinkage: {
- if (I->isConstant()) {
- const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
- if (TAI->getCStringSection() && CVA && CVA->isCString()) {
- SwitchToDataSection(TAI->getCStringSection(), I);
- break;
- }
- }
- // FIXME: special handling for ".ctors" & ".dtors" sections
- if (I->hasSection() &&
- (I->getSection() == ".ctors" ||
- I->getSection() == ".dtors")) {
- std::string SectionName = ".section " + I->getSection();
-
- if (Subtarget->isTargetCygwin()) {
- SectionName += ",\"aw\"";
- } else {
- assert(!Subtarget->isTargetDarwin());
- SectionName += ",\"aw\",@progbits";
- }
-
- SwitchToDataSection(SectionName.c_str());
- } else {
- SwitchToDataSection(TAI->getDataSection(), I);
- }
-
- break;
- }
- default:
- assert(0 && "Unknown linkage type!");
- }
+void X86AsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op,
+ raw_ostream &O, const char *Modifier) {
+ const MachineOperand &BaseReg = MI->getOperand(Op);
+ const MachineOperand &IndexReg = MI->getOperand(Op+2);
+ const MachineOperand &DispSpec = MI->getOperand(Op+3);
+
+ // If we really don't want to print out (rip), don't.
+ bool HasBaseReg = BaseReg.getReg() != 0;
+ if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
+ BaseReg.getReg() == X86::RIP)
+ HasBaseReg = false;
+
+ // HasParenPart - True if we will print out the () part of the mem ref.
+ bool HasParenPart = IndexReg.getReg() || HasBaseReg;
+
+ if (DispSpec.isImm()) {
+ int DispVal = DispSpec.getImm();
+ if (DispVal || !HasParenPart)
+ O << DispVal;
+ } else {
+ assert(DispSpec.isGlobal() || DispSpec.isCPI() ||
+ DispSpec.isJTI() || DispSpec.isSymbol());
+ printSymbolOperand(MI->getOperand(Op+3), O);
+ }
+
+ if (Modifier && strcmp(Modifier, "H") == 0)
+ O << "+8";
+
+ if (HasParenPart) {
+ assert(IndexReg.getReg() != X86::ESP &&
+ "X86 doesn't allow scaling by ESP");