From bruno.cardoso at gmail.com Mon Jul 6 00:09:34 2009 From: bruno.cardoso at gmail.com (Bruno Cardoso Lopes) Date: Mon, 06 Jul 2009 05:09:34 -0000 Subject: [llvm-commits] [llvm] r74813 - in /llvm/trunk: include/llvm/CodeGen/ include/llvm/Target/ lib/CodeGen/ lib/Target/ARM/ lib/Target/Alpha/ lib/Target/PowerPC/ lib/Target/X86/ tools/llc/ tools/lto/ Message-ID: <200907060509.n6659Zbt026565@zion.cs.uiuc.edu> Author: bruno Date: Mon Jul 6 00:09:34 2009 New Revision: 74813 URL: http://llvm.org/viewvc/llvm-project?rev=74813&view=rev Log: Add the Object Code Emitter class. Original patch by Aaron Gray, I did some cleanup, removed some #includes and moved Object Code Emitter out-of-line. Modified: llvm/trunk/include/llvm/CodeGen/BinaryObject.h llvm/trunk/include/llvm/CodeGen/FileWriters.h llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h llvm/trunk/include/llvm/Target/TargetMachine.h llvm/trunk/lib/CodeGen/ELFWriter.cpp llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp llvm/trunk/lib/CodeGen/MachO.h llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp llvm/trunk/lib/CodeGen/MachOCodeEmitter.h llvm/trunk/lib/CodeGen/MachOWriter.cpp llvm/trunk/lib/CodeGen/MachOWriter.h llvm/trunk/lib/Target/ARM/ARM.h llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp llvm/trunk/lib/Target/ARM/ARMTargetMachine.h llvm/trunk/lib/Target/Alpha/Alpha.h llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h llvm/trunk/lib/Target/PowerPC/PPC.h llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h llvm/trunk/lib/Target/X86/X86.h llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp llvm/trunk/lib/Target/X86/X86TargetMachine.cpp llvm/trunk/lib/Target/X86/X86TargetMachine.h llvm/trunk/tools/llc/llc.cpp llvm/trunk/tools/lto/LTOCodeGenerator.cpp Modified: llvm/trunk/include/llvm/CodeGen/BinaryObject.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/BinaryObject.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/BinaryObject.h (original) +++ llvm/trunk/include/llvm/CodeGen/BinaryObject.h Mon Jul 6 00:09:34 2009 @@ -146,27 +146,27 @@ /// emitDWordLE - This callback is invoked when a 64-bit word needs to be /// written to the data stream in little-endian format. inline void emitDWordLE(uint64_t W) { - Data.push_back(unsigned(W >> 0) & 255); - Data.push_back(unsigned(W >> 8) & 255); - Data.push_back(unsigned(W >> 16) & 255); - Data.push_back(unsigned(W >> 24) & 255); - Data.push_back(unsigned(W >> 32) & 255); - Data.push_back(unsigned(W >> 40) & 255); - Data.push_back(unsigned(W >> 48) & 255); - Data.push_back(unsigned(W >> 56) & 255); + Data.push_back((W >> 0) & 255); + Data.push_back((W >> 8) & 255); + Data.push_back((W >> 16) & 255); + Data.push_back((W >> 24) & 255); + Data.push_back((W >> 32) & 255); + Data.push_back((W >> 40) & 255); + Data.push_back((W >> 48) & 255); + Data.push_back((W >> 56) & 255); } /// emitDWordBE - This callback is invoked when a 64-bit word needs to be /// written to the data stream in big-endian format. inline void emitDWordBE(uint64_t W) { - Data.push_back(unsigned(W >> 56) & 255); - Data.push_back(unsigned(W >> 48) & 255); - Data.push_back(unsigned(W >> 40) & 255); - Data.push_back(unsigned(W >> 32) & 255); - Data.push_back(unsigned(W >> 24) & 255); - Data.push_back(unsigned(W >> 16) & 255); - Data.push_back(unsigned(W >> 8) & 255); - Data.push_back(unsigned(W >> 0) & 255); + Data.push_back((W >> 56) & 255); + Data.push_back((W >> 48) & 255); + Data.push_back((W >> 40) & 255); + Data.push_back((W >> 32) & 255); + Data.push_back((W >> 24) & 255); + Data.push_back((W >> 16) & 255); + Data.push_back((W >> 8) & 255); + Data.push_back((W >> 0) & 255); } /// fixByte - This callback is invoked when a byte needs to be @@ -270,11 +270,11 @@ } /// emitAlignment - Pad the data to the specified alignment. - void emitAlignment(unsigned Alignment) { + void emitAlignment(unsigned Alignment, uint8_t fill = 0) { if (Alignment <= 1) return; unsigned PadSize = -Data.size() & (Alignment-1); for (unsigned i = 0; igetMachineCodeEmitter(); + return (ObjectCodeEmitter*) &EW->getMachineCodeEmitter(); } //===----------------------------------------------------------------------===// Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original) +++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Mon Jul 6 00:09:34 2009 @@ -126,6 +126,23 @@ return false; // success! } +/// addPassesToEmitFileFinish - If the passes to emit the specified file had to +/// be split up (e.g., to add an object writer pass), this method can be used to +/// finish up adding passes to emit the file, if necessary. +bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM, + ObjectCodeEmitter *OCE, + CodeGenOpt::Level OptLevel) { + if (OCE) + addSimpleCodeEmitter(PM, OptLevel, PrintEmittedAsm, *OCE); + + PM.add(createGCInfoDeleter()); + + // Delete machine code for this function + PM.add(createMachineCodeDeleter()); + + return false; // success! +} + /// addPassesToEmitMachineCode - Add passes to the specified pass manager to /// get machine code emitted. This uses a MachineCodeEmitter object to handle /// actually outputting the machine code and resolving things like the address Modified: llvm/trunk/lib/CodeGen/MachO.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachO.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachO.h (original) +++ llvm/trunk/lib/CodeGen/MachO.h Mon Jul 6 00:09:34 2009 @@ -17,6 +17,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/CodeGen/MachineRelocation.h" +#include "llvm/CodeGen/BinaryObject.h" #include "llvm/Target/TargetAsmInfo.h" #include #include @@ -272,11 +273,10 @@ /// turned into the SectionCommand in the load command for a particlar /// segment. -struct MachOSection { +struct MachOSection : public BinaryObject { std::string sectname; // name of this section, std::string segname; // segment this section goes in uint64_t addr; // memory address of this section - uint64_t size; // size in bytes of this section uint32_t offset; // file offset of this section uint32_t align; // section alignment (power of 2) uint32_t reloff; // file offset of relocation entries @@ -290,19 +290,10 @@ /// to the correct section. uint32_t Index; - /// SectionData - The actual data for this section which we are building - /// up for emission to the file. - DataBuffer SectionData; - /// RelocBuffer - A buffer to hold the mach-o relocations before we write /// them out at the appropriate location in the file. DataBuffer RelocBuffer; - /// Relocations - The relocations that we have encountered so far in this - /// section that we will need to convert to MachORelocation entries when - /// the file is written. - std::vector Relocations; - // Constants for the section types (low 8 bits of flags field) // see enum { S_REGULAR = 0, @@ -374,48 +365,49 @@ } MachOSection(const std::string &seg, const std::string §) - : sectname(sect), segname(seg), addr(0), size(0), offset(0), align(2), - reloff(0), nreloc(0), flags(0), reserved1(0), reserved2(0), + : BinaryObject(), sectname(sect), segname(seg), addr(0), offset(0), + align(2), reloff(0), nreloc(0), flags(0), reserved1(0), reserved2(0), reserved3(0) { } }; // end struct MachOSection - /// MachOSymTab - This struct contains information about the offsets and - /// size of symbol table information. - /// segment. - struct MachODySymTab { - uint32_t cmd; // LC_DYSYMTAB - uint32_t cmdsize; // sizeof( MachODySymTab ) - uint32_t ilocalsym; // index to local symbols - uint32_t nlocalsym; // number of local symbols - uint32_t iextdefsym; // index to externally defined symbols - uint32_t nextdefsym; // number of externally defined symbols - uint32_t iundefsym; // index to undefined symbols - uint32_t nundefsym; // number of undefined symbols - uint32_t tocoff; // file offset to table of contents - uint32_t ntoc; // number of entries in table of contents - uint32_t modtaboff; // file offset to module table - uint32_t nmodtab; // number of module table entries - uint32_t extrefsymoff; // offset to referenced symbol table - uint32_t nextrefsyms; // number of referenced symbol table entries - uint32_t indirectsymoff; // file offset to the indirect symbol table - uint32_t nindirectsyms; // number of indirect symbol table entries - uint32_t extreloff; // offset to external relocation entries - uint32_t nextrel; // number of external relocation entries - uint32_t locreloff; // offset to local relocation entries - uint32_t nlocrel; // number of local relocation entries - - // Constants for the cmd field - // see - enum { LC_DYSYMTAB = 0x0B // dynamic link-edit symbol table info - }; - - MachODySymTab() : cmd(LC_DYSYMTAB), cmdsize(20 * sizeof(uint32_t)), - ilocalsym(0), nlocalsym(0), iextdefsym(0), nextdefsym(0), - iundefsym(0), nundefsym(0), tocoff(0), ntoc(0), modtaboff(0), - nmodtab(0), extrefsymoff(0), nextrefsyms(0), indirectsymoff(0), - nindirectsyms(0), extreloff(0), nextrel(0), locreloff(0), nlocrel(0) { } - }; +/// MachOSymTab - This struct contains information about the offsets and +/// size of symbol table information. +/// segment. +struct MachODySymTab { + uint32_t cmd; // LC_DYSYMTAB + uint32_t cmdsize; // sizeof(MachODySymTab) + uint32_t ilocalsym; // index to local symbols + uint32_t nlocalsym; // number of local symbols + uint32_t iextdefsym; // index to externally defined symbols + uint32_t nextdefsym; // number of externally defined symbols + uint32_t iundefsym; // index to undefined symbols + uint32_t nundefsym; // number of undefined symbols + uint32_t tocoff; // file offset to table of contents + uint32_t ntoc; // number of entries in table of contents + uint32_t modtaboff; // file offset to module table + uint32_t nmodtab; // number of module table entries + uint32_t extrefsymoff; // offset to referenced symbol table + uint32_t nextrefsyms; // number of referenced symbol table entries + uint32_t indirectsymoff; // file offset to the indirect symbol table + uint32_t nindirectsyms; // number of indirect symbol table entries + uint32_t extreloff; // offset to external relocation entries + uint32_t nextrel; // number of external relocation entries + uint32_t locreloff; // offset to local relocation entries + uint32_t nlocrel; // number of local relocation entries + + // Constants for the cmd field + // see + enum { LC_DYSYMTAB = 0x0B // dynamic link-edit symbol table info + }; + + MachODySymTab() : cmd(LC_DYSYMTAB), cmdsize(20 * sizeof(uint32_t)), + ilocalsym(0), nlocalsym(0), iextdefsym(0), nextdefsym(0), + iundefsym(0), nundefsym(0), tocoff(0), ntoc(0), modtaboff(0), + nmodtab(0), extrefsymoff(0), nextrefsyms(0), indirectsymoff(0), + nindirectsyms(0), extreloff(0), nextrel(0), locreloff(0), nlocrel(0) { } + +}; // end struct MachODySymTab } // end namespace llvm Modified: llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp (original) +++ llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp Mon Jul 6 00:09:34 2009 @@ -16,6 +16,7 @@ #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/OutputBuffer.h" +#include //===----------------------------------------------------------------------===// // MachOCodeEmitter Implementation @@ -39,28 +40,18 @@ // Get the Mach-O Section that this function belongs in. MachOSection *MOS = MOW.getTextSection(); - // FIXME: better memory management - MOS->SectionData.reserve(4096); - BufferBegin = &MOS->SectionData[0]; - BufferEnd = BufferBegin + MOS->SectionData.capacity(); - // Upgrade the section alignment if required. if (MOS->align < Align) MOS->align = Align; - // Round the size up to the correct alignment for starting the new function. - if ((MOS->size & ((1 << Align) - 1)) != 0) { - MOS->size += (1 << Align); - MOS->size &= ~((1 << Align) - 1); - } + MOS->emitAlignment(Align); - // FIXME: Using MOS->size directly here instead of calculating it from the - // output buffer size (impossible because the code emitter deals only in raw - // bytes) forces us to manually synchronize size and write padding zero bytes - // to the output buffer for all non-text sections. For text sections, we do - // not synchonize the output buffer, and we just blow up if anyone tries to - // write non-code to it. An assert should probably be added to - // AddSymbolToSection to prevent calling it on the text section. - CurBufferPtr = BufferBegin + MOS->size; + // Create symbol for function entry + const GlobalValue *FuncV = MF.getFunction(); + MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TAI); + FnSym.n_value = getCurrentPCOffset(); + + // add it to the symtab. + MOW.SymbolTable.push_back(FnSym); } /// finishFunction - This callback is invoked after the function is completely @@ -71,15 +62,6 @@ // Get the Mach-O Section that this function belongs in. MachOSection *MOS = MOW.getTextSection(); - // Get a symbol for the function to add to the symbol table - // FIXME: it seems like we should call something like AddSymbolToSection - // in startFunction rather than changing the section size and symbol n_value - // here. - const GlobalValue *FuncV = MF.getFunction(); - MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TAI); - FnSym.n_value = MOS->size; - MOS->size = CurBufferPtr - BufferBegin; - // Emit constant pool to appropriate section(s) emitConstantPool(MF.getConstantPool()); @@ -112,12 +94,9 @@ } else { assert(0 && "Unhandled relocation type"); } - MOS->Relocations.push_back(MR); + MOS->addRelocation(MR); } Relocations.clear(); - - // Finally, add it to the symtab. - MOW.SymbolTable.push_back(FnSym); // Clear per-function data structures. CPLocations.clear(); @@ -151,13 +130,10 @@ unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); MachOSection *Sec = MOW.getConstSection(CP[i].Val.ConstVal); - OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); + OutputBuffer SecDataOut(Sec->getData(), is64Bit, isLittleEndian); - CPLocations.push_back(Sec->SectionData.size()); + CPLocations.push_back(Sec->size()); CPSections.push_back(Sec->Index); - - // FIXME: remove when we have unified size + output buffer - Sec->size += Size; // Allocate space in the section for the global. // FIXME: need alignment? @@ -165,14 +141,12 @@ for (unsigned j = 0; j < Size; ++j) SecDataOut.outbyte(0); - MOW.InitMem(CP[i].Val.ConstVal, &Sec->SectionData[0], CPLocations[i], - TM.getTargetData(), Sec->Relocations); + MachOWriter::InitMem(CP[i].Val.ConstVal, CPLocations[i], TM.getTargetData(), Sec); } } /// emitJumpTables - Emit all the jump tables for a given jump table info /// record to the appropriate section. - void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) { const std::vector &JT = MJTI->getJumpTables(); if (JT.empty()) return; @@ -183,24 +157,21 @@ MachOSection *Sec = MOW.getJumpTableSection(); unsigned TextSecIndex = MOW.getTextSection()->Index; - OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); + OutputBuffer SecDataOut(Sec->getData(), is64Bit, isLittleEndian); for (unsigned i = 0, e = JT.size(); i != e; ++i) { // For each jump table, record its offset from the start of the section, // reserve space for the relocations to the MBBs, and add the relocations. const std::vector &MBBs = JT[i].MBBs; - JTLocations.push_back(Sec->SectionData.size()); + JTLocations.push_back(Sec->size()); for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi) { - MachineRelocation MR(MOW.GetJTRelocation(Sec->SectionData.size(), - MBBs[mi])); + MachineRelocation MR(MOW.GetJTRelocation(Sec->size(), MBBs[mi])); MR.setResultPointer((void *)JTLocations[i]); MR.setConstantVal(TextSecIndex); - Sec->Relocations.push_back(MR); + Sec->addRelocation(MR); SecDataOut.outaddr(0); } } - // FIXME: remove when we have unified size + output buffer - Sec->size = Sec->SectionData.size(); } } // end namespace llvm Modified: llvm/trunk/lib/CodeGen/MachOCodeEmitter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOCodeEmitter.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOCodeEmitter.h (original) +++ llvm/trunk/lib/CodeGen/MachOCodeEmitter.h Mon Jul 6 00:09:34 2009 @@ -11,15 +11,13 @@ #define MACHOCODEEMITTER_H #include "MachOWriter.h" -#include "llvm/CodeGen/MachineCodeEmitter.h" -#include namespace llvm { /// MachOCodeEmitter - This class is used by the MachOWriter to emit the code /// for functions to the Mach-O file. -class MachOCodeEmitter : public MachineCodeEmitter { +class MachOCodeEmitter : public ObjectCodeEmitter { MachOWriter &MOW; /// Target machine description. @@ -34,27 +32,12 @@ /// Relocations - These are the relocations that the function needs, as /// emitted. std::vector Relocations; - - /// CPLocations - This is a map of constant pool indices to offsets from the - /// start of the section for that constant pool index. - std::vector CPLocations; - - /// CPSections - This is a map of constant pool indices to the MachOSection - /// containing the constant pool entry for that index. - std::vector CPSections; - - /// JTLocations - This is a map of jump table indices to offsets from the - /// start of the section for that jump table index. - std::vector JTLocations; - - /// MBBLocations - This vector is a mapping from MBB ID's to their address. - /// It is filled in by the StartMachineBasicBlock callback and queried by - /// the getMachineBasicBlockAddress callback. - std::vector MBBLocations; - + + std::map Labels; + public: - MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM) - { + MachOCodeEmitter(MachOWriter &mow, MachOSection &mos) : + ObjectCodeEmitter(&mos), MOW(mow), TM(MOW.TM) { is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; isLittleEndian = TM.getTargetData()->isLittleEndian(); TAI = TM.getTargetAsmInfo(); @@ -69,58 +52,17 @@ void emitConstantPool(MachineConstantPool *MCP); void emitJumpTables(MachineJumpTableInfo *MJTI); - - virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const { - assert(CPLocations.size() > Index && "CP not emitted!"); - return CPLocations[Index]; - } - virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const { - assert(JTLocations.size() > Index && "JT not emitted!"); - return JTLocations[Index]; - } - - virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) { - if (MBBLocations.size() <= (unsigned)MBB->getNumber()) - MBBLocations.resize((MBB->getNumber()+1)*2); - MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); - } - virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const { - assert(MBBLocations.size() > (unsigned)MBB->getNumber() && - MBBLocations[MBB->getNumber()] && "MBB not emitted!"); - return MBBLocations[MBB->getNumber()]; + virtual void emitLabel(uint64_t LabelID) { + Labels[LabelID] = getCurrentPCOffset(); } virtual uintptr_t getLabelAddress(uint64_t Label) const { - assert(0 && "get Label not implemented"); - abort(); - return 0; - } - - virtual void emitLabel(uint64_t LabelID) { - assert(0 && "emit Label not implemented"); - abort(); + return Labels.find(Label)->second; } virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { } - /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE! - virtual void startGVStub(const GlobalValue* F, unsigned StubSize, - unsigned Alignment = 1) { - assert(0 && "JIT specific function called!"); - abort(); - } - virtual void startGVStub(const GlobalValue* F, void *Buffer, - unsigned StubSize) { - assert(0 && "JIT specific function called!"); - abort(); - } - virtual void *finishGVStub(const GlobalValue* F) { - assert(0 && "JIT specific function called!"); - abort(); - return 0; - } - }; // end class MachOCodeEmitter } // end namespace llvm Modified: llvm/trunk/lib/CodeGen/MachOWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/MachOWriter.cpp Mon Jul 6 00:09:34 2009 @@ -46,12 +46,12 @@ /// AddMachOWriter - Concrete function to add the Mach-O writer to the function /// pass manager. -MachineCodeEmitter *AddMachOWriter(PassManagerBase &PM, +ObjectCodeEmitter *AddMachOWriter(PassManagerBase &PM, raw_ostream &O, TargetMachine &TM) { MachOWriter *MOW = new MachOWriter(O, TM); PM.add(MOW); - return &MOW->getMachineCodeEmitter(); + return MOW->getObjectCodeEmitter(); } //===----------------------------------------------------------------------===// @@ -60,8 +60,9 @@ char MachOWriter::ID = 0; -MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm) - : MachineFunctionPass(&ID), O(o), TM(tm) { +MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm) + : MachineFunctionPass(&ID), O(o), TM(tm) + { is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; isLittleEndian = TM.getTargetData()->isLittleEndian(); @@ -69,11 +70,11 @@ // Create the machine code emitter object for this target. - MCE = new MachOCodeEmitter(*this); + MachOCE = new MachOCodeEmitter(*this, *getTextSection(true)); } MachOWriter::~MachOWriter() { - delete MCE; + delete MachOCE; } bool MachOWriter::doInitialization(Module &M) { @@ -97,13 +98,13 @@ /// the Mach-O file to 'O'. bool MachOWriter::doFinalization(Module &M) { // FIXME: we don't handle debug info yet, we should probably do that. - - // Okay, the.text section has been completed, build the .data, .bss, and + // Okay, the.text section has been completed, build the .data, .bss, and // "common" sections next. + for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) EmitGlobal(I); - + // Emit the header and load commands. EmitHeaderAndLoadCommands(); @@ -133,38 +134,32 @@ // Reserve space in the .bss section for this symbol while maintaining the // desired section alignment, which must be at least as much as required by // this symbol. - OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); + OutputBuffer SecDataOut(Sec->getData(), is64Bit, isLittleEndian); if (Align) { - uint64_t OrigSize = Sec->size; Align = Log2_32(Align); Sec->align = std::max(unsigned(Sec->align), Align); - Sec->size = (Sec->size + Align - 1) & ~(Align-1); - // Add alignment padding to buffer as well. - // FIXME: remove when we have unified size + output buffer - unsigned AlignedSize = Sec->size - OrigSize; - for (unsigned i = 0; i < AlignedSize; ++i) - SecDataOut.outbyte(0); + Sec->emitAlignment(Sec->align); } // Globals without external linkage apparently do not go in the symbol table. if (!GV->hasLocalLinkage()) { MachOSym Sym(GV, Mang->getValueName(GV), Sec->Index, TAI); - Sym.n_value = Sec->size; + Sym.n_value = Sec->size(); SymbolTable.push_back(Sym); } // Record the offset of the symbol, and then allocate space for it. // FIXME: remove when we have unified size + output buffer - Sec->size += Size; - - // Now that we know what section the GlovalVariable is going to be emitted + + // Now that we know what section the GlovalVariable is going to be emitted // into, update our mappings. // FIXME: We may also need to update this when outputting non-GlobalVariable // GlobalValues such as functions. - GVSection[GV] = Sec; - GVOffset[GV] = Sec->SectionData.size(); + GVSection[GV] = Sec; + GVOffset[GV] = Sec->size(); + // Allocate space in the section for the global. for (unsigned i = 0; i < Size; ++i) SecDataOut.outbyte(0); @@ -174,7 +169,7 @@ const Type *Ty = GV->getType()->getElementType(); unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); bool NoInit = !GV->hasInitializer(); - + // If this global has a zero initializer, it is part of the .bss or common // section. if (NoInit || GV->getInitializer()->isNullValue()) { @@ -183,8 +178,7 @@ // merged with other symbols. if (NoInit || GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() || GV->hasCommonLinkage()) { - MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV), - MachOSym::NO_SECT, TAI); + MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV), MachOSym::NO_SECT, TAI); // For undefined (N_UNDF) external (N_EXT) types, n_value is the size in // bytes of the symbol. ExtOrCommonSym.n_value = Size; @@ -198,15 +192,14 @@ AddSymbolToSection(BSS, GV); return; } - + // Scalar read-only data goes in a literal section if the scalar is 4, 8, or // 16 bytes, or a cstring. Other read only data goes into a regular const // section. Read-write data goes in the data section. - MachOSection *Sec = GV->isConstant() ? getConstSection(GV->getInitializer()) : + MachOSection *Sec = GV->isConstant() ? getConstSection(GV->getInitializer()) : getDataSection(); AddSymbolToSection(Sec, GV); - InitMem(GV->getInitializer(), &Sec->SectionData[0], GVOffset[GV], - TM.getTargetData(), Sec->Relocations); + InitMem(GV->getInitializer(), GVOffset[GV], TM.getTargetData(), Sec); } @@ -214,21 +207,22 @@ void MachOWriter::EmitHeaderAndLoadCommands() { // Step #0: Fill in the segment load command size, since we need it to figure // out the rest of the header fields + MachOSegment SEG("", is64Bit); SEG.nsects = SectionList.size(); - SEG.cmdsize = SEG.cmdSize(is64Bit) + + SEG.cmdsize = SEG.cmdSize(is64Bit) + SEG.nsects * SectionList[0]->cmdSize(is64Bit); - + // Step #1: calculate the number of load commands. We always have at least // one, for the LC_SEGMENT load command, plus two for the normal // and dynamic symbol tables, if there are any symbols. Header.ncmds = SymbolTable.empty() ? 1 : 3; - + // Step #2: calculate the size of the load commands Header.sizeofcmds = SEG.cmdsize; if (!SymbolTable.empty()) Header.sizeofcmds += SymTab.cmdsize + DySymTab.cmdsize; - + // Step #3: write the header to the file // Local alias to shortenify coming code. DataBuffer &FH = Header.HeaderData; @@ -243,15 +237,15 @@ FHOut.outword(Header.flags); if (is64Bit) FHOut.outword(Header.reserved); - + // Step #4: Finish filling in the segment load command and write it out for (std::vector::iterator I = SectionList.begin(), E = SectionList.end(); I != E; ++I) - SEG.filesize += (*I)->size; + SEG.filesize += (*I)->size(); SEG.vmsize = SEG.filesize; SEG.fileoff = Header.cmdSize(is64Bit) + Header.sizeofcmds; - + FHOut.outword(SEG.cmd); FHOut.outword(SEG.cmdsize); FHOut.outstring(SEG.segname, 16); @@ -263,42 +257,42 @@ FHOut.outword(SEG.initprot); FHOut.outword(SEG.nsects); FHOut.outword(SEG.flags); - - // Step #5: Finish filling in the fields of the MachOSections + + // Step #5: Finish filling in the fields of the MachOSections uint64_t currentAddr = 0; for (std::vector::iterator I = SectionList.begin(), E = SectionList.end(); I != E; ++I) { MachOSection *MOS = *I; MOS->addr = currentAddr; MOS->offset = currentAddr + SEG.fileoff; - // FIXME: do we need to do something with alignment here? - currentAddr += MOS->size; + currentAddr += MOS->size(); } - + // Step #6: Emit the symbol table to temporary buffers, so that we know the // size of the string table when we write the next load command. This also // sorts and assigns indices to each of the symbols, which is necessary for // emitting relocations to externally-defined objects. BufferSymbolAndStringTable(); - + // Step #7: Calculate the number of relocations for each section and write out // the section commands for each section currentAddr += SEG.fileoff; for (std::vector::iterator I = SectionList.begin(), E = SectionList.end(); I != E; ++I) { MachOSection *MOS = *I; + // Convert the relocations to target-specific relocations, and fill in the // relocation offset for this section. CalculateRelocations(*MOS); MOS->reloff = MOS->nreloc ? currentAddr : 0; currentAddr += MOS->nreloc * 8; - + // write the finalized section command to the output buffer FHOut.outstring(MOS->sectname, 16); FHOut.outstring(MOS->segname, 16); FHOut.outaddr(MOS->addr); - FHOut.outaddr(MOS->size); + FHOut.outaddr(MOS->size()); FHOut.outword(MOS->offset); FHOut.outword(MOS->align); FHOut.outword(MOS->reloff); @@ -309,7 +303,7 @@ if (is64Bit) FHOut.outword(MOS->reserved3); } - + // Step #8: Emit LC_SYMTAB/LC_DYSYMTAB load commands SymTab.symoff = currentAddr; SymTab.nsyms = SymbolTable.size(); @@ -345,39 +339,40 @@ FHOut.outword(DySymTab.nextrel); FHOut.outword(DySymTab.locreloff); FHOut.outword(DySymTab.nlocrel); - + O.write((char*)&FH[0], FH.size()); } /// EmitSections - Now that we have constructed the file header and load /// commands, emit the data for each section to the file. - void MachOWriter::EmitSections() { for (std::vector::iterator I = SectionList.begin(), E = SectionList.end(); I != E; ++I) // Emit the contents of each section - O.write((char*)&(*I)->SectionData[0], (*I)->size); + if ((*I)->size()) + O.write((char*)&(*I)->getData()[0], (*I)->size()); } + +/// EmitRelocations - emit relocation data from buffer. void MachOWriter::EmitRelocations() { for (std::vector::iterator I = SectionList.begin(), E = SectionList.end(); I != E; ++I) // Emit the relocation entry data for each section. - O.write((char*)&(*I)->RelocBuffer[0], (*I)->RelocBuffer.size()); + if ((*I)->RelocBuffer.size()) + O.write((char*)&(*I)->RelocBuffer[0], (*I)->RelocBuffer.size()); } /// BufferSymbolAndStringTable - Sort the symbols we encountered and assign them /// each a string table index so that they appear in the correct order in the /// output file. - void MachOWriter::BufferSymbolAndStringTable() { // The order of the symbol table is: // 1. local symbols // 2. defined external symbols (sorted by name) // 3. undefined external symbols (sorted by name) - + // Before sorting the symbols, check the PendingGlobals for any undefined // globals that need to be put in the symbol table. - for (std::vector::iterator I = PendingGlobals.begin(), E = PendingGlobals.end(); I != E; ++I) { if (GVOffset[*I] == 0 && GVSection[*I] == 0) { @@ -389,19 +384,15 @@ // Sort the symbols by name, so that when we partition the symbols by scope // of definition, we won't have to sort by name within each partition. - std::sort(SymbolTable.begin(), SymbolTable.end(), MachOSym::SymCmp()); - // Parition the symbol table entries so that all local symbols come before + // Parition the symbol table entries so that all local symbols come before // all symbols with external linkage. { 1 | 2 3 } - - std::partition(SymbolTable.begin(), SymbolTable.end(), - MachOSym::PartitionByLocal); - + std::partition(SymbolTable.begin(), SymbolTable.end(), MachOSym::PartitionByLocal); + // Advance iterator to beginning of external symbols and partition so that // all external symbols defined in this module come before all external // symbols defined elsewhere. { 1 | 2 | 3 } - for (std::vector::iterator I = SymbolTable.begin(), E = SymbolTable.end(); I != E; ++I) { if (!MachOSym::PartitionByLocal(*I)) { @@ -410,10 +401,9 @@ } } - // Calculate the starting index for each of the local, extern defined, and + // Calculate the starting index for each of the local, extern defined, and // undefined symbols, as well as the number of each to put in the LC_DYSYMTAB // load command. - for (std::vector::iterator I = SymbolTable.begin(), E = SymbolTable.end(); I != E; ++I) { if (MachOSym::PartitionByLocal(*I)) { @@ -427,10 +417,9 @@ ++DySymTab.nundefsym; } } - + // Write out a leading zero byte when emitting string table, for n_strx == 0 // which means an empty string. - OutputBuffer StrTOut(StrT, is64Bit, isLittleEndian); StrTOut.outbyte(0); @@ -439,7 +428,6 @@ // 2. strings for local symbols // Since this is the opposite order from the symbol table, which we have just // sorted, we can walk the symbol table backwards to output the string table. - for (std::vector::reverse_iterator I = SymbolTable.rbegin(), E = SymbolTable.rend(); I != E; ++I) { if (I->GVName == "") { @@ -463,7 +451,7 @@ I->n_value += GVSection[GV]->addr; if (GV && (GVOffset[GV] == -1)) GVOffset[GV] = index; - + // Emit nlist to buffer SymTOut.outword(I->n_strx); SymTOut.outbyte(I->n_type); @@ -478,32 +466,29 @@ /// and the offset into that section. From this information, create the /// appropriate target-specific MachORelocation type and add buffer it to be /// written out after we are finished writing out sections. - void MachOWriter::CalculateRelocations(MachOSection &MOS) { - for (unsigned i = 0, e = MOS.Relocations.size(); i != e; ++i) { - MachineRelocation &MR = MOS.Relocations[i]; + std::vector Relocations = MOS.getRelocations(); + for (unsigned i = 0, e = Relocations.size(); i != e; ++i) { + MachineRelocation &MR = Relocations[i]; unsigned TargetSection = MR.getConstantVal(); unsigned TargetAddr = 0; unsigned TargetIndex = 0; // This is a scattered relocation entry if it points to a global value with // a non-zero offset. - bool Scattered = false; bool Extern = false; // Since we may not have seen the GlobalValue we were interested in yet at // the time we emitted the relocation for it, fix it up now so that it // points to the offset into the correct section. - if (MR.isGlobalValue()) { GlobalValue *GV = MR.getGlobalValue(); MachOSection *MOSPtr = GVSection[GV]; intptr_t Offset = GVOffset[GV]; - + // If we have never seen the global before, it must be to a symbol // defined in another module (N_UNDF). - if (!MOSPtr) { // FIXME: need to append stub suffix Extern = true; @@ -515,10 +500,9 @@ } MR.setResultPointer((void*)Offset); } - + // If the symbol is locally defined, pass in the address of the section and // the section index to the code which will generate the target relocation. - if (!Extern) { MachOSection &To = *SectionList[TargetSection - 1]; TargetAddr = To.addr; @@ -526,7 +510,7 @@ } OutputBuffer RelocOut(MOS.RelocBuffer, is64Bit, isLittleEndian); - OutputBuffer SecOut(MOS.SectionData, is64Bit, isLittleEndian); + OutputBuffer SecOut(MOS.getData(), is64Bit, isLittleEndian); MOS.nreloc += GetTargetRelocation(MR, MOS.Index, TargetAddr, TargetIndex, RelocOut, SecOut, Scattered, Extern); @@ -535,22 +519,21 @@ // InitMem - Write the value of a Constant to the specified memory location, // converting it into bytes and relocations. - -void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset, - const TargetData *TD, - std::vector &MRs) { +void MachOWriter::InitMem(const Constant *C, uintptr_t Offset, + const TargetData *TD, MachOSection* mos) { typedef std::pair CPair; std::vector WorkList; - + uint8_t *Addr = &mos->getData()[0]; + WorkList.push_back(CPair(C,(intptr_t)Addr + Offset)); - + intptr_t ScatteredOffset = 0; - + while (!WorkList.empty()) { const Constant *PC = WorkList.back().first; intptr_t PA = WorkList.back().second; WorkList.pop_back(); - + if (isa(PC)) { continue; } else if (const ConstantVector *CP = dyn_cast(PC)) { @@ -643,7 +626,7 @@ memset(ptr, 0, TD->getPointerSize()); else if (const GlobalValue* GV = dyn_cast(PC)) { // FIXME: what about function stubs? - MRs.push_back(MachineRelocation::getGV(PA-(intptr_t)Addr, + mos->addRelocation(MachineRelocation::getGV(PA-(intptr_t)Addr, MachineRelocation::VANILLA, const_cast(GV), ScatteredOffset)); Modified: llvm/trunk/lib/CodeGen/MachOWriter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOWriter.h (original) +++ llvm/trunk/lib/CodeGen/MachOWriter.h Mon Jul 6 00:09:34 2009 @@ -15,17 +15,24 @@ #define MACHOWRITER_H #include "MachO.h" +#include "llvm/Constants.h" +#include "llvm/DerivedTypes.h" #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachOWriterInfo.h" +#include #include namespace llvm { class GlobalVariable; class Mangler; - class MachineCodeEmitter; + class MachineRelocation; + class ObjectCodeEmitter; class MachOCodeEmitter; + class TargetData; + class TargetMachine; class OutputBuffer; class raw_ostream; @@ -38,8 +45,9 @@ friend class MachOCodeEmitter; public: static char ID; - MachineCodeEmitter &getMachineCodeEmitter() const { - return *(MachineCodeEmitter*)MCE; + + ObjectCodeEmitter *getObjectCodeEmitter() { + return reinterpret_cast(MachOCE); } MachOWriter(raw_ostream &O, TargetMachine &TM); @@ -62,10 +70,10 @@ /// Mangler *Mang; - /// MCE - The MachineCodeEmitter object that we are exposing to emit machine + /// MachOCE - The MachineCodeEmitter object that we are exposing to emit machine /// code for functions to the .o file. - MachOCodeEmitter *MCE; + MachOCodeEmitter *MachOCE; /// is64Bit/isLittleEndian - This information is inferred from the target /// machine directly, indicating what header values and flags to set. @@ -225,9 +233,10 @@ /// SymbolTable to aid in emitting the DYSYMTAB load command. std::vector DynamicSymbolTable; - static void InitMem(const Constant *C, void *Addr, intptr_t Offset, + static void InitMem(const Constant *C, + uintptr_t Offset, const TargetData *TD, - std::vector &MRs); + MachOSection* mos); private: void AddSymbolToSection(MachOSection *MOS, GlobalVariable *GV); Modified: llvm/trunk/lib/Target/ARM/ARM.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARM.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARM.h (original) +++ llvm/trunk/lib/Target/ARM/ARM.h Mon Jul 6 00:09:34 2009 @@ -24,6 +24,7 @@ class FunctionPass; class MachineCodeEmitter; class JITCodeEmitter; +class ObjectCodeEmitter; class raw_ostream; // Enums corresponding to ARM condition codes @@ -101,6 +102,8 @@ MachineCodeEmitter &MCE); FunctionPass *createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM, JITCodeEmitter &JCE); +FunctionPass *createARMObjectCodeEmitterPass(ARMBaseTargetMachine &TM, + ObjectCodeEmitter &OCE); FunctionPass *createARMLoadStoreOptimizationPass(bool PreAlloc = false); FunctionPass *createARMConstantIslandPass(); Modified: llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp Mon Jul 6 00:09:34 2009 @@ -26,6 +26,7 @@ #include "llvm/PassManager.h" #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/CodeGen/JITCodeEmitter.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstr.h" @@ -174,18 +175,18 @@ /// createARMCodeEmitterPass - Return a pass that emits the collected ARM code /// to the specified MCE object. -namespace llvm { - -FunctionPass *createARMCodeEmitterPass(ARMBaseTargetMachine &TM, - MachineCodeEmitter &MCE) { +FunctionPass *llvm::createARMCodeEmitterPass(ARMBaseTargetMachine &TM, + MachineCodeEmitter &MCE) { return new Emitter(TM, MCE); } -FunctionPass *createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM, - JITCodeEmitter &JCE) { +FunctionPass *llvm::createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM, + JITCodeEmitter &JCE) { return new Emitter(TM, JCE); } - -} // end namespace llvm +FunctionPass *llvm::createARMObjectCodeEmitterPass(ARMBaseTargetMachine &TM, + ObjectCodeEmitter &OCE) { + return new Emitter(TM, OCE); +} template bool Emitter::runOnMachineFunction(MachineFunction &MF) { Modified: llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp Mon Jul 6 00:09:34 2009 @@ -228,6 +228,25 @@ return false; } +bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE) { + // FIXME: Move this to TargetJITInfo! + if (DefRelocModel == Reloc::Default) + setRelocationModel(Reloc::Static); + + // Machine code emitter pass for ARM. + PM.add(createARMObjectCodeEmitterPass(*this, OCE)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(errs(), *this, true)); + } + + return false; +} + bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, @@ -258,4 +277,18 @@ return false; } +bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE) { + // Machine code emitter pass for ARM. + PM.add(createARMObjectCodeEmitterPass(*this, OCE)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(errs(), *this, true)); + } + + return false; +} Modified: llvm/trunk/lib/Target/ARM/ARMTargetMachine.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMTargetMachine.h (original) +++ llvm/trunk/lib/Target/ARM/ARMTargetMachine.h Mon Jul 6 00:09:34 2009 @@ -77,6 +77,8 @@ bool DumpAsm, MachineCodeEmitter &MCE); virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &MCE); + virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &OCE); virtual bool addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, @@ -85,6 +87,10 @@ CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &MCE); + virtual bool addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE); }; /// ARMTargetMachine - ARM target machine. Modified: llvm/trunk/lib/Target/Alpha/Alpha.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/Alpha.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/Alpha/Alpha.h (original) +++ llvm/trunk/lib/Target/Alpha/Alpha.h Mon Jul 6 00:09:34 2009 @@ -22,6 +22,7 @@ class AlphaTargetMachine; class FunctionPass; class MachineCodeEmitter; + class ObjectCodeEmitter; class raw_ostream; FunctionPass *createAlphaISelDag(AlphaTargetMachine &TM); @@ -32,7 +33,9 @@ FunctionPass *createAlphaCodeEmitterPass(AlphaTargetMachine &TM, MachineCodeEmitter &MCE); FunctionPass *createAlphaJITCodeEmitterPass(AlphaTargetMachine &TM, - JITCodeEmitter &JCE); + JITCodeEmitter &JCE); + FunctionPass *createAlphaObjectCodeEmitterPass(AlphaTargetMachine &TM, + ObjectCodeEmitter &OCE); FunctionPass *createAlphaLLRPPass(AlphaTargetMachine &tm); FunctionPass *createAlphaBranchSelectionPass(); Modified: llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp (original) +++ llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp Mon Jul 6 00:09:34 2009 @@ -19,6 +19,7 @@ #include "llvm/PassManager.h" #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/CodeGen/JITCodeEmitter.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/Passes.h" @@ -91,6 +92,10 @@ JITCodeEmitter &JCE) { return new Emitter(TM, JCE); } +FunctionPass *llvm::createAlphaObjectCodeEmitterPass(AlphaTargetMachine &TM, + ObjectCodeEmitter &OCE) { + return new Emitter(TM, OCE); +} template bool Emitter::runOnMachineFunction(MachineFunction &MF) { Modified: llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp (original) +++ llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp Mon Jul 6 00:09:34 2009 @@ -119,6 +119,17 @@ } return false; } +bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &OCE) { + PM.add(createAlphaObjectCodeEmitterPass(*this, OCE)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(errs(), *this, true)); + } + return false; +} bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, @@ -131,4 +142,10 @@ JITCodeEmitter &JCE) { return addCodeEmitter(PM, OptLevel, DumpAsm, JCE); } +bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE) { + return addCodeEmitter(PM, OptLevel, DumpAsm, OCE); +} Modified: llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h (original) +++ llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h Mon Jul 6 00:09:34 2009 @@ -74,6 +74,8 @@ bool DumpAsm, MachineCodeEmitter &MCE); virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &JCE); + virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &JCE); virtual bool addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, @@ -82,6 +84,10 @@ CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &JCE); + virtual bool addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE); static void registerAsmPrinter(AsmPrinterCtorFn F) { AsmPrinterCtor = F; Modified: llvm/trunk/lib/Target/PowerPC/PPC.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPC.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/PPC.h (original) +++ llvm/trunk/lib/Target/PowerPC/PPC.h Mon Jul 6 00:09:34 2009 @@ -24,6 +24,7 @@ class PPCTargetMachine; class FunctionPass; class MachineCodeEmitter; + class ObjectCodeEmitter; class raw_ostream; FunctionPass *createPPCBranchSelectionPass(); @@ -33,7 +34,9 @@ FunctionPass *createPPCCodeEmitterPass(PPCTargetMachine &TM, MachineCodeEmitter &MCE); FunctionPass *createPPCJITCodeEmitterPass(PPCTargetMachine &TM, - JITCodeEmitter &MCE); + JITCodeEmitter &MCE); +FunctionPass *createPPCObjectCodeEmitterPass(PPCTargetMachine &TM, + ObjectCodeEmitter &OCE); } // end namespace llvm; // Defines symbolic names for PowerPC registers. This defines a mapping from Modified: llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp (original) +++ llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp Mon Jul 6 00:09:34 2009 @@ -19,6 +19,7 @@ #include "llvm/PassManager.h" #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/CodeGen/JITCodeEmitter.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineModuleInfo.h" @@ -91,6 +92,7 @@ /// createPPCCodeEmitterPass - Return a pass that emits the collected PPC code /// to the specified MCE object. + FunctionPass *llvm::createPPCCodeEmitterPass(PPCTargetMachine &TM, MachineCodeEmitter &MCE) { return new Emitter(TM, MCE); @@ -101,6 +103,11 @@ return new Emitter(TM, JCE); } +FunctionPass *llvm::createPPCObjectCodeEmitterPass(PPCTargetMachine &TM, + ObjectCodeEmitter &OCE) { + return new Emitter(TM, OCE); +} + template bool Emitter::runOnMachineFunction(MachineFunction &MF) { assert((MF.getTarget().getRelocationModel() != Reloc::Default || @@ -252,6 +259,7 @@ Reloc = PPC::reloc_pcrel_bx; else // BCC instruction Reloc = PPC::reloc_pcrel_bcx; + MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(), Reloc, MO.getMBB())); } else { Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp (original) +++ llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp Mon Jul 6 00:09:34 2009 @@ -221,6 +221,38 @@ return false; } +bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &OCE) { + // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64. + // FIXME: This should be moved to TargetJITInfo!! + if (Subtarget.isPPC64()) { + // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many + // instructions to materialize arbitrary global variable + function + + // constant pool addresses. + setRelocationModel(Reloc::PIC_); + // Temporary workaround for the inability of PPC64 JIT to handle jump + // tables. + DisableJumpTables = true; + } else { + setRelocationModel(Reloc::Static); + } + + // Inform the subtarget that we are in JIT mode. FIXME: does this break macho + // writing? + Subtarget.SetJITMode(); + + // Machine code emitter pass for PowerPC. + PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(errs(), *this, true)); + } + + return false; +} + bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, @@ -251,3 +283,19 @@ return false; } +bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE) { + // Machine code emitter pass for PowerPC. + PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(errs(), *this, true)); + } + + return false; +} + + Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h (original) +++ llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h Mon Jul 6 00:09:34 2009 @@ -85,12 +85,17 @@ bool DumpAsm, MachineCodeEmitter &MCE); virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &JCE); + virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &OCE); virtual bool addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, MachineCodeEmitter &MCE); virtual bool addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &JCE); + virtual bool addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &OCE); virtual bool getEnableTailMergeDefault() const; }; Modified: llvm/trunk/lib/Target/X86/X86.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86.h (original) +++ llvm/trunk/lib/Target/X86/X86.h Mon Jul 6 00:09:34 2009 @@ -56,6 +56,8 @@ MachineCodeEmitter &MCE); FunctionPass *createX86JITCodeEmitterPass(X86TargetMachine &TM, JITCodeEmitter &JCE); +FunctionPass *createX86ObjectCodeEmitterPass(X86TargetMachine &TM, + ObjectCodeEmitter &OCE); /// createX86EmitCodeToMemory - Returns a pass that converts a register /// allocated function into raw machine code in a dynamically Modified: llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp (original) +++ llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp Mon Jul 6 00:09:34 2009 @@ -22,6 +22,7 @@ #include "llvm/PassManager.h" #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/CodeGen/JITCodeEmitter.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineModuleInfo.h" @@ -106,18 +107,18 @@ /// createX86CodeEmitterPass - Return a pass that emits the collected X86 code /// to the specified templated MachineCodeEmitter object. -namespace llvm { - -FunctionPass *createX86CodeEmitterPass(X86TargetMachine &TM, - MachineCodeEmitter &MCE) { +FunctionPass *llvm::createX86CodeEmitterPass(X86TargetMachine &TM, + MachineCodeEmitter &MCE) { return new Emitter(TM, MCE); } -FunctionPass *createX86JITCodeEmitterPass(X86TargetMachine &TM, - JITCodeEmitter &JCE) { +FunctionPass *llvm::createX86JITCodeEmitterPass(X86TargetMachine &TM, + JITCodeEmitter &JCE) { return new Emitter(TM, JCE); } - -} // end namespace llvm +FunctionPass *llvm::createX86ObjectCodeEmitterPass(X86TargetMachine &TM, + ObjectCodeEmitter &OCE) { + return new Emitter(TM, OCE); +} template bool Emitter::runOnMachineFunction(MachineFunction &MF) { Modified: llvm/trunk/lib/Target/X86/X86TargetMachine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86TargetMachine.cpp (original) +++ llvm/trunk/lib/Target/X86/X86TargetMachine.cpp Mon Jul 6 00:09:34 2009 @@ -290,6 +290,36 @@ return false; } +bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE) { + // FIXME: Move this to TargetJITInfo! + // On Darwin, do not override 64-bit setting made in X86TargetMachine(). + if (DefRelocModel == Reloc::Default && + (!Subtarget.isTargetDarwin() || !Subtarget.is64Bit())) + setRelocationModel(Reloc::Static); + + // 64-bit JIT places everything in the same buffer except external functions. + // On Darwin, use small code model but hack the call instruction for + // externals. Elsewhere, do not assume globals are in the lower 4G. + if (Subtarget.is64Bit()) { + if (Subtarget.isTargetDarwin()) + setCodeModel(CodeModel::Small); + else + setCodeModel(CodeModel::Large); + } + + PM.add(createX86ObjectCodeEmitterPass(*this, OCE)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(errs(), *this, true)); + } + + return false; +} + bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, @@ -318,3 +348,16 @@ return false; } +bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, + ObjectCodeEmitter &OCE) { + PM.add(createX86ObjectCodeEmitterPass(*this, OCE)); + if (DumpAsm) { + assert(AsmPrinterCtor && "AsmPrinter was not linked in"); + if (AsmPrinterCtor) + PM.add(AsmPrinterCtor(errs(), *this, true)); + } + + return false; +} Modified: llvm/trunk/lib/Target/X86/X86TargetMachine.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86TargetMachine.h (original) +++ llvm/trunk/lib/Target/X86/X86TargetMachine.h Mon Jul 6 00:09:34 2009 @@ -84,12 +84,17 @@ bool DumpAsm, MachineCodeEmitter &MCE); virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &JCE); + virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &OCE); virtual bool addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, MachineCodeEmitter &MCE); virtual bool addSimpleCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, bool DumpAsm, JITCodeEmitter &JCE); + virtual bool addSimpleCodeEmitter(PassManagerBase &PM, + CodeGenOpt::Level OptLevel, + bool DumpAsm, ObjectCodeEmitter &OCE); }; /// X86_32TargetMachine - X86 32-bit target machine. Modified: llvm/trunk/tools/llc/llc.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/tools/llc/llc.cpp (original) +++ llvm/trunk/tools/llc/llc.cpp Mon Jul 6 00:09:34 2009 @@ -17,6 +17,7 @@ #include "llvm/CodeGen/FileWriters.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" #include "llvm/Target/SubtargetFeature.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" @@ -312,7 +313,7 @@ #endif // Ask the target to add backend passes as necessary. - MachineCodeEmitter *MCE = 0; + ObjectCodeEmitter *OCE = 0; // Override default to generate verbose assembly. Target.setAsmVerbosityDefault(true); @@ -331,14 +332,14 @@ case FileModel::AsmFile: break; case FileModel::MachOFile: - MCE = AddMachOWriter(Passes, *Out, Target); + OCE = AddMachOWriter(Passes, *Out, Target); break; case FileModel::ElfFile: - MCE = AddELFWriter(Passes, *Out, Target); + OCE = AddELFWriter(Passes, *Out, Target); break; } - if (Target.addPassesToEmitFileFinish(Passes, MCE, OLvl)) { + if (Target.addPassesToEmitFileFinish(Passes, OCE, OLvl)) { std::cerr << argv[0] << ": target does not support generation of this" << " file type!\n"; if (Out != &outs()) delete Out; Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=74813&r1=74812&r2=74813&view=diff ============================================================================== --- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original) +++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Mon Jul 6 00:09:34 2009 @@ -430,16 +430,16 @@ codeGenPasses->add(new TargetData(*_target->getTargetData())); - MachineCodeEmitter* mce = NULL; + ObjectCodeEmitter* oce = NULL; switch (_target->addPassesToEmitFile(*codeGenPasses, out, TargetMachine::AssemblyFile, CodeGenOpt::Aggressive)) { case FileModel::MachOFile: - mce = AddMachOWriter(*codeGenPasses, out, *_target); + oce = AddMachOWriter(*codeGenPasses, out, *_target); break; case FileModel::ElfFile: - mce = AddELFWriter(*codeGenPasses, out, *_target); + oce = AddELFWriter(*codeGenPasses, out, *_target); break; case FileModel::AsmFile: break; @@ -449,7 +449,7 @@ return true; } - if (_target->addPassesToEmitFileFinish(*codeGenPasses, mce, + if (_target->addPassesToEmitFileFinish(*codeGenPasses, oce, CodeGenOpt::Aggressive)) { errMsg = "target does not support generation of this file type"; return true; From bruno.cardoso at gmail.com Mon Jul 6 00:14:39 2009 From: bruno.cardoso at gmail.com (Bruno Cardoso Lopes) Date: Mon, 6 Jul 2009 02:14:39 -0300 Subject: [llvm-commits] [llvm] r74813 - in /llvm/trunk: include/llvm/CodeGen/ include/llvm/Target/ lib/CodeGen/ lib/Target/ARM/ lib/Target/Alpha/ lib/Target/PowerPC/ lib/Target/X86/ tools/llc/ tools/lto/ In-Reply-To: <200907060509.n6659Zbt026565@zion.cs.uiuc.edu> References: <200907060509.n6659Zbt026565@zion.cs.uiuc.edu> Message-ID: <275e64e40907052214r45b51489i1631eaa19f92b834@mail.gmail.com> Aaron asked me to include the original patch documentation, attached now. On Mon, Jul 6, 2009 at 2:09 AM, Bruno Cardoso Lopes wrote: > Author: bruno > Date: Mon Jul ?6 00:09:34 2009 > New Revision: 74813 > > URL: http://llvm.org/viewvc/llvm-project?rev=74813&view=rev > Log: > Add the Object Code Emitter class. Original patch by Aaron Gray, I did some > cleanup, removed some #includes and moved Object Code Emitter out-of-line. > > > Modified: > ? ?llvm/trunk/include/llvm/CodeGen/BinaryObject.h > ? ?llvm/trunk/include/llvm/CodeGen/FileWriters.h > ? ?llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h > ? ?llvm/trunk/include/llvm/Target/TargetMachine.h > ? ?llvm/trunk/lib/CodeGen/ELFWriter.cpp > ? ?llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp > ? ?llvm/trunk/lib/CodeGen/MachO.h > ? ?llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp > ? ?llvm/trunk/lib/CodeGen/MachOCodeEmitter.h > ? ?llvm/trunk/lib/CodeGen/MachOWriter.cpp > ? ?llvm/trunk/lib/CodeGen/MachOWriter.h > ? ?llvm/trunk/lib/Target/ARM/ARM.h > ? ?llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp > ? ?llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp > ? ?llvm/trunk/lib/Target/ARM/ARMTargetMachine.h > ? ?llvm/trunk/lib/Target/Alpha/Alpha.h > ? ?llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp > ? ?llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp > ? ?llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h > ? ?llvm/trunk/lib/Target/PowerPC/PPC.h > ? ?llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp > ? ?llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp > ? ?llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h > ? ?llvm/trunk/lib/Target/X86/X86.h > ? ?llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp > ? ?llvm/trunk/lib/Target/X86/X86TargetMachine.cpp > ? ?llvm/trunk/lib/Target/X86/X86TargetMachine.h > ? ?llvm/trunk/tools/llc/llc.cpp > ? ?llvm/trunk/tools/lto/LTOCodeGenerator.cpp > > Modified: llvm/trunk/include/llvm/CodeGen/BinaryObject.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/BinaryObject.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/include/llvm/CodeGen/BinaryObject.h (original) > +++ llvm/trunk/include/llvm/CodeGen/BinaryObject.h Mon Jul ?6 00:09:34 2009 > @@ -146,27 +146,27 @@ > ? /// emitDWordLE - This callback is invoked when a 64-bit word needs to be > ? /// written to the data stream in little-endian format. > ? inline void emitDWordLE(uint64_t W) { > - ? ?Data.push_back(unsigned(W >> ?0) & 255); > - ? ?Data.push_back(unsigned(W >> ?8) & 255); > - ? ?Data.push_back(unsigned(W >> 16) & 255); > - ? ?Data.push_back(unsigned(W >> 24) & 255); > - ? ?Data.push_back(unsigned(W >> 32) & 255); > - ? ?Data.push_back(unsigned(W >> 40) & 255); > - ? ?Data.push_back(unsigned(W >> 48) & 255); > - ? ?Data.push_back(unsigned(W >> 56) & 255); > + ? ?Data.push_back((W >> ?0) & 255); > + ? ?Data.push_back((W >> ?8) & 255); > + ? ?Data.push_back((W >> 16) & 255); > + ? ?Data.push_back((W >> 24) & 255); > + ? ?Data.push_back((W >> 32) & 255); > + ? ?Data.push_back((W >> 40) & 255); > + ? ?Data.push_back((W >> 48) & 255); > + ? ?Data.push_back((W >> 56) & 255); > ? } > > ? /// emitDWordBE - This callback is invoked when a 64-bit word needs to be > ? /// written to the data stream in big-endian format. > ? inline void emitDWordBE(uint64_t W) { > - ? ?Data.push_back(unsigned(W >> 56) & 255); > - ? ?Data.push_back(unsigned(W >> 48) & 255); > - ? ?Data.push_back(unsigned(W >> 40) & 255); > - ? ?Data.push_back(unsigned(W >> 32) & 255); > - ? ?Data.push_back(unsigned(W >> 24) & 255); > - ? ?Data.push_back(unsigned(W >> 16) & 255); > - ? ?Data.push_back(unsigned(W >> ?8) & 255); > - ? ?Data.push_back(unsigned(W >> ?0) & 255); > + ? ?Data.push_back((W >> 56) & 255); > + ? ?Data.push_back((W >> 48) & 255); > + ? ?Data.push_back((W >> 40) & 255); > + ? ?Data.push_back((W >> 32) & 255); > + ? ?Data.push_back((W >> 24) & 255); > + ? ?Data.push_back((W >> 16) & 255); > + ? ?Data.push_back((W >> ?8) & 255); > + ? ?Data.push_back((W >> ?0) & 255); > ? } > > ? /// fixByte - This callback is invoked when a byte needs to be > @@ -270,11 +270,11 @@ > ? } > > ? /// emitAlignment - Pad the data to the specified alignment. > - ?void emitAlignment(unsigned Alignment) { > + ?void emitAlignment(unsigned Alignment, uint8_t fill = 0) { > ? ? if (Alignment <= 1) return; > ? ? unsigned PadSize = -Data.size() & (Alignment-1); > ? ? for (unsigned i = 0; i - ? ? ?Data.push_back(0); > + ? ? ?Data.push_back(fill); > ? } > > ? /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be > > Modified: llvm/trunk/include/llvm/CodeGen/FileWriters.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/FileWriters.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/include/llvm/CodeGen/FileWriters.h (original) > +++ llvm/trunk/include/llvm/CodeGen/FileWriters.h Mon Jul ?6 00:09:34 2009 > @@ -17,14 +17,14 @@ > ?namespace llvm { > > ? class PassManagerBase; > - ?class MachineCodeEmitter; > + ?class ObjectCodeEmitter; > ? class TargetMachine; > ? class raw_ostream; > > - ?MachineCodeEmitter *AddELFWriter(PassManagerBase &FPM, raw_ostream &O, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TargetMachine &TM); > - ?MachineCodeEmitter *AddMachOWriter(PassManagerBase &FPM, raw_ostream &O, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? TargetMachine &TM); > + ?ObjectCodeEmitter *AddELFWriter(PassManagerBase &FPM, raw_ostream &O, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TargetMachine &TM); > + ?ObjectCodeEmitter *AddMachOWriter(PassManagerBase &FPM, raw_ostream &O, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TargetMachine &TM); > > ?} // end llvm namespace > > > Modified: llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h (original) > +++ llvm/trunk/include/llvm/CodeGen/MachineCodeEmitter.h Mon Jul ?6 00:09:34 2009 > @@ -74,24 +74,6 @@ > ? /// false. > ? /// > ? virtual bool finishFunction(MachineFunction &F) = 0; > - > - ?/// startGVStub - This callback is invoked when the JIT needs the > - ?/// address of a GV (e.g. function) that has not been code generated yet. > - ?/// The StubSize specifies the total size required by the stub. > - ?/// > - ?virtual void startGVStub(const GlobalValue* GV, unsigned StubSize, > - ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned Alignment = 1) = 0; > - > - ?/// startGVStub - This callback is invoked when the JIT needs the address of a > - ?/// GV (e.g. function) that has not been code generated yet. ?Buffer points to > - ?/// memory already allocated for this stub. > - ?/// > - ?virtual void startGVStub(const GlobalValue* GV, void *Buffer, > - ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned StubSize) = 0; > - > - ?/// finishGVStub - This callback is invoked to terminate a GV stub. > - ?/// > - ?virtual void *finishGVStub(const GlobalValue* F) = 0; > > ? /// emitByte - This callback is invoked when a byte needs to be written to the > ? /// output stream. > @@ -288,14 +270,13 @@ > > ? /// getCurrentPCOffset - Return the offset from the start of the emitted > ? /// buffer that we are currently writing to. > - ?uintptr_t getCurrentPCOffset() const { > + ?virtual uintptr_t getCurrentPCOffset() const { > ? ? return CurBufferPtr-BufferBegin; > ? } > > ? /// addRelocation - Whenever a relocatable address is needed, it should be > ? /// noted with this interface. > ? virtual void addRelocation(const MachineRelocation &MR) = 0; > - > > ? /// FIXME: These should all be handled with relocations! > > > Modified: llvm/trunk/include/llvm/Target/TargetMachine.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/include/llvm/Target/TargetMachine.h (original) > +++ llvm/trunk/include/llvm/Target/TargetMachine.h Mon Jul ?6 00:09:34 2009 > @@ -29,6 +29,7 @@ > ?class TargetFrameInfo; > ?class MachineCodeEmitter; > ?class JITCodeEmitter; > +class ObjectCodeEmitter; > ?class TargetRegisterInfo; > ?class Module; > ?class PassManagerBase; > @@ -257,6 +258,16 @@ > ? ? return true; > ? } > > + ?/// addPassesToEmitFileFinish - If the passes to emit the specified file had > + ?/// to be split up (e.g., to add an object writer pass), this method can be > + ?/// used to finish up adding passes to emit the file, if necessary. > + ?/// > + ?virtual bool addPassesToEmitFileFinish(PassManagerBase &, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter *, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level) { > + ? ?return true; > + ?} > + > ? /// addPassesToEmitMachineCode - Add passes to the specified pass manager to > ? /// get machine code emitted. ?This uses a MachineCodeEmitter object to handle > ? /// actually outputting the machine code and resolving things like the address > @@ -335,7 +346,15 @@ > ? /// used to finish up adding passes to emit the file, if necessary. > ? /// > ? virtual bool addPassesToEmitFileFinish(PassManagerBase &PM, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter *MCE, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter *JCE, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level); > + > + ?/// addPassesToEmitFileFinish - If the passes to emit the specified file had > + ?/// to be split up (e.g., to add an object writer pass), this method can be > + ?/// used to finish up adding passes to emit the file, if necessary. > + ?/// > + ?virtual bool addPassesToEmitFileFinish(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter *OCE, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level); > > ? /// addPassesToEmitMachineCode - Add passes to the specified pass manager to > @@ -432,6 +451,15 @@ > ? ? return true; > ? } > > + ?/// addSimpleCodeEmitter - This pass should be overridden by the target to add > + ?/// a code emitter (without setting flags), if supported. ?If this is not > + ?/// supported, 'true' should be returned. ?If DumpAsm is true, the generated > + ?/// assembly is printed to cerr. > + ?virtual bool addSimpleCodeEmitter(PassManagerBase &, CodeGenOpt::Level, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool /*DumpAsm*/, ObjectCodeEmitter &) { > + ? ?return true; > + ?} > + > ? /// getEnableTailMergeDefault - the default setting for -enable-tail-merge > ? /// on this target. ?User flag overrides. > ? virtual bool getEnableTailMergeDefault() const { return true; } > > Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original) > +++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Mon Jul ?6 00:09:34 2009 > @@ -40,6 +40,8 @@ > ?#include "llvm/CodeGen/BinaryObject.h" > ?#include "llvm/CodeGen/FileWriters.h" > ?#include "llvm/CodeGen/MachineCodeEmitter.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > +#include "llvm/CodeGen/MachineCodeEmitter.h" > ?#include "llvm/CodeGen/MachineConstantPool.h" > ?#include "llvm/Target/TargetAsmInfo.h" > ?#include "llvm/Target/TargetData.h" > @@ -54,12 +56,12 @@ > ?char ELFWriter::ID = 0; > ?/// AddELFWriter - Concrete function to add the ELF writer to the function pass > ?/// manager. > -MachineCodeEmitter *llvm::AddELFWriter(PassManagerBase &PM, > +ObjectCodeEmitter *llvm::AddELFWriter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raw_ostream &O, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TargetMachine &TM) { > ? ELFWriter *EW = new ELFWriter(O, TM); > ? PM.add(EW); > - ?return &EW->getMachineCodeEmitter(); > + ?return (ObjectCodeEmitter*) &EW->getMachineCodeEmitter(); > ?} > > ?//===----------------------------------------------------------------------===// > > Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original) > +++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Mon Jul ?6 00:09:34 2009 > @@ -126,6 +126,23 @@ > ? return false; // success! > ?} > > +/// addPassesToEmitFileFinish - If the passes to emit the specified file had to > +/// be split up (e.g., to add an object writer pass), this method can be used to > +/// finish up adding passes to emit the file, if necessary. > +bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter *OCE, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel) { > + ?if (OCE) > + ? ?addSimpleCodeEmitter(PM, OptLevel, PrintEmittedAsm, *OCE); > + > + ?PM.add(createGCInfoDeleter()); > + > + ?// Delete machine code for this function > + ?PM.add(createMachineCodeDeleter()); > + > + ?return false; // success! > +} > + > ?/// addPassesToEmitMachineCode - Add passes to the specified pass manager to > ?/// get machine code emitted. ?This uses a MachineCodeEmitter object to handle > ?/// actually outputting the machine code and resolving things like the address > > Modified: llvm/trunk/lib/CodeGen/MachO.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachO.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/CodeGen/MachO.h (original) > +++ llvm/trunk/lib/CodeGen/MachO.h Mon Jul ?6 00:09:34 2009 > @@ -17,6 +17,7 @@ > ?#include "llvm/Constants.h" > ?#include "llvm/DerivedTypes.h" > ?#include "llvm/CodeGen/MachineRelocation.h" > +#include "llvm/CodeGen/BinaryObject.h" > ?#include "llvm/Target/TargetAsmInfo.h" > ?#include > ?#include > @@ -272,11 +273,10 @@ > ?/// turned into the SectionCommand in the load command for a particlar > ?/// segment. > > -struct MachOSection { > +struct MachOSection : public BinaryObject { > ? std::string ?sectname; // name of this section, > ? std::string ?segname; ?// segment this section goes in > ? uint64_t ?addr; ? ? ? ?// memory address of this section > - ?uint64_t ?size; ? ? ? ?// size in bytes of this section > ? uint32_t ?offset; ? ? ?// file offset of this section > ? uint32_t ?align; ? ? ? // section alignment (power of 2) > ? uint32_t ?reloff; ? ? ?// file offset of relocation entries > @@ -290,19 +290,10 @@ > ? /// to the correct section. > ? uint32_t Index; > > - ?/// SectionData - The actual data for this section which we are building > - ?/// up for emission to the file. > - ?DataBuffer SectionData; > - > ? /// RelocBuffer - A buffer to hold the mach-o relocations before we write > ? /// them out at the appropriate location in the file. > ? DataBuffer RelocBuffer; > > - ?/// Relocations - The relocations that we have encountered so far in this > - ?/// section that we will need to convert to MachORelocation entries when > - ?/// the file is written. > - ?std::vector Relocations; > - > ? // Constants for the section types (low 8 bits of flags field) > ? // see > ? enum { S_REGULAR = 0, > @@ -374,48 +365,49 @@ > ? } > > ? MachOSection(const std::string &seg, const std::string §) > - ? ?: sectname(sect), segname(seg), addr(0), size(0), offset(0), align(2), > - ? ? ?reloff(0), nreloc(0), flags(0), reserved1(0), reserved2(0), > + ? ?: BinaryObject(), sectname(sect), segname(seg), addr(0), offset(0), > + ? ? ?align(2), reloff(0), nreloc(0), flags(0), reserved1(0), reserved2(0), > ? ? ? reserved3(0) { } > > ?}; // end struct MachOSection > > - ? ?/// MachOSymTab - This struct contains information about the offsets and > - ? ?/// size of symbol table information. > - ? ?/// segment. > - ? ?struct MachODySymTab { > - ? ? ?uint32_t cmd; ? ? ? ? ? ? // LC_DYSYMTAB > - ? ? ?uint32_t cmdsize; ? ? ? ? // sizeof( MachODySymTab ) > - ? ? ?uint32_t ilocalsym; ? ? ? // index to local symbols > - ? ? ?uint32_t nlocalsym; ? ? ? // number of local symbols > - ? ? ?uint32_t iextdefsym; ? ? ?// index to externally defined symbols > - ? ? ?uint32_t nextdefsym; ? ? ?// number of externally defined symbols > - ? ? ?uint32_t iundefsym; ? ? ? // index to undefined symbols > - ? ? ?uint32_t nundefsym; ? ? ? // number of undefined symbols > - ? ? ?uint32_t tocoff; ? ? ? ? ?// file offset to table of contents > - ? ? ?uint32_t ntoc; ? ? ? ? ? ?// number of entries in table of contents > - ? ? ?uint32_t modtaboff; ? ? ? // file offset to module table > - ? ? ?uint32_t nmodtab; ? ? ? ? // number of module table entries > - ? ? ?uint32_t extrefsymoff; ? ?// offset to referenced symbol table > - ? ? ?uint32_t nextrefsyms; ? ? // number of referenced symbol table entries > - ? ? ?uint32_t indirectsymoff; ?// file offset to the indirect symbol table > - ? ? ?uint32_t nindirectsyms; ? // number of indirect symbol table entries > - ? ? ?uint32_t extreloff; ? ? ? // offset to external relocation entries > - ? ? ?uint32_t nextrel; ? ? ? ? // number of external relocation entries > - ? ? ?uint32_t locreloff; ? ? ? // offset to local relocation entries > - ? ? ?uint32_t nlocrel; ? ? ? ? // number of local relocation entries > - > - ? ? ?// Constants for the cmd field > - ? ? ?// see > - ? ? ?enum { LC_DYSYMTAB = 0x0B ?// dynamic link-edit symbol table info > - ? ? ?}; > - > - ? ? ?MachODySymTab() : cmd(LC_DYSYMTAB), cmdsize(20 * sizeof(uint32_t)), > - ? ? ? ?ilocalsym(0), nlocalsym(0), iextdefsym(0), nextdefsym(0), > - ? ? ? ?iundefsym(0), nundefsym(0), tocoff(0), ntoc(0), modtaboff(0), > - ? ? ? ?nmodtab(0), extrefsymoff(0), nextrefsyms(0), indirectsymoff(0), > - ? ? ? ?nindirectsyms(0), extreloff(0), nextrel(0), locreloff(0), nlocrel(0) { } > - ? ?}; > +/// MachOSymTab - This struct contains information about the offsets and > +/// size of symbol table information. > +/// segment. > +struct MachODySymTab { > + ?uint32_t cmd; ? ? ? ? ? ? // LC_DYSYMTAB > + ?uint32_t cmdsize; ? ? ? ? // sizeof(MachODySymTab) > + ?uint32_t ilocalsym; ? ? ? // index to local symbols > + ?uint32_t nlocalsym; ? ? ? // number of local symbols > + ?uint32_t iextdefsym; ? ? ?// index to externally defined symbols > + ?uint32_t nextdefsym; ? ? ?// number of externally defined symbols > + ?uint32_t iundefsym; ? ? ? // index to undefined symbols > + ?uint32_t nundefsym; ? ? ? // number of undefined symbols > + ?uint32_t tocoff; ? ? ? ? ?// file offset to table of contents > + ?uint32_t ntoc; ? ? ? ? ? ?// number of entries in table of contents > + ?uint32_t modtaboff; ? ? ? // file offset to module table > + ?uint32_t nmodtab; ? ? ? ? // number of module table entries > + ?uint32_t extrefsymoff; ? ?// offset to referenced symbol table > + ?uint32_t nextrefsyms; ? ? // number of referenced symbol table entries > + ?uint32_t indirectsymoff; ?// file offset to the indirect symbol table > + ?uint32_t nindirectsyms; ? // number of indirect symbol table entries > + ?uint32_t extreloff; ? ? ? // offset to external relocation entries > + ?uint32_t nextrel; ? ? ? ? // number of external relocation entries > + ?uint32_t locreloff; ? ? ? // offset to local relocation entries > + ?uint32_t nlocrel; ? ? ? ? // number of local relocation entries > + > + ?// Constants for the cmd field > + ?// see > + ?enum { LC_DYSYMTAB = 0x0B ?// dynamic link-edit symbol table info > + ?}; > + > + ?MachODySymTab() : cmd(LC_DYSYMTAB), cmdsize(20 * sizeof(uint32_t)), > + ? ?ilocalsym(0), nlocalsym(0), iextdefsym(0), nextdefsym(0), > + ? ?iundefsym(0), nundefsym(0), tocoff(0), ntoc(0), modtaboff(0), > + ? ?nmodtab(0), extrefsymoff(0), nextrefsyms(0), indirectsymoff(0), > + ? ?nindirectsyms(0), extreloff(0), nextrel(0), locreloff(0), nlocrel(0) { } > + > +}; // end struct MachODySymTab > > ?} // end namespace llvm > > > Modified: llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp (original) > +++ llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp Mon Jul ?6 00:09:34 2009 > @@ -16,6 +16,7 @@ > ?#include "llvm/Target/TargetAsmInfo.h" > ?#include "llvm/Support/Mangler.h" > ?#include "llvm/Support/OutputBuffer.h" > +#include > > ?//===----------------------------------------------------------------------===// > ?// ? ? ? ? ? ? ? ? ? ? ? MachOCodeEmitter Implementation > @@ -39,28 +40,18 @@ > ? // Get the Mach-O Section that this function belongs in. > ? MachOSection *MOS = MOW.getTextSection(); > > - ?// FIXME: better memory management > - ?MOS->SectionData.reserve(4096); > - ?BufferBegin = &MOS->SectionData[0]; > - ?BufferEnd = BufferBegin + MOS->SectionData.capacity(); > - > ? // Upgrade the section alignment if required. > ? if (MOS->align < Align) MOS->align = Align; > > - ?// Round the size up to the correct alignment for starting the new function. > - ?if ((MOS->size & ((1 << Align) - 1)) != 0) { > - ? ?MOS->size += (1 << Align); > - ? ?MOS->size &= ~((1 << Align) - 1); > - ?} > + ?MOS->emitAlignment(Align); > > - ?// FIXME: Using MOS->size directly here instead of calculating it from the > - ?// output buffer size (impossible because the code emitter deals only in raw > - ?// bytes) forces us to manually synchronize size and write padding zero bytes > - ?// to the output buffer for all non-text sections. ?For text sections, we do > - ?// not synchonize the output buffer, and we just blow up if anyone tries to > - ?// write non-code to it. ?An assert should probably be added to > - ?// AddSymbolToSection to prevent calling it on the text section. > - ?CurBufferPtr = BufferBegin + MOS->size; > + ?// Create symbol for function entry > + ?const GlobalValue *FuncV = MF.getFunction(); > + ?MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TAI); > + ?FnSym.n_value = getCurrentPCOffset(); > + > + ?// add it to the symtab. > + ?MOW.SymbolTable.push_back(FnSym); > ?} > > ?/// finishFunction - This callback is invoked after the function is completely > @@ -71,15 +62,6 @@ > ? // Get the Mach-O Section that this function belongs in. > ? MachOSection *MOS = MOW.getTextSection(); > > - ?// Get a symbol for the function to add to the symbol table > - ?// FIXME: it seems like we should call something like AddSymbolToSection > - ?// in startFunction rather than changing the section size and symbol n_value > - ?// here. > - ?const GlobalValue *FuncV = MF.getFunction(); > - ?MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TAI); > - ?FnSym.n_value = MOS->size; > - ?MOS->size = CurBufferPtr - BufferBegin; > - > ? // Emit constant pool to appropriate section(s) > ? emitConstantPool(MF.getConstantPool()); > > @@ -112,12 +94,9 @@ > ? ? } else { > ? ? ? assert(0 && "Unhandled relocation type"); > ? ? } > - ? ?MOS->Relocations.push_back(MR); > + ? ?MOS->addRelocation(MR); > ? } > ? Relocations.clear(); > - > - ?// Finally, add it to the symtab. > - ?MOW.SymbolTable.push_back(FnSym); > > ? // Clear per-function data structures. > ? CPLocations.clear(); > @@ -151,13 +130,10 @@ > ? ? unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); > > ? ? MachOSection *Sec = MOW.getConstSection(CP[i].Val.ConstVal); > - ? ?OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); > + ? ?OutputBuffer SecDataOut(Sec->getData(), is64Bit, isLittleEndian); > > - ? ?CPLocations.push_back(Sec->SectionData.size()); > + ? ?CPLocations.push_back(Sec->size()); > ? ? CPSections.push_back(Sec->Index); > - > - ? ?// FIXME: remove when we have unified size + output buffer > - ? ?Sec->size += Size; > > ? ? // Allocate space in the section for the global. > ? ? // FIXME: need alignment? > @@ -165,14 +141,12 @@ > ? ? for (unsigned j = 0; j < Size; ++j) > ? ? ? SecDataOut.outbyte(0); > > - ? ?MOW.InitMem(CP[i].Val.ConstVal, &Sec->SectionData[0], CPLocations[i], > - ? ? ? ? ? ? ? ?TM.getTargetData(), Sec->Relocations); > + ? ?MachOWriter::InitMem(CP[i].Val.ConstVal, CPLocations[i], TM.getTargetData(), Sec); > ? } > ?} > > ?/// emitJumpTables - Emit all the jump tables for a given jump table info > ?/// record to the appropriate section. > - > ?void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) { > ? const std::vector &JT = MJTI->getJumpTables(); > ? if (JT.empty()) return; > @@ -183,24 +157,21 @@ > > ? MachOSection *Sec = MOW.getJumpTableSection(); > ? unsigned TextSecIndex = MOW.getTextSection()->Index; > - ?OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); > + ?OutputBuffer SecDataOut(Sec->getData(), is64Bit, isLittleEndian); > > ? for (unsigned i = 0, e = JT.size(); i != e; ++i) { > ? ? // For each jump table, record its offset from the start of the section, > ? ? // reserve space for the relocations to the MBBs, and add the relocations. > ? ? const std::vector &MBBs = JT[i].MBBs; > - ? ?JTLocations.push_back(Sec->SectionData.size()); > + ? ?JTLocations.push_back(Sec->size()); > ? ? for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi) { > - ? ? ?MachineRelocation MR(MOW.GetJTRelocation(Sec->SectionData.size(), > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MBBs[mi])); > + ? ? ?MachineRelocation MR(MOW.GetJTRelocation(Sec->size(), MBBs[mi])); > ? ? ? MR.setResultPointer((void *)JTLocations[i]); > ? ? ? MR.setConstantVal(TextSecIndex); > - ? ? ?Sec->Relocations.push_back(MR); > + ? ? ?Sec->addRelocation(MR); > ? ? ? SecDataOut.outaddr(0); > ? ? } > ? } > - ?// FIXME: remove when we have unified size + output buffer > - ?Sec->size = Sec->SectionData.size(); > ?} > > ?} // end namespace llvm > > Modified: llvm/trunk/lib/CodeGen/MachOCodeEmitter.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOCodeEmitter.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/CodeGen/MachOCodeEmitter.h (original) > +++ llvm/trunk/lib/CodeGen/MachOCodeEmitter.h Mon Jul ?6 00:09:34 2009 > @@ -11,15 +11,13 @@ > ?#define MACHOCODEEMITTER_H > > ?#include "MachOWriter.h" > -#include "llvm/CodeGen/MachineCodeEmitter.h" > -#include > > ?namespace llvm { > > ?/// MachOCodeEmitter - This class is used by the MachOWriter to emit the code > ?/// for functions to the Mach-O file. > > -class MachOCodeEmitter : public MachineCodeEmitter { > +class MachOCodeEmitter : public ObjectCodeEmitter { > ? MachOWriter &MOW; > > ? /// Target machine description. > @@ -34,27 +32,12 @@ > ? /// Relocations - These are the relocations that the function needs, as > ? /// emitted. > ? std::vector Relocations; > - > - ?/// CPLocations - This is a map of constant pool indices to offsets from the > - ?/// start of the section for that constant pool index. > - ?std::vector CPLocations; > - > - ?/// CPSections - This is a map of constant pool indices to the MachOSection > - ?/// containing the constant pool entry for that index. > - ?std::vector CPSections; > - > - ?/// JTLocations - This is a map of jump table indices to offsets from the > - ?/// start of the section for that jump table index. > - ?std::vector JTLocations; > - > - ?/// MBBLocations - This vector is a mapping from MBB ID's to their address. > - ?/// It is filled in by the StartMachineBasicBlock callback and queried by > - ?/// the getMachineBasicBlockAddress callback. > - ?std::vector MBBLocations; > - > + > + ?std::map Labels; > + > ?public: > - ?MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM) > - ?{ > + ?MachOCodeEmitter(MachOWriter &mow, MachOSection &mos) : > + ? ? ? ?ObjectCodeEmitter(&mos), MOW(mow), TM(MOW.TM) { > ? ? is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; > ? ? isLittleEndian = TM.getTargetData()->isLittleEndian(); > ? ? TAI = TM.getTargetAsmInfo(); > @@ -69,58 +52,17 @@ > > ? void emitConstantPool(MachineConstantPool *MCP); > ? void emitJumpTables(MachineJumpTableInfo *MJTI); > - > - ?virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const { > - ? ?assert(CPLocations.size() > Index && "CP not emitted!"); > - ? ?return CPLocations[Index]; > - ?} > - ?virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const { > - ? ?assert(JTLocations.size() > Index && "JT not emitted!"); > - ? ?return JTLocations[Index]; > - ?} > - > - ?virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) { > - ? ?if (MBBLocations.size() <= (unsigned)MBB->getNumber()) > - ? ? ?MBBLocations.resize((MBB->getNumber()+1)*2); > - ? ?MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); > - ?} > > - ?virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const { > - ? ?assert(MBBLocations.size() > (unsigned)MBB->getNumber() && > - ? ? ? ? ? MBBLocations[MBB->getNumber()] && "MBB not emitted!"); > - ? ?return MBBLocations[MBB->getNumber()]; > + ?virtual void emitLabel(uint64_t LabelID) { > + ? ?Labels[LabelID] = getCurrentPCOffset(); > ? } > > ? virtual uintptr_t getLabelAddress(uint64_t Label) const { > - ? ?assert(0 && "get Label not implemented"); > - ? ?abort(); > - ? ?return 0; > - ?} > - > - ?virtual void emitLabel(uint64_t LabelID) { > - ? ?assert(0 && "emit Label not implemented"); > - ? ?abort(); > + ? ?return Labels.find(Label)->second; > ? } > > ? virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { } > > - ?/// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE! > - ?virtual void startGVStub(const GlobalValue* F, unsigned StubSize, > - ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned Alignment = 1) { > - ? ?assert(0 && "JIT specific function called!"); > - ? ?abort(); > - ?} > - ?virtual void startGVStub(const GlobalValue* F, void *Buffer, > - ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned StubSize) { > - ? ?assert(0 && "JIT specific function called!"); > - ? ?abort(); > - ?} > - ?virtual void *finishGVStub(const GlobalValue* F) { > - ? ?assert(0 && "JIT specific function called!"); > - ? ?abort(); > - ? ?return 0; > - ?} > - > ?}; // end class MachOCodeEmitter > > ?} // end namespace llvm > > Modified: llvm/trunk/lib/CodeGen/MachOWriter.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/CodeGen/MachOWriter.cpp (original) > +++ llvm/trunk/lib/CodeGen/MachOWriter.cpp Mon Jul ?6 00:09:34 2009 > @@ -46,12 +46,12 @@ > > ?/// AddMachOWriter - Concrete function to add the Mach-O writer to the function > ?/// pass manager. > -MachineCodeEmitter *AddMachOWriter(PassManagerBase &PM, > +ObjectCodeEmitter *AddMachOWriter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?raw_ostream &O, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TargetMachine &TM) { > ? MachOWriter *MOW = new MachOWriter(O, TM); > ? PM.add(MOW); > - ?return &MOW->getMachineCodeEmitter(); > + ?return MOW->getObjectCodeEmitter(); > ?} > > ?//===----------------------------------------------------------------------===// > @@ -60,8 +60,9 @@ > > ?char MachOWriter::ID = 0; > > -MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm) > - ?: MachineFunctionPass(&ID), O(o), TM(tm) { > +MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm) > + ?: MachineFunctionPass(&ID), O(o), TM(tm) > + ?{ > ? is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; > ? isLittleEndian = TM.getTargetData()->isLittleEndian(); > > @@ -69,11 +70,11 @@ > > ? // Create the machine code emitter object for this target. > > - ?MCE = new MachOCodeEmitter(*this); > + ?MachOCE = new MachOCodeEmitter(*this, *getTextSection(true)); > ?} > > ?MachOWriter::~MachOWriter() { > - ?delete MCE; > + ?delete MachOCE; > ?} > > ?bool MachOWriter::doInitialization(Module &M) { > @@ -97,13 +98,13 @@ > ?/// the Mach-O file to 'O'. > ?bool MachOWriter::doFinalization(Module &M) { > ? // FIXME: we don't handle debug info yet, we should probably do that. > - > - ?// Okay, the.text section has been completed, build the .data, .bss, and > + ?// Okay, the.text section has been completed, build the .data, .bss, and > ? // "common" sections next. > + > ? for (Module::global_iterator I = M.global_begin(), E = M.global_end(); > ? ? ? ?I != E; ++I) > ? ? EmitGlobal(I); > - > + > ? // Emit the header and load commands. > ? EmitHeaderAndLoadCommands(); > > @@ -133,38 +134,32 @@ > ? // Reserve space in the .bss section for this symbol while maintaining the > ? // desired section alignment, which must be at least as much as required by > ? // this symbol. > - ?OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); > + ?OutputBuffer SecDataOut(Sec->getData(), is64Bit, isLittleEndian); > > ? if (Align) { > - ? ?uint64_t OrigSize = Sec->size; > ? ? Align = Log2_32(Align); > ? ? Sec->align = std::max(unsigned(Sec->align), Align); > - ? ?Sec->size = (Sec->size + Align - 1) & ~(Align-1); > > - ? ?// Add alignment padding to buffer as well. > - ? ?// FIXME: remove when we have unified size + output buffer > - ? ?unsigned AlignedSize = Sec->size - OrigSize; > - ? ?for (unsigned i = 0; i < AlignedSize; ++i) > - ? ? ?SecDataOut.outbyte(0); > + ? ?Sec->emitAlignment(Sec->align); > ? } > ? // Globals without external linkage apparently do not go in the symbol table. > ? if (!GV->hasLocalLinkage()) { > ? ? MachOSym Sym(GV, Mang->getValueName(GV), Sec->Index, TAI); > - ? ?Sym.n_value = Sec->size; > + ? ?Sym.n_value = Sec->size(); > ? ? SymbolTable.push_back(Sym); > ? } > > ? // Record the offset of the symbol, and then allocate space for it. > ? // FIXME: remove when we have unified size + output buffer > - ?Sec->size += Size; > - > - ?// Now that we know what section the GlovalVariable is going to be emitted > + > + ?// Now that we know what section the GlovalVariable is going to be emitted > ? // into, update our mappings. > ? // FIXME: We may also need to update this when outputting non-GlobalVariable > ? // GlobalValues such as functions. > - ?GVSection[GV] = Sec; > - ?GVOffset[GV] = Sec->SectionData.size(); > > + ?GVSection[GV] = Sec; > + ?GVOffset[GV] = Sec->size(); > + > ? // Allocate space in the section for the global. > ? for (unsigned i = 0; i < Size; ++i) > ? ? SecDataOut.outbyte(0); > @@ -174,7 +169,7 @@ > ? const Type *Ty = GV->getType()->getElementType(); > ? unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); > ? bool NoInit = !GV->hasInitializer(); > - > + > ? // If this global has a zero initializer, it is part of the .bss or common > ? // section. > ? if (NoInit || GV->getInitializer()->isNullValue()) { > @@ -183,8 +178,7 @@ > ? ? // merged with other symbols. > ? ? if (NoInit || GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() || > ? ? ? ? GV->hasCommonLinkage()) { > - ? ? ?MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV), > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MachOSym::NO_SECT, TAI); > + ? ? ?MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV), MachOSym::NO_SECT, TAI); > ? ? ? // For undefined (N_UNDF) external (N_EXT) types, n_value is the size in > ? ? ? // bytes of the symbol. > ? ? ? ExtOrCommonSym.n_value = Size; > @@ -198,15 +192,14 @@ > ? ? AddSymbolToSection(BSS, GV); > ? ? return; > ? } > - > + > ? // Scalar read-only data goes in a literal section if the scalar is 4, 8, or > ? // 16 bytes, or a cstring. ?Other read only data goes into a regular const > ? // section. ?Read-write data goes in the data section. > - ?MachOSection *Sec = GV->isConstant() ? getConstSection(GV->getInitializer()) : > + ?MachOSection *Sec = GV->isConstant() ? getConstSection(GV->getInitializer()) : > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?getDataSection(); > ? AddSymbolToSection(Sec, GV); > - ?InitMem(GV->getInitializer(), &Sec->SectionData[0], GVOffset[GV], > - ? ? ? ? ?TM.getTargetData(), Sec->Relocations); > + ?InitMem(GV->getInitializer(), GVOffset[GV], TM.getTargetData(), Sec); > ?} > > > @@ -214,21 +207,22 @@ > ?void MachOWriter::EmitHeaderAndLoadCommands() { > ? // Step #0: Fill in the segment load command size, since we need it to figure > ? // ? ? ? ? ?out the rest of the header fields > + > ? MachOSegment SEG("", is64Bit); > ? SEG.nsects ?= SectionList.size(); > - ?SEG.cmdsize = SEG.cmdSize(is64Bit) + > + ?SEG.cmdsize = SEG.cmdSize(is64Bit) + > ? ? ? ? ? ? ? ? SEG.nsects * SectionList[0]->cmdSize(is64Bit); > - > + > ? // Step #1: calculate the number of load commands. ?We always have at least > ? // ? ? ? ? ?one, for the LC_SEGMENT load command, plus two for the normal > ? // ? ? ? ? ?and dynamic symbol tables, if there are any symbols. > ? Header.ncmds = SymbolTable.empty() ? 1 : 3; > - > + > ? // Step #2: calculate the size of the load commands > ? Header.sizeofcmds = SEG.cmdsize; > ? if (!SymbolTable.empty()) > ? ? Header.sizeofcmds += SymTab.cmdsize + DySymTab.cmdsize; > - > + > ? // Step #3: write the header to the file > ? // Local alias to shortenify coming code. > ? DataBuffer &FH = Header.HeaderData; > @@ -243,15 +237,15 @@ > ? FHOut.outword(Header.flags); > ? if (is64Bit) > ? ? FHOut.outword(Header.reserved); > - > + > ? // Step #4: Finish filling in the segment load command and write it out > ? for (std::vector::iterator I = SectionList.begin(), > ? ? ? ? ?E = SectionList.end(); I != E; ++I) > - ? ?SEG.filesize += (*I)->size; > + ? ?SEG.filesize += (*I)->size(); > > ? SEG.vmsize = SEG.filesize; > ? SEG.fileoff = Header.cmdSize(is64Bit) + Header.sizeofcmds; > - > + > ? FHOut.outword(SEG.cmd); > ? FHOut.outword(SEG.cmdsize); > ? FHOut.outstring(SEG.segname, 16); > @@ -263,42 +257,42 @@ > ? FHOut.outword(SEG.initprot); > ? FHOut.outword(SEG.nsects); > ? FHOut.outword(SEG.flags); > - > - ?// Step #5: Finish filling in the fields of the MachOSections > + > + ?// Step #5: Finish filling in the fields of the MachOSections > ? uint64_t currentAddr = 0; > ? for (std::vector::iterator I = SectionList.begin(), > ? ? ? ? ?E = SectionList.end(); I != E; ++I) { > ? ? MachOSection *MOS = *I; > ? ? MOS->addr = currentAddr; > ? ? MOS->offset = currentAddr + SEG.fileoff; > - > ? ? // FIXME: do we need to do something with alignment here? > - ? ?currentAddr += MOS->size; > + ? ?currentAddr += MOS->size(); > ? } > - > + > ? // Step #6: Emit the symbol table to temporary buffers, so that we know the > ? // size of the string table when we write the next load command. ?This also > ? // sorts and assigns indices to each of the symbols, which is necessary for > ? // emitting relocations to externally-defined objects. > ? BufferSymbolAndStringTable(); > - > + > ? // Step #7: Calculate the number of relocations for each section and write out > ? // the section commands for each section > ? currentAddr += SEG.fileoff; > ? for (std::vector::iterator I = SectionList.begin(), > ? ? ? ? ?E = SectionList.end(); I != E; ++I) { > ? ? MachOSection *MOS = *I; > + > ? ? // Convert the relocations to target-specific relocations, and fill in the > ? ? // relocation offset for this section. > ? ? CalculateRelocations(*MOS); > ? ? MOS->reloff = MOS->nreloc ? currentAddr : 0; > ? ? currentAddr += MOS->nreloc * 8; > - > + > ? ? // write the finalized section command to the output buffer > ? ? FHOut.outstring(MOS->sectname, 16); > ? ? FHOut.outstring(MOS->segname, 16); > ? ? FHOut.outaddr(MOS->addr); > - ? ?FHOut.outaddr(MOS->size); > + ? ?FHOut.outaddr(MOS->size()); > ? ? FHOut.outword(MOS->offset); > ? ? FHOut.outword(MOS->align); > ? ? FHOut.outword(MOS->reloff); > @@ -309,7 +303,7 @@ > ? ? if (is64Bit) > ? ? ? FHOut.outword(MOS->reserved3); > ? } > - > + > ? // Step #8: Emit LC_SYMTAB/LC_DYSYMTAB load commands > ? SymTab.symoff ?= currentAddr; > ? SymTab.nsyms ? = SymbolTable.size(); > @@ -345,39 +339,40 @@ > ? FHOut.outword(DySymTab.nextrel); > ? FHOut.outword(DySymTab.locreloff); > ? FHOut.outword(DySymTab.nlocrel); > - > + > ? O.write((char*)&FH[0], FH.size()); > ?} > > ?/// EmitSections - Now that we have constructed the file header and load > ?/// commands, emit the data for each section to the file. > - > ?void MachOWriter::EmitSections() { > ? for (std::vector::iterator I = SectionList.begin(), > ? ? ? ? ?E = SectionList.end(); I != E; ++I) > ? ? // Emit the contents of each section > - ? ?O.write((char*)&(*I)->SectionData[0], (*I)->size); > + ? ?if ((*I)->size()) > + ? ? ?O.write((char*)&(*I)->getData()[0], (*I)->size()); > ?} > + > +/// EmitRelocations - emit relocation data from buffer. > ?void MachOWriter::EmitRelocations() { > ? for (std::vector::iterator I = SectionList.begin(), > ? ? ? ? ?E = SectionList.end(); I != E; ++I) > ? ? // Emit the relocation entry data for each section. > - ? ?O.write((char*)&(*I)->RelocBuffer[0], (*I)->RelocBuffer.size()); > + ? ?if ((*I)->RelocBuffer.size()) > + ? ? ?O.write((char*)&(*I)->RelocBuffer[0], (*I)->RelocBuffer.size()); > ?} > > ?/// BufferSymbolAndStringTable - Sort the symbols we encountered and assign them > ?/// each a string table index so that they appear in the correct order in the > ?/// output file. > - > ?void MachOWriter::BufferSymbolAndStringTable() { > ? // The order of the symbol table is: > ? // 1. local symbols > ? // 2. defined external symbols (sorted by name) > ? // 3. undefined external symbols (sorted by name) > - > + > ? // Before sorting the symbols, check the PendingGlobals for any undefined > ? // globals that need to be put in the symbol table. > - > ? for (std::vector::iterator I = PendingGlobals.begin(), > ? ? ? ? ?E = PendingGlobals.end(); I != E; ++I) { > ? ? if (GVOffset[*I] == 0 && GVSection[*I] == 0) { > @@ -389,19 +384,15 @@ > > ? // Sort the symbols by name, so that when we partition the symbols by scope > ? // of definition, we won't have to sort by name within each partition. > - > ? std::sort(SymbolTable.begin(), SymbolTable.end(), MachOSym::SymCmp()); > > - ?// Parition the symbol table entries so that all local symbols come before > + ?// Parition the symbol table entries so that all local symbols come before > ? // all symbols with external linkage. { 1 | 2 3 } > - > - ?std::partition(SymbolTable.begin(), SymbolTable.end(), > - ? ? ? ? ? ? ? ? MachOSym::PartitionByLocal); > - > + ?std::partition(SymbolTable.begin(), SymbolTable.end(), MachOSym::PartitionByLocal); > + > ? // Advance iterator to beginning of external symbols and partition so that > ? // all external symbols defined in this module come before all external > ? // symbols defined elsewhere. { 1 | 2 | 3 } > - > ? for (std::vector::iterator I = SymbolTable.begin(), > ? ? ? ? ?E = SymbolTable.end(); I != E; ++I) { > ? ? if (!MachOSym::PartitionByLocal(*I)) { > @@ -410,10 +401,9 @@ > ? ? } > ? } > > - ?// Calculate the starting index for each of the local, extern defined, and > + ?// Calculate the starting index for each of the local, extern defined, and > ? // undefined symbols, as well as the number of each to put in the LC_DYSYMTAB > ? // load command. > - > ? for (std::vector::iterator I = SymbolTable.begin(), > ? ? ? ? ?E = SymbolTable.end(); I != E; ++I) { > ? ? if (MachOSym::PartitionByLocal(*I)) { > @@ -427,10 +417,9 @@ > ? ? ? ++DySymTab.nundefsym; > ? ? } > ? } > - > + > ? // Write out a leading zero byte when emitting string table, for n_strx == 0 > ? // which means an empty string. > - > ? OutputBuffer StrTOut(StrT, is64Bit, isLittleEndian); > ? StrTOut.outbyte(0); > > @@ -439,7 +428,6 @@ > ? // 2. strings for local symbols > ? // Since this is the opposite order from the symbol table, which we have just > ? // sorted, we can walk the symbol table backwards to output the string table. > - > ? for (std::vector::reverse_iterator I = SymbolTable.rbegin(), > ? ? ? ? E = SymbolTable.rend(); I != E; ++I) { > ? ? if (I->GVName == "") { > @@ -463,7 +451,7 @@ > ? ? ? I->n_value += GVSection[GV]->addr; > ? ? if (GV && (GVOffset[GV] == -1)) > ? ? ? GVOffset[GV] = index; > - > + > ? ? // Emit nlist to buffer > ? ? SymTOut.outword(I->n_strx); > ? ? SymTOut.outbyte(I->n_type); > @@ -478,32 +466,29 @@ > ?/// and the offset into that section. ?From this information, create the > ?/// appropriate target-specific MachORelocation type and add buffer it to be > ?/// written out after we are finished writing out sections. > - > ?void MachOWriter::CalculateRelocations(MachOSection &MOS) { > - ?for (unsigned i = 0, e = MOS.Relocations.size(); i != e; ++i) { > - ? ?MachineRelocation &MR = MOS.Relocations[i]; > + ?std::vector Relocations = ?MOS.getRelocations(); > + ?for (unsigned i = 0, e = Relocations.size(); i != e; ++i) { > + ? ?MachineRelocation &MR = Relocations[i]; > ? ? unsigned TargetSection = MR.getConstantVal(); > ? ? unsigned TargetAddr = 0; > ? ? unsigned TargetIndex = 0; > > ? ? // This is a scattered relocation entry if it points to a global value with > ? ? // a non-zero offset. > - > ? ? bool Scattered = false; > ? ? bool Extern = false; > > ? ? // Since we may not have seen the GlobalValue we were interested in yet at > ? ? // the time we emitted the relocation for it, fix it up now so that it > ? ? // points to the offset into the correct section. > - > ? ? if (MR.isGlobalValue()) { > ? ? ? GlobalValue *GV = MR.getGlobalValue(); > ? ? ? MachOSection *MOSPtr = GVSection[GV]; > ? ? ? intptr_t Offset = GVOffset[GV]; > - > + > ? ? ? // If we have never seen the global before, it must be to a symbol > ? ? ? // defined in another module (N_UNDF). > - > ? ? ? if (!MOSPtr) { > ? ? ? ? // FIXME: need to append stub suffix > ? ? ? ? Extern = true; > @@ -515,10 +500,9 @@ > ? ? ? } > ? ? ? MR.setResultPointer((void*)Offset); > ? ? } > - > + > ? ? // If the symbol is locally defined, pass in the address of the section and > ? ? // the section index to the code which will generate the target relocation. > - > ? ? if (!Extern) { > ? ? ? ? MachOSection &To = *SectionList[TargetSection - 1]; > ? ? ? ? TargetAddr = To.addr; > @@ -526,7 +510,7 @@ > ? ? } > > ? ? OutputBuffer RelocOut(MOS.RelocBuffer, is64Bit, isLittleEndian); > - ? ?OutputBuffer SecOut(MOS.SectionData, is64Bit, isLittleEndian); > + ? ?OutputBuffer SecOut(MOS.getData(), is64Bit, isLittleEndian); > > ? ? MOS.nreloc += GetTargetRelocation(MR, MOS.Index, TargetAddr, TargetIndex, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? RelocOut, SecOut, Scattered, Extern); > @@ -535,22 +519,21 @@ > > ?// InitMem - Write the value of a Constant to the specified memory location, > ?// converting it into bytes and relocations. > - > -void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset, > - ? ? ? ? ? ? ? ? ? ? ? ? ?const TargetData *TD, > - ? ? ? ? ? ? ? ? ? ? ? ? ?std::vector &MRs) { > +void MachOWriter::InitMem(const Constant *C, uintptr_t Offset, > + ? ? ? ? ? ? ? ? ? ? ? ? ?const TargetData *TD, MachOSection* mos) { > ? typedef std::pair CPair; > ? std::vector WorkList; > - > + ?uint8_t *Addr = &mos->getData()[0]; > + > ? WorkList.push_back(CPair(C,(intptr_t)Addr + Offset)); > - > + > ? intptr_t ScatteredOffset = 0; > - > + > ? while (!WorkList.empty()) { > ? ? const Constant *PC = WorkList.back().first; > ? ? intptr_t PA = WorkList.back().second; > ? ? WorkList.pop_back(); > - > + > ? ? if (isa(PC)) { > ? ? ? continue; > ? ? } else if (const ConstantVector *CP = dyn_cast(PC)) { > @@ -643,7 +626,7 @@ > ? ? ? ? ? memset(ptr, 0, TD->getPointerSize()); > ? ? ? ? else if (const GlobalValue* GV = dyn_cast(PC)) { > ? ? ? ? ? // FIXME: what about function stubs? > - ? ? ? ? ?MRs.push_back(MachineRelocation::getGV(PA-(intptr_t)Addr, > + ? ? ? ? ?mos->addRelocation(MachineRelocation::getGV(PA-(intptr_t)Addr, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MachineRelocation::VANILLA, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const_cast(GV), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ScatteredOffset)); > > Modified: llvm/trunk/lib/CodeGen/MachOWriter.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/CodeGen/MachOWriter.h (original) > +++ llvm/trunk/lib/CodeGen/MachOWriter.h Mon Jul ?6 00:09:34 2009 > @@ -15,17 +15,24 @@ > ?#define MACHOWRITER_H > > ?#include "MachO.h" > +#include "llvm/Constants.h" > +#include "llvm/DerivedTypes.h" > ?#include "llvm/CodeGen/MachineFunctionPass.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > ?#include "llvm/Target/TargetData.h" > ?#include "llvm/Target/TargetMachine.h" > ?#include "llvm/Target/TargetMachOWriterInfo.h" > +#include > ?#include > > ?namespace llvm { > ? class GlobalVariable; > ? class Mangler; > - ?class MachineCodeEmitter; > + ?class MachineRelocation; > + ?class ObjectCodeEmitter; > ? class MachOCodeEmitter; > + ?class TargetData; > + ?class TargetMachine; > ? class OutputBuffer; > ? class raw_ostream; > > @@ -38,8 +45,9 @@ > ? ? friend class MachOCodeEmitter; > ? public: > ? ? static char ID; > - ? ?MachineCodeEmitter &getMachineCodeEmitter() const { > - ? ? ?return *(MachineCodeEmitter*)MCE; > + > + ? ?ObjectCodeEmitter *getObjectCodeEmitter() { > + ? ? ?return reinterpret_cast(MachOCE); > ? ? } > > ? ? MachOWriter(raw_ostream &O, TargetMachine &TM); > @@ -62,10 +70,10 @@ > ? ? /// > ? ? Mangler *Mang; > > - ? ?/// MCE - The MachineCodeEmitter object that we are exposing to emit machine > + ? ?/// MachOCE - The MachineCodeEmitter object that we are exposing to emit machine > ? ? /// code for functions to the .o file. > > - ? ?MachOCodeEmitter *MCE; > + ? ?MachOCodeEmitter *MachOCE; > > ? ? /// is64Bit/isLittleEndian - This information is inferred from the target > ? ? /// machine directly, indicating what header values and flags to set. > @@ -225,9 +233,10 @@ > ? ? /// SymbolTable to aid in emitting the DYSYMTAB load command. > ? ? std::vector DynamicSymbolTable; > > - ? ?static void InitMem(const Constant *C, void *Addr, intptr_t Offset, > + ? ?static void InitMem(const Constant *C, > + ? ? ? ? ? ? ? ? ? ? ? ?uintptr_t Offset, > ? ? ? ? ? ? ? ? ? ? ? ? const TargetData *TD, > - ? ? ? ? ? ? ? ? ? ? ? ?std::vector &MRs); > + ? ? ? ? ? ? ? ? ? ? ? ?MachOSection* mos); > > ? private: > ? ? void AddSymbolToSection(MachOSection *MOS, GlobalVariable *GV); > > Modified: llvm/trunk/lib/Target/ARM/ARM.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARM.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/ARM/ARM.h (original) > +++ llvm/trunk/lib/Target/ARM/ARM.h Mon Jul ?6 00:09:34 2009 > @@ -24,6 +24,7 @@ > ?class FunctionPass; > ?class MachineCodeEmitter; > ?class JITCodeEmitter; > +class ObjectCodeEmitter; > ?class raw_ostream; > > ?// Enums corresponding to ARM condition codes > @@ -101,6 +102,8 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MachineCodeEmitter &MCE); > ?FunctionPass *createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &JCE); > +FunctionPass *createARMObjectCodeEmitterPass(ARMBaseTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE); > > ?FunctionPass *createARMLoadStoreOptimizationPass(bool PreAlloc = false); > ?FunctionPass *createARMConstantIslandPass(); > > Modified: llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp (original) > +++ llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp Mon Jul ?6 00:09:34 2009 > @@ -26,6 +26,7 @@ > ?#include "llvm/PassManager.h" > ?#include "llvm/CodeGen/MachineCodeEmitter.h" > ?#include "llvm/CodeGen/JITCodeEmitter.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > ?#include "llvm/CodeGen/MachineConstantPool.h" > ?#include "llvm/CodeGen/MachineFunctionPass.h" > ?#include "llvm/CodeGen/MachineInstr.h" > @@ -174,18 +175,18 @@ > ?/// createARMCodeEmitterPass - Return a pass that emits the collected ARM code > ?/// to the specified MCE object. > > -namespace llvm { > - > -FunctionPass *createARMCodeEmitterPass(ARMBaseTargetMachine &TM, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MachineCodeEmitter &MCE) { > +FunctionPass *llvm::createARMCodeEmitterPass(ARMBaseTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MachineCodeEmitter &MCE) { > ? return new Emitter(TM, MCE); > ?} > -FunctionPass *createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?JITCodeEmitter &JCE) { > +FunctionPass *llvm::createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?JITCodeEmitter &JCE) { > ? return new Emitter(TM, JCE); > ?} > - > -} // end namespace llvm > +FunctionPass *llvm::createARMObjectCodeEmitterPass(ARMBaseTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE) { > + ?return new Emitter(TM, OCE); > +} > > ?template > ?bool Emitter::runOnMachineFunction(MachineFunction &MF) { > > Modified: llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp (original) > +++ llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp Mon Jul ?6 00:09:34 2009 > @@ -228,6 +228,25 @@ > ? return false; > ?} > > +bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE) { > + ?// FIXME: Move this to TargetJITInfo! > + ?if (DefRelocModel == Reloc::Default) > + ? ?setRelocationModel(Reloc::Static); > + > + ?// Machine code emitter pass for ARM. > + ?PM.add(createARMObjectCodeEmitterPass(*this, OCE)); > + ?if (DumpAsm) { > + ? ?assert(AsmPrinterCtor && "AsmPrinter was not linked in"); > + ? ?if (AsmPrinterCtor) > + ? ? ?PM.add(AsmPrinterCtor(errs(), *this, true)); > + ?} > + > + ?return false; > +} > + > ?bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > @@ -258,4 +277,18 @@ > ? return false; > ?} > > +bool ARMBaseTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE) { > + ?// Machine code emitter pass for ARM. > + ?PM.add(createARMObjectCodeEmitterPass(*this, OCE)); > + ?if (DumpAsm) { > + ? ?assert(AsmPrinterCtor && "AsmPrinter was not linked in"); > + ? ?if (AsmPrinterCtor) > + ? ? ?PM.add(AsmPrinterCtor(errs(), *this, true)); > + ?} > + > + ?return false; > +} > > > Modified: llvm/trunk/lib/Target/ARM/ARMTargetMachine.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/ARM/ARMTargetMachine.h (original) > +++ llvm/trunk/lib/Target/ARM/ARMTargetMachine.h Mon Jul ?6 00:09:34 2009 > @@ -77,6 +77,8 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, MachineCodeEmitter &MCE); > ? virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, JITCodeEmitter &MCE); > + ?virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &OCE); > ? virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > @@ -85,6 +87,10 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &MCE); > + ?virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE); > ?}; > > ?/// ARMTargetMachine - ARM target machine. > > Modified: llvm/trunk/lib/Target/Alpha/Alpha.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/Alpha.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/Alpha/Alpha.h (original) > +++ llvm/trunk/lib/Target/Alpha/Alpha.h Mon Jul ?6 00:09:34 2009 > @@ -22,6 +22,7 @@ > ? class AlphaTargetMachine; > ? class FunctionPass; > ? class MachineCodeEmitter; > + ?class ObjectCodeEmitter; > ? class raw_ostream; > > ? FunctionPass *createAlphaISelDag(AlphaTargetMachine &TM); > @@ -32,7 +33,9 @@ > ? FunctionPass *createAlphaCodeEmitterPass(AlphaTargetMachine &TM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MachineCodeEmitter &MCE); > ? FunctionPass *createAlphaJITCodeEmitterPass(AlphaTargetMachine &TM, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &JCE); > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?JITCodeEmitter &JCE); > + ?FunctionPass *createAlphaObjectCodeEmitterPass(AlphaTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE); > ? FunctionPass *createAlphaLLRPPass(AlphaTargetMachine &tm); > ? FunctionPass *createAlphaBranchSelectionPass(); > > > Modified: llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp (original) > +++ llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp Mon Jul ?6 00:09:34 2009 > @@ -19,6 +19,7 @@ > ?#include "llvm/PassManager.h" > ?#include "llvm/CodeGen/MachineCodeEmitter.h" > ?#include "llvm/CodeGen/JITCodeEmitter.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > ?#include "llvm/CodeGen/MachineFunctionPass.h" > ?#include "llvm/CodeGen/MachineInstr.h" > ?#include "llvm/CodeGen/Passes.h" > @@ -91,6 +92,10 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &JCE) { > ? return new Emitter(TM, JCE); > ?} > +FunctionPass *llvm::createAlphaObjectCodeEmitterPass(AlphaTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE) { > + ?return new Emitter(TM, OCE); > +} > > ?template > ?bool Emitter::runOnMachineFunction(MachineFunction &MF) { > > Modified: llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp (original) > +++ llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.cpp Mon Jul ?6 00:09:34 2009 > @@ -119,6 +119,17 @@ > ? } > ? return false; > ?} > +bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &OCE) { > + ?PM.add(createAlphaObjectCodeEmitterPass(*this, OCE)); > + ?if (DumpAsm) { > + ? ?assert(AsmPrinterCtor && "AsmPrinter was not linked in"); > + ? ?if (AsmPrinterCtor) > + ? ? ?PM.add(AsmPrinterCtor(errs(), *this, true)); > + ?} > + ?return false; > +} > ?bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > @@ -131,4 +142,10 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &JCE) { > ? return addCodeEmitter(PM, OptLevel, DumpAsm, JCE); > ?} > +bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE) { > + ?return addCodeEmitter(PM, OptLevel, DumpAsm, OCE); > +} > > > Modified: llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h (original) > +++ llvm/trunk/lib/Target/Alpha/AlphaTargetMachine.h Mon Jul ?6 00:09:34 2009 > @@ -74,6 +74,8 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, MachineCodeEmitter &MCE); > ? virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, JITCodeEmitter &JCE); > + ?virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &JCE); > ? virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > @@ -82,6 +84,10 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &JCE); > + ?virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE); > > ? static void registerAsmPrinter(AsmPrinterCtorFn F) { > ? ? AsmPrinterCtor = F; > > Modified: llvm/trunk/lib/Target/PowerPC/PPC.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPC.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/PowerPC/PPC.h (original) > +++ llvm/trunk/lib/Target/PowerPC/PPC.h Mon Jul ?6 00:09:34 2009 > @@ -24,6 +24,7 @@ > ? class PPCTargetMachine; > ? class FunctionPass; > ? class MachineCodeEmitter; > + ?class ObjectCodeEmitter; > ? class raw_ostream; > > ?FunctionPass *createPPCBranchSelectionPass(); > @@ -33,7 +34,9 @@ > ?FunctionPass *createPPCCodeEmitterPass(PPCTargetMachine &TM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MachineCodeEmitter &MCE); > ?FunctionPass *createPPCJITCodeEmitterPass(PPCTargetMachine &TM, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &MCE); > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?JITCodeEmitter &MCE); > +FunctionPass *createPPCObjectCodeEmitterPass(PPCTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE); > ?} // end namespace llvm; > > ?// Defines symbolic names for PowerPC registers. ?This defines a mapping from > > Modified: llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp (original) > +++ llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp Mon Jul ?6 00:09:34 2009 > @@ -19,6 +19,7 @@ > ?#include "llvm/PassManager.h" > ?#include "llvm/CodeGen/MachineCodeEmitter.h" > ?#include "llvm/CodeGen/JITCodeEmitter.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > ?#include "llvm/CodeGen/MachineFunctionPass.h" > ?#include "llvm/CodeGen/MachineInstrBuilder.h" > ?#include "llvm/CodeGen/MachineModuleInfo.h" > @@ -91,6 +92,7 @@ > > ?/// createPPCCodeEmitterPass - Return a pass that emits the collected PPC code > ?/// to the specified MCE object. > + > ?FunctionPass *llvm::createPPCCodeEmitterPass(PPCTargetMachine &TM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MachineCodeEmitter &MCE) { > ? return new Emitter(TM, MCE); > @@ -101,6 +103,11 @@ > ? return new Emitter(TM, JCE); > ?} > > +FunctionPass *llvm::createPPCObjectCodeEmitterPass(PPCTargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE) { > + ?return new Emitter(TM, OCE); > +} > + > ?template > ?bool Emitter::runOnMachineFunction(MachineFunction &MF) { > ? assert((MF.getTarget().getRelocationModel() != Reloc::Default || > @@ -252,6 +259,7 @@ > ? ? ? Reloc = PPC::reloc_pcrel_bx; > ? ? else // BCC instruction > ? ? ? Reloc = PPC::reloc_pcrel_bcx; > + > ? ? MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Reloc, MO.getMBB())); > ? } else { > > Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp (original) > +++ llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp Mon Jul ?6 00:09:34 2009 > @@ -221,6 +221,38 @@ > ? return false; > ?} > > +bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &OCE) { > + ?// The JIT should use the static relocation model in ppc32 mode, PIC in ppc64. > + ?// FIXME: This should be moved to TargetJITInfo!! > + ?if (Subtarget.isPPC64()) { > + ? ?// We use PIC codegen in ppc64 mode, because otherwise we'd have to use many > + ? ?// instructions to materialize arbitrary global variable + function + > + ? ?// constant pool addresses. > + ? ?setRelocationModel(Reloc::PIC_); > + ? ?// Temporary workaround for the inability of PPC64 JIT to handle jump > + ? ?// tables. > + ? ?DisableJumpTables = true; > + ?} else { > + ? ?setRelocationModel(Reloc::Static); > + ?} > + > + ?// Inform the subtarget that we are in JIT mode. ?FIXME: does this break macho > + ?// writing? > + ?Subtarget.SetJITMode(); > + > + ?// Machine code emitter pass for PowerPC. > + ?PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); > + ?if (DumpAsm) { > + ? ?assert(AsmPrinterCtor && "AsmPrinter was not linked in"); > + ? ?if (AsmPrinterCtor) > + ? ? ?PM.add(AsmPrinterCtor(errs(), *this, true)); > + ?} > + > + ?return false; > +} > + > ?bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > @@ -251,3 +283,19 @@ > ? return false; > ?} > > +bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE) { > + ?// Machine code emitter pass for PowerPC. > + ?PM.add(createPPCObjectCodeEmitterPass(*this, OCE)); > + ?if (DumpAsm) { > + ? ?assert(AsmPrinterCtor && "AsmPrinter was not linked in"); > + ? ?if (AsmPrinterCtor) > + ? ? ?PM.add(AsmPrinterCtor(errs(), *this, true)); > + ?} > + > + ?return false; > +} > + > + > > Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h (original) > +++ llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.h Mon Jul ?6 00:09:34 2009 > @@ -85,12 +85,17 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, MachineCodeEmitter &MCE); > ? virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, JITCodeEmitter &JCE); > + ?virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &OCE); > ? virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, MachineCodeEmitter &MCE); > ? virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, JITCodeEmitter &JCE); > + ?virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &OCE); > ? virtual bool getEnableTailMergeDefault() const; > ?}; > > > Modified: llvm/trunk/lib/Target/X86/X86.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/X86/X86.h (original) > +++ llvm/trunk/lib/Target/X86/X86.h Mon Jul ?6 00:09:34 2009 > @@ -56,6 +56,8 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?MachineCodeEmitter &MCE); > ?FunctionPass *createX86JITCodeEmitterPass(X86TargetMachine &TM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? JITCodeEmitter &JCE); > +FunctionPass *createX86ObjectCodeEmitterPass(X86TargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE); > > ?/// createX86EmitCodeToMemory - Returns a pass that converts a register > ?/// allocated function into raw machine code in a dynamically > > Modified: llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp (original) > +++ llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp Mon Jul ?6 00:09:34 2009 > @@ -22,6 +22,7 @@ > ?#include "llvm/PassManager.h" > ?#include "llvm/CodeGen/MachineCodeEmitter.h" > ?#include "llvm/CodeGen/JITCodeEmitter.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > ?#include "llvm/CodeGen/MachineFunctionPass.h" > ?#include "llvm/CodeGen/MachineInstr.h" > ?#include "llvm/CodeGen/MachineModuleInfo.h" > @@ -106,18 +107,18 @@ > ?/// createX86CodeEmitterPass - Return a pass that emits the collected X86 code > ?/// to the specified templated MachineCodeEmitter object. > > -namespace llvm { > - > -FunctionPass *createX86CodeEmitterPass(X86TargetMachine &TM, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MachineCodeEmitter &MCE) { > +FunctionPass *llvm::createX86CodeEmitterPass(X86TargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MachineCodeEmitter &MCE) { > ? return new Emitter(TM, MCE); > ?} > -FunctionPass *createX86JITCodeEmitterPass(X86TargetMachine &TM, > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?JITCodeEmitter &JCE) { > +FunctionPass *llvm::createX86JITCodeEmitterPass(X86TargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?JITCodeEmitter &JCE) { > ? return new Emitter(TM, JCE); > ?} > - > -} // end namespace llvm > +FunctionPass *llvm::createX86ObjectCodeEmitterPass(X86TargetMachine &TM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter &OCE) { > + ?return new Emitter(TM, OCE); > +} > > ?template > ?bool Emitter::runOnMachineFunction(MachineFunction &MF) { > > Modified: llvm/trunk/lib/Target/X86/X86TargetMachine.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetMachine.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/X86/X86TargetMachine.cpp (original) > +++ llvm/trunk/lib/Target/X86/X86TargetMachine.cpp Mon Jul ?6 00:09:34 2009 > @@ -290,6 +290,36 @@ > ? return false; > ?} > > +bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE) { > + ?// FIXME: Move this to TargetJITInfo! > + ?// On Darwin, do not override 64-bit setting made in X86TargetMachine(). > + ?if (DefRelocModel == Reloc::Default && > + ? ? ? ?(!Subtarget.isTargetDarwin() || !Subtarget.is64Bit())) > + ? ?setRelocationModel(Reloc::Static); > + > + ?// 64-bit JIT places everything in the same buffer except external functions. > + ?// On Darwin, use small code model but hack the call instruction for > + ?// externals. ?Elsewhere, do not assume globals are in the lower 4G. > + ?if (Subtarget.is64Bit()) { > + ? ?if (Subtarget.isTargetDarwin()) > + ? ? ?setCodeModel(CodeModel::Small); > + ? ?else > + ? ? ?setCodeModel(CodeModel::Large); > + ?} > + > + ?PM.add(createX86ObjectCodeEmitterPass(*this, OCE)); > + ?if (DumpAsm) { > + ? ?assert(AsmPrinterCtor && "AsmPrinter was not linked in"); > + ? ?if (AsmPrinterCtor) > + ? ? ?PM.add(AsmPrinterCtor(errs(), *this, true)); > + ?} > + > + ?return false; > +} > + > ?bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, > @@ -318,3 +348,16 @@ > ? return false; > ?} > > +bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ObjectCodeEmitter &OCE) { > + ?PM.add(createX86ObjectCodeEmitterPass(*this, OCE)); > + ?if (DumpAsm) { > + ? ?assert(AsmPrinterCtor && "AsmPrinter was not linked in"); > + ? ?if (AsmPrinterCtor) > + ? ? ?PM.add(AsmPrinterCtor(errs(), *this, true)); > + ?} > + > + ?return false; > +} > > Modified: llvm/trunk/lib/Target/X86/X86TargetMachine.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetMachine.h?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/lib/Target/X86/X86TargetMachine.h (original) > +++ llvm/trunk/lib/Target/X86/X86TargetMachine.h Mon Jul ?6 00:09:34 2009 > @@ -84,12 +84,17 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, MachineCodeEmitter &MCE); > ? virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, JITCodeEmitter &JCE); > + ?virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &OCE); > ? virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, MachineCodeEmitter &MCE); > ? virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CodeGenOpt::Level OptLevel, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool DumpAsm, JITCodeEmitter &JCE); > + ?virtual bool addSimpleCodeEmitter(PassManagerBase &PM, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Level OptLevel, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bool DumpAsm, ObjectCodeEmitter &OCE); > ?}; > > ?/// X86_32TargetMachine - X86 32-bit target machine. > > Modified: llvm/trunk/tools/llc/llc.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/tools/llc/llc.cpp (original) > +++ llvm/trunk/tools/llc/llc.cpp Mon Jul ?6 00:09:34 2009 > @@ -17,6 +17,7 @@ > ?#include "llvm/CodeGen/FileWriters.h" > ?#include "llvm/CodeGen/LinkAllCodegenComponents.h" > ?#include "llvm/CodeGen/LinkAllAsmWriterComponents.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > ?#include "llvm/Target/SubtargetFeature.h" > ?#include "llvm/Target/TargetData.h" > ?#include "llvm/Target/TargetMachine.h" > @@ -312,7 +313,7 @@ > ?#endif > > ? ? // Ask the target to add backend passes as necessary. > - ? ?MachineCodeEmitter *MCE = 0; > + ? ?ObjectCodeEmitter *OCE = 0; > > ? ? // Override default to generate verbose assembly. > ? ? Target.setAsmVerbosityDefault(true); > @@ -331,14 +332,14 @@ > ? ? case FileModel::AsmFile: > ? ? ? break; > ? ? case FileModel::MachOFile: > - ? ? ?MCE = AddMachOWriter(Passes, *Out, Target); > + ? ? ?OCE = AddMachOWriter(Passes, *Out, Target); > ? ? ? break; > ? ? case FileModel::ElfFile: > - ? ? ?MCE = AddELFWriter(Passes, *Out, Target); > + ? ? ?OCE = AddELFWriter(Passes, *Out, Target); > ? ? ? break; > ? ? } > > - ? ?if (Target.addPassesToEmitFileFinish(Passes, MCE, OLvl)) { > + ? ?if (Target.addPassesToEmitFileFinish(Passes, OCE, OLvl)) { > ? ? ? std::cerr << argv[0] << ": target does not support generation of this" > ? ? ? ? ? ? ? ? << " file type!\n"; > ? ? ? if (Out != &outs()) delete Out; > > Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=74813&r1=74812&r2=74813&view=diff > > ============================================================================== > --- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original) > +++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Mon Jul ?6 00:09:34 2009 > @@ -430,16 +430,16 @@ > > ? ? codeGenPasses->add(new TargetData(*_target->getTargetData())); > > - ? ?MachineCodeEmitter* mce = NULL; > + ? ?ObjectCodeEmitter* oce = NULL; > > ? ? switch (_target->addPassesToEmitFile(*codeGenPasses, out, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TargetMachine::AssemblyFile, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Aggressive)) { > ? ? ? ? case FileModel::MachOFile: > - ? ? ? ? ? ?mce = AddMachOWriter(*codeGenPasses, out, *_target); > + ? ? ? ? ? ?oce = AddMachOWriter(*codeGenPasses, out, *_target); > ? ? ? ? ? ? break; > ? ? ? ? case FileModel::ElfFile: > - ? ? ? ? ? ?mce = AddELFWriter(*codeGenPasses, out, *_target); > + ? ? ? ? ? ?oce = AddELFWriter(*codeGenPasses, out, *_target); > ? ? ? ? ? ? break; > ? ? ? ? case FileModel::AsmFile: > ? ? ? ? ? ? break; > @@ -449,7 +449,7 @@ > ? ? ? ? ? ? return true; > ? ? } > > - ? ?if (_target->addPassesToEmitFileFinish(*codeGenPasses, mce, > + ? ?if (_target->addPassesToEmitFileFinish(*codeGenPasses, oce, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?CodeGenOpt::Aggressive)) { > ? ? ? ? errMsg = "target does not support generation of this file type"; > ? ? ? ? return true; > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > -- Bruno Cardoso Lopes http://www.brunocardoso.cc -------------- next part -------------- This MachO-DOE patch introduces the ObjectCodeEmitter and BinaryObject classes and adds ObejectCodeEmitter to the code emitters, intermediate and llc, and LTO code. This demonstrates and tests the ObjectCodeEmitter and BinaryObject classes, but stubs the ELFWritter and makes it useless until updated to use this prototype DOE framework. I added label support to the MachOWriter in the process and am getting semi encoraging results in its output. * include/llvm/Target/TargetMachine.h class TargetMachine - added addPassesToEmitFileFinish() for ObjectCodeEmitter class LLVMTargetMachine - addPassesToEmitFileFinish() for ObjectCodeEmitter - addSimpleCodeEmitter() for ObjectCodeEmitter * include/llvm/CodeGen/FileWriters.h - change AddMachOWriter() to return an ObjectCodeEmitter - change AddELFWriter() to return an ObjectCodeEmitter * include/llvm/CodeGen/MachineCodeEmitter.h - removed GVStub methods - made MachineCodeEmitter::getCurrentPCOffset() virtual * include/llvm/CodeGen/ObjectCodeEmitter.h - new file * include/llvm/CodeGen/BinaryObject.h - removed unnecessary unsigned casts - added reserveBytes() method - added Alignment filler byte value * lib/CodeGen/LLVMTargetMachine.cpp - added LLVMTargetMachine::addPassesToEmitFileFinish() * lib/CodeGen/ELFWriter.cpp - kludge to cast and converted AddELFWriter to return ObjectCodeEmitter * lib/CodeGen/MachO.h * lib/CodeGen/MachOCodeEmitter.h * lib/CodeGen/MachOCodeEmitter.cpp * lib/CodeGen/MachOWriter.h * lib/CodeGen/MachOWriter.cpp - converted to use ObjectCodeEmitter - made getObjectCodeEmitter() return a pointer * lib/Target/X86/X86.h * lib/Target/X86/X86CodeEmitter.cpp - added createX86ObjectCodeEmitterPass() * lib/Target/X86/X86TargetMachine.h * lib/Target/X86/X86TargetMachine.cpp - added X86TargetMachine::addCodeEmitter() - added X86TargetMachine::addSimpleCodeEmitter() * lib/Target/PowerPC/PPC.h * lib/Target/PowerPC/PPCCodeEmitter.cpp - added createPPCObjectCodeEmitterPass() * lib/Target/PowerPC/PPCTargetMachine.h * lib/Target/PowerPC/PPCTargetMachine.cpp - added PPCTargetMachine::addCodeEmitter() - added PPCTargetMachine::addSimpleCodeEmitter() * lib/Target/ARM/ARM.h * lib/Target/ARM/ARMCodeEmitter.cpp - added createARMObjectCodeEmitterPass() * lib/Target/ARM/ARMTargetMachine.h * lib/Target/ARM/ARMTargetMachine.cpp - added ARMTargetMachine::addCodeEmitter() - added ARMTargetMachine::addSimpleCodeEmitter() * lib/Target/Alpha/Alpha.h * lib/Target/Alpha/AlphaCodeEmitter.cpp - added createAlphaObjectCodeEmitterPass() * lib/Target/Alpha/AlphaTargetMachine.h * lib/Target/Alpha/AlphaTargetMachine.cpp - added AlphaTargetMachine::addCodeEmitter() - added AlphaTargetMachine::addSimpleCodeEmitter() * tools/lto/LTOCodeGenerator.cpp * tools/llc/llc.cpp - converted to use ObjectCodeEmitter From nicholas at mxc.ca Mon Jul 6 00:16:09 2009 From: nicholas at mxc.ca (Nick Lewycky) Date: Sun, 05 Jul 2009 22:16:09 -0700 Subject: [llvm-commits] PATCH: remove VICmp and VFCmp. Message-ID: <4A518899.80806@mxc.ca> This patch removes vicmp and vfcmp, which has the positive side that it fixes existing type-safety bugs and simplifies some code, but a downside in that it XFAILs 9 CodeGen tests. May I commit this? Nick -------------- next part -------------- A non-text attachment was scrubbed... Name: remove-vcmp.patch Type: text/x-diff Size: 86165 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090705/f403abc9/attachment.bin From bruno.cardoso at gmail.com Mon Jul 6 00:16:40 2009 From: bruno.cardoso at gmail.com (Bruno Cardoso Lopes) Date: Mon, 06 Jul 2009 05:16:40 -0000 Subject: [llvm-commits] [llvm] r74814 - in /llvm/trunk: include/llvm/CodeGen/ObjectCodeEmitter.h lib/CodeGen/ObjectCodeEmitter.cpp Message-ID: <200907060516.n665Gekx026755@zion.cs.uiuc.edu> Author: bruno Date: Mon Jul 6 00:16:40 2009 New Revision: 74814 URL: http://llvm.org/viewvc/llvm-project?rev=74814&view=rev Log: Just forgot to include the two new files Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto ============================================================================== --- llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h (added) +++ llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h Mon Jul 6 00:16:40 2009 @@ -0,0 +1,171 @@ +//===-- llvm/CodeGen/ObjectCodeEmitter.h - Object Code Emitter -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Generalized Object Code Emitter, works with ObjectModule and BinaryObject. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CODEGEN_OBJECTCODEEMITTER_H +#define LLVM_CODEGEN_OBJECTCODEEMITTER_H + +#include "llvm/CodeGen/MachineCodeEmitter.h" + +namespace llvm { + +class BinaryObject; +class MachineBasicBlock; +class MachineCodeEmitter; +class MachineFunction; +class MachineConstantPool; +class MachineJumpTableInfo; +class MachineModuleInfo; + +class ObjectCodeEmitter : public MachineCodeEmitter { +protected: + + /// Binary Object (Section or Segment) we are emitting to. + BinaryObject *BO; + + /// MBBLocations - This vector is a mapping from MBB ID's to their address. + /// It is filled in by the StartMachineBasicBlock callback and queried by + /// the getMachineBasicBlockAddress callback. + std::vector MBBLocations; + + /// LabelLocations - This vector is a mapping from Label ID's to their + /// address. + std::vector LabelLocations; + + /// CPLocations - This is a map of constant pool indices to offsets from the + /// start of the section for that constant pool index. + std::vector CPLocations; + + /// CPSections - This is a map of constant pool indices to the Section + /// containing the constant pool entry for that index. + std::vector CPSections; + + /// JTLocations - This is a map of jump table indices to offsets from the + /// start of the section for that jump table index. + std::vector JTLocations; + +public: + ObjectCodeEmitter(); + ObjectCodeEmitter(BinaryObject *bo); + virtual ~ObjectCodeEmitter(); + + /// setBinaryObject - set the BinaryObject we are writting to + void setBinaryObject(BinaryObject *bo); + + /// emitByte - This callback is invoked when a byte needs to be + /// written to the data stream, without buffer overflow testing. + void emitByte(uint8_t B); + + /// emitWordLE - This callback is invoked when a 32-bit word needs to be + /// written to the data stream in little-endian format. + void emitWordLE(uint32_t W); + + /// emitWordBE - This callback is invoked when a 32-bit word needs to be + /// written to the data stream in big-endian format. + void emitWordBE(uint32_t W); + + /// emitDWordLE - This callback is invoked when a 64-bit word needs to be + /// written to the data stream in little-endian format. + void emitDWordLE(uint64_t W); + + /// emitDWordBE - This callback is invoked when a 64-bit word needs to be + /// written to the data stream in big-endian format. + void emitDWordBE(uint64_t W); + + /// emitAlignment - Move the CurBufferPtr pointer up the the specified + /// alignment (saturated to BufferEnd of course). + void emitAlignment(unsigned Alignment = 0, uint8_t fill = 0); + + /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be + /// written to the data stream. + void emitULEB128Bytes(uint64_t Value); + + /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be + /// written to the data stream. + void emitSLEB128Bytes(uint64_t Value); + + /// emitString - This callback is invoked when a String needs to be + /// written to the data stream. + void emitString(const std::string &String); + + /// getCurrentPCValue - This returns the address that the next emitted byte + /// will be output to. + uintptr_t getCurrentPCValue() const; + + /// getCurrentPCOffset - Return the offset from the start of the emitted + /// buffer that we are currently writing to. + uintptr_t getCurrentPCOffset() const; + + /// addRelocation - Whenever a relocatable address is needed, it should be + /// noted with this interface. + void addRelocation(const MachineRelocation& relocation); + + /// startFunction - This callback is invoked when the specified function is + /// about to be code generated. This initializes the BufferBegin/End/Ptr + /// fields. + virtual void startFunction(MachineFunction &F) = 0; + + /// finishFunction - This callback is invoked when the specified function has + /// finished code generation. If a buffer overflow has occurred, this method + /// returns true (the callee is required to try again), otherwise it returns + /// false. + virtual bool finishFunction(MachineFunction &F) = 0; + + /// StartMachineBasicBlock - This should be called by the target when a new + /// basic block is about to be emitted. This way the MCE knows where the + /// start of the block is, and can implement getMachineBasicBlockAddress. + virtual void StartMachineBasicBlock(MachineBasicBlock *MBB); + + /// getMachineBasicBlockAddress - Return the address of the specified + /// MachineBasicBlock, only usable after the label for the MBB has been + /// emitted. + virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const; + + /// emitLabel - Emits a label + virtual void emitLabel(uint64_t LabelID) = 0; + + /// getLabelAddress - Return the address of the specified LabelID, only usable + /// after the LabelID has been emitted. + virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0; + + /// emitJumpTables - Emit all the jump tables for a given jump table info + /// record to the appropriate section. + virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0; + + /// getJumpTableEntryAddress - Return the address of the jump table with index + /// 'Index' in the function that last called initJumpTableInfo. + virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const; + + /// emitConstantPool - For each constant pool entry, figure out which section + /// the constant should live in, allocate space for it, and emit it to the + /// Section data buffer. + virtual void emitConstantPool(MachineConstantPool *MCP) = 0; + + /// getConstantPoolEntryAddress - Return the address of the 'Index' entry in + /// the constant pool that was last emitted with the emitConstantPool method. + virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const; + + /// getConstantPoolEntrySection - Return the section of the 'Index' entry in + /// the constant pool that was last emitted with the emitConstantPool method. + virtual uintptr_t getConstantPoolEntrySection(unsigned Index) const; + + /// Specifies the MachineModuleInfo object. This is used for exception handling + /// purposes. + virtual void setModuleInfo(MachineModuleInfo* Info) = 0; + // to be implemented or depreciated with MachineModuleInfo + +}; // end class ObjectCodeEmitter + +} // end namespace llvm + +#endif + Added: llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto ============================================================================== --- llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp (added) +++ llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Mon Jul 6 00:16:40 2009 @@ -0,0 +1,142 @@ +//===-- llvm/CodeGen/ObjectCodeEmitter.cpp -------------------- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/BinaryObject.h" +#include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineRelocation.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" + +//===----------------------------------------------------------------------===// +// ObjectCodeEmitter Implementation +//===----------------------------------------------------------------------===// + +namespace llvm { + +ObjectCodeEmitter::ObjectCodeEmitter() : BO(0) {} +ObjectCodeEmitter::ObjectCodeEmitter(BinaryObject *bo) : BO(bo) {} +ObjectCodeEmitter::~ObjectCodeEmitter() {} + +/// setBinaryObject - set the BinaryObject we are writting to +void ObjectCodeEmitter::setBinaryObject(BinaryObject *bo) { BO = bo; } + +/// emitByte - This callback is invoked when a byte needs to be +/// written to the data stream, without buffer overflow testing. +void ObjectCodeEmitter::emitByte(uint8_t B) { + BO->emitByte(B); +} + +/// emitWordLE - This callback is invoked when a 32-bit word needs to be +/// written to the data stream in little-endian format. +void ObjectCodeEmitter::emitWordLE(uint32_t W) { + BO->emitWordLE(W); +} + +/// emitWordBE - This callback is invoked when a 32-bit word needs to be +/// written to the data stream in big-endian format. +void ObjectCodeEmitter::emitWordBE(uint32_t W) { + BO->emitWordBE(W); +} + +/// emitDWordLE - This callback is invoked when a 64-bit word needs to be +/// written to the data stream in little-endian format. +void ObjectCodeEmitter::emitDWordLE(uint64_t W) { + BO->emitDWordLE(W); +} + +/// emitDWordBE - This callback is invoked when a 64-bit word needs to be +/// written to the data stream in big-endian format. +void ObjectCodeEmitter::emitDWordBE(uint64_t W) { + BO->emitDWordBE(W); +} + +/// emitAlignment - Move the CurBufferPtr pointer up the the specified +/// alignment (saturated to BufferEnd of course). +void ObjectCodeEmitter::emitAlignment(unsigned Alignment /* 0 */, + uint8_t fill /* 0 */) { + BO->emitAlignment(Alignment, fill); +} + +/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be +/// written to the data stream. +void ObjectCodeEmitter::emitULEB128Bytes(uint64_t Value) { + BO->emitULEB128Bytes(Value); +} + +/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be +/// written to the data stream. +void ObjectCodeEmitter::emitSLEB128Bytes(uint64_t Value) { + BO->emitSLEB128Bytes(Value); +} + +/// emitString - This callback is invoked when a String needs to be +/// written to the data stream. +void ObjectCodeEmitter::emitString(const std::string &String) { + BO->emitString(String); +} + +/// getCurrentPCValue - This returns the address that the next emitted byte +/// will be output to. +uintptr_t ObjectCodeEmitter::getCurrentPCValue() const { + return BO->getCurrentPCOffset(); +} + +/// getCurrentPCOffset - Return the offset from the start of the emitted +/// buffer that we are currently writing to. +uintptr_t ObjectCodeEmitter::getCurrentPCOffset() const { + return BO->getCurrentPCOffset(); +} + +/// addRelocation - Whenever a relocatable address is needed, it should be +/// noted with this interface. +void ObjectCodeEmitter::addRelocation(const MachineRelocation& relocation) { + BO->addRelocation(relocation); +} + +/// StartMachineBasicBlock - This should be called by the target when a new +/// basic block is about to be emitted. This way the MCE knows where the +/// start of the block is, and can implement getMachineBasicBlockAddress. +void ObjectCodeEmitter::StartMachineBasicBlock(MachineBasicBlock *MBB) { + if (MBBLocations.size() <= (unsigned)MBB->getNumber()) + MBBLocations.resize((MBB->getNumber()+1)*2); + MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); +} + +/// getMachineBasicBlockAddress - Return the address of the specified +/// MachineBasicBlock, only usable after the label for the MBB has been +/// emitted. +uintptr_t +ObjectCodeEmitter::getMachineBasicBlockAddress(MachineBasicBlock *MBB) const { + assert(MBBLocations.size() > (unsigned)MBB->getNumber() && + MBBLocations[MBB->getNumber()] && "MBB not emitted!"); + return MBBLocations[MBB->getNumber()]; +} + +/// getJumpTableEntryAddress - Return the address of the jump table with index +/// 'Index' in the function that last called initJumpTableInfo. +uintptr_t ObjectCodeEmitter::getJumpTableEntryAddress(unsigned Index) const { + assert(JTLocations.size() > Index && "JT not emitted!"); + return JTLocations[Index]; +} + +/// getConstantPoolEntryAddress - Return the address of the 'Index' entry in +/// the constant pool that was last emitted with the emitConstantPool method. +uintptr_t ObjectCodeEmitter::getConstantPoolEntryAddress(unsigned Index) const { + assert(CPLocations.size() > Index && "CP not emitted!"); + return CPLocations[Index]; +} + +/// getConstantPoolEntrySection - Return the section of the 'Index' entry in +/// the constant pool that was last emitted with the emitConstantPool method. +uintptr_t ObjectCodeEmitter::getConstantPoolEntrySection(unsigned Index) const { + assert(CPSections.size() > Index && "CP not emitted!"); + return CPSections[Index]; +} + +} // end namespace llvm + From eli.friedman at gmail.com Mon Jul 6 01:02:46 2009 From: eli.friedman at gmail.com (Eli Friedman) Date: Sun, 5 Jul 2009 23:02:46 -0700 Subject: [llvm-commits] PATCH: remove VICmp and VFCmp. In-Reply-To: <4A518899.80806@mxc.ca> References: <4A518899.80806@mxc.ca> Message-ID: On Sun, Jul 5, 2009 at 10:16 PM, Nick Lewycky wrote: > This patch removes vicmp and vfcmp, which has the positive side that it > fixes existing type-safety bugs and simplifies some code, but a downside in > that it XFAILs 9 CodeGen tests. > > May I commit this? The only question is whether anyone is using it; since vector icmp is effectively unusable, the only ways to compare vectors without vicmp/vfcmp are by scalarizing them or using platform-specific intrinsics. Either way, it's probably best to wait a few days to see if anyone objects. It would be nice to include testcases for the relevant type-safety bugs. -Eli From bruno.cardoso at gmail.com Mon Jul 6 01:40:51 2009 From: bruno.cardoso at gmail.com (Bruno Cardoso Lopes) Date: Mon, 06 Jul 2009 06:40:51 -0000 Subject: [llvm-commits] [llvm] r74817 - in /llvm/trunk/lib/CodeGen: MachO.h MachOCodeEmitter.cpp MachOCodeEmitter.h MachOWriter.cpp MachOWriter.h Message-ID: <200907060640.n666epJo029039@zion.cs.uiuc.edu> Author: bruno Date: Mon Jul 6 01:40:51 2009 New Revision: 74817 URL: http://llvm.org/viewvc/llvm-project?rev=74817&view=rev Log: Cleanup MachO writer and code emitter. Fix 80 cols problems, remove extra spaces, shrink down includes and move some methods out-of-line Modified: llvm/trunk/lib/CodeGen/MachO.h llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp llvm/trunk/lib/CodeGen/MachOCodeEmitter.h llvm/trunk/lib/CodeGen/MachOWriter.cpp llvm/trunk/lib/CodeGen/MachOWriter.h Modified: llvm/trunk/lib/CodeGen/MachO.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachO.h?rev=74817&r1=74816&r2=74817&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachO.h (original) +++ llvm/trunk/lib/CodeGen/MachO.h Mon Jul 6 01:40:51 2009 @@ -14,18 +14,15 @@ #ifndef MACHO_H #define MACHO_H -#include "llvm/Constants.h" -#include "llvm/DerivedTypes.h" -#include "llvm/CodeGen/MachineRelocation.h" #include "llvm/CodeGen/BinaryObject.h" -#include "llvm/Target/TargetAsmInfo.h" #include #include namespace llvm { -typedef std::vector DataBuffer; - +class GlobalValue; +class TargetAsmInfo; + /// MachOSym - This struct contains information about each symbol that is /// added to logical symbol table for the module. This is eventually /// turned into a real symbol table in the file. @@ -111,7 +108,7 @@ /// HeaderData - The actual data for the header which we are building /// up for emission to the file. - DataBuffer HeaderData; + std::vector HeaderData; // Constants for the filetype field // see for additional info on the various types @@ -181,8 +178,8 @@ }; MachOHeader() : magic(0), filetype(0), ncmds(0), sizeofcmds(0), flags(0), - reserved(0) { } - + reserved(0) {} + /// cmdSize - This routine returns the size of the MachOSection as written /// to disk, depending on whether the destination is a 64 bit Mach-O file. unsigned cmdSize(bool is64Bit) const { @@ -204,7 +201,7 @@ } }; // end struct MachOHeader - + /// MachOSegment - This struct contains the necessary information to /// emit the load commands for each section in the file. struct MachOSegment { @@ -246,13 +243,13 @@ SEG_VM_PROT_EXECUTE = VM_PROT_EXECUTE, SEG_VM_PROT_ALL = VM_PROT_ALL }; - + // Constants for the cmd field // see enum { LC_SEGMENT = 0x01, // segment of this file to be mapped LC_SEGMENT_64 = 0x19 // 64-bit segment of this file to be mapped }; - + /// cmdSize - This routine returns the size of the MachOSection as written /// to disk, depending on whether the destination is a 64 bit Mach-O file. unsigned cmdSize(bool is64Bit) const { @@ -285,15 +282,15 @@ uint32_t reserved1; // reserved (for offset or index) uint32_t reserved2; // reserved (for count or sizeof) uint32_t reserved3; // reserved (64 bit only) - + /// A unique number for this section, which will be used to match symbols /// to the correct section. uint32_t Index; - + /// RelocBuffer - A buffer to hold the mach-o relocations before we write /// them out at the appropriate location in the file. - DataBuffer RelocBuffer; - + std::vector RelocBuffer; + // Constants for the section types (low 8 bits of flags field) // see enum { S_REGULAR = 0, @@ -405,7 +402,7 @@ ilocalsym(0), nlocalsym(0), iextdefsym(0), nextdefsym(0), iundefsym(0), nundefsym(0), tocoff(0), ntoc(0), modtaboff(0), nmodtab(0), extrefsymoff(0), nextrefsyms(0), indirectsymoff(0), - nindirectsyms(0), extreloff(0), nextrel(0), locreloff(0), nlocrel(0) { } + nindirectsyms(0), extreloff(0), nextrel(0), locreloff(0), nlocrel(0) {} }; // end struct MachODySymTab Modified: llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp?rev=74817&r1=74816&r2=74817&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp (original) +++ llvm/trunk/lib/CodeGen/MachOCodeEmitter.cpp Mon Jul 6 01:40:51 2009 @@ -7,13 +7,18 @@ // //===----------------------------------------------------------------------===// +#include "MachO.h" +#include "MachOWriter.h" #include "MachOCodeEmitter.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Function.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" +#include "llvm/CodeGen/MachineRelocation.h" #include "llvm/Target/TargetAsmInfo.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/OutputBuffer.h" #include @@ -23,7 +28,14 @@ //===----------------------------------------------------------------------===// namespace llvm { - + +MachOCodeEmitter::MachOCodeEmitter(MachOWriter &mow, MachOSection &mos) : + ObjectCodeEmitter(&mos), MOW(mow), TM(MOW.TM) { + is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; + isLittleEndian = TM.getTargetData()->isLittleEndian(); + TAI = TM.getTargetAsmInfo(); +} + /// startFunction - This callback is invoked when a new machine function is /// about to be emitted. @@ -141,7 +153,8 @@ for (unsigned j = 0; j < Size; ++j) SecDataOut.outbyte(0); - MachOWriter::InitMem(CP[i].Val.ConstVal, CPLocations[i], TM.getTargetData(), Sec); + MachOWriter::InitMem(CP[i].Val.ConstVal, CPLocations[i], + TM.getTargetData(), Sec); } } Modified: llvm/trunk/lib/CodeGen/MachOCodeEmitter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOCodeEmitter.h?rev=74817&r1=74816&r2=74817&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOCodeEmitter.h (original) +++ llvm/trunk/lib/CodeGen/MachOCodeEmitter.h Mon Jul 6 01:40:51 2009 @@ -10,10 +10,13 @@ #ifndef MACHOCODEEMITTER_H #define MACHOCODEEMITTER_H -#include "MachOWriter.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" +#include namespace llvm { +class MachOWriter; + /// MachOCodeEmitter - This class is used by the MachOWriter to emit the code /// for functions to the Mach-O file. @@ -36,12 +39,7 @@ std::map Labels; public: - MachOCodeEmitter(MachOWriter &mow, MachOSection &mos) : - ObjectCodeEmitter(&mos), MOW(mow), TM(MOW.TM) { - is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; - isLittleEndian = TM.getTargetData()->isLittleEndian(); - TAI = TM.getTargetAsmInfo(); - } + MachOCodeEmitter(MachOWriter &mow, MachOSection &mos); virtual void startFunction(MachineFunction &MF); virtual bool finishFunction(MachineFunction &MF); @@ -49,7 +47,7 @@ virtual void addRelocation(const MachineRelocation &MR) { Relocations.push_back(MR); } - + void emitConstantPool(MachineConstantPool *MCP); void emitJumpTables(MachineJumpTableInfo *MJTI); Modified: llvm/trunk/lib/CodeGen/MachOWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.cpp?rev=74817&r1=74816&r2=74817&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/MachOWriter.cpp Mon Jul 6 01:40:51 2009 @@ -22,25 +22,20 @@ // //===----------------------------------------------------------------------===// +#include "MachO.h" #include "MachOWriter.h" #include "MachOCodeEmitter.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/PassManager.h" -#include "llvm/CodeGen/FileWriters.h" -#include "llvm/CodeGen/MachineCodeEmitter.h" -#include "llvm/CodeGen/MachineConstantPool.h" -#include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/Target/TargetAsmInfo.h" -#include "llvm/Target/TargetJITInfo.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetMachOWriterInfo.h" #include "llvm/Support/Mangler.h" -#include "llvm/Support/MathExtras.h" #include "llvm/Support/OutputBuffer.h" -#include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h" -#include -#include namespace llvm { @@ -60,16 +55,14 @@ char MachOWriter::ID = 0; -MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm) - : MachineFunctionPass(&ID), O(o), TM(tm) - { +MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm) + : MachineFunctionPass(&ID), O(o), TM(tm) { is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; isLittleEndian = TM.getTargetData()->isLittleEndian(); TAI = TM.getTargetAsmInfo(); // Create the machine code emitter object for this target. - MachOCE = new MachOCodeEmitter(*this, *getTextSection(true)); } @@ -98,13 +91,13 @@ /// the Mach-O file to 'O'. bool MachOWriter::doFinalization(Module &M) { // FIXME: we don't handle debug info yet, we should probably do that. - // Okay, the.text section has been completed, build the .data, .bss, and + // Okay, the.text section has been completed, build the .data, .bss, and // "common" sections next. for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) EmitGlobal(I); - + // Emit the header and load commands. EmitHeaderAndLoadCommands(); @@ -126,6 +119,89 @@ return false; } +// getConstSection - Get constant section for Constant 'C' +MachOSection *MachOWriter::getConstSection(Constant *C) { + const ConstantArray *CVA = dyn_cast(C); + if (CVA && CVA->isCString()) + return getSection("__TEXT", "__cstring", + MachOSection::S_CSTRING_LITERALS); + + const Type *Ty = C->getType(); + if (Ty->isPrimitiveType() || Ty->isInteger()) { + unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); + switch(Size) { + default: break; // Fall through to __TEXT,__const + case 4: + return getSection("__TEXT", "__literal4", + MachOSection::S_4BYTE_LITERALS); + case 8: + return getSection("__TEXT", "__literal8", + MachOSection::S_8BYTE_LITERALS); + case 16: + return getSection("__TEXT", "__literal16", + MachOSection::S_16BYTE_LITERALS); + } + } + return getSection("__TEXT", "__const"); +} + +// getJumpTableSection - Select the Jump Table section +MachOSection *MachOWriter::getJumpTableSection() { + if (TM.getRelocationModel() == Reloc::PIC_) + return getTextSection(false); + else + return getSection("__TEXT", "__const"); +} + +// getSection - Return the section with the specified name, creating a new +// section if one does not already exist. +MachOSection *MachOWriter::getSection(const std::string &seg, + const std::string §, + unsigned Flags /* = 0 */ ) { + MachOSection *MOS = SectionLookup[seg+sect]; + if (MOS) return MOS; + + MOS = new MachOSection(seg, sect); + SectionList.push_back(MOS); + MOS->Index = SectionList.size(); + MOS->flags = MachOSection::S_REGULAR | Flags; + SectionLookup[seg+sect] = MOS; + return MOS; +} + +// getTextSection - Return text section with different flags for code/data +MachOSection *MachOWriter::getTextSection(bool isCode /* = true */ ) { + if (isCode) + return getSection("__TEXT", "__text", + MachOSection::S_ATTR_PURE_INSTRUCTIONS | + MachOSection::S_ATTR_SOME_INSTRUCTIONS); + else + return getSection("__TEXT", "__text"); +} + +MachOSection *MachOWriter::getBSSSection() { + return getSection("__DATA", "__bss", MachOSection::S_ZEROFILL); +} + +// GetJTRelocation - Get a relocation a new BB relocation based +// on target information. +MachineRelocation MachOWriter::GetJTRelocation(unsigned Offset, + MachineBasicBlock *MBB) const { + return TM.getMachOWriterInfo()->GetJTRelocation(Offset, MBB); +} + +// GetTargetRelocation - Returns the number of relocations. +unsigned MachOWriter::GetTargetRelocation(MachineRelocation &MR, + unsigned FromIdx, unsigned ToAddr, + unsigned ToIndex, OutputBuffer &RelocOut, + OutputBuffer &SecOut, bool Scattered, + bool Extern) { + return TM.getMachOWriterInfo()->GetTargetRelocation(MR, FromIdx, ToAddr, + ToIndex, RelocOut, + SecOut, Scattered, + Extern); +} + void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) { const Type *Ty = GV->getType()->getElementType(); unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); @@ -151,15 +227,15 @@ // Record the offset of the symbol, and then allocate space for it. // FIXME: remove when we have unified size + output buffer - - // Now that we know what section the GlovalVariable is going to be emitted + + // Now that we know what section the GlovalVariable is going to be emitted // into, update our mappings. // FIXME: We may also need to update this when outputting non-GlobalVariable // GlobalValues such as functions. GVSection[GV] = Sec; GVOffset[GV] = Sec->size(); - + // Allocate space in the section for the global. for (unsigned i = 0; i < Size; ++i) SecDataOut.outbyte(0); @@ -169,7 +245,7 @@ const Type *Ty = GV->getType()->getElementType(); unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); bool NoInit = !GV->hasInitializer(); - + // If this global has a zero initializer, it is part of the .bss or common // section. if (NoInit || GV->getInitializer()->isNullValue()) { @@ -178,7 +254,8 @@ // merged with other symbols. if (NoInit || GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() || GV->hasCommonLinkage()) { - MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV), MachOSym::NO_SECT, TAI); + MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV), + MachOSym::NO_SECT, TAI); // For undefined (N_UNDF) external (N_EXT) types, n_value is the size in // bytes of the symbol. ExtOrCommonSym.n_value = Size; @@ -192,11 +269,11 @@ AddSymbolToSection(BSS, GV); return; } - + // Scalar read-only data goes in a literal section if the scalar is 4, 8, or // 16 bytes, or a cstring. Other read only data goes into a regular const // section. Read-write data goes in the data section. - MachOSection *Sec = GV->isConstant() ? getConstSection(GV->getInitializer()) : + MachOSection *Sec = GV->isConstant() ? getConstSection(GV->getInitializer()) : getDataSection(); AddSymbolToSection(Sec, GV); InitMem(GV->getInitializer(), GVOffset[GV], TM.getTargetData(), Sec); @@ -210,22 +287,22 @@ MachOSegment SEG("", is64Bit); SEG.nsects = SectionList.size(); - SEG.cmdsize = SEG.cmdSize(is64Bit) + + SEG.cmdsize = SEG.cmdSize(is64Bit) + SEG.nsects * SectionList[0]->cmdSize(is64Bit); - + // Step #1: calculate the number of load commands. We always have at least // one, for the LC_SEGMENT load command, plus two for the normal // and dynamic symbol tables, if there are any symbols. Header.ncmds = SymbolTable.empty() ? 1 : 3; - + // Step #2: calculate the size of the load commands Header.sizeofcmds = SEG.cmdsize; if (!SymbolTable.empty()) Header.sizeofcmds += SymTab.cmdsize + DySymTab.cmdsize; - + // Step #3: write the header to the file // Local alias to shortenify coming code. - DataBuffer &FH = Header.HeaderData; + std::vector &FH = Header.HeaderData; OutputBuffer FHOut(FH, is64Bit, isLittleEndian); FHOut.outword(Header.magic); @@ -237,7 +314,7 @@ FHOut.outword(Header.flags); if (is64Bit) FHOut.outword(Header.reserved); - + // Step #4: Finish filling in the segment load command and write it out for (std::vector::iterator I = SectionList.begin(), E = SectionList.end(); I != E; ++I) @@ -245,7 +322,7 @@ SEG.vmsize = SEG.filesize; SEG.fileoff = Header.cmdSize(is64Bit) + Header.sizeofcmds; - + FHOut.outword(SEG.cmd); FHOut.outword(SEG.cmdsize); FHOut.outstring(SEG.segname, 16); @@ -257,8 +334,8 @@ FHOut.outword(SEG.initprot); FHOut.outword(SEG.nsects); FHOut.outword(SEG.flags); - - // Step #5: Finish filling in the fields of the MachOSections + + // Step #5: Finish filling in the fields of the MachOSections uint64_t currentAddr = 0; for (std::vector::iterator I = SectionList.begin(), E = SectionList.end(); I != E; ++I) { @@ -268,13 +345,13 @@ // FIXME: do we need to do something with alignment here? currentAddr += MOS->size(); } - + // Step #6: Emit the symbol table to temporary buffers, so that we know the // size of the string table when we write the next load command. This also // sorts and assigns indices to each of the symbols, which is necessary for // emitting relocations to externally-defined objects. BufferSymbolAndStringTable(); - + // Step #7: Calculate the number of relocations for each section and write out // the section commands for each section currentAddr += SEG.fileoff; @@ -287,7 +364,7 @@ CalculateRelocations(*MOS); MOS->reloff = MOS->nreloc ? currentAddr : 0; currentAddr += MOS->nreloc * 8; - + // write the finalized section command to the output buffer FHOut.outstring(MOS->sectname, 16); FHOut.outstring(MOS->segname, 16); @@ -303,7 +380,7 @@ if (is64Bit) FHOut.outword(MOS->reserved3); } - + // Step #8: Emit LC_SYMTAB/LC_DYSYMTAB load commands SymTab.symoff = currentAddr; SymTab.nsyms = SymbolTable.size(); @@ -339,7 +416,7 @@ FHOut.outword(DySymTab.nextrel); FHOut.outword(DySymTab.locreloff); FHOut.outword(DySymTab.nlocrel); - + O.write((char*)&FH[0], FH.size()); } @@ -370,7 +447,7 @@ // 1. local symbols // 2. defined external symbols (sorted by name) // 3. undefined external symbols (sorted by name) - + // Before sorting the symbols, check the PendingGlobals for any undefined // globals that need to be put in the symbol table. for (std::vector::iterator I = PendingGlobals.begin(), @@ -386,10 +463,11 @@ // of definition, we won't have to sort by name within each partition. std::sort(SymbolTable.begin(), SymbolTable.end(), MachOSym::SymCmp()); - // Parition the symbol table entries so that all local symbols come before + // Parition the symbol table entries so that all local symbols come before // all symbols with external linkage. { 1 | 2 3 } - std::partition(SymbolTable.begin(), SymbolTable.end(), MachOSym::PartitionByLocal); - + std::partition(SymbolTable.begin(), SymbolTable.end(), + MachOSym::PartitionByLocal); + // Advance iterator to beginning of external symbols and partition so that // all external symbols defined in this module come before all external // symbols defined elsewhere. { 1 | 2 | 3 } @@ -401,7 +479,7 @@ } } - // Calculate the starting index for each of the local, extern defined, and + // Calculate the starting index for each of the local, extern defined, and // undefined symbols, as well as the number of each to put in the LC_DYSYMTAB // load command. for (std::vector::iterator I = SymbolTable.begin(), @@ -417,7 +495,7 @@ ++DySymTab.nundefsym; } } - + // Write out a leading zero byte when emitting string table, for n_strx == 0 // which means an empty string. OutputBuffer StrTOut(StrT, is64Bit, isLittleEndian); @@ -451,7 +529,7 @@ I->n_value += GVSection[GV]->addr; if (GV && (GVOffset[GV] == -1)) GVOffset[GV] = index; - + // Emit nlist to buffer SymTOut.outword(I->n_strx); SymTOut.outbyte(I->n_type); @@ -486,7 +564,7 @@ GlobalValue *GV = MR.getGlobalValue(); MachOSection *MOSPtr = GVSection[GV]; intptr_t Offset = GVOffset[GV]; - + // If we have never seen the global before, it must be to a symbol // defined in another module (N_UNDF). if (!MOSPtr) { @@ -500,7 +578,7 @@ } MR.setResultPointer((void*)Offset); } - + // If the symbol is locally defined, pass in the address of the section and // the section index to the code which will generate the target relocation. if (!Extern) { @@ -519,21 +597,21 @@ // InitMem - Write the value of a Constant to the specified memory location, // converting it into bytes and relocations. -void MachOWriter::InitMem(const Constant *C, uintptr_t Offset, +void MachOWriter::InitMem(const Constant *C, uintptr_t Offset, const TargetData *TD, MachOSection* mos) { typedef std::pair CPair; std::vector WorkList; uint8_t *Addr = &mos->getData()[0]; - + WorkList.push_back(CPair(C,(intptr_t)Addr + Offset)); - + intptr_t ScatteredOffset = 0; - + while (!WorkList.empty()) { const Constant *PC = WorkList.back().first; intptr_t PA = WorkList.back().second; WorkList.pop_back(); - + if (isa(PC)) { continue; } else if (const ConstantVector *CP = dyn_cast(PC)) { @@ -626,7 +704,7 @@ memset(ptr, 0, TD->getPointerSize()); else if (const GlobalValue* GV = dyn_cast(PC)) { // FIXME: what about function stubs? - mos->addRelocation(MachineRelocation::getGV(PA-(intptr_t)Addr, + mos->addRelocation(MachineRelocation::getGV(PA-(intptr_t)Addr, MachineRelocation::VANILLA, const_cast(GV), ScatteredOffset)); Modified: llvm/trunk/lib/CodeGen/MachOWriter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.h?rev=74817&r1=74816&r2=74817&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/MachOWriter.h (original) +++ llvm/trunk/lib/CodeGen/MachOWriter.h Mon Jul 6 01:40:51 2009 @@ -14,29 +14,27 @@ #ifndef MACHOWRITER_H #define MACHOWRITER_H -#include "MachO.h" -#include "llvm/Constants.h" -#include "llvm/DerivedTypes.h" #include "llvm/CodeGen/MachineFunctionPass.h" -#include "llvm/CodeGen/ObjectCodeEmitter.h" -#include "llvm/Target/TargetData.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetMachOWriterInfo.h" #include #include namespace llvm { + class Constant; class GlobalVariable; class Mangler; class MachineRelocation; - class ObjectCodeEmitter; class MachOCodeEmitter; + class MachODySymTab; + class MachOHeader; + class MachOSection; + class MachOSym; class TargetData; class TargetMachine; + class TargetAsmInfo; + class ObjectCodeEmitter; class OutputBuffer; class raw_ostream; - /// MachOWriter - This class implements the common target-independent code for /// writing Mach-O files. Targets should derive a class from this to /// parameterize the output format. @@ -69,36 +67,30 @@ /// Mang - The object used to perform name mangling for this module. /// Mangler *Mang; - - /// MachOCE - The MachineCodeEmitter object that we are exposing to emit machine - /// code for functions to the .o file. + /// MachOCE - The MachineCodeEmitter object that we are exposing to emit + /// machine code for functions to the .o file. MachOCodeEmitter *MachOCE; /// is64Bit/isLittleEndian - This information is inferred from the target /// machine directly, indicating what header values and flags to set. - bool is64Bit, isLittleEndian; // Target Asm Info - const TargetAsmInfo *TAI; /// Header - An instance of MachOHeader that we will update while we build /// the file, and then emit during finalization. - MachOHeader Header; /// doInitialization - Emit the file header and all of the global variables /// for the module to the Mach-O file. - bool doInitialization(Module &M); bool runOnMachineFunction(MachineFunction &MF); /// doFinalization - Now that the module has been completely processed, emit /// the Mach-O file to 'O'. - bool doFinalization(Module &M); private: @@ -106,85 +98,37 @@ /// SectionList - This is the list of sections that we have emitted to the /// file. Once the file has been completely built, the segment load command /// SectionCommands are constructed from this info. - std::vector SectionList; /// SectionLookup - This is a mapping from section name to SectionList entry - std::map SectionLookup; - + /// GVSection - This is a mapping from a GlobalValue to a MachOSection, /// to aid in emitting relocations. - std::map GVSection; - /// GVOffset - This is a mapping from a GlobalValue to an offset from the + /// GVOffset - This is a mapping from a GlobalValue to an offset from the /// start of the section in which the GV resides, to aid in emitting /// relocations. - std::map GVOffset; /// getSection - Return the section with the specified name, creating a new /// section if one does not already exist. - MachOSection *getSection(const std::string &seg, const std::string §, - unsigned Flags = 0) { - MachOSection *MOS = SectionLookup[seg+sect]; - if (MOS) return MOS; - - MOS = new MachOSection(seg, sect); - SectionList.push_back(MOS); - MOS->Index = SectionList.size(); - MOS->flags = MachOSection::S_REGULAR | Flags; - SectionLookup[seg+sect] = MOS; - return MOS; - } - MachOSection *getTextSection(bool isCode = true) { - if (isCode) - return getSection("__TEXT", "__text", - MachOSection::S_ATTR_PURE_INSTRUCTIONS | - MachOSection::S_ATTR_SOME_INSTRUCTIONS); - else - return getSection("__TEXT", "__text"); - } - MachOSection *getBSSSection() { - return getSection("__DATA", "__bss", MachOSection::S_ZEROFILL); - } + unsigned Flags = 0); + + /// getTextSection - Return text section with different flags for code/data + MachOSection *getTextSection(bool isCode = true); + MachOSection *getDataSection() { return getSection("__DATA", "__data"); } - MachOSection *getConstSection(Constant *C) { - const ConstantArray *CVA = dyn_cast(C); - if (CVA && CVA->isCString()) - return getSection("__TEXT", "__cstring", - MachOSection::S_CSTRING_LITERALS); - - const Type *Ty = C->getType(); - if (Ty->isPrimitiveType() || Ty->isInteger()) { - unsigned Size = TM.getTargetData()->getTypeAllocSize(Ty); - switch(Size) { - default: break; // Fall through to __TEXT,__const - case 4: - return getSection("__TEXT", "__literal4", - MachOSection::S_4BYTE_LITERALS); - case 8: - return getSection("__TEXT", "__literal8", - MachOSection::S_8BYTE_LITERALS); - case 16: - return getSection("__TEXT", "__literal16", - MachOSection::S_16BYTE_LITERALS); - } - } - return getSection("__TEXT", "__const"); - } - MachOSection *getJumpTableSection() { - if (TM.getRelocationModel() == Reloc::PIC_) - return getTextSection(false); - else - return getSection("__TEXT", "__const"); - } - - /// MachOSymTab - This struct contains information about the offsets and + + MachOSection *getBSSSection(); + MachOSection *getConstSection(Constant *C); + MachOSection *getJumpTableSection(); + + /// MachOSymTab - This struct contains information about the offsets and /// size of symbol table information. /// segment. struct MachOSymTab { @@ -199,44 +143,42 @@ // see enum { LC_SYMTAB = 0x02 // link-edit stab symbol table info }; - + MachOSymTab() : cmd(LC_SYMTAB), cmdsize(6 * sizeof(uint32_t)), symoff(0), nsyms(0), stroff(0), strsize(0) { } }; - + /// SymTab - The "stab" style symbol table information - MachOSymTab SymTab; + MachOSymTab SymTab; /// DySymTab - symbol table info for the dynamic link editor MachODySymTab DySymTab; protected: - + /// SymbolTable - This is the list of symbols we have emitted to the file. /// This actually gets rearranged before emission to the file (to put the /// local symbols first in the list). std::vector SymbolTable; - + /// SymT - A buffer to hold the symbol table before we write it out at the /// appropriate location in the file. - DataBuffer SymT; - + std::vector SymT; + /// StrT - A buffer to hold the string table before we write it out at the /// appropriate location in the file. - DataBuffer StrT; - + std::vector StrT; + /// PendingSyms - This is a list of externally defined symbols that we have /// been asked to emit, but have not seen a reference to. When a reference /// is seen, the symbol will move from this list to the SymbolTable. std::vector PendingGlobals; - + /// DynamicSymbolTable - This is just a vector of indices into /// SymbolTable to aid in emitting the DYSYMTAB load command. std::vector DynamicSymbolTable; - - static void InitMem(const Constant *C, - uintptr_t Offset, - const TargetData *TD, - MachOSection* mos); + + static void InitMem(const Constant *C, uintptr_t Offset, + const TargetData *TD, MachOSection* mos); private: void AddSymbolToSection(MachOSection *MOS, GlobalVariable *GV); @@ -247,25 +189,16 @@ void BufferSymbolAndStringTable(); void CalculateRelocations(MachOSection &MOS); + // GetJTRelocation - Get a relocation a new BB relocation based + // on target information. MachineRelocation GetJTRelocation(unsigned Offset, - MachineBasicBlock *MBB) const { - return TM.getMachOWriterInfo()->GetJTRelocation(Offset, MBB); - } + MachineBasicBlock *MBB) const; /// GetTargetRelocation - Returns the number of relocations. - unsigned GetTargetRelocation(MachineRelocation &MR, - unsigned FromIdx, - unsigned ToAddr, - unsigned ToIndex, - OutputBuffer &RelocOut, - OutputBuffer &SecOut, - bool Scattered, - bool Extern) { - return TM.getMachOWriterInfo()->GetTargetRelocation(MR, FromIdx, ToAddr, - ToIndex, RelocOut, - SecOut, Scattered, - Extern); - } + unsigned GetTargetRelocation(MachineRelocation &MR, unsigned FromIdx, + unsigned ToAddr, unsigned ToIndex, + OutputBuffer &RelocOut, OutputBuffer &SecOut, + bool Scattered, bool Extern); }; } From sanjiv.gupta at microchip.com Mon Jul 6 03:22:16 2009 From: sanjiv.gupta at microchip.com (Sanjiv Gupta) Date: Mon, 06 Jul 2009 08:22:16 -0000 Subject: [llvm-commits] [llvm] r74819 - /llvm/trunk/lib/Target/PIC16/PIC16.h Message-ID: <200907060822.n668MG0k011337@zion.cs.uiuc.edu> Author: sgupta Date: Mon Jul 6 03:22:15 2009 New Revision: 74819 URL: http://llvm.org/viewvc/llvm-project?rev=74819&view=rev Log: Corrected the names description. Change in a comment. No functionality change. Modified: llvm/trunk/lib/Target/PIC16/PIC16.h Modified: llvm/trunk/lib/Target/PIC16/PIC16.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16.h?rev=74819&r1=74818&r2=74819&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16.h (original) +++ llvm/trunk/lib/Target/PIC16/PIC16.h Mon Jul 6 03:22:15 2009 @@ -83,7 +83,7 @@ // initialized globals - @idata..# // Function frame - @.frame_section. // Function autos - @.autos_section. - // Declarations - @section.0 + // Declarations - Enclosed in comments. No section for them. //---------------------------------------------------------- // Tags used to mangle different names. From bruno.cardoso at gmail.com Mon Jul 6 04:27:00 2009 From: bruno.cardoso at gmail.com (Bruno Cardoso Lopes) Date: Mon, 06 Jul 2009 09:27:00 -0000 Subject: [llvm-commits] [llvm] r74821 - in /llvm/trunk/lib/CodeGen: ELFCodeEmitter.cpp ELFCodeEmitter.h ELFWriter.cpp ELFWriter.h Message-ID: <200907060927.n669R4bv013725@zion.cs.uiuc.edu> Author: bruno Date: Mon Jul 6 04:26:48 2009 New Revision: 74821 URL: http://llvm.org/viewvc/llvm-project?rev=74821&view=rev Log: Changed ELFCodeEmitter to inherit from ObjectCodeEmitter Modified: llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp llvm/trunk/lib/CodeGen/ELFCodeEmitter.h llvm/trunk/lib/CodeGen/ELFWriter.cpp llvm/trunk/lib/CodeGen/ELFWriter.h Modified: llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp?rev=74821&r1=74820&r2=74821&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp (original) +++ llvm/trunk/lib/CodeGen/ELFCodeEmitter.cpp Mon Jul 6 04:26:48 2009 @@ -33,47 +33,30 @@ /// startFunction - This callback is invoked when a new machine function is /// about to be emitted. void ELFCodeEmitter::startFunction(MachineFunction &MF) { + DOUT << "processing function: " << MF.getFunction()->getName() << "\n"; + // Get the ELF Section that this function belongs in. ES = &EW.getTextSection(); - DOUT << "processing function: " << MF.getFunction()->getName() << "\n"; - - // FIXME: better memory management, this will be replaced by BinaryObjects - BinaryData &BD = ES->getData(); - BD.reserve(4096); - BufferBegin = &BD[0]; - BufferEnd = BufferBegin + BD.capacity(); + // Set the desired binary object to be used by the code emitters + setBinaryObject(ES); // Get the function alignment in bytes unsigned Align = (1 << MF.getAlignment()); - // Align the section size with the function alignment, so the function can - // start in a aligned offset, also update the section alignment if needed. - if (ES->Align < Align) ES->Align = Align; - ES->Size = (ES->Size + (Align-1)) & (-Align); - - // Snaity check on allocated space for text section - assert( ES->Size < 4096 && "no more space in TextSection" ); + // The function must start on its required alignment + ES->emitAlignment(Align); - // FIXME: Using ES->Size directly here instead of calculating it from the - // output buffer size (impossible because the code emitter deals only in raw - // bytes) forces us to manually synchronize size and write padding zero bytes - // to the output buffer for all non-text sections. For text sections, we do - // not synchonize the output buffer, and we just blow up if anyone tries to - // write non-code to it. An assert should probably be added to - // AddSymbolToSection to prevent calling it on the text section. - CurBufferPtr = BufferBegin + ES->Size; + // Update the section alignment if needed. + if (ES->Align < Align) ES->Align = Align; - // Record function start address relative to BufferBegin - FnStartPtr = CurBufferPtr; + // Record the function start offset + FnStartOff = ES->getCurrentPCOffset(); } /// finishFunction - This callback is invoked after the function is completely /// finished. bool ELFCodeEmitter::finishFunction(MachineFunction &MF) { - // Update Section Size - ES->Size = CurBufferPtr - BufferBegin; - // Add a symbol to represent the function. const Function *F = MF.getFunction(); ELFSym FnSym(F); @@ -81,10 +64,10 @@ FnSym.setBind(EW.getGlobalELFLinkage(F)); FnSym.setVisibility(EW.getGlobalELFVisibility(F)); FnSym.SectionIdx = ES->SectionIdx; - FnSym.Size = CurBufferPtr-FnStartPtr; + FnSym.Size = ES->getCurrentPCOffset()-FnStartOff; // Offset from start of Section - FnSym.Value = FnStartPtr-BufferBegin; + FnSym.Value = FnStartOff; // Locals should go on the symbol list front if (!F->hasPrivateLinkage()) { Modified: llvm/trunk/lib/CodeGen/ELFCodeEmitter.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFCodeEmitter.h?rev=74821&r1=74820&r2=74821&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/ELFCodeEmitter.h (original) +++ llvm/trunk/lib/CodeGen/ELFCodeEmitter.h Mon Jul 6 04:26:48 2009 @@ -10,7 +10,7 @@ #ifndef ELFCODEEMITTER_H #define ELFCODEEMITTER_H -#include "llvm/CodeGen/MachineCodeEmitter.h" +#include "llvm/CodeGen/ObjectCodeEmitter.h" #include namespace llvm { @@ -19,7 +19,7 @@ /// ELFCodeEmitter - This class is used by the ELFWriter to /// emit the code for functions to the ELF file. - class ELFCodeEmitter : public MachineCodeEmitter { + class ELFCodeEmitter : public ObjectCodeEmitter { ELFWriter &EW; /// Target machine description @@ -28,30 +28,11 @@ /// Section containing code for functions ELFSection *ES; - /// Relocations - These are the relocations that the function needs, as - /// emitted. + /// Relocations - Record relocations needed by the current function std::vector Relocations; - /// CPLocations - This is a map of constant pool indices to offsets from the - /// start of the section for that constant pool index. - std::vector CPLocations; - - /// CPSections - This is a map of constant pool indices to the MachOSection - /// containing the constant pool entry for that index. - std::vector CPSections; - - /// JTLocations - This is a map of jump table indices to offsets from the - /// start of the section for that jump table index. - std::vector JTLocations; - - /// MBBLocations - This vector is a mapping from MBB ID's to their address. - /// It is filled in by the StartMachineBasicBlock callback and queried by - /// the getMachineBasicBlockAddress callback. - std::vector MBBLocations; - - /// FnStartPtr - Pointer to the start location of the current function - /// in the buffer - uint8_t *FnStartPtr; + /// FnStartPtr - Function offset from the beginning of ELFSection 'ES' + uintptr_t FnStartOff; /// JumpTableSectionIdx - Holds the index of the Jump Table Section unsigned JumpTableSectionIdx; @@ -59,71 +40,36 @@ explicit ELFCodeEmitter(ELFWriter &ew) : EW(ew), TM(EW.TM), JumpTableSectionIdx(0) {} - void startFunction(MachineFunction &F); - bool finishFunction(MachineFunction &F); - + /// addRelocation - Register new relocations for this function void addRelocation(const MachineRelocation &MR) { Relocations.push_back(MR); } - virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) { - if (MBBLocations.size() <= (unsigned)MBB->getNumber()) - MBBLocations.resize((MBB->getNumber()+1)*2); - MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); - } + /// emitConstantPool - For each constant pool entry, figure out which + /// section the constant should live in and emit data to it + void emitConstantPool(MachineConstantPool *MCP); - virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const { - assert(CPLocations.size() > Index && "CP not emitted!"); - return CPLocations[Index]; - } + /// emitJumpTables - Emit all the jump tables for a given jump table + /// info and record them to the appropriate section. + void emitJumpTables(MachineJumpTableInfo *MJTI); - virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const { - assert(JTLocations.size() > Index && "JT not emitted!"); - return JTLocations[Index]; - } + void startFunction(MachineFunction &F); + bool finishFunction(MachineFunction &F); - virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const { - assert(MBBLocations.size() > (unsigned)MBB->getNumber() && - MBBLocations[MBB->getNumber()] && "MBB not emitted!"); - return MBBLocations[MBB->getNumber()]; + /// emitLabel - Emits a label + virtual void emitLabel(uint64_t LabelID) { + assert("emitLabel not implemented"); } + /// getLabelAddress - Return the address of the specified LabelID, + /// only usable after the LabelID has been emitted. virtual uintptr_t getLabelAddress(uint64_t Label) const { - assert(0 && "Label address not implementated yet!"); - abort(); + assert("getLabelAddress not implemented"); return 0; } - virtual void emitLabel(uint64_t LabelID) { - assert(0 && "emit Label not implementated yet!"); - abort(); - } - - /// emitConstantPool - For each constant pool entry, figure out which section - /// the constant should live in and emit the constant. - void emitConstantPool(MachineConstantPool *MCP); - - /// emitJumpTables - Emit all the jump tables for a given jump table info - /// record to the appropriate section. - void emitJumpTables(MachineJumpTableInfo *MJTI); - virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) {} - /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE! - void startGVStub(const GlobalValue* F, unsigned StubSize, - unsigned Alignment = 1) { - assert(0 && "JIT specific function called!"); - abort(); - } - void startGVStub(const GlobalValue* F, void *Buffer, unsigned StubSize) { - assert(0 && "JIT specific function called!"); - abort(); - } - void *finishGVStub(const GlobalValue *F) { - assert(0 && "JIT specific function called!"); - abort(); - return 0; - } }; // end class ELFCodeEmitter } // end namespace llvm Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=74821&r1=74820&r2=74821&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original) +++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Mon Jul 6 04:26:48 2009 @@ -51,17 +51,18 @@ #include "llvm/Support/Streams.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Debug.h" + using namespace llvm; char ELFWriter::ID = 0; -/// AddELFWriter - Concrete function to add the ELF writer to the function pass -/// manager. + +/// AddELFWriter - Add the ELF writer to the function pass manager ObjectCodeEmitter *llvm::AddELFWriter(PassManagerBase &PM, - raw_ostream &O, - TargetMachine &TM) { + raw_ostream &O, + TargetMachine &TM) { ELFWriter *EW = new ELFWriter(O, TM); PM.add(EW); - return (ObjectCodeEmitter*) &EW->getMachineCodeEmitter(); + return EW->getObjectCodeEmitter(); } //===----------------------------------------------------------------------===// @@ -77,15 +78,15 @@ TAI = TM.getTargetAsmInfo(); TEW = TM.getELFWriterInfo(); - // Create the machine code emitter object for this target. - MCE = new ELFCodeEmitter(*this); + // Create the object code emitter object for this target. + ElfCE = new ELFCodeEmitter(*this); // Inital number of sections NumSections = 0; } ELFWriter::~ELFWriter() { - delete MCE; + delete ElfCE; } // doInitialization - Emit the file header and all of the global variables for @@ -361,23 +362,13 @@ bool ELFWriter::runOnMachineFunction(MachineFunction &MF) { - // Nothing to do here, this is all done through the MCE object above. + // Nothing to do here, this is all done through the ElfCE object above. return false; } /// doFinalization - Now that the module has been completely processed, emit /// the ELF file to 'O'. bool ELFWriter::doFinalization(Module &M) { - /// FIXME: This should be removed when moving to ObjectCodeEmiter. Since the - /// current ELFCodeEmiter uses CurrBuff, ... it doesn't update S.Data - /// vector size for .text sections, so this is a quick dirty fix - ELFSection &TS = getTextSection(); - if (TS.Size) { - BinaryData &BD = TS.getData(); - for (unsigned e=0; e(ElfCE); } ELFWriter(raw_ostream &O, TargetMachine &TM); ~ELFWriter(); - typedef std::vector DataBuffer; - protected: /// Output stream to send the resultant object file to. raw_ostream &O; @@ -67,7 +67,7 @@ /// MCE - The MachineCodeEmitter object that we are exposing to emit machine /// code for functions to the .o file. - ELFCodeEmitter *MCE; + ELFCodeEmitter *ElfCE; /// TAI - Target Asm Info, provide information about section names for /// globals and other target specific stuff. From sanjiv.gupta at microchip.com Mon Jul 6 05:18:44 2009 From: sanjiv.gupta at microchip.com (Sanjiv Gupta) Date: Mon, 06 Jul 2009 10:18:44 -0000 Subject: [llvm-commits] [llvm] r74822 - in /llvm/trunk/lib: CompilerDriver/BuiltinOptions.cpp CompilerDriver/Main.cpp Target/PIC16/PIC16.h Target/PIC16/PIC16AsmPrinter.cpp Target/PIC16/PIC16TargetAsmInfo.cpp Target/PIC16/PIC16TargetAsmInfo.h Message-ID: <200907061018.n66AIjau015273@zion.cs.uiuc.edu> Author: sgupta Date: Mon Jul 6 05:18:37 2009 New Revision: 74822 URL: http://llvm.org/viewvc/llvm-project?rev=74822&view=rev Log: Implement _CONFIG macro to allow users to se to configuration settings on the part. Implement _section macro to allow users to place objects in specific sections. Implement _address macro to allow users to place objects at a particular address. Placing objects at a memory address: crate a unique section name from varname, address, object type and put that section at specified address. Mark this section a full (size = banksize) so that other objects do not compete for it while placing objects to sections in AsmPrinter. Modified: llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp llvm/trunk/lib/CompilerDriver/Main.cpp llvm/trunk/lib/Target/PIC16/PIC16.h llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h Modified: llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp?rev=74822&r1=74821&r2=74822&view=diff ============================================================================== --- llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp (original) +++ llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp Mon Jul 6 05:18:37 2009 @@ -52,4 +52,5 @@ "Use current working directory"), clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"), clEnumValEnd), - cl::ValueOptional); + //cl::ValueOptional); + cl::Hidden); Modified: llvm/trunk/lib/CompilerDriver/Main.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/Main.cpp?rev=74822&r1=74821&r2=74822&view=diff ============================================================================== --- llvm/trunk/lib/CompilerDriver/Main.cpp (original) +++ llvm/trunk/lib/CompilerDriver/Main.cpp Mon Jul 6 05:18:37 2009 @@ -31,6 +31,17 @@ sys::Path getTempDir() { sys::Path tempDir; +///////////////////////////////////////////// + std::string p = "tmp-objs"; + tempDir = sys::Path(p); + if (!tempDir.exists()) { + std::string ErrMsg; + if (tempDir.createDirectoryOnDisk(true, &ErrMsg)) + throw std::runtime_error(ErrMsg); + } + return tempDir; +///////////////////////////////////////////// + // GCC 4.5-style -save-temps handling. if (SaveTemps == SaveTempsEnum::Unset) { tempDir = sys::Path::GetTemporaryDirectory(); Modified: llvm/trunk/lib/Target/PIC16/PIC16.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16.h?rev=74822&r1=74821&r2=74822&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16.h (original) +++ llvm/trunk/lib/Target/PIC16/PIC16.h Mon Jul 6 05:18:37 2009 @@ -221,17 +221,29 @@ return Func1 + tag + "# CODE"; } - // udata and idata section names are generated by a given number. + // udata, romdata and idata section names are generated by a given number. // @udata..# - static std::string getUdataSectionName(unsigned num) { + static std::string getUdataSectionName(unsigned num, + std::string prefix = "") { std::ostringstream o; - o << getTagName(PREFIX_SYMBOL) << "udata." << num << ".# UDATA"; + o << getTagName(PREFIX_SYMBOL) << prefix << "udata." << num + << ".# UDATA"; return o.str(); } - static std::string getIdataSectionName(unsigned num) { + static std::string getRomdataSectionName(unsigned num, + std::string prefix = "") { std::ostringstream o; - o << getTagName(PREFIX_SYMBOL) << "idata." << num << ".# IDATA"; + o << getTagName(PREFIX_SYMBOL) << prefix << "romdata." << num + << ".# ROMDATA"; + return o.str(); + } + + static std::string getIdataSectionName(unsigned num, + std::string prefix = "") { + std::ostringstream o; + o << getTagName(PREFIX_SYMBOL) << prefix << "idata." << num + << ".# IDATA"; return o.str(); } Modified: llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp?rev=74822&r1=74821&r2=74822&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp Mon Jul 6 05:18:37 2009 @@ -272,18 +272,19 @@ // Emit initialized data placed in ROM. void PIC16AsmPrinter::EmitRomData (Module &M) { - - std::vector Items = PTAI->ROSection->Items; - if (! Items.size()) return; - - // Print ROData ection. - O << "\n"; - SwitchToSection(PTAI->ROSection->S_); - for (unsigned j = 0; j < Items.size(); j++) { - O << Mang->getValueName(Items[j]); - Constant *C = Items[j]->getInitializer(); - int AddrSpace = Items[j]->getType()->getAddressSpace(); - EmitGlobalConstant(C, AddrSpace); + // Print ROM Data section. + std::vector ROSections = PTAI->ROSections; + for (unsigned i = 0; i < ROSections.size(); i++) { + std::vector Items = ROSections[i]->Items; + if (! Items.size()) continue; + O << "\n"; + SwitchToSection(PTAI->ROSections[i]->S_); + for (unsigned j = 0; j < Items.size(); j++) { + O << Mang->getValueName(Items[j]); + Constant *C = Items[j]->getInitializer(); + int AddrSpace = Items[j]->getType()->getAddressSpace(); + EmitGlobalConstant(C, AddrSpace); + } } } Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp?rev=74822&r1=74821&r2=74822&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp (original) +++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp Mon Jul 6 05:18:37 2009 @@ -44,7 +44,8 @@ // Need because otherwise a .text symbol is emitted by DwarfWriter // in BeginModule, and gpasm cribbs for that .text symbol. TextSection = getUnnamedSection("", SectionFlags::Code); - ROSection = new PIC16Section(getReadOnlySection()); + PIC16Section *ROSection = new PIC16Section(getReadOnlySection()); + ROSections.push_back(ROSection); ExternalVarDecls = new PIC16Section(getNamedSection("ExternalVarDecls")); ExternalVarDefs = new PIC16Section(getNamedSection("ExternalVarDefs")); // Set it to false because we weed to generate c file name and not bc file @@ -235,10 +236,8 @@ return getIDATASectionForGlobal(GV); // This is initialized data in rom, put it in the readonly section. - if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE) { - ROSection->Items.push_back(GV); - return ROSection->S_; - } + if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE) + return getROSectionForGlobal(GV); // Else let the default implementation take care of it. return TargetAsmInfo::SelectSectionForGlobal(GV); @@ -258,7 +257,191 @@ delete AutosSections[i]; } - delete ROSection; + for (unsigned i = 0; i < ROSections.size(); i++) { + delete ROSections[i]; + } + delete ExternalVarDecls; delete ExternalVarDefs; } + +// Override the default implementation. Create PIC16sections for variables +// which have a section name or address. +const Section* +PIC16TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { + const Section* S; + // If GV has a sectin name or section address create that section now. + if (GV->hasSection()) { + std::string SectName = GV->getSection(); + // If address for a variable is specified, get the address and create + // section. + std::string AddrStr = "Address="; + if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) { + std::string SectAddr = SectName.substr(AddrStr.length()); + S = CreateSectionForGlobal(GV, SectAddr); + } + else { + S = CreateSectionForGlobal(GV); + } + } else { + // Use section depending on the 'type' of variable + S = SelectSectionForGlobal(GV); + } + return S; +} + +// Create a new section for global variable. If Addr is given then create +// section at that address else create by name. +const Section * +PIC16TargetAsmInfo::CreateSectionForGlobal(const GlobalValue *GV1, + std::string Addr) const { + const GlobalVariable *GV = dyn_cast(GV1); + + if (!GV) + return TargetAsmInfo::SectionForGlobal(GV1); + + // See if this is an uninitialized global. + const Constant *C = GV->getInitializer(); + if (C->isNullValue()) + return CreateBSSSectionForGlobal(GV, Addr); + + // If this is initialized data in RAM. Put it in the correct IDATA section. + if (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE) + return CreateIDATASectionForGlobal(GV, Addr); + + // This is initialized data in rom, put it in the readonly section. + if (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE) + return CreateROSectionForGlobal(GV, Addr); + + // Else let the default implementation take care of it. + return TargetAsmInfo::SectionForGlobal(GV); +} + +// Create uninitialized section for a variable. +const Section * +PIC16TargetAsmInfo::CreateBSSSectionForGlobal(const GlobalVariable *GV, + std::string Addr) const { + assert (GV->hasInitializer() && "This global doesn't need space"); + Constant *C = GV->getInitializer(); + assert (C->isNullValue() && "Unitialized globals has non-zero initializer"); + std::string Name; + // If address is given then create a section at that address else create a + // section by section name specified in GV. + PIC16Section *FoundBSS = NULL; + if (Addr.empty()) { + Name = GV->getSection() + " UDATA"; + for (unsigned i = 0; i < BSSSections.size(); i++) { + if (BSSSections[i]->S_->getName() == Name) { + FoundBSS = BSSSections[i]; + break; + } + } + } + else { + std::string Prefix = GV->getName() + "." + Addr + "."; + Name = PAN::getUdataSectionName(BSSSections.size(), Prefix) + " " + Addr; + } + + PIC16Section *NewBSS = FoundBSS; + if (NewBSS == NULL) { + const Section *NewSection = getNamedSection (Name.c_str()); + NewBSS = new PIC16Section(NewSection); + BSSSections.push_back(NewBSS); + } + + // Insert the GV into this BSS. + NewBSS->Items.push_back(GV); + + // We do not want to put any GV without explicit section into this section + // so set its size to DatabankSize. + NewBSS->Size = DataBankSize; + return NewBSS->S_; +} + +// Get rom section for a variable. Currently there can be only one rom section +// unless a variable explicitly requests a section. +const Section * +PIC16TargetAsmInfo::getROSectionForGlobal(const GlobalVariable *GV) const { + ROSections[0]->Items.push_back(GV); + return ROSections[0]->S_; +} + +// Create initialized data section for a variable. +const Section * +PIC16TargetAsmInfo::CreateIDATASectionForGlobal(const GlobalVariable *GV, + std::string Addr) const { + assert (GV->hasInitializer() && "This global doesn't need space"); + Constant *C = GV->getInitializer(); + assert (!C->isNullValue() && "initialized globals has zero initializer"); + assert (GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE && + "can be used for initialized RAM data only"); + + std::string Name; + // If address is given then create a section at that address else create a + // section by section name specified in GV. + PIC16Section *FoundIDATASec = NULL; + if (Addr.empty()) { + Name = GV->getSection() + " IDATA"; + for (unsigned i = 0; i < IDATASections.size(); i++) { + if (IDATASections[i]->S_->getName() == Name) { + FoundIDATASec = IDATASections[i]; + break; + } + } + } + else { + std::string Prefix = GV->getName() + "." + Addr + "."; + Name = PAN::getIdataSectionName(IDATASections.size(), Prefix) + " " + Addr; + } + + PIC16Section *NewIDATASec = FoundIDATASec; + if (NewIDATASec == NULL) { + const Section *NewSection = getNamedSection (Name.c_str()); + NewIDATASec = new PIC16Section(NewSection); + IDATASections.push_back(NewIDATASec); + } + // Insert the GV into this IDATA Section. + NewIDATASec->Items.push_back(GV); + // We do not want to put any GV without explicit section into this section + // so set its size to DatabankSize. + NewIDATASec->Size = DataBankSize; + return NewIDATASec->S_; +} + +// Create a section in rom for a variable. +const Section * +PIC16TargetAsmInfo::CreateROSectionForGlobal(const GlobalVariable *GV, + std::string Addr) const { + assert (GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE && + "can be used for ROM data only"); + + std::string Name; + // If address is given then create a section at that address else create a + // section by section name specified in GV. + PIC16Section *FoundROSec = NULL; + if (Addr.empty()) { + Name = GV->getSection() + " ROMDATA"; + for (unsigned i = 1; i < ROSections.size(); i++) { + if (ROSections[i]->S_->getName() == Name) { + FoundROSec = ROSections[i]; + break; + } + } + } + else { + std::string Prefix = GV->getName() + "." + Addr + "."; + Name = PAN::getRomdataSectionName(ROSections.size(), Prefix) + " " + Addr; + } + + PIC16Section *NewRomSec = FoundROSec; + if (NewRomSec == NULL) { + const Section *NewSection = getNamedSection (Name.c_str()); + NewRomSec = new PIC16Section(NewSection); + ROSections.push_back(NewRomSec); + } + + // Insert the GV into this ROM Section. + NewRomSec->Items.push_back(GV); + return NewRomSec->S_; +} + Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h?rev=74822&r1=74821&r2=74822&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h (original) +++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h Mon Jul 6 05:18:37 2009 @@ -48,7 +48,7 @@ mutable std::vector BSSSections; mutable std::vector IDATASections; mutable std::vector AutosSections; - mutable PIC16Section *ROSection; + mutable std::vector ROSections; mutable PIC16Section *ExternalVarDecls; mutable PIC16Section *ExternalVarDefs; virtual ~PIC16TargetAsmInfo(); @@ -62,9 +62,16 @@ const Section *getBSSSectionForGlobal(const GlobalVariable *GV) const; const Section *getIDATASectionForGlobal(const GlobalVariable *GV) const; const Section *getSectionForAuto(const GlobalVariable *GV) const; + const Section *CreateBSSSectionForGlobal(const GlobalVariable *GV, + std::string Addr = "") const; + const Section *CreateIDATASectionForGlobal(const GlobalVariable *GV, + std::string Addr = "") const; + const Section *getROSectionForGlobal(const GlobalVariable *GV) const; + const Section *CreateROSectionForGlobal(const GlobalVariable *GV, + std::string Addr = "") const; virtual const Section *SelectSectionForGlobal(const GlobalValue *GV) const; - - + const Section * CreateSectionForGlobal(const GlobalValue *GV, + std::string Addr = "") const; public: void SetSectionForGVs(Module &M); std::vector getBSSSections() const { @@ -76,6 +83,10 @@ std::vector getAutosSections() const { return AutosSections; } + std::vector getROSections() const { + return ROSections; + } + virtual const Section* SectionForGlobal(const GlobalValue *GV) const; }; } // namespace llvm From anton at korobeynikov.info Mon Jul 6 05:24:41 2009 From: anton at korobeynikov.info (Anton Korobeynikov) Date: Mon, 6 Jul 2009 14:24:41 +0400 Subject: [llvm-commits] [llvm] r74822 - in /llvm/trunk/lib: CompilerDriver/BuiltinOptions.cpp CompilerDriver/Main.cpp Target/PIC16/PIC16.h Target/PIC16/PIC16AsmPrinter.cpp Target/PIC16/PIC16TargetAsmInfo.cpp Target/PIC16/PIC16TargetAsmInfo.h In-Reply-To: <200907061018.n66AIjau015273@zion.cs.uiuc.edu> References: <200907061018.n66AIjau015273@zion.cs.uiuc.edu> Message-ID: Hello, Sanjiv > +///////////////////////////////////////////// > + std::string p = "tmp-objs"; > + tempDir = sys::Path(p); > + if (!tempDir.exists()) { > + std::string ErrMsg; > + if (tempDir.createDirectoryOnDisk(true, &ErrMsg)) > + throw std::runtime_error(ErrMsg); > + } > + return tempDir; > +///////////////////////////////////////////// > + Revert this hunk, please, it breaks the whole driver. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University From anton at korobeynikov.info Mon Jul 6 05:25:52 2009 From: anton at korobeynikov.info (Anton Korobeynikov) Date: Mon, 6 Jul 2009 14:25:52 +0400 Subject: [llvm-commits] [llvm] r74822 - in /llvm/trunk/lib: CompilerDriver/BuiltinOptions.cpp CompilerDriver/Main.cpp Target/PIC16/PIC16.h Target/PIC16/PIC16AsmPrinter.cpp Target/PIC16/PIC16TargetAsmInfo.cpp Target/PIC16/PIC16TargetAsmInfo.h In-Reply-To: <200907061018.n66AIjau015273@zion.cs.uiuc.edu> References: <200907061018.n66AIjau015273@zion.cs.uiuc.edu> Message-ID: ============================================================================== > --- llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp (original) > +++ llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp Mon Jul 6 05:18:37 2009 > @@ -52,4 +52,5 @@ > "Use current working directory"), > clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"), > clEnumValEnd), > - cl::ValueOptional); > + //cl::ValueOptional); > + cl::Hidden); And this one - too. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University From sanjiv.gupta at microchip.com Mon Jul 6 05:34:24 2009 From: sanjiv.gupta at microchip.com (Sanjiv Gupta) Date: Mon, 06 Jul 2009 10:34:24 -0000 Subject: [llvm-commits] [llvm] r74823 - in /llvm/trunk/lib/CompilerDriver: BuiltinOptions.cpp Main.cpp Message-ID: <200907061034.n66AYPWS015997@zion.cs.uiuc.edu> Author: sgupta Date: Mon Jul 6 05:34:10 2009 New Revision: 74823 URL: http://llvm.org/viewvc/llvm-project?rev=74823&view=rev Log: Reverting back the changes checked-in accidently. Modified: llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp llvm/trunk/lib/CompilerDriver/Main.cpp Modified: llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp?rev=74823&r1=74822&r2=74823&view=diff ============================================================================== --- llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp (original) +++ llvm/trunk/lib/CompilerDriver/BuiltinOptions.cpp Mon Jul 6 05:34:10 2009 @@ -52,5 +52,4 @@ "Use current working directory"), clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"), clEnumValEnd), - //cl::ValueOptional); - cl::Hidden); + cl::ValueOptional); Modified: llvm/trunk/lib/CompilerDriver/Main.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/Main.cpp?rev=74823&r1=74822&r2=74823&view=diff ============================================================================== --- llvm/trunk/lib/CompilerDriver/Main.cpp (original) +++ llvm/trunk/lib/CompilerDriver/Main.cpp Mon Jul 6 05:34:10 2009 @@ -31,17 +31,6 @@ sys::Path getTempDir() { sys::Path tempDir; -///////////////////////////////////////////// - std::string p = "tmp-objs"; - tempDir = sys::Path(p); - if (!tempDir.exists()) { - std::string ErrMsg; - if (tempDir.createDirectoryOnDisk(true, &ErrMsg)) - throw std::runtime_error(ErrMsg); - } - return tempDir; -///////////////////////////////////////////// - // GCC 4.5-style -save-temps handling. if (SaveTemps == SaveTempsEnum::Unset) { tempDir = sys::Path::GetTemporaryDirectory(); From xerxes at zafena.se Mon Jul 6 05:57:02 2009 From: xerxes at zafena.se (=?ISO-8859-1?Q?Xerxes_R=E5nby?=) Date: Mon, 06 Jul 2009 12:57:02 +0200 Subject: [llvm-commits] [patch] fix for: llvm_start_multithreaded() failed Message-ID: <4A51D87E.3090908@zafena.se> Greetings! when using the current llvm svn tip with the curent icedtea6 tip to compile OpenJDK i got a binary that complained alot that llvm_start_multithreaded failed to initialize. OpenJDK Shark VM warning: llvm_start_multithreaded() failed The attached patch fixes this issue: llvm/lib/System/Threading.cpp Let the LLVM_MULTITHREADED macro propagate from config.h to Threading.cpp so that the multithreaded llvm implementation are actually compiled in and used. Have a great day! Xerxes -------------- next part -------------- A non-text attachment was scrubbed... Name: llvm_start_multithreaded_LLVM_MULTITHREADED_config.h.patch Type: text/x-patch Size: 418 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090706/77a57dae/attachment.bin From xerxes at zafena.se Mon Jul 6 07:52:43 2009 From: xerxes at zafena.se (=?ISO-8859-1?Q?Xerxes_R=E5nby?=) Date: Mon, 06 Jul 2009 14:52:43 +0200 Subject: [llvm-commits] [patch] cmake add lib/CodeGen/ObjectCodeEmitter.cpp Message-ID: <4A51F39B.3080408@zafena.se> fixes: ../../lib/libLLVMAlphaCodeGen.a(AlphaCodeEmitter.cpp.o): In function `(anonymous namespace)::Emitter::emitBasicBlock(llvm::MachineBasicBlock&)': AlphaCodeEmitter.cpp:(.text+0x132c): undefined reference to `llvm::ObjectCodeEmitter::emitWordLE(unsigned int and similar issues for cmake builds. -------------- next part -------------- A non-text attachment was scrubbed... Name: cmake_add_ObjectCodeEmitter.cpp.patch Type: text/x-patch Size: 417 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090706/8a9ce30a/attachment.bin From aaronngray.lists at googlemail.com Mon Jul 6 08:55:17 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 14:55:17 +0100 Subject: [llvm-commits] [llvm] r74814 - in /llvm/trunk: include/llvm/CodeGen/ObjectCodeEmitter.h lib/CodeGen/ObjectCodeEmitter.cpp References: <200907060516.n665Gekx026755@zion.cs.uiuc.edu> Message-ID: <7669CA9A7D814D5DBD8507485499BCD5@HPLAPTOP> The ObjectCodeEmitter was ment to be inline code to be used by the *CodeEmitter classes to end up with super fast code generation. Putting them as noninline classes is a bad idea. Basically this is why I/we parameterized the *CodeEmitter Classes in the first place. Aaron > Author: bruno > Date: Mon Jul 6 00:16:40 2009 > New Revision: 74814 > > URL: http://llvm.org/viewvc/llvm-project?rev=74814&view=rev > Log: > Just forgot to include the two new files > > Added: > llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h > llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp > > Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h > URL: > http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto > > ============================================================================== > --- llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h (added) > +++ llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h Mon Jul 6 > 00:16:40 2009 > @@ -0,0 +1,171 @@ > +//===-- llvm/CodeGen/ObjectCodeEmitter.h - Object Code Emitter -*- > C++ -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > +// > +// Generalized Object Code Emitter, works with ObjectModule and > BinaryObject. > +// > +//===----------------------------------------------------------------------===// > + > +#ifndef LLVM_CODEGEN_OBJECTCODEEMITTER_H > +#define LLVM_CODEGEN_OBJECTCODEEMITTER_H > + > +#include "llvm/CodeGen/MachineCodeEmitter.h" > + > +namespace llvm { > + > +class BinaryObject; > +class MachineBasicBlock; > +class MachineCodeEmitter; > +class MachineFunction; > +class MachineConstantPool; > +class MachineJumpTableInfo; > +class MachineModuleInfo; > + > +class ObjectCodeEmitter : public MachineCodeEmitter { > +protected: > + > + /// Binary Object (Section or Segment) we are emitting to. > + BinaryObject *BO; > + > + /// MBBLocations - This vector is a mapping from MBB ID's to their > address. > + /// It is filled in by the StartMachineBasicBlock callback and queried > by > + /// the getMachineBasicBlockAddress callback. > + std::vector MBBLocations; > + > + /// LabelLocations - This vector is a mapping from Label ID's to their > + /// address. > + std::vector LabelLocations; > + > + /// CPLocations - This is a map of constant pool indices to offsets > from the > + /// start of the section for that constant pool index. > + std::vector CPLocations; > + > + /// CPSections - This is a map of constant pool indices to the Section > + /// containing the constant pool entry for that index. > + std::vector CPSections; > + > + /// JTLocations - This is a map of jump table indices to offsets from > the > + /// start of the section for that jump table index. > + std::vector JTLocations; > + > +public: > + ObjectCodeEmitter(); > + ObjectCodeEmitter(BinaryObject *bo); > + virtual ~ObjectCodeEmitter(); > + > + /// setBinaryObject - set the BinaryObject we are writting to > + void setBinaryObject(BinaryObject *bo); > + > + /// emitByte - This callback is invoked when a byte needs to be > + /// written to the data stream, without buffer overflow testing. > + void emitByte(uint8_t B); > + > + /// emitWordLE - This callback is invoked when a 32-bit word needs to > be > + /// written to the data stream in little-endian format. > + void emitWordLE(uint32_t W); > + > + /// emitWordBE - This callback is invoked when a 32-bit word needs to > be > + /// written to the data stream in big-endian format. > + void emitWordBE(uint32_t W); > + > + /// emitDWordLE - This callback is invoked when a 64-bit word needs to > be > + /// written to the data stream in little-endian format. > + void emitDWordLE(uint64_t W); > + > + /// emitDWordBE - This callback is invoked when a 64-bit word needs to > be > + /// written to the data stream in big-endian format. > + void emitDWordBE(uint64_t W); > + > + /// emitAlignment - Move the CurBufferPtr pointer up the the specified > + /// alignment (saturated to BufferEnd of course). > + void emitAlignment(unsigned Alignment = 0, uint8_t fill = 0); > + > + /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to > be > + /// written to the data stream. > + void emitULEB128Bytes(uint64_t Value); > + > + /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to > be > + /// written to the data stream. > + void emitSLEB128Bytes(uint64_t Value); > + > + /// emitString - This callback is invoked when a String needs to be > + /// written to the data stream. > + void emitString(const std::string &String); > + > + /// getCurrentPCValue - This returns the address that the next emitted > byte > + /// will be output to. > + uintptr_t getCurrentPCValue() const; > + > + /// getCurrentPCOffset - Return the offset from the start of the > emitted > + /// buffer that we are currently writing to. > + uintptr_t getCurrentPCOffset() const; > + > + /// addRelocation - Whenever a relocatable address is needed, it should > be > + /// noted with this interface. > + void addRelocation(const MachineRelocation& relocation); > + > + /// startFunction - This callback is invoked when the specified > function is > + /// about to be code generated. This initializes the > BufferBegin/End/Ptr > + /// fields. > + virtual void startFunction(MachineFunction &F) = 0; > + > + /// finishFunction - This callback is invoked when the specified > function has > + /// finished code generation. If a buffer overflow has occurred, this > method > + /// returns true (the callee is required to try again), otherwise it > returns > + /// false. > + virtual bool finishFunction(MachineFunction &F) = 0; > + > + /// StartMachineBasicBlock - This should be called by the target when a > new > + /// basic block is about to be emitted. This way the MCE knows where > the > + /// start of the block is, and can implement > getMachineBasicBlockAddress. > + virtual void StartMachineBasicBlock(MachineBasicBlock *MBB); > + > + /// getMachineBasicBlockAddress - Return the address of the specified > + /// MachineBasicBlock, only usable after the label for the MBB has been > + /// emitted. > + virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) > const; > + > + /// emitLabel - Emits a label > + virtual void emitLabel(uint64_t LabelID) = 0; > + > + /// getLabelAddress - Return the address of the specified LabelID, only > usable > + /// after the LabelID has been emitted. > + virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0; > + > + /// emitJumpTables - Emit all the jump tables for a given jump table > info > + /// record to the appropriate section. > + virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0; > + > + /// getJumpTableEntryAddress - Return the address of the jump table > with index > + /// 'Index' in the function that last called initJumpTableInfo. > + virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const; > + > + /// emitConstantPool - For each constant pool entry, figure out which > section > + /// the constant should live in, allocate space for it, and emit it to > the > + /// Section data buffer. > + virtual void emitConstantPool(MachineConstantPool *MCP) = 0; > + > + /// getConstantPoolEntryAddress - Return the address of the 'Index' > entry in > + /// the constant pool that was last emitted with the emitConstantPool > method. > + virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const; > + > + /// getConstantPoolEntrySection - Return the section of the 'Index' > entry in > + /// the constant pool that was last emitted with the emitConstantPool > method. > + virtual uintptr_t getConstantPoolEntrySection(unsigned Index) const; > + > + /// Specifies the MachineModuleInfo object. This is used for exception > handling > + /// purposes. > + virtual void setModuleInfo(MachineModuleInfo* Info) = 0; > + // to be implemented or depreciated with MachineModuleInfo > + > +}; // end class ObjectCodeEmitter > + > +} // end namespace llvm > + > +#endif > + > > Added: llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp > URL: > http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto > > ============================================================================== > --- llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp (added) > +++ llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Mon Jul 6 00:16:40 2009 > @@ -0,0 +1,142 @@ > +//===-- llvm/CodeGen/ObjectCodeEmitter.cpp -------------------- -*- > C++ -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > + > +#include "llvm/CodeGen/BinaryObject.h" > +#include "llvm/CodeGen/MachineBasicBlock.h" > +#include "llvm/CodeGen/MachineRelocation.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > + > +//===----------------------------------------------------------------------===// > +// ObjectCodeEmitter Implementation > +//===----------------------------------------------------------------------===// > + > +namespace llvm { > + > +ObjectCodeEmitter::ObjectCodeEmitter() : BO(0) {} > +ObjectCodeEmitter::ObjectCodeEmitter(BinaryObject *bo) : BO(bo) {} > +ObjectCodeEmitter::~ObjectCodeEmitter() {} > + > +/// setBinaryObject - set the BinaryObject we are writting to > +void ObjectCodeEmitter::setBinaryObject(BinaryObject *bo) { BO = bo; } > + > +/// emitByte - This callback is invoked when a byte needs to be > +/// written to the data stream, without buffer overflow testing. > +void ObjectCodeEmitter::emitByte(uint8_t B) { > + BO->emitByte(B); > +} > + > +/// emitWordLE - This callback is invoked when a 32-bit word needs to be > +/// written to the data stream in little-endian format. > +void ObjectCodeEmitter::emitWordLE(uint32_t W) { > + BO->emitWordLE(W); > +} > + > +/// emitWordBE - This callback is invoked when a 32-bit word needs to be > +/// written to the data stream in big-endian format. > +void ObjectCodeEmitter::emitWordBE(uint32_t W) { > + BO->emitWordBE(W); > +} > + > +/// emitDWordLE - This callback is invoked when a 64-bit word needs to be > +/// written to the data stream in little-endian format. > +void ObjectCodeEmitter::emitDWordLE(uint64_t W) { > + BO->emitDWordLE(W); > +} > + > +/// emitDWordBE - This callback is invoked when a 64-bit word needs to be > +/// written to the data stream in big-endian format. > +void ObjectCodeEmitter::emitDWordBE(uint64_t W) { > + BO->emitDWordBE(W); > +} > + > +/// emitAlignment - Move the CurBufferPtr pointer up the the specified > +/// alignment (saturated to BufferEnd of course). > +void ObjectCodeEmitter::emitAlignment(unsigned Alignment /* 0 */, > + uint8_t fill /* 0 */) { > + BO->emitAlignment(Alignment, fill); > +} > + > +/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to > be > +/// written to the data stream. > +void ObjectCodeEmitter::emitULEB128Bytes(uint64_t Value) { > + BO->emitULEB128Bytes(Value); > +} > + > +/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to > be > +/// written to the data stream. > +void ObjectCodeEmitter::emitSLEB128Bytes(uint64_t Value) { > + BO->emitSLEB128Bytes(Value); > +} > + > +/// emitString - This callback is invoked when a String needs to be > +/// written to the data stream. > +void ObjectCodeEmitter::emitString(const std::string &String) { > + BO->emitString(String); > +} > + > +/// getCurrentPCValue - This returns the address that the next emitted > byte > +/// will be output to. > +uintptr_t ObjectCodeEmitter::getCurrentPCValue() const { > + return BO->getCurrentPCOffset(); > +} > + > +/// getCurrentPCOffset - Return the offset from the start of the emitted > +/// buffer that we are currently writing to. > +uintptr_t ObjectCodeEmitter::getCurrentPCOffset() const { > + return BO->getCurrentPCOffset(); > +} > + > +/// addRelocation - Whenever a relocatable address is needed, it should > be > +/// noted with this interface. > +void ObjectCodeEmitter::addRelocation(const MachineRelocation& > relocation) { > + BO->addRelocation(relocation); > +} > + > +/// StartMachineBasicBlock - This should be called by the target when a > new > +/// basic block is about to be emitted. This way the MCE knows where the > +/// start of the block is, and can implement getMachineBasicBlockAddress. > +void ObjectCodeEmitter::StartMachineBasicBlock(MachineBasicBlock *MBB) { > + if (MBBLocations.size() <= (unsigned)MBB->getNumber()) > + MBBLocations.resize((MBB->getNumber()+1)*2); > + MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); > +} > + > +/// getMachineBasicBlockAddress - Return the address of the specified > +/// MachineBasicBlock, only usable after the label for the MBB has been > +/// emitted. > +uintptr_t > +ObjectCodeEmitter::getMachineBasicBlockAddress(MachineBasicBlock *MBB) > const { > + assert(MBBLocations.size() > (unsigned)MBB->getNumber() && > + MBBLocations[MBB->getNumber()] && "MBB not emitted!"); > + return MBBLocations[MBB->getNumber()]; > +} > + > +/// getJumpTableEntryAddress - Return the address of the jump table with > index > +/// 'Index' in the function that last called initJumpTableInfo. > +uintptr_t ObjectCodeEmitter::getJumpTableEntryAddress(unsigned Index) > const { > + assert(JTLocations.size() > Index && "JT not emitted!"); > + return JTLocations[Index]; > +} > + > +/// getConstantPoolEntryAddress - Return the address of the 'Index' entry > in > +/// the constant pool that was last emitted with the emitConstantPool > method. > +uintptr_t ObjectCodeEmitter::getConstantPoolEntryAddress(unsigned Index) > const { > + assert(CPLocations.size() > Index && "CP not emitted!"); > + return CPLocations[Index]; > +} > + > +/// getConstantPoolEntrySection - Return the section of the 'Index' entry > in > +/// the constant pool that was last emitted with the emitConstantPool > method. > +uintptr_t ObjectCodeEmitter::getConstantPoolEntrySection(unsigned Index) > const { > + assert(CPSections.size() > Index && "CP not emitted!"); > + return CPSections[Index]; > +} > + > +} // end namespace llvm > + > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From aaronngray.lists at googlemail.com Mon Jul 6 08:59:16 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 14:59:16 +0100 Subject: [llvm-commits] [llvm] r74814 - in /llvm/trunk: include/llvm/CodeGen/ObjectCodeEmitter.h lib/CodeGen/ObjectCodeEmitter.cpp References: <200907060516.n665Gekx026755@zion.cs.uiuc.edu> Message-ID: Bruno, You also removed the 'virtual' on 'uintptr_t ::ObjecCodeEmitter::getCurrentPCOffset() const'. This is critical for correct code generation on the *CodeEmitter. Aaron > Author: bruno > Date: Mon Jul 6 00:16:40 2009 > New Revision: 74814 > > URL: http://llvm.org/viewvc/llvm-project?rev=74814&view=rev > Log: > Just forgot to include the two new files > > Added: > llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h > llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp > > Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h > URL: > http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto > > ============================================================================== > --- llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h (added) > +++ llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h Mon Jul 6 > 00:16:40 2009 > @@ -0,0 +1,171 @@ > +//===-- llvm/CodeGen/ObjectCodeEmitter.h - Object Code Emitter -*- > C++ -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > +// > +// Generalized Object Code Emitter, works with ObjectModule and > BinaryObject. > +// > +//===----------------------------------------------------------------------===// > + > +#ifndef LLVM_CODEGEN_OBJECTCODEEMITTER_H > +#define LLVM_CODEGEN_OBJECTCODEEMITTER_H > + > +#include "llvm/CodeGen/MachineCodeEmitter.h" > + > +namespace llvm { > + > +class BinaryObject; > +class MachineBasicBlock; > +class MachineCodeEmitter; > +class MachineFunction; > +class MachineConstantPool; > +class MachineJumpTableInfo; > +class MachineModuleInfo; > + > +class ObjectCodeEmitter : public MachineCodeEmitter { > +protected: > + > + /// Binary Object (Section or Segment) we are emitting to. > + BinaryObject *BO; > + > + /// MBBLocations - This vector is a mapping from MBB ID's to their > address. > + /// It is filled in by the StartMachineBasicBlock callback and queried > by > + /// the getMachineBasicBlockAddress callback. > + std::vector MBBLocations; > + > + /// LabelLocations - This vector is a mapping from Label ID's to their > + /// address. > + std::vector LabelLocations; > + > + /// CPLocations - This is a map of constant pool indices to offsets > from the > + /// start of the section for that constant pool index. > + std::vector CPLocations; > + > + /// CPSections - This is a map of constant pool indices to the Section > + /// containing the constant pool entry for that index. > + std::vector CPSections; > + > + /// JTLocations - This is a map of jump table indices to offsets from > the > + /// start of the section for that jump table index. > + std::vector JTLocations; > + > +public: > + ObjectCodeEmitter(); > + ObjectCodeEmitter(BinaryObject *bo); > + virtual ~ObjectCodeEmitter(); > + > + /// setBinaryObject - set the BinaryObject we are writting to > + void setBinaryObject(BinaryObject *bo); > + > + /// emitByte - This callback is invoked when a byte needs to be > + /// written to the data stream, without buffer overflow testing. > + void emitByte(uint8_t B); > + > + /// emitWordLE - This callback is invoked when a 32-bit word needs to > be > + /// written to the data stream in little-endian format. > + void emitWordLE(uint32_t W); > + > + /// emitWordBE - This callback is invoked when a 32-bit word needs to > be > + /// written to the data stream in big-endian format. > + void emitWordBE(uint32_t W); > + > + /// emitDWordLE - This callback is invoked when a 64-bit word needs to > be > + /// written to the data stream in little-endian format. > + void emitDWordLE(uint64_t W); > + > + /// emitDWordBE - This callback is invoked when a 64-bit word needs to > be > + /// written to the data stream in big-endian format. > + void emitDWordBE(uint64_t W); > + > + /// emitAlignment - Move the CurBufferPtr pointer up the the specified > + /// alignment (saturated to BufferEnd of course). > + void emitAlignment(unsigned Alignment = 0, uint8_t fill = 0); > + > + /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to > be > + /// written to the data stream. > + void emitULEB128Bytes(uint64_t Value); > + > + /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to > be > + /// written to the data stream. > + void emitSLEB128Bytes(uint64_t Value); > + > + /// emitString - This callback is invoked when a String needs to be > + /// written to the data stream. > + void emitString(const std::string &String); > + > + /// getCurrentPCValue - This returns the address that the next emitted > byte > + /// will be output to. > + uintptr_t getCurrentPCValue() const; > + > + /// getCurrentPCOffset - Return the offset from the start of the > emitted > + /// buffer that we are currently writing to. > + uintptr_t getCurrentPCOffset() const; > + > + /// addRelocation - Whenever a relocatable address is needed, it should > be > + /// noted with this interface. > + void addRelocation(const MachineRelocation& relocation); > + > + /// startFunction - This callback is invoked when the specified > function is > + /// about to be code generated. This initializes the > BufferBegin/End/Ptr > + /// fields. > + virtual void startFunction(MachineFunction &F) = 0; > + > + /// finishFunction - This callback is invoked when the specified > function has > + /// finished code generation. If a buffer overflow has occurred, this > method > + /// returns true (the callee is required to try again), otherwise it > returns > + /// false. > + virtual bool finishFunction(MachineFunction &F) = 0; > + > + /// StartMachineBasicBlock - This should be called by the target when a > new > + /// basic block is about to be emitted. This way the MCE knows where > the > + /// start of the block is, and can implement > getMachineBasicBlockAddress. > + virtual void StartMachineBasicBlock(MachineBasicBlock *MBB); > + > + /// getMachineBasicBlockAddress - Return the address of the specified > + /// MachineBasicBlock, only usable after the label for the MBB has been > + /// emitted. > + virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) > const; > + > + /// emitLabel - Emits a label > + virtual void emitLabel(uint64_t LabelID) = 0; > + > + /// getLabelAddress - Return the address of the specified LabelID, only > usable > + /// after the LabelID has been emitted. > + virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0; > + > + /// emitJumpTables - Emit all the jump tables for a given jump table > info > + /// record to the appropriate section. > + virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0; > + > + /// getJumpTableEntryAddress - Return the address of the jump table > with index > + /// 'Index' in the function that last called initJumpTableInfo. > + virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const; > + > + /// emitConstantPool - For each constant pool entry, figure out which > section > + /// the constant should live in, allocate space for it, and emit it to > the > + /// Section data buffer. > + virtual void emitConstantPool(MachineConstantPool *MCP) = 0; > + > + /// getConstantPoolEntryAddress - Return the address of the 'Index' > entry in > + /// the constant pool that was last emitted with the emitConstantPool > method. > + virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const; > + > + /// getConstantPoolEntrySection - Return the section of the 'Index' > entry in > + /// the constant pool that was last emitted with the emitConstantPool > method. > + virtual uintptr_t getConstantPoolEntrySection(unsigned Index) const; > + > + /// Specifies the MachineModuleInfo object. This is used for exception > handling > + /// purposes. > + virtual void setModuleInfo(MachineModuleInfo* Info) = 0; > + // to be implemented or depreciated with MachineModuleInfo > + > +}; // end class ObjectCodeEmitter > + > +} // end namespace llvm > + > +#endif > + > > Added: llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp > URL: > http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto > > ============================================================================== > --- llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp (added) > +++ llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Mon Jul 6 00:16:40 2009 > @@ -0,0 +1,142 @@ > +//===-- llvm/CodeGen/ObjectCodeEmitter.cpp -------------------- -*- > C++ -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > + > +#include "llvm/CodeGen/BinaryObject.h" > +#include "llvm/CodeGen/MachineBasicBlock.h" > +#include "llvm/CodeGen/MachineRelocation.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > + > +//===----------------------------------------------------------------------===// > +// ObjectCodeEmitter Implementation > +//===----------------------------------------------------------------------===// > + > +namespace llvm { > + > +ObjectCodeEmitter::ObjectCodeEmitter() : BO(0) {} > +ObjectCodeEmitter::ObjectCodeEmitter(BinaryObject *bo) : BO(bo) {} > +ObjectCodeEmitter::~ObjectCodeEmitter() {} > + > +/// setBinaryObject - set the BinaryObject we are writting to > +void ObjectCodeEmitter::setBinaryObject(BinaryObject *bo) { BO = bo; } > + > +/// emitByte - This callback is invoked when a byte needs to be > +/// written to the data stream, without buffer overflow testing. > +void ObjectCodeEmitter::emitByte(uint8_t B) { > + BO->emitByte(B); > +} > + > +/// emitWordLE - This callback is invoked when a 32-bit word needs to be > +/// written to the data stream in little-endian format. > +void ObjectCodeEmitter::emitWordLE(uint32_t W) { > + BO->emitWordLE(W); > +} > + > +/// emitWordBE - This callback is invoked when a 32-bit word needs to be > +/// written to the data stream in big-endian format. > +void ObjectCodeEmitter::emitWordBE(uint32_t W) { > + BO->emitWordBE(W); > +} > + > +/// emitDWordLE - This callback is invoked when a 64-bit word needs to be > +/// written to the data stream in little-endian format. > +void ObjectCodeEmitter::emitDWordLE(uint64_t W) { > + BO->emitDWordLE(W); > +} > + > +/// emitDWordBE - This callback is invoked when a 64-bit word needs to be > +/// written to the data stream in big-endian format. > +void ObjectCodeEmitter::emitDWordBE(uint64_t W) { > + BO->emitDWordBE(W); > +} > + > +/// emitAlignment - Move the CurBufferPtr pointer up the the specified > +/// alignment (saturated to BufferEnd of course). > +void ObjectCodeEmitter::emitAlignment(unsigned Alignment /* 0 */, > + uint8_t fill /* 0 */) { > + BO->emitAlignment(Alignment, fill); > +} > + > +/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to > be > +/// written to the data stream. > +void ObjectCodeEmitter::emitULEB128Bytes(uint64_t Value) { > + BO->emitULEB128Bytes(Value); > +} > + > +/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to > be > +/// written to the data stream. > +void ObjectCodeEmitter::emitSLEB128Bytes(uint64_t Value) { > + BO->emitSLEB128Bytes(Value); > +} > + > +/// emitString - This callback is invoked when a String needs to be > +/// written to the data stream. > +void ObjectCodeEmitter::emitString(const std::string &String) { > + BO->emitString(String); > +} > + > +/// getCurrentPCValue - This returns the address that the next emitted > byte > +/// will be output to. > +uintptr_t ObjectCodeEmitter::getCurrentPCValue() const { > + return BO->getCurrentPCOffset(); > +} > + > +/// getCurrentPCOffset - Return the offset from the start of the emitted > +/// buffer that we are currently writing to. > +uintptr_t ObjectCodeEmitter::getCurrentPCOffset() const { > + return BO->getCurrentPCOffset(); > +} > + > +/// addRelocation - Whenever a relocatable address is needed, it should > be > +/// noted with this interface. > +void ObjectCodeEmitter::addRelocation(const MachineRelocation& > relocation) { > + BO->addRelocation(relocation); > +} > + > +/// StartMachineBasicBlock - This should be called by the target when a > new > +/// basic block is about to be emitted. This way the MCE knows where the > +/// start of the block is, and can implement getMachineBasicBlockAddress. > +void ObjectCodeEmitter::StartMachineBasicBlock(MachineBasicBlock *MBB) { > + if (MBBLocations.size() <= (unsigned)MBB->getNumber()) > + MBBLocations.resize((MBB->getNumber()+1)*2); > + MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); > +} > + > +/// getMachineBasicBlockAddress - Return the address of the specified > +/// MachineBasicBlock, only usable after the label for the MBB has been > +/// emitted. > +uintptr_t > +ObjectCodeEmitter::getMachineBasicBlockAddress(MachineBasicBlock *MBB) > const { > + assert(MBBLocations.size() > (unsigned)MBB->getNumber() && > + MBBLocations[MBB->getNumber()] && "MBB not emitted!"); > + return MBBLocations[MBB->getNumber()]; > +} > + > +/// getJumpTableEntryAddress - Return the address of the jump table with > index > +/// 'Index' in the function that last called initJumpTableInfo. > +uintptr_t ObjectCodeEmitter::getJumpTableEntryAddress(unsigned Index) > const { > + assert(JTLocations.size() > Index && "JT not emitted!"); > + return JTLocations[Index]; > +} > + > +/// getConstantPoolEntryAddress - Return the address of the 'Index' entry > in > +/// the constant pool that was last emitted with the emitConstantPool > method. > +uintptr_t ObjectCodeEmitter::getConstantPoolEntryAddress(unsigned Index) > const { > + assert(CPLocations.size() > Index && "CP not emitted!"); > + return CPLocations[Index]; > +} > + > +/// getConstantPoolEntrySection - Return the section of the 'Index' entry > in > +/// the constant pool that was last emitted with the emitConstantPool > method. > +uintptr_t ObjectCodeEmitter::getConstantPoolEntrySection(unsigned Index) > const { > + assert(CPSections.size() > Index && "CP not emitted!"); > + return CPSections[Index]; > +} > + > +} // end namespace llvm > + > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From aaronngray.lists at googlemail.com Mon Jul 6 09:03:14 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 15:03:14 +0100 Subject: [llvm-commits] [llvm] r74814 - in /llvm/trunk: include/llvm/CodeGen/ObjectCodeEmitter.h lib/CodeGen/ObjectCodeEmitter.cpp References: <200907060516.n665Gekx026755@zion.cs.uiuc.edu> Message-ID: <06885ECEBD364A47B9AC5057F2E6C279@HPLAPTOP> Ah, 'uintptr_t getCurrentPCOffset() const' is 'virtual' in MachineCodeEmitter :) Sorry, Aaron > Author: bruno > Date: Mon Jul 6 00:16:40 2009 > New Revision: 74814 > > URL: http://llvm.org/viewvc/llvm-project?rev=74814&view=rev > Log: > Just forgot to include the two new files > > Added: > llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h > llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp > > Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h > URL: > http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto > > ============================================================================== > --- llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h (added) > +++ llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h Mon Jul 6 > 00:16:40 2009 > @@ -0,0 +1,171 @@ > +//===-- llvm/CodeGen/ObjectCodeEmitter.h - Object Code Emitter -*- > C++ -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > +// > +// Generalized Object Code Emitter, works with ObjectModule and > BinaryObject. > +// > +//===----------------------------------------------------------------------===// > + > +#ifndef LLVM_CODEGEN_OBJECTCODEEMITTER_H > +#define LLVM_CODEGEN_OBJECTCODEEMITTER_H > + > +#include "llvm/CodeGen/MachineCodeEmitter.h" > + > +namespace llvm { > + > +class BinaryObject; > +class MachineBasicBlock; > +class MachineCodeEmitter; > +class MachineFunction; > +class MachineConstantPool; > +class MachineJumpTableInfo; > +class MachineModuleInfo; > + > +class ObjectCodeEmitter : public MachineCodeEmitter { > +protected: > + > + /// Binary Object (Section or Segment) we are emitting to. > + BinaryObject *BO; > + > + /// MBBLocations - This vector is a mapping from MBB ID's to their > address. > + /// It is filled in by the StartMachineBasicBlock callback and queried > by > + /// the getMachineBasicBlockAddress callback. > + std::vector MBBLocations; > + > + /// LabelLocations - This vector is a mapping from Label ID's to their > + /// address. > + std::vector LabelLocations; > + > + /// CPLocations - This is a map of constant pool indices to offsets > from the > + /// start of the section for that constant pool index. > + std::vector CPLocations; > + > + /// CPSections - This is a map of constant pool indices to the Section > + /// containing the constant pool entry for that index. > + std::vector CPSections; > + > + /// JTLocations - This is a map of jump table indices to offsets from > the > + /// start of the section for that jump table index. > + std::vector JTLocations; > + > +public: > + ObjectCodeEmitter(); > + ObjectCodeEmitter(BinaryObject *bo); > + virtual ~ObjectCodeEmitter(); > + > + /// setBinaryObject - set the BinaryObject we are writting to > + void setBinaryObject(BinaryObject *bo); > + > + /// emitByte - This callback is invoked when a byte needs to be > + /// written to the data stream, without buffer overflow testing. > + void emitByte(uint8_t B); > + > + /// emitWordLE - This callback is invoked when a 32-bit word needs to > be > + /// written to the data stream in little-endian format. > + void emitWordLE(uint32_t W); > + > + /// emitWordBE - This callback is invoked when a 32-bit word needs to > be > + /// written to the data stream in big-endian format. > + void emitWordBE(uint32_t W); > + > + /// emitDWordLE - This callback is invoked when a 64-bit word needs to > be > + /// written to the data stream in little-endian format. > + void emitDWordLE(uint64_t W); > + > + /// emitDWordBE - This callback is invoked when a 64-bit word needs to > be > + /// written to the data stream in big-endian format. > + void emitDWordBE(uint64_t W); > + > + /// emitAlignment - Move the CurBufferPtr pointer up the the specified > + /// alignment (saturated to BufferEnd of course). > + void emitAlignment(unsigned Alignment = 0, uint8_t fill = 0); > + > + /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to > be > + /// written to the data stream. > + void emitULEB128Bytes(uint64_t Value); > + > + /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to > be > + /// written to the data stream. > + void emitSLEB128Bytes(uint64_t Value); > + > + /// emitString - This callback is invoked when a String needs to be > + /// written to the data stream. > + void emitString(const std::string &String); > + > + /// getCurrentPCValue - This returns the address that the next emitted > byte > + /// will be output to. > + uintptr_t getCurrentPCValue() const; > + > + /// getCurrentPCOffset - Return the offset from the start of the > emitted > + /// buffer that we are currently writing to. > + uintptr_t getCurrentPCOffset() const; > + > + /// addRelocation - Whenever a relocatable address is needed, it should > be > + /// noted with this interface. > + void addRelocation(const MachineRelocation& relocation); > + > + /// startFunction - This callback is invoked when the specified > function is > + /// about to be code generated. This initializes the > BufferBegin/End/Ptr > + /// fields. > + virtual void startFunction(MachineFunction &F) = 0; > + > + /// finishFunction - This callback is invoked when the specified > function has > + /// finished code generation. If a buffer overflow has occurred, this > method > + /// returns true (the callee is required to try again), otherwise it > returns > + /// false. > + virtual bool finishFunction(MachineFunction &F) = 0; > + > + /// StartMachineBasicBlock - This should be called by the target when a > new > + /// basic block is about to be emitted. This way the MCE knows where > the > + /// start of the block is, and can implement > getMachineBasicBlockAddress. > + virtual void StartMachineBasicBlock(MachineBasicBlock *MBB); > + > + /// getMachineBasicBlockAddress - Return the address of the specified > + /// MachineBasicBlock, only usable after the label for the MBB has been > + /// emitted. > + virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) > const; > + > + /// emitLabel - Emits a label > + virtual void emitLabel(uint64_t LabelID) = 0; > + > + /// getLabelAddress - Return the address of the specified LabelID, only > usable > + /// after the LabelID has been emitted. > + virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0; > + > + /// emitJumpTables - Emit all the jump tables for a given jump table > info > + /// record to the appropriate section. > + virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0; > + > + /// getJumpTableEntryAddress - Return the address of the jump table > with index > + /// 'Index' in the function that last called initJumpTableInfo. > + virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const; > + > + /// emitConstantPool - For each constant pool entry, figure out which > section > + /// the constant should live in, allocate space for it, and emit it to > the > + /// Section data buffer. > + virtual void emitConstantPool(MachineConstantPool *MCP) = 0; > + > + /// getConstantPoolEntryAddress - Return the address of the 'Index' > entry in > + /// the constant pool that was last emitted with the emitConstantPool > method. > + virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const; > + > + /// getConstantPoolEntrySection - Return the section of the 'Index' > entry in > + /// the constant pool that was last emitted with the emitConstantPool > method. > + virtual uintptr_t getConstantPoolEntrySection(unsigned Index) const; > + > + /// Specifies the MachineModuleInfo object. This is used for exception > handling > + /// purposes. > + virtual void setModuleInfo(MachineModuleInfo* Info) = 0; > + // to be implemented or depreciated with MachineModuleInfo > + > +}; // end class ObjectCodeEmitter > + > +} // end namespace llvm > + > +#endif > + > > Added: llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp > URL: > http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto > > ============================================================================== > --- llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp (added) > +++ llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Mon Jul 6 00:16:40 2009 > @@ -0,0 +1,142 @@ > +//===-- llvm/CodeGen/ObjectCodeEmitter.cpp -------------------- -*- > C++ -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > + > +#include "llvm/CodeGen/BinaryObject.h" > +#include "llvm/CodeGen/MachineBasicBlock.h" > +#include "llvm/CodeGen/MachineRelocation.h" > +#include "llvm/CodeGen/ObjectCodeEmitter.h" > + > +//===----------------------------------------------------------------------===// > +// ObjectCodeEmitter Implementation > +//===----------------------------------------------------------------------===// > + > +namespace llvm { > + > +ObjectCodeEmitter::ObjectCodeEmitter() : BO(0) {} > +ObjectCodeEmitter::ObjectCodeEmitter(BinaryObject *bo) : BO(bo) {} > +ObjectCodeEmitter::~ObjectCodeEmitter() {} > + > +/// setBinaryObject - set the BinaryObject we are writting to > +void ObjectCodeEmitter::setBinaryObject(BinaryObject *bo) { BO = bo; } > + > +/// emitByte - This callback is invoked when a byte needs to be > +/// written to the data stream, without buffer overflow testing. > +void ObjectCodeEmitter::emitByte(uint8_t B) { > + BO->emitByte(B); > +} > + > +/// emitWordLE - This callback is invoked when a 32-bit word needs to be > +/// written to the data stream in little-endian format. > +void ObjectCodeEmitter::emitWordLE(uint32_t W) { > + BO->emitWordLE(W); > +} > + > +/// emitWordBE - This callback is invoked when a 32-bit word needs to be > +/// written to the data stream in big-endian format. > +void ObjectCodeEmitter::emitWordBE(uint32_t W) { > + BO->emitWordBE(W); > +} > + > +/// emitDWordLE - This callback is invoked when a 64-bit word needs to be > +/// written to the data stream in little-endian format. > +void ObjectCodeEmitter::emitDWordLE(uint64_t W) { > + BO->emitDWordLE(W); > +} > + > +/// emitDWordBE - This callback is invoked when a 64-bit word needs to be > +/// written to the data stream in big-endian format. > +void ObjectCodeEmitter::emitDWordBE(uint64_t W) { > + BO->emitDWordBE(W); > +} > + > +/// emitAlignment - Move the CurBufferPtr pointer up the the specified > +/// alignment (saturated to BufferEnd of course). > +void ObjectCodeEmitter::emitAlignment(unsigned Alignment /* 0 */, > + uint8_t fill /* 0 */) { > + BO->emitAlignment(Alignment, fill); > +} > + > +/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to > be > +/// written to the data stream. > +void ObjectCodeEmitter::emitULEB128Bytes(uint64_t Value) { > + BO->emitULEB128Bytes(Value); > +} > + > +/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to > be > +/// written to the data stream. > +void ObjectCodeEmitter::emitSLEB128Bytes(uint64_t Value) { > + BO->emitSLEB128Bytes(Value); > +} > + > +/// emitString - This callback is invoked when a String needs to be > +/// written to the data stream. > +void ObjectCodeEmitter::emitString(const std::string &String) { > + BO->emitString(String); > +} > + > +/// getCurrentPCValue - This returns the address that the next emitted > byte > +/// will be output to. > +uintptr_t ObjectCodeEmitter::getCurrentPCValue() const { > + return BO->getCurrentPCOffset(); > +} > + > +/// getCurrentPCOffset - Return the offset from the start of the emitted > +/// buffer that we are currently writing to. > +uintptr_t ObjectCodeEmitter::getCurrentPCOffset() const { > + return BO->getCurrentPCOffset(); > +} > + > +/// addRelocation - Whenever a relocatable address is needed, it should > be > +/// noted with this interface. > +void ObjectCodeEmitter::addRelocation(const MachineRelocation& > relocation) { > + BO->addRelocation(relocation); > +} > + > +/// StartMachineBasicBlock - This should be called by the target when a > new > +/// basic block is about to be emitted. This way the MCE knows where the > +/// start of the block is, and can implement getMachineBasicBlockAddress. > +void ObjectCodeEmitter::StartMachineBasicBlock(MachineBasicBlock *MBB) { > + if (MBBLocations.size() <= (unsigned)MBB->getNumber()) > + MBBLocations.resize((MBB->getNumber()+1)*2); > + MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); > +} > + > +/// getMachineBasicBlockAddress - Return the address of the specified > +/// MachineBasicBlock, only usable after the label for the MBB has been > +/// emitted. > +uintptr_t > +ObjectCodeEmitter::getMachineBasicBlockAddress(MachineBasicBlock *MBB) > const { > + assert(MBBLocations.size() > (unsigned)MBB->getNumber() && > + MBBLocations[MBB->getNumber()] && "MBB not emitted!"); > + return MBBLocations[MBB->getNumber()]; > +} > + > +/// getJumpTableEntryAddress - Return the address of the jump table with > index > +/// 'Index' in the function that last called initJumpTableInfo. > +uintptr_t ObjectCodeEmitter::getJumpTableEntryAddress(unsigned Index) > const { > + assert(JTLocations.size() > Index && "JT not emitted!"); > + return JTLocations[Index]; > +} > + > +/// getConstantPoolEntryAddress - Return the address of the 'Index' entry > in > +/// the constant pool that was last emitted with the emitConstantPool > method. > +uintptr_t ObjectCodeEmitter::getConstantPoolEntryAddress(unsigned Index) > const { > + assert(CPLocations.size() > Index && "CP not emitted!"); > + return CPLocations[Index]; > +} > + > +/// getConstantPoolEntrySection - Return the section of the 'Index' entry > in > +/// the constant pool that was last emitted with the emitConstantPool > method. > +uintptr_t ObjectCodeEmitter::getConstantPoolEntrySection(unsigned Index) > const { > + assert(CPSections.size() > Index && "CP not emitted!"); > + return CPSections[Index]; > +} > + > +} // end namespace llvm > + > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From baldrick at free.fr Mon Jul 6 09:28:39 2009 From: baldrick at free.fr (Duncan Sands) Date: Mon, 06 Jul 2009 14:28:39 -0000 Subject: [llvm-commits] [llvm] r74825 - /llvm/trunk/lib/CodeGen/CMakeLists.txt Message-ID: <200907061428.n66ESgmn023597@zion.cs.uiuc.edu> Author: baldrick Date: Mon Jul 6 09:28:32 2009 New Revision: 74825 URL: http://llvm.org/viewvc/llvm-project?rev=74825&view=rev Log: Fix the cmake build - patch by Xerxes R?nby. Modified: llvm/trunk/lib/CodeGen/CMakeLists.txt Modified: llvm/trunk/lib/CodeGen/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CMakeLists.txt?rev=74825&r1=74824&r2=74825&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/CMakeLists.txt (original) +++ llvm/trunk/lib/CodeGen/CMakeLists.txt Mon Jul 6 09:28:32 2009 @@ -31,6 +31,7 @@ MachineRegisterInfo.cpp MachineSink.cpp MachineVerifier.cpp + ObjectCodeEmitter.cpp OcamlGC.cpp PBQP.cpp PHIElimination.cpp From aaronngray.lists at googlemail.com Mon Jul 6 10:05:50 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 16:05:50 +0100 Subject: [llvm-commits] [patch] cmake add lib/CodeGen/ObjectCodeEmitter.cpp References: <4A51F39B.3080408@zafena.se> Message-ID: > fixes: > ../../lib/libLLVMAlphaCodeGen.a(AlphaCodeEmitter.cpp.o): In function > `(anonymous > namespace)::Emitter::emitBasicBlock(llvm::MachineBasicBlock&)': > AlphaCodeEmitter.cpp:(.text+0x132c): undefined reference to > `llvm::ObjectCodeEmitter::emitWordLE(unsigned int > and similar issues for cmake builds. Thanks, we had forgotten about CMake ! Aaron From stuart at apple.com Mon Jul 6 10:36:24 2009 From: stuart at apple.com (Stuart Hastings) Date: Mon, 06 Jul 2009 15:36:24 -0000 Subject: [llvm-commits] [llvm] r74829 - /llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp Message-ID: <200907061536.n66FaOBo026070@zion.cs.uiuc.edu> Author: stuart Date: Mon Jul 6 10:36:23 2009 New Revision: 74829 URL: http://llvm.org/viewvc/llvm-project?rev=74829&view=rev Log: Mark this test as Darwin only. Patch by Bill Wendling. Modified: llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp Modified: llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2009-06-30-ByrefBlock.cpp?rev=74829&r1=74828&r2=74829&view=diff ============================================================================== --- llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp (original) +++ llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp Mon Jul 6 10:36:23 2009 @@ -1,6 +1,9 @@ -// Insure __block_holder_tmp is allocated on the stack. +// Insure __block_holder_tmp is allocated on the stack. Darwin only. // RUN: %llvmgxx %s -S -O2 -o - | egrep {__block_holder_tmp.*alloca} +// XFAIL: * +// XTARGET: darwin // +// END. extern void fubar_dispatch_sync(void (^PP)(void)); void fubar() { __block void *voodoo; From jyasskin at google.com Mon Jul 6 11:50:30 2009 From: jyasskin at google.com (Jeffrey Yasskin) Date: Mon, 06 Jul 2009 16:50:30 -0000 Subject: [llvm-commits] [llvm] r74834 - /llvm/trunk/lib/System/Errno.cpp Message-ID: <200907061650.n66GoV5i028434@zion.cs.uiuc.edu> Author: jyasskin Date: Mon Jul 6 11:50:27 2009 New Revision: 74834 URL: http://llvm.org/viewvc/llvm-project?rev=74834&view=rev Log: Oops, I #included errno.h from inside the llvm::sys namespace. Modified: llvm/trunk/lib/System/Errno.cpp Modified: llvm/trunk/lib/System/Errno.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Errno.cpp?rev=74834&r1=74833&r2=74834&view=diff ============================================================================== --- llvm/trunk/lib/System/Errno.cpp (original) +++ llvm/trunk/lib/System/Errno.cpp Mon Jul 6 11:50:27 2009 @@ -17,6 +17,10 @@ #if HAVE_STRING_H #include +#if HAVE_ERRNO_H +#include +#endif + //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system //=== independent code. @@ -26,7 +30,6 @@ namespace sys { #if HAVE_ERRNO_H -#include std::string StrError() { return StrError(errno); } From clattner at apple.com Mon Jul 6 12:10:55 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 10:10:55 -0700 Subject: [llvm-commits] PATCH: remove VICmp and VFCmp. In-Reply-To: <4A518899.80806@mxc.ca> References: <4A518899.80806@mxc.ca> Message-ID: <7ABB6DFD-7F2E-4F31-A7D9-FC86362095E6@apple.com> On Jul 5, 2009, at 10:16 PM, Nick Lewycky wrote: > This patch removes vicmp and vfcmp, which has the positive side that > it fixes existing type-safety bugs and simplifies some code, but a > downside in that it XFAILs 9 CodeGen tests. I haven't had a chance to look at the patch, but removing v[fi]cmp will almost certainly break clang (which generates them for vector comparisons in opencl/ext_vector mode). The right way to remove this is to make codegen pattern match [fi]cmp+sext to the same nodes it is using for v[fi]cmp, then change clang to generate [fi]cmp+sext instead of v[if]cmp, then nuke v[fi]cmp. This way we won't loose any codegen capability and clang will still build :). I'm happy to help with this, but I won't have time to for another couple days. -Chris From sabre at nondot.org Mon Jul 6 12:25:04 2009 From: sabre at nondot.org (Chris Lattner) Date: Mon, 06 Jul 2009 17:25:04 -0000 Subject: [llvm-commits] [llvm] r74835 - /llvm/trunk/lib/System/Threading.cpp Message-ID: <200907061725.n66HP8CM029643@zion.cs.uiuc.edu> Author: lattner Date: Mon Jul 6 12:24:48 2009 New Revision: 74835 URL: http://llvm.org/viewvc/llvm-project?rev=74835&view=rev Log: improve portability to windows, patch by Xerces Ranby! Modified: llvm/trunk/lib/System/Threading.cpp Modified: llvm/trunk/lib/System/Threading.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Threading.cpp?rev=74835&r1=74834&r2=74835&view=diff ============================================================================== --- llvm/trunk/lib/System/Threading.cpp (original) +++ llvm/trunk/lib/System/Threading.cpp Mon Jul 6 12:24:48 2009 @@ -14,8 +14,8 @@ #include "llvm/System/Threading.h" #include "llvm/System/Atomic.h" #include "llvm/System/Mutex.h" +#include "llvm/Config/config.h" #include - using namespace llvm; static bool multithreaded_mode = false; From sabre at nondot.org Mon Jul 6 12:30:12 2009 From: sabre at nondot.org (Chris Lattner) Date: Mon, 06 Jul 2009 17:30:12 -0000 Subject: [llvm-commits] [llvm] r74836 - in /llvm/trunk: include/llvm-c/Core.h lib/VMCore/Core.cpp Message-ID: <200907061730.n66HUGRI029862@zion.cs.uiuc.edu> Author: lattner Date: Mon Jul 6 12:29:59 2009 New Revision: 74836 URL: http://llvm.org/viewvc/llvm-project?rev=74836&view=rev Log: Add two new accessors to the C bindings, patch by Wladimir van der Laan! Modified: llvm/trunk/include/llvm-c/Core.h llvm/trunk/lib/VMCore/Core.cpp Modified: llvm/trunk/include/llvm-c/Core.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=74836&r1=74835&r2=74836&view=diff ============================================================================== --- llvm/trunk/include/llvm-c/Core.h (original) +++ llvm/trunk/include/llvm-c/Core.h Mon Jul 6 12:29:59 2009 @@ -218,6 +218,7 @@ /** See Module::addTypeName. */ int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty); void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name); +LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name); /** See Module::dump. */ void LLVMDumpModule(LLVMModuleRef M); @@ -398,6 +399,7 @@ int LLVMIsConstant(LLVMValueRef Val); int LLVMIsNull(LLVMValueRef Val); int LLVMIsUndef(LLVMValueRef Val); +LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty); /* Operations on scalar constants */ LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, Modified: llvm/trunk/lib/VMCore/Core.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=74836&r1=74835&r2=74836&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Core.cpp (original) +++ llvm/trunk/lib/VMCore/Core.cpp Mon Jul 6 12:29:59 2009 @@ -101,6 +101,11 @@ TST.remove(I); } +LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) { + std::string N(Name); + return wrap(unwrap(M)->getTypeByName(N)); +} + void LLVMDumpModule(LLVMModuleRef M) { unwrap(M)->dump(); } @@ -313,6 +318,10 @@ return isa(unwrap(Val)); } +LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) { + return wrap(ConstantPointerNull::get(unwrap(Ty))); +} + /*--.. Operations on scalar constants ......................................--*/ LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, From clattner at apple.com Mon Jul 6 12:34:41 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 10:34:41 -0700 Subject: [llvm-commits] llvm-c patch to add LLVMGetTypeByName and LLVMConstPointerNull In-Reply-To: <3a7f9e660907021956he1ae821vc7fb3068e8475d9c@mail.gmail.com> References: <3a7f9e660907021956he1ae821vc7fb3068e8475d9c@mail.gmail.com> Message-ID: <1AFE566F-80A6-48A8-9FB0-791CC436B436@apple.com> On Jul 2, 2009, at 7:56 PM, Wladimir van der Laan wrote: > Dear LLVM developers, > > When working on a project using LLVM I ran into two important calls > that were missing from the llvm-c API (and thus from llvm-py, which > binds it): > > LLVMGetTypeByName - a way to get a typedef by name > LLVMConstPointerNull - get a null pointer of whatever type > > The attached patch fixes this problem by adding them in Core.h and > Core.cpp. I might run into more of these, but I thought it'd be better > to send this patch before I forget about it. Applied, thanks! http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090706/080163.html -Chris From aaronngray.lists at googlemail.com Mon Jul 6 12:57:31 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 18:57:31 +0100 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction Message-ID: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> This patch separates the template instatiations for the createX86*CodeEmitterPass of [X86]Emiiter into separate .cpp file and thus different object modules in the library. This will result in a slightly smaller footprint for programs just using one of the MachineCodeEmitter, ObjectCodeEmitter, or JITCodeEmitter classes. This should save 2 * 47K each for llc, lli, and LTOCodeGenerator. Although the MachineCodeEmitter version is not being use anymore at present I have left it in for now. It also opens the door for altername MachineCodeEmitters for experimental or other purposes such as unladen Swallow. I will be submitting simular patches for Alpha, ARM, and PowerPC if this one gets accepted. I have made CMake the necessary CMake changes too in the patch. This patch needs to be applied relatively quickly as it moves X86CodeEmitter.cpp code to X86CodeEmitter.h and any chages in SVN inbetween would be lost. Aaron -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090706/d07eab74/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: x86-Memory-Opt.patch Type: application/octet-stream Size: 63830 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090706/d07eab74/attachment.obj From sanjiv.gupta at microchip.com Mon Jul 6 13:07:15 2009 From: sanjiv.gupta at microchip.com (Sanjiv Gupta) Date: Mon, 06 Jul 2009 18:07:15 -0000 Subject: [llvm-commits] [llvm] r74838 - /llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp Message-ID: <200907061807.n66I7G1Q031039@zion.cs.uiuc.edu> Author: sgupta Date: Mon Jul 6 13:07:06 2009 New Revision: 74838 URL: http://llvm.org/viewvc/llvm-project?rev=74838&view=rev Log: pic16 isn't ready to handle llvm.metadata yet. Modified: llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp Modified: llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp?rev=74838&r1=74837&r2=74838&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp (original) +++ llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp Mon Jul 6 13:07:06 2009 @@ -348,6 +348,8 @@ std::vector IDATASections = PTAI->IDATASections; for (unsigned i = 0; i < IDATASections.size(); i++) { O << "\n"; + if (IDATASections[i]->S_->getName().find("llvm.") != std::string::npos) + continue; SwitchToSection(IDATASections[i]->S_); std::vector Items = IDATASections[i]->Items; for (unsigned j = 0; j < Items.size(); j++) { From sanjiv.gupta at microchip.com Mon Jul 6 13:09:15 2009 From: sanjiv.gupta at microchip.com (Sanjiv Gupta) Date: Mon, 06 Jul 2009 18:09:15 -0000 Subject: [llvm-commits] [llvm] r74839 - /llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp Message-ID: <200907061809.n66I9G8G031101@zion.cs.uiuc.edu> Author: sgupta Date: Mon Jul 6 13:09:11 2009 New Revision: 74839 URL: http://llvm.org/viewvc/llvm-project?rev=74839&view=rev Log: pic16 doesn't have a Data64bitsDirective. Set it NULL explicitly to tell the generic code to not pick the default. Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp?rev=74839&r1=74838&r2=74839&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp (original) +++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp Mon Jul 6 13:09:11 2009 @@ -30,6 +30,7 @@ Data8bitsDirective = " db "; Data16bitsDirective = " dw "; Data32bitsDirective = " dl "; + Data64bitsDirective = NULL; RomData8bitsDirective = " dw "; RomData16bitsDirective = " rom_di "; RomData32bitsDirective = " rom_dl "; From brukman+llvm at gmail.com Mon Jul 6 13:29:13 2009 From: brukman+llvm at gmail.com (Misha Brukman) Date: Mon, 06 Jul 2009 18:29:13 -0000 Subject: [llvm-commits] [llvm] r74840 - /llvm/trunk/utils/crosstool/ARM/build-install-linux.sh Message-ID: <200907061829.n66ITIV6031680@zion.cs.uiuc.edu> Author: brukman Date: Mon Jul 6 13:29:03 2009 New Revision: 74840 URL: http://llvm.org/viewvc/llvm-project?rev=74840&view=rev Log: * Allow skipping parts of the installation to be able to do it in parts if one phase fails and the user wants to reinstall one of the components. * Fixed LLVM-GCC configuration flags: s/--with-gnu-{as,ld}/--with-{as,ld}/ The former is a boolean flag, the latter is a flag that takes a path. * Added a new flag CROSS_MARCH, defaults to armv6. Modified: llvm/trunk/utils/crosstool/ARM/build-install-linux.sh Modified: llvm/trunk/utils/crosstool/ARM/build-install-linux.sh URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/crosstool/ARM/build-install-linux.sh?rev=74840&r1=74839&r2=74840&view=diff ============================================================================== --- llvm/trunk/utils/crosstool/ARM/build-install-linux.sh (original) +++ llvm/trunk/utils/crosstool/ARM/build-install-linux.sh Mon Jul 6 13:29:03 2009 @@ -17,6 +17,7 @@ readonly CROSS_HOST="x86_64-unknown-linux-gnu" readonly CROSS_TARGET="arm-none-linux-gnueabi" +readonly CROSS_MARCH="${CROSS_MARCH:-armv6}" readonly CODE_SOURCERY="${INSTALL_ROOT}/codesourcery" readonly CODE_SOURCERY_PKG_PATH="${CODE_SOURCERY_PKG_PATH:-${HOME}/codesourcery}" @@ -104,12 +105,9 @@ } installCodeSourcery() { - # Create CodeSourcery dir, if necessary. - verifyNotDir ${CODE_SOURCERY} - sudoCreateDir ${CODE_SOURCERY} - - # Unpack the tarball. + # Unpack the tarball, creating the CodeSourcery dir, if necessary. if [[ ! -d ${CODE_SOURCERY_ROOT} ]]; then + sudoCreateDir ${CODE_SOURCERY} cd ${CODE_SOURCERY} if [[ -e ${CODE_SOURCERY_PKG_PATH}/${CODE_SOURCERY_PKG} ]]; then runCommand "Unpacking CodeSourcery in ${CODE_SOURCERY}" \ @@ -122,7 +120,7 @@ exit fi else - echo "CodeSourcery install dir already exists." + echo "CodeSourcery install dir already exists; skipping." fi # Verify our CodeSourcery toolchain installation. @@ -141,7 +139,11 @@ } installLLVM() { - verifyNotDir ${LLVM_INSTALL_DIR} + if [[ -d ${LLVM_INSTALL_DIR} ]]; then + echo "LLVM install dir ${LLVM_INSTALL_DIR} exists; skipping." + return + fi + sudoCreateDir ${LLVM_INSTALL_DIR} # Unpack LLVM tarball; should create the directory "llvm". @@ -165,7 +167,11 @@ } installLLVMGCC() { - verifyNotDir ${LLVMGCC_INSTALL_DIR} + if [[ -d ${LLVMGCC_INSTALL_DIR} ]]; then + echo "LLVM-GCC install dir ${LLVMGCC_INSTALL_DIR} exists; skipping." + return + fi + sudoCreateDir ${LLVMGCC_INSTALL_DIR} # Unpack LLVM-GCC tarball; should create the directory "llvm-gcc-4.2". @@ -182,8 +188,9 @@ --prefix=${LLVMGCC_INSTALL_DIR} \ --program-prefix=llvm- \ --target=${CROSS_TARGET} \ - --with-gnu-as=${CROSS_TARGET_AS} \ - --with-gnu-ld=${CROSS_TARGET_LD} \ + --with-arch=${CROSS_MARCH} \ + --with-as=${CROSS_TARGET_AS} \ + --with-ld=${CROSS_TARGET_LD} \ --with-sysroot=${SYSROOT} runAndLog "Building LLVM-GCC" ${LLVMGCC_OBJ_DIR}/llvmgcc-build.log \ make From kremenek at apple.com Mon Jul 6 13:31:19 2009 From: kremenek at apple.com (Ted Kremenek) Date: Mon, 06 Jul 2009 18:31:19 -0000 Subject: [llvm-commits] [llvm] r74842 - /llvm/tags/checker/checker-0.213/ Message-ID: <200907061831.n66IVK9V031819@zion.cs.uiuc.edu> Author: kremenek Date: Mon Jul 6 13:31:18 2009 New Revision: 74842 URL: http://llvm.org/viewvc/llvm-project?rev=74842&view=rev Log: Tagging checker-0.213. Added: llvm/tags/checker/checker-0.213/ - copied from r74841, llvm/trunk/ From resistor at mac.com Mon Jul 6 13:42:47 2009 From: resistor at mac.com (Owen Anderson) Date: Mon, 06 Jul 2009 18:42:47 -0000 Subject: [llvm-commits] [llvm] r74844 - in /llvm/trunk: include/llvm/Analysis/ include/llvm/Support/ lib/Analysis/ lib/Transforms/IPO/ lib/Transforms/Instrumentation/ lib/Transforms/Scalar/ lib/Transforms/Utils/ Message-ID: <200907061842.n66Igvqn032166@zion.cs.uiuc.edu> Author: resistor Date: Mon Jul 6 13:42:36 2009 New Revision: 74844 URL: http://llvm.org/viewvc/llvm-project?rev=74844&view=rev Log: Thread LLVMContext through the constant folding APIs, which touches a lot of files. Modified: llvm/trunk/include/llvm/Analysis/ConstantFolding.h llvm/trunk/include/llvm/Analysis/ScalarEvolution.h llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h llvm/trunk/include/llvm/Support/TargetFolder.h llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp llvm/trunk/lib/Analysis/ConstantFolding.cpp llvm/trunk/lib/Analysis/ScalarEvolution.cpp llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp llvm/trunk/lib/Transforms/Scalar/ConstantProp.cpp llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp llvm/trunk/lib/Transforms/Scalar/SCCP.cpp llvm/trunk/lib/Transforms/Scalar/TailDuplication.cpp llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp llvm/trunk/lib/Transforms/Utils/UnrollLoop.cpp Modified: llvm/trunk/include/llvm/Analysis/ConstantFolding.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ConstantFolding.h?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ConstantFolding.h (original) +++ llvm/trunk/include/llvm/Analysis/ConstantFolding.h Mon Jul 6 13:42:36 2009 @@ -22,18 +22,20 @@ class TargetData; class Function; class Type; + class LLVMContext; /// ConstantFoldInstruction - Attempt to constant fold the specified /// instruction. If successful, the constant result is returned, if not, null /// is returned. Note that this function can only fail when attempting to fold /// instructions like loads and stores, which have no constant expression form. /// -Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0); +Constant *ConstantFoldInstruction(Instruction *I, LLVMContext* Context, + const TargetData *TD = 0); /// ConstantFoldConstantExpression - Attempt to fold the constant expression /// using the specified TargetData. If successful, the constant result is /// result is returned, if not, null is returned. -Constant *ConstantFoldConstantExpression(ConstantExpr *CE, +Constant *ConstantFoldConstantExpression(ConstantExpr *CE, LLVMContext* Context, const TargetData *TD = 0); /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the @@ -44,6 +46,7 @@ /// Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, Constant*const * Ops, unsigned NumOps, + LLVMContext* Context, const TargetData *TD = 0); /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare @@ -52,13 +55,15 @@ /// Constant *ConstantFoldCompareInstOperands(unsigned Predicate, Constant*const * Ops, unsigned NumOps, + LLVMContext* Context, const TargetData *TD = 0); /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a /// getelementptr constantexpr, return the constant value being addressed by the /// constant expression, or null if something is funny and we can't decide. -Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE); +Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE, + LLVMContext* Context); /// canConstantFoldCallTo - Return true if its even possible to fold a call to /// the specified function. Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Mon Jul 6 13:42:36 2009 @@ -36,6 +36,7 @@ class Type; class ScalarEvolution; class TargetData; + class LLVMContext; /// SCEV - This class represents an analyzed expression in the program. These /// are opaque objects that the client is not allowed to do much with @@ -354,6 +355,8 @@ static char ID; // Pass identification, replacement for typeid ScalarEvolution(); + LLVMContext* getContext() const { return Context; } + /// isSCEVable - Test if values of the given type are analyzable within /// the SCEV framework. This primarily includes integer types, and it /// can optionally include pointer types if the ScalarEvolution class Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h Mon Jul 6 13:42:36 2009 @@ -37,7 +37,7 @@ friend struct SCEVVisitor; public: explicit SCEVExpander(ScalarEvolution &se) - : SE(se), Builder(TargetFolder(se.TD)) {} + : SE(se), Builder(TargetFolder(se.TD, se.getContext())) {} /// clear - Erase the contents of the InsertedExpressions map so that users /// trying to expand the same expression into multiple BasicBlocks or Modified: llvm/trunk/include/llvm/Support/TargetFolder.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetFolder.h?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/include/llvm/Support/TargetFolder.h (original) +++ llvm/trunk/include/llvm/Support/TargetFolder.h Mon Jul 6 13:42:36 2009 @@ -25,21 +25,24 @@ namespace llvm { class TargetData; +class LLVMContext; /// TargetFolder - Create constants with target dependent folding. class TargetFolder { const TargetData *TD; + LLVMContext* Context; /// Fold - Fold the constant using target specific information. Constant *Fold(Constant *C) const { if (ConstantExpr *CE = dyn_cast(C)) - if (Constant *CF = ConstantFoldConstantExpression(CE, TD)) + if (Constant *CF = ConstantFoldConstantExpression(CE, Context, TD)) return CF; return C; } public: - explicit TargetFolder(const TargetData *TheTD) : TD(TheTD) {} + explicit TargetFolder(const TargetData *TheTD, LLVMContext* C) : + TD(TheTD), Context(C) {} //===--------------------------------------------------------------------===// // Binary Operators Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original) +++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Mon Jul 6 13:42:36 2009 @@ -22,6 +22,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/Instructions.h" #include "llvm/IntrinsicInst.h" +#include "llvm/LLVMContext.h" #include "llvm/Pass.h" #include "llvm/Target/TargetData.h" #include "llvm/ADT/SmallVector.h" @@ -394,13 +395,13 @@ // the base pointers. while (isGEP(GEP1->getOperand(0)) && GEP1->getOperand(1) == - Constant::getNullValue(GEP1->getOperand(1)->getType())) + Context->getNullValue(GEP1->getOperand(1)->getType())) GEP1 = cast(GEP1->getOperand(0)); const Value *BasePtr1 = GEP1->getOperand(0); while (isGEP(GEP2->getOperand(0)) && GEP2->getOperand(1) == - Constant::getNullValue(GEP2->getOperand(1)->getType())) + Context->getNullValue(GEP2->getOperand(1)->getType())) GEP2 = cast(GEP2->getOperand(0)); const Value *BasePtr2 = GEP2->getOperand(0); @@ -480,7 +481,7 @@ for (unsigned i = 0; i != GEPOperands.size(); ++i) if (!isa(GEPOperands[i])) GEPOperands[i] = - Constant::getNullValue(GEPOperands[i]->getType()); + Context->getNullValue(GEPOperands[i]->getType()); int64_t Offset = getTargetData().getIndexedOffset(BasePtr->getType(), &GEPOperands[0], @@ -498,16 +499,16 @@ // This function is used to determine if the indices of two GEP instructions are // equal. V1 and V2 are the indices. -static bool IndexOperandsEqual(Value *V1, Value *V2) { +static bool IndexOperandsEqual(Value *V1, Value *V2, LLVMContext* Context) { if (V1->getType() == V2->getType()) return V1 == V2; if (Constant *C1 = dyn_cast(V1)) if (Constant *C2 = dyn_cast(V2)) { // Sign extend the constants to long types, if necessary if (C1->getType() != Type::Int64Ty) - C1 = ConstantExpr::getSExt(C1, Type::Int64Ty); + C1 = Context->getConstantExprSExt(C1, Type::Int64Ty); if (C2->getType() != Type::Int64Ty) - C2 = ConstantExpr::getSExt(C2, Type::Int64Ty); + C2 = Context->getConstantExprSExt(C2, Type::Int64Ty); return C1 == C2; } return false; @@ -535,7 +536,8 @@ unsigned MaxOperands = std::max(NumGEP1Operands, NumGEP2Operands); unsigned UnequalOper = 0; while (UnequalOper != MinOperands && - IndexOperandsEqual(GEP1Ops[UnequalOper], GEP2Ops[UnequalOper])) { + IndexOperandsEqual(GEP1Ops[UnequalOper], GEP2Ops[UnequalOper], + Context)) { // Advance through the type as we go... ++UnequalOper; if (const CompositeType *CT = dyn_cast(BasePtr1Ty)) @@ -600,9 +602,9 @@ if (G1OC->getType() != G2OC->getType()) { // Sign extend both operands to long. if (G1OC->getType() != Type::Int64Ty) - G1OC = ConstantExpr::getSExt(G1OC, Type::Int64Ty); + G1OC = Context->getConstantExprSExt(G1OC, Type::Int64Ty); if (G2OC->getType() != Type::Int64Ty) - G2OC = ConstantExpr::getSExt(G2OC, Type::Int64Ty); + G2OC = Context->getConstantExprSExt(G2OC, Type::Int64Ty); GEP1Ops[FirstConstantOper] = G1OC; GEP2Ops[FirstConstantOper] = G2OC; } @@ -689,7 +691,7 @@ // TargetData::getIndexedOffset. for (i = 0; i != MaxOperands; ++i) if (!isa(GEP1Ops[i])) - GEP1Ops[i] = Constant::getNullValue(GEP1Ops[i]->getType()); + GEP1Ops[i] = Context->getNullValue(GEP1Ops[i]->getType()); // Okay, now get the offset. This is the relative offset for the full // instruction. const TargetData &TD = getTargetData(); @@ -734,7 +736,7 @@ const Type *ZeroIdxTy = GEPPointerTy; for (unsigned i = 0; i != FirstConstantOper; ++i) { if (!isa(ZeroIdxTy)) - GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::Int32Ty); + GEP1Ops[i] = GEP2Ops[i] = Context->getNullValue(Type::Int32Ty); if (const CompositeType *CT = dyn_cast(ZeroIdxTy)) ZeroIdxTy = CT->getTypeAtIndex(GEP1Ops[i]); @@ -749,7 +751,7 @@ // If they are equal, use a zero index... if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) { if (!isa(Op1)) - GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Op1->getType()); + GEP1Ops[i] = GEP2Ops[i] = Context->getNullValue(Op1->getType()); // Otherwise, just keep the constants we have. } else { if (Op1) { @@ -775,9 +777,11 @@ // value possible. // if (const ArrayType *AT = dyn_cast(BasePtr1Ty)) - GEP1Ops[i] = ConstantInt::get(Type::Int64Ty,AT->getNumElements()-1); + GEP1Ops[i] = + Context->getConstantInt(Type::Int64Ty,AT->getNumElements()-1); else if (const VectorType *VT = dyn_cast(BasePtr1Ty)) - GEP1Ops[i] = ConstantInt::get(Type::Int64Ty,VT->getNumElements()-1); + GEP1Ops[i] = + Context->getConstantInt(Type::Int64Ty,VT->getNumElements()-1); } } @@ -792,7 +796,7 @@ return MayAlias; // Be conservative with out-of-range accesses } } else { // Conservatively assume the minimum value for this index - GEP2Ops[i] = Constant::getNullValue(Op2->getType()); + GEP2Ops[i] = Context->getNullValue(Op2->getType()); } } } Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original) +++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Jul 6 13:42:36 2009 @@ -19,6 +19,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/Instructions.h" #include "llvm/Intrinsics.h" +#include "llvm/LLVMContext.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/Target/TargetData.h" @@ -92,7 +93,8 @@ /// these together. If target data info is available, it is provided as TD, /// otherwise TD is null. static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, - Constant *Op1, const TargetData *TD){ + Constant *Op1, const TargetData *TD, + LLVMContext* Context){ // SROA // Fold (and 0xffffffff00000000, (shl x, 32)) -> shl. @@ -110,7 +112,7 @@ if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, *TD) && GV1 == GV2) { // (&GV+C1) - (&GV+C2) -> C1-C2, pointer arithmetic cannot overflow. - return ConstantInt::get(Op0->getType(), Offs1-Offs2); + return Context->getConstantInt(Op0->getType(), Offs1-Offs2); } } @@ -121,6 +123,7 @@ /// constant expression, do so. static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps, const Type *ResultTy, + LLVMContext* Context, const TargetData *TD) { Constant *Ptr = Ops[0]; if (!TD || !cast(Ptr->getType())->getElementType()->isSized()) @@ -147,14 +150,14 @@ uint64_t Offset = TD->getIndexedOffset(Ptr->getType(), (Value**)Ops+1, NumOps-1); - Constant *C = ConstantInt::get(TD->getIntPtrType(), Offset+BasePtr); - return ConstantExpr::getIntToPtr(C, ResultTy); + Constant *C = Context->getConstantInt(TD->getIntPtrType(), Offset+BasePtr); + return Context->getConstantExprIntToPtr(C, ResultTy); } /// FoldBitCast - Constant fold bitcast, symbolically evaluating it with /// targetdata. Return 0 if unfoldable. static Constant *FoldBitCast(Constant *C, const Type *DestTy, - const TargetData &TD) { + const TargetData &TD, LLVMContext* Context) { // If this is a bitcast from constant vector -> vector, fold it. if (ConstantVector *CV = dyn_cast(C)) { if (const VectorType *DestVTy = dyn_cast(DestTy)) { @@ -180,24 +183,24 @@ if (DstEltTy->isFloatingPoint()) { // Fold to an vector of integers with same size as our FP type. unsigned FPWidth = DstEltTy->getPrimitiveSizeInBits(); - const Type *DestIVTy = VectorType::get(IntegerType::get(FPWidth), - NumDstElt); + const Type *DestIVTy = Context->getVectorType( + Context->getIntegerType(FPWidth), NumDstElt); // Recursively handle this integer conversion, if possible. - C = FoldBitCast(C, DestIVTy, TD); + C = FoldBitCast(C, DestIVTy, TD, Context); if (!C) return 0; // Finally, VMCore can handle this now that #elts line up. - return ConstantExpr::getBitCast(C, DestTy); + return Context->getConstantExprBitCast(C, DestTy); } // Okay, we know the destination is integer, if the input is FP, convert // it to integer first. if (SrcEltTy->isFloatingPoint()) { unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits(); - const Type *SrcIVTy = VectorType::get(IntegerType::get(FPWidth), - NumSrcElt); + const Type *SrcIVTy = Context->getVectorType( + Context->getIntegerType(FPWidth), NumSrcElt); // Ask VMCore to do the conversion now that #elts line up. - C = ConstantExpr::getBitCast(C, SrcIVTy); + C = Context->getConstantExprBitCast(C, SrcIVTy); CV = dyn_cast(C); if (!CV) return 0; // If VMCore wasn't able to fold it, bail out. } @@ -211,7 +214,7 @@ SmallVector Result; if (NumDstElt < NumSrcElt) { // Handle: bitcast (<4 x i32> to <2 x i64>) - Constant *Zero = Constant::getNullValue(DstEltTy); + Constant *Zero = Context->getNullValue(DstEltTy); unsigned Ratio = NumSrcElt/NumDstElt; unsigned SrcBitSize = SrcEltTy->getPrimitiveSizeInBits(); unsigned SrcElt = 0; @@ -224,15 +227,15 @@ if (!Src) return 0; // Reject constantexpr elements. // Zero extend the element to the right size. - Src = ConstantExpr::getZExt(Src, Elt->getType()); + Src = Context->getConstantExprZExt(Src, Elt->getType()); // Shift it to the right place, depending on endianness. - Src = ConstantExpr::getShl(Src, - ConstantInt::get(Src->getType(), ShiftAmt)); + Src = Context->getConstantExprShl(Src, + Context->getConstantInt(Src->getType(), ShiftAmt)); ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize; // Mix it in. - Elt = ConstantExpr::getOr(Elt, Src); + Elt = Context->getConstantExprOr(Elt, Src); } Result.push_back(Elt); } @@ -250,17 +253,17 @@ for (unsigned j = 0; j != Ratio; ++j) { // Shift the piece of the value into the right place, depending on // endianness. - Constant *Elt = ConstantExpr::getLShr(Src, - ConstantInt::get(Src->getType(), ShiftAmt)); + Constant *Elt = Context->getConstantExprLShr(Src, + Context->getConstantInt(Src->getType(), ShiftAmt)); ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize; // Truncate and remember this piece. - Result.push_back(ConstantExpr::getTrunc(Elt, DstEltTy)); + Result.push_back(Context->getConstantExprTrunc(Elt, DstEltTy)); } } } - return ConstantVector::get(Result.data(), Result.size()); + return Context->getConstantVector(Result.data(), Result.size()); } } @@ -278,10 +281,11 @@ /// is returned. Note that this function can only fail when attempting to fold /// instructions like loads and stores, which have no constant expression form. /// -Constant *llvm::ConstantFoldInstruction(Instruction *I, const TargetData *TD) { +Constant *llvm::ConstantFoldInstruction(Instruction *I, LLVMContext* Context, + const TargetData *TD) { if (PHINode *PN = dyn_cast(I)) { if (PN->getNumIncomingValues() == 0) - return UndefValue::get(PN->getType()); + return Context->getUndef(PN->getType()); Constant *Result = dyn_cast(PN->getIncomingValue(0)); if (Result == 0) return 0; @@ -306,16 +310,18 @@ if (const CmpInst *CI = dyn_cast(I)) return ConstantFoldCompareInstOperands(CI->getPredicate(), - Ops.data(), Ops.size(), TD); + Ops.data(), Ops.size(), + Context, TD); else return ConstantFoldInstOperands(I->getOpcode(), I->getType(), - Ops.data(), Ops.size(), TD); + Ops.data(), Ops.size(), Context, TD); } /// ConstantFoldConstantExpression - Attempt to fold the constant expression /// using the specified TargetData. If successful, the constant result is /// result is returned, if not, null is returned. Constant *llvm::ConstantFoldConstantExpression(ConstantExpr *CE, + LLVMContext* Context, const TargetData *TD) { SmallVector Ops; for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i) @@ -323,10 +329,11 @@ if (CE->isCompare()) return ConstantFoldCompareInstOperands(CE->getPredicate(), - Ops.data(), Ops.size(), TD); + Ops.data(), Ops.size(), + Context, TD); else return ConstantFoldInstOperands(CE->getOpcode(), CE->getType(), - Ops.data(), Ops.size(), TD); + Ops.data(), Ops.size(), Context, TD); } /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the @@ -337,14 +344,16 @@ /// Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, Constant* const* Ops, unsigned NumOps, + LLVMContext* Context, const TargetData *TD) { // Handle easy binops first. if (Instruction::isBinaryOp(Opcode)) { if (isa(Ops[0]) || isa(Ops[1])) - if (Constant *C = SymbolicallyEvaluateBinop(Opcode, Ops[0], Ops[1], TD)) + if (Constant *C = SymbolicallyEvaluateBinop(Opcode, Ops[0], Ops[1], TD, + Context)) return C; - return ConstantExpr::get(Opcode, Ops[0], Ops[1]); + return Context->getConstantExpr(Opcode, Ops[0], Ops[1]); } switch (Opcode) { @@ -368,15 +377,15 @@ unsigned InWidth = Input->getType()->getScalarSizeInBits(); if (TD->getPointerSizeInBits() < InWidth) { Constant *Mask = - ConstantInt::get(APInt::getLowBitsSet(InWidth, + Context->getConstantInt(APInt::getLowBitsSet(InWidth, TD->getPointerSizeInBits())); - Input = ConstantExpr::getAnd(Input, Mask); + Input = Context->getConstantExprAnd(Input, Mask); } // Do a zext or trunc to get to the dest size. - return ConstantExpr::getIntegerCast(Input, DestTy, false); + return Context->getConstantExprIntegerCast(Input, DestTy, false); } } - return ConstantExpr::getCast(Opcode, Ops[0], DestTy); + return Context->getConstantExprCast(Opcode, Ops[0], DestTy); case Instruction::IntToPtr: // If the input is a ptrtoint, turn the pair into a ptr to ptr bitcast if // the int size is >= the ptr size. This requires knowing the width of a @@ -387,8 +396,8 @@ CE->getType()->getScalarSizeInBits()) { if (CE->getOpcode() == Instruction::PtrToInt) { Constant *Input = CE->getOperand(0); - Constant *C = FoldBitCast(Input, DestTy, *TD); - return C ? C : ConstantExpr::getBitCast(Input, DestTy); + Constant *C = FoldBitCast(Input, DestTy, *TD, Context); + return C ? C : Context->getConstantExprBitCast(Input, DestTy); } // If there's a constant offset added to the integer value before // it is casted back to a pointer, see if the expression can be @@ -411,17 +420,18 @@ if (ElemIdx.ult(APInt(ElemIdx.getBitWidth(), AT->getNumElements()))) { Constant *Index[] = { - Constant::getNullValue(CE->getType()), - ConstantInt::get(ElemIdx) + Context->getNullValue(CE->getType()), + Context->getConstantInt(ElemIdx) }; - return ConstantExpr::getGetElementPtr(GV, &Index[0], 2); + return + Context->getConstantExprGetElementPtr(GV, &Index[0], 2); } } } } } } - return ConstantExpr::getCast(Opcode, Ops[0], DestTy); + return Context->getConstantExprCast(Opcode, Ops[0], DestTy); case Instruction::Trunc: case Instruction::ZExt: case Instruction::SExt: @@ -431,25 +441,25 @@ case Instruction::SIToFP: case Instruction::FPToUI: case Instruction::FPToSI: - return ConstantExpr::getCast(Opcode, Ops[0], DestTy); + return Context->getConstantExprCast(Opcode, Ops[0], DestTy); case Instruction::BitCast: if (TD) - if (Constant *C = FoldBitCast(Ops[0], DestTy, *TD)) + if (Constant *C = FoldBitCast(Ops[0], DestTy, *TD, Context)) return C; - return ConstantExpr::getBitCast(Ops[0], DestTy); + return Context->getConstantExprBitCast(Ops[0], DestTy); case Instruction::Select: - return ConstantExpr::getSelect(Ops[0], Ops[1], Ops[2]); + return Context->getConstantExprSelect(Ops[0], Ops[1], Ops[2]); case Instruction::ExtractElement: - return ConstantExpr::getExtractElement(Ops[0], Ops[1]); + return Context->getConstantExprExtractElement(Ops[0], Ops[1]); case Instruction::InsertElement: - return ConstantExpr::getInsertElement(Ops[0], Ops[1], Ops[2]); + return Context->getConstantExprInsertElement(Ops[0], Ops[1], Ops[2]); case Instruction::ShuffleVector: - return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]); + return Context->getConstantExprShuffleVector(Ops[0], Ops[1], Ops[2]); case Instruction::GetElementPtr: - if (Constant *C = SymbolicallyEvaluateGEP(Ops, NumOps, DestTy, TD)) + if (Constant *C = SymbolicallyEvaluateGEP(Ops, NumOps, DestTy, Context, TD)) return C; - return ConstantExpr::getGetElementPtr(Ops[0], Ops+1, NumOps-1); + return Context->getConstantExprGetElementPtr(Ops[0], Ops+1, NumOps-1); } } @@ -460,6 +470,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, Constant*const * Ops, unsigned NumOps, + LLVMContext* Context, const TargetData *TD) { // fold: icmp (inttoptr x), null -> icmp x, 0 // fold: icmp (ptrtoint x), 0 -> icmp x, null @@ -474,10 +485,11 @@ if (CE0->getOpcode() == Instruction::IntToPtr) { // Convert the integer value to the right size to ensure we get the // proper extension or truncation. - Constant *C = ConstantExpr::getIntegerCast(CE0->getOperand(0), + Constant *C = Context->getConstantExprIntegerCast(CE0->getOperand(0), IntPtrTy, false); - Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) }; - return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, TD); + Constant *NewOps[] = { C, Context->getNullValue(C->getType()) }; + return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, + Context, TD); } // Only do this transformation if the int is intptrty in size, otherwise @@ -485,9 +497,10 @@ if (CE0->getOpcode() == Instruction::PtrToInt && CE0->getType() == IntPtrTy) { Constant *C = CE0->getOperand(0); - Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) }; + Constant *NewOps[] = { C, Context->getNullValue(C->getType()) }; // FIXME! - return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, TD); + return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, + Context, TD); } } @@ -498,12 +511,13 @@ if (CE0->getOpcode() == Instruction::IntToPtr) { // Convert the integer value to the right size to ensure we get the // proper extension or truncation. - Constant *C0 = ConstantExpr::getIntegerCast(CE0->getOperand(0), + Constant *C0 = Context->getConstantExprIntegerCast(CE0->getOperand(0), IntPtrTy, false); - Constant *C1 = ConstantExpr::getIntegerCast(CE1->getOperand(0), + Constant *C1 = Context->getConstantExprIntegerCast(CE1->getOperand(0), IntPtrTy, false); Constant *NewOps[] = { C0, C1 }; - return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, TD); + return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, + Context, TD); } // Only do this transformation if the int is intptrty in size, otherwise @@ -514,12 +528,13 @@ Constant *NewOps[] = { CE0->getOperand(0), CE1->getOperand(0) }; - return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, TD); + return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, + Context, TD); } } } } - return ConstantExpr::getCompare(Predicate, Ops[0], Ops[1]); + return Context->getConstantExprCompare(Predicate, Ops[0], Ops[1]); } @@ -527,8 +542,9 @@ /// getelementptr constantexpr, return the constant value being addressed by the /// constant expression, or null if something is funny and we can't decide. Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, - ConstantExpr *CE) { - if (CE->getOperand(1) != Constant::getNullValue(CE->getOperand(1)->getType())) + ConstantExpr *CE, + LLVMContext* Context) { + if (CE->getOperand(1) != Context->getNullValue(CE->getOperand(1)->getType())) return 0; // Do not allow stepping over the value! // Loop over all of the operands, tracking down which value we are @@ -543,9 +559,9 @@ if (ConstantStruct *CS = dyn_cast(C)) { C = CS->getOperand(El); } else if (isa(C)) { - C = Constant::getNullValue(STy->getElementType(El)); + C = Context->getNullValue(STy->getElementType(El)); } else if (isa(C)) { - C = UndefValue::get(STy->getElementType(El)); + C = Context->getUndef(STy->getElementType(El)); } else { return 0; } @@ -556,9 +572,9 @@ if (ConstantArray *CA = dyn_cast(C)) C = CA->getOperand(CI->getZExtValue()); else if (isa(C)) - C = Constant::getNullValue(ATy->getElementType()); + C = Context->getNullValue(ATy->getElementType()); else if (isa(C)) - C = UndefValue::get(ATy->getElementType()); + C = Context->getUndef(ATy->getElementType()); else return 0; } else if (const VectorType *PTy = dyn_cast(*I)) { @@ -567,9 +583,9 @@ if (ConstantVector *CP = dyn_cast(C)) C = CP->getOperand(CI->getZExtValue()); else if (isa(C)) - C = Constant::getNullValue(PTy->getElementType()); + C = Context->getNullValue(PTy->getElementType()); else if (isa(C)) - C = UndefValue::get(PTy->getElementType()); + C = Context->getUndef(PTy->getElementType()); else return 0; } else { @@ -664,7 +680,7 @@ } static Constant *ConstantFoldFP(double (*NativeFP)(double), double V, - const Type *Ty) { + const Type *Ty, LLVMContext* Context) { errno = 0; V = NativeFP(V); if (errno != 0) { @@ -673,16 +689,17 @@ } if (Ty == Type::FloatTy) - return ConstantFP::get(APFloat((float)V)); + return Context->getConstantFP(APFloat((float)V)); if (Ty == Type::DoubleTy) - return ConstantFP::get(APFloat(V)); + return Context->getConstantFP(APFloat(V)); assert(0 && "Can only constant fold float/double"); return 0; // dummy return to suppress warning } static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double), double V, double W, - const Type *Ty) { + const Type *Ty, + LLVMContext* Context) { errno = 0; V = NativeFP(V, W); if (errno != 0) { @@ -691,9 +708,9 @@ } if (Ty == Type::FloatTy) - return ConstantFP::get(APFloat((float)V)); + return Context->getConstantFP(APFloat((float)V)); if (Ty == Type::DoubleTy) - return ConstantFP::get(APFloat(V)); + return Context->getConstantFP(APFloat(V)); assert(0 && "Can only constant fold float/double"); return 0; // dummy return to suppress warning } @@ -705,6 +722,7 @@ llvm::ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands) { if (!F->hasName()) return 0; + LLVMContext* Context = F->getContext(); const char *Str = F->getNameStart(); unsigned Len = F->getNameLen(); @@ -722,75 +740,75 @@ switch (Str[0]) { case 'a': if (Len == 4 && !strcmp(Str, "acos")) - return ConstantFoldFP(acos, V, Ty); + return ConstantFoldFP(acos, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "asin")) - return ConstantFoldFP(asin, V, Ty); + return ConstantFoldFP(asin, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "atan")) - return ConstantFoldFP(atan, V, Ty); + return ConstantFoldFP(atan, V, Ty, Context); break; case 'c': if (Len == 4 && !strcmp(Str, "ceil")) - return ConstantFoldFP(ceil, V, Ty); + return ConstantFoldFP(ceil, V, Ty, Context); else if (Len == 3 && !strcmp(Str, "cos")) - return ConstantFoldFP(cos, V, Ty); + return ConstantFoldFP(cos, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "cosh")) - return ConstantFoldFP(cosh, V, Ty); + return ConstantFoldFP(cosh, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "cosf")) - return ConstantFoldFP(cos, V, Ty); + return ConstantFoldFP(cos, V, Ty, Context); break; case 'e': if (Len == 3 && !strcmp(Str, "exp")) - return ConstantFoldFP(exp, V, Ty); + return ConstantFoldFP(exp, V, Ty, Context); break; case 'f': if (Len == 4 && !strcmp(Str, "fabs")) - return ConstantFoldFP(fabs, V, Ty); + return ConstantFoldFP(fabs, V, Ty, Context); else if (Len == 5 && !strcmp(Str, "floor")) - return ConstantFoldFP(floor, V, Ty); + return ConstantFoldFP(floor, V, Ty, Context); break; case 'l': if (Len == 3 && !strcmp(Str, "log") && V > 0) - return ConstantFoldFP(log, V, Ty); + return ConstantFoldFP(log, V, Ty, Context); else if (Len == 5 && !strcmp(Str, "log10") && V > 0) - return ConstantFoldFP(log10, V, Ty); + return ConstantFoldFP(log10, V, Ty, Context); else if (!strcmp(Str, "llvm.sqrt.f32") || !strcmp(Str, "llvm.sqrt.f64")) { if (V >= -0.0) - return ConstantFoldFP(sqrt, V, Ty); + return ConstantFoldFP(sqrt, V, Ty, Context); else // Undefined - return Constant::getNullValue(Ty); + return Context->getNullValue(Ty); } break; case 's': if (Len == 3 && !strcmp(Str, "sin")) - return ConstantFoldFP(sin, V, Ty); + return ConstantFoldFP(sin, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "sinh")) - return ConstantFoldFP(sinh, V, Ty); + return ConstantFoldFP(sinh, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "sqrt") && V >= 0) - return ConstantFoldFP(sqrt, V, Ty); + return ConstantFoldFP(sqrt, V, Ty, Context); else if (Len == 5 && !strcmp(Str, "sqrtf") && V >= 0) - return ConstantFoldFP(sqrt, V, Ty); + return ConstantFoldFP(sqrt, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "sinf")) - return ConstantFoldFP(sin, V, Ty); + return ConstantFoldFP(sin, V, Ty, Context); break; case 't': if (Len == 3 && !strcmp(Str, "tan")) - return ConstantFoldFP(tan, V, Ty); + return ConstantFoldFP(tan, V, Ty, Context); else if (Len == 4 && !strcmp(Str, "tanh")) - return ConstantFoldFP(tanh, V, Ty); + return ConstantFoldFP(tanh, V, Ty, Context); break; default: break; } } else if (ConstantInt *Op = dyn_cast(Operands[0])) { if (Len > 11 && !memcmp(Str, "llvm.bswap", 10)) - return ConstantInt::get(Op->getValue().byteSwap()); + return Context->getConstantInt(Op->getValue().byteSwap()); else if (Len > 11 && !memcmp(Str, "llvm.ctpop", 10)) - return ConstantInt::get(Ty, Op->getValue().countPopulation()); + return Context->getConstantInt(Ty, Op->getValue().countPopulation()); else if (Len > 10 && !memcmp(Str, "llvm.cttz", 9)) - return ConstantInt::get(Ty, Op->getValue().countTrailingZeros()); + return Context->getConstantInt(Ty, Op->getValue().countTrailingZeros()); else if (Len > 10 && !memcmp(Str, "llvm.ctlz", 9)) - return ConstantInt::get(Ty, Op->getValue().countLeadingZeros()); + return Context->getConstantInt(Ty, Op->getValue().countLeadingZeros()); } } else if (NumOperands == 2) { if (ConstantFP *Op1 = dyn_cast(Operands[0])) { @@ -805,18 +823,18 @@ Op2->getValueAPF().convertToDouble(); if (Len == 3 && !strcmp(Str, "pow")) { - return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty); + return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty, Context); } else if (Len == 4 && !strcmp(Str, "fmod")) { - return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty); + return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty, Context); } else if (Len == 5 && !strcmp(Str, "atan2")) { - return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty); + return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty, Context); } } else if (ConstantInt *Op2C = dyn_cast(Operands[1])) { if (!strcmp(Str, "llvm.powi.f32")) { - return ConstantFP::get(APFloat((float)std::pow((float)Op1V, + return Context->getConstantFP(APFloat((float)std::pow((float)Op1V, (int)Op2C->getZExtValue()))); } else if (!strcmp(Str, "llvm.powi.f64")) { - return ConstantFP::get(APFloat((double)std::pow((double)Op1V, + return Context->getConstantFP(APFloat((double)std::pow((double)Op1V, (int)Op2C->getZExtValue()))); } } Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon Jul 6 13:42:36 2009 @@ -3420,6 +3420,7 @@ if (Constant *C = dyn_cast(V)) return C; if (GlobalValue *GV = dyn_cast(V)) return GV; Instruction *I = cast(V); + LLVMContext* Context = I->getParent()->getContext(); std::vector Operands; Operands.resize(I->getNumOperands()); @@ -3431,10 +3432,12 @@ if (const CmpInst *CI = dyn_cast(I)) return ConstantFoldCompareInstOperands(CI->getPredicate(), - &Operands[0], Operands.size()); + &Operands[0], Operands.size(), + Context); else return ConstantFoldInstOperands(I->getOpcode(), I->getType(), - &Operands[0], Operands.size()); + &Operands[0], Operands.size(), + Context); } /// getConstantEvolutionLoopExitValue - If we know that the specified Phi is @@ -3636,10 +3639,11 @@ Constant *C; if (const CmpInst *CI = dyn_cast(I)) C = ConstantFoldCompareInstOperands(CI->getPredicate(), - &Operands[0], Operands.size()); + &Operands[0], Operands.size(), + Context); else C = ConstantFoldInstOperands(I->getOpcode(), I->getType(), - &Operands[0], Operands.size()); + &Operands[0], Operands.size(), Context); Pair.first->second = C; return getSCEV(C); } Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original) +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Mon Jul 6 13:42:36 2009 @@ -282,7 +282,8 @@ /// users of the global, cleaning up the obvious ones. This is largely just a /// quick scan over the use list to clean up the easy and obvious cruft. This /// returns true if it made a change. -static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) { +static bool CleanupConstantGlobalUsers(Value *V, Constant *Init, + LLVMContext* Context) { bool Changed = false; for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;) { User *U = *UI++; @@ -302,12 +303,12 @@ if (CE->getOpcode() == Instruction::GetElementPtr) { Constant *SubInit = 0; if (Init) - SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE); - Changed |= CleanupConstantGlobalUsers(CE, SubInit); + SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE, Context); + Changed |= CleanupConstantGlobalUsers(CE, SubInit, Context); } else if (CE->getOpcode() == Instruction::BitCast && isa(CE->getType())) { // Pointer cast, delete any stores and memsets to the global. - Changed |= CleanupConstantGlobalUsers(CE, 0); + Changed |= CleanupConstantGlobalUsers(CE, 0, Context); } if (CE->use_empty()) { @@ -321,11 +322,11 @@ Constant *SubInit = 0; if (!isa(GEP->getOperand(0))) { ConstantExpr *CE = - dyn_cast_or_null(ConstantFoldInstruction(GEP)); + dyn_cast_or_null(ConstantFoldInstruction(GEP, Context)); if (Init && CE && CE->getOpcode() == Instruction::GetElementPtr) - SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE); + SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE, Context); } - Changed |= CleanupConstantGlobalUsers(GEP, SubInit); + Changed |= CleanupConstantGlobalUsers(GEP, SubInit, Context); if (GEP->use_empty()) { GEP->eraseFromParent(); @@ -343,7 +344,7 @@ if (SafeToDestroyConstant(C)) { C->destroyConstant(); // This could have invalidated UI, start over from scratch. - CleanupConstantGlobalUsers(V, Init); + CleanupConstantGlobalUsers(V, Init, Context); return true; } } @@ -783,7 +784,7 @@ // nor is the global. if (AllNonStoreUsesGone) { DOUT << " *** GLOBAL NOW DEAD!\n"; - CleanupConstantGlobalUsers(GV, 0); + CleanupConstantGlobalUsers(GV, 0, Context); if (GV->use_empty()) { GV->eraseFromParent(); ++NumDeleted; @@ -795,10 +796,10 @@ /// ConstantPropUsersOf - Walk the use list of V, constant folding all of the /// instructions that are foldable. -static void ConstantPropUsersOf(Value *V) { +static void ConstantPropUsersOf(Value *V, LLVMContext* Context) { for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ) if (Instruction *I = dyn_cast(*UI++)) - if (Constant *NewC = ConstantFoldInstruction(I)) { + if (Constant *NewC = ConstantFoldInstruction(I, Context)) { I->replaceAllUsesWith(NewC); // Advance UI to the next non-I use to avoid invalidating it! @@ -925,9 +926,9 @@ // To further other optimizations, loop over all users of NewGV and try to // constant prop them. This will promote GEP instructions with constant // indices into GEP constant-exprs, which will allow global-opt to hack on it. - ConstantPropUsersOf(NewGV); + ConstantPropUsersOf(NewGV, Context); if (RepValue != NewGV) - ConstantPropUsersOf(RepValue); + ConstantPropUsersOf(RepValue, Context); return NewGV; } @@ -1717,7 +1718,8 @@ // Delete any stores we can find to the global. We may not be able to // make it completely dead though. - bool Changed = CleanupConstantGlobalUsers(GV, GV->getInitializer()); + bool Changed = CleanupConstantGlobalUsers(GV, GV->getInitializer(), + Context); // If the global is dead now, delete it. if (GV->use_empty()) { @@ -1732,7 +1734,7 @@ GV->setConstant(true); // Clean up any obviously simplifiable users now. - CleanupConstantGlobalUsers(GV, GV->getInitializer()); + CleanupConstantGlobalUsers(GV, GV->getInitializer(), Context); // If the global is dead now, just nuke it. if (GV->use_empty()) { @@ -1762,7 +1764,7 @@ GV->setInitializer(SOVConstant); // Clean up any obviously simplifiable users now. - CleanupConstantGlobalUsers(GV, GV->getInitializer()); + CleanupConstantGlobalUsers(GV, GV->getInitializer(), Context); if (GV->use_empty()) { DOUT << " *** Substituting initializer allowed us to " @@ -2007,7 +2009,7 @@ /// enough for us to understand. In particular, if it is a cast of something, /// we punt. We basically just support direct accesses to globals and GEP's of /// globals. This should be kept up to date with CommitValueTo. -static bool isSimpleEnoughPointerToCommit(Constant *C) { +static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext* Context) { if (GlobalVariable *GV = dyn_cast(C)) { if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage()) return false; // do not allow weak/linkonce/dllimport/dllexport linkage. @@ -2021,7 +2023,8 @@ if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage()) return false; // do not allow weak/linkonce/dllimport/dllexport linkage. return GV->hasInitializer() && - ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE); + ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE, + Context); } return false; } @@ -2113,7 +2116,8 @@ /// P after the stores reflected by 'memory' have been performed. If we can't /// decide, return null. static Constant *ComputeLoadResult(Constant *P, - const DenseMap &Memory) { + const DenseMap &Memory, + LLVMContext* Context) { // If this memory location has been recently stored, use the stored value: it // is the most up-to-date. DenseMap::const_iterator I = Memory.find(P); @@ -2132,7 +2136,8 @@ isa(CE->getOperand(0))) { GlobalVariable *GV = cast(CE->getOperand(0)); if (GV->hasInitializer()) - return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE); + return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE, + Context); } return 0; // don't know how to evaluate. @@ -2179,7 +2184,7 @@ if (StoreInst *SI = dyn_cast(CurInst)) { if (SI->isVolatile()) return false; // no volatile accesses. Constant *Ptr = getVal(Values, SI->getOperand(1)); - if (!isSimpleEnoughPointerToCommit(Ptr)) + if (!isSimpleEnoughPointerToCommit(Ptr, Context)) // If this is too complex for us to commit, reject it. return false; Constant *Val = getVal(Values, SI->getOperand(0)); @@ -2212,7 +2217,7 @@ } else if (LoadInst *LI = dyn_cast(CurInst)) { if (LI->isVolatile()) return false; // no volatile accesses. InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)), - MutatedMemory); + MutatedMemory, Context); if (InstResult == 0) return false; // Could not evaluate load. } else if (AllocaInst *AI = dyn_cast(CurInst)) { if (AI->isArrayAllocation()) return false; // Cannot handle array allocs. Modified: llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp (original) +++ llvm/trunk/lib/Transforms/Instrumentation/BlockProfiling.cpp Mon Jul 6 13:42:36 2009 @@ -21,6 +21,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Support/Compiler.h" @@ -62,10 +63,10 @@ if (!I->isDeclaration()) ++NumFunctions; - const Type *ATy = ArrayType::get(Type::Int32Ty, NumFunctions); + const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions); GlobalVariable *Counters = new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, - Constant::getNullValue(ATy), "FuncProfCounters", &M); + Context->getNullValue(ATy), "FuncProfCounters", &M); // Instrument all of the functions... unsigned i = 0; @@ -107,10 +108,10 @@ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) NumBlocks += I->size(); - const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks); + const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks); GlobalVariable *Counters = new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, - Constant::getNullValue(ATy), "BlockProfCounters", &M); + Context->getNullValue(ATy), "BlockProfCounters", &M); // Instrument all of the blocks... unsigned i = 0; Modified: llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp (original) +++ llvm/trunk/lib/Transforms/Instrumentation/EdgeProfiling.cpp Mon Jul 6 13:42:36 2009 @@ -20,6 +20,7 @@ #include "ProfilingUtils.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Support/Compiler.h" @@ -63,10 +64,10 @@ NumEdges += BB->getTerminator()->getNumSuccessors(); } - const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges); + const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges); GlobalVariable *Counters = new GlobalVariable(ATy, false, GlobalValue::InternalLinkage, - Constant::getNullValue(ATy), "EdgeProfCounters", &M); + Context->getNullValue(ATy), "EdgeProfCounters", &M); // Instrument all of the edges... unsigned i = 0; Modified: llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp (original) +++ llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp Mon Jul 6 13:42:36 2009 @@ -18,13 +18,15 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, GlobalValue *Array) { + LLVMContext* Context = MainFn->getContext(); const Type *ArgVTy = - PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)); - const PointerType *UIntPtr = PointerType::getUnqual(Type::Int32Ty); + Context->getPointerTypeUnqual(Context->getPointerTypeUnqual(Type::Int8Ty)); + const PointerType *UIntPtr = Context->getPointerTypeUnqual(Type::Int32Ty); Module &M = *MainFn->getParent(); Constant *InitFn = M.getOrInsertFunction(FnName, Type::Int32Ty, Type::Int32Ty, ArgVTy, UIntPtr, Type::Int32Ty, @@ -33,27 +35,27 @@ // This could force argc and argv into programs that wouldn't otherwise have // them, but instead we just pass null values in. std::vector Args(4); - Args[0] = Constant::getNullValue(Type::Int32Ty); - Args[1] = Constant::getNullValue(ArgVTy); + Args[0] = Context->getNullValue(Type::Int32Ty); + Args[1] = Context->getNullValue(ArgVTy); // Skip over any allocas in the entry block. BasicBlock *Entry = MainFn->begin(); BasicBlock::iterator InsertPos = Entry->begin(); while (isa(InsertPos)) ++InsertPos; - std::vector GEPIndices(2, Constant::getNullValue(Type::Int32Ty)); + std::vector GEPIndices(2, Context->getNullValue(Type::Int32Ty)); unsigned NumElements = 0; if (Array) { - Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0], + Args[2] = Context->getConstantExprGetElementPtr(Array, &GEPIndices[0], GEPIndices.size()); NumElements = cast(Array->getType()->getElementType())->getNumElements(); } else { // If this profiling instrumentation doesn't have a constant array, just // pass null. - Args[2] = ConstantPointerNull::get(UIntPtr); + Args[2] = Context->getConstantPointerNull(UIntPtr); } - Args[3] = ConstantInt::get(Type::Int32Ty, NumElements); + Args[3] = Context->getConstantInt(Type::Int32Ty, NumElements); Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(), "newargc", InsertPos); @@ -99,6 +101,8 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, GlobalValue *CounterArray) { + LLVMContext* Context = BB->getContext(); + // Insert the increment after any alloca or PHI instructions... BasicBlock::iterator InsertPos = BB->getFirstNonPHI(); while (isa(InsertPos)) @@ -106,15 +110,16 @@ // Create the getelementptr constant expression std::vector Indices(2); - Indices[0] = Constant::getNullValue(Type::Int32Ty); - Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); + Indices[0] = Context->getNullValue(Type::Int32Ty); + Indices[1] = Context->getConstantInt(Type::Int32Ty, CounterNum); Constant *ElementPtr = - ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], Indices.size()); + Context->getConstantExprGetElementPtr(CounterArray, &Indices[0], + Indices.size()); // Load, increment and store the value back. Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos); Value *NewVal = BinaryOperator::Create(Instruction::Add, OldVal, - ConstantInt::get(Type::Int32Ty, 1), + Context->getConstantInt(Type::Int32Ty, 1), "NewFuncCounter", InsertPos); new StoreInst(NewVal, ElementPtr, InsertPos); } Modified: llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp (original) +++ llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp Mon Jul 6 13:42:36 2009 @@ -33,6 +33,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Pass.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Instructions.h" #include "llvm/Constants.h" @@ -195,7 +196,7 @@ GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t, uint64_t resetval) : T(t) { - ConstantInt* Init = ConstantInt::get(T, resetval); + ConstantInt* Init = M.getContext().getConstantInt(T, resetval); ResetValue = Init; Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage, Init, "RandomSteeringCounter", &M); @@ -207,14 +208,16 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); + LLVMContext* Context = bb->getContext(); //decrement counter LoadInst* l = new LoadInst(Counter, "counter", t); - ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, ConstantInt::get(T, 0), + ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, + Context->getConstantInt(T, 0), "countercc", t); - Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1), + Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1), "counternew", t); new StoreInst(nv, Counter, t); t->setCondition(s); @@ -232,7 +235,7 @@ GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t, uint64_t resetval) : AI(0), T(t) { - ConstantInt* Init = ConstantInt::get(T, resetval); + ConstantInt* Init = M.getContext().getConstantInt(T, resetval); ResetValue = Init; Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage, Init, "RandomSteeringCounter", &M); @@ -279,14 +282,16 @@ void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); + LLVMContext* Context = bb->getContext(); //decrement counter LoadInst* l = new LoadInst(AI, "counter", t); - ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, ConstantInt::get(T, 0), + ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, + Context->getConstantInt(T, 0), "countercc", t); - Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1), + Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1), "counternew", t); new StoreInst(nv, AI, t); t->setCondition(s); @@ -312,14 +317,15 @@ void CycleCounter::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); + LLVMContext* Context = bb->getContext(); CallInst* c = CallInst::Create(F, "rdcc", t); BinaryOperator* b = - BinaryOperator::CreateAnd(c, ConstantInt::get(Type::Int64Ty, rm), + BinaryOperator::CreateAnd(c, Context->getConstantInt(Type::Int64Ty, rm), "mrdcc", t); ICmpInst *s = new ICmpInst(ICmpInst::ICMP_EQ, b, - ConstantInt::get(Type::Int64Ty, 0), + Context->getConstantInt(Type::Int64Ty, 0), "mrdccc", t); t->setCondition(s); @@ -345,16 +351,16 @@ // Create the getelementptr constant expression std::vector Indices(2); - Indices[0] = Constant::getNullValue(Type::Int32Ty); - Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); - Constant *ElementPtr = ConstantExpr::getGetElementPtr(CounterArray, + Indices[0] = Context->getNullValue(Type::Int32Ty); + Indices[1] = Context->getConstantInt(Type::Int32Ty, CounterNum); + Constant *ElementPtr = Context->getConstantExprGetElementPtr(CounterArray, &Indices[0], 2); // Load, increment and store the value back. Value *OldVal = new LoadInst(ElementPtr, "OldCounter", InsertPos); profcode.insert(OldVal); Value *NewVal = BinaryOperator::CreateAdd(OldVal, - ConstantInt::get(Type::Int32Ty, 1), + Context->getConstantInt(Type::Int32Ty, 1), "NewCounter", InsertPos); profcode.insert(NewVal); profcode.insert(new StoreInst(NewVal, ElementPtr, InsertPos)); @@ -475,7 +481,7 @@ //b: BranchInst::Create(cast(Translate(dst)), bbC); BranchInst::Create(dst, cast(Translate(dst)), - ConstantInt::get(Type::Int1Ty, true), bbCp); + Context->getConstantInt(Type::Int1Ty, true), bbCp); //c: { TerminatorInst* iB = src->getTerminator(); @@ -532,7 +538,7 @@ ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0), cast( Translate(T->getSuccessor(0))), - ConstantInt::get(Type::Int1Ty, + Context->getConstantInt(Type::Int1Ty, true))); //do whatever is needed now that the function is duplicated Modified: llvm/trunk/lib/Transforms/Scalar/ConstantProp.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ConstantProp.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/ConstantProp.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/ConstantProp.cpp Mon Jul 6 13:42:36 2009 @@ -67,7 +67,7 @@ WorkList.erase(WorkList.begin()); // Get an element from the worklist... if (!I->use_empty()) // Don't muck with dead instructions... - if (Constant *C = ConstantFoldInstruction(I)) { + if (Constant *C = ConstantFoldInstruction(I, Context)) { // Add all of the users of this instruction to the worklist, they might // be constant propagatable now... for (Value::use_iterator UI = I->use_begin(), UE = I->use_end(); Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jul 6 13:42:36 2009 @@ -11598,7 +11598,8 @@ if (GlobalVariable *GV = dyn_cast(CE->getOperand(0))) if (GV->isConstant() && GV->hasDefinitiveInitializer()) if (Constant *V = - ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE)) + ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE, + Context)) return ReplaceInstUsesWith(LI, V); if (CE->getOperand(0)->isNullValue()) { // Insert a new store to null instruction before the load to indicate @@ -12876,7 +12877,7 @@ } // ConstantProp instruction if trivially constant. - if (Constant *C = ConstantFoldInstruction(Inst, TD)) { + if (Constant *C = ConstantFoldInstruction(Inst, BB->getContext(), TD)) { DOUT << "IC: ConstFold to: " << *C << " from: " << *Inst; Inst->replaceAllUsesWith(C); ++NumConstProp; @@ -12991,7 +12992,7 @@ } // Instruction isn't dead, see if we can constant propagate it. - if (Constant *C = ConstantFoldInstruction(I, TD)) { + if (Constant *C = ConstantFoldInstruction(I, F.getContext(), TD)) { DOUT << "IC: ConstFold to: " << *C << " from: " << *I; // Add operands to the worklist. @@ -13011,7 +13012,8 @@ // See if we can constant fold its operands. for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i) if (ConstantExpr *CE = dyn_cast(i)) - if (Constant *NewC = ConstantFoldConstantExpression(CE, TD)) + if (Constant *NewC = ConstantFoldConstantExpression(CE, + F.getContext(), TD)) if (NewC != CE) { i->set(NewC); Changed = true; Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Mon Jul 6 13:42:36 2009 @@ -982,7 +982,7 @@ BI = NewBB->begin(); for (BasicBlock::iterator E = NewBB->end(); BI != E; ) { Instruction *Inst = BI++; - if (Constant *C = ConstantFoldInstruction(Inst, TD)) { + if (Constant *C = ConstantFoldInstruction(Inst, BB->getContext(), TD)) { Inst->replaceAllUsesWith(C); Inst->eraseFromParent(); continue; Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp Mon Jul 6 13:42:36 2009 @@ -986,7 +986,7 @@ Worklist.pop_back(); // Simple constant folding. - if (Constant *C = ConstantFoldInstruction(I)) { + if (Constant *C = ConstantFoldInstruction(I, Context)) { ReplaceUsesOfWith(I, C, Worklist, L, LPM); continue; } Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Mon Jul 6 13:42:36 2009 @@ -1158,7 +1158,8 @@ if (GlobalVariable *GV = dyn_cast(CE->getOperand(0))) if (GV->isConstant() && GV->hasDefinitiveInitializer()) if (Constant *V = - ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE)) { + ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE, + Context)) { markConstant(IV, &I, V); return; } Modified: llvm/trunk/lib/Transforms/Scalar/TailDuplication.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/TailDuplication.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/TailDuplication.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/TailDuplication.cpp Mon Jul 6 13:42:36 2009 @@ -358,7 +358,7 @@ Instruction *Inst = BI++; if (isInstructionTriviallyDead(Inst)) Inst->eraseFromParent(); - else if (Constant *C = ConstantFoldInstruction(Inst)) { + else if (Constant *C = ConstantFoldInstruction(Inst, Context)) { Inst->replaceAllUsesWith(C); Inst->eraseFromParent(); } Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Mon Jul 6 13:42:36 2009 @@ -338,7 +338,8 @@ if (const CmpInst *CI = dyn_cast(I)) return ConstantFoldCompareInstOperands(CI->getPredicate(), - &Ops[0], Ops.size(), TD); + &Ops[0], Ops.size(), + Context, TD); if (const LoadInst *LI = dyn_cast(I)) if (ConstantExpr *CE = dyn_cast(Ops[0])) @@ -346,10 +347,10 @@ if (GlobalVariable *GV = dyn_cast(CE->getOperand(0))) if (GV->isConstant() && GV->hasDefinitiveInitializer()) return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), - CE); + CE, Context); return ConstantFoldInstOperands(I->getOpcode(), I->getType(), &Ops[0], - Ops.size(), TD); + Ops.size(), Context, TD); } /// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto, Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Jul 6 13:42:36 2009 @@ -1178,6 +1178,7 @@ /// ultimate destination. static bool FoldCondBranchOnPHI(BranchInst *BI) { BasicBlock *BB = BI->getParent(); + LLVMContext* Context = BB->getContext(); PHINode *PN = dyn_cast(BI->getCondition()); // NOTE: we currently cannot transform this case if the PHI node is used // outside of the block. @@ -1243,7 +1244,7 @@ } // Check for trivial simplification. - if (Constant *C = ConstantFoldInstruction(N)) { + if (Constant *C = ConstantFoldInstruction(N, Context)) { TranslateMap[BBI] = C; delete N; // Constant folded away, don't need actual inst } else { Modified: llvm/trunk/lib/Transforms/Utils/UnrollLoop.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/UnrollLoop.cpp?rev=74844&r1=74843&r2=74844&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/UnrollLoop.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/UnrollLoop.cpp Mon Jul 6 13:42:36 2009 @@ -349,7 +349,8 @@ if (isInstructionTriviallyDead(Inst)) (*BB)->getInstList().erase(Inst); - else if (Constant *C = ConstantFoldInstruction(Inst)) { + else if (Constant *C = ConstantFoldInstruction(Inst, + Header->getContext())) { Inst->replaceAllUsesWith(C); (*BB)->getInstList().erase(Inst); } From resistor at mac.com Mon Jul 6 13:44:08 2009 From: resistor at mac.com (Owen Anderson) Date: Mon, 06 Jul 2009 18:44:08 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r74845 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp Message-ID: <200907061844.n66Ii969032213@zion.cs.uiuc.edu> Author: resistor Date: Mon Jul 6 13:44:04 2009 New Revision: 74845 URL: http://llvm.org/viewvc/llvm-project?rev=74845&view=rev Log: Update for constant folding API changes. Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=74845&r1=74844&r2=74845&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Mon Jul 6 13:44:04 2009 @@ -466,7 +466,7 @@ TheTarget = TME->CtorFn(*TheModule, FeatureStr); assert(TheTarget->getTargetData()->isBigEndian() == BYTES_BIG_ENDIAN); - TheFolder = new TargetFolder(TheTarget->getTargetData()); + TheFolder = new TargetFolder(TheTarget->getTargetData(), &getGlobalContext()); // Install information about target datalayout stuff into the module for // optimizer use. Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=74845&r1=74844&r2=74845&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Mon Jul 6 13:44:04 2009 @@ -33,6 +33,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/InlineAsm.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/System/Host.h" @@ -7904,7 +7905,7 @@ FieldPtr = ConstantFoldInstOperands(Instruction::GetElementPtr, FieldPtr->getType(), Ops, - 3, &TD); + 3, &getGlobalContext(), &TD); // Now that we did an offset from the start of the struct, subtract off // the offset from BitStart. From resistor at mac.com Mon Jul 6 13:50:55 2009 From: resistor at mac.com (Owen Anderson) Date: Mon, 06 Jul 2009 18:50:55 -0000 Subject: [llvm-commits] [llvm] r74846 - /llvm/trunk/lib/System/Threading.cpp Message-ID: <200907061850.n66IoxVS032412@zion.cs.uiuc.edu> Author: resistor Date: Mon Jul 6 13:50:47 2009 New Revision: 74846 URL: http://llvm.org/viewvc/llvm-project?rev=74846&view=rev Log: We need to include config.h to get the proper setting to LLVM_MULTITHREADED. Patch by Xerxes Ranby. Modified: llvm/trunk/lib/System/Threading.cpp Modified: llvm/trunk/lib/System/Threading.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Threading.cpp?rev=74846&r1=74845&r2=74846&view=diff ============================================================================== --- llvm/trunk/lib/System/Threading.cpp (original) +++ llvm/trunk/lib/System/Threading.cpp Mon Jul 6 13:50:47 2009 @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Config/config.h" #include "llvm/System/Threading.h" #include "llvm/System/Atomic.h" #include "llvm/System/Mutex.h" From evan.cheng at apple.com Mon Jul 6 14:11:05 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 6 Jul 2009 12:11:05 -0700 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction In-Reply-To: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> Message-ID: <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> Sorry, I am missing some context. Why is each of the emitter a separate template instantiation in the first place? Why can't the code in X86CodeEmitter.cpp be shared across all 3? Evan On Jul 6, 2009, at 10:57 AM, Aaron Gray wrote: > This patch separates the template instatiations for the > createX86*CodeEmitterPass of [X86]Emiiter into > separate .cpp file and thus different object modules in the library. > This will result in a slightly smaller footprint for programs just > using one of the MachineCodeEmitter, ObjectCodeEmitter, or > JITCodeEmitter classes. > > This should save 2 * 47K each for llc, lli, and LTOCodeGenerator. > > Although the MachineCodeEmitter version is not being use anymore at > present I have left it in for now. > > It also opens the door for altername MachineCodeEmitters for > experimental or other purposes such as unladen Swallow. > > I will be submitting simular patches for Alpha, ARM, and PowerPC if > this one gets accepted. > > I have made CMake the necessary CMake changes too in the patch. > > This patch needs to be applied relatively quickly as it moves > X86CodeEmitter.cpp code to X86CodeEmitter.h and any chages in SVN > inbetween would be lost. > > Aaron > > From mai4 at uiuc.edu Mon Jul 6 14:32:56 2009 From: mai4 at uiuc.edu (Haohui Mai) Date: Mon, 06 Jul 2009 19:32:56 -0000 Subject: [llvm-commits] [poolalloc] r74848 - in /poolalloc/trunk/lib/DSA: Steensgaard.cpp SteensgaardAA.cpp Message-ID: <200907061932.n66JWuwL001216@zion.cs.uiuc.edu> Author: mai4 Date: Mon Jul 6 14:32:55 2009 New Revision: 74848 URL: http://llvm.org/viewvc/llvm-project?rev=74848&view=rev Log: Export the DSGraph interface of steensgaard alais analysis. Added: poolalloc/trunk/lib/DSA/SteensgaardAA.cpp Modified: poolalloc/trunk/lib/DSA/Steensgaard.cpp Modified: poolalloc/trunk/lib/DSA/Steensgaard.cpp URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Steensgaard.cpp?rev=74848&r1=74847&r2=74848&view=diff ============================================================================== --- poolalloc/trunk/lib/DSA/Steensgaard.cpp (original) +++ poolalloc/trunk/lib/DSA/Steensgaard.cpp Mon Jul 6 14:32:55 2009 @@ -1,4 +1,4 @@ -//===- Steensgaard.cpp - Context Insensitive Alias Analysis ---------------===// +//===- Steensgaard.cpp - Context Insensitive Data Structure Analysis ------===// // // The LLVM Compiler Infrastructure // @@ -7,10 +7,9 @@ // //===----------------------------------------------------------------------===// // -// This pass uses the data structure graphs to implement a simple context -// insensitive alias analysis. It does this by computing the local analysis -// graphs for all of the functions, then merging them together into a single big -// graph without cloning. +// This pass computes a context-insensitive data analysis graph. It does this +// by computing the local analysis graphs for all of the functions, then merging +// them together into a single big graph without cloning. // //===----------------------------------------------------------------------===// @@ -21,116 +20,57 @@ #include "llvm/Module.h" #include "llvm/Support/Debug.h" #include -using namespace llvm; - -namespace { - class Steens : public ModulePass, public AliasAnalysis { - DSGraph *ResultGraph; - - EquivalenceClasses GlobalECs; // Always empty - public: - static char ID; - Steens() : ModulePass((intptr_t)&ID), ResultGraph(0) {} - ~Steens() { - releaseMyMemory(); - assert(ResultGraph == 0 && "releaseMemory not called?"); - } - - //------------------------------------------------ - // Implement the Pass API - // - - // run - Build up the result graph, representing the pointer graph for the - // program. - // - bool runOnModule(Module &M); - - virtual void releaseMyMemory() { delete ResultGraph; ResultGraph = 0; } - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AliasAnalysis::getAnalysisUsage(AU); - AU.setPreservesAll(); // Does not transform code... - AU.addRequired(); // Uses local dsgraph - } - - // print - Implement the Pass::print method... - void print(OStream O, const Module *M) const { - if (O.stream()) print(*O.stream(), M); - } - void print(std::ostream &O, const Module *M) const { - assert(ResultGraph && "Result graph has not yet been computed!"); - ResultGraph->writeGraphToFile(O, "steensgaards"); - } - //------------------------------------------------ - // Implement the AliasAnalysis API - // - - AliasResult alias(const Value *V1, unsigned V1Size, - const Value *V2, unsigned V2Size); - - virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); - virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2); - - private: - void ResolveFunctionCall(const Function *F, const DSCallSite &Call, - DSNodeHandle &RetVal); - }; - - // Register the pass... - RegisterPass X("steens-aa", - "Steensgaard's alias analysis (DSGraph based)"); +using namespace llvm; - // Register as an implementation of AliasAnalysis - RegisterAnalysisGroup Y(X); +SteensgaardDataStructures::~SteensgaardDataStructures() { + releaseMyMemory(); + assert(ResultGraph == 0 && "releaseMemory not called?"); } -char Steens::ID; - -ModulePass *llvm::createSteensgaardPass() { return new Steens(); } - -/// ResolveFunctionCall - Resolve the actual arguments of a call to function F -/// with the specified call site descriptor. This function links the arguments -/// and the return value for the call site context-insensitively. -/// -void Steens::ResolveFunctionCall(const Function *F, const DSCallSite &Call, - DSNodeHandle &RetVal) { - assert(ResultGraph != 0 && "Result graph not allocated!"); - DSGraph::ScalarMapTy &ValMap = ResultGraph->getScalarMap(); - - // Handle the return value of the function... - if (Call.getRetVal().getNode() && RetVal.getNode()) - RetVal.mergeWith(Call.getRetVal()); +void +SteensgaardDataStructures::releaseMyMemory() { + delete ResultGraph; + ResultGraph = 0; +} - // Loop over all pointer arguments, resolving them to their provided pointers - unsigned PtrArgIdx = 0; - for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end(); - AI != AE && PtrArgIdx < Call.getNumPtrArgs(); ++AI) { - DSGraph::ScalarMapTy::iterator I = ValMap.find(AI); - if (I != ValMap.end()) // If its a pointer argument... - I->second.mergeWith(Call.getPtrArg(PtrArgIdx++)); - } +// print - Implement the Pass::print method... +void +SteensgaardDataStructures::print(OStream O, const Module *M) const { + if (O.stream()) print(*O.stream(), M); } +void +SteensgaardDataStructures::print(std::ostream &O, const Module *M) const { + assert(ResultGraph && "Result graph has not yet been computed!"); + ResultGraph->writeGraphToFile(O, "steensgaards"); +} /// run - Build up the result graph, representing the pointer graph for the /// program. /// -bool Steens::runOnModule(Module &M) { - InitializeAliasAnalysis(this); +bool +SteensgaardDataStructures::runOnModule(Module &M) { + DS = &getAnalysis(); + return runOnModuleInternal(M); +} + +bool +SteensgaardDataStructures::runOnModuleInternal(Module &M) { assert(ResultGraph == 0 && "Result graph already allocated!"); - LocalDataStructures &LDS = getAnalysis(); // Create a new, empty, graph... ResultGraph = new DSGraph(GlobalECs, getTargetData()); - ResultGraph->spliceFrom(LDS.getGlobalsGraph()); + ResultGraph->spliceFrom(DS->getGlobalsGraph()); // Loop over the rest of the module, merging graphs for non-external functions // into this graph. // - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (!I->isDeclaration()) - ResultGraph->spliceFrom(LDS.getDSGraph(*I)); + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + if (!I->isDeclaration()) { + ResultGraph->spliceFrom(DS->getDSGraph(*I)); + } + } ResultGraph->removeTriviallyDeadNodes(); @@ -139,11 +79,9 @@ // Now that we have all of the graphs inlined, we can go about eliminating // call nodes... // - std::list &Calls = ResultGraph->getAuxFunctionCalls(); - assert(Calls.empty() && "Aux call list is already in use??"); // Start with a copy of the original call sites. - Calls = ResultGraph->getFunctionCalls(); + std::list & Calls = ResultGraph->getFunctionCalls(); for (std::list::iterator CI = Calls.begin(), E = Calls.end(); CI != E;) { @@ -187,95 +125,47 @@ // Update the "incomplete" markers on the nodes, ignoring unknownness due to // incoming arguments... ResultGraph->maskIncompleteMarkers(); - ResultGraph->markIncompleteNodes(DSGraph::IgnoreGlobals | - DSGraph::MarkFormalArgs); + + ResultGraph->markIncompleteNodes(DSGraph::MarkFormalArgs | DSGraph::IgnoreGlobals); // Remove any nodes that are dead after all of the merging we have done... // FIXME: We should be able to disable the globals graph for steens! - //ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); + + ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); print(DOUT, &M); return false; } -AliasAnalysis::AliasResult Steens::alias(const Value *V1, unsigned V1Size, - const Value *V2, unsigned V2Size) { - assert(ResultGraph && "Result graph has not been computed yet!"); - - DSGraph::ScalarMapTy &GSM = ResultGraph->getScalarMap(); - - DSGraph::ScalarMapTy::iterator I = GSM.find(const_cast(V1)); - DSGraph::ScalarMapTy::iterator J = GSM.find(const_cast(V2)); - if (I != GSM.end() && !I->second.isNull() && - J != GSM.end() && !J->second.isNull()) { - DSNodeHandle &V1H = I->second; - DSNodeHandle &V2H = J->second; - - // If at least one of the nodes is complete, we can say something about - // this. If one is complete and the other isn't, then they are obviously - // different nodes. If they are both complete, we can't say anything - // useful. - if (I->second.getNode()->isCompleteNode() || - J->second.getNode()->isCompleteNode()) { - // If the two pointers point to different data structure graph nodes, they - // cannot alias! - if (V1H.getNode() != V2H.getNode()) - return NoAlias; - - // See if they point to different offsets... if so, we may be able to - // determine that they do not alias... - unsigned O1 = I->second.getOffset(), O2 = J->second.getOffset(); - if (O1 != O2) { - if (O2 < O1) { // Ensure that O1 <= O2 - std::swap(V1, V2); - std::swap(O1, O2); - std::swap(V1Size, V2Size); - } - - if (O1+V1Size <= O2) - return NoAlias; - } - } - } +/// ResolveFunctionCall - Resolve the actual arguments of a call to function F +/// with the specified call site descriptor. This function links the arguments +/// and the return value for the call site context-insensitively. +/// +void +SteensgaardDataStructures::ResolveFunctionCall(const Function *F, + const DSCallSite &Call, + DSNodeHandle &RetVal) { - // If we cannot determine alias properties based on our graph, fall back on - // some other AA implementation. - // - return AliasAnalysis::alias(V1, V1Size, V2, V2Size); -} + assert(ResultGraph != 0 && "Result graph not allocated!"); + DSGraph::ScalarMapTy &ValMap = ResultGraph->getScalarMap(); -AliasAnalysis::ModRefResult -Steens::getModRefInfo(CallSite CS, Value *P, unsigned Size) { - AliasAnalysis::ModRefResult Result = ModRef; - - // Find the node in question. - DSGraph::ScalarMapTy &GSM = ResultGraph->getScalarMap(); - DSGraph::ScalarMapTy::iterator I = GSM.find(P); - - if (I != GSM.end() && !I->second.isNull()) { - DSNode *N = I->second.getNode(); - if (N->isCompleteNode()) { - // If this is a direct call to an external function, and if the pointer - // points to a complete node, the external function cannot modify or read - // the value (we know it's not passed out of the program!). - if (Function *F = CS.getCalledFunction()) - if (F->isDeclaration()) - return NoModRef; - - // Otherwise, if the node is complete, but it is only M or R, return this. - // This can be useful for globals that should be marked const but are not. - if (!N->isModifiedNode()) - Result = (ModRefResult)(Result & ~Mod); - if (!N->isReadNode()) - Result = (ModRefResult)(Result & ~Ref); - } - } + // Handle the return value of the function... + if (Call.getRetVal().getNode() && RetVal.getNode()) + RetVal.mergeWith(Call.getRetVal()); - return (ModRefResult)(Result & AliasAnalysis::getModRefInfo(CS, P, Size)); + // Loop over all pointer arguments, resolving them to their provided pointers + unsigned PtrArgIdx = 0; + for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end(); + AI != AE && PtrArgIdx < Call.getNumPtrArgs(); ++AI) { + DSGraph::ScalarMapTy::iterator I = ValMap.find(AI); + if (I != ValMap.end()) // If its a pointer argument... + I->second.mergeWith(Call.getPtrArg(PtrArgIdx++)); + } } -AliasAnalysis::ModRefResult -Steens::getModRefInfo(CallSite CS1, CallSite CS2) -{ - return AliasAnalysis::getModRefInfo(CS1,CS2); -} +char SteensgaardDataStructures::ID = 0; + +// Register the pass... +static RegisterPass X +("dsa-steens", + "Context-insensitive Data Structure Analysis"); Added: poolalloc/trunk/lib/DSA/SteensgaardAA.cpp URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/SteensgaardAA.cpp?rev=74848&view=auto ============================================================================== --- poolalloc/trunk/lib/DSA/SteensgaardAA.cpp (added) +++ poolalloc/trunk/lib/DSA/SteensgaardAA.cpp Mon Jul 6 14:32:55 2009 @@ -0,0 +1,162 @@ +//===- Steensgaard.cpp - Context Insensitive Alias Analysis ---------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This pass uses the data structure graphs to implement a simple context +// insensitive alias analysis. It does this by computing the local analysis +// graphs for all of the functions, then merging them together into a single big +// graph without cloning. +// +//===----------------------------------------------------------------------===// + +#include "dsa/DataStructure.h" +#include "dsa/DSGraph.h" +#include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/Passes.h" +#include "llvm/Module.h" +#include "llvm/Support/Debug.h" +#include +using namespace llvm; + +namespace { + class Steens : public ModulePass, public AliasAnalysis { + DSGraph * ResultGraph; + public: + static char ID; + Steens() : ModulePass((intptr_t)&ID), ResultGraph(NULL) {} + ~Steens() { } + + //------------------------------------------------ + // Implement the Pass API + // + + // run - Build up the result graph, representing the pointer graph for the + // program. + // + bool runOnModule(Module &M); + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AliasAnalysis::getAnalysisUsage(AU); + AU.setPreservesAll(); // Does not transform code... + AU.addRequired(); // Uses steensgaard dsgraph + } + + //------------------------------------------------ + // Implement the AliasAnalysis API + // + + AliasResult alias(const Value *V1, unsigned V1Size, + const Value *V2, unsigned V2Size); + + virtual ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size); + virtual ModRefResult getModRefInfo(CallSite CS1, CallSite CS2); + + }; + + // Register the pass... + RegisterPass X("steens-aa", + "Steensgaard's alias analysis (DSGraph based)"); + + // Register as an implementation of AliasAnalysis + RegisterAnalysisGroup Y(X); +} + +char Steens::ID; + +ModulePass *llvm::createSteensgaardPass() { return new Steens(); } + +/// run - Build up the result graph, representing the pointer graph for the +/// program. +/// +bool Steens::runOnModule(Module &M) { + InitializeAliasAnalysis(this); + ResultGraph = getAnalysis().getResultGraph(); + return false; +} + +AliasAnalysis::AliasResult Steens::alias(const Value *V1, unsigned V1Size, + const Value *V2, unsigned V2Size) { + assert(ResultGraph && "Result graph has not been computed yet!"); + + DSGraph::ScalarMapTy &GSM = ResultGraph->getScalarMap(); + + DSGraph::ScalarMapTy::iterator I = GSM.find(const_cast(V1)); + DSGraph::ScalarMapTy::iterator J = GSM.find(const_cast(V2)); + if (I != GSM.end() && !I->second.isNull() && + J != GSM.end() && !J->second.isNull()) { + DSNodeHandle &V1H = I->second; + DSNodeHandle &V2H = J->second; + + // If at least one of the nodes is complete, we can say something about + // this. If one is complete and the other isn't, then they are obviously + // different nodes. If they are both complete, we can't say anything + // useful. + if (I->second.getNode()->isCompleteNode() || + J->second.getNode()->isCompleteNode()) { + // If the two pointers point to different data structure graph nodes, they + // cannot alias! + if (V1H.getNode() != V2H.getNode()) + return NoAlias; + + // See if they point to different offsets... if so, we may be able to + // determine that they do not alias... + unsigned O1 = I->second.getOffset(), O2 = J->second.getOffset(); + if (O1 != O2) { + if (O2 < O1) { // Ensure that O1 <= O2 + std::swap(V1, V2); + std::swap(O1, O2); + std::swap(V1Size, V2Size); + } + + if (O1+V1Size <= O2) + return NoAlias; + } + } + } + + // If we cannot determine alias properties based on our graph, fall back on + // some other AA implementation. + // + return AliasAnalysis::alias(V1, V1Size, V2, V2Size); +} + +AliasAnalysis::ModRefResult +Steens::getModRefInfo(CallSite CS, Value *P, unsigned Size) { + AliasAnalysis::ModRefResult Result = ModRef; + + // Find the node in question. + DSGraph::ScalarMapTy &GSM = ResultGraph->getScalarMap(); + DSGraph::ScalarMapTy::iterator I = GSM.find(P); + + if (I != GSM.end() && !I->second.isNull()) { + DSNode *N = I->second.getNode(); + if (N->isCompleteNode()) { + // If this is a direct call to an external function, and if the pointer + // points to a complete node, the external function cannot modify or read + // the value (we know it's not passed out of the program!). + if (Function *F = CS.getCalledFunction()) + if (F->isDeclaration()) + return NoModRef; + + // Otherwise, if the node is complete, but it is only M or R, return this. + // This can be useful for globals that should be marked const but are not. + if (!N->isModifiedNode()) + Result = (ModRefResult)(Result & ~Mod); + if (!N->isReadNode()) + Result = (ModRefResult)(Result & ~Ref); + } + } + + return (ModRefResult)(Result & AliasAnalysis::getModRefInfo(CS, P, Size)); +} + +AliasAnalysis::ModRefResult +Steens::getModRefInfo(CallSite CS1, CallSite CS2) +{ + return AliasAnalysis::getModRefInfo(CS1,CS2); +} From bruno.cardoso at gmail.com Mon Jul 6 14:53:36 2009 From: bruno.cardoso at gmail.com (Bruno Cardoso Lopes) Date: Mon, 6 Jul 2009 16:53:36 -0300 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction In-Reply-To: <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> Message-ID: <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> On Mon, Jul 6, 2009 at 4:11 PM, Evan Cheng wrote: > Sorry, I am missing some context. Why is each of the emitter a separate > template instantiation in the first place? Why can't the code in This happens because ObjectCodeEmitter is a lot simpler than JITCodeEmitter and we don't need to deal with CurrBufferBegin, GVStub*, and so on. > X86CodeEmitter.cpp be shared across all 3? I agree with Evan, I don't see why this code shouldn't be shared, besides that, putting all that code in a header file doesn't seems like the right approach. -- Bruno Cardoso Lopes http://www.brunocardoso.cc From aaronngray.lists at googlemail.com Mon Jul 6 15:13:34 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 21:13:34 +0100 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> Message-ID: <1F76B5AD92E84E2AAF89D7725C81112E@HPLAPTOP> > Sorry, I am missing some context. Why is each of the emitter a separate > template instantiation in the first place? Why can't the code in > X86CodeEmitter.cpp be shared across all 3? If you rememer we generically parameterized X86CodeEmitter, ARMBaseCodeEmitter, AlphaCodeEmitter, and the PowerPCCodeEmitter to take different machineCodeEmitters, one for JIT, JITCodeEmitter, and one for ObjectCodeEmission. Both JITCodeEmitter and ObjectCodeEmitter inherit from MachineCodeEmitter, but JITCodeEmitter writes to a buffer where as MachineCodeEmitter writes to a vector. Basically this patch is a cleanup patch that reduces the need to linkin the JITCodeEmitter version of the actual code Emitter if you are only producing Object Modules, or coversly the Emitter if you are doing JIT, which is where you may want a small footprint on some embedded device. Having templates and templated methods into headers is quite common stuff in projects which use alot of templating. Basically everything is transparent and this allow other CodeEmitters to be created and added easily. Reid Kleckner may well want to inherit from the current JITCodeEmitter and add extra functionality for his unladden swallow Python/LLVM project. And having separate .cpp objects means we don't link in his code and he only links in what code he needs. Hope this explains things, Aaron > Evan > On Jul 6, 2009, at 10:57 AM, Aaron Gray wrote: > >> This patch separates the template instatiations for the >> createX86*CodeEmitterPass of [X86]Emiiter into separate >> .cpp file and thus different object modules in the library. This will >> result in a slightly smaller footprint for programs just using one of >> the MachineCodeEmitter, ObjectCodeEmitter, or JITCodeEmitter classes. >> >> This should save 2 * 47K each for llc, lli, and LTOCodeGenerator. >> >> Although the MachineCodeEmitter version is not being use anymore at >> present I have left it in for now. >> >> It also opens the door for altername MachineCodeEmitters for >> experimental or other purposes such as unladen Swallow. >> >> I will be submitting simular patches for Alpha, ARM, and PowerPC if this >> one gets accepted. >> >> I have made CMake the necessary CMake changes too in the patch. >> >> This patch needs to be applied relatively quickly as it moves >> X86CodeEmitter.cpp code to X86CodeEmitter.h and any chages in SVN >> inbetween would be lost. >> >> Aaron >> >> > From aaronngray.lists at googlemail.com Mon Jul 6 15:17:05 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 21:17:05 +0100 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> Message-ID: > On Mon, Jul 6, 2009 at 4:11 PM, Evan Cheng wrote: >> Sorry, I am missing some context. Why is each of the emitter a separate >> template instantiation in the first place? Why can't the code in > > This happens because ObjectCodeEmitter is a lot simpler than > JITCodeEmitter and > we don't need to deal with CurrBufferBegin, GVStub*, and so on. > >> X86CodeEmitter.cpp be shared across all 3? > > I agree with Evan, I don't see why this code shouldn't be shared, > besides that, putting > all that code in a header file doesn't seems like the right approach. > On Mon, Jul 6, 2009 at 4:11 PM, Evan Cheng wrote: >> Sorry, I am missing some context. Why is each of the emitter a separate >> template instantiation in the first place? Why can't the code in > > This happens because ObjectCodeEmitter is a lot simpler than > JITCodeEmitter and > we don't need to deal with CurrBufferBegin, GVStub*, and so on. > >> X86CodeEmitter.cpp be shared across all 3? > > I agree with Evan, I don't see why this code shouldn't be shared, > besides that, putting > all that code in a header file doesn't seems like the right approach. Its the right approach. It allows us to have separate object modules thus reducing memory overheads for other projects that at least one other person has been asking for. Putting templated code in headers and instatiating separately in .cpp files is quite common practice once you use templating alot. Aaron From bruno.cardoso at gmail.com Mon Jul 6 16:16:28 2009 From: bruno.cardoso at gmail.com (Bruno Cardoso Lopes) Date: Mon, 6 Jul 2009 18:16:28 -0300 Subject: [llvm-commits] [llvm] r74814 - in /llvm/trunk: include/llvm/CodeGen/ObjectCodeEmitter.h lib/CodeGen/ObjectCodeEmitter.cpp In-Reply-To: <7669CA9A7D814D5DBD8507485499BCD5@HPLAPTOP> References: <200907060516.n665Gekx026755@zion.cs.uiuc.edu> <7669CA9A7D814D5DBD8507485499BCD5@HPLAPTOP> Message-ID: <275e64e40907061416q7d1bfdd8g7f8d781104b0d462@mail.gmail.com> On Mon, Jul 6, 2009 at 10:55 AM, Aaron Gray wrote: > The ObjectCodeEmitter was ment to be inline code to be used by the > *CodeEmitter classes to end up with super fast code generation. Putting them > as noninline classes is a bad idea. Basically this is why I/we parameterized > the *CodeEmitter Classes in the first place. I had problems with this in the original patch, could you send a new patch with this modifications? Thanks > > Aaron > >> Author: bruno >> Date: Mon Jul ?6 00:16:40 2009 >> New Revision: 74814 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=74814&view=rev >> Log: >> Just forgot to include the two new files >> >> Added: >> ? ?llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h >> ? ?llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp >> >> Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h >> URL: >> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto >> >> ============================================================================== >> --- llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h (added) >> +++ llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h Mon Jul ?6 >> 00:16:40 2009 >> @@ -0,0 +1,171 @@ >> +//===-- llvm/CodeGen/ObjectCodeEmitter.h - Object Code Emitter -*- >> C++ -*-===// >> +// >> +// ? ? ? ? ? ? ? ? ? ? The LLVM Compiler Infrastructure >> +// >> +// This file is distributed under the University of Illinois Open Source >> +// License. See LICENSE.TXT for details. >> +// >> +//===----------------------------------------------------------------------===// >> +// >> +// ?Generalized Object Code Emitter, works with ObjectModule and >> BinaryObject. >> +// >> +//===----------------------------------------------------------------------===// >> + >> +#ifndef LLVM_CODEGEN_OBJECTCODEEMITTER_H >> +#define LLVM_CODEGEN_OBJECTCODEEMITTER_H >> + >> +#include "llvm/CodeGen/MachineCodeEmitter.h" >> + >> +namespace llvm { >> + >> +class BinaryObject; >> +class MachineBasicBlock; >> +class MachineCodeEmitter; >> +class MachineFunction; >> +class MachineConstantPool; >> +class MachineJumpTableInfo; >> +class MachineModuleInfo; >> + >> +class ObjectCodeEmitter : public MachineCodeEmitter { >> +protected: >> + >> + ?/// Binary Object (Section or Segment) we are emitting to. >> + ?BinaryObject *BO; >> + >> + ?/// MBBLocations - This vector is a mapping from MBB ID's to their >> address. >> + ?/// It is filled in by the StartMachineBasicBlock callback and queried >> by >> + ?/// the getMachineBasicBlockAddress callback. >> + ?std::vector MBBLocations; >> + >> + ?/// LabelLocations - This vector is a mapping from Label ID's to their >> + ?/// address. >> + ?std::vector LabelLocations; >> + >> + ?/// CPLocations - This is a map of constant pool indices to offsets >> from the >> + ?/// start of the section for that constant pool index. >> + ?std::vector CPLocations; >> + >> + ?/// CPSections - This is a map of constant pool indices to the Section >> + ?/// containing the constant pool entry for that index. >> + ?std::vector CPSections; >> + >> + ?/// JTLocations - This is a map of jump table indices to offsets from >> the >> + ?/// start of the section for that jump table index. >> + ?std::vector JTLocations; >> + >> +public: >> + ?ObjectCodeEmitter(); >> + ?ObjectCodeEmitter(BinaryObject *bo); >> + ?virtual ~ObjectCodeEmitter(); >> + >> + ?/// setBinaryObject - set the BinaryObject we are writting to >> + ?void setBinaryObject(BinaryObject *bo); >> + >> + ?/// emitByte - This callback is invoked when a byte needs to be >> + ?/// written to the data stream, without buffer overflow testing. >> + ?void emitByte(uint8_t B); >> + >> + ?/// emitWordLE - This callback is invoked when a 32-bit word needs to >> be >> + ?/// written to the data stream in little-endian format. >> + ?void emitWordLE(uint32_t W); >> + >> + ?/// emitWordBE - This callback is invoked when a 32-bit word needs to >> be >> + ?/// written to the data stream in big-endian format. >> + ?void emitWordBE(uint32_t W); >> + >> + ?/// emitDWordLE - This callback is invoked when a 64-bit word needs to >> be >> + ?/// written to the data stream in little-endian format. >> + ?void emitDWordLE(uint64_t W); >> + >> + ?/// emitDWordBE - This callback is invoked when a 64-bit word needs to >> be >> + ?/// written to the data stream in big-endian format. >> + ?void emitDWordBE(uint64_t W); >> + >> + ?/// emitAlignment - Move the CurBufferPtr pointer up the the specified >> + ?/// alignment (saturated to BufferEnd of course). >> + ?void emitAlignment(unsigned Alignment = 0, uint8_t fill = 0); >> + >> + ?/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to >> be >> + ?/// written to the data stream. >> + ?void emitULEB128Bytes(uint64_t Value); >> + >> + ?/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to >> be >> + ?/// written to the data stream. >> + ?void emitSLEB128Bytes(uint64_t Value); >> + >> + ?/// emitString - This callback is invoked when a String needs to be >> + ?/// written to the data stream. >> + ?void emitString(const std::string &String); >> + >> + ?/// getCurrentPCValue - This returns the address that the next emitted >> byte >> + ?/// will be output to. >> + ?uintptr_t getCurrentPCValue() const; >> + >> + ?/// getCurrentPCOffset - Return the offset from the start of the >> emitted >> + ?/// buffer that we are currently writing to. >> + ?uintptr_t getCurrentPCOffset() const; >> + >> + ?/// addRelocation - Whenever a relocatable address is needed, it should >> be >> + ?/// noted with this interface. >> + ?void addRelocation(const MachineRelocation& relocation); >> + >> + ?/// startFunction - This callback is invoked when the specified >> function is >> + ?/// about to be code generated. ?This initializes the >> BufferBegin/End/Ptr >> + ?/// fields. >> + ?virtual void startFunction(MachineFunction &F) = 0; >> + >> + ?/// finishFunction - This callback is invoked when the specified >> function has >> + ?/// finished code generation. ?If a buffer overflow has occurred, this >> method >> + ?/// returns true (the callee is required to try again), otherwise it >> returns >> + ?/// false. >> + ?virtual bool finishFunction(MachineFunction &F) = 0; >> + >> + ?/// StartMachineBasicBlock - This should be called by the target when a >> new >> + ?/// basic block is about to be emitted. ?This way the MCE knows where >> the >> + ?/// start of the block is, and can implement >> getMachineBasicBlockAddress. >> + ?virtual void StartMachineBasicBlock(MachineBasicBlock *MBB); >> + >> + ?/// getMachineBasicBlockAddress - Return the address of the specified >> + ?/// MachineBasicBlock, only usable after the label for the MBB has been >> + ?/// emitted. >> + ?virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) >> const; >> + >> + ?/// emitLabel - Emits a label >> + ?virtual void emitLabel(uint64_t LabelID) = 0; >> + >> + ?/// getLabelAddress - Return the address of the specified LabelID, only >> usable >> + ?/// after the LabelID has been emitted. >> + ?virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0; >> + >> + ?/// emitJumpTables - Emit all the jump tables for a given jump table >> info >> + ?/// record to the appropriate section. >> + ?virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0; >> + >> + ?/// getJumpTableEntryAddress - Return the address of the jump table >> with index >> + ?/// 'Index' in the function that last called initJumpTableInfo. >> + ?virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const; >> + >> + ?/// emitConstantPool - For each constant pool entry, figure out which >> section >> + ?/// the constant should live in, allocate space for it, and emit it to >> the >> + ?/// Section data buffer. >> + ?virtual void emitConstantPool(MachineConstantPool *MCP) = 0; >> + >> + ?/// getConstantPoolEntryAddress - Return the address of the 'Index' >> entry in >> + ?/// the constant pool that was last emitted with the emitConstantPool >> method. >> + ?virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const; >> + >> + ?/// getConstantPoolEntrySection - Return the section of the 'Index' >> entry in >> + ?/// the constant pool that was last emitted with the emitConstantPool >> method. >> + ?virtual uintptr_t getConstantPoolEntrySection(unsigned Index) const; >> + >> + ?/// Specifies the MachineModuleInfo object. This is used for exception >> handling >> + ?/// purposes. >> + ?virtual void setModuleInfo(MachineModuleInfo* Info) = 0; >> + ?// to be implemented or depreciated with MachineModuleInfo >> + >> +}; // end class ObjectCodeEmitter >> + >> +} // end namespace llvm >> + >> +#endif >> + >> >> Added: llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto >> >> ============================================================================== >> --- llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp (added) >> +++ llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Mon Jul ?6 00:16:40 2009 >> @@ -0,0 +1,142 @@ >> +//===-- llvm/CodeGen/ObjectCodeEmitter.cpp -------------------- -*- >> C++ -*-===// >> +// >> +// ? ? ? ? ? ? ? ? ? ? The LLVM Compiler Infrastructure >> +// >> +// This file is distributed under the University of Illinois Open Source >> +// License. See LICENSE.TXT for details. >> +// >> +//===----------------------------------------------------------------------===// >> + >> +#include "llvm/CodeGen/BinaryObject.h" >> +#include "llvm/CodeGen/MachineBasicBlock.h" >> +#include "llvm/CodeGen/MachineRelocation.h" >> +#include "llvm/CodeGen/ObjectCodeEmitter.h" >> + >> +//===----------------------------------------------------------------------===// >> +// ? ? ? ? ? ? ? ? ? ? ? ObjectCodeEmitter Implementation >> +//===----------------------------------------------------------------------===// >> + >> +namespace llvm { >> + >> +ObjectCodeEmitter::ObjectCodeEmitter() : BO(0) {} >> +ObjectCodeEmitter::ObjectCodeEmitter(BinaryObject *bo) : BO(bo) {} >> +ObjectCodeEmitter::~ObjectCodeEmitter() {} >> + >> +/// setBinaryObject - set the BinaryObject we are writting to >> +void ObjectCodeEmitter::setBinaryObject(BinaryObject *bo) { BO = bo; } >> + >> +/// emitByte - This callback is invoked when a byte needs to be >> +/// written to the data stream, without buffer overflow testing. >> +void ObjectCodeEmitter::emitByte(uint8_t B) { >> + ?BO->emitByte(B); >> +} >> + >> +/// emitWordLE - This callback is invoked when a 32-bit word needs to be >> +/// written to the data stream in little-endian format. >> +void ObjectCodeEmitter::emitWordLE(uint32_t W) { >> + ?BO->emitWordLE(W); >> +} >> + >> +/// emitWordBE - This callback is invoked when a 32-bit word needs to be >> +/// written to the data stream in big-endian format. >> +void ObjectCodeEmitter::emitWordBE(uint32_t W) { >> + ?BO->emitWordBE(W); >> +} >> + >> +/// emitDWordLE - This callback is invoked when a 64-bit word needs to be >> +/// written to the data stream in little-endian format. >> +void ObjectCodeEmitter::emitDWordLE(uint64_t W) { >> + ?BO->emitDWordLE(W); >> +} >> + >> +/// emitDWordBE - This callback is invoked when a 64-bit word needs to be >> +/// written to the data stream in big-endian format. >> +void ObjectCodeEmitter::emitDWordBE(uint64_t W) { >> + ?BO->emitDWordBE(W); >> +} >> + >> +/// emitAlignment - Move the CurBufferPtr pointer up the the specified >> +/// alignment (saturated to BufferEnd of course). >> +void ObjectCodeEmitter::emitAlignment(unsigned Alignment /* 0 */, >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?uint8_t fill /* 0 */) { >> + ?BO->emitAlignment(Alignment, fill); >> +} >> + >> +/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to >> be >> +/// written to the data stream. >> +void ObjectCodeEmitter::emitULEB128Bytes(uint64_t Value) { >> + ?BO->emitULEB128Bytes(Value); >> +} >> + >> +/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to >> be >> +/// written to the data stream. >> +void ObjectCodeEmitter::emitSLEB128Bytes(uint64_t Value) { >> + ?BO->emitSLEB128Bytes(Value); >> +} >> + >> +/// emitString - This callback is invoked when a String needs to be >> +/// written to the data stream. >> +void ObjectCodeEmitter::emitString(const std::string &String) { >> + ?BO->emitString(String); >> +} >> + >> +/// getCurrentPCValue - This returns the address that the next emitted >> byte >> +/// will be output to. >> +uintptr_t ObjectCodeEmitter::getCurrentPCValue() const { >> + ?return BO->getCurrentPCOffset(); >> +} >> + >> +/// getCurrentPCOffset - Return the offset from the start of the emitted >> +/// buffer that we are currently writing to. >> +uintptr_t ObjectCodeEmitter::getCurrentPCOffset() const { >> + ?return BO->getCurrentPCOffset(); >> +} >> + >> +/// addRelocation - Whenever a relocatable address is needed, it should >> be >> +/// noted with this interface. >> +void ObjectCodeEmitter::addRelocation(const MachineRelocation& >> relocation) { >> + ?BO->addRelocation(relocation); >> +} >> + >> +/// StartMachineBasicBlock - This should be called by the target when a >> new >> +/// basic block is about to be emitted. ?This way the MCE knows where the >> +/// start of the block is, and can implement getMachineBasicBlockAddress. >> +void ObjectCodeEmitter::StartMachineBasicBlock(MachineBasicBlock *MBB) { >> + ?if (MBBLocations.size() <= (unsigned)MBB->getNumber()) >> + ? ?MBBLocations.resize((MBB->getNumber()+1)*2); >> + ?MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); >> +} >> + >> +/// getMachineBasicBlockAddress - Return the address of the specified >> +/// MachineBasicBlock, only usable after the label for the MBB has been >> +/// emitted. >> +uintptr_t >> +ObjectCodeEmitter::getMachineBasicBlockAddress(MachineBasicBlock *MBB) >> const { >> + ?assert(MBBLocations.size() > (unsigned)MBB->getNumber() && >> + ? ? ? ? MBBLocations[MBB->getNumber()] && "MBB not emitted!"); >> + ?return MBBLocations[MBB->getNumber()]; >> +} >> + >> +/// getJumpTableEntryAddress - Return the address of the jump table with >> index >> +/// 'Index' in the function that last called initJumpTableInfo. >> +uintptr_t ObjectCodeEmitter::getJumpTableEntryAddress(unsigned Index) >> const { >> + ?assert(JTLocations.size() > Index && "JT not emitted!"); >> + ?return JTLocations[Index]; >> +} >> + >> +/// getConstantPoolEntryAddress - Return the address of the 'Index' entry >> in >> +/// the constant pool that was last emitted with the emitConstantPool >> method. >> +uintptr_t ObjectCodeEmitter::getConstantPoolEntryAddress(unsigned Index) >> const { >> + ?assert(CPLocations.size() > Index && "CP not emitted!"); >> + ?return CPLocations[Index]; >> +} >> + >> +/// getConstantPoolEntrySection - Return the section of the 'Index' entry >> in >> +/// the constant pool that was last emitted with the emitConstantPool >> method. >> +uintptr_t ObjectCodeEmitter::getConstantPoolEntrySection(unsigned Index) >> const { >> + ?assert(CPSections.size() > Index && "CP not emitted!"); >> + ?return CPSections[Index]; >> +} >> + >> +} // end namespace llvm >> + >> >> >> _______________________________________________ >> llvm-commits mailing list >> llvm-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > -- Bruno Cardoso Lopes http://www.brunocardoso.cc From xerxes at zafena.se Mon Jul 6 16:18:47 2009 From: xerxes at zafena.se (=?ISO-8859-1?Q?Xerxes_R=E5nby?=) Date: Mon, 06 Jul 2009 23:18:47 +0200 Subject: [llvm-commits] [llvm] r74835 *AND* r74846 - /llvm/trunk/lib/System/Threading.cpp In-Reply-To: <200907061725.n66HP8CM029643@zion.cs.uiuc.edu> References: <200907061725.n66HP8CM029643@zion.cs.uiuc.edu> Message-ID: <4A526A37.8090901@zafena.se> Thank you Chris and Owen for both applying my patch... the funny thing are that Chris have applied a "new variant" of the patch that added the config.h at the bottom while Owen applied the patch as is and thus added the config.h at the top. Basically now we have one config.h extra in Threading.cpp Chris would you mind if we back out your reverse-alphabetic version with the removed newline out? Cheers Xerxes Den 2009-07-06 19:25, Chris Lattner skrev: > Author: lattner > Date: Mon Jul 6 12:24:48 2009 > New Revision: 74835 > > URL: http://llvm.org/viewvc/llvm-project?rev=74835&view=rev > Log: > improve portability to windows, patch by Xerces Ranby! > > Modified: > llvm/trunk/lib/System/Threading.cpp > > Modified: llvm/trunk/lib/System/Threading.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Threading.cpp?rev=74835&r1=74834&r2=74835&view=diff > > ============================================================================== > --- llvm/trunk/lib/System/Threading.cpp (original) > +++ llvm/trunk/lib/System/Threading.cpp Mon Jul 6 12:24:48 2009 > @@ -14,8 +14,8 @@ > #include "llvm/System/Threading.h" > #include "llvm/System/Atomic.h" > #include "llvm/System/Mutex.h" > +#include "llvm/Config/config.h" > #include > - > using namespace llvm; > > static bool multithreaded_mode = false; > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > Den 2009-07-06 20:50, Owen Anderson skrev: > Author: resistor > Date: Mon Jul 6 13:50:47 2009 > New Revision: 74846 > > URL: http://llvm.org/viewvc/llvm-project?rev=74846&view=rev > Log: > We need to include config.h to get the proper setting to LLVM_MULTITHREADED. > > Patch by Xerxes Ranby. > > Modified: > llvm/trunk/lib/System/Threading.cpp > > Modified: llvm/trunk/lib/System/Threading.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Threading.cpp?rev=74846&r1=74845&r2=74846&view=diff > > ============================================================================== > --- llvm/trunk/lib/System/Threading.cpp (original) > +++ llvm/trunk/lib/System/Threading.cpp Mon Jul 6 13:50:47 2009 > @@ -11,6 +11,7 @@ > // > //===----------------------------------------------------------------------===// > > +#include "llvm/Config/config.h" > #include "llvm/System/Threading.h" > #include "llvm/System/Atomic.h" > #include "llvm/System/Mutex.h" > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > From resistor at mac.com Mon Jul 6 16:24:39 2009 From: resistor at mac.com (Owen Anderson) Date: Mon, 06 Jul 2009 21:24:39 -0000 Subject: [llvm-commits] [llvm] r74854 - /llvm/trunk/lib/System/Threading.cpp Message-ID: <200907062124.n66LOdmc004752@zion.cs.uiuc.edu> Author: resistor Date: Mon Jul 6 16:24:37 2009 New Revision: 74854 URL: http://llvm.org/viewvc/llvm-project?rev=74854&view=rev Log: No need to double-include config.h Modified: llvm/trunk/lib/System/Threading.cpp Modified: llvm/trunk/lib/System/Threading.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Threading.cpp?rev=74854&r1=74853&r2=74854&view=diff ============================================================================== --- llvm/trunk/lib/System/Threading.cpp (original) +++ llvm/trunk/lib/System/Threading.cpp Mon Jul 6 16:24:37 2009 @@ -11,12 +11,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Config/config.h" #include "llvm/System/Threading.h" #include "llvm/System/Atomic.h" #include "llvm/System/Mutex.h" #include "llvm/Config/config.h" #include + using namespace llvm; static bool multithreaded_mode = false; From isanbard at gmail.com Mon Jul 6 16:33:09 2009 From: isanbard at gmail.com (Bill Wendling) Date: Mon, 06 Jul 2009 21:33:09 -0000 Subject: [llvm-commits] [llvm] r74855 - /llvm/tags/Apple/llvmCore-2116/ Message-ID: <200907062133.n66LX9O0005014@zion.cs.uiuc.edu> Author: void Date: Mon Jul 6 16:33:09 2009 New Revision: 74855 URL: http://llvm.org/viewvc/llvm-project?rev=74855&view=rev Log: Creating llvmCore-2116 branch Added: llvm/tags/Apple/llvmCore-2116/ - copied from r74854, llvm/trunk/ From isanbard at gmail.com Mon Jul 6 16:33:17 2009 From: isanbard at gmail.com (Bill Wendling) Date: Mon, 06 Jul 2009 21:33:17 -0000 Subject: [llvm-commits] [llvm-gcc-4.2] r74856 - /llvm-gcc-4.2/tags/Apple/llvmgcc42-2116/ Message-ID: <200907062133.n66LXH0L005033@zion.cs.uiuc.edu> Author: void Date: Mon Jul 6 16:33:17 2009 New Revision: 74856 URL: http://llvm.org/viewvc/llvm-project?rev=74856&view=rev Log: Creating llvmgcc42-2116 branch Added: llvm-gcc-4.2/tags/Apple/llvmgcc42-2116/ - copied from r74855, llvm-gcc-4.2/trunk/ From evan.cheng at apple.com Mon Jul 6 16:34:05 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 06 Jul 2009 21:34:05 -0000 Subject: [llvm-commits] [llvm] r74857 - in /llvm/trunk: lib/CodeGen/LiveVariables.cpp test/CodeGen/X86/2009-07-06-TwoAddrAssert.ll Message-ID: <200907062134.n66LY5e8005067@zion.cs.uiuc.edu> Author: evancheng Date: Mon Jul 6 16:34:05 2009 New Revision: 74857 URL: http://llvm.org/viewvc/llvm-project?rev=74857&view=rev Log: Avoid adding a duplicate def. This fixes PR4478. Added: llvm/trunk/test/CodeGen/X86/2009-07-06-TwoAddrAssert.ll Modified: llvm/trunk/lib/CodeGen/LiveVariables.cpp Modified: llvm/trunk/lib/CodeGen/LiveVariables.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveVariables.cpp?rev=74857&r1=74856&r2=74857&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/LiveVariables.cpp (original) +++ llvm/trunk/lib/CodeGen/LiveVariables.cpp Mon Jul 6 16:34:05 2009 @@ -369,8 +369,17 @@ for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); unsigned SubReg = *SubRegs; ++SubRegs) { if (PartUses.count(SubReg)) { - PhysRegDef[Reg]->addOperand(MachineOperand::CreateReg(SubReg, - true, true)); + bool NeedDef = true; + if (PhysRegDef[Reg] == PhysRegDef[SubReg]) { + MachineOperand *MO = PhysRegDef[Reg]->findRegisterDefOperand(SubReg); + if (MO) { + NeedDef = false; + assert(!MO->isDead()); + } + } + if (NeedDef) + PhysRegDef[Reg]->addOperand(MachineOperand::CreateReg(SubReg, + true, true)); LastRefOrPartRef->addRegisterKilled(SubReg, TRI, true); for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS) PartUses.erase(*SS); Added: llvm/trunk/test/CodeGen/X86/2009-07-06-TwoAddrAssert.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2009-07-06-TwoAddrAssert.ll?rev=74857&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/X86/2009-07-06-TwoAddrAssert.ll (added) +++ llvm/trunk/test/CodeGen/X86/2009-07-06-TwoAddrAssert.ll Mon Jul 6 16:34:05 2009 @@ -0,0 +1,137 @@ +; RUN: llvm-as < %s | llc -march=x86 -mtriple=x86_64-unknown-freebsd7.2 +; PR4478 + + %struct.sockaddr = type <{ i8, i8, [14 x i8] }> + +define i32 @main(i32 %argc, i8** %argv) nounwind { +entry: + br label %while.cond + +while.cond: ; preds = %sw.bb6, %entry + switch i32 undef, label %sw.default [ + i32 -1, label %while.end + i32 119, label %sw.bb6 + ] + +sw.bb6: ; preds = %while.cond + br i1 undef, label %if.then, label %while.cond + +if.then: ; preds = %sw.bb6 + ret i32 1 + +sw.default: ; preds = %while.cond + ret i32 1 + +while.end: ; preds = %while.cond + br i1 undef, label %if.then15, label %if.end16 + +if.then15: ; preds = %while.end + ret i32 1 + +if.end16: ; preds = %while.end + br i1 undef, label %lor.lhs.false, label %if.then21 + +lor.lhs.false: ; preds = %if.end16 + br i1 undef, label %if.end22, label %if.then21 + +if.then21: ; preds = %lor.lhs.false, %if.end16 + ret i32 1 + +if.end22: ; preds = %lor.lhs.false + br i1 undef, label %lor.lhs.false27, label %if.then51 + +lor.lhs.false27: ; preds = %if.end22 + br i1 undef, label %lor.lhs.false39, label %if.then51 + +lor.lhs.false39: ; preds = %lor.lhs.false27 + br i1 undef, label %if.end52, label %if.then51 + +if.then51: ; preds = %lor.lhs.false39, %lor.lhs.false27, %if.end22 + ret i32 1 + +if.end52: ; preds = %lor.lhs.false39 + br i1 undef, label %if.then57, label %if.end58 + +if.then57: ; preds = %if.end52 + ret i32 1 + +if.end58: ; preds = %if.end52 + br i1 undef, label %if.then64, label %if.end65 + +if.then64: ; preds = %if.end58 + ret i32 1 + +if.end65: ; preds = %if.end58 + br i1 undef, label %if.then71, label %if.end72 + +if.then71: ; preds = %if.end65 + ret i32 1 + +if.end72: ; preds = %if.end65 + br i1 undef, label %if.then83, label %if.end84 + +if.then83: ; preds = %if.end72 + ret i32 1 + +if.end84: ; preds = %if.end72 + br i1 undef, label %if.then101, label %if.end102 + +if.then101: ; preds = %if.end84 + ret i32 1 + +if.end102: ; preds = %if.end84 + br i1 undef, label %if.then113, label %if.end114 + +if.then113: ; preds = %if.end102 + ret i32 1 + +if.end114: ; preds = %if.end102 + br i1 undef, label %if.then209, label %if.end210 + +if.then209: ; preds = %if.end114 + ret i32 1 + +if.end210: ; preds = %if.end114 + br i1 undef, label %if.then219, label %if.end220 + +if.then219: ; preds = %if.end210 + ret i32 1 + +if.end220: ; preds = %if.end210 + br i1 undef, label %if.end243, label %lor.lhs.false230 + +lor.lhs.false230: ; preds = %if.end220 + unreachable + +if.end243: ; preds = %if.end220 + br i1 undef, label %if.then249, label %if.end250 + +if.then249: ; preds = %if.end243 + ret i32 1 + +if.end250: ; preds = %if.end243 + br i1 undef, label %if.end261, label %if.then260 + +if.then260: ; preds = %if.end250 + ret i32 1 + +if.end261: ; preds = %if.end250 + br i1 undef, label %if.then270, label %if.end271 + +if.then270: ; preds = %if.end261 + ret i32 1 + +if.end271: ; preds = %if.end261 + %call.i = call i32 @arc4random() nounwind ; [#uses=1] + %rem.i = urem i32 %call.i, 16383 ; [#uses=1] + %rem1.i = trunc i32 %rem.i to i16 ; [#uses=1] + %conv2.i = or i16 %rem1.i, -16384 ; [#uses=1] + %0 = call i16 asm "xchgb ${0:h}, ${0:b}", "=Q,0,~{dirflag},~{fpsr},~{flags}"(i16 %conv2.i) nounwind ; [#uses=1] + store i16 %0, i16* undef + %call281 = call i32 @bind(i32 undef, %struct.sockaddr* undef, i32 16) nounwind ; [#uses=0] + unreachable +} + +declare i32 @bind(i32, %struct.sockaddr*, i32) + +declare i32 @arc4random() From evan.cheng at apple.com Mon Jul 6 16:47:45 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 6 Jul 2009 14:47:45 -0700 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction In-Reply-To: <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> Message-ID: We need to revisit the approach. Templatizing the CodeEmitter class is probably not the right way to go Sorry I didn't think hard about this when the patch landed back the end of May. Chris' recent "machine code" work is obsoleting at least object code emitter so I'll let him comment. Evan On Jul 6, 2009, at 12:53 PM, Bruno Cardoso Lopes wrote: > On Mon, Jul 6, 2009 at 4:11 PM, Evan Cheng > wrote: >> Sorry, I am missing some context. Why is each of the emitter a >> separate >> template instantiation in the first place? Why can't the code in > > This happens because ObjectCodeEmitter is a lot simpler than > JITCodeEmitter and > we don't need to deal with CurrBufferBegin, GVStub*, and so on. > >> X86CodeEmitter.cpp be shared across all 3? > > I agree with Evan, I don't see why this code shouldn't be shared, > besides that, putting > all that code in a header file doesn't seems like the right approach. > > -- > Bruno Cardoso Lopes > http://www.brunocardoso.cc From aaronngray.lists at googlemail.com Mon Jul 6 16:49:02 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 22:49:02 +0100 Subject: [llvm-commits] [llvm] r74814 - in /llvm/trunk: include/llvm/CodeGen/ObjectCodeEmitter.h lib/CodeGen/ObjectCodeEmitter.cpp In-Reply-To: <275e64e40907061416q7d1bfdd8g7f8d781104b0d462@mail.gmail.com> References: <200907060516.n665Gekx026755@zion.cs.uiuc.edu> <7669CA9A7D814D5DBD8507485499BCD5@HPLAPTOP> <275e64e40907061416q7d1bfdd8g7f8d781104b0d462@mail.gmail.com> Message-ID: <9719867c0907061449s146605cct18f07d4df91ec2e0@mail.gmail.com> 2009/7/6 Bruno Cardoso Lopes > On Mon, Jul 6, 2009 at 10:55 AM, Aaron > Gray wrote: > > The ObjectCodeEmitter was ment to be inline code to be used by the > > *CodeEmitter classes to end up with super fast code generation. Putting > them > > as noninline classes is a bad idea. Basically this is why I/we > parameterized > > the *CodeEmitter Classes in the first place. > > I had problems with this in the original patch, could you send a new > patch with this modifications? > Here we go. I only did the emit* methods. Aaron > Aaron > >> Author: bruno >> Date: Mon Jul 6 00:16:40 2009 >> New Revision: 74814 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=74814&view=rev >> Log: >> Just forgot to include the two new files >> >> Added: >> llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h >> llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp >> >> Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h >> URL: >> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto >> >> ============================================================================== >> --- llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h (added) >> +++ llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h Mon Jul 6 >> 00:16:40 2009 >> @@ -0,0 +1,171 @@ >> +//===-- llvm/CodeGen/ObjectCodeEmitter.h - Object Code Emitter -*- >> C++ -*-===// >> +// >> +// The LLVM Compiler Infrastructure >> +// >> +// This file is distributed under the University of Illinois Open Source >> +// License. See LICENSE.TXT for details. >> +// >> +//===----------------------------------------------------------------------===// >> +// >> +// Generalized Object Code Emitter, works with ObjectModule and >> BinaryObject. >> +// >> +//===----------------------------------------------------------------------===// >> + >> +#ifndef LLVM_CODEGEN_OBJECTCODEEMITTER_H >> +#define LLVM_CODEGEN_OBJECTCODEEMITTER_H >> + >> +#include "llvm/CodeGen/MachineCodeEmitter.h" >> + >> +namespace llvm { >> + >> +class BinaryObject; >> +class MachineBasicBlock; >> +class MachineCodeEmitter; >> +class MachineFunction; >> +class MachineConstantPool; >> +class MachineJumpTableInfo; >> +class MachineModuleInfo; >> + >> +class ObjectCodeEmitter : public MachineCodeEmitter { >> +protected: >> + >> + /// Binary Object (Section or Segment) we are emitting to. >> + BinaryObject *BO; >> + >> + /// MBBLocations - This vector is a mapping from MBB ID's to their >> address. >> + /// It is filled in by the StartMachineBasicBlock callback and queried >> by >> + /// the getMachineBasicBlockAddress callback. >> + std::vector MBBLocations; >> + >> + /// LabelLocations - This vector is a mapping from Label ID's to their >> + /// address. >> + std::vector LabelLocations; >> + >> + /// CPLocations - This is a map of constant pool indices to offsets >> from the >> + /// start of the section for that constant pool index. >> + std::vector CPLocations; >> + >> + /// CPSections - This is a map of constant pool indices to the Section >> + /// containing the constant pool entry for that index. >> + std::vector CPSections; >> + >> + /// JTLocations - This is a map of jump table indices to offsets from >> the >> + /// start of the section for that jump table index. >> + std::vector JTLocations; >> + >> +public: >> + ObjectCodeEmitter(); >> + ObjectCodeEmitter(BinaryObject *bo); >> + virtual ~ObjectCodeEmitter(); >> + >> + /// setBinaryObject - set the BinaryObject we are writting to >> + void setBinaryObject(BinaryObject *bo); >> + >> + /// emitByte - This callback is invoked when a byte needs to be >> + /// written to the data stream, without buffer overflow testing. >> + void emitByte(uint8_t B); >> + >> + /// emitWordLE - This callback is invoked when a 32-bit word needs to >> be >> + /// written to the data stream in little-endian format. >> + void emitWordLE(uint32_t W); >> + >> + /// emitWordBE - This callback is invoked when a 32-bit word needs to >> be >> + /// written to the data stream in big-endian format. >> + void emitWordBE(uint32_t W); >> + >> + /// emitDWordLE - This callback is invoked when a 64-bit word needs to >> be >> + /// written to the data stream in little-endian format. >> + void emitDWordLE(uint64_t W); >> + >> + /// emitDWordBE - This callback is invoked when a 64-bit word needs to >> be >> + /// written to the data stream in big-endian format. >> + void emitDWordBE(uint64_t W); >> + >> + /// emitAlignment - Move the CurBufferPtr pointer up the the specified >> + /// alignment (saturated to BufferEnd of course). >> + void emitAlignment(unsigned Alignment = 0, uint8_t fill = 0); >> + >> + /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to >> be >> + /// written to the data stream. >> + void emitULEB128Bytes(uint64_t Value); >> + >> + /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to >> be >> + /// written to the data stream. >> + void emitSLEB128Bytes(uint64_t Value); >> + >> + /// emitString - This callback is invoked when a String needs to be >> + /// written to the data stream. >> + void emitString(const std::string &String); >> + >> + /// getCurrentPCValue - This returns the address that the next emitted >> byte >> + /// will be output to. >> + uintptr_t getCurrentPCValue() const; >> + >> + /// getCurrentPCOffset - Return the offset from the start of the >> emitted >> + /// buffer that we are currently writing to. >> + uintptr_t getCurrentPCOffset() const; >> + >> + /// addRelocation - Whenever a relocatable address is needed, it should >> be >> + /// noted with this interface. >> + void addRelocation(const MachineRelocation& relocation); >> + >> + /// startFunction - This callback is invoked when the specified >> function is >> + /// about to be code generated. This initializes the >> BufferBegin/End/Ptr >> + /// fields. >> + virtual void startFunction(MachineFunction &F) = 0; >> + >> + /// finishFunction - This callback is invoked when the specified >> function has >> + /// finished code generation. If a buffer overflow has occurred, this >> method >> + /// returns true (the callee is required to try again), otherwise it >> returns >> + /// false. >> + virtual bool finishFunction(MachineFunction &F) = 0; >> + >> + /// StartMachineBasicBlock - This should be called by the target when a >> new >> + /// basic block is about to be emitted. This way the MCE knows where >> the >> + /// start of the block is, and can implement >> getMachineBasicBlockAddress. >> + virtual void StartMachineBasicBlock(MachineBasicBlock *MBB); >> + >> + /// getMachineBasicBlockAddress - Return the address of the specified >> + /// MachineBasicBlock, only usable after the label for the MBB has been >> + /// emitted. >> + virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) >> const; >> + >> + /// emitLabel - Emits a label >> + virtual void emitLabel(uint64_t LabelID) = 0; >> + >> + /// getLabelAddress - Return the address of the specified LabelID, only >> usable >> + /// after the LabelID has been emitted. >> + virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0; >> + >> + /// emitJumpTables - Emit all the jump tables for a given jump table >> info >> + /// record to the appropriate section. >> + virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0; >> + >> + /// getJumpTableEntryAddress - Return the address of the jump table >> with index >> + /// 'Index' in the function that last called initJumpTableInfo. >> + virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const; >> + >> + /// emitConstantPool - For each constant pool entry, figure out which >> section >> + /// the constant should live in, allocate space for it, and emit it to >> the >> + /// Section data buffer. >> + virtual void emitConstantPool(MachineConstantPool *MCP) = 0; >> + >> + /// getConstantPoolEntryAddress - Return the address of the 'Index' >> entry in >> + /// the constant pool that was last emitted with the emitConstantPool >> method. >> + virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const; >> + >> + /// getConstantPoolEntrySection - Return the section of the 'Index' >> entry in >> + /// the constant pool that was last emitted with the emitConstantPool >> method. >> + virtual uintptr_t getConstantPoolEntrySection(unsigned Index) const; >> + >> + /// Specifies the MachineModuleInfo object. This is used for exception >> handling >> + /// purposes. >> + virtual void setModuleInfo(MachineModuleInfo* Info) = 0; >> + // to be implemented or depreciated with MachineModuleInfo >> + >> +}; // end class ObjectCodeEmitter >> + >> +} // end namespace llvm >> + >> +#endif >> + >> >> Added: llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto >> >> ============================================================================== >> --- llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp (added) >> +++ llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Mon Jul 6 00:16:40 2009 >> @@ -0,0 +1,142 @@ >> +//===-- llvm/CodeGen/ObjectCodeEmitter.cpp -------------------- -*- >> C++ -*-===// >> +// >> +// The LLVM Compiler Infrastructure >> +// >> +// This file is distributed under the University of Illinois Open Source >> +// License. See LICENSE.TXT for details. >> +// >> +//===----------------------------------------------------------------------===// >> + >> +#include "llvm/CodeGen/BinaryObject.h" >> +#include "llvm/CodeGen/MachineBasicBlock.h" >> +#include "llvm/CodeGen/MachineRelocation.h" >> +#include "llvm/CodeGen/ObjectCodeEmitter.h" >> + >> +//===----------------------------------------------------------------------===// >> +// ObjectCodeEmitter Implementation >> +//===----------------------------------------------------------------------===// >> + >> +namespace llvm { >> + >> +ObjectCodeEmitter::ObjectCodeEmitter() : BO(0) {} >> +ObjectCodeEmitter::ObjectCodeEmitter(BinaryObject *bo) : BO(bo) {} >> +ObjectCodeEmitter::~ObjectCodeEmitter() {} >> + >> +/// setBinaryObject - set the BinaryObject we are writting to >> +void ObjectCodeEmitter::setBinaryObject(BinaryObject *bo) { BO = bo; } >> + >> +/// emitByte - This callback is invoked when a byte needs to be >> +/// written to the data stream, without buffer overflow testing. >> +void ObjectCodeEmitter::emitByte(uint8_t B) { >> + BO->emitByte(B); >> +} >> + >> +/// emitWordLE - This callback is invoked when a 32-bit word needs to be >> +/// written to the data stream in little-endian format. >> +void ObjectCodeEmitter::emitWordLE(uint32_t W) { >> + BO->emitWordLE(W); >> +} >> + >> +/// emitWordBE - This callback is invoked when a 32-bit word needs to be >> +/// written to the data stream in big-endian format. >> +void ObjectCodeEmitter::emitWordBE(uint32_t W) { >> + BO->emitWordBE(W); >> +} >> + >> +/// emitDWordLE - This callback is invoked when a 64-bit word needs to be >> +/// written to the data stream in little-endian format. >> +void ObjectCodeEmitter::emitDWordLE(uint64_t W) { >> + BO->emitDWordLE(W); >> +} >> + >> +/// emitDWordBE - This callback is invoked when a 64-bit word needs to be >> +/// written to the data stream in big-endian format. >> +void ObjectCodeEmitter::emitDWordBE(uint64_t W) { >> + BO->emitDWordBE(W); >> +} >> + >> +/// emitAlignment - Move the CurBufferPtr pointer up the the specified >> +/// alignment (saturated to BufferEnd of course). >> +void ObjectCodeEmitter::emitAlignment(unsigned Alignment /* 0 */, >> + uint8_t fill /* 0 */) { >> + BO->emitAlignment(Alignment, fill); >> +} >> + >> +/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to >> be >> +/// written to the data stream. >> +void ObjectCodeEmitter::emitULEB128Bytes(uint64_t Value) { >> + BO->emitULEB128Bytes(Value); >> +} >> + >> +/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to >> be >> +/// written to the data stream. >> +void ObjectCodeEmitter::emitSLEB128Bytes(uint64_t Value) { >> + BO->emitSLEB128Bytes(Value); >> +} >> + >> +/// emitString - This callback is invoked when a String needs to be >> +/// written to the data stream. >> +void ObjectCodeEmitter::emitString(const std::string &String) { >> + BO->emitString(String); >> +} >> + >> +/// getCurrentPCValue - This returns the address that the next emitted >> byte >> +/// will be output to. >> +uintptr_t ObjectCodeEmitter::getCurrentPCValue() const { >> + return BO->getCurrentPCOffset(); >> +} >> + >> +/// getCurrentPCOffset - Return the offset from the start of the emitted >> +/// buffer that we are currently writing to. >> +uintptr_t ObjectCodeEmitter::getCurrentPCOffset() const { >> + return BO->getCurrentPCOffset(); >> +} >> + >> +/// addRelocation - Whenever a relocatable address is needed, it should >> be >> +/// noted with this interface. >> +void ObjectCodeEmitter::addRelocation(const MachineRelocation& >> relocation) { >> + BO->addRelocation(relocation); >> +} >> + >> +/// StartMachineBasicBlock - This should be called by the target when a >> new >> +/// basic block is about to be emitted. This way the MCE knows where the >> +/// start of the block is, and can implement getMachineBasicBlockAddress. >> +void ObjectCodeEmitter::StartMachineBasicBlock(MachineBasicBlock *MBB) { >> + if (MBBLocations.size() <= (unsigned)MBB->getNumber()) >> + MBBLocations.resize((MBB->getNumber()+1)*2); >> + MBBLocations[MBB->getNumber()] = getCurrentPCOffset(); >> +} >> + >> +/// getMachineBasicBlockAddress - Return the address of the specified >> +/// MachineBasicBlock, only usable after the label for the MBB has been >> +/// emitted. >> +uintptr_t >> +ObjectCodeEmitter::getMachineBasicBlockAddress(MachineBasicBlock *MBB) >> const { >> + assert(MBBLocations.size() > (unsigned)MBB->getNumber() && >> + MBBLocations[MBB->getNumber()] && "MBB not emitted!"); >> + return MBBLocations[MBB->getNumber()]; >> +} >> + >> +/// getJumpTableEntryAddress - Return the address of the jump table with >> index >> +/// 'Index' in the function that last called initJumpTableInfo. >> +uintptr_t ObjectCodeEmitter::getJumpTableEntryAddress(unsigned Index) >> const { >> + assert(JTLocations.size() > Index && "JT not emitted!"); >> + return JTLocations[Index]; >> +} >> + >> +/// getConstantPoolEntryAddress - Return the address of the 'Index' entry >> in >> +/// the constant pool that was last emitted with the emitConstantPool >> method. >> +uintptr_t ObjectCodeEmitter::getConstantPoolEntryAddress(unsigned Index) >> const { >> + assert(CPLocations.size() > Index && "CP not emitted!"); >> + return CPLocations[Index]; >> +} >> + >> +/// getConstantPoolEntrySection - Return the section of the 'Index' entry >> in >> +/// the constant pool that was last emitted with the emitConstantPool >> method. >> +uintptr_t ObjectCodeEmitter::getConstantPoolEntrySection(unsigned Index) >> const { >> + assert(CPSections.size() > Index && "CP not emitted!"); >> + return CPSections[Index]; >> +} >> + >> +} // end namespace llvm >> + >> >> >> _______________________________________________ >> llvm-commits mailing list >> llvm-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > -- > Bruno Cardoso Lopes > http://www.brunocardoso.cc > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090706/cd83b121/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: ObjectCodeEmitter.patch Type: application/octet-stream Size: 3893 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090706/cd83b121/attachment.obj From aaronngray.lists at googlemail.com Mon Jul 6 16:56:28 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 22:56:28 +0100 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> Message-ID: <0772BCC55D8C48209386001E95355240@HPLAPTOP> > We need to revisit the approach. Templatizing the CodeEmitter class is > probably not the right way to go Sorry I didn't think hard about this > when the patch landed back the end of May. Chris' recent "machine code" > work is obsoleting at least object code emitter so I'll let him comment. I have put alot of work into getting this far. My designs are really dependant upon this approach and it yeilds the fastest code emission at base level. All my subsequet code is really based on this approach. Chris know about the DOE development, and the designs have been on the Wiki for some time. Templating and using inline methods allow the fastest approach to the actual code emission. Its nice clean and efficient code, that allows bespoke usage of the code generator backend, for the JIT and Object Module emission. Aaron > Evan > > On Jul 6, 2009, at 12:53 PM, Bruno Cardoso Lopes wrote: > >> On Mon, Jul 6, 2009 at 4:11 PM, Evan Cheng wrote: >>> Sorry, I am missing some context. Why is each of the emitter a separate >>> template instantiation in the first place? Why can't the code in >> >> This happens because ObjectCodeEmitter is a lot simpler than >> JITCodeEmitter and >> we don't need to deal with CurrBufferBegin, GVStub*, and so on. >> >>> X86CodeEmitter.cpp be shared across all 3? >> >> I agree with Evan, I don't see why this code shouldn't be shared, >> besides that, putting >> all that code in a header file doesn't seems like the right approach. >> >> -- >> Bruno Cardoso Lopes >> http://www.brunocardoso.cc > From clattner at apple.com Mon Jul 6 16:59:01 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 14:59:01 -0700 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction In-Reply-To: References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> Message-ID: <160305E8-E713-49FD-9905-1792F398B34C@apple.com> On Jul 6, 2009, at 1:17 PM, Aaron Gray wrote: >>> >>> X86CodeEmitter.cpp be shared across all 3? >> >> I agree with Evan, I don't see why this code shouldn't be shared, >> besides that, putting >> all that code in a header file doesn't seems like the right approach. > > Its the right approach. > > It allows us to have separate object modules thus reducing memory > overheads > for other projects that at least one other person has been asking for. > > Putting templated code in headers and instatiating separately > in .cpp files > is quite common practice once you use templating alot. Hi Guys, I'm behind on code review, but why is this stuff templated at all? This seems very wrong. We *really* care about the JIT code size footprint and templating the whole emitter is not a good way to help footprint :) -Chris From clattner at apple.com Mon Jul 6 17:00:26 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 15:00:26 -0700 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction In-Reply-To: <0772BCC55D8C48209386001E95355240@HPLAPTOP> References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> <0772BCC55D8C48209386001E95355240@HPLAPTOP> Message-ID: <2754CA63-0EF0-41B7-8217-F464354C6A87@apple.com> On Jul 6, 2009, at 2:56 PM, Aaron Gray wrote: >> We need to revisit the approach. Templatizing the CodeEmitter class >> is probably not the right way to go Sorry I didn't think hard about >> this when the patch landed back the end of May. Chris' recent >> "machine code" work is obsoleting at least object code emitter so >> I'll let him comment. > > I have put alot of work into getting this far. My designs are really > dependant upon this approach and it yeilds the fastest code emission > at base level. All my subsequet code is really based on this > approach. Chris know about the DOE development, and the designs have > been on the Wiki for some time. > > Templating and using inline methods allow the fastest approach to > the actual code emission. Its nice clean and efficient code, that > allows bespoke usage of the code generator backend, for the JIT and > Object Module emission. Hi Aaron, what part of your design talks about this? What problem is templating this all solving? -Chris From clattner at apple.com Mon Jul 6 17:01:19 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 15:01:19 -0700 Subject: [llvm-commits] [llvm] r74844 - in /llvm/trunk: include/llvm/Analysis/ include/llvm/Support/ lib/Analysis/ lib/Transforms/IPO/ lib/Transforms/Instrumentation/ lib/Transforms/Scalar/ lib/Transforms/Utils/ In-Reply-To: <200907061842.n66Igvqn032166@zion.cs.uiuc.edu> References: <200907061842.n66Igvqn032166@zion.cs.uiuc.edu> Message-ID: <47D9F5D9-7F5A-499A-B61F-1D0F87EB2EE5@apple.com> On Jul 6, 2009, at 11:42 AM, Owen Anderson wrote: > Author: resistor > Date: Mon Jul 6 13:42:36 2009 > New Revision: 74844 > > URL: http://llvm.org/viewvc/llvm-project?rev=74844&view=rev > Log: > Thread LLVMContext through the constant folding APIs, which touches > a lot of files. > -Constant *ConstantFoldInstruction(Instruction *I, const TargetData > *TD = 0); > +Constant *ConstantFoldInstruction(Instruction *I, LLVMContext* > Context, Owen, please use "LLVMContext *Context", not "LLVMContext* Context" as we previously discussed. -Chris From evan.cheng at apple.com Mon Jul 6 17:05:45 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 06 Jul 2009 22:05:45 -0000 Subject: [llvm-commits] [llvm] r74866 - in /llvm/trunk: lib/Target/ARM/ARMInstrInfo.td test/CodeGen/ARM/mls.ll Message-ID: <200907062205.n66M5jOF006218@zion.cs.uiuc.edu> Author: evancheng Date: Mon Jul 6 17:05:45 2009 New Revision: 74866 URL: http://llvm.org/viewvc/llvm-project?rev=74866&view=rev Log: Added ARM::mls for armv6t2. Added: llvm/trunk/test/CodeGen/ARM/mls.ll Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrInfo.td?rev=74866&r1=74865&r2=74866&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrInfo.td (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Mon Jul 6 17:05:45 2009 @@ -93,6 +93,7 @@ def HasV5T : Predicate<"Subtarget->hasV5TOps()">; def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">; def HasV6 : Predicate<"Subtarget->hasV6Ops()">; +def HasV6T2 : Predicate<"Subtarget->hasV6T2Ops()">; def HasV7 : Predicate<"Subtarget->hasV7Ops()">; def HasVFP2 : Predicate<"Subtarget->hasVFP2()">; def HasVFP3 : Predicate<"Subtarget->hasVFP3()">; @@ -1019,6 +1020,11 @@ "mla", " $dst, $a, $b, $c", [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>; +def MLS : AMul1I <0b0000011, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), + "mls", " $dst, $a, $b, $c", + [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>, + Requires<[IsARM, HasV6T2]>; + // Extra precision multiplies with low / high results let neverHasSideEffects = 1 in { let isCommutable = 1 in { Added: llvm/trunk/test/CodeGen/ARM/mls.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/mls.ll?rev=74866&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/ARM/mls.ll (added) +++ llvm/trunk/test/CodeGen/ARM/mls.ll Mon Jul 6 17:05:45 2009 @@ -0,0 +1,14 @@ +; RUN: llvm-as < %s | llc -march=arm -mattr=+v6t2 | grep {mls\\W*r\[0-9\],\\W*r\[0-9\],\\W*r\[0-9\],\\W*r\[0-9\]} | count 1 + +define i32 @f1(i32 %a, i32 %b, i32 %c) { + %tmp1 = mul i32 %a, %b + %tmp2 = sub i32 %c, %tmp1 + ret i32 %tmp2 +} + +; sub doesn't commute, so no mls for this one +define i32 @f2(i32 %a, i32 %b, i32 %c) { + %tmp1 = mul i32 %a, %b + %tmp2 = sub i32 %tmp1, %c + ret i32 %tmp2 +} From aaronngray.lists at googlemail.com Mon Jul 6 17:07:52 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Mon, 6 Jul 2009 23:07:52 +0100 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> <0772BCC55D8C48209386001E95355240@HPLAPTOP> <2754CA63-0EF0-41B7-8217-F464354C6A87@apple.com> Message-ID: <1DDE1F32B1CA4138A16F4434BF65EB36@HPLAPTOP> > On Jul 6, 2009, at 2:56 PM, Aaron Gray wrote: > >>> We need to revisit the approach. Templatizing the CodeEmitter class is >>> probably not the right way to go Sorry I didn't think hard about this >>> when the patch landed back the end of May. Chris' recent "machine >>> code" work is obsoleting at least object code emitter so I'll let him >>> comment. >> >> I have put alot of work into getting this far. My designs are really >> dependant upon this approach and it yeilds the fastest code emission at >> base level. All my subsequet code is really based on this approach. >> Chris know about the DOE development, and the designs have been on the >> Wiki for some time. >> >> Templating and using inline methods allow the fastest approach to the >> actual code emission. Its nice clean and efficient code, that allows >> bespoke usage of the code generator backend, for the JIT and Object >> Module emission. > > Hi Aaron, what part of your design talks about this? What problem is > templating this all solving? Templating allows us to have mutiple types of MachineCodeEmitters, the JITCodeEmitter, and the ObjectCodeEmitter, and any other kind of CodeEmitter we require in the future, e.g. Reid Kleckner' requirements to combine JIT and GDB. It allows these emiiters to be efficient and be inlined functions. If you study the code you will see what I mean. Aaron From clattner at apple.com Mon Jul 6 17:11:49 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 15:11:49 -0700 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction In-Reply-To: <1DDE1F32B1CA4138A16F4434BF65EB36@HPLAPTOP> References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> <0772BCC55D8C48209386001E95355240@HPLAPTOP> <2754CA63-0EF0-41B7-8217-F464354C6A87@apple.com> <1DDE1F32B1CA4138A16F4434BF65EB36@HPLAPTOP> Message-ID: <669DD8A2-E16D-4E48-9D13-3C2816E60722@apple.com> On Jul 6, 2009, at 3:07 PM, Aaron Gray wrote: >> >> Hi Aaron, what part of your design talks about this? What problem >> is templating this all solving? > > Templating allows us to have mutiple types of MachineCodeEmitters, > the JITCodeEmitter, and the ObjectCodeEmitter, and any other kind of > CodeEmitter we require in the future, e.g. Reid Kleckner' > requirements to combine JIT and GDB. It allows these emiiters to be > efficient and be inlined functions. If you study the code you will > see what I mean. There are many other ways to split this out. Emitting machine code should not need templates. This sounds like you have the wrong abstraction level here. Why can't virtual methods, containment, etc be used instead of templates? The X86 code that says "output an add as these 3 bytes" should be completely independent from the code that does something with the bytes. -Chris From evan.cheng at apple.com Mon Jul 6 17:23:47 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 06 Jul 2009 22:23:47 -0000 Subject: [llvm-commits] [llvm] r74868 - in /llvm/trunk: lib/Target/ARM/ARMCodeEmitter.cpp lib/Target/ARM/ARMInstrInfo.td lib/Target/ARM/ARMInstrThumb2.td test/CodeGen/ARM/bfc.ll Message-ID: <200907062223.n66MNlrU006805@zion.cs.uiuc.edu> Author: evancheng Date: Mon Jul 6 17:23:46 2009 New Revision: 74868 URL: http://llvm.org/viewvc/llvm-project?rev=74868&view=rev Log: Add bfc to armv6t2. Added: llvm/trunk/test/CodeGen/ARM/bfc.ll Modified: llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp llvm/trunk/lib/Target/ARM/ARMInstrInfo.td llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Modified: llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp?rev=74868&r1=74867&r2=74868&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp Mon Jul 6 17:23:46 2009 @@ -741,6 +741,11 @@ unsigned ImplicitRn) { const TargetInstrDesc &TID = MI.getDesc(); + if (TID.Opcode == ARM::BFC) { + cerr << "ERROR: ARMv6t2 JIT is not yet supported.\n"; + abort(); + } + // Part of binary is determined by TableGn. unsigned Binary = getBinaryCodeForInstr(MI); Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrInfo.td?rev=74868&r1=74867&r2=74868&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrInfo.td (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Mon Jul 6 17:23:46 2009 @@ -170,6 +170,27 @@ return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17; }]>; +/// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield +/// e.g., 0xf000ffff +def bf_inv_mask_imm : Operand, + PatLeaf<(imm), [{ + uint32_t v = (uint32_t)N->getZExtValue(); + if (v == 0xffffffff) + return 0; + // naive checker. should do better, but simple is best for now since it's + // more likely to be correct. + while (v & 1) v >>= 1; // shift off the leading 1's + if (v) + { + while (!(v & 1)) v >>=1; // shift off the mask + while (v & 1) v >>= 1; // shift off the trailing 1's + } + // if this is a mask for clearing a bitfield, what's left should be zero. + return (v == 0); +}] > { + let PrintMethod = "printBitfieldInvMaskImmOperand"; +} + class BinOpFrag : PatFrag<(ops node:$LHS, node:$RHS), res>; class UnOpFrag : PatFrag<(ops node:$Src), res>; @@ -993,6 +1014,15 @@ defm BIC : AsI1_bin_irs<0b1110, "bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>; +def BFC : I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm), + AddrMode1, Size4Bytes, IndexModeNone, DPFrm, + "bfc", " $dst, $imm", "$src = $dst", + [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>, + Requires<[IsARM, HasV6T2]> { + let Inst{27-21} = 0b0111110; + let Inst{6-0} = 0b0011111; +} + def MVNr : AsI1<0b1111, (outs GPR:$dst), (ins GPR:$src), DPFrm, "mvn", " $dst, $src", [(set GPR:$dst, (not GPR:$src))]>, UnaryDP; Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td?rev=74868&r1=74867&r2=74868&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Mon Jul 6 17:23:46 2009 @@ -89,27 +89,6 @@ return (uint32_t)N->getZExtValue() < 65536; }]>; -/// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield -/// e.g., 0xf000ffff -def bf_inv_mask_imm : Operand, - PatLeaf<(imm), [{ - uint32_t v = (uint32_t)N->getZExtValue(); - if (v == 0xffffffff) - return 0; - // naive checker. should do better, but simple is best for now since it's - // more likely to be correct. - while (v & 1) v >>= 1; // shift off the leading 1's - if (v) - { - while (!(v & 1)) v >>=1; // shift off the mask - while (v & 1) v >>= 1; // shift off the trailing 1's - } - // if this is a mask for clearing a bitfield, what's left should be zero. - return (v == 0); -}] > { - let PrintMethod = "printBitfieldInvMaskImmOperand"; -} - /// Split a 32-bit immediate into two 16 bit parts. def t2_lo16 : SDNodeXFormgetTargetConstant((uint32_t)N->getZExtValue() & 0xffff, @@ -820,29 +799,28 @@ defm t2BIC : T2I_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>; -def : T2Pat<(and GPR:$src, t2_so_imm_not:$imm), - (t2BICri GPR:$src, t2_so_imm_not:$imm)>; +let Constraints = "$src = $dst" in +def t2BFC : T2I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm), + "bfc", " $dst, $imm", + [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>; -defm t2ORN : T2I_bin_irs<"orn", BinOpFrag<(or node:$LHS, (not node:$RHS))>>; +// FIXME: A8.6.18 BFI - Bitfield insert (Encoding T1) -def : T2Pat<(or GPR:$src, t2_so_imm_not:$imm), - (t2ORNri GPR:$src, t2_so_imm_not:$imm)>; +defm t2ORN : T2I_bin_irs<"orn", BinOpFrag<(or node:$LHS, (not node:$RHS))>>; // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version let AddedComplexity = 1 in defm t2MVN : T2I_un_irs <"mvn", UnOpFrag<(not node:$Src)>, 1, 1>; -def : T2Pat<(t2_so_imm_not:$src), - (t2MVNi t2_so_imm_not:$src)>; -// A8.6.17 BFC - Bitfield clear -// FIXME: Also available in ARM mode. -let Constraints = "$src = $dst" in -def t2BFC : T2I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm), - "bfc", " $dst, $imm", - [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>; +def : T2Pat<(and GPR:$src, t2_so_imm_not:$imm), + (t2BICri GPR:$src, t2_so_imm_not:$imm)>; -// FIXME: A8.6.18 BFI - Bitfield insert (Encoding T1) +def : T2Pat<(or GPR:$src, t2_so_imm_not:$imm), + (t2ORNri GPR:$src, t2_so_imm_not:$imm)>; + +def : T2Pat<(t2_so_imm_not:$src), + (t2MVNi t2_so_imm_not:$src)>; //===----------------------------------------------------------------------===// // Multiply Instructions. Added: llvm/trunk/test/CodeGen/ARM/bfc.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/bfc.ll?rev=74868&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/ARM/bfc.ll (added) +++ llvm/trunk/test/CodeGen/ARM/bfc.ll Mon Jul 6 17:23:46 2009 @@ -0,0 +1,19 @@ +; RUN: llvm-as < %s | llc -march=arm -mattr=+v6t2 | grep "bfc " | count 3 + +; 4278190095 = 0xff00000f +define i32 @f1(i32 %a) { + %tmp = and i32 %a, 4278190095 + ret i32 %tmp +} + +; 4286578688 = 0xff800000 +define i32 @f2(i32 %a) { + %tmp = and i32 %a, 4286578688 + ret i32 %tmp +} + +; 4095 = 0x00000fff +define i32 @f3(i32 %a) { + %tmp = and i32 %a, 4095 + ret i32 %tmp +} From sabre at nondot.org Mon Jul 6 17:24:16 2009 From: sabre at nondot.org (Chris Lattner) Date: Mon, 06 Jul 2009 22:24:16 -0000 Subject: [llvm-commits] [compiler-rt] r74869 - /compiler-rt/trunk/make/filter-inputs Message-ID: <200907062224.n66MOGAo006830@zion.cs.uiuc.edu> Author: lattner Date: Mon Jul 6 17:24:16 2009 New Revision: 74869 URL: http://llvm.org/viewvc/llvm-project?rev=74869&view=rev Log: improve portability to platforms that don't put python in /usr/bin. Patch by Pawel Worach! Modified: compiler-rt/trunk/make/filter-inputs Modified: compiler-rt/trunk/make/filter-inputs URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/filter-inputs?rev=74869&r1=74868&r2=74869&view=diff ============================================================================== --- compiler-rt/trunk/make/filter-inputs (original) +++ compiler-rt/trunk/make/filter-inputs Mon Jul 6 17:24:16 2009 @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python #===- make/filter-inputs ---------------------------------------------------===# # From clattner at apple.com Mon Jul 6 17:24:38 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 15:24:38 -0700 Subject: [llvm-commits] [patch] Fix compiler_rt build system on FreeBSD In-Reply-To: References: Message-ID: On Jul 5, 2009, at 2:21 PM, Pawel Worach wrote: > Hi, > > Please use env(1) to call python, FreeBSD installs python in > /usr/local/bin and probably other systems behave the same way. Thanks, applied: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090706/080194.html -Chris > > Index: make/filter-inputs > =================================================================== > --- make/filter-inputs (revision 74795) > +++ make/filter-inputs (working copy) > @@ -1,4 +1,4 @@ > -#!/usr/bin/python > +#!/usr/bin/env python > > #===- make/filter-inputs > ---------------------------------------------------===# > # > > -- > Pawel > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From evan.cheng at apple.com Mon Jul 6 17:29:14 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 06 Jul 2009 22:29:14 -0000 Subject: [llvm-commits] [llvm] r74871 - /llvm/trunk/lib/Target/ARM/ARMSubtarget.h Message-ID: <200907062229.n66MTEet007009@zion.cs.uiuc.edu> Author: evancheng Date: Mon Jul 6 17:29:14 2009 New Revision: 74871 URL: http://llvm.org/viewvc/llvm-project?rev=74871&view=rev Log: isThumb2 really should mean thumb2 only, not thumb2+. Modified: llvm/trunk/lib/Target/ARM/ARMSubtarget.h Modified: llvm/trunk/lib/Target/ARM/ARMSubtarget.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMSubtarget.h?rev=74871&r1=74870&r2=74871&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMSubtarget.h (original) +++ llvm/trunk/lib/Target/ARM/ARMSubtarget.h Mon Jul 6 17:29:14 2009 @@ -108,7 +108,7 @@ bool isThumb() const { return IsThumb; } bool isThumb1Only() const { return IsThumb && (ThumbMode == Thumb1); } - bool isThumb2() const { return IsThumb && (ThumbMode >= Thumb2); } + bool isThumb2() const { return IsThumb && (ThumbMode == Thumb2); } bool hasThumb2() const { return ThumbMode >= Thumb2; } bool isR9Reserved() const { return IsR9Reserved; } From resistor at mac.com Mon Jul 6 17:37:39 2009 From: resistor at mac.com (Owen Anderson) Date: Mon, 06 Jul 2009 22:37:39 -0000 Subject: [llvm-commits] [llvm] r74873 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolutionExpander.h include/llvm/Analysis/SparsePropagation.h include/llvm/Analysis/ValueTracking.h lib/Analysis/DebugInfo.cpp lib/Analysis/LoopVR.cpp lib/Analysis/ScalarEvolution.cpp lib/Analysis/ScalarEvolutionExpander.cpp lib/Analysis/SparsePropagation.cpp lib/Analysis/ValueTracking.cpp lib/Transforms/IPO/IPConstantPropagation.cpp lib/Transforms/Scalar/SCCP.cpp Message-ID: <200907062237.n66Mbdpg007256@zion.cs.uiuc.edu> Author: resistor Date: Mon Jul 6 17:37:39 2009 New Revision: 74873 URL: http://llvm.org/viewvc/llvm-project?rev=74873&view=rev Log: Finish LLVMContext-ing lib/Analysis. This required pushing LLVMContext's through the ValueTracking API. Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h llvm/trunk/include/llvm/Analysis/SparsePropagation.h llvm/trunk/include/llvm/Analysis/ValueTracking.h llvm/trunk/lib/Analysis/DebugInfo.cpp llvm/trunk/lib/Analysis/LoopVR.cpp llvm/trunk/lib/Analysis/ScalarEvolution.cpp llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp llvm/trunk/lib/Analysis/SparsePropagation.cpp llvm/trunk/lib/Analysis/ValueTracking.cpp llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h Mon Jul 6 17:37:39 2009 @@ -59,6 +59,8 @@ } private: + LLVMContext *getContext() const { return SE.getContext(); } + /// InsertBinop - Insert the specified binary operator, doing a small amount /// of work to avoid inserting an obviously redundant operation. Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS); Modified: llvm/trunk/include/llvm/Analysis/SparsePropagation.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/SparsePropagation.h?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/SparsePropagation.h (original) +++ llvm/trunk/include/llvm/Analysis/SparsePropagation.h Mon Jul 6 17:37:39 2009 @@ -31,6 +31,7 @@ class BasicBlock; class Function; class SparseSolver; + class LLVMContext; template class SmallVectorImpl; @@ -113,6 +114,8 @@ /// compute transfer functions. AbstractLatticeFunction *LatticeFunc; + LLVMContext *Context; + DenseMap ValueState; // The state each value is in. SmallPtrSet BBExecutable; // The bbs that are executable. @@ -128,8 +131,8 @@ SparseSolver(const SparseSolver&); // DO NOT IMPLEMENT void operator=(const SparseSolver&); // DO NOT IMPLEMENT public: - explicit SparseSolver(AbstractLatticeFunction *Lattice) - : LatticeFunc(Lattice) {} + explicit SparseSolver(AbstractLatticeFunction *Lattice, LLVMContext* C) + : LatticeFunc(Lattice), Context(C) {} ~SparseSolver() { delete LatticeFunc; } Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original) +++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Mon Jul 6 17:37:39 2009 @@ -23,6 +23,7 @@ class Instruction; class APInt; class TargetData; + class LLVMContext; /// ComputeMaskedBits - Determine which of the bits specified in Mask are /// known to be either zero or one and return them in the KnownZero/KnownOne @@ -64,14 +65,16 @@ Value *FindInsertedValue(Value *V, const unsigned *idx_begin, const unsigned *idx_end, + LLVMContext *Context, Instruction *InsertBefore = 0); /// This is a convenience wrapper for finding values indexed by a single index /// only. inline Value *FindInsertedValue(Value *V, const unsigned Idx, + LLVMContext *Context, Instruction *InsertBefore = 0) { const unsigned Idxs[1] = { Idx }; - return FindInsertedValue(V, &Idxs[0], &Idxs[1], InsertBefore); + return FindInsertedValue(V, &Idxs[0], &Idxs[1], Context, InsertBefore); } /// GetConstantStringInfo - This function computes the length of a Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/DebugInfo.cpp (original) +++ llvm/trunk/lib/Analysis/DebugInfo.cpp Mon Jul 6 17:37:39 2009 @@ -18,6 +18,7 @@ #include "llvm/Intrinsics.h" #include "llvm/IntrinsicInst.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/Dwarf.h" @@ -455,14 +456,15 @@ DIFactory::DIFactory(Module &m) : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0), DeclareFn(0) { - EmptyStructPtr = PointerType::getUnqual(StructType::get()); + EmptyStructPtr = + M.getContext().getPointerTypeUnqual(M.getContext().getStructType()); } /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. /// This is only valid when the descriptor is non-null. Constant *DIFactory::getCastToEmpty(DIDescriptor D) { - if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); - return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); + if (D.isNull()) return M.getContext().getNullValue(EmptyStructPtr); + return M.getContext().getConstantExprBitCast(D.getGV(), EmptyStructPtr); } Constant *DIFactory::GetTagConstant(unsigned TAG) { @@ -478,21 +480,21 @@ // Return Constant if previously defined. if (Slot) return Slot; - const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); + const PointerType *DestTy = M.getContext().getPointerTypeUnqual(Type::Int8Ty); // If empty string then use a i8* null instead. if (String.empty()) - return Slot = ConstantPointerNull::get(DestTy); + return Slot = M.getContext().getConstantPointerNull(DestTy); // Construct string as an llvm constant. - Constant *ConstStr = ConstantArray::get(String); + Constant *ConstStr = M.getContext().getConstantArray(String); // Otherwise create and return a new string global. GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, GlobalVariable::InternalLinkage, ConstStr, ".str", &M); StrGV->setSection("llvm.metadata"); - return Slot = ConstantExpr::getBitCast(StrGV, DestTy); + return Slot = M.getContext().getConstantExprBitCast(StrGV, DestTy); } //===----------------------------------------------------------------------===// @@ -504,10 +506,12 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { SmallVector Elts; + LLVMContext& Ctxt = M.getContext(); + for (unsigned i = 0; i != NumTys; ++i) Elts.push_back(getCastToEmpty(Tys[i])); - Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, + Constant *Init = Ctxt.getConstantArray(Ctxt.getArrayType(EmptyStructPtr, Elts.size()), Elts.data(), Elts.size()); // If we already have this array, just return the uniqued version. @@ -527,11 +531,12 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subrange_type), - ConstantInt::get(Type::Int64Ty, Lo), - ConstantInt::get(Type::Int64Ty, Hi) + M.getContext().getConstantInt(Type::Int64Ty, Lo), + M.getContext().getConstantInt(Type::Int64Ty, Hi) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); // If we already have this range, just return the uniqued version. DIDescriptor &Entry = SimpleConstantCache[Init]; @@ -559,20 +564,22 @@ bool isOptimized, const char *Flags, unsigned RunTimeVer) { + LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), - Constant::getNullValue(EmptyStructPtr), - ConstantInt::get(Type::Int32Ty, LangID), + Ctxt.getNullValue(EmptyStructPtr), + Ctxt.getConstantInt(Type::Int32Ty, LangID), GetStringConstant(Filename), GetStringConstant(Directory), GetStringConstant(Producer), - ConstantInt::get(Type::Int1Ty, isMain), - ConstantInt::get(Type::Int1Ty, isOptimized), + Ctxt.getConstantInt(Type::Int1Ty, isMain), + Ctxt.getConstantInt(Type::Int1Ty, isOptimized), GetStringConstant(Flags), - ConstantInt::get(Type::Int32Ty, RunTimeVer) + Ctxt.getConstantInt(Type::Int32Ty, RunTimeVer) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -587,10 +594,11 @@ Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_enumerator), GetStringConstant(Name), - ConstantInt::get(Type::Int64Ty, Val) + M.getContext().getConstantInt(Type::Int64Ty, Val) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -610,20 +618,23 @@ uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, unsigned Encoding) { + + LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_base_type), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), - ConstantInt::get(Type::Int32Ty, Encoding) + Ctxt.getConstantInt(Type::Int32Ty, LineNumber), + Ctxt.getConstantInt(Type::Int64Ty, SizeInBits), + Ctxt.getConstantInt(Type::Int64Ty, AlignInBits), + Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits), + Ctxt.getConstantInt(Type::Int32Ty, Flags), + Ctxt.getConstantInt(Type::Int32Ty, Encoding) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.basictype.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -645,20 +656,23 @@ uint64_t OffsetInBits, unsigned Flags, DIType DerivedFrom) { + + LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), + Ctxt.getConstantInt(Type::Int32Ty, LineNumber), + Ctxt.getConstantInt(Type::Int64Ty, SizeInBits), + Ctxt.getConstantInt(Type::Int64Ty, AlignInBits), + Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits), + Ctxt.getConstantInt(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -681,23 +695,24 @@ DIType DerivedFrom, DIArray Elements, unsigned RuntimeLang) { - + LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), + Ctxt.getConstantInt(Type::Int32Ty, LineNumber), + Ctxt.getConstantInt(Type::Int64Ty, SizeInBits), + Ctxt.getConstantInt(Type::Int64Ty, AlignInBits), + Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits), + Ctxt.getConstantInt(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom), getCastToEmpty(Elements), - ConstantInt::get(Type::Int32Ty, RuntimeLang) + Ctxt.getConstantInt(Type::Int32Ty, RuntimeLang) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.composite.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -720,21 +735,23 @@ bool isLocalToUnit, bool isDefinition) { + LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subprogram), - Constant::getNullValue(EmptyStructPtr), + Ctxt.getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + Ctxt.getConstantInt(Type::Int32Ty, LineNo), getCastToEmpty(Type), - ConstantInt::get(Type::Int1Ty, isLocalToUnit), - ConstantInt::get(Type::Int1Ty, isDefinition) + Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit), + Ctxt.getConstantInt(Type::Int1Ty, isDefinition) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -752,22 +769,25 @@ DICompileUnit CompileUnit, unsigned LineNo, DIType Type,bool isLocalToUnit, bool isDefinition, llvm::GlobalVariable *Val) { + + LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_variable), - Constant::getNullValue(EmptyStructPtr), + Ctxt.getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + Ctxt.getConstantInt(Type::Int32Ty, LineNo), getCastToEmpty(Type), - ConstantInt::get(Type::Int1Ty, isLocalToUnit), - ConstantInt::get(Type::Int1Ty, isDefinition), - ConstantExpr::getBitCast(Val, EmptyStructPtr) + Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit), + Ctxt.getConstantInt(Type::Int1Ty, isDefinition), + Ctxt.getConstantExprBitCast(Val, EmptyStructPtr) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -783,16 +803,19 @@ const std::string &Name, DICompileUnit CompileUnit, unsigned LineNo, DIType Type) { + LLVMContext& Ctxt = M.getContext(); + Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + Ctxt.getConstantInt(Type::Int32Ty, LineNo), getCastToEmpty(Type) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.variable.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -811,7 +834,8 @@ getCastToEmpty(Context) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = + M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.block.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -838,8 +862,8 @@ // Invoke llvm.dbg.stoppoint Value *Args[] = { - llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo), - llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo), + M.getContext().getConstantInt(llvm::Type::Int32Ty, LineNo), + M.getContext().getConstantInt(llvm::Type::Int32Ty, ColNo), getCastToEmpty(CU) }; CallInst::Create(StopPointFn, Args, Args+3, "", BB); @@ -942,7 +966,7 @@ const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); if (!Ty) return 0; - Ty = PointerType::get(Ty, 0); + Ty = V->getParent()->getContext().getPointerType(Ty, 0); Value *Val = V->stripPointerCasts(); for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); Modified: llvm/trunk/lib/Analysis/LoopVR.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopVR.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/LoopVR.cpp (original) +++ llvm/trunk/lib/Analysis/LoopVR.cpp Mon Jul 6 17:37:39 2009 @@ -15,6 +15,7 @@ #include "llvm/Analysis/LoopVR.h" #include "llvm/Constants.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/Assembly/Writer.h" #include "llvm/Support/CFG.h" @@ -71,8 +72,8 @@ ConstantRange X = getRange(Mul->getOperand(0), T, SE); if (X.isFullSet()) return FullSet; - const IntegerType *Ty = IntegerType::get(X.getBitWidth()); - const IntegerType *ExTy = IntegerType::get(X.getBitWidth() * + const IntegerType *Ty = Context->getIntegerType(X.getBitWidth()); + const IntegerType *ExTy = Context->getIntegerType(X.getBitWidth() * Mul->getNumOperands()); ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth()); Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon Jul 6 17:37:39 2009 @@ -65,6 +65,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/GlobalVariable.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/LoopInfo.h" @@ -3839,8 +3840,12 @@ return std::make_pair(CNC, CNC); } - ConstantInt *Solution1 = ConstantInt::get((NegB + SqrtVal).sdiv(TwoA)); - ConstantInt *Solution2 = ConstantInt::get((NegB - SqrtVal).sdiv(TwoA)); + LLVMContext *Context = SE.getContext(); + + ConstantInt *Solution1 = + Context->getConstantInt((NegB + SqrtVal).sdiv(TwoA)); + ConstantInt *Solution2 = + Context->getConstantInt((NegB - SqrtVal).sdiv(TwoA)); return std::make_pair(SE.getConstant(Solution1), SE.getConstant(Solution2)); @@ -3908,7 +3913,7 @@ #endif // Pick the smallest positive root value. if (ConstantInt *CB = - dyn_cast(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, + dyn_cast(Context->getConstantExprICmp(ICmpInst::ICMP_ULT, R1->getValue(), R2->getValue()))) { if (CB->getZExtValue() == false) std::swap(R1, R2); // R1 is the minimum root now. @@ -4157,7 +4162,7 @@ // Check Add for unsigned overflow. // TODO: More sophisticated things could be done here. - const Type *WideTy = IntegerType::get(getTypeSizeInBits(Ty) + 1); + const Type *WideTy = Context->getIntegerType(getTypeSizeInBits(Ty) + 1); const SCEV* OperandExtendedAdd = getAddExpr(getZeroExtendExpr(Diff, WideTy), getZeroExtendExpr(RoundUp, WideTy)); @@ -4313,7 +4318,7 @@ // The exit value should be (End+A)/A. APInt ExitVal = (End + A).udiv(A); - ConstantInt *ExitValue = ConstantInt::get(ExitVal); + ConstantInt *ExitValue = SE.getContext()->getConstantInt(ExitVal); // Evaluate at the exit value. If we really did fall out of the valid // range, then we computed our trip count, otherwise wrap around or other @@ -4325,7 +4330,7 @@ // Ensure that the previous value is in the range. This is a sanity check. assert(Range.contains( EvaluateConstantChrecAtConstant(this, - ConstantInt::get(ExitVal - One), SE)->getValue()) && + SE.getContext()->getConstantInt(ExitVal - One), SE)->getValue()) && "Linear scev computation is off in a bad way!"); return SE.getConstant(ExitValue); } else if (isQuadratic()) { @@ -4345,8 +4350,9 @@ if (R1) { // Pick the smallest positive root value. if (ConstantInt *CB = - dyn_cast(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, - R1->getValue(), R2->getValue()))) { + dyn_cast( + SE.getContext()->getConstantExprICmp(ICmpInst::ICMP_ULT, + R1->getValue(), R2->getValue()))) { if (CB->getZExtValue() == false) std::swap(R1, R2); // R1 is the minimum root now. @@ -4358,7 +4364,8 @@ SE); if (Range.contains(R1Val->getValue())) { // The next iteration must be out of the range... - ConstantInt *NextVal = ConstantInt::get(R1->getValue()->getValue()+1); + ConstantInt *NextVal = + SE.getContext()->getConstantInt(R1->getValue()->getValue()+1); R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE); if (!Range.contains(R1Val->getValue())) @@ -4368,7 +4375,8 @@ // If R1 was not in the range, then it is a good return value. Make // sure that R1-1 WAS in the range though, just in case. - ConstantInt *NextVal = ConstantInt::get(R1->getValue()->getValue()-1); + ConstantInt *NextVal = + SE.getContext()->getConstantInt(R1->getValue()->getValue()-1); R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE); if (Range.contains(R1Val->getValue())) return R1; Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Mon Jul 6 17:37:39 2009 @@ -15,6 +15,7 @@ #include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/Analysis/LoopInfo.h" +#include "llvm/LLVMContext.h" #include "llvm/Target/TargetData.h" #include "llvm/ADT/STLExtras.h" using namespace llvm; @@ -54,7 +55,7 @@ // FIXME: keep track of the cast instruction. if (Constant *C = dyn_cast(V)) - return ConstantExpr::getCast(Op, C, Ty); + return getContext()->getConstantExprCast(Op, C, Ty); if (Argument *A = dyn_cast(V)) { // Check to see if there is already a cast! @@ -125,7 +126,7 @@ // Fold a binop with constant operands. if (Constant *CLHS = dyn_cast(LHS)) if (Constant *CRHS = dyn_cast(RHS)) - return ConstantExpr::get(Opcode, CLHS, CRHS); + return getContext()->getConstantExpr(Opcode, CLHS, CRHS); // Do a quick scan to see if we have this binop nearby. If so, reuse it. unsigned ScanLimit = 6; @@ -166,7 +167,7 @@ // For a Constant, check for a multiple of the given factor. if (const SCEVConstant *C = dyn_cast(S)) { ConstantInt *CI = - ConstantInt::get(C->getValue()->getValue().sdiv(Factor)); + SE.getContext()->getConstantInt(C->getValue()->getValue().sdiv(Factor)); // If the quotient is zero and the remainder is non-zero, reject // the value at this scale. It will be considered for subsequent // smaller scales. @@ -286,7 +287,7 @@ Ops = NewOps; AnyNonZeroIndices |= !ScaledOps.empty(); Value *Scaled = ScaledOps.empty() ? - Constant::getNullValue(Ty) : + getContext()->getNullValue(Ty) : expandCodeFor(SE.getAddExpr(ScaledOps), Ty); GepIndices.push_back(Scaled); @@ -299,7 +300,8 @@ uint64_t FullOffset = C->getValue()->getZExtValue(); if (FullOffset < SL.getSizeInBytes()) { unsigned ElIdx = SL.getElementContainingOffset(FullOffset); - GepIndices.push_back(ConstantInt::get(Type::Int32Ty, ElIdx)); + GepIndices.push_back( + getContext()->getConstantInt(Type::Int32Ty, ElIdx)); ElTy = STy->getTypeAtIndex(ElIdx); Ops[0] = SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx)); @@ -328,7 +330,7 @@ // Fold a GEP with constant operands. if (Constant *CLHS = dyn_cast(V)) if (Constant *CRHS = dyn_cast(Idx)) - return ConstantExpr::getGetElementPtr(CLHS, &CRHS, 1); + return getContext()->getConstantExprGetElementPtr(CLHS, &CRHS, 1); // Do a quick scan to see if we have this GEP nearby. If so, reuse it. unsigned ScanLimit = 6; @@ -400,7 +402,7 @@ // -1 * ... ---> 0 - ... if (FirstOp == 1) - V = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), V); + V = InsertBinop(Instruction::Sub, getContext()->getNullValue(Ty), V); return V; } @@ -412,7 +414,7 @@ const APInt &RHS = SC->getValue()->getValue(); if (RHS.isPowerOf2()) return InsertBinop(Instruction::LShr, LHS, - ConstantInt::get(Ty, RHS.logBase2())); + getContext()->getConstantInt(Ty, RHS.logBase2())); } Value *RHS = expandCodeFor(S->getRHS(), Ty); @@ -522,7 +524,7 @@ BasicBlock *Preheader = L->getLoopPreheader(); PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin()); InsertedValues.insert(PN); - PN->addIncoming(Constant::getNullValue(Ty), Preheader); + PN->addIncoming(getContext()->getNullValue(Ty), Preheader); pred_iterator HPI = pred_begin(Header); assert(HPI != pred_end(Header) && "Loop with zero preds???"); @@ -532,7 +534,7 @@ // Insert a unit add instruction right before the terminator corresponding // to the back-edge. - Constant *One = ConstantInt::get(Ty, 1); + Constant *One = getContext()->getConstantInt(Ty, 1); Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next", (*HPI)->getTerminator()); InsertedValues.insert(Add); Modified: llvm/trunk/lib/Analysis/SparsePropagation.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/SparsePropagation.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/SparsePropagation.cpp (original) +++ llvm/trunk/lib/Analysis/SparsePropagation.cpp Mon Jul 6 17:37:39 2009 @@ -17,6 +17,7 @@ #include "llvm/Constants.h" #include "llvm/Function.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Support/Debug.h" using namespace llvm; @@ -153,7 +154,7 @@ } // Constant condition variables mean the branch can only go a single way - Succs[C == ConstantInt::getFalse()] = true; + Succs[C == Context->getConstantIntFalse()] = true; return; } Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original) +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Jul 6 17:37:39 2009 @@ -17,6 +17,7 @@ #include "llvm/Instructions.h" #include "llvm/GlobalVariable.h" #include "llvm/IntrinsicInst.h" +#include "llvm/LLVMContext.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/MathExtras.h" @@ -834,6 +835,7 @@ Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType, SmallVector &Idxs, unsigned IdxSkip, + LLVMContext* Context, Instruction *InsertBefore) { const llvm::StructType *STy = llvm::dyn_cast(IndexedType); if (STy) { @@ -845,7 +847,7 @@ Idxs.push_back(i); Value *PrevTo = To; To = BuildSubAggregate(From, To, STy->getElementType(i), Idxs, IdxSkip, - InsertBefore); + Context, InsertBefore); Idxs.pop_back(); if (!To) { // Couldn't find any inserted value for this index? Cleanup @@ -868,7 +870,7 @@ // we might be able to find the complete struct somewhere. // Find the value that is at that particular spot - Value *V = FindInsertedValue(From, Idxs.begin(), Idxs.end()); + Value *V = FindInsertedValue(From, Idxs.begin(), Idxs.end(), Context); if (!V) return NULL; @@ -891,16 +893,18 @@ // // All inserted insertvalue instructions are inserted before InsertBefore Value *BuildSubAggregate(Value *From, const unsigned *idx_begin, - const unsigned *idx_end, Instruction *InsertBefore) { + const unsigned *idx_end, LLVMContext *Context, + Instruction *InsertBefore) { assert(InsertBefore && "Must have someplace to insert!"); const Type *IndexedType = ExtractValueInst::getIndexedType(From->getType(), idx_begin, idx_end); - Value *To = UndefValue::get(IndexedType); + Value *To = Context->getUndef(IndexedType); SmallVector Idxs(idx_begin, idx_end); unsigned IdxSkip = Idxs.size(); - return BuildSubAggregate(From, To, IndexedType, Idxs, IdxSkip, InsertBefore); + return BuildSubAggregate(From, To, IndexedType, Idxs, IdxSkip, + Context, InsertBefore); } /// FindInsertedValue - Given an aggregrate and an sequence of indices, see if @@ -910,7 +914,8 @@ /// If InsertBefore is not null, this function will duplicate (modified) /// insertvalues when a part of a nested struct is extracted. Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin, - const unsigned *idx_end, Instruction *InsertBefore) { + const unsigned *idx_end, LLVMContext* Context, + Instruction *InsertBefore) { // Nothing to index? Just return V then (this is useful at the end of our // recursion) if (idx_begin == idx_end) @@ -921,20 +926,20 @@ assert(ExtractValueInst::getIndexedType(V->getType(), idx_begin, idx_end) && "Invalid indices for type?"); const CompositeType *PTy = cast(V->getType()); - + if (isa(V)) - return UndefValue::get(ExtractValueInst::getIndexedType(PTy, + return Context->getUndef(ExtractValueInst::getIndexedType(PTy, idx_begin, idx_end)); else if (isa(V)) - return Constant::getNullValue(ExtractValueInst::getIndexedType(PTy, - idx_begin, - idx_end)); + return Context->getNullValue(ExtractValueInst::getIndexedType(PTy, + idx_begin, + idx_end)); else if (Constant *C = dyn_cast(V)) { if (isa(C) || isa(C)) // Recursively process this constant - return FindInsertedValue(C->getOperand(*idx_begin), idx_begin + 1, idx_end, - InsertBefore); + return FindInsertedValue(C->getOperand(*idx_begin), idx_begin + 1, + idx_end, Context, InsertBefore); } else if (InsertValueInst *I = dyn_cast(V)) { // Loop the indices for the insertvalue instruction in parallel with the // requested indices @@ -953,7 +958,8 @@ // %C = insertvalue {i32, i32 } %A, i32 11, 1 // which allows the unused 0,0 element from the nested struct to be // removed. - return BuildSubAggregate(V, idx_begin, req_idx, InsertBefore); + return BuildSubAggregate(V, idx_begin, req_idx, + Context, InsertBefore); else // We can't handle this without inserting insertvalues return 0; @@ -964,13 +970,13 @@ // looking for, then. if (*req_idx != *i) return FindInsertedValue(I->getAggregateOperand(), idx_begin, idx_end, - InsertBefore); + Context, InsertBefore); } // If we end up here, the indices of the insertvalue match with those // requested (though possibly only partially). Now we recursively look at // the inserted value, passing any remaining indices. return FindInsertedValue(I->getInsertedValueOperand(), req_idx, idx_end, - InsertBefore); + Context, InsertBefore); } else if (ExtractValueInst *I = dyn_cast(V)) { // If we're extracting a value from an aggregrate that was extracted from // something else, we can extract from that something else directly instead. @@ -994,7 +1000,7 @@ && "Number of indices added not correct?"); return FindInsertedValue(I->getAggregateOperand(), Idxs.begin(), Idxs.end(), - InsertBefore); + Context, InsertBefore); } // Otherwise, we don't know (such as, extracting from a function return value // or load instruction) Modified: llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp (original) +++ llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp Mon Jul 6 17:37:39 2009 @@ -183,7 +183,7 @@ if (!STy) V = RI->getOperand(i); else - V = FindInsertedValue(RI->getOperand(0), i); + V = FindInsertedValue(RI->getOperand(0), i, Context); if (V) { // Ignore undefs, we can change them into anything Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=74873&r1=74872&r2=74873&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Mon Jul 6 17:37:39 2009 @@ -642,7 +642,7 @@ DenseMap, LatticeVal>::iterator It = TrackedMultipleRetVals.find(std::make_pair(F, i)); if (It == TrackedMultipleRetVals.end()) break; - if (Value *Val = FindInsertedValue(I.getOperand(0), i)) + if (Value *Val = FindInsertedValue(I.getOperand(0), i, Context)) mergeInValue(It->second, F, getValueState(Val)); } } From isanbard at gmail.com Mon Jul 6 17:59:40 2009 From: isanbard at gmail.com (Bill Wendling) Date: Mon, 6 Jul 2009 15:59:40 -0700 Subject: [llvm-commits] [llvm] r74829 - /llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp In-Reply-To: <200907061536.n66FaOBo026070@zion.cs.uiuc.edu> References: <200907061536.n66FaOBo026070@zion.cs.uiuc.edu> Message-ID: <16e5fdf90907061559v4bc0be72o705cd41156820ad1@mail.gmail.com> Thanks, Stuart! -bw On Mon, Jul 6, 2009 at 8:36 AM, Stuart Hastings wrote: > Author: stuart > Date: Mon Jul ?6 10:36:23 2009 > New Revision: 74829 > > URL: http://llvm.org/viewvc/llvm-project?rev=74829&view=rev > Log: > Mark this test as Darwin only. ?Patch by Bill Wendling. > > Modified: > ? ?llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp > > Modified: llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FrontendC%2B%2B/2009-06-30-ByrefBlock.cpp?rev=74829&r1=74828&r2=74829&view=diff > > ============================================================================== > --- llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp (original) > +++ llvm/trunk/test/FrontendC++/2009-06-30-ByrefBlock.cpp Mon Jul ?6 10:36:23 2009 > @@ -1,6 +1,9 @@ > -// Insure __block_holder_tmp is allocated on the stack. > +// Insure __block_holder_tmp is allocated on the stack. ?Darwin only. > ?// RUN: %llvmgxx %s -S -O2 -o - | egrep {__block_holder_tmp.*alloca} > +// XFAIL: * > +// XTARGET: darwin > ?// > +// END. > ?extern void fubar_dispatch_sync(void (^PP)(void)); > ?void fubar() { > ? __block void *voodoo; > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > From resistor at mac.com Mon Jul 6 18:00:20 2009 From: resistor at mac.com (Owen Anderson) Date: Mon, 06 Jul 2009 23:00:20 -0000 Subject: [llvm-commits] [llvm] r74878 - in /llvm/trunk: include/llvm/ include/llvm/Analysis/ include/llvm/Support/ include/llvm/Transforms/Utils/ lib/Analysis/ lib/Transforms/IPO/ lib/Transforms/Instrumentation/ lib/Transforms/Scalar/ lib/Transforms/Utils/ lib/VMCore/ Message-ID: <200907062300.n66N0M8g007987@zion.cs.uiuc.edu> Author: resistor Date: Mon Jul 6 18:00:19 2009 New Revision: 74878 URL: http://llvm.org/viewvc/llvm-project?rev=74878&view=rev Log: "LLVMContext* " --> "LLVMContext *" Modified: llvm/trunk/include/llvm/Analysis/ConstantFolding.h llvm/trunk/include/llvm/Analysis/ScalarEvolution.h llvm/trunk/include/llvm/Analysis/SparsePropagation.h llvm/trunk/include/llvm/BasicBlock.h llvm/trunk/include/llvm/Function.h llvm/trunk/include/llvm/Pass.h llvm/trunk/include/llvm/Support/TargetFolder.h llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp llvm/trunk/lib/Analysis/ConstantFolding.cpp llvm/trunk/lib/Analysis/ScalarEvolution.cpp llvm/trunk/lib/Analysis/ValueTracking.cpp llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp llvm/trunk/lib/Transforms/Scalar/SCCP.cpp llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp llvm/trunk/lib/Transforms/Utils/Local.cpp llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp llvm/trunk/lib/VMCore/BasicBlock.cpp llvm/trunk/lib/VMCore/Function.cpp Modified: llvm/trunk/include/llvm/Analysis/ConstantFolding.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ConstantFolding.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ConstantFolding.h (original) +++ llvm/trunk/include/llvm/Analysis/ConstantFolding.h Mon Jul 6 18:00:19 2009 @@ -29,13 +29,13 @@ /// is returned. Note that this function can only fail when attempting to fold /// instructions like loads and stores, which have no constant expression form. /// -Constant *ConstantFoldInstruction(Instruction *I, LLVMContext* Context, +Constant *ConstantFoldInstruction(Instruction *I, LLVMContext *Context, const TargetData *TD = 0); /// ConstantFoldConstantExpression - Attempt to fold the constant expression /// using the specified TargetData. If successful, the constant result is /// result is returned, if not, null is returned. -Constant *ConstantFoldConstantExpression(ConstantExpr *CE, LLVMContext* Context, +Constant *ConstantFoldConstantExpression(ConstantExpr *CE, LLVMContext *Context, const TargetData *TD = 0); /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the @@ -46,7 +46,7 @@ /// Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, Constant*const * Ops, unsigned NumOps, - LLVMContext* Context, + LLVMContext *Context, const TargetData *TD = 0); /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare @@ -55,7 +55,7 @@ /// Constant *ConstantFoldCompareInstOperands(unsigned Predicate, Constant*const * Ops, unsigned NumOps, - LLVMContext* Context, + LLVMContext *Context, const TargetData *TD = 0); @@ -63,7 +63,7 @@ /// getelementptr constantexpr, return the constant value being addressed by the /// constant expression, or null if something is funny and we can't decide. Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE, - LLVMContext* Context); + LLVMContext *Context); /// canConstantFoldCallTo - Return true if its even possible to fold a call to /// the specified function. Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Mon Jul 6 18:00:19 2009 @@ -355,7 +355,7 @@ static char ID; // Pass identification, replacement for typeid ScalarEvolution(); - LLVMContext* getContext() const { return Context; } + LLVMContext *getContext() const { return Context; } /// isSCEVable - Test if values of the given type are analyzable within /// the SCEV framework. This primarily includes integer types, and it Modified: llvm/trunk/include/llvm/Analysis/SparsePropagation.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/SparsePropagation.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/SparsePropagation.h (original) +++ llvm/trunk/include/llvm/Analysis/SparsePropagation.h Mon Jul 6 18:00:19 2009 @@ -131,7 +131,7 @@ SparseSolver(const SparseSolver&); // DO NOT IMPLEMENT void operator=(const SparseSolver&); // DO NOT IMPLEMENT public: - explicit SparseSolver(AbstractLatticeFunction *Lattice, LLVMContext* C) + explicit SparseSolver(AbstractLatticeFunction *Lattice, LLVMContext *C) : LatticeFunc(Lattice), Context(C) {} ~SparseSolver() { delete LatticeFunc; Modified: llvm/trunk/include/llvm/BasicBlock.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BasicBlock.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/BasicBlock.h (original) +++ llvm/trunk/include/llvm/BasicBlock.h Mon Jul 6 18:00:19 2009 @@ -88,7 +88,7 @@ public: /// getContext - Get the context in which this basic block lives, /// or null if it is not currently attached to a function. - LLVMContext* getContext() const; + LLVMContext *getContext() const; /// Instruction iterators... typedef InstListType::iterator iterator; Modified: llvm/trunk/include/llvm/Function.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Function.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Function.h (original) +++ llvm/trunk/include/llvm/Function.h Mon Jul 6 18:00:19 2009 @@ -129,7 +129,7 @@ /// getContext - Return a pointer to the LLVMContext associated with this /// function, or NULL if this function is not bound to a context yet. - LLVMContext* getContext() const; + LLVMContext *getContext() const; /// isVarArg - Return true if this function takes a variable number of /// arguments. Modified: llvm/trunk/include/llvm/Pass.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Pass.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Pass.h (original) +++ llvm/trunk/include/llvm/Pass.h Mon Jul 6 18:00:19 2009 @@ -79,7 +79,7 @@ Pass(const Pass &); // DO NOT IMPLEMENT protected: - LLVMContext* Context; + LLVMContext *Context; public: explicit Pass(intptr_t pid) : Resolver(0), PassID(pid) { Modified: llvm/trunk/include/llvm/Support/TargetFolder.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TargetFolder.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Support/TargetFolder.h (original) +++ llvm/trunk/include/llvm/Support/TargetFolder.h Mon Jul 6 18:00:19 2009 @@ -30,7 +30,7 @@ /// TargetFolder - Create constants with target dependent folding. class TargetFolder { const TargetData *TD; - LLVMContext* Context; + LLVMContext *Context; /// Fold - Fold the constant using target specific information. Constant *Fold(Constant *C) const { @@ -41,7 +41,7 @@ } public: - explicit TargetFolder(const TargetData *TheTD, LLVMContext* C) : + explicit TargetFolder(const TargetData *TheTD, LLVMContext *C) : TD(TheTD), Context(C) {} //===--------------------------------------------------------------------===// Modified: llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h (original) +++ llvm/trunk/include/llvm/Transforms/Utils/PromoteMemToReg.h Mon Jul 6 18:00:19 2009 @@ -40,7 +40,7 @@ /// void PromoteMemToReg(const std::vector &Allocas, DominatorTree &DT, DominanceFrontier &DF, - LLVMContext* Context, + LLVMContext *Context, AliasSetTracker *AST = 0); } // End llvm namespace Modified: llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h (original) +++ llvm/trunk/include/llvm/Transforms/Utils/ValueMapper.h Mon Jul 6 18:00:19 2009 @@ -23,7 +23,7 @@ class LLVMContext; typedef DenseMap ValueMapTy; - Value *MapValue(const Value *V, ValueMapTy &VM, LLVMContext* Context); + Value *MapValue(const Value *V, ValueMapTy &VM, LLVMContext *Context); void RemapInstruction(Instruction *I, ValueMapTy &VM); } // End llvm namespace Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original) +++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Mon Jul 6 18:00:19 2009 @@ -499,7 +499,7 @@ // This function is used to determine if the indices of two GEP instructions are // equal. V1 and V2 are the indices. -static bool IndexOperandsEqual(Value *V1, Value *V2, LLVMContext* Context) { +static bool IndexOperandsEqual(Value *V1, Value *V2, LLVMContext *Context) { if (V1->getType() == V2->getType()) return V1 == V2; if (Constant *C1 = dyn_cast(V1)) Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original) +++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Jul 6 18:00:19 2009 @@ -94,7 +94,7 @@ /// otherwise TD is null. static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, Constant *Op1, const TargetData *TD, - LLVMContext* Context){ + LLVMContext *Context){ // SROA // Fold (and 0xffffffff00000000, (shl x, 32)) -> shl. @@ -123,7 +123,7 @@ /// constant expression, do so. static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps, const Type *ResultTy, - LLVMContext* Context, + LLVMContext *Context, const TargetData *TD) { Constant *Ptr = Ops[0]; if (!TD || !cast(Ptr->getType())->getElementType()->isSized()) @@ -157,7 +157,7 @@ /// FoldBitCast - Constant fold bitcast, symbolically evaluating it with /// targetdata. Return 0 if unfoldable. static Constant *FoldBitCast(Constant *C, const Type *DestTy, - const TargetData &TD, LLVMContext* Context) { + const TargetData &TD, LLVMContext *Context) { // If this is a bitcast from constant vector -> vector, fold it. if (ConstantVector *CV = dyn_cast(C)) { if (const VectorType *DestVTy = dyn_cast(DestTy)) { @@ -281,7 +281,7 @@ /// is returned. Note that this function can only fail when attempting to fold /// instructions like loads and stores, which have no constant expression form. /// -Constant *llvm::ConstantFoldInstruction(Instruction *I, LLVMContext* Context, +Constant *llvm::ConstantFoldInstruction(Instruction *I, LLVMContext *Context, const TargetData *TD) { if (PHINode *PN = dyn_cast(I)) { if (PN->getNumIncomingValues() == 0) @@ -321,7 +321,7 @@ /// using the specified TargetData. If successful, the constant result is /// result is returned, if not, null is returned. Constant *llvm::ConstantFoldConstantExpression(ConstantExpr *CE, - LLVMContext* Context, + LLVMContext *Context, const TargetData *TD) { SmallVector Ops; for (User::op_iterator i = CE->op_begin(), e = CE->op_end(); i != e; ++i) @@ -344,7 +344,7 @@ /// Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, Constant* const* Ops, unsigned NumOps, - LLVMContext* Context, + LLVMContext *Context, const TargetData *TD) { // Handle easy binops first. if (Instruction::isBinaryOp(Opcode)) { @@ -470,7 +470,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, Constant*const * Ops, unsigned NumOps, - LLVMContext* Context, + LLVMContext *Context, const TargetData *TD) { // fold: icmp (inttoptr x), null -> icmp x, 0 // fold: icmp (ptrtoint x), 0 -> icmp x, null @@ -543,7 +543,7 @@ /// constant expression, or null if something is funny and we can't decide. Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE, - LLVMContext* Context) { + LLVMContext *Context) { if (CE->getOperand(1) != Context->getNullValue(CE->getOperand(1)->getType())) return 0; // Do not allow stepping over the value! @@ -680,7 +680,7 @@ } static Constant *ConstantFoldFP(double (*NativeFP)(double), double V, - const Type *Ty, LLVMContext* Context) { + const Type *Ty, LLVMContext *Context) { errno = 0; V = NativeFP(V); if (errno != 0) { @@ -699,7 +699,7 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double), double V, double W, const Type *Ty, - LLVMContext* Context) { + LLVMContext *Context) { errno = 0; V = NativeFP(V, W); if (errno != 0) { @@ -722,7 +722,7 @@ llvm::ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands) { if (!F->hasName()) return 0; - LLVMContext* Context = F->getContext(); + LLVMContext *Context = F->getContext(); const char *Str = F->getNameStart(); unsigned Len = F->getNameLen(); Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon Jul 6 18:00:19 2009 @@ -3421,7 +3421,7 @@ if (Constant *C = dyn_cast(V)) return C; if (GlobalValue *GV = dyn_cast(V)) return GV; Instruction *I = cast(V); - LLVMContext* Context = I->getParent()->getContext(); + LLVMContext *Context = I->getParent()->getContext(); std::vector Operands; Operands.resize(I->getNumOperands()); Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original) +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Jul 6 18:00:19 2009 @@ -835,7 +835,7 @@ Value *BuildSubAggregate(Value *From, Value* To, const Type *IndexedType, SmallVector &Idxs, unsigned IdxSkip, - LLVMContext* Context, + LLVMContext *Context, Instruction *InsertBefore) { const llvm::StructType *STy = llvm::dyn_cast(IndexedType); if (STy) { @@ -914,7 +914,7 @@ /// If InsertBefore is not null, this function will duplicate (modified) /// insertvalues when a part of a nested struct is extracted. Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin, - const unsigned *idx_end, LLVMContext* Context, + const unsigned *idx_end, LLVMContext *Context, Instruction *InsertBefore) { // Nothing to index? Just return V then (this is useful at the end of our // recursion) Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original) +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Mon Jul 6 18:00:19 2009 @@ -246,7 +246,7 @@ } static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx, - LLVMContext* Context) { + LLVMContext *Context) { ConstantInt *CI = dyn_cast(Idx); if (!CI) return 0; unsigned IdxV = CI->getZExtValue(); @@ -283,7 +283,7 @@ /// quick scan over the use list to clean up the easy and obvious cruft. This /// returns true if it made a change. static bool CleanupConstantGlobalUsers(Value *V, Constant *Init, - LLVMContext* Context) { + LLVMContext *Context) { bool Changed = false; for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;) { User *U = *UI++; @@ -465,7 +465,7 @@ /// this transformation is safe already. We return the first global variable we /// insert so that the caller can reprocess it. static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, - LLVMContext* Context) { + LLVMContext *Context) { // Make sure this global only has simple uses that we can SRA. if (!GlobalUsersSafeToSRA(GV)) return 0; @@ -674,7 +674,7 @@ } static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV, - LLVMContext* Context) { + LLVMContext *Context) { bool Changed = false; for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ) { Instruction *I = cast(*UI++); @@ -742,7 +742,7 @@ /// if the loaded value is dynamically null, then we know that they cannot be /// reachable with a null optimize away the load. static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV, - LLVMContext* Context) { + LLVMContext *Context) { bool Changed = false; // Keep track of whether we are able to remove all the uses of the global @@ -796,7 +796,7 @@ /// ConstantPropUsersOf - Walk the use list of V, constant folding all of the /// instructions that are foldable. -static void ConstantPropUsersOf(Value *V, LLVMContext* Context) { +static void ConstantPropUsersOf(Value *V, LLVMContext *Context) { for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ) if (Instruction *I = dyn_cast(*UI++)) if (Constant *NewC = ConstantFoldInstruction(I, Context)) { @@ -817,7 +817,7 @@ /// malloc into a global, and any loads of GV as uses of the new global. static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, MallocInst *MI, - LLVMContext* Context) { + LLVMContext *Context) { DOUT << "PROMOTING MALLOC GLOBAL: " << *GV << " MALLOC = " << *MI; ConstantInt *NElements = cast(MI->getArraySize()); @@ -1131,7 +1131,7 @@ static Value *GetHeapSROAValue(Value *V, unsigned FieldNo, DenseMap > &InsertedScalarizedValues, std::vector > &PHIsToRewrite, - LLVMContext* Context) { + LLVMContext *Context) { std::vector &FieldVals = InsertedScalarizedValues[V]; if (FieldNo >= FieldVals.size()) @@ -1174,7 +1174,7 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser, DenseMap > &InsertedScalarizedValues, std::vector > &PHIsToRewrite, - LLVMContext* Context) { + LLVMContext *Context) { // If this is a comparison against null, handle it. if (ICmpInst *SCI = dyn_cast(LoadUser)) { assert(isa(SCI->getOperand(1))); @@ -1245,7 +1245,7 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Load, DenseMap > &InsertedScalarizedValues, std::vector > &PHIsToRewrite, - LLVMContext* Context) { + LLVMContext *Context) { for (Value::use_iterator UI = Load->use_begin(), E = Load->use_end(); UI != E; ) { Instruction *User = cast(*UI++); @@ -1262,7 +1262,7 @@ /// PerformHeapAllocSRoA - MI is an allocation of an array of structures. Break /// it up into multiple allocations of arrays of the fields. static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI, - LLVMContext* Context){ + LLVMContext *Context){ DOUT << "SROA HEAP ALLOC: " << *GV << " MALLOC = " << *MI; const StructType *STy = cast(MI->getAllocatedType()); @@ -1442,7 +1442,7 @@ MallocInst *MI, Module::global_iterator &GVI, TargetData &TD, - LLVMContext* Context) { + LLVMContext *Context) { // If this is a malloc of an abstract type, don't touch it. if (!MI->getAllocatedType()->isSized()) return false; @@ -1526,7 +1526,7 @@ // that only one value (besides its initializer) is ever stored to the global. static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, Module::global_iterator &GVI, - TargetData &TD, LLVMContext* Context) { + TargetData &TD, LLVMContext *Context) { // Ignore no-op GEPs and bitcasts. StoredOnceVal = StoredOnceVal->stripPointerCasts(); @@ -1558,7 +1558,7 @@ /// can shrink the global into a boolean and select between the two values /// whenever it is used. This exposes the values to other scalar optimizations. static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal, - LLVMContext* Context) { + LLVMContext *Context) { const Type *GVElType = GV->getType()->getElementType(); // If GVElType is already i1, it is already shrunk. If the type of the GV is @@ -1941,7 +1941,7 @@ /// specified array, returning the new global to use. static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, const std::vector &Ctors, - LLVMContext* Context) { + LLVMContext *Context) { // If we made a change, reassemble the initializer list. std::vector CSVals; CSVals.push_back(Context->getConstantInt(Type::Int32Ty, 65535)); @@ -2009,7 +2009,7 @@ /// enough for us to understand. In particular, if it is a cast of something, /// we punt. We basically just support direct accesses to globals and GEP's of /// globals. This should be kept up to date with CommitValueTo. -static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext* Context) { +static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext *Context) { if (GlobalVariable *GV = dyn_cast(C)) { if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage()) return false; // do not allow weak/linkonce/dllimport/dllexport linkage. @@ -2034,7 +2034,7 @@ /// At this point, the GEP operands of Addr [0, OpNo) have been stepped into. static Constant *EvaluateStoreInto(Constant *Init, Constant *Val, ConstantExpr *Addr, unsigned OpNo, - LLVMContext* Context) { + LLVMContext *Context) { // Base case of the recursion. if (OpNo == Addr->getNumOperands()) { assert(Val->getType() == Init->getType() && "Type mismatch!"); @@ -2097,7 +2097,7 @@ /// CommitValueTo - We have decided that Addr (which satisfies the predicate /// isSimpleEnoughPointerToCommit) should get Val as its value. Make it happen. static void CommitValueTo(Constant *Val, Constant *Addr, - LLVMContext* Context) { + LLVMContext *Context) { if (GlobalVariable *GV = dyn_cast(Addr)) { assert(GV->hasInitializer()); GV->setInitializer(Val); @@ -2117,7 +2117,7 @@ /// decide, return null. static Constant *ComputeLoadResult(Constant *P, const DenseMap &Memory, - LLVMContext* Context) { + LLVMContext *Context) { // If this memory location has been recently stored, use the stored value: it // is the most up-to-date. DenseMap::const_iterator I = Memory.find(P); @@ -2156,7 +2156,7 @@ if (std::find(CallStack.begin(), CallStack.end(), F) != CallStack.end()) return false; - LLVMContext* Context = F->getContext(); + LLVMContext *Context = F->getContext(); CallStack.push_back(F); Modified: llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp (original) +++ llvm/trunk/lib/Transforms/Instrumentation/ProfilingUtils.cpp Mon Jul 6 18:00:19 2009 @@ -23,7 +23,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, GlobalValue *Array) { - LLVMContext* Context = MainFn->getContext(); + LLVMContext *Context = MainFn->getContext(); const Type *ArgVTy = Context->getPointerTypeUnqual(Context->getPointerTypeUnqual(Type::Int8Ty)); const PointerType *UIntPtr = Context->getPointerTypeUnqual(Type::Int32Ty); @@ -101,7 +101,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, GlobalValue *CounterArray) { - LLVMContext* Context = BB->getContext(); + LLVMContext *Context = BB->getContext(); // Insert the increment after any alloca or PHI instructions... BasicBlock::iterator InsertPos = BB->getFirstNonPHI(); Modified: llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp (original) +++ llvm/trunk/lib/Transforms/Instrumentation/RSProfiling.cpp Mon Jul 6 18:00:19 2009 @@ -208,7 +208,7 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); - LLVMContext* Context = bb->getContext(); + LLVMContext *Context = bb->getContext(); //decrement counter LoadInst* l = new LoadInst(Counter, "counter", t); @@ -282,7 +282,7 @@ void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); - LLVMContext* Context = bb->getContext(); + LLVMContext *Context = bb->getContext(); //decrement counter LoadInst* l = new LoadInst(AI, "counter", t); @@ -317,7 +317,7 @@ void CycleCounter::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); - LLVMContext* Context = bb->getContext(); + LLVMContext *Context = bb->getContext(); CallInst* c = CallInst::Create(F, "rdcc", t); BinaryOperator* b = Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jul 6 18:00:19 2009 @@ -83,7 +83,7 @@ static char ID; // Pass identification, replacement for typeid InstCombiner() : FunctionPass(&ID) {} - LLVMContext* getContext() { return Context; } + LLVMContext *getContext() { return Context; } /// AddToWorkList - Add the specified instruction to the worklist if it /// isn't already in it. @@ -568,7 +568,7 @@ // dyn_castNegVal - Given a 'sub' instruction, return the RHS of the instruction // if the LHS is a constant zero (which is the 'negate' form). // -static inline Value *dyn_castNegVal(Value *V, LLVMContext* Context) { +static inline Value *dyn_castNegVal(Value *V, LLVMContext *Context) { if (BinaryOperator::isNeg(V)) return BinaryOperator::getNegArgument(V); @@ -587,7 +587,7 @@ // instruction if the LHS is a constant negative zero (which is the 'negate' // form). // -static inline Value *dyn_castFNegVal(Value *V, LLVMContext* Context) { +static inline Value *dyn_castFNegVal(Value *V, LLVMContext *Context) { if (BinaryOperator::isFNeg(V)) return BinaryOperator::getFNegArgument(V); @@ -602,7 +602,7 @@ return 0; } -static inline Value *dyn_castNotVal(Value *V, LLVMContext* Context) { +static inline Value *dyn_castNotVal(Value *V, LLVMContext *Context) { if (BinaryOperator::isNot(V)) return BinaryOperator::getNotArgument(V); @@ -618,7 +618,7 @@ // Otherwise, return null. // static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST, - LLVMContext* Context) { + LLVMContext *Context) { if (V->hasOneUse() && V->getType()->isInteger()) if (Instruction *I = dyn_cast(V)) { if (I->getOpcode() == Instruction::Mul) @@ -658,19 +658,19 @@ } /// AddOne - Add one to a ConstantInt -static Constant *AddOne(Constant *C, LLVMContext* Context) { +static Constant *AddOne(Constant *C, LLVMContext *Context) { return Context->getConstantExprAdd(C, Context->getConstantInt(C->getType(), 1)); } /// SubOne - Subtract one from a ConstantInt -static Constant *SubOne(ConstantInt *C, LLVMContext* Context) { +static Constant *SubOne(ConstantInt *C, LLVMContext *Context) { return Context->getConstantExprSub(C, Context->getConstantInt(C->getType(), 1)); } /// MultiplyOverflows - True if the multiply can not be expressed in an int /// this size. static bool MultiplyOverflows(ConstantInt *C1, ConstantInt *C2, bool sign, - LLVMContext* Context) { + LLVMContext *Context) { uint32_t W = C1->getBitWidth(); APInt LHSExt = C1->getValue(), RHSExt = C2->getValue(); if (sign) { @@ -697,7 +697,7 @@ /// are any bits set in the constant that are not demanded. If so, shrink the /// constant and return true. static bool ShrinkDemandedConstant(Instruction *I, unsigned OpNo, - APInt Demanded, LLVMContext* Context) { + APInt Demanded, LLVMContext *Context) { assert(I && "No instruction?"); assert(OpNo < I->getNumOperands() && "Operand index too large"); @@ -1800,7 +1800,7 @@ /// template static Instruction *AssociativeOpt(BinaryOperator &Root, const Functor &F, - LLVMContext* Context) { + LLVMContext *Context) { unsigned Opcode = Root.getOpcode(); Value *LHS = Root.getOperand(0); @@ -1872,8 +1872,8 @@ // AddRHS - Implements: X + X --> X << 1 struct AddRHS { Value *RHS; - LLVMContext* Context; - AddRHS(Value *rhs, LLVMContext* C) : RHS(rhs), Context(C) {} + LLVMContext *Context; + AddRHS(Value *rhs, LLVMContext *C) : RHS(rhs), Context(C) {} bool shouldApply(Value *LHS) const { return LHS == RHS; } Instruction *apply(BinaryOperator &Add) const { return BinaryOperator::CreateShl(Add.getOperand(0), @@ -1885,8 +1885,8 @@ // iff C1&C2 == 0 struct AddMaskingAnd { Constant *C2; - LLVMContext* Context; - AddMaskingAnd(Constant *c, LLVMContext* C) : C2(c), Context(C) {} + LLVMContext *Context; + AddMaskingAnd(Constant *c, LLVMContext *C) : C2(c), Context(C) {} bool shouldApply(Value *LHS) const { ConstantInt *C1; return match(LHS, m_And(m_Value(), m_ConstantInt(C1))) && @@ -1901,7 +1901,7 @@ static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO, InstCombiner *IC) { - LLVMContext* Context = IC->getContext(); + LLVMContext *Context = IC->getContext(); if (CastInst *CI = dyn_cast(&I)) { return IC->InsertCastBefore(CI->getOpcode(), SO, I.getType(), I); @@ -3389,7 +3389,7 @@ /// new ICmp instruction. The sign is passed in to determine which kind /// of predicate to use in the new icmp instruction. static Value *getICmpValue(bool sign, unsigned code, Value *LHS, Value *RHS, - LLVMContext* Context) { + LLVMContext *Context) { switch (code) { default: assert(0 && "Illegal ICmp code!"); case 0: return Context->getConstantIntFalse(); @@ -3423,7 +3423,7 @@ /// opcode and two operands into either a FCmp instruction. isordered is passed /// in to determine which kind of predicate to use in the new fcmp instruction. static Value *getFCmpValue(bool isordered, unsigned code, - Value *LHS, Value *RHS, LLVMContext* Context) { + Value *LHS, Value *RHS, LLVMContext *Context) { switch (code) { default: assert(0 && "Illegal FCmp code!"); case 0: @@ -5271,7 +5271,7 @@ } static ConstantInt *ExtractElement(Constant *V, Constant *Idx, - LLVMContext* Context) { + LLVMContext *Context) { return cast(Context->getConstantExprExtractElement(V, Idx)); } @@ -5290,7 +5290,7 @@ /// AddWithOverflow - Compute Result = In1+In2, returning true if the result /// overflowed for this type. static bool AddWithOverflow(Constant *&Result, Constant *In1, - Constant *In2, LLVMContext* Context, + Constant *In2, LLVMContext *Context, bool IsSigned = false) { Result = Context->getConstantExprAdd(In1, In2); @@ -5326,7 +5326,7 @@ /// SubWithOverflow - Compute Result = In1-In2, returning true if the result /// overflowed for this type. static bool SubWithOverflow(Constant *&Result, Constant *In1, - Constant *In2, LLVMContext* Context, + Constant *In2, LLVMContext *Context, bool IsSigned = false) { Result = Context->getConstantExprSub(In1, In2); @@ -5354,7 +5354,7 @@ TargetData &TD = IC.getTargetData(); gep_type_iterator GTI = gep_type_begin(GEP); const Type *IntPtrTy = TD.getIntPtrType(); - LLVMContext* Context = IC.getContext(); + LLVMContext *Context = IC.getContext(); Value *Result = Context->getNullValue(IntPtrTy); // Build a mask for high order bits. @@ -7718,7 +7718,7 @@ /// X*Scale+Offset. /// static Value *DecomposeSimpleLinearExpr(Value *Val, unsigned &Scale, - int &Offset, LLVMContext* Context) { + int &Offset, LLVMContext *Context) { assert(Val->getType() == Type::Int32Ty && "Unexpected allocation size type!"); if (ConstantInt *CI = dyn_cast(Val)) { Offset = CI->getZExtValue(); @@ -8089,7 +8089,7 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset, SmallVectorImpl &NewIndices, const TargetData *TD, - LLVMContext* Context) { + LLVMContext *Context) { if (!Ty->isSized()) return 0; // Start with the index over the outer type. Note that the type size @@ -8742,7 +8742,7 @@ /// FitsInFPType - Return a Constant* for the specified FP constant if it fits /// in the specified FP type without changing its value. static Constant *FitsInFPType(ConstantFP *CFP, const fltSemantics &Sem, - LLVMContext* Context) { + LLVMContext *Context) { bool losesInfo; APFloat F = CFP->getValueAPF(); (void)F.convert(Sem, APFloat::rmNearestTiesToEven, &losesInfo); @@ -8753,7 +8753,7 @@ /// LookThroughFPExtensions - If this is an fp extension instruction, look /// through it until we get the source value. -static Value *LookThroughFPExtensions(Value *V, LLVMContext* Context) { +static Value *LookThroughFPExtensions(Value *V, LLVMContext *Context) { if (Instruction *I = dyn_cast(V)) if (I->getOpcode() == Instruction::FPExt) return LookThroughFPExtensions(I->getOperand(0), Context); @@ -9076,7 +9076,7 @@ /// GetSelectFoldableConstant - For the same transformation as the previous /// function, return the identity constant that goes into the select. static Constant *GetSelectFoldableConstant(Instruction *I, - LLVMContext* Context) { + LLVMContext *Context) { switch (I->getOpcode()) { default: assert(0 && "This cannot happen!"); abort(); case Instruction::Add: @@ -11450,7 +11450,7 @@ const TargetData *TD) { User *CI = cast(LI.getOperand(0)); Value *CastOp = CI->getOperand(0); - LLVMContext* Context = IC.getContext(); + LLVMContext *Context = IC.getContext(); if (TD) { if (ConstantExpr *CE = dyn_cast(CI)) { @@ -11675,7 +11675,7 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) { User *CI = cast(SI.getOperand(1)); Value *CastOp = CI->getOperand(0); - LLVMContext* Context = IC.getContext(); + LLVMContext *Context = IC.getContext(); const Type *DestPTy = cast(CI->getType())->getElementType(); const PointerType *SrcTy = dyn_cast(CastOp->getType()); @@ -12304,7 +12304,7 @@ /// value is already around as a register, for example if it were inserted then /// extracted from the vector. static Value *FindScalarElement(Value *V, unsigned EltNo, - LLVMContext* Context) { + LLVMContext *Context) { assert(isa(V->getType()) && "Not looking at a vector?"); const VectorType *PTy = cast(V->getType()); unsigned Width = PTy->getNumElements(); @@ -12480,7 +12480,7 @@ /// Otherwise, return false. static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS, std::vector &Mask, - LLVMContext* Context) { + LLVMContext *Context) { assert(V->getType() == LHS->getType() && V->getType() == RHS->getType() && "Invalid CollectSingleShuffleElements"); unsigned NumElts = cast(V->getType())->getNumElements(); @@ -12550,7 +12550,7 @@ /// RHS of the shuffle instruction, if it is not null. Return a shuffle mask /// that computes V and the LHS value of the shuffle. static Value *CollectShuffleElements(Value *V, std::vector &Mask, - Value *&RHS, LLVMContext* Context) { + Value *&RHS, LLVMContext *Context) { assert(isa(V->getType()) && (RHS == 0 || V->getType() == RHS->getType()) && "Invalid shuffle!"); Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Mon Jul 6 18:00:19 2009 @@ -795,7 +795,7 @@ /// result can not be determined, a null pointer is returned. static Constant *GetResultOfComparison(CmpInst::Predicate pred, Value *LHS, Value *RHS, - LLVMContext* Context) { + LLVMContext *Context) { if (Constant *CLHS = dyn_cast(LHS)) if (Constant *CRHS = dyn_cast(RHS)) return Context->getConstantExprCompare(pred, CLHS, CRHS); Modified: llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/LoopIndexSplit.cpp Mon Jul 6 18:00:19 2009 @@ -294,14 +294,14 @@ // Return V+1 static Value *getPlusOne(Value *V, bool Sign, Instruction *InsertPt, - LLVMContext* Context) { + LLVMContext *Context) { Constant *One = Context->getConstantInt(V->getType(), 1, Sign); return BinaryOperator::CreateAdd(V, One, "lsp", InsertPt); } // Return V-1 static Value *getMinusOne(Value *V, bool Sign, Instruction *InsertPt, - LLVMContext* Context) { + LLVMContext *Context) { Constant *One = Context->getConstantInt(V->getType(), 1, Sign); return BinaryOperator::CreateSub(V, One, "lsp", InsertPt); } Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Mon Jul 6 18:00:19 2009 @@ -200,7 +200,7 @@ /// static Instruction *LowerNegateToMultiply(Instruction *Neg, std::map, unsigned> &ValueRankMap, - LLVMContext* Context) { + LLVMContext *Context) { Constant *Cst = Context->getConstantIntAllOnesValue(Neg->getType()); Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg); @@ -458,7 +458,7 @@ /// reassociation. static Instruction *ConvertShiftToMul(Instruction *Shl, std::map, unsigned> &ValueRankMap, - LLVMContext* Context) { + LLVMContext *Context) { // If an operand of this shift is a reassociable multiply, or if the shift // is used by a reassociable multiply or add, turn into a multiply. if (isReassociableOp(Shl->getOperand(0), Instruction::Mul) || Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Mon Jul 6 18:00:19 2009 @@ -139,7 +139,7 @@ /// Constant Propagation. /// class SCCPSolver : public InstVisitor { - LLVMContext* Context; + LLVMContext *Context; DenseSet BBExecutable;// The basic blocks that are executable std::map ValueState; // The state each value is in. @@ -179,7 +179,7 @@ typedef std::pair Edge; DenseSet KnownFeasibleEdges; public: - void setContext(LLVMContext* C) { Context = C; } + void setContext(LLVMContext *C) { Context = C; } /// MarkBlockExecutable - This method can be used by clients to mark all of /// the blocks that are known to be intrinsically live in the processed unit. Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Mon Jul 6 18:00:19 2009 @@ -1261,7 +1261,7 @@ /// and stores would mutate the memory. static void MergeInType(const Type *In, uint64_t Offset, const Type *&VecTy, unsigned AllocaSize, const TargetData &TD, - LLVMContext* Context) { + LLVMContext *Context) { // If this could be contributing to a vector, analyze it. if (VecTy != Type::VoidTy) { // either null or a vector type. Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp Mon Jul 6 18:00:19 2009 @@ -58,7 +58,7 @@ /// ChangeToUnreachable - Insert an unreachable instruction before the specified /// instruction, making it and the rest of the code in the block dead. -static void ChangeToUnreachable(Instruction *I, LLVMContext* Context) { +static void ChangeToUnreachable(Instruction *I, LLVMContext *Context) { BasicBlock *BB = I->getParent(); // Loop over all of the successors, removing BB's entry from any PHI // nodes. @@ -97,7 +97,7 @@ static bool MarkAliveBlocks(BasicBlock *BB, SmallPtrSet &Reachable, - LLVMContext* Context) { + LLVMContext *Context) { SmallVector Worklist; Worklist.push_back(BB); Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Mon Jul 6 18:00:19 2009 @@ -325,7 +325,7 @@ /// mapping its operands through ValueMap if they are available. Constant *PruningFunctionCloner:: ConstantFoldMappedInstruction(const Instruction *I) { - LLVMContext* Context = I->getParent()->getContext(); + LLVMContext *Context = I->getParent()->getContext(); SmallVector Ops; for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) @@ -367,7 +367,7 @@ ClonedCodeInfo *CodeInfo, const TargetData *TD) { assert(NameSuffix && "NameSuffix cannot be null!"); - LLVMContext* Context = OldFunc->getContext(); + LLVMContext *Context = OldFunc->getContext(); #ifndef NDEBUG for (Function::const_arg_iterator II = OldFunc->arg_begin(), Modified: llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp Mon Jul 6 18:00:19 2009 @@ -238,7 +238,7 @@ DOUT << "inputs: " << inputs.size() << "\n"; DOUT << "outputs: " << outputs.size() << "\n"; - LLVMContext* Context = header->getContext(); + LLVMContext *Context = header->getContext(); // This function returns unsigned, outputs will go back by reference. switch (NumExitBlocks) { @@ -352,7 +352,7 @@ void CodeExtractor:: emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, Values &inputs, Values &outputs) { - LLVMContext* Context = codeReplacer->getContext(); + LLVMContext *Context = codeReplacer->getContext(); // Emit a call to the new function, passing in: *pointer to struct (if // aggregating parameters), or plan inputs and allocated memory for outputs Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/Local.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/Local.cpp Mon Jul 6 18:00:19 2009 @@ -263,7 +263,7 @@ /// too, recursively. void llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) { - LLVMContext* Context = PN->getParent()->getContext(); + LLVMContext *Context = PN->getParent()->getContext(); // We can remove a PHI if it is on a cycle in the def-use graph // where each node in the cycle has degree one, i.e. only one use, Modified: llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Mon Jul 6 18:00:19 2009 @@ -183,7 +183,7 @@ /// AliasSetTracker *AST; - LLVMContext* Context; + LLVMContext *Context; /// AllocaLookup - Reverse mapping of Allocas. /// @@ -216,7 +216,7 @@ public: PromoteMem2Reg(const std::vector &A, DominatorTree &dt, DominanceFrontier &df, AliasSetTracker *ast, - LLVMContext* C) + LLVMContext *C) : Allocas(A), DT(dt), DF(df), AST(ast), Context(C) {} void run(); @@ -999,7 +999,7 @@ /// void llvm::PromoteMemToReg(const std::vector &Allocas, DominatorTree &DT, DominanceFrontier &DF, - LLVMContext* Context, AliasSetTracker *AST) { + LLVMContext *Context, AliasSetTracker *AST) { // If there is nothing to do, bail out... if (Allocas.empty()) return; Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Jul 6 18:00:19 2009 @@ -1178,7 +1178,7 @@ /// ultimate destination. static bool FoldCondBranchOnPHI(BranchInst *BI) { BasicBlock *BB = BI->getParent(); - LLVMContext* Context = BB->getContext(); + LLVMContext *Context = BB->getContext(); PHINode *PN = dyn_cast(BI->getCondition()); // NOTE: we currently cannot transform this case if the PHI node is used // outside of the block. @@ -1276,7 +1276,7 @@ /// FoldTwoEntryPHINode - Given a BB that starts with the specified two-entry /// PHI node, see if we can eliminate it. static bool FoldTwoEntryPHINode(PHINode *PN) { - LLVMContext* Context = PN->getParent()->getContext(); + LLVMContext *Context = PN->getParent()->getContext(); // Ok, this is a two entry PHI node. Check to see if this is a simple "if // statement", which has a very simple dominance structure. Basically, we @@ -1609,7 +1609,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) { assert(PBI->isConditional() && BI->isConditional()); BasicBlock *BB = BI->getParent(); - LLVMContext* Context = BB->getContext(); + LLVMContext *Context = BB->getContext(); // If this block ends with a branch instruction, and if there is a // predecessor that ends on a branch of the same condition, make Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Mon Jul 6 18:00:19 2009 @@ -22,7 +22,7 @@ #include "llvm/ADT/SmallVector.h" using namespace llvm; -Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext* Context) { +Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext *Context) { Value *&VMSlot = VM[V]; if (VMSlot) return VMSlot; // Does it exist in the map yet? Modified: llvm/trunk/lib/VMCore/BasicBlock.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/BasicBlock.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/BasicBlock.cpp (original) +++ llvm/trunk/lib/VMCore/BasicBlock.cpp Mon Jul 6 18:00:19 2009 @@ -29,7 +29,7 @@ return 0; } -LLVMContext* BasicBlock::getContext() const { +LLVMContext *BasicBlock::getContext() const { return Parent ? Parent->getContext() : 0; } Modified: llvm/trunk/lib/VMCore/Function.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Function.cpp?rev=74878&r1=74877&r2=74878&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Function.cpp (original) +++ llvm/trunk/lib/VMCore/Function.cpp Mon Jul 6 18:00:19 2009 @@ -114,7 +114,7 @@ // Helper Methods in Function //===----------------------------------------------------------------------===// -LLVMContext* Function::getContext() const { +LLVMContext *Function::getContext() const { const Module* M = getParent(); if (M) return &M->getContext(); return 0; From dpatel at apple.com Mon Jul 6 18:11:08 2009 From: dpatel at apple.com (Devang Patel) Date: Mon, 06 Jul 2009 23:11:08 -0000 Subject: [llvm-commits] [llvm] r74879 - /llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp Message-ID: <200907062311.n66NB9Q6008275@zion.cs.uiuc.edu> Author: dpatel Date: Mon Jul 6 18:11:08 2009 New Revision: 74879 URL: http://llvm.org/viewvc/llvm-project?rev=74879&view=rev Log: Add FIXMEs. Modified: llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp Modified: llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp?rev=74879&r1=74878&r2=74879&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp (original) +++ llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp Mon Jul 6 18:11:08 2009 @@ -200,6 +200,7 @@ /// required initializations. void PIC16DbgInfo::BeginModule(Module &M) { // Emit file directive for module. + // FIXME : What if more then one CUs are present in a module ? GlobalVariable *CU = M.getNamedGlobal("llvm.dbg.compile_unit"); if (CU) { EmitDebugDirectives = true; @@ -321,6 +322,7 @@ E = M.getGlobalList().end(); I != E; I++) { // Structures and union declaration's debug info has llvm.dbg.composite // in its name. + // FIXME: Checking and relying on llvm.dbg.composite name is not a good idea. if(I->getName().find("llvm.dbg.composite") != std::string::npos) { GlobalVariable *GV = cast(I); DICompositeType CTy(GV); @@ -425,6 +427,7 @@ /// EmitVarDebugInfo - Emit debug information for all variables. /// void PIC16DbgInfo::EmitVarDebugInfo(Module &M) { + // FIXME : This anchor has been removed. GlobalVariable *Root = M.getGlobalVariable("llvm.dbg.global_variables"); if (!Root) return; From dpatel at apple.com Mon Jul 6 18:28:39 2009 From: dpatel at apple.com (Devang Patel) Date: Mon, 06 Jul 2009 23:28:39 -0000 Subject: [llvm-commits] [llvm] r74880 - /llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp Message-ID: <200907062328.n66NSdab008802@zion.cs.uiuc.edu> Author: dpatel Date: Mon Jul 6 18:28:36 2009 New Revision: 74880 URL: http://llvm.org/viewvc/llvm-project?rev=74880&view=rev Log: Avoid directly relying on llvm.dbg.compile_unit and llvm.dbg.global_variables. PIC16 developers, please verify. Thanks. Modified: llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp Modified: llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp?rev=74880&r1=74879&r2=74880&view=diff ============================================================================== --- llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp (original) +++ llvm/trunk/lib/Target/PIC16/PIC16DebugInfo.cpp Mon Jul 6 18:28:36 2009 @@ -200,9 +200,13 @@ /// required initializations. void PIC16DbgInfo::BeginModule(Module &M) { // Emit file directive for module. - // FIXME : What if more then one CUs are present in a module ? - GlobalVariable *CU = M.getNamedGlobal("llvm.dbg.compile_unit"); - if (CU) { + SmallVector CUs; + SmallVector GVs; + SmallVector SPs; + CollectDebugInfoAnchors(M, CUs, GVs, SPs); + if (!CUs.empty()) { + // FIXME : What if more then one CUs are present in a module ? + GlobalVariable *CU = CUs[0]; EmitDebugDirectives = true; SwitchToCU(CU); } @@ -427,32 +431,30 @@ /// EmitVarDebugInfo - Emit debug information for all variables. /// void PIC16DbgInfo::EmitVarDebugInfo(Module &M) { - // FIXME : This anchor has been removed. - GlobalVariable *Root = M.getGlobalVariable("llvm.dbg.global_variables"); - if (!Root) + SmallVector CUs; + SmallVector GVs; + SmallVector SPs; + CollectDebugInfoAnchors(M, CUs, GVs, SPs); + if (GVs.empty()) return; - Constant *RootC = cast(*Root->use_begin()); - for (Value::use_iterator UI = RootC->use_begin(), UE = Root->use_end(); - UI != UE; ++UI) { - for (Value::use_iterator UUI = UI->use_begin(), UUE = UI->use_end(); - UUI != UUE; ++UUI) { - DIGlobalVariable DIGV(cast(*UUI)); - DIType Ty = DIGV.getType(); - unsigned short TypeNo = 0; - bool HasAux = false; - int Aux[PIC16Dbg::AuxSize] = { 0 }; - std::string TagName = ""; - std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getName(); - PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName); - // Emit debug info only if type information is availaible. - if (TypeNo != PIC16Dbg::T_NULL) { - O << "\n\t.type " << VarName << ", " << TypeNo; - short ClassNo = getStorageClass(DIGV); - O << "\n\t.class " << VarName << ", " << ClassNo; - if (HasAux) - EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName); - } + for (SmallVector::iterator I = GVs.begin(), + E = GVs.end(); I != E; ++I) { + DIGlobalVariable DIGV(*I); + DIType Ty = DIGV.getType(); + unsigned short TypeNo = 0; + bool HasAux = false; + int Aux[PIC16Dbg::AuxSize] = { 0 }; + std::string TagName = ""; + std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getName(); + PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName); + // Emit debug info only if type information is availaible. + if (TypeNo != PIC16Dbg::T_NULL) { + O << "\n\t.type " << VarName << ", " << TypeNo; + short ClassNo = getStorageClass(DIGV); + O << "\n\t.class " << VarName << ", " << ClassNo; + if (HasAux) + EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName); } } O << "\n"; From dpatel at apple.com Mon Jul 6 18:40:50 2009 From: dpatel at apple.com (Devang Patel) Date: Mon, 06 Jul 2009 23:40:50 -0000 Subject: [llvm-commits] [llvm] r74881 - /llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Message-ID: <200907062340.n66NeobY009171@zion.cs.uiuc.edu> Author: dpatel Date: Mon Jul 6 18:40:48 2009 New Revision: 74881 URL: http://llvm.org/viewvc/llvm-project?rev=74881&view=rev Log: !"i" is a valid MDString. Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=74881&r1=74880&r2=74881&view=diff ============================================================================== --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original) +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Jul 6 18:40:48 2009 @@ -1010,7 +1010,6 @@ break; } case bitc::CST_CODE_MDSTRING: { - if (Record.size() < 2) return Error("Invalid MDSTRING record"); unsigned MDStringLength = Record.size(); SmallString<8> String; String.resize(MDStringLength); From dpatel at apple.com Mon Jul 6 18:44:33 2009 From: dpatel at apple.com (Devang Patel) Date: Mon, 06 Jul 2009 23:44:33 -0000 Subject: [llvm-commits] [llvm] r74882 - in /llvm/trunk: include/llvm/CodeGen/ValueTypes.h include/llvm/CodeGen/ValueTypes.td utils/TableGen/CodeGenTarget.cpp utils/TableGen/IntrinsicEmitter.cpp Message-ID: <200907062344.n66NiXQ3009273@zion.cs.uiuc.edu> Author: dpatel Date: Mon Jul 6 18:44:32 2009 New Revision: 74882 URL: http://llvm.org/viewvc/llvm-project?rev=74882&view=rev Log: Add new ValueType for metadata. Modified: llvm/trunk/include/llvm/CodeGen/ValueTypes.h llvm/trunk/include/llvm/CodeGen/ValueTypes.td llvm/trunk/utils/TableGen/CodeGenTarget.cpp llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp Modified: llvm/trunk/include/llvm/CodeGen/ValueTypes.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ValueTypes.h?rev=74882&r1=74881&r2=74882&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/ValueTypes.h (original) +++ llvm/trunk/include/llvm/CodeGen/ValueTypes.h Mon Jul 6 18:44:32 2009 @@ -83,6 +83,9 @@ // This value must be a multiple of 32. MAX_ALLOWED_VALUETYPE = 64, + // Metadata - This is MDNode or MDString. + Metadata = 251, + // iPTRAny - An int value the size of the pointer of the current // target to any address space. This must only be used internal to // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR. Modified: llvm/trunk/include/llvm/CodeGen/ValueTypes.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ValueTypes.td?rev=74882&r1=74881&r2=74882&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/ValueTypes.td (original) +++ llvm/trunk/include/llvm/CodeGen/ValueTypes.td Mon Jul 6 18:44:32 2009 @@ -57,7 +57,9 @@ def v8f32 : ValueType<256, 33>; // 8 x f32 vector value def v2f64 : ValueType<128, 34>; // 2 x f64 vector value def v4f64 : ValueType<256, 35>; // 4 x f64 vector value - + +def MetadataVT: ValueType<0, 251>; // Metadata + // Pseudo valuetype mapped to the current pointer size to any address space. // Should only be used in TableGen. def iPTRAny : ValueType<0, 252>; Modified: llvm/trunk/utils/TableGen/CodeGenTarget.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=74882&r1=74881&r2=74882&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/CodeGenTarget.cpp (original) +++ llvm/trunk/utils/TableGen/CodeGenTarget.cpp Mon Jul 6 18:44:32 2009 @@ -118,6 +118,7 @@ case MVT::v4f64: return "MVT::v4f64"; case MVT::v3i32: return "MVT::v3i32"; case MVT::v3f32: return "MVT::v3f32"; + case MVT::Metadata: return "MVT::Metadata"; case MVT::iPTR: return "MVT::iPTR"; case MVT::iPTRAny: return "MVT::iPTRAny"; default: assert(0 && "ILLEGAL VALUE TYPE!"); return ""; Modified: llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp?rev=74882&r1=74881&r2=74882&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/IntrinsicEmitter.cpp Mon Jul 6 18:44:32 2009 @@ -159,6 +159,8 @@ OS << "Type::PPC_FP128Ty"; } else if (VT == MVT::isVoid) { OS << "Type::VoidTy"; + } else if (VT == MVT::Metadata) { + OS << "Type::MetadataTy"; } else { assert(false && "Unsupported ValueType!"); } From dpatel at apple.com Mon Jul 6 18:46:03 2009 From: dpatel at apple.com (Devang Patel) Date: Mon, 06 Jul 2009 23:46:03 -0000 Subject: [llvm-commits] [llvm] r74883 - /llvm/trunk/include/llvm/CodeGen/MachineOperand.h Message-ID: <200907062346.n66Nk4Zo009321@zion.cs.uiuc.edu> Author: dpatel Date: Mon Jul 6 18:46:02 2009 New Revision: 74883 URL: http://llvm.org/viewvc/llvm-project?rev=74883&view=rev Log: Add isMetadata() to check metadata operand. Modified: llvm/trunk/include/llvm/CodeGen/MachineOperand.h Modified: llvm/trunk/include/llvm/CodeGen/MachineOperand.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineOperand.h?rev=74883&r1=74882&r2=74883&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineOperand.h (original) +++ llvm/trunk/include/llvm/CodeGen/MachineOperand.h Mon Jul 6 18:46:02 2009 @@ -164,6 +164,8 @@ bool isGlobal() const { return OpKind == MO_GlobalAddress; } /// isSymbol - Tests if this is a MO_ExternalSymbol operand. bool isSymbol() const { return OpKind == MO_ExternalSymbol; } + /// isMetadata - Tests if this is a MO_Metadata operand. + bool isMetadata() const { return OpKind == MO_Metadata; } //===--------------------------------------------------------------------===// // Accessors for Register Operands @@ -325,7 +327,7 @@ } void setOffset(int64_t Offset) { - assert((isGlobal() || isSymbol() || isCPI()) && + assert((isGlobal() || isSymbol() || isCPI() || isMetadata()) && "Wrong MachineOperand accessor"); Contents.OffsetedInfo.Offset = Offset; } From dalej at apple.com Mon Jul 6 19:18:55 2009 From: dalej at apple.com (Dale Johannesen) Date: Tue, 07 Jul 2009 00:18:55 -0000 Subject: [llvm-commits] [llvm] r74886 - /llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Message-ID: <200907070018.n670IvCH010224@zion.cs.uiuc.edu> Author: johannes Date: Mon Jul 6 19:18:49 2009 New Revision: 74886 URL: http://llvm.org/viewvc/llvm-project?rev=74886&view=rev Log: Don't accept globals as matching 'i' constraint in PIC modes (in accordance with existing comment). gcc.apple/asm-block-25.c Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=74886&r1=74885&r2=74886&view=diff ============================================================================== --- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original) +++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Mon Jul 6 19:18:49 2009 @@ -8803,10 +8803,15 @@ continue; } } - + // Otherwise, this isn't something we can handle, reject it. return; } + // If we require an extra load to get this address, as in PIC mode, we + // can't accept it. + if (Subtarget->GVRequiresExtraLoad(GA->getGlobal(), + getTargetMachine(), false)) + return; if (hasMemory) Op = LowerGlobalAddress(GA->getGlobal(), Op.getDebugLoc(), Offset, DAG); From rnk at mit.edu Mon Jul 6 17:45:57 2009 From: rnk at mit.edu (Reid Kleckner) Date: Mon, 6 Jul 2009 15:45:57 -0700 Subject: [llvm-commits] [patch] Minor X86CodeEmitter Memory Foot Reduction In-Reply-To: <1DDE1F32B1CA4138A16F4434BF65EB36@HPLAPTOP> References: <9719867c0907061057w1c3fc45em92b05528c88aa684@mail.gmail.com> <07E0D0CF-5038-4B7C-AB6F-DA5A5206A4E2@apple.com> <275e64e40907061253y1729940atc4818e9fa244ac5e@mail.gmail.com> <0772BCC55D8C48209386001E95355240@HPLAPTOP> <2754CA63-0EF0-41B7-8217-F464354C6A87@apple.com> <1DDE1F32B1CA4138A16F4434BF65EB36@HPLAPTOP> Message-ID: <9a9942200907061545l60ac78aamfda65ead1e479916@mail.gmail.com> > Templating allows us to have mutiple types of MachineCodeEmitters, the > JITCodeEmitter, and the ObjectCodeEmitter, and any other kind of CodeEmitter > we require in the future, e.g. Reid Kleckner' requirements to combine JIT > and GDB. It allows these emiiters to be efficient and be inlined functions. > If you study the code you will see what I mean. FWIW, I've hacked my way around any awkwardnesses in the current API. This whole JIT-to-GDB-through-ELF thing is a hack, and I wouldn't consider my use case too much in designing the API. Besides, I'm learning that the right way to do this might be to implement a custom binary file descriptor for GDB to use so that I don't actually have to generate ELF. Reid From clattner at apple.com Mon Jul 6 20:09:32 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 18:09:32 -0700 Subject: [llvm-commits] [llvm] r74883 - /llvm/trunk/include/llvm/CodeGen/MachineOperand.h In-Reply-To: <200907062346.n66Nk4Zo009321@zion.cs.uiuc.edu> References: <200907062346.n66Nk4Zo009321@zion.cs.uiuc.edu> Message-ID: On Jul 6, 2009, at 4:46 PM, Devang Patel wrote: > Author: dpatel > Date: Mon Jul 6 18:46:02 2009 > New Revision: 74883 > > URL: http://llvm.org/viewvc/llvm-project?rev=74883&view=rev > Log: > Add isMetadata() to check metadata operand. Hey Devang, What is your plan to use MetaData MachineInstr operands? Can you elaborate on how you plan to use these? -Chris > > Modified: > llvm/trunk/include/llvm/CodeGen/MachineOperand.h > > Modified: llvm/trunk/include/llvm/CodeGen/MachineOperand.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineOperand.h?rev=74883&r1=74882&r2=74883&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/include/llvm/CodeGen/MachineOperand.h (original) > +++ llvm/trunk/include/llvm/CodeGen/MachineOperand.h Mon Jul 6 > 18:46:02 2009 > @@ -164,6 +164,8 @@ > bool isGlobal() const { return OpKind == MO_GlobalAddress; } > /// isSymbol - Tests if this is a MO_ExternalSymbol operand. > bool isSymbol() const { return OpKind == MO_ExternalSymbol; } > + /// isMetadata - Tests if this is a MO_Metadata operand. > + bool isMetadata() const { return OpKind == MO_Metadata; } > > // > = > = > =-------------------------------------------------------------------- > ===// > // Accessors for Register Operands > @@ -325,7 +327,7 @@ > } > > void setOffset(int64_t Offset) { > - assert((isGlobal() || isSymbol() || isCPI()) && > + assert((isGlobal() || isSymbol() || isCPI() || isMetadata()) && > "Wrong MachineOperand accessor"); > Contents.OffsetedInfo.Offset = Offset; > } > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From evan.cheng at apple.com Mon Jul 6 20:16:42 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 07 Jul 2009 01:16:42 -0000 Subject: [llvm-commits] [llvm] r74888 - /llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp Message-ID: <200907070116.n671GgMm011973@zion.cs.uiuc.edu> Author: evancheng Date: Mon Jul 6 20:16:41 2009 New Revision: 74888 URL: http://llvm.org/viewvc/llvm-project?rev=74888&view=rev Log: 80 col violation. Modified: llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp Modified: llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp?rev=74888&r1=74887&r2=74888&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp Mon Jul 6 20:16:41 2009 @@ -590,8 +590,8 @@ // Note the new unconditional branch is not being recorded. // There doesn't seem to be meaningful DebugInfo available; this doesn't // correspond to anything in the source. - BuildMI(OrigBB, DebugLoc::getUnknownLoc(), - TII->get(isThumb ? ((isThumb2) ? ARM::t2B : ARM::tB) : ARM::B)).addMBB(NewBB); + unsigned Opc = isThumb ? (isThumb2 ? ARM::t2B : ARM::tB) : ARM::B; + BuildMI(OrigBB, DebugLoc::getUnknownLoc(), TII->get(Opc)).addMBB(NewBB); NumSplit++; // Update the CFG. All succs of OrigBB are now succs of NewBB. From evan.cheng at apple.com Mon Jul 6 20:17:28 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 07 Jul 2009 01:17:28 -0000 Subject: [llvm-commits] [llvm] r74889 - in /llvm/trunk: lib/Target/ARM/ARMISelDAGToDAG.cpp lib/Target/ARM/ARMISelLowering.cpp lib/Target/ARM/ARMInstrThumb2.td test/CodeGen/Thumb2/thumb2-mulhi.ll test/CodeGen/Thumb2/thumb2-smla.ll test/CodeGen/Thumb2/thumb2-smul.ll Message-ID: <200907070117.n671HSFE012012@zion.cs.uiuc.edu> Author: evancheng Date: Mon Jul 6 20:17:28 2009 New Revision: 74889 URL: http://llvm.org/viewvc/llvm-project?rev=74889&view=rev Log: Add some more Thumb2 multiplication instructions. Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-mulhi.ll llvm/trunk/test/CodeGen/Thumb2/thumb2-smla.ll llvm/trunk/test/CodeGen/Thumb2/thumb2-smul.ll Modified: llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Modified: llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp?rev=74889&r1=74888&r2=74889&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp Mon Jul 6 20:17:28 2009 @@ -923,7 +923,7 @@ break; } case ISD::MUL: - if (Subtarget->isThumb()) + if (Subtarget->isThumb1Only()) break; if (ConstantSDNode *C = dyn_cast(Op.getOperand(1))) { unsigned RHSV = C->getZExtValue(); @@ -953,20 +953,37 @@ Op.getOperand(0), getAL(CurDAG), CurDAG->getRegister(0, MVT::i32)); case ISD::UMUL_LOHI: { - SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1), + if (Subtarget->isThumb1Only()) + break; + if (Subtarget->isThumb()) { + SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1), + getAL(CurDAG), CurDAG->getRegister(0, MVT::i32), + CurDAG->getRegister(0, MVT::i32) }; + return CurDAG->getTargetNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4); + } else { + SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1), getAL(CurDAG), CurDAG->getRegister(0, MVT::i32), CurDAG->getRegister(0, MVT::i32) }; - return CurDAG->getTargetNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5); + return CurDAG->getTargetNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5); + } } case ISD::SMUL_LOHI: { - SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1), + if (Subtarget->isThumb1Only()) + break; + if (Subtarget->isThumb()) { + SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1), + getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) }; + return CurDAG->getTargetNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4); + } else { + SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1), getAL(CurDAG), CurDAG->getRegister(0, MVT::i32), CurDAG->getRegister(0, MVT::i32) }; - return CurDAG->getTargetNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5); + return CurDAG->getTargetNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5); + } } case ISD::LOAD: { SDNode *ResNode = 0; - if (Subtarget->isThumb2()) + if (Subtarget->isThumb() && Subtarget->hasThumb2()) ResNode = SelectT2IndexedLoad(Op); else ResNode = SelectARMIndexedLoad(Op); Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=74889&r1=74888&r2=74889&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Mon Jul 6 20:17:28 2009 @@ -246,7 +246,7 @@ } // i64 operation support. - if (Subtarget->isThumb()) { + if (Subtarget->isThumb1Only()) { setOperationAction(ISD::MUL, MVT::i64, Expand); setOperationAction(ISD::MULHU, MVT::i32, Expand); setOperationAction(ISD::MULHS, MVT::i32, Expand); @@ -255,7 +255,7 @@ } else { setOperationAction(ISD::MUL, MVT::i64, Expand); setOperationAction(ISD::MULHU, MVT::i32, Expand); - if (!Subtarget->hasV6Ops()) + if (!Subtarget->isThumb() && !Subtarget->hasV6Ops()) setOperationAction(ISD::MULHS, MVT::i32, Expand); } setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); @@ -3034,7 +3034,7 @@ bool isInc; bool isLegal = false; - if (Subtarget->isThumb2()) + if (Subtarget->isThumb() && Subtarget->hasThumb2()) isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, Offset, isInc, DAG); else @@ -3071,7 +3071,7 @@ bool isInc; bool isLegal = false; - if (Subtarget->isThumb2()) + if (Subtarget->isThumb() && Subtarget->hasThumb2()) isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, isInc, DAG); else Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td?rev=74889&r1=74888&r2=74889&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Mon Jul 6 20:17:28 2009 @@ -838,7 +838,113 @@ "mls", " $dst, $a, $b, $c", [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>; -// FIXME: SMULL, etc. +// Extra precision multiplies with low / high results +let neverHasSideEffects = 1 in { +let isCommutable = 1 in { +def t2SMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), + "smull", " $ldst, $hdst, $a, $b", []>; + +def t2UMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), + "umull", " $ldst, $hdst, $a, $b", []>; +} + +// Multiply + accumulate +def t2SMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), + "smlal", " $ldst, $hdst, $a, $b", []>; + +def t2UMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), + "umlal", " $ldst, $hdst, $a, $b", []>; + +def t2UMAAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), + "umaal", " $ldst, $hdst, $a, $b", []>; +} // neverHasSideEffects + +// Most significant word multiply +def t2SMMUL : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), + "smmul", " $dst, $a, $b", + [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>; + +def t2SMMLA : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), + "smmla", " $dst, $a, $b, $c", + [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>; + + +def t2SMMLS : T2I <(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), + "smmls", " $dst, $a, $b, $c", + [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>; + +multiclass T2I_smul { + def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), + !strconcat(opc, "bb"), " $dst, $a, $b", + [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16), + (sext_inreg GPR:$b, i16)))]>; + + def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), + !strconcat(opc, "bt"), " $dst, $a, $b", + [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16), + (sra GPR:$b, (i32 16))))]>; + + def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), + !strconcat(opc, "tb"), " $dst, $a, $b", + [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)), + (sext_inreg GPR:$b, i16)))]>; + + def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), + !strconcat(opc, "tt"), " $dst, $a, $b", + [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)), + (sra GPR:$b, (i32 16))))]>; + + def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), + !strconcat(opc, "wb"), " $dst, $a, $b", + [(set GPR:$dst, (sra (opnode GPR:$a, + (sext_inreg GPR:$b, i16)), (i32 16)))]>; + + def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), + !strconcat(opc, "wt"), " $dst, $a, $b", + [(set GPR:$dst, (sra (opnode GPR:$a, + (sra GPR:$b, (i32 16))), (i32 16)))]>; +} + + +multiclass T2I_smla { + def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), + !strconcat(opc, "bb"), " $dst, $a, $b, $acc", + [(set GPR:$dst, (add GPR:$acc, + (opnode (sext_inreg GPR:$a, i16), + (sext_inreg GPR:$b, i16))))]>; + + def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), + !strconcat(opc, "bt"), " $dst, $a, $b, $acc", + [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16), + (sra GPR:$b, (i32 16)))))]>; + + def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), + !strconcat(opc, "tb"), " $dst, $a, $b, $acc", + [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)), + (sext_inreg GPR:$b, i16))))]>; + + def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), + !strconcat(opc, "tt"), " $dst, $a, $b, $acc", + [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)), + (sra GPR:$b, (i32 16)))))]>; + + def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), + !strconcat(opc, "wb"), " $dst, $a, $b, $acc", + [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a, + (sext_inreg GPR:$b, i16)), (i32 16))))]>; + + def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), + !strconcat(opc, "wt"), " $dst, $a, $b, $acc", + [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a, + (sra GPR:$b, (i32 16))), (i32 16))))]>; +} + +defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>; +defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>; + +// TODO: Halfword multiple accumulate long: SMLAL +// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD + //===----------------------------------------------------------------------===// // Misc. Arithmetic Instructions. Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-mulhi.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-mulhi.ll?rev=74889&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb2/thumb2-mulhi.ll (added) +++ llvm/trunk/test/CodeGen/Thumb2/thumb2-mulhi.ll Mon Jul 6 20:17:28 2009 @@ -0,0 +1,20 @@ +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep smmul | count 1 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep umull | count 1 + +define i32 @smulhi(i32 %x, i32 %y) { + %tmp = sext i32 %x to i64 ; [#uses=1] + %tmp1 = sext i32 %y to i64 ; [#uses=1] + %tmp2 = mul i64 %tmp1, %tmp ; [#uses=1] + %tmp3 = lshr i64 %tmp2, 32 ; [#uses=1] + %tmp3.upgrd.1 = trunc i64 %tmp3 to i32 ; [#uses=1] + ret i32 %tmp3.upgrd.1 +} + +define i32 @umulhi(i32 %x, i32 %y) { + %tmp = zext i32 %x to i64 ; [#uses=1] + %tmp1 = zext i32 %y to i64 ; [#uses=1] + %tmp2 = mul i64 %tmp1, %tmp ; [#uses=1] + %tmp3 = lshr i64 %tmp2, 32 ; [#uses=1] + %tmp3.upgrd.2 = trunc i64 %tmp3 to i32 ; [#uses=1] + ret i32 %tmp3.upgrd.2 +} Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-smla.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-smla.ll?rev=74889&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb2/thumb2-smla.ll (added) +++ llvm/trunk/test/CodeGen/Thumb2/thumb2-smla.ll Mon Jul 6 20:17:28 2009 @@ -0,0 +1,10 @@ +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | \ +; RUN: grep smlabt | count 1 + +define i32 @f3(i32 %a, i16 %x, i32 %y) { + %tmp = sext i16 %x to i32 ; [#uses=1] + %tmp2 = ashr i32 %y, 16 ; [#uses=1] + %tmp3 = mul i32 %tmp2, %tmp ; [#uses=1] + %tmp5 = add i32 %tmp3, %a ; [#uses=1] + ret i32 %tmp5 +} Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-smul.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-smul.ll?rev=74889&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb2/thumb2-smul.ll (added) +++ llvm/trunk/test/CodeGen/Thumb2/thumb2-smul.ll Mon Jul 6 20:17:28 2009 @@ -0,0 +1,23 @@ +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | \ +; RUN: grep smulbt | count 1 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | \ +; RUN: grep smultt | count 1 + + at x = weak global i16 0 ; [#uses=1] + at y = weak global i16 0 ; [#uses=0] + +define i32 @f1(i32 %y) { + %tmp = load i16* @x ; [#uses=1] + %tmp1 = add i16 %tmp, 2 ; [#uses=1] + %tmp2 = sext i16 %tmp1 to i32 ; [#uses=1] + %tmp3 = ashr i32 %y, 16 ; [#uses=1] + %tmp4 = mul i32 %tmp2, %tmp3 ; [#uses=1] + ret i32 %tmp4 +} + +define i32 @f2(i32 %x, i32 %y) { + %tmp1 = ashr i32 %x, 16 ; [#uses=1] + %tmp3 = ashr i32 %y, 16 ; [#uses=1] + %tmp4 = mul i32 %tmp3, %tmp1 ; [#uses=1] + ret i32 %tmp4 +} From devang.patel at gmail.com Mon Jul 6 20:34:01 2009 From: devang.patel at gmail.com (Devang Patel) Date: Mon, 6 Jul 2009 18:34:01 -0700 Subject: [llvm-commits] [llvm] r74883 - /llvm/trunk/include/llvm/CodeGen/MachineOperand.h In-Reply-To: References: <200907062346.n66Nk4Zo009321@zion.cs.uiuc.edu> Message-ID: <352a1fb20907061834m1e2f102m851dc27d592105d1@mail.gmail.com> Chris, On Mon, Jul 6, 2009 at 6:09 PM, Chris Lattner wrote: > > On Jul 6, 2009, at 4:46 PM, Devang Patel wrote: > >> Author: dpatel >> Date: Mon Jul ?6 18:46:02 2009 >> New Revision: 74883 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=74883&view=rev >> Log: >> Add isMetadata() to check metadata operand. > > Hey Devang, > > What is your plan to use MetaData MachineInstr operands? ?Can you > elaborate on how you plan to use these? My near term goal is to replace all Global Variables used to encode debug info (llvm.dbg.*) by MDNodes. As a step towards this goal, I need MetaData as machine instruction operand to handle printDeclare(). - Devang From mai4 at uiuc.edu Mon Jul 6 22:42:28 2009 From: mai4 at uiuc.edu (Haohui Mai) Date: Tue, 07 Jul 2009 03:42:28 -0000 Subject: [llvm-commits] [poolalloc] r74891 - /poolalloc/trunk/include/dsa/DataStructure.h Message-ID: <200907070342.n673gTXp016001@zion.cs.uiuc.edu> Author: mai4 Date: Mon Jul 6 22:42:27 2009 New Revision: 74891 URL: http://llvm.org/viewvc/llvm-project?rev=74891&view=rev Log: Add the declaration of Steensgaard DSA pass. Modified: poolalloc/trunk/include/dsa/DataStructure.h Modified: poolalloc/trunk/include/dsa/DataStructure.h URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=74891&r1=74890&r2=74891&view=diff ============================================================================== --- poolalloc/trunk/include/dsa/DataStructure.h (original) +++ poolalloc/trunk/include/dsa/DataStructure.h Mon Jul 6 22:42:27 2009 @@ -410,6 +410,46 @@ {} }; +/// SteensgaardsDataStructures - Analysis that computes a context-insensitive +/// data structure graphs for the whole program. +/// +class SteensgaardDataStructures : public DataStructures { + DSGraph * ResultGraph; + DataStructures * DS; + void ResolveFunctionCall(const Function *F, const DSCallSite &Call, + DSNodeHandle &RetVal); + bool runOnModuleInternal(Module &M); + +public: + static char ID; + SteensgaardDataStructures() : + DataStructures((intptr_t)&ID, "steensgaard."), + ResultGraph(NULL) {} + ~SteensgaardDataStructures(); + virtual bool runOnModule(Module &M); + virtual void releaseMyMemory(); + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); + AU.setPreservesAll(); + } + + /// getDSGraph - Return the data structure graph for the specified function. + /// + DSGraph *getDSGraph(const Function &F) const { + return ResultGraph; + } + + /// getDSGraph - Return the data structure graph for the whole program. + /// + DSGraph *getResultGraph() const { + return ResultGraph; + } + + void print(OStream O, const Module *M) const; + void print(std::ostream &O, const Module *M) const; + +}; } // End llvm namespace From mai4 at uiuc.edu Mon Jul 6 23:18:07 2009 From: mai4 at uiuc.edu (Haohui Mai) Date: Tue, 07 Jul 2009 04:18:07 -0000 Subject: [llvm-commits] [poolalloc] r74892 - in /poolalloc/trunk: include/poolalloc/PoolAllocate.h lib/PoolAllocate/PAMultipleGlobalPool.cpp Message-ID: <200907070418.n674I8ix017137@zion.cs.uiuc.edu> Author: mai4 Date: Mon Jul 6 23:18:07 2009 New Revision: 74892 URL: http://llvm.org/viewvc/llvm-project?rev=74892&view=rev Log: Context-insensitive pool allocation. Added: poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=74892&r1=74891&r2=74892&view=diff ============================================================================== --- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original) +++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Mon Jul 6 23:18:07 2009 @@ -25,7 +25,9 @@ #include "llvm/Support/CallSite.h" #include "llvm/ADT/EquivalenceClasses.h" #include "llvm/ADT/VectorExtras.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/Support/CommandLine.h" + #include "dsa/DataStructure.h" #include "poolalloc/ADT/HashExtras.h" #include "poolalloc/Config/config.h" @@ -461,6 +463,36 @@ } }; -} +/// PoolAllocateMultipleGlobalPool +/// Context-insensitive pool allocation. It pool allocates objects into multiple +/// global pools. It does not need to rewrite the functions declarations, which +/// simplifies the implementation a lot. Technically, PoolAllocateSimple, which +/// pool allocates everything into a single global pool, is a +/// special case of PoolAllocateMultipleGlobalPool. +/// +/// It requires some work on code clean up to make these two pass integrate +/// nicely. +class PoolAllocateMultipleGlobalPool : public PoolAllocate { + TargetData * TD; + void ProcessFunctionBodySimple(Function& F, TargetData & TD); + /// Mapping between DSNodes and Pool descriptors. For this pass, it is a + /// one-to-one relationship. + DenseMap PoolMap; +public: + static char ID; + PoolAllocateMultipleGlobalPool(bool passAllArgs=false, bool SAFECode = true) + : PoolAllocate (passAllArgs, SAFECode, (intptr_t)&ID) {} + ~PoolAllocateMultipleGlobalPool(); + virtual void getAnalysisUsage(AnalysisUsage &AU) const; + virtual bool runOnModule(Module &M); + void CreateGlobalPool(unsigned RecSize, unsigned Align, + Module& M); + + virtual Value * getGlobalPool (const DSNode * Node); + virtual Value * getPool (const DSNode * N, Function & F); + +}; + +} #endif Added: poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp?rev=74892&view=auto ============================================================================== --- poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp (added) +++ poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp Mon Jul 6 23:18:07 2009 @@ -0,0 +1,352 @@ +//===-- PAMultipleGlobalPool.cpp - Multiple Global Pool Allocation Pass ---===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// A minimal poolallocator that assignes all allocation to multiple global +// pools. +// +// +//===----------------------------------------------------------------------===// + +#define DEBUG_TYPE "poolalloc" + +#include "dsa/DataStructure.h" +#include "dsa/DSGraph.h" +#include "dsa/CallTargets.h" +#include "poolalloc/PoolAllocate.h" +#include "llvm/Constants.h" +#include "llvm/DerivedTypes.h" +#include "llvm/Instructions.h" +#include "llvm/Module.h" +#include "llvm/Constants.h" +#include "llvm/Support/CFG.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" +#include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/ADT/DepthFirstIterator.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/Timer.h" + +#include + +using namespace llvm; +using namespace PA; + +char llvm::PoolAllocateMultipleGlobalPool::ID = 0; + +namespace { + RegisterPass + X("poolalloc-multi-global-pool", "Pool allocate objects into multiple global pools"); + + RegisterAnalysisGroup PAGroup1(X); +} + +static inline Value * +castTo (Value * V, const Type * Ty, std::string Name, Instruction * InsertPt) { + // + // Don't bother creating a cast if it's already the correct type. + // + if (V->getType() == Ty) + return V; + + // + // If it's a constant, just create a constant expression. + // + if (Constant * C = dyn_cast(V)) { + Constant * CE = ConstantExpr::getZExtOrBitCast (C, Ty); + return CE; + } + + // + // Otherwise, insert a cast instruction. + // + return CastInst::CreateZExtOrBitCast (V, Ty, Name, InsertPt); +} + +void PoolAllocateMultipleGlobalPool::getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); + AU.addRequired(); + // It is a big lie. + AU.setPreservesAll(); +} + +bool PoolAllocateMultipleGlobalPool::runOnModule(Module &M) { + if (M.begin() == M.end()) return false; + Graphs = &getAnalysis(); + assert (Graphs && "No DSA pass available!\n"); + + TargetData & TD = getAnalysis(); + + // Add the pool* prototypes to the module + AddPoolPrototypes(&M); + + // + // Create the global pool. + // + CreateGlobalPool(32, 1, M); + + // + // Now that all call targets are available, rewrite the function bodies of the + // clones. + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + std::string name = I->getName(); + if (name == "poolalloc.init") continue; + if (!(I->isDeclaration())) + ProcessFunctionBodySimple(*I, TD); + } + + return true; +} + +void +PoolAllocateMultipleGlobalPool::ProcessFunctionBodySimple (Function& F, TargetData & TD) { + std::vector toDelete; + std::vector Returns; + + // + // Create a silly Function Info structure for this function. + // + FuncInfo FInfo(F); + FunctionInfo.insert (std::make_pair(&F, FInfo)); + + // + // Get the DSGraph for this function. + // + DSGraph* ECG = Graphs->getDSGraph(F); + + for (Function::iterator i = F.begin(), e = F.end(); i != e; ++i) + for (BasicBlock::iterator ii = i->begin(), ee = i->end(); ii != ee; ++ii) { + if (MallocInst * MI = dyn_cast(ii)) { + // Associate the global pool decriptor with the DSNode + DSNode * Node = ECG->getNodeForValue(MI).getNode(); + GlobalVariable * Pool = PoolMap[Node]; + FInfo.PoolDescriptors.insert(std::make_pair(Node,Pool)); + + // Mark the malloc as an instruction to delete + toDelete.push_back(ii); + + // Create instructions to calculate the size of the allocation in + // bytes + Value * AllocSize; + if (MI->isArrayAllocation()) { + Value * NumElements = MI->getArraySize(); + Value * ElementSize = ConstantInt::get (Type::Int32Ty, + TD.getTypeAllocSize(MI->getAllocatedType())); + AllocSize = BinaryOperator::Create (Instruction::Mul, + ElementSize, + NumElements, + "sizetmp", + MI); + } else { + AllocSize = ConstantInt::get (Type::Int32Ty, + TD.getTypeAllocSize(MI->getAllocatedType())); + } + + Value* args[] = {Pool, AllocSize}; + Instruction* x = CallInst::Create(PoolAlloc, &args[0], &args[2], MI->getName(), ii); + ii->replaceAllUsesWith(CastInst::CreatePointerCast(x, ii->getType(), "", ii)); + } else if (CallInst * CI = dyn_cast(ii)) { + CallSite CS(CI); + Function *CF = CS.getCalledFunction(); + if (ConstantExpr *CE = dyn_cast(CS.getCalledValue())) + if (CE->getOpcode() == Instruction::BitCast && + isa(CE->getOperand(0))) + CF = cast(CE->getOperand(0)); + if (CF && (CF->isDeclaration()) && (CF->getName() == "realloc")) { + // Associate the global pool decriptor with the DSNode + DSNode * Node = ECG->getNodeForValue(CI).getNode(); + GlobalVariable * Pool = PoolMap[Node]; + + FInfo.PoolDescriptors.insert(std::make_pair(Node,Pool)); + + // Mark the realloc as an instruction to delete + toDelete.push_back(ii); + + // Insertion point - Instruction before which all our instructions go + Instruction *InsertPt = CI; + Value *OldPtr = CS.getArgument(0); + Value *Size = CS.getArgument(1); + + // Ensure the size and pointer arguments are of the correct type + if (Size->getType() != Type::Int32Ty) + Size = CastInst::CreateIntegerCast (Size, + Type::Int32Ty, + false, + Size->getName(), + InsertPt); + + static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty); + if (OldPtr->getType() != VoidPtrTy) + OldPtr = CastInst::CreatePointerCast (OldPtr, + VoidPtrTy, + OldPtr->getName(), + InsertPt); + + std::string Name = CI->getName(); CI->setName(""); + Value* Opts[3] = {Pool, OldPtr, Size}; + Instruction *V = CallInst::Create (PoolRealloc, + Opts, + Opts + 3, + Name, + InsertPt); + Instruction *Casted = V; + if (V->getType() != CI->getType()) + Casted = CastInst::CreatePointerCast (V, CI->getType(), V->getName(), InsertPt); + + // Update def-use info + CI->replaceAllUsesWith(Casted); + } else if (CF && (CF->isDeclaration()) && (CF->getName() == "calloc")) { + // Associate the global pool decriptor with the DSNode + DSNode * Node = ECG->getNodeForValue(CI).getNode(); + GlobalVariable * Pool = PoolMap[Node]; + FInfo.PoolDescriptors.insert(std::make_pair(Node,Pool)); + + // Mark the realloc as an instruction to delete + toDelete.push_back(ii); + + // Insertion point - Instruction before which all our instructions go + Instruction *InsertPt = CI; + Value *NumElements = CS.getArgument(0); + Value *Size = CS.getArgument(1); + + // Ensure the size and pointer arguments are of the correct type + if (Size->getType() != Type::Int32Ty) + Size = CastInst::CreateIntegerCast (Size, + Type::Int32Ty, + false, + Size->getName(), + InsertPt); + + if (NumElements->getType() != Type::Int32Ty) + NumElements = CastInst::CreateIntegerCast (Size, + Type::Int32Ty, + false, + NumElements->getName(), + InsertPt); + + std::string Name = CI->getName(); CI->setName(""); + Value* Opts[3] = {Pool, NumElements, Size}; + Instruction *V = CallInst::Create (PoolCalloc, + Opts, + Opts + 3, + Name, + InsertPt); + + Instruction *Casted = V; + if (V->getType() != CI->getType()) + Casted = CastInst::CreatePointerCast (V, CI->getType(), V->getName(), InsertPt); + + // Update def-use info + CI->replaceAllUsesWith(Casted); + } else if (CF && (CF->isDeclaration()) && (CF->getName() == "strdup")) { + // Associate the global pool decriptor with the DSNode + DSNode * Node = ECG->getNodeForValue(CI).getNode(); + GlobalVariable * Pool = PoolMap[Node]; + FInfo.PoolDescriptors.insert(std::make_pair(Node, Pool)); + + // Mark the realloc as an instruction to delete + toDelete.push_back(ii); + + // Insertion point - Instruction before which all our instructions go + Instruction *InsertPt = CI; + Value *OldPtr = CS.getArgument(0); + + // Ensure the size and pointer arguments are of the correct type + static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty); + if (OldPtr->getType() != VoidPtrTy) + OldPtr = CastInst::CreatePointerCast (OldPtr, + VoidPtrTy, + OldPtr->getName(), + InsertPt); + + std::string Name = CI->getName(); CI->setName(""); + Value* Opts[2] = {Pool, OldPtr}; + Instruction *V = CallInst::Create (PoolStrdup, + Opts, + Opts + 2, + Name, + InsertPt); + Instruction *Casted = V; + if (V->getType() != CI->getType()) + Casted = CastInst::CreatePointerCast (V, CI->getType(), V->getName(), InsertPt); + + // Update def-use info + CI->replaceAllUsesWith(Casted); + } + } else if (FreeInst * FI = dyn_cast(ii)) { + Type * VoidPtrTy = PointerType::getUnqual(Type::Int8Ty); + Value * FreedNode = castTo (FI->getPointerOperand(), VoidPtrTy, "cast", ii); + DSNode * Node = ECG->getNodeForValue(FreedNode).getNode(); + GlobalVariable * Pool = PoolMap[Node]; + toDelete.push_back(ii); + Value* args[] = {Pool, FreedNode}; + CallInst::Create(PoolFree, &args[0], &args[2], "", ii); + } else if (isa(ii)) { + Returns.push_back(cast(ii)); + } + } + + //delete malloc and alloca insts + for (unsigned x = 0; x < toDelete.size(); ++x) + toDelete[x]->eraseFromParent(); +} + +/// CreateGlobalPool - Create a global pool descriptor object, and insert a +/// poolinit for it into poolalloc.init +void +PoolAllocateMultipleGlobalPool::CreateGlobalPool (unsigned RecSize, + unsigned Align, + Module& M) { + + Function *InitFunc = Function::Create + (FunctionType::get(Type::VoidTy, std::vector(), false), + GlobalValue::InternalLinkage, "poolalloc.init", &M); + + BasicBlock * BB = BasicBlock::Create("entry", InitFunc); + + SteensgaardDataStructures * DS = dynamic_cast(Graphs); + + assert (DS && "PoolAllocateMultipleGlobalPools requires Steensgaard Data Structure!"); + + DSGraph * G = DS->getResultGraph(); + for(DSGraph::node_const_iterator I = G->node_begin(), + E = G->node_end(); I != E; ++I) { + + GlobalVariable *GV = + new GlobalVariable(getPoolType(), false, GlobalValue::ExternalLinkage, + Constant::getNullValue(getPoolType()), + "__poolalloc_GlobalPool", + &M); + + Value *ElSize = ConstantInt::get(Type::Int32Ty, RecSize); + Value *AlignV = ConstantInt::get(Type::Int32Ty, Align); + Value* Opts[3] = {GV, ElSize, AlignV}; + + CallInst::Create(PoolInit, Opts, Opts + 3, "", BB); + PoolMap[&(*I)] = GV; + } + + ReturnInst::Create(BB); +} + +Value * +PoolAllocateMultipleGlobalPool::getGlobalPool (const DSNode * Node) { + Value * Pool = PoolMap[Node]; + assert (Pool && "Every DSNode corresponds to a pool handle!"); + return Pool; +} + +Value * +PoolAllocateMultipleGlobalPool::getPool (const DSNode * N, Function & F) { + return getGlobalPool(N); +} + +PoolAllocateMultipleGlobalPool::~PoolAllocateMultipleGlobalPool() {} From clattner at apple.com Mon Jul 6 23:37:38 2009 From: clattner at apple.com (Chris Lattner) Date: Mon, 6 Jul 2009 21:37:38 -0700 Subject: [llvm-commits] [llvm] r74883 - /llvm/trunk/include/llvm/CodeGen/MachineOperand.h In-Reply-To: <352a1fb20907061834m1e2f102m851dc27d592105d1@mail.gmail.com> References: <200907062346.n66Nk4Zo009321@zion.cs.uiuc.edu> <352a1fb20907061834m1e2f102m851dc27d592105d1@mail.gmail.com> Message-ID: <40BDA519-E5B7-4081-A095-6A5C6739D661@apple.com> On Jul 6, 2009, at 6:34 PM, Devang Patel wrote: > Chris, > > On Mon, Jul 6, 2009 at 6:09 PM, Chris Lattner > wrote: >> >> On Jul 6, 2009, at 4:46 PM, Devang Patel wrote: >> >>> Author: dpatel >>> Date: Mon Jul 6 18:46:02 2009 >>> New Revision: 74883 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=74883&view=rev >>> Log: >>> Add isMetadata() to check metadata operand. >> >> Hey Devang, >> >> What is your plan to use MetaData MachineInstr operands? Can you >> elaborate on how you plan to use these? > > My near term goal is to replace all Global Variables used to encode > debug info (llvm.dbg.*) by MDNodes. As a step towards this goal, I > need MetaData as machine instruction operand to handle printDeclare(). Do we really want to propagate llvm.declare intrinsics into machineinstrs? Why not have ISel tag the stack slot with the MDNode instead of lowering to a machineinstr? -Chris From sabre at nondot.org Mon Jul 6 23:55:58 2009 From: sabre at nondot.org (Chris Lattner) Date: Mon, 6 Jul 2009 23:55:58 -0500 Subject: [llvm-commits] CVS: llvm-www/Users.html Message-ID: <200907070455.n674tw7P018334@zion.cs.uiuc.edu> Changes in directory llvm-www: Users.html updated: 1.50 -> 1.51 --- Log message: Mention NVIDIA's OpenCL implementation, ok'd by Christopher Lamb. --- Diffs of the changes: (+8 -1) Users.html | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletion(-) Index: llvm-www/Users.html diff -u llvm-www/Users.html:1.50 llvm-www/Users.html:1.51 --- llvm-www/Users.html:1.50 Sun Mar 29 13:47:42 2009 +++ llvm-www/Users.html Mon Jul 6 23:54:48 2009 @@ -108,6 +108,13 @@ Compiler for stack machine architecture + + + NVIDIA + OpenCL runtime compiler (Clang + LLVM) + + + Rapidmind @@ -440,6 +447,6 @@ src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!">
LLVM Development List
- Last modified: $Date: 2009/03/29 18:47:42 $ + Last modified: $Date: 2009/07/07 04:54:48 $ From evan.cheng at apple.com Tue Jul 7 00:35:53 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 07 Jul 2009 05:35:53 -0000 Subject: [llvm-commits] [llvm] r74895 - in /llvm/trunk: lib/Target/ARM/ARMInstrThumb2.td test/CodeGen/Thumb2/thumb2-pack.ll Message-ID: <200907070535.n675ZrrN019683@zion.cs.uiuc.edu> Author: evancheng Date: Tue Jul 7 00:35:52 2009 New Revision: 74895 URL: http://llvm.org/viewvc/llvm-project?rev=74895&view=rev Log: Add Thumb2 pkhbt / pkhtb. Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-pack.ll Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td?rev=74895&r1=74894&r2=74895&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Tue Jul 7 00:35:52 2009 @@ -966,9 +966,6 @@ (or (and (srl GPR:$src, (i32 8)), 0xFF0000), (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>; -///// -/// A8.6.137 REVSH -///// def t2REVSH : T2I<(outs GPR:$dst), (ins GPR:$src), "revsh", " $dst, $src", [(set GPR:$dst, @@ -976,7 +973,31 @@ (or (srl (and GPR:$src, 0xFFFF), (i32 8)), (shl GPR:$src, (i32 8))), i16))]>; -// FIXME: PKHxx etc. +def t2PKHBT : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt), + "pkhbt", " $dst, $src1, $src2, LSL $shamt", + [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF), + (and (shl GPR:$src2, (i32 imm:$shamt)), + 0xFFFF0000)))]>; + +// Alternate cases for PKHBT where identities eliminate some nodes. +def : T2Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)), + (t2PKHBT GPR:$src1, GPR:$src2, 0)>; +def : T2Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)), + (t2PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>; + +def t2PKHTB : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt), + "pkhtb", " $dst, $src1, $src2, ASR $shamt", + [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000), + (and (sra GPR:$src2, imm16_31:$shamt), + 0xFFFF)))]>; + +// Alternate cases for PKHTB where identities eliminate some nodes. Note that +// a shift amount of 0 is *not legal* here, it is PKHBT instead. +def : T2Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, (i32 16))), + (t2PKHTB GPR:$src1, GPR:$src2, 16)>; +def : T2Pat<(or (and GPR:$src1, 0xFFFF0000), + (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)), + (t2PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>; //===----------------------------------------------------------------------===// // Comparison Instructions... Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-pack.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-pack.ll?rev=74895&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb2/thumb2-pack.ll (added) +++ llvm/trunk/test/CodeGen/Thumb2/thumb2-pack.ll Tue Jul 7 00:35:52 2009 @@ -0,0 +1,73 @@ +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | \ +; RUN: grep pkhbt | count 5 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | \ +; RUN: grep pkhtb | count 4 + +define i32 @test1(i32 %X, i32 %Y) { + %tmp1 = and i32 %X, 65535 ; [#uses=1] + %tmp4 = shl i32 %Y, 16 ; [#uses=1] + %tmp5 = or i32 %tmp4, %tmp1 ; [#uses=1] + ret i32 %tmp5 +} + +define i32 @test1a(i32 %X, i32 %Y) { + %tmp19 = and i32 %X, 65535 ; [#uses=1] + %tmp37 = shl i32 %Y, 16 ; [#uses=1] + %tmp5 = or i32 %tmp37, %tmp19 ; [#uses=1] + ret i32 %tmp5 +} + +define i32 @test2(i32 %X, i32 %Y) { + %tmp1 = and i32 %X, 65535 ; [#uses=1] + %tmp3 = shl i32 %Y, 12 ; [#uses=1] + %tmp4 = and i32 %tmp3, -65536 ; [#uses=1] + %tmp57 = or i32 %tmp4, %tmp1 ; [#uses=1] + ret i32 %tmp57 +} + +define i32 @test3(i32 %X, i32 %Y) { + %tmp19 = and i32 %X, 65535 ; [#uses=1] + %tmp37 = shl i32 %Y, 18 ; [#uses=1] + %tmp5 = or i32 %tmp37, %tmp19 ; [#uses=1] + ret i32 %tmp5 +} + +define i32 @test4(i32 %X, i32 %Y) { + %tmp1 = and i32 %X, 65535 ; [#uses=1] + %tmp3 = and i32 %Y, -65536 ; [#uses=1] + %tmp46 = or i32 %tmp3, %tmp1 ; [#uses=1] + ret i32 %tmp46 +} + +define i32 @test5(i32 %X, i32 %Y) { + %tmp17 = and i32 %X, -65536 ; [#uses=1] + %tmp2 = bitcast i32 %Y to i32 ; [#uses=1] + %tmp4 = lshr i32 %tmp2, 16 ; [#uses=2] + %tmp5 = or i32 %tmp4, %tmp17 ; [#uses=1] + ret i32 %tmp5 +} + +define i32 @test5a(i32 %X, i32 %Y) { + %tmp110 = and i32 %X, -65536 ; [#uses=1] + %tmp37 = lshr i32 %Y, 16 ; [#uses=1] + %tmp39 = bitcast i32 %tmp37 to i32 ; [#uses=1] + %tmp5 = or i32 %tmp39, %tmp110 ; [#uses=1] + ret i32 %tmp5 +} + +define i32 @test6(i32 %X, i32 %Y) { + %tmp1 = and i32 %X, -65536 ; [#uses=1] + %tmp37 = lshr i32 %Y, 12 ; [#uses=1] + %tmp38 = bitcast i32 %tmp37 to i32 ; [#uses=1] + %tmp4 = and i32 %tmp38, 65535 ; [#uses=1] + %tmp59 = or i32 %tmp4, %tmp1 ; [#uses=1] + ret i32 %tmp59 +} + +define i32 @test7(i32 %X, i32 %Y) { + %tmp1 = and i32 %X, -65536 ; [#uses=1] + %tmp3 = ashr i32 %Y, 18 ; [#uses=1] + %tmp4 = and i32 %tmp3, 65535 ; [#uses=1] + %tmp57 = or i32 %tmp4, %tmp1 ; [#uses=1] + ret i32 %tmp57 +} From sanjiv.gupta at microchip.com Tue Jul 7 03:04:53 2009 From: sanjiv.gupta at microchip.com (Sanjiv Gupta) Date: Tue, 07 Jul 2009 08:04:53 -0000 Subject: [llvm-commits] [llvm] r74898 - /llvm/trunk/lib/CodeGen/PHIElimination.cpp Message-ID: <200907070804.n6784sHX030896@zion.cs.uiuc.edu> Author: sgupta Date: Tue Jul 7 03:04:51 2009 New Revision: 74898 URL: http://llvm.org/viewvc/llvm-project?rev=74898&view=rev Log: if the terminator is a branch depending upon the side effects of a previous cmp; a copy can not be inserted here if the copy insn also has side effects. We don't have access to the attributes of copy insn here; so just play safe by finding a safe locations for branch terminators. Modified: llvm/trunk/lib/CodeGen/PHIElimination.cpp Modified: llvm/trunk/lib/CodeGen/PHIElimination.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PHIElimination.cpp?rev=74898&r1=74897&r2=74898&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/PHIElimination.cpp (original) +++ llvm/trunk/lib/CodeGen/PHIElimination.cpp Tue Jul 7 03:04:51 2009 @@ -169,9 +169,15 @@ return MBB.begin(); // If this basic block does not contain an invoke, then control flow always - // reaches the end of it, so place the copy there. The logic below works in - // this case too, but is more expensive. - if (!isa(MBB.getBasicBlock()->getTerminator())) + // reaches the end of it, so place the copy there. + // If the terminator is a branch depending upon the side effects of a + // previous cmp; a copy can not be inserted here if the copy insn also + // side effects. We don't have access to the attributes of copy insn here; + // so just play safe by finding a safe locations for branch terminators. + // + // The logic below works in this case too, but is more expensive. + const TerminatorInst *TermInst = MBB.getBasicBlock()->getTerminator(); + if (!(isa(TermInst) || isa(TermInst))) return MBB.getFirstTerminator(); // Discover any definition/uses in this basic block. From aaronngray.lists at googlemail.com Tue Jul 7 10:27:47 2009 From: aaronngray.lists at googlemail.com (Aaron Gray) Date: Tue, 7 Jul 2009 16:27:47 +0100 Subject: [llvm-commits] [patch] JITCodeEmitter speedup patch Message-ID: <9719867c0907070827r60eb90c2q52c6a3fa52b933d7@mail.gmail.com> You probably won't want this patch, premature optmization and all that, but I will send it anyway as I had ti ready to send once the ObjectCodeEmitter patch when in removing the cruft that was standing in the way in MachineCodeEmitter. It also has a extend() method for extending the buffer and continuing if th buffer overfolws. And a reserveBytes that can be used in conjunction with the raw*emit methods to allow a whole instruction to be output without any buffer checking. This patch relies on the generically parameterized *CodeEmitters for its performance. And would its performance would be overridded buy the use of vitutal methods for the emit methods. Aaaron -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090707/4d56bb8a/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: JITCodeEmitter.patch Type: application/octet-stream Size: 9012 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090707/4d56bb8a/attachment.obj From foldr at codedgers.com Tue Jul 7 11:07:47 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:07:47 -0000 Subject: [llvm-commits] [llvm] r74903 - /llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Message-ID: <200907071607.n67G7m1P019006@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:07:36 2009 New Revision: 74903 URL: http://llvm.org/viewvc/llvm-project?rev=74903&view=rev Log: Comment fix. Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=74903&r1=74902&r2=74903&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Tue Jul 7 11:07:36 2009 @@ -81,11 +81,10 @@ } // checkNumberOfArguments - Ensure that the number of args in d is -// less than or equal to min_arguments, otherwise throw an exception. +// greater than or equal to min_arguments, otherwise throw an exception. void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) { if (!d || d->getNumArgs() < min_arguments) - throw d->getOperator()->getAsString() - + ": too few arguments!"; + throw d->getOperator()->getAsString() + ": too few arguments!"; } // isDagEmpty - is this DAG marked with an empty marker? From foldr at codedgers.com Tue Jul 7 11:08:11 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:08:11 -0000 Subject: [llvm-commits] [llvm] r74904 - /llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Message-ID: <200907071608.n67G8BeX019029@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:08:11 2009 New Revision: 74904 URL: http://llvm.org/viewvc/llvm-project?rev=74904&view=rev Log: Refactoring. Make isList(), isSwitch() and isParameter() member functions of OptionDescription. Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=74904&r1=74903&r2=74904&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Tue Jul 7 11:08:11 2009 @@ -138,20 +138,21 @@ /// OptionType - One of six different option types. See the /// documentation for detailed description of differences. namespace OptionType { + enum OptionType { Alias, Switch, Parameter, ParameterList, Prefix, PrefixList}; -bool IsList (OptionType t) { - return (t == ParameterList || t == PrefixList); -} + bool IsList (OptionType t) { + return (t == ParameterList || t == PrefixList); + } -bool IsSwitch (OptionType t) { - return (t == Switch); -} + bool IsSwitch (OptionType t) { + return (t == Switch); + } -bool IsParameter (OptionType t) { - return (t == Parameter || t == Prefix); -} + bool IsParameter (OptionType t) { + return (t == Parameter || t == Prefix); + } } @@ -228,6 +229,15 @@ bool isReallyHidden() const; void setReallyHidden(); + bool isParameter() const + { return OptionType::IsParameter(this->Type); } + + bool isSwitch() const + { return OptionType::IsSwitch(this->Type); } + + bool isList() const + { return OptionType::IsList(this->Type); } + }; void OptionDescription::Merge (const OptionDescription& other) @@ -960,7 +970,7 @@ if (TestName == "switch_on") { const OptionDescription& OptDesc = OptDescs.FindOption(OptName); - if (!OptionType::IsSwitch(OptDesc.Type)) + if (!OptDesc.isSwitch()) throw OptName + ": incorrect option type - should be a switch!"; O << OptDesc.GenVariableName(); return true; @@ -983,7 +993,7 @@ } else { const OptionDescription& OptDesc = OptDescs.FindOption(OptName); - if (OptionType::IsSwitch(OptDesc.Type)) + if (OptDesc.isSwitch()) throw OptName + ": incorrect option type - should be a list or parameter!"; O << Test << OptDesc.GenVariableName() << ".empty()"; @@ -1007,13 +1017,13 @@ const OptionDescription& OptDesc = OptDescs.FindOption(OptName); if (TestName == "parameter_equals") { - if (!OptionType::IsParameter(OptDesc.Type)) + if (!OptDesc.isParameter()) throw OptName + ": incorrect option type - should be a parameter!"; O << OptDesc.GenVariableName() << " == \"" << OptArg << "\""; return true; } else if (TestName == "element_in_list") { - if (!OptionType::IsList(OptDesc.Type)) + if (!OptDesc.isList()) throw OptName + ": incorrect option type - should be a list!"; const std::string& VarName = OptDesc.GenVariableName(); O << "std::find(" << VarName << ".begin(),\n" @@ -1463,14 +1473,14 @@ if (D.isMultiVal()) throw std::string("Can't use unpack_values with multi-valued options!"); - if (OptionType::IsList(D.Type)) { + if (D.isList()) { O << IndentLevel << "for (" << D.GenTypeDeclaration() << "::iterator B = " << D.GenVariableName() << ".begin(),\n" << IndentLevel << "E = " << D.GenVariableName() << ".end(); B != E; ++B)\n" << IndentLevel << Indent1 << "llvm::SplitString(*B, vec, \",\");\n"; } - else if (OptionType::IsParameter(D.Type)){ + else if (D.isParameter()){ O << Indent3 << "llvm::SplitString(" << D.GenVariableName() << ", vec, \",\");\n"; } @@ -1686,15 +1696,15 @@ O << ", cl::Prefix"; if (val.isRequired()) { - if (OptionType::IsList(val.Type) && !val.isMultiVal()) + if (val.isList() && !val.isMultiVal()) O << ", cl::OneOrMore"; else O << ", cl::Required"; } - else if (val.isOneOrMore() && OptionType::IsList(val.Type)) { + else if (val.isOneOrMore() && val.isList()) { O << ", cl::OneOrMore"; } - else if (val.isZeroOrOne() && OptionType::IsList(val.Type)) { + else if (val.isZeroOrOne() && val.isList()) { O << ", cl::ZeroOrOne"; } From foldr at codedgers.com Tue Jul 7 11:08:41 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:08:41 -0000 Subject: [llvm-commits] [llvm] r74905 - in /llvm/trunk: include/llvm/CompilerDriver/Common.td utils/TableGen/LLVMCConfigurationEmitter.cpp Message-ID: <200907071608.n67G8fvx019058@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:08:41 2009 New Revision: 74905 URL: http://llvm.org/viewvc/llvm-project?rev=74905&view=rev Log: Add an 'init' option property. Makes possible to provide default values for options defined in plugins (same as cl::init). Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Common.td?rev=74905&r1=74904&r2=74905&view=diff ============================================================================== --- llvm/trunk/include/llvm/CompilerDriver/Common.td (original) +++ llvm/trunk/include/llvm/CompilerDriver/Common.td Tue Jul 7 11:08:41 2009 @@ -39,6 +39,7 @@ def extern; def help; def hidden; +def init; def multi_val; def one_or_more; def really_hidden; @@ -51,6 +52,10 @@ // The 'case' construct. def case; +// Boolean constants. +def true; +def false; + // Boolean operators. def and; def or; Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=74905&r1=74904&r2=74905&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original) +++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Tue Jul 7 11:08:41 2009 @@ -187,11 +187,12 @@ unsigned Flags; std::string Help; unsigned MultiVal; + Init* InitVal; OptionDescription(OptionType::OptionType t = OptionType::Switch, const std::string& n = "", const std::string& h = DefaultHelpString) - : Type(t), Name(n), Flags(0x0), Help(h), MultiVal(1) + : Type(t), Name(n), Flags(0x0), Help(h), MultiVal(1), InitVal(0) {} /// GenTypeDeclaration - Returns the C++ variable type of this @@ -447,6 +448,7 @@ AddHandler("extern", &CollectOptionProperties::onExtern); AddHandler("help", &CollectOptionProperties::onHelp); AddHandler("hidden", &CollectOptionProperties::onHidden); + AddHandler("init", &CollectOptionProperties::onInit); AddHandler("multi_val", &CollectOptionProperties::onMultiVal); AddHandler("one_or_more", &CollectOptionProperties::onOneOrMore); AddHandler("really_hidden", &CollectOptionProperties::onReallyHidden); @@ -490,6 +492,20 @@ optDesc_.setRequired(); } + void onInit (const DagInit* d) { + checkNumberOfArguments(d, 1); + Init* i = d->getArg(0); + const std::string& str = i->getAsString(); + + bool correct = optDesc_.isParameter() && dynamic_cast(i); + correct |= (optDesc_.isSwitch() && (str == "true" || str == "false")); + + if (!correct) + throw std::string("Incorrect usage of the 'init' option property!"); + + optDesc_.InitVal = i; + } + void onOneOrMore (const DagInit* d) { checkNumberOfArguments(d, 0); if (optDesc_.isRequired() || optDesc_.isZeroOrOne()) @@ -1716,7 +1732,12 @@ } if (val.MultiVal > 1) - O << ", cl::multi_val(" << val.MultiVal << ")"; + O << ", cl::multi_val(" << val.MultiVal << ')'; + + if (val.InitVal) { + const std::string& str = val.InitVal->getAsString(); + O << ", cl::init(" << str << ')'; + } if (!val.Help.empty()) O << ", cl::desc(\"" << val.Help << "\")"; From foldr at codedgers.com Tue Jul 7 11:09:06 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:09:06 -0000 Subject: [llvm-commits] [llvm] r74906 - /llvm/trunk/include/llvm/CompilerDriver/Common.td Message-ID: <200907071609.n67G96iS019082@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:09:05 2009 New Revision: 74906 URL: http://llvm.org/viewvc/llvm-project?rev=74906&view=rev Log: s/llvmc2/llvmc/ Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Common.td?rev=74906&r1=74905&r2=74906&view=diff ============================================================================== --- llvm/trunk/include/llvm/CompilerDriver/Common.td (original) +++ llvm/trunk/include/llvm/CompilerDriver/Common.td Tue Jul 7 11:09:05 2009 @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file contains common definitions used in llvmc2 tool description files. +// This file contains common definitions used in llvmc tool description files. // //===----------------------------------------------------------------------===// From foldr at codedgers.com Tue Jul 7 11:09:29 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:09:29 -0000 Subject: [llvm-commits] [llvm] r74907 - /llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Message-ID: <200907071609.n67G9Ujs019102@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:09:29 2009 New Revision: 74907 URL: http://llvm.org/viewvc/llvm-project?rev=74907&view=rev Log: Documentation update. Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst?rev=74907&r1=74906&r2=74907&view=diff ============================================================================== --- llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst (original) +++ llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Tue Jul 7 11:09:29 2009 @@ -347,6 +347,12 @@ 3))``. Only list options can have this attribute; you can, however, use the ``one_or_more`` and ``zero_or_one`` properties. + - ``init`` - this option has a default value, either a string (if it is a + parameter), or a boolean (if it is a switch; boolean constants are called + ``true`` and ``false``). List options can't have this attribute. Usage + examples: ``(switch_option "foo", (init true))``; ``(prefix_option "bar", + (init "baz"))``. + - ``extern`` - this option is defined in some other plugin, see below. External options From foldr at codedgers.com Tue Jul 7 11:09:49 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:09:49 -0000 Subject: [llvm-commits] [llvm] r74908 - /llvm/trunk/docs/CompilerDriver.html Message-ID: <200907071609.n67G9nVJ019123@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:09:48 2009 New Revision: 74908 URL: http://llvm.org/viewvc/llvm-project?rev=74908&view=rev Log: Regenerate. Modified: llvm/trunk/docs/CompilerDriver.html Modified: llvm/trunk/docs/CompilerDriver.html URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CompilerDriver.html?rev=74908&r1=74907&r2=74908&view=diff ============================================================================== --- llvm/trunk/docs/CompilerDriver.html (original) +++ llvm/trunk/docs/CompilerDriver.html Tue Jul 7 11:09:48 2009 @@ -341,6 +341,11 @@ special cases). Usage example: (parameter_list_option "foo", (multi_val 3)). Only list options can have this attribute; you can, however, use the one_or_more and zero_or_one properties. +
  • init - this option has a default value, either a string (if it is a +parameter), or a boolean (if it is a switch; boolean constants are called +true and false). List options can't have this attribute. Usage +examples: (switch_option "foo", (init true)); (prefix_option "bar", +(init "baz")).
  • extern - this option is defined in some other plugin, see below.
  • From parseerror at gmail.com Tue Jul 7 09:46:19 2009 From: parseerror at gmail.com (Ryan Flynn) Date: Tue, 7 Jul 2009 10:46:19 -0400 Subject: [llvm-commits] patch: CodeGen/BinaryObject.h explicit typecast Message-ID: BinaryObject.h was implicitly converting between uint{16,32,64}_t to uint8_t (via 'foo & 255'), i replaced this with an explicit (uint8_t) cast which is equivalent, faster and more correct (silences type-related warnings). Also, following coding standards I replaced post-increment with pre-increment. Ryan -------------- next part -------------- A non-text attachment was scrubbed... Name: CodeGen-BinaryObject-explicit-typecast.patch Type: application/octet-stream Size: 7850 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090707/0b5f58f0/attachment.obj From andrelct at dcc.ufmg.br Tue Jul 7 11:25:06 2009 From: andrelct at dcc.ufmg.br (Andre Tavares) Date: Tue, 07 Jul 2009 13:25:06 -0300 Subject: [llvm-commits] SSI bug fix Message-ID: <4A5376E2.2000804@dcc.ufmg.br> Hello, I have fixed the bug found by Nick on the SSI code. The attachment contains the patch for that code. The bug is described here: http://llvm.org/bugs/show_bug.cgi?id=4511 Regards, -- Andre Tavares Master Student in Computer Science - UFMG - Brasil http://dcc.ufmg.br/~andrelct -------------- next part -------------- A non-text attachment was scrubbed... Name: ssi.patch Type: text/x-patch Size: 13323 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090707/48377df0/attachment.bin From resistor at mac.com Tue Jul 7 11:31:28 2009 From: resistor at mac.com (Owen Anderson) Date: Tue, 07 Jul 2009 16:31:28 -0000 Subject: [llvm-commits] [llvm] r74910 - /llvm/trunk/lib/Analysis/DebugInfo.cpp Message-ID: <200907071631.n67GVS8h019766@zion.cs.uiuc.edu> Author: resistor Date: Tue Jul 7 11:31:25 2009 New Revision: 74910 URL: http://llvm.org/viewvc/llvm-project?rev=74910&view=rev Log: Revert part of r74873 that broke Clang's debug info generation. Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=74910&r1=74909&r2=74910&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/DebugInfo.cpp (original) +++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Jul 7 11:31:25 2009 @@ -18,7 +18,6 @@ #include "llvm/Intrinsics.h" #include "llvm/IntrinsicInst.h" #include "llvm/Instructions.h" -#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/Dwarf.h" @@ -456,15 +455,14 @@ DIFactory::DIFactory(Module &m) : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0), DeclareFn(0) { - EmptyStructPtr = - M.getContext().getPointerTypeUnqual(M.getContext().getStructType()); + EmptyStructPtr = PointerType::getUnqual(StructType::get()); } /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. /// This is only valid when the descriptor is non-null. Constant *DIFactory::getCastToEmpty(DIDescriptor D) { - if (D.isNull()) return M.getContext().getNullValue(EmptyStructPtr); - return M.getContext().getConstantExprBitCast(D.getGV(), EmptyStructPtr); + if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); + return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); } Constant *DIFactory::GetTagConstant(unsigned TAG) { @@ -480,21 +478,21 @@ // Return Constant if previously defined. if (Slot) return Slot; - const PointerType *DestTy = M.getContext().getPointerTypeUnqual(Type::Int8Ty); + const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); // If empty string then use a i8* null instead. if (String.empty()) - return Slot = M.getContext().getConstantPointerNull(DestTy); + return Slot = ConstantPointerNull::get(DestTy); // Construct string as an llvm constant. - Constant *ConstStr = M.getContext().getConstantArray(String); + Constant *ConstStr = ConstantArray::get(String); // Otherwise create and return a new string global. GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, GlobalVariable::InternalLinkage, ConstStr, ".str", &M); StrGV->setSection("llvm.metadata"); - return Slot = M.getContext().getConstantExprBitCast(StrGV, DestTy); + return Slot = ConstantExpr::getBitCast(StrGV, DestTy); } //===----------------------------------------------------------------------===// @@ -506,12 +504,10 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { SmallVector Elts; - LLVMContext& Ctxt = M.getContext(); - for (unsigned i = 0; i != NumTys; ++i) Elts.push_back(getCastToEmpty(Tys[i])); - Constant *Init = Ctxt.getConstantArray(Ctxt.getArrayType(EmptyStructPtr, + Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, Elts.size()), Elts.data(), Elts.size()); // If we already have this array, just return the uniqued version. @@ -531,12 +527,11 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subrange_type), - M.getContext().getConstantInt(Type::Int64Ty, Lo), - M.getContext().getConstantInt(Type::Int64Ty, Hi) + ConstantInt::get(Type::Int64Ty, Lo), + ConstantInt::get(Type::Int64Ty, Hi) }; - Constant *Init = - M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); // If we already have this range, just return the uniqued version. DIDescriptor &Entry = SimpleConstantCache[Init]; @@ -564,22 +559,20 @@ bool isOptimized, const char *Flags, unsigned RunTimeVer) { - LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), - Ctxt.getNullValue(EmptyStructPtr), - Ctxt.getConstantInt(Type::Int32Ty, LangID), + Constant::getNullValue(EmptyStructPtr), + ConstantInt::get(Type::Int32Ty, LangID), GetStringConstant(Filename), GetStringConstant(Directory), GetStringConstant(Producer), - Ctxt.getConstantInt(Type::Int1Ty, isMain), - Ctxt.getConstantInt(Type::Int1Ty, isOptimized), + ConstantInt::get(Type::Int1Ty, isMain), + ConstantInt::get(Type::Int1Ty, isOptimized), GetStringConstant(Flags), - Ctxt.getConstantInt(Type::Int32Ty, RunTimeVer) + ConstantInt::get(Type::Int32Ty, RunTimeVer) }; - Constant *Init = - Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -594,11 +587,10 @@ Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_enumerator), GetStringConstant(Name), - M.getContext().getConstantInt(Type::Int64Ty, Val) + ConstantInt::get(Type::Int64Ty, Val) }; - Constant *Init = - M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -618,23 +610,20 @@ uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, unsigned Encoding) { - - LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_base_type), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - Ctxt.getConstantInt(Type::Int32Ty, LineNumber), - Ctxt.getConstantInt(Type::Int64Ty, SizeInBits), - Ctxt.getConstantInt(Type::Int64Ty, AlignInBits), - Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits), - Ctxt.getConstantInt(Type::Int32Ty, Flags), - Ctxt.getConstantInt(Type::Int32Ty, Encoding) + ConstantInt::get(Type::Int32Ty, LineNumber), + ConstantInt::get(Type::Int64Ty, SizeInBits), + ConstantInt::get(Type::Int64Ty, AlignInBits), + ConstantInt::get(Type::Int64Ty, OffsetInBits), + ConstantInt::get(Type::Int32Ty, Flags), + ConstantInt::get(Type::Int32Ty, Encoding) }; - Constant *Init = - Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.basictype.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -656,23 +645,20 @@ uint64_t OffsetInBits, unsigned Flags, DIType DerivedFrom) { - - LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - Ctxt.getConstantInt(Type::Int32Ty, LineNumber), - Ctxt.getConstantInt(Type::Int64Ty, SizeInBits), - Ctxt.getConstantInt(Type::Int64Ty, AlignInBits), - Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits), - Ctxt.getConstantInt(Type::Int32Ty, Flags), + ConstantInt::get(Type::Int32Ty, LineNumber), + ConstantInt::get(Type::Int64Ty, SizeInBits), + ConstantInt::get(Type::Int64Ty, AlignInBits), + ConstantInt::get(Type::Int64Ty, OffsetInBits), + ConstantInt::get(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom) }; - Constant *Init = - Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -695,24 +681,23 @@ DIType DerivedFrom, DIArray Elements, unsigned RuntimeLang) { - LLVMContext& Ctxt = M.getContext(); + Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - Ctxt.getConstantInt(Type::Int32Ty, LineNumber), - Ctxt.getConstantInt(Type::Int64Ty, SizeInBits), - Ctxt.getConstantInt(Type::Int64Ty, AlignInBits), - Ctxt.getConstantInt(Type::Int64Ty, OffsetInBits), - Ctxt.getConstantInt(Type::Int32Ty, Flags), + ConstantInt::get(Type::Int32Ty, LineNumber), + ConstantInt::get(Type::Int64Ty, SizeInBits), + ConstantInt::get(Type::Int64Ty, AlignInBits), + ConstantInt::get(Type::Int64Ty, OffsetInBits), + ConstantInt::get(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom), getCastToEmpty(Elements), - Ctxt.getConstantInt(Type::Int32Ty, RuntimeLang) + ConstantInt::get(Type::Int32Ty, RuntimeLang) }; - Constant *Init = - Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.composite.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -735,23 +720,21 @@ bool isLocalToUnit, bool isDefinition) { - LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subprogram), - Ctxt.getNullValue(EmptyStructPtr), + Constant::getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - Ctxt.getConstantInt(Type::Int32Ty, LineNo), + ConstantInt::get(Type::Int32Ty, LineNo), getCastToEmpty(Type), - Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit), - Ctxt.getConstantInt(Type::Int1Ty, isDefinition) + ConstantInt::get(Type::Int1Ty, isLocalToUnit), + ConstantInt::get(Type::Int1Ty, isDefinition) }; - Constant *Init = - Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -769,25 +752,22 @@ DICompileUnit CompileUnit, unsigned LineNo, DIType Type,bool isLocalToUnit, bool isDefinition, llvm::GlobalVariable *Val) { - - LLVMContext& Ctxt = M.getContext(); Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_variable), - Ctxt.getNullValue(EmptyStructPtr), + Constant::getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - Ctxt.getConstantInt(Type::Int32Ty, LineNo), + ConstantInt::get(Type::Int32Ty, LineNo), getCastToEmpty(Type), - Ctxt.getConstantInt(Type::Int1Ty, isLocalToUnit), - Ctxt.getConstantInt(Type::Int1Ty, isDefinition), - Ctxt.getConstantExprBitCast(Val, EmptyStructPtr) + ConstantInt::get(Type::Int1Ty, isLocalToUnit), + ConstantInt::get(Type::Int1Ty, isDefinition), + ConstantExpr::getBitCast(Val, EmptyStructPtr) }; - Constant *Init = - Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -803,19 +783,16 @@ const std::string &Name, DICompileUnit CompileUnit, unsigned LineNo, DIType Type) { - LLVMContext& Ctxt = M.getContext(); - Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - Ctxt.getConstantInt(Type::Int32Ty, LineNo), + ConstantInt::get(Type::Int32Ty, LineNo), getCastToEmpty(Type) }; - Constant *Init = - Ctxt.getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.variable.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -834,8 +811,7 @@ getCastToEmpty(Context) }; - Constant *Init = - M.getContext().getConstantStruct(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.block.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -862,8 +838,8 @@ // Invoke llvm.dbg.stoppoint Value *Args[] = { - M.getContext().getConstantInt(llvm::Type::Int32Ty, LineNo), - M.getContext().getConstantInt(llvm::Type::Int32Ty, ColNo), + llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo), + llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo), getCastToEmpty(CU) }; CallInst::Create(StopPointFn, Args, Args+3, "", BB); @@ -966,7 +942,7 @@ const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); if (!Ty) return 0; - Ty = V->getParent()->getContext().getPointerType(Ty, 0); + Ty = PointerType::get(Ty, 0); Value *Val = V->stripPointerCasts(); for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); From foldr at codedgers.com Tue Jul 7 11:39:35 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:39:35 -0000 Subject: [llvm-commits] [llvm] r74912 - /llvm/trunk/tools/llvmc/example/mcc16/driver/Main.cpp Message-ID: <200907071639.n67GdaGU020068@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:39:33 2009 New Revision: 74912 URL: http://llvm.org/viewvc/llvm-project?rev=74912&view=rev Log: Show how to modify built-in options. Sanjiv complained about the need to maintain local changes to lib/CompilerDriver. Modified: llvm/trunk/tools/llvmc/example/mcc16/driver/Main.cpp Modified: llvm/trunk/tools/llvmc/example/mcc16/driver/Main.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/example/mcc16/driver/Main.cpp?rev=74912&r1=74911&r2=74912&view=diff ============================================================================== --- llvm/trunk/tools/llvmc/example/mcc16/driver/Main.cpp (original) +++ llvm/trunk/tools/llvmc/example/mcc16/driver/Main.cpp Tue Jul 7 11:39:33 2009 @@ -7,8 +7,25 @@ // //===----------------------------------------------------------------------===// // -// Just include CompilerDriver/Main.inc. +// Usually this file just includes CompilerDriver/Main.inc, but here we apply +// some trickery to make the built-in '-save-temps' option hidden and enabled +// by default. // //===----------------------------------------------------------------------===// -#include "llvm/CompilerDriver/Main.inc" +#include "llvm/CompilerDriver/BuiltinOptions.h" +#include "llvm/CompilerDriver/ForceLinkage.h" + +namespace llvmc { + int Main(int argc, char** argv); +} + +int main(int argc, char** argv) { + + // HACK + SaveTemps = SaveTempsEnum::Obj; + SaveTemps.setHiddenFlag(llvm::cl::Hidden); + + llvmc::ForceLinkage(); + return llvmc::Main(argc, argv); +} From foldr at codedgers.com Tue Jul 7 11:43:49 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:43:49 -0000 Subject: [llvm-commits] [llvm] r74913 - /llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Message-ID: <200907071643.n67Ghnjg020205@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:43:49 2009 New Revision: 74913 URL: http://llvm.org/viewvc/llvm-project?rev=74913&view=rev Log: Documentation update. Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst?rev=74913&r1=74912&r2=74913&view=diff ============================================================================== --- llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst (original) +++ llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Tue Jul 7 11:43:49 2009 @@ -368,7 +368,8 @@ (switch_option "E", (extern)) ... -See also the section on plugin `priorities`__. +If an external option has additional attributes besides 'extern', they are +ignored. See also the section on plugin `priorities`__. __ priorities_ From foldr at codedgers.com Tue Jul 7 11:44:22 2009 From: foldr at codedgers.com (Mikhail Glushenkov) Date: Tue, 07 Jul 2009 16:44:22 -0000 Subject: [llvm-commits] [llvm] r74914 - /llvm/trunk/docs/CompilerDriver.html Message-ID: <200907071644.n67GiN89020260@zion.cs.uiuc.edu> Author: foldr Date: Tue Jul 7 11:44:20 2009 New Revision: 74914 URL: http://llvm.org/viewvc/llvm-project?rev=74914&view=rev Log: Regenerate. Modified: llvm/trunk/docs/CompilerDriver.html Modified: llvm/trunk/docs/CompilerDriver.html URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CompilerDriver.html?rev=74914&r1=74913&r2=74914&view=diff ============================================================================== --- llvm/trunk/docs/CompilerDriver.html (original) +++ llvm/trunk/docs/CompilerDriver.html Tue Jul 7 11:44:20 2009 @@ -363,7 +363,8 @@ (switch_option "E", (extern)) ... -

    See also the section on plugin priorities.

    +

    If an external option has additional attributes besides 'extern', they are +ignored. See also the section on plugin priorities.

    From resistor at mac.com Tue Jul 7 11:56:28 2009 From: resistor at mac.com (Owen Anderson) Date: Tue, 07 Jul 2009 16:56:28 -0000 Subject: [llvm-commits] [llvm] r74915 - /llvm/trunk/include/llvm/LLVMContext.h Message-ID: <200907071656.n67GuV2D020871@zion.cs.uiuc.edu> Author: resistor Date: Tue Jul 7 11:56:05 2009 New Revision: 74915 URL: http://llvm.org/viewvc/llvm-project?rev=74915&view=rev Log: This parameter should default to true, not false. Modified: llvm/trunk/include/llvm/LLVMContext.h Modified: llvm/trunk/include/llvm/LLVMContext.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=74915&r1=74914&r2=74915&view=diff ============================================================================== --- llvm/trunk/include/llvm/LLVMContext.h (original) +++ llvm/trunk/include/llvm/LLVMContext.h Tue Jul 7 11:56:05 2009 @@ -95,7 +95,7 @@ Constant* getConstantArray(const ArrayType* T, Constant* const* Vals, unsigned NumVals); Constant* getConstantArray(const std::string& Initializer, - bool AddNull = false); + bool AddNull = true); // ConstantExpr accessors Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2); From mai4 at uiuc.edu Tue Jul 7 11:58:22 2009 From: mai4 at uiuc.edu (Haohui Mai) Date: Tue, 07 Jul 2009 16:58:22 -0000 Subject: [llvm-commits] [poolalloc] r74916 - in /poolalloc/trunk: include/dsa/DataStructure.h lib/DSA/Steensgaard.cpp Message-ID: <200907071658.n67GwN4V020945@zion.cs.uiuc.edu> Author: mai4 Date: Tue Jul 7 11:58:21 2009 New Revision: 74916 URL: http://llvm.org/viewvc/llvm-project?rev=74916&view=rev Log: Don't delete ResultsGraph in SteensgaardDataStructures::releaseMyMemory() during destruction since it is deleted by DataStructures::releaseMemory(). Modified: poolalloc/trunk/include/dsa/DataStructure.h poolalloc/trunk/lib/DSA/Steensgaard.cpp Modified: poolalloc/trunk/include/dsa/DataStructure.h URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=74916&r1=74915&r2=74916&view=diff ============================================================================== --- poolalloc/trunk/include/dsa/DataStructure.h (original) +++ poolalloc/trunk/include/dsa/DataStructure.h Tue Jul 7 11:58:21 2009 @@ -140,13 +140,13 @@ virtual void releaseMemory(); - bool hasDSGraph(const Function &F) const { + virtual bool hasDSGraph(const Function &F) const { return DSInfo.find(&F) != DSInfo.end(); } /// getDSGraph - Return the data structure graph for the specified function. /// - DSGraph *getDSGraph(const Function &F) const { + virtual DSGraph *getDSGraph(const Function &F) const { hash_map::const_iterator I = DSInfo.find(&F); assert(I != DSInfo.end() && "Function not in module!"); return I->second; @@ -427,7 +427,7 @@ ResultGraph(NULL) {} ~SteensgaardDataStructures(); virtual bool runOnModule(Module &M); - virtual void releaseMyMemory(); + virtual void releaseMemory(); virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); @@ -436,8 +436,12 @@ /// getDSGraph - Return the data structure graph for the specified function. /// - DSGraph *getDSGraph(const Function &F) const { - return ResultGraph; + virtual DSGraph *getDSGraph(const Function &F) const { + return getResultGraph() ; + } + + virtual bool hasDSGraph(const Function &F) const { + return true; } /// getDSGraph - Return the data structure graph for the whole program. Modified: poolalloc/trunk/lib/DSA/Steensgaard.cpp URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Steensgaard.cpp?rev=74916&r1=74915&r2=74916&view=diff ============================================================================== --- poolalloc/trunk/lib/DSA/Steensgaard.cpp (original) +++ poolalloc/trunk/lib/DSA/Steensgaard.cpp Tue Jul 7 11:58:21 2009 @@ -23,15 +23,14 @@ using namespace llvm; -SteensgaardDataStructures::~SteensgaardDataStructures() { - releaseMyMemory(); - assert(ResultGraph == 0 && "releaseMemory not called?"); -} +SteensgaardDataStructures::~SteensgaardDataStructures() { } void -SteensgaardDataStructures::releaseMyMemory() { - delete ResultGraph; +SteensgaardDataStructures::releaseMemory() { + // Here we don't need to delete the result graph, because it aliases with the + // GlobalsGraph, which is deleted by DataStructures::releaseMemory(). ResultGraph = 0; + DataStructures::releaseMemory(); } // print - Implement the Pass::print method... @@ -133,6 +132,8 @@ ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); + // Assign the result graph to globals graph. It should be the same. + GlobalsGraph = ResultGraph; print(DOUT, &M); return false; } From gohman at apple.com Tue Jul 7 12:06:26 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 07 Jul 2009 17:06:26 -0000 Subject: [llvm-commits] [llvm] r74918 - in /llvm/trunk: include/llvm/Analysis/IVUsers.h include/llvm/Analysis/LoopVR.h include/llvm/Analysis/ScalarEvolution.h include/llvm/Analysis/ScalarEvolutionExpander.h include/llvm/Analysis/ScalarEvolutionExpressions.h lib/Analysis/IVUsers.cpp lib/Analysis/LoopVR.cpp lib/Analysis/ScalarEvolution.cpp lib/Analysis/ScalarEvolutionExpander.cpp lib/Transforms/Scalar/IndVarSimplify.cpp lib/Transforms/Scalar/LoopDeletion.cpp lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200907071706.n67H6SVd021298@zion.cs.uiuc.edu> Author: djg Date: Tue Jul 7 12:06:11 2009 New Revision: 74918 URL: http://llvm.org/viewvc/llvm-project?rev=74918&view=rev Log: Change all SCEV* to SCEV *. Modified: llvm/trunk/include/llvm/Analysis/IVUsers.h llvm/trunk/include/llvm/Analysis/LoopVR.h llvm/trunk/include/llvm/Analysis/ScalarEvolution.h llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h llvm/trunk/lib/Analysis/IVUsers.cpp llvm/trunk/lib/Analysis/LoopVR.cpp llvm/trunk/lib/Analysis/ScalarEvolution.cpp llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Modified: llvm/trunk/include/llvm/Analysis/IVUsers.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/IVUsers.h?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/IVUsers.h (original) +++ llvm/trunk/include/llvm/Analysis/IVUsers.h Tue Jul 7 12:06:11 2009 @@ -34,7 +34,7 @@ class IVStrideUse : public CallbackVH, public ilist_node { public: IVStrideUse(IVUsersOfOneStride *parent, - const SCEV* offset, + const SCEV *offset, Instruction* U, Value *O) : CallbackVH(U), Parent(parent), Offset(offset), OperandValToReplace(O), @@ -58,10 +58,10 @@ /// getOffset - Return the offset to add to a theoeretical induction /// variable that starts at zero and counts up by the stride to compute /// the value for the use. This always has the same type as the stride. - const SCEV* getOffset() const { return Offset; } + const SCEV *getOffset() const { return Offset; } /// setOffset - Assign a new offset to this use. - void setOffset(const SCEV* Val) { + void setOffset(const SCEV *Val) { Offset = Val; } @@ -96,7 +96,7 @@ IVUsersOfOneStride *Parent; /// Offset - The offset to add to the base induction expression. - const SCEV* Offset; + const SCEV *Offset; /// OperandValToReplace - The Value of the operand in the user instruction /// that this IVStrideUse is representing. @@ -158,7 +158,7 @@ /// initial value and the operand that uses the IV. ilist Users; - void addUser(const SCEV* Offset, Instruction *User, Value *Operand) { + void addUser(const SCEV *Offset, Instruction *User, Value *Operand) { Users.push_back(new IVStrideUse(this, Offset, User, Operand)); } }; @@ -178,12 +178,12 @@ /// IVUsesByStride - A mapping from the strides in StrideOrder to the /// uses in IVUses. - std::map IVUsesByStride; + std::map IVUsesByStride; /// StrideOrder - An ordering of the keys in IVUsesByStride that is stable: /// We use this to iterate over the IVUsesByStride collection without being /// dependent on random ordering of pointers in the process. - SmallVector StrideOrder; + SmallVector StrideOrder; private: virtual void getAnalysisUsage(AnalysisUsage &AU) const; @@ -203,7 +203,7 @@ /// getReplacementExpr - Return a SCEV expression which computes the /// value of the OperandValToReplace of the given IVStrideUse. - const SCEV* getReplacementExpr(const IVStrideUse &U) const; + const SCEV *getReplacementExpr(const IVStrideUse &U) const; void print(raw_ostream &OS, const Module* = 0) const; virtual void print(std::ostream &OS, const Module* = 0) const; Modified: llvm/trunk/include/llvm/Analysis/LoopVR.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopVR.h?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/LoopVR.h (original) +++ llvm/trunk/include/llvm/Analysis/LoopVR.h Tue Jul 7 12:06:11 2009 @@ -78,9 +78,9 @@ private: ConstantRange compute(Value *V); - ConstantRange getRange(const SCEV* S, Loop *L, ScalarEvolution &SE); + ConstantRange getRange(const SCEV *S, Loop *L, ScalarEvolution &SE); - ConstantRange getRange(const SCEV* S, const SCEV* T, ScalarEvolution &SE); + ConstantRange getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE); std::map Map; }; Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolution.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolution.h?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolution.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolution.h Tue Jul 7 12:06:11 2009 @@ -89,9 +89,9 @@ /// the same value, but which uses the concrete value Conc instead of the /// symbolic value. If this SCEV does not use the symbolic value, it /// returns itself. - virtual const SCEV* - replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + virtual const SCEV * + replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const = 0; /// dominates - Return true if elements that makes up this SCEV dominates @@ -134,9 +134,9 @@ virtual const Type *getType() const; virtual bool hasComputableLoopEvolution(const Loop *L) const; virtual void print(raw_ostream &OS) const; - virtual const SCEV* - replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + virtual const SCEV * + replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const; virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const { @@ -184,7 +184,7 @@ /// Scalars - This is a cache of the scalars we have analyzed so far. /// - std::map Scalars; + std::map Scalars; /// BackedgeTakenInfo - Information about the backedge-taken count /// of a loop. This currently inclues an exact count and a maximum count. @@ -192,16 +192,16 @@ struct BackedgeTakenInfo { /// Exact - An expression indicating the exact backedge-taken count of /// the loop if it is known, or a SCEVCouldNotCompute otherwise. - const SCEV* Exact; + const SCEV *Exact; /// Exact - An expression indicating the least maximum backedge-taken /// count of the loop that is known, or a SCEVCouldNotCompute. - const SCEV* Max; + const SCEV *Max; - /*implicit*/ BackedgeTakenInfo(const SCEV* exact) : + /*implicit*/ BackedgeTakenInfo(const SCEV *exact) : Exact(exact), Max(exact) {} - BackedgeTakenInfo(const SCEV* exact, const SCEV* max) : + BackedgeTakenInfo(const SCEV *exact, const SCEV *max) : Exact(exact), Max(max) {} /// hasAnyInfo - Test whether this BackedgeTakenInfo contains any @@ -231,30 +231,30 @@ /// createSCEV - We know that there is no SCEV for the specified value. /// Analyze the expression. - const SCEV* createSCEV(Value *V); + const SCEV *createSCEV(Value *V); /// createNodeForPHI - Provide the special handling we need to analyze PHI /// SCEVs. - const SCEV* createNodeForPHI(PHINode *PN); + const SCEV *createNodeForPHI(PHINode *PN); /// createNodeForGEP - Provide the special handling we need to analyze GEP /// SCEVs. - const SCEV* createNodeForGEP(User *GEP); + const SCEV *createNodeForGEP(User *GEP); /// ReplaceSymbolicValueWithConcrete - This looks up the computed SCEV value /// for the specified instruction and replaces any references to the /// symbolic value SymName with the specified value. This is used during /// PHI resolution. void ReplaceSymbolicValueWithConcrete(Instruction *I, - const SCEV* SymName, - const SCEV* NewVal); + const SCEV *SymName, + const SCEV *NewVal); /// getBECount - Subtract the end and start values and divide by the step, /// rounding up, to get the number of times the backedge is executed. Return /// CouldNotCompute if an intermediate computation overflows. - const SCEV* getBECount(const SCEV* Start, - const SCEV* End, - const SCEV* Step); + const SCEV *getBECount(const SCEV *Start, + const SCEV *End, + const SCEV *Step); /// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given /// loop, lazily computing new values if the loop hasn't been analyzed @@ -292,7 +292,7 @@ /// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition /// of 'icmp op load X, cst', try to see if we can compute the trip count. - const SCEV* + const SCEV * ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI, Constant *RHS, const Loop *L, @@ -303,19 +303,19 @@ /// try to evaluate a few iterations of the loop until we get the exit /// condition gets a value of ExitWhen (true or false). If we cannot /// evaluate the trip count of the loop, return CouldNotCompute. - const SCEV* ComputeBackedgeTakenCountExhaustively(const Loop *L, + const SCEV *ComputeBackedgeTakenCountExhaustively(const Loop *L, Value *Cond, bool ExitWhen); /// HowFarToZero - Return the number of times a backedge comparing the /// specified value to zero will execute. If not computable, return /// CouldNotCompute. - const SCEV* HowFarToZero(const SCEV *V, const Loop *L); + const SCEV *HowFarToZero(const SCEV *V, const Loop *L); /// HowFarToNonZero - Return the number of times a backedge checking the /// specified value for nonzero will execute. If not computable, return /// CouldNotCompute. - const SCEV* HowFarToNonZero(const SCEV *V, const Loop *L); + const SCEV *HowFarToNonZero(const SCEV *V, const Loop *L); /// HowManyLessThans - Return the number of times a backedge containing the /// specified less-than comparison will execute. If not computable, return @@ -375,115 +375,115 @@ /// getSCEV - Return a SCEV expression handle for the full generality of the /// specified expression. - const SCEV* getSCEV(Value *V); + const SCEV *getSCEV(Value *V); - const SCEV* getConstant(ConstantInt *V); - const SCEV* getConstant(const APInt& Val); - const SCEV* getConstant(const Type *Ty, uint64_t V, bool isSigned = false); - const SCEV* getTruncateExpr(const SCEV* Op, const Type *Ty); - const SCEV* getZeroExtendExpr(const SCEV* Op, const Type *Ty); - const SCEV* getSignExtendExpr(const SCEV* Op, const Type *Ty); - const SCEV* getAnyExtendExpr(const SCEV* Op, const Type *Ty); - const SCEV* getAddExpr(SmallVectorImpl &Ops); - const SCEV* getAddExpr(const SCEV* LHS, const SCEV* RHS) { - SmallVector Ops; + const SCEV *getConstant(ConstantInt *V); + const SCEV *getConstant(const APInt& Val); + const SCEV *getConstant(const Type *Ty, uint64_t V, bool isSigned = false); + const SCEV *getTruncateExpr(const SCEV *Op, const Type *Ty); + const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty); + const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty); + const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty); + const SCEV *getAddExpr(SmallVectorImpl &Ops); + const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS) { + SmallVector Ops; Ops.push_back(LHS); Ops.push_back(RHS); return getAddExpr(Ops); } - const SCEV* getAddExpr(const SCEV* Op0, const SCEV* Op1, - const SCEV* Op2) { - SmallVector Ops; + const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1, + const SCEV *Op2) { + SmallVector Ops; Ops.push_back(Op0); Ops.push_back(Op1); Ops.push_back(Op2); return getAddExpr(Ops); } - const SCEV* getMulExpr(SmallVectorImpl &Ops); - const SCEV* getMulExpr(const SCEV* LHS, const SCEV* RHS) { - SmallVector Ops; + const SCEV *getMulExpr(SmallVectorImpl &Ops); + const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS) { + SmallVector Ops; Ops.push_back(LHS); Ops.push_back(RHS); return getMulExpr(Ops); } - const SCEV* getUDivExpr(const SCEV* LHS, const SCEV* RHS); - const SCEV* getAddRecExpr(const SCEV* Start, const SCEV* Step, + const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS); + const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L); - const SCEV* getAddRecExpr(SmallVectorImpl &Operands, + const SCEV *getAddRecExpr(SmallVectorImpl &Operands, const Loop *L); - const SCEV* getAddRecExpr(const SmallVectorImpl &Operands, + const SCEV *getAddRecExpr(const SmallVectorImpl &Operands, const Loop *L) { - SmallVector NewOp(Operands.begin(), Operands.end()); + SmallVector NewOp(Operands.begin(), Operands.end()); return getAddRecExpr(NewOp, L); } - const SCEV* getSMaxExpr(const SCEV* LHS, const SCEV* RHS); - const SCEV* getSMaxExpr(SmallVectorImpl &Operands); - const SCEV* getUMaxExpr(const SCEV* LHS, const SCEV* RHS); - const SCEV* getUMaxExpr(SmallVectorImpl &Operands); - const SCEV* getSMinExpr(const SCEV* LHS, const SCEV* RHS); - const SCEV* getUMinExpr(const SCEV* LHS, const SCEV* RHS); - const SCEV* getUnknown(Value *V); - const SCEV* getCouldNotCompute(); + const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS); + const SCEV *getSMaxExpr(SmallVectorImpl &Operands); + const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS); + const SCEV *getUMaxExpr(SmallVectorImpl &Operands); + const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS); + const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS); + const SCEV *getUnknown(Value *V); + const SCEV *getCouldNotCompute(); /// getNegativeSCEV - Return the SCEV object corresponding to -V. /// - const SCEV* getNegativeSCEV(const SCEV* V); + const SCEV *getNegativeSCEV(const SCEV *V); /// getNotSCEV - Return the SCEV object corresponding to ~V. /// - const SCEV* getNotSCEV(const SCEV* V); + const SCEV *getNotSCEV(const SCEV *V); /// getMinusSCEV - Return LHS-RHS. /// - const SCEV* getMinusSCEV(const SCEV* LHS, - const SCEV* RHS); + const SCEV *getMinusSCEV(const SCEV *LHS, + const SCEV *RHS); /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion /// of the input value to the specified type. If the type must be /// extended, it is zero extended. - const SCEV* getTruncateOrZeroExtend(const SCEV* V, const Type *Ty); + const SCEV *getTruncateOrZeroExtend(const SCEV *V, const Type *Ty); /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion /// of the input value to the specified type. If the type must be /// extended, it is sign extended. - const SCEV* getTruncateOrSignExtend(const SCEV* V, const Type *Ty); + const SCEV *getTruncateOrSignExtend(const SCEV *V, const Type *Ty); /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of /// the input value to the specified type. If the type must be extended, /// it is zero extended. The conversion must not be narrowing. - const SCEV* getNoopOrZeroExtend(const SCEV* V, const Type *Ty); + const SCEV *getNoopOrZeroExtend(const SCEV *V, const Type *Ty); /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of /// the input value to the specified type. If the type must be extended, /// it is sign extended. The conversion must not be narrowing. - const SCEV* getNoopOrSignExtend(const SCEV* V, const Type *Ty); + const SCEV *getNoopOrSignExtend(const SCEV *V, const Type *Ty); /// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of /// the input value to the specified type. If the type must be extended, /// it is extended with unspecified bits. The conversion must not be /// narrowing. - const SCEV* getNoopOrAnyExtend(const SCEV* V, const Type *Ty); + const SCEV *getNoopOrAnyExtend(const SCEV *V, const Type *Ty); /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the /// input value to the specified type. The conversion must not be /// widening. - const SCEV* getTruncateOrNoop(const SCEV* V, const Type *Ty); + const SCEV *getTruncateOrNoop(const SCEV *V, const Type *Ty); /// getIntegerSCEV - Given a SCEVable type, create a constant for the /// specified signed integer value and return a SCEV for the constant. - const SCEV* getIntegerSCEV(int Val, const Type *Ty); + const SCEV *getIntegerSCEV(int Val, const Type *Ty); /// getUMaxFromMismatchedTypes - Promote the operands to the wider of /// the types using zero-extension, and then perform a umax operation /// with them. - const SCEV* getUMaxFromMismatchedTypes(const SCEV* LHS, - const SCEV* RHS); + const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS, + const SCEV *RHS); /// getUMinFromMismatchedTypes - Promote the operands to the wider of /// the types using zero-extension, and then perform a umin operation /// with them. - const SCEV* getUMinFromMismatchedTypes(const SCEV* LHS, - const SCEV* RHS); + const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS, + const SCEV *RHS); /// hasSCEV - Return true if the SCEV for this value has already been /// computed. @@ -491,7 +491,7 @@ /// setSCEV - Insert the specified SCEV into the map of current SCEVs for /// the specified value. - void setSCEV(Value *V, const SCEV* H); + void setSCEV(Value *V, const SCEV *H); /// getSCEVAtScope - Return a SCEV expression handle for the specified value /// at the specified scope in the program. The L value specifies a loop @@ -503,11 +503,11 @@ /// /// In the case that a relevant loop exit value cannot be computed, the /// original value V is returned. - const SCEV* getSCEVAtScope(const SCEV *S, const Loop *L); + const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L); /// getSCEVAtScope - This is a convenience function which does /// getSCEVAtScope(getSCEV(V), L). - const SCEV* getSCEVAtScope(Value *V, const Loop *L); + const SCEV *getSCEVAtScope(Value *V, const Loop *L); /// isLoopGuardedByCond - Test whether entry to the loop is protected by /// a conditional between LHS and RHS. This is used to help avoid max @@ -526,12 +526,12 @@ /// loop-invariant backedge-taken count (see /// hasLoopInvariantBackedgeTakenCount). /// - const SCEV* getBackedgeTakenCount(const Loop *L); + const SCEV *getBackedgeTakenCount(const Loop *L); /// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except /// return the least SCEV value that is known never to be less than the /// actual backedge taken count. - const SCEV* getMaxBackedgeTakenCount(const Loop *L); + const SCEV *getMaxBackedgeTakenCount(const Loop *L); /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop /// has an analyzable loop-invariant backedge-taken count. @@ -548,15 +548,15 @@ /// time, the minimum number of times S is divisible by 2. For example, /// given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the /// bitwidth of S. - uint32_t GetMinTrailingZeros(const SCEV* S); + uint32_t GetMinTrailingZeros(const SCEV *S); /// GetMinLeadingZeros - Determine the minimum number of zero bits that S is /// guaranteed to begin with (at every loop iteration). - uint32_t GetMinLeadingZeros(const SCEV* S); + uint32_t GetMinLeadingZeros(const SCEV *S); /// GetMinSignBits - Determine the minimum number of sign bits that S is /// guaranteed to begin with. - uint32_t GetMinSignBits(const SCEV* S); + uint32_t GetMinSignBits(const SCEV *S); virtual bool runOnFunction(Function &F); virtual void releaseMemory(); Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h Tue Jul 7 12:06:11 2009 @@ -53,7 +53,7 @@ /// expandCodeFor - Insert code to directly compute the specified SCEV /// expression into the program. The inserted code is inserted into the /// specified block. - Value *expandCodeFor(const SCEV* SH, const Type *Ty, Instruction *IP) { + Value *expandCodeFor(const SCEV *SH, const Type *Ty, Instruction *IP) { Builder.SetInsertPoint(IP->getParent(), IP); return expandCodeFor(SH, Ty); } @@ -72,8 +72,8 @@ /// expandAddToGEP - Expand a SCEVAddExpr with a pointer type into a GEP /// instead of using ptrtoint+arithmetic+inttoptr. - Value *expandAddToGEP(const SCEV* const *op_begin, - const SCEV* const *op_end, + Value *expandAddToGEP(const SCEV *const *op_begin, + const SCEV *const *op_end, const PointerType *PTy, const Type *Ty, Value *V); Value *expand(const SCEV *S); @@ -82,7 +82,7 @@ /// expression into the program. The inserted code is inserted into the /// SCEVExpander's current insertion point. If a type is specified, the /// result will be expanded to have that type, with a cast if necessary. - Value *expandCodeFor(const SCEV* SH, const Type *Ty = 0); + Value *expandCodeFor(const SCEV *SH, const Type *Ty = 0); /// isInsertedInstruction - Return true if the specified instruction was /// inserted by the code rewriter. If so, the client should not modify the Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h (original) +++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Tue Jul 7 12:06:11 2009 @@ -53,8 +53,8 @@ virtual const Type *getType() const; - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const { return this; } @@ -77,15 +77,15 @@ /// class SCEVCastExpr : public SCEV { protected: - const SCEV* Op; + const SCEV *Op; const Type *Ty; - SCEVCastExpr(unsigned SCEVTy, const SCEV* op, const Type *ty); + SCEVCastExpr(unsigned SCEVTy, const SCEV *op, const Type *ty); public: virtual void Profile(FoldingSetNodeID &ID) const; - const SCEV* getOperand() const { return Op; } + const SCEV *getOperand() const { return Op; } virtual const Type *getType() const { return Ty; } virtual bool isLoopInvariant(const Loop *L) const { @@ -114,13 +114,13 @@ class SCEVTruncateExpr : public SCEVCastExpr { friend class ScalarEvolution; - SCEVTruncateExpr(const SCEV* op, const Type *ty); + SCEVTruncateExpr(const SCEV *op, const Type *ty); public: - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const { - const SCEV* H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); + const SCEV *H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H == Op) return this; return SE.getTruncateExpr(H, Ty); @@ -142,13 +142,13 @@ class SCEVZeroExtendExpr : public SCEVCastExpr { friend class ScalarEvolution; - SCEVZeroExtendExpr(const SCEV* op, const Type *ty); + SCEVZeroExtendExpr(const SCEV *op, const Type *ty); public: - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const { - const SCEV* H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); + const SCEV *H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H == Op) return this; return SE.getZeroExtendExpr(H, Ty); @@ -170,13 +170,13 @@ class SCEVSignExtendExpr : public SCEVCastExpr { friend class ScalarEvolution; - SCEVSignExtendExpr(const SCEV* op, const Type *ty); + SCEVSignExtendExpr(const SCEV *op, const Type *ty); public: - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const { - const SCEV* H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); + const SCEV *H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H == Op) return this; return SE.getSignExtendExpr(H, Ty); @@ -198,22 +198,24 @@ /// class SCEVNAryExpr : public SCEV { protected: - SmallVector Operands; + SmallVector Operands; - SCEVNAryExpr(enum SCEVTypes T, const SmallVectorImpl &ops) + SCEVNAryExpr(enum SCEVTypes T, const SmallVectorImpl &ops) : SCEV(T), Operands(ops.begin(), ops.end()) {} public: virtual void Profile(FoldingSetNodeID &ID) const; unsigned getNumOperands() const { return (unsigned)Operands.size(); } - const SCEV* getOperand(unsigned i) const { + const SCEV *getOperand(unsigned i) const { assert(i < Operands.size() && "Operand index out of range!"); return Operands[i]; } - const SmallVectorImpl &getOperands() const { return Operands; } - typedef SmallVectorImpl::const_iterator op_iterator; + const SmallVectorImpl &getOperands() const { + return Operands; + } + typedef SmallVectorImpl::const_iterator op_iterator; op_iterator op_begin() const { return Operands.begin(); } op_iterator op_end() const { return Operands.end(); } @@ -260,12 +262,12 @@ class SCEVCommutativeExpr : public SCEVNAryExpr { protected: SCEVCommutativeExpr(enum SCEVTypes T, - const SmallVectorImpl &ops) + const SmallVectorImpl &ops) : SCEVNAryExpr(T, ops) {} public: - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const; virtual const char *getOperationStr() const = 0; @@ -289,7 +291,7 @@ class SCEVAddExpr : public SCEVCommutativeExpr { friend class ScalarEvolution; - explicit SCEVAddExpr(const SmallVectorImpl &ops) + explicit SCEVAddExpr(const SmallVectorImpl &ops) : SCEVCommutativeExpr(scAddExpr, ops) { } @@ -309,7 +311,7 @@ class SCEVMulExpr : public SCEVCommutativeExpr { friend class ScalarEvolution; - explicit SCEVMulExpr(const SmallVectorImpl &ops) + explicit SCEVMulExpr(const SmallVectorImpl &ops) : SCEVCommutativeExpr(scMulExpr, ops) { } @@ -330,16 +332,16 @@ class SCEVUDivExpr : public SCEV { friend class ScalarEvolution; - const SCEV* LHS; - const SCEV* RHS; - SCEVUDivExpr(const SCEV* lhs, const SCEV* rhs) + const SCEV *LHS; + const SCEV *RHS; + SCEVUDivExpr(const SCEV *lhs, const SCEV *rhs) : SCEV(scUDivExpr), LHS(lhs), RHS(rhs) {} public: virtual void Profile(FoldingSetNodeID &ID) const; - const SCEV* getLHS() const { return LHS; } - const SCEV* getRHS() const { return RHS; } + const SCEV *getLHS() const { return LHS; } + const SCEV *getRHS() const { return RHS; } virtual bool isLoopInvariant(const Loop *L) const { return LHS->isLoopInvariant(L) && RHS->isLoopInvariant(L); @@ -350,11 +352,11 @@ RHS->hasComputableLoopEvolution(L); } - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const { - const SCEV* L = LHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); - const SCEV* R = RHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); + const SCEV *L = LHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); + const SCEV *R = RHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (L == LHS && R == RHS) return this; else @@ -389,7 +391,7 @@ const Loop *L; - SCEVAddRecExpr(const SmallVectorImpl &ops, const Loop *l) + SCEVAddRecExpr(const SmallVectorImpl &ops, const Loop *l) : SCEVNAryExpr(scAddRecExpr, ops), L(l) { for (size_t i = 0, e = Operands.size(); i != e; ++i) assert(Operands[i]->isLoopInvariant(l) && @@ -399,15 +401,16 @@ public: virtual void Profile(FoldingSetNodeID &ID) const; - const SCEV* getStart() const { return Operands[0]; } + const SCEV *getStart() const { return Operands[0]; } const Loop *getLoop() const { return L; } /// getStepRecurrence - This method constructs and returns the recurrence /// indicating how much this expression steps by. If this is a polynomial /// of degree N, it returns a chrec of degree N-1. - const SCEV* getStepRecurrence(ScalarEvolution &SE) const { + const SCEV *getStepRecurrence(ScalarEvolution &SE) const { if (isAffine()) return getOperand(1); - return SE.getAddRecExpr(SmallVector(op_begin()+1,op_end()), + return SE.getAddRecExpr(SmallVector(op_begin()+1, + op_end()), getLoop()); } @@ -435,7 +438,7 @@ /// evaluateAtIteration - Return the value of this chain of recurrences at /// the specified iteration number. - const SCEV* evaluateAtIteration(const SCEV* It, ScalarEvolution &SE) const; + const SCEV *evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const; /// getNumIterationsInRange - Return the number of iterations of this loop /// that produce values in the specified constant range. Another way of @@ -443,11 +446,11 @@ /// value is not in the condition, thus computing the exit count. If the /// iteration count can't be computed, an instance of SCEVCouldNotCompute is /// returned. - const SCEV* getNumIterationsInRange(ConstantRange Range, + const SCEV *getNumIterationsInRange(ConstantRange Range, ScalarEvolution &SE) const; - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const; virtual void print(raw_ostream &OS) const; @@ -466,7 +469,7 @@ class SCEVSMaxExpr : public SCEVCommutativeExpr { friend class ScalarEvolution; - explicit SCEVSMaxExpr(const SmallVectorImpl &ops) + explicit SCEVSMaxExpr(const SmallVectorImpl &ops) : SCEVCommutativeExpr(scSMaxExpr, ops) { } @@ -487,7 +490,7 @@ class SCEVUMaxExpr : public SCEVCommutativeExpr { friend class ScalarEvolution; - explicit SCEVUMaxExpr(const SmallVectorImpl &ops) + explicit SCEVUMaxExpr(const SmallVectorImpl &ops) : SCEVCommutativeExpr(scUMaxExpr, ops) { } @@ -524,8 +527,8 @@ return false; // not computable } - const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym, - const SCEV* Conc, + const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym, + const SCEV *Conc, ScalarEvolution &SE) const { if (&*Sym == this) return Conc; return this; Modified: llvm/trunk/lib/Analysis/IVUsers.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IVUsers.cpp?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/IVUsers.cpp (original) +++ llvm/trunk/lib/Analysis/IVUsers.cpp Tue Jul 7 12:06:11 2009 @@ -39,7 +39,7 @@ /// containsAddRecFromDifferentLoop - Determine whether expression S involves a /// subexpression that is an AddRec from a loop other than L. An outer loop /// of L is OK, but not an inner loop nor a disjoint loop. -static bool containsAddRecFromDifferentLoop(const SCEV* S, Loop *L) { +static bool containsAddRecFromDifferentLoop(const SCEV *S, Loop *L) { // This is very common, put it first. if (isa(S)) return false; @@ -80,10 +80,10 @@ /// a mix of loop invariant and loop variant expressions. The start cannot, /// however, contain an AddRec from a different loop, unless that loop is an /// outer loop of the current loop. -static bool getSCEVStartAndStride(const SCEV* &SH, Loop *L, Loop *UseLoop, - const SCEV* &Start, const SCEV* &Stride, +static bool getSCEVStartAndStride(const SCEV *&SH, Loop *L, Loop *UseLoop, + const SCEV *&Start, const SCEV *&Stride, ScalarEvolution *SE, DominatorTree *DT) { - const SCEV* TheAddRec = Start; // Initialize to zero. + const SCEV *TheAddRec = Start; // Initialize to zero. // If the outer level is an AddExpr, the operands are all start values except // for a nested AddRecExpr. @@ -109,9 +109,9 @@ // Use getSCEVAtScope to attempt to simplify other loops out of // the picture. - const SCEV* AddRecStart = AddRec->getStart(); + const SCEV *AddRecStart = AddRec->getStart(); AddRecStart = SE->getSCEVAtScope(AddRecStart, UseLoop); - const SCEV* AddRecStride = AddRec->getStepRecurrence(*SE); + const SCEV *AddRecStride = AddRec->getStepRecurrence(*SE); // FIXME: If Start contains an SCEVAddRecExpr from a different loop, other // than an outer loop of the current loop, reject it. LSR has no concept of @@ -196,13 +196,13 @@ return true; // Instruction already handled. // Get the symbolic expression for this instruction. - const SCEV* ISE = SE->getSCEV(I); + const SCEV *ISE = SE->getSCEV(I); if (isa(ISE)) return false; // Get the start and stride for this expression. Loop *UseLoop = LI->getLoopFor(I->getParent()); - const SCEV* Start = SE->getIntegerSCEV(0, ISE->getType()); - const SCEV* Stride = Start; + const SCEV *Start = SE->getIntegerSCEV(0, ISE->getType()); + const SCEV *Stride = Start; if (!getSCEVStartAndStride(ISE, L, UseLoop, Start, Stride, SE, DT)) return false; // Non-reducible symbolic expression, bail out. @@ -254,7 +254,7 @@ if (IVUseShouldUsePostIncValue(User, I, L, LI, DT, this)) { // The value used will be incremented by the stride more than we are // expecting, so subtract this off. - const SCEV* NewStart = SE->getMinusSCEV(Start, Stride); + const SCEV *NewStart = SE->getMinusSCEV(Start, Stride); StrideUses->addUser(NewStart, User, I); StrideUses->Users.back().setIsUseOfPostIncrementedValue(true); DOUT << " USING POSTINC SCEV, START=" << *NewStart<< "\n"; @@ -295,9 +295,9 @@ /// getReplacementExpr - Return a SCEV expression which computes the /// value of the OperandValToReplace of the given IVStrideUse. -const SCEV* IVUsers::getReplacementExpr(const IVStrideUse &U) const { +const SCEV *IVUsers::getReplacementExpr(const IVStrideUse &U) const { // Start with zero. - const SCEV* RetVal = SE->getIntegerSCEV(0, U.getParent()->Stride->getType()); + const SCEV *RetVal = SE->getIntegerSCEV(0, U.getParent()->Stride->getType()); // Create the basic add recurrence. RetVal = SE->getAddRecExpr(RetVal, U.getParent()->Stride, L); // Add the offset in a separate step, because it may be loop-variant. @@ -308,7 +308,7 @@ RetVal = SE->getAddExpr(RetVal, U.getParent()->Stride); // Evaluate the expression out of the loop, if possible. if (!L->contains(U.getUser()->getParent())) { - const SCEV* ExitVal = SE->getSCEVAtScope(RetVal, L->getParentLoop()); + const SCEV *ExitVal = SE->getSCEVAtScope(RetVal, L->getParentLoop()); if (ExitVal->isLoopInvariant(L)) RetVal = ExitVal; } @@ -325,7 +325,7 @@ OS << ":\n"; for (unsigned Stride = 0, e = StrideOrder.size(); Stride != e; ++Stride) { - std::map::const_iterator SI = + std::map::const_iterator SI = IVUsesByStride.find(StrideOrder[Stride]); assert(SI != IVUsesByStride.end() && "Stride doesn't exist!"); OS << " Stride " << *SI->first->getType() << " " << *SI->first << ":\n"; Modified: llvm/trunk/lib/Analysis/LoopVR.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopVR.cpp?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/LoopVR.cpp (original) +++ llvm/trunk/lib/Analysis/LoopVR.cpp Tue Jul 7 12:06:11 2009 @@ -27,8 +27,8 @@ static RegisterPass X("loopvr", "Loop Value Ranges", false, true); /// getRange - determine the range for a particular SCEV within a given Loop -ConstantRange LoopVR::getRange(const SCEV* S, Loop *L, ScalarEvolution &SE) { - const SCEV* T = SE.getBackedgeTakenCount(L); +ConstantRange LoopVR::getRange(const SCEV *S, Loop *L, ScalarEvolution &SE) { + const SCEV *T = SE.getBackedgeTakenCount(L); if (isa(T)) return ConstantRange(cast(S->getType())->getBitWidth(), true); @@ -37,7 +37,7 @@ } /// getRange - determine the range for a particular SCEV with a given trip count -ConstantRange LoopVR::getRange(const SCEV* S, const SCEV* T, ScalarEvolution &SE){ +ConstantRange LoopVR::getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE){ if (const SCEVConstant *C = dyn_cast(S)) return ConstantRange(C->getValue()->getValue()); @@ -183,8 +183,8 @@ if (!Trip) return FullSet; if (AddRec->isAffine()) { - const SCEV* StartHandle = AddRec->getStart(); - const SCEV* StepHandle = AddRec->getOperand(1); + const SCEV *StartHandle = AddRec->getStart(); + const SCEV *StepHandle = AddRec->getOperand(1); const SCEVConstant *Step = dyn_cast(StepHandle); if (!Step) return FullSet; @@ -195,7 +195,7 @@ if ((TripExt * StepExt).ugt(APInt::getLowBitsSet(ExWidth, ExWidth >> 1))) return FullSet; - const SCEV* EndHandle = SE.getAddExpr(StartHandle, + const SCEV *EndHandle = SE.getAddExpr(StartHandle, SE.getMulExpr(T, StepHandle)); const SCEVConstant *Start = dyn_cast(StartHandle); const SCEVConstant *End = dyn_cast(EndHandle); @@ -255,7 +255,7 @@ ScalarEvolution &SE = getAnalysis(); - const SCEV* S = SE.getSCEV(I); + const SCEV *S = SE.getSCEV(I); if (isa(S) || isa(S)) return ConstantRange(cast(V->getType())->getBitWidth(), false); Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Tue Jul 7 12:06:11 2009 @@ -14,7 +14,7 @@ // There are several aspects to this library. First is the representation of // scalar expressions, which are represented as subclasses of the SCEV class. // These classes are used to represent certain types of subexpressions that we -// can handle. These classes are reference counted, managed by the const SCEV* +// can handle. These classes are reference counted, managed by the const SCEV * // class. We only create one SCEV of a particular shape, so pointer-comparisons // for equality are legal. // @@ -180,7 +180,7 @@ return S->getSCEVType() == scCouldNotCompute; } -const SCEV* ScalarEvolution::getConstant(ConstantInt *V) { +const SCEV *ScalarEvolution::getConstant(ConstantInt *V) { FoldingSetNodeID ID; ID.AddInteger(scConstant); ID.AddPointer(V); @@ -192,11 +192,11 @@ return S; } -const SCEV* ScalarEvolution::getConstant(const APInt& Val) { +const SCEV *ScalarEvolution::getConstant(const APInt& Val) { return getConstant(ConstantInt::get(Val)); } -const SCEV* +const SCEV * ScalarEvolution::getConstant(const Type *Ty, uint64_t V, bool isSigned) { return getConstant(ConstantInt::get(cast(Ty), V, isSigned)); } @@ -213,7 +213,7 @@ } SCEVCastExpr::SCEVCastExpr(unsigned SCEVTy, - const SCEV* op, const Type *ty) + const SCEV *op, const Type *ty) : SCEV(SCEVTy), Op(op), Ty(ty) {} void SCEVCastExpr::Profile(FoldingSetNodeID &ID) const { @@ -226,7 +226,7 @@ return Op->dominates(BB, DT); } -SCEVTruncateExpr::SCEVTruncateExpr(const SCEV* op, const Type *ty) +SCEVTruncateExpr::SCEVTruncateExpr(const SCEV *op, const Type *ty) : SCEVCastExpr(scTruncate, op, ty) { assert((Op->getType()->isInteger() || isa(Op->getType())) && (Ty->isInteger() || isa(Ty)) && @@ -237,7 +237,7 @@ OS << "(trunc " << *Op->getType() << " " << *Op << " to " << *Ty << ")"; } -SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEV* op, const Type *ty) +SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEV *op, const Type *ty) : SCEVCastExpr(scZeroExtend, op, ty) { assert((Op->getType()->isInteger() || isa(Op->getType())) && (Ty->isInteger() || isa(Ty)) && @@ -248,7 +248,7 @@ OS << "(zext " << *Op->getType() << " " << *Op << " to " << *Ty << ")"; } -SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEV* op, const Type *ty) +SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEV *op, const Type *ty) : SCEVCastExpr(scSignExtend, op, ty) { assert((Op->getType()->isInteger() || isa(Op->getType())) && (Ty->isInteger() || isa(Ty)) && @@ -274,10 +274,10 @@ const SCEV *Conc, ScalarEvolution &SE) const { for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { - const SCEV* H = + const SCEV *H = getOperand(i)->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H != getOperand(i)) { - SmallVector NewOps; + SmallVector NewOps; NewOps.reserve(getNumOperands()); for (unsigned j = 0; j != i; ++j) NewOps.push_back(getOperand(j)); @@ -352,10 +352,10 @@ const SCEV *Conc, ScalarEvolution &SE) const { for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { - const SCEV* H = + const SCEV *H = getOperand(i)->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H != getOperand(i)) { - SmallVector NewOps; + SmallVector NewOps; NewOps.reserve(getNumOperands()); for (unsigned j = 0; j != i; ++j) NewOps.push_back(getOperand(j)); @@ -558,7 +558,7 @@ /// this to depend on where the addresses of various SCEV objects happened to /// land in memory. /// -static void GroupByComplexity(SmallVectorImpl &Ops, +static void GroupByComplexity(SmallVectorImpl &Ops, LoopInfo *LI) { if (Ops.size() < 2) return; // Noop if (Ops.size() == 2) { @@ -601,7 +601,7 @@ /// BinomialCoefficient - Compute BC(It, K). The result has width W. /// Assume, K > 0. -static const SCEV* BinomialCoefficient(const SCEV* It, unsigned K, +static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K, ScalarEvolution &SE, const Type* ResultTy) { // Handle the simplest case efficiently. @@ -694,15 +694,15 @@ // Calculate the product, at width T+W const IntegerType *CalculationTy = IntegerType::get(CalculationBits); - const SCEV* Dividend = SE.getTruncateOrZeroExtend(It, CalculationTy); + const SCEV *Dividend = SE.getTruncateOrZeroExtend(It, CalculationTy); for (unsigned i = 1; i != K; ++i) { - const SCEV* S = SE.getMinusSCEV(It, SE.getIntegerSCEV(i, It->getType())); + const SCEV *S = SE.getMinusSCEV(It, SE.getIntegerSCEV(i, It->getType())); Dividend = SE.getMulExpr(Dividend, SE.getTruncateOrZeroExtend(S, CalculationTy)); } // Divide by 2^T - const SCEV* DivResult = SE.getUDivExpr(Dividend, SE.getConstant(DivFactor)); + const SCEV *DivResult = SE.getUDivExpr(Dividend, SE.getConstant(DivFactor)); // Truncate the result, and divide by K! / 2^T. @@ -719,14 +719,14 @@ /// /// where BC(It, k) stands for binomial coefficient. /// -const SCEV* SCEVAddRecExpr::evaluateAtIteration(const SCEV* It, +const SCEV *SCEVAddRecExpr::evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const { - const SCEV* Result = getStart(); + const SCEV *Result = getStart(); for (unsigned i = 1, e = getNumOperands(); i != e; ++i) { // The computation is correct in the face of overflow provided that the // multiplication is performed _after_ the evaluation of the binomial // coefficient. - const SCEV* Coeff = BinomialCoefficient(It, i, SE, getType()); + const SCEV *Coeff = BinomialCoefficient(It, i, SE, getType()); if (isa(Coeff)) return Coeff; @@ -739,7 +739,7 @@ // SCEV Expression folder implementations //===----------------------------------------------------------------------===// -const SCEV* ScalarEvolution::getTruncateExpr(const SCEV* Op, +const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, const Type *Ty) { assert(getTypeSizeInBits(Op->getType()) > getTypeSizeInBits(Ty) && "This is not a truncating conversion!"); @@ -766,7 +766,7 @@ // If the input value is a chrec scev, truncate the chrec's operands. if (const SCEVAddRecExpr *AddRec = dyn_cast(Op)) { - SmallVector Operands; + SmallVector Operands; for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i) Operands.push_back(getTruncateExpr(AddRec->getOperand(i), Ty)); return getAddRecExpr(Operands, AddRec->getLoop()); @@ -784,7 +784,7 @@ return S; } -const SCEV* ScalarEvolution::getZeroExtendExpr(const SCEV* Op, +const SCEV *ScalarEvolution::getZeroExtendExpr(const SCEV *Op, const Type *Ty) { assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) && "This is not an extending conversion!"); @@ -818,28 +818,28 @@ // in infinite recursion. In the later case, the analysis code will // cope with a conservative value, and it will take care to purge // that value once it has finished. - const SCEV* MaxBECount = getMaxBackedgeTakenCount(AR->getLoop()); + const SCEV *MaxBECount = getMaxBackedgeTakenCount(AR->getLoop()); if (!isa(MaxBECount)) { // Manually compute the final value for AR, checking for // overflow. - const SCEV* Start = AR->getStart(); - const SCEV* Step = AR->getStepRecurrence(*this); + const SCEV *Start = AR->getStart(); + const SCEV *Step = AR->getStepRecurrence(*this); // Check whether the backedge-taken count can be losslessly casted to // the addrec's type. The count is always unsigned. - const SCEV* CastedMaxBECount = + const SCEV *CastedMaxBECount = getTruncateOrZeroExtend(MaxBECount, Start->getType()); - const SCEV* RecastedMaxBECount = + const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); if (MaxBECount == RecastedMaxBECount) { const Type *WideTy = IntegerType::get(getTypeSizeInBits(Start->getType()) * 2); // Check whether Start+Step*MaxBECount has no unsigned overflow. - const SCEV* ZMul = + const SCEV *ZMul = getMulExpr(CastedMaxBECount, getTruncateOrZeroExtend(Step, Start->getType())); - const SCEV* Add = getAddExpr(Start, ZMul); - const SCEV* OperandExtendedAdd = + const SCEV *Add = getAddExpr(Start, ZMul); + const SCEV *OperandExtendedAdd = getAddExpr(getZeroExtendExpr(Start, WideTy), getMulExpr(getZeroExtendExpr(CastedMaxBECount, WideTy), getZeroExtendExpr(Step, WideTy))); @@ -851,7 +851,7 @@ // Similar to above, only this time treat the step value as signed. // This covers loops that count down. - const SCEV* SMul = + const SCEV *SMul = getMulExpr(CastedMaxBECount, getTruncateOrSignExtend(Step, Start->getType())); Add = getAddExpr(Start, SMul); @@ -880,7 +880,7 @@ return S; } -const SCEV* ScalarEvolution::getSignExtendExpr(const SCEV* Op, +const SCEV *ScalarEvolution::getSignExtendExpr(const SCEV *Op, const Type *Ty) { assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) && "This is not an extending conversion!"); @@ -914,28 +914,28 @@ // in infinite recursion. In the later case, the analysis code will // cope with a conservative value, and it will take care to purge // that value once it has finished. - const SCEV* MaxBECount = getMaxBackedgeTakenCount(AR->getLoop()); + const SCEV *MaxBECount = getMaxBackedgeTakenCount(AR->getLoop()); if (!isa(MaxBECount)) { // Manually compute the final value for AR, checking for // overflow. - const SCEV* Start = AR->getStart(); - const SCEV* Step = AR->getStepRecurrence(*this); + const SCEV *Start = AR->getStart(); + const SCEV *Step = AR->getStepRecurrence(*this); // Check whether the backedge-taken count can be losslessly casted to // the addrec's type. The count is always unsigned. - const SCEV* CastedMaxBECount = + const SCEV *CastedMaxBECount = getTruncateOrZeroExtend(MaxBECount, Start->getType()); - const SCEV* RecastedMaxBECount = + const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); if (MaxBECount == RecastedMaxBECount) { const Type *WideTy = IntegerType::get(getTypeSizeInBits(Start->getType()) * 2); // Check whether Start+Step*MaxBECount has no signed overflow. - const SCEV* SMul = + const SCEV *SMul = getMulExpr(CastedMaxBECount, getTruncateOrSignExtend(Step, Start->getType())); - const SCEV* Add = getAddExpr(Start, SMul); - const SCEV* OperandExtendedAdd = + const SCEV *Add = getAddExpr(Start, SMul); + const SCEV *OperandExtendedAdd = getAddExpr(getSignExtendExpr(Start, WideTy), getMulExpr(getZeroExtendExpr(CastedMaxBECount, WideTy), getSignExtendExpr(Step, WideTy))); @@ -963,7 +963,7 @@ /// getAnyExtendExpr - Return a SCEV for the given operand extended with /// unspecified bits out to the given type. /// -const SCEV* ScalarEvolution::getAnyExtendExpr(const SCEV* Op, +const SCEV *ScalarEvolution::getAnyExtendExpr(const SCEV *Op, const Type *Ty) { assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) && "This is not an extending conversion!"); @@ -978,19 +978,19 @@ // Peel off a truncate cast. if (const SCEVTruncateExpr *T = dyn_cast(Op)) { - const SCEV* NewOp = T->getOperand(); + const SCEV *NewOp = T->getOperand(); if (getTypeSizeInBits(NewOp->getType()) < getTypeSizeInBits(Ty)) return getAnyExtendExpr(NewOp, Ty); return getTruncateOrNoop(NewOp, Ty); } // Next try a zext cast. If the cast is folded, use it. - const SCEV* ZExt = getZeroExtendExpr(Op, Ty); + const SCEV *ZExt = getZeroExtendExpr(Op, Ty); if (!isa(ZExt)) return ZExt; // Next try a sext cast. If the cast is folded, use it. - const SCEV* SExt = getSignExtendExpr(Op, Ty); + const SCEV *SExt = getSignExtendExpr(Op, Ty); if (!isa(SExt)) return SExt; @@ -1028,10 +1028,10 @@ /// is also used as a check to avoid infinite recursion. /// static bool -CollectAddOperandsWithScales(DenseMap &M, - SmallVector &NewOps, +CollectAddOperandsWithScales(DenseMap &M, + SmallVector &NewOps, APInt &AccumulatedConstant, - const SmallVectorImpl &Ops, + const SmallVectorImpl &Ops, const APInt &Scale, ScalarEvolution &SE) { bool Interesting = false; @@ -1052,9 +1052,9 @@ } else { // A multiplication of a constant with some other value. Update // the map. - SmallVector MulOps(Mul->op_begin()+1, Mul->op_end()); - const SCEV* Key = SE.getMulExpr(MulOps); - std::pair::iterator, bool> Pair = + SmallVector MulOps(Mul->op_begin()+1, Mul->op_end()); + const SCEV *Key = SE.getMulExpr(MulOps); + std::pair::iterator, bool> Pair = M.insert(std::make_pair(Key, NewScale)); if (Pair.second) { NewOps.push_back(Pair.first->first); @@ -1072,7 +1072,7 @@ AccumulatedConstant += Scale * C->getValue()->getValue(); } else { // An ordinary operand. Update the map. - std::pair::iterator, bool> Pair = + std::pair::iterator, bool> Pair = M.insert(std::make_pair(Ops[i], Scale)); if (Pair.second) { NewOps.push_back(Pair.first->first); @@ -1098,7 +1098,7 @@ /// getAddExpr - Get a canonical add expression, or something simpler if /// possible. -const SCEV* ScalarEvolution::getAddExpr(SmallVectorImpl &Ops) { +const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops) { assert(!Ops.empty() && "Cannot get empty add!"); if (Ops.size() == 1) return Ops[0]; #ifndef NDEBUG @@ -1142,8 +1142,8 @@ if (Ops[i] == Ops[i+1]) { // X + Y + Y --> X + Y*2 // Found a match, merge the two values into a multiply, and add any // remaining values to the result. - const SCEV* Two = getIntegerSCEV(2, Ty); - const SCEV* Mul = getMulExpr(Ops[i], Two); + const SCEV *Two = getIntegerSCEV(2, Ty); + const SCEV *Mul = getMulExpr(Ops[i], Two); if (Ops.size() == 2) return Mul; Ops.erase(Ops.begin()+i, Ops.begin()+i+2); @@ -1159,7 +1159,7 @@ const SCEVTruncateExpr *Trunc = cast(Ops[Idx]); const Type *DstType = Trunc->getType(); const Type *SrcType = Trunc->getOperand()->getType(); - SmallVector LargeOps; + SmallVector LargeOps; bool Ok = true; // Check all the operands to see if they can be represented in the // source type of the truncate. @@ -1175,7 +1175,7 @@ // is much more likely to be foldable here. LargeOps.push_back(getSignExtendExpr(C, SrcType)); } else if (const SCEVMulExpr *M = dyn_cast(Ops[i])) { - SmallVector LargeMulOps; + SmallVector LargeMulOps; for (unsigned j = 0, f = M->getNumOperands(); j != f && Ok; ++j) { if (const SCEVTruncateExpr *T = dyn_cast(M->getOperand(j))) { @@ -1203,7 +1203,7 @@ } if (Ok) { // Evaluate the expression in the larger type. - const SCEV* Fold = getAddExpr(LargeOps); + const SCEV *Fold = getAddExpr(LargeOps); // If it folds to something simple, use it. Otherwise, don't. if (isa(Fold) || isa(Fold)) return getTruncateExpr(Fold, DstType); @@ -1240,16 +1240,16 @@ // operands multiplied by constant values. if (Idx < Ops.size() && isa(Ops[Idx])) { uint64_t BitWidth = getTypeSizeInBits(Ty); - DenseMap M; - SmallVector NewOps; + DenseMap M; + SmallVector NewOps; APInt AccumulatedConstant(BitWidth, 0); if (CollectAddOperandsWithScales(M, NewOps, AccumulatedConstant, Ops, APInt(BitWidth, 1), *this)) { // Some interesting folding opportunity is present, so its worthwhile to // re-generate the operands list. Group the operands by constant scale, // to avoid multiplying by the same constant scale multiple times. - std::map, APIntCompare> MulOpLists; - for (SmallVector::iterator I = NewOps.begin(), + std::map, APIntCompare> MulOpLists; + for (SmallVector::iterator I = NewOps.begin(), E = NewOps.end(); I != E; ++I) MulOpLists[M.find(*I)->second].push_back(*I); // Re-generate the operands list. @@ -1279,17 +1279,17 @@ for (unsigned AddOp = 0, e = Ops.size(); AddOp != e; ++AddOp) if (MulOpSCEV == Ops[AddOp] && !isa(Ops[AddOp])) { // Fold W + X + (X * Y * Z) --> W + (X * ((Y*Z)+1)) - const SCEV* InnerMul = Mul->getOperand(MulOp == 0); + const SCEV *InnerMul = Mul->getOperand(MulOp == 0); if (Mul->getNumOperands() != 2) { // If the multiply has more than two operands, we must get the // Y*Z term. - SmallVector MulOps(Mul->op_begin(), Mul->op_end()); + SmallVector MulOps(Mul->op_begin(), Mul->op_end()); MulOps.erase(MulOps.begin()+MulOp); InnerMul = getMulExpr(MulOps); } - const SCEV* One = getIntegerSCEV(1, Ty); - const SCEV* AddOne = getAddExpr(InnerMul, One); - const SCEV* OuterMul = getMulExpr(AddOne, Ops[AddOp]); + const SCEV *One = getIntegerSCEV(1, Ty); + const SCEV *AddOne = getAddExpr(InnerMul, One); + const SCEV *OuterMul = getMulExpr(AddOne, Ops[AddOp]); if (Ops.size() == 2) return OuterMul; if (AddOp < Idx) { Ops.erase(Ops.begin()+AddOp); @@ -1313,22 +1313,22 @@ OMulOp != e; ++OMulOp) if (OtherMul->getOperand(OMulOp) == MulOpSCEV) { // Fold X + (A*B*C) + (A*D*E) --> X + (A*(B*C+D*E)) - const SCEV* InnerMul1 = Mul->getOperand(MulOp == 0); + const SCEV *InnerMul1 = Mul->getOperand(MulOp == 0); if (Mul->getNumOperands() != 2) { SmallVector MulOps(Mul->op_begin(), Mul->op_end()); MulOps.erase(MulOps.begin()+MulOp); InnerMul1 = getMulExpr(MulOps); } - const SCEV* InnerMul2 = OtherMul->getOperand(OMulOp == 0); + const SCEV *InnerMul2 = OtherMul->getOperand(OMulOp == 0); if (OtherMul->getNumOperands() != 2) { SmallVector MulOps(OtherMul->op_begin(), OtherMul->op_end()); MulOps.erase(MulOps.begin()+OMulOp); InnerMul2 = getMulExpr(MulOps); } - const SCEV* InnerMulSum = getAddExpr(InnerMul1,InnerMul2); - const SCEV* OuterMul = getMulExpr(MulOpSCEV, InnerMulSum); + const SCEV *InnerMulSum = getAddExpr(InnerMul1,InnerMul2); + const SCEV *OuterMul = getMulExpr(MulOpSCEV, InnerMulSum); if (Ops.size() == 2) return OuterMul; Ops.erase(Ops.begin()+Idx); Ops.erase(Ops.begin()+OtherMulIdx-1); @@ -1349,7 +1349,7 @@ for (; Idx < Ops.size() && isa(Ops[Idx]); ++Idx) { // Scan all of the other operands to this add and add them to the vector if // they are loop invariant w.r.t. the recurrence. - SmallVector LIOps; + SmallVector LIOps; const SCEVAddRecExpr *AddRec = cast(Ops[Idx]); for (unsigned i = 0, e = Ops.size(); i != e; ++i) if (Ops[i]->isLoopInvariant(AddRec->getLoop())) { @@ -1363,11 +1363,11 @@ // NLI + LI + {Start,+,Step} --> NLI + {LI+Start,+,Step} LIOps.push_back(AddRec->getStart()); - SmallVector AddRecOps(AddRec->op_begin(), + SmallVector AddRecOps(AddRec->op_begin(), AddRec->op_end()); AddRecOps[0] = getAddExpr(LIOps); - const SCEV* NewRec = getAddRecExpr(AddRecOps, AddRec->getLoop()); + const SCEV *NewRec = getAddRecExpr(AddRecOps, AddRec->getLoop()); // If all of the other operands were loop invariant, we are done. if (Ops.size() == 1) return NewRec; @@ -1399,7 +1399,7 @@ } NewOps[i] = getAddExpr(NewOps[i], OtherAddRec->getOperand(i)); } - const SCEV* NewAddRec = getAddRecExpr(NewOps, AddRec->getLoop()); + const SCEV *NewAddRec = getAddRecExpr(NewOps, AddRec->getLoop()); if (Ops.size() == 2) return NewAddRec; @@ -1432,7 +1432,7 @@ /// getMulExpr - Get a canonical multiply expression, or something simpler if /// possible. -const SCEV* ScalarEvolution::getMulExpr(SmallVectorImpl &Ops) { +const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl &Ops) { assert(!Ops.empty() && "Cannot get empty mul!"); #ifndef NDEBUG for (unsigned i = 1, e = Ops.size(); i != e; ++i) @@ -1513,7 +1513,7 @@ for (; Idx < Ops.size() && isa(Ops[Idx]); ++Idx) { // Scan all of the other operands to this mul and add them to the vector if // they are loop invariant w.r.t. the recurrence. - SmallVector LIOps; + SmallVector LIOps; const SCEVAddRecExpr *AddRec = cast(Ops[Idx]); for (unsigned i = 0, e = Ops.size(); i != e; ++i) if (Ops[i]->isLoopInvariant(AddRec->getLoop())) { @@ -1525,7 +1525,7 @@ // If we found some loop invariants, fold them into the recurrence. if (!LIOps.empty()) { // NLI * LI * {Start,+,Step} --> NLI * {LI*Start,+,LI*Step} - SmallVector NewOps; + SmallVector NewOps; NewOps.reserve(AddRec->getNumOperands()); if (LIOps.size() == 1) { const SCEV *Scale = LIOps[0]; @@ -1533,13 +1533,13 @@ NewOps.push_back(getMulExpr(Scale, AddRec->getOperand(i))); } else { for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i) { - SmallVector MulOps(LIOps.begin(), LIOps.end()); + SmallVector MulOps(LIOps.begin(), LIOps.end()); MulOps.push_back(AddRec->getOperand(i)); NewOps.push_back(getMulExpr(MulOps)); } } - const SCEV* NewRec = getAddRecExpr(NewOps, AddRec->getLoop()); + const SCEV *NewRec = getAddRecExpr(NewOps, AddRec->getLoop()); // If all of the other operands were loop invariant, we are done. if (Ops.size() == 1) return NewRec; @@ -1563,14 +1563,14 @@ if (AddRec->getLoop() == OtherAddRec->getLoop()) { // F * G --> {A,+,B} * {C,+,D} --> {A*C,+,F*D + G*B + B*D} const SCEVAddRecExpr *F = AddRec, *G = OtherAddRec; - const SCEV* NewStart = getMulExpr(F->getStart(), + const SCEV *NewStart = getMulExpr(F->getStart(), G->getStart()); - const SCEV* B = F->getStepRecurrence(*this); - const SCEV* D = G->getStepRecurrence(*this); - const SCEV* NewStep = getAddExpr(getMulExpr(F, D), + const SCEV *B = F->getStepRecurrence(*this); + const SCEV *D = G->getStepRecurrence(*this); + const SCEV *NewStep = getAddExpr(getMulExpr(F, D), getMulExpr(G, B), getMulExpr(B, D)); - const SCEV* NewAddRec = getAddRecExpr(NewStart, NewStep, + const SCEV *NewAddRec = getAddRecExpr(NewStart, NewStep, F->getLoop()); if (Ops.size() == 2) return NewAddRec; @@ -1636,24 +1636,24 @@ getAddRecExpr(getZeroExtendExpr(AR->getStart(), ExtTy), getZeroExtendExpr(Step, ExtTy), AR->getLoop())) { - SmallVector Operands; + SmallVector Operands; for (unsigned i = 0, e = AR->getNumOperands(); i != e; ++i) Operands.push_back(getUDivExpr(AR->getOperand(i), RHS)); return getAddRecExpr(Operands, AR->getLoop()); } // (A*B)/C --> A*(B/C) if safe and B/C can be folded. if (const SCEVMulExpr *M = dyn_cast(LHS)) { - SmallVector Operands; + SmallVector Operands; for (unsigned i = 0, e = M->getNumOperands(); i != e; ++i) Operands.push_back(getZeroExtendExpr(M->getOperand(i), ExtTy)); if (getZeroExtendExpr(M, ExtTy) == getMulExpr(Operands)) // Find an operand that's safely divisible. for (unsigned i = 0, e = M->getNumOperands(); i != e; ++i) { - const SCEV* Op = M->getOperand(i); - const SCEV* Div = getUDivExpr(Op, RHSC); + const SCEV *Op = M->getOperand(i); + const SCEV *Div = getUDivExpr(Op, RHSC); if (!isa(Div) && getMulExpr(Div, RHSC) == Op) { - const SmallVectorImpl &MOperands = M->getOperands(); - Operands = SmallVector(MOperands.begin(), + const SmallVectorImpl &MOperands = M->getOperands(); + Operands = SmallVector(MOperands.begin(), MOperands.end()); Operands[i] = Div; return getMulExpr(Operands); @@ -1662,13 +1662,13 @@ } // (A+B)/C --> (A/C + B/C) if safe and A/C and B/C can be folded. if (const SCEVAddRecExpr *A = dyn_cast(LHS)) { - SmallVector Operands; + SmallVector Operands; for (unsigned i = 0, e = A->getNumOperands(); i != e; ++i) Operands.push_back(getZeroExtendExpr(A->getOperand(i), ExtTy)); if (getZeroExtendExpr(A, ExtTy) == getAddExpr(Operands)) { Operands.clear(); for (unsigned i = 0, e = A->getNumOperands(); i != e; ++i) { - const SCEV* Op = getUDivExpr(A->getOperand(i), RHS); + const SCEV *Op = getUDivExpr(A->getOperand(i), RHS); if (isa(Op) || getMulExpr(Op, RHS) != A->getOperand(i)) break; Operands.push_back(Op); @@ -1702,9 +1702,9 @@ /// getAddRecExpr - Get an add recurrence expression for the specified loop. /// Simplify the expression as much as possible. -const SCEV* ScalarEvolution::getAddRecExpr(const SCEV* Start, - const SCEV* Step, const Loop *L) { - SmallVector Operands; +const SCEV *ScalarEvolution::getAddRecExpr(const SCEV *Start, + const SCEV *Step, const Loop *L) { + SmallVector Operands; Operands.push_back(Start); if (const SCEVAddRecExpr *StepChrec = dyn_cast(Step)) if (StepChrec->getLoop() == L) { @@ -1720,7 +1720,7 @@ /// getAddRecExpr - Get an add recurrence expression for the specified loop. /// Simplify the expression as much as possible. const SCEV * -ScalarEvolution::getAddRecExpr(SmallVectorImpl &Operands, +ScalarEvolution::getAddRecExpr(SmallVectorImpl &Operands, const Loop *L) { if (Operands.size() == 1) return Operands[0]; #ifndef NDEBUG @@ -1739,7 +1739,7 @@ if (const SCEVAddRecExpr *NestedAR = dyn_cast(Operands[0])) { const Loop* NestedLoop = NestedAR->getLoop(); if (L->getLoopDepth() < NestedLoop->getLoopDepth()) { - SmallVector NestedOperands(NestedAR->op_begin(), + SmallVector NestedOperands(NestedAR->op_begin(), NestedAR->op_end()); Operands[0] = NestedAR->getStart(); // AddRecs require their operands be loop-invariant with respect to their @@ -1784,14 +1784,14 @@ const SCEV *ScalarEvolution::getSMaxExpr(const SCEV *LHS, const SCEV *RHS) { - SmallVector Ops; + SmallVector Ops; Ops.push_back(LHS); Ops.push_back(RHS); return getSMaxExpr(Ops); } -const SCEV* -ScalarEvolution::getSMaxExpr(SmallVectorImpl &Ops) { +const SCEV * +ScalarEvolution::getSMaxExpr(SmallVectorImpl &Ops) { assert(!Ops.empty() && "Cannot get empty smax!"); if (Ops.size() == 1) return Ops[0]; #ifndef NDEBUG @@ -1881,14 +1881,14 @@ const SCEV *ScalarEvolution::getUMaxExpr(const SCEV *LHS, const SCEV *RHS) { - SmallVector Ops; + SmallVector Ops; Ops.push_back(LHS); Ops.push_back(RHS); return getUMaxExpr(Ops); } -const SCEV* -ScalarEvolution::getUMaxExpr(SmallVectorImpl &Ops) { +const SCEV * +ScalarEvolution::getUMaxExpr(SmallVectorImpl &Ops) { assert(!Ops.empty() && "Cannot get empty umax!"); if (Ops.size() == 1) return Ops[0]; #ifndef NDEBUG @@ -1988,7 +1988,7 @@ return getNotSCEV(getUMaxExpr(getNotSCEV(LHS), getNotSCEV(RHS))); } -const SCEV* ScalarEvolution::getUnknown(Value *V) { +const SCEV *ScalarEvolution::getUnknown(Value *V) { // Don't attempt to do anything other than create a SCEVUnknown object // here. createSCEV only calls getUnknown after checking for all other // interesting possibilities, and any other code that calls getUnknown @@ -2055,7 +2055,7 @@ return TD->getIntPtrType(); } -const SCEV* ScalarEvolution::getCouldNotCompute() { +const SCEV *ScalarEvolution::getCouldNotCompute() { return &CouldNotCompute; } @@ -2067,26 +2067,26 @@ /// getSCEV - Return an existing SCEV if it exists, otherwise analyze the /// expression and create a new one. -const SCEV* ScalarEvolution::getSCEV(Value *V) { +const SCEV *ScalarEvolution::getSCEV(Value *V) { assert(isSCEVable(V->getType()) && "Value is not SCEVable!"); - std::map::iterator I = Scalars.find(V); + std::map::iterator I = Scalars.find(V); if (I != Scalars.end()) return I->second; - const SCEV* S = createSCEV(V); + const SCEV *S = createSCEV(V); Scalars.insert(std::make_pair(SCEVCallbackVH(V, this), S)); return S; } /// getIntegerSCEV - Given a SCEVable type, create a constant for the /// specified signed integer value and return a SCEV for the constant. -const SCEV* ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) { +const SCEV *ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) { const IntegerType *ITy = cast(getEffectiveSCEVType(Ty)); return getConstant(ConstantInt::get(ITy, Val)); } /// getNegativeSCEV - Return a SCEV corresponding to -V = -1*V /// -const SCEV* ScalarEvolution::getNegativeSCEV(const SCEV* V) { +const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V) { if (const SCEVConstant *VC = dyn_cast(V)) return getConstant(cast(ConstantExpr::getNeg(VC->getValue()))); @@ -2096,13 +2096,13 @@ } /// getNotSCEV - Return a SCEV corresponding to ~V = -1-V -const SCEV* ScalarEvolution::getNotSCEV(const SCEV* V) { +const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) { if (const SCEVConstant *VC = dyn_cast(V)) return getConstant(cast(ConstantExpr::getNot(VC->getValue()))); const Type *Ty = V->getType(); Ty = getEffectiveSCEVType(Ty); - const SCEV* AllOnes = getConstant(ConstantInt::getAllOnesValue(Ty)); + const SCEV *AllOnes = getConstant(ConstantInt::getAllOnesValue(Ty)); return getMinusSCEV(AllOnes, V); } @@ -2117,8 +2117,8 @@ /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion of the /// input value to the specified type. If the type must be extended, it is zero /// extended. -const SCEV* -ScalarEvolution::getTruncateOrZeroExtend(const SCEV* V, +const SCEV * +ScalarEvolution::getTruncateOrZeroExtend(const SCEV *V, const Type *Ty) { const Type *SrcTy = V->getType(); assert((SrcTy->isInteger() || (TD && isa(SrcTy))) && @@ -2134,8 +2134,8 @@ /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion of the /// input value to the specified type. If the type must be extended, it is sign /// extended. -const SCEV* -ScalarEvolution::getTruncateOrSignExtend(const SCEV* V, +const SCEV * +ScalarEvolution::getTruncateOrSignExtend(const SCEV *V, const Type *Ty) { const Type *SrcTy = V->getType(); assert((SrcTy->isInteger() || (TD && isa(SrcTy))) && @@ -2151,8 +2151,8 @@ /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of the /// input value to the specified type. If the type must be extended, it is zero /// extended. The conversion must not be narrowing. -const SCEV* -ScalarEvolution::getNoopOrZeroExtend(const SCEV* V, const Type *Ty) { +const SCEV * +ScalarEvolution::getNoopOrZeroExtend(const SCEV *V, const Type *Ty) { const Type *SrcTy = V->getType(); assert((SrcTy->isInteger() || (TD && isa(SrcTy))) && (Ty->isInteger() || (TD && isa(Ty))) && @@ -2167,8 +2167,8 @@ /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of the /// input value to the specified type. If the type must be extended, it is sign /// extended. The conversion must not be narrowing. -const SCEV* -ScalarEvolution::getNoopOrSignExtend(const SCEV* V, const Type *Ty) { +const SCEV * +ScalarEvolution::getNoopOrSignExtend(const SCEV *V, const Type *Ty) { const Type *SrcTy = V->getType(); assert((SrcTy->isInteger() || (TD && isa(SrcTy))) && (Ty->isInteger() || (TD && isa(Ty))) && @@ -2184,8 +2184,8 @@ /// the input value to the specified type. If the type must be extended, /// it is extended with unspecified bits. The conversion must not be /// narrowing. -const SCEV* -ScalarEvolution::getNoopOrAnyExtend(const SCEV* V, const Type *Ty) { +const SCEV * +ScalarEvolution::getNoopOrAnyExtend(const SCEV *V, const Type *Ty) { const Type *SrcTy = V->getType(); assert((SrcTy->isInteger() || (TD && isa(SrcTy))) && (Ty->isInteger() || (TD && isa(Ty))) && @@ -2199,8 +2199,8 @@ /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the /// input value to the specified type. The conversion must not be widening. -const SCEV* -ScalarEvolution::getTruncateOrNoop(const SCEV* V, const Type *Ty) { +const SCEV * +ScalarEvolution::getTruncateOrNoop(const SCEV *V, const Type *Ty) { const Type *SrcTy = V->getType(); assert((SrcTy->isInteger() || (TD && isa(SrcTy))) && (Ty->isInteger() || (TD && isa(Ty))) && @@ -2217,8 +2217,8 @@ /// with them. const SCEV *ScalarEvolution::getUMaxFromMismatchedTypes(const SCEV *LHS, const SCEV *RHS) { - const SCEV* PromotedLHS = LHS; - const SCEV* PromotedRHS = RHS; + const SCEV *PromotedLHS = LHS; + const SCEV *PromotedRHS = RHS; if (getTypeSizeInBits(LHS->getType()) > getTypeSizeInBits(RHS->getType())) PromotedRHS = getZeroExtendExpr(RHS, LHS->getType()); @@ -2233,8 +2233,8 @@ /// with them. const SCEV *ScalarEvolution::getUMinFromMismatchedTypes(const SCEV *LHS, const SCEV *RHS) { - const SCEV* PromotedLHS = LHS; - const SCEV* PromotedRHS = RHS; + const SCEV *PromotedLHS = LHS; + const SCEV *PromotedRHS = RHS; if (getTypeSizeInBits(LHS->getType()) > getTypeSizeInBits(RHS->getType())) PromotedRHS = getZeroExtendExpr(RHS, LHS->getType()); @@ -2251,11 +2251,11 @@ ScalarEvolution::ReplaceSymbolicValueWithConcrete(Instruction *I, const SCEV *SymName, const SCEV *NewVal) { - std::map::iterator SI = + std::map::iterator SI = Scalars.find(SCEVCallbackVH(I, this)); if (SI == Scalars.end()) return; - const SCEV* NV = + const SCEV *NV = SI->second->replaceSymbolicValuesWithConcrete(SymName, NewVal, *this); if (NV == SI->second) return; // No change. @@ -2271,7 +2271,7 @@ /// createNodeForPHI - PHI nodes have two cases. Either the PHI node exists in /// a loop header, making it a potential recurrence, or it doesn't. /// -const SCEV* ScalarEvolution::createNodeForPHI(PHINode *PN) { +const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { if (PN->getNumIncomingValues() == 2) // The loops have been canonicalized. if (const Loop *L = LI->getLoopFor(PN->getParent())) if (L->getHeader() == PN->getParent()) { @@ -2281,14 +2281,14 @@ unsigned BackEdge = IncomingEdge^1; // While we are analyzing this PHI node, handle its value symbolically. - const SCEV* SymbolicName = getUnknown(PN); + const SCEV *SymbolicName = getUnknown(PN); assert(Scalars.find(PN) == Scalars.end() && "PHI node already processed?"); Scalars.insert(std::make_pair(SCEVCallbackVH(PN, this), SymbolicName)); // Using this symbolic name for the PHI, analyze the value coming around // the back-edge. - const SCEV* BEValue = getSCEV(PN->getIncomingValue(BackEdge)); + const SCEV *BEValue = getSCEV(PN->getIncomingValue(BackEdge)); // NOTE: If BEValue is loop invariant, we know that the PHI node just // has a special value for the first iteration of the loop. @@ -2308,11 +2308,11 @@ if (FoundIndex != Add->getNumOperands()) { // Create an add with everything but the specified operand. - SmallVector Ops; + SmallVector Ops; for (unsigned i = 0, e = Add->getNumOperands(); i != e; ++i) if (i != FoundIndex) Ops.push_back(Add->getOperand(i)); - const SCEV* Accum = getAddExpr(Ops); + const SCEV *Accum = getAddExpr(Ops); // This is not a valid addrec if the step amount is varying each // loop iteration, but is not itself an addrec in this loop. @@ -2341,13 +2341,13 @@ // Because the other in-value of i (0) fits the evolution of BEValue // i really is an addrec evolution. if (AddRec->getLoop() == L && AddRec->isAffine()) { - const SCEV* StartVal = getSCEV(PN->getIncomingValue(IncomingEdge)); + const SCEV *StartVal = getSCEV(PN->getIncomingValue(IncomingEdge)); // If StartVal = j.start - j.stride, we can use StartVal as the // initial step of the addrec evolution. if (StartVal == getMinusSCEV(AddRec->getOperand(0), AddRec->getOperand(1))) { - const SCEV* PHISCEV = + const SCEV *PHISCEV = getAddRecExpr(StartVal, AddRec->getOperand(1), L); // Okay, for the entire analysis of this edge we assumed the PHI @@ -2371,14 +2371,14 @@ /// createNodeForGEP - Expand GEP instructions into add and multiply /// operations. This allows them to be analyzed by regular SCEV code. /// -const SCEV* ScalarEvolution::createNodeForGEP(User *GEP) { +const SCEV *ScalarEvolution::createNodeForGEP(User *GEP) { const Type *IntPtrTy = TD->getIntPtrType(); Value *Base = GEP->getOperand(0); // Don't attempt to analyze GEPs over unsized objects. if (!cast(Base->getType())->getElementType()->isSized()) return getUnknown(GEP); - const SCEV* TotalOffset = getIntegerSCEV(0, IntPtrTy); + const SCEV *TotalOffset = getIntegerSCEV(0, IntPtrTy); gep_type_iterator GTI = gep_type_begin(GEP); for (GetElementPtrInst::op_iterator I = next(GEP->op_begin()), E = GEP->op_end(); @@ -2394,7 +2394,7 @@ getIntegerSCEV(Offset, IntPtrTy)); } else { // For an array, add the element offset, explicitly scaled. - const SCEV* LocalOffset = getSCEV(Index); + const SCEV *LocalOffset = getSCEV(Index); if (!isa(LocalOffset->getType())) // Getelementptr indicies are signed. LocalOffset = getTruncateOrSignExtend(LocalOffset, @@ -2414,7 +2414,7 @@ /// the minimum number of times S is divisible by 2. For example, given {4,+,8} /// it returns 2. If S is guaranteed to be 0, it returns the bitwidth of S. uint32_t -ScalarEvolution::GetMinTrailingZeros(const SCEV* S) { +ScalarEvolution::GetMinTrailingZeros(const SCEV *S) { if (const SCEVConstant *C = dyn_cast(S)) return C->getValue()->getValue().countTrailingZeros(); @@ -2491,7 +2491,7 @@ } uint32_t -ScalarEvolution::GetMinLeadingZeros(const SCEV* S) { +ScalarEvolution::GetMinLeadingZeros(const SCEV *S) { // TODO: Handle other SCEV expression types here. if (const SCEVConstant *C = dyn_cast(S)) @@ -2517,7 +2517,7 @@ } uint32_t -ScalarEvolution::GetMinSignBits(const SCEV* S) { +ScalarEvolution::GetMinSignBits(const SCEV *S) { // TODO: Handle other SCEV expression types here. if (const SCEVConstant *C = dyn_cast(S)) { @@ -2576,7 +2576,7 @@ /// createSCEV - We know that there is no SCEV for the specified value. /// Analyze the expression. /// -const SCEV* ScalarEvolution::createSCEV(Value *V) { +const SCEV *ScalarEvolution::createSCEV(Value *V) { if (!isSCEVable(V->getType())) return getUnknown(V); @@ -2646,7 +2646,7 @@ // In order for this transformation to be safe, the LHS must be of the // form X*(2^n) and the Or constant must be less than 2^n. if (ConstantInt *CI = dyn_cast(U->getOperand(1))) { - const SCEV* LHS = getSCEV(U->getOperand(0)); + const SCEV *LHS = getSCEV(U->getOperand(0)); const APInt &CIVal = CI->getValue(); if (GetMinTrailingZeros(LHS) >= (CIVal.getBitWidth() - CIVal.countLeadingZeros())) @@ -2676,7 +2676,7 @@ if (const SCEVZeroExtendExpr *Z = dyn_cast(getSCEV(U->getOperand(0)))) { const Type *UTy = U->getType(); - const SCEV* Z0 = Z->getOperand(); + const SCEV *Z0 = Z->getOperand(); const Type *Z0Ty = Z0->getType(); unsigned Z0TySize = getTypeSizeInBits(Z0Ty); @@ -2845,14 +2845,14 @@ /// loop-invariant backedge-taken count (see /// hasLoopInvariantBackedgeTakenCount). /// -const SCEV* ScalarEvolution::getBackedgeTakenCount(const Loop *L) { +const SCEV *ScalarEvolution::getBackedgeTakenCount(const Loop *L) { return getBackedgeTakenInfo(L).Exact; } /// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except /// return the least SCEV value that is known never to be less than the /// actual backedge taken count. -const SCEV* ScalarEvolution::getMaxBackedgeTakenCount(const Loop *L) { +const SCEV *ScalarEvolution::getMaxBackedgeTakenCount(const Loop *L) { return getBackedgeTakenInfo(L).Max; } @@ -2919,7 +2919,7 @@ SmallVector Worklist; for (BasicBlock::iterator I = Header->begin(); PHINode *PN = dyn_cast(I); ++I) { - std::map::iterator It = + std::map::iterator It = Scalars.find((Value*)I); if (It != Scalars.end() && !isa(It->second)) Worklist.push_back(PN); @@ -2942,8 +2942,8 @@ L->getExitingBlocks(ExitingBlocks); // Examine all exits and pick the most conservative values. - const SCEV* BECount = getCouldNotCompute(); - const SCEV* MaxBECount = getCouldNotCompute(); + const SCEV *BECount = getCouldNotCompute(); + const SCEV *MaxBECount = getCouldNotCompute(); bool CouldNotComputeBECount = false; for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) { BackedgeTakenInfo NewBTI = @@ -3052,8 +3052,8 @@ ComputeBackedgeTakenCountFromExitCond(L, BO->getOperand(0), TBB, FBB); BackedgeTakenInfo BTI1 = ComputeBackedgeTakenCountFromExitCond(L, BO->getOperand(1), TBB, FBB); - const SCEV* BECount = getCouldNotCompute(); - const SCEV* MaxBECount = getCouldNotCompute(); + const SCEV *BECount = getCouldNotCompute(); + const SCEV *MaxBECount = getCouldNotCompute(); if (L->contains(TBB)) { // Both conditions must be true for the loop to continue executing. // Choose the less conservative count. @@ -3087,8 +3087,8 @@ ComputeBackedgeTakenCountFromExitCond(L, BO->getOperand(0), TBB, FBB); BackedgeTakenInfo BTI1 = ComputeBackedgeTakenCountFromExitCond(L, BO->getOperand(1), TBB, FBB); - const SCEV* BECount = getCouldNotCompute(); - const SCEV* MaxBECount = getCouldNotCompute(); + const SCEV *BECount = getCouldNotCompute(); + const SCEV *MaxBECount = getCouldNotCompute(); if (L->contains(FBB)) { // Both conditions must be false for the loop to continue executing. // Choose the less conservative count. @@ -3146,7 +3146,7 @@ // Handle common loops like: for (X = "string"; *X; ++X) if (LoadInst *LI = dyn_cast(ExitCond->getOperand(0))) if (Constant *RHS = dyn_cast(ExitCond->getOperand(1))) { - const SCEV* ItCnt = + const SCEV *ItCnt = ComputeLoadConstantCompareBackedgeTakenCount(LI, RHS, L, Cond); if (!isa(ItCnt)) { unsigned BitWidth = getTypeSizeInBits(ItCnt->getType()); @@ -3156,8 +3156,8 @@ } } - const SCEV* LHS = getSCEV(ExitCond->getOperand(0)); - const SCEV* RHS = getSCEV(ExitCond->getOperand(1)); + const SCEV *LHS = getSCEV(ExitCond->getOperand(0)); + const SCEV *RHS = getSCEV(ExitCond->getOperand(1)); // Try to evaluate any dependencies out of the loop. LHS = getSCEVAtScope(LHS, L); @@ -3180,20 +3180,20 @@ ConstantRange CompRange( ICmpInst::makeConstantRange(Cond, RHSC->getValue()->getValue())); - const SCEV* Ret = AddRec->getNumIterationsInRange(CompRange, *this); + const SCEV *Ret = AddRec->getNumIterationsInRange(CompRange, *this); if (!isa(Ret)) return Ret; } switch (Cond) { case ICmpInst::ICMP_NE: { // while (X != Y) // Convert to: while (X-Y != 0) - const SCEV* TC = HowFarToZero(getMinusSCEV(LHS, RHS), L); + const SCEV *TC = HowFarToZero(getMinusSCEV(LHS, RHS), L); if (!isa(TC)) return TC; break; } case ICmpInst::ICMP_EQ: { // Convert to: while (X-Y == 0) // while (X == Y) - const SCEV* TC = HowFarToNonZero(getMinusSCEV(LHS, RHS), L); + const SCEV *TC = HowFarToNonZero(getMinusSCEV(LHS, RHS), L); if (!isa(TC)) return TC; break; } @@ -3237,8 +3237,8 @@ static ConstantInt * EvaluateConstantChrecAtConstant(const SCEVAddRecExpr *AddRec, ConstantInt *C, ScalarEvolution &SE) { - const SCEV* InVal = SE.getConstant(C); - const SCEV* Val = AddRec->evaluateAtIteration(InVal, SE); + const SCEV *InVal = SE.getConstant(C); + const SCEV *Val = AddRec->evaluateAtIteration(InVal, SE); assert(isa(Val) && "Evaluation of SCEV at constant didn't fold correctly?"); return cast(Val)->getValue(); @@ -3317,7 +3317,7 @@ // Okay, we know we have a (load (gep GV, 0, X)) comparison with a constant. // Check to see if X is a loop variant variable value now. - const SCEV* Idx = getSCEV(VarIdx); + const SCEV *Idx = getSCEV(VarIdx); Idx = getSCEVAtScope(Idx, L); // We can only recognize very limited forms of loop index expressions, in @@ -3556,7 +3556,7 @@ /// /// In the case that a relevant loop exit value cannot be computed, the /// original value V is returned. -const SCEV* ScalarEvolution::getSCEVAtScope(const SCEV *V, const Loop *L) { +const SCEV *ScalarEvolution::getSCEVAtScope(const SCEV *V, const Loop *L) { // FIXME: this should be turned into a virtual method on SCEV! if (isa(V)) return V; @@ -3573,7 +3573,7 @@ // to see if the loop that contains it has a known backedge-taken // count. If so, we may be able to force computation of the exit // value. - const SCEV* BackedgeTakenCount = getBackedgeTakenCount(LI); + const SCEV *BackedgeTakenCount = getBackedgeTakenCount(LI); if (const SCEVConstant *BTCC = dyn_cast(BackedgeTakenCount)) { // Okay, we know how many times the containing loop executes. If @@ -3611,7 +3611,7 @@ if (!isSCEVable(Op->getType())) return V; - const SCEV* OpV = getSCEVAtScope(getSCEV(Op), L); + const SCEV *OpV = getSCEVAtScope(getSCEV(Op), L); if (const SCEVConstant *SC = dyn_cast(OpV)) { Constant *C = SC->getValue(); if (C->getType() != Op->getType()) @@ -3658,7 +3658,7 @@ // Avoid performing the look-up in the common case where the specified // expression has no loop-variant portions. for (unsigned i = 0, e = Comm->getNumOperands(); i != e; ++i) { - const SCEV* OpAtScope = getSCEVAtScope(Comm->getOperand(i), L); + const SCEV *OpAtScope = getSCEVAtScope(Comm->getOperand(i), L); if (OpAtScope != Comm->getOperand(i)) { // Okay, at least one of these operands is loop variant but might be // foldable. Build a new instance of the folded commutative expression. @@ -3686,8 +3686,8 @@ } if (const SCEVUDivExpr *Div = dyn_cast(V)) { - const SCEV* LHS = getSCEVAtScope(Div->getLHS(), L); - const SCEV* RHS = getSCEVAtScope(Div->getRHS(), L); + const SCEV *LHS = getSCEVAtScope(Div->getLHS(), L); + const SCEV *RHS = getSCEVAtScope(Div->getRHS(), L); if (LHS == Div->getLHS() && RHS == Div->getRHS()) return Div; // must be loop invariant return getUDivExpr(LHS, RHS); @@ -3699,7 +3699,7 @@ if (!L || !AddRec->getLoop()->contains(L->getHeader())) { // To evaluate this recurrence, we need to know how many times the AddRec // loop iterates. Compute this now. - const SCEV* BackedgeTakenCount = getBackedgeTakenCount(AddRec->getLoop()); + const SCEV *BackedgeTakenCount = getBackedgeTakenCount(AddRec->getLoop()); if (BackedgeTakenCount == getCouldNotCompute()) return AddRec; // Then, evaluate the AddRec. @@ -3709,21 +3709,21 @@ } if (const SCEVZeroExtendExpr *Cast = dyn_cast(V)) { - const SCEV* Op = getSCEVAtScope(Cast->getOperand(), L); + const SCEV *Op = getSCEVAtScope(Cast->getOperand(), L); if (Op == Cast->getOperand()) return Cast; // must be loop invariant return getZeroExtendExpr(Op, Cast->getType()); } if (const SCEVSignExtendExpr *Cast = dyn_cast(V)) { - const SCEV* Op = getSCEVAtScope(Cast->getOperand(), L); + const SCEV *Op = getSCEVAtScope(Cast->getOperand(), L); if (Op == Cast->getOperand()) return Cast; // must be loop invariant return getSignExtendExpr(Op, Cast->getType()); } if (const SCEVTruncateExpr *Cast = dyn_cast(V)) { - const SCEV* Op = getSCEVAtScope(Cast->getOperand(), L); + const SCEV *Op = getSCEVAtScope(Cast->getOperand(), L); if (Op == Cast->getOperand()) return Cast; // must be loop invariant return getTruncateExpr(Op, Cast->getType()); @@ -3735,7 +3735,7 @@ /// getSCEVAtScope - This is a convenience function which does /// getSCEVAtScope(getSCEV(V), L). -const SCEV* ScalarEvolution::getSCEVAtScope(Value *V, const Loop *L) { +const SCEV *ScalarEvolution::getSCEVAtScope(Value *V, const Loop *L) { return getSCEVAtScope(getSCEV(V), L); } @@ -3748,7 +3748,7 @@ /// A and B isn't important. /// /// If the equation does not have a solution, SCEVCouldNotCompute is returned. -static const SCEV* SolveLinEquationWithOverflow(const APInt &A, const APInt &B, +static const SCEV *SolveLinEquationWithOverflow(const APInt &A, const APInt &B, ScalarEvolution &SE) { uint32_t BW = A.getBitWidth(); assert(BW == B.getBitWidth() && "Bit widths must be the same."); @@ -3791,7 +3791,7 @@ /// given quadratic chrec {L,+,M,+,N}. This returns either the two roots (which /// might be the same) or two SCEVCouldNotCompute objects. /// -static std::pair +static std::pair SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) { assert(AddRec->getNumOperands() == 3 && "This is not a quadratic chrec!"); const SCEVConstant *LC = dyn_cast(AddRec->getOperand(0)); @@ -3854,7 +3854,7 @@ /// HowFarToZero - Return the number of times a backedge comparing the specified /// value to zero will execute. If not computable, return CouldNotCompute. -const SCEV* ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L) { +const SCEV *ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L) { // If the value is a constant if (const SCEVConstant *C = dyn_cast(V)) { // If the value is already zero, the branch will execute zero times. @@ -3902,7 +3902,7 @@ } else if (AddRec->isQuadratic() && AddRec->getType()->isInteger()) { // If this is a quadratic (3-term) AddRec {L,+,M,+,N}, find the roots of // the quadratic equation to solve it. - std::pair Roots = SolveQuadraticEquation(AddRec, + std::pair Roots = SolveQuadraticEquation(AddRec, *this); const SCEVConstant *R1 = dyn_cast(Roots.first); const SCEVConstant *R2 = dyn_cast(Roots.second); @@ -3921,7 +3921,7 @@ // We can only use this value if the chrec ends up with an exact zero // value at this index. When solving for "X*X != 5", for example, we // should not accept a root of 2. - const SCEV* Val = AddRec->evaluateAtIteration(R1, *this); + const SCEV *Val = AddRec->evaluateAtIteration(R1, *this); if (Val->isZero()) return R1; // We found a quadratic root! } @@ -3934,7 +3934,7 @@ /// HowFarToNonZero - Return the number of times a backedge checking the /// specified value for nonzero will execute. If not computable, return /// CouldNotCompute -const SCEV* ScalarEvolution::HowFarToNonZero(const SCEV *V, const Loop *L) { +const SCEV *ScalarEvolution::HowFarToNonZero(const SCEV *V, const Loop *L) { // Loops that look like: while (X == 0) are very strange indeed. We don't // handle them yet except for the trivial case. This could be expanded in the // future as needed. @@ -3995,7 +3995,7 @@ /// more general, since a front-end may have replicated the controlling /// expression. /// -static bool HasSameValue(const SCEV* A, const SCEV* B) { +static bool HasSameValue(const SCEV *A, const SCEV *B) { // Quick check to see if they are the same SCEV. if (A == B) return true; @@ -4148,22 +4148,22 @@ /// getBECount - Subtract the end and start values and divide by the step, /// rounding up, to get the number of times the backedge is executed. Return /// CouldNotCompute if an intermediate computation overflows. -const SCEV* ScalarEvolution::getBECount(const SCEV* Start, - const SCEV* End, - const SCEV* Step) { +const SCEV *ScalarEvolution::getBECount(const SCEV *Start, + const SCEV *End, + const SCEV *Step) { const Type *Ty = Start->getType(); - const SCEV* NegOne = getIntegerSCEV(-1, Ty); - const SCEV* Diff = getMinusSCEV(End, Start); - const SCEV* RoundUp = getAddExpr(Step, NegOne); + const SCEV *NegOne = getIntegerSCEV(-1, Ty); + const SCEV *Diff = getMinusSCEV(End, Start); + const SCEV *RoundUp = getAddExpr(Step, NegOne); // Add an adjustment to the difference between End and Start so that // the division will effectively round up. - const SCEV* Add = getAddExpr(Diff, RoundUp); + const SCEV *Add = getAddExpr(Diff, RoundUp); // Check Add for unsigned overflow. // TODO: More sophisticated things could be done here. const Type *WideTy = Context->getIntegerType(getTypeSizeInBits(Ty) + 1); - const SCEV* OperandExtendedAdd = + const SCEV *OperandExtendedAdd = getAddExpr(getZeroExtendExpr(Diff, WideTy), getZeroExtendExpr(RoundUp, WideTy)); if (getZeroExtendExpr(Add, WideTy) != OperandExtendedAdd) @@ -4188,7 +4188,7 @@ if (AddRec->isAffine()) { // FORNOW: We only support unit strides. unsigned BitWidth = getTypeSizeInBits(AddRec->getType()); - const SCEV* Step = AddRec->getStepRecurrence(*this); + const SCEV *Step = AddRec->getStepRecurrence(*this); // TODO: handle non-constant strides. const SCEVConstant *CStep = dyn_cast(Step); @@ -4224,7 +4224,7 @@ // treat m-n as signed nor unsigned due to overflow possibility. // First, we get the value of the LHS in the first iteration: n - const SCEV* Start = AddRec->getOperand(0); + const SCEV *Start = AddRec->getOperand(0); // Determine the minimum constant start value. const SCEV *MinStart = isa(Start) ? Start : @@ -4235,7 +4235,7 @@ // then we know that it will run exactly (m-n)/s times. Otherwise, we // only know that it will execute (max(m,n)-n)/s times. In both cases, // the division must round up. - const SCEV* End = RHS; + const SCEV *End = RHS; if (!isLoopGuardedByCond(L, isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, getMinusSCEV(Start, Step), RHS)) @@ -4243,7 +4243,7 @@ : getUMaxExpr(RHS, Start); // Determine the maximum constant end value. - const SCEV* MaxEnd = + const SCEV *MaxEnd = isa(End) ? End : getConstant(isSigned ? APInt::getSignedMaxValue(BitWidth) .ashr(GetMinSignBits(End) - 1) : @@ -4252,11 +4252,11 @@ // Finally, we subtract these two values and divide, rounding up, to get // the number of times the backedge is executed. - const SCEV* BECount = getBECount(Start, End, Step); + const SCEV *BECount = getBECount(Start, End, Step); // The maximum backedge count is similar, except using the minimum start // value and the maximum end value. - const SCEV* MaxBECount = getBECount(MinStart, MaxEnd, Step); + const SCEV *MaxBECount = getBECount(MinStart, MaxEnd, Step); return BackedgeTakenInfo(BECount, MaxBECount); } @@ -4269,7 +4269,7 @@ /// this is that it returns the first iteration number where the value is not in /// the condition, thus computing the exit count. If the iteration count can't /// be computed, an instance of SCEVCouldNotCompute is returned. -const SCEV* SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, +const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, ScalarEvolution &SE) const { if (Range.isFullSet()) // Infinite loop. return SE.getCouldNotCompute(); @@ -4277,9 +4277,9 @@ // If the start is a non-zero constant, shift the range to simplify things. if (const SCEVConstant *SC = dyn_cast(getStart())) if (!SC->getValue()->isZero()) { - SmallVector Operands(op_begin(), op_end()); + SmallVector Operands(op_begin(), op_end()); Operands[0] = SE.getIntegerSCEV(0, SC->getType()); - const SCEV* Shifted = SE.getAddRecExpr(Operands, getLoop()); + const SCEV *Shifted = SE.getAddRecExpr(Operands, getLoop()); if (const SCEVAddRecExpr *ShiftedAddRec = dyn_cast(Shifted)) return ShiftedAddRec->getNumIterationsInRange( @@ -4338,12 +4338,12 @@ // quadratic equation to solve it. To do this, we must frame our problem in // terms of figuring out when zero is crossed, instead of when // Range.getUpper() is crossed. - SmallVector NewOps(op_begin(), op_end()); + SmallVector NewOps(op_begin(), op_end()); NewOps[0] = SE.getNegativeSCEV(SE.getConstant(Range.getUpper())); - const SCEV* NewAddRec = SE.getAddRecExpr(NewOps, getLoop()); + const SCEV *NewAddRec = SE.getAddRecExpr(NewOps, getLoop()); // Next, solve the constructed addrec - std::pair Roots = + std::pair Roots = SolveQuadraticEquation(cast(NewAddRec), SE); const SCEVConstant *R1 = dyn_cast(Roots.first); const SCEVConstant *R2 = dyn_cast(Roots.second); @@ -4525,12 +4525,12 @@ if (isSCEVable(I->getType())) { OS << *I; OS << " --> "; - const SCEV* SV = SE.getSCEV(&*I); + const SCEV *SV = SE.getSCEV(&*I); SV->print(OS); const Loop *L = LI->getLoopFor((*I).getParent()); - const SCEV* AtUse = SE.getSCEVAtScope(SV, L); + const SCEV *AtUse = SE.getSCEVAtScope(SV, L); if (AtUse != SV) { OS << " --> "; AtUse->print(OS); @@ -4538,7 +4538,7 @@ if (L) { OS << "\t\t" "Exits: "; - const SCEV* ExitValue = SE.getSCEVAtScope(SV, L->getParentLoop()); + const SCEV *ExitValue = SE.getSCEVAtScope(SV, L->getParentLoop()); if (!ExitValue->isLoopInvariant(L)) { OS << "<>"; } else { Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original) +++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Tue Jul 7 12:06:11 2009 @@ -156,8 +156,8 @@ /// TODO: When ScalarEvolution gets a SCEVSDivExpr, this can be made /// unnecessary; in its place, just signed-divide Ops[i] by the scale and /// check to see if the divide was folded. -static bool FactorOutConstant(const SCEV* &S, - const SCEV* &Remainder, +static bool FactorOutConstant(const SCEV *&S, + const SCEV *&Remainder, const APInt &Factor, ScalarEvolution &SE) { // Everything is divisible by one. @@ -172,7 +172,7 @@ // the value at this scale. It will be considered for subsequent // smaller scales. if (C->isZero() || !CI->isZero()) { - const SCEV* Div = SE.getConstant(CI); + const SCEV *Div = SE.getConstant(CI); S = Div; Remainder = SE.getAddExpr(Remainder, @@ -197,13 +197,13 @@ // In an AddRec, check if both start and step are divisible. if (const SCEVAddRecExpr *A = dyn_cast(S)) { - const SCEV* Step = A->getStepRecurrence(SE); - const SCEV* StepRem = SE.getIntegerSCEV(0, Step->getType()); + const SCEV *Step = A->getStepRecurrence(SE); + const SCEV *StepRem = SE.getIntegerSCEV(0, Step->getType()); if (!FactorOutConstant(Step, StepRem, Factor, SE)) return false; if (!StepRem->isZero()) return false; - const SCEV* Start = A->getStart(); + const SCEV *Start = A->getStart(); if (!FactorOutConstant(Start, Remainder, Factor, SE)) return false; S = SE.getAddRecExpr(Start, Step, A->getLoop()); @@ -238,14 +238,14 @@ /// loop-invariant portions of expressions, after considering what /// can be folded using target addressing modes. /// -Value *SCEVExpander::expandAddToGEP(const SCEV* const *op_begin, - const SCEV* const *op_end, +Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, + const SCEV *const *op_end, const PointerType *PTy, const Type *Ty, Value *V) { const Type *ElTy = PTy->getElementType(); SmallVector GepIndices; - SmallVector Ops(op_begin, op_end); + SmallVector Ops(op_begin, op_end); bool AnyNonZeroIndices = false; // Decend down the pointer's type and attempt to convert the other @@ -256,14 +256,14 @@ for (;;) { APInt ElSize = APInt(SE.getTypeSizeInBits(Ty), ElTy->isSized() ? SE.TD->getTypeAllocSize(ElTy) : 0); - SmallVector NewOps; - SmallVector ScaledOps; + SmallVector NewOps; + SmallVector ScaledOps; for (unsigned i = 0, e = Ops.size(); i != e; ++i) { // Split AddRecs up into parts as either of the parts may be usable // without the other. if (const SCEVAddRecExpr *A = dyn_cast(Ops[i])) if (!A->getStart()->isZero()) { - const SCEV* Start = A->getStart(); + const SCEV *Start = A->getStart(); Ops.push_back(SE.getAddRecExpr(SE.getIntegerSCEV(0, A->getType()), A->getStepRecurrence(SE), A->getLoop())); @@ -272,8 +272,8 @@ } // If the scale size is not 0, attempt to factor out a scale. if (ElSize != 0) { - const SCEV* Op = Ops[i]; - const SCEV* Remainder = SE.getIntegerSCEV(0, Op->getType()); + const SCEV *Op = Ops[i]; + const SCEV *Remainder = SE.getIntegerSCEV(0, Op->getType()); if (FactorOutConstant(Op, Remainder, ElSize, SE)) { ScaledOps.push_back(Op); // Op now has ElSize factored out. NewOps.push_back(Remainder); @@ -370,7 +370,7 @@ // comments on expandAddToGEP for details. if (SE.TD) if (const PointerType *PTy = dyn_cast(V->getType())) { - const SmallVectorImpl &Ops = S->getOperands(); + const SmallVectorImpl &Ops = S->getOperands(); return expandAddToGEP(&Ops[0], &Ops[Ops.size() - 1], PTy, Ty, V); } @@ -424,7 +424,7 @@ /// Move parts of Base into Rest to leave Base with the minimal /// expression that provides a pointer operand suitable for a /// GEP expansion. -static void ExposePointerBase(const SCEV* &Base, const SCEV* &Rest, +static void ExposePointerBase(const SCEV *&Base, const SCEV *&Rest, ScalarEvolution &SE) { while (const SCEVAddRecExpr *A = dyn_cast(Base)) { Base = A->getStart(); @@ -435,7 +435,7 @@ } if (const SCEVAddExpr *A = dyn_cast(Base)) { Base = A->getOperand(A->getNumOperands()-1); - SmallVector NewAddOps(A->op_begin(), A->op_end()); + SmallVector NewAddOps(A->op_begin(), A->op_end()); NewAddOps.back() = Rest; Rest = SE.getAddExpr(NewAddOps); ExposePointerBase(Base, Rest, SE); @@ -477,16 +477,16 @@ // {X,+,F} --> X + {0,+,F} if (!S->getStart()->isZero()) { - const SmallVectorImpl &SOperands = S->getOperands(); - SmallVector NewOps(SOperands.begin(), SOperands.end()); + const SmallVectorImpl &SOperands = S->getOperands(); + SmallVector NewOps(SOperands.begin(), SOperands.end()); NewOps[0] = SE.getIntegerSCEV(0, Ty); - const SCEV* Rest = SE.getAddRecExpr(NewOps, L); + const SCEV *Rest = SE.getAddRecExpr(NewOps, L); // Turn things like ptrtoint+arithmetic+inttoptr into GEP. See the // comments on expandAddToGEP for details. if (SE.TD) { - const SCEV* Base = S->getStart(); - const SCEV* RestArray[1] = { Rest }; + const SCEV *Base = S->getStart(); + const SCEV *RestArray[1] = { Rest }; // Dig into the expression to find the pointer base for a GEP. ExposePointerBase(Base, RestArray[0], SE); // If we found a pointer, expand the AddRec with a GEP. @@ -565,19 +565,19 @@ // folders, then expandCodeFor the closed form. This allows the folders to // simplify the expression without having to build a bunch of special code // into this folder. - const SCEV* IH = SE.getUnknown(I); // Get I as a "symbolic" SCEV. + const SCEV *IH = SE.getUnknown(I); // Get I as a "symbolic" SCEV. // Promote S up to the canonical IV type, if the cast is foldable. - const SCEV* NewS = S; - const SCEV* Ext = SE.getNoopOrAnyExtend(S, I->getType()); + const SCEV *NewS = S; + const SCEV *Ext = SE.getNoopOrAnyExtend(S, I->getType()); if (isa(Ext)) NewS = Ext; - const SCEV* V = cast(NewS)->evaluateAtIteration(IH, SE); + const SCEV *V = cast(NewS)->evaluateAtIteration(IH, SE); //cerr << "Evaluated: " << *this << "\n to: " << *V << "\n"; // Truncate the result down to the original type, if needed. - const SCEV* T = SE.getTruncateOrNoop(V, Ty); + const SCEV *T = SE.getTruncateOrNoop(V, Ty); return expand(T); } @@ -636,7 +636,7 @@ return LHS; } -Value *SCEVExpander::expandCodeFor(const SCEV* SH, const Type *Ty) { +Value *SCEVExpander::expandCodeFor(const SCEV *SH, const Type *Ty) { // Expand the code for this SCEV. Value *V = expand(SH); if (Ty) { @@ -697,7 +697,7 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L, const Type *Ty) { assert(Ty->isInteger() && "Can only insert integer induction variables!"); - const SCEV* H = SE.getAddRecExpr(SE.getIntegerSCEV(0, Ty), + const SCEV *H = SE.getAddRecExpr(SE.getIntegerSCEV(0, Ty), SE.getIntegerSCEV(1, Ty), L); BasicBlock *SaveInsertBB = Builder.GetInsertBlock(); BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint(); Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Tue Jul 7 12:06:11 2009 @@ -98,7 +98,7 @@ void RewriteNonIntegerIVs(Loop *L); - ICmpInst *LinearFunctionTestReplace(Loop *L, const SCEV* BackedgeTakenCount, + ICmpInst *LinearFunctionTestReplace(Loop *L, const SCEV *BackedgeTakenCount, Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, @@ -129,7 +129,7 @@ /// SCEV analysis can determine a loop-invariant trip count of the loop, which /// is actually a much broader range than just linear tests. ICmpInst *IndVarSimplify::LinearFunctionTestReplace(Loop *L, - const SCEV* BackedgeTakenCount, + const SCEV *BackedgeTakenCount, Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, @@ -138,13 +138,13 @@ // against the preincremented value, otherwise we prefer to compare against // the post-incremented value. Value *CmpIndVar; - const SCEV* RHS = BackedgeTakenCount; + const SCEV *RHS = BackedgeTakenCount; if (ExitingBlock == L->getLoopLatch()) { // Add one to the "backedge-taken" count to get the trip count. // If this addition may overflow, we have to be more pessimistic and // cast the induction variable before doing the add. - const SCEV* Zero = SE->getIntegerSCEV(0, BackedgeTakenCount->getType()); - const SCEV* N = + const SCEV *Zero = SE->getIntegerSCEV(0, BackedgeTakenCount->getType()); + const SCEV *N = SE->getAddExpr(BackedgeTakenCount, SE->getIntegerSCEV(1, BackedgeTakenCount->getType())); if ((isa(N) && !N->isZero()) || @@ -264,7 +264,7 @@ // Okay, this instruction has a user outside of the current loop // and varies predictably *inside* the loop. Evaluate the value it // contains when the loop exits, if possible. - const SCEV* ExitValue = SE->getSCEVAtScope(Inst, L->getParentLoop()); + const SCEV *ExitValue = SE->getSCEVAtScope(Inst, L->getParentLoop()); if (!ExitValue->isLoopInvariant(L)) continue; @@ -339,7 +339,7 @@ RewriteNonIntegerIVs(L); BasicBlock *ExitingBlock = L->getExitingBlock(); // may be null - const SCEV* BackedgeTakenCount = SE->getBackedgeTakenCount(L); + const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L); // Create a rewriter object which we'll use to transform the code with. SCEVExpander Rewriter(*SE); @@ -367,14 +367,14 @@ NeedCannIV = true; } for (unsigned i = 0, e = IU->StrideOrder.size(); i != e; ++i) { - const SCEV* Stride = IU->StrideOrder[i]; + const SCEV *Stride = IU->StrideOrder[i]; const Type *Ty = SE->getEffectiveSCEVType(Stride->getType()); if (!LargestType || SE->getTypeSizeInBits(Ty) > SE->getTypeSizeInBits(LargestType)) LargestType = Ty; - std::map::iterator SI = + std::map::iterator SI = IU->IVUsesByStride.find(IU->StrideOrder[i]); assert(SI != IU->IVUsesByStride.end() && "Stride doesn't exist!"); @@ -458,9 +458,9 @@ // the need for the code evaluation methods to insert induction variables // of different sizes. for (unsigned i = 0, e = IU->StrideOrder.size(); i != e; ++i) { - const SCEV* Stride = IU->StrideOrder[i]; + const SCEV *Stride = IU->StrideOrder[i]; - std::map::iterator SI = + std::map::iterator SI = IU->IVUsesByStride.find(IU->StrideOrder[i]); assert(SI != IU->IVUsesByStride.end() && "Stride doesn't exist!"); ilist &List = SI->second->Users; @@ -471,7 +471,7 @@ Instruction *User = UI->getUser(); // Compute the final addrec to expand into code. - const SCEV* AR = IU->getReplacementExpr(*UI); + const SCEV *AR = IU->getReplacementExpr(*UI); // FIXME: It is an extremely bad idea to indvar substitute anything more // complex than affine induction variables. Doing so will put expensive Modified: llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp Tue Jul 7 12:06:11 2009 @@ -187,7 +187,7 @@ // Don't remove loops for which we can't solve the trip count. // They could be infinite, in which case we'd be changing program behavior. ScalarEvolution& SE = getAnalysis(); - const SCEV* S = SE.getBackedgeTakenCount(L); + const SCEV *S = SE.getBackedgeTakenCount(L); if (isa(S)) return false; Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=74918&r1=74917&r2=74918&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Tue Jul 7 12:06:11 2009 @@ -65,11 +65,11 @@ /// StrengthReduceStridedIVUsers. It contains the stride, the common base, as /// well as the PHI node and increment value created for rewrite. struct VISIBILITY_HIDDEN IVExpr { - const SCEV* Stride; - const SCEV* Base; + const SCEV *Stride; + const SCEV *Base; PHINode *PHI; - IVExpr(const SCEV* const stride, const SCEV* const base, PHINode *phi) + IVExpr(const SCEV *const stride, const SCEV *const base, PHINode *phi) : Stride(stride), Base(base), PHI(phi) {} }; @@ -78,7 +78,7 @@ struct VISIBILITY_HIDDEN IVsOfOneStride { std::vector IVs; - void addIV(const SCEV* const Stride, const SCEV* const Base, PHINode *PHI) { + void addIV(const SCEV *const Stride, const SCEV *const Base, PHINode *PHI) { IVs.push_back(IVExpr(Stride, Base, PHI)); } }; @@ -92,11 +92,11 @@ /// IVsByStride - Keep track of all IVs that have been inserted for a /// particular stride. - std::map IVsByStride; + std::map IVsByStride; /// StrideNoReuse - Keep track of all the strides whose ivs cannot be /// reused (nor should they be rewritten to reuse other strides). - SmallSet StrideNoReuse; + SmallSet StrideNoReuse; /// DeadInsts - Keep track of instructions we may have made dead, so that /// we can remove them after we are done working. @@ -134,7 +134,7 @@ private: ICmpInst *ChangeCompareStride(Loop *L, ICmpInst *Cond, IVStrideUse* &CondUse, - const SCEV* const * &CondStride); + const SCEV *const * &CondStride); void OptimizeIndvars(Loop *L); void OptimizeLoopCountIV(Loop *L); @@ -150,16 +150,16 @@ IVStrideUse* &CondUse); bool FindIVUserForCond(ICmpInst *Cond, IVStrideUse *&CondUse, - const SCEV* const * &CondStride); + const SCEV *const * &CondStride); bool RequiresTypeConversion(const Type *Ty, const Type *NewTy); - const SCEV* CheckForIVReuse(bool, bool, bool, const SCEV* const&, + const SCEV *CheckForIVReuse(bool, bool, bool, const SCEV *const&, IVExpr&, const Type*, const std::vector& UsersToProcess); bool ValidScale(bool, int64_t, const std::vector& UsersToProcess); bool ValidOffset(bool, int64_t, int64_t, const std::vector& UsersToProcess); - const SCEV* CollectIVUsers(const SCEV* const &Stride, + const SCEV *CollectIVUsers(const SCEV *const &Stride, IVUsersOfOneStride &Uses, Loop *L, bool &AllUsesAreAddresses, @@ -169,11 +169,11 @@ const std::vector &UsersToProcess, const Loop *L, bool AllUsesAreAddresses, - const SCEV* Stride); + const SCEV *Stride); void PrepareToStrengthReduceFully( std::vector &UsersToProcess, - const SCEV* Stride, - const SCEV* CommonExprs, + const SCEV *Stride, + const SCEV *CommonExprs, const Loop *L, SCEVExpander &PreheaderRewriter); void PrepareToStrengthReduceFromSmallerStride( @@ -183,13 +183,13 @@ Instruction *PreInsertPt); void PrepareToStrengthReduceWithNewPhi( std::vector &UsersToProcess, - const SCEV* Stride, - const SCEV* CommonExprs, + const SCEV *Stride, + const SCEV *CommonExprs, Value *CommonBaseV, Instruction *IVIncInsertPt, const Loop *L, SCEVExpander &PreheaderRewriter); - void StrengthReduceStridedIVUsers(const SCEV* const &Stride, + void StrengthReduceStridedIVUsers(const SCEV *const &Stride, IVUsersOfOneStride &Uses, Loop *L); void DeleteTriviallyDeadInstructions(); @@ -233,7 +233,7 @@ /// containsAddRecFromDifferentLoop - Determine whether expression S involves a /// subexpression that is an AddRec from a loop other than L. An outer loop /// of L is OK, but not an inner loop nor a disjoint loop. -static bool containsAddRecFromDifferentLoop(const SCEV* S, Loop *L) { +static bool containsAddRecFromDifferentLoop(const SCEV *S, Loop *L) { // This is very common, put it first. if (isa(S)) return false; @@ -328,7 +328,7 @@ /// this use. As the use is processed, information gets moved from this /// field to the Imm field (below). BasedUser values are sorted by this /// field. - const SCEV* Base; + const SCEV *Base; /// Inst - The instruction using the induction variable. Instruction *Inst; @@ -341,7 +341,7 @@ /// before Inst, because it will be folded into the imm field of the /// instruction. This is also sometimes used for loop-variant values that /// must be added inside the loop. - const SCEV* Imm; + const SCEV *Imm; /// Phi - The induction variable that performs the striding that /// should be used for this user. @@ -363,13 +363,13 @@ // Once we rewrite the code to insert the new IVs we want, update the // operands of Inst to use the new expression 'NewBase', with 'Imm' added // to it. - void RewriteInstructionToUseNewBase(const SCEV* const &NewBase, + void RewriteInstructionToUseNewBase(const SCEV *const &NewBase, Instruction *InsertPt, SCEVExpander &Rewriter, Loop *L, Pass *P, LoopInfo &LI, SmallVectorImpl &DeadInsts); - Value *InsertCodeForBaseAtPosition(const SCEV* const &NewBase, + Value *InsertCodeForBaseAtPosition(const SCEV *const &NewBase, const Type *Ty, SCEVExpander &Rewriter, Instruction *IP, Loop *L, @@ -384,7 +384,7 @@ cerr << " Inst: " << *Inst; } -Value *BasedUser::InsertCodeForBaseAtPosition(const SCEV* const &NewBase, +Value *BasedUser::InsertCodeForBaseAtPosition(const SCEV *const &NewBase, const Type *Ty, SCEVExpander &Rewriter, Instruction *IP, Loop *L, @@ -408,7 +408,7 @@ Value *Base = Rewriter.expandCodeFor(NewBase, 0, BaseInsertPt); - const SCEV* NewValSCEV = SE->getUnknown(Base); + const SCEV *NewValSCEV = SE->getUnknown(Base); // Always emit the immediate into the same block as the user. NewValSCEV = SE->getAddExpr(NewValSCEV, Imm); @@ -423,7 +423,7 @@ // value of NewBase in the case that it's a diffferent instruction from // the PHI that NewBase is computed from, or null otherwise. // -void BasedUser::RewriteInstructionToUseNewBase(const SCEV* const &NewBase, +void BasedUser::RewriteInstructionToUseNewBase(const SCEV *const &NewBase, Instruction *NewBasePt, SCEVExpander &Rewriter, Loop *L, Pass *P, LoopInfo &LI, @@ -535,7 +535,7 @@ /// fitsInAddressMode - Return true if V can be subsumed within an addressing /// mode, and does not need to be put in a register first. -static bool fitsInAddressMode(const SCEV* const &V, const Type *AccessTy, +static bool fitsInAddressMode(const SCEV *const &V, const Type *AccessTy, const TargetLowering *TLI, bool HasBaseReg) { if (const SCEVConstant *SC = dyn_cast(V)) { int64_t VC = SC->getValue()->getSExtValue(); @@ -567,12 +567,12 @@ /// MoveLoopVariantsToImmediateField - Move any subexpressions from Val that are /// loop varying to the Imm operand. -static void MoveLoopVariantsToImmediateField(const SCEV* &Val, const SCEV* &Imm, +static void MoveLoopVariantsToImmediateField(const SCEV *&Val, const SCEV *&Imm, Loop *L, ScalarEvolution *SE) { if (Val->isLoopInvariant(L)) return; // Nothing to do. if (const SCEVAddExpr *SAE = dyn_cast(Val)) { - SmallVector NewOps; + SmallVector NewOps; NewOps.reserve(SAE->getNumOperands()); for (unsigned i = 0; i != SAE->getNumOperands(); ++i) @@ -590,10 +590,10 @@ Val = SE->getAddExpr(NewOps); } else if (const SCEVAddRecExpr *SARE = dyn_cast(Val)) { // Try to pull immediates out of the start value of nested addrec's. - const SCEV* Start = SARE->getStart(); + const SCEV *Start = SARE->getStart(); MoveLoopVariantsToImmediateField(Start, Imm, L, SE); - SmallVector Ops(SARE->op_begin(), SARE->op_end()); + SmallVector Ops(SARE->op_begin(), SARE->op_end()); Ops[0] = Start; Val = SE->getAddRecExpr(Ops, SARE->getLoop()); } else { @@ -609,15 +609,15 @@ /// Accumulate these immediate values into the Imm value. static void MoveImmediateValues(const TargetLowering *TLI, const Type *AccessTy, - const SCEV* &Val, const SCEV* &Imm, + const SCEV *&Val, const SCEV *&Imm, bool isAddress, Loop *L, ScalarEvolution *SE) { if (const SCEVAddExpr *SAE = dyn_cast(Val)) { - SmallVector NewOps; + SmallVector NewOps; NewOps.reserve(SAE->getNumOperands()); for (unsigned i = 0; i != SAE->getNumOperands(); ++i) { - const SCEV* NewOp = SAE->getOperand(i); + const SCEV *NewOp = SAE->getOperand(i); MoveImmediateValues(TLI, AccessTy, NewOp, Imm, isAddress, L, SE); if (!NewOp->isLoopInvariant(L)) { @@ -636,11 +636,11 @@ return; } else if (const SCEVAddRecExpr *SARE = dyn_cast(Val)) { // Try to pull immediates out of the start value of nested addrec's. - const SCEV* Start = SARE->getStart(); + const SCEV *Start = SARE->getStart(); MoveImmediateValues(TLI, AccessTy, Start, Imm, isAddress, L, SE); if (Start != SARE->getStart()) { - SmallVector Ops(SARE->op_begin(), SARE->op_end()); + SmallVector Ops(SARE->op_begin(), SARE->op_end()); Ops[0] = Start; Val = SE->getAddRecExpr(Ops, SARE->getLoop()); } @@ -651,8 +651,8 @@ fitsInAddressMode(SME->getOperand(0), AccessTy, TLI, false) && SME->getNumOperands() == 2 && SME->isLoopInvariant(L)) { - const SCEV* SubImm = SE->getIntegerSCEV(0, Val->getType()); - const SCEV* NewOp = SME->getOperand(1); + const SCEV *SubImm = SE->getIntegerSCEV(0, Val->getType()); + const SCEV *NewOp = SME->getOperand(1); MoveImmediateValues(TLI, AccessTy, NewOp, SubImm, isAddress, L, SE); // If we extracted something out of the subexpressions, see if we can @@ -687,7 +687,7 @@ static void MoveImmediateValues(const TargetLowering *TLI, Instruction *User, - const SCEV* &Val, const SCEV* &Imm, + const SCEV *&Val, const SCEV *&Imm, bool isAddress, Loop *L, ScalarEvolution *SE) { const Type *AccessTy = getAccessType(User); @@ -697,19 +697,19 @@ /// SeparateSubExprs - Decompose Expr into all of the subexpressions that are /// added together. This is used to reassociate common addition subexprs /// together for maximal sharing when rewriting bases. -static void SeparateSubExprs(SmallVector &SubExprs, - const SCEV* Expr, +static void SeparateSubExprs(SmallVector &SubExprs, + const SCEV *Expr, ScalarEvolution *SE) { if (const SCEVAddExpr *AE = dyn_cast(Expr)) { for (unsigned j = 0, e = AE->getNumOperands(); j != e; ++j) SeparateSubExprs(SubExprs, AE->getOperand(j), SE); } else if (const SCEVAddRecExpr *SARE = dyn_cast(Expr)) { - const SCEV* Zero = SE->getIntegerSCEV(0, Expr->getType()); + const SCEV *Zero = SE->getIntegerSCEV(0, Expr->getType()); if (SARE->getOperand(0) == Zero) { SubExprs.push_back(Expr); } else { // Compute the addrec with zero as its base. - SmallVector Ops(SARE->op_begin(), SARE->op_end()); + SmallVector Ops(SARE->op_begin(), SARE->op_end()); Ops[0] = Zero; // Start with zero base. SubExprs.push_back(SE->getAddRecExpr(Ops, SARE->getLoop())); @@ -733,7 +733,7 @@ /// not remove anything. This looks for things like (a+b+c) and /// (a+c+d) and computes the common (a+c) subexpression. The common expression /// is *removed* from the Bases and returned. -static const SCEV* +static const SCEV * RemoveCommonExpressionsFromUseBases(std::vector &Uses, ScalarEvolution *SE, Loop *L, const TargetLowering *TLI) { @@ -741,9 +741,9 @@ // Only one use? This is a very common case, so we handle it specially and // cheaply. - const SCEV* Zero = SE->getIntegerSCEV(0, Uses[0].Base->getType()); - const SCEV* Result = Zero; - const SCEV* FreeResult = Zero; + const SCEV *Zero = SE->getIntegerSCEV(0, Uses[0].Base->getType()); + const SCEV *Result = Zero; + const SCEV *FreeResult = Zero; if (NumUses == 1) { // If the use is inside the loop, use its base, regardless of what it is: // it is clearly shared across all the IV's. If the use is outside the loop @@ -759,13 +759,13 @@ // Also track whether all uses of each expression can be moved into an // an addressing mode "for free"; such expressions are left within the loop. // struct SubExprUseData { unsigned Count; bool notAllUsesAreFree; }; - std::map SubExpressionUseData; + std::map SubExpressionUseData; // UniqueSubExprs - Keep track of all of the subexpressions we see in the // order we see them. - SmallVector UniqueSubExprs; + SmallVector UniqueSubExprs; - SmallVector SubExprs; + SmallVector SubExprs; unsigned NumUsesInsideLoop = 0; for (unsigned i = 0; i != NumUses; ++i) { // If the user is outside the loop, just ignore it for base computation. @@ -809,7 +809,7 @@ // Now that we know how many times each is used, build Result. Iterate over // UniqueSubexprs so that we have a stable ordering. for (unsigned i = 0, e = UniqueSubExprs.size(); i != e; ++i) { - std::map::iterator I = + std::map::iterator I = SubExpressionUseData.find(UniqueSubExprs[i]); assert(I != SubExpressionUseData.end() && "Entry not found?"); if (I->second.Count == NumUsesInsideLoop) { // Found CSE! @@ -853,7 +853,7 @@ if (FreeResult != Zero) { SeparateSubExprs(SubExprs, FreeResult, SE); for (unsigned j = 0, e = SubExprs.size(); j != e; ++j) { - std::map::iterator I = + std::map::iterator I = SubExpressionUseData.find(SubExprs[j]); SubExpressionUseData.erase(I); } @@ -982,10 +982,10 @@ /// be folded into the addressing mode, nor even that the factor be constant; /// a multiply (executed once) outside the loop is better than another IV /// within. Well, usually. -const SCEV* LoopStrengthReduce::CheckForIVReuse(bool HasBaseReg, +const SCEV *LoopStrengthReduce::CheckForIVReuse(bool HasBaseReg, bool AllUsesAreAddresses, bool AllUsesAreOutsideLoop, - const SCEV* const &Stride, + const SCEV *const &Stride, IVExpr &IV, const Type *Ty, const std::vector& UsersToProcess) { if (StrideNoReuse.count(Stride)) @@ -995,7 +995,7 @@ int64_t SInt = SC->getValue()->getSExtValue(); for (unsigned NewStride = 0, e = IU->StrideOrder.size(); NewStride != e; ++NewStride) { - std::map::iterator SI = + std::map::iterator SI = IVsByStride.find(IU->StrideOrder[NewStride]); if (SI == IVsByStride.end() || !isa(SI->first) || StrideNoReuse.count(SI->first)) @@ -1048,7 +1048,7 @@ // an existing IV if we can. for (unsigned NewStride = 0, e = IU->StrideOrder.size(); NewStride != e; ++NewStride) { - std::map::iterator SI = + std::map::iterator SI = IVsByStride.find(IU->StrideOrder[NewStride]); if (SI == IVsByStride.end() || !isa(SI->first)) continue; @@ -1068,7 +1068,7 @@ // -1*old. for (unsigned NewStride = 0, e = IU->StrideOrder.size(); NewStride != e; ++NewStride) { - std::map::iterator SI = + std::map::iterator SI = IVsByStride.find(IU->StrideOrder[NewStride]); if (SI == IVsByStride.end()) continue; @@ -1097,7 +1097,7 @@ /// isNonConstantNegative - Return true if the specified scev is negated, but /// not a constant. -static bool isNonConstantNegative(const SCEV* const &Expr) { +static bool isNonConstantNegative(const SCEV *const &Expr) { const SCEVMulExpr *Mul = dyn_cast(Expr); if (!Mul) return false; @@ -1114,7 +1114,7 @@ /// of the strided accesses, as well as the old information from Uses. We /// progressively move information from the Base field to the Imm field, until /// we eventually have the full access expression to rewrite the use. -const SCEV* LoopStrengthReduce::CollectIVUsers(const SCEV* const &Stride, +const SCEV *LoopStrengthReduce::CollectIVUsers(const SCEV *const &Stride, IVUsersOfOneStride &Uses, Loop *L, bool &AllUsesAreAddresses, @@ -1145,7 +1145,7 @@ // for the strides (e.g. if we have "A+C+B" and "A+B+D" as our bases, find // "A+B"), emit it to the preheader, then remove the expression from the // UsersToProcess base values. - const SCEV* CommonExprs = + const SCEV *CommonExprs = RemoveCommonExpressionsFromUseBases(UsersToProcess, SE, L, TLI); // Next, figure out what we can represent in the immediate fields of @@ -1211,7 +1211,7 @@ const std::vector &UsersToProcess, const Loop *L, bool AllUsesAreAddresses, - const SCEV* Stride) { + const SCEV *Stride) { if (!EnableFullLSRMode) return false; @@ -1248,7 +1248,7 @@ if (!Imm) Imm = SE->getIntegerSCEV(0, Stride->getType()); const Instruction *Inst = UsersToProcess[i].Inst; const Type *AccessTy = getAccessType(Inst); - const SCEV* Diff = SE->getMinusSCEV(UsersToProcess[i].Imm, Imm); + const SCEV *Diff = SE->getMinusSCEV(UsersToProcess[i].Imm, Imm); if (!Diff->isZero() && (!AllUsesAreAddresses || !fitsInAddressMode(Diff, AccessTy, TLI, /*HasBaseReg=*/true))) @@ -1282,7 +1282,7 @@ /// /// Return the created phi node. /// -static PHINode *InsertAffinePhi(const SCEV* Start, const SCEV* Step, +static PHINode *InsertAffinePhi(const SCEV *Start, const SCEV *Step, Instruction *IVIncInsertPt, const Loop *L, SCEVExpander &Rewriter) { @@ -1302,7 +1302,7 @@ // If the stride is negative, insert a sub instead of an add for the // increment. bool isNegative = isNonConstantNegative(Step); - const SCEV* IncAmount = Step; + const SCEV *IncAmount = Step; if (isNegative) IncAmount = Rewriter.SE.getNegativeSCEV(Step); @@ -1341,13 +1341,13 @@ // loop before users outside of the loop with a particular base. // // We would like to use stable_sort here, but we can't. The problem is that - // const SCEV*'s don't have a deterministic ordering w.r.t to each other, so + // const SCEV *'s don't have a deterministic ordering w.r.t to each other, so // we don't have anything to do a '<' comparison on. Because we think the // number of uses is small, do a horrible bubble sort which just relies on // ==. for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) { // Get a base value. - const SCEV* Base = UsersToProcess[i].Base; + const SCEV *Base = UsersToProcess[i].Base; // Compact everything with this base to be consecutive with this one. for (unsigned j = i+1; j != e; ++j) { @@ -1366,8 +1366,8 @@ void LoopStrengthReduce::PrepareToStrengthReduceFully( std::vector &UsersToProcess, - const SCEV* Stride, - const SCEV* CommonExprs, + const SCEV *Stride, + const SCEV *CommonExprs, const Loop *L, SCEVExpander &PreheaderRewriter) { DOUT << " Fully reducing all users\n"; @@ -1379,9 +1379,9 @@ // TODO: The uses are grouped by base, but not sorted. We arbitrarily // pick the first Imm value here to start with, and adjust it for the // other uses. - const SCEV* Imm = UsersToProcess[i].Imm; - const SCEV* Base = UsersToProcess[i].Base; - const SCEV* Start = SE->getAddExpr(CommonExprs, Base, Imm); + const SCEV *Imm = UsersToProcess[i].Imm; + const SCEV *Base = UsersToProcess[i].Base; + const SCEV *Start = SE->getAddExpr(CommonExprs, Base, Imm); PHINode *Phi = InsertAffinePhi(Start, Stride, IVIncInsertPt, L, PreheaderRewriter); // Loop over all the users with the same base. @@ -1413,8 +1413,8 @@ void LoopStrengthReduce::PrepareToStrengthReduceWithNewPhi( std::vector &UsersToProcess, - const SCEV* Stride, - const SCEV* CommonExprs, + const SCEV *Stride, + const SCEV *CommonExprs, Value *CommonBaseV, Instruction *IVIncInsertPt, const Loop *L, @@ -1490,7 +1490,7 @@ /// StrengthReduceStridedIVUsers - Strength reduce all of the users of a single /// stride of IV. All of the users may have different starting values, and this /// may not be the only stride. -void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV* const &Stride, +void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, IVUsersOfOneStride &Uses, Loop *L) { // If all the users are moved to another stride, then there is nothing to do. @@ -1513,7 +1513,7 @@ // move information from the Base field to the Imm field, until we eventually // have the full access expression to rewrite the use. std::vector UsersToProcess; - const SCEV* CommonExprs = CollectIVUsers(Stride, Uses, L, AllUsesAreAddresses, + const SCEV *CommonExprs = CollectIVUsers(Stride, Uses, L, AllUsesAreAddresses, AllUsesAreOutsideLoop, UsersToProcess); @@ -1531,8 +1531,8 @@ // If all uses are addresses, consider sinking the immediate part of the // common expression back into uses if they can fit in the immediate fields. if (TLI && HaveCommonExprs && AllUsesAreAddresses) { - const SCEV* NewCommon = CommonExprs; - const SCEV* Imm = SE->getIntegerSCEV(0, ReplacedTy); + const SCEV *NewCommon = CommonExprs; + const SCEV *Imm = SE->getIntegerSCEV(0, ReplacedTy); MoveImmediateValues(TLI, Type::VoidTy, NewCommon, Imm, true, L, SE); if (!Imm->isZero()) { bool DoSink = true; @@ -1578,7 +1578,7 @@ Value *CommonBaseV = Context->getNullValue(ReplacedTy); - const SCEV* RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy); + const SCEV *RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy); IVExpr ReuseIV(SE->getIntegerSCEV(0, Type::Int32Ty), SE->getIntegerSCEV(0, Type::Int32Ty), 0); @@ -1618,7 +1618,7 @@ // strength-reduced forms. This outer loop handles all bases, the inner // loop handles all users of a particular base. while (!UsersToProcess.empty()) { - const SCEV* Base = UsersToProcess.back().Base; + const SCEV *Base = UsersToProcess.back().Base; Instruction *Inst = UsersToProcess.back().Inst; // Emit the code for Base into the preheader. @@ -1673,7 +1673,7 @@ User.Inst->moveBefore(IVIncInsertPt); } - const SCEV* RewriteExpr = SE->getUnknown(RewriteOp); + const SCEV *RewriteExpr = SE->getUnknown(RewriteOp); if (SE->getEffectiveSCEVType(RewriteOp->getType()) != SE->getEffectiveSCEVType(ReplacedTy)) { @@ -1705,7 +1705,7 @@ // The base has been used to initialize the PHI node but we don't want // it here. if (!ReuseIV.Base->isZero()) { - const SCEV* typedBase = ReuseIV.Base; + const SCEV *typedBase = ReuseIV.Base; if (SE->getEffectiveSCEVType(RewriteExpr->getType()) != SE->getEffectiveSCEVType(ReuseIV.Base->getType())) { // It's possible the original IV is a larger type than the new IV, @@ -1770,10 +1770,10 @@ /// set the IV user and stride information and return true, otherwise return /// false. bool LoopStrengthReduce::FindIVUserForCond(ICmpInst *Cond, IVStrideUse *&CondUse, - const SCEV* const * &CondStride) { + const SCEV *const * &CondStride) { for (unsigned Stride = 0, e = IU->StrideOrder.size(); Stride != e && !CondUse; ++Stride) { - std::map::iterator SI = + std::map::iterator SI = IU->IVUsesByStride.find(IU->StrideOrder[Stride]); assert(SI != IU->IVUsesByStride.end() && "Stride doesn't exist!"); @@ -1800,7 +1800,7 @@ const ScalarEvolution *SE; explicit StrideCompare(const ScalarEvolution *se) : SE(se) {} - bool operator()(const SCEV* const &LHS, const SCEV* const &RHS) { + bool operator()(const SCEV *const &LHS, const SCEV *const &RHS) { const SCEVConstant *LHSC = dyn_cast(LHS); const SCEVConstant *RHSC = dyn_cast(RHS); if (LHSC && RHSC) { @@ -1843,14 +1843,14 @@ /// if (v1 < 30) goto loop ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond, IVStrideUse* &CondUse, - const SCEV* const* &CondStride) { + const SCEV *const* &CondStride) { // If there's only one stride in the loop, there's nothing to do here. if (IU->StrideOrder.size() < 2) return Cond; // If there are other users of the condition's stride, don't bother // trying to change the condition because the stride will still // remain. - std::map::iterator I = + std::map::iterator I = IU->IVUsesByStride.find(*CondStride); if (I == IU->IVUsesByStride.end() || I->second->Users.size() != 1) @@ -1867,11 +1867,11 @@ const Type *NewCmpTy = NULL; unsigned TyBits = SE->getTypeSizeInBits(CmpTy); unsigned NewTyBits = 0; - const SCEV* *NewStride = NULL; + const SCEV **NewStride = NULL; Value *NewCmpLHS = NULL; Value *NewCmpRHS = NULL; int64_t Scale = 1; - const SCEV* NewOffset = SE->getIntegerSCEV(0, CmpTy); + const SCEV *NewOffset = SE->getIntegerSCEV(0, CmpTy); if (ConstantInt *C = dyn_cast(Cond->getOperand(1))) { int64_t CmpVal = C->getValue().getSExtValue(); @@ -1883,7 +1883,7 @@ // Look for a suitable stride / iv as replacement. for (unsigned i = 0, e = IU->StrideOrder.size(); i != e; ++i) { - std::map::iterator SI = + std::map::iterator SI = IU->IVUsesByStride.find(IU->StrideOrder[i]); if (!isa(SI->first)) continue; @@ -1963,7 +1963,7 @@ bool AllUsesAreAddresses = true; bool AllUsesAreOutsideLoop = true; std::vector UsersToProcess; - const SCEV* CommonExprs = CollectIVUsers(SI->first, *SI->second, L, + const SCEV *CommonExprs = CollectIVUsers(SI->first, *SI->second, L, AllUsesAreAddresses, AllUsesAreOutsideLoop, UsersToProcess); @@ -2098,13 +2098,13 @@ SelectInst *Sel = dyn_cast(Cond->getOperand(1)); if (!Sel || !Sel->hasOneUse()) return Cond; - const SCEV* BackedgeTakenCount = SE->getBackedgeTakenCount(L); + const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L); if (isa(BackedgeTakenCount)) return Cond; - const SCEV* One = SE->getIntegerSCEV(1, BackedgeTakenCount->getType()); + const SCEV *One = SE->getIntegerSCEV(1, BackedgeTakenCount->getType()); // Add one to the backedge-taken count to get the trip count. - const SCEV* IterationCount = SE->getAddExpr(BackedgeTakenCount, One); + const SCEV *IterationCount = SE->getAddExpr(BackedgeTakenCount, One); // Check for a max calculation that matches the pattern. if (!isa(IterationCount) && !isa(IterationCount)) @@ -2117,13 +2117,13 @@ if (Max->getNumOperands() != 2) return Cond; - const SCEV* MaxLHS = Max->getOperand(0); - const SCEV* MaxRHS = Max->getOperand(1); + const SCEV *MaxLHS = Max->getOperand(0); + const SCEV *MaxRHS = Max->getOperand(1); if (!MaxLHS || MaxLHS != One) return Cond; // Check the relevant induction variable for conformance to // the pattern. - const SCEV* IV = SE->getSCEV(Cond->getOperand(0)); + const SCEV *IV = SE->getSCEV(Cond->getOperand(0)); const SCEVAddRecExpr *AR = dyn_cast(IV); if (!AR || !AR->isAffine() || AR->getStart() != One || @@ -2169,13 +2169,13 @@ /// inside the loop then try to eliminate the cast opeation. void LoopStrengthReduce::OptimizeShadowIV(Loop *L) { - const SCEV* BackedgeTakenCount = SE->getBackedgeTakenCount(L); + const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L); if (isa(BackedgeTakenCount)) return; for (unsigned Stride = 0, e = IU->StrideOrder.size(); Stride != e; ++Stride) { - std::map::iterator SI = + std::map::iterator SI = IU->IVUsesByStride.find(IU->StrideOrder[Stride]); assert(SI != IU->IVUsesByStride.end() && "Stride doesn't exist!"); if (!isa(SI->first)) @@ -2305,7 +2305,7 @@ // Search IVUsesByStride to find Cond's IVUse if there is one. IVStrideUse *CondUse = 0; - const SCEV* const *CondStride = 0; + const SCEV *const *CondStride = 0; ICmpInst *Cond = cast(TermBr->getCondition()); if (!FindIVUserForCond(Cond, CondUse, CondStride)) return; // setcc doesn't use the IV. @@ -2335,7 +2335,7 @@ int64_t SInt = SC->getValue()->getSExtValue(); for (unsigned NewStride = 0, ee = IU->StrideOrder.size(); NewStride != ee; ++NewStride) { - std::map::iterator SI = + std::map::iterator SI = IU->IVUsesByStride.find(IU->StrideOrder[NewStride]); if (!isa(SI->first) || SI->first == *CondStride) continue; @@ -2349,7 +2349,7 @@ bool AllUsesAreAddresses = true; bool AllUsesAreOutsideLoop = true; std::vector UsersToProcess; - const SCEV* CommonExprs = CollectIVUsers(SI->first, *SI->second, L, + const SCEV *CommonExprs = CollectIVUsers(SI->first, *SI->second, L, AllUsesAreAddresses, AllUsesAreOutsideLoop, UsersToProcess); @@ -2410,7 +2410,7 @@ void LoopStrengthReduce::OptimizeLoopCountIV(Loop *L) { // If the number of times the loop is executed isn't computable, give up. - const SCEV* BackedgeTakenCount = SE->getBackedgeTakenCount(L); + const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L); if (isa(BackedgeTakenCount)) return; @@ -2439,9 +2439,9 @@ // Handle only tests for equality for the moment, and only stride 1. if (Cond->getPredicate() != CmpInst::ICMP_EQ) return; - const SCEV* IV = SE->getSCEV(Cond->getOperand(0)); + const SCEV *IV = SE->getSCEV(Cond->getOperand(0)); const SCEVAddRecExpr *AR = dyn_cast(IV); - const SCEV* One = SE->getIntegerSCEV(1, BackedgeTakenCount->getType()); + const SCEV *One = SE->getIntegerSCEV(1, BackedgeTakenCount->getType()); if (!AR || !AR->isAffine() || AR->getStepRecurrence(*SE) != One) return; // If the RHS of the comparison is defined inside the loop, the rewrite @@ -2557,7 +2557,7 @@ // strides deterministic - not dependent on map order. for (unsigned Stride = 0, e = IU->StrideOrder.size(); Stride != e; ++Stride) { - std::map::iterator SI = + std::map::iterator SI = IU->IVUsesByStride.find(IU->StrideOrder[Stride]); assert(SI != IU->IVUsesByStride.end() && "Stride doesn't exist!"); // FIXME: Generalize to non-affine IV's. From resistor at mac.com Tue Jul 7 12:12:57 2009 From: resistor at mac.com (Owen Anderson) Date: Tue, 07 Jul 2009 17:12:57 -0000 Subject: [llvm-commits] [llvm] r74920 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp Message-ID: <200907071712.n67HCxXb021589@zion.cs.uiuc.edu> Author: resistor Date: Tue Jul 7 12:12:53 2009 New Revision: 74920 URL: http://llvm.org/viewvc/llvm-project?rev=74920&view=rev Log: Re-LLVMContext-ize DebugInfo, now with less breakage. Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h llvm/trunk/lib/Analysis/DebugInfo.cpp Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=74920&r1=74919&r2=74920&view=diff ============================================================================== --- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original) +++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Tue Jul 7 12:12:53 2009 @@ -39,6 +39,7 @@ class DebugLoc; class DebugLocTracker; class Instruction; + class LLVMContext; class DIDescriptor { protected: @@ -407,6 +408,8 @@ /// descriptors. class DIFactory { Module &M; + LLVMContext& VMContext; + // Cached values for uniquing and faster lookups. const Type *EmptyStructPtr; // "{}*". Function *StopPointFn; // llvm.dbg.stoppoint Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=74920&r1=74919&r2=74920&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/DebugInfo.cpp (original) +++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Jul 7 12:12:53 2009 @@ -18,6 +18,7 @@ #include "llvm/Intrinsics.h" #include "llvm/IntrinsicInst.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/Dwarf.h" @@ -453,22 +454,23 @@ //===----------------------------------------------------------------------===// DIFactory::DIFactory(Module &m) - : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0), + : M(m), VMContext(M.getContext()), StopPointFn(0), FuncStartFn(0), + RegionStartFn(0), RegionEndFn(0), DeclareFn(0) { - EmptyStructPtr = PointerType::getUnqual(StructType::get()); + EmptyStructPtr = VMContext.getPointerTypeUnqual(VMContext.getStructType()); } /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. /// This is only valid when the descriptor is non-null. Constant *DIFactory::getCastToEmpty(DIDescriptor D) { if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); - return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); + return VMContext.getConstantExprBitCast(D.getGV(), EmptyStructPtr); } Constant *DIFactory::GetTagConstant(unsigned TAG) { assert((TAG & LLVMDebugVersionMask) == 0 && "Tag too large for debug encoding!"); - return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); + return VMContext.getConstantInt(Type::Int32Ty, TAG | LLVMDebugVersion); } Constant *DIFactory::GetStringConstant(const std::string &String) { @@ -478,21 +480,21 @@ // Return Constant if previously defined. if (Slot) return Slot; - const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); + const PointerType *DestTy = VMContext.getPointerTypeUnqual(Type::Int8Ty); // If empty string then use a i8* null instead. if (String.empty()) - return Slot = ConstantPointerNull::get(DestTy); + return Slot = VMContext.getConstantPointerNull(DestTy); // Construct string as an llvm constant. - Constant *ConstStr = ConstantArray::get(String); + Constant *ConstStr = VMContext.getConstantArray(String); // Otherwise create and return a new string global. GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, GlobalVariable::InternalLinkage, ConstStr, ".str", &M); StrGV->setSection("llvm.metadata"); - return Slot = ConstantExpr::getBitCast(StrGV, DestTy); + return Slot = VMContext.getConstantExprBitCast(StrGV, DestTy); } //===----------------------------------------------------------------------===// @@ -507,7 +509,7 @@ for (unsigned i = 0; i != NumTys; ++i) Elts.push_back(getCastToEmpty(Tys[i])); - Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, + Constant *Init = VMContext.getConstantArray(VMContext.getArrayType(EmptyStructPtr, Elts.size()), Elts.data(), Elts.size()); // If we already have this array, just return the uniqued version. @@ -527,11 +529,12 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subrange_type), - ConstantInt::get(Type::Int64Ty, Lo), - ConstantInt::get(Type::Int64Ty, Hi) + VMContext.getConstantInt(Type::Int64Ty, Lo), + VMContext.getConstantInt(Type::Int64Ty, Hi) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); // If we already have this range, just return the uniqued version. DIDescriptor &Entry = SimpleConstantCache[Init]; @@ -561,18 +564,19 @@ unsigned RunTimeVer) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), - Constant::getNullValue(EmptyStructPtr), - ConstantInt::get(Type::Int32Ty, LangID), + VMContext.getNullValue(EmptyStructPtr), + VMContext.getConstantInt(Type::Int32Ty, LangID), GetStringConstant(Filename), GetStringConstant(Directory), GetStringConstant(Producer), - ConstantInt::get(Type::Int1Ty, isMain), - ConstantInt::get(Type::Int1Ty, isOptimized), + VMContext.getConstantInt(Type::Int1Ty, isMain), + VMContext.getConstantInt(Type::Int1Ty, isOptimized), GetStringConstant(Flags), - ConstantInt::get(Type::Int32Ty, RunTimeVer) + VMContext.getConstantInt(Type::Int32Ty, RunTimeVer) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -587,10 +591,11 @@ Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_enumerator), GetStringConstant(Name), - ConstantInt::get(Type::Int64Ty, Val) + VMContext.getConstantInt(Type::Int64Ty, Val) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -615,15 +620,16 @@ getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), - ConstantInt::get(Type::Int32Ty, Encoding) + VMContext.getConstantInt(Type::Int32Ty, LineNumber), + VMContext.getConstantInt(Type::Int64Ty, SizeInBits), + VMContext.getConstantInt(Type::Int64Ty, AlignInBits), + VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), + VMContext.getConstantInt(Type::Int32Ty, Flags), + VMContext.getConstantInt(Type::Int32Ty, Encoding) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.basictype.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -650,15 +656,16 @@ getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), + VMContext.getConstantInt(Type::Int32Ty, LineNumber), + VMContext.getConstantInt(Type::Int64Ty, SizeInBits), + VMContext.getConstantInt(Type::Int64Ty, AlignInBits), + VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), + VMContext.getConstantInt(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -687,17 +694,18 @@ getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), + VMContext.getConstantInt(Type::Int32Ty, LineNumber), + VMContext.getConstantInt(Type::Int64Ty, SizeInBits), + VMContext.getConstantInt(Type::Int64Ty, AlignInBits), + VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), + VMContext.getConstantInt(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom), getCastToEmpty(Elements), - ConstantInt::get(Type::Int32Ty, RuntimeLang) + VMContext.getConstantInt(Type::Int32Ty, RuntimeLang) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.composite.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -722,19 +730,20 @@ Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subprogram), - Constant::getNullValue(EmptyStructPtr), + VMContext.getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + VMContext.getConstantInt(Type::Int32Ty, LineNo), getCastToEmpty(Type), - ConstantInt::get(Type::Int1Ty, isLocalToUnit), - ConstantInt::get(Type::Int1Ty, isDefinition) + VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit), + VMContext.getConstantInt(Type::Int1Ty, isDefinition) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -754,20 +763,21 @@ bool isDefinition, llvm::GlobalVariable *Val) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_variable), - Constant::getNullValue(EmptyStructPtr), + VMContext.getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + VMContext.getConstantInt(Type::Int32Ty, LineNo), getCastToEmpty(Type), - ConstantInt::get(Type::Int1Ty, isLocalToUnit), - ConstantInt::get(Type::Int1Ty, isDefinition), - ConstantExpr::getBitCast(Val, EmptyStructPtr) + VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit), + VMContext.getConstantInt(Type::Int1Ty, isDefinition), + VMContext.getConstantExprBitCast(Val, EmptyStructPtr) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -788,11 +798,12 @@ getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + VMContext.getConstantInt(Type::Int32Ty, LineNo), getCastToEmpty(Type) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.variable.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -804,14 +815,15 @@ /// CreateBlock - This creates a descriptor for a lexical block with the -/// specified parent context. +/// specified parent VMContext. DIBlock DIFactory::CreateBlock(DIDescriptor Context) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_lexical_block), getCastToEmpty(Context) }; - Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); + Constant *Init = VMContext.getConstantStruct(Elts, + sizeof(Elts)/sizeof(Elts[0])); M.addTypeName("llvm.dbg.block.type", Init->getType()); GlobalVariable *GV = new GlobalVariable(Init->getType(), true, @@ -838,8 +850,8 @@ // Invoke llvm.dbg.stoppoint Value *Args[] = { - llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo), - llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo), + VMContext.getConstantInt(llvm::Type::Int32Ty, LineNo), + VMContext.getConstantInt(llvm::Type::Int32Ty, ColNo), getCastToEmpty(CU) }; CallInst::Create(StopPointFn, Args, Args+3, "", BB); @@ -939,10 +951,12 @@ Value *findDbgGlobalDeclare(GlobalVariable *V) { const Module *M = V->getParent(); + LLVMContext& Context = M->getContext(); + const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); if (!Ty) return 0; - Ty = PointerType::get(Ty, 0); + Ty = Context.getPointerType(Ty, 0); Value *Val = V->stripPointerCasts(); for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); From clattner at apple.com Tue Jul 7 12:16:08 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 7 Jul 2009 10:16:08 -0700 Subject: [llvm-commits] [PATCH] Improve error handling, supersede cerr+abort In-Reply-To: <4A4D065C.5080809@gmail.com> References: <4A47D8D4.6060001@gmail.com> <60D5E8C7-05E7-4D68-9D61-E07D83090882@apple.com> <4A4B23CA.2070603@gmail.com> <6a8523d60907010802o84d6bd9k2d19ad928cf1bb1d@mail.gmail.com> <4A4D065C.5080809@gmail.com> Message-ID: On Jul 2, 2009, at 12:11 PM, T?r?k Edwin wrote: > On 2009-07-01 18:02, Daniel Dunbar wrote: >> 2009/7/1 T?r?k Edwin : >> >>>> We don't need this. Assertions "can't happen", so assert(0) >>>> really is >>>> unreachable. >>>> >>>> >>> What if assertions are turned off? Should we just remove the calls >>> to >>> abort() after each assert(0)? >>> I thought the abort()s were there after the assert(0) so that the >>> compiler knows that the codepaths >>> never return even with assertions turned off. >>> >> >> The compiler will still know this if we replace such places with a >> report_error call, and report_error is marked noreturn. >> > > Yes, llvm_report_error is already marked as noreturn. > > Can I commit the patch? Yes, this looks great, please commit. Sorry for the delay, -Chris From clattner at apple.com Tue Jul 7 12:16:44 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 7 Jul 2009 10:16:44 -0700 Subject: [llvm-commits] [llvm] r74742 - /llvm/trunk/utils/TableGen/ In-Reply-To: <200907030010.n630AV3N029704@zion.cs.uiuc.edu> References: <200907030010.n630AV3N029704@zion.cs.uiuc.edu> Message-ID: <6F951BA9-8441-46A5-AB49-0954B9192775@apple.com> On Jul 2, 2009, at 5:10 PM, Daniel Dunbar wrote: > Author: ddunbar > Date: Thu Jul 2 19:10:29 2009 > New Revision: 74742 > > URL: http://llvm.org/viewvc/llvm-project?rev=74742&view=rev > Log: > Replace std::iostreams with raw_ostream in TableGen. > - Sorry, I can't help myself. Yay :) -Chris From edwintorok at gmail.com Tue Jul 7 12:32:53 2009 From: edwintorok at gmail.com (Torok Edwin) Date: Tue, 07 Jul 2009 17:32:53 -0000 Subject: [llvm-commits] [llvm] r74922 - in /llvm/trunk: include/llvm/Support/Compiler.h include/llvm/Support/ErrorHandling.h lib/ExecutionEngine/ExecutionEngine.cpp lib/ExecutionEngine/JIT/JIT.cpp lib/Support/ErrorHandling.cpp Message-ID: <200907071733.n67HX5E5022485@zion.cs.uiuc.edu> Author: edwin Date: Tue Jul 7 12:32:34 2009 New Revision: 74922 URL: http://llvm.org/viewvc/llvm-project?rev=74922&view=rev Log: Introduce new error handling API. This will replace exit()/abort() style error handling with an API that allows clients to register custom error handling hooks. The default is to call exit(1) when no error handler is provided. Added: llvm/trunk/include/llvm/Support/ErrorHandling.h llvm/trunk/lib/Support/ErrorHandling.cpp Modified: llvm/trunk/include/llvm/Support/Compiler.h llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Modified: llvm/trunk/include/llvm/Support/Compiler.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=74922&r1=74921&r2=74922&view=diff ============================================================================== --- llvm/trunk/include/llvm/Support/Compiler.h (original) +++ llvm/trunk/include/llvm/Support/Compiler.h Tue Jul 7 12:32:34 2009 @@ -56,4 +56,10 @@ #define DISABLE_INLINE #endif +#ifdef __GNUC__ +#define NORETURN __attribute__((noreturn)) +#else +#define NORETURN +#endif + #endif Added: llvm/trunk/include/llvm/Support/ErrorHandling.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ErrorHandling.h?rev=74922&view=auto ============================================================================== --- llvm/trunk/include/llvm/Support/ErrorHandling.h (added) +++ llvm/trunk/include/llvm/Support/ErrorHandling.h Tue Jul 7 12:32:34 2009 @@ -0,0 +1,52 @@ +//===- llvm/Support/ErrorHandling.h - Callbacks for errors ------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines an API used to indicate error conditions. +// Callbacks can be registered for these errors through this API. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_ERRORHANDLING_H +#define LLVM_SUPPORT_ERRORHANDLING_H + +#include "llvm/Support/Compiler.h" + +namespace llvm { + // An error handler callback. + typedef void (*llvm_error_handler_t)(const std::string& reason); + + // Installs a new error handler: this function will be called whenever a + // serious error is encountered by LLVM. + // If you are using llvm_start_multithreaded, you should register the handler + // before doing that. + // + // If no error handler is installed the default is to print the error message + // to stderr, and call exit(1). + // If an error handler is installed then it is the handler's responsibility to + // log the message, it will no longer be printed to stderr. + // If the error handler returns, then exit(1) will be called. + void llvm_install_error_handler(llvm_error_handler_t handler); + + // Restores default error handling behaviour. + // This must not be called between llvm_start_multithreaded() and + // llvm_stop_multithreaded(). + void llvm_remove_error_handler(void); + + // Reports a serious error, calling any installed error handler. + // If no error handler is installed the default is to print the message to + void llvm_report_error(const std::string &reason) NORETURN; + + // This function calls abort(). + // Call this after assert(0), so that compiler knows the path is not + // reachable. + void llvm_unreachable(void) NORETURN; +} + +#endif + Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=74922&r1=74921&r2=74922&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Tue Jul 7 12:32:34 2009 @@ -22,6 +22,7 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MutexGuard.h" #include "llvm/System/DynamicLibrary.h" #include "llvm/System/Host.h" @@ -640,7 +641,7 @@ case Type::FP128TyID: { APFloat apfLHS = APFloat(LHS.IntVal); switch (CE->getOpcode()) { - default: assert(0 && "Invalid long double opcode"); abort(); + default: assert(0 && "Invalid long double opcode");llvm_unreachable(); case Instruction::FAdd: apfLHS.add(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); @@ -953,9 +954,8 @@ sys::DynamicLibrary::SearchForAddressOfSymbol(I->getName().c_str())) addGlobalMapping(I, SymAddr); else { - cerr << "Could not resolve external global address: " - << I->getName() << "\n"; - abort(); + llvm_report_error("Could not resolve external global address: " + +I->getName()); } } } Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=74922&r1=74921&r2=74922&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Tue Jul 7 12:32:34 2009 @@ -27,6 +27,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetJITInfo.h" #include "llvm/Support/Dwarf.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MutexGuard.h" #include "llvm/System/DynamicLibrary.h" #include "llvm/Config/config.h" @@ -671,9 +672,8 @@ #endif Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(GV->getName().c_str()); if (Ptr == 0 && !areDlsymStubsEnabled()) { - cerr << "Could not resolve external global address: " - << GV->getName() << "\n"; - abort(); + llvm_report_error("Could not resolve external global address: " + +GV->getName()); } addGlobalMapping(GV, Ptr); } else { Added: llvm/trunk/lib/Support/ErrorHandling.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ErrorHandling.cpp?rev=74922&view=auto ============================================================================== --- llvm/trunk/lib/Support/ErrorHandling.cpp (added) +++ llvm/trunk/lib/Support/ErrorHandling.cpp Tue Jul 7 12:32:34 2009 @@ -0,0 +1,53 @@ +//===- lib/Support/ErrorHandling.cpp - Callbacks for errors -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines an API for error handling, it supersedes cerr+abort(), and +// cerr+exit() style error handling. +// Callbacks can be registered for these errors through this API. +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/System/Threading.h" +#include +#include + +using namespace llvm; +using namespace std; + +static llvm_error_handler_t ErrorHandler = 0; +namespace llvm { +void llvm_install_error_handler(llvm_error_handler_t handler) { + assert(!llvm_is_multithreaded() && + "Cannot register error handlers after starting multithreaded mode!\n"); + assert(!ErrorHandler && "Error handler already registered!\n"); + ErrorHandler = handler; +} + +void llvm_remove_error_handler(void) { + ErrorHandler = 0; +} + +void llvm_report_error(const std::string &reason) +{ + if (!ErrorHandler) { + errs() << "LLVM ERROR: " << reason << "\n"; + } else { + ErrorHandler(reason); + } + exit(1); +} + +void llvm_unreachable(void) +{ + abort(); +} +} + From edwintorok at gmail.com Tue Jul 7 12:40:25 2009 From: edwintorok at gmail.com (Torok Edwin) Date: Tue, 07 Jul 2009 17:40:25 -0000 Subject: [llvm-commits] [llvm] r74923 - /llvm/trunk/lib/Support/ErrorHandling.cpp Message-ID: <200907071740.n67HeRYA022715@zion.cs.uiuc.edu> Author: edwin Date: Tue Jul 7 12:39:53 2009 New Revision: 74923 URL: http://llvm.org/viewvc/llvm-project?rev=74923&view=rev Log: Fix braces. Modified: llvm/trunk/lib/Support/ErrorHandling.cpp Modified: llvm/trunk/lib/Support/ErrorHandling.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ErrorHandling.cpp?rev=74923&r1=74922&r2=74923&view=diff ============================================================================== --- llvm/trunk/lib/Support/ErrorHandling.cpp (original) +++ llvm/trunk/lib/Support/ErrorHandling.cpp Tue Jul 7 12:39:53 2009 @@ -35,8 +35,7 @@ ErrorHandler = 0; } -void llvm_report_error(const std::string &reason) -{ +void llvm_report_error(const std::string &reason) { if (!ErrorHandler) { errs() << "LLVM ERROR: " << reason << "\n"; } else { @@ -45,8 +44,7 @@ exit(1); } -void llvm_unreachable(void) -{ +void llvm_unreachable(void) { abort(); } } From sabre at nondot.org Tue Jul 7 12:50:21 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 17:50:21 -0000 Subject: [llvm-commits] [llvm] r74924 - /llvm/trunk/lib/System/DynamicLibrary.cpp Message-ID: <200907071750.n67HoOFW023241@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 12:50:11 2009 New Revision: 74924 URL: http://llvm.org/viewvc/llvm-project?rev=74924&view=rev Log: we don't use libtool anymore, update comments. Modified: llvm/trunk/lib/System/DynamicLibrary.cpp Modified: llvm/trunk/lib/System/DynamicLibrary.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/DynamicLibrary.cpp?rev=74924&r1=74923&r2=74924&view=diff ============================================================================== --- llvm/trunk/lib/System/DynamicLibrary.cpp (original) +++ llvm/trunk/lib/System/DynamicLibrary.cpp Tue Jul 7 12:50:11 2009 @@ -23,26 +23,18 @@ static std::map symbols; static llvm::sys::SmartRWMutex SymbolsLock; - void llvm::sys::DynamicLibrary::AddSymbol(const char* symbolName, void *symbolValue) { llvm::sys::SmartScopedWriter Writer(&SymbolsLock); symbols[symbolName] = symbolValue; } -// It is not possible to use ltdl.c on VC++ builds as the terms of its LGPL -// license and special exception would cause all of LLVM to be placed under -// the LGPL. This is because the exception applies only when libtool is -// used, and obviously libtool is not used with Visual Studio. An entirely -// separate implementation is provided in win32/DynamicLibrary.cpp. - #ifdef LLVM_ON_WIN32 #include "Win32/DynamicLibrary.inc" #else -//#include "ltdl.h" #include #include using namespace llvm; @@ -53,7 +45,6 @@ //=== independent code. //===----------------------------------------------------------------------===// -//static std::vector OpenedHandles; static std::vector OpenedHandles; DynamicLibrary::DynamicLibrary() {} @@ -61,7 +52,8 @@ DynamicLibrary::~DynamicLibrary() { SmartScopedWriter Writer(&SymbolsLock); while(!OpenedHandles.empty()) { - void *H = OpenedHandles.back(); OpenedHandles.pop_back(); + void *H = OpenedHandles.back(); + OpenedHandles.pop_back(); dlclose(H); } } @@ -80,8 +72,6 @@ } void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) { - // check_ltdl_initialization(); - // First check symbols added via AddSymbol(). SymbolsLock.reader_acquire(); std::map::iterator I = symbols.find(symbolName); From evan.cheng at apple.com Tue Jul 7 12:50:29 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 7 Jul 2009 10:50:29 -0700 Subject: [llvm-commits] [llvm] r74898 - /llvm/trunk/lib/CodeGen/PHIElimination.cpp In-Reply-To: <200907070804.n6784sHX030896@zion.cs.uiuc.edu> References: <200907070804.n6784sHX030896@zion.cs.uiuc.edu> Message-ID: This patch broke a whole bunch of tests. For example on Grawp-PIC: New Test Failures: test/CodeGen/ARM/2008-11-19-ScavengerAssert.ll [DEJAGNU] test/CodeGen/X86/2006-05-02-InstrSched2.ll [DEJAGNU] test/CodeGen/X86/2008-05-21-CoalescerBug.ll for PR2343 [DEJAGNU] test/CodeGen/X86/stack-color-with-reg-2.ll [DEJAGNU] test/CodeGen/X86/twoaddr-pass-sink.ll [DEJAGNU] Applications/oggenc/oggenc [LLC compile, ] Benchmarks/ASCI_Purple/SMG2000/smg2000 [LLC compile, ] Benchmarks/mafft/pairlocalalign [LLC compile, ] Benchmarks/MallocBench/gs/gs [LLC compile, ] Benchmarks/mediabench/mpeg2/mpeg2dec/mpeg2decode [LLC compile, ] Benchmarks/MiBench/consumer-jpeg/consumer-jpeg [LLC compile, ] Benchmarks/MiBench/consumer-lame/consumer-lame [LLC compile, ] Benchmarks/Misc/whetstone [LLC compile, ] Benchmarks/Ptrdist/yacr2/yacr2 [LLC compile, ] Nurbs/nurbs [LLC compile, ] SPEC/CFP2006/433.milc/433.milc [LLC compile, ] SPEC/CINT2000/176.gcc/176.gcc [LLC compile, ] SPEC/CINT2000/254.gap/254.gap [LLC compile, ] SPEC/CINT2006/403.gcc/403.gcc [LLC compile, ] I'll back it out for now. Sanjiv, please investigate. Thanks. Evan On Jul 7, 2009, at 1:04 AM, Sanjiv Gupta wrote: > Author: sgupta > Date: Tue Jul 7 03:04:51 2009 > New Revision: 74898 > > URL: http://llvm.org/viewvc/llvm-project?rev=74898&view=rev > Log: > if the terminator is a branch depending upon the side effects of a > previous cmp; a copy can not be inserted here if the copy insn also > has > side effects. We don't have access to the attributes of copy insn > here; > so just play safe by finding a safe locations for branch terminators. > > Modified: > llvm/trunk/lib/CodeGen/PHIElimination.cpp > > Modified: llvm/trunk/lib/CodeGen/PHIElimination.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PHIElimination.cpp?rev=74898&r1=74897&r2=74898&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- llvm/trunk/lib/CodeGen/PHIElimination.cpp (original) > +++ llvm/trunk/lib/CodeGen/PHIElimination.cpp Tue Jul 7 03:04:51 2009 > @@ -169,9 +169,15 @@ > return MBB.begin(); > > // If this basic block does not contain an invoke, then control > flow always > - // reaches the end of it, so place the copy there. The logic > below works in > - // this case too, but is more expensive. > - if (!isa(MBB.getBasicBlock()->getTerminator())) > + // reaches the end of it, so place the copy there. > + // If the terminator is a branch depending upon the side effects > of a > + // previous cmp; a copy can not be inserted here if the copy insn > also > + // side effects. We don't have access to the attributes of copy > insn here; > + // so just play safe by finding a safe locations for branch > terminators. > + // > + // The logic below works in this case too, but is more expensive. > + const TerminatorInst *TermInst = MBB.getBasicBlock()- > >getTerminator(); > + if (!(isa(TermInst) || isa(TermInst))) > return MBB.getFirstTerminator(); > > // Discover any definition/uses in this basic block. > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090707/6da76e8b/attachment.html From evan.cheng at apple.com Tue Jul 7 12:50:47 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 07 Jul 2009 17:50:47 -0000 Subject: [llvm-commits] [llvm] r74925 - /llvm/trunk/lib/CodeGen/PHIElimination.cpp Message-ID: <200907071750.n67Holjj023262@zion.cs.uiuc.edu> Author: evancheng Date: Tue Jul 7 12:50:43 2009 New Revision: 74925 URL: http://llvm.org/viewvc/llvm-project?rev=74925&view=rev Log: Revert 74898. It broke several tests. Modified: llvm/trunk/lib/CodeGen/PHIElimination.cpp Modified: llvm/trunk/lib/CodeGen/PHIElimination.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PHIElimination.cpp?rev=74925&r1=74924&r2=74925&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/PHIElimination.cpp (original) +++ llvm/trunk/lib/CodeGen/PHIElimination.cpp Tue Jul 7 12:50:43 2009 @@ -169,15 +169,9 @@ return MBB.begin(); // If this basic block does not contain an invoke, then control flow always - // reaches the end of it, so place the copy there. - // If the terminator is a branch depending upon the side effects of a - // previous cmp; a copy can not be inserted here if the copy insn also - // side effects. We don't have access to the attributes of copy insn here; - // so just play safe by finding a safe locations for branch terminators. - // - // The logic below works in this case too, but is more expensive. - const TerminatorInst *TermInst = MBB.getBasicBlock()->getTerminator(); - if (!(isa(TermInst) || isa(TermInst))) + // reaches the end of it, so place the copy there. The logic below works in + // this case too, but is more expensive. + if (!isa(MBB.getBasicBlock()->getTerminator())) return MBB.getFirstTerminator(); // Discover any definition/uses in this basic block. From sabre at nondot.org Tue Jul 7 13:02:29 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 18:02:29 -0000 Subject: [llvm-commits] [llvm] r74926 - in /llvm/trunk: include/llvm/System/DynamicLibrary.h lib/System/DynamicLibrary.cpp Message-ID: <200907071802.n67I2Z6b023676@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 13:01:58 2009 New Revision: 74926 URL: http://llvm.org/viewvc/llvm-project?rev=74926&view=rev Log: remove dead code, noone creates instances of "DynamicLibrary", so the ctor and dtor are dead. Modified: llvm/trunk/include/llvm/System/DynamicLibrary.h llvm/trunk/lib/System/DynamicLibrary.cpp Modified: llvm/trunk/include/llvm/System/DynamicLibrary.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/DynamicLibrary.h?rev=74926&r1=74925&r2=74926&view=diff ============================================================================== --- llvm/trunk/include/llvm/System/DynamicLibrary.h (original) +++ llvm/trunk/include/llvm/System/DynamicLibrary.h Tue Jul 7 13:01:58 2009 @@ -14,7 +14,6 @@ #ifndef LLVM_SYSTEM_DYNAMIC_LIBRARY_H #define LLVM_SYSTEM_DYNAMIC_LIBRARY_H -#include "llvm/System/Path.h" #include namespace llvm { @@ -30,66 +29,40 @@ /// but rather the main program itself, useful on Windows where the main /// executable cannot be searched. class DynamicLibrary { - /// @name Constructors - /// @{ - public: - /// Construct a DynamicLibrary that represents the currently executing - /// program. The program must have been linked with -export-dynamic or - /// -dlopen self for this to work. - /// @throws std::string indicating why the program couldn't be opened. - /// @brief Open program as dynamic library. - DynamicLibrary(); - - /// After destruction, the symbols of the library will no longer be - /// available to the program. - /// @brief Closes the DynamicLibrary - ~DynamicLibrary(); - - /// @} - /// @name Functions - /// @{ - public: - /// This function allows a library to be loaded without instantiating a - /// DynamicLibrary object. Consequently, it is marked as being permanent - /// and will only be unloaded when the program terminates. This returns - /// false on success or returns true and fills in *ErrMsg on failure. - /// @brief Open a dynamic library permanently. - static bool LoadLibraryPermanently(const char* filename, - std::string *ErrMsg = 0); - - /// This function will search through all previously loaded dynamic - /// libraries for the symbol \p symbolName. If it is found, the addressof - /// that symbol is returned. If not, null is returned. Note that this will - /// search permanently loaded libraries (LoadLibraryPermanently) as well - /// as ephemerally loaded libraries (constructors). - /// @throws std::string on error. - /// @brief Search through libraries for address of a symbol - static void* SearchForAddressOfSymbol(const char* symbolName); - - /// @brief Convenience function for C++ophiles. - static void* SearchForAddressOfSymbol(const std::string& symbolName) { - return SearchForAddressOfSymbol(symbolName.c_str()); - } - - /// This functions permanently adds the symbol \p symbolName with the - /// value \p symbolValue. These symbols are searched before any - /// libraries. - /// @brief Add searchable symbol/value pair. - static void AddSymbol(const char* symbolName, void *symbolValue); - - /// @brief Convenience function for C++ophiles. - static void AddSymbol(const std::string& symbolName, void *symbolValue) { - AddSymbol(symbolName.c_str(), symbolValue); - } - - /// @} - /// @name Implementation - /// @{ - protected: - void* handle; // Opaque handle for information about the library - DynamicLibrary(const DynamicLibrary&); ///< Do not implement - DynamicLibrary& operator=(const DynamicLibrary&); ///< Do not implement - /// @} + DynamicLibrary(); // DO NOT IMPLEMENT + public: + /// This function allows a library to be loaded without instantiating a + /// DynamicLibrary object. Consequently, it is marked as being permanent + /// and will only be unloaded when the program terminates. This returns + /// false on success or returns true and fills in *ErrMsg on failure. + /// @brief Open a dynamic library permanently. + static bool LoadLibraryPermanently(const char *filename, + std::string *ErrMsg = 0); + + /// This function will search through all previously loaded dynamic + /// libraries for the symbol \p symbolName. If it is found, the addressof + /// that symbol is returned. If not, null is returned. Note that this will + /// search permanently loaded libraries (LoadLibraryPermanently) as well + /// as ephemerally loaded libraries (constructors). + /// @throws std::string on error. + /// @brief Search through libraries for address of a symbol + static void *SearchForAddressOfSymbol(const char *symbolName); + + /// @brief Convenience function for C++ophiles. + static void *SearchForAddressOfSymbol(const std::string &symbolName) { + return SearchForAddressOfSymbol(symbolName.c_str()); + } + + /// This functions permanently adds the symbol \p symbolName with the + /// value \p symbolValue. These symbols are searched before any + /// libraries. + /// @brief Add searchable symbol/value pair. + static void AddSymbol(const char *symbolName, void *symbolValue); + + /// @brief Convenience function for C++ophiles. + static void AddSymbol(const std::string &symbolName, void *symbolValue) { + AddSymbol(symbolName.c_str(), symbolValue); + } }; } // End sys namespace Modified: llvm/trunk/lib/System/DynamicLibrary.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/DynamicLibrary.cpp?rev=74926&r1=74925&r2=74926&view=diff ============================================================================== --- llvm/trunk/lib/System/DynamicLibrary.cpp (original) +++ llvm/trunk/lib/System/DynamicLibrary.cpp Tue Jul 7 13:01:58 2009 @@ -18,6 +18,7 @@ #include #include #include +#include // Collection of symbol name/value pairs to be searched prior to any libraries. static std::map symbols; @@ -47,16 +48,6 @@ static std::vector OpenedHandles; -DynamicLibrary::DynamicLibrary() {} - -DynamicLibrary::~DynamicLibrary() { - SmartScopedWriter Writer(&SymbolsLock); - while(!OpenedHandles.empty()) { - void *H = OpenedHandles.back(); - OpenedHandles.pop_back(); - dlclose(H); - } -} bool DynamicLibrary::LoadLibraryPermanently(const char *Filename, std::string *ErrMsg) { From sabre at nondot.org Tue Jul 7 13:17:33 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 18:17:33 -0000 Subject: [llvm-commits] [llvm] r74927 - in /llvm/trunk: include/llvm/System/DynamicLibrary.h lib/System/DynamicLibrary.cpp Message-ID: <200907071817.n67IHbJ8024168@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 13:17:07 2009 New Revision: 74927 URL: http://llvm.org/viewvc/llvm-project?rev=74927&view=rev Log: Eliminate the static constructors and locks from DynamicLibrary.cpp. This fixes PR4512 and eliminating static ctors is always good. Losing thread safety is unfortunate, but the code is just incredibly poorly designed. If someone is interested, the "right" solution is to split DynamicLibrary.cpp into two separate pieces: a stateless piece in libsystem, and a simple support file in libsupport that has the "state" (e.g. AddSymbol) in managed static objects. Doing this would both fix memory leaks we already have, as well as make the code thread safe again. it would also make sense to move all the unix specific code in System/DynamicLibrary.cpp into System/Unix/DynamicLibrary.inc. Modified: llvm/trunk/include/llvm/System/DynamicLibrary.h llvm/trunk/lib/System/DynamicLibrary.cpp Modified: llvm/trunk/include/llvm/System/DynamicLibrary.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/DynamicLibrary.h?rev=74927&r1=74926&r2=74927&view=diff ============================================================================== --- llvm/trunk/include/llvm/System/DynamicLibrary.h (original) +++ llvm/trunk/include/llvm/System/DynamicLibrary.h Tue Jul 7 13:17:07 2009 @@ -36,6 +36,9 @@ /// and will only be unloaded when the program terminates. This returns /// false on success or returns true and fills in *ErrMsg on failure. /// @brief Open a dynamic library permanently. + /// + /// NOTE: This function is not thread safe. + /// static bool LoadLibraryPermanently(const char *filename, std::string *ErrMsg = 0); @@ -46,9 +49,15 @@ /// as ephemerally loaded libraries (constructors). /// @throws std::string on error. /// @brief Search through libraries for address of a symbol + /// + /// NOTE: This function is not thread safe. + /// static void *SearchForAddressOfSymbol(const char *symbolName); /// @brief Convenience function for C++ophiles. + /// + /// NOTE: This function is not thread safe. + /// static void *SearchForAddressOfSymbol(const std::string &symbolName) { return SearchForAddressOfSymbol(symbolName.c_str()); } @@ -57,9 +66,15 @@ /// value \p symbolValue. These symbols are searched before any /// libraries. /// @brief Add searchable symbol/value pair. + /// + /// NOTE: This function is not thread safe. + /// static void AddSymbol(const char *symbolName, void *symbolValue); /// @brief Convenience function for C++ophiles. + /// + /// NOTE: This function is not thread safe. + /// static void AddSymbol(const std::string &symbolName, void *symbolValue) { AddSymbol(symbolName.c_str(), symbolValue); } Modified: llvm/trunk/lib/System/DynamicLibrary.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/DynamicLibrary.cpp?rev=74927&r1=74926&r2=74927&view=diff ============================================================================== --- llvm/trunk/lib/System/DynamicLibrary.cpp (original) +++ llvm/trunk/lib/System/DynamicLibrary.cpp Tue Jul 7 13:17:07 2009 @@ -9,11 +9,13 @@ // // This header file implements the operating system DynamicLibrary concept. // +// FIXME: This file leaks the ExplicitSymbols and OpenedHandles vector, and is +// not thread safe! +// //===----------------------------------------------------------------------===// #include "llvm/System/DynamicLibrary.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/System/RWMutex.h" #include "llvm/Config/config.h" #include #include @@ -21,13 +23,13 @@ #include // Collection of symbol name/value pairs to be searched prior to any libraries. -static std::map symbols; -static llvm::sys::SmartRWMutex SymbolsLock; +static std::map *ExplicitSymbols = 0; void llvm::sys::DynamicLibrary::AddSymbol(const char* symbolName, void *symbolValue) { - llvm::sys::SmartScopedWriter Writer(&SymbolsLock); - symbols[symbolName] = symbolValue; + if (ExplicitSymbols == 0) + ExplicitSymbols = new std::map(); + (*ExplicitSymbols)[symbolName] = symbolValue; } #ifdef LLVM_ON_WIN32 @@ -37,7 +39,6 @@ #else #include -#include using namespace llvm; using namespace llvm::sys; @@ -46,44 +47,44 @@ //=== independent code. //===----------------------------------------------------------------------===// -static std::vector OpenedHandles; +static std::vector *OpenedHandles = 0; bool DynamicLibrary::LoadLibraryPermanently(const char *Filename, std::string *ErrMsg) { - SmartScopedWriter Writer(&SymbolsLock); void *H = dlopen(Filename, RTLD_LAZY|RTLD_GLOBAL); if (H == 0) { - if (ErrMsg) - *ErrMsg = dlerror(); + if (ErrMsg) *ErrMsg = dlerror(); return true; } - OpenedHandles.push_back(H); + if (OpenedHandles == 0) + OpenedHandles = new std::vector(); + OpenedHandles->push_back(H); return false; } void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) { // First check symbols added via AddSymbol(). - SymbolsLock.reader_acquire(); - std::map::iterator I = symbols.find(symbolName); - std::map::iterator E = symbols.end(); - SymbolsLock.reader_release(); + if (ExplicitSymbols) { + std::map::iterator I = + ExplicitSymbols->find(symbolName); + std::map::iterator E = ExplicitSymbols->end(); - if (I != E) - return I->second; + if (I != E) + return I->second; + } - SymbolsLock.writer_acquire(); // Now search the libraries. - for (std::vector::iterator I = OpenedHandles.begin(), - E = OpenedHandles.end(); I != E; ++I) { - //lt_ptr ptr = lt_dlsym(*I, symbolName); - void *ptr = dlsym(*I, symbolName); - if (ptr) { - SymbolsLock.writer_release(); - return ptr; + if (OpenedHandles) { + for (std::vector::iterator I = OpenedHandles->begin(), + E = OpenedHandles->end(); I != E; ++I) { + //lt_ptr ptr = lt_dlsym(*I, symbolName); + void *ptr = dlsym(*I, symbolName); + if (ptr) { + return ptr; + } } } - SymbolsLock.writer_release(); #define EXPLICIT_SYMBOL(SYM) \ extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM From isanbard at gmail.com Tue Jul 7 13:21:34 2009 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 07 Jul 2009 18:21:34 -0000 Subject: [llvm-commits] [llvm] r74928 - /llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Message-ID: <200907071821.n67ILZoK024535@zion.cs.uiuc.edu> Author: void Date: Tue Jul 7 13:21:19 2009 New Revision: 74928 URL: http://llvm.org/viewvc/llvm-project?rev=74928&view=rev Log: Remove unused parameter. Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=74928&r1=74927&r2=74928&view=diff ============================================================================== --- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original) +++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Tue Jul 7 13:21:19 2009 @@ -282,8 +282,8 @@ /// the JIT. See JITEventListener.h for more details. Does not /// take ownership of the argument. The argument may be NULL, in /// which case these functions do nothing. - virtual void RegisterJITEventListener(JITEventListener *L) {} - virtual void UnregisterJITEventListener(JITEventListener *L) {} + virtual void RegisterJITEventListener(JITEventListener *) {} + virtual void UnregisterJITEventListener(JITEventListener *) {} /// DisableLazyCompilation - If called, the JIT will abort if lazy compilation /// is ever attempted. From sabre at nondot.org Tue Jul 7 13:28:30 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 18:28:30 -0000 Subject: [llvm-commits] [llvm] r74929 - /llvm/trunk/include/llvm/CodeGen/BinaryObject.h Message-ID: <200907071828.n67ISaxY024878@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 13:28:00 2009 New Revision: 74929 URL: http://llvm.org/viewvc/llvm-project?rev=74929&view=rev Log: "BinaryObject.h was implicitly converting between uint{16,32,64}_t to uint8_t (via 'foo & 255'), i replaced this with an explicit (uint8_t) cast which is equivalent, faster and more correct (silences type-related warnings). Also, following coding standards I replaced post-increment with pre-increment." Patch by Ryan Flynn! Modified: llvm/trunk/include/llvm/CodeGen/BinaryObject.h Modified: llvm/trunk/include/llvm/CodeGen/BinaryObject.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/BinaryObject.h?rev=74929&r1=74928&r2=74929&view=diff ============================================================================== --- llvm/trunk/include/llvm/CodeGen/BinaryObject.h (original) +++ llvm/trunk/include/llvm/CodeGen/BinaryObject.h Tue Jul 7 13:28:00 2009 @@ -86,15 +86,15 @@ /// emitWord16LE - This callback is invoked when a 16-bit word needs to be /// written to the data stream in correct endian format and correct size. inline void emitWord16LE(uint16_t W) { - Data.push_back((W >> 0) & 255); - Data.push_back((W >> 8) & 255); + Data.push_back((uint8_t)(W >> 0)); + Data.push_back((uint8_t)(W >> 8)); } /// emitWord16BE - This callback is invoked when a 16-bit word needs to be /// written to the data stream in correct endian format and correct size. inline void emitWord16BE(uint16_t W) { - Data.push_back((W >> 8) & 255); - Data.push_back((W >> 0) & 255); + Data.push_back((uint8_t)(W >> 8)); + Data.push_back((uint8_t)(W >> 0)); } /// emitWord - This callback is invoked when a word needs to be @@ -127,46 +127,46 @@ /// emitWordLE - This callback is invoked when a 32-bit word needs to be /// written to the data stream in little-endian format. inline void emitWordLE(uint32_t W) { - Data.push_back((W >> 0) & 255); - Data.push_back((W >> 8) & 255); - Data.push_back((W >> 16) & 255); - Data.push_back((W >> 24) & 255); + Data.push_back((uint8_t)(W >> 0)); + Data.push_back((uint8_t)(W >> 8)); + Data.push_back((uint8_t)(W >> 16)); + Data.push_back((uint8_t)(W >> 24)); } /// emitWordBE - This callback is invoked when a 32-bit word needs to be /// written to the data stream in big-endian format. /// inline void emitWordBE(uint32_t W) { - Data.push_back((W >> 24) & 255); - Data.push_back((W >> 16) & 255); - Data.push_back((W >> 8) & 255); - Data.push_back((W >> 0) & 255); + Data.push_back((uint8_t)(W >> 24)); + Data.push_back((uint8_t)(W >> 16)); + Data.push_back((uint8_t)(W >> 8)); + Data.push_back((uint8_t)(W >> 0)); } /// emitDWordLE - This callback is invoked when a 64-bit word needs to be /// written to the data stream in little-endian format. inline void emitDWordLE(uint64_t W) { - Data.push_back((W >> 0) & 255); - Data.push_back((W >> 8) & 255); - Data.push_back((W >> 16) & 255); - Data.push_back((W >> 24) & 255); - Data.push_back((W >> 32) & 255); - Data.push_back((W >> 40) & 255); - Data.push_back((W >> 48) & 255); - Data.push_back((W >> 56) & 255); + Data.push_back((uint8_t)(W >> 0)); + Data.push_back((uint8_t)(W >> 8)); + Data.push_back((uint8_t)(W >> 16)); + Data.push_back((uint8_t)(W >> 24)); + Data.push_back((uint8_t)(W >> 32)); + Data.push_back((uint8_t)(W >> 40)); + Data.push_back((uint8_t)(W >> 48)); + Data.push_back((uint8_t)(W >> 56)); } /// emitDWordBE - This callback is invoked when a 64-bit word needs to be /// written to the data stream in big-endian format. inline void emitDWordBE(uint64_t W) { - Data.push_back((W >> 56) & 255); - Data.push_back((W >> 48) & 255); - Data.push_back((W >> 40) & 255); - Data.push_back((W >> 32) & 255); - Data.push_back((W >> 24) & 255); - Data.push_back((W >> 16) & 255); - Data.push_back((W >> 8) & 255); - Data.push_back((W >> 0) & 255); + Data.push_back((uint8_t)(W >> 56)); + Data.push_back((uint8_t)(W >> 48)); + Data.push_back((uint8_t)(W >> 40)); + Data.push_back((uint8_t)(W >> 32)); + Data.push_back((uint8_t)(W >> 24)); + Data.push_back((uint8_t)(W >> 16)); + Data.push_back((uint8_t)(W >> 8)); + Data.push_back((uint8_t)(W >> 0)); } /// fixByte - This callback is invoked when a byte needs to be @@ -187,15 +187,15 @@ /// emitWord16LE - This callback is invoked when a 16-bit word needs to /// fixup the data stream in little endian format. inline void fixWord16LE(uint16_t W, uint32_t offset) { - Data[offset++] = W & 255; - Data[offset] = (W >> 8) & 255; + Data[offset] = (uint8_t)(W >> 0); + Data[++offset] = (uint8_t)(W >> 8); } /// fixWord16BE - This callback is invoked when a 16-bit word needs to /// fixup data stream in big endian format. inline void fixWord16BE(uint16_t W, uint32_t offset) { - Data[offset++] = (W >> 8) & 255; - Data[offset] = W & 255; + Data[offset] = (uint8_t)(W >> 8); + Data[++offset] = (uint8_t)(W >> 0); } /// emitWord - This callback is invoked when a word needs to @@ -219,19 +219,19 @@ /// fixWord32LE - This callback is invoked when a 32-bit word needs to /// fixup the data in little endian format. inline void fixWord32LE(uint32_t W, uint32_t offset) { - Data[offset++] = W & 255; - Data[offset++] = (W >> 8) & 255; - Data[offset++] = (W >> 16) & 255; - Data[offset] = (W >> 24) & 255; + Data[offset] = (uint8_t)(W >> 0); + Data[++offset] = (uint8_t)(W >> 8); + Data[++offset] = (uint8_t)(W >> 16); + Data[++offset] = (uint8_t)(W >> 24); } /// fixWord32BE - This callback is invoked when a 32-bit word needs to /// fixup the data in big endian format. inline void fixWord32BE(uint32_t W, uint32_t offset) { - Data[offset++] = (W >> 24) & 255; - Data[offset++] = (W >> 16) & 255; - Data[offset++] = (W >> 8) & 255; - Data[offset] = W & 255; + Data[offset] = (uint8_t)(W >> 24); + Data[++offset] = (uint8_t)(W >> 16); + Data[++offset] = (uint8_t)(W >> 8); + Data[++offset] = (uint8_t)(W >> 0); } /// fixWord64 - This callback is invoked when a 64-bit word needs to @@ -246,27 +246,27 @@ /// fixWord64BE - This callback is invoked when a 64-bit word needs to /// fixup the data in little endian format. inline void fixWord64LE(uint64_t W, uint32_t offset) { - Data[offset++] = W & 255; - Data[offset++] = (W >> 8) & 255; - Data[offset++] = (W >> 16) & 255; - Data[offset++] = (W >> 24) & 255; - Data[offset++] = (W >> 32) & 255; - Data[offset++] = (W >> 40) & 255; - Data[offset++] = (W >> 48) & 255; - Data[offset] = (W >> 56) & 255; + Data[offset] = (uint8_t)(W >> 0); + Data[++offset] = (uint8_t)(W >> 8); + Data[++offset] = (uint8_t)(W >> 16); + Data[++offset] = (uint8_t)(W >> 24); + Data[++offset] = (uint8_t)(W >> 32); + Data[++offset] = (uint8_t)(W >> 40); + Data[++offset] = (uint8_t)(W >> 48); + Data[++offset] = (uint8_t)(W >> 56); } /// fixWord64BE - This callback is invoked when a 64-bit word needs to /// fixup the data in big endian format. inline void fixWord64BE(uint64_t W, uint32_t offset) { - Data[offset++] = (W >> 56) & 255; - Data[offset++] = (W >> 48) & 255; - Data[offset++] = (W >> 40) & 255; - Data[offset++] = (W >> 32) & 255; - Data[offset++] = (W >> 24) & 255; - Data[offset++] = (W >> 16) & 255; - Data[offset++] = (W >> 8) & 255; - Data[offset] = W & 255; + Data[offset] = (uint8_t)(W >> 56); + Data[++offset] = (uint8_t)(W >> 48); + Data[++offset] = (uint8_t)(W >> 40); + Data[++offset] = (uint8_t)(W >> 32); + Data[++offset] = (uint8_t)(W >> 24); + Data[++offset] = (uint8_t)(W >> 16); + Data[++offset] = (uint8_t)(W >> 8); + Data[++offset] = (uint8_t)(W >> 0); } /// emitAlignment - Pad the data to the specified alignment. @@ -281,7 +281,7 @@ /// written to the data stream. void emitULEB128Bytes(uint64_t Value) { do { - unsigned char Byte = Value & 0x7f; + uint8_t Byte = (uint8_t)(Value & 0x7f); Value >>= 7; if (Value) Byte |= 0x80; emitByte(Byte); @@ -295,7 +295,7 @@ bool IsMore; do { - unsigned char Byte = Value & 0x7f; + uint8_t Byte = (uint8_t)(Value & 0x7f); Value >>= 7; IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; if (IsMore) Byte |= 0x80; From clattner at apple.com Tue Jul 7 13:29:16 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 7 Jul 2009 11:29:16 -0700 Subject: [llvm-commits] patch: CodeGen/BinaryObject.h explicit typecast In-Reply-To: References: Message-ID: <3E60DC6A-8BF0-44E9-8239-4ED032C0A0AF@apple.com> On Jul 7, 2009, at 7:46 AM, Ryan Flynn wrote: > BinaryObject.h was implicitly converting between uint{16,32,64}_t to > uint8_t (via 'foo & 255'), i replaced this with an explicit (uint8_t) > cast which is equivalent, faster and more correct (silences > type-related warnings). Also, following coding standards I replaced > post-increment with pre-increment. Looks great, thanks! http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090706/080244.html -Chris From gohman at apple.com Tue Jul 7 13:30:22 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 7 Jul 2009 11:30:22 -0700 Subject: [llvm-commits] PATCH: remove VICmp and VFCmp. In-Reply-To: <7ABB6DFD-7F2E-4F31-A7D9-FC86362095E6@apple.com> References: <4A518899.80806@mxc.ca> <7ABB6DFD-7F2E-4F31-A7D9-FC86362095E6@apple.com> Message-ID: <05085D11-65C9-478A-B854-1EAC52FD9E42@apple.com> On Jul 6, 2009, at 10:10 AM, Chris Lattner wrote: > > On Jul 5, 2009, at 10:16 PM, Nick Lewycky wrote: > > >> This patch removes vicmp and vfcmp, which has the positive side that >> >> it fixes existing type-safety bugs and simplifies some code, but a >> >> downside in that it XFAILs 9 CodeGen tests. >> > > I haven't had a chance to look at the patch, but removing v[fi]cmp > will almost certainly break clang (which generates them for vector > comparisons in opencl/ext_vector mode). The right way to remove this > is to make codegen pattern match [fi]cmp+sext to the same nodes it is > using for v[fi]cmp, then change clang to generate [fi]cmp+sext instead > of v[if]cmp, then nuke v[fi]cmp. This way we won't loose any codegen > capability and clang will still build :). Vector [fi]cmp are not yet ready to replace v[fi]cmp, and there's more work required than just adding patterns. Work has been one to support vector [fi]cmp in the IR, however no work has been done to support it in CodeGen yet. Adding support in CodeGen will require a variety of fairly straight-forward changes, plus finding a solution for vectors of i1 in CodeGen. Here's a simple example: define <4 x float> @foo(<4 x float> %a, <4 x float> %b, <4 x float> %c, <4 x float> %d) { %y = fcmp olt <4 x float> %a, %b %z = select <4 x i1> %y, <4 x float> %c, <4 x float> %d ret <4 x float> %z } %y has type <4 x i1>. This is not a legal type on most current architectures. But, many architectures have ways of supporting this kind of code, often by putting the comparison result in a <4 x i32> register. The main twist is that a type like <4 x i1> might be legalized to either <4 x i32> or <4 x i64> on a target like x86, depending on the type of the comparison operands, so the current getTypeToTransformTo, which assumes that every type has a unique destination type, isn't sufficient. But this just needs some creativity. Dan From sabre at nondot.org Tue Jul 7 13:31:21 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 18:31:21 -0000 Subject: [llvm-commits] [llvm] r74930 - /llvm/trunk/tools/lli/lli.cpp Message-ID: <200907071831.n67IVQu7025026@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 13:31:09 2009 New Revision: 74930 URL: http://llvm.org/viewvc/llvm-project?rev=74930&view=rev Log: Fix lli to print an error and exit when EE returns null but no string. Patch by Eric Rannaud! Modified: llvm/trunk/tools/lli/lli.cpp Modified: llvm/trunk/tools/lli/lli.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=74930&r1=74929&r2=74930&view=diff ============================================================================== --- llvm/trunk/tools/lli/lli.cpp (original) +++ llvm/trunk/tools/lli/lli.cpp Tue Jul 7 13:31:09 2009 @@ -147,8 +147,11 @@ InitializeNativeTarget(); EE = ExecutionEngine::create(MP, ForceInterpreter, &ErrorMsg, OLvl); - if (!EE && !ErrorMsg.empty()) { - std::cerr << argv[0] << ":error creating EE: " << ErrorMsg << "\n"; + if (!EE) { + if (!ErrorMsg.empty()) + std::cerr << argv[0] << ": error creating EE: " << ErrorMsg << "\n"; + else + std::cerr << argv[0] << ": unknown error creating EE!\n"; exit(1); } From resistor at mac.com Tue Jul 7 13:33:05 2009 From: resistor at mac.com (Owen Anderson) Date: Tue, 07 Jul 2009 18:33:05 -0000 Subject: [llvm-commits] [llvm] r74931 - in /llvm/trunk: include/llvm/System/ lib/CodeGen/SelectionDAG/ lib/CompilerDriver/ lib/ExecutionEngine/Interpreter/ lib/Support/ lib/Target/ lib/VMCore/ Message-ID: <200907071833.n67IX975025096@zion.cs.uiuc.edu> Author: resistor Date: Tue Jul 7 13:33:04 2009 New Revision: 74931 URL: http://llvm.org/viewvc/llvm-project?rev=74931&view=rev Log: Have scoped mutexes take referenes instead of pointers. Modified: llvm/trunk/include/llvm/System/Mutex.h llvm/trunk/include/llvm/System/RWMutex.h llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp llvm/trunk/lib/CompilerDriver/Plugin.cpp llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp llvm/trunk/lib/Support/Annotation.cpp llvm/trunk/lib/Support/PluginLoader.cpp llvm/trunk/lib/Support/Statistic.cpp llvm/trunk/lib/Support/Timer.cpp llvm/trunk/lib/Target/TargetData.cpp llvm/trunk/lib/VMCore/Constants.cpp llvm/trunk/lib/VMCore/Function.cpp llvm/trunk/lib/VMCore/LeakDetector.cpp llvm/trunk/lib/VMCore/Pass.cpp llvm/trunk/lib/VMCore/PassManager.cpp llvm/trunk/lib/VMCore/Type.cpp llvm/trunk/lib/VMCore/TypeSymbolTable.cpp llvm/trunk/lib/VMCore/Value.cpp Modified: llvm/trunk/include/llvm/System/Mutex.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Mutex.h?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/include/llvm/System/Mutex.h (original) +++ llvm/trunk/include/llvm/System/Mutex.h Tue Jul 7 13:33:04 2009 @@ -131,15 +131,15 @@ template class SmartScopedLock { - SmartMutex* mtx; + SmartMutex& mtx; public: - SmartScopedLock(SmartMutex* m) : mtx(m) { - mtx->acquire(); + SmartScopedLock(SmartMutex& m) : mtx(m) { + mtx.acquire(); } ~SmartScopedLock() { - mtx->release(); + mtx.release(); } }; Modified: llvm/trunk/include/llvm/System/RWMutex.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/RWMutex.h?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/include/llvm/System/RWMutex.h (original) +++ llvm/trunk/include/llvm/System/RWMutex.h Tue Jul 7 13:33:04 2009 @@ -141,15 +141,14 @@ /// ScopedReader - RAII acquisition of a reader lock template struct SmartScopedReader { - SmartRWMutex* mutex; + SmartRWMutex& mutex; - explicit SmartScopedReader(SmartRWMutex* m) { - mutex = m; - mutex->reader_acquire(); + explicit SmartScopedReader(SmartRWMutex& m) : mutex(m) { + mutex.reader_acquire(); } ~SmartScopedReader() { - mutex->reader_release(); + mutex.reader_release(); } }; typedef SmartScopedReader ScopedReader; @@ -157,15 +156,14 @@ /// ScopedWriter - RAII acquisition of a writer lock template struct SmartScopedWriter { - SmartRWMutex* mutex; + SmartRWMutex& mutex; - explicit SmartScopedWriter(SmartRWMutex* m) { - mutex = m; - mutex->writer_acquire(); + explicit SmartScopedWriter(SmartRWMutex& m) : mutex(m) { + mutex.writer_acquire(); } ~SmartScopedWriter() { - mutex->writer_release(); + mutex.writer_release(); } }; typedef SmartScopedWriter ScopedWriter; Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Jul 7 13:33:04 2009 @@ -5010,7 +5010,7 @@ /// getValueTypeList - Return a pointer to the specified value type. /// const MVT *SDNode::getValueTypeList(MVT VT) { - sys::SmartScopedLock Lock(&*VTMutex); + sys::SmartScopedLock Lock(*VTMutex); if (VT.isExtended()) { return &(*EVTs->insert(VT).first); } else { Modified: llvm/trunk/lib/CompilerDriver/Plugin.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/Plugin.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/CompilerDriver/Plugin.cpp (original) +++ llvm/trunk/lib/CompilerDriver/Plugin.cpp Tue Jul 7 13:33:04 2009 @@ -42,7 +42,7 @@ namespace llvmc { PluginLoader::PluginLoader() { - llvm::sys::SmartScopedLock Lock(&*PluginMutex); + llvm::sys::SmartScopedLock Lock(*PluginMutex); if (!pluginListInitialized) { for (PluginRegistry::iterator B = PluginRegistry::begin(), E = PluginRegistry::end(); B != E; ++B) @@ -53,7 +53,7 @@ } PluginLoader::~PluginLoader() { - llvm::sys::SmartScopedLock Lock(&*PluginMutex); + llvm::sys::SmartScopedLock Lock(*PluginMutex); if (pluginListInitialized) { for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); B != E; ++B) @@ -63,14 +63,14 @@ } void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) { - llvm::sys::SmartScopedLock Lock(&*PluginMutex); + llvm::sys::SmartScopedLock Lock(*PluginMutex); for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); B != E; ++B) (*B)->PopulateLanguageMap(langMap); } void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) { - llvm::sys::SmartScopedLock Lock(&*PluginMutex); + llvm::sys::SmartScopedLock Lock(*PluginMutex); for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); B != E; ++B) (*B)->PopulateCompilationGraph(graph); Modified: llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp (original) +++ llvm/trunk/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Tue Jul 7 13:33:04 2009 @@ -97,7 +97,7 @@ ExtName += getTypeID(FT->getContainedType(i)); ExtName += "_" + F->getName(); - sys::ScopedLock Writer(&*FunctionsLock); + sys::ScopedLock Writer(*FunctionsLock); ExFunc FnPtr = FuncNames[ExtName]; if (FnPtr == 0) FnPtr = FuncNames["lle_X_"+F->getName()]; @@ -539,7 +539,7 @@ void Interpreter::initializeExternalFunctions() { - sys::ScopedLock Writer(&*FunctionsLock); + sys::ScopedLock Writer(*FunctionsLock); FuncNames["lle_X_atexit"] = lle_X_atexit; FuncNames["lle_X_exit"] = lle_X_exit; FuncNames["lle_X_abort"] = lle_X_abort; Modified: llvm/trunk/lib/Support/Annotation.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Annotation.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/Support/Annotation.cpp (original) +++ llvm/trunk/lib/Support/Annotation.cpp Tue Jul 7 13:33:04 2009 @@ -55,7 +55,7 @@ } static void eraseFromFactMap(unsigned ID) { - sys::SmartScopedWriter Writer(&*AnnotationsLock); + sys::SmartScopedWriter Writer(*AnnotationsLock); TheFactMap->erase(ID); } @@ -66,7 +66,7 @@ AnnotationsLock->reader_release(); if (I == E) { - sys::SmartScopedWriter Writer(&*AnnotationsLock); + sys::SmartScopedWriter Writer(*AnnotationsLock); I = IDMap->find(Name); if (I == IDMap->end()) { unsigned newCount = sys::AtomicIncrement(&IDCounter); @@ -91,7 +91,7 @@ // only be used for debugging. // const char *AnnotationManager::getName(AnnotationID ID) { // ID -> Name - sys::SmartScopedReader Reader(&*AnnotationsLock); + sys::SmartScopedReader Reader(*AnnotationsLock); IDMapType &TheMap = *IDMap; for (IDMapType::iterator I = TheMap.begin(); ; ++I) { assert(I != TheMap.end() && "Annotation ID is unknown!"); @@ -106,7 +106,7 @@ void AnnotationManager::registerAnnotationFactory(AnnotationID ID, AnnFactory F, void *ExtraData) { if (F) { - sys::SmartScopedWriter Writer(&*AnnotationsLock); + sys::SmartScopedWriter Writer(*AnnotationsLock); getFactMap()[ID.ID] = std::make_pair(F, ExtraData); } else { eraseFromFactMap(ID.ID); Modified: llvm/trunk/lib/Support/PluginLoader.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PluginLoader.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/Support/PluginLoader.cpp (original) +++ llvm/trunk/lib/Support/PluginLoader.cpp Tue Jul 7 13:33:04 2009 @@ -25,7 +25,7 @@ static ManagedStatic > PluginsLock; void PluginLoader::operator=(const std::string &Filename) { - sys::SmartScopedLock Lock(&*PluginsLock); + sys::SmartScopedLock Lock(*PluginsLock); std::string Error; if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) { cerr << "Error opening '" << Filename << "': " << Error @@ -36,12 +36,12 @@ } unsigned PluginLoader::getNumPlugins() { - sys::SmartScopedLock Lock(&*PluginsLock); + sys::SmartScopedLock Lock(*PluginsLock); return Plugins.isConstructed() ? Plugins->size() : 0; } std::string &PluginLoader::getPlugin(unsigned num) { - sys::SmartScopedLock Lock(&*PluginsLock); + sys::SmartScopedLock Lock(*PluginsLock); assert(Plugins.isConstructed() && num < Plugins->size() && "Asking for an out of bounds plugin"); return (*Plugins)[num]; Modified: llvm/trunk/lib/Support/Statistic.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Statistic.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/Support/Statistic.cpp (original) +++ llvm/trunk/lib/Support/Statistic.cpp Tue Jul 7 13:33:04 2009 @@ -65,7 +65,7 @@ void Statistic::RegisterStatistic() { // If stats are enabled, inform StatInfo that this statistic should be // printed. - sys::ScopedLock Writer(&*StatLock); + sys::ScopedLock Writer(*StatLock); if (!Initialized) { if (Enabled) StatInfo->addStatistic(this); Modified: llvm/trunk/lib/Support/Timer.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/Support/Timer.cpp (original) +++ llvm/trunk/lib/Support/Timer.cpp Tue Jul 7 13:33:04 2009 @@ -145,7 +145,7 @@ static ManagedStatic > ActiveTimers; void Timer::startTimer() { - sys::SmartScopedLock L(&Lock); + sys::SmartScopedLock L(Lock); Started = true; ActiveTimers->push_back(this); TimeRecord TR = getTimeRecord(true); @@ -157,7 +157,7 @@ } void Timer::stopTimer() { - sys::SmartScopedLock L(&Lock); + sys::SmartScopedLock L(Lock); TimeRecord TR = getTimeRecord(false); Elapsed += TR.Elapsed; UserTime += TR.UserTime; @@ -229,7 +229,7 @@ static ManagedStatic NamedGroupedTimers; static Timer &getNamedRegionTimer(const std::string &Name) { - sys::SmartScopedLock L(&*TimerLock); + sys::SmartScopedLock L(*TimerLock); Name2Timer::iterator I = NamedTimers->find(Name); if (I != NamedTimers->end()) return I->second; @@ -239,7 +239,7 @@ static Timer &getNamedRegionTimer(const std::string &Name, const std::string &GroupName) { - sys::SmartScopedLock L(&*TimerLock); + sys::SmartScopedLock L(*TimerLock); Name2Pair::iterator I = NamedGroupedTimers->find(GroupName); if (I == NamedGroupedTimers->end()) { @@ -365,7 +365,7 @@ void TimerGroup::removeTimer() { - sys::SmartScopedLock L(&*TimerLock); + sys::SmartScopedLock L(*TimerLock); if (--NumTimers == 0 && !TimersToPrint.empty()) { // Print timing report... // Sort the timers in descending order by amount of time taken... std::sort(TimersToPrint.begin(), TimersToPrint.end(), @@ -434,12 +434,12 @@ } void TimerGroup::addTimer() { - sys::SmartScopedLock L(&*TimerLock); + sys::SmartScopedLock L(*TimerLock); ++NumTimers; } void TimerGroup::addTimerToPrint(const Timer &T) { - sys::SmartScopedLock L(&*TimerLock); + sys::SmartScopedLock L(*TimerLock); TimersToPrint.push_back(Timer(true, T)); } Modified: llvm/trunk/lib/Target/TargetData.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetData.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/Target/TargetData.cpp (original) +++ llvm/trunk/lib/Target/TargetData.cpp Tue Jul 7 13:33:04 2009 @@ -352,7 +352,7 @@ if (!LayoutInfo.isConstructed()) return; - sys::SmartScopedLock Lock(&*LayoutLock); + sys::SmartScopedLock Lock(*LayoutLock); // Remove any layouts for this TD. LayoutInfoTy &TheMap = *LayoutInfo; for (LayoutInfoTy::iterator I = TheMap.begin(), E = TheMap.end(); I != E; ) { @@ -369,7 +369,7 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const { LayoutInfoTy &TheMap = *LayoutInfo; - sys::SmartScopedLock Lock(&*LayoutLock); + sys::SmartScopedLock Lock(*LayoutLock); StructLayout *&SL = TheMap[LayoutKey(this, Ty)]; if (SL) return SL; @@ -394,7 +394,7 @@ void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const { if (!LayoutInfo.isConstructed()) return; // No cache. - sys::SmartScopedLock Lock(&*LayoutLock); + sys::SmartScopedLock Lock(*LayoutLock); LayoutInfoTy::iterator I = LayoutInfo->find(LayoutKey(this, Ty)); if (I == LayoutInfo->end()) return; Modified: llvm/trunk/lib/VMCore/Constants.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Constants.cpp (original) +++ llvm/trunk/lib/VMCore/Constants.cpp Tue Jul 7 13:33:04 2009 @@ -307,7 +307,7 @@ ConstantsLock->reader_release(); if (!Slot) { - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); ConstantInt *&NewSlot = (*IntConstants)[Key]; if (!Slot) { NewSlot = new ConstantInt(ITy, V); @@ -414,7 +414,7 @@ ConstantsLock->reader_release(); if (!Slot) { - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); ConstantFP *&NewSlot = (*FPConstants)[Key]; if (!NewSlot) { const Type *Ty; @@ -1231,7 +1231,7 @@ /// getOrCreate - Return the specified constant from the map, creating it if /// necessary. ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) { - sys::SmartScopedLock Lock(&ValueMapLock); + sys::SmartScopedLock Lock(ValueMapLock); MapKey Lookup(Ty, V); ConstantClass* Result = 0; @@ -1249,7 +1249,7 @@ } void remove(ConstantClass *CP) { - sys::SmartScopedLock Lock(&ValueMapLock); + sys::SmartScopedLock Lock(ValueMapLock); typename MapTy::iterator I = FindExistingElement(CP); assert(I != Map.end() && "Constant not found in constant table!"); assert(I->second == CP && "Didn't find correct element?"); @@ -1334,7 +1334,7 @@ } void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) { - sys::SmartScopedLock Lock(&ValueMapLock); + sys::SmartScopedLock Lock(ValueMapLock); typename AbstractTypeMapTy::iterator I = AbstractTypeMap.find(cast(OldTy)); @@ -1793,7 +1793,7 @@ static ManagedStatic > MDStringCache; MDString *MDString::get(const char *StrBegin, const char *StrEnd) { - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); StringMapEntry &Entry = MDStringCache->GetOrCreateValue( StrBegin, StrEnd); MDString *&S = Entry.getValue(); @@ -1804,7 +1804,7 @@ } MDString *MDString::get(const std::string &Str) { - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); StringMapEntry &Entry = MDStringCache->GetOrCreateValue( Str.data(), Str.data() + Str.size()); MDString *&S = Entry.getValue(); @@ -1815,7 +1815,7 @@ } void MDString::destroyConstant() { - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd)); destroyConstantImpl(); } @@ -1847,7 +1847,7 @@ ConstantsLock->reader_release(); if (!N) { - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint); if (!N) { // InsertPoint will have been set by the FindNodeOrInsertPos call. @@ -1859,7 +1859,7 @@ } void MDNode::destroyConstant() { - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); MDNodeSet->RemoveNode(this); destroyConstantImpl(); @@ -2790,7 +2790,7 @@ Replacement = ConstantAggregateZero::get(getType()); } else { // Check to see if we have this array type already. - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); bool Exists; ArrayConstantsTy::MapTy::iterator I = ArrayConstants->InsertOrGetItem(Lookup, Exists); @@ -2866,7 +2866,7 @@ Replacement = ConstantAggregateZero::get(getType()); } else { // Check to see if we have this array type already. - sys::SmartScopedWriter Writer(&*ConstantsLock); + sys::SmartScopedWriter Writer(*ConstantsLock); bool Exists; StructConstantsTy::MapTy::iterator I = StructConstants->InsertOrGetItem(Lookup, Exists); Modified: llvm/trunk/lib/VMCore/Function.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Function.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Function.cpp (original) +++ llvm/trunk/lib/VMCore/Function.cpp Tue Jul 7 13:33:04 2009 @@ -242,18 +242,18 @@ static ManagedStatic > GCLock; bool Function::hasGC() const { - sys::SmartScopedReader Reader(&*GCLock); + sys::SmartScopedReader Reader(*GCLock); return GCNames && GCNames->count(this); } const char *Function::getGC() const { assert(hasGC() && "Function has no collector"); - sys::SmartScopedReader Reader(&*GCLock); + sys::SmartScopedReader Reader(*GCLock); return *(*GCNames)[this]; } void Function::setGC(const char *Str) { - sys::SmartScopedWriter Writer(&*GCLock); + sys::SmartScopedWriter Writer(*GCLock); if (!GCNamePool) GCNamePool = new StringPool(); if (!GCNames) @@ -262,7 +262,7 @@ } void Function::clearGC() { - sys::SmartScopedWriter Writer(&*GCLock); + sys::SmartScopedWriter Writer(*GCLock); if (GCNames) { GCNames->erase(this); if (GCNames->empty()) { Modified: llvm/trunk/lib/VMCore/LeakDetector.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LeakDetector.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/LeakDetector.cpp (original) +++ llvm/trunk/lib/VMCore/LeakDetector.cpp Tue Jul 7 13:33:04 2009 @@ -54,7 +54,7 @@ // immediately, it is added to the CachedValue Value. If it is // immediately removed, no set search need be performed. void addGarbage(const T* o) { - sys::SmartScopedWriter Writer(&*LeakDetectorLock); + sys::SmartScopedWriter Writer(*LeakDetectorLock); if (Cache) { assert(Ts.count(Cache) == 0 && "Object already in set!"); Ts.insert(Cache); @@ -63,7 +63,7 @@ } void removeGarbage(const T* o) { - sys::SmartScopedWriter Writer(&*LeakDetectorLock); + sys::SmartScopedWriter Writer(*LeakDetectorLock); if (o == Cache) Cache = 0; // Cache hit else @@ -73,7 +73,7 @@ bool hasGarbage(const std::string& Message) { addGarbage(0); // Flush the Cache - sys::SmartScopedReader Reader(&*LeakDetectorLock); + sys::SmartScopedReader Reader(*LeakDetectorLock); assert(Cache == 0 && "No value should be cached anymore!"); if (!Ts.empty()) { Modified: llvm/trunk/lib/VMCore/Pass.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Pass.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Pass.cpp (original) +++ llvm/trunk/lib/VMCore/Pass.cpp Tue Jul 7 13:33:04 2009 @@ -233,7 +233,7 @@ getPassRegistrar()->RegisterPass(*this); // Notify any listeners. - sys::SmartScopedLock Lock(&ListenersLock); + sys::SmartScopedLock Lock(ListenersLock); if (Listeners) for (std::vector::iterator I = Listeners->begin(), E = Listeners->end(); I != E; ++I) @@ -286,14 +286,14 @@ // PassRegistrationListener ctor - Add the current object to the list of // PassRegistrationListeners... PassRegistrationListener::PassRegistrationListener() { - sys::SmartScopedLock Lock(&ListenersLock); + sys::SmartScopedLock Lock(ListenersLock); if (!Listeners) Listeners = new std::vector(); Listeners->push_back(this); } // dtor - Remove object from list of listeners... PassRegistrationListener::~PassRegistrationListener() { - sys::SmartScopedLock Lock(&ListenersLock); + sys::SmartScopedLock Lock(ListenersLock); std::vector::iterator I = std::find(Listeners->begin(), Listeners->end(), this); assert(Listeners && I != Listeners->end() && Modified: llvm/trunk/lib/VMCore/PassManager.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassManager.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/PassManager.cpp (original) +++ llvm/trunk/lib/VMCore/PassManager.cpp Tue Jul 7 13:33:04 2009 @@ -392,7 +392,7 @@ if (dynamic_cast(P)) return; - sys::SmartScopedLock Lock(&*TimingInfoMutex); + sys::SmartScopedLock Lock(*TimingInfoMutex); std::map::iterator I = TimingData.find(P); if (I == TimingData.end()) I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first; @@ -403,7 +403,7 @@ if (dynamic_cast(P)) return; - sys::SmartScopedLock Lock(&*TimingInfoMutex); + sys::SmartScopedLock Lock(*TimingInfoMutex); std::map::iterator I = TimingData.find(P); assert(I != TimingData.end() && "passStarted/passEnded not nested right!"); I->second.stopTimer(); Modified: llvm/trunk/lib/VMCore/Type.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Type.cpp (original) +++ llvm/trunk/lib/VMCore/Type.cpp Tue Jul 7 13:33:04 2009 @@ -1006,7 +1006,7 @@ // First, see if the type is already in the table, for which // a reader lock suffices. - sys::SmartScopedLock L(&*TypeMapLock); + sys::SmartScopedLock L(*TypeMapLock); ITy = IntegerTypes->get(IVT); if (!ITy) { @@ -1079,7 +1079,7 @@ FunctionValType VT(ReturnType, Params, isVarArg); FunctionType *FT = 0; - sys::SmartScopedLock L(&*TypeMapLock); + sys::SmartScopedLock L(*TypeMapLock); FT = FunctionTypes->get(VT); if (!FT) { @@ -1129,7 +1129,7 @@ ArrayValType AVT(ElementType, NumElements); ArrayType *AT = 0; - sys::SmartScopedLock L(&*TypeMapLock); + sys::SmartScopedLock L(*TypeMapLock); AT = ArrayTypes->get(AVT); if (!AT) { @@ -1188,7 +1188,7 @@ VectorValType PVT(ElementType, NumElements); VectorType *PT = 0; - sys::SmartScopedLock L(&*TypeMapLock); + sys::SmartScopedLock L(*TypeMapLock); PT = VectorTypes->get(PVT); if (!PT) { @@ -1250,7 +1250,7 @@ StructValType STV(ETypes, isPacked); StructType *ST = 0; - sys::SmartScopedLock L(&*TypeMapLock); + sys::SmartScopedLock L(*TypeMapLock); ST = StructTypes->get(STV); if (!ST) { @@ -1329,7 +1329,7 @@ PointerType *PT = 0; - sys::SmartScopedLock L(&*TypeMapLock); + sys::SmartScopedLock L(*TypeMapLock); PT = PointerTypes->get(PVT); if (!PT) { @@ -1488,7 +1488,7 @@ void DerivedType::refineAbstractTypeTo(const Type *NewType) { // All recursive calls will go through unlockedRefineAbstractTypeTo, // to avoid deadlock problems. - sys::SmartScopedLock L(&*TypeMapLock); + sys::SmartScopedLock L(*TypeMapLock); unlockedRefineAbstractTypeTo(NewType); } Modified: llvm/trunk/lib/VMCore/TypeSymbolTable.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/TypeSymbolTable.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/TypeSymbolTable.cpp (original) +++ llvm/trunk/lib/VMCore/TypeSymbolTable.cpp Tue Jul 7 13:33:04 2009 @@ -37,7 +37,7 @@ std::string TypeSymbolTable::getUniqueName(const std::string &BaseName) const { std::string TryName = BaseName; - sys::SmartScopedReader Reader(&*TypeSymbolTableLock); + sys::SmartScopedReader Reader(*TypeSymbolTableLock); const_iterator End = tmap.end(); @@ -49,7 +49,7 @@ // lookup a type by name - returns null on failure Type* TypeSymbolTable::lookup(const std::string& Name) const { - sys::SmartScopedReader Reader(&*TypeSymbolTableLock); + sys::SmartScopedReader Reader(*TypeSymbolTableLock); const_iterator TI = tmap.find(Name); Type* result = 0; @@ -134,7 +134,7 @@ // This function is called when one of the types in the type plane are refined void TypeSymbolTable::refineAbstractType(const DerivedType *OldType, const Type *NewType) { - sys::SmartScopedReader Reader(&*TypeSymbolTableLock); + sys::SmartScopedReader Reader(*TypeSymbolTableLock); // Loop over all of the types in the symbol table, replacing any references // to OldType with references to NewType. Note that there may be multiple @@ -165,7 +165,7 @@ // Loop over all of the types in the symbol table, dropping any abstract // type user entries for AbsTy which occur because there are names for the // type. - sys::SmartScopedReader Reader(&*TypeSymbolTableLock); + sys::SmartScopedReader Reader(*TypeSymbolTableLock); for (iterator TI = begin(), TE = end(); TI != TE; ++TI) if (TI->second == const_cast(static_cast(AbsTy))) AbsTy->removeAbstractTypeUser(this); @@ -179,7 +179,7 @@ void TypeSymbolTable::dump() const { cerr << "TypeSymbolPlane: "; - sys::SmartScopedReader Reader(&*TypeSymbolTableLock); + sys::SmartScopedReader Reader(*TypeSymbolTableLock); for_each(tmap.begin(), tmap.end(), DumpTypes); } Modified: llvm/trunk/lib/VMCore/Value.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=74931&r1=74930&r2=74931&view=diff ============================================================================== --- llvm/trunk/lib/VMCore/Value.cpp (original) +++ llvm/trunk/lib/VMCore/Value.cpp Tue Jul 7 13:33:04 2009 @@ -430,7 +430,7 @@ if (VP->HasValueHandle) { // If this value already has a ValueHandle, then it must be in the // ValueHandles map already. - sys::SmartScopedReader Reader(&*ValueHandlesLock); + sys::SmartScopedReader Reader(*ValueHandlesLock); ValueHandleBase *&Entry = (*ValueHandles)[VP]; assert(Entry != 0 && "Value doesn't have any handles?"); AddToExistingUseList(&Entry); @@ -442,7 +442,7 @@ // reallocate itself, which would invalidate all of the PrevP pointers that // point into the old table. Handle this by checking for reallocation and // updating the stale pointers only if needed. - sys::SmartScopedWriter Writer(&*ValueHandlesLock); + sys::SmartScopedWriter Writer(*ValueHandlesLock); ValueHandlesTy &Handles = *ValueHandles; const void *OldBucketPtr = Handles.getPointerIntoBucketsArray(); @@ -484,7 +484,7 @@ // If the Next pointer was null, then it is possible that this was the last // ValueHandle watching VP. If so, delete its entry from the ValueHandles // map. - sys::SmartScopedWriter Writer(&*ValueHandlesLock); + sys::SmartScopedWriter Writer(*ValueHandlesLock); ValueHandlesTy &Handles = *ValueHandles; if (Handles.isPointerIntoBucketsArray(PrevPtr)) { Handles.erase(VP); From brukman at gmail.com Tue Jul 7 13:35:41 2009 From: brukman at gmail.com (Misha Brukman) Date: Tue, 7 Jul 2009 14:35:41 -0400 Subject: [llvm-commits] [llvm] r74929 - /llvm/trunk/include/llvm/CodeGen/BinaryObject.h In-Reply-To: <200907071828.n67ISaxY024878@zion.cs.uiuc.edu> References: <200907071828.n67ISaxY024878@zion.cs.uiuc.edu> Message-ID: 2009/7/7 Chris Lattner > - Data.push_back((W >> 0) & 255); > - Data.push_back((W >> 8) & 255); > + Data.push_back((uint8_t)(W >> 0)); > + Data.push_back((uint8_t)(W >> 8)); These are all C-style casts, rather than C++-style casts, e.g. static_cast(value) . Is there a preference for C-style casts in LLVM? I thought we were trying to stick with C++ here. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090707/537a8e7c/attachment.html From sabre at nondot.org Tue Jul 7 13:40:11 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 18:40:11 -0000 Subject: [llvm-commits] [llvm] r74932 - /llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Message-ID: <200907071840.n67IeHsG025328@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 13:39:49 2009 New Revision: 74932 URL: http://llvm.org/viewvc/llvm-project?rev=74932&view=rev Log: fix some type confusion in ReadVBR64: "Piece" should be only 32 bits, not 64, because we read at most 32 bits at a time. OTOH, "Result" must be 64-bits and insertion into it must be 64-bit clean. Thanks to Ivan Sorokin for bringing this up. Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=74932&r1=74931&r2=74932&view=diff ============================================================================== --- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original) +++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Tue Jul 7 13:39:49 2009 @@ -260,6 +260,7 @@ uint32_t Read(unsigned NumBits) { + assert(NumBits <= 32 && "Cannot return more than 32 bits!"); // If the field is fully contained by CurWord, return it quickly. if (BitsInCurWord >= NumBits) { uint32_t R = CurWord & ((1U << NumBits)-1); @@ -322,17 +323,19 @@ } } + // ReadVBR64 - Read a VBR that may have a value up to 64-bits in size. The + // chunk size of the VBR must still be <= 32 bits though. uint64_t ReadVBR64(unsigned NumBits) { - uint64_t Piece = Read(NumBits); - if ((Piece & (uint64_t(1) << (NumBits-1))) == 0) - return Piece; + uint32_t Piece = Read(NumBits); + if ((Piece & (1U << (NumBits-1))) == 0) + return uint64_t(Piece); uint64_t Result = 0; unsigned NextBit = 0; while (1) { - Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit; + Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit; - if ((Piece & (uint64_t(1) << (NumBits-1))) == 0) + if ((Piece & (1U << (NumBits-1))) == 0) return Result; NextBit += NumBits-1; From sabre at nondot.org Tue Jul 7 13:43:49 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 18:43:49 -0000 Subject: [llvm-commits] [llvm] r74933 - /llvm/trunk/include/llvm/ADT/PostOrderIterator.h Message-ID: <200907071843.n67Ihnsi025447@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 13:43:48 2009 New Revision: 74933 URL: http://llvm.org/viewvc/llvm-project?rev=74933&view=rev Log: fix a bug in post-order iterators with external storage, patch by Olaf Krzikalla! Modified: llvm/trunk/include/llvm/ADT/PostOrderIterator.h Modified: llvm/trunk/include/llvm/ADT/PostOrderIterator.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/PostOrderIterator.h?rev=74933&r1=74932&r2=74933&view=diff ============================================================================== --- llvm/trunk/include/llvm/ADT/PostOrderIterator.h (original) +++ llvm/trunk/include/llvm/ADT/PostOrderIterator.h Tue Jul 7 13:43:48 2009 @@ -71,7 +71,7 @@ inline po_iterator() {} // End is when stack is empty. inline po_iterator(NodeType *BB, SetType &S) : - po_iterator_storage(&S) { + po_iterator_storage(S) { if(!S.count(BB)) { this->Visited.insert(BB); VisitStack.push(std::make_pair(BB, GT::child_begin(BB))); @@ -80,7 +80,7 @@ } inline po_iterator(SetType &S) : - po_iterator_storage(&S) { + po_iterator_storage(S) { } // End is when stack is empty. public: typedef typename super::pointer pointer; From resistor at mac.com Tue Jul 7 13:44:16 2009 From: resistor at mac.com (Owen Anderson) Date: Tue, 07 Jul 2009 18:44:16 -0000 Subject: [llvm-commits] [llvm] r74934 - in /llvm/trunk/lib/AsmParser: LLLexer.cpp LLLexer.h LLParser.h Message-ID: <200907071844.n67IiGth025476@zion.cs.uiuc.edu> Author: resistor Date: Tue Jul 7 13:44:11 2009 New Revision: 74934 URL: http://llvm.org/viewvc/llvm-project?rev=74934&view=rev Log: Use LLVMContext in the LLLexer. Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp llvm/trunk/lib/AsmParser/LLLexer.h llvm/trunk/lib/AsmParser/LLParser.h Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=74934&r1=74933&r2=74934&view=diff ============================================================================== --- llvm/trunk/lib/AsmParser/LLLexer.cpp (original) +++ llvm/trunk/lib/AsmParser/LLLexer.cpp Tue Jul 7 13:44:11 2009 @@ -14,6 +14,7 @@ #include "LLLexer.h" #include "llvm/DerivedTypes.h" #include "llvm/Instruction.h" +#include "llvm/LLVMContext.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/SourceMgr.h" @@ -180,8 +181,9 @@ // Lexer definition. //===----------------------------------------------------------------------===// -LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err) - : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), APFloatVal(0.0) { +LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err, + LLVMContext &C) + : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) { CurPtr = CurBuf->getBufferStart(); } @@ -452,7 +454,7 @@ Error("bitwidth for integer type out of range!"); return lltok::Error; } - TyVal = IntegerType::get(NumBits); + TyVal = Context.getIntegerType(NumBits); return lltok::Type; } Modified: llvm/trunk/lib/AsmParser/LLLexer.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.h?rev=74934&r1=74933&r2=74934&view=diff ============================================================================== --- llvm/trunk/lib/AsmParser/LLLexer.h (original) +++ llvm/trunk/lib/AsmParser/LLLexer.h Tue Jul 7 13:44:11 2009 @@ -24,12 +24,14 @@ class MemoryBuffer; class Type; class SMDiagnostic; + class LLVMContext; class LLLexer { const char *CurPtr; MemoryBuffer *CurBuf; SMDiagnostic &ErrorInfo; SourceMgr &SM; + LLVMContext &Context; // Information about the current token. const char *TokStart; @@ -42,7 +44,8 @@ std::string TheError; public: - explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &); + explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &, + LLVMContext &C); ~LLLexer() {} lltok::Kind Lex() { Modified: llvm/trunk/lib/AsmParser/LLParser.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=74934&r1=74933&r2=74934&view=diff ============================================================================== --- llvm/trunk/lib/AsmParser/LLParser.h (original) +++ llvm/trunk/lib/AsmParser/LLParser.h Tue Jul 7 13:44:11 2009 @@ -74,7 +74,7 @@ std::vector NumberedVals; public: LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) : - Context(m->getContext()), Lex(F, SM, Err), M(m) {} + Context(m->getContext()), Lex(F, SM, Err, m->getContext()), M(m) {} bool Run(); LLVMContext& getContext() { return Context; } From devang.patel at gmail.com Tue Jul 7 13:44:34 2009 From: devang.patel at gmail.com (Devang Patel) Date: Tue, 7 Jul 2009 11:44:34 -0700 Subject: [llvm-commits] [llvm] r74920 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp In-Reply-To: <200907071712.n67HCxXb021589@zion.cs.uiuc.edu> References: <200907071712.n67HCxXb021589@zion.cs.uiuc.edu> Message-ID: <352a1fb20907071144l5869e350qe299935b908554@mail.gmail.com> Thanks! - Devang On Tue, Jul 7, 2009 at 10:12 AM, Owen Anderson wrote: > Author: resistor > Date: Tue Jul ?7 12:12:53 2009 > New Revision: 74920 > > URL: http://llvm.org/viewvc/llvm-project?rev=74920&view=rev > Log: > Re-LLVMContext-ize DebugInfo, now with less breakage. > > Modified: > ? ?llvm/trunk/include/llvm/Analysis/DebugInfo.h > ? ?llvm/trunk/lib/Analysis/DebugInfo.cpp > > Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=74920&r1=74919&r2=74920&view=diff > > ============================================================================== > --- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original) > +++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Tue Jul ?7 12:12:53 2009 > @@ -39,6 +39,7 @@ > ? class DebugLoc; > ? class DebugLocTracker; > ? class Instruction; > + ?class LLVMContext; > > ? class DIDescriptor { > ? protected: > @@ -407,6 +408,8 @@ > ? /// descriptors. > ? class DIFactory { > ? ? Module &M; > + ? ?LLVMContext& VMContext; > + > ? ? // Cached values for uniquing and faster lookups. > ? ? const Type *EmptyStructPtr; // "{}*". > ? ? Function *StopPointFn; ? // llvm.dbg.stoppoint > > Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=74920&r1=74919&r2=74920&view=diff > > ============================================================================== > --- llvm/trunk/lib/Analysis/DebugInfo.cpp (original) > +++ llvm/trunk/lib/Analysis/DebugInfo.cpp Tue Jul ?7 12:12:53 2009 > @@ -18,6 +18,7 @@ > ?#include "llvm/Intrinsics.h" > ?#include "llvm/IntrinsicInst.h" > ?#include "llvm/Instructions.h" > +#include "llvm/LLVMContext.h" > ?#include "llvm/Module.h" > ?#include "llvm/Analysis/ValueTracking.h" > ?#include "llvm/Support/Dwarf.h" > @@ -453,22 +454,23 @@ > ?//===----------------------------------------------------------------------===// > > ?DIFactory::DIFactory(Module &m) > - ?: M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0), > + ?: M(m), VMContext(M.getContext()), StopPointFn(0), FuncStartFn(0), > + ? ?RegionStartFn(0), RegionEndFn(0), > ? ? DeclareFn(0) { > - ?EmptyStructPtr = PointerType::getUnqual(StructType::get()); > + ?EmptyStructPtr = VMContext.getPointerTypeUnqual(VMContext.getStructType()); > ?} > > ?/// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. > ?/// This is only valid when the descriptor is non-null. > ?Constant *DIFactory::getCastToEmpty(DIDescriptor D) { > ? if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); > - ?return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); > + ?return VMContext.getConstantExprBitCast(D.getGV(), EmptyStructPtr); > ?} > > ?Constant *DIFactory::GetTagConstant(unsigned TAG) { > ? assert((TAG & LLVMDebugVersionMask) == 0 && > ? ? ? ? ?"Tag too large for debug encoding!"); > - ?return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); > + ?return VMContext.getConstantInt(Type::Int32Ty, TAG | LLVMDebugVersion); > ?} > > ?Constant *DIFactory::GetStringConstant(const std::string &String) { > @@ -478,21 +480,21 @@ > ? // Return Constant if previously defined. > ? if (Slot) return Slot; > > - ?const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); > + ?const PointerType *DestTy = VMContext.getPointerTypeUnqual(Type::Int8Ty); > > ? // If empty string then use a i8* null instead. > ? if (String.empty()) > - ? ?return Slot = ConstantPointerNull::get(DestTy); > + ? ?return Slot = VMContext.getConstantPointerNull(DestTy); > > ? // Construct string as an llvm constant. > - ?Constant *ConstStr = ConstantArray::get(String); > + ?Constant *ConstStr = VMContext.getConstantArray(String); > > ? // Otherwise create and return a new string global. > ? GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?GlobalVariable::InternalLinkage, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ConstStr, ".str", &M); > ? StrGV->setSection("llvm.metadata"); > - ?return Slot = ConstantExpr::getBitCast(StrGV, DestTy); > + ?return Slot = VMContext.getConstantExprBitCast(StrGV, DestTy); > ?} > > ?//===----------------------------------------------------------------------===// > @@ -507,7 +509,7 @@ > ? for (unsigned i = 0; i != NumTys; ++i) > ? ? Elts.push_back(getCastToEmpty(Tys[i])); > > - ?Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, > + ?Constant *Init = VMContext.getConstantArray(VMContext.getArrayType(EmptyStructPtr, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Elts.size()), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Elts.data(), Elts.size()); > ? // If we already have this array, just return the uniqued version. > @@ -527,11 +529,12 @@ > ?DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { > ? Constant *Elts[] = { > ? ? GetTagConstant(dwarf::DW_TAG_subrange_type), > - ? ?ConstantInt::get(Type::Int64Ty, Lo), > - ? ?ConstantInt::get(Type::Int64Ty, Hi) > + ? ?VMContext.getConstantInt(Type::Int64Ty, Lo), > + ? ?VMContext.getConstantInt(Type::Int64Ty, Hi) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? // If we already have this range, just return the uniqued version. > ? DIDescriptor &Entry = SimpleConstantCache[Init]; > @@ -561,18 +564,19 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned RunTimeVer) { > ? Constant *Elts[] = { > ? ? GetTagConstant(dwarf::DW_TAG_compile_unit), > - ? ?Constant::getNullValue(EmptyStructPtr), > - ? ?ConstantInt::get(Type::Int32Ty, LangID), > + ? ?VMContext.getNullValue(EmptyStructPtr), > + ? ?VMContext.getConstantInt(Type::Int32Ty, LangID), > ? ? GetStringConstant(Filename), > ? ? GetStringConstant(Directory), > ? ? GetStringConstant(Producer), > - ? ?ConstantInt::get(Type::Int1Ty, isMain), > - ? ?ConstantInt::get(Type::Int1Ty, isOptimized), > + ? ?VMContext.getConstantInt(Type::Int1Ty, isMain), > + ? ?VMContext.getConstantInt(Type::Int1Ty, isOptimized), > ? ? GetStringConstant(Flags), > - ? ?ConstantInt::get(Type::Int32Ty, RunTimeVer) > + ? ?VMContext.getConstantInt(Type::Int32Ty, RunTimeVer) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -587,10 +591,11 @@ > ? Constant *Elts[] = { > ? ? GetTagConstant(dwarf::DW_TAG_enumerator), > ? ? GetStringConstant(Name), > - ? ?ConstantInt::get(Type::Int64Ty, Val) > + ? ?VMContext.getConstantInt(Type::Int64Ty, Val) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -615,15 +620,16 @@ > ? ? getCastToEmpty(Context), > ? ? GetStringConstant(Name), > ? ? getCastToEmpty(CompileUnit), > - ? ?ConstantInt::get(Type::Int32Ty, LineNumber), > - ? ?ConstantInt::get(Type::Int64Ty, SizeInBits), > - ? ?ConstantInt::get(Type::Int64Ty, AlignInBits), > - ? ?ConstantInt::get(Type::Int64Ty, OffsetInBits), > - ? ?ConstantInt::get(Type::Int32Ty, Flags), > - ? ?ConstantInt::get(Type::Int32Ty, Encoding) > + ? ?VMContext.getConstantInt(Type::Int32Ty, LineNumber), > + ? ?VMContext.getConstantInt(Type::Int64Ty, SizeInBits), > + ? ?VMContext.getConstantInt(Type::Int64Ty, AlignInBits), > + ? ?VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), > + ? ?VMContext.getConstantInt(Type::Int32Ty, Flags), > + ? ?VMContext.getConstantInt(Type::Int32Ty, Encoding) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.basictype.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -650,15 +656,16 @@ > ? ? getCastToEmpty(Context), > ? ? GetStringConstant(Name), > ? ? getCastToEmpty(CompileUnit), > - ? ?ConstantInt::get(Type::Int32Ty, LineNumber), > - ? ?ConstantInt::get(Type::Int64Ty, SizeInBits), > - ? ?ConstantInt::get(Type::Int64Ty, AlignInBits), > - ? ?ConstantInt::get(Type::Int64Ty, OffsetInBits), > - ? ?ConstantInt::get(Type::Int32Ty, Flags), > + ? ?VMContext.getConstantInt(Type::Int32Ty, LineNumber), > + ? ?VMContext.getConstantInt(Type::Int64Ty, SizeInBits), > + ? ?VMContext.getConstantInt(Type::Int64Ty, AlignInBits), > + ? ?VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), > + ? ?VMContext.getConstantInt(Type::Int32Ty, Flags), > ? ? getCastToEmpty(DerivedFrom) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -687,17 +694,18 @@ > ? ? getCastToEmpty(Context), > ? ? GetStringConstant(Name), > ? ? getCastToEmpty(CompileUnit), > - ? ?ConstantInt::get(Type::Int32Ty, LineNumber), > - ? ?ConstantInt::get(Type::Int64Ty, SizeInBits), > - ? ?ConstantInt::get(Type::Int64Ty, AlignInBits), > - ? ?ConstantInt::get(Type::Int64Ty, OffsetInBits), > - ? ?ConstantInt::get(Type::Int32Ty, Flags), > + ? ?VMContext.getConstantInt(Type::Int32Ty, LineNumber), > + ? ?VMContext.getConstantInt(Type::Int64Ty, SizeInBits), > + ? ?VMContext.getConstantInt(Type::Int64Ty, AlignInBits), > + ? ?VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), > + ? ?VMContext.getConstantInt(Type::Int32Ty, Flags), > ? ? getCastToEmpty(DerivedFrom), > ? ? getCastToEmpty(Elements), > - ? ?ConstantInt::get(Type::Int32Ty, RuntimeLang) > + ? ?VMContext.getConstantInt(Type::Int32Ty, RuntimeLang) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.composite.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -722,19 +730,20 @@ > > ? Constant *Elts[] = { > ? ? GetTagConstant(dwarf::DW_TAG_subprogram), > - ? ?Constant::getNullValue(EmptyStructPtr), > + ? ?VMContext.getNullValue(EmptyStructPtr), > ? ? getCastToEmpty(Context), > ? ? GetStringConstant(Name), > ? ? GetStringConstant(DisplayName), > ? ? GetStringConstant(LinkageName), > ? ? getCastToEmpty(CompileUnit), > - ? ?ConstantInt::get(Type::Int32Ty, LineNo), > + ? ?VMContext.getConstantInt(Type::Int32Ty, LineNo), > ? ? getCastToEmpty(Type), > - ? ?ConstantInt::get(Type::Int1Ty, isLocalToUnit), > - ? ?ConstantInt::get(Type::Int1Ty, isDefinition) > + ? ?VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit), > + ? ?VMContext.getConstantInt(Type::Int1Ty, isDefinition) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -754,20 +763,21 @@ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bool isDefinition, llvm::GlobalVariable *Val) { > ? Constant *Elts[] = { > ? ? GetTagConstant(dwarf::DW_TAG_variable), > - ? ?Constant::getNullValue(EmptyStructPtr), > + ? ?VMContext.getNullValue(EmptyStructPtr), > ? ? getCastToEmpty(Context), > ? ? GetStringConstant(Name), > ? ? GetStringConstant(DisplayName), > ? ? GetStringConstant(LinkageName), > ? ? getCastToEmpty(CompileUnit), > - ? ?ConstantInt::get(Type::Int32Ty, LineNo), > + ? ?VMContext.getConstantInt(Type::Int32Ty, LineNo), > ? ? getCastToEmpty(Type), > - ? ?ConstantInt::get(Type::Int1Ty, isLocalToUnit), > - ? ?ConstantInt::get(Type::Int1Ty, isDefinition), > - ? ?ConstantExpr::getBitCast(Val, EmptyStructPtr) > + ? ?VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit), > + ? ?VMContext.getConstantInt(Type::Int1Ty, isDefinition), > + ? ?VMContext.getConstantExprBitCast(Val, EmptyStructPtr) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -788,11 +798,12 @@ > ? ? getCastToEmpty(Context), > ? ? GetStringConstant(Name), > ? ? getCastToEmpty(CompileUnit), > - ? ?ConstantInt::get(Type::Int32Ty, LineNo), > + ? ?VMContext.getConstantInt(Type::Int32Ty, LineNo), > ? ? getCastToEmpty(Type) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.variable.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -804,14 +815,15 @@ > > > ?/// CreateBlock - This creates a descriptor for a lexical block with the > -/// specified parent context. > +/// specified parent VMContext. > ?DIBlock DIFactory::CreateBlock(DIDescriptor Context) { > ? Constant *Elts[] = { > ? ? GetTagConstant(dwarf::DW_TAG_lexical_block), > ? ? getCastToEmpty(Context) > ? }; > > - ?Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); > + ?Constant *Init = VMContext.getConstantStruct(Elts, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sizeof(Elts)/sizeof(Elts[0])); > > ? M.addTypeName("llvm.dbg.block.type", Init->getType()); > ? GlobalVariable *GV = new GlobalVariable(Init->getType(), true, > @@ -838,8 +850,8 @@ > > ? // Invoke llvm.dbg.stoppoint > ? Value *Args[] = { > - ? ?llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo), > - ? ?llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo), > + ? ?VMContext.getConstantInt(llvm::Type::Int32Ty, LineNo), > + ? ?VMContext.getConstantInt(llvm::Type::Int32Ty, ColNo), > ? ? getCastToEmpty(CU) > ? }; > ? CallInst::Create(StopPointFn, Args, Args+3, "", BB); > @@ -939,10 +951,12 @@ > > ? Value *findDbgGlobalDeclare(GlobalVariable *V) { > ? ? const Module *M = V->getParent(); > + ? ?LLVMContext& Context = M->getContext(); > + > ? ? const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); > ? ? if (!Ty) return 0; > > - ? ?Ty = PointerType::get(Ty, 0); > + ? ?Ty = Context.getPointerType(Ty, 0); > > ? ? Value *Val = V->stripPointerCasts(); > ? ? for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > -- - Devang From mrs at apple.com Tue Jul 7 13:52:17 2009 From: mrs at apple.com (Mike Stump) Date: Tue, 07 Jul 2009 18:52:17 -0000 Subject: [llvm-commits] [llvm] r74936 - /llvm/trunk/lib/Support/CMakeLists.txt Message-ID: <200907071852.n67IqHFt025917@zion.cs.uiuc.edu> Author: mrs Date: Tue Jul 7 13:52:14 2009 New Revision: 74936 URL: http://llvm.org/viewvc/llvm-project?rev=74936&view=rev Log: Fix build. Modified: llvm/trunk/lib/Support/CMakeLists.txt Modified: llvm/trunk/lib/Support/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CMakeLists.txt?rev=74936&r1=74935&r2=74936&view=diff ============================================================================== --- llvm/trunk/lib/Support/CMakeLists.txt (original) +++ llvm/trunk/lib/Support/CMakeLists.txt Tue Jul 7 13:52:14 2009 @@ -8,6 +8,7 @@ ConstantRange.cpp Debug.cpp Dwarf.cpp + ErrorHandling.cpp FileUtilities.cpp FoldingSet.cpp GraphWriter.cpp From devang.patel at gmail.com Tue Jul 7 13:54:35 2009 From: devang.patel at gmail.com (Devang Patel) Date: Tue, 7 Jul 2009 11:54:35 -0700 Subject: [llvm-commits] [llvm] r74883 - /llvm/trunk/include/llvm/CodeGen/MachineOperand.h In-Reply-To: <40BDA519-E5B7-4081-A095-6A5C6739D661@apple.com> References: <200907062346.n66Nk4Zo009321@zion.cs.uiuc.edu> <352a1fb20907061834m1e2f102m851dc27d592105d1@mail.gmail.com> <40BDA519-E5B7-4081-A095-6A5C6739D661@apple.com> Message-ID: <352a1fb20907071154w588690beka08df3261e3bb91e@mail.gmail.com> Chris, On Mon, Jul 6, 2009 at 9:37 PM, Chris Lattner wrote: > > On Jul 6, 2009, at 6:34 PM, Devang Patel wrote: > >> Chris, >> >> On Mon, Jul 6, 2009 at 6:09 PM, Chris Lattner >> wrote: >>> >>> On Jul 6, 2009, at 4:46 PM, Devang Patel wrote: >>> >>>> Author: dpatel >>>> Date: Mon Jul ?6 18:46:02 2009 >>>> New Revision: 74883 >>>> >>>> URL: http://llvm.org/viewvc/llvm-project?rev=74883&view=rev >>>> Log: >>>> Add isMetadata() to check metadata operand. >>> >>> Hey Devang, >>> >>> What is your plan to use MetaData MachineInstr operands? ?Can you >>> elaborate on how you plan to use these? >> >> My near term goal is to replace all Global Variables used to encode >> debug info (llvm.dbg.*) by MDNodes. As a step towards this goal, I >> need MetaData as machine instruction operand to handle printDeclare(). > > Do we really want to propagate llvm.declare intrinsics into > machineinstrs? No. The question was "now or later " ? I'll fix it now :) >?Why not have ISel tag the stack slot with the MDNode > instead of lowering to a machineinstr? - Devang From edwintorok at gmail.com Tue Jul 7 13:54:34 2009 From: edwintorok at gmail.com (=?ISO-8859-1?Q?T=F6r=F6k_Edwin?=) Date: Tue, 07 Jul 2009 21:54:34 +0300 Subject: [llvm-commits] [llvm] r74936 - /llvm/trunk/lib/Support/CMakeLists.txt In-Reply-To: <200907071852.n67IqHFt025917@zion.cs.uiuc.edu> References: <200907071852.n67IqHFt025917@zion.cs.uiuc.edu> Message-ID: <4A5399EA.1000704@gmail.com> On 2009-07-07 21:52, Mike Stump wrote: > Author: mrs > Date: Tue Jul 7 13:52:14 2009 > New Revision: 74936 > > URL: http://llvm.org/viewvc/llvm-project?rev=74936&view=rev > Log: > Fix build. > > Thanks, I forgot that CMake needs to be told about new files. Best regards, --Edwin From evan.cheng at apple.com Tue Jul 7 14:16:57 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 07 Jul 2009 19:16:57 -0000 Subject: [llvm-commits] [llvm] r74938 - /llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Message-ID: <200907071917.n67JH4J3026913@zion.cs.uiuc.edu> Author: evancheng Date: Tue Jul 7 14:16:24 2009 New Revision: 74938 URL: http://llvm.org/viewvc/llvm-project?rev=74938&view=rev Log: Add BX and BXr9 encodings. Patch by Sean Callanan. Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Modified: llvm/trunk/lib/Target/ARM/ARMInstrInfo.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrInfo.td?rev=74938&r1=74937&r2=74938&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrInfo.td (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrInfo.td Tue Jul 7 14:16:24 2009 @@ -618,7 +618,11 @@ // ARMv4T def BX : ABXIx2<(outs), (ins GPR:$func, variable_ops), "mov lr, pc\n\tbx $func", - [(ARMcall_nolink GPR:$func)]>, Requires<[IsNotDarwin]>; + [(ARMcall_nolink GPR:$func)]>, Requires<[IsNotDarwin]> { + let Inst{7-4} = 0b0001; + let Inst{19-8} = 0b111111111111; + let Inst{27-20} = 0b00010010; + } } } @@ -647,7 +651,11 @@ // ARMv4T def BXr9 : ABXIx2<(outs), (ins GPR:$func, variable_ops), "mov lr, pc\n\tbx $func", - [(ARMcall_nolink GPR:$func)]>, Requires<[IsDarwin]>; + [(ARMcall_nolink GPR:$func)]>, Requires<[IsDarwin]> { + let Inst{7-4} = 0b0001; + let Inst{19-8} = 0b111111111111; + let Inst{27-20} = 0b00010010; + } } } From mrs at apple.com Tue Jul 7 14:37:32 2009 From: mrs at apple.com (Mike Stump) Date: Tue, 7 Jul 2009 12:37:32 -0700 Subject: [llvm-commits] [llvm] r74936 - /llvm/trunk/lib/Support/CMakeLists.txt In-Reply-To: <4A5399EA.1000704@gmail.com> References: <200907071852.n67IqHFt025917@zion.cs.uiuc.edu> <4A5399EA.1000704@gmail.com> Message-ID: On Jul 7, 2009, at 11:54 AM, T?r?k Edwin wrote: > On 2009-07-07 21:52, Mike Stump wrote: >> URL: http://llvm.org/viewvc/llvm-project?rev=74936&view=rev >> Log: >> Fix build. > > Thanks, I forgot that CMake needs to be told about new files. We could do *.cpp in there... In some respects, this would promote a cleaner code... From mai4 at uiuc.edu Tue Jul 7 14:58:03 2009 From: mai4 at uiuc.edu (Haohui Mai) Date: Tue, 07 Jul 2009 19:58:03 -0000 Subject: [llvm-commits] [poolalloc] r74939 - in /poolalloc/trunk/lib/PoolAllocate: PAMultipleGlobalPool.cpp PASimple.cpp Message-ID: <200907071958.n67Jw5g4028267@zion.cs.uiuc.edu> Author: mai4 Date: Tue Jul 7 14:57:47 2009 New Revision: 74939 URL: http://llvm.org/viewvc/llvm-project?rev=74939&view=rev Log: Rename poolalloc.init into __poolalloc_init and mark them as external linkage to make sure clients can call them. Modified: poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Modified: poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp?rev=74939&r1=74938&r2=74939&view=diff ============================================================================== --- poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp (original) +++ poolalloc/trunk/lib/PoolAllocate/PAMultipleGlobalPool.cpp Tue Jul 7 14:57:47 2009 @@ -98,7 +98,7 @@ // clones. for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { std::string name = I->getName(); - if (name == "poolalloc.init") continue; + if (name == "__poolalloc_init") continue; if (!(I->isDeclaration())) ProcessFunctionBodySimple(*I, TD); } @@ -308,7 +308,7 @@ Function *InitFunc = Function::Create (FunctionType::get(Type::VoidTy, std::vector(), false), - GlobalValue::InternalLinkage, "poolalloc.init", &M); + GlobalValue::ExternalLinkage, "__poolalloc_init", &M); BasicBlock * BB = BasicBlock::Create("entry", InitFunc); Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=74939&r1=74938&r2=74939&view=diff ============================================================================== --- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original) +++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Tue Jul 7 14:57:47 2009 @@ -139,7 +139,7 @@ // clones. for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { std::string name = I->getName(); - if (name == "poolalloc.init") continue; + if (name == "__poolalloc_init") continue; if (!(I->isDeclaration())) ProcessFunctionBodySimple(*I, TD); } @@ -359,7 +359,7 @@ Function *InitFunc = Function::Create (FunctionType::get(Type::VoidTy, std::vector(), false), - GlobalValue::InternalLinkage, "poolalloc.init", &M); + GlobalValue::ExternalLinkage, "__poolalloc_init", &M); BasicBlock * BB = BasicBlock::Create("entry", InitFunc); Value *ElSize = ConstantInt::get(Type::Int32Ty, RecSize); From mai4 at uiuc.edu Tue Jul 7 14:59:08 2009 From: mai4 at uiuc.edu (Haohui Mai) Date: Tue, 07 Jul 2009 19:59:08 -0000 Subject: [llvm-commits] [poolalloc] r74940 - in /poolalloc/trunk: include/dsa/DataStructure.h lib/DSA/Steensgaard.cpp Message-ID: <200907071959.n67Jx8X4028306@zion.cs.uiuc.edu> Author: mai4 Date: Tue Jul 7 14:59:07 2009 New Revision: 74940 URL: http://llvm.org/viewvc/llvm-project?rev=74940&view=rev Log: Bug fix on handling globals graph. Modified: poolalloc/trunk/include/dsa/DataStructure.h poolalloc/trunk/lib/DSA/Steensgaard.cpp Modified: poolalloc/trunk/include/dsa/DataStructure.h URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=74940&r1=74939&r2=74940&view=diff ============================================================================== --- poolalloc/trunk/include/dsa/DataStructure.h (original) +++ poolalloc/trunk/include/dsa/DataStructure.h Tue Jul 7 14:59:07 2009 @@ -430,6 +430,7 @@ virtual void releaseMemory(); virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); AU.addRequired(); AU.setPreservesAll(); } Modified: poolalloc/trunk/lib/DSA/Steensgaard.cpp URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Steensgaard.cpp?rev=74940&r1=74939&r2=74940&view=diff ============================================================================== --- poolalloc/trunk/lib/DSA/Steensgaard.cpp (original) +++ poolalloc/trunk/lib/DSA/Steensgaard.cpp Tue Jul 7 14:59:07 2009 @@ -27,10 +27,10 @@ void SteensgaardDataStructures::releaseMemory() { - // Here we don't need to delete the result graph, because it aliases with the - // GlobalsGraph, which is deleted by DataStructures::releaseMemory(). + // Here we don't need to delete the result graph, because it aliases with the + // GlobalsGraph, which is deleted by DataStructures::releaseMemory(). ResultGraph = 0; - DataStructures::releaseMemory(); + DataStructures::releaseMemory(); } // print - Implement the Pass::print method... @@ -51,17 +51,23 @@ bool SteensgaardDataStructures::runOnModule(Module &M) { DS = &getAnalysis(); + init(&getAnalysis()); return runOnModuleInternal(M); } bool SteensgaardDataStructures::runOnModuleInternal(Module &M) { assert(ResultGraph == 0 && "Result graph already allocated!"); + // Create a new, empty, graph... ResultGraph = new DSGraph(GlobalECs, getTargetData()); + ResultGraph->setGlobalsGraph(ResultGraph); ResultGraph->spliceFrom(DS->getGlobalsGraph()); + // Assign the result graph to globals graph. It should be the same. + GlobalsGraph = ResultGraph; + // Loop over the rest of the module, merging graphs for non-external functions // into this graph. // @@ -130,10 +136,8 @@ // Remove any nodes that are dead after all of the merging we have done... // FIXME: We should be able to disable the globals graph for steens! - ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); + // ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); - // Assign the result graph to globals graph. It should be the same. - GlobalsGraph = ResultGraph; print(DOUT, &M); return false; } From gohman at apple.com Tue Jul 7 15:05:34 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 07 Jul 2009 20:05:34 -0000 Subject: [llvm-commits] [llvm] r74941 - /llvm/trunk/docs/ReleaseNotes-2.6.html Message-ID: <200907072005.n67K5Zpr028923@zion.cs.uiuc.edu> Author: djg Date: Tue Jul 7 15:05:15 2009 New Revision: 74941 URL: http://llvm.org/viewvc/llvm-project?rev=74941&view=rev Log: Add a paragraph about the Add->FAdd API change. Modified: llvm/trunk/docs/ReleaseNotes-2.6.html Modified: llvm/trunk/docs/ReleaseNotes-2.6.html URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ReleaseNotes-2.6.html?rev=74941&r1=74940&r2=74941&view=diff ============================================================================== --- llvm/trunk/docs/ReleaseNotes-2.6.html (original) +++ llvm/trunk/docs/ReleaseNotes-2.6.html Tue Jul 7 15:05:15 2009 @@ -441,6 +441,14 @@ context which can be passed in any and all cases where a context is required.
  • The getABITypeSize methods are now called getAllocSize.
  • +
  • The Add, Sub, and Mul operators are no longer + overloaded for floating-point types. Floating-point addition, subtraction, + and multiplication are now represented with new operators FAdd, + FSub, and FMul. In the IRBuilder API, + CreateAdd, CreateSub, CreateMul, and + CreateNeg should only be used for integer arithmetic now; + CreateFAdd, CreateFSub, CreateFMul, and + CreateFNeg should now be used for floating-point arithmetic.
  • From clattner at apple.com Tue Jul 7 15:11:29 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 7 Jul 2009 13:11:29 -0700 Subject: [llvm-commits] [llvm] r74929 - /llvm/trunk/include/llvm/CodeGen/BinaryObject.h In-Reply-To: References: <200907071828.n67ISaxY024878@zion.cs.uiuc.edu> Message-ID: <9AB82B78-CBF9-403F-8292-8805B8AA52DA@apple.com> On Jul 7, 2009, at 11:35 AM, Misha Brukman wrote: > 2009/7/7 Chris Lattner > - Data.push_back((W >> 0) & 255); > - Data.push_back((W >> 8) & 255); > + Data.push_back((uint8_t)(W >> 0)); > + Data.push_back((uint8_t)(W >> 8)); > > These are all C-style casts, rather than C++-style casts, e.g. > static_cast(value) . > Is there a preference for C-style casts in LLVM? I thought we were > trying to stick with C++ here. We don't use one consistently over the other. I don't think there is a clear win to using c++ style casts here, in the sense that they don't add any value. OTOH, for const_cast, I think that using the c++ style cast makes the intention more clear. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20090707/63e0a903/attachment.html From clattner at apple.com Tue Jul 7 15:16:06 2009 From: clattner at apple.com (Chris Lattner) Date: Tue, 7 Jul 2009 13:16:06 -0700 Subject: [llvm-commits] PATCH: remove VICmp and VFCmp. In-Reply-To: <05085D11-65C9-478A-B854-1EAC52FD9E42@apple.com> References: <4A518899.80806@mxc.ca> <7ABB6DFD-7F2E-4F31-A7D9-FC86362095E6@apple.com> <05085D11-65C9-478A-B854-1EAC52FD9E42@apple.com> Message-ID: On Jul 7, 2009, at 11:30 AM, Dan Gohman wrote: > On Jul 6, 2009, at 10:10 AM, Chris Lattner wrote: > On Jul 5, 2009, at 10:16 PM, Nick Lewycky wrote: >>> This patch removes vicmp and vfcmp, which has the positive side that >>> >>> it fixes existing type-safety bugs and simplifies some code, but a >>> >>> downside in that it XFAILs 9 CodeGen tests. >>> >> >> I haven't had a chance to look at the patch, but removing v[fi]cmp >> will almost certainly break clang (which generates them for vector >> comparisons in opencl/ext_vector mode). The right way to remove this >> is to make codegen pattern match [fi]cmp+sext to the same nodes it is >> using for v[fi]cmp, then change clang to generate [fi]cmp+sext >> instead >> of v[if]cmp, then nuke v[fi]cmp. This way we won't loose any codegen >> capability and clang will still build :). > > Vector [fi]cmp are not yet ready to replace v[fi]cmp, and there's > more work required than just adding patterns. > > Work has been one to support vector [fi]cmp in the IR, however no > work has been done to support it in CodeGen yet. Adding support in > CodeGen will require a variety of fairly straight-forward > changes, plus finding a solution for vectors of i1 in CodeGen. I don't see a need to fix the "vector of i1" issue right now. In fact, I don't see an issue at all. There are two things we care about: making compare+sext turn into the current nice code that v*cmp produces, and eventually handling compare +select. Both of these idioms are trivial enough that they could be handled by pre-legalize dag combine, forming (e.g.) ISD::VSETCC nodes. Then legalize won't ever see vectors of i1 in code that we care about. -Chris From resistor at mac.com Tue Jul 7 15:19:10 2009 From: resistor at mac.com (Owen Anderson) Date: Tue, 07 Jul 2009 20:19:10 -0000 Subject: [llvm-commits] [llvm] r74942 - in /llvm/trunk/lib/Bitcode/Reader: BitcodeReader.cpp BitcodeReader.h Message-ID: <200907072019.n67KJB4e029461@zion.cs.uiuc.edu> Author: resistor Date: Tue Jul 7 15:18:58 2009 New Revision: 74942 URL: http://llvm.org/viewvc/llvm-project?rev=74942&view=rev Log: LLVMContext-ify the bitcode reader. Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=74942&r1=74941&r2=74942&view=diff ============================================================================== --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original) +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jul 7 15:18:58 2009 @@ -17,6 +17,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/InlineAsm.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/MDNode.h" #include "llvm/Module.h" #include "llvm/AutoUpgrade.h" @@ -137,9 +138,9 @@ void *operator new(size_t s) { return User::operator new(s, 1); } - explicit ConstantPlaceHolder(const Type *Ty) + explicit ConstantPlaceHolder(const Type *Ty, LLVMContext& Context) : ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) { - Op<0>() = UndefValue::get(Type::Int32Ty); + Op<0>() = Context.getUndef(Type::Int32Ty); } /// @brief Methods to support type inquiry through isa, cast, and dyn_cast. @@ -202,7 +203,7 @@ } // Create and return a placeholder, which will later be RAUW'd. - Constant *C = new ConstantPlaceHolder(Ty); + Constant *C = new ConstantPlaceHolder(Ty, Context); ValuePtrs[Idx] = C; return C; } @@ -285,12 +286,13 @@ // Make the new constant. Constant *NewC; if (ConstantArray *UserCA = dyn_cast(UserC)) { - NewC = ConstantArray::get(UserCA->getType(), &NewOps[0], NewOps.size()); + NewC = Context.getConstantArray(UserCA->getType(), &NewOps[0], + NewOps.size()); } else if (ConstantStruct *UserCS = dyn_cast(UserC)) { - NewC = ConstantStruct::get(&NewOps[0], NewOps.size(), - UserCS->getType()->isPacked()); + NewC = Context.getConstantStruct(&NewOps[0], NewOps.size(), + UserCS->getType()->isPacked()); } else if (isa(UserC)) { - NewC = ConstantVector::get(&NewOps[0], NewOps.size()); + NewC = Context.getConstantVector(&NewOps[0], NewOps.size()); } else { assert(isa(UserC) && "Must be a ConstantExpr."); NewC = cast(UserC)->getWithOperands(&NewOps[0], @@ -318,7 +320,7 @@ // The type table allows forward references. Push as many Opaque types as // needed to get up to ID. while (TypeList.size() <= ID) - TypeList.push_back(OpaqueType::get()); + TypeList.push_back(Context.getOpaqueType()); return TypeList.back().get(); } @@ -508,7 +510,7 @@ if (Record.size() < 1) return Error("Invalid Integer type record"); - ResultTy = IntegerType::get(Record[0]); + ResultTy = Context.getIntegerType(Record[0]); break; case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or // [pointee type, address space] @@ -517,7 +519,8 @@ unsigned AddressSpace = 0; if (Record.size() == 2) AddressSpace = Record[1]; - ResultTy = PointerType::get(getTypeByID(Record[0], true), AddressSpace); + ResultTy = Context.getPointerType(getTypeByID(Record[0], true), + AddressSpace); break; } case bitc::TYPE_CODE_FUNCTION: { @@ -529,7 +532,7 @@ for (unsigned i = 3, e = Record.size(); i != e; ++i) ArgTys.push_back(getTypeByID(Record[i], true)); - ResultTy = FunctionType::get(getTypeByID(Record[2], true), ArgTys, + ResultTy = Context.getFunctionType(getTypeByID(Record[2], true), ArgTys, Record[0]); break; } @@ -539,24 +542,24 @@ std::vector EltTys; for (unsigned i = 1, e = Record.size(); i != e; ++i) EltTys.push_back(getTypeByID(Record[i], true)); - ResultTy = StructType::get(EltTys, Record[0]); + ResultTy = Context.getStructType(EltTys, Record[0]); break; } case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty] if (Record.size() < 2) return Error("Invalid ARRAY type record"); - ResultTy = ArrayType::get(getTypeByID(Record[1], true), Record[0]); + ResultTy = Context.getArrayType(getTypeByID(Record[1], true), Record[0]); break; case bitc::TYPE_CODE_VECTOR: // VECTOR: [numelts, eltty] if (Record.size() < 2) return Error("Invalid VECTOR type record"); - ResultTy = VectorType::get(getTypeByID(Record[1], true), Record[0]); + ResultTy = Context.getVectorType(getTypeByID(Record[1], true), Record[0]); break; } if (NumRecords == TypeList.size()) { // If this is a new type slot, just append it. - TypeList.push_back(ResultTy ? ResultTy : OpaqueType::get()); + TypeList.push_back(ResultTy ? ResultTy : Context.getOpaqueType()); ++NumRecords; } else if (ResultTy == 0) { // Otherwise, this was forward referenced, so an opaque type was created, @@ -777,7 +780,7 @@ switch (Stream.ReadRecord(Code, Record)) { default: // Default behavior: unknown constant case bitc::CST_CODE_UNDEF: // UNDEF - V = UndefValue::get(CurTy); + V = Context.getUndef(CurTy); break; case bitc::CST_CODE_SETTYPE: // SETTYPE: [typeid] if (Record.empty()) @@ -787,12 +790,12 @@ CurTy = TypeList[Record[0]]; continue; // Skip the ValueList manipulation. case bitc::CST_CODE_NULL: // NULL - V = Constant::getNullValue(CurTy); + V = Context.getNullValue(CurTy); break; case bitc::CST_CODE_INTEGER: // INTEGER: [intval] if (!isa(CurTy) || Record.empty()) return Error("Invalid CST_INTEGER record"); - V = ConstantInt::get(CurTy, DecodeSignRotatedValue(Record[0])); + V = Context.getConstantInt(CurTy, DecodeSignRotatedValue(Record[0])); break; case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval] if (!isa(CurTy) || Record.empty()) @@ -803,7 +806,7 @@ Words.resize(NumWords); for (unsigned i = 0; i != NumWords; ++i) Words[i] = DecodeSignRotatedValue(Record[i]); - V = ConstantInt::get(APInt(cast(CurTy)->getBitWidth(), + V = Context.getConstantInt(APInt(cast(CurTy)->getBitWidth(), NumWords, &Words[0])); break; } @@ -811,21 +814,21 @@ if (Record.empty()) return Error("Invalid FLOAT record"); if (CurTy == Type::FloatTy) - V = ConstantFP::get(APFloat(APInt(32, (uint32_t)Record[0]))); + V = Context.getConstantFP(APFloat(APInt(32, (uint32_t)Record[0]))); else if (CurTy == Type::DoubleTy) - V = ConstantFP::get(APFloat(APInt(64, Record[0]))); + V = Context.getConstantFP(APFloat(APInt(64, Record[0]))); else if (CurTy == Type::X86_FP80Ty) { // Bits are not stored the same way as a normal i80 APInt, compensate. uint64_t Rearrange[2]; Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16); Rearrange[1] = Record[0] >> 48; - V = ConstantFP::get(APFloat(APInt(80, 2, Rearrange))); + V = Context.getConstantFP(APFloat(APInt(80, 2, Rearrange))); } else if (CurTy == Type::FP128Ty) - V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0]), true)); + V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0]), true)); else if (CurTy == Type::PPC_FP128Ty) - V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0]))); + V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0]))); else - V = UndefValue::get(CurTy); + V = Context.getUndef(CurTy); break; } @@ -840,19 +843,19 @@ for (unsigned i = 0; i != Size; ++i) Elts.push_back(ValueList.getConstantFwdRef(Record[i], STy->getElementType(i))); - V = ConstantStruct::get(STy, Elts); + V = Context.getConstantStruct(STy, Elts); } else if (const ArrayType *ATy = dyn_cast(CurTy)) { const Type *EltTy = ATy->getElementType(); for (unsigned i = 0; i != Size; ++i) Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy)); - V = ConstantArray::get(ATy, Elts); + V = Context.getConstantArray(ATy, Elts); } else if (const VectorType *VTy = dyn_cast(CurTy)) { const Type *EltTy = VTy->getElementType(); for (unsigned i = 0; i != Size; ++i) Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy)); - V = ConstantVector::get(Elts); + V = Context.getConstantVector(Elts); } else { - V = UndefValue::get(CurTy); + V = Context.getUndef(CurTy); } break; } @@ -866,8 +869,8 @@ unsigned Size = Record.size(); std::vector Elts; for (unsigned i = 0; i != Size; ++i) - Elts.push_back(ConstantInt::get(EltTy, Record[i])); - V = ConstantArray::get(ATy, Elts); + Elts.push_back(Context.getConstantInt(EltTy, Record[i])); + V = Context.getConstantArray(ATy, Elts); break; } case bitc::CST_CODE_CSTRING: { // CSTRING: [values] @@ -880,20 +883,20 @@ unsigned Size = Record.size(); std::vector Elts; for (unsigned i = 0; i != Size; ++i) - Elts.push_back(ConstantInt::get(EltTy, Record[i])); - Elts.push_back(Constant::getNullValue(EltTy)); - V = ConstantArray::get(ATy, Elts); + Elts.push_back(Context.getConstantInt(EltTy, Record[i])); + Elts.push_back(Context.getNullValue(EltTy)); + V = Context.getConstantArray(ATy, Elts); break; } case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval] if (Record.size() < 3) return Error("Invalid CE_BINOP record"); int Opc = GetDecodedBinaryOpcode(Record[0], CurTy); if (Opc < 0) { - V = UndefValue::get(CurTy); // Unknown binop. + V = Context.getUndef(CurTy); // Unknown binop. } else { Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy); Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy); - V = ConstantExpr::get(Opc, LHS, RHS); + V = Context.getConstantExpr(Opc, LHS, RHS); } break; } @@ -901,12 +904,12 @@ if (Record.size() < 3) return Error("Invalid CE_CAST record"); int Opc = GetDecodedCastOpcode(Record[0]); if (Opc < 0) { - V = UndefValue::get(CurTy); // Unknown cast. + V = Context.getUndef(CurTy); // Unknown cast. } else { const Type *OpTy = getTypeByID(Record[1]); if (!OpTy) return Error("Invalid CE_CAST record"); Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy); - V = ConstantExpr::getCast(Opc, Op, CurTy); + V = Context.getConstantExprCast(Opc, Op, CurTy); } break; } @@ -918,12 +921,13 @@ if (!ElTy) return Error("Invalid CE_GEP record"); Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy)); } - V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1); + V = Context.getConstantExprGetElementPtr(Elts[0], &Elts[1], + Elts.size()-1); break; } case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#] if (Record.size() < 3) return Error("Invalid CE_SELECT record"); - V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0], + V = Context.getConstantExprSelect(ValueList.getConstantFwdRef(Record[0], Type::Int1Ty), ValueList.getConstantFwdRef(Record[1],CurTy), ValueList.getConstantFwdRef(Record[2],CurTy)); @@ -935,7 +939,7 @@ if (OpTy == 0) return Error("Invalid CE_EXTRACTELT record"); Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty); - V = ConstantExpr::getExtractElement(Op0, Op1); + V = Context.getConstantExprExtractElement(Op0, Op1); break; } case bitc::CST_CODE_CE_INSERTELT: { // CE_INSERTELT: [opval, opval, opval] @@ -946,7 +950,7 @@ Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy->getElementType()); Constant *Op2 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty); - V = ConstantExpr::getInsertElement(Op0, Op1, Op2); + V = Context.getConstantExprInsertElement(Op0, Op1, Op2); break; } case bitc::CST_CODE_CE_SHUFFLEVEC: { // CE_SHUFFLEVEC: [opval, opval, opval] @@ -955,9 +959,10 @@ return Error("Invalid CE_SHUFFLEVEC record"); Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy); - const Type *ShufTy=VectorType::get(Type::Int32Ty, OpTy->getNumElements()); + const Type *ShufTy = Context.getVectorType(Type::Int32Ty, + OpTy->getNumElements()); Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy); - V = ConstantExpr::getShuffleVector(Op0, Op1, Op2); + V = Context.getConstantExprShuffleVector(Op0, Op1, Op2); break; } case bitc::CST_CODE_CE_SHUFVEC_EX: { // [opty, opval, opval, opval] @@ -967,9 +972,10 @@ return Error("Invalid CE_SHUFVEC_EX record"); Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy); - const Type *ShufTy=VectorType::get(Type::Int32Ty, RTy->getNumElements()); + const Type *ShufTy = Context.getVectorType(Type::Int32Ty, + RTy->getNumElements()); Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy); - V = ConstantExpr::getShuffleVector(Op0, Op1, Op2); + V = Context.getConstantExprShuffleVector(Op0, Op1, Op2); break; } case bitc::CST_CODE_CE_CMP: { // CE_CMP: [opty, opval, opval, pred] @@ -980,13 +986,13 @@ Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy); if (OpTy->isFloatingPoint()) - V = ConstantExpr::getFCmp(Record[3], Op0, Op1); + V = Context.getConstantExprFCmp(Record[3], Op0, Op1); else if (!isa(OpTy)) - V = ConstantExpr::getICmp(Record[3], Op0, Op1); + V = Context.getConstantExprICmp(Record[3], Op0, Op1); else if (OpTy->isFPOrFPVector()) - V = ConstantExpr::getVFCmp(Record[3], Op0, Op1); + V = Context.getConstantExprVFCmp(Record[3], Op0, Op1); else - V = ConstantExpr::getVICmp(Record[3], Op0, Op1); + V = Context.getConstantExprVICmp(Record[3], Op0, Op1); break; } case bitc::CST_CODE_INLINEASM: { @@ -1015,7 +1021,7 @@ String.resize(MDStringLength); for (unsigned i = 0; i != MDStringLength; ++i) String[i] = Record[i]; - V = MDString::get(String.c_str(), String.c_str() + MDStringLength); + V = Context.getMDString(String.c_str(), String.c_str() + MDStringLength); break; } case bitc::CST_CODE_MDNODE: { @@ -1031,7 +1037,7 @@ else Elts.push_back(NULL); } - V = MDNode::get(&Elts[0], Elts.size()); + V = Context.getMDNode(&Elts[0], Elts.size()); break; } } @@ -1693,7 +1699,7 @@ if (Vs.size() > 1 || (isa(ReturnType) && (Vs.empty() || Vs[0]->getType() != ReturnType))) { - Value *RV = UndefValue::get(ReturnType); + Value *RV = Context.getUndef(ReturnType); for (unsigned i = 0, e = Vs.size(); i != e; ++i) { I = InsertValueInst::Create(RV, Vs[i], i, "mrv"); CurBB->getInstList().push_back(I); @@ -1879,7 +1885,8 @@ unsigned OpNum = 0; Value *Val, *Ptr; if (getValueTypePair(Record, OpNum, NextValueNo, Val) || - getValue(Record, OpNum, PointerType::getUnqual(Val->getType()), Ptr)|| + getValue(Record, OpNum, + Context.getPointerTypeUnqual(Val->getType()), Ptr)|| OpNum+2 != Record.size()) return Error("Invalid STORE record"); @@ -1972,7 +1979,7 @@ // We found at least one unresolved value. Nuke them all to avoid leaks. for (unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){ if ((A = dyn_cast(ValueList.back())) && A->getParent() == 0) { - A->replaceAllUsesWith(UndefValue::get(A->getType())); + A->replaceAllUsesWith(Context.getUndef(A->getType())); delete A; } } Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h?rev=74942&r1=74941&r2=74942&view=diff ============================================================================== --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h (original) +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h Tue Jul 7 15:18:58 2009 @@ -44,8 +44,9 @@ /// number that holds the resolved value. typedef std::vector > ResolveConstantsTy; ResolveConstantsTy ResolveConstants; + LLVMContext& Context; public: - BitcodeReaderValueList() {} + BitcodeReaderValueList(LLVMContext& C) : Context(C) {} ~BitcodeReaderValueList() { assert(ResolveConstants.empty() && "Constants not resolved?"); } @@ -126,7 +127,7 @@ DenseMap > DeferredFunctionInfo; public: explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext& C) - : Context(C), Buffer(buffer), ErrorString(0) { + : Context(C), Buffer(buffer), ErrorString(0), ValueList(C) { HasReversedFunctionsWithBodies = false; } ~BitcodeReader() { From sabre at nondot.org Tue Jul 7 15:30:48 2009 From: sabre at nondot.org (Chris Lattner) Date: Tue, 07 Jul 2009 20:30:48 -0000 Subject: [llvm-commits] [llvm] r74944 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/MC/MCAsmStreamer.cpp test/MC/AsmParser/directive_comm.s tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h Message-ID: <200907072030.n67KUnY0029857@zion.cs.uiuc.edu> Author: lattner Date: Tue Jul 7 15:30:46 2009 New Revision: 74944 URL: http://llvm.org/viewvc/llvm-project?rev=74944&view=rev Log: Implement parsing support for the .comm directive. Patch by Kevin Enderby! Added: llvm/trunk/test/MC/AsmParser/directive_comm.s Modified: llvm/trunk/include/llvm/MC/MCStreamer.h llvm/trunk/lib/MC/MCAsmStreamer.cpp llvm/trunk/tools/llvm-mc/AsmParser.cpp llvm/trunk/tools/llvm-mc/AsmParser.h Modified: llvm/trunk/include/llvm/MC/MCStreamer.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=74944&r1=74943&r2=74944&view=diff ============================================================================== --- llvm/trunk/include/llvm/MC/MCStreamer.h (original) +++ llvm/trunk/include/llvm/MC/MCStreamer.h Tue Jul 7 15:30:46 2009 @@ -115,6 +115,15 @@ virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute) = 0; + /// EmitCommonSymbol - Emit a common symbol of @param Size with the @param + /// Pow2Alignment if non-zero. + /// + /// @param Symbol - The common symbol to emit. + /// @param Size - The size of the common symbol. + /// @param Pow2Alignment - The alignment of the common symbol if non-zero. + virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size, + unsigned Pow2Alignment) = 0; + /// @} /// @name Generating Data /// @{ Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=74944&r1=74943&r2=74944&view=diff ============================================================================== --- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original) +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Jul 7 15:30:46 2009 @@ -41,6 +41,9 @@ virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute); + virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size, + unsigned Pow2Alignment); + virtual void EmitBytes(const char *Data, unsigned Length); virtual void EmitValue(const MCValue &Value, unsigned Size); @@ -142,6 +145,15 @@ OS << ' ' << Symbol->getName() << '\n'; } +void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size, + unsigned Pow2Alignment) { + OS << ".comm"; + OS << ' ' << Symbol->getName() << ',' << Size; + if (Pow2Alignment != 0) + OS << ',' << Pow2Alignment; + OS << '\n'; +} + void MCAsmStreamer::EmitBytes(const char *Data, unsigned Length) { assert(CurSection && "Cannot emit contents before setting section!"); for (unsigned i = 0; i != Length; ++i) Added: llvm/trunk/test/MC/AsmParser/directive_comm.s URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_comm.s?rev=74944&view=auto ============================================================================== --- llvm/trunk/test/MC/AsmParser/directive_comm.s (added) +++ llvm/trunk/test/MC/AsmParser/directive_comm.s Tue Jul 7 15:30:46 2009 @@ -0,0 +1,8 @@ +# RUN: llvm-mc %s > %t + +# RUN: grep -A 3 TEST0 %t > %t2 +# RUN: grep ".comm a,6,2" %t2 | count 1 +# RUN: grep ".comm b,8" %t2 | count 1 +TEST0: + .comm a, 4+2, 2 + .comm b,8 Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=74944&r1=74943&r2=74944&view=diff ============================================================================== --- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original) +++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jul 7 15:30:46 2009 @@ -520,6 +520,9 @@ if (!strcmp(IDVal, ".weak_reference")) return ParseDirectiveSymbolAttribute(MCStreamer::WeakReference); + if (!strcmp(IDVal, ".comm")) + return ParseDirectiveComm(); + Warning(IDLoc, "ignoring directive for now"); EatToEndOfStatement(); return false; @@ -896,3 +899,59 @@ Lexer.Lex(); return false; } + +/// ParseDirectiveComm +/// ::= .comm identifier , size_expression [ , align_expression ] +bool AsmParser::ParseDirectiveComm() { + if (Lexer.isNot(asmtok::Identifier)) + return TokError("expected identifier in directive"); + + // handle the identifier as the key symbol. + SMLoc IDLoc = Lexer.getLoc(); + MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal()); + Lexer.Lex(); + + if (Lexer.isNot(asmtok::Comma)) + return TokError("unexpected token in directive"); + Lexer.Lex(); + + int64_t Size; + SMLoc SizeLoc = Lexer.getLoc(); + if (ParseAbsoluteExpression(Size)) + return true; + + int64_t Pow2Alignment = 0; + SMLoc Pow2AlignmentLoc; + if (Lexer.is(asmtok::Comma)) { + Lexer.Lex(); + Pow2AlignmentLoc = Lexer.getLoc(); + if (ParseAbsoluteExpression(Pow2Alignment)) + return true; + } + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in '.comm' directive"); + + Lexer.Lex(); + + // NOTE: a size of zero should create a undefined symbol + if (Size < 0) + return Error(SizeLoc, "invalid '.comm' size, can't be less than zero"); + + // NOTE: The alignment in the directive is a power of 2 value, the assember + // may internally end up wanting an alignment in bytes. + // FIXME: Diagnose overflow. + if (Pow2Alignment < 0) + return Error(Pow2AlignmentLoc, "invalid '.comm' alignment, can't be less " + "than zero"); + + // TODO: Symbol must be undefined or it is a error to re-defined the symbol + if (Sym->getSection() || Ctx.GetSymbolValue(Sym)) + return Error(IDLoc, "invalid symbol redefinition"); + + // TODO: Symbol to be made into a common with this Size and Pow2Alignment + + Out.EmitCommonSymbol(Sym, Size, Pow2Alignment); + + return false; +} Modified: llvm/trunk/tools/llvm-mc/AsmParser.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=74944&r1=74943&r2=74944&view=diff ============================================================================== --- llvm/trunk/tools/llvm-mc/AsmParser.h (original) +++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jul 7 15:30:46 2009 @@ -109,6 +109,8 @@ /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which /// accepts a single symbol (which should be a label or an external). bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr); + + bool ParseDirectiveComm(); // ".comm" }; From evan.cheng at apple.com Tue Jul 7 15:38:18 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 07 Jul 2009 20:38:18 -0000 Subject: [llvm-commits] [llvm] r74945 - in /llvm/trunk/test/CodeGen/Thumb: long_shift.ll mul.ll Message-ID: <200907072038.n67KcJN2030074@zion.cs.uiuc.edu> Author: evancheng Date: Tue Jul 7 15:38:08 2009 New Revision: 74945 URL: http://llvm.org/viewvc/llvm-project?rev=74945&view=rev Log: Add missing tests. Added: llvm/trunk/test/CodeGen/Thumb/long_shift.ll llvm/trunk/test/CodeGen/Thumb/mul.ll Added: llvm/trunk/test/CodeGen/Thumb/long_shift.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb/long_shift.ll?rev=74945&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb/long_shift.ll (added) +++ llvm/trunk/test/CodeGen/Thumb/long_shift.ll Tue Jul 7 15:38:08 2009 @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s | llc -march=thumb + +define i64 @f0(i64 %A, i64 %B) { + %tmp = bitcast i64 %A to i64 + %tmp2 = lshr i64 %B, 1 + %tmp3 = sub i64 %tmp, %tmp2 + ret i64 %tmp3 +} + +define i32 @f1(i64 %x, i64 %y) { + %a = shl i64 %x, %y + %b = trunc i64 %a to i32 + ret i32 %b +} + +define i32 @f2(i64 %x, i64 %y) { + %a = ashr i64 %x, %y + %b = trunc i64 %a to i32 + ret i32 %b +} + +define i32 @f3(i64 %x, i64 %y) { + %a = lshr i64 %x, %y + %b = trunc i64 %a to i32 + ret i32 %b +} Added: llvm/trunk/test/CodeGen/Thumb/mul.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb/mul.ll?rev=74945&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb/mul.ll (added) +++ llvm/trunk/test/CodeGen/Thumb/mul.ll Tue Jul 7 15:38:08 2009 @@ -0,0 +1,22 @@ +; RUN: llvm-as < %s | llc -march=thumb | grep mul | count 3 +; RUN: llvm-as < %s | llc -march=thumb | grep lsl | count 1 + +define i32 @f1(i32 %u) { + %tmp = mul i32 %u, %u + ret i32 %tmp +} + +define i32 @f2(i32 %u, i32 %v) { + %tmp = mul i32 %u, %v + ret i32 %tmp +} + +define i32 @f3(i32 %u) { + %tmp = mul i32 %u, 5 + ret i32 %tmp +} + +define i32 @f4(i32 %u) { + %tmp = mul i32 %u, 4 + ret i32 %tmp +} From evan.cheng at apple.com Tue Jul 7 15:39:04 2009 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 07 Jul 2009 20:39:04 -0000 Subject: [llvm-commits] [llvm] r74946 - in /llvm/trunk: lib/Target/ARM/ARMISelDAGToDAG.cpp lib/Target/ARM/ARMInstrThumb2.td test/CodeGen/Thumb2/thumb2-select.ll test/CodeGen/Thumb2/thumb2-select_xform.ll Message-ID: <200907072039.n67Kd4ed030111@zion.cs.uiuc.edu> Author: evancheng Date: Tue Jul 7 15:39:03 2009 New Revision: 74946 URL: http://llvm.org/viewvc/llvm-project?rev=74946&view=rev Log: Add Thumb2 movcc instructions. Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-select.ll llvm/trunk/test/CodeGen/Thumb2/thumb2-select_xform.ll Modified: llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Modified: llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp?rev=74946&r1=74945&r2=74946&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp (original) +++ llvm/trunk/lib/Target/ARM/ARMISelDAGToDAG.cpp Tue Jul 7 15:39:03 2009 @@ -1031,7 +1031,6 @@ return NULL; } case ARMISD::CMOV: { - bool isThumb = Subtarget->isThumb(); MVT VT = Op.getValueType(); SDValue N0 = Op.getOperand(0); SDValue N1 = Op.getOperand(1); @@ -1041,39 +1040,68 @@ assert(N2.getOpcode() == ISD::Constant); assert(N3.getOpcode() == ISD::Register); - // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc) - // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc) - // Pattern complexity = 18 cost = 1 size = 0 - SDValue CPTmp0; - SDValue CPTmp1; - SDValue CPTmp2; - if (!isThumb && VT == MVT::i32 && - SelectShifterOperandReg(Op, N1, CPTmp0, CPTmp1, CPTmp2)) { - SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned) - cast(N2)->getZExtValue()), - MVT::i32); - SDValue Ops[] = { N0, CPTmp0, CPTmp1, CPTmp2, Tmp2, N3, InFlag }; - return CurDAG->SelectNodeTo(Op.getNode(), ARM::MOVCCs, MVT::i32, Ops, 7); - } + if (!Subtarget->isThumb1Only() && VT == MVT::i32) { + // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc) + // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc) + // Pattern complexity = 18 cost = 1 size = 0 + SDValue CPTmp0; + SDValue CPTmp1; + SDValue CPTmp2; + if (Subtarget->isThumb()) { + if (SelectT2ShifterOperandReg(Op, N1, CPTmp0, CPTmp1)) { + SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned) + cast(N2)->getZExtValue()), + MVT::i32); + SDValue Ops[] = { N0, CPTmp0, CPTmp1, Tmp2, N3, InFlag }; + return CurDAG->SelectNodeTo(Op.getNode(), + ARM::t2MOVCCs, MVT::i32,Ops, 6); + } + } else { + if (SelectShifterOperandReg(Op, N1, CPTmp0, CPTmp1, CPTmp2)) { + SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned) + cast(N2)->getZExtValue()), + MVT::i32); + SDValue Ops[] = { N0, CPTmp0, CPTmp1, CPTmp2, Tmp2, N3, InFlag }; + return CurDAG->SelectNodeTo(Op.getNode(), + ARM::MOVCCs, MVT::i32, Ops, 7); + } + } - // Pattern: (ARMcmov:i32 GPR:i32:$false, - // (imm:i32)<><>:$true, - // (imm:i32):$cc) - // Emits: (MOVCCi:i32 GPR:i32:$false, - // (so_imm_XFORM:i32 (imm:i32):$true), (imm:i32):$cc) - // Pattern complexity = 10 cost = 1 size = 0 - if (VT == MVT::i32 && - N3.getOpcode() == ISD::Constant && - Predicate_so_imm(N3.getNode())) { - SDValue Tmp1 = CurDAG->getTargetConstant(((unsigned) - cast(N1)->getZExtValue()), - MVT::i32); - Tmp1 = Transform_so_imm_XFORM(Tmp1.getNode()); - SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned) - cast(N2)->getZExtValue()), - MVT::i32); - SDValue Ops[] = { N0, Tmp1, Tmp2, N3, InFlag }; - return CurDAG->SelectNodeTo(Op.getNode(), ARM::MOVCCi, MVT::i32, Ops, 5); + // Pattern: (ARMcmov:i32 GPR:i32:$false, + // (imm:i32)<><>:$true, + // (imm:i32):$cc) + // Emits: (MOVCCi:i32 GPR:i32:$false, + // (so_imm_XFORM:i32 (imm:i32):$true), (imm:i32):$cc) + // Pattern complexity = 10 cost = 1 size = 0 + if (N3.getOpcode() == ISD::Constant) { + if (Subtarget->isThumb()) { + if (Predicate_t2_so_imm(N3.getNode())) { + SDValue Tmp1 = CurDAG->getTargetConstant(((unsigned) + cast(N1)->getZExtValue()), + MVT::i32); + Tmp1 = Transform_t2_so_imm_XFORM(Tmp1.getNode()); + SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned) + cast(N2)->getZExtValue()), + MVT::i32); + SDValue Ops[] = { N0, Tmp1, Tmp2, N3, InFlag }; + return CurDAG->SelectNodeTo(Op.getNode(), + ARM::t2MOVCCi, MVT::i32, Ops, 5); + } + } else { + if (Predicate_so_imm(N3.getNode())) { + SDValue Tmp1 = CurDAG->getTargetConstant(((unsigned) + cast(N1)->getZExtValue()), + MVT::i32); + Tmp1 = Transform_so_imm_XFORM(Tmp1.getNode()); + SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned) + cast(N2)->getZExtValue()), + MVT::i32); + SDValue Ops[] = { N0, Tmp1, Tmp2, N3, InFlag }; + return CurDAG->SelectNodeTo(Op.getNode(), + ARM::MOVCCi, MVT::i32, Ops, 5); + } + } + } } // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc) @@ -1094,7 +1122,9 @@ default: assert(false && "Illegal conditional move type!"); break; case MVT::i32: - Opc = isThumb ? ARM::tMOVCCr : ARM::MOVCCr; + Opc = Subtarget->isThumb() + ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr) + : ARM::MOVCCr; break; case MVT::f32: Opc = ARM::FCPYScc; Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td?rev=74946&r1=74945&r2=74946&view=diff ============================================================================== --- llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td (original) +++ llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Tue Jul 7 15:39:03 2009 @@ -1028,7 +1028,24 @@ // Short range conditional branch. Looks awesome for loops. Need to figure // out how to use this one. -// FIXME: Conditional moves + +// Conditional moves +// FIXME: should be able to write a pattern for ARMcmov, but can't use +// a two-value operand where a dag node expects two operands. :( +def t2MOVCCr : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true), + "mov", " $dst, $true", + [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>, + RegConstraint<"$false = $dst">; + +def t2MOVCCs : T2I<(outs GPR:$dst), (ins GPR:$false, t2_so_reg:$true), + "mov", " $dst, $true", +[/*(set GPR:$dst, (ARMcmov GPR:$false, t2_so_reg:$true, imm:$cc, CCR:$ccr))*/]>, + RegConstraint<"$false = $dst">; + +def t2MOVCCi : T2I<(outs GPR:$dst), (ins GPR:$false, t2_so_imm:$true), + "mov", " $dst, $true", +[/*(set GPR:$dst, (ARMcmov GPR:$false, t2_so_imm:$true, imm:$cc, CCR:$ccr))*/]>, + RegConstraint<"$false = $dst">; //===----------------------------------------------------------------------===// // Control-Flow Instructions Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-select.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-select.ll?rev=74946&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb2/thumb2-select.ll (added) +++ llvm/trunk/test/CodeGen/Thumb2/thumb2-select.ll Tue Jul 7 15:39:03 2009 @@ -0,0 +1,48 @@ +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep moveq | count 1 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep movgt | count 1 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep movlt | count 1 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep movle | count 1 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep movls | count 1 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep movhi | count 1 + +define i32 @f1(i32 %a.s) { +entry: + %tmp = icmp eq i32 %a.s, 4 + %tmp1.s = select i1 %tmp, i32 2, i32 3 + ret i32 %tmp1.s +} + +define i32 @f2(i32 %a.s) { +entry: + %tmp = icmp sgt i32 %a.s, 4 + %tmp1.s = select i1 %tmp, i32 2, i32 3 + ret i32 %tmp1.s +} + +define i32 @f3(i32 %a.s, i32 %b.s) { +entry: + %tmp = icmp slt i32 %a.s, %b.s + %tmp1.s = select i1 %tmp, i32 2, i32 3 + ret i32 %tmp1.s +} + +define i32 @f4(i32 %a.s, i32 %b.s) { +entry: + %tmp = icmp sle i32 %a.s, %b.s + %tmp1.s = select i1 %tmp, i32 2, i32 3 + ret i32 %tmp1.s +} + +define i32 @f5(i32 %a.u, i32 %b.u) { +entry: + %tmp = icmp ule i32 %a.u, %b.u + %tmp1.s = select i1 %tmp, i32 2, i32 3 + ret i32 %tmp1.s +} + +define i32 @f6(i32 %a.u, i32 %b.u) { +entry: + %tmp = icmp ugt i32 %a.u, %b.u + %tmp1.s = select i1 %tmp, i32 2, i32 3 + ret i32 %tmp1.s +} Added: llvm/trunk/test/CodeGen/Thumb2/thumb2-select_xform.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-select_xform.ll?rev=74946&view=auto ============================================================================== --- llvm/trunk/test/CodeGen/Thumb2/thumb2-select_xform.ll (added) +++ llvm/trunk/test/CodeGen/Thumb2/thumb2-select_xform.ll Tue Jul 7 15:39:03 2009 @@ -0,0 +1,23 @@ +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep mov | count 3 +; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 | grep mvn | count 1 + +define i32 @t1(i32 %a, i32 %b, i32 %c) nounwind { + %tmp1 = icmp sgt i32 %c, 10 + %tmp2 = select i1 %tmp1, i32 0, i32 2147483647 + %tmp3 = add i32 %tmp2, %b + ret i32 %tmp3 +} + +define i32 @t2(i32 %a, i32 %b, i32 %c) nounwind { + %tmp1 = icmp sgt i32 %c, 10 + %tmp2 = select i1 %tmp1, i32 0, i32 2147483648 + %tmp3 = add i32 %tmp2, %b + ret i32 %tmp3 +} + +define i32 @t3(i32 %a, i32 %b, i32 %c, i32 %d) nounwind { + %tmp1 = icmp sgt i32 %c, 10 + %tmp2 = select i1 %tmp1, i32 0, i32 10 + %tmp3 = sub i32 %b, %tmp2 + ret i32 %tmp3 +} From gohman at apple.com Tue Jul 7 15:47:54 2009 From: gohman at apple.com (Dan Gohman) Date: Tue, 07 Jul 2009 20:47:54 -0000 Subject: [llvm-commits] [llvm] r74947 - /llvm/trunk/include/llvm/Instructions.h Message-ID: <200907072047.n67KltBR030489@zion.cs.uiuc.edu> Author: djg Date: Tue Jul 7 15:47:48 2009 New Revision: 74947 URL: http://llvm.org/viewvc/llvm-project?rev=74947&view=rev Log: Fix a typo and a grammaro in a comment. Modified: llvm/trunk/include/llvm/Instructions.h Modified: llvm/trunk/include/llvm/Instructions.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=74947&r1=74946&r2=74947&view=diff ============================================================================== --- llvm/trunk/include/llvm/Instructions.h (original) +++ llvm/trunk/include/llvm/Instructions.h Tue Jul 7 15:47:48 2009 @@ -51,7 +51,7 @@ /// bool isArrayAllocation() const; - /// getArraySize - Get the number of element allocated, for a simple + /// getArraySize - Get the number of elements allocated. For a simple /// allocation of a single element, this will return a constant 1 value. /// const Value *getArraySize() const { return getOperand(0); } From resistor at mac.com Tue Jul 7 16:07:16 2009 From: resistor at mac.com (Owen Anderson) Date: Tue, 07 Jul 2009 21:07:16 -0000 Subject: [llvm-commits] [llvm] r74948 - /llvm/trunk/lib/Linker/LinkModules.cpp Message-ID: <200907072107.n67L7GrB031392@zion.cs.uiuc.edu> Author: resistor Date: Tue Jul 7 16:07:14 2009 New Revision: 74948 URL: http://llvm.org/viewvc/llvm-project?rev=74948&view=rev Log: LLVM Context-ification. Modified: llvm/trunk/lib/Linker/LinkModules.cpp Modified: llvm/trunk/lib/Linker/LinkModules.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=74948&r1=74947&r2=74948&view=diff ============================================================================== --- llvm/trunk/lib/Linker/LinkModules.cpp (original) +++ llvm/trunk/lib/Linker/LinkModules.cpp Tue Jul 7 16:07:14 2009 @@ -19,6 +19,7 @@ #include "llvm/Linker.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/TypeSymbolTable.h" #include "llvm/ValueSymbolTable.h" @@ -348,7 +349,8 @@ // RemapOperand - Use ValueMap to convert constants from one module to another. static Value *RemapOperand(const Value *In, - std::map &ValueMap) { + std::map &ValueMap, + LLVMContext &Context) { std::map::const_iterator I = ValueMap.find(In); if (I != ValueMap.end()) return I->second; @@ -363,24 +365,30 @@ if (const ConstantArray *CPA = dyn_cast(CPV)) { std::vector Operands(CPA->getNumOperands()); for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i) - Operands[i] =cast(RemapOperand(CPA->getOperand(i), ValueMap)); - Result = ConstantArray::get(cast(CPA->getType()), Operands); + Operands[i] =cast(RemapOperand(CPA->getOperand(i), ValueMap, + Context)); + Result = + Context.getConstantArray(cast(CPA->getType()), Operands); } else if (const ConstantStruct *CPS = dyn_cast(CPV)) { std::vector Operands(CPS->getNumOperands()); for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i) - Operands[i] =cast(RemapOperand(CPS->getOperand(i), ValueMap)); - Result = ConstantStruct::get(cast(CPS->getType()), Operands); + Operands[i] =cast(RemapOperand(CPS->getOperand(i), ValueMap, + Context)); + Result = + Context.getConstantStruct(cast(CPS->getType()), Operands); } else if (isa(CPV) || isa(CPV)) { Result = const_cast(CPV); } else if (const ConstantVector *CP = dyn_cast(CPV)) { std::vector Operands(CP->getNumOperands()); for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) - Operands[i] = cast(RemapOperand(CP->getOperand(i), ValueMap)); - Result = ConstantVector::get(Operands); + Operands[i] = cast(RemapOperand(CP->getOperand(i), ValueMap, + Context)); + Result = Context.getConstantVector(Operands); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { std::vector Ops; for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) - Ops.push_back(cast(RemapOperand(CE->getOperand(i),ValueMap))); + Ops.push_back(cast(RemapOperand(CE->getOperand(i),ValueMap, + Context))); Result = CE->getWithOperands(Ops); } else { assert(!isa(CPV) && "Unmapped global?"); @@ -528,6 +536,7 @@ std::multimap &AppendingVars, std::string *Err) { ValueSymbolTable &DestSymTab = Dest->getValueSymbolTable(); + LLVMContext &Context = Dest->getContext(); // Loop over all of the globals in the src module, mapping them over as we go for (Module::const_global_iterator I = Src->global_begin(), @@ -631,7 +640,8 @@ // Propagate alignment, section, and visibility info. CopyGVAttributes(NewDGV, SGV); - DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV, DGV->getType())); + DGV->replaceAllUsesWith(Context.getConstantExprBitCast(NewDGV, + DGV->getType())); // DGV will conflict with NewDGV because they both had the same // name. We must erase this now so ForceRenaming doesn't assert @@ -677,7 +687,7 @@ DGV->setLinkage(NewLinkage); // Make sure to remember this mapping... - ValueMap[SGV] = ConstantExpr::getBitCast(DGV, SGV->getType()); + ValueMap[SGV] = Context.getConstantExprBitCast(DGV, SGV->getType()); } return false; } @@ -710,6 +720,8 @@ static bool LinkAlias(Module *Dest, const Module *Src, std::map &ValueMap, std::string *Err) { + LLVMContext &Context = Dest->getContext(); + // Loop over all alias in the src module for (Module::const_alias_iterator I = Src->alias_begin(), E = Src->alias_end(); I != E; ++I) { @@ -782,7 +794,7 @@ // Any uses of DGV need to change to NewGA, with cast, if needed. if (SGA->getType() != DGVar->getType()) - DGVar->replaceAllUsesWith(ConstantExpr::getBitCast(NewGA, + DGVar->replaceAllUsesWith(Context.getConstantExprBitCast(NewGA, DGVar->getType())); else DGVar->replaceAllUsesWith(NewGA); @@ -811,7 +823,7 @@ // Any uses of DF need to change to NewGA, with cast, if needed. if (SGA->getType() != DF->getType()) - DF->replaceAllUsesWith(ConstantExpr::getBitCast(NewGA, + DF->replaceAllUsesWith(Context.getConstantExprBitCast(NewGA, DF->getType())); else DF->replaceAllUsesWith(NewGA); @@ -866,7 +878,8 @@ if (SGV->hasInitializer()) { // Only process initialized GV's // Figure out what the initializer looks like in the dest module... Constant *SInit = - cast(RemapOperand(SGV->getInitializer(), ValueMap)); + cast(RemapOperand(SGV->getInitializer(), ValueMap, + Dest->getContext())); // Grab destination global variable or alias. GlobalValue *DGV = cast(ValueMap[SGV]->stripPointerCasts()); @@ -914,6 +927,7 @@ std::map &ValueMap, std::string *Err) { ValueSymbolTable &DestSymTab = Dest->getValueSymbolTable(); + LLVMContext &Context = Dest->getContext(); // Loop over all of the functions in the src module, mapping them over for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { @@ -979,7 +993,8 @@ CopyGVAttributes(NewDF, SF); // Any uses of DF need to change to NewDF, with cast - DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF, DGV->getType())); + DGV->replaceAllUsesWith(Context.getConstantExprBitCast(NewDF, + DGV->getType())); // DF will conflict with NewDF because they both had the same. We must // erase this now so ForceRenaming doesn't assert because DF might @@ -1017,7 +1032,7 @@ DGV->setLinkage(NewLinkage); // Make sure to remember this mapping. - ValueMap[SF] = ConstantExpr::getBitCast(DGV, SF->getType()); + ValueMap[SF] = Context.getConstantExprBitCast(DGV, SF->getType()); } return false; } @@ -1053,7 +1068,7 @@ for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE; ++OI) if (!isa(*OI) && !isa(*OI)) - *OI = RemapOperand(*OI, ValueMap); + *OI = RemapOperand(*OI, ValueMap, *Dest->getContext()); // There is no need to map the arguments anymore. for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end(); @@ -1094,6 +1109,8 @@ std::string *ErrorMsg) { if (AppendingVars.empty()) return false; // Nothing to do. + LLVMContext &Context = M->getContext(); + // Loop over the multimap of appending vars, processing any variables with the // same name, forming a new appending global variable with both of the // initializers merged together, then rewrite references to the old variables @@ -1132,7 +1149,8 @@ "Appending variables with different section name need to be linked!"); unsigned NewSize = T1->getNumElements() + T2->getNumElements(); - ArrayType *NewType = ArrayType::get(T1->getElementType(), NewSize); + ArrayType *NewType = Context.getArrayType(T1->getElementType(), + NewSize); G1->setName(""); // Clear G1's name in case of a conflict! @@ -1152,7 +1170,7 @@ Inits.push_back(I->getOperand(i)); } else { assert(isa(G1->getInitializer())); - Constant *CV = Constant::getNullValue(T1->getElementType()); + Constant *CV = Context.getNullValue(T1->getElementType()); for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) Inits.push_back(CV); } @@ -1161,11 +1179,11 @@ Inits.push_back(I->getOperand(i)); } else { assert(isa(G2->getInitializer())); - Constant *CV = Constant::getNullValue(T2->getElementType()); + Constant *CV = Context.getNullValue(T2->getElementType()); for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) Inits.push_back(CV); } - NG->setInitializer(ConstantArray::get(NewType, Inits)); + NG->setInitializer(Context.getConstantArray(NewType, Inits)); Inits.clear(); // Replace any uses of the two global variables with uses of the new @@ -1173,8 +1191,10 @@ // FIXME: This should rewrite simple/straight-forward uses such as // getelementptr instructions to not use the Cast! - G1->replaceAllUsesWith(ConstantExpr::getBitCast(NG, G1->getType())); - G2->replaceAllUsesWith(ConstantExpr::getBitCast(NG, G2->getType())); + G1->replaceAllUsesWith(Context.getConstantExprBitCast(NG, + G1->getType())); + G2->replaceAllUsesWith(Context.getConstantExprBitCast(NG, + G2->getType())); // Remove the two globals from the module now... M->getGlobalList().erase(G1); From dpatel at apple.com Tue Jul 7 16:12:32 2009 From: dpatel at apple.com (Devang Patel) Date: Tue, 07 Jul 2009 21:12:32 -0000 Subject: [llvm-commits] [llvm] r74949 - in /llvm/trunk/lib/CodeGen/AsmPrinter: DwarfDebug.cpp DwarfDebug.h Message-ID: <200907072112.n67LCWT1031690@zion.cs.uiuc.edu> Author: dpatel Date: Tue Jul 7 16:12:32 2009 New Revision: 74949 URL: http://llvm.org/viewvc/llvm-project?rev=74949&view=rev Log: Remove dead code. Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=74949&r1=74948&r2=74949&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original) +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Jul 7 16:12:32 2009 @@ -1622,33 +1622,8 @@ DIVariable DV(GV); GlobalVariable *V = DV.getContext().getGV(); - // FIXME: The code that checks for the inlined local variable is a hack! - DenseMap::iterator - AI = AbstractInstanceRootMap.find(V); - - if (AI != AbstractInstanceRootMap.end()) { - // This method is called each time a DECLARE node is encountered. For an - // inlined function, this could be many, many times. We don't want to - // re-add variables to that DIE for each time. We just want to add them - // once. Check to make sure that we haven't added them already. - DenseMap >::iterator - IP = InlinedParamMap.find(V); - - if (IP != InlinedParamMap.end() && IP->second.count(GV) > 0) { - if (TimePassesIsEnabled) - DebugTimer->stopTimer(); - return; - } - - // or GV is an inlined local variable. - Scope = AI->second; - InlinedParamMap[V].insert(GV); - InlinedFnVar = true; - } else { - // or GV is a local variable. - Scope = getOrCreateScope(V); - } + // or GV is a local variable. + Scope = getOrCreateScope(V); } } Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=74949&r1=74948&r2=74949&view=diff ============================================