From lattner at cs.uiuc.edu Mon May 24 00:38:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon May 24 00:38:03 2004 Subject: [llvm-commits] CVS: llvm/docs/ReleaseNotes.html Message-ID: <200405240535.AAA01008@zion.cs.uiuc.edu> Changes in directory llvm/docs: ReleaseNotes.html updated: 1.186 -> 1.187 --- Log message: new feature --- Diffs of the changes: (+3 -1) Index: llvm/docs/ReleaseNotes.html diff -u llvm/docs/ReleaseNotes.html:1.186 llvm/docs/ReleaseNotes.html:1.187 --- llvm/docs/ReleaseNotes.html:1.186 Sun May 23 23:53:32 2004 +++ llvm/docs/ReleaseNotes.html Mon May 24 00:34:32 2004 @@ -112,6 +112,8 @@ collectors.
  • LLVM now includes an implementation of Andersen's interprocedural alias analysis algorithm.
  • +
  • Bugpoint can extract individual +basic blocks to track down reduce miscompilation testcases.
  • @@ -675,7 +677,7 @@ src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /> The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/24 04:53:32 $ + Last modified: $Date: 2004/05/24 05:34:32 $ From lattner at cs.uiuc.edu Mon May 24 00:38:08 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon May 24 00:38:08 2004 Subject: [llvm-commits] CVS: llvm/docs/BytecodeFormat.html Message-ID: <200405240535.AAA01003@zion.cs.uiuc.edu> Changes in directory llvm/docs: BytecodeFormat.html updated: 1.5 -> 1.6 --- Log message: Lots of minor typo fixes, some minor inaccuracies fixed, and some new material. --- Diffs of the changes: (+62 -38) Index: llvm/docs/BytecodeFormat.html diff -u llvm/docs/BytecodeFormat.html:1.5 llvm/docs/BytecodeFormat.html:1.6 --- llvm/docs/BytecodeFormat.html:1.5 Sun May 23 23:55:32 2004 +++ llvm/docs/BytecodeFormat.html Mon May 24 00:35:17 2004 @@ -46,8 +46,8 @@
    Abstract
    -

    This document is an (after the fact) specification of the LLVM bytecode -file format. It documents the binary encoding rules of the bytecode file format +

    This document describes the LLVM bytecode +file format. It specifies the binary encoding rules of the bytecode file format so that equivalent systems can encode bytecode files correctly. The LLVM bytecode representation is used to store the intermediate representation on disk in compacted form. @@ -58,7 +58,10 @@

    This section describes the general concepts of the bytecode file format -without getting into bit and byte level specifics.

    +without getting into bit and byte level specifics. Note that the LLVM bytecode +format may change in the future, but will always be backwards compatible with +older formats. This document only describes the most current version of the +bytecode format.

    Blocks
    @@ -83,19 +86,20 @@
  • InstructionList (0x32).
  • CompactionTable (0x33).
  • -

    All blocks are variable length. They consume just enough bytes to express -their contents. Each block begins with an integer identifier and the length -of the block.

    +

    All blocks are variable length, and the block header specifies the size of +the block. All blocks are rounded aligned to even 32-bit boundaries, so they +always start and end of this boundary. Each block begins with an integer +identifier and the length of the block, which does not include the padding +bytes needed for alignment.

    Lists

    Most blocks are constructed of lists of information. Lists can be constructed of other lists, etc. This decomposition of information follows the containment -hierarchy of the LLVM Intermediate Representation. For example, a function is -composed of a list of basic blocks. Each basic block is composed of a set of -instructions. This list of list nesting and hierarchy is maintained in the -bytecode file.

    +hierarchy of the LLVM Intermediate Representation. For example, a function +contains a list of instructions (the terminator instructions implicitly define +the end of the basic blocks).

    A list is encoded into the file simply by encoding the number of entries as an integer followed by each of the entries. The reader knows when the list is done because it will have filled the list with the required numbe of entries. @@ -106,7 +110,7 @@

    Fields are units of information that LLVM knows how to write atomically. Most fields have a uniform length or some kind of length indication built into -their encoding. For example, a constant string (array of SByte or UByte) is +their encoding. For example, a constant string (array of bytes) is written simply as the length followed by the characters. Although this is similar to a list, constant strings are treated atomically and are thus fields.

    @@ -121,7 +125,8 @@

    Each field that can be put out is encoded into the file using a small set of primitives. The rules for these primitives are described below.

    Variable Bit Rate Encoding

    -

    To minimize the number of bytes written for small quantities, an encoding +

    Most of the values written to LLVM bytecode files are small integers. To +minimize the number of bytes written for these quantities, an encoding scheme similar to UTF-8 is used to write integer data. The scheme is known as variable bit rate (vbr) encoding. In this encoding, the high bit of each byte is used to indicate if more bytes follow. If (byte & 0x80) is non-zero @@ -148,8 +153,15 @@ 956-629,223,372,036,854,775,807 1063-691,180,591,620,717,411,303,423 -

    Note that in practice, the tenth byte could only encode bits 63 and 64 +

    Note that in practice, the tenth byte could only encode bit 63 since the maximum quantity to use this encoding is a 64-bit integer.

    + +

    Signed VBR values are encoded with the standard vbr encoding, but +with the sign bit as the low order bit instead of the high order bit. This +allows small negative quantities to be encoded efficiently. For example, -3 +is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << 1) | +0)", emitted with the standard vbr encoding above.

    +

    The table below defines the encoding rules for type names used in the descriptions of blocks and fields in the next section. Any type name with the suffix _vbr indicate a quantity that is encoded using @@ -176,7 +188,7 @@ int64_vbr A 64-bit signed integer that occupies from one to ten - bytes using variable bit rate encoding. + bytes using the signed variable bit rate encoding. char A single unsigned character encoded into one byte @@ -187,8 +199,7 @@ string A uint_vbr indicating the length of the character string immediately followed by the characters of the string. There is no - terminating null byte in the string. Characters are interpreted as unsigned - char and are generally US-ASCII encoded. + terminating null byte in the string. data An arbitrarily long segment of data to which no @@ -219,18 +230,18 @@ fields in detail. These descriptions are provided in tabular form. Each table has four columns that specify:

      -
    1. Byte(s). The offset in bytes of the field from the start of +
    2. Byte(s): The offset in bytes of the field from the start of its container (block, list, other field).
    3. -
    4. Bit(s). The offset in bits of the field from the start of +
    5. Bit(s): The offset in bits of the field from the start of the byte field. Bits are always little endian. That is, bit addresses with smaller values have smaller address (i.e. 20 is at bit 0, 21 at 1, etc.)
    6. -
    7. Align? Indicates if this field is aligned to 32 bits or not. +
    8. Align?: Indicates if this field is aligned to 32 bits or not. This indicates where the next field starts, always on a 32 bit boundary.
    9. -
    10. Type. The basic type of information contained in the field.
    11. -
    12. Description. Descripts the contents of the field.
    13. +
    14. Type: The basic type of information contained in the field.
    15. +
    16. Description: Describes the contents of the field.
    @@ -240,20 +251,21 @@ of bytes known as blocks. The blocks are written sequentially to the file in the following order:

      -
    1. Signature. This block contains the file signature - (magic number) that identifies the file as LLVM bytecode.
    2. -
    3. Module Block. This is the top level block in a +
    4. Signature: This contains the file signature + (magic number) that identifies the file as LLVM bytecode and the bytecode + version number.
    5. +
    6. Module Block: This is the top level block in a bytecode file. It contains all the other blocks.
    7. -
    8. Global Type Pool. This block contains all the +
    9. Global Type Pool: This block contains all the global (module) level types.
    10. -
    11. Module Info. This block contains the types of the +
    12. Module Info: This block contains the types of the global variables and functions in the module as well as the constant initializers for the global variables
    13. -
    14. Constants. This block contains all the global +
    15. Constants: This block contains all the global constants except function arguments, global values and constant strings.
    16. -
    17. Functions. One function block is written for +
    18. Functions: One function block is written for each function in the module.
    19. -
    20. Symbol Table. The module level symbol table that +
    21. Symbol Table: The module level symbol table that provides names for the various other entries in the file is the final block written.
    @@ -261,7 +273,7 @@
    Signature Block
    -

    The signature block occurs in every LLVM bytecode file and is always first. +

    The signature occurs in every LLVM bytecode file and is always first. It simply provides a few bytes of data to identify the file as being an LLVM bytecode file. This block is always four bytes in length and differs from the other blocks because there is no identifier and no block length at the start @@ -294,12 +306,18 @@

    The module block contains a small pre-amble and all the other blocks in the file. Of particular note, the bytecode format number is simply a 28-bit monotonically increase integer that identifiers the version of the bytecode -format. While the bytecode format version is not related to the LLVM release -(it doesn't automatically get increased with each new LLVM release), there is -a definite correspondence between the bytecode format version and the LLVM -release.

    -

    The table below shows the format of the module block header. The blocks it -contains are detailed in other sections.

    +format (which is not directly related to the LLVM release number). The +bytecode versions defined so far are (note that this document only describes +the latest version):

    + + + +

    The table below shows the format of the module block header. It is defined +by blocks described in other sections.

    @@ -337,11 +355,17 @@ solely of other block types in sequence.
    Byte(s)
    + +

    Note that we plan to eventually expand the target description capabilities +of bytecode files to target +triples.

    +
    +
    Global Type Pool
    -

    The global type pool consists of type definitions. Their order of appearnce +

    The global type pool consists of type definitions. Their order of appearance in the file determines their slot number (0 based). Slot numbers are used to replace pointers in the intermediate representation. Each slot number uniquely identifies one entry in a type plane (a collection of values of the same type). @@ -447,7 +471,7 @@ Reid Spencer and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/24 04:55:32 $ + Last modified: $Date: 2004/05/24 05:35:17 $ From tbrethou at cs.uiuc.edu Mon May 24 01:13:02 2004 From: tbrethou at cs.uiuc.edu (Tanya Brethour) Date: Mon May 24 01:13:02 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/MachineFunction.cpp MachineBasicBlock.cpp Message-ID: <200405240611.BAA28931@seraph.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: MachineFunction.cpp updated: 1.56 -> 1.57 MachineBasicBlock.cpp updated: 1.11 -> 1.12 --- Log message: Added MachineFunction parent* to MachineBasicBlock. Customized ilist template to set the parent when a MachineBasicBlock is added to a MachineFunction. --- Diffs of the changes: (+34 -14) Index: llvm/lib/CodeGen/MachineFunction.cpp diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.56 llvm/lib/CodeGen/MachineFunction.cpp:1.57 --- llvm/lib/CodeGen/MachineFunction.cpp:1.56 Wed May 12 16:35:23 2004 +++ llvm/lib/CodeGen/MachineFunction.cpp Mon May 24 01:11:46 2004 @@ -24,6 +24,8 @@ #include "llvm/Target/TargetFrameInfo.h" #include "llvm/Function.h" #include "llvm/iOther.h" +#include "Support/LeakDetector.h" + using namespace llvm; static AnnotationID MF_AID( @@ -84,6 +86,22 @@ //===---------------------------------------------------------------------===// // MachineFunction implementation //===---------------------------------------------------------------------===// +MachineBasicBlock* ilist_traits::createNode() +{ + MachineBasicBlock* dummy = new MachineBasicBlock(); + LeakDetector::removeGarbageObject(dummy); + return dummy; +} + +void ilist_traits::transferNodesFromList( + iplist >& toList, + ilist_iterator first, + ilist_iterator last) +{ + if (parent != toList.parent) + for (; first != last; ++first) + first->Parent = toList.parent; +} MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM) @@ -92,6 +110,7 @@ MFInfo = new MachineFunctionInfo(*this); FrameInfo = new MachineFrameInfo(); ConstantPool = new MachineConstantPool(); + BasicBlocks.parent = this; } MachineFunction::~MachineFunction() { Index: llvm/lib/CodeGen/MachineBasicBlock.cpp diff -u llvm/lib/CodeGen/MachineBasicBlock.cpp:1.11 llvm/lib/CodeGen/MachineBasicBlock.cpp:1.12 --- llvm/lib/CodeGen/MachineBasicBlock.cpp:1.11 Sun May 23 22:44:52 2004 +++ llvm/lib/CodeGen/MachineBasicBlock.cpp Mon May 24 01:11:47 2004 @@ -20,29 +20,25 @@ #include "Support/LeakDetector.h" using namespace llvm; -const MachineFunction *MachineBasicBlock::getParent() const { - // Get the parent by getting the Function parent of the basic block, and - // getting the MachineFunction from it. - return &MachineFunction::get(getBasicBlock()->getParent()); -} - -MachineFunction *MachineBasicBlock::getParent() { - // Get the parent by getting the Function parent of the basic block, and - // getting the MachineFunction from it. - return &MachineFunction::get(getBasicBlock()->getParent()); -} - // MBBs start out as #-1. When a MBB is added to a MachineFunction, it // gets the next available unique MBB number. If it is removed from a // MachineFunction, it goes back to being #-1. void ilist_traits::addNodeToList (MachineBasicBlock* N) { - N->Number = N->getParent ()->getNextMBBNumber (); + assert(N->Parent == 0 && "machine instruction already in a basic block"); + N->Parent = parent; + N->Number = parent->getNextMBBNumber(); + LeakDetector::removeGarbageObject(N); + + } void ilist_traits::removeNodeFromList (MachineBasicBlock* N) { + assert(N->Parent != 0 && "machine instruction not in a basic block"); + N->Parent = 0; N->Number = -1; + LeakDetector::addGarbageObject(N); } @@ -93,8 +89,13 @@ void MachineBasicBlock::print(std::ostream &OS) const { + if(!getParent()) { + OS << "Can't print out MachineBasicBlock because parent MachineFunction is null\n"; + return; + } const BasicBlock *LBB = getBasicBlock(); - OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n"; + if(LBB) + OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n"; for (const_iterator I = begin(); I != end(); ++I) { OS << "\t"; I->print(OS, getParent()->getTarget()); From tbrethou at cs.uiuc.edu Mon May 24 01:14:02 2004 From: tbrethou at cs.uiuc.edu (Tanya Brethour) Date: Mon May 24 01:14:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineBasicBlock.h MachineFunction.h Message-ID: <200405240612.BAA28940@seraph.cs.uiuc.edu> Changes in directory llvm/include/llvm/CodeGen: MachineBasicBlock.h updated: 1.32 -> 1.33 MachineFunction.h updated: 1.33 -> 1.34 --- Log message: Added MachineFunction parent* to MachineBasicBlock. Customized ilist template to set the parent when a MachineBasicBlock is added to a MachineFunction. --- Diffs of the changes: (+37 -3) Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h diff -u llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.32 llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.33 --- llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.32 Wed May 12 16:57:23 2004 +++ llvm/include/llvm/CodeGen/MachineBasicBlock.h Mon May 24 01:11:51 2004 @@ -64,10 +64,11 @@ std::vector Predecessors; std::vector Successors; int Number; + MachineFunction *Parent; public: MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb), - Number(-1) { + Number(-1), Parent(0) { Insts.parent = this; } ~MachineBasicBlock() {} @@ -79,8 +80,8 @@ /// getParent - Return the MachineFunction containing this basic block. /// - const MachineFunction *getParent() const; - MachineFunction *getParent(); + const MachineFunction *getParent() const { return Parent; } + MachineFunction *getParent() { return Parent; } typedef ilist::iterator iterator; typedef ilist::const_iterator const_iterator; Index: llvm/include/llvm/CodeGen/MachineFunction.h diff -u llvm/include/llvm/CodeGen/MachineFunction.h:1.33 llvm/include/llvm/CodeGen/MachineFunction.h:1.34 --- llvm/include/llvm/CodeGen/MachineFunction.h:1.33 Wed May 12 16:35:21 2004 +++ llvm/include/llvm/CodeGen/MachineFunction.h Mon May 24 01:11:51 2004 @@ -23,6 +23,39 @@ namespace llvm { +// ilist_traits +template <> +class ilist_traits { + // this is only set by the MachineFunction owning the ilist + friend class MachineFunction; + MachineFunction* parent; + +public: + ilist_traits() : parent(0) { } + + static MachineBasicBlock* getPrev(MachineBasicBlock* N) { return N->Prev; } + static MachineBasicBlock* getNext(MachineBasicBlock* N) { return N->Next; } + + static const MachineBasicBlock* + getPrev(const MachineBasicBlock* N) { return N->Prev; } + + static const MachineBasicBlock* + getNext(const MachineBasicBlock* N) { return N->Next; } + + static void setPrev(MachineBasicBlock* N, MachineBasicBlock* prev) { N->Prev = prev; } + static void setNext(MachineBasicBlock* N, MachineBasicBlock* next) { N->Next = next; } + + static MachineBasicBlock* createNode(); + void addNodeToList(MachineBasicBlock* N); + void removeNodeFromList(MachineBasicBlock* N); + void transferNodesFromList( + iplist >& toList, + ilist_iterator first, + ilist_iterator last); +}; + + + class Function; class TargetMachine; class SSARegMap; From lattner at cs.uiuc.edu Mon May 24 01:27:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon May 24 01:27:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/Inliner.cpp Message-ID: <200405240624.BAA10388@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: Inliner.cpp updated: 1.14 -> 1.15 --- Log message: Fix a bug in my previous checkin --- Diffs of the changes: (+1 -0) Index: llvm/lib/Transforms/IPO/Inliner.cpp diff -u llvm/lib/Transforms/IPO/Inliner.cpp:1.14 llvm/lib/Transforms/IPO/Inliner.cpp:1.15 --- llvm/lib/Transforms/IPO/Inliner.cpp:1.14 Sun May 23 16:22:17 2004 +++ llvm/lib/Transforms/IPO/Inliner.cpp Mon May 24 01:24:46 2004 @@ -125,6 +125,7 @@ if (Callee->isExternal() || CallSites[CSi].getInstruction()->getParent()->getParent() ==Callee){ std::swap(CallSites[CSi], CallSites.back()); + CallSites.pop_back(); --CSi; continue; } From tbrethou at cs.uiuc.edu Mon May 24 02:16:01 2004 From: tbrethou at cs.uiuc.edu (Tanya Brethour) Date: Mon May 24 02:16:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineBasicBlock.h MachineFunction.h Message-ID: <200405240714.CAA15853@seraph.cs.uiuc.edu> Changes in directory llvm/include/llvm/CodeGen: MachineBasicBlock.h updated: 1.33 -> 1.34 MachineFunction.h updated: 1.34 -> 1.35 --- Log message: Moved MachineBasicBlock deconstructor to cpp file and removed it from LeakDetector to fix memory leak bug. --- Diffs of the changes: (+6 -5) Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h diff -u llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.33 llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.34 --- llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.33 Mon May 24 01:11:51 2004 +++ llvm/include/llvm/CodeGen/MachineBasicBlock.h Mon May 24 02:14:33 2004 @@ -71,7 +71,8 @@ Number(-1), Parent(0) { Insts.parent = this; } - ~MachineBasicBlock() {} + + ~MachineBasicBlock(); /// getBasicBlock - Return the LLVM basic block that this instance /// corresponded to originally. Index: llvm/include/llvm/CodeGen/MachineFunction.h diff -u llvm/include/llvm/CodeGen/MachineFunction.h:1.34 llvm/include/llvm/CodeGen/MachineFunction.h:1.35 --- llvm/include/llvm/CodeGen/MachineFunction.h:1.34 Mon May 24 01:11:51 2004 +++ llvm/include/llvm/CodeGen/MachineFunction.h Mon May 24 02:14:35 2004 @@ -28,10 +28,10 @@ class ilist_traits { // this is only set by the MachineFunction owning the ilist friend class MachineFunction; - MachineFunction* parent; + MachineFunction* Parent; public: - ilist_traits() : parent(0) { } + ilist_traits() : Parent(0) { } static MachineBasicBlock* getPrev(MachineBasicBlock* N) { return N->Prev; } static MachineBasicBlock* getNext(MachineBasicBlock* N) { return N->Next; } @@ -68,7 +68,7 @@ const TargetMachine &Target; // List of machine basic blocks in function - iplist BasicBlocks; + ilist BasicBlocks; // Keeping track of mapping from SSA values to registers SSARegMap *SSARegMapping; @@ -145,7 +145,7 @@ static MachineFunction& get(const Function *F); // Provide accessors for the MachineBasicBlock list... - typedef iplist BasicBlockListType; + typedef ilist BasicBlockListType; typedef BasicBlockListType::iterator iterator; typedef BasicBlockListType::const_iterator const_iterator; typedef std::reverse_iterator const_reverse_iterator; From tbrethou at cs.uiuc.edu Mon May 24 02:16:06 2004 From: tbrethou at cs.uiuc.edu (Tanya Brethour) Date: Mon May 24 02:16:06 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/MachineFunction.cpp MachineBasicBlock.cpp Message-ID: <200405240714.CAA15844@seraph.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: MachineFunction.cpp updated: 1.57 -> 1.58 MachineBasicBlock.cpp updated: 1.12 -> 1.13 --- Log message: Moved MachineBasicBlock deconstructor to cpp file and removed it from LeakDetector to fix memory leak bug. --- Diffs of the changes: (+11 -5) Index: llvm/lib/CodeGen/MachineFunction.cpp diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.57 llvm/lib/CodeGen/MachineFunction.cpp:1.58 --- llvm/lib/CodeGen/MachineFunction.cpp:1.57 Mon May 24 01:11:46 2004 +++ llvm/lib/CodeGen/MachineFunction.cpp Mon May 24 02:14:26 2004 @@ -98,9 +98,9 @@ ilist_iterator first, ilist_iterator last) { - if (parent != toList.parent) + if (Parent != toList.Parent) for (; first != last; ++first) - first->Parent = toList.parent; + first->Parent = toList.Parent; } MachineFunction::MachineFunction(const Function *F, @@ -110,7 +110,7 @@ MFInfo = new MachineFunctionInfo(*this); FrameInfo = new MachineFrameInfo(); ConstantPool = new MachineConstantPool(); - BasicBlocks.parent = this; + BasicBlocks.Parent = this; } MachineFunction::~MachineFunction() { Index: llvm/lib/CodeGen/MachineBasicBlock.cpp diff -u llvm/lib/CodeGen/MachineBasicBlock.cpp:1.12 llvm/lib/CodeGen/MachineBasicBlock.cpp:1.13 --- llvm/lib/CodeGen/MachineBasicBlock.cpp:1.12 Mon May 24 01:11:47 2004 +++ llvm/lib/CodeGen/MachineBasicBlock.cpp Mon May 24 02:14:27 2004 @@ -20,14 +20,20 @@ #include "Support/LeakDetector.h" using namespace llvm; +MachineBasicBlock::~MachineBasicBlock() { + LeakDetector::removeGarbageObject(this); +} + + + // MBBs start out as #-1. When a MBB is added to a MachineFunction, it // gets the next available unique MBB number. If it is removed from a // MachineFunction, it goes back to being #-1. void ilist_traits::addNodeToList (MachineBasicBlock* N) { assert(N->Parent == 0 && "machine instruction already in a basic block"); - N->Parent = parent; - N->Number = parent->getNextMBBNumber(); + N->Parent = Parent; + N->Number = Parent->getNextMBBNumber(); LeakDetector::removeGarbageObject(N); From alkis at cs.uiuc.edu Mon May 24 03:30:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 03:30:02 2004 Subject: [llvm-commits] CVS: llvm-java/test/ClassFile/Simple.java Message-ID: <200405240827.DAA27651@zion.cs.uiuc.edu> Changes in directory llvm-java/test/ClassFile: Simple.java updated: 1.2 -> 1.3 --- Log message: Declare constructor as private so that code for it is not emitted. --- Diffs of the changes: (+4 -1) Index: llvm-java/test/ClassFile/Simple.java diff -u llvm-java/test/ClassFile/Simple.java:1.2 llvm-java/test/ClassFile/Simple.java:1.3 --- llvm-java/test/ClassFile/Simple.java:1.2 Wed May 19 16:10:18 2004 +++ llvm-java/test/ClassFile/Simple.java Mon May 24 03:27:20 2004 @@ -2,8 +2,11 @@ public class Simple { + private Simple() { + // declare constructor private so that it is not emitted + } + public static int main(String[] args) { return 0; } } - From gaeke at cs.uiuc.edu Mon May 24 03:56:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 24 03:56:01 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/TraceToFunction.h Message-ID: <200405240854.DAA17106@seraph.cs.uiuc.edu> Changes in directory reopt/include/reopt: TraceToFunction.h updated: 1.13 -> 1.14 --- Log message: Allow getCorrespondingValue to ignore live-in values on request. --- Diffs of the changes: (+7 -3) Index: reopt/include/reopt/TraceToFunction.h diff -u reopt/include/reopt/TraceToFunction.h:1.13 reopt/include/reopt/TraceToFunction.h:1.14 --- reopt/include/reopt/TraceToFunction.h:1.13 Sun May 23 05:09:43 2004 +++ reopt/include/reopt/TraceToFunction.h Mon May 24 03:54:45 2004 @@ -78,10 +78,14 @@ /// ValueToIntMap LiveInToParameterMap; - Value *getCorrespondingValue (const Value *V) { - if (LiveInToParameterMap.find (V) != LiveInToParameterMap.end ()) { - return getFunctionArg (TraceFn, LiveInToParameterMap[V]); + Value *getCorrespondingValue (const Value *V, bool preferLiveIn = true) { + if (preferLiveIn) { + ValueToIntMap::iterator It = LiveInToParameterMap.find (V); + if (It != LiveInToParameterMap.end ()) + return getFunctionArg (TraceFn, It->second); } + // Otherwise, ignore live-in values (useful for getting the live-out + // version of a value that is both live-out and live-in) ValueMap::iterator i = O2CMap.find (V); assert (O2CMap.end() != i && "getCorrespondingValue called on value not in map"); From gaeke at cs.uiuc.edu Mon May 24 03:57:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 24 03:57:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405240854.DAA17107@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.69 -> 1.70 --- Log message: Remove some dead variables and update some debugging messages. Bug fixes in rewriteEpilog: * Ignore live-in values when looking up saved reg alloc state; before, if we had a value which was both live-in and live-out, we would pass in the live-in value, modify it, and return the live-in value! * Don't reload fp twice in the epilog. * Instead of doing reg->reg copies for live-out values, save them into the stack slots from which they will be reloaded into the correct matrixFn registers later. This prevents read-after-write bugs when reading the live-out values (but for now we don't support live values in stack slots, sigh.) --- Diffs of the changes: (+53 -37) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.69 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.70 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.69 Sun May 23 05:05:02 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Mon May 24 03:54:46 2004 @@ -200,10 +200,14 @@ std::cerr << " )\n"); } +/// getValueAllocState - Returns a pair containing the +/// saved register allocator state for a value. +/// static std::pair -getValueAllocState (TraceFunction *TF, Value *V) { +getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true) { return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V), - getValueAllocStateFromGlobal (TF->TraceFn, TF->getCorrespondingValue (V))); + getValueAllocStateFromGlobal (TF->TraceFn, + TF->getCorrespondingValue (V, preferLiveIn))); } unsigned UnpackTraceFunction::stackOffsetForReg (unsigned R) { @@ -213,8 +217,7 @@ void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) { const TargetRegInfo &TRI = TM->getRegInfo (); - static const unsigned fp = SparcV9::i6, sp = SparcV9::o6, g0 = SparcV9::g0, - g1 = SparcV9::g1, g2 = SparcV9::g2; + static const unsigned sp = SparcV9::o6, g1 = SparcV9::g1, g2 = SparcV9::g2; // UTF prolog: start out by clearing everything out of the entry basic block // (FIXME: may not work once we start doing optimizations!!! We will probably @@ -244,8 +247,8 @@ AllocInfo &Source = as.second.first, &Target = as.second.second; if (Source != Target) if (Source.AllocState == AllocInfo::Allocated) { - DEBUG (std::cerr << "Need to save incoming live value in reg " - << Source.Placement << " onto the stack\n"); + DEBUG (std::cerr << "rewriteProlog: Need to save incoming live value " + << "in reg " << Source.Placement << " onto the stack\n"); RegsToSave.insert (Source.Placement); } } @@ -334,13 +337,9 @@ static unsigned getSavedStateIndexOfInstruction (const Function *F, const Instruction *I) { unsigned Key = 0; - DEBUG(std::cerr << "getSavedStateIndexOfInstruction(F = " << F->getName() - << "(), I = " << *I << ")\n"); for (const_inst_iterator II=inst_begin (F), IE=inst_end (F); II!=IE; ++II) { - if (&*II == I) { - DEBUG(std::cerr << "--> returns " << Key << "\n"); + if (&*II == I) return Key; - } ++Key; } // By this time we had better have found it, otherwise we are about to do bad @@ -390,10 +389,15 @@ // (InstructionKey, OperandKey, ...): for (unsigned i = 0; i < FAllocState->numTuples; ++i) { OperandAllocState &T = FAllocState->tuples[i]; - if (T.Instruction == InstructionKey && T.Operand == OperandKey) - return AllocInfo (T.Instruction, T.Operand, - (AllocInfo::AllocStateTy) T.AllocState, - T.Placement); + if (T.Instruction == InstructionKey && T.Operand == OperandKey) { + AllocInfo AI (T.Instruction, T.Operand, + (AllocInfo::AllocStateTy) T.AllocState, T.Placement); + DEBUG (std::cerr << "Alloc state saved in module for " + << F->getName () << ":" << V->getName () << " (key = " + << InstructionKey << "," << OperandKey << ") is " << AI + << "\n"); + return AI; + } } // By this time we had better have found it, otherwise we are about to do bad // things. @@ -429,14 +433,14 @@ } // Reconstruct the AllocInfo for V by searching // FState for a tuple that starts with (InstructionKey, OperandKey, ...): - DEBUG(std::cerr << "Looking for " << F->getName () << "()'s value " - << *V << "(Instruction " << InstructionKey << " Operand " - << OperandKey << ")... " << FState.size () - << " tuples to search.\n"); for (unsigned i = 0, s = FState.size (); i < s; ++i) { AllocInfo &T = FState[i]; - if (T.Instruction == InstructionKey && T.Operand == OperandKey) + if (T.Instruction == InstructionKey && T.Operand == OperandKey) { + DEBUG (std::cerr << "Alloc state saved in global for " << F->getName () + << ":" << V->getName () << " (key = " << InstructionKey << "," + << OperandKey << ") is " << T << "\n"); return T; + } } // By this time we had better have found it, otherwise we are about to do bad // things. @@ -449,40 +453,52 @@ void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB) { const TargetRegInfo &TRI = TM->getRegInfo (); - static const unsigned fp = SparcV9::i6, sp = SparcV9::o6, g0 = SparcV9::g0, - g1 = SparcV9::g1, g2 = SparcV9::g2; + static const unsigned fp = SparcV9::i6, sp = SparcV9::o6, g2 = SparcV9::g2; // UTF epilog: start out by clearing everything out of the exit basic block // (FIXME: may not work once we start doing optimizations!!! We will probably // have to use a separate MBB) MBB.clear (); - // Restore old FP. + // Insert stores from each live-out variable's reg. in the trace + // to its stack slot in the trace function, from which it will be + // reloaded below into a register. std::vector mvec; - TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), fp, TRI.getRegType(fp), - g2); - for (std::vector::iterator vi = mvec.begin (), - ve = mvec.end (); vi != ve; ++vi) - MBB.push_back (*vi); - RegsToRestore.erase (fp); - - // Insert copies from each live-out variable's reg. in the trace - // to its reg. in the matrix function. - Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn; LiveVariableSet &So = TF->LiveOutSet; for (LiveVariableSet::iterator SI = So.begin (), SE = So.end (); SI != SE; ++SI) { Value *V = *SI; - std::pair ai = getValueAllocState (TF, V); + std::pair ai = getValueAllocState (TF, V, false); + // Source is traceFn's register, Target is matrixFn's register AllocInfo &Target = ai.first, &Source = ai.second; - if (Source != Target) - insertCopyMachineInstrs (Source, Target, MBB, V->getType ()); + assert (Target.AllocState == AllocInfo::Allocated + && Source.AllocState == AllocInfo::Allocated + && "FIXME: does not handle live values in stack slots yet"); + mvec.clear (); + unsigned R = Source.Placement; + unsigned RegType = TRI.getRegType (R); + DEBUG (std::cerr << "rewriteEpilog: saving live-out value: " << V->getName() + << " is allocated to reg#" << Target.AllocState + << " in MatrixFn and reg#" << Source.AllocState << " in TraceFn\n"); + TRI.cpReg2MemMI (mvec, R, sp, stackOffsetForReg (Target.Placement), + RegType, g2); + for (std::vector::iterator vi = mvec.begin (), + ve = mvec.end (); vi != ve; ++vi) + MBB.push_back (*vi); } + // Restore old FP. + mvec.clear (); + TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), fp, TRI.getRegType(fp), + g2); + for (std::vector::iterator vi = mvec.begin (), + ve = mvec.end (); vi != ve; ++vi) + MBB.push_back (*vi); + RegsToSave.erase (fp); + // Get the set of registers used in this function which we saved in // rewriteProlog, earlier, and restore all used registers from stack // except SP. - int RegType; for (std::set::iterator i = RegsToSave.begin (), e = RegsToSave.end (); i != e; ++i) { mvec.clear (); From lattner at cs.uiuc.edu Mon May 24 13:09:04 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon May 24 13:09:04 2004 Subject: [llvm-commits] CVS: llvm/docs/llvm.css Message-ID: <200405241806.NAA06275@zion.cs.uiuc.edu> Changes in directory llvm/docs: llvm.css updated: 1.18 -> 1.19 --- Log message: Make doc_code shrink-to-fit. This only works in mozilla, but it doesn't hurt legibility on IE --- Diffs of the changes: (+4 -2) Index: llvm/docs/llvm.css diff -u llvm/docs/llvm.css:1.18 llvm/docs/llvm.css:1.19 --- llvm/docs/llvm.css:1.18 Sun May 23 16:25:50 2004 +++ llvm/docs/llvm.css Mon May 24 13:05:58 2004 @@ -54,5 +54,7 @@ .doc_warning { color: red; font-weight: bold } .doc_code { border: solid 1px gray; background: #eeeeee; - margin: 0 0 0 1em; - padding: 0 0 0 1em } + margin: 0 1em 0 1em; + padding: 0 1em 0 1em; + display:table; + } From alkis at cs.uiuc.edu Mon May 24 13:37:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 13:37:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/classdump/classdump.cpp Message-ID: <200405241835.NAA06505@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/classdump: classdump.cpp updated: 1.6 -> 1.7 --- Log message: Add command line support to both utilities. --- Diffs of the changes: (+3 -0) Index: llvm-java/tools/classdump/classdump.cpp diff -u llvm-java/tools/classdump/classdump.cpp:1.6 llvm-java/tools/classdump/classdump.cpp:1.7 --- llvm-java/tools/classdump/classdump.cpp:1.6 Sat May 22 01:48:35 2004 +++ llvm-java/tools/classdump/classdump.cpp Mon May 24 13:34:52 2004 @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include +#include #include #include @@ -24,6 +25,8 @@ int main(int argc, char* argv[]) { PrintStackTraceOnErrorSignal(); + cl::ParseCommandLineOptions(argc, argv, + "class dump utility"); try { std::auto_ptr cf( From alkis at cs.uiuc.edu Mon May 24 13:38:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 13:38:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/class2llvm/class2llvm.cpp Message-ID: <200405241835.NAA06512@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/class2llvm: class2llvm.cpp updated: 1.2 -> 1.3 --- Log message: Add command line support to both utilities. --- Diffs of the changes: (+3 -0) Index: llvm-java/tools/class2llvm/class2llvm.cpp diff -u llvm-java/tools/class2llvm/class2llvm.cpp:1.2 llvm-java/tools/class2llvm/class2llvm.cpp:1.3 --- llvm-java/tools/class2llvm/class2llvm.cpp:1.2 Sat May 22 18:25:22 2004 +++ llvm-java/tools/class2llvm/class2llvm.cpp Mon May 24 13:34:52 2004 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,8 @@ int main(int argc, char* argv[]) { PrintStackTraceOnErrorSignal(); + cl::ParseCommandLineOptions(argc, argv, + "classfile to llvm utility"); try { std::auto_ptr cf( From alkis at cs.uiuc.edu Mon May 24 13:40:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 13:40:03 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405241837.NAA06591@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.13 -> 1.14 --- Log message: Add some very simple debugging info. --- Diffs of the changes: (+9 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.13 llvm-java/lib/Compiler/Compiler.cpp:1.14 --- llvm-java/lib/Compiler/Compiler.cpp:1.13 Sun May 23 18:03:35 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 13:37:16 2004 @@ -11,6 +11,8 @@ // //===----------------------------------------------------------------------===// +#define DEBUG_TYPE "javacompiler" + #include #include #include @@ -19,6 +21,7 @@ #include #include #include +#include #include using namespace llvm; @@ -171,8 +174,10 @@ void Compiler::compileMethod(Module& module, const Java::Method& method) { using namespace llvm::Java::Opcode; + DEBUG(std::cerr << "compiling method: " << method.getName()->str() << '\n'); + Function* function = - module.getOrInsertFunction(method.getName()->str(), Type::VoidTy); + module.getOrInsertFunction(method.getName()->str(), Type::VoidTy, 0); const Java::CodeAttribute* codeAttr = Java::getCodeAttribute(method.getAttributes()); @@ -776,6 +781,9 @@ Module* Compiler::compile(const ClassFile& cf) { + DEBUG(std::cerr << "compiling class: " + << cf.getThisClass()->getName()->str() << '\n'); + Module* module = new Module(cf.getThisClass()->getName()->str()); const Java::Methods& methods = cf.getMethods(); From alkis at cs.uiuc.edu Mon May 24 14:46:04 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 14:46:04 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405241943.OAA06800@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.14 -> 1.15 --- Log message: Fix bug in bytecode->BasicBlock mapping creation. --- Diffs of the changes: (+4 -6) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.14 llvm-java/lib/Compiler/Compiler.cpp:1.15 --- llvm-java/lib/Compiler/Compiler.cpp:1.14 Mon May 24 13:37:16 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 14:43:30 2004 @@ -50,7 +50,6 @@ bc2bbMap_.clear(); bc2bbMap_.assign(codeAttr.getCodeSize(), NULL); - bc2bbMap_[0] = new BasicBlock("entry", &function); const uint8_t* code = codeAttr.getCode(); for (unsigned i = 0; i < codeAttr.getCodeSize(); ++i) { @@ -161,13 +160,12 @@ } } - unsigned i = 0; - BasicBlock* bb = bc2bbMap_[i]; - while (++i < codeAttr.getCodeSize()) { + BasicBlock* bb = new BasicBlock("entry", &function); + for (unsigned i = 0; i < codeAttr.getCodeSize(); ++i) { if (bc2bbMap_[i]) - bc2bbMap_[i] = bb; - else bb = bc2bbMap_[i]; + else + bc2bbMap_[i] = bb; } } From alkis at cs.uiuc.edu Mon May 24 15:03:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 15:03:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405242000.PAA06908@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.15 -> 1.16 --- Log message: Create and initialize locals in the beginning of the function. Ignore INVOKESPECIAL bytecodes so that we can compile simple methods like (the method is missing code for the INVOKESPECIAL bytecode): alkis at moro ClassFile $ cat Simple.java package edu.uiuc.cs.llvm; public class Simple { public static int main(String[] args) { return 0; } } alkis at moro ClassFile $ ../../tools/Debug/class2llvm -debug < Simple.class implementation ; Functions: void ""() { entry: alloca void* ; :0 [#uses=2] store void* null, void** %0 load void** %0 ; :0 [#uses=0] ret void } void %main() { entry: ret int 0 } alkis at moro ClassFile $ --- Diffs of the changes: (+51 -15) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.15 llvm-java/lib/Compiler/Compiler.cpp:1.16 --- llvm-java/lib/Compiler/Compiler.cpp:1.15 Mon May 24 14:43:30 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 15:00:23 2004 @@ -40,6 +40,7 @@ } // namespace void Compiler::compileMethodInit(Function& function, + const ClassFile& cf, const CodeAttribute& codeAttr) { while (!opStack_.empty()) @@ -169,7 +170,24 @@ } } -void Compiler::compileMethod(Module& module, const Java::Method& method) { +Value* Compiler::getOrCreateLocal(unsigned index, const Type* type) +{ + if (!locals_[index]) { + BasicBlock* entry = bc2bbMap_[0]; + Instruction* alloc = new AllocaInst(type); + locals_[index] = alloc; + Instruction* store = + new StoreInst(llvm::Constant::getNullValue(type), locals_[index]); + entry->getInstList().push_front(store); + entry->getInstList().push_front(alloc); + } + + return locals_[index]; +} + +void Compiler::compileMethod(Module& module, + const ClassFile& cf, + const Java::Method& method) { using namespace llvm::Java::Opcode; DEBUG(std::cerr << "compiling method: " << method.getName()->str() << '\n'); @@ -180,7 +198,12 @@ const Java::CodeAttribute* codeAttr = Java::getCodeAttribute(method.getAttributes()); - compileMethodInit(*function, *codeAttr); + compileMethodInit(*function, cf, *codeAttr); + + // FIXME: this should really be a non-void type when the object + // model is finalized + const Type* ObjectTy = Type::VoidTy; + const Type* ObjectRefTy = PointerType::get(ObjectTy); const uint8_t* code = codeAttr->getCode(); for (unsigned i = 0; i < codeAttr->getCodeSize(); ++i) { @@ -189,9 +212,7 @@ i += wide; switch (code[i]) { case ACONST_NULL: - // FIXME: should push a null pointer of type Object* - opStack_.push( - ConstantPointerNull::get(PointerType::get(Type::VoidTy))); + opStack_.push(llvm::Constant::getNullValue(ObjectRefTy)); break; case ICONST_M1: case ICONST_0: @@ -244,7 +265,8 @@ case ALOAD: { // FIXME: use opcodes to perform type checking unsigned index = readUByte(code, i); - Instruction* in = new LoadInst(locals_[index]); + Instruction* in = + new LoadInst(getOrCreateLocal(index, ObjectRefTy)); opStack_.push(in); bc2bbMap_[bcStart]->getInstList().push_back(in); break; @@ -253,7 +275,9 @@ case ILOAD_1: case ILOAD_2: case ILOAD_3: { - Instruction* in = new LoadInst(locals_[code[i]-ILOAD_0]); + unsigned index = code[i] - ILOAD_0; + Instruction* in = + new LoadInst(getOrCreateLocal(index, ObjectRefTy)); opStack_.push(in); bc2bbMap_[bcStart]->getInstList().push_back(in); break; @@ -262,7 +286,9 @@ case LLOAD_1: case LLOAD_2: case LLOAD_3: { - Instruction* in = new LoadInst(locals_[code[i]-LLOAD_0]); + unsigned index = code[i] - LLOAD_0; + Instruction* in = + new LoadInst(getOrCreateLocal(index, ObjectRefTy)); opStack_.push(in); bc2bbMap_[bcStart]->getInstList().push_back(in); break; @@ -271,7 +297,9 @@ case FLOAD_1: case FLOAD_2: case FLOAD_3: { - Instruction* in = new LoadInst(locals_[code[i]-FLOAD_0]); + unsigned index = code[i] - FLOAD_0; + Instruction* in = + new LoadInst(getOrCreateLocal(index, ObjectRefTy)); opStack_.push(in); bc2bbMap_[bcStart]->getInstList().push_back(in); break; @@ -280,7 +308,9 @@ case DLOAD_1: case DLOAD_2: case DLOAD_3: { - Instruction* in = new LoadInst(locals_[code[i]-DLOAD_0]); + unsigned index = code[i] - DLOAD_0; + Instruction* in = + new LoadInst(getOrCreateLocal(index, ObjectRefTy)); opStack_.push(in); bc2bbMap_[bcStart]->getInstList().push_back(in); break; @@ -289,7 +319,9 @@ case ALOAD_1: case ALOAD_2: case ALOAD_3: { - Instruction* in = new LoadInst(locals_[code[i]-ALOAD_0]); + unsigned index = code[i] - ALOAD_0; + Instruction* in = + new LoadInst(getOrCreateLocal(index, ObjectRefTy)); opStack_.push(in); bc2bbMap_[bcStart]->getInstList().push_back(in); break; @@ -731,7 +763,12 @@ case GETFIELD: case PUTFIELD: case INVOKEVIRTUAL: - case INVOKESPECIAL: + assert(0 && "not implemented"); + case INVOKESPECIAL: { + unsigned index = readUShort(code, i); + DEBUG(std::cerr << "ignoring INVOKESPECIAL\n"); + break; + } case INVOKESTATIC: case INVOKEINTERFACE: case XXXUNUSEDXXX: @@ -754,8 +791,7 @@ Instruction::SetNE, }; Value* v1 = opStack_.top(); opStack_.pop(); - // FIXME: should compare to a null pointer of type Object* - Value* v2 =ConstantPointerNull::get(PointerType::get(Type::VoidTy)); + Value* v2 = llvm::Constant::getNullValue(ObjectRefTy); Instruction* in = new SetCondInst(java2llvm[i-IFNULL], v1, v2); bc2bbMap_[bcStart]->getInstList().push_back(in); new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], @@ -787,7 +823,7 @@ const Java::Methods& methods = cf.getMethods(); for (Java::Methods::const_iterator i = methods.begin(), e = methods.end(); i != e; ++i) - compileMethod(*module, **i); + compileMethod(*module, cf, **i); return module; } From alkis at cs.uiuc.edu Mon May 24 15:04:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 15:04:01 2004 Subject: [llvm-commits] CVS: llvm-java/test/ClassFile/Simple.java Message-ID: <200405242001.PAA06988@zion.cs.uiuc.edu> Changes in directory llvm-java/test/ClassFile: Simple.java updated: 1.3 -> 1.4 --- Log message: Remove private constructor. The constructor is still emitted, but javap -c doesn't output it. --- Diffs of the changes: (+0 -4) Index: llvm-java/test/ClassFile/Simple.java diff -u llvm-java/test/ClassFile/Simple.java:1.3 llvm-java/test/ClassFile/Simple.java:1.4 --- llvm-java/test/ClassFile/Simple.java:1.3 Mon May 24 03:27:20 2004 +++ llvm-java/test/ClassFile/Simple.java Mon May 24 15:01:26 2004 @@ -2,10 +2,6 @@ public class Simple { - private Simple() { - // declare constructor private so that it is not emitted - } - public static int main(String[] args) { return 0; } From alkis at cs.uiuc.edu Mon May 24 15:04:04 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 15:04:04 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Compiler.h Message-ID: <200405242000.PAA06915@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Compiler.h updated: 1.3 -> 1.4 --- Log message: Create and initialize locals in the beginning of the function. Ignore INVOKESPECIAL bytecodes so that we can compile simple methods like (the method is missing code for the INVOKESPECIAL bytecode): alkis at moro ClassFile $ cat Simple.java package edu.uiuc.cs.llvm; public class Simple { public static int main(String[] args) { return 0; } } alkis at moro ClassFile $ ../../tools/Debug/class2llvm -debug < Simple.class implementation ; Functions: void ""() { entry: alloca void* ; :0 [#uses=2] store void* null, void** %0 load void** %0 ; :0 [#uses=0] ret void } void %main() { entry: ret int 0 } alkis at moro ClassFile $ --- Diffs of the changes: (+7 -1) Index: llvm-java/include/llvm/Java/Compiler.h diff -u llvm-java/include/llvm/Java/Compiler.h:1.3 llvm-java/include/llvm/Java/Compiler.h:1.4 --- llvm-java/include/llvm/Java/Compiler.h:1.3 Sat May 22 20:15:53 2004 +++ llvm-java/include/llvm/Java/Compiler.h Mon May 24 15:00:23 2004 @@ -26,8 +26,14 @@ private: void compileMethodInit(Function& function, + const ClassFile& cf, const CodeAttribute& codeAttr); - void compileMethod(Module& module, const Method& method); + + Value* getOrCreateLocal(unsigned index, const Type* type); + + void compileMethod(Module& module, + const ClassFile& cf, + const Method& method); private: typedef std::stack > OperandStack; From alkis at cs.uiuc.edu Mon May 24 15:37:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 15:37:02 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405242034.PAA07223@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h updated: 1.4 -> 1.5 --- Log message: Add enum for primitive array types. --- Diffs of the changes: (+15 -0) Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.4 llvm-java/include/llvm/Java/Bytecode.h:1.5 --- llvm-java/include/llvm/Java/Bytecode.h:1.4 Sun May 23 05:17:31 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Mon May 24 15:34:38 2004 @@ -230,6 +230,21 @@ } // namespace Opcode + namespace AType { + + enum { + BOOLEAN = 4, + CHAR = 5, + FLOAT = 6, + DOUBLE = 7, + BYTE = 8, + SHORT = 9, + INT = 10, + LONG = 11, + }; + + } // namespace AType + inline int readSByte(const uint8_t* code, unsigned& i) { return code[++i]; } From gaeke at cs.uiuc.edu Mon May 24 15:38:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 24 15:38:03 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405242036.PAA03806@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.57 -> 1.58 --- Log message: Our dominance assumption for phi nodes only holds for phi nodes on the trace. --- Diffs of the changes: (+2 -2) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.57 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.58 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.57 Sat May 22 01:56:39 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Mon May 24 15:36:10 2004 @@ -113,8 +113,8 @@ Instruction *UInst = dyn_cast (*ui); if (!UInst) // Non-Instruction Users scare me, mommy return false; - if (isa (UInst)) - continue; // If a Phi node uses a value that's defined in the + if (isa (UInst) && T.contains (UInst->getParent ())) + continue; // If a Phi node in the trace uses a value that's defined in the // trace, the def. must have originally dominated the Phi. BasicBlock *UBlock = UInst->getParent (); if (Block == UBlock) { From gaeke at cs.uiuc.edu Mon May 24 16:03:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 24 16:03:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405242101.QAA04387@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.70 -> 1.71 --- Log message: Fix bug in debugging output...geez... --- Diffs of the changes: (+2 -2) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.70 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.71 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.70 Mon May 24 03:54:46 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Mon May 24 16:01:25 2004 @@ -478,8 +478,8 @@ unsigned R = Source.Placement; unsigned RegType = TRI.getRegType (R); DEBUG (std::cerr << "rewriteEpilog: saving live-out value: " << V->getName() - << " is allocated to reg#" << Target.AllocState - << " in MatrixFn and reg#" << Source.AllocState << " in TraceFn\n"); + << " is allocated to reg#" << Target.Placement + << " in MatrixFn and reg#" << Source.Placement << " in TraceFn\n"); TRI.cpReg2MemMI (mvec, R, sp, stackOffsetForReg (Target.Placement), RegType, g2); for (std::vector::iterator vi = mvec.begin (), From alkis at cs.uiuc.edu Mon May 24 17:04:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 17:04:02 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405242201.RAA07580@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h updated: 1.5 -> 1.6 --- Log message: Add header guards. --- Diffs of the changes: (+5 -0) Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.5 llvm-java/include/llvm/Java/Bytecode.h:1.6 --- llvm-java/include/llvm/Java/Bytecode.h:1.5 Mon May 24 15:34:38 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Mon May 24 17:01:27 2004 @@ -11,6 +11,9 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_JAVA_BYTECODE_H +#define LLVM_JAVA_BYTECODE_H + #include #include @@ -277,3 +280,5 @@ } } } // namespace llvm::Java + +#endif//LLVM_JAVA_BYTECODE_H From alkis at cs.uiuc.edu Mon May 24 17:06:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 17:06:01 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405242203.RAA07614@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.10 -> 1.11 --- Log message: Add header guards. --- Diffs of the changes: (+5 -0) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.10 llvm-java/include/llvm/Java/ClassFile.h:1.11 --- llvm-java/include/llvm/Java/ClassFile.h:1.10 Sat May 22 00:57:09 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Mon May 24 17:03:22 2004 @@ -12,6 +12,9 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_JAVA_CLASSFILE_H +#define LLVM_JAVA_CLASSFILE_H + #include #include #include @@ -443,3 +446,5 @@ }; } } // namespace llvm::Java + +#endif//LLVM_JAVA_CLASSFILE_H From lattner at cs.uiuc.edu Mon May 24 20:38:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon May 24 20:38:01 2004 Subject: [llvm-commits] CVS: llvm-www/www-index.html Message-ID: <200405250135.UAA09365@zion.cs.uiuc.edu> Changes in directory llvm-www: www-index.html updated: 1.99 -> 1.100 --- Log message: Add a note --- Diffs of the changes: (+3 -0) Index: llvm-www/www-index.html diff -u llvm-www/www-index.html:1.99 llvm-www/www-index.html:1.100 --- llvm-www/www-index.html:1.99 Fri Apr 16 11:02:26 2004 +++ llvm-www/www-index.html Mon May 24 20:34:50 2004 @@ -94,6 +94,9 @@ compilation model, including link-time, install-time, run-time, and offline optimization. +

  • LLVM has full support for accurate + garbage collection.
  • +
  • It includes native code generators for X86 and Sparc (both of which work as JIT or static compilers). LLVM can also compile to C code, for portability. Other native backends are in development.
  • From alkis at cs.uiuc.edu Mon May 24 20:51:00 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 20:51:00 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/BytecodeParser.h Compiler.h Bytecode.h Message-ID: <200405250148.UAA09455@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: BytecodeParser.h added (r1.1) Compiler.h updated: 1.4 -> 1.5 Bytecode.h updated: 1.6 -> 1.7 --- Log message: Huge refactoring. Parsing code now lives in BytecodeParser and Compiler uses the pimpl idiom. CompilerImpl is a BytecodeParser which also uses a Bytecode2BasicBlockMapper (BytecodeParser) to build the bytecode->BasicBlock map. The refactoring of the parsing code eliminates the duplicate switches and makes the code simpler (several bytecodes are handled by one call iconst_, bipush and sipush for example). Some bugs in the Bytecode2BasicBlockMapper where fixes (not all basic blocks were created). --- Diffs of the changes: (+774 -33) Index: llvm-java/include/llvm/Java/BytecodeParser.h diff -c /dev/null llvm-java/include/llvm/Java/BytecodeParser.h:1.1 *** /dev/null Mon May 24 20:48:10 2004 --- llvm-java/include/llvm/Java/BytecodeParser.h Mon May 24 20:48:00 2004 *************** *** 0 **** --- 1,763 ---- + //===-- BytecodeParser.h - Java bytecode parser ---------------*- C++ -*-===// + // + // 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 file contains Java bytecode parser baseclass: a class that + // helps writing Java bytecode parsers. + // + //===----------------------------------------------------------------------===// + + #ifndef LLVM_JAVA_BYTECODEPARSER_H + #define LLVM_JAVA_BYTECODEPARSER_H + + #include + + namespace llvm { namespace Java { + + /// @brief This class provides a base class that eases bytecode + /// parsing. + /// + /// By default all the do_* methods do nothing. A subclass can + /// override at will to provide specific behaviour. + template + class BytecodeParser { + protected: + typedef std::vector > SwitchCases; + + enum JSetCC { EQ, NE, LT, GE, GT, LE }; + + enum JType { + REFERENCE = 0, // this is not defined in the java spec + BOOLEAN = 4, + CHAR = 5, + FLOAT = 6, + DOUBLE = 7, + BYTE = 8, + SHORT = 9, + INT = 10, + LONG = 11, + }; + + private: + SwitchCases switchCases_; + + protected: + #define THIS ((SubClass*)this) + + /// @brief parse code pointed to by \c code of size \c size + /// + /// This function parses the code pointed to by \c code and + /// calls the subclass's do_ method + /// appropriately. When this function returns all code up to + /// \c size is parsed. + void parse(const uint8_t* code, unsigned size) { + using namespace Opcode; + + for (unsigned i = 0; i < size; ++i) { + unsigned curBC = i; + bool wide = code[i] == WIDE; + i += wide; + switch (code[i]) { + case ACONST_NULL: + THIS->do_aconst_null(curBC); + break; + case ICONST_M1: + case ICONST_0: + case ICONST_1: + case ICONST_2: + case ICONST_3: + case ICONST_4: + case ICONST_5: + THIS->do_iconst(curBC, code[i]-ICONST_0); + break; + case LCONST_0: + case LCONST_1: + THIS->do_lconst(curBC, code[i]-LCONST_0); + break; + case FCONST_0: + case FCONST_1: + case FCONST_2: + THIS->do_fconst(curBC, code[i]-FCONST_0); + break; + case DCONST_0: + case DCONST_1: + THIS->do_dconst(curBC, code[i]-DCONST_0); + break; + case BIPUSH: + THIS->do_iconst(curBC, readSByte(code, i)); + break; + case SIPUSH: + THIS->do_iconst(curBC, readSShort(code, i)); + break; + case LDC: + THIS->do_ldc(curBC, readUByte(code, i)); + break; + case LDC_W: + THIS->do_ldc(curBC, readUShort(code, i)); + break; + case LDC2_W: + THIS->do_ldc(curBC, readUShort(code, i)); + break; + case ILOAD: + THIS->do_load( + curBC, INT, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case LLOAD: + THIS->do_load( + curBC, LONG, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case FLOAD: + THIS->do_load( + curBC, FLOAT, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case DLOAD: + THIS->do_load( + curBC, DOUBLE, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case ALOAD: + THIS->do_load( + curBC, REFERENCE, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case ILOAD_0: + case ILOAD_1: + case ILOAD_2: + case ILOAD_3: + THIS->do_load(curBC, INT, code[i]-ILOAD_0); + break; + case LLOAD_0: + case LLOAD_1: + case LLOAD_2: + case LLOAD_3: + THIS->do_load(curBC, LONG, code[i]-LLOAD_0); + break; + case FLOAD_0: + case FLOAD_1: + case FLOAD_2: + case FLOAD_3: + THIS->do_load(curBC, FLOAT, code[i]-FLOAD_0); + break; + case DLOAD_0: + case DLOAD_1: + case DLOAD_2: + case DLOAD_3: + THIS->do_load(curBC, DOUBLE, code[i]-DLOAD_0); + break; + case ALOAD_0: + case ALOAD_1: + case ALOAD_2: + case ALOAD_3: + THIS->do_load(curBC, REFERENCE, code[i]-ALOAD_0); + break; + case IALOAD: + THIS->do_aload(curBC, INT); + break; + case LALOAD: + THIS->do_aload(curBC, LONG); + break; + case FALOAD: + THIS->do_aload(curBC, FLOAT); + break; + case DALOAD: + THIS->do_aload(curBC, DOUBLE); + break; + case AALOAD: + THIS->do_aload(curBC, REFERENCE); + break; + case BALOAD: + THIS->do_aload(curBC, BYTE); + break; + case CALOAD: + THIS->do_aload(curBC, CHAR); + break; + case SALOAD: + THIS->do_aload(curBC, SHORT); + break; + case ISTORE: + THIS->do_store( + curBC, INT, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case LSTORE: + THIS->do_store( + curBC, LONG, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case FSTORE: + THIS->do_store( + curBC, FLOAT, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case DSTORE: + THIS->do_store( + curBC, DOUBLE, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case ASTORE: + THIS->do_store( + curBC, REFERENCE, + wide ? readUShort(code, i) : readUByte(code, i)); + break; + case ISTORE_0: + case ISTORE_1: + case ISTORE_2: + case ISTORE_3: + THIS->do_store(curBC, INT, code[i]-ISTORE_0); + break; + case LSTORE_0: + case LSTORE_1: + case LSTORE_2: + case LSTORE_3: + THIS->do_store(curBC, LONG, code[i]-LSTORE_0); + break; + case FSTORE_0: + case FSTORE_1: + case FSTORE_2: + case FSTORE_3: + THIS->do_store(curBC, FLOAT, code[i]-FSTORE_0); + break; + case DSTORE_0: + case DSTORE_1: + case DSTORE_2: + case DSTORE_3: + THIS->do_store(curBC, DOUBLE, code[i]-DSTORE_0); + break; + case ASTORE_0: + case ASTORE_1: + case ASTORE_2: + case ASTORE_3: + THIS->do_store(curBC, REFERENCE, code[i]-ASTORE_0); + break; + case IASTORE: + THIS->do_astore(curBC, INT); + break; + case LASTORE: + THIS->do_astore(curBC, LONG); + break; + case FASTORE: + THIS->do_astore(curBC, FLOAT); + break; + case DASTORE: + THIS->do_astore(curBC, DOUBLE); + break; + case AASTORE: + THIS->do_astore(curBC, REFERENCE); + break; + case BASTORE: + THIS->do_astore(curBC, BYTE); + break; + case CASTORE: + THIS->do_astore(curBC, CHAR); + break; + case SASTORE: + THIS->do_astore(curBC, SHORT); + break; + case POP: + THIS->do_pop(curBC); + break; + case POP2: + THIS->do_pop2(curBC); + break; + case DUP: + THIS->do_dup(curBC); + break; + case DUP_X1: + THIS->do_dup_x1(curBC); + break; + case DUP_X2: + THIS->do_dup_x2(curBC); + break; + case DUP2: + THIS->do_dup2(curBC); + break; + case DUP2_X1: + THIS->do_dup2_x1(curBC); + break; + case DUP2_X2: + THIS->do_dup2_x2(curBC); + break; + case SWAP: + THIS->do_swap(curBC); + break; + case IADD: + case LADD: + case FADD: + case DADD: + THIS->do_add(curBC); + break; + case ISUB: + case LSUB: + case FSUB: + case DSUB: + THIS->do_sub(curBC); + break; + case IMUL: + case LMUL: + case FMUL: + case DMUL: + THIS->do_mul(curBC); + break; + case IDIV: + case LDIV: + case FDIV: + case DDIV: + THIS->do_div(curBC); + break; + case IREM: + case LREM: + case FREM: + case DREM: + THIS->do_rem(curBC); + break; + case INEG: + case LNEG: + case FNEG: + case DNEG: + THIS->do_neg(curBC); + break; + case ISHL: + case LSHL: + THIS->do_shl(curBC); + break; + case ISHR: + case LSHR: + THIS->do_shr(curBC); + break; + case IUSHR: + case LUSHR: + THIS->do_ushr(curBC); + break; + case IAND: + case LAND: + THIS->do_and(curBC); + break; + case IOR: + case LOR: + THIS->do_or(curBC); + break; + case IXOR: + case LXOR: + THIS->do_xor(curBC); + break; + case IINC: + THIS->do_iinc( + curBC, readUByte(code, i), readUByte(code, i)); + break; + case I2L: + THIS->do_convert(curBC, LONG); + break; + case I2F: + THIS->do_convert(curBC, FLOAT); + break; + case I2D: + THIS->do_convert(curBC, DOUBLE); + break; + case L2I: + THIS->do_convert(curBC, INT); + break; + case L2F: + THIS->do_convert(curBC, FLOAT); + break; + case L2D: + THIS->do_convert(curBC, DOUBLE); + break; + case F2I: + THIS->do_convert(curBC, INT); + break; + case F2L: + THIS->do_convert(curBC, LONG); + break; + case F2D: + THIS->do_convert(curBC, DOUBLE); + break; + case D2I: + THIS->do_convert(curBC, INT); + break; + case D2L: + THIS->do_convert(curBC, LONG); + break; + case D2F: + THIS->do_convert(curBC, FLOAT); + break; + case I2B: + THIS->do_convert(curBC, BYTE); + break; + case I2C: + THIS->do_convert(curBC, CHAR); + break; + case I2S: + THIS->do_convert(curBC, SHORT); + break; + case LCMP: + THIS->do_cmp(curBC); + break; + case FCMPL: + THIS->do_cmpl(curBC); + break; + case FCMPG: + THIS->do_cmpg(curBC); + break; + case DCMPL: + THIS->do_cmpl(curBC); + break; + case DCMPG: + THIS->do_cmpg(curBC); + break; + case IFEQ: { + unsigned t = curBC + readSShort(code, i); + THIS->do_if(curBC, EQ, INT, t, i + 1); + break; + } + case IFNE: { + unsigned t = curBC + readSShort(code, i); + THIS->do_if(curBC, NE, INT, t, i + 1); + break; + } + case IFLT: { + unsigned t = curBC + readSShort(code, i); + THIS->do_if(curBC, LT, INT, t, i + 1); + break; + } + case IFGE: { + unsigned t = curBC + readSShort(code, i); + THIS->do_if(curBC, GE, INT, t, i + 1); + break; + } + case IFGT: { + unsigned t = curBC + readSShort(code, i); + THIS->do_if(curBC, GT, INT, t, i + 1); + break; + } + case IFLE: { + unsigned t = curBC + readSShort(code, i); + THIS->do_if(curBC, LE, INT, t, i + 1); + break; + } + case IF_ICMPEQ: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, EQ, t, i + 1); + break; + } + case IF_ICMPNE: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, NE, t, i + 1); + break; + } + case IF_ICMPLT: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, LT, t, i + 1); + break; + } + case IF_ICMPGE: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, GE, t, i + 1); + break; + } + case IF_ICMPGT: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, GT, t, i + 1); + break; + } + case IF_ICMPLE: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, LE, t, i + 1); + break; + } + case IF_IACMPEQ: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, EQ, t, i + 1); + break; + } + case IF_IACMPNE: { + unsigned t = curBC + readSShort(code, i); + THIS->do_ifcmp(curBC, NE, t, i + 1); + break; + } + case GOTO: + THIS->do_goto(curBC, curBC + readSShort(code, i)); + break; + case JSR: + THIS->do_jsr(curBC, curBC + readSShort(code, i)); + break; + case RET: + THIS->do_ret(curBC, readUByte(code, i)); + break; + case TABLESWITCH: { + switchCases_.clear(); + skipPadBytes(code, i); + int def = readSInt(code, i); + int low = readSInt(code, i); + int high = readSInt(code, i); + switchCases_.reserve(high - low + 1); + while (low <= high) + switchCases_.push_back( + std::make_pair(low++, curBC + readSInt(code, i))); + THIS->do_switch(curBC, curBC + def, switchCases_); + break; + } + case LOOKUPSWITCH: { + switchCases_.clear(); + skipPadBytes(code, i); + int def = readSInt(code, i); + unsigned pairCount = readUInt(code, i); + switchCases_.reserve(pairCount); + while (pairCount--) + switchCases_.push_back( + std::make_pair(readSInt(code, i), + curBC + readSInt(code, i))); + THIS->do_switch(curBC, curBC + def, switchCases_); + break; + } + case IRETURN: + case LRETURN: + case FRETURN: + case DRETURN: + case ARETURN: + THIS->do_return(curBC); + break; + case RETURN: + THIS->do_return_void(curBC); + break; + case GETSTATIC: + THIS->do_getstatic(curBC, readUShort(code, i)); + break; + case PUTSTATIC: + THIS->do_putstatic(curBC, readUShort(code, i)); + break; + case GETFIELD: + THIS->do_getfield(curBC, readUShort(code, i)); + break; + case PUTFIELD: + THIS->do_putfield(curBC, readUShort(code, i)); + break; + case INVOKEVIRTUAL: + THIS->do_invokevirtual(curBC, readUShort(code, i)); + break; + case INVOKESPECIAL: + THIS->do_invokespecial(curBC, readUShort(code, i)); + break; + case INVOKESTATIC: + THIS->do_invokestatic(curBC, readUShort(code, i)); + break; + case INVOKEINTERFACE: { + THIS->do_invokeinterface(curBC, readUShort(code, i)); + unsigned count = readUByte(code, i); + unsigned zero = readUByte(code, i); + break; + } + case XXXUNUSEDXXX: + // FIXME: must throw something + break; + case NEW: + THIS->do_new(curBC, readUShort(code, i)); + break; + case NEWARRAY: + THIS->do_newarray(curBC, + static_cast(readUByte(code, i))); + break; + case ANEWARRAY: + THIS->do_anewarray(curBC, readUShort(code, i)); + break; + case ARRAYLENGTH: + THIS->do_arraylength(curBC); + break; + case ATHROW: + THIS->do_athrow(curBC); + break; + case CHECKCAST: + THIS->do_checkcast(curBC, readUShort(code, i)); + break; + case INSTANCEOF: + THIS->do_instanceof(curBC, readUShort(code, i)); + break; + case MONITORENTER: + THIS->do_monitorenter(curBC); + break; + case MONITOREXIT: + THIS->do_monitorexit(curBC); + break; + case WIDE: + // FIXME: must throw something + break; + case MULTIANEWARRAY: + THIS->do_multianewarray( + curBC, readUShort(code, i), readUByte(code, i)); + break; + case IFNULL: { + unsigned t = curBC + readUShort(code, i); + THIS->do_if(curBC, EQ, REFERENCE, t, i + 1); + break; + } + case IFNONNULL: { + unsigned t = curBC + readUShort(code, i); + THIS->do_if(curBC, NE, REFERENCE, t, i + 1); + break; + } + case GOTO_W: + THIS->do_goto(curBC, curBC + readSInt(code, i)); + break; + case JSR_W: + THIS->do_jsr(curBC, curBC + readSInt(code, i)); + break; + case BREAKPOINT: + case IMPDEP1: + case IMPDEP2: + case NOP: + break; + } + } + } + + #undef THIS + + /// @brief called on ACONST_NULL + void do_aconst_null(unsigned bcI) { } + /// @brief called on ICONST_, SIPUSH and BIPUSH + void do_iconst(unsigned bcI, int value) { } + /// @brief called on LCONST_ + void do_lconst(unsigned bcI, long long value) { } + /// @brief called on FCONST_ + void do_fconst(unsigned bcI, float value) { } + /// @brief called on DCONST_ + void do_dconst(unsigned bcI, double value) { } + /// @brief called on LDC, LDC_W and LDC2_W + void do_ldc(unsigned bcI, unsigned index) { } + /// @brief called on ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, + /// ILOAD_, LLOAD_, FLOAD_, DLOAD_, and ALOAD_ + void do_load(unsigned bcI, JType type, unsigned index) { } + /// @brief called on IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, + /// BALOAD, CALOAD, and SALOAD + void do_aload(unsigned bcI, JType type) { } + /// @brief called on ISTORE, LSTORE, FSTORE, DSTORE, ASTORE, + /// ISTORE_, LSTORE_, FSTORE_, DSTORE_, and + /// ASTORE_ + void do_store(unsigned bcI, JType type, unsigned index) { } + /// @brief called on IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, + /// BASTORE, CASTORE, and SASTORE + void do_astore(unsigned bcI, JType type) { } + /// @brief called on POP + void do_pop(unsigned bcI) { } + /// @brief called on POP2 + void do_pop2(unsigned bcI) { } + /// @brief called on DUP + void do_dup(unsigned bcI) { } + /// @brief called on DUP_X1 + void do_dup_x1(unsigned bcI) { } + /// @brief called on DUP_X2 + void do_dup_x2(unsigned bcI) { } + /// @brief called on DUP2 + void do_dup2(unsigned bcI) { } + /// @brief called on DUP2_X1 + void do_dup2_x1(unsigned bcI) { } + /// @brief called on DUP2_X2 + void do_dup2_x2(unsigned bcI) { } + /// @brief called on SWAP + void do_swap(unsigned bcI) { } + /// @brief called on IADD, LADD, FADD, and DADD + void do_add(unsigned bcI) { } + /// @brief called on ISUB, LSUB, FSUB, and DSUB + void do_sub(unsigned bcI) { } + /// @brief called on IMUL, LMUL, FMUL, and DMUL + void do_mul(unsigned bcI) { } + /// @brief called on IDIV, LDIV, FDIV, and DDIV + void do_div(unsigned bcI) { } + /// @brief called on IREM, LREM, FREM, and DREM + void do_rem(unsigned bcI) { } + /// @brief called on INEG, LNEG, FNEG, and DNEG + void do_neg(unsigned bcI) { } + /// @brief called on ISHL and LSHL + void do_shl(unsigned bcI) { } + /// @brief called on ISHR and LSHR + void do_shr(unsigned bcI) { } + /// @brief called on IUSHR and LUSHR + void do_ushr(unsigned bcI) { } + /// @brief called on IAND and LAND + void do_and(unsigned bcI) { } + /// @brief called on IOR or LOR + void do_or(unsigned bcI) { } + /// @brief called on IXOR and LXOR + void do_xor(unsigned bcI) { } + /// @brief called on IINC + void do_iinc(unsigned bcI, unsigned index, unsigned amount) { } + /// @brief called on I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, + /// F2D, D2I, D2L, D2F, I2B, I2C, and I2S + void do_convert(unsigned bcI, JType to) { } + /// @brief called on LCMP + void do_cmp(unsigned bcI) { } + /// @brief called on FCMPL and DCMPL + void do_cmpl(unsigned bcI) { } + /// @brief called on FCMPG and DCMPG + void do_cmpg(unsigned bcI) { } + /// @brief called on IF, IFNULL, and IFNONNULL + void do_if(unsigned bcI, JSetCC cc, JType type, + unsigned t, unsigned f) { } + /// @brief called on IFCMP and IFACMP + void do_ifcmp(unsigned bcI, JSetCC cc, + unsigned t, unsigned f) { } + /// @brief called on GOTO and GOTO_W + void do_goto(unsigned bcI, unsigned target) { } + /// @brief called on JSR and JSR_W + void do_jsr(unsigned bcI, unsigned target) { } + /// @brief called on RET + void do_ret(unsigned bcI, unsigned index) { } + /// @brief called on TABLESWITCH and LOOKUPSWITCH + void do_switch(unsigned bcI, + unsigned defTarget, + const SwitchCases& sw) { } + /// @brief called on IRETURN, LRETURN, FRETURN, DRETURN and + /// ARETURN + void do_return(unsigned bcI) { } + /// @brief called on RETURN + void do_return_void(unsigned bcI) { } + /// @brief called on GETSTATIC + void do_getstatic(unsigned bcI, unsigned index) { } + /// @brief called on PUTSTATIC + void do_putstatic(unsigned bcI, unsigned index) { } + /// @brief called on GETFIELD + void do_getfield(unsigned bcI, unsigned index) { } + /// @brief called on PUTFIELD + void do_putfield(unsigned bcI, unsigned index) { } + /// @brief called on INVOKEVIRTUAL + void do_invokevirtual(unsigned bcI, unsigned index) { } + /// @brief called on INVOKESPECIAL + void do_invokespecial(unsigned bcI, unsigned index) { } + /// @brief called on INVOKESTATIC + void do_invokestatic(unsigned bcI, unsigned index) { } + /// @brief called on INVOKEINTERFACE + void do_invokeinterface(unsigned bcI, unsigned index) { } + /// @brief called on NEW + void do_new(unsigned bcI, unsigned index) { } + /// @brief called on NEWARRAY + void do_newarray(unsigned bcI, JType type) { } + /// @brief called on ANEWARRAY + void do_anewarray(unsigned bcI, unsigned index) { } + /// @brief called on ARRAYLENGTH + void do_arraylength(unsigned bcI) { } + /// @brief called on ATHROW + void do_athrow(unsigned bcI) { } + /// @brief called on CHECKCAST + void do_checkcast(unsigned bcI, unsigned index) { } + /// @brief called on INSTANCEOF + void do_instanceof(unsigned bcI, unsigned index) { } + /// @brief called on MONITORENTER + void do_monitorenter(unsigned bcI) { } + /// @brief called on MONITOREXIT + void do_monitorexit(unsigned bcI) { } + /// @brief called on MULTIANEWARRAY + void do_multianewarray(unsigned bcI, + unsigned index, + unsigned dims) { } + }; + + } } // namespace llvm::Java + + #endif//LLVM_JAVA_BYTECODEPARSER_H Index: llvm-java/include/llvm/Java/Compiler.h diff -u llvm-java/include/llvm/Java/Compiler.h:1.4 llvm-java/include/llvm/Java/Compiler.h:1.5 --- llvm-java/include/llvm/Java/Compiler.h:1.4 Mon May 24 15:00:23 2004 +++ llvm-java/include/llvm/Java/Compiler.h Mon May 24 20:48:00 2004 @@ -15,34 +15,27 @@ #define LLVM_JAVA_COMPILER_H #include -#include -#include namespace llvm { namespace Java { + namespace { + class CompilerImpl; + } + class Compiler { public: + Compiler(); + ~Compiler(); + Module* compile(const ClassFile& cf); private: - void compileMethodInit(Function& function, - const ClassFile& cf, - const CodeAttribute& codeAttr); - - Value* getOrCreateLocal(unsigned index, const Type* type); - - void compileMethod(Module& module, - const ClassFile& cf, - const Method& method); + // do not implement + Compiler(const Compiler&); + const Compiler& operator=(const Compiler&); private: - typedef std::stack > OperandStack; - typedef std::vector Locals; - typedef std::vector BC2BBMap; - - OperandStack opStack_; - Locals locals_; - BC2BBMap bc2bbMap_; + CompilerImpl* compilerImpl_; }; } } // namespace llvm::Java Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.6 llvm-java/include/llvm/Java/Bytecode.h:1.7 --- llvm-java/include/llvm/Java/Bytecode.h:1.6 Mon May 24 17:01:27 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Mon May 24 20:48:00 2004 @@ -233,21 +233,6 @@ } // namespace Opcode - namespace AType { - - enum { - BOOLEAN = 4, - CHAR = 5, - FLOAT = 6, - DOUBLE = 7, - BYTE = 8, - SHORT = 9, - INT = 10, - LONG = 11, - }; - - } // namespace AType - inline int readSByte(const uint8_t* code, unsigned& i) { return code[++i]; } From alkis at cs.uiuc.edu Mon May 24 20:51:05 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 20:51:05 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405250148.UAA09444@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.16 -> 1.17 --- Log message: Huge refactoring. Parsing code now lives in BytecodeParser and Compiler uses the pimpl idiom. CompilerImpl is a BytecodeParser which also uses a Bytecode2BasicBlockMapper (BytecodeParser) to build the bytecode->BasicBlock map. The refactoring of the parsing code eliminates the duplicate switches and makes the code simpler (several bytecodes are handled by one call iconst_, bipush and sipush for example). Some bugs in the Bytecode2BasicBlockMapper where fixes (not all basic blocks were created). --- Diffs of the changes: (+406 -625) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.16 llvm-java/lib/Compiler/Compiler.cpp:1.17 --- llvm-java/lib/Compiler/Compiler.cpp:1.16 Mon May 24 15:00:23 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 20:48:00 2004 @@ -14,6 +14,7 @@ #define DEBUG_TYPE "javacompiler" #include +#include #include #include #include @@ -23,11 +24,18 @@ #include #include #include +#include +#include using namespace llvm; using namespace llvm::Java; -namespace { +namespace llvm { namespace Java { namespace { + + typedef std::vector BC2BBMap; + typedef std::stack > OperandStack; + typedef std::vector Locals; + inline bool isTwoSlotValue(const Value* v) { return v->getType() == Type::LongTy | v->getType() == Type::DoubleTy; @@ -37,402 +45,219 @@ return !isTwoSlotValue(v); } -} // namespace - -void Compiler::compileMethodInit(Function& function, - const ClassFile& cf, - const CodeAttribute& codeAttr) -{ - while (!opStack_.empty()) - opStack_.pop(); + struct Bytecode2BasicBlockMapper + : public BytecodeParser { + public: + Bytecode2BasicBlockMapper(Function& f, + BC2BBMap& m, + const CodeAttribute& c) + : function_(f), bc2bbMap_(m), codeAttr_(c) { } + + void compute() { + bc2bbMap_.clear(); + bc2bbMap_.assign(codeAttr_.getCodeSize(), NULL); + + parse(codeAttr_.getCode(), codeAttr_.getCodeSize()); + + BasicBlock* bb = new BasicBlock("entry", &function_); + for (unsigned i = 0; i < bc2bbMap_.size(); ++i) { + if (bc2bbMap_[i]) + bb = bc2bbMap_[i]; + else + bc2bbMap_[i] = bb; + } + } - locals_.clear(); - locals_.assign(codeAttr.getMaxLocals(), NULL); + void do_if(unsigned bcI, JSetCC cc, JType type, + unsigned t, unsigned f) { + if (!bc2bbMap_[t]) + bc2bbMap_[t] = + new BasicBlock("bb at bc" + utostr(t), &function_); + if (!bc2bbMap_[f]) + bc2bbMap_[f] = + new BasicBlock("bb at bc" + utostr(f), &function_); + } + + void do_ifcmp(unsigned bcI, JSetCC cc, + unsigned t, unsigned f) { + if (!bc2bbMap_[t]) + bc2bbMap_[t] = + new BasicBlock("bb at bc" + utostr(t), &function_); + if (!bc2bbMap_[f]) + bc2bbMap_[f] = + new BasicBlock("bb at bc" + utostr(f), &function_); + } + + void do_switch(unsigned bcI, + unsigned defTarget, + const SwitchCases& sw) { + for (unsigned i = 0; i < sw.size(); ++i) { + unsigned target = sw[i].second; + if (!bc2bbMap_[target]) + bc2bbMap_[target] = + new BasicBlock("bb at bc" + utostr(target), &function_); + } + } - bc2bbMap_.clear(); - bc2bbMap_.assign(codeAttr.getCodeSize(), NULL); + private: + Function& function_; + BC2BBMap& bc2bbMap_; + const CodeAttribute& codeAttr_; + }; + + struct CompilerImpl : + public BytecodeParser { + private: + const Type* getType(JType type) { + switch (type) { + // FIXME: this should really be a non-void type when the object + // model is finalized + case REFERENCE: return Type::VoidTy; + case BOOLEAN: return Type::BoolTy; + case CHAR: return Type::UByteTy; + case FLOAT: return Type::FloatTy; + case DOUBLE: return Type::DoubleTy; + case BYTE: return Type::SByteTy; + case SHORT: return Type::ShortTy; + case INT: return Type::IntTy; + case LONG: return Type::LongTy; + default: assert(0 && "Invalid JType to Type conversion!"); + } - const uint8_t* code = codeAttr.getCode(); - for (unsigned i = 0; i < codeAttr.getCodeSize(); ++i) { - using namespace llvm::Java::Opcode; - - unsigned bcStart = i; - bool wide = code[i] == WIDE; - i += wide; - switch (code[i]) { - case BIPUSH: - case LDC: - case NEWARRAY: - ++i; - break; - case ILOAD: - case LLOAD: - case FLOAD: - case DLOAD: - case ALOAD: - case ISTORE: - case LSTORE: - case FSTORE: - case DSTORE: - case ASTORE: - case RET: - i += 1 + wide; - break; - case SIPUSH: - case LDC_W: - case LDC2_W: - case GOTO: - case JSR: - case GETSTATIC: - case PUTSTATIC: - case GETFIELD: - case PUTFIELD: - case INVOKEVIRTUAL: - case INVOKESPECIAL: - case INVOKESTATIC: - case INVOKEINTERFACE: - case NEW: - case ANEWARRAY: - case ARRAYLENGTH: - case ATHROW: - case CHECKCAST: - case INSTANCEOF: - i += 2; - break; - case IINC: - i += 2 * (1 + wide); - break; - case IFEQ: - case IFNE: - case IFLT: - case IFGE: - case IFGT: - case IFLE: - case IF_ICMPEQ: - case IF_ICMPNE: - case IF_ICMPLT: - case IF_ICMPGE: - case IF_ICMPGT: - case IF_ICMPLE: - case IF_IACMPEQ: - case IF_IACMPNE: - case IFNULL: - case IFNONNULL: { - unsigned index = readUShort(code, i); - bc2bbMap_[bcStart] = new BasicBlock( - std::string("bb at bc") + utostr(bcStart), &function); - break; - } - case TABLESWITCH: { - skipPadBytes(code, i); - readSInt(code, i); - int low = readSInt(code, i); - int high = readSInt(code, i); - while (low++ <= high) { - unsigned bcIndex = bcStart + readSInt(code, i); - bc2bbMap_[bcIndex] = new BasicBlock( - std::string("bb at bc") + utostr(bcIndex), &function); - } - break; - } - case LOOKUPSWITCH: { - skipPadBytes(code, i); - readSInt(code, i); - unsigned pairCount = readUInt(code, i); - while (pairCount--) { - readSInt(code, i); - unsigned bcIndex = bcStart + readSInt(code, i); - bc2bbMap_[bcIndex] = new BasicBlock( - std::string("bb at bc") + utostr(bcIndex), &function); - } - break; - } - case XXXUNUSEDXXX: - throw "FIXME: create new exception class"; - case MULTIANEWARRAY: - i += 3; - break; - case GOTO_W: - case JSR_W: - i+= 4; - break; - default: - break; + return NULL; } - } - BasicBlock* bb = new BasicBlock("entry", &function); - for (unsigned i = 0; i < codeAttr.getCodeSize(); ++i) { - if (bc2bbMap_[i]) - bb = bc2bbMap_[i]; - else - bc2bbMap_[i] = bb; - } -} + Instruction::BinaryOps getSetCC(JSetCC cc) { + switch (cc) { + case EQ: return Instruction::SetEQ; + case NE: return Instruction::SetNE; + case LT: return Instruction::SetLT; + case GE: return Instruction::SetGE; + case GT: return Instruction::SetGT; + case LE: return Instruction::SetLE; + default: assert(0 && "Invalid JSetCC to BinaryOps conversion!"); + } + return static_cast(-1); + } -Value* Compiler::getOrCreateLocal(unsigned index, const Type* type) -{ - if (!locals_[index]) { - BasicBlock* entry = bc2bbMap_[0]; - Instruction* alloc = new AllocaInst(type); - locals_[index] = alloc; - Instruction* store = - new StoreInst(llvm::Constant::getNullValue(type), locals_[index]); - entry->getInstList().push_front(store); - entry->getInstList().push_front(alloc); - } + void compileMethodInit(Function& function, + const ClassFile& cf, + const CodeAttribute& codeAttr) { + while (!opStack_.empty()) + opStack_.pop(); - return locals_[index]; -} + locals_.clear(); + locals_.assign(codeAttr.getMaxLocals(), NULL); -void Compiler::compileMethod(Module& module, - const ClassFile& cf, - const Java::Method& method) { - using namespace llvm::Java::Opcode; - - DEBUG(std::cerr << "compiling method: " << method.getName()->str() << '\n'); - - Function* function = - module.getOrInsertFunction(method.getName()->str(), Type::VoidTy, 0); - - const Java::CodeAttribute* codeAttr = - Java::getCodeAttribute(method.getAttributes()); - - compileMethodInit(*function, cf, *codeAttr); - - // FIXME: this should really be a non-void type when the object - // model is finalized - const Type* ObjectTy = Type::VoidTy; - const Type* ObjectRefTy = PointerType::get(ObjectTy); - - const uint8_t* code = codeAttr->getCode(); - for (unsigned i = 0; i < codeAttr->getCodeSize(); ++i) { - unsigned bcStart = i; - bool wide = code[i] == WIDE; - i += wide; - switch (code[i]) { - case ACONST_NULL: - opStack_.push(llvm::Constant::getNullValue(ObjectRefTy)); - break; - case ICONST_M1: - case ICONST_0: - case ICONST_1: - case ICONST_2: - case ICONST_3: - case ICONST_4: - case ICONST_5: - opStack_.push(ConstantSInt::get(Type::IntTy, code[i]-ICONST_0)); - break; - case LCONST_0: - case LCONST_1: - opStack_.push(ConstantSInt::get(Type::LongTy, code[i]-LCONST_0)); - break; - case FCONST_0: - case FCONST_1: - case FCONST_2: - opStack_.push(ConstantFP::get(Type::FloatTy, code[i]-FCONST_0)); - break; - case DCONST_0: - case DCONST_1: - opStack_.push(ConstantFP::get(Type::DoubleTy, code[i]-DCONST_0)); - break; - case BIPUSH: { - int imm = readSByte(code, i); - opStack_.push(ConstantSInt::get(Type::IntTy, imm)); - break; - } - case SIPUSH: { - int imm = readSShort(code, i); - opStack_.push(ConstantSInt::get(Type::IntTy, imm)); - break; - } - case LDC: { - unsigned index = readUByte(code, i); - // FIXME: load constant from constant pool - } - case LDC_W: { - unsigned index = readUShort(code, i); - // FIXME: load constant from constant pool - } - case LDC2_W: { - unsigned index = readUShort(code, i); - // FIXME: load constant from constant pool - } - case ILOAD: - case LLOAD: - case FLOAD: - case DLOAD: - case ALOAD: { - // FIXME: use opcodes to perform type checking - unsigned index = readUByte(code, i); - Instruction* in = - new LoadInst(getOrCreateLocal(index, ObjectRefTy)); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + Bytecode2BasicBlockMapper mapper(function, bc2bbMap_, codeAttr); + mapper.compute(); } - case ILOAD_0: - case ILOAD_1: - case ILOAD_2: - case ILOAD_3: { - unsigned index = code[i] - ILOAD_0; - Instruction* in = - new LoadInst(getOrCreateLocal(index, ObjectRefTy)); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + Value* getOrCreateLocal(unsigned index, const Type* type) { + if (!locals_[index]) { + BasicBlock* entry = bc2bbMap_[0]; + Instruction* alloc = new AllocaInst(type); + locals_[index] = alloc; + Instruction* store = new StoreInst( + llvm::Constant::getNullValue(alloc->getType()), alloc); + entry->getInstList().push_front(store); + entry->getInstList().push_front(alloc); + } + + return locals_[index]; } - case LLOAD_0: - case LLOAD_1: - case LLOAD_2: - case LLOAD_3: { - unsigned index = code[i] - LLOAD_0; - Instruction* in = - new LoadInst(getOrCreateLocal(index, ObjectRefTy)); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + public: + void compileMethod(Module& module, + const ClassFile& cf, + const Method& method) { + DEBUG(std::cerr << "compiling method: " + << method.getName()->str() << '\n'); + + Function* function = + module.getOrInsertFunction(method.getName()->str(), + Type::VoidTy, 0); + + const Java::CodeAttribute* codeAttr = + Java::getCodeAttribute(method.getAttributes()); + + compileMethodInit(*function, cf, *codeAttr); + + parse(codeAttr->getCode(), codeAttr->getCodeSize()); } - case FLOAD_0: - case FLOAD_1: - case FLOAD_2: - case FLOAD_3: { - unsigned index = code[i] - FLOAD_0; - Instruction* in = - new LoadInst(getOrCreateLocal(index, ObjectRefTy)); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + void do_aconst_null(unsigned bcI) { + opStack_.push(llvm::Constant::getNullValue( + PointerType::get(getType(REFERENCE)))); } - case DLOAD_0: - case DLOAD_1: - case DLOAD_2: - case DLOAD_3: { - unsigned index = code[i] - DLOAD_0; - Instruction* in = - new LoadInst(getOrCreateLocal(index, ObjectRefTy)); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + void do_iconst(unsigned bcI, int value) { + opStack_.push(ConstantSInt::get(Type::IntTy, value)); } - case ALOAD_0: - case ALOAD_1: - case ALOAD_2: - case ALOAD_3: { - unsigned index = code[i] - ALOAD_0; - Instruction* in = - new LoadInst(getOrCreateLocal(index, ObjectRefTy)); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + void do_lconst(unsigned bcI, long long value) { + opStack_.push(ConstantSInt::get(Type::LongTy, value)); } - case IALOAD: - case LALOAD: - case FALOAD: - case DALOAD: - case AALOAD: - case BALOAD: - case CALOAD: - case SALOAD: - assert(0 && "not implemented"); - case ISTORE: - case LSTORE: - case FSTORE: - case DSTORE: - case ASTORE: { - // FIXME: use opcodes to perform type checking - unsigned index = readUByte(code, i); - Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = new StoreInst(v1, locals_[index]); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + void do_fconst(unsigned bcI, float value) { + opStack_.push(ConstantFP::get(Type::FloatTy, value)); } - case ISTORE_0: - case ISTORE_1: - case ISTORE_2: - case ISTORE_3: { - Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = - new StoreInst(v1, locals_[code[i]-ISTORE_0]); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + void do_dconst(unsigned bcI, double value) { + opStack_.push(ConstantFP::get(Type::DoubleTy, value)); } - case LSTORE_0: - case LSTORE_1: - case LSTORE_2: - case LSTORE_3: { - Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = - new StoreInst(v1, locals_[code[i]-LSTORE_0]); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + void do_ldc(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); } - case FSTORE_0: - case FSTORE_1: - case FSTORE_2: - case FSTORE_3: { - Value* v1 = opStack_.top(); opStack_.pop(); + + void do_load(unsigned bcI, JType type, unsigned index) { Instruction* in = - new StoreInst(v1, locals_[code[i]-FSTORE_0]); + new LoadInst(getOrCreateLocal(index, getType(type))); opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + bc2bbMap_[bcI]->getInstList().push_back(in); } - case DSTORE_0: - case DSTORE_1: - case DSTORE_2: - case DSTORE_3: { - Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = - new StoreInst(v1, locals_[code[i]-DSTORE_0]); - opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + + void do_aload(unsigned bcI, JType type) { + assert(0 && "not implemented"); } - case ASTORE_0: - case ASTORE_1: - case ASTORE_2: - case ASTORE_3: { + + void do_store(unsigned bcI, JType type, unsigned index) { Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = - new StoreInst(v1, locals_[code[i]-ASTORE_0]); + new StoreInst(v1, getOrCreateLocal(index, getType(type))); opStack_.push(in); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + bc2bbMap_[bcI]->getInstList().push_back(in); } - case IASTORE: - case LASTORE: - case FASTORE: - case DASTORE: - case AASTORE: - case BASTORE: - case CASTORE: - case SASTORE: + + + void do_astore(unsigned bcI, JType type) { assert(0 && "not implemented"); - case POP: + } + + void do_pop(unsigned bcI) { opStack_.pop(); - break; - case POP2: { + } + + void do_pop2(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); if (isOneSlotValue(v1)) opStack_.pop(); - break; } - case DUP: + + void do_dup(unsigned bcI) { opStack_.push(opStack_.top()); - break; - case DUP_X1: { + } + + void do_dup_x1(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); opStack_.push(v1); opStack_.push(v2); opStack_.push(v1); - break; } - case DUP_X2: { + + void do_dup_x2(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); if (isOneSlotValue(v2)) { @@ -447,9 +272,9 @@ opStack_.push(v2); opStack_.push(v1); } - break; } - case DUP2: { + + void do_dup2(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); if (isOneSlotValue(v1)) { Value* v2 = opStack_.top(); opStack_.pop(); @@ -462,9 +287,9 @@ opStack_.push(v1); opStack_.push(v1); } - break; } - case DUP2_X1: { + + void do_dup2_x1(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); if (isOneSlotValue(v1)) { @@ -480,9 +305,9 @@ opStack_.push(v2); opStack_.push(v1); } - break; } - case DUP2_X2: { + + void do_dup2_x2(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); if (isOneSlotValue(v1)) { @@ -518,299 +343,255 @@ opStack_.push(v1); } } - break; } - case SWAP: { + + void do_swap(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); opStack_.push(v1); opStack_.push(v2); - break; } - case IADD: - case LADD: - case FADD: - case DADD: { - Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::Add, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; - } - case ISUB: - case LSUB: - case FSUB: - case DSUB: { - Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::Sub, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; - } - case IMUL: - case LMUL: - case FMUL: - case DMUL: { - Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::Mul, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; - } - case IDIV: - case LDIV: - case FDIV: - case DDIV: { - Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::Div, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; - } - case IREM: - case LREM: - case FREM: - case DREM: { - Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::Rem, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; - } - case INEG: - case LNEG: - case FNEG: - case DNEG: - case ISHL: - case LSHL: { + + void do_add(unsigned bcI) { + do_binary_op_common(bcI, Instruction::Add); + } + + void do_sub(unsigned bcI) { + do_binary_op_common(bcI, Instruction::Sub); + } + + void do_mul(unsigned bcI) { + do_binary_op_common(bcI, Instruction::Mul); + } + + void do_div(unsigned bcI) { + do_binary_op_common(bcI, Instruction::Div); + } + + void do_rem(unsigned bcI) { + do_binary_op_common(bcI, Instruction::Rem); + } + + void do_neg(unsigned bcI) { + assert(0 && "not implemented"); + } + + void do_shl(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); Instruction* in = new ShiftInst(Instruction::Shl, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push(in); } - case ISHR: - case LSHR: { + + void do_shr(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); Instruction* in = new ShiftInst(Instruction::Shr, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push(in); } - case IUSHR: - case LUSHR: { + + void do_ushr(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = new CastInst(v1, v1->getType()->getUnsignedVersion()); - bc2bbMap_[bcStart]->getInstList().push_back(in); + bc2bbMap_[bcI]->getInstList().push_back(in); Value* v2 = opStack_.top(); opStack_.pop(); in = new ShiftInst(Instruction::Shr, in, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push(in); } - case IAND: - case LAND: { + + void do_and(unsigned bcI) { + do_binary_op_common(bcI, Instruction::And); + } + + void do_or(unsigned bcI) { + do_binary_op_common(bcI, Instruction::Or); + } + + void do_xor(unsigned bcI) { + do_binary_op_common(bcI, Instruction::Xor); + } + + void do_binary_op_common(unsigned bcI, Instruction::BinaryOps op) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::And, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + Instruction* in = BinaryOperator::create(op, v1, v2); + bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push(in); } - case IOR: - case LOR: { + + + void do_iinc(unsigned bcI, unsigned index, unsigned amount) { + assert(0 && "not implemented"); + } + + void do_convert(unsigned bcI, JType to) { Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::Or, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; + Instruction* in = new CastInst(v1, getType(to)); + bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push(in); + } + + void do_cmp(unsigned bcI) { + assert(0 && "not implemented"); + } + + void do_cmpl(unsigned bcI) { + assert(0 && "not implemented"); } - case IXOR: - case LXOR: { + + void do_cmpg(unsigned bcI) { + assert(0 && "not implemented"); + } + + void do_if(unsigned bcI, JSetCC cc, JType type, + unsigned t, unsigned f) { Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(Instruction::Xor, v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - break; - } - case IINC: - case I2L: - case I2F: - case I2D: - case L2I: - case L2F: - case L2D: - case F2I: - case F2L: - case F2D: - case D2I: - case D2L: - case D2F: - case I2B: - case I2C: - case I2S: - case LCMP: - case FCMPL: - case FCMPG: - case DCMPL: - case DCMPG: - assert(0 && "not implemented"); - case IFEQ: - case IFNE: - case IFLT: - case IFGE: - case IFGT: - case IFLE: { - static Instruction::BinaryOps java2llvm[] = { - Instruction::SetEQ, - Instruction::SetNE, - Instruction::SetLT, - Instruction::SetGE, - Instruction::SetGT, - Instruction::SetLE, - }; - Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = ConstantSInt::get(Type::IntTy, 0); - Instruction* in = new SetCondInst(java2llvm[i-IFEQ], v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], - bc2bbMap_[i + 1], - bc2bbMap_[bcStart]); - break; - } - case IF_ICMPEQ: - case IF_ICMPNE: - case IF_ICMPLT: - case IF_ICMPGE: - case IF_ICMPGT: - case IF_ICMPLE: { - static Instruction::BinaryOps java2llvm[] = { - Instruction::SetEQ, - Instruction::SetNE, - Instruction::SetLT, - Instruction::SetGE, - Instruction::SetGT, - Instruction::SetLE, - }; + Value* v2 = llvm::Constant::getNullValue(getType(type)); + Instruction* in = new SetCondInst(getSetCC(cc), v1, v2); + bc2bbMap_[bcI]->getInstList().push_back(in); + new BranchInst(bc2bbMap_[t], + bc2bbMap_[f], + bc2bbMap_[bcI]); + } + + void do_ifcmp(unsigned bcI, JSetCC cc, + unsigned t, unsigned f) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = new SetCondInst(java2llvm[i-IF_ICMPEQ], v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], - bc2bbMap_[i + 1], - bc2bbMap_[bcStart]); - break; - } - case IF_IACMPEQ: - case IF_IACMPNE: { - static Instruction::BinaryOps java2llvm[] = { - Instruction::SetEQ, - Instruction::SetNE, - }; + Instruction* in = new SetCondInst(getSetCC(cc), v1, v2); + bc2bbMap_[bcI]->getInstList().push_back(in); + new BranchInst(bc2bbMap_[t], + bc2bbMap_[f], + bc2bbMap_[bcI]); + } + + void do_goto(unsigned bcI, unsigned target) { + new BranchInst(bc2bbMap_[target], bc2bbMap_[bcI]); + } + + void do_jsr(unsigned bcI, unsigned target) { + assert(0 && "not implemented"); + } + + void do_ret(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_switch(unsigned bcI, + unsigned defTarget, + const SwitchCases& sw) { Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = new SetCondInst(java2llvm[i-IF_IACMPEQ], v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], - bc2bbMap_[i + 1], - bc2bbMap_[bcStart]); - break; - } - case GOTO: - new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)]); - break; - case JSR: - case RET: - assert(0 && "not implemented"); - case TABLESWITCH: { - Value* v1 = opStack_.top(); opStack_.pop(); - skipPadBytes(code, i); - int def = readSInt(code, i); - int low = readSInt(code, i); - int high = readSInt(code, i); - SwitchInst* in = - new SwitchInst(v1, bc2bbMap_[bcStart + def],bc2bbMap_[bcStart]); - while (low <= high) - in->addCase(ConstantSInt::get(Type::IntTy, low++), - bc2bbMap_[bcStart + readSInt(code, i)]); - break; - } - case LOOKUPSWITCH: { - Value* v1 = opStack_.top(); opStack_.pop(); - skipPadBytes(code, i); - int def = readSInt(code, i); - unsigned pairCount = readUInt(code, i); SwitchInst* in = - new SwitchInst(v1, bc2bbMap_[bcStart + def],bc2bbMap_[bcStart]); - while (pairCount--) - in->addCase(ConstantSInt::get(Type::IntTy, readSInt(code, i)), - bc2bbMap_[bcStart + readSInt(code, i)]); - break; - } - case IRETURN: - case LRETURN: - case FRETURN: - case DRETURN: - case ARETURN: { - Value* v1 = opStack_.top(); opStack_.pop(); - new ReturnInst(v1, bc2bbMap_[bcStart]); - break; - } - case RETURN: - new ReturnInst(NULL, bc2bbMap_[bcStart]); - break; - case GETSTATIC: - case PUTSTATIC: - case GETFIELD: - case PUTFIELD: - case INVOKEVIRTUAL: + new SwitchInst(v1, bc2bbMap_[defTarget], bc2bbMap_[bcI]); + for (unsigned i = 0; i < sw.size(); ++i) + in->addCase(ConstantSInt::get(Type::IntTy, sw[i].first), + bc2bbMap_[sw[i].second]); + } + + void do_return(unsigned bcI) { + Value* v1 = opStack_.top(); opStack_.pop(); + new ReturnInst(v1, bc2bbMap_[bcI]); + } + + void do_return_void(unsigned bcI) { + new ReturnInst(NULL, bc2bbMap_[bcI]); + } + + void do_getstatic(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_putstatic(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_getfield(unsigned bcI, unsigned index) { assert(0 && "not implemented"); - case INVOKESPECIAL: { - unsigned index = readUShort(code, i); + } + + void do_putfield(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_invokevirtual(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_invokespecial(unsigned bcI, unsigned index) { DEBUG(std::cerr << "ignoring INVOKESPECIAL\n"); - break; } - case INVOKESTATIC: - case INVOKEINTERFACE: - case XXXUNUSEDXXX: - case NEW: - case NEWARRAY: - case ANEWARRAY: - case ARRAYLENGTH: - case ATHROW: - case CHECKCAST: - case INSTANCEOF: - case MONITORENTER: - case MONITOREXIT: -// case WIDE: - case MULTIANEWARRAY: - assert(0 && "not implemented"); - case IFNULL: - case IFNONNULL: { - static Instruction::BinaryOps java2llvm[] = { - Instruction::SetEQ, - Instruction::SetNE, - }; - Value* v1 = opStack_.top(); opStack_.pop(); - Value* v2 = llvm::Constant::getNullValue(ObjectRefTy); - Instruction* in = new SetCondInst(java2llvm[i-IFNULL], v1, v2); - bc2bbMap_[bcStart]->getInstList().push_back(in); - new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], - bc2bbMap_[i + 1], - bc2bbMap_[bcStart]); - break; - } - case GOTO_W: - new BranchInst(bc2bbMap_[bcStart + readSInt(code, i)]); - break; - case JSR_W: - assert(0 && "not implemented"); - case BREAKPOINT: - case IMPDEP1: - case IMPDEP2: - case NOP: - break; + + void do_invokestatic(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); } - } + + void do_invokeinterface(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_new(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_newarray(unsigned bcI, JType type) { + assert(0 && "not implemented"); + } + + void do_anewarray(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_arraylength(unsigned bcI) { + assert(0 && "not implemented"); + } + + void do_athrow(unsigned bcI) { + assert(0 && "not implemented"); + } + + void do_checkcast(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_instanceof(unsigned bcI, unsigned index) { + assert(0 && "not implemented"); + } + + void do_monitorenter(unsigned bcI) { + assert(0 && "not implemented"); + } + + void do_monitorexit(unsigned bcI) { + assert(0 && "not implemented"); + } + + void do_multianewarray(unsigned bcI, + unsigned index, + unsigned dims) { + assert(0 && "not implemented"); + } + + private: + OperandStack opStack_; + Locals locals_; + BC2BBMap bc2bbMap_; + }; + +} } } // namespace llvm::Java:: + +Compiler::Compiler() + : compilerImpl_(new CompilerImpl()) +{ + +} + +Compiler::~Compiler() +{ + delete compilerImpl_; } Module* Compiler::compile(const ClassFile& cf) @@ -823,7 +604,7 @@ const Java::Methods& methods = cf.getMethods(); for (Java::Methods::const_iterator i = methods.begin(), e = methods.end(); i != e; ++i) - compileMethod(*module, cf, **i); + compilerImpl_->compileMethod(*module, cf, **i); return module; } From alkis at cs.uiuc.edu Mon May 24 21:14:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 21:14:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405250211.VAA09650@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.17 -> 1.18 --- Log message: Add names to variables. --- Diffs of the changes: (+11 -10) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.17 llvm-java/lib/Compiler/Compiler.cpp:1.18 --- llvm-java/lib/Compiler/Compiler.cpp:1.17 Mon May 24 20:48:00 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 21:11:15 2004 @@ -32,11 +32,12 @@ namespace llvm { namespace Java { namespace { + const std::string TMP("tmp"); + typedef std::vector BC2BBMap; typedef std::stack > OperandStack; typedef std::vector Locals; - inline bool isTwoSlotValue(const Value* v) { return v->getType() == Type::LongTy | v->getType() == Type::DoubleTy; } @@ -213,7 +214,7 @@ void do_load(unsigned bcI, JType type, unsigned index) { Instruction* in = - new LoadInst(getOrCreateLocal(index, getType(type))); + new LoadInst(getOrCreateLocal(index, getType(type)), TMP); opStack_.push(in); bc2bbMap_[bcI]->getInstList().push_back(in); } @@ -379,7 +380,7 @@ void do_shl(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = new ShiftInst(Instruction::Shl, v1, v2); + Instruction* in = new ShiftInst(Instruction::Shl, v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } @@ -387,7 +388,7 @@ void do_shr(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = new ShiftInst(Instruction::Shr, v1, v2); + Instruction* in = new ShiftInst(Instruction::Shr, v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } @@ -395,10 +396,10 @@ void do_ushr(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = - new CastInst(v1, v1->getType()->getUnsignedVersion()); + new CastInst(v1, v1->getType()->getUnsignedVersion(), TMP); bc2bbMap_[bcI]->getInstList().push_back(in); Value* v2 = opStack_.top(); opStack_.pop(); - in = new ShiftInst(Instruction::Shr, in, v2); + in = new ShiftInst(Instruction::Shr, in, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } @@ -418,7 +419,7 @@ void do_binary_op_common(unsigned bcI, Instruction::BinaryOps op) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(op, v1, v2); + Instruction* in = BinaryOperator::create(op, v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } @@ -430,7 +431,7 @@ void do_convert(unsigned bcI, JType to) { Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = new CastInst(v1, getType(to)); + Instruction* in = new CastInst(v1, getType(to), TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } @@ -451,7 +452,7 @@ unsigned t, unsigned f) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = llvm::Constant::getNullValue(getType(type)); - Instruction* in = new SetCondInst(getSetCC(cc), v1, v2); + Instruction* in = new SetCondInst(getSetCC(cc), v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); new BranchInst(bc2bbMap_[t], bc2bbMap_[f], @@ -462,7 +463,7 @@ unsigned t, unsigned f) { Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); - Instruction* in = new SetCondInst(getSetCC(cc), v1, v2); + Instruction* in = new SetCondInst(getSetCC(cc), v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); new BranchInst(bc2bbMap_[t], bc2bbMap_[f], From alkis at cs.uiuc.edu Mon May 24 21:19:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 21:19:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405250216.VAA09697@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.18 -> 1.19 --- Log message: Add names to local variables. --- Diffs of the changes: (+2 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.18 llvm-java/lib/Compiler/Compiler.cpp:1.19 --- llvm-java/lib/Compiler/Compiler.cpp:1.18 Mon May 24 21:11:15 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 21:16:34 2004 @@ -157,7 +157,8 @@ Value* getOrCreateLocal(unsigned index, const Type* type) { if (!locals_[index]) { BasicBlock* entry = bc2bbMap_[0]; - Instruction* alloc = new AllocaInst(type); + Instruction* alloc = + new AllocaInst(type, NULL, "local" + utostr(index)); locals_[index] = alloc; Instruction* store = new StoreInst( llvm::Constant::getNullValue(alloc->getType()), alloc); From alkis at cs.uiuc.edu Mon May 24 21:27:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 21:27:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405250224.VAA09732@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.19 -> 1.20 --- Log message: Use better names for functions. --- Diffs of the changes: (+7 -2) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.19 llvm-java/lib/Compiler/Compiler.cpp:1.20 --- llvm-java/lib/Compiler/Compiler.cpp:1.19 Mon May 24 21:16:34 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 21:24:38 2004 @@ -176,9 +176,14 @@ DEBUG(std::cerr << "compiling method: " << method.getName()->str() << '\n'); + std::string name = cf.getThisClass()->getName()->str(); + name += '/'; + name += method.getName()->str(); + name += method.getDescriptor()->str(); + + // FIXME: use proper function type Function* function = - module.getOrInsertFunction(method.getName()->str(), - Type::VoidTy, 0); + module.getOrInsertFunction(name, Type::VoidTy, 0); const Java::CodeAttribute* codeAttr = Java::getCodeAttribute(method.getAttributes()); From alkis at cs.uiuc.edu Mon May 24 22:23:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 22:23:03 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405250320.WAA09874@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.20 -> 1.21 --- Log message: Actually use the conditional in if and ifcmp bytecodes. --- Diffs of the changes: (+2 -0) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.20 llvm-java/lib/Compiler/Compiler.cpp:1.21 --- llvm-java/lib/Compiler/Compiler.cpp:1.20 Mon May 24 21:24:38 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 22:20:05 2004 @@ -462,6 +462,7 @@ bc2bbMap_[bcI]->getInstList().push_back(in); new BranchInst(bc2bbMap_[t], bc2bbMap_[f], + in, bc2bbMap_[bcI]); } @@ -473,6 +474,7 @@ bc2bbMap_[bcI]->getInstList().push_back(in); new BranchInst(bc2bbMap_[t], bc2bbMap_[f], + in, bc2bbMap_[bcI]); } From alkis at cs.uiuc.edu Mon May 24 22:49:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 22:49:02 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405250346.WAA09986@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h updated: 1.7 -> 1.8 --- Log message: Simplify code for readSInt() and fix bug in skipPadBytes(). --- Diffs of the changes: (+5 -6) Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.7 llvm-java/include/llvm/Java/Bytecode.h:1.8 --- llvm-java/include/llvm/Java/Bytecode.h:1.7 Mon May 24 20:48:00 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Mon May 24 22:46:15 2004 @@ -250,18 +250,17 @@ } inline int readSInt(const uint8_t* code, unsigned& i) { - return ((readUByte(code, i) << 24) | - (readUByte(code, i) << 16) | - (readUByte(code, i) << 8) | - readUByte(code, i)); + return (readUShort(code, i) << 16) | readUShort(code, i); } inline unsigned readUInt(const uint8_t* code, unsigned& i) { return readSInt(code, i); } - inline void skipPadBytes(const uint8_t* code, unsigned& i) { - while (((unsigned)&code[++i]) & 0XFF); + inline void skipPadBytes(unsigned& i) { + unsigned lastTwoBits = i & 0x3; + i += (4 - lastTwoBits) & 0x3; + --i; } } } // namespace llvm::Java From alkis at cs.uiuc.edu Mon May 24 22:50:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 22:50:01 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/BytecodeParser.h Message-ID: <200405250346.WAA10015@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: BytecodeParser.h updated: 1.1 -> 1.2 --- Log message: Simplify code for readSInt() and fix bug in skipPadBytes(). --- Diffs of the changes: (+2 -2) Index: llvm-java/include/llvm/Java/BytecodeParser.h diff -u llvm-java/include/llvm/Java/BytecodeParser.h:1.1 llvm-java/include/llvm/Java/BytecodeParser.h:1.2 --- llvm-java/include/llvm/Java/BytecodeParser.h:1.1 Mon May 24 20:48:00 2004 +++ llvm-java/include/llvm/Java/BytecodeParser.h Mon May 24 22:46:47 2004 @@ -493,7 +493,7 @@ break; case TABLESWITCH: { switchCases_.clear(); - skipPadBytes(code, i); + skipPadBytes(i); int def = readSInt(code, i); int low = readSInt(code, i); int high = readSInt(code, i); @@ -506,7 +506,7 @@ } case LOOKUPSWITCH: { switchCases_.clear(); - skipPadBytes(code, i); + skipPadBytes(i); int def = readSInt(code, i); unsigned pairCount = readUInt(code, i); switchCases_.reserve(pairCount); From alkis at cs.uiuc.edu Mon May 24 22:54:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Mon May 24 22:54:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405250351.WAA10058@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.21 -> 1.22 --- Log message: Create basic blocks for default targets in switch statements. --- Diffs of the changes: (+3 -0) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.21 llvm-java/lib/Compiler/Compiler.cpp:1.22 --- llvm-java/lib/Compiler/Compiler.cpp:1.21 Mon May 24 22:20:05 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Mon May 24 22:50:51 2004 @@ -92,6 +92,9 @@ void do_switch(unsigned bcI, unsigned defTarget, const SwitchCases& sw) { + if (!bc2bbMap_[defTarget]) + bc2bbMap_[defTarget] = + new BasicBlock("bb at bc" + utostr(defTarget), &function_); for (unsigned i = 0; i < sw.size(); ++i) { unsigned target = sw[i].second; if (!bc2bbMap_[target]) From lattner at cs.uiuc.edu Mon May 24 23:31:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon May 24 23:31:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/cast.ll Message-ID: <200405250428.XAA11681@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: cast.ll updated: 1.19 -> 1.20 --- Log message: Add a new test16 and fix some other tests that were not properly written --- Diffs of the changes: (+8 -4) Index: llvm/test/Regression/Transforms/InstCombine/cast.ll diff -u llvm/test/Regression/Transforms/InstCombine/cast.ll:1.19 llvm/test/Regression/Transforms/InstCombine/cast.ll:1.20 --- llvm/test/Regression/Transforms/InstCombine/cast.ll:1.19 Fri Feb 27 23:26:06 2004 +++ llvm/test/Regression/Transforms/InstCombine/cast.ll Mon May 24 23:28:43 2004 @@ -88,14 +88,18 @@ } bool %test14(sbyte %A) { - %B = cast sbyte %A to ubyte - %X = setlt ubyte %B, 128 ; setge %A, 0 + %c = cast sbyte %A to ubyte + %X = setlt ubyte %c, 128 ; setge %A, 0 ret bool %X } bool %test15(ubyte %A) { - %B = cast ubyte %A to sbyte - %X = setlt sbyte %B, 0 ; setgt %A, 127 + %c = cast ubyte %A to sbyte + %X = setlt sbyte %c, 0 ; setgt %A, 127 ret bool %X } +bool %test16(int* %P) { + %c = cast int* %P to bool ;; setne P, null + ret bool %c +} From lattner at cs.uiuc.edu Mon May 24 23:32:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon May 24 23:32:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200405250429.XAA11692@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.203 -> 1.204 --- Log message: Implement instcombine/cast.ll:test16: Canonicalize cast X to bool into a setne instruction --- Diffs of the changes: (+5 -0) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.203 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.204 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.203 Thu May 13 15:56:34 2004 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon May 24 23:29:21 2004 @@ -1996,6 +1996,11 @@ } } + // If this is a cast to bool, turn it into the appropriate setne instruction. + if (CI.getType() == Type::BoolTy) + return BinaryOperator::create(Instruction::SetNE, CI.getOperand(0), + Constant::getNullValue(CI.getOperand(0)->getType())); + // If casting the result of a getelementptr instruction with no offset, turn // this into a cast of the original pointer! // From lattner at cs.uiuc.edu Tue May 25 00:35:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue May 25 00:35:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Constants.h Message-ID: <200405250532.AAA26896@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: Constants.h updated: 1.46 -> 1.47 --- Log message: Add some helpers --- Diffs of the changes: (+3 -0) Index: llvm/include/llvm/Constants.h diff -u llvm/include/llvm/Constants.h:1.46 llvm/include/llvm/Constants.h:1.47 --- llvm/include/llvm/Constants.h:1.46 Sun Apr 4 18:20:26 2004 +++ llvm/include/llvm/Constants.h Tue May 25 00:32:13 2004 @@ -583,6 +583,9 @@ static Constant *getShl(Constant *C1, Constant *C2); static Constant *getShr(Constant *C1, Constant *C2); + static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr + static Constant *getSShr(Constant *C1, Constant *C2); // signed shr + /// Getelementptr form... /// static Constant *getGetElementPtr(Constant *C, From lattner at cs.uiuc.edu Tue May 25 00:36:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue May 25 00:36:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp Message-ID: <200405250532.AAA27971@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Constants.cpp updated: 1.87 -> 1.88 --- Log message: Implement some helpers --- Diffs of the changes: (+10 -0) Index: llvm/lib/VMCore/Constants.cpp diff -u llvm/lib/VMCore/Constants.cpp:1.87 llvm/lib/VMCore/Constants.cpp:1.88 --- llvm/lib/VMCore/Constants.cpp:1.87 Sun Apr 4 18:20:30 2004 +++ llvm/lib/VMCore/Constants.cpp Tue May 25 00:32:43 2004 @@ -372,7 +372,17 @@ return get(Instruction::Shr, C1, C2); } +Constant *ConstantExpr::getUShr(Constant *C1, Constant *C2) { + if (C1->getType()->isUnsigned()) return getShr(C1, C2); + return getCast(getShr(getCast(C1, + C1->getType()->getUnsignedVersion()), C2), C1->getType()); +} +Constant *ConstantExpr::getSShr(Constant *C1, Constant *C2) { + if (C1->getType()->isSigned()) return getShr(C1, C2); + return getCast(getShr(getCast(C1, + C1->getType()->getSignedVersion()), C2), C1->getType()); +} //===----------------------------------------------------------------------===// From lattner at cs.uiuc.edu Tue May 25 01:34:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue May 25 01:34:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/shift.ll Message-ID: <200405250630.BAA02017@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: shift.ll updated: 1.15 -> 1.16 --- Log message: New testcase --- Diffs of the changes: (+6 -0) Index: llvm/test/Regression/Transforms/InstCombine/shift.ll diff -u llvm/test/Regression/Transforms/InstCombine/shift.ll:1.15 llvm/test/Regression/Transforms/InstCombine/shift.ll:1.16 --- llvm/test/Regression/Transforms/InstCombine/shift.ll:1.15 Fri Apr 9 18:47:24 2004 +++ llvm/test/Regression/Transforms/InstCombine/shift.ll Tue May 25 01:30:49 2004 @@ -109,3 +109,9 @@ ret int %V } +bool %test16(int %X) { + %tmp.3 = shr int %X, ubyte 4 + %tmp.6 = and int %tmp.3, 1 + %tmp.7 = setne int %tmp.6, 0 ;; X & 16 != 0 + ret bool %tmp.7 +} From lattner at cs.uiuc.edu Tue May 25 01:35:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue May 25 01:35:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200405250632.BAA02026@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.204 -> 1.205 --- Log message: Implement InstCombine:shift.ll:test16, which turns (X >> C1) & C2 != C3 into (X & (C2 << C1)) != (C3 << C1), where the shift may be either left or right and the compare may be any one. This triggers 1546 times in 176.gcc alone, as it is a common pattern that occurs for bitfield accesses. --- Diffs of the changes: (+35 -0) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.204 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.205 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.204 Mon May 24 23:29:21 2004 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue May 25 01:32:08 2004 @@ -1475,6 +1475,41 @@ // integers at the end of their ranges... // if (ConstantInt *CI = dyn_cast(Op1)) { + if (Instruction *LHSI = dyn_cast(Op0)) + if (LHSI->hasOneUse() && LHSI->getNumOperands() == 2 && + isa(LHSI->getOperand(1))) { + // If this is: (X >> C1) & C2 != C3 (where any shift and any compare + // could exist), turn it into (X & (C2 << C1)) != (C3 << C1). This + // happens a LOT in code produced by the C front-end, for bitfield + // access. + if (LHSI->getOpcode() == Instruction::And && + LHSI->getOperand(0)->hasOneUse()) + if (ShiftInst *Shift = dyn_cast(LHSI->getOperand(0))) + if (ConstantUInt *ShAmt = + dyn_cast(Shift->getOperand(1))) { + ConstantInt *AndCST = cast(LHSI->getOperand(1)); + + // We can fold this as long as we can't shift unknown bits into + // the mask. This can only happen with signed shift rights, as + // they sign-extend. + const Type *Ty = Shift->getType(); + if (Shift->getOpcode() != Instruction::Shr || + Shift->getType()->isUnsigned() || + // To test for the bad case of the signed shr, see if any of + // the bits shifted in could be tested after the mask. + ConstantExpr::getAnd(ConstantExpr::getShl(ConstantInt::getAllOnesValue(Ty), ConstantUInt::get(Type::UByteTy, Ty->getPrimitiveSize()*8-ShAmt->getValue())), AndCST)->isNullValue()) { + unsigned ShiftOp = Shift->getOpcode() == Instruction::Shl + ? Instruction::Shr : Instruction::Shl; + I.setOperand(1, ConstantExpr::get(ShiftOp, CI, ShAmt)); + LHSI->setOperand(1, ConstantExpr::get(ShiftOp, AndCST, ShAmt)); + LHSI->setOperand(0, Shift->getOperand(0)); + WorkList.push_back(Shift); // Shift is probably dead. + AddUsesToWorkList(I); + return &I; + } + } + } + // Simplify seteq and setne instructions... if (I.getOpcode() == Instruction::SetEQ || I.getOpcode() == Instruction::SetNE) { From vadve at cs.uiuc.edu Tue May 25 03:35:03 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Tue May 25 03:35:03 2004 Subject: [llvm-commits] CVS: llvm/test/Programs/MultiSource/Benchmarks/Olden/voronoi/newvor.c Message-ID: <200405250831.DAA31434@psmith.cs.uiuc.edu> Changes in directory llvm/test/Programs/MultiSource/Benchmarks/Olden/voronoi: newvor.c updated: 1.3 -> 1.4 --- Log message: Fixed myalign() to use memalign() instead of doing it manually, which causes most heap nodes to be collapsed. --- Diffs of the changes: (+10 -0) Index: llvm/test/Programs/MultiSource/Benchmarks/Olden/voronoi/newvor.c diff -u llvm/test/Programs/MultiSource/Benchmarks/Olden/voronoi/newvor.c:1.3 llvm/test/Programs/MultiSource/Benchmarks/Olden/voronoi/newvor.c:1.4 --- llvm/test/Programs/MultiSource/Benchmarks/Olden/voronoi/newvor.c:1.3 Sun Oct 19 18:54:09 2003 +++ llvm/test/Programs/MultiSource/Benchmarks/Olden/voronoi/newvor.c Tue May 25 03:31:18 2004 @@ -163,14 +163,24 @@ /* memalign() on my SGI doesn't work. Thus, I have to write my own */ void* myalign(int align_size, int alloc_size) { +#ifdef MEMALIGN_IS_NOT_AVAILABLE char* base = (char*)malloc(alloc_size + align_size); +#else + char* base = (char*)memalign(align_size, alloc_size); +#endif void *Result; if (base == NULL){ printf("myalign() failed\n"); exit(-1); } +#ifdef MEMALIGN_IS_NOT_AVAILABLE return (void*)(base + align_size - ((uptrint)base % align_size)); +#else + return base; +#endif } + + QUAD_EDGE alloc_edge() { QUAD_EDGE ans; From vadve at cs.uiuc.edu Tue May 25 03:35:11 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Tue May 25 03:35:11 2004 Subject: [llvm-commits] CVS: llvm/lib/Analysis/DataStructure/Local.cpp Message-ID: <200405250815.DAA23989@psmith.cs.uiuc.edu> Changes in directory llvm/lib/Analysis/DataStructure: Local.cpp updated: 1.103 -> 1.104 --- Log message: Recognize memalign and friends, and handle them specially. --- Diffs of the changes: (+2 -1) Index: llvm/lib/Analysis/DataStructure/Local.cpp diff -u llvm/lib/Analysis/DataStructure/Local.cpp:1.103 llvm/lib/Analysis/DataStructure/Local.cpp:1.104 --- llvm/lib/Analysis/DataStructure/Local.cpp:1.103 Sun May 23 16:14:09 2004 +++ llvm/lib/Analysis/DataStructure/Local.cpp Tue May 25 03:14:52 2004 @@ -523,7 +523,8 @@ N->setModifiedMarker(); return; default: - if (F->getName() == "calloc") { + if (F->getName() == "calloc" || F->getName() == "posix_memalign" || + F->getName() == "memalign" || F->getName() == "valloc") { setDestTo(*CS.getInstruction(), createNode()->setHeapNodeMarker()->setModifiedMarker()); return; From reid at x10sys.com Tue May 25 07:21:09 2004 From: reid at x10sys.com (Reid Spencer) Date: Tue May 25 07:21:09 2004 Subject: [llvm-commits] ATTENTION: SymbolTable Change!! Message-ID: <1085475570.15835.353.camel@bashful.x10sys.com> LLVMers, On the way to resolving bug 122, I am committing my SymbolTable rewrite. If you are working on anything that uses the SymbolTable, I suggest you read the documentation in include/llvm/SymbolTable.h. The changes I've committed reduce the use of Type::TypeTy. This static member will go away in the future, so please do not propagate new code that uses it. There is no reason to use it in order to access the "type plane" in the new SymbolTable. There are some corner cases where its still needed elsewhere, however. Here's a quickie summary of how the new SymbolTable interface affects its users: 1. The data structures are embedded so if you were thinking of using any std::map functionality, its gone. 2. Some of the generic std::map functionality has been added to SymbolTable to make it compatible (e.g. empty() ). 3. The iterator names and concepts have changed significantly. In the future, please use the following conventions: (a) To iterate over the all type planes use plane_begin() and plane_end(). These are semantically equivalent to the begin() and end() methods inherited from std::map on the old SymbolTable. For iterating over planes, please use an iterator named PI. (b) To iterate over the type type plane (the plane of Type::TypeTy), please use type_begin() and type_end(). Previously, users of the SymbolTable would use ST.find(Type::TypeTy) to access the type type plane. This is now semantically incorrect and will always return std::map.end()! Use type_begin() and type_end() instead. These will get you an iterator over the name/Type pairs in the type type plane. For iteration over types, please use an iterator named TI. (c) To iterate over the values in one type plane (except for the plane of types), use value_begin(Type*) and value_end(Type*). These methods will get you an iterator over the name/Value pairs in the single type plane given by the arguments. For iterating over values, please use an iterator named VI. 4. Some functionality (like "strip") has been moved into the SymbolTable. This means that the SymbolStripping pass is now a single call to the SymbolTable::strip() method. These changes pass all feature tests. Some of the regression tests fail and I'm not sure if its due to (a) my changes, (b) my old cfrontend, or (c) someone else's changes. I suspect its more of (b) and (c) but I will look into this in more detail later this week. Next steps on bug 122 (each a separate commit): * Completely rid ourselves of Type::TypeTy. This involves a rewrite of the SlotCalculator which will be divided up between Bytecode writer and ASM writer. * Make Type not inherit from Value and fix the resulting fall out. * Get rid of ConstantPointerRef. If you have *any* questions about this, please email me. Thanks, Reid. Here's the Feature/Regression test results: --- STATISTICS --------------------------------------------------------------- 902 tests total 874 ( 97%) tests as expected 27 ( 3%) tests unexpected FAIL 1 ( 0%) tests unexpected PASS --- TESTS WITH UNEXPECTED OUTCOMES ------------------------------------------- Regression.Assembler.ConstantExprFold : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/trConstantExprFold.llx/testscript.ConstantExprFold.llx Output: /proj/work/llvm/build/test/tmp/trConstantExprFold.llx/testscript.ConstantExprFold.llx.out Regression.C++Frontend.2004-01-11-DynamicInitializedConstant: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2004-01-11-DynamicInitializedConstant.cpp.tr/testscript.2004-01-11-DynamicInitializedConstant.cpp.tr Output: /proj/work/llvm/build/test/tmp/tr2004-01-11-DynamicInitializedConstant.cpp.tr/testscript.2004-01-11-DynamicInitializedConstant.cpp.tr.out Regression.C++Frontend.2004-03-08-ReinterpretCastCopy: FAIL , expected PASS Compiling C++ code failed Regression.C++Frontend.2004-03-15-CleanupsAndGotos: FAIL , expected PASS Compiling C++ code failed Regression.CFrontend.2002-07-14-MiscListTests : FAIL , expected PASS Compiling code failed Regression.CFrontend.2003-06-29-MultipleFunctionDefinition: FAIL , expected PASS Compiling C code failed Regression.CFrontend.2003-12-14-ExternInlineSupport: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2003-12-14-ExternInlineSupport.c.tr/testscript.2003-12-14-ExternInlineSupport.c.tr Output: /proj/work/llvm/build/test/tmp/tr2003-12-14-ExternInlineSupport.c.tr/testscript.2003-12-14-ExternInlineSupport.c.tr.out Regression.CFrontend.2004-01-08-ExternInlineRedefine: FAIL , expected PASS Compiling C code failed Regression.CFrontend.2004-02-12-LargeAggregateCopy: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2004-02-12-LargeAggregateCopy.c.tr/testscript.2004-02-12-LargeAggregateCopy.c.tr Output: /proj/work/llvm/build/test/tmp/tr2004-02-12-LargeAggregateCopy.c.tr/testscript.2004-02-12-LargeAggregateCopy.c.tr.out Regression.CFrontend.2004-02-13-BuiltinFrameReturnAddress: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2004-02-13-BuiltinFrameReturnAddress.c.tr/testscript.2004-02-13-BuiltinFrameReturnAddress.c.tr Output: /proj/work/llvm/build/test/tmp/tr2004-02-13-BuiltinFrameReturnAddress.c.tr/testscript.2004-02-13-BuiltinFrameReturnAddress.c.tr.out Regression.CFrontend.2004-02-13-IllegalVararg : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2004-02-13-IllegalVararg.c.tr/testscript.2004-02-13-IllegalVararg.c.tr Output: /proj/work/llvm/build/test/tmp/tr2004-02-13-IllegalVararg.c.tr/testscript.2004-02-13-IllegalVararg.c.tr.out Regression.CFrontend.2004-02-13-Memset : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2004-02-13-Memset.c.tr/testscript.2004-02-13-Memset.c.tr Output: /proj/work/llvm/build/test/tmp/tr2004-02-13-Memset.c.tr/testscript.2004-02-13-Memset.c.tr.out Regression.CFrontend.2004-02-14-ZeroInitializer: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2004-02-14-ZeroInitializer.c.tr/testscript.2004-02-14-ZeroInitializer.c.tr Output: /proj/work/llvm/build/test/tmp/tr2004-02-14-ZeroInitializer.c.tr/testscript.2004-02-14-ZeroInitializer.c.tr.out Regression.CFrontend.2004-03-07-ComplexDivEquals: FAIL , expected PASS Compiling C code failed Regression.CFrontend.2004-03-15-SimpleIndirectGoto: FAIL , expected PASS Compiling C code failed Regression.CFrontend.2004-03-16-AsmRegisterCrash: FAIL , expected PASS Compiling C code failed Regression.CFrontend.2004-05-21-IncompleteEnum: FAIL , expected PASS Compiling C code failed Regression.CodeGen.Generic.2004-04-09-SameValueCoalescing: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2004-04-09-SameValueCoalescing.llx/testscript.2004-04-09-SameValueCoalescing.llx Output: /proj/work/llvm/build/test/tmp/tr2004-04-09-SameValueCoalescing.llx/testscript.2004-04-09-SameValueCoalescing.llx.out Regression.CodeGen.Generic.BasicInstrs : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/trBasicInstrs.llx/testscript.BasicInstrs.llx Output: /proj/work/llvm/build/test/tmp/trBasicInstrs.llx/testscript.BasicInstrs.llx.out Regression.Linker.2003-01-30-LinkerTypeRename : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2003-01-30-LinkerTypeRename.ll/testscript.2003-01-30-LinkerTypeRename.ll Output: /proj/work/llvm/build/test/tmp/tr2003-01-30-LinkerTypeRename.ll/testscript.2003-01-30-LinkerTypeRename.ll.out Regression.Linker.2003-10-21-ConflictingTypesTolerance: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2003-10-21-ConflictingTypesTolerance.ll/testscript.2003-10-21-ConflictingTypesTolerance.ll Output: /proj/work/llvm/build/test/tmp/tr2003-10-21-ConflictingTypesTolerance.ll/testscript.2003-10-21-ConflictingTypesTolerance.ll.out Regression.Other.2002-03-11-ExprAssertion : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2002-03-11-ExprAssertion.ll/testscript.2002-03-11-ExprAssertion.ll Output: /proj/work/llvm/build/test/tmp/tr2002-03-11-ExprAssertion.ll/testscript.2002-03-11-ExprAssertion.ll.out Regression.Other.2002-03-14-ValueToLarge : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2002-03-14-ValueToLarge.ll/testscript.2002-03-14-ValueToLarge.ll Output: /proj/work/llvm/build/test/tmp/tr2002-03-14-ValueToLarge.ll/testscript.2002-03-14-ValueToLarge.ll.out Regression.Transforms.CorrelatedExprs.nullpointer: XPASS Regression.Transforms.InstCombine.load : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/trload.ll/testscript.load.ll Output: /proj/work/llvm/build/test/tmp/trload.ll/testscript.load.ll.out Regression.Transforms.InstCombine.phi : FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/trphi.ll/testscript.phi.ll Output: /proj/work/llvm/build/test/tmp/trphi.ll/testscript.phi.ll.out Regression.Transforms.SimplifyCFG.2002-05-05-EmptyBlockMerge: FAIL , expected PASS Script: /proj/work/llvm/build/test/tmp/tr2002-05-05-EmptyBlockMerge.ll/testscript.2002-05-05-EmptyBlockMerge.ll Output: /proj/work/llvm/build/test/tmp/tr2002-05-05-EmptyBlockMerge.ll/testscript.2002-05-05-EmptyBlockMerge.ll.out Regression.Verifier.2002-04-13-RetTypes : FAIL , expected PASS /proj/work/llvm/llvm/test/Regression/Verifier/2002-04-13-RetTypes.ll assembled gmake: [qmtest] Error 1 (ignored) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20040525/94a7a5a7/attachment.bin From llvm at cs.uiuc.edu Tue May 25 07:21:14 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:14 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Verifier.cpp Message-ID: <200405250853.DAA13701@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Verifier.cpp updated: 1.100 -> 1.101 --- Log message: Convert to SymbolTable's new iteration interface. Remove tabs. --- Diffs of the changes: (+27 -14) Index: llvm/lib/VMCore/Verifier.cpp diff -u llvm/lib/VMCore/Verifier.cpp:1.100 llvm/lib/VMCore/Verifier.cpp:1.101 --- llvm/lib/VMCore/Verifier.cpp:1.100 Sun May 23 16:16:51 2004 +++ llvm/lib/VMCore/Verifier.cpp Tue May 25 03:53:29 2004 @@ -64,21 +64,21 @@ bool Broken; // Is this module found to be broken? bool RealPass; // Are we not being run by a PassManager? VerifierFailureAction action; - // What to do if verification fails. + // What to do if verification fails. Module *Mod; // Module we are verifying right now DominatorSet *DS; // Dominator set, caution can be null! std::stringstream msgs; // A stringstream to collect messages Verifier() - : Broken(false), RealPass(true), action(AbortProcessAction), + : Broken(false), RealPass(true), action(AbortProcessAction), DS(0), msgs( std::ios_base::app | std::ios_base::out ) {} Verifier( VerifierFailureAction ctn ) - : Broken(false), RealPass(true), action(ctn), DS(0), + : Broken(false), RealPass(true), action(ctn), DS(0), msgs( std::ios_base::app | std::ios_base::out ) {} Verifier(bool AB ) - : Broken(false), RealPass(true), + : Broken(false), RealPass(true), action( AB ? AbortProcessAction : PrintMessageAction), DS(0), - msgs( std::ios_base::app | std::ios_base::out ) {} + msgs( std::ios_base::app | std::ios_base::out ) {} Verifier(DominatorSet &ds) : Broken(false), RealPass(false), action(PrintMessageAction), DS(&ds), msgs( std::ios_base::app | std::ios_base::out ) {} @@ -184,14 +184,17 @@ if (!V) return; if (isa(V)) { msgs << *V; - } else if (const Type *Ty = dyn_cast(V)) { - WriteTypeSymbolic(msgs, Ty, Mod); } else { WriteAsOperand (msgs, V, true, true, Mod); msgs << "\n"; } } + void WriteType(const Type* T ) { + if ( !T ) return; + WriteTypeSymbolic(msgs, T, Mod ); + } + // CheckFailed - A check failed, so print out the condition and the message // that failed. This provides a nice place to put a breakpoint if you want @@ -206,6 +209,14 @@ WriteValue(V4); Broken = true; } + + void CheckFailed( const std::string& Message, const Value* V1, + const Type* T2, const Value* V3 = 0 ) { + msgs << Message << "\n"; + WriteValue(V1); + WriteType(T2); + WriteValue(V3); + } }; RegisterOpt X("verify", "Module Verifier"); @@ -241,21 +252,21 @@ // verifySymbolTable - Verify that a function or module symbol table is ok // void Verifier::verifySymbolTable(SymbolTable &ST) { - // Loop over all of the types in the symbol table... - for (SymbolTable::iterator TI = ST.begin(), TE = ST.end(); TI != TE; ++TI) - for (SymbolTable::type_iterator I = TI->second.begin(), - E = TI->second.end(); I != E; ++I) { - Value *V = I->second; + // Loop over all of the values in all type planes in the symbol table. + for (SymbolTable::plane_const_iterator PI = ST.plane_begin(), + PE = ST.plane_end(); PI != PE; ++PI) + for (SymbolTable::value_const_iterator VI = PI->second.begin(), + VE = PI->second.end(); VI != VE; ++VI) { + Value *V = VI->second; // Check that there are no void typed values in the symbol table. Values // with a void type cannot be put into symbol tables because they cannot // have names! Assert1(V->getType() != Type::VoidTy, - "Values with void type are not allowed to have names!", V); + "Values with void type are not allowed to have names!", V); } } - // visitFunction - Verify that a function is ok. // void Verifier::visitFunction(Function &F) { @@ -749,3 +760,5 @@ PM.run((Module&)M); return V->Broken; } + +// vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 07:21:25 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:25 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Module.cpp Message-ID: <200405250852.DAA13513@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Module.cpp updated: 1.49 -> 1.50 --- Log message: Convert to SymbolTable's new lookup and iteration interfaces. --- Diffs of the changes: (+6 -7) Index: llvm/lib/VMCore/Module.cpp diff -u llvm/lib/VMCore/Module.cpp:1.49 llvm/lib/VMCore/Module.cpp:1.50 --- llvm/lib/VMCore/Module.cpp:1.49 Wed Apr 21 13:27:56 2004 +++ llvm/lib/VMCore/Module.cpp Tue May 25 03:52:20 2004 @@ -246,7 +246,7 @@ bool Module::addTypeName(const std::string &Name, const Type *Ty) { SymbolTable &ST = getSymbolTable(); - if (ST.lookup(Type::TypeTy, Name)) return true; // Already in symtab... + if (ST.lookupType(Name)) return true; // Already in symtab... // Not in symbol table? Set the name with the Symtab as an argument so the // type knows what to update... @@ -259,7 +259,7 @@ /// null if there is none by that name. const Type *Module::getTypeByName(const std::string &Name) const { const SymbolTable &ST = getSymbolTable(); - return cast_or_null(ST.lookup(Type::TypeTy, Name)); + return cast_or_null(ST.lookupType(Name)); } // getTypeName - If there is at least one entry in the symbol table for the @@ -267,13 +267,12 @@ // std::string Module::getTypeName(const Type *Ty) const { const SymbolTable &ST = getSymbolTable(); - if (ST.find(Type::TypeTy) == ST.end()) - return ""; // No names for types... - SymbolTable::type_const_iterator TI = ST.type_begin(Type::TypeTy); - SymbolTable::type_const_iterator TE = ST.type_end(Type::TypeTy); + SymbolTable::type_const_iterator TI = ST.type_begin(); + SymbolTable::type_const_iterator TE = ST.type_end(); + if ( TI == TE ) return ""; // No names for types - while (TI != TE && TI->second != (const Value*)Ty) + while (TI != TE && TI->second != Ty) ++TI; if (TI != TE) // Must have found an entry! From llvm at cs.uiuc.edu Tue May 25 07:21:29 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:29 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200405250852.DAA13460@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.128 -> 1.129 --- Log message: Convert to SymbolTable's new iteration interface. --- Diffs of the changes: (+34 -29) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.128 llvm/lib/VMCore/AsmWriter.cpp:1.129 --- llvm/lib/VMCore/AsmWriter.cpp:1.128 Wed Apr 28 14:24:28 2004 +++ llvm/lib/VMCore/AsmWriter.cpp Tue May 25 03:52:09 2004 @@ -105,19 +105,16 @@ std::map &TypeNames) { if (!M) return; const SymbolTable &ST = M->getSymbolTable(); - SymbolTable::const_iterator PI = ST.find(Type::TypeTy); - if (PI != ST.end()) { - SymbolTable::type_const_iterator I = PI->second.begin(); - for (; I != PI->second.end(); ++I) { - // As a heuristic, don't insert pointer to primitive types, because - // they are used too often to have a single useful name. - // - const Type *Ty = cast(I->second); - if (!isa(Ty) || - !cast(Ty)->getElementType()->isPrimitiveType() || - isa(cast(Ty)->getElementType())) - TypeNames.insert(std::make_pair(Ty, getLLVMName(I->first))); - } + SymbolTable::type_const_iterator TI = ST.type_begin(); + for (; TI != ST.type_end(); ++TI ) { + // As a heuristic, don't insert pointer to primitive types, because + // they are used too often to have a single useful name. + // + const Type *Ty = cast(TI->second); + if (!isa(Ty) || + !cast(Ty)->getElementType()->isPrimitiveType() || + isa(cast(Ty)->getElementType())) + TypeNames.insert(std::make_pair(Ty, getLLVMName(TI->first))); } } @@ -605,26 +602,31 @@ } -/// printSymbolTable - Run through symbol table looking for named constants -/// if a named constant is found, emit it's declaration... -/// +// printSymbolTable - Run through symbol table looking for constants +// and types. Emit their declarations. void AssemblyWriter::printSymbolTable(const SymbolTable &ST) { - for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) { - SymbolTable::type_const_iterator I = ST.type_begin(TI->first); - SymbolTable::type_const_iterator End = ST.type_end(TI->first); + + // Print the types. + for (SymbolTable::type_const_iterator TI = ST.type_begin(); + TI != ST.type_end(); ++TI ) { + *Out << "\t" << getLLVMName(TI->first) << " = type "; + + // Make sure we print out at least one level of the type structure, so + // that we do not get %FILE = type %FILE + // + printTypeAtLeastOneLevel(TI->second) << "\n"; + } - for (; I != End; ++I) { - const Value *V = I->second; + // Print the constants, in type plane order. + for (SymbolTable::plane_const_iterator PI = ST.plane_begin(); + PI != ST.plane_end(); ++PI ) { + SymbolTable::value_const_iterator VI = ST.value_begin(PI->first); + SymbolTable::value_const_iterator VE = ST.value_end(PI->first); + + for (; VI != VE; ++VI) { + const Value *V = VI->second; if (const Constant *CPV = dyn_cast(V)) { printConstant(CPV); - } else if (const Type *Ty = dyn_cast(V)) { - assert(Ty->getType() == Type::TypeTy && TI->first == Type::TypeTy); - *Out << "\t" << getLLVMName(I->first) << " = type "; - - // Make sure we print out at least one level of the type structure, so - // that we do not get %FILE = type %FILE - // - printTypeAtLeastOneLevel(Ty) << "\n"; } } } @@ -1014,6 +1016,7 @@ } void Value::dump() const { print(std::cerr); } +void Type::dump() const { print(std::cerr); } //===----------------------------------------------------------------------===// // CachedWriter Class Implementation @@ -1062,3 +1065,5 @@ Out = &os; if (AW) AW->setStream(os); } + +// vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 07:21:33 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:33 2004 Subject: [llvm-commits] CVS: llvm/tools/bugpoint/CrashDebugger.cpp Message-ID: <200405250853.DAA13718@zion.cs.uiuc.edu> Changes in directory llvm/tools/bugpoint: CrashDebugger.cpp updated: 1.34 -> 1.35 --- Log message: Convert to SymbolTable's new iteration interface. --- Diffs of the changes: (+3 -3) Index: llvm/tools/bugpoint/CrashDebugger.cpp diff -u llvm/tools/bugpoint/CrashDebugger.cpp:1.34 llvm/tools/bugpoint/CrashDebugger.cpp:1.35 --- llvm/tools/bugpoint/CrashDebugger.cpp:1.34 Sun Mar 14 14:50:42 2004 +++ llvm/tools/bugpoint/CrashDebugger.cpp Tue May 25 03:53:40 2004 @@ -245,9 +245,9 @@ BBs.clear(); for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) { SymbolTable &ST = BlockInfo[i].first->getSymbolTable(); - SymbolTable::iterator I = ST.find(Type::LabelTy); - if (I != ST.end() && I->second.count(BlockInfo[i].second)) - BBs.push_back(cast(I->second[BlockInfo[i].second])); + SymbolTable::plane_iterator PI = ST.find(Type::LabelTy); + if (PI != ST.plane_end() && PI->second.count(BlockInfo[i].second)) + BBs.push_back(cast(PI->second[BlockInfo[i].second])); } return true; } From llvm at cs.uiuc.edu Tue May 25 07:21:37 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:37 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/SlotCalculator.cpp Message-ID: <200405250852.DAA13530@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: SlotCalculator.cpp updated: 1.53 -> 1.54 --- Log message: Convert to SymbolTable's new iteration interface. --- Diffs of the changes: (+35 -15) Index: llvm/lib/VMCore/SlotCalculator.cpp diff -u llvm/lib/VMCore/SlotCalculator.cpp:1.53 llvm/lib/VMCore/SlotCalculator.cpp:1.54 --- llvm/lib/VMCore/SlotCalculator.cpp:1.53 Tue Apr 27 10:13:09 2004 +++ llvm/lib/VMCore/SlotCalculator.cpp Tue May 25 03:52:31 2004 @@ -248,18 +248,32 @@ // into the values table... // void SlotCalculator::processSymbolTable(const SymbolTable *ST) { - for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I) - for (SymbolTable::type_const_iterator TI = I->second.begin(), - TE = I->second.end(); TI != TE; ++TI) - getOrCreateSlot(TI->second); + // Do the types first. + for (SymbolTable::type_const_iterator TI = ST->type_begin(), + TE = ST->type_end(); TI != TE; ++TI ) + getOrCreateSlot(TI->second); + + // Now do the values. + for (SymbolTable::plane_const_iterator PI = ST->plane_begin(), + PE = ST->plane_end(); PI != PE; ++PI) + for (SymbolTable::value_const_iterator VI = PI->second.begin(), + VE = PI->second.end(); VI != VE; ++VI) + getOrCreateSlot(VI->second); } void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) { - for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I) - for (SymbolTable::type_const_iterator TI = I->second.begin(), - TE = I->second.end(); TI != TE; ++TI) - if (isa(TI->second) || isa(TI->second)) - getOrCreateSlot(TI->second); + // Do the types first + for (SymbolTable::type_const_iterator TI = ST->type_begin(), + TE = ST->type_end(); TI != TE; ++TI ) + getOrCreateSlot(TI->second); + + // Now do the constant values in all planes + for (SymbolTable::plane_const_iterator PI = ST->plane_begin(), + PE = ST->plane_end(); PI != PE; ++PI) + for (SymbolTable::value_const_iterator VI = PI->second.begin(), + VE = PI->second.end(); VI != VE; ++VI) + if (isa(VI->second)) + getOrCreateSlot(VI->second); } @@ -452,13 +466,19 @@ getOrCreateCompactionTableSlot(VAN->getArgType()); } + // Do the types in the symbol table const SymbolTable &ST = F->getSymbolTable(); - for (SymbolTable::const_iterator I = ST.begin(), E = ST.end(); I != E; ++I) - for (SymbolTable::type_const_iterator TI = I->second.begin(), - TE = I->second.end(); TI != TE; ++TI) - if (isa(TI->second) || isa(TI->second) || - isa(TI->second)) - getOrCreateCompactionTableSlot(TI->second); + for (SymbolTable::type_const_iterator TI = ST.type_begin(), + TE = ST.type_end(); TI != TE; ++TI) + getOrCreateCompactionTableSlot(TI->second); + + // Now do the constants and global values + for (SymbolTable::plane_const_iterator PI = ST.plane_begin(), + PE = ST.plane_end(); PI != PE; ++PI) + for (SymbolTable::value_const_iterator VI = PI->second.begin(), + VE = PI->second.end(); VI != VE; ++VI) + if (isa(VI->second) || isa(VI->second)) + getOrCreateCompactionTableSlot(VI->second); // Now that we have all of the values in the table, and know what types are // referenced, make sure that there is at least the zero initializer in any From llvm at cs.uiuc.edu Tue May 25 07:21:40 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:40 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/CloneModule.cpp Message-ID: <200405250851.DAA13397@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: CloneModule.cpp updated: 1.9 -> 1.10 --- Log message: Convert to SymbolTable's new iteration interface. --- Diffs of the changes: (+7 -5) Index: llvm/lib/Transforms/Utils/CloneModule.cpp diff -u llvm/lib/Transforms/Utils/CloneModule.cpp:1.9 llvm/lib/Transforms/Utils/CloneModule.cpp:1.10 --- llvm/lib/Transforms/Utils/CloneModule.cpp:1.9 Fri Jan 9 00:12:15 2004 +++ llvm/lib/Transforms/Utils/CloneModule.cpp Tue May 25 03:51:47 2004 @@ -33,11 +33,11 @@ // Copy all of the type symbol table entries over... const SymbolTable &SymTab = M->getSymbolTable(); - SymbolTable::const_iterator TypeI = SymTab.find(Type::TypeTy); - if (TypeI != SymTab.end()) - for (SymbolTable::VarMap::const_iterator I = TypeI->second.begin(), - E = TypeI->second.end(); I != E; ++I) - New->addTypeName(I->first, cast(I->second)); + SymbolTable::type_const_iterator TypeI = SymTab.type_begin(); + SymbolTable::type_const_iterator TypeE = SymTab.type_end(); + for ( ; TypeI != TypeE; ++TypeI ) { + New->addTypeName(TypeI->first, TypeI->second); + } // Create the value map that maps things from the old module over to the new // module. @@ -89,3 +89,5 @@ return New; } + +// vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 07:21:44 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:44 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/Linker.cpp Message-ID: <200405250852.DAA13441@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: Linker.cpp updated: 1.69 -> 1.70 --- Log message: Convert to SymbolTable's new lookup and iteration interfaces. --- Diffs of the changes: (+24 -24) Index: llvm/lib/Transforms/Utils/Linker.cpp diff -u llvm/lib/Transforms/Utils/Linker.cpp:1.69 llvm/lib/Transforms/Utils/Linker.cpp:1.70 --- llvm/lib/Transforms/Utils/Linker.cpp:1.69 Tue Mar 30 20:58:28 2004 +++ llvm/lib/Transforms/Utils/Linker.cpp Tue May 25 03:51:58 2004 @@ -172,22 +172,21 @@ const SymbolTable *SrcST = &Src->getSymbolTable(); // Look for a type plane for Type's... - SymbolTable::const_iterator PI = SrcST->find(Type::TypeTy); - if (PI == SrcST->end()) return false; // No named types, do nothing. + SymbolTable::type_const_iterator TI = SrcST->type_begin(); + SymbolTable::type_const_iterator TE = SrcST->type_end(); + if (TI == TE) return false; // No named types, do nothing. // Some types cannot be resolved immediately because they depend on other // types being resolved to each other first. This contains a list of types we // are waiting to recheck. std::vector DelayedTypesToResolve; - const SymbolTable::VarMap &VM = PI->second; - for (SymbolTable::type_const_iterator I = VM.begin(), E = VM.end(); - I != E; ++I) { - const std::string &Name = I->first; - Type *RHS = cast(I->second); + for ( ; TI != TE; ++TI ) { + const std::string &Name = TI->first; + Type *RHS = TI->second; // Check to see if this type name is already in the dest module... - Type *Entry = cast_or_null(DestST->lookup(Type::TypeTy, Name)); + Type *Entry = DestST->lookupType(Name); if (ResolveTypes(Entry, RHS, DestST, Name)) { // They look different, save the types 'till later to resolve. @@ -203,8 +202,8 @@ // Try direct resolution by name... for (unsigned i = 0; i != DelayedTypesToResolve.size(); ++i) { const std::string &Name = DelayedTypesToResolve[i]; - Type *T1 = cast(VM.find(Name)->second); - Type *T2 = cast(DestST->lookup(Type::TypeTy, Name)); + Type *T1 = SrcST->lookupType(Name); + Type *T2 = DestST->lookupType(Name); if (!ResolveTypes(T2, T1, DestST, Name)) { // We are making progress! DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i); @@ -218,8 +217,8 @@ // two types: { int* } and { opaque* } for (unsigned i = 0, e = DelayedTypesToResolve.size(); i != e; ++i) { const std::string &Name = DelayedTypesToResolve[i]; - PATypeHolder T1(cast(VM.find(Name)->second)); - PATypeHolder T2(cast(DestST->lookup(Type::TypeTy, Name))); + PATypeHolder T1(SrcST->lookupType(Name)); + PATypeHolder T2(DestST->lookupType(Name)); if (!RecursiveResolveTypes(T2, T1, DestST, Name)) { // We are making progress! @@ -236,8 +235,8 @@ if (DelayedTypesToResolve.size() == OldSize) { const std::string &Name = DelayedTypesToResolve.back(); - const Type *T1 = cast(VM.find(Name)->second); - const Type *T2 = cast(DestST->lookup(Type::TypeTy, Name)); + const Type *T1 = SrcST->lookupType(Name); + const Type *T2 = DestST->lookupType(Name); std::cerr << "WARNING: Type conflict between types named '" << Name << "'.\n Src='"; WriteTypeSymbolic(std::cerr, T1, Src); @@ -383,29 +382,29 @@ // It doesn't exist exactly, scan through all of the type planes in the symbol // table, checking each of them for a type-compatible version. // - for (SymbolTable::iterator I = ST->begin(), E = ST->end(); I != E; ++I) - if (I->first != Type::TypeTy) { - SymbolTable::VarMap &VM = I->second; - - // Does this type plane contain an entry with the specified name? - SymbolTable::type_iterator TI = VM.find(Name); - if (TI != VM.end()) { + for (SymbolTable::plane_iterator PI = ST->plane_begin(), PE = ST->plane_end(); + PI != PE; ++PI) { + SymbolTable::ValueMap &VM = PI->second; + + // Does this type plane contain an entry with the specified name? + SymbolTable::value_iterator VI = VM.find(Name); + if (VI != VM.end()) { // // Ensure that this type if placed correctly into the symbol table. // - assert(TI->second->getType() == I->first && "Type conflict!"); + assert(VI->second->getType() == PI->first && "Type conflict!"); // // Save a reference to the new type. Resolving the type can modify the // symbol table, invalidating the TI variable. // - Value *ValPtr = TI->second; + Value *ValPtr = VI->second; // // Determine whether we can fold the two types together, resolving them. // If so, we can use this value. // - if (!RecursiveResolveTypes(Ty, I->first, ST, "")) + if (!RecursiveResolveTypes(Ty, PI->first, ST, "")) return cast(ValPtr); } } @@ -925,3 +924,4 @@ return false; } +// vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 07:21:50 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:50 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/SymbolTable.cpp Message-ID: <200405250852.DAA13582@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: SymbolTable.cpp updated: 1.42 -> 1.43 --- Log message: Completely rewrote the class. SymbolTable now separates Type* from Value* in preparation\ for making Type not derive from Value. There are now separate interfaces \ for looking up, finding, and inserting Types and Values. There are also \ three separate iterator interfaces, one for type planes, one for the types \ (type type plane), and one for values within a type plane. See the \ documentation in the Header file. --- Diffs of the changes: (+240 -108) Index: llvm/lib/VMCore/SymbolTable.cpp diff -u llvm/lib/VMCore/SymbolTable.cpp:1.42 llvm/lib/VMCore/SymbolTable.cpp:1.43 --- llvm/lib/VMCore/SymbolTable.cpp:1.42 Wed Dec 31 01:08:19 2003 +++ llvm/lib/VMCore/SymbolTable.cpp Tue May 25 03:52:42 2004 @@ -2,8 +2,9 @@ // // 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 file was developed by the LLVM research group and revised by Reid +// Spencer. It is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -16,6 +17,7 @@ #include "llvm/Module.h" #include "Support/StringExtras.h" #include + using namespace llvm; #define DEBUG_SYMBOL_TABLE 0 @@ -23,27 +25,22 @@ SymbolTable::~SymbolTable() { // Drop all abstract type references in the type plane... - iterator TyPlane = find(Type::TypeTy); - if (TyPlane != end()) { - VarMap &TyP = TyPlane->second; - for (VarMap::iterator I = TyP.begin(), E = TyP.end(); I != E; ++I) { - const Type *Ty = cast(I->second); - if (Ty->isAbstract()) // If abstract, drop the reference... - cast(Ty)->removeAbstractTypeUser(this); - } + for (type_iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) { + if (TI->second->isAbstract()) // If abstract, drop the reference... + cast(TI->second)->removeAbstractTypeUser(this); } - // TODO: FIXME: BIG ONE: This doesn't unreference abstract types for the planes - // that could still have entries! + // TODO: FIXME: BIG ONE: This doesn't unreference abstract types for the + // planes that could still have entries! #ifndef NDEBUG // Only do this in -g mode... bool LeftoverValues = true; - for (iterator i = begin(); i != end(); ++i) { - for (type_iterator I = i->second.begin(); I != i->second.end(); ++I) - if (!isa(I->second) && !isa(I->second)) { + for (plane_iterator PI = pmap.begin(); PI != pmap.end(); ++PI) { + for (value_iterator VI = PI->second.begin(); VI != PI->second.end(); ++VI) + if (!isa(VI->second) ) { std::cerr << "Value still in symbol table! Type = '" - << i->first->getDescription() << "' Name = '" - << I->first << "'\n"; + << PI->first->getDescription() << "' Name = '" + << VI->first << "'\n"; LeftoverValues = false; } } @@ -57,47 +54,58 @@ // the specified type. // std::string SymbolTable::getUniqueName(const Type *Ty, - const std::string &BaseName) { - iterator I = find(Ty); - if (I == end()) return BaseName; + const std::string &BaseName) const { + // Find the plane + plane_const_iterator PI = pmap.find(Ty); + if (PI == pmap.end()) return BaseName; std::string TryName = BaseName; - type_iterator End = I->second.end(); + const ValueMap& vmap = PI->second; + value_const_iterator End = vmap.end(); - while (I->second.find(TryName) != End) // Loop until we find a free + // See if the name exists + while (vmap.find(TryName) != End) // Loop until we find a free TryName = BaseName + utostr(++LastUnique); // name in the symbol table return TryName; } - -// lookup - Returns null on failure... +// lookup a value - Returns null on failure... Value *SymbolTable::lookup(const Type *Ty, const std::string &Name) const { - const_iterator I = find(Ty); - if (I != end()) { // We have symbols in that plane... - type_const_iterator J = I->second.find(Name); - if (J != I->second.end()) // and the name is in our hash table... - return J->second; + plane_const_iterator PI = pmap.find(Ty); + if (PI != pmap.end()) { // We have symbols in that plane... + value_const_iterator VI = PI->second.find(Name); + if (VI != PI->second.end()) // and the name is in our hash table... + return VI->second; } + return 0; +} + +// lookup a type by name - returns null on failure +Type* SymbolTable::lookupType( const std::string& Name ) const { + type_const_iterator TI = tmap.find( Name ); + if ( TI != tmap.end() ) + return TI->second; return 0; } +// Remove a value void SymbolTable::remove(Value *N) { assert(N->hasName() && "Value doesn't have name!"); if (InternallyInconsistent) return; - iterator I = find(N->getType()); - assert(I != end() && - "Trying to remove a type that doesn't have a plane yet!"); - removeEntry(I, I->second.find(N->getName())); + plane_iterator PI = pmap.find(N->getType()); + assert(PI != pmap.end() && + "Trying to remove a value that doesn't have a type plane yet!"); + removeEntry(PI, PI->second.find(N->getName())); } + // removeEntry - Remove a value from the symbol table... -// -Value *SymbolTable::removeEntry(iterator Plane, type_iterator Entry) { +Value *SymbolTable::removeEntry(plane_iterator Plane, value_iterator Entry) { if (InternallyInconsistent) return 0; - assert(Plane != super::end() && + assert(Plane != pmap.end() && Entry != Plane->second.end() && "Invalid entry to remove!"); Value *Result = Entry->second; @@ -123,34 +131,60 @@ cast(Plane->first)->removeAbstractTypeUser(this); } - erase(Plane); + pmap.erase(Plane); } + return Result; +} + + +// remove - Remove a type +void SymbolTable::remove(Type* Ty ) { + type_iterator TI = this->type_begin(); + type_iterator TE = this->type_end(); + + // Search for the entry + while ( TI != TE && TI->second != Ty ) + ++TI; + + if ( TI != TE ) + this->removeEntry( TI ); +} + + +// removeEntry - Remove a type from the symbol table... +Type* SymbolTable::removeEntry(type_iterator Entry) { + if (InternallyInconsistent) return 0; + assert( Entry != tmap.end() && "Invalid entry to remove!"); + + Type* Result = Entry->second; + +#if DEBUG_SYMBOL_TABLE + dump(); + std::cerr << " Removing Value: " << Result->getName() << "\n"; +#endif + + tmap.erase(Entry); // If we are removing an abstract type, remove the symbol table from it's use // list... - if (Ty == Type::TypeTy) { - const Type *T = cast(Result); - if (T->isAbstract()) { + if (Result->isAbstract()) { #if DEBUG_ABSTYPE - std::cerr << "Removing abs type from symtab" << T->getDescription()<<"\n"; + std::cerr << "Removing abstract type from symtab" << Result->getDescription()<<"\n"; #endif - cast(T)->removeAbstractTypeUser(this); - } + cast(Result)->removeAbstractTypeUser(this); } return Result; } -// insertEntry - Insert a value into the symbol table with the specified -// name... -// + +// insertEntry - Insert a value into the symbol table with the specified name. void SymbolTable::insertEntry(const std::string &Name, const Type *VTy, Value *V) { - // Check to see if there is a naming conflict. If so, rename this value! if (lookup(VTy, Name)) { std::string UniqueName = getUniqueName(VTy, Name); - assert(InternallyInconsistent == false && "Infinite loop inserting entry!"); + assert(InternallyInconsistent == false && "Infinite loop inserting value!"); InternallyInconsistent = true; V->setName(UniqueName, this); InternallyInconsistent = false; @@ -163,11 +197,11 @@ << VTy->getDescription() << "\n"; #endif - iterator I = find(VTy); - if (I == end()) { // Not in collection yet... insert dummy entry + plane_iterator PI = pmap.find(VTy); + if (PI == pmap.end()) { // Not in collection yet... insert dummy entry // Insert a new empty element. I points to the new elements. - I = super::insert(make_pair(VTy, VarMap())).first; - assert(I != end() && "How did insert fail?"); + PI = pmap.insert(make_pair(VTy, ValueMap())).first; + assert(PI != pmap.end() && "How did insert fail?"); // Check to see if the type is abstract. If so, it might be refined in the // future, which would cause the plane of the old type to get merged into @@ -182,31 +216,126 @@ } } - I->second.insert(make_pair(Name, V)); + PI->second.insert(make_pair(Name, V)); +} + + +// insertEntry - Insert a value into the symbol table with the specified +// name... +// +void SymbolTable::insertEntry(const std::string& Name, Type* T) { + + // Check to see if there is a naming conflict. If so, rename this type! + std::string UniqueName = Name; + if (lookupType(Name)) + UniqueName = getUniqueName(T, Name); + +#if DEBUG_SYMBOL_TABLE + dump(); + std::cerr << " Inserting type: " << UniqueName << ": " + << T->getDescription() << "\n"; +#endif + + // Insert the tmap entry + tmap.insert(make_pair(UniqueName, T)); // If we are adding an abstract type, add the symbol table to it's use list. - if (VTy == Type::TypeTy) { - const Type *T = cast(V); - if (T->isAbstract()) { - cast(T)->addAbstractTypeUser(this); + if (T->isAbstract()) { + cast(T)->addAbstractTypeUser(this); #if DEBUG_ABSTYPE - std::cerr << "Added abstract type to ST: " << T->getDescription() << "\n"; + std::cerr << "Added abstract type to ST: " << T->getDescription() << "\n"; #endif + } +} + + +// Determine how many entries for a given type. +unsigned SymbolTable::type_size(const Type *Ty) const { + plane_const_iterator PI = pmap.find(Ty); + if ( PI == pmap.end() ) return 0; + return PI->second.size(); +} + + +// Get the name of a value +std::string SymbolTable::get_name( const Value* V ) const { + value_const_iterator VI = this->value_begin( V->getType() ); + value_const_iterator VE = this->value_end( V->getType() ); + + // Search for the entry + while ( VI != VE && VI->second != V ) + ++VI; + + if ( VI != VE ) + return VI->first; + + return ""; +} + + +// Get the name of a type +std::string SymbolTable::get_name( const Type* T ) const { + if (tmap.empty()) return ""; // No types at all. + + type_const_iterator TI = tmap.begin(); + type_const_iterator TE = tmap.end(); + + // Search for the entry + while (TI != TE && TI->second != T ) + ++TI; + + if (TI != TE) // Must have found an entry! + return TI->first; + return ""; // Must not have found anything... +} + + +// Strip the symbol table of its names. +bool SymbolTable::strip( void ) { + bool RemovedSymbol = false; + for (plane_iterator I = pmap.begin(); I != pmap.end();) { + // Removing items from the plane can cause the plane itself to get deleted. + // If this happens, make sure we incremented our plane iterator already! + ValueMap &Plane = (I++)->second; + value_iterator B = Plane.begin(), Bend = Plane.end(); + while (B != Bend) { // Found nonempty type plane! + Value *V = B->second; + if (isa(V)) { + remove(V); + RemovedSymbol = true; + } else { + if (!isa(V) || cast(V)->hasInternalLinkage()){ + // Set name to "", removing from symbol table! + V->setName("", this); + RemovedSymbol = true; + } + } + ++B; } } + + for (type_iterator TI = tmap.begin(); TI != tmap.end(); ) { + Type* T = (TI++)->second; + remove(T); + RemovedSymbol = true; + } + + return RemovedSymbol; } + // This function is called when one of the types in the type plane are refined void SymbolTable::refineAbstractType(const DerivedType *OldType, const Type *NewType) { - // Search to see if we have any values of the type oldtype. If so, we need to + + // Search to see if we have any values of the type Oldtype. If so, we need to // move them into the newtype plane... - iterator TPI = find(OldType); - if (TPI != end()) { + plane_iterator PI = pmap.find(OldType); + if (PI != pmap.end()) { // Get a handle to the new type plane... - iterator NewTypeIt = find(NewType); - if (NewTypeIt == super::end()) { // If no plane exists, add one - NewTypeIt = super::insert(make_pair(NewType, VarMap())).first; + plane_iterator NewTypeIt = pmap.find(NewType); + if (NewTypeIt == pmap.end()) { // If no plane exists, add one + NewTypeIt = pmap.insert(make_pair(NewType, ValueMap())).first; if (NewType->isAbstract()) { cast(NewType)->addAbstractTypeUser(this); @@ -217,22 +346,22 @@ } } - VarMap &NewPlane = NewTypeIt->second; - VarMap &OldPlane = TPI->second; + ValueMap &NewPlane = NewTypeIt->second; + ValueMap &OldPlane = PI->second; while (!OldPlane.empty()) { std::pair V = *OldPlane.begin(); // Check to see if there is already a value in the symbol table that this // would collide with. - type_iterator TI = NewPlane.find(V.first); - if (TI != NewPlane.end() && TI->second == V.second) { + value_iterator VI = NewPlane.find(V.first); + if (VI != NewPlane.end() && VI->second == V.second) { // No action - } else if (TI != NewPlane.end()) { + } else if (VI != NewPlane.end()) { // The only thing we are allowing for now is two external global values // folded into one. // - GlobalValue *ExistGV = dyn_cast(TI->second); + GlobalValue *ExistGV = dyn_cast(VI->second); GlobalValue *NewGV = dyn_cast(V.second); if (ExistGV && NewGV) { @@ -294,71 +423,74 @@ OldType->removeAbstractTypeUser(this); // Remove the plane that is no longer used - erase(TPI); + pmap.erase(PI); } - TPI = find(Type::TypeTy); - if (TPI != end()) { - // 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 - // occurrences, and although we only need to remove one at a time, it's - // faster to remove them all in one pass. - // - VarMap &TyPlane = TPI->second; - for (VarMap::iterator I = TyPlane.begin(), E = TyPlane.end(); I != E; ++I) - if (I->second == (Value*)OldType) { // FIXME when Types aren't const. + // 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 + // occurrences, and although we only need to remove one at a time, it's + // faster to remove them all in one pass. + // + for (type_iterator I = type_begin(), E = type_end(); I != E; ++I) { + if (I->second == (Type*)OldType) { // FIXME when Types aren't const. #if DEBUG_ABSTYPE - std::cerr << "Removing type " << OldType->getDescription() << "\n"; + std::cerr << "Removing type " << OldType->getDescription() << "\n"; #endif - OldType->removeAbstractTypeUser(this); + OldType->removeAbstractTypeUser(this); - I->second = (Value*)NewType; // TODO FIXME when types aren't const - if (NewType->isAbstract()) { + I->second = (Type*)NewType; // TODO FIXME when types aren't const + if (NewType->isAbstract()) { #if DEBUG_ABSTYPE - std::cerr << "Added type " << NewType->getDescription() << "\n"; + std::cerr << "Added type " << NewType->getDescription() << "\n"; #endif - cast(NewType)->addAbstractTypeUser(this); - } + cast(NewType)->addAbstractTypeUser(this); } + } } } + +// Handle situation where type becomes Concreate from Abstract void SymbolTable::typeBecameConcrete(const DerivedType *AbsTy) { - iterator TPI = find(AbsTy); + plane_iterator PI = pmap.find(AbsTy); // If there are any values in the symbol table of this type, then the type - // plan is a use of the abstract type which must be dropped. - if (TPI != end()) + // plane is a use of the abstract type which must be dropped. + if (PI != pmap.end()) AbsTy->removeAbstractTypeUser(this); - TPI = find(Type::TypeTy); - if (TPI != end()) { - // 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. - // - VarMap &TyPlane = TPI->second; - for (VarMap::iterator I = TyPlane.begin(), E = TyPlane.end(); I != E; ++I) - if (I->second == (Value*)AbsTy) // FIXME when Types aren't const. - AbsTy->removeAbstractTypeUser(this); - } + // 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. + for (type_iterator TI = type_begin(), TE = type_end(); TI != TE; ++TI) + if (TI->second == (Type*)AbsTy) // FIXME when Types aren't const. + AbsTy->removeAbstractTypeUser(this); } static void DumpVal(const std::pair &V) { - std::cout << " '" << V.first << "' = "; + std::cerr << " '" << V.first << "' = "; V.second->dump(); - std::cout << "\n"; + std::cerr << "\n"; } static void DumpPlane(const std::pair >&P){ - std::cout << " Plane: "; P.first->dump(); - std::cout << "\n"; + std::cerr << "\n"; for_each(P.second.begin(), P.second.end(), DumpVal); } +static void DumpTypes(const std::pair& T ) { + std::cerr << " '" << T.first << "' = "; + T.second->dump(); + std::cerr << "\n"; +} + void SymbolTable::dump() const { - std::cout << "Symbol table dump:\n"; - for_each(begin(), end(), DumpPlane); + std::cerr << "Symbol table dump:\n Plane:"; + for_each(pmap.begin(), pmap.end(), DumpPlane); + std::cerr << " Types: "; + for_each(tmap.begin(), tmap.end(), DumpTypes); } + +// vim: sw=2 ai From llvm at cs.uiuc.edu Tue May 25 07:21:54 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:54 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/TailDuplication.cpp Message-ID: <200405250851.DAA13364@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: TailDuplication.cpp updated: 1.19 -> 1.20 --- Log message: Remove unused header file. --- Diffs of the changes: (+0 -1) Index: llvm/lib/Transforms/Scalar/TailDuplication.cpp diff -u llvm/lib/Transforms/Scalar/TailDuplication.cpp:1.19 llvm/lib/Transforms/Scalar/TailDuplication.cpp:1.20 --- llvm/lib/Transforms/Scalar/TailDuplication.cpp:1.19 Sat Apr 17 19:52:43 2004 +++ llvm/lib/Transforms/Scalar/TailDuplication.cpp Tue May 25 03:51:36 2004 @@ -26,7 +26,6 @@ #include "llvm/Pass.h" #include "llvm/Type.h" #include "llvm/Support/CFG.h" -#include "llvm/Support/ValueHolder.h" #include "llvm/Transforms/Utils/Local.h" #include "Support/CommandLine.h" #include "Support/Debug.h" From llvm at cs.uiuc.edu Tue May 25 07:21:59 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:21:59 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/SymbolStripping.cpp Message-ID: <200405250851.DAA13312@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: SymbolStripping.cpp updated: 1.25 -> 1.26 --- Log message: Make this pass simply invoke SymbolTable::strip(). --- Diffs of the changes: (+2 -31) Index: llvm/lib/Transforms/Scalar/SymbolStripping.cpp diff -u llvm/lib/Transforms/Scalar/SymbolStripping.cpp:1.25 llvm/lib/Transforms/Scalar/SymbolStripping.cpp:1.26 --- llvm/lib/Transforms/Scalar/SymbolStripping.cpp:1.25 Sat Jan 10 15:36:49 2004 +++ llvm/lib/Transforms/Scalar/SymbolStripping.cpp Tue May 25 03:51:25 2004 @@ -27,39 +27,10 @@ #include "llvm/Pass.h" using namespace llvm; -static bool StripSymbolTable(SymbolTable &SymTab) { - bool RemovedSymbol = false; - - for (SymbolTable::iterator I = SymTab.begin(); I != SymTab.end();) { - // Removing items from the plane can cause the plane itself to get deleted. - // If this happens, make sure we incremented our plane iterator already! - std::map &Plane = (I++)->second; - - SymbolTable::type_iterator B = Plane.begin(), Bend = Plane.end(); - while (B != Bend) { // Found nonempty type plane! - Value *V = B->second; - - if (isa(V) || isa(V)) { - SymTab.type_remove(B++); - RemovedSymbol = true; - } else { - ++B; - if (!isa(V) || cast(V)->hasInternalLinkage()){ - // Set name to "", removing from symbol table! - V->setName("", &SymTab); - RemovedSymbol = true; - } - } - } - } - - return RemovedSymbol; -} - namespace { struct SymbolStripping : public FunctionPass { virtual bool runOnFunction(Function &F) { - return StripSymbolTable(F.getSymbolTable()); + return F.getSymbolTable().strip(); } virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); @@ -69,7 +40,7 @@ struct FullSymbolStripping : public SymbolStripping { virtual bool doInitialization(Module &M) { - return StripSymbolTable(M.getSymbolTable()); + return M.getSymbolTable().strip(); } }; RegisterOpt Y("mstrip", From llvm at cs.uiuc.edu Tue May 25 07:22:03 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/MutateStructTypes.cpp Message-ID: <200405250851.DAA13295@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: MutateStructTypes.cpp updated: 1.46 -> 1.47 --- Log message: Convert to SymbolTable's new iteration interface. --- Diffs of the changes: (+8 -10) Index: llvm/lib/Transforms/IPO/MutateStructTypes.cpp diff -u llvm/lib/Transforms/IPO/MutateStructTypes.cpp:1.46 llvm/lib/Transforms/IPO/MutateStructTypes.cpp:1.47 --- llvm/lib/Transforms/IPO/MutateStructTypes.cpp:1.46 Sun Feb 8 22:37:31 2004 +++ llvm/lib/Transforms/IPO/MutateStructTypes.cpp Tue May 25 03:51:14 2004 @@ -269,16 +269,13 @@ // Remap the symbol table to refer to the types in a nice way // SymbolTable &ST = M.getSymbolTable(); - SymbolTable::iterator I = ST.find(Type::TypeTy); - if (I != ST.end()) { // Get the type plane for Type's - SymbolTable::VarMap &Plane = I->second; - for (SymbolTable::type_iterator TI = Plane.begin(), TE = Plane.end(); - TI != TE; ++TI) { - // FIXME: This is gross, I'm reaching right into a symbol table and - // mucking around with it's internals... but oh well. - // - TI->second = (Value*)cast(ConvertType(cast(TI->second))); - } + SymbolTable::type_iterator TI = ST.type_begin(); + SymbolTable::type_iterator TE = ST.type_end(); + for ( ; TI != TE; ++TI ) { + // FIXME: This is gross, I'm reaching right into a symbol table and + // mucking around with it's internals... but oh well. + // + TI->second = const_cast(ConvertType(TI->second)); } } @@ -495,3 +492,4 @@ return true; } +// vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 07:22:07 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:07 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/DeadTypeElimination.cpp Message-ID: <200405250851.DAA13242@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: DeadTypeElimination.cpp updated: 1.49 -> 1.50 --- Log message: Convert to SymbolTable's new iteration interface. --- Diffs of the changes: (+16 -17) Index: llvm/lib/Transforms/IPO/DeadTypeElimination.cpp diff -u llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.49 llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.50 --- llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.49 Thu Feb 26 14:02:23 2004 +++ llvm/lib/Transforms/IPO/DeadTypeElimination.cpp Tue May 25 03:51:03 2004 @@ -74,25 +74,24 @@ // Check the symbol table for superfluous type entries... // // Grab the 'type' plane of the module symbol... - SymbolTable::iterator STI = ST.find(Type::TypeTy); - if (STI != ST.end()) { - // Loop over all entries in the type plane... - SymbolTable::VarMap &Plane = STI->second; - for (SymbolTable::VarMap::iterator PI = Plane.begin(); PI != Plane.end();) { - // If this entry should be unconditionally removed, or if we detect that - // the type is not used, remove it. - const Type *RHS = cast(PI->second); - if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) { - Plane.erase(PI++); - ++NumKilled; - Changed = true; - } else { - ++PI; - // We only need to leave one name for each type. - UsedTypes.erase(RHS); - } + SymbolTable::type_iterator TI = ST.type_begin(); + while ( TI != ST.type_end() ) { + // If this entry should be unconditionally removed, or if we detect that + // the type is not used, remove it. + const Type *RHS = TI->second; + if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) { + SymbolTable::type_iterator ToRemove = TI++; + ST.remove(TI->second); + ++NumKilled; + Changed = true; + } else { + ++TI; + // We only need to leave one name for each type. + UsedTypes.erase(RHS); } } return Changed; } + +// vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 07:22:11 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:11 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9AsmPrinter.cpp Message-ID: <200405250851.DAA13223@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9AsmPrinter.cpp updated: 1.112 -> 1.113 --- Log message: Remove use of Type::TypeTy from an assert. It will go away soon. --- Diffs of the changes: (+0 -1) Index: llvm/lib/Target/SparcV9/SparcV9AsmPrinter.cpp diff -u llvm/lib/Target/SparcV9/SparcV9AsmPrinter.cpp:1.112 llvm/lib/Target/SparcV9/SparcV9AsmPrinter.cpp:1.113 --- llvm/lib/Target/SparcV9/SparcV9AsmPrinter.cpp:1.112 Tue May 4 16:41:45 2004 +++ llvm/lib/Target/SparcV9/SparcV9AsmPrinter.cpp Tue May 25 03:50:52 2004 @@ -301,7 +301,6 @@ /// void AsmPrinter::printSingleConstantValue(const Constant* CV) { assert(CV->getType() != Type::VoidTy && - CV->getType() != Type::TypeTy && CV->getType() != Type::LabelTy && "Unexpected type for Constant"); From llvm at cs.uiuc.edu Tue May 25 07:22:15 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:15 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200405250850.DAA13179@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.176 -> 1.177 --- Log message: Convert to SymbolTable's new iteration interface. --- Diffs of the changes: (+20 -19) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.176 llvm/lib/Target/CBackend/Writer.cpp:1.177 --- llvm/lib/Target/CBackend/Writer.cpp:1.176 Sun May 23 16:23:30 2004 +++ llvm/lib/Target/CBackend/Writer.cpp Tue May 25 03:50:41 2004 @@ -219,19 +219,18 @@ // already named, and removing names for structure types that are not used. // SymbolTable &MST = M.getSymbolTable(); - if (MST.find(Type::TypeTy) != MST.end()) - for (SymbolTable::type_iterator I = MST.type_begin(Type::TypeTy), - E = MST.type_end(Type::TypeTy); I != E; ) { - SymbolTable::type_iterator It = I++; - if (StructType *STy = dyn_cast(It->second)) { - // If this is not used, remove it from the symbol table. - std::set::iterator UTI = UT.find(STy); - if (UTI == UT.end()) - MST.remove(It->first, It->second); - else - UT.erase(UTI); - } + for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end(); + TI != TE; ) { + SymbolTable::type_iterator I = TI++; + if (StructType *STy = dyn_cast(I->second)) { + // If this is not used, remove it from the symbol table. + std::set::iterator UTI = UT.find(STy); + if (UTI == UT.end()) + MST.remove(I->first, I->second); + else + UT.erase(UTI); } + } // UT now contains types that are not named. Loop over it, naming // structure types. @@ -291,7 +290,7 @@ } if (MTy->isVarArg()) { if (MTy->getNumParams()) - FunctionInnards << ", ..."; + FunctionInnards << ", ..."; } else if (!MTy->getNumParams()) { FunctionInnards << "void"; } @@ -865,12 +864,12 @@ /// void CWriter::printModuleTypes(const SymbolTable &ST) { // If there are no type names, exit early. - if (ST.find(Type::TypeTy) == ST.end()) + if ( ! ST.hasTypes() ) return; // We are only interested in the type plane of the symbol table... - SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy); - SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy); + SymbolTable::type_const_iterator I = ST.type_begin(); + SymbolTable::type_const_iterator End = ST.type_end(); // Print out forward declarations for structure types before anything else! Out << "/* Structure forward decls */\n"; @@ -885,7 +884,7 @@ // Now we can print out typedefs... Out << "/* Typedefs */\n"; - for (I = ST.type_begin(Type::TypeTy); I != End; ++I) { + for (I = ST.type_begin(); I != End; ++I) { const Type *Ty = cast(I->second); std::string Name = "l_" + Mangler::makeNameProper(I->first); Out << "typedef "; @@ -902,7 +901,7 @@ // printed in the correct order. // Out << "/* Structure contents */\n"; - for (I = ST.type_begin(Type::TypeTy); I != End; ++I) + for (I = ST.type_begin(); I != End; ++I) if (const StructType *STy = dyn_cast(I->second)) // Only print out used types! printContainedStructs(STy, StructPrinted); @@ -969,7 +968,7 @@ } else { // Loop over the arguments, printing them... for (FunctionType::param_iterator I = FT->param_begin(), - E = FT->param_end(); I != E; ++I) { + E = FT->param_end(); I != E; ++I) { if (I != FT->param_begin()) FunctionInnards << ", "; printType(FunctionInnards, *I); } @@ -1510,3 +1509,5 @@ IntrinsicLowering *IL) { return new CTargetMachine(M, IL); } + +// vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 07:22:19 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:19 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/DerivedTypes.h Message-ID: <200405250845.DAA12471@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: DerivedTypes.h updated: 1.56 -> 1.57 --- Log message: Convert dump() method to call Type::dump() instead of Value::dump(). --- Diffs of the changes: (+1 -1) Index: llvm/include/llvm/DerivedTypes.h diff -u llvm/include/llvm/DerivedTypes.h:1.56 llvm/include/llvm/DerivedTypes.h:1.57 --- llvm/include/llvm/DerivedTypes.h:1.56 Sun Apr 4 20:25:21 2004 +++ llvm/include/llvm/DerivedTypes.h Tue May 25 03:45:42 2004 @@ -88,7 +88,7 @@ /// void refineAbstractTypeTo(const Type *NewType); - void dump() const { Value::dump(); } + void dump() const { Type::dump(); } // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const DerivedType *T) { return true; } From llvm at cs.uiuc.edu Tue May 25 07:22:23 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:23 2004 Subject: [llvm-commits] CVS: llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Message-ID: <200405250846.DAA12573@zion.cs.uiuc.edu> Changes in directory llvm/lib/ExecutionEngine/Interpreter: ExternalFunctions.cpp updated: 1.73 -> 1.74 --- Log message: Get rid of a wart: useless getFILE function is now a cast macro. --- Diffs of the changes: (+2 -42) Index: llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp diff -u llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.73 llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.74 --- llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.73 Sat May 1 01:42:15 2004 +++ llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Tue May 25 03:46:15 2004 @@ -22,7 +22,6 @@ #include "Interpreter.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" -#include "llvm/SymbolTable.h" #include "llvm/Target/TargetData.h" #include "Support/DynamicLinker.h" #include "Config/dlfcn.h" @@ -541,47 +540,8 @@ //===----------------------------------------------------------------------===// // getFILE - Turn a pointer in the host address space into a legit pointer in -// the interpreter address space. For the most part, this is an identity -// transformation, but if the program refers to stdio, stderr, stdin then they -// have pointers that are relative to the __iob array. If this is the case, -// change the FILE into the REAL stdio stream. -// -static FILE *getFILE(void *Ptr) { - static Module *LastMod = 0; - static PointerTy IOBBase = 0; - static unsigned FILESize; - - if (LastMod != &TheInterpreter->getModule()) { // Module change or initialize? - Module *M = LastMod = &TheInterpreter->getModule(); - - // Check to see if the currently loaded module contains an __iob symbol... - GlobalVariable *IOB = 0; - SymbolTable &ST = M->getSymbolTable(); - for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) { - SymbolTable::VarMap &M = I->second; - for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end(); - J != E; ++J) - if (J->first == "__iob") - if ((IOB = dyn_cast(J->second))) - break; - if (IOB) break; - } - } - - // Check to see if this is a reference to __iob... - if (IOBBase) { - unsigned FDNum = ((unsigned long)Ptr-IOBBase)/FILESize; - if (FDNum == 0) - return stdin; - else if (FDNum == 1) - return stdout; - else if (FDNum == 2) - return stderr; - } - - return (FILE*)Ptr; -} - +// the interpreter address space. This is an identity transformation. +#define getFILE(ptr) ((FILE*)ptr) // FILE *fopen(const char *filename, const char *mode); GenericValue lle_X_fopen(FunctionType *M, const vector &Args) { From llvm at cs.uiuc.edu Tue May 25 07:22:27 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:27 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Type.h Message-ID: <200405250846.DAA12540@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: Type.h updated: 1.42 -> 1.43 --- Log message: Give Type its own dump() method in preparation for Type != Value. --- Diffs of the changes: (+3 -0) Index: llvm/include/llvm/Type.h diff -u llvm/include/llvm/Type.h:1.42 llvm/include/llvm/Type.h:1.43 --- llvm/include/llvm/Type.h:1.42 Fri Mar 26 15:43:12 2004 +++ llvm/include/llvm/Type.h Tue May 25 03:46:04 2004 @@ -128,6 +128,9 @@ public: virtual void print(std::ostream &O) const; + /// @brief Debugging support: print to stderr + virtual void dump() const; + //===--------------------------------------------------------------------===// // Property accessors for dealing with types... Some of these virtual methods // are defined in private classes defined in Type.cpp for primitive types. From llvm at cs.uiuc.edu Tue May 25 07:22:32 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:32 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/SymbolTable.h Message-ID: <200405250846.DAA12488@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: SymbolTable.h updated: 1.30 -> 1.31 --- Log message: Completely rewrote the class. SymbolTable now separates Type* from Value* in preparation\ for making Type not derive from Value. There are now separate interfaces \ for looking up, finding, and inserting Types and Values. There are also \ three separate iterator interfaces, one for type planes, one for the types \ (type type plane), and one for values within a type plane. See the \ documentation in the Header file. --- Diffs of the changes: (+336 -83) Index: llvm/include/llvm/SymbolTable.h diff -u llvm/include/llvm/SymbolTable.h:1.30 llvm/include/llvm/SymbolTable.h:1.31 --- llvm/include/llvm/SymbolTable.h:1.30 Wed Dec 31 01:08:19 2003 +++ llvm/include/llvm/SymbolTable.h Tue May 25 03:45:53 2004 @@ -2,21 +2,13 @@ // // 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 file was developed by the LLVM research group and re-written by Reid +// Spencer. It is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // -// This file implements a symbol table that has planes broken up by type. -// Identical types may have overlapping symbol names as long as they are -// distinct. -// -// Note that this implements a chained symbol table. If a name being 'lookup'd -// isn't found in the current symbol table, then the parent symbol table is -// searched. -// -// This chaining behavior does NOT affect iterators though: only the lookup -// method. +// This file implements the main symbol table for LLVM. // //===----------------------------------------------------------------------===// @@ -28,112 +20,373 @@ namespace llvm { -class SymbolTable : public AbstractTypeUser, - public std::map > { +/// This class provides a symbol table of name/value pairs that is broken +/// up by type. For each Type* there is a "plane" of name/value pairs in +/// the symbol table. Identical types may have overlapping symbol names as +/// long as they are distinct. The SymbolTable also tracks, separately, a +/// map of name/type pairs. This allows types to be named. Types are treated +/// distinctly from Values. +/// +/// The SymbolTable provides several utility functions for answering common +/// questions about its contents as well as an iterator interface for +/// directly iterating over the contents. To reduce confusion, the terms +/// "type", "value", and "plane" are used consistently. For example, +/// There is a TypeMap typedef that is the mapping of names to Types. +/// Similarly there is a ValueMap typedef that is the mapping of +/// names to Values. Finally, there is a PlaneMap typedef that is the +/// mapping of types to planes of ValueMap. THis is the basic structure +/// of the symbol table. When you call type_begin() you're asking +/// for an iterator at the start of the TypeMap. When you call +/// plane_begin(), you're asking for an iterator at the start of +/// the PlaneMap. Finally, when you call value_begin(), you're asking +/// for an iterator at the start of a ValueMap for a specific type +/// plane. +class SymbolTable : public AbstractTypeUser { + +/// @name Types +/// @{ public: - typedef std::map VarMap; - typedef std::map super; - typedef VarMap::iterator type_iterator; - typedef VarMap::const_iterator type_const_iterator; + /// @brief A mapping of names to types. + typedef std::map TypeMap; + + /// @brief An iterator over the TypeMap. + typedef TypeMap::iterator type_iterator; + + /// @brief A const_iterator over the TypeMap. + typedef TypeMap::const_iterator type_const_iterator; + + /// @brief A mapping of names to values. + typedef std::map ValueMap; + + /// @brief An iterator over a ValueMap. + typedef ValueMap::iterator value_iterator; + + /// @brief A const_iterator over a ValueMap. + typedef ValueMap::const_iterator value_const_iterator; + + /// @brief A mapping of types to names to values (type planes). + typedef std::map PlaneMap; + + /// @brief An iterator over the type planes. + typedef PlaneMap::iterator plane_iterator; - inline SymbolTable() : InternallyInconsistent(false), LastUnique(0) {} + /// @brief A const_iterator over the type planes + typedef PlaneMap::const_iterator plane_const_iterator; + +/// @} +/// @name Constructors +/// @{ +public: + + inline SymbolTable() + : pmap(), tmap(), InternallyInconsistent(false), LastUnique(0) {} ~SymbolTable(); - // lookup - Returns null on failure... +/// @} +/// @name Accessors +/// @{ +public: + + /// This method finds the value with the given \p name in the + /// type plane \p Ty and returns it. This method will not find any + /// Types, only Values. Use lookupType to find Types by name. + /// @returns null on failure, otherwise the Value associated with + /// the \p name in type plane \p Ty. + /// @brief Lookup a named, typed value. Value *lookup(const Type *Ty, const std::string &name) const; - // insert - Add named definition to the symbol table... - inline void insert(Value *N) { - assert(N->hasName() && "Value must be named to go into symbol table!"); - insertEntry(N->getName(), N->getType(), N); + /// This method finds the type with the given \p name in the + /// type map and returns it. + /// @returns null if the name is not found, otherwise the Type + /// associated with the \p name. + /// @brief Lookup a type by name. + Type* lookupType( const std::string& name ) const; + + /// @returns true iff the type map is not empty. + /// @brief Determine if there are types in the symbol table + inline bool hasTypes() const { return ! tmap.empty(); } + + /// @returns true iff the type map and the type plane are both not + /// empty. + /// @brief Determine if the symbol table is empty + inline bool isEmpty() const { return pmap.empty() && tmap.empty(); } + + /// The plane associated with the \p TypeID parameter is found + /// and the number of entries in the plane is returned. + /// @returns Number of entries in the specified type plane or 0. + /// @brief Get the size of a type plane. + unsigned type_size(const Type *TypeID) const; + + /// @brief The number of name/type pairs is returned. + inline unsigned num_types() const { return tmap.size(); } + + /// Finds the value \p val in the symbol table and returns its + /// name. Only the type plane associated with the type of \p val + /// is searched. + /// @brief Return the name of a value + std::string get_name( const Value* Val ) const; + + /// Finds the type \p Ty in the symbol table and returns its name. + /// @brief Return the name of a type + std::string get_name( const Type* Ty ) const; + + /// Given a base name, return a string that is either equal to it or + /// derived from it that does not already occur in the symbol table + /// for the specified type. + /// @brief Get a name unique to this symbol table + std::string getUniqueName(const Type *Ty, + const std::string &BaseName) const; + + /// This function can be used from the debugger to display the + /// content of the symbol table while debugging. + /// @brief Print out symbol table on stderr + void dump() const; + +/// @} +/// @name Mutators +/// @{ +public: + + /// This method adds the provided value \p N to the symbol table. + /// The Value must have both a name and a type which are extracted + /// and used to place the value in the correct type plane under + /// the value's name. + /// @brief Add a named value to the symbol table + inline void insert(Value *Val) { + assert(Val && "Can't insert null type into symbol table!"); + assert(Val->hasName() && "Value must be named to go into symbol table!"); + insertEntry(Val->getName(), Val->getType(), Val); } - void remove(Value *N); - Value *type_remove(const type_iterator &It) { - return removeEntry(find(It->second->getType()), It); + /// Inserts a constant or type into the symbol table with the specified + /// name. There can be a many to one mapping between names and constants + /// or types. + /// @brief Insert a constant or type. + inline void insert(const std::string &Name, Value *Val) { + assert(Val && "Can't insert null type into symbol table!"); + assert((isa(Val) || isa(Val)) && + "Can only insert types and constants into a symbol table!"); + insertEntry(Name, Val->getType(), Val); } - // insert - Insert a constant or type into the symbol table with the specified - // name... There can be a many to one mapping between names and - // (constant/type)s. - // - inline void insert(const std::string &Name, Value *V) { - assert((isa(V) || isa(V)) && - "Can only insert types and constants here!"); - insertEntry(Name, V->getType(), V); + /// Inserts a type into the symbol table with the specified name. There + /// can be a many-to-one mapping between names and types. This method + /// allows a type with an existing entry in the symbol table to get + /// a new name. + /// @brief Insert a type under a new name. + inline void insert(const std::string &Name, Type *Typ) { + assert(Typ && "Can't insert null type into symbol table!"); + insertEntry(Name, Typ ); } - /// remove - Remove a constant or type from the symbol table with the - /// specified name. - Value *remove(const std::string &Name, Value *V) { - iterator TI = find(V->getType()); - return removeEntry(TI, TI->second.find(Name)); + /// This method removes a named value from the symbol table. The + /// type and name of the Value are extracted from \p N and used to + /// lookup the Value in the correct type plane. If the Value is + /// not in the symbol table, this method silently ignores the + /// request. + /// @brief Remove a named value from the symbol table. + void remove(Value* Val); + + /// This method removes a named type from the symbol table. The + /// name of the type is extracted from \P T and used to look up + /// the Type in the type map. If the Type is not in the symbol + /// table, this method silently ignores the request. + /// @brief Remove a named type from the symbol table. + void remove(Type* Typ ); + + /// Remove a constant or type with the specified name from the + /// symbol table. + /// @returns the removed Value. + /// @brief Remove a constant or type from the symbol table. + inline Value* remove(const std::string &Name, Value *Val) { + assert(Val && "Can't remove null value from symbol table!"); + plane_iterator PI = pmap.find(Val->getType()); + return removeEntry(PI, PI->second.find(Name)); } - // getUniqueName - Given a base name, return a string that is either equal to - // it (or derived from it) that does not already occur in the symbol table for - // the specified type. - // - std::string getUniqueName(const Type *Ty, const std::string &BaseName); + /// Remove a type with the specified name from the symbol table. + /// @returns the removed Type. + /// @brief Remove a named tyep from the symbol table. + inline Type* remove(const std::string& Name, Type* T ) { + return removeEntry( tmap.find(Name) ); + } - inline unsigned type_size(const Type *TypeID) const { - return find(TypeID)->second.size(); + /// Removes a specific value from the symbol table. + /// @returns the removed value. + /// @brief Remove a specific value given by an iterator + inline Value *value_remove(const value_iterator &It) { + return this->removeEntry(pmap.find(It->second->getType()), It); } - // Note that type_begin / type_end only work if you know that an element of - // TypeID is already in the symbol table!!! - // - inline type_iterator type_begin(const Type *TypeID) { - return find(TypeID)->second.begin(); + /// This method will strip the symbol table of its names leaving + /// the type and values. + /// @brief Strip the symbol table. + bool strip(); + + /// @brief Empty the symbol table completely. + inline void clear() { pmap.clear(); tmap.clear(); } + +/// @} +/// @name Iteration +/// @{ +public: + + /// Get an iterator that starts at the beginning of the type planes. + /// The iterator will iterate over the Type/ValueMap pairs in the + /// type planes. + inline plane_iterator plane_begin() { return pmap.begin(); } + + /// Get a const_iterator that starts at the beginning of the type + /// planes. The iterator will iterate over the Type/ValueMap pairs + /// in the type planes. + inline plane_const_iterator plane_begin() const { return pmap.begin(); } + + /// Get an iterator at the end of the type planes. This serves as + /// the marker for end of iteration over the type planes. + inline plane_iterator plane_end() { return pmap.end(); } + + /// Get a const_iterator at the end of the type planes. This serves as + /// the marker for end of iteration over the type planes. + inline plane_const_iterator plane_end() const { return pmap.end(); } + + /// Get an iterator that starts at the beginning of a type plane. + /// The iterator will iterate over the name/value pairs in the type plane. + /// @note The type plane must already exist before using this. + inline value_iterator value_begin(const Type *Typ) { + assert(Typ && "Can't get value iterator with null type!"); + return pmap.find(Typ)->second.begin(); } - inline type_const_iterator type_begin(const Type *TypeID) const { - return find(TypeID)->second.begin(); + + /// Get a const_iterator that starts at the beginning of a type plane. + /// The iterator will iterate over the name/value pairs in the type plane. + /// @note The type plane must already exist before using this. + inline value_const_iterator value_begin(const Type *Typ) const { + assert(Typ && "Can't get value iterator with null type!"); + return pmap.find(Typ)->second.begin(); } - inline type_iterator type_end(const Type *TypeID) { - return find(TypeID)->second.end(); + /// Get an iterator to the end of a type plane. This serves as the marker + /// for end of iteration of the type plane. + /// @note The type plane must already exist before using this. + inline value_iterator value_end(const Type *Typ) { + assert(Typ && "Can't get value iterator with null type!"); + return pmap.find(Typ)->second.end(); } - inline type_const_iterator type_end(const Type *TypeID) const { - return find(TypeID)->second.end(); + + /// Get a const_iterator to the end of a type plane. This serves as the + /// marker for end of iteration of the type plane. + /// @note The type plane must already exist before using this. + inline value_const_iterator value_end(const Type *Typ) const { + assert(Typ && "Can't get value iterator with null type!"); + return pmap.find(Typ)->second.end(); } - void dump() const; // Debug method, print out symbol table + /// Get an iterator to the start of the name/Type map. + inline type_iterator type_begin() { return tmap.begin(); } -private: - // InternallyInconsistent - There are times when the symbol table is - // internally inconsistent with the rest of the program. In this one case, a - // value exists with a Name, and it's not in the symbol table. When we call - // V->setName(""), it tries to remove itself from the symbol table and dies. - // We know this is happening, and so if the flag InternallyInconsistent is - // set, removal from the symbol table is a noop. - // - bool InternallyInconsistent; + /// @brief Get a const_iterator to the start of the name/Type map. + inline type_const_iterator type_begin() const { return tmap.begin(); } + + /// Get an iterator to the end of the name/Type map. This serves as the + /// marker for end of iteration of the types. + inline type_iterator type_end() { return tmap.end(); } + + /// Get a const-iterator to the end of the name/Type map. This serves + /// as the marker for end of iteration of the types. + inline type_const_iterator type_end() const { return tmap.end(); } + + /// This method returns a plane_const_iterator for iteration over + /// the type planes starting at a specific plane, given by \p Ty. + /// @brief Find a type plane. + inline plane_const_iterator find(const Type* Typ ) const { + assert(Typ && "Can't find type plane with null type!"); + return pmap.find( Typ ); + } + + /// This method returns a plane_iterator for iteration over the + /// type planes starting at a specific plane, given by \p Ty. + /// @breif Find a type plane. + inline plane_iterator find( const Type* Typ ) { + assert(Typ && "Can't find type plane with null type!"); + return pmap.find(Typ); + } - // LastUnique - This value is used to retain the last unique value used - // by getUniqueName to generate unique names. - unsigned long LastUnique; - - inline super::value_type operator[](const Type *Ty) { - assert(0 && "Should not use this operator to access symbol table!"); - return super::value_type(); + /// This method returns a ValueMap* for a specific type plane. This + /// interface is deprecated and may go away in the future. + /// @deprecated + /// @brief Find a type plane + inline const ValueMap* findPlane( const Type* Typ ) const { + assert(Typ && "Can't find type plane with null type!"); + plane_const_iterator I = pmap.find( Typ ); + if ( I == pmap.end() ) return 0; + return &I->second; } - // insertEntry - Insert a value into the symbol table with the specified - // name... - // +/// @} +/// @name Internal Methods +/// @{ +private: + /// @brief Insert a value into the symbol table with the specified name. void insertEntry(const std::string &Name, const Type *Ty, Value *V); - // removeEntry - Remove a value from the symbol table... - // - Value *removeEntry(iterator Plane, type_iterator Entry); + /// @brief Insert a type into the symbol table with the specified name. + void insertEntry(const std::string &Name, Type *T); + + /// Remove a specific value from a specific plane in the SymbolTable. + /// @returns the removed Value. + Value* removeEntry(plane_iterator Plane, value_iterator Entry); + + /// Remove a specific type from the SymbolTable. + /// @returns the removed Type. + Type* removeEntry(type_iterator Entry); - // This function is called when one of the types in the type plane are refined + /// This function is called when one of the types in the type plane + /// is refined. virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy); + + /// This function markes a type as being concrete (defined). virtual void typeBecameConcrete(const DerivedType *AbsTy); + +/// @} +/// @name Internal Data +/// @{ +private: + + /// This is the main content of the symbol table. It provides + /// separate type planes for named values. That is, each named + /// value is organized into a separate dictionary based on + /// Type. This means that the same name can be used for different + /// types without conflict. Note that the Type::TypeTy plane is + /// not stored in this map but is in tmap. + /// @brief The mapping of types to names to values. + PlaneMap pmap; + + /// This is the Type::TypeTy plane. It is separated from the pmap + /// because the elements of the map are name/Type pairs not + /// name/Value pairs and Type is not a Value. + TypeMap tmap; + + /// There are times when the symbol table is internally inconsistent with + /// the rest of the program. In this one case, a value exists with a Name, + /// and it's not in the symbol table. When we call V->setName(""), it + /// tries to remove itself from the symbol table and dies. We know this + /// is happening, and so if the flag InternallyInconsistent is set, + /// removal from the symbol table is a noop. + /// @brief Indicator of symbol table internal inconsistency. + bool InternallyInconsistent; + + /// This value is used to retain the last unique value used + /// by getUniqueName to generate unique names. + mutable unsigned long LastUnique; + +/// @} + }; } // End llvm namespace +// vim: sw=2 + #endif + From llvm at cs.uiuc.edu Tue May 25 07:22:36 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 07:22:36 2004 Subject: [llvm-commits] CVS: llvm/docs/GarbageCollection.html Message-ID: <200405250845.DAA12438@zion.cs.uiuc.edu> Changes in directory llvm/docs: GarbageCollection.html updated: 1.2 -> 1.3 --- Log message: Fix a small typo. --- Diffs of the changes: (+2 -2) Index: llvm/docs/GarbageCollection.html diff -u llvm/docs/GarbageCollection.html:1.2 llvm/docs/GarbageCollection.html:1.3 --- llvm/docs/GarbageCollection.html:1.2 Sun May 23 23:54:31 2004 +++ llvm/docs/GarbageCollection.html Tue May 25 03:45:31 2004 @@ -190,7 +190,7 @@ ... ;; "CodeBlock" is the block corresponding to the start - ;; of the scope scope above. + ;; of the scope above. CodeBlock: ;; Initialize the object, telling LLVM that it is now live. ;; Java has type-tags on objects, so it doesn't need any @@ -411,7 +411,7 @@ Chris Lattner
    LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/24 04:54:31 $ + Last modified: $Date: 2004/05/25 08:45:31 $ From llvm at cs.uiuc.edu Tue May 25 10:24:58 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 10:24:58 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/SymbolTable.cpp Message-ID: <200405251520.KAA10063@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: SymbolTable.cpp updated: 1.43 -> 1.44 --- Log message: Made it illegal to pass a Type* through one of the Value* interfaces. The SymbolTable will now assert if this is done. This didn't find any incorrect usage of SymbolTable but will prevent future mistakes until Type != Value. --- Diffs of the changes: (+4 -0) Index: llvm/lib/VMCore/SymbolTable.cpp diff -u llvm/lib/VMCore/SymbolTable.cpp:1.43 llvm/lib/VMCore/SymbolTable.cpp:1.44 --- llvm/lib/VMCore/SymbolTable.cpp:1.43 Tue May 25 03:52:42 2004 +++ llvm/lib/VMCore/SymbolTable.cpp Tue May 25 10:20:47 2004 @@ -93,6 +93,7 @@ // Remove a value void SymbolTable::remove(Value *N) { assert(N->hasName() && "Value doesn't have name!"); + assert(!isa(N) && "Can't remove types through this interface."); if (InternallyInconsistent) return; plane_iterator PI = pmap.find(N->getType()); @@ -109,6 +110,7 @@ Entry != Plane->second.end() && "Invalid entry to remove!"); Value *Result = Entry->second; + assert(!isa(Result) && "Can't remove types through this interface."); const Type *Ty = Result->getType(); #if DEBUG_SYMBOL_TABLE dump(); @@ -181,6 +183,7 @@ // insertEntry - Insert a value into the symbol table with the specified name. void SymbolTable::insertEntry(const std::string &Name, const Type *VTy, Value *V) { + assert(!isa(V) && "Can't insert types through this interface."); // Check to see if there is a naming conflict. If so, rename this value! if (lookup(VTy, Name)) { std::string UniqueName = getUniqueName(VTy, Name); @@ -259,6 +262,7 @@ // Get the name of a value std::string SymbolTable::get_name( const Value* V ) const { + assert(!isa(V) && "Can't get name of types through this interface."); value_const_iterator VI = this->value_begin( V->getType() ); value_const_iterator VE = this->value_end( V->getType() ); From llvm at cs.uiuc.edu Tue May 25 10:51:02 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 10:51:02 2004 Subject: [llvm-commits] CVS: llvm/docs/BytecodeFormat.html Message-ID: <200405251548.KAA10148@zion.cs.uiuc.edu> Changes in directory llvm/docs: BytecodeFormat.html updated: 1.6 -> 1.7 --- Log message: Added a bit on slot numbers. --- Diffs of the changes: (+39 -1) Index: llvm/docs/BytecodeFormat.html diff -u llvm/docs/BytecodeFormat.html:1.6 llvm/docs/BytecodeFormat.html:1.7 --- llvm/docs/BytecodeFormat.html:1.6 Mon May 24 00:35:17 2004 +++ llvm/docs/BytecodeFormat.html Tue May 25 10:47:57 2004 @@ -19,6 +19,7 @@
  • Blocks
  • Lists
  • Fields
  • +
  • Slots
  • Encoding Rules
  • Alignment
  • @@ -120,6 +121,43 @@ written and how the bits are to be interpreted.

    +
    Slots
    +
    +

    The bytecode format uses the notion of a "slot" to reference Types and +Values. Since the bytecode file is a direct representation of LLVM's +intermediate representation, there is a need to represent pointers in the file. +Slots are used for this purpose. For example, if one has the following assembly: +

    +
    
    +  %MyType = type { int, sbyte };
    +  %MyVar = external global %MyType ;
    +
    +

    there are two definitions. The definition of %MyVar uses %MyType and %MyType +is used by %MyVar. In the C++ IR this linkage between %MyVar and %MyType is +made explicitly by the use of C++ pointers. In bytecode, however, there's no +ability to store memory addresses. Instead, we compute and write out slot +numbers for every type and Value written to the file.

    +

    A slot number is simply an unsigned 32-bit integer encoded in the variable +bit rate scheme (see encoding below). This ensures that +low slot numbers are encoded in one byte. Through various bits of magic LLVM +attempts to always keep the slot numbers low. The first attempt is to associate +slot numbers with their "type plane". That is, Values of the same type are +written to the bytecode file in a list (sequentially). Their order in that list +determines their slot number. This means that slot #1 doesn't mean anything +unless you also specify for which type you want slot #1. Types are handled +specially and are always written to the file first (in the Global Type Pool) and +in such a way that both forward and backward references of the types can be +resolved with a single pass through the type pool.

    +

    Slot numbers are also kept small by rearranging their order. Because of the +structure of LLVM, certain values are much more likely to be used frequently +in the body of a function. For this reason, a compaction table is provided in +the body of a function if its use would make the function body smaller. +Suppose you have a function body that uses just the types "int*" and "{double}" +but uses them thousands of time. Its worthwhile to ensure that the slot number +for these types are low so they can be encoded in a single byte (via vbr). +This is exactly what the compaction table does.

    +
    +
    Encoding Primitives

    Each field that can be put out is encoded into the file using a small set @@ -471,7 +509,7 @@ Reid Spencer and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/24 05:35:17 $ + Last modified: $Date: 2004/05/25 15:47:57 $ From llvm at cs.uiuc.edu Tue May 25 12:31:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 12:31:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/ValueHolder.h Message-ID: <200405251728.MAA10791@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: ValueHolder.h (r1.5) removed --- Log message: Removed unused, useless header file. --- Diffs of the changes: (+0 -0) From llvm at cs.uiuc.edu Tue May 25 12:32:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 12:32:01 2004 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y Message-ID: <200405251729.MAA10806@zion.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: llvmAsmParser.y updated: 1.163 -> 1.164 --- Log message: Changed to use SymbolTable's new lookup interface. --- Diffs of the changes: (+2 -2) Index: llvm/lib/AsmParser/llvmAsmParser.y diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.163 llvm/lib/AsmParser/llvmAsmParser.y:1.164 --- llvm/lib/AsmParser/llvmAsmParser.y:1.163 Sat Apr 17 18:49:15 2004 +++ llvm/lib/AsmParser/llvmAsmParser.y Tue May 25 12:29:21 2004 @@ -239,7 +239,7 @@ Value *N = 0; if (inFunctionScope()) { SymTab = &CurFun.CurrentFunction->getSymbolTable(); - N = SymTab->lookup(Type::TypeTy, Name); + N = SymTab->lookupType(Name); } if (N == 0) { @@ -247,7 +247,7 @@ // hasn't been added to the module... // SymTab = &CurModule.CurrentModule->getSymbolTable(); - N = SymTab->lookup(Type::TypeTy, Name); + N = SymTab->lookupType(Name); if (N == 0) break; } From llvm at cs.uiuc.edu Tue May 25 12:33:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 12:33:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Writer/Writer.cpp Message-ID: <200405251730.MAA10818@zion.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Writer: Writer.cpp updated: 1.62 -> 1.63 --- Log message: Changed to use SymbolTable's new iteration interfaces. --- Diffs of the changes: (+18 -6) Index: llvm/lib/Bytecode/Writer/Writer.cpp diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.62 llvm/lib/Bytecode/Writer/Writer.cpp:1.63 --- llvm/lib/Bytecode/Writer/Writer.cpp:1.62 Sun Apr 4 20:27:26 2004 +++ llvm/lib/Bytecode/Writer/Writer.cpp Tue May 25 12:29:59 2004 @@ -307,22 +307,34 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { // Do not output the Bytecode block for an empty symbol table, it just wastes // space! - if (MST.begin() == MST.end()) return; + if (MST.plane_begin() == MST.plane_end()) return; BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTable, Out, true/* ElideIfEmpty*/); - for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) { - SymbolTable::type_const_iterator I = MST.type_begin(TI->first); - SymbolTable::type_const_iterator End = MST.type_end(TI->first); + //Symtab block header: [num entries][type id number] + output_vbr(MST.num_types(), Out); + output_vbr((unsigned)Table.getSlot(Type::TypeTy), Out); + for (SymbolTable::type_const_iterator TI = MST.type_begin(), + TE = MST.type_end(); TI != TE; ++TI ) { + //Symtab entry:[def slot #][name] + output_vbr((unsigned)Table.getSlot(TI->second), Out); + output(TI->first, Out, /*align=*/false); + } + + // Now do each of the type planes in order. + for (SymbolTable::plane_const_iterator PI = MST.plane_begin(), + PE = MST.plane_end(); PI != PE; ++PI) { + SymbolTable::value_const_iterator I = MST.value_begin(PI->first); + SymbolTable::value_const_iterator End = MST.value_end(PI->first); int Slot; if (I == End) continue; // Don't mess with an absent type... // Symtab block header: [num entries][type id number] - output_vbr(MST.type_size(TI->first), Out); + output_vbr(MST.type_size(PI->first), Out); - Slot = Table.getSlot(TI->first); + Slot = Table.getSlot(PI->first); assert(Slot != -1 && "Type in symtab, but not in table!"); output_vbr((unsigned)Slot, Out); From lattner at cs.uiuc.edu Tue May 25 12:40:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue May 25 12:40:01 2004 Subject: [llvm-commits] CVS: llvm-www/Documentation.html Message-ID: <200405251737.MAA11507@zion.cs.uiuc.edu> Changes in directory llvm-www: Documentation.html updated: 1.6 -> 1.7 --- Log message: Add a whole mess of missing links --- Diffs of the changes: (+9 -0) Index: llvm-www/Documentation.html diff -u llvm-www/Documentation.html:1.6 llvm-www/Documentation.html:1.7 --- llvm-www/Documentation.html:1.6 Sat Feb 21 23:43:30 2004 +++ llvm-www/Documentation.html Tue May 25 12:37:13 2004 @@ -56,6 +56,9 @@ on how to write a new alias analysis implementation or how to use existing analyses. +

  • Accurate Garbage Collection with LLVM - +The interfaces source-language compilers should use for compiling GC'd programs.
  • +
  • Source Level Debugging with LLVM - This document describes the design and philosophy behind the LLVM source-level debugger.
  • @@ -78,6 +81,12 @@
  • The Stacker Cronicles - This document describes both the Stacker language and LLVM frontend, but also some details about LLVM useful for those writing front-ends.
  • + +
  • Extending LLVM - Look here to see how +to add instructions and intrinsics to LLVM.
  • +
  • Coding Standards - Guidelines for +hacking LLVM source.
  • +
  • LLVM Bytecode File Format
  • Doxygen generated documentation (classes)
  • From lattner at cs.uiuc.edu Tue May 25 12:41:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue May 25 12:41:02 2004 Subject: [llvm-commits] CVS: llvm-www/Documentation.html Message-ID: <200405251738.MAA12131@zion.cs.uiuc.edu> Changes in directory llvm-www: Documentation.html updated: 1.7 -> 1.8 --- Log message: Futhermore, give them the correct path --- Diffs of the changes: (+4 -4) Index: llvm-www/Documentation.html diff -u llvm-www/Documentation.html:1.7 llvm-www/Documentation.html:1.8 --- llvm-www/Documentation.html:1.7 Tue May 25 12:37:13 2004 +++ llvm-www/Documentation.html Tue May 25 12:38:05 2004 @@ -56,7 +56,7 @@ on how to write a new alias analysis implementation or how to use existing analyses. -
  • Accurate Garbage Collection with LLVM - +
  • Accurate Garbage Collection with LLVM - The interfaces source-language compilers should use for compiling GC'd programs.
  • Source Level Debugging with LLVM - @@ -82,11 +82,11 @@ describes both the Stacker language and LLVM frontend, but also some details about LLVM useful for those writing front-ends.
  • -
  • Extending LLVM - Look here to see how +
  • Extending LLVM - Look here to see how to add instructions and intrinsics to LLVM.
  • -
  • Coding Standards - Guidelines for +
  • Coding Standards - Guidelines for hacking LLVM source.
  • -
  • LLVM Bytecode File Format
  • +
  • LLVM Bytecode File Format
  • Doxygen generated documentation (classes)
  • From lattner at cs.uiuc.edu Tue May 25 12:48:05 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue May 25 12:48:05 2004 Subject: [llvm-commits] CVS: llvm/docs/BytecodeFormat.html Message-ID: <200405251745.MAA12791@zion.cs.uiuc.edu> Changes in directory llvm/docs: BytecodeFormat.html updated: 1.7 -> 1.8 --- Log message: Make use of the doc_author and doc_code styles. 'ify llvm names. Minor other edits --- Diffs of the changes: (+15 -13) Index: llvm/docs/BytecodeFormat.html diff -u llvm/docs/BytecodeFormat.html:1.7 llvm/docs/BytecodeFormat.html:1.8 --- llvm/docs/BytecodeFormat.html:1.7 Tue May 25 10:47:57 2004 +++ llvm/docs/BytecodeFormat.html Tue May 25 12:44:58 2004 @@ -38,10 +38,9 @@ -
    -

    Written by Reid Spencer -and Chris Lattner

    -

    +
    +

    Written by Reid Spencer +

    @@ -128,13 +127,16 @@ intermediate representation, there is a need to represent pointers in the file. Slots are used for this purpose. For example, if one has the following assembly:

    -
    
    -  %MyType = type { int, sbyte };
    -  %MyVar = external global %MyType ;
    -
    -

    there are two definitions. The definition of %MyVar uses %MyType and %MyType -is used by %MyVar. In the C++ IR this linkage between %MyVar and %MyType is -made explicitly by the use of C++ pointers. In bytecode, however, there's no + +

    + %MyType = type { int, sbyte }
    + %MyVar = external global %MyType +
    + +

    there are two definitions. The definition of %MyVar uses +%MyType. In the C++ IR this linkage between %MyVar and +%MyType is +explicit through the use of C++ pointers. In bytecode, however, there's no ability to store memory addresses. Instead, we compute and write out slot numbers for every type and Value written to the file.

    A slot number is simply an unsigned 32-bit integer encoded in the variable @@ -146,7 +148,7 @@ determines their slot number. This means that slot #1 doesn't mean anything unless you also specify for which type you want slot #1. Types are handled specially and are always written to the file first (in the Global Type Pool) and -in such a way that both forward and backward references of the types can be +in such a way that both forward and backward references of the types can often be resolved with a single pass through the type pool.

    Slot numbers are also kept small by rearranging their order. Because of the structure of LLVM, certain values are much more likely to be used frequently @@ -509,7 +511,7 @@ Reid Spencer and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/25 15:47:57 $ + Last modified: $Date: 2004/05/25 17:44:58 $ From llvm at cs.uiuc.edu Tue May 25 13:17:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 13:17:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200405251814.NAA12932@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.129 -> 1.130 --- Log message: Document a couple functions. --- Diffs of the changes: (+5 -0) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.129 llvm/lib/VMCore/AsmWriter.cpp:1.130 --- llvm/lib/VMCore/AsmWriter.cpp:1.129 Tue May 25 03:52:09 2004 +++ llvm/lib/VMCore/AsmWriter.cpp Tue May 25 13:14:38 2004 @@ -1015,7 +1015,12 @@ o << getType() << " " << getName(); } +// Value::dump - allow easy printing of Values from the debugger. +// Located here because so much of the needed functionality is here. void Value::dump() const { print(std::cerr); } + +// Type::dump - allow easy printing of Values from the debugger. +// Located here because so much of the needed functionality is here. void Type::dump() const { print(std::cerr); } //===----------------------------------------------------------------------===// From llvm at cs.uiuc.edu Tue May 25 13:18:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 13:18:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Internal/ Message-ID: <200405251815.NAA12942@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Internal: --- Log message: Directory /var/cvs/llvm/llvm/include/llvm/Internal added to the repository --- Diffs of the changes: (+0 -0) From alkis at cs.uiuc.edu Tue May 25 13:27:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 13:27:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/ValueHolder.cpp Message-ID: <200405251824.NAA13035@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: ValueHolder.cpp (r1.4) removed --- Log message: Remove this file as well as it is no longer needed nor it compiles --- Diffs of the changes: (+0 -0) From alkis at cs.uiuc.edu Tue May 25 13:38:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 13:38:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405251835.NAA23660@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.22 -> 1.23 --- Log message: Create entry basic block before anything else so that it really is the entry basic block ;-) --- Diffs of the changes: (+4 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.22 llvm-java/lib/Compiler/Compiler.cpp:1.23 --- llvm-java/lib/Compiler/Compiler.cpp:1.22 Mon May 24 22:50:51 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 13:35:06 2004 @@ -58,9 +58,10 @@ bc2bbMap_.clear(); bc2bbMap_.assign(codeAttr_.getCodeSize(), NULL); + BasicBlock* bb = new BasicBlock("entry", &function_); + parse(codeAttr_.getCode(), codeAttr_.getCodeSize()); - BasicBlock* bb = new BasicBlock("entry", &function_); for (unsigned i = 0; i < bc2bbMap_.size(); ++i) { if (bc2bbMap_[i]) bb = bc2bbMap_[i]; @@ -194,6 +195,8 @@ compileMethodInit(*function, cf, *codeAttr); parse(codeAttr->getCode(), codeAttr->getCodeSize()); + + assert(function->getEntryBlock().getName() == "entry"); } void do_aconst_null(unsigned bcI) { From llvm at cs.uiuc.edu Tue May 25 13:48:02 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 13:48:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/SlotTable.cpp Message-ID: <200405251845.NAA31895@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: SlotTable.cpp added (r1.1) --- Log message: Adding the initial implementation of the SlotTable class. This class is the Abstract Data Type that holds slot number values and associates them with Type* and Value*. The SlotTable is simply the holder of the slot numbers and provides a controlled interface for building the table. It does not enforce any particular idiom or functionality for manipulating the slot numbers. This is part of bug_122. The SlotCalculator and SlotMachine classes will follow. --- Diffs of the changes: (+115 -0) Index: llvm/lib/Support/SlotTable.cpp diff -c /dev/null llvm/lib/Support/SlotTable.cpp:1.1 *** /dev/null Tue May 25 13:45:01 2004 --- llvm/lib/Support/SlotTable.cpp Tue May 25 13:44:51 2004 *************** *** 0 **** --- 1,115 ---- + //===-- SlotCalculator.cpp - Calculate what slots values land in ----------===// + // + // 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 file implements a utility class for keeping track of slot numbers for + // bytecode and assembly writing. + // + //===----------------------------------------------------------------------===// + + #include "llvm/Internal/SlotTable.h" + #include "llvm/Type.h" + #include "llvm/Value.h" + #include "llvm/GlobalValue.h" + #include "llvm/Constants.h" + + using namespace llvm; + + //===----------------------------------------------------------------------===// + // SlotTable Implementation + //===----------------------------------------------------------------------===// + + SlotTable::SlotTable( bool dont_insert_primitives ) { + if ( ! dont_insert_primitives ) + this->insertPrimitives(); + } + + // empty - determine if the slot table is completely empty. + bool SlotTable::empty() const { + return vTable.empty() && vMap.empty() && tPlane.empty() && tMap.empty(); + } + + // getSlot - get the slot number associated with value Val + SlotTable::SlotNum SlotTable::getSlot(const Value* Val) const { + ValueMap::const_iterator I = vMap.find( Val ); + if ( I != vMap.end() ) + return I->second; + + // Do not number ConstantPointerRef's at all. They are an abomination. + if (const ConstantPointerRef *CPR = dyn_cast(Val)) + return this->getSlot(CPR->getValue()); + + return BAD_SLOT; + } + + // getSlot - get the slot number associated with type Typ + SlotTable::SlotNum SlotTable::getSlot(const Type* Typ) const { + TypeMap::const_iterator I = tMap.find( Typ ); + if ( I != tMap.end() ) + return I->second; + + return BAD_SLOT; + } + + // clear - completely clear the slot table of all entries + void SlotTable::clear() { + vTable.clear(); + vMap.clear(); + tPlane.clear(); + tMap.clear(); + } + + // resize - make sure there's enough room for specific number of planes + void SlotTable::resize( size_t new_size ) { + vTable.resize( new_size ); + } + + // insert - insert a Value into a specific plane + SlotTable::SlotNum SlotTable::insert( const Value* Val, PlaneNum plane ) { + if ( vTable.size() <= plane ) // Make sure we have the type plane allocated + vTable.resize(plane+1, ValuePlane()); + + // Insert node into table and map + SlotNum DestSlot = vMap[Val] = vTable[plane].size(); + vTable[plane].push_back(Val); + return DestSlot; + } + + // insert - insert a type into a specific plane + SlotTable::SlotNum SlotTable::insert( const Type* Typ ) { + // Insert node into table and map + SlotNum DestSlot = tMap[Typ] = tPlane.size(); + tPlane.push_back(Typ); + return DestSlot; + } + + // remove - remove a value from the slot table + SlotTable::SlotNum SlotTable::remove( const Value* Val, PlaneNum plane ) { + // FIXME: not implemented - not sure we need it + return BAD_SLOT; + } + + // remove - remove a type from the slot table + SlotTable::SlotNum SlotTable::remove( const Type* Typ ) { + // FIXME: not implemented - not sure we need it + return BAD_SLOT; + } + + // insertPrimitives - insert the primitive types for initialization + // Make sure that all of the primitive types are in the table + // and that their Primitive ID is equal to their slot # + void SlotTable::insertPrimitives() { + for (PlaneNum plane = 0; plane < Type::FirstDerivedTyID; ++plane) { + const Type* Ty = Type::getPrimitiveType((Type::PrimitiveID) plane); + assert(Ty && "Couldn't get primitive type id"); + SlotNum slot = this->insert(Ty); + assert(slot == plane && "Type slot didn't match plane number"); + } + } + + // vim: sw=2 From llvm at cs.uiuc.edu Tue May 25 13:48:08 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 13:48:08 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Internal/SlotTable.h Message-ID: <200405251845.NAA31896@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Internal: SlotTable.h added (r1.1) --- Log message: Adding the initial implementation of the SlotTable class. This class is the Abstract Data Type that holds slot number values and associates them with Type* and Value*. The SlotTable is simply the holder of the slot numbers and provides a controlled interface for building the table. It does not enforce any particular idiom or functionality for manipulating the slot numbers. This is part of bug_122. The SlotCalculator and SlotMachine classes will follow. --- Diffs of the changes: (+194 -0) Index: llvm/include/llvm/Internal/SlotTable.h diff -c /dev/null llvm/include/llvm/Internal/SlotTable.h:1.1 *** /dev/null Tue May 25 13:45:01 2004 --- llvm/include/llvm/Internal/SlotTable.h Tue May 25 13:44:51 2004 *************** *** 0 **** --- 1,194 ---- + //===-- Internal/SlotTable.h - Type/Value Slot Holder -----------*- C++ -*-===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by Reid Spencer and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This file declares the SlotTable class for type plane numbering. + // + //===----------------------------------------------------------------------===// + + #ifndef LLVM_INTERNAL_SLOTTABLE_H + #define LLVM_INTERNAL_SLOTTABLE_H + + #include + #include + + namespace llvm { + + // Forward declarations + class Value; + class Type; + class Module; + class Function; + class SymbolTable; + class ConstantArray; + + /// This class is the common abstract data type for both the SlotMachine and + /// the SlotCalculator. It provides the two-way mapping between Values and + /// Slots as well as the two-way mapping between Types and Slots. For Values, + /// the slot number can be extracted by simply using the getSlot() + /// method and passing in the Value. For Types, it is the same. + /// @brief Abstract data type for slot numbers. + class SlotTable + { + /// @name Types + /// @{ + public: + + /// This type is used throughout the code to make it clear that + /// an unsigned value refers to a Slot number and not something else. + /// @brief Type slot number identification type. + typedef unsigned SlotNum; + + /// This type is used throughout the code to make it clear that an + /// unsigned value refers to a type plane number and not something else. + /// @brief The type of a plane number (corresponds to Type::PrimitiveID). + typedef unsigned PlaneNum; + + /// @brief Some constants used as flags instead of actual slot numbers + enum Constants { + MAX_SLOT = 4294967294U, + BAD_SLOT = 4294967295U + }; + + /// @brief A single plane of Values. Intended index is slot number. + typedef std::vector ValuePlane; + + /// @brief A table of Values. Intended index is Type::PrimitiveID. + typedef std::vector ValueTable; + + /// @brief A map of values to slot numbers. + typedef std::map ValueMap; + + /// @brief A single plane of Types. Intended index is slot number. + typedef std::vector TypePlane; + + /// @brief A map of types to slot numbers. + typedef std::map TypeMap; + + /// @} + /// @name Constructors + /// @{ + public: + /// This constructor initializes all the containers in the SlotTable + /// to empty and then inserts all the primitive types into the type plane + /// by default. This is done as a convenience since most uses of the + /// SlotTable will need the primitive types. If you don't need them, pass + /// in true. + /// @brief Default Constructor + SlotTable( + bool dont_insert_primitives = false ///< Control insertion of primitives. + ); + + /// @} + /// @name Accessors + /// @{ + public: + /// @brief Get the number of planes of values. + size_t value_size() const { return vTable.size(); } + + /// @brief Get the number of types. + size_t type_size() const { return tPlane.size(); } + + /// @brief Determine if a specific type plane in the value table exists + bool plane_exists(PlaneNum plane) const { + return vTable.size() > plane; + } + + /// @brief Determine if a specific type plane in the value table is empty + bool plane_empty(PlaneNum plane) const { + return (plane_exists(plane) ? vTable[plane].empty() : true); + } + + /// @brief Get the number of entries in a specific plane of the value table + size_t plane_size(PlaneNum plane) const { + return (plane_exists(plane) ? vTable[plane].size() : 0 ); + } + + /// @returns true if the slot table is completely empty. + /// @brief Determine if the SlotTable is empty. + bool empty() const; + + /// @returns the slot number or BAD_SLOT if Val is not in table. + /// @brief Get a slot number for a Value. + SlotNum getSlot(const Value* Val) const; + + /// @returns the slot number or BAD_SLOT if Type is not in the table. + /// @brief Get a slot number for a Type. + SlotNum getSlot(const Type* Typ) const; + + /// @returns true iff the Value is in the table. + /// @brief Determine if a Value has a slot number. + bool hasSlot(const Value* Val) { return getSlot(Val) != BAD_SLOT; } + + /// @returns true iff the Type is in the table. + /// @brief Determine if a Type has a slot number. + bool hasSlot(const Type* Typ) { return getSlot(Typ) != BAD_SLOT; } + + /// @} + /// @name Mutators + /// @{ + public: + /// @brief Completely clear the SlotTable; + void clear(); + + /// @brief Resize the table to incorporate at least \p new_size planes + void resize( size_t new_size ); + + /// @returns the slot number of the newly inserted value in its plane + /// @brief Add a Value to the SlotTable + SlotNum insert(const Value* Val, PlaneNum plane ); + + /// @returns the slot number of the newly inserted type + /// @brief Add a Type to the SlotTable + SlotNum insert( const Type* Typ ); + + /// @returns the slot number that \p Val had when it was in the table + /// @brief Remove a Value from the SlotTable + SlotNum remove( const Value* Val, PlaneNum plane ); + + /// @returns the slot number that \p Typ had when it was in the table + /// @brief Remove a Type from the SlotTable + SlotNum remove( const Type* Typ ); + + /// @} + /// @name Implementation Details + /// @{ + private: + /// Insert the primitive types into the type plane. This is called + /// by the constructor to initialize the type plane. + void insertPrimitives(); + + /// @} + /// @name Data + /// @{ + private: + /// A two dimensional table of Values indexed by type and slot number. This + /// allows for efficient lookup of a Value by its type and slot number. + ValueTable vTable; + + /// A map of Values to unsigned integer. This allows for efficient lookup of + /// A Value's slot number in its type plane. + ValueMap vMap; + + /// A one dimensional vector of Types indexed by slot number. Types are + /// handled separately because they are not Values. + TypePlane tPlane; + + /// A map of Types to unsigned integer. This allows for efficient lookup of + /// a Type's slot number in the type plane. + TypeMap tMap; + + /// @} + + }; + + } // End llvm namespace + + // vim: sw=2 + + #endif From alkis at cs.uiuc.edu Tue May 25 14:01:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 14:01:02 2004 Subject: [llvm-commits] CVS: llvm-java/test/Compiler/ Message-ID: <200405251858.NAA32024@zion.cs.uiuc.edu> Changes in directory llvm-java/test/Compiler: --- Log message: Directory /home/vadve/shared/PublicCVS/llvm-java/test/Compiler added to the repository --- Diffs of the changes: (+0 -0) From llvm at cs.uiuc.edu Tue May 25 14:06:04 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 14:06:04 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/SlotTable.cpp Message-ID: <200405251903.OAA32068@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: SlotTable.cpp updated: 1.1 -> 1.2 --- Log message: Make some improvements suggested by Chris. --- Diffs of the changes: (+9 -8) Index: llvm/lib/Support/SlotTable.cpp diff -u llvm/lib/Support/SlotTable.cpp:1.1 llvm/lib/Support/SlotTable.cpp:1.2 --- llvm/lib/Support/SlotTable.cpp:1.1 Tue May 25 13:44:51 2004 +++ llvm/lib/Support/SlotTable.cpp Tue May 25 14:03:21 2004 @@ -1,4 +1,4 @@ -//===-- SlotCalculator.cpp - Calculate what slots values land in ----------===// +//===-- SlotTable.cpp - Abstract data type for slot numbers ---------------===// // // The LLVM Compiler Infrastructure // @@ -7,16 +7,15 @@ // //===----------------------------------------------------------------------===// // -// This file implements a utility class for keeping track of slot numbers for -// bytecode and assembly writing. +// This file implements an abstract data type for keeping track of slot numbers +// for bytecode and assembly writing or any other purpose. // //===----------------------------------------------------------------------===// -#include "llvm/Internal/SlotTable.h" +#include "llvm/Constants.h" #include "llvm/Type.h" -#include "llvm/Value.h" #include "llvm/GlobalValue.h" -#include "llvm/Constants.h" +#include "llvm/Internal/SlotTable.h" using namespace llvm; @@ -80,9 +79,11 @@ return DestSlot; } -// insert - insert a type into a specific plane +// insert - insert a type SlotTable::SlotNum SlotTable::insert( const Type* Typ ) { - // Insert node into table and map + // Insert node into table and map making sure that + // the same type isn't inserted twice. + assert(tMap.find(Typ) == tMap.end() && "Can't insert a Type multiple times"); SlotNum DestSlot = tMap[Typ] = tPlane.size(); tPlane.push_back(Typ); return DestSlot; From llvm at cs.uiuc.edu Tue May 25 14:12:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 14:12:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Internal/SlotTable.h Message-ID: <200405251909.OAA32110@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Internal: SlotTable.h updated: 1.1 -> 1.2 --- Log message: Make the constructor explicit so we can't implicitly convert bool to SlotTable. --- Diffs of the changes: (+1 -1) Index: llvm/include/llvm/Internal/SlotTable.h diff -u llvm/include/llvm/Internal/SlotTable.h:1.1 llvm/include/llvm/Internal/SlotTable.h:1.2 --- llvm/include/llvm/Internal/SlotTable.h:1.1 Tue May 25 13:44:51 2004 +++ llvm/include/llvm/Internal/SlotTable.h Tue May 25 14:09:25 2004 @@ -80,7 +80,7 @@ /// SlotTable will need the primitive types. If you don't need them, pass /// in true. /// @brief Default Constructor - SlotTable( + explicit SlotTable( bool dont_insert_primitives = false ///< Control insertion of primitives. ); From alkis at cs.uiuc.edu Tue May 25 14:41:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 14:41:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405251938.OAA32263@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.23 -> 1.24 --- Log message: Create default branch entry last in a switch statement. --- Diffs of the changes: (+3 -3) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.23 llvm-java/lib/Compiler/Compiler.cpp:1.24 --- llvm-java/lib/Compiler/Compiler.cpp:1.23 Tue May 25 13:35:06 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 14:38:05 2004 @@ -93,15 +93,15 @@ void do_switch(unsigned bcI, unsigned defTarget, const SwitchCases& sw) { - if (!bc2bbMap_[defTarget]) - bc2bbMap_[defTarget] = - new BasicBlock("bb at bc" + utostr(defTarget), &function_); for (unsigned i = 0; i < sw.size(); ++i) { unsigned target = sw[i].second; if (!bc2bbMap_[target]) bc2bbMap_[target] = new BasicBlock("bb at bc" + utostr(target), &function_); } + if (!bc2bbMap_[defTarget]) + bc2bbMap_[defTarget] = + new BasicBlock("bb at bc" + utostr(defTarget), &function_); } private: From alkis at cs.uiuc.edu Tue May 25 14:42:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 14:42:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405251939.OAA32309@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.24 -> 1.25 --- Log message: Fix some serious type bugs when creating and initializing locals variables. --- Diffs of the changes: (+2 -2) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.24 llvm-java/lib/Compiler/Compiler.cpp:1.25 --- llvm-java/lib/Compiler/Compiler.cpp:1.24 Tue May 25 14:38:05 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 14:39:29 2004 @@ -117,7 +117,7 @@ switch (type) { // FIXME: this should really be a non-void type when the object // model is finalized - case REFERENCE: return Type::VoidTy; + case REFERENCE: return PointerType::get(Type::VoidTy); case BOOLEAN: return Type::BoolTy; case CHAR: return Type::UByteTy; case FLOAT: return Type::FloatTy; @@ -165,7 +165,7 @@ new AllocaInst(type, NULL, "local" + utostr(index)); locals_[index] = alloc; Instruction* store = new StoreInst( - llvm::Constant::getNullValue(alloc->getType()), alloc); + llvm::Constant::getNullValue(type), alloc); entry->getInstList().push_front(store); entry->getInstList().push_front(alloc); } From llvm at cs.uiuc.edu Tue May 25 15:04:02 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 15:04:02 2004 Subject: [llvm-commits] CVS: llvm/Makefile Message-ID: <200405252001.PAA32711@zion.cs.uiuc.edu> Changes in directory llvm: Makefile updated: 1.24 -> 1.25 --- Log message: Change the install-includes target to completely ignore the llvm/Internal directory. Headers located there are not public to LLVM but are shared between LLVM modules. --- Diffs of the changes: (+2 -2) Index: llvm/Makefile diff -u llvm/Makefile:1.24 llvm/Makefile:1.25 --- llvm/Makefile:1.24 Fri Apr 23 19:10:56 2004 +++ llvm/Makefile Tue May 25 15:01:25 2004 @@ -33,9 +33,9 @@ install-includes: $(MKDIR) $(DESTDIR)$(includedir)/llvm - cd include && find * '!' '(' -name '*~' -o -name .cvsignore ')' -print | grep -v CVS | pax -rwdvpe $(DESTDIR)$(includedir)/llvm + cd include && find * -path '*/Internal' -prune -o '(' '!' '(' -name '*~' -o -name .cvsignore ')' -print ')' | grep -v CVS | pax -rwdvpe $(DESTDIR)$(includedir)/llvm ifneq ($(BUILD_SRC_ROOT),$(BUILD_OBJ_ROOT)) - cd $(BUILD_SRC_ROOT)/include && find * '!' '(' -name '*~' -o -name .cvsignore ')' -print | grep -v CVS | pax -rwdvpe $(DESTDIR)$(includedir)/llvm + cd $(BUILD_SRC_ROOT)/include && find * -path '*/Internal' -prune -o '(' '!' '(' -name '*~' -o -name .cvsignore ')' -print ')' | grep -v CVS | pax -rwdvpe $(DESTDIR)$(includedir)/llvm endif install:: install-includes From alkis at cs.uiuc.edu Tue May 25 15:06:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 15:06:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405252003.PAA00573@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.25 -> 1.26 --- Log message: Change type of Object to sbyte* so that llvm-as can parse it. Also change basic block names to bc so that they can be parsed as well. --- Diffs of the changes: (+7 -7) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.25 llvm-java/lib/Compiler/Compiler.cpp:1.26 --- llvm-java/lib/Compiler/Compiler.cpp:1.25 Tue May 25 14:39:29 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 15:03:14 2004 @@ -74,20 +74,20 @@ unsigned t, unsigned f) { if (!bc2bbMap_[t]) bc2bbMap_[t] = - new BasicBlock("bb at bc" + utostr(t), &function_); + new BasicBlock("bc" + utostr(t), &function_); if (!bc2bbMap_[f]) bc2bbMap_[f] = - new BasicBlock("bb at bc" + utostr(f), &function_); + new BasicBlock("bc" + utostr(f), &function_); } void do_ifcmp(unsigned bcI, JSetCC cc, unsigned t, unsigned f) { if (!bc2bbMap_[t]) bc2bbMap_[t] = - new BasicBlock("bb at bc" + utostr(t), &function_); + new BasicBlock("bc" + utostr(t), &function_); if (!bc2bbMap_[f]) bc2bbMap_[f] = - new BasicBlock("bb at bc" + utostr(f), &function_); + new BasicBlock("bc" + utostr(f), &function_); } void do_switch(unsigned bcI, @@ -97,11 +97,11 @@ unsigned target = sw[i].second; if (!bc2bbMap_[target]) bc2bbMap_[target] = - new BasicBlock("bb at bc" + utostr(target), &function_); + new BasicBlock("bc" + utostr(target), &function_); } if (!bc2bbMap_[defTarget]) bc2bbMap_[defTarget] = - new BasicBlock("bb at bc" + utostr(defTarget), &function_); + new BasicBlock("bc" + utostr(defTarget), &function_); } private: @@ -117,7 +117,7 @@ switch (type) { // FIXME: this should really be a non-void type when the object // model is finalized - case REFERENCE: return PointerType::get(Type::VoidTy); + case REFERENCE: return PointerType::get(Type::SByteTy); case BOOLEAN: return Type::BoolTy; case CHAR: return Type::UByteTy; case FLOAT: return Type::FloatTy; From llvm at cs.uiuc.edu Tue May 25 15:12:05 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Tue May 25 15:12:05 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/SlotTable.cpp Message-ID: <200405252009.PAA00803@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: SlotTable.cpp updated: 1.2 -> 1.3 --- Log message: Put SlotTable.h inclusion back at front of list to be coding standards compliant. Thanks, Chris. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Support/SlotTable.cpp diff -u llvm/lib/Support/SlotTable.cpp:1.2 llvm/lib/Support/SlotTable.cpp:1.3 --- llvm/lib/Support/SlotTable.cpp:1.2 Tue May 25 14:03:21 2004 +++ llvm/lib/Support/SlotTable.cpp Tue May 25 15:09:05 2004 @@ -12,10 +12,10 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Internal/SlotTable.h" #include "llvm/Constants.h" #include "llvm/Type.h" #include "llvm/GlobalValue.h" -#include "llvm/Internal/SlotTable.h" using namespace llvm; From alkis at cs.uiuc.edu Tue May 25 15:26:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 15:26:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405252023.PAA00893@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.26 -> 1.27 --- Log message: Fix binary ops and conditional compilation. Values were reversed (v2 is at the top of the stack not v1). --- Diffs of the changes: (+6 -6) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.26 llvm-java/lib/Compiler/Compiler.cpp:1.27 --- llvm-java/lib/Compiler/Compiler.cpp:1.26 Tue May 25 15:03:14 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 15:23:17 2004 @@ -390,27 +390,27 @@ } void do_shl(unsigned bcI) { - Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); + Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = new ShiftInst(Instruction::Shl, v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } void do_shr(unsigned bcI) { - Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); + Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = new ShiftInst(Instruction::Shr, v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } void do_ushr(unsigned bcI) { + Value* v2 = opStack_.top(); opStack_.pop(); Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = new CastInst(v1, v1->getType()->getUnsignedVersion(), TMP); bc2bbMap_[bcI]->getInstList().push_back(in); - Value* v2 = opStack_.top(); opStack_.pop(); in = new ShiftInst(Instruction::Shr, in, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); @@ -429,8 +429,8 @@ } void do_binary_op_common(unsigned bcI, Instruction::BinaryOps op) { - Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); + Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = BinaryOperator::create(op, v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); @@ -462,8 +462,8 @@ void do_if(unsigned bcI, JSetCC cc, JType type, unsigned t, unsigned f) { - Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = llvm::Constant::getNullValue(getType(type)); + Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = new SetCondInst(getSetCC(cc), v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); new BranchInst(bc2bbMap_[t], @@ -474,8 +474,8 @@ void do_ifcmp(unsigned bcI, JSetCC cc, unsigned t, unsigned f) { - Value* v1 = opStack_.top(); opStack_.pop(); Value* v2 = opStack_.top(); opStack_.pop(); + Value* v1 = opStack_.top(); opStack_.pop(); Instruction* in = new SetCondInst(getSetCC(cc), v1, v2, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); new BranchInst(bc2bbMap_[t], From gaeke at cs.uiuc.edu Tue May 25 15:45:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Tue May 25 15:45:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/RegAlloc/AllocInfo.h Message-ID: <200405252043.PAA03738@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/RegAlloc: AllocInfo.h updated: 1.7 -> 1.8 --- Log message: Add a (not very meaningful) default constructor for AllocInfo objects. --- Diffs of the changes: (+8 -4) Index: llvm/lib/Target/SparcV9/RegAlloc/AllocInfo.h diff -u llvm/lib/Target/SparcV9/RegAlloc/AllocInfo.h:1.7 llvm/lib/Target/SparcV9/RegAlloc/AllocInfo.h:1.8 --- llvm/lib/Target/SparcV9/RegAlloc/AllocInfo.h:1.7 Mon Mar 8 17:22:01 2004 +++ llvm/lib/Target/SparcV9/RegAlloc/AllocInfo.h Tue May 25 15:43:47 2004 @@ -32,10 +32,14 @@ AllocStateTy AllocState; int Placement; - AllocInfo (unsigned Instruction_, unsigned Operand_, - AllocStateTy AllocState_, int Placement_) : - Instruction (Instruction_), Operand (Operand_), - AllocState (AllocState_), Placement (Placement_) { } + AllocInfo (int Inst_, int Op_, AllocStateTy State_, int Place_) : + Instruction(Inst_), Operand(Op_), AllocState(State_), Placement(Place_) { } + + /// AllocInfo constructor -- Default constructor creates an invalid AllocInfo + /// (presumably to be replaced with something meaningful later). + /// + AllocInfo () : + Instruction(-1), Operand(-1), AllocState(NotAllocated), Placement(-1) { } /// getConstantType - Return a StructType representing an AllocInfo object. /// From gaeke at cs.uiuc.edu Tue May 25 15:46:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Tue May 25 15:46:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405252043.PAA03745@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.71 -> 1.72 --- Log message: Be extra paranoid about saving live-in value registers on the stack. --- Diffs of the changes: (+8 -7) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.71 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.72 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.71 Mon May 24 16:01:25 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Tue May 25 15:43:48 2004 @@ -245,12 +245,13 @@ std::make_pair (V, getValueAllocState (TF, V)); AllocStates.insert (as); AllocInfo &Source = as.second.first, &Target = as.second.second; - if (Source != Target) - if (Source.AllocState == AllocInfo::Allocated) { - DEBUG (std::cerr << "rewriteProlog: Need to save incoming live value " - << "in reg " << Source.Placement << " onto the stack\n"); - RegsToSave.insert (Source.Placement); - } + assert (Source.AllocState == AllocInfo::Allocated && + Target.AllocState == AllocInfo::Allocated && + "Only handle live-in values in registers for now!"); + DEBUG (std::cerr << "rewriteProlog: Need to save incoming live value " + << "in reg " << Source.Placement << " onto the stack\n"); + RegsToSave.insert (Source.Placement); + RegsToSave.insert (Target.Placement); } // 3. Save used registers onto the stack. @@ -473,7 +474,7 @@ AllocInfo &Target = ai.first, &Source = ai.second; assert (Target.AllocState == AllocInfo::Allocated && Source.AllocState == AllocInfo::Allocated - && "FIXME: does not handle live values in stack slots yet"); + && "FIXME: does not handle live-out values in stack slots yet"); mvec.clear (); unsigned R = Source.Placement; unsigned RegType = TRI.getRegType (R); From alkis at cs.uiuc.edu Tue May 25 16:01:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 16:01:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405252058.PAA01616@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.27 -> 1.28 --- Log message: Share code for shift bytecodes and make the unsigned shift really work. --- Diffs of the changes: (+26 -14) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.27 llvm-java/lib/Compiler/Compiler.cpp:1.28 --- llvm-java/lib/Compiler/Compiler.cpp:1.27 Tue May 25 15:23:17 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 15:57:52 2004 @@ -390,28 +390,40 @@ } void do_shl(unsigned bcI) { - Value* v2 = opStack_.top(); opStack_.pop(); - Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = new ShiftInst(Instruction::Shl, v1, v2, TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - opStack_.push(in); + do_shift_common(bcI, Instruction::Shl); } void do_shr(unsigned bcI) { - Value* v2 = opStack_.top(); opStack_.pop(); - Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = new ShiftInst(Instruction::Shr, v1, v2, TMP); + do_shift_common(bcI, Instruction::Shr); + } + + void do_ushr(unsigned bcI) { + // cast value to be shifted into its unsigned version + do_swap(bcI); + Value* value = opStack_.top(); opStack_.pop(); + Instruction* in = new CastInst + (value, value->getType()->getUnsignedVersion(), TMP); + bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push(in); + do_swap(bcI); + + do_shift_common(bcI, Instruction::Shr); + + // cast shifted value back to its original signed version + value = opStack_.top(); opStack_.pop(); + in = new CastInst + (value, value->getType()->getSignedVersion(), TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } - void do_ushr(unsigned bcI) { - Value* v2 = opStack_.top(); opStack_.pop(); - Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = - new CastInst(v1, v1->getType()->getUnsignedVersion(), TMP); + void do_shift_common(unsigned bcI, Instruction::OtherOps op) { + Value* amount = opStack_.top(); opStack_.pop(); + Value* value = opStack_.top(); opStack_.pop(); + Instruction* in = new CastInst(amount, Type::UByteTy, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); - in = new ShiftInst(Instruction::Shr, in, v2, TMP); + amount = in; + in = new ShiftInst(op, value, amount, TMP); bc2bbMap_[bcI]->getInstList().push_back(in); opStack_.push(in); } From alkis at cs.uiuc.edu Tue May 25 16:02:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 16:02:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405252058.PAA01671@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.28 -> 1.29 --- Log message: Add a fixme. --- Diffs of the changes: (+1 -0) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.28 llvm-java/lib/Compiler/Compiler.cpp:1.29 --- llvm-java/lib/Compiler/Compiler.cpp:1.28 Tue May 25 15:57:52 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 15:58:45 2004 @@ -186,6 +186,7 @@ name += method.getDescriptor()->str(); // FIXME: use proper function type + // FIXME: emit with internal linkage if function is private Function* function = module.getOrInsertFunction(name, Type::VoidTy, 0); From alkis at cs.uiuc.edu Tue May 25 16:49:05 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 16:49:05 2004 Subject: [llvm-commits] CVS: llvm-java/test/Compiler/TableSwitch.java LookupSwitch.java If.java Arithm.java Message-ID: <200405252146.QAA07335@zion.cs.uiuc.edu> Changes in directory llvm-java/test/Compiler: TableSwitch.java added (r1.1) LookupSwitch.java added (r1.1) If.java added (r1.1) Arithm.java added (r1.1) --- Log message: Add some compiler test cases. --- Diffs of the changes: (+50 -0) Index: llvm-java/test/Compiler/TableSwitch.java diff -c /dev/null llvm-java/test/Compiler/TableSwitch.java:1.1 *** /dev/null Tue May 25 16:46:28 2004 --- llvm-java/test/Compiler/TableSwitch.java Tue May 25 16:46:18 2004 *************** *** 0 **** --- 1,15 ---- + package edu.uiuc.cs.llvm; + + public class TableSwitch + { + public static int main(String[] args) { + switch (4) { + case 0: return 4; + case 1: return 3; + case 2: return 2; + case 3: return 1; + case 4: return 0; + default: return -1; + } + } + } Index: llvm-java/test/Compiler/LookupSwitch.java diff -c /dev/null llvm-java/test/Compiler/LookupSwitch.java:1.1 *** /dev/null Tue May 25 16:46:28 2004 --- llvm-java/test/Compiler/LookupSwitch.java Tue May 25 16:46:18 2004 *************** *** 0 **** --- 1,13 ---- + package edu.uiuc.cs.llvm; + + public class LookupSwitch + { + public static int main(String[] args) { + switch (128) { + case 0: return 255; + case 128: return 128; + case 255: return 0; + default: return -1; + } + } + } Index: llvm-java/test/Compiler/If.java diff -c /dev/null llvm-java/test/Compiler/If.java:1.1 *** /dev/null Tue May 25 16:46:28 2004 --- llvm-java/test/Compiler/If.java Tue May 25 16:46:18 2004 *************** *** 0 **** --- 1,11 ---- + package edu.uiuc.cs.llvm; + + public class If + { + public static int main(String[] args) { + int i = 0; + if (i == 0) + return 0; + return 1; + } + } Index: llvm-java/test/Compiler/Arithm.java diff -c /dev/null llvm-java/test/Compiler/Arithm.java:1.1 *** /dev/null Tue May 25 16:46:28 2004 --- llvm-java/test/Compiler/Arithm.java Tue May 25 16:46:18 2004 *************** *** 0 **** --- 1,11 ---- + package edu.uiuc.cs.llvm; + + public class Arithm + { + public static int main(String[] args) { + int one = 1; + int two = 2; + + return (one + two) - (two * two) + (two / one) + (two % one) + (two << one) - (two >> 1); // = 4 + } + } From alkis at cs.uiuc.edu Tue May 25 16:55:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 16:55:01 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/BytecodeParser.h Message-ID: <200405252152.QAA07373@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: BytecodeParser.h updated: 1.2 -> 1.3 --- Log message: Fix parsing problem in LOOKUPSWITCH. Evaluation order of function arguments is not specified in C/C++. In this case gcc was evaluating last to first so the case/offset pairs were reversed. --- Diffs of the changes: (+5 -4) Index: llvm-java/include/llvm/Java/BytecodeParser.h diff -u llvm-java/include/llvm/Java/BytecodeParser.h:1.2 llvm-java/include/llvm/Java/BytecodeParser.h:1.3 --- llvm-java/include/llvm/Java/BytecodeParser.h:1.2 Mon May 24 22:46:47 2004 +++ llvm-java/include/llvm/Java/BytecodeParser.h Tue May 25 16:52:26 2004 @@ -508,12 +508,13 @@ switchCases_.clear(); skipPadBytes(i); int def = readSInt(code, i); - unsigned pairCount = readUInt(code, i); + int pairCount = readSInt(code, i); switchCases_.reserve(pairCount); - while (pairCount--) + while (pairCount--) { + int value = readSInt(code, i); switchCases_.push_back( - std::make_pair(readSInt(code, i), - curBC + readSInt(code, i))); + std::make_pair(value, curBC + readSInt(code, i))); + } THIS->do_switch(curBC, curBC + def, switchCases_); break; } From alkis at cs.uiuc.edu Tue May 25 19:33:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 19:33:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405260030.TAA14128@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.29 -> 1.30 --- Log message: Move member variables to the top of the class definition. Use a separate block for local variable initialization and only add it to the function if it is non-empty. --- Diffs of the changes: (+20 -9) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.29 llvm-java/lib/Compiler/Compiler.cpp:1.30 --- llvm-java/lib/Compiler/Compiler.cpp:1.29 Tue May 25 15:58:45 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 19:29:59 2004 @@ -68,6 +68,8 @@ else bc2bbMap_[i] = bb; } + + assert(function_.getEntryBlock().getName() == "entry"); } void do_if(unsigned bcI, JSetCC cc, JType type, @@ -113,6 +115,12 @@ struct CompilerImpl : public BytecodeParser { private: + OperandStack opStack_; + Locals locals_; + BC2BBMap bc2bbMap_; + BasicBlock* prologue_; + + private: const Type* getType(JType type) { switch (type) { // FIXME: this should really be a non-void type when the object @@ -156,18 +164,19 @@ Bytecode2BasicBlockMapper mapper(function, bc2bbMap_, codeAttr); mapper.compute(); + + prologue_ = new BasicBlock("prologue"); } Value* getOrCreateLocal(unsigned index, const Type* type) { if (!locals_[index]) { - BasicBlock* entry = bc2bbMap_[0]; Instruction* alloc = new AllocaInst(type, NULL, "local" + utostr(index)); locals_[index] = alloc; Instruction* store = new StoreInst( llvm::Constant::getNullValue(type), alloc); - entry->getInstList().push_front(store); - entry->getInstList().push_front(alloc); + prologue_->getInstList().push_back(alloc); + prologue_->getInstList().push_back(store); } return locals_[index]; @@ -197,7 +206,14 @@ parse(codeAttr->getCode(), codeAttr->getCodeSize()); - assert(function->getEntryBlock().getName() == "entry"); + // if the prologue is not empty, make it the entry block + // of the function with entry as its only successor + if (prologue_->empty()) + delete prologue_; + else { + function->getBasicBlockList().push_front(prologue_); + new BranchInst(prologue_->getNext(), prologue_); + } } void do_aconst_null(unsigned bcI) { @@ -602,11 +618,6 @@ unsigned dims) { assert(0 && "not implemented"); } - - private: - OperandStack opStack_; - Locals locals_; - BC2BBMap bc2bbMap_; }; } } } // namespace llvm::Java:: From alkis at cs.uiuc.edu Tue May 25 19:56:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 19:56:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405260053.TAA14234@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.30 -> 1.31 --- Log message: The to increment amount in IINC is a sign extended byte. --- Diffs of the changes: (+1 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.30 llvm-java/lib/Compiler/Compiler.cpp:1.31 --- llvm-java/lib/Compiler/Compiler.cpp:1.30 Tue May 25 19:29:59 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 19:53:37 2004 @@ -466,7 +466,7 @@ } - void do_iinc(unsigned bcI, unsigned index, unsigned amount) { + void do_iinc(unsigned bcI, unsigned index, int amount) { assert(0 && "not implemented"); } From alkis at cs.uiuc.edu Tue May 25 19:57:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 19:57:02 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/BytecodeParser.h Message-ID: <200405260053.TAA14239@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: BytecodeParser.h updated: 1.3 -> 1.4 --- Log message: The to increment amount in IINC is a sign extended byte. --- Diffs of the changes: (+2 -2) Index: llvm-java/include/llvm/Java/BytecodeParser.h diff -u llvm-java/include/llvm/Java/BytecodeParser.h:1.3 llvm-java/include/llvm/Java/BytecodeParser.h:1.4 --- llvm-java/include/llvm/Java/BytecodeParser.h:1.3 Tue May 25 16:52:26 2004 +++ llvm-java/include/llvm/Java/BytecodeParser.h Tue May 25 19:53:37 2004 @@ -350,7 +350,7 @@ break; case IINC: THIS->do_iinc( - curBC, readUByte(code, i), readUByte(code, i)); + curBC, readUByte(code, i), readSByte(code, i)); break; case I2L: THIS->do_convert(curBC, LONG); @@ -688,7 +688,7 @@ /// @brief called on IXOR and LXOR void do_xor(unsigned bcI) { } /// @brief called on IINC - void do_iinc(unsigned bcI, unsigned index, unsigned amount) { } + void do_iinc(unsigned bcI, unsigned index, int amount) { } /// @brief called on I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, /// F2D, D2I, D2L, D2F, I2B, I2C, and I2S void do_convert(unsigned bcI, JType to) { } From alkis at cs.uiuc.edu Tue May 25 20:32:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 20:32:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405260129.UAA14414@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.31 -> 1.32 --- Log message: Implement the IINC bytecode. --- Diffs of the changes: (+10 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.31 llvm-java/lib/Compiler/Compiler.cpp:1.32 --- llvm-java/lib/Compiler/Compiler.cpp:1.31 Tue May 25 19:53:37 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Tue May 25 20:29:08 2004 @@ -467,7 +467,16 @@ void do_iinc(unsigned bcI, unsigned index, int amount) { - assert(0 && "not implemented"); + Instruction* in = + new LoadInst(getOrCreateLocal(index, Type::IntTy), TMP); + bc2bbMap_[bcI]->getInstList().push_back(in); + in = BinaryOperator::create(Instruction::Add, + in, + ConstantSInt::get(Type::IntTy, amount), + TMP); + bc2bbMap_[bcI]->getInstList().push_back(in); + in = new StoreInst(in, getOrCreateLocal(index, Type::IntTy)); + bc2bbMap_[bcI]->getInstList().push_back(in); } void do_convert(unsigned bcI, JType to) { From alkis at cs.uiuc.edu Tue May 25 20:32:09 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 25 20:32:09 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405260128.UAA14395@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h updated: 1.8 -> 1.9 --- Log message: Fix bug in reading sign extended bytes off the bytecode stream. --- Diffs of the changes: (+1 -1) Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.8 llvm-java/include/llvm/Java/Bytecode.h:1.9 --- llvm-java/include/llvm/Java/Bytecode.h:1.8 Mon May 24 22:46:15 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Tue May 25 20:28:49 2004 @@ -234,7 +234,7 @@ } // namespace Opcode inline int readSByte(const uint8_t* code, unsigned& i) { - return code[++i]; + return ((int8_t*)code)[++i]; } inline unsigned readUByte(const uint8_t* code, unsigned& i) { From tbrethou at cs.uiuc.edu Wed May 26 01:29:03 2004 From: tbrethou at cs.uiuc.edu (Tanya Brethour) Date: Wed May 26 01:29:03 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/ModuloScheduling/MSSchedule.cpp MSSchedule.h Message-ID: <200405260627.BAA14773@seraph.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/ModuloScheduling: MSSchedule.cpp added (r1.1) MSSchedule.h added (r1.1) --- Log message: Adding scheduling class. --- Diffs of the changes: (+246 -0) Index: llvm/lib/CodeGen/ModuloScheduling/MSSchedule.cpp diff -c /dev/null llvm/lib/CodeGen/ModuloScheduling/MSSchedule.cpp:1.1 *** /dev/null Wed May 26 01:27:46 2004 --- llvm/lib/CodeGen/ModuloScheduling/MSSchedule.cpp Wed May 26 01:27:36 2004 *************** *** 0 **** --- 1,183 ---- + //===-- MSSchedule.cpp Schedule ---------------------------------*- C++ -*-===// + // + // 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. + // + //===----------------------------------------------------------------------===// + // + // + // + //===----------------------------------------------------------------------===// + #define DEBUG_TYPE "ModuloSched" + + #include "MSSchedule.h" + #include "Support/Debug.h" + #include "llvm/Target/TargetSchedInfo.h" + #include + + using namespace llvm; + + bool MSSchedule::insert(MSchedGraphNode *node, int cycle) { + + //First, check if the cycle has a spot free to start + if(schedule.find(cycle) != schedule.end()) { + if (schedule[cycle].size() < numIssue) { + if(resourcesFree(node, cycle)) { + schedule[cycle].push_back(node); + DEBUG(std::cerr << "Found spot in map, and there is an issue slot\n"); + return false; + } + } + } + //Not in the map yet so put it in + else { + if(resourcesFree(node,cycle)) { + std::vector nodes; + nodes.push_back(node); + schedule[cycle] = nodes; + DEBUG(std::cerr << "Nothing in map yet so taking an issue slot\n"); + return false; + } + } + + DEBUG(std::cerr << "All issue slots taken\n"); + return true; + + } + + bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) { + + //Get Resource usage for this instruction + const TargetSchedInfo & msi = node->getParent()->getTarget()->getSchedInfo(); + int currentCycle = cycle; + bool success = true; + + //Get resource usage for this instruction + InstrRUsage rUsage = msi.getInstrRUsage(node->getInst()->getOpcode()); + std::vector > resources = rUsage.resourcesByCycle; + + //Loop over resources in each cycle and increments their usage count + for(unsigned i=0; i < resources.size(); ++i) { + for(unsigned j=0; j < resources[i].size(); ++j) { + int resourceNum = resources[i][j]; + + //Check if this resource is available for this cycle + std::map >::iterator resourcesForCycle = resourceNumPerCycle.find(currentCycle); + + //First check map of resources for this cycle + if(resourcesForCycle != resourceNumPerCycle.end()) { + //A map exists for this cycle, so lets check for the resource + std::map::iterator resourceUse = resourcesForCycle->second.find(resourceNum); + if(resourceUse != resourcesForCycle->second.end()) { + //Check if there are enough of this resource and if so, increase count and move on + if(resourceUse->second < CPUResource::getCPUResource(resourceNum)->maxNumUsers) + ++resourceUse->second; + else { + success = false; + } + } + //Not in the map yet, so put it + else + resourcesForCycle->second[resourceNum] = 1; + + } + else { + //Create a new map and put in our resource + std::map resourceMap; + resourceMap[resourceNum] = 1; + resourceNumPerCycle[cycle] = resourceMap; + } + if(!success) + break; + } + if(!success) + break; + //Increase cycle + currentCycle++; + } + + if(!success) { + int oldCycle = cycle; + DEBUG(std::cerr << "Backtrack\n"); + //Get resource usage for this instruction + InstrRUsage rUsage = msi.getInstrRUsage(node->getInst()->getOpcode()); + std::vector > resources = rUsage.resourcesByCycle; + + //Loop over resources in each cycle and increments their usage count + for(unsigned i=0; i < resources.size(); ++i) { + if(oldCycle < currentCycle) { + + //Check if this resource is available for this cycle + std::map >::iterator resourcesForCycle = resourceNumPerCycle.find(oldCycle); + + for(unsigned j=0; j < resources[i].size(); ++j) { + int resourceNum = resources[i][j]; + //remove from map + std::map::iterator resourceUse = resourcesForCycle->second.find(resourceNum); + //assert if not in the map.. since it should be! + //assert(resourceUse != resourcesForCycle.end() && "Resource should be in map!"); + --resourceUse->second; + } + } + else + break; + oldCycle++; + } + return false; + + } + + return true; + + } + + bool MSSchedule::constructKernel(int II) { + MSchedGraphNode *branchNode; + + int stageNum = (schedule.rbegin()->first)/ II; + DEBUG(std::cerr << "Number of Stages: " << stageNum << "\n"); + + for(int index = 0; index < II; ++index) { + int count = 0; + for(int i = index; i <= (schedule.rbegin()->first); i+=II) { + if(schedule.count(i)) { + for(std::vector::iterator I = schedule[i].begin(), + E = schedule[i].end(); I != E; ++I) { + //Check if its a branch + if((*I)->isBranch()) { + branchNode = *I; + assert(count == 0 && "Branch can not be from a previous iteration"); + } + else + //FIXME: Check if the instructions in the earlier stage conflict + kernel.push_back(std::make_pair(*I, count)); + } + } + ++count; + } + } + + //Add Branch to the end + kernel.push_back(std::make_pair(branchNode, 0)); + + return true; + } + + + void MSSchedule::print(std::ostream &os) const { + os << "Schedule:\n"; + + for(schedule_const_iterator I = schedule.begin(), E = schedule.end(); I != E; ++I) { + os << "Cycle: " << I->first << "\n"; + for(std::vector::const_iterator node = I->second.begin(), nodeEnd = I->second.end(); node != nodeEnd; ++node) + os << **node << "\n"; + } + + os << "Kernel:\n"; + for(std::vector >::const_iterator I = kernel.begin(), + E = kernel.end(); I != E; ++I) + os << "Node: " << *(I->first) << " Stage: " << I->second << "\n"; + } + Index: llvm/lib/CodeGen/ModuloScheduling/MSSchedule.h diff -c /dev/null llvm/lib/CodeGen/ModuloScheduling/MSSchedule.h:1.1 *** /dev/null Wed May 26 01:27:46 2004 --- llvm/lib/CodeGen/ModuloScheduling/MSSchedule.h Wed May 26 01:27:36 2004 *************** *** 0 **** --- 1,63 ---- + //===-- MSSchedule.h - Schedule ------- -------------------------*- C++ -*-===// + // + // 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. + // + //===----------------------------------------------------------------------===// + // + // The schedule generated by a scheduling algorithm + // + //===----------------------------------------------------------------------===// + + #ifndef LLVM_MSSCHEDULE_H + #define LLVM_MSSCHEDULE_H + + #include "MSchedGraph.h" + #include + + namespace llvm { + + class MSSchedule { + std::map > schedule; + unsigned numIssue; + + //Internal map to keep track of explicit resources + std::map > resourceNumPerCycle; + + //Check if all resources are free + bool resourcesFree(MSchedGraphNode*, int); + + //Resulting kernel + std::vector > kernel; + + public: + MSSchedule(int num) : numIssue(num) {} + MSSchedule() : numIssue(4) {} + bool insert(MSchedGraphNode *node, int cycle); + int getStartCycle(MSchedGraphNode *node); + void clear() { schedule.clear(); resourceNumPerCycle.clear(); kernel.clear(); } + std::vector >* getKernel() { return &kernel; } + bool constructKernel(int II); + + + + //iterators + typedef std::map >::iterator schedule_iterator; + typedef std::map >::const_iterator schedule_const_iterator; + schedule_iterator begin() { return schedule.begin(); }; + schedule_iterator end() { return schedule.end(); }; + void print(std::ostream &os) const; + + typedef std::vector >::iterator kernel_iterator; + typedef std::vector >::const_iterator kernel_const_iterator; + kernel_iterator kernel_begin() { return kernel.begin(); } + kernel_iterator kernel_end() { return kernel.end(); } + + }; + + } + + + #endif From tbrethou at cs.uiuc.edu Wed May 26 01:29:13 2004 From: tbrethou at cs.uiuc.edu (Tanya Brethour) Date: Wed May 26 01:29:13 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp MSchedGraph.h ModuloScheduling.cpp ModuloScheduling.h Message-ID: <200405260627.BAA14757@seraph.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/ModuloScheduling: MSchedGraph.cpp updated: 1.2 -> 1.3 MSchedGraph.h updated: 1.2 -> 1.3 ModuloScheduling.cpp updated: 1.17 -> 1.18 ModuloScheduling.h updated: 1.12 -> 1.13 --- Log message: Updating my cvs versions. THis is still in progress and much will be changed. --- Diffs of the changes: (+299 -157) Index: llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp diff -u llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp:1.2 llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp:1.3 --- llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp:1.2 Sat May 8 11:12:10 2004 +++ llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp Wed May 26 01:27:18 2004 @@ -1,4 +1,4 @@ -//===-- MSchedGraph.h - Scheduling Graph ------------------------*- C++ -*-===// +//===-- MSchedGraph.cpp - Scheduling Graph ------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -13,6 +13,7 @@ #define DEBUG_TYPE "ModuloSched" #include "MSchedGraph.h" +#include "../../Target/SparcV9/SparcV9RegisterInfo.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/Target/TargetInstrInfo.h" #include "Support/Debug.h" @@ -21,8 +22,8 @@ MSchedGraphNode::MSchedGraphNode(const MachineInstr* inst, MSchedGraph *graph, - unsigned late) - : Inst(inst), Parent(graph), latency(late) { + unsigned late, bool isBranch) + : Inst(inst), Parent(graph), latency(late), isBranchInstr(isBranch) { //Add to the graph graph->addNode(inst, this); @@ -118,7 +119,7 @@ //using the op code, create a new node for it, and add to the //graph. - MachineOpCode MIopCode = MI->getOpcode(); + MachineOpCode opCode = MI->getOpcode(); int delay; #if 0 // FIXME: LOOK INTO THIS @@ -128,26 +129,30 @@ delay = MTI.minLatency(MIopCode); else #endif - /// FIxME: get this from the sched class. - delay = 7; //MTI.maxLatency(MIopCode); + //Get delay + delay = MTI.maxLatency(opCode); //Create new node for this machine instruction and add to the graph. //Create only if not a nop - if(MTI.isNop(MIopCode)) + if(MTI.isNop(opCode)) continue; //Add PHI to phi instruction list to be processed later - if (MIopCode == TargetInstrInfo::PHI) + if (opCode == TargetInstrInfo::PHI) phiInstrs.push_back(MI); + bool isBranch = false; + + //We want to flag the branch node to treat it special + if(MTI.isBranch(opCode)) + isBranch = true; + //Node is created and added to the graph automatically - MSchedGraphNode *node = new MSchedGraphNode(MI, this, delay); + MSchedGraphNode *node = new MSchedGraphNode(MI, this, delay, isBranch); DEBUG(std::cerr << "Created Node: " << *node << "\n"); - - //Check OpCode to keep track of memory operations to add memory dependencies later. - MachineOpCode opCode = MI->getOpcode(); + //Check OpCode to keep track of memory operations to add memory dependencies later. if(MTI.isLoad(opCode) || MTI.isStore(opCode)) memInstructions.push_back(node); @@ -158,14 +163,14 @@ //Get Operand const MachineOperand &mOp = MI->getOperand(i); - //Check if it has an allocated register (Note: this means it - //is greater then zero because zero is a special register for - //Sparc that holds the constant zero + //Check if it has an allocated register if(mOp.hasAllocatedReg()) { int regNum = mOp.getReg(); - + + if(regNum != SparcV9::g0) { //Put into our map regNumtoNodeMap[regNum].push_back(std::make_pair(i, node)); + } continue; } @@ -179,7 +184,7 @@ assert((mOp.getVRegValue() != NULL) && "Null value is defined"); //Check if this is a read operation in a phi node, if so DO NOT PROCESS - if(mOp.isUse() && (MIopCode == TargetInstrInfo::PHI)) + if(mOp.isUse() && (opCode == TargetInstrInfo::PHI)) continue; @@ -334,24 +339,24 @@ //Src only uses the register (read) if(srcIsUse) srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister, - MSchedGraphEdge::AntiDep, 1); + MSchedGraphEdge::AntiDep, 1); else if(srcIsUseandDef) { srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister, - MSchedGraphEdge::AntiDep, 1); + MSchedGraphEdge::AntiDep, 1); srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister, - MSchedGraphEdge::OutputDep, 1); + MSchedGraphEdge::OutputDep, 1); } else srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister, - MSchedGraphEdge::OutputDep, 1); + MSchedGraphEdge::OutputDep, 1); } //Dest node is a read else { if(!srcIsUse || srcIsUseandDef) srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister, - MSchedGraphEdge::TrueDep,1 ); + MSchedGraphEdge::TrueDep,1 ); } Index: llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.h diff -u llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.h:1.2 llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.h:1.3 --- llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.h:1.2 Sat May 8 11:12:10 2004 +++ llvm/lib/CodeGen/ModuloScheduling/MSchedGraph.h Wed May 26 01:27:18 2004 @@ -58,13 +58,14 @@ const MachineInstr* Inst; //Machine Instruction MSchedGraph* Parent; //Graph this node belongs to unsigned latency; //Latency of Instruction - + bool isBranchInstr; //Is this node the branch instr or not + std::vector Predecessors; //Predecessor Nodes std::vector Successors; public: MSchedGraphNode(const MachineInstr *inst, MSchedGraph *graph, - unsigned late=0); + unsigned late=0, bool isBranch=false); //Iterators typedef std::vector::iterator pred_iterator; @@ -85,6 +86,7 @@ MSchedGraphNode> succ_iterator; succ_iterator succ_begin(); succ_iterator succ_end(); + void addOutEdge(MSchedGraphNode *destination, @@ -103,7 +105,7 @@ bool isSuccessor(MSchedGraphNode *); bool isPredecessor(MSchedGraphNode *); - + bool isBranch() { return isBranchInstr; } //Debug support void print(std::ostream &os) const; @@ -200,7 +202,7 @@ iterator begin() { return GraphMap.begin(); } reverse_iterator rbegin() { return GraphMap.rbegin(); } reverse_iterator rend() { return GraphMap.rend(); } - + const TargetMachine* getTarget() { return &Target; } }; Index: llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp diff -u llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp:1.17 llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp:1.18 --- llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp:1.17 Sat May 8 11:12:10 2004 +++ llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp Wed May 26 01:27:18 2004 @@ -135,7 +135,8 @@ II = std::max(RecMII, ResMII); - DEBUG(std::cerr << "II starts out as " << II << "\n"); + + DEBUG(std::cerr << "II starts out as " << II << " ( RecMII=" << RecMII << "and ResMII=" << ResMII << "\n"); //Calculate Node Properties calculateNodeAttributes(MSG, ResMII); @@ -165,20 +166,9 @@ //Finally schedule nodes computeSchedule(); - - //Dump out final schedule - //std::cerr << "FINALSCHEDULE\n"; - //Dump out current schedule - /*for(std::map > >::iterator J = schedule.begin(), - JE = schedule.end(); J != JE; ++J) { - std::cerr << "Cycle " << J->first << ":\n"; - for(std::vector >::iterator VI = J->second.begin(), VE = J->second.end(); VI != VE; ++VI) - std::cerr << "Resource ID: " << VI->first << " by node " << *(VI->second) << "\n"; - } - std::cerr << "END FINAL SCHEDULE\n"; - - DEBUG(std::cerr << "II ends up as " << II << "\n"); - */ + DEBUG(schedule.print(std::cerr)); + + reconstructLoop(BI); nodeToAttributesMap.clear(); @@ -265,11 +255,12 @@ //Find maximum usage count //Get max number of instructions that can be issued at once. (FIXME) - int issueSlots = 1; // msi.maxNumIssueTotal; + int issueSlots = msi.maxNumIssueTotal; for(std::map::iterator RB = resourceUsageCount.begin(), RE = resourceUsageCount.end(); RB != RE; ++RB) { + //Get the total number of the resources in our cpu - //int resourceNum = msi.getCPUResourceNum(RB->first); + int resourceNum = CPUResource::getCPUResource(RB->first)->maxNumUsers; //Get total usage count for this resources unsigned usageCount = RB->second; @@ -277,9 +268,9 @@ //Divide the usage count by either the max number we can issue or the number of //resources (whichever is its upper bound) double finalUsageCount; - //if( resourceNum <= issueSlots) - //finalUsageCount = ceil(1.0 * usageCount / resourceNum); - //else + if( resourceNum <= issueSlots) + finalUsageCount = ceil(1.0 * usageCount / resourceNum); + else finalUsageCount = ceil(1.0 * usageCount / issueSlots); @@ -363,7 +354,7 @@ return false; bool findEdge = edgesToIgnore.count(std::make_pair(srcNode, destNode->getInEdgeNum(srcNode))); - DEBUG(std::cerr << "Ignore Edge from " << *srcNode << " to " << *destNode << "? " << findEdge << "\n"); + return findEdge; } @@ -561,10 +552,23 @@ } if(!same) { - //if(srcBENode == 0 || destBENode == 0) { - srcBENode = recurrence.back(); - destBENode = recurrence.front(); - //} + srcBENode = recurrence.back(); + destBENode = recurrence.front(); + + //FIXME + if(destBENode->getInEdge(srcBENode).getIteDiff() == 0) { + //DEBUG(std::cerr << "NOT A BACKEDGE\n"); + //find actual backedge HACK HACK + for(unsigned i=0; i< recurrence.size()-1; ++i) { + if(recurrence[i+1]->getInEdge(recurrence[i]).getIteDiff() == 1) { + srcBENode = recurrence[i]; + destBENode = recurrence[i+1]; + break; + } + + } + + } DEBUG(std::cerr << "Back Edge to Remove: " << *srcBENode << " to " << *destBENode << "\n"); edgesToIgnore.insert(std::make_pair(srcBENode, destBENode->getInEdgeNum(srcBENode))); recurrenceList.insert(std::make_pair(II, recurrence)); @@ -996,42 +1000,47 @@ int LateStart = 99999; //Set to something higher then we would ever expect (FIXME) bool hasSucc = false; bool hasPred = false; - std::set seenNodes; - - for(std::map > > >::iterator J = schedule.begin(), - JE = schedule.end(); J != JE; ++J) { - - //For each resource with nodes scheduled, loop over the nodes and see if they - //are a predecessor or successor of this current node we are trying - //to schedule. - for(std::vector > >::iterator schedNodeVec = J->second.begin(), SNE = J->second.end(); schedNodeVec != SNE; ++schedNodeVec) { + + if(!(*I)->isBranch()) { + //Loop over nodes in the schedule and determine if they are predecessors + //or successors of the node we are trying to schedule + for(MSSchedule::schedule_iterator nodesByCycle = schedule.begin(), nodesByCycleEnd = schedule.end(); + nodesByCycle != nodesByCycleEnd; ++nodesByCycle) { - for(std::vector::iterator schedNode = schedNodeVec->second.begin(), schedNodeEnd = schedNodeVec->second.end(); schedNode != schedNodeEnd; ++schedNode) { - if((*I)->isPredecessor(*schedNode) && !seenNodes.count(*schedNode)) { + //For this cycle, get the vector of nodes schedule and loop over it + for(std::vector::iterator schedNode = nodesByCycle->second.begin(), SNE = nodesByCycle->second.end(); schedNode != SNE; ++schedNode) { + + if((*I)->isPredecessor(*schedNode)) { if(!ignoreEdge(*schedNode, *I)) { int diff = (*I)->getInEdge(*schedNode).getIteDiff(); - int ES_Temp = J->first + (*schedNode)->getLatency() - diff * II; - DEBUG(std::cerr << "Diff: " << diff << " Cycle: " << J->first << "\n"); + int ES_Temp = nodesByCycle->first + (*schedNode)->getLatency() - diff * II; + DEBUG(std::cerr << "Diff: " << diff << " Cycle: " << nodesByCycle->first << "\n"); DEBUG(std::cerr << "Temp EarlyStart: " << ES_Temp << " Prev EarlyStart: " << EarlyStart << "\n"); EarlyStart = std::max(EarlyStart, ES_Temp); hasPred = true; } } - if((*I)->isSuccessor(*schedNode) && !seenNodes.count(*schedNode)) { + if((*I)->isSuccessor(*schedNode)) { if(!ignoreEdge(*I,*schedNode)) { int diff = (*schedNode)->getInEdge(*I).getIteDiff(); - int LS_Temp = J->first - (*I)->getLatency() + diff * II; - DEBUG(std::cerr << "Diff: " << diff << " Cycle: " << J->first << "\n"); + int LS_Temp = nodesByCycle->first - (*I)->getLatency() + diff * II; + DEBUG(std::cerr << "Diff: " << diff << " Cycle: " << nodesByCycle->first << "\n"); DEBUG(std::cerr << "Temp LateStart: " << LS_Temp << " Prev LateStart: " << LateStart << "\n"); LateStart = std::min(LateStart, LS_Temp); hasSucc = true; } } - seenNodes.insert(*schedNode); } } } - seenNodes.clear(); + else { + //WARNING: HACK! FIXME!!!! + EarlyStart = II-1; + LateStart = II-1; + hasPred = 1; + hasSucc = 1; + } + DEBUG(std::cerr << "Has Successors: " << hasSucc << ", Has Pred: " << hasPred << "\n"); DEBUG(std::cerr << "EarlyStart: " << EarlyStart << ", LateStart: " << LateStart << "\n"); @@ -1058,6 +1067,13 @@ } } + + DEBUG(std::cerr << "Constructing Kernel\n"); + success = schedule.constructKernel(II); + if(!success) { + ++II; + schedule.clear(); + } } } @@ -1068,17 +1084,6 @@ DEBUG(std::cerr << *node << " (Start Cycle: " << start << ", End Cycle: " << end << ")\n"); - /*std::cerr << "CURRENT SCHEDULE\n"; - //Dump out current schedule - for(std::map > >::iterator J = schedule.begin(), - JE = schedule.end(); J != JE; ++J) { - std::cerr << "Cycle " << J->first << ":\n"; - for(std::vector >::iterator VI = J->second.begin(), VE = J->second.end(); VI != VE; ++VI) - std::cerr << "Resource ID: " << VI->first << " by node " << *(VI->second) << "\n"; - } - std::cerr << "END CURRENT SCHEDULE\n"; - */ - //Make sure start and end are not negative if(start < 0) start = 0; @@ -1089,10 +1094,7 @@ if(start > end) forward = false; - const TargetSchedInfo & msi = target.getSchedInfo(); - bool increaseSC = true; - int cycle = start ; @@ -1100,79 +1102,8 @@ increaseSC = false; - //Get the resource used by this instruction - //Get resource usage for this instruction - InstrRUsage rUsage = msi.getInstrRUsage(node->getInst()->getOpcode()); - std::vector > resources = rUsage.resourcesByCycle; - - //Loop over each resource and see if we can put it into the schedule - for(unsigned r=0; r < resources.size(); ++r) { - unsigned intermediateCycle = cycle + r; - - for(unsigned j=0; j < resources[r].size(); ++j) { - //Put it into the schedule - DEBUG(std::cerr << "Attempting to put resource " << resources[r][j] << " in schedule at cycle: " << intermediateCycle << "\n"); - - //Check if resource is free at this cycle - std::vector > > resourceForCycle = schedule[intermediateCycle]; - - //Vector of nodes using this resource - std::vector *nodesUsingResource; - - for(std::vector > >::iterator I = resourceForCycle.begin(), E= resourceForCycle.end(); I != E; ++I) { - - if(I->first == resources[r][j]) { - //Get the number of available for this resource - unsigned numResource = CPUResource::getCPUResource(resources[r][j])->maxNumUsers; - nodesUsingResource = &(I->second); - - //Check that there are enough of this resource, otherwise - //we need to increase/decrease the cycle - if(I->second.size() >= numResource) { - DEBUG(std::cerr << "No open spot for this resource in this cycle\n"); - increaseSC = true; - } - break; - - } - //safe to put into schedule - } - - if(increaseSC) - break; - - else { - DEBUG(std::cerr << "Found spot in schedule\n"); - //Add node to resource vector - if(nodesUsingResource == 0) { - nodesUsingResource = new std::vector; - resourceForCycle.push_back(std::make_pair(resources[r][j], *nodesUsingResource)); - } - - nodesUsingResource->push_back(node); - - schedule[intermediateCycle] = resourceForCycle; - } - } - if(increaseSC) { - /*for(unsigned x = 0; x < r; ++x) { - unsigned removeCycle = x + start; - for(unsigned j=0; j < resources[x].size(); ++j) { - std::vector > resourceForCycle = schedule[removeCycle]; - for(std::vector >::iterator I = resourceForCycle.begin(), E= resourceForCycle.end(); I != E; ++I) { - if(I->first == resources[x][j]) { - //remove it - resourceForCycle.erase(I); - } - } - //Put vector back - schedule[removeCycle] = resourceForCycle; - } - }*/ - - break; - } - } + increaseSC = schedule.insert(node, cycle); + if(!increaseSC) return true; @@ -1190,5 +1121,202 @@ return false; } } + return success; } + +/*void ModuloSchedulingPass::saveValue(const MachineInstr *inst, std::set &valuestoSave, std::vector *valuesForNode) { + int numFound = 0; + Instruction *tmp; + + //For each value* in this inst that is a def, we want to save a copy + //Target info + const TargetInstrInfo & mii = target.getInstrInfo(); + for(unsigned i=0; i < inst->getNumOperands(); ++i) { + //get machine operand + const MachineOperand &mOp = inst->getOperand(i); + if(mOp.getType() == MachineOperand::MO_VirtualRegister && mOp.isDef()) { + //Save copy in tmpInstruction + numFound++; + tmp = TmpInstruction(mii.getMachineCodeFor(mOp.getVRegValue()), + mOp.getVRegValue()); + valuesForNode->push_back(tmp); + } + } + + assert(numFound == 1 && "We should have only found one def to this virtual register!"); +}*/ + +void ModuloSchedulingPass::writePrologue(std::vector &prologues, MachineBasicBlock *origBB, std::vector &llvm_prologues) { + std::map > inKernel; + int maxStageCount = 0; + + for(MSSchedule::kernel_iterator I = schedule.kernel_begin(), E = schedule.kernel_end(); I != E; ++I) { + maxStageCount = std::max(maxStageCount, I->second); + + //Ignore the branch, we will handle this separately + if(I->first->isBranch()) + continue; + + //Put int the map so we know what instructions in each stage are in the kernel + if(I->second > 0) + inKernel[I->second].insert(I->first->getInst()); + } + + //Now write the prologues + for(std::map >::iterator I = inKernel.begin(), E = inKernel.end(); + I != E; ++I) { + BasicBlock *llvmBB = new BasicBlock(); + MachineBasicBlock *machineBB = new MachineBasicBlock(llvmBB); + + //Loop over original machine basic block. If we see an instruction from this + //stage that is NOT in the kernel, then it needs to be added into the prologue + //We go in order to preserve dependencies + for(MachineBasicBlock::const_iterator MI = origBB->begin(), ME = origBB->end(); ME != MI; ++MI) { + if(I->second.count(&*MI)) + continue; + else + machineBB->push_back(MI->clone()); + } + + prologues.push_back(machineBB); + llvm_prologues.push_back(llvmBB); + } +} + + +void ModuloSchedulingPass::reconstructLoop(const MachineBasicBlock *BB) { + + //The new loop will consist of an prologue, the kernel, and one or more epilogues. + + std::vector prologues; + std::vector llvm_prologues; + + + + //create a vector of epilogues corresponding to each stage + /*std::vector epilogues; + + //Create kernel + MachineBasicBlock *kernel = new MachineBasicBlock(); + + //keep track of stage count + int stageCount = 0; + + //Target info + const TargetInstrInfo & mii = target.getInstrInfo(); + + //Map for creating MachinePhis + std::map > nodeAndValueMap; + + + //Loop through the kernel and clone instructions that need to be put into the prologue + for(MSSchedule::kernel_iterator I = schedule.kernel_begin(), E = schedule.kernel_end(); I != E; ++I) { + //For each pair see if the stage is greater then 0 + //if so, then ALL instructions before this in the original loop, need to be + //copied into the prologue + MachineBasicBlock::const_iterator actualInst; + + + //ignore branch + if(I->first->isBranch()) + continue; + + if(I->second > 0) { + + assert(I->second >= stageCount && "Visiting instruction from previous stage count.\n"); + + + //Make a set that has all the Value*'s that we read + std::set valuesToSave; + + //For this instruction, get the Value*'s that it reads and put them into the set. + //Assert if there is an operand of another type that we need to save + const MachineInstr *inst = I->first->getInst(); + for(unsigned i=0; i < inst->getNumOperands(); ++i) { + //get machine operand + const MachineOperand &mOp = inst->getOperand(i); + + if(mOp.getType() == MachineOperand::MO_VirtualRegister && mOp.isUse()) { + //find the value in the map + if (const Value* srcI = mOp.getVRegValue()) + valuesToSave.insert(srcI); + } + + if(mOp.getType() != MachineOperand::MO_VirtualRegister && mOp.isUse()) { + assert("Our assumption is wrong. We have another type of register that needs to be saved\n"); + } + } + + //Check if we skipped a stage count, we need to add that stuff here + if(I->second - stageCount > 1) { + int temp = stageCount; + while(I->second - temp > 1) { + for(MachineBasicBlock::const_iterator MI = BB->begin(), ME = BB->end(); ME != MI; ++MI) { + //Check that MI is not a branch before adding, we add branches separately + if(!mii.isBranch(MI->getOpcode()) && !mii.isNop(MI->getOpcode())) { + prologue->push_back(MI->clone()); + saveValue(&*MI, valuesToSave); + } + } + ++temp; + } + } + + if(I->second == stageCount) + continue; + + stageCount = I->second; + DEBUG(std::cerr << "Found Instruction from Stage > 0\n"); + //Loop over instructions in original basic block and clone them. Add to the prologue + for (MachineBasicBlock::const_iterator MI = BB->begin(), e = BB->end(); MI != e; ++MI) { + if(&*MI == I->first->getInst()) { + actualInst = MI; + break; + } + else { + //Check that MI is not a branch before adding, we add branches separately + if(!mii.isBranch(MI->getOpcode()) && !mii.isNop(MI->getOpcode())) + prologue->push_back(MI->clone()); + } + } + + //Now add in all instructions from this one on to its corresponding epilogue + MachineBasicBlock *epi = new MachineBasicBlock(); + epilogues.push_back(epi); + + for(MachineBasicBlock::const_iterator MI = actualInst, ME = BB->end(); ME != MI; ++MI) { + //Check that MI is not a branch before adding, we add branches separately + if(!mii.isBranch(MI->getOpcode()) && !mii.isNop(MI->getOpcode())) + epi->push_back(MI->clone()); + } + } + } + + //Create kernel + for(MSSchedule::kernel_iterator I = schedule.kernel_begin(), + E = schedule.kernel_end(); I != E; ++I) { + kernel->push_back(I->first->getInst()->clone()); + + } + + //Debug stuff + ((MachineBasicBlock*)BB)->getParent()->getBasicBlockList().push_back(prologue); + std::cerr << "PROLOGUE:\n"; + prologue->print(std::cerr); + + ((MachineBasicBlock*)BB)->getParent()->getBasicBlockList().push_back(kernel); + std::cerr << "KERNEL: \n"; + kernel->print(std::cerr); + + for(std::vector::iterator MBB = epilogues.begin(), ME = epilogues.end(); + MBB != ME; ++MBB) { + std::cerr << "EPILOGUE:\n"; + ((MachineBasicBlock*)BB)->getParent()->getBasicBlockList().push_back(*MBB); + (*MBB)->print(std::cerr); + }*/ + + + +} + Index: llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.h diff -u llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.h:1.12 llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.h:1.13 --- llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.h:1.12 Sat May 8 11:12:10 2004 +++ llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.h Wed May 26 01:27:18 2004 @@ -14,6 +14,7 @@ #define LLVM_MODULOSCHEDULING_H #include "MSchedGraph.h" +#include "MSSchedule.h" #include "llvm/Function.h" #include "llvm/Pass.h" #include @@ -54,7 +55,7 @@ std::vector FinalNodeOrder; //Schedule table, key is the cycle number and the vector is resource, node pairs - std::map > > > schedule; + MSSchedule schedule; //Current initiation interval int II; @@ -87,6 +88,12 @@ void predIntersect(std::vector &CurrentSet, std::vector &IntersectResult); void succIntersect(std::vector &CurrentSet, std::vector &IntersectResult); + + void reconstructLoop(const MachineBasicBlock*); + + //void saveValue(const MachineInstr*, const std::set&, std::vector*); + + void writePrologue(std::vector &prologues, MachineBasicBlock *origBB, std::vector &llvm_prologues); public: ModuloSchedulingPass(TargetMachine &targ) : target(targ) {} From llvm at cs.uiuc.edu Wed May 26 02:22:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Wed May 26 02:22:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200405260719.CAA01417@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.130 -> 1.131 --- Log message: Part of bug 122: http://llvm.cs.uiuc.edu/PR122 . Removed dependency of AsmWriter on SlotCalculator by incorporating a significantly simpler "SlotMachine" into this file. The SlotMachine is tailored for use by only the AsmWriter whose requirements for slot numbers are vastly different than from the Bytecode/Writer. Code change passes all Feature and Regression tests. --- Diffs of the changes: (+426 -52) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.130 llvm/lib/VMCore/AsmWriter.cpp:1.131 --- llvm/lib/VMCore/AsmWriter.cpp:1.130 Tue May 25 13:14:38 2004 +++ llvm/lib/VMCore/AsmWriter.cpp Wed May 26 02:18:52 2004 @@ -27,7 +27,6 @@ #include "llvm/iOther.h" #include "llvm/Module.h" #include "llvm/SymbolTable.h" -#include "llvm/Analysis/SlotCalculator.h" #include "llvm/Assembly/Writer.h" #include "llvm/Support/CFG.h" #include "Support/StringExtras.h" @@ -35,6 +34,105 @@ #include using namespace llvm; +namespace { + +/// This class provides computation of slot numbers for LLVM Assembly writing. +/// @brief LLVM Assembly Writing Slot Computation. +class SlotMachine { + +/// @name Types +/// @{ +public: + + /// @brief A mapping of Values to slot numbers + typedef std::map ValueMap; + + /// @brief A plane with next slot number and ValueMap + struct Plane { + unsigned next_slot; ///< The next slot number to use + ValueMap map; ///< The map of Value* -> unsigned + Plane() { next_slot = 0; } ///< Make sure we start at 0 + }; + + /// @brief The map of planes by Type + typedef std::map TypedPlanes; + +/// @} +/// @name Constructors +/// @{ +public: + /// @brief Construct from a module + SlotMachine(const Module *M ); + + /// @brief Construct from a function, starting out in incorp state. + SlotMachine(const Function *F ); + +/// @} +/// @name Accessors +/// @{ +public: + /// Return the slot number of the specified value in it's type + /// plane. Its an error to ask for something not in the SlotMachine. + /// Its an error to ask for a Type* + unsigned getSlot(const Value *V) const; + +/// @} +/// @name Mutators +/// @{ +public: + /// If you'd like to deal with a function instead of just a module, use + /// this method to get its data into the SlotMachine. + void incorporateFunction(const Function *F); + + /// After calling incorporateFunction, use this method to remove the + /// most recently incorporated function from the SlotMachine. This + /// will reset the state of the machine back to just the module contents. + void purgeFunction(); + +/// @} +/// @name Implementation Details +/// @{ +private: + /// Values can be crammed into here at will. If they haven't + /// been inserted already, they get inserted, otherwise they are ignored. + /// Either way, the slot number for the Value* is returned. + unsigned createSlot(const Value *V); + + /// Insert a value into the value table. Return the slot number + /// that it now occupies. BadThings(TM) will happen if you insert a + /// Value that's already been inserted. + unsigned insertValue( const Value *V ); + + /// Add all of the module level global variables (and their initializers) + /// and function declarations, but not the contents of those functions. + void processModule(); + + SlotMachine(const SlotMachine &); // DO NOT IMPLEMENT + void operator=(const SlotMachine &); // DO NOT IMPLEMENT + +/// @} +/// @name Data +/// @{ +public: + + /// @brief The module for which we are holding slot numbers + const Module *TheModule; + + /// @brief Whether or not we have a function incorporated + bool FunctionIncorporated; + + /// @brief The TypePlanes map for the module level data + TypedPlanes mMap; + + /// @brief The TypePlanes map for the function level data + TypedPlanes fMap; + +/// @} + +}; + +} + static RegisterPass X("printm", "Print module to stderr",PassInfo::Analysis|PassInfo::Optimization); static RegisterPass @@ -43,7 +141,7 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V, bool PrintName, std::map &TypeTable, - SlotCalculator *Table); + SlotMachine *Machine); static const Module *getModuleFromVal(const Value *V) { if (const Argument *MA = dyn_cast(V)) @@ -58,18 +156,18 @@ return 0; } -static SlotCalculator *createSlotCalculator(const Value *V) { +static SlotMachine *createSlotMachine(const Value *V) { assert(!isa(V) && "Can't create an SC for a type!"); if (const Argument *FA = dyn_cast(V)) { - return new SlotCalculator(FA->getParent(), false); + return new SlotMachine(FA->getParent()); } else if (const Instruction *I = dyn_cast(V)) { - return new SlotCalculator(I->getParent()->getParent(), false); + return new SlotMachine(I->getParent()->getParent()); } else if (const BasicBlock *BB = dyn_cast(V)) { - return new SlotCalculator(BB->getParent(), false); + return new SlotMachine(BB->getParent()); } else if (const GlobalVariable *GV = dyn_cast(V)){ - return new SlotCalculator(GV->getParent(), false); + return new SlotMachine(GV->getParent()); } else if (const Function *Func = dyn_cast(V)) { - return new SlotCalculator(Func, false); + return new SlotMachine(Func); } return 0; } @@ -246,7 +344,7 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV, bool PrintName, std::map &TypeTable, - SlotCalculator *Table) { + SlotMachine *Machine) { if (const ConstantBool *CB = dyn_cast(CV)) { Out << (CB == ConstantBool::True ? "true" : "false"); } else if (const ConstantSInt *CI = dyn_cast(CV)) { @@ -322,12 +420,12 @@ Out << " "; printTypeInt(Out, ETy, TypeTable); WriteAsOperandInternal(Out, CA->getOperand(0), - PrintName, TypeTable, Table); + PrintName, TypeTable, Machine); for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) { Out << ", "; printTypeInt(Out, ETy, TypeTable); WriteAsOperandInternal(Out, CA->getOperand(i), PrintName, - TypeTable, Table); + TypeTable, Machine); } } Out << " ]"; @@ -339,14 +437,14 @@ printTypeInt(Out, CS->getOperand(0)->getType(), TypeTable); WriteAsOperandInternal(Out, CS->getOperand(0), - PrintName, TypeTable, Table); + PrintName, TypeTable, Machine); for (unsigned i = 1; i < CS->getNumOperands(); i++) { Out << ", "; printTypeInt(Out, CS->getOperand(i)->getType(), TypeTable); WriteAsOperandInternal(Out, CS->getOperand(i), - PrintName, TypeTable, Table); + PrintName, TypeTable, Machine); } } @@ -355,14 +453,14 @@ Out << "null"; } else if (const ConstantPointerRef *PR = dyn_cast(CV)) { - WriteAsOperandInternal(Out, PR->getValue(), true, TypeTable, Table); + WriteAsOperandInternal(Out, PR->getValue(), true, TypeTable, Machine); } else if (const ConstantExpr *CE = dyn_cast(CV)) { Out << CE->getOpcodeName() << " ("; for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) { printTypeInt(Out, (*OI)->getType(), TypeTable); - WriteAsOperandInternal(Out, *OI, PrintName, TypeTable, Table); + WriteAsOperandInternal(Out, *OI, PrintName, TypeTable, Machine); if (OI+1 != CE->op_end()) Out << ", "; } @@ -386,35 +484,30 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V, bool PrintName, std::map &TypeTable, - SlotCalculator *Table) { + SlotMachine *Machine) { Out << " "; if (PrintName && V->hasName()) { Out << getLLVMName(V->getName()); } else { if (const Constant *CV = dyn_cast(V)) { - WriteConstantInt(Out, CV, PrintName, TypeTable, Table); + WriteConstantInt(Out, CV, PrintName, TypeTable, Machine); } else { int Slot; - if (Table) { - Slot = Table->getSlot(V); + if (Machine) { + Slot = Machine->getSlot(V); } else { if (const Type *Ty = dyn_cast(V)) { Out << Ty->getDescription(); return; } - Table = createSlotCalculator(V); - if (Table == 0) { Out << "BAD VALUE TYPE!"; return; } + Machine = createSlotMachine(V); + if (Machine == 0) { Out << "BAD VALUE TYPE!"; return; } - Slot = Table->getSlot(V); - delete Table; + Slot = Machine->getSlot(V); + delete Machine; } - if (Slot >= 0) Out << "%" << Slot; - else if (PrintName) - if (V->hasName()) - Out << "getName()) << ">"; - else - Out << ""; // Not embedded into a location? + Out << "%" << Slot; } } } @@ -447,14 +540,14 @@ class AssemblyWriter { std::ostream *Out; - SlotCalculator &Table; + SlotMachine &Machine; const Module *TheModule; std::map TypeNames; AssemblyAnnotationWriter *AnnotationWriter; public: - inline AssemblyWriter(std::ostream &o, SlotCalculator &Tab, const Module *M, + inline AssemblyWriter(std::ostream &o, SlotMachine &Mac, const Module *M, AssemblyAnnotationWriter *AAW) - : Out(&o), Table(Tab), TheModule(M), AnnotationWriter(AAW) { + : Out(&o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) { // If the module has a symbol table, take all global types and stuff their // names into the TypeNames map. @@ -548,7 +641,7 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType, bool PrintName) { if (PrintType) { *Out << " "; printType(Operand->getType()); } - WriteAsOperandInternal(*Out, Operand, PrintName, TypeNames, &Table); + WriteAsOperandInternal(*Out, Operand, PrintName, TypeNames, &Machine); } @@ -674,7 +767,7 @@ else *Out << "\"\""; *Out << "("; - Table.incorporateFunction(F); + Machine.incorporateFunction(F); // Loop over the arguments, printing them... const FunctionType *FT = F->getFunctionType(); @@ -701,7 +794,7 @@ *Out << "}\n"; } - Table.purgeFunction(); + Machine.purgeFunction(); } /// printArgument - This member is called for every argument that is passed into @@ -717,8 +810,6 @@ // Output name, if available... if (Arg->hasName()) *Out << " " << getLLVMName(Arg->getName()); - else if (Table.getSlot(Arg) < 0) - *Out << ""; } /// printBasicBlock - This member is called for each basic block in a method. @@ -727,12 +818,7 @@ if (BB->hasName()) { // Print out the label if it exists... *Out << "\n" << BB->getName() << ":"; } else if (!BB->use_empty()) { // Don't print block # of no uses... - int Slot = Table.getSlot(BB); - *Out << "\n;

    - -
  • The SymbolTable class
  • -
  • The ilist and iplist classes -
      -
    • Creating, inserting, moving and deleting from LLVM lists
    • -
    -
  • -
  • Important iterator invalidation semantics to be aware of.
  • - +
  • The Argument class
  • + + +
  • The SymbolTable class
  • +
  • The ilist and iplist classes +
      +
    • Creating, inserting, moving and deleting from LLVM lists
    • +
    +
  • +
  • Important iterator invalidation semantics to be aware of.
  • @@ -204,6 +202,10 @@
  • Bjarne Stroustrup's C++ Page
  • +
  • +Bruce Eckel's Thinking in C++, 2nd ed. Volume 2 Revision 4.0 (even better, get +the book).
  • +

    You are also encouraged to take a look at the + +

    +
    +

    This class provides a symbol table that the +Function and +Module classes use for naming definitions. The symbol table can +provide a name for any Value or +Type. SymbolTable is an abstract data +type. It hides the data it contains and provides access to it through a +controlled interface.

    + +

    To use the SymbolTable well, you need to understand the +structure of the information it holds. The class contains two +std::map objects. The first, pmap, is a map of +Type* to maps of name (std::string) to Value*. +The second, tmap, is a map of names to Type*. Thus, Values +are stored in two-dimensions and accessed by Type and name. Types, +however, are stored in a single dimension and accessed only by name.

    + +

    The interface of this class provides three basic types of operations: +

      +
    1. Accessors. Accessors provide read-only access to information + such as finding a value for a name with the + lookup method.
    2. +
    3. Mutators. Mutators allow the user to add information to the + SymbolTable with methods like + insert.
    4. +
    5. Iterators. Iterators allow the user to traverse the content + of the symbol table in well defined ways, such as the method + type_begin.
    6. +
    + +

    Accessors

    +
    +
    Value* lookup(const Type* Ty, const std::string& name) const: +
    +
    The lookup method searches the type plane given by the + Ty parameter for a Value with the provided name. + If a suitable Value is not found, null is returned.
    + +
    Type* lookupType( const std::string& name) const:
    +
    The lookupType method searches through the types for a + Type with the provided name. If a suitable Type + is not found, null is returned.
    + +
    bool hasTypes() const:
    +
    This function returns true if an entry has been made into the type + map.
    + +
    bool isEmpty() const:
    +
    This function returns true if both the value and types maps are + empty
    + +
    std::string get_name(const Value*) const:
    +
    This function returns the name of the Value provided or the empty + string if the Value is not in the symbol table.
    + +
    std::string get_name(const Type*) const:
    +
    This function returns the name of the Type provided or the empty + string if the Type is not in the symbol table.
    +
    + +

    Mutators

    +
    +
    void insert(Value *Val):
    +
    This method adds the provided value to the symbol table. The Value must + have both a name and a type which are extracted and used to place the value + in the correct type plane under the value's name.
    + +
    void insert(const std::string& Name, Value *Val):
    +
    Inserts a constant or type into the symbol table with the specified + name. There can be a many to one mapping between names and constants + or types.
    + +
    void insert(const std::string& Name, Type *Typ):
    +
    Inserts a type into the symbol table with the specified name. There + can be a many-to-one mapping between names and types. This method + allows a type with an existing entry in the symbol table to get + a new name.
    + +
    void remove(Value* Val):
    +
    This method removes a named value from the symbol table. The + type and name of the Value are extracted from \p N and used to + lookup the Value in the correct type plane. If the Value is + not in the symbol table, this method silently ignores the + request.
    + +
    void remove(Type* Typ):
    +
    This method removes a named type from the symbol table. The + name of the type is extracted from \P T and used to look up + the Type in the type map. If the Type is not in the symbol + table, this method silently ignores the request.
    + +
    Value* remove(const std::string& Name, Value *Val):
    +
    Remove a constant or type with the specified name from the + symbol table.
    + +
    Type* remove(const std::string& Name, Type* T):
    +
    Remove a type with the specified name from the symbol table. + Returns the removed Type.
    + +
    Value *value_remove(const value_iterator& It):
    +
    Removes a specific value from the symbol table. + Returns the removed value.
    + +
    bool strip():
    +
    This method will strip the symbol table of its names leaving + the type and values.
    + +
    void clear():
    +
    Empty the symbol table completely.
    +
    + +

    Iteration

    +

    The following functions describe three types of iterators you can obtain +the beginning or end of the sequence for both const and non-const. It is +important to keep track of the different kinds of iterators. There are +three idioms worth pointing out:

    + + + + + + + + + + + + + + +
    UnitsIteratorIdiom
    Planes Of name/Value mapsPI
    +for (SymbolTable::plane_const_iterator PI = ST.plane_begin(),
    +PE = ST.plane_end(); PI != PE; ++PI ) {
    +  PI->first // This is the Type* of the plane
    +  PI->second // This is the SymbolTable::ValueMap of name/Value pairs
    +    
    All name/Type PairsTI
    +for (SymbolTable::type_const_iterator TI = ST.type_begin(),
    +     TE = ST.type_end(); TI != TE; ++TI )
    +  TI->first  // This is the name of the type
    +  TI->second // This is the Type* value associated with the name
    +    
    name/Value pairs in a planeVI
    +for (SymbolTable::value_const_iterator VI = ST.value_begin(SomeType),
    +     VE = ST.value_end(SomeType); VI != VE; ++VI )
    +  VI->first  // This is the name of the Value
    +  VI->second // This is the Value* value associated with the name
    +    
    +

    Using the recommended iterator names and idioms will help you avoid +making mistakes. Of particular note, make sure that whenever you use +value_begin(SomeType) that you always compare the resulting iterator +with value_end(SomeType) not value_end(SomeOtherType) or else you +will loop infinitely.

    + +
    + +
    plane_iterator plane_begin():
    +
    Get an iterator that starts at the beginning of the type planes. + The iterator will iterate over the Type/ValueMap pairs in the + type planes.
    + +
    plane_const_iterator plane_begin() const:
    +
    Get a const_iterator that starts at the beginning of the type + planes. The iterator will iterate over the Type/ValueMap pairs + in the type planes.
    + +
    plane_iterator plane_end():
    +
    Get an iterator at the end of the type planes. This serves as + the marker for end of iteration over the type planes.
    + +
    plane_const_iterator plane_end() const:
    +
    Get a const_iterator at the end of the type planes. This serves as + the marker for end of iteration over the type planes.
    + +
    value_iterator value_begin(const Type *Typ):
    +
    Get an iterator that starts at the beginning of a type plane. + The iterator will iterate over the name/value pairs in the type plane. + Note: The type plane must already exist before using this.
    + +
    value_const_iterator value_begin(const Type *Typ) const:
    +
    Get a const_iterator that starts at the beginning of a type plane. + The iterator will iterate over the name/value pairs in the type plane. + Note: The type plane must already exist before using this.
    + +
    value_iterator value_end(const Type *Typ):
    +
    Get an iterator to the end of a type plane. This serves as the marker + for end of iteration of the type plane. + Note: The type plane must already exist before using this.
    + +
    value_const_iterator value_end(const Type *Typ) const:
    +
    Get a const_iterator to the end of a type plane. This serves as the + marker for end of iteration of the type plane. + Note: the type plane must already exist before using this.
    + +
    type_iterator type_begin():
    +
    Get an iterator to the start of the name/Type map.
    + +
    type_const_iterator type_begin() cons:
    +
    Get a const_iterator to the start of the name/Type map.
    + +
    type_iterator type_end():
    +
    Get an iterator to the end of the name/Type map. This serves as the + marker for end of iteration of the types.
    + +
    type_const_iterator type_end() const:
    +
    Get a const-iterator to the end of the name/Type map. This serves + as the marker for end of iteration of the types.
    + +
    plane_const_iterator find(const Type* Typ ) const:
    +
    This method returns a plane_const_iterator for iteration over + the type planes starting at a specific plane, given by \p Ty.
    + +
    plane_iterator find( const Type* Typ :
    +
    This method returns a plane_iterator for iteration over the + type planes starting at a specific plane, given by \p Ty.
    + +
    const ValueMap* findPlane( const Type* Typ ) cons:
    +
    This method returns a ValueMap* for a specific type plane. This + interface is deprecated and may go away in the future.
    +
    +
    +
    @@ -1801,8 +2027,10 @@ Dinakar Dhurjati and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/23 21:06:58 $ + Last modified: $Date: 2004/05/26 08:41:35 $
    + From gaeke at cs.uiuc.edu Wed May 26 04:34:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 04:34:02 2004 Subject: [llvm-commits] CVS: reopt/test/run-tests Message-ID: <200405260932.EAA15301@kain.cs.uiuc.edu> Changes in directory reopt/test: run-tests added (r1.1) --- Log message: This is the script that I use to test the trace optimizer. --- Diffs of the changes: (+92 -0) Index: reopt/test/run-tests diff -c /dev/null reopt/test/run-tests:1.1 *** /dev/null Wed May 26 04:32:33 2004 --- reopt/test/run-tests Wed May 26 04:32:22 2004 *************** *** 0 **** --- 1,92 ---- + #!/usr/bin/ksh + # reoptimizer test script + + warn () { + echo ${1+"$@"} 1>&2 + } + + die () { + warn ${1+"$@"} + exit 1 + } + + # sanity check to make sure that the reoptimizer args are set + if [ -z "$LLVM_REOPT" ]; then + warn "Warning: \$LLVM_REOPT is not set." + fi + + # parse arguments + outputonly=0 + action=test + for arg in $@; do + case $arg in + -output) outputonly=1 ;; + -clean) action=clean ;; + -debug) action=debug ;; + -test) action=test ;; + *) benchmk=$arg ;; + esac + done + + # sanity check arguments + if [ -z "$benchmk" ]; then + die "Error: You must specify a benchmark." + fi + if [ \( $outputonly -ne 0 \) -a \( "$action" != "clean" \) ]; then + die "Error: -output only meaningful w/ -clean" + fi + + # choose from among the programs we know of (sets SUBDIR) + case $benchmk in + burg) SUBDIR=MultiSource/Applications/Burg ;; + siod) SUBDIR=MultiSource/Applications/siod ;; + ary3) SUBDIR=SingleSource/Reoptimizer/Ary3 ;; + sieve) SUBDIR=SingleSource/Reoptimizer/Sieve ;; + lists) SUBDIR=SingleSource/Reoptimizer/Lists ;; + shootout) SUBDIR=SingleSource/Benchmarks/Shootout ;; + mynestedloop) SUBDIR=SingleSource/Reoptimizer/MyNestedLoop ;; + *) die "Error: Unknown benchmark $arg" ;; + esac + echo "Starting ${action} on $benchmk" + + # get full path to test/Programs subdirectory + objroot=`gmake prdirs | egrep 'LLVM.*Object Root' |cut -d: -f2-` + fullsubdirpath="${objroot}/test/Programs/${SUBDIR}" + + do_debug () { + cd $fullsubdirpath + reoptllcbinary=`echo Output/*.reopt-llc` + case $reoptllcbinary in + *\**) die "Error: $benchmk reoptimizer binary is not built yet" ;; + esac + set -- $reoptllcbinary + reoptllcbinary=$1 + grep STDIN_FILENAME Makefile + grep RUN_OPTIONS Makefile + prog_args=`grep RUN_OPTIONS Makefile | cut -d= -f2-` + gdbcmd="exec gdb --args $reoptllcbinary $prog_args" + echo "running '$gdbcmd' in $fullsubdirpath" + eval $gdbcmd + } + + do_clean () { + echo "cleaning in $fullsubdirpath" + rm $fullsubdirpath/Output/*.out-reopt-llc + if [ $outputonly -eq 0 ]; then + find $fullsubdirpath -name "*reopt*" -print |xargs rm + fi + } + + do_test () { + exec gmake SUBDIR=$SUBDIR + } + + case $action in + debug) do_debug ;; + clean) do_clean ;; + test) do_test ;; + *) die "Unknown action $action" ;; + esac + + # we're done + exit 0 From gaeke at cs.uiuc.edu Wed May 26 04:42:00 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 04:42:00 2004 Subject: [llvm-commits] CVS: reopt/test/TEST.reopt.Makefile Message-ID: <200405260940.EAA17000@kain.cs.uiuc.edu> Changes in directory reopt/test: TEST.reopt.Makefile updated: 1.13 -> 1.14 --- Log message: Use the same linker that the compiler uses --- Diffs of the changes: (+3 -1) Index: reopt/test/TEST.reopt.Makefile diff -u reopt/test/TEST.reopt.Makefile:1.13 reopt/test/TEST.reopt.Makefile:1.14 --- reopt/test/TEST.reopt.Makefile:1.13 Sat May 22 01:56:40 2004 +++ reopt/test/TEST.reopt.Makefile Wed May 26 04:40:18 2004 @@ -46,9 +46,11 @@ # Solaris libraries that the Reoptimizer depends on REOPTIMIZER_SOLARISLIBS = -lcpc -lm -lrt -lmalloc -ldl +MYLD = $(shell $(CXX) --print-prog-name=ld) + WHOLE_REOPTIMIZER = $(REOPTLIBDIR)/wholereoptimizer.o $(WHOLE_REOPTIMIZER): $(REOPTIMIZER_OBJS) $(REOPTIMIZER_LLVMOBJS) - /usr/ccs/bin/ld -r -o $@ $+ + $(MYLD) -r -o $@ $+ # Libraries that should be checked for freshness when doing # Reoptimizer tests (http://www.goodegg.com/eggdating.html) From gaeke at cs.uiuc.edu Wed May 26 04:45:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 04:45:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405260943.EAA17385@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.72 -> 1.73 --- Log message: Remember to copy caller's sp to callee's fp at end of saves. Replace erroneous use of MachineOperand::UseAndDef with Def. Don't bother with the if (Source!=Target) optimization. --- Diffs of the changes: (+21 -18) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.72 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.73 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.72 Tue May 25 15:43:48 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Wed May 26 04:43:49 2004 @@ -217,7 +217,8 @@ void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) { const TargetRegInfo &TRI = TM->getRegInfo (); - static const unsigned sp = SparcV9::o6, g1 = SparcV9::g1, g2 = SparcV9::g2; + static const unsigned sp = SparcV9::o6, fp = SparcV9::i6, g1 = SparcV9::g1, + g2 = SparcV9::g2; // UTF prolog: start out by clearing everything out of the entry basic block // (FIXME: may not work once we start doing optimizations!!! We will probably @@ -226,7 +227,7 @@ // 0. Save caller's stack pointer in %g1. E.push_back (BuildMI (V9::ORr, 3).addMReg (sp).addZImm (0).addMReg (g1, - MachineOperand::UseAndDef)); + MachineOperand::Def)); // 1. Emit ADD instruction to allocate the right amount of stack space. E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize) @@ -278,6 +279,10 @@ E.push_back (*vi); } + // Caller's stack pointer becomes our frame pointer. + E.push_back (BuildMI (V9::ORr, 3).addMReg (g1).addZImm (0).addMReg (fp, + MachineOperand::Def)); + // 4. Insert a copy for each live-in variable to copy it from the stack // to the register that was allocated for it in the TraceFn. for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; @@ -285,22 +290,20 @@ Value *V = *SI; std::pair &ai = AllocStates[V]; AllocInfo &Source = ai.first, &Target = ai.second; - if (Source != Target) { - assert (Target.AllocState == AllocInfo::Allocated - && "FIXME: can't do mem-->mem copy of live-ins yet"); - // FIXME: The following should really be using insertCopyMachineInstrs or - // something like it. - mvec.clear (); - assert (TRI.getRegType (Target.Placement) - == TRI.getRegType (Source.Placement) - && "Live-in value changed reg type?!"); - unsigned RegType = TRI.getRegType (Target.Placement); - TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (Source.Placement), - Target.Placement, RegType, g2); - for (std::vector::iterator vi = mvec.begin (), - ve = mvec.end (); vi != ve; ++vi) - E.push_back (*vi); - } + assert (Target.AllocState == AllocInfo::Allocated + && "FIXME: can't do mem-->mem copy of live-ins yet"); + // FIXME: The following should really be using insertCopyMachineInstrs or + // something like it. + mvec.clear (); + assert (TRI.getRegType (Target.Placement) + == TRI.getRegType (Source.Placement) + && "Live-in value changed reg type?!"); + unsigned RegType = TRI.getRegType (Target.Placement); + TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (Source.Placement), + Target.Placement, RegType, g2); + for (std::vector::iterator vi = mvec.begin (), + ve = mvec.end (); vi != ve; ++vi) + E.push_back (*vi); } } From gaeke at cs.uiuc.edu Wed May 26 05:07:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 05:07:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405261005.FAA20177@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.39 -> 1.40 --- Log message: Remove unneeded #includes. --- Diffs of the changes: (+0 -4) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.39 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.40 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.39 Sun May 23 05:05:01 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Wed May 26 05:05:29 2004 @@ -19,11 +19,8 @@ #include "reopt/VirtualMem.h" #include "reopt/InstrUtils.h" #include "Support/Debug.h" -#include "Support/StringExtras.h" -#include "Support/FileUtilities.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Assembly/PrintModulePass.h" -#include "llvm/Bytecode/Writer.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/MachineCodeEmitter.h" @@ -34,7 +31,6 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachineImpls.h" -#include namespace llvm { From lattner at cs.uiuc.edu Wed May 26 11:56:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed May 26 11:56:02 2004 Subject: [llvm-commits] CVS: llvm/docs/ProgrammersManual.html Message-ID: <200405261653.LAA22876@zion.cs.uiuc.edu> Changes in directory llvm/docs: ProgrammersManual.html updated: 1.57 -> 1.58 --- Log message: Fix a bug in reid's checkin --- Diffs of the changes: (+4 -3) Index: llvm/docs/ProgrammersManual.html diff -u llvm/docs/ProgrammersManual.html:1.57 llvm/docs/ProgrammersManual.html:1.58 --- llvm/docs/ProgrammersManual.html:1.57 Wed May 26 03:41:35 2004 +++ llvm/docs/ProgrammersManual.html Wed May 26 11:52:55 2004 @@ -114,8 +114,9 @@ @@ -2027,7 +2028,7 @@ Dinakar Dhurjati and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/26 08:41:35 $ + Last modified: $Date: 2004/05/26 16:52:55 $ From lattner at cs.uiuc.edu Wed May 26 12:11:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed May 26 12:11:02 2004 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y Message-ID: <200405261708.MAA25745@zion.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: llvmAsmParser.y updated: 1.164 -> 1.165 --- Log message: A quick and ugly hack to fix PR345: http://llvm.cs.uiuc.edu/PR345 . I used TypeTy specifically to make Reid cringe :) --- Diffs of the changes: (+7 -1) Index: llvm/lib/AsmParser/llvmAsmParser.y diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.164 llvm/lib/AsmParser/llvmAsmParser.y:1.165 --- llvm/lib/AsmParser/llvmAsmParser.y:1.164 Tue May 25 12:29:21 2004 +++ llvm/lib/AsmParser/llvmAsmParser.y Wed May 26 12:08:25 2004 @@ -515,7 +515,13 @@ CurFun.CurrentFunction->getSymbolTable() : CurModule.CurrentModule->getSymbolTable(); - Value *Existing = ST.lookup(V->getType(), Name); + Value *Existing; + // FIXME: this is really gross + if (V->getType() != Type::TypeTy) + Existing = ST.lookup(V->getType(), Name); + else + Existing = ST.lookupType(Name); + if (Existing) { // Inserting a name that is already defined??? // There is only one case where this is allowed: when we are refining an // opaque type. In this case, Existing will be an opaque type. From lattner at cs.uiuc.edu Wed May 26 12:19:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed May 26 12:19:02 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/CBackend/2003-10-23-UnusedType.ll Message-ID: <200405261714.MAA28012@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/CBackend: 2003-10-23-UnusedType.ll updated: 1.1 -> 1.2 --- Log message: Make the test use the %A type --- Diffs of the changes: (+1 -0) Index: llvm/test/Regression/CodeGen/CBackend/2003-10-23-UnusedType.ll diff -u llvm/test/Regression/CodeGen/CBackend/2003-10-23-UnusedType.ll:1.1 llvm/test/Regression/CodeGen/CBackend/2003-10-23-UnusedType.ll:1.2 --- llvm/test/Regression/CodeGen/CBackend/2003-10-23-UnusedType.ll:1.1 Thu Oct 23 14:25:53 2003 +++ llvm/test/Regression/CodeGen/CBackend/2003-10-23-UnusedType.ll Wed May 26 12:14:49 2004 @@ -1,3 +1,4 @@ %A = type { uint, sbyte*, { uint, uint, uint, uint, uint, uint, uint, uint }*, ushort } +void %test(%A *) { ret void } From lattner at cs.uiuc.edu Wed May 26 12:24:04 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed May 26 12:24:04 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200405261721.MAA28309@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.177 -> 1.178 --- Log message: Fix PR344: http://llvm.cs.uiuc.edu/PR344 : the incorrect remove was being used. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.177 llvm/lib/Target/CBackend/Writer.cpp:1.178 --- llvm/lib/Target/CBackend/Writer.cpp:1.177 Tue May 25 03:50:41 2004 +++ llvm/lib/Target/CBackend/Writer.cpp Wed May 26 12:20:52 2004 @@ -226,7 +226,7 @@ // If this is not used, remove it from the symbol table. std::set::iterator UTI = UT.find(STy); if (UTI == UT.end()) - MST.remove(I->first, I->second); + MST.remove(I->first, (Type*)I->second); else UT.erase(UTI); } From brukman at cs.uiuc.edu Wed May 26 12:46:05 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Wed May 26 12:46:05 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/SymbolTable.h Message-ID: <200405261743.MAA28523@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: SymbolTable.h updated: 1.31 -> 1.32 --- Log message: Fix spelling of doxygen directive. --- Diffs of the changes: (+1 -1) Index: llvm/include/llvm/SymbolTable.h diff -u llvm/include/llvm/SymbolTable.h:1.31 llvm/include/llvm/SymbolTable.h:1.32 --- llvm/include/llvm/SymbolTable.h:1.31 Tue May 25 03:45:53 2004 +++ llvm/include/llvm/SymbolTable.h Wed May 26 12:42:51 2004 @@ -306,7 +306,7 @@ /// This method returns a plane_iterator for iteration over the /// type planes starting at a specific plane, given by \p Ty. - /// @breif Find a type plane. + /// @brief Find a type plane. inline plane_iterator find( const Type* Typ ) { assert(Typ && "Can't find type plane with null type!"); return pmap.find(Typ); From gaeke at cs.uiuc.edu Wed May 26 16:22:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:22:01 2004 Subject: [llvm-commits] CVS: reopt/test/TEST.reopt.Makefile Message-ID: <200405262121.QAA27781@kain.cs.uiuc.edu> Changes in directory reopt/test: TEST.reopt.Makefile updated: 1.14 -> 1.15 --- Log message: More libraries are needed... btw, it's kind of dumb that linking in executionengine makes you link in lli-jit and lli-interpreter. Abort if ld fails... I want to know sooner rather than later. --- Diffs of the changes: (+5 -4) Index: reopt/test/TEST.reopt.Makefile diff -u reopt/test/TEST.reopt.Makefile:1.14 reopt/test/TEST.reopt.Makefile:1.15 --- reopt/test/TEST.reopt.Makefile:1.14 Wed May 26 04:40:18 2004 +++ reopt/test/TEST.reopt.Makefile Wed May 26 16:21:02 2004 @@ -28,14 +28,15 @@ # Libraries that contain the Reoptimizer itself REOPTIMIZER_OBJS = $(REOPTLIBDIR)/firstTrigger.o \ $(REOPTLIBDIR)/tracecache.o $(REOPTLIBDIR)/mapinfo.o \ - $(REOPTLIBDIR)/scratchmemory.o $(REOPTLIBDIR)/tracetofunction.o + $(REOPTLIBDIR)/scratchmemory.o $(REOPTLIBDIR)/tracetofunction.o $(REOPTLIBDIR)/tracejit.o # Object files that contain common LLVM code the Reoptimizer depends on REOPTIMIZER_LLVMOBJS = $(DESTLIBCURRENT)/vmcore.o \ $(DESTLIBCURRENT)/bcreader.o $(DESTLIBCURRENT)/bcwriter.o \ $(DESTLIBCURRENT)/sparcv9.o $(DESTLIBCURRENT)/sparcv9select.o \ $(DESTLIBCURRENT)/sparcv9livevar.o $(DESTLIBCURRENT)/sched.o \ - $(DESTLIBCURRENT)/codegen.o + $(DESTLIBCURRENT)/codegen.o $(DESTLIBCURRENT)/executionengine.o \ + $(DESTLIBCURRENT)/lli-jit.o $(DESTLIBCURRENT)/lli-interpreter.o # Library archive files that contain common LLVM code the Reoptimizer depends on REOPTIMIZER_LLVMLIBS = $(DESTLIBCURRENT)/libsparcv9regalloc.a \ @@ -73,7 +74,7 @@ $(PROGRAMS_TO_TEST:%=Output/%.reopt-llc.s): \ Output/%.reopt-llc.s: Output/%.llvm.bc @echo "===== Building Reoptimizer version of $(TESTNAME) =====" - -$(LOPT) -q -inline -lowerswitch -enable-correct-eh-support \ + $(LOPT) -q -inline -lowerswitch -enable-correct-eh-support \ -lowerinvoke -branch-combine -emitfuncs -instloops $< | $(LLC) \ $(LLCFLAGS) -disable-sched -disable-strip -f -enable-maps \ -save-ra-state -o $@ @@ -82,7 +83,7 @@ # compiler. $(PROGRAMS_TO_TEST:%=Output/%.reopt-llc): \ Output/%.reopt-llc: Output/%.reopt-llc.s $(REOPTIMIZER_LIBDEPS) - -$(CXX) $(CFLAGS) $< -o $@ $(REOPTIMIZER_LDADD) + $(CXX) $(CFLAGS) $< -o $@ $(REOPTIMIZER_LDADD) # 3. Run the reoptimized version. $(PROGRAMS_TO_TEST:%=Output/%.out-reopt-llc): \ From gaeke at cs.uiuc.edu Wed May 26 16:25:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:25:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceJIT/ Message-ID: <200405262124.QAA27887@kain.cs.uiuc.edu> Changes in directory reopt/lib/TraceJIT: --- Log message: Directory /home/vadve/shared/InternalCVS/reopt/lib/TraceJIT added to the repository --- Diffs of the changes: (+0 -0) From gaeke at cs.uiuc.edu Wed May 26 16:25:10 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:25:10 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceOptEmitter.cpp Message-ID: <200405262123.QAA27851@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: TraceOptEmitter.cpp (r1.9) removed --- Log message: TraceOptEmitter has been folded into the TraceJIT. --- Diffs of the changes: (+0 -0) From gaeke at cs.uiuc.edu Wed May 26 16:26:04 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:26:04 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceWriter.cpp Message-ID: <200405262123.QAA27872@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: TraceWriter.cpp updated: 1.2 -> 1.3 --- Log message: Make WriteTraceToFile() take a pointer, not a reference, to Trace. --- Diffs of the changes: (+5 -3) Index: reopt/lib/LightWtProfiling/TraceWriter.cpp diff -u reopt/lib/LightWtProfiling/TraceWriter.cpp:1.2 reopt/lib/LightWtProfiling/TraceWriter.cpp:1.3 --- reopt/lib/LightWtProfiling/TraceWriter.cpp:1.2 Sat May 22 01:56:38 2004 +++ reopt/lib/LightWtProfiling/TraceWriter.cpp Wed May 26 16:23:38 2004 @@ -35,10 +35,12 @@ return bbNum; } -void WriteTraceToFile (Trace &T) { +void WriteTraceToFile (Trace *Tr) { + assert (Tr); + // Get unique filename for trace & corresponding module. std::string traceFileName, bytecodeFileName; - Function *F = T.getFunction (); + Function *F = Tr->getFunction (); unsigned count = 0; do { ++count; @@ -49,7 +51,7 @@ // Write out trace. std::ofstream out (traceFileName.c_str ()); out << F->getName () << "\n"; - for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) + for (Trace::iterator i = Tr->begin (), e = Tr->end (); i != e; ++i) out << getBasicBlockIndex (*i) << " "; out << "\n"; out.close (); From gaeke at cs.uiuc.edu Wed May 26 16:27:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:27:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/ReoptimizerInternal.h Message-ID: <200405262123.QAA27858@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: ReoptimizerInternal.h updated: 1.4 -> 1.5 --- Log message: TraceOptEmitter has been folded into the TraceJIT. Declare class Trace forward here, and declare the TraceWriter interface here. --- Diffs of the changes: (+5 -5) Index: reopt/lib/LightWtProfiling/ReoptimizerInternal.h diff -u reopt/lib/LightWtProfiling/ReoptimizerInternal.h:1.4 reopt/lib/LightWtProfiling/ReoptimizerInternal.h:1.5 --- reopt/lib/LightWtProfiling/ReoptimizerInternal.h:1.4 Tue Apr 27 13:34:43 2004 +++ reopt/lib/LightWtProfiling/ReoptimizerInternal.h Wed May 26 16:23:36 2004 @@ -40,6 +40,7 @@ class VirtualMem; class TraceCache; +class Trace; class Module; class ModuleProvider; @@ -151,14 +152,13 @@ extern uint64_t llvm_interval_counter; -// TraceOptEmitter.cpp ////////////////////////////////////////////////// - -MachineCodeEmitter *createTraceOptEmitter(const TargetData &TD); - // RuntimeOptimizations.cpp ///////////////////////////////////////////// -void addGlobalMapping(const GlobalValue *GV, uint64_t Addr); void optimizeTrace (std::vector &vBB, uint64_t a); + +// TraceWriter.cpp ////////////////////////////////////////////////////// + +void WriteTraceToFile (Trace *T); }; // end namespace llvm From gaeke at cs.uiuc.edu Wed May 26 16:27:14 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:27:14 2004 Subject: [llvm-commits] CVS: reopt/lib/Makefile Message-ID: <200405262124.QAA27913@kain.cs.uiuc.edu> Changes in directory reopt/lib: Makefile updated: 1.21 -> 1.22 --- Log message: Add TraceJIT subdir to the build --- Diffs of the changes: (+1 -1) Index: reopt/lib/Makefile diff -u reopt/lib/Makefile:1.21 reopt/lib/Makefile:1.22 --- reopt/lib/Makefile:1.21 Sat May 22 15:42:40 2004 +++ reopt/lib/Makefile Wed May 26 16:24:00 2004 @@ -1,5 +1,5 @@ LEVEL = .. -DIRS := BinInterface Mapping TraceCache Trigger LightWtProfiling Inst Optimizations TraceToFunction +DIRS := BinInterface Mapping TraceCache Trigger LightWtProfiling Inst Optimizations TraceToFunction TraceJIT include $(LEVEL)/Makefile.config From gaeke at cs.uiuc.edu Wed May 26 16:28:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:28:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405262123.QAA27865@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.40 -> 1.41 --- Log message: Use the new TraceJIT subclass of ExecutionEngine to optimize traces. --- Diffs of the changes: (+9 -74) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.40 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.41 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.40 Wed May 26 05:05:29 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Wed May 26 16:23:37 2004 @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "ReoptimizerInternal.h" +#include "../TraceJIT/TraceJIT.h" #include "reopt/UnpackTraceFunction.h" #include "reopt/TraceToFunction.h" #include "reopt/VirtualMem.h" @@ -34,42 +35,9 @@ namespace llvm { -static IntrinsicLowering *IL = 0; -static TargetMachine *Target = 0; -static const TargetData *TD = 0; -static MachineCodeEmitter *MCE = 0; -static FunctionPassManager *PM = 0; -static UnpackTraceFunction *UTF = 0; - extern bool SaveStateToModule; extern bool SaveRegAllocState; -///==----- Machinery to keep track of where a TraceFunction's code is ------==// -// This deliberately mimics the code used by ExecutionEngine, in case we ever -// want to turn the Reoptimizer into an ExecutionEngine. - -/// GlobalAddressMap - A mapping between LLVM global values and their -/// actualized version... -std::map GlobalAddressMap; - -void addGlobalMapping(const GlobalValue *GV, uint64_t Addr) { - uint64_t &CurVal = GlobalAddressMap[GV]; - assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!"); - CurVal = Addr; -} - -/// getPointerToGlobalIfAvailable - This returns the address of the specified -/// global value if it is available, otherwise it returns null. -/// -uint64_t getPointerToGlobalIfAvailable(const GlobalValue *GV) { - std::map::iterator I = GlobalAddressMap.find(GV); - return I != GlobalAddressMap.end() ? I->second : 0; -} - -///==----------------------------------------------------------------------==/// - -extern void WriteTraceToFile (Trace &T); - extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr, uint64_t traceEndAddr) { DEBUG (std::cerr << "\n*** About to return from optimizeTrace(). GDB" @@ -81,29 +49,6 @@ << std::dec); } -static void addPassesToReoptimizeTrace (FunctionPassManager &PM, - const TargetData *TD, - TargetMachine *Target, - MachineCodeEmitter *MCE) { - // Verify that the generated function's bytecode is good, then compile it - // down to machine code. Then, "unpack" it back into its matrix function. - // FIXME: Register allocation hints also need to be added to the PassManager, - // so that we do not get clobbered by the overhead of adding copies in - // UnpackTraceFunction. - DEBUG(PM.add (new PrintFunctionPass ("Function created from trace:\n", - &std::cerr))); - PM.add (new TargetData (*TD)); - DEBUG (PM.add (createVerifierPass ())); - Target->getJITInfo ()->addPassesToJITCompile (PM); - DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, - "Before unpacking:\n"))); - UTF = new UnpackTraceFunction (Target); - PM.add (UTF); - DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, - "After unpacking:\n"))); - Target->addPassesToEmitMachineCode (PM, *MCE); -} - /// This method is called when we have finally constructed a /// trace. The first parameter is the vector of basic blocks that form /// the trace; the second parameter is the starting @@ -119,18 +64,10 @@ // Initialization stuff: ensure module has been read in, and allocate a // target machine, if there isn't one already. - static bool initDone = false; - if (!initDone) { + static TraceJIT *TJIT = 0; + if (!TJIT) { assert (MP); - IL = new DefaultIntrinsicLowering (); - Target = allocateSparcV9TargetMachine (*MP->getModule (), IL); - TD = &Target->getTargetData (); - MCE = createTraceOptEmitter (*TD); - // Set up the pass manager and trace function unpacker - PM = new FunctionPassManager (MP); - addPassesToReoptimizeTrace (*PM, TD, Target, MCE); - initDone = true; - + TJIT = TraceJIT::create (MP); // Force the SPARCv9 register allocator to save its state into a global // variable SaveRegAllocState = true; @@ -140,23 +77,21 @@ // Turn the vector of basic blocks into a Trace, and then turn the Trace into // a TraceFunction. Trace T (vBB); - DEBUG (WriteTraceToFile (T)); + DEBUG (WriteTraceToFile (&T)); TraceFunction *TF = TraceFunction::get (T); - // Run optimization passes, then unpack the trace function. - UTF->setTraceFunction (TF); // Pass out-of-band information to UTF... - PM->run (*TF->TraceFn); + // Compile the TraceFunction to machine code using the optimizing trace JIT compiler, and + // unpack the resulting optimized trace back into its matrix function. + uint64_t traceStartAddr = TJIT->compileTraceFunction (TF); // Add a branch from address A (the parameter to this method) to the // entry basic block of the unpacked TraceFn. Future executions of the trace // will proceed from the optimized version of the code. - uint64_t traceStartAddr = getPointerToGlobalIfAvailable (TF->TraceFn); - assert (traceStartAddr && "Address of code for TraceFn was NULL after JIT?!"); DEBUG(std::cerr << "Writing branch at 0x" << std::hex << a << " to point to 0x" << traceStartAddr << std::dec << "\n"); vm->writeBranchInstruction(a, traceStartAddr); doFlush (a, a + 4); - TraceOptimizerDone(a, traceStartAddr, MCE->getCurrentPCValue ()); + TraceOptimizerDone(a, traceStartAddr, TJIT->getEmitter ()->getCurrentPCValue ()); } } // end namespace llvm From gaeke at cs.uiuc.edu Wed May 26 16:29:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 26 16:29:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceJIT/Makefile TraceJIT.cpp TraceJIT.h TraceJITEmitter.cpp TraceJITIntercept.cpp Message-ID: <200405262125.QAA27948@kain.cs.uiuc.edu> Changes in directory reopt/lib/TraceJIT: Makefile added (r1.1) TraceJIT.cpp added (r1.1) TraceJIT.h added (r1.1) TraceJITEmitter.cpp added (r1.1) TraceJITIntercept.cpp added (r1.1) --- Log message: Import TraceJIT: a new ExecutionEngine based on the JIT, designed to reoptimize TraceFunctions at runtime. --- Diffs of the changes: (+689 -0) Index: reopt/lib/TraceJIT/Makefile diff -c /dev/null reopt/lib/TraceJIT/Makefile:1.1 *** /dev/null Wed May 26 16:25:23 2004 --- reopt/lib/TraceJIT/Makefile Wed May 26 16:25:13 2004 *************** *** 0 **** --- 1,12 ---- + ##===- lib/TraceJIT/Makefile -------------------------------*- Makefile -*-===## + # + # 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. + # + ##===----------------------------------------------------------------------===## + LEVEL = ../.. + LIBRARYNAME = tracejit + + include $(LEVEL)/Makefile.common Index: reopt/lib/TraceJIT/TraceJIT.cpp diff -c /dev/null reopt/lib/TraceJIT/TraceJIT.cpp:1.1 *** /dev/null Wed May 26 16:25:23 2004 --- reopt/lib/TraceJIT/TraceJIT.cpp Wed May 26 16:25:13 2004 *************** *** 0 **** --- 1,268 ---- + //===-- TraceJIT.cpp - LLVM Just in Time Compiler -------------------------===// + // + // 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 tool implements a just-in-time compiler for LLVM, allowing direct + // execution of LLVM bytecode in an efficient manner. + // + //===----------------------------------------------------------------------===// + + #include "TraceJIT.h" + #include "../LightWtProfiling/ReoptimizerInternal.h" + #include "reopt/TraceToFunction.h" + #include "reopt/UnpackTraceFunction.h" + #include "llvm/CodeGen/MachineCodeEmitter.h" + #include "llvm/CodeGen/MachineFunction.h" + #include "llvm/DerivedTypes.h" + #include "llvm/ExecutionEngine/GenericValue.h" + #include "llvm/Function.h" + #include "llvm/GlobalVariable.h" + #include "llvm/Module.h" + #include "llvm/ModuleProvider.h" + #include "llvm/Analysis/Verifier.h" + #include "llvm/Assembly/PrintModulePass.h" + #include "llvm/CodeGen/Passes.h" + #include "llvm/Target/TargetMachine.h" + #include "llvm/Target/TargetMachineImpls.h" + #include "llvm/Target/TargetJITInfo.h" + #include "Support/CommandLine.h" + #include "Support/DynamicLinker.h" + #include "Support/Debug.h" + using namespace llvm; + + namespace llvm { + extern bool SaveStateToModule; + extern bool SaveRegAllocState; + extern MachineCodeEmitter *createTraceJITEmitter (TraceJIT *JIT); + } // end namespace llvm + + void TraceJIT::addPassesToReoptimizeTrace (FunctionPassManager &PM) { + // Verify that the generated function's bytecode is good, then compile it + // down to machine code. Then, "unpack" it back into its matrix function. + // FIXME: Register allocation hints also need to be added to the PassManager, + // so that we do not get clobbered by the overhead of adding copies in + // UnpackTraceFunction. + DEBUG (PM.add (new PrintFunctionPass ("Function created from trace:\n", + &std::cerr))); + DEBUG (PM.add (createVerifierPass ())); + TJI.addPassesToJITCompile (PM); + DEBUG (PM.add (createMachineFunctionPrinterPass (&std::cerr, + "Before unpacking:\n"))); + PM.add (UTF); + DEBUG (PM.add (createMachineFunctionPrinterPass (&std::cerr, + "After unpacking:\n"))); + + // Force the SPARCv9 register allocator to save its state into a global + // variable where UTF can read it. + SaveRegAllocState = true; + SaveStateToModule = false; + } + + TraceJIT::TraceJIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji) + : ExecutionEngine(MP), TM(tm), TJI(tji), PM(MP) { + setTargetData(TM.getTargetData()); + + // Initialize MCE & trace-function unpacker + MCE = createTraceJITEmitter (this); + UTF = new UnpackTraceFunction (&TM); + + PM.add (new TargetData (getTargetData ())); + + // Compile LLVM Code down to machine code in the intermediate representation + addPassesToReoptimizeTrace (PM); + + // Turn the machine code intermediate representation into bytes in memory that + // may be executed. + if (TM.addPassesToEmitMachineCode(PM, *MCE)) { + std::cerr << "Target '" << TM.getName() + << "' doesn't support machine code emission!\n"; + abort(); + } + } + + TraceJIT::~TraceJIT() { + delete MCE; + delete &TM; + } + + /// run - Start execution with the specified function and arguments. + /// + GenericValue TraceJIT::runFunction(Function *F, + const std::vector &ArgValues) { + assert (F && "Function *F was null at entry to run()"); + GenericValue rv; + + if (ArgValues.size() == 3) { + int (*PF)(int, char **, const char **) = + (int(*)(int, char **, const char **))getPointerToFunction(F); + assert(PF && "Pointer to fn's code was null after getPointerToFunction"); + + // Call the function. + int ExitCode = PF(ArgValues[0].IntVal, (char **) GVTOP (ArgValues[1]), + (const char **) GVTOP (ArgValues[2])); + + rv.IntVal = ExitCode; + } else { + // FIXME: This code should handle a couple of common cases efficiently, but + // it should also implement the general case by code-gening a new anonymous + // nullary function to call. + assert(ArgValues.size() == 1); + void (*PF)(int) = (void(*)(int))getPointerToFunction(F); + assert(PF && "Pointer to fn's code was null after getPointerToFunction"); + PF(ArgValues[0].IntVal); + } + + return rv; + } + + /// runJITOnFunction - Run the FunctionPassManager full of + /// just-in-time compilation passes on F, hopefully filling in + /// GlobalAddress[F] with the address of F's machine code. + /// + void TraceJIT::runJITOnFunction(Function *F) { + static bool isAlreadyCodeGenerating = false; + assert(!isAlreadyCodeGenerating && "Error: Recursive compilation detected!"); + + // TraceJIT the function + isAlreadyCodeGenerating = true; + PM.run(*F); + isAlreadyCodeGenerating = false; + + // If the function referred to a global variable that had not yet been + // emitted, it allocates memory for the global, but doesn't emit it yet. Emit + // all of these globals now. + while (!PendingGlobals.empty()) { + const GlobalVariable *GV = PendingGlobals.back(); + PendingGlobals.pop_back(); + EmitGlobalVariable(GV); + } + } + + /// getPointerToFunction - This method is used to get the address of the + /// specified function, compiling it if neccesary. + /// + void *TraceJIT::getPointerToFunction(Function *F) { + if (void *Addr = getPointerToGlobalIfAvailable(F)) + return Addr; // Check if function already code gen'd + + // Make sure we read in the function if it exists in this Module + try { + MP->materializeFunction(F); + } catch (...) { + std::cerr << "Error parsing bytecode file!\n"; + abort(); + } + + // First try to see if we can dig it out of the executable. + void *Addr = getPointerToNamedFunction(F->getName()); + if (Addr) { + addGlobalMapping(F, Addr); + return Addr; + } + + if (!F->isExternal()) { + // Try to compile it + runJITOnFunction(F); + Addr = getPointerToGlobalIfAvailable(F); + } + + assert(Addr && "Can't find function"); + return Addr; + } + + // getPointerToFunctionOrStub - If the specified function has been + // code-gen'd, return a pointer to the function. If not, compile it, or use + // a stub to implement lazy compilation if available. + // + void *TraceJIT::getPointerToFunctionOrStub(Function *F) { + // If we have already code generated the function, just return the address. + if (void *Addr = getPointerToGlobalIfAvailable(F)) + return Addr; + + // Otherwise, codegen the function. + return getPointerToFunction(F); + } + + /// getOrEmitGlobalVariable - Return the address of the specified global + /// variable, possibly emitting it to memory if needed. This is used by the + /// Emitter. + void *TraceJIT::getOrEmitGlobalVariable(const GlobalVariable *GV) { + void *Ptr = getPointerToGlobalIfAvailable(GV); + if (Ptr) return Ptr; + + // If the global is external, just remember the address. + if (GV->isExternal()) { + Ptr = GetAddressOfSymbol(GV->getName().c_str()); + if (Ptr == 0) { + std::cerr << "Could not resolve external global address: " + << GV->getName() << "\n"; + abort(); + } + } else { + // If the global hasn't been emitted to memory yet, allocate space. We will + // actually initialize the global after current function has finished + // compilation. + Ptr =new char[getTargetData().getTypeSize(GV->getType()->getElementType())]; + PendingGlobals.push_back(GV); + } + addGlobalMapping(GV, Ptr); + return Ptr; + } + + + /// recompileAndRelinkFunction - This method is used to force a function + /// which has already been compiled, to be compiled again, possibly + /// after it has been modified. Then the entry to the old copy is overwritten + /// with a branch to the new copy. If there was no old copy, this acts + /// just like TraceJIT::getPointerToFunction(). + /// + void *TraceJIT::recompileAndRelinkFunction(Function *F) { + void *OldAddr = getPointerToGlobalIfAvailable(F); + + // If it's not already compiled there is no reason to patch it up. + if (OldAddr == 0) { return getPointerToFunction(F); } + + // Delete the old function mapping. + addGlobalMapping(F, 0); + + // Recodegen the function + runJITOnFunction(F); + + // Update state, forward the old function to the new function. + void *Addr = getPointerToGlobalIfAvailable(F); + assert(Addr && "Code generation didn't add function to GlobalAddress table!"); + TJI.replaceMachineCodeForFunction(OldAddr, Addr); + return Addr; + } + + /// create - Create and return a new SparcV9 TraceJIT compiler, or 0 if + /// there is an error. + /// + TraceJIT *TraceJIT::create(ModuleProvider *MP, IntrinsicLowering *IL) { + // Allocate a SparcV9 target. + TargetMachine *Target = allocateSparcV9TargetMachine(*MP->getModule(), IL); + assert(Target && "Could not allocate target machine!"); + + // If the target supports TraceJIT code generation, return a new TraceJIT now. + if (TargetJITInfo *TJ = Target->getJITInfo()) + return new TraceJIT(MP, *Target, *TJ); + + // Fail... + return 0; + } + + uint64_t TraceJIT::compileTraceFunction (TraceFunction *TF) { + // Pass out-of-band information to UTF. + UTF->setTraceFunction (TF); + + // Compile & unpack the TraceFunction. + uint64_t traceStartAddr = (uint64_t) getPointerToFunction (TF->TraceFn); + assert (traceStartAddr && "Address of code for TraceFn was NULL after JIT?!"); + return traceStartAddr; + } + Index: reopt/lib/TraceJIT/TraceJIT.h diff -c /dev/null reopt/lib/TraceJIT/TraceJIT.h:1.1 *** /dev/null Wed May 26 16:25:23 2004 --- reopt/lib/TraceJIT/TraceJIT.h Wed May 26 16:25:13 2004 *************** *** 0 **** --- 1,106 ---- + //===-- TraceJIT.h - Class definition for the TraceJIT ----------*- C++ -*-===// + // + // 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 file defines the top-level TraceJIT data structure. + // + //===----------------------------------------------------------------------===// + + #ifndef TRACEJIT_H + #define TRACEJIT_H + + #include "llvm/ExecutionEngine/ExecutionEngine.h" + #include "llvm/PassManager.h" + #include + + namespace llvm { + + class Function; + class GlobalValue; + class Constant; + class TargetMachine; + class TargetJITInfo; + class MachineCodeEmitter; + class TraceFunction; + class UnpackTraceFunction; + + class TraceJIT : public ExecutionEngine { + TargetMachine &TM; // The current target we are compiling to + TargetJITInfo &TJI; // The TargetJITInfo for the current target + + FunctionPassManager PM; // Passes to compile a TraceFunction + MachineCodeEmitter *MCE; // Optimized trace code emitter + UnpackTraceFunction *UTF; // TraceFunction unpacker + + /// PendingGlobals - Global variables which have had memory allocated for them + /// while a function was code generated, but which have not been initialized + /// yet. + std::vector PendingGlobals; + + TraceJIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji); + public: + ~TraceJIT(); + + /// create - Create an return a new TraceJIT compiler if there is one available + /// for the current target. Otherwise, return null. If the TraceJIT is created + /// successfully, it takes responsibility for deleting the specified + /// IntrinsicLowering implementation. + /// + static TraceJIT *create(ModuleProvider *MP, IntrinsicLowering *IL = 0); + + /// run - Start execution with the specified function and arguments. + /// + virtual GenericValue runFunction(Function *F, + const std::vector &ArgValues); + + /// getPointerToNamedFunction - This method returns the address of the + /// specified function by using the dlsym function call. As such it is only + /// useful for resolving library symbols, not code generated symbols. + /// + void *getPointerToNamedFunction(const std::string &Name); + + // CompilationCallback - Invoked the first time that a call site is found, + // which causes lazy compilation of the target function. + // + static void CompilationCallback(); + + /// getPointerToFunction - This returns the address of the specified function, + /// compiling it if necessary. + /// + void *getPointerToFunction(Function *F); + + /// getOrEmitGlobalVariable - Return the address of the specified global + /// variable, possibly emitting it to memory if needed. This is used by the + /// Emitter. + void *getOrEmitGlobalVariable(const GlobalVariable *GV); + + /// getPointerToFunctionOrStub - If the specified function has been + /// code-gen'd, return a pointer to the function. If not, compile it, or use + /// a stub to implement lazy compilation if available. + /// + void *getPointerToFunctionOrStub(Function *F); + + /// recompileAndRelinkFunction - This method is used to force a function + /// which has already been compiled, to be compiled again, possibly + /// after it has been modified. Then the entry to the old copy is overwritten + /// with a branch to the new copy. If there was no old copy, this acts + /// just like TraceJIT::getPointerToFunction(). + /// + void *recompileAndRelinkFunction(Function *F); + + uint64_t compileTraceFunction (TraceFunction *TF); + + MachineCodeEmitter *getEmitter() { return MCE; } + private: + void addPassesToReoptimizeTrace (FunctionPassManager &PM); + void runJITOnFunction (Function *F); + }; + + } // End llvm namespace + + #endif Index: reopt/lib/TraceJIT/TraceJITEmitter.cpp diff -c /dev/null reopt/lib/TraceJIT/TraceJITEmitter.cpp:1.1 *** /dev/null Wed May 26 16:25:23 2004 --- reopt/lib/TraceJIT/TraceJITEmitter.cpp Wed May 26 16:25:13 2004 *************** *** 0 **** --- 1,212 ---- + //===-- TraceJITEmitter.cpp - Write machine code to executable memory -----===// + // + // 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. + // + //===----------------------------------------------------------------------===// + // + // The trace reoptimizer uses this MachineCodeEmitter to output + // optimized machine code to memory, so that it can be executed instead of + // the corresponding unoptimized code. + // + // Currently, it uses the same executable memory segment that the + // TraceCache would use, but the TraceCache is unaware of it, so they can + // not be used together. + // + //===----------------------------------------------------------------------===// + + #include "TraceJIT.h" + #include "reopt/ScratchMemory.h" + #include "reopt/VirtualMem.h" + #include "reopt/InstrUtils.h" + #include "../LightWtProfiling/ReoptimizerInternal.h" + #include "llvm/Constant.h" + #include "llvm/Module.h" + #include "llvm/CodeGen/MachineCodeEmitter.h" + #include "llvm/CodeGen/MachineFunction.h" + #include "llvm/CodeGen/MachineConstantPool.h" + #include "llvm/Target/TargetData.h" + #include "Support/Debug.h" + #include "Support/DynamicLinker.h" + using namespace llvm; + + namespace { + /// TraceJITEmitter - The trace reoptimizer's MachineCodeEmitter, + /// which is used to output functions to memory for execution. + /// + class TraceJITEmitter : public MachineCodeEmitter { + TraceJIT *TheJIT; + + // CurBlock - The start of the current block of memory. CurByte - The + // current byte being emitted to. + uint64_t CurBlock, CurByte; + uint64_t FunctionBase, CurFunctionPtr; + + // ConstantPoolAddresses - Contains the location for each entry in the + // constant pool. + std::vector ConstantPoolAddresses; + public: + TraceJITEmitter (TraceJIT *JIT_) : TheJIT (JIT_) { + // Re-use the existing DummyFunction area for code emission in the + // Reoptimizer. No memory is reserved for stubs. + FunctionBase = (uint64_t) OptimizedTraceTextArea; + // Allocate functions forward from the function base. + CurFunctionPtr = FunctionBase; + } + + virtual void startFunction(MachineFunction &F); + virtual void finishFunction(MachineFunction &F); + virtual void emitConstantPool(MachineConstantPool *MCP); + virtual void startFunctionStub(const Function &F, unsigned StubSize) { + abort (); + } + virtual void* finishFunctionStub(const Function &F) { + abort (); + } + virtual void emitByte(unsigned char B); + virtual void emitWord(unsigned W); + virtual void emitWordAt(unsigned W, unsigned *Ptr); + + virtual uint64_t getGlobalValueAddress(GlobalValue *V); + virtual uint64_t getGlobalValueAddress(const std::string &Name); + virtual uint64_t getConstantPoolEntryAddress(unsigned Entry); + virtual uint64_t getCurrentPCValue(); + + // forceCompilationOf - Force the compilation of the specified function, and + // return its address, because we REALLY need the address now. + // + // FIXME: This is JIT specific! + // + virtual uint64_t forceCompilationOf(Function *F); + }; + } // end anonymous namespace + + namespace llvm { + + MachineCodeEmitter *createTraceJITEmitter(TraceJIT *JIT) { + return new TraceJITEmitter(JIT); + } + + } // end namespace llvm + + void TraceJITEmitter::startFunction(MachineFunction &F) { + // Round up to a 64-bit word boundary. + CurBlock = (CurFunctionPtr + 7) & ~7; + CurByte = CurBlock; + + // Remember where we started generating this function. + TheJIT->addGlobalMapping(F.getFunction(), (void*)CurBlock); + } + + void TraceJITEmitter::finishFunction(MachineFunction &F) { + assert(CurByte > CurFunctionPtr); + CurFunctionPtr = CurByte; + + ConstantPoolAddresses.clear(); + + DEBUG(std::cerr << "Finished CodeGen of [" << (void*)CurBlock + << "] Function: " << F.getFunction()->getName() + << ": " << CurByte-CurBlock << " bytes of text\n"); + } + + void TraceJITEmitter::emitConstantPool(MachineConstantPool *MCP) { + const std::vector &Constants = MCP->getConstants(); + if (Constants.empty()) return; + + std::vector ConstantOffset; + ConstantOffset.reserve(Constants.size()); + + // Calculate how much space we will need for all the constants, and the offset + // each one will live in. + unsigned TotalSize = 0; + for (unsigned i = 0, e = Constants.size(); i != e; ++i) { + const Type *Ty = Constants[i]->getType(); + unsigned Size = TheJIT->getTargetData().getTypeSize(Ty); + unsigned Alignment = TheJIT->getTargetData().getTypeAlignment(Ty); + // Make sure to take into account the alignment requirements of the type. + TotalSize = (TotalSize + Alignment-1) & ~(Alignment-1); + + // Remember the offset this element lives at. + ConstantOffset.push_back(TotalSize); + TotalSize += Size; // Reserve space for the constant. + } + + // Now that we know how much memory to allocate, do so. + char *Pool = new char[TotalSize]; + + // Actually output all of the constants, and remember their addresses. + for (unsigned i = 0, e = Constants.size(); i != e; ++i) { + void *Addr = Pool + ConstantOffset[i]; + TheJIT->InitializeMemory(Constants[i], Addr); + ConstantPoolAddresses.push_back(Addr); + } + } + + void TraceJITEmitter::emitByte(unsigned char B) { + std::cerr << "TraceJITEmitter: attempt to emit a single byte: 0x" + << std::hex << (unsigned)B << std::dec << " at cursor: " + << CurByte << "\n"; + abort (); + // *CurByte = W; + ++CurByte; + } + + void TraceJITEmitter::emitWord(unsigned W) { + // This won't work if the endianness of the host and target don't agree! (For + // a JIT this can't happen though. :) + DEBUG (std::cerr << "TraceJITEmitter: emitting word 0x" << std::hex << W + << " at cursor: " << CurByte << std::dec << "\n"); + vm->writeInstToVM (CurByte, W); // does: *(unsigned*)CurByte = W; + doFlush (CurByte - sizeof (unsigned), (uint64_t) CurByte + sizeof (unsigned)); + CurByte += sizeof(unsigned); + } + + void TraceJITEmitter::emitWordAt(unsigned W, unsigned *Ptr) { + DEBUG (std::cerr << "TraceJITEmitter: emitting word 0x" << std::hex << W + << std::dec << " at pointer: " << Ptr << "\n"); + vm->writeInstToVM ((uint64_t) Ptr, W); // does: *Ptr = W; + doFlush ((uint64_t) Ptr - sizeof (unsigned), + (uint64_t) Ptr + sizeof (unsigned)); + } + + uint64_t TraceJITEmitter::getGlobalValueAddress(GlobalValue *V) { + // Try looking up the function to see if it is already compiled, if not return + // 0. + if (isa(V)) { + if (V->hasName ()) { + uint64_t where = (uint64_t) GetAddressOfSymbol (V->getName ()); + if (where) + return where; + } + return (uint64_t)TheJIT->getPointerToGlobalIfAvailable(V); + } else { + return (uint64_t)TheJIT->getOrEmitGlobalVariable(cast(V)); + } + } + + uint64_t TraceJITEmitter::getGlobalValueAddress(const std::string &Name) { + return (uint64_t)TheJIT->getPointerToNamedFunction(Name); + } + + // getConstantPoolEntryAddress - Return the address of the 'ConstantNum' entry + // in the constant pool that was last emitted with the 'emitConstantPool' + // method. + // + uint64_t TraceJITEmitter::getConstantPoolEntryAddress(unsigned ConstantNum) { + assert(ConstantNum < ConstantPoolAddresses.size() && + "Invalid ConstantPoolIndex!"); + return (uint64_t)ConstantPoolAddresses[ConstantNum]; + } + + // getCurrentPCValue - This returns the address that the next emitted byte + // will be output to. + // + uint64_t TraceJITEmitter::getCurrentPCValue() { + return CurByte; + } + + uint64_t TraceJITEmitter::forceCompilationOf(Function *F) { + return (uint64_t)TheJIT->getPointerToFunction(F); + } Index: reopt/lib/TraceJIT/TraceJITIntercept.cpp diff -c /dev/null reopt/lib/TraceJIT/TraceJITIntercept.cpp:1.1 *** /dev/null Wed May 26 16:25:23 2004 --- reopt/lib/TraceJIT/TraceJITIntercept.cpp Wed May 26 16:25:13 2004 *************** *** 0 **** --- 1,91 ---- + //===-- Intercept.cpp - System function interception routines -------------===// + // + // 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. + // + //===----------------------------------------------------------------------===// + // + // If a function call occurs to an external function, the TraceJIT is designed to use + // the dynamic loader interface to find a function to call. This is useful for + // calling system calls and library functions that are not available in LLVM. + // Some system calls, however, need to be handled specially. For this reason, + // we intercept some of them here and use our own stubs to handle them. + // + //===----------------------------------------------------------------------===// + + #include "TraceJIT.h" + #include "Support/DynamicLinker.h" + #include + #include + using namespace llvm; + + // AtExitHandlers - List of functions to call when the program exits, + // registered with the atexit() library function. + static std::vector AtExitHandlers; + + /// runAtExitHandlers - Run any functions registered by the program's + /// calls to atexit(3), which we intercept and store in + /// AtExitHandlers. + /// + static void runAtExitHandlers() { + while (!AtExitHandlers.empty()) { + void (*Fn)() = AtExitHandlers.back(); + AtExitHandlers.pop_back(); + Fn(); + } + } + + //===----------------------------------------------------------------------===// + // Function stubs that are invoked instead of certain library calls + //===----------------------------------------------------------------------===// + + // Force the following functions to be linked in to anything that uses the + // TraceJIT. This is a hack designed to work around the all-too-clever Glibc + // strategy of making these functions work differently when inlined vs. when + // not inlined, and hiding their real definitions in a separate archive file + // that the dynamic linker can't see. For more info, search for + // 'libc_nonshared.a' on Google, or read http://llvm.cs.uiuc.edu/PR274. + #if defined(__linux__) + void *FunctionPointers[] = { + (void *) stat, + (void *) fstat, + (void *) lstat, + (void *) stat64, + (void *) fstat64, + (void *) lstat64, + (void *) atexit, + (void *) mknod + }; + #endif // __linux__ + + // NoopFn - Used if we have nothing else to call... + static void NoopFn() {} + + // jit_exit - Used to intercept the "exit" library call. + static void jit_exit(int Status) { + runAtExitHandlers(); // Run atexit handlers... + exit(Status); + } + + // jit_atexit - Used to intercept the "atexit" library call. + static int jit_atexit(void (*Fn)(void)) { + AtExitHandlers.push_back(Fn); // Take note of atexit handler... + return 0; // Always successful + } + + //===----------------------------------------------------------------------===// + // + /// getPointerToNamedFunction - This method returns the address of the specified + /// function by using the dynamic loader interface. As such it is only useful + /// for resolving library symbols, not code generated symbols. + /// + void *TraceJIT::getPointerToNamedFunction(const std::string &Name) { + // Check to see if this is one of the functions we want to intercept... + if (Name == "exit") return (void*)&jit_exit; + if (Name == "atexit") return (void*)&jit_atexit; + + // Try to look it up in the process image. + return GetAddressOfSymbol(Name); + } From alkis at cs.uiuc.edu Wed May 26 16:41:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 16:41:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp Message-ID: <200405262138.QAA30910@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: UnifyFunctionExitNodes.cpp updated: 1.29 -> 1.30 --- Log message: Use one destination constructor for the unconditional branch. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp diff -u llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp:1.29 llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp:1.30 --- llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp:1.29 Fri Nov 21 10:52:03 2003 +++ llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp Wed May 26 16:38:14 2004 @@ -66,7 +66,7 @@ E = UnwindingBlocks.end(); I != E; ++I) { BasicBlock *BB = *I; BB->getInstList().pop_back(); // Remove the return insn - new BranchInst(UnwindBlock, 0, 0, BB); + new BranchInst(UnwindBlock, BB); } } From alkis at cs.uiuc.edu Wed May 26 16:44:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 16:44:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/iSwitch.cpp iMemory.cpp iCall.cpp iBranch.cpp Instruction.cpp InstrTypes.cpp Message-ID: <200405262141.QAA31006@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: iSwitch.cpp updated: 1.11 -> 1.12 iMemory.cpp updated: 1.38 -> 1.39 iCall.cpp updated: 1.23 -> 1.24 iBranch.cpp updated: 1.12 -> 1.13 Instruction.cpp updated: 1.35 -> 1.36 InstrTypes.cpp updated: 1.24 -> 1.25 --- Log message: Refactor common initialization code in private init() functions. This is a first step in supplying append to basic block constructors for all instruction types. --- Diffs of the changes: (+96 -98) Index: llvm/lib/VMCore/iSwitch.cpp diff -u llvm/lib/VMCore/iSwitch.cpp:1.11 llvm/lib/VMCore/iSwitch.cpp:1.12 --- llvm/lib/VMCore/iSwitch.cpp:1.11 Thu Nov 20 11:45:12 2003 +++ llvm/lib/VMCore/iSwitch.cpp Wed May 26 16:41:09 2004 @@ -15,20 +15,22 @@ #include "llvm/BasicBlock.h" using namespace llvm; -SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest, +void SwitchInst::init(Value *Value, BasicBlock *Default) +{ + assert(Value && Default); + Operands.push_back(Use(Value, this)); + Operands.push_back(Use(Default, this)); +} + +SwitchInst::SwitchInst(Value *V, BasicBlock *D, Instruction *InsertBefore) : TerminatorInst(Instruction::Switch, InsertBefore) { - assert(V && DefaultDest); - Operands.push_back(Use(V, this)); - Operands.push_back(Use(DefaultDest, this)); + init(V, D); } -SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest, - BasicBlock *InsertAtEnd) +SwitchInst::SwitchInst(Value *V, BasicBlock *D, BasicBlock *InsertAtEnd) : TerminatorInst(Instruction::Switch, InsertAtEnd) { - assert(V && DefaultDest); - Operands.push_back(Use(V, this)); - Operands.push_back(Use(DefaultDest, this)); + init(V, D); } SwitchInst::SwitchInst(const SwitchInst &SI) Index: llvm/lib/VMCore/iMemory.cpp diff -u llvm/lib/VMCore/iMemory.cpp:1.38 llvm/lib/VMCore/iMemory.cpp:1.39 --- llvm/lib/VMCore/iMemory.cpp:1.38 Thu May 6 17:15:47 2004 +++ llvm/lib/VMCore/iMemory.cpp Wed May 26 16:41:09 2004 @@ -67,16 +67,14 @@ LoadInst::LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBef) : Instruction(cast(Ptr->getType())->getElementType(), Load, Name, InsertBef), Volatile(false) { - Operands.reserve(1); - Operands.push_back(Use(Ptr, this)); + init(Ptr); } LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, Instruction *InsertBef) : Instruction(cast(Ptr->getType())->getElementType(), Load, Name, InsertBef), Volatile(isVolatile) { - Operands.reserve(1); - Operands.push_back(Use(Ptr, this)); + init(Ptr); } //===----------------------------------------------------------------------===// @@ -85,19 +83,13 @@ StoreInst::StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore) : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(false) { - - Operands.reserve(2); - Operands.push_back(Use(Val, this)); - Operands.push_back(Use(Ptr, this)); + init(Val, Ptr); } StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile, Instruction *InsertBefore) : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) { - - Operands.reserve(2); - Operands.push_back(Use(Val, this)); - Operands.push_back(Use(Ptr, this)); + init(Val, Ptr); } @@ -113,16 +105,21 @@ return Ty; } -GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector &Idx, - const std::string &Name, Instruction *InBe) - : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), - Idx, true))), - GetElementPtr, Name, InBe) { +void GetElementPtrInst::init(Value *Ptr, const std::vector &Idx) +{ Operands.reserve(1+Idx.size()); Operands.push_back(Use(Ptr, this)); for (unsigned i = 0, E = Idx.size(); i != E; ++i) Operands.push_back(Use(Idx[i], this)); +} + +GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector &Idx, + const std::string &Name, Instruction *InBe) + : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), + Idx, true))), + GetElementPtr, Name, InBe) { + init(Ptr, Idx); } // getIndexedType - Returns the type of the element that would be loaded with Index: llvm/lib/VMCore/iCall.cpp diff -u llvm/lib/VMCore/iCall.cpp:1.23 llvm/lib/VMCore/iCall.cpp:1.24 --- llvm/lib/VMCore/iCall.cpp:1.23 Sun Feb 8 22:14:01 2004 +++ llvm/lib/VMCore/iCall.cpp Wed May 26 16:41:09 2004 @@ -99,51 +99,42 @@ // InvokeInst Implementation //===----------------------------------------------------------------------===// -InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal, - BasicBlock *IfException, - const std::vector ¶ms, - const std::string &Name, Instruction *InsertBefore) - : TerminatorInst(cast(cast(Func->getType()) - ->getElementType())->getReturnType(), - Instruction::Invoke, Name, InsertBefore) { - Operands.reserve(3+params.size()); - Operands.push_back(Use(Func, this)); +void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, + const std::vector &Params) +{ + Operands.reserve(3+Params.size()); + Operands.push_back(Use(Fn, this)); Operands.push_back(Use((Value*)IfNormal, this)); Operands.push_back(Use((Value*)IfException, this)); const FunctionType *MTy = - cast(cast(Func->getType())->getElementType()); + cast(cast(Fn->getType())->getElementType()); - assert((params.size() == MTy->getNumParams()) || - (MTy->isVarArg() && params.size() > MTy->getNumParams()) && + assert((Params.size() == MTy->getNumParams()) || + (MTy->isVarArg() && Params.size() > MTy->getNumParams()) && "Calling a function with bad signature"); - for (unsigned i = 0; i < params.size(); i++) - Operands.push_back(Use(params[i], this)); + for (unsigned i = 0; i < Params.size(); i++) + Operands.push_back(Use(Params[i], this)); } -InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal, +InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, - const std::vector ¶ms, - const std::string &Name, BasicBlock *InsertAtEnd) - : TerminatorInst(cast(cast(Func->getType()) + const std::vector &Params, + const std::string &Name, Instruction *InsertBefore) + : TerminatorInst(cast(cast(Fn->getType()) ->getElementType())->getReturnType(), - Instruction::Invoke, Name) { - Operands.reserve(3+params.size()); - Operands.push_back(Use(Func, this)); - Operands.push_back(Use((Value*)IfNormal, this)); - Operands.push_back(Use((Value*)IfException, this)); - const FunctionType *MTy = - cast(cast(Func->getType())->getElementType()); - - assert((params.size() == MTy->getNumParams()) || - (MTy->isVarArg() && params.size() > MTy->getNumParams()) && - "Calling a function with bad signature"); - - for (unsigned i = 0; i < params.size(); i++) - Operands.push_back(Use(params[i], this)); + Instruction::Invoke, Name, InsertBefore) { + init(Fn, IfNormal, IfException, Params); +} - if (InsertAtEnd) - InsertAtEnd->getInstList().push_back(this); +InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal, + BasicBlock *IfException, + const std::vector &Params, + const std::string &Name, BasicBlock *InsertAtEnd) + : TerminatorInst(cast(cast(Fn->getType()) + ->getElementType())->getReturnType(), + Instruction::Invoke, Name, InsertAtEnd) { + init(Fn, IfNormal, IfException, Params); } InvokeInst::InvokeInst(const InvokeInst &CI) Index: llvm/lib/VMCore/iBranch.cpp diff -u llvm/lib/VMCore/iBranch.cpp:1.12 llvm/lib/VMCore/iBranch.cpp:1.13 --- llvm/lib/VMCore/iBranch.cpp:1.12 Thu Nov 20 12:11:56 2003 +++ llvm/lib/VMCore/iBranch.cpp Wed May 26 16:41:09 2004 @@ -28,52 +28,45 @@ assert(0 && "UnwindInst has no successors!"); } +void BranchInst::init(BasicBlock *IfTrue) +{ + assert(IfTrue != 0 && "Branch destination may not be null!"); + Operands.reserve(1); + Operands.push_back(Use(IfTrue, this)); +} + +void BranchInst::init(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond) +{ + assert(IfTrue && IfFalse && Cond && + "Branch destinations and condition may not be null!"); + assert(Cond && Cond->getType() == Type::BoolTy && + "May only branch on boolean predicates!"); + Operands.reserve(3); + Operands.push_back(Use(IfTrue, this)); + Operands.push_back(Use(IfFalse, this)); + Operands.push_back(Use(Cond, this)); +} + BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond, Instruction *InsertBefore) : TerminatorInst(Instruction::Br, InsertBefore) { - assert(True != 0 && "True branch destination may not be null!!!"); - Operands.reserve(False ? 3 : 1); - Operands.push_back(Use(True, this)); - if (False) { - Operands.push_back(Use(False, this)); - Operands.push_back(Use(Cond, this)); - } - - assert(!!False == !!Cond && - "Either both cond and false or neither can be specified!"); - assert((Cond == 0 || Cond->getType() == Type::BoolTy) && - "May only branch on boolean predicates!!!!"); + init(True, False, Cond); } BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond, BasicBlock *InsertAtEnd) : TerminatorInst(Instruction::Br, InsertAtEnd) { - assert(True != 0 && "True branch destination may not be null!!!"); - Operands.reserve(False ? 3 : 1); - Operands.push_back(Use(True, this)); - if (False) { - Operands.push_back(Use(False, this)); - Operands.push_back(Use(Cond, this)); - } - - assert(!!False == !!Cond && - "Either both cond and false or neither can be specified!"); - assert((Cond == 0 || Cond->getType() == Type::BoolTy) && - "May only branch on boolean predicates!!!!"); + init(True, False, Cond); } BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore) : TerminatorInst(Instruction::Br, InsertBefore) { - assert(True != 0 && "True branch destination may not be null!!!"); - Operands.reserve(1); - Operands.push_back(Use(True, this)); + init(True); } BranchInst::BranchInst(BasicBlock *True, BasicBlock *InsertAtEnd) : TerminatorInst(Instruction::Br, InsertAtEnd) { - assert(True != 0 && "True branch destination may not be null!!!"); - Operands.reserve(1); - Operands.push_back(Use(True, this)); + init(True); } BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) { Index: llvm/lib/VMCore/Instruction.cpp diff -u llvm/lib/VMCore/Instruction.cpp:1.35 llvm/lib/VMCore/Instruction.cpp:1.36 --- llvm/lib/VMCore/Instruction.cpp:1.35 Thu Mar 11 23:54:20 2004 +++ llvm/lib/VMCore/Instruction.cpp Wed May 26 16:41:09 2004 @@ -17,14 +17,18 @@ #include "Support/LeakDetector.h" using namespace llvm; -Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name, - Instruction *InsertBefore) - : User(ty, Value::InstructionVal, Name) { - Parent = 0; - iType = it; - +void Instruction::init() +{ // Make sure that we get added to a basicblock LeakDetector::addGarbageObject(this); +} + +Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name, + Instruction *InsertBefore) + : User(ty, Value::InstructionVal, Name), + Parent(0), + iType(it) { + init(); // If requested, insert this instruction into a basic block... if (InsertBefore) { @@ -32,6 +36,18 @@ "Instruction to insert before is not in a basic block!"); InsertBefore->getParent()->getInstList().insert(InsertBefore, this); } +} + +Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name, + BasicBlock *InsertAtEnd) + : User(ty, Value::InstructionVal, Name), + Parent(0), + iType(it) { + init(); + + // append this instruction into the basic block + assert(InsertAtEnd && "Basic block to append to may not be NULL!"); + InsertAtEnd->getInstList().push_back(this); } void Instruction::setParent(BasicBlock *P) { Index: llvm/lib/VMCore/InstrTypes.cpp diff -u llvm/lib/VMCore/InstrTypes.cpp:1.24 llvm/lib/VMCore/InstrTypes.cpp:1.25 --- llvm/lib/VMCore/InstrTypes.cpp:1.24 Thu Nov 20 11:45:12 2003 +++ llvm/lib/VMCore/InstrTypes.cpp Wed May 26 16:41:09 2004 @@ -29,8 +29,7 @@ } TerminatorInst::TerminatorInst(Instruction::TermOps iType, BasicBlock *IAE) - : Instruction(Type::VoidTy, iType) { - if (IAE) IAE->getInstList().push_back(this); + : Instruction(Type::VoidTy, iType, "", IAE) { } From alkis at cs.uiuc.edu Wed May 26 16:45:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 16:45:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/iTerminators.h iMemory.h Instruction.h InstrTypes.h Message-ID: <200405262141.QAA31009@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: iTerminators.h updated: 1.40 -> 1.41 iMemory.h updated: 1.44 -> 1.45 Instruction.h updated: 1.52 -> 1.53 InstrTypes.h updated: 1.36 -> 1.37 --- Log message: Refactor common initialization code in private init() functions. This is a first step in supplying append to basic block constructors for all instruction types. --- Diffs of the changes: (+37 -10) Index: llvm/include/llvm/iTerminators.h diff -u llvm/include/llvm/iTerminators.h:1.40 llvm/include/llvm/iTerminators.h:1.41 --- llvm/include/llvm/iTerminators.h:1.40 Thu Feb 26 17:20:29 2004 +++ llvm/include/llvm/iTerminators.h Wed May 26 16:41:09 2004 @@ -32,6 +32,14 @@ Operands.push_back(Use(RI.Operands[0], this)); } } + + void init(Value *RetVal) { + if (RetVal) { + Operands.reserve(1); + Operands.push_back(Use(RetVal, this)); + } + } + public: // ReturnInst constructors: // ReturnInst() - 'ret void' instruction @@ -42,17 +50,11 @@ // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0) : TerminatorInst(Instruction::Ret, InsertBefore) { - if (RetVal) { - Operands.reserve(1); - Operands.push_back(Use(RetVal, this)); - } + init(RetVal); } ReturnInst(Value *RetVal, BasicBlock *InsertAtEnd) : TerminatorInst(Instruction::Ret, InsertAtEnd) { - if (RetVal) { - Operands.reserve(1); - Operands.push_back(Use(RetVal, this)); - } + init(RetVal); } virtual Instruction *clone() const { return new ReturnInst(*this); } @@ -87,6 +89,8 @@ /// class BranchInst : public TerminatorInst { BranchInst(const BranchInst &BI); + void init(BasicBlock *IfTrue); + void init(BasicBlock *True, BasicBlock *False, Value *Cond); public: // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): // BranchInst(BB *B) - 'br B' @@ -161,6 +165,8 @@ // Operand[2n ] = Value to match // Operand[2n+1] = BasicBlock to go to on match SwitchInst(const SwitchInst &RI); + void init(Value *Value, BasicBlock *Default); + public: SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0); SwitchInst(Value *Value, BasicBlock *Default, BasicBlock *InsertAtEnd); @@ -259,6 +265,8 @@ /// class InvokeInst : public TerminatorInst { InvokeInst(const InvokeInst &BI); + void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, + const std::vector &Params); public: InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, const std::vector &Params, const std::string &Name = "", Index: llvm/include/llvm/iMemory.h diff -u llvm/include/llvm/iMemory.h:1.44 llvm/include/llvm/iMemory.h:1.45 --- llvm/include/llvm/iMemory.h:1.44 Tue Feb 10 12:44:16 2004 +++ llvm/include/llvm/iMemory.h Wed May 26 16:41:09 2004 @@ -163,6 +163,10 @@ Operands.push_back(Use(LI.Operands[0], this)); } bool Volatile; // True if this is a volatile load + void init(Value *Ptr) { + Operands.reserve(1); + Operands.push_back(Use(Ptr, this)); + } public: LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore); LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false, @@ -210,6 +214,11 @@ Operands.push_back(Use(SI.Operands[1], this)); } bool Volatile; // True if this is a volatile store + void init(Value *Val, Value *Ptr) { + Operands.reserve(2); + Operands.push_back(Use(Val, this)); + Operands.push_back(Use(Ptr, this)); + } public: StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, @@ -258,6 +267,8 @@ for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i) Operands.push_back(Use(EPI.Operands[i], this)); } + void init(Value *Ptr, const std::vector &Idx); + public: GetElementPtrInst(Value *Ptr, const std::vector &Idx, const std::string &Name = "", Instruction *InsertBefore =0); Index: llvm/include/llvm/Instruction.h diff -u llvm/include/llvm/Instruction.h:1.52 llvm/include/llvm/Instruction.h:1.53 --- llvm/include/llvm/Instruction.h:1.52 Fri Apr 16 10:46:43 2004 +++ llvm/include/llvm/Instruction.h Wed May 26 16:41:09 2004 @@ -36,11 +36,15 @@ friend class SymbolTableListTraits >; void setParent(BasicBlock *P); + void init(); + protected: unsigned iType; // InstructionType: The opcode of the instruction Instruction(const Type *Ty, unsigned iType, const std::string &Name = "", Instruction *InsertBefore = 0); + Instruction(const Type *Ty, unsigned iType, const std::string &Name, + BasicBlock *InsertAtEnd); public: ~Instruction() { Index: llvm/include/llvm/InstrTypes.h diff -u llvm/include/llvm/InstrTypes.h:1.36 llvm/include/llvm/InstrTypes.h:1.37 --- llvm/include/llvm/InstrTypes.h:1.36 Thu Nov 20 11:44:37 2003 +++ llvm/include/llvm/InstrTypes.h Wed May 26 16:41:09 2004 @@ -32,9 +32,13 @@ TerminatorInst(Instruction::TermOps iType, Instruction *InsertBefore = 0); TerminatorInst(const Type *Ty, Instruction::TermOps iType, const std::string &Name = "", Instruction *InsertBefore = 0) - : Instruction(Ty, iType, Name, InsertBefore) { - } + : Instruction(Ty, iType, Name, InsertBefore) {} + TerminatorInst(Instruction::TermOps iType, BasicBlock *InsertAtEnd); + TerminatorInst(const Type *Ty, Instruction::TermOps iType, + const std::string &Name, BasicBlock *InsertAtEnd) + : Instruction(Ty, iType, Name, InsertAtEnd) {} + public: /// Terminators must implement the methods required by Instruction... From llvm at cs.uiuc.edu Wed May 26 16:49:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Wed May 26 16:49:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/SymbolTable.h Message-ID: <200405262146.QAA31074@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: SymbolTable.h updated: 1.32 -> 1.33 --- Log message: Tighten up checking on SymbolTable interface to make it illegal to pass a Type* where a Value* is expected. --- Diffs of the changes: (+4 -2) Index: llvm/include/llvm/SymbolTable.h diff -u llvm/include/llvm/SymbolTable.h:1.32 llvm/include/llvm/SymbolTable.h:1.33 --- llvm/include/llvm/SymbolTable.h:1.32 Wed May 26 12:42:51 2004 +++ llvm/include/llvm/SymbolTable.h Wed May 26 16:46:18 2004 @@ -165,8 +165,9 @@ /// @brief Insert a constant or type. inline void insert(const std::string &Name, Value *Val) { assert(Val && "Can't insert null type into symbol table!"); - assert((isa(Val) || isa(Val)) && - "Can only insert types and constants into a symbol table!"); + assert(!isa(Val) && "Cannot insert types with this interface!"); + assert(isa(Val) && + "Can only insert constants into a symbol table!"); insertEntry(Name, Val->getType(), Val); } @@ -201,6 +202,7 @@ /// @brief Remove a constant or type from the symbol table. inline Value* remove(const std::string &Name, Value *Val) { assert(Val && "Can't remove null value from symbol table!"); + assert(!isa(Val) && "Can't remove types with this interface!"); plane_iterator PI = pmap.find(Val->getType()); return removeEntry(PI, PI->second.find(Name)); } From llvm at cs.uiuc.edu Wed May 26 16:52:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Wed May 26 16:52:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Type.h Message-ID: <200405262148.QAA31104@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: Type.h updated: 1.43 -> 1.44 --- Log message: Provide the correct patch for bug 345: http://llvm.cs.uiuc.edu/PR345 . The solution is to add a setTypeName function to llvmAsmParser.y and then use it in the one place in the grammar that needs it. Also had to make Type::setName public because setTypeName needs it in order to retain compatibility with setValueName. --- Diffs of the changes: (+5 -4) Index: llvm/include/llvm/Type.h diff -u llvm/include/llvm/Type.h:1.43 llvm/include/llvm/Type.h:1.44 --- llvm/include/llvm/Type.h:1.43 Tue May 25 03:46:04 2004 +++ llvm/include/llvm/Type.h Wed May 26 16:48:31 2004 @@ -96,10 +96,6 @@ Type(const std::string &Name, PrimitiveID id); virtual ~Type() {} - /// setName - Associate the name with this type in the symbol table, but don't - /// set the local name to be equal specified name. - /// - virtual void setName(const std::string &Name, SymbolTable *ST = 0); /// Types can become nonabstract later, if they are refined. /// @@ -130,6 +126,11 @@ /// @brief Debugging support: print to stderr virtual void dump() const; + + /// setName - Associate the name with this type in the symbol table, but don't + /// set the local name to be equal specified name. + /// + virtual void setName(const std::string &Name, SymbolTable *ST = 0); //===--------------------------------------------------------------------===// // Property accessors for dealing with types... Some of these virtual methods From llvm at cs.uiuc.edu Wed May 26 16:52:12 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Wed May 26 16:52:12 2004 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y Message-ID: <200405262148.QAA31097@zion.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: llvmAsmParser.y updated: 1.165 -> 1.166 --- Log message: Provide the correct patch for bug 345: http://llvm.cs.uiuc.edu/PR345 . The solution is to add a setTypeName function to llvmAsmParser.y and then use it in the one place in the grammar that needs it. Also had to make Type::setName public because setTypeName needs it in order to retain compatibility with setValueName. --- Diffs of the changes: (+68 -7) Index: llvm/lib/AsmParser/llvmAsmParser.y diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.165 llvm/lib/AsmParser/llvmAsmParser.y:1.166 --- llvm/lib/AsmParser/llvmAsmParser.y:1.165 Wed May 26 12:08:25 2004 +++ llvm/lib/AsmParser/llvmAsmParser.y Wed May 26 16:48:31 2004 @@ -502,6 +502,7 @@ // for the typeplane, false is returned. // static bool setValueName(Value *V, char *NameStr) { + assert(!isa(V) && "Can't set name of a Type with setValueName"); if (NameStr == 0) return false; std::string Name(NameStr); // Copy string @@ -515,12 +516,7 @@ CurFun.CurrentFunction->getSymbolTable() : CurModule.CurrentModule->getSymbolTable(); - Value *Existing; - // FIXME: this is really gross - if (V->getType() != Type::TypeTy) - Existing = ST.lookup(V->getType(), Name); - else - Existing = ST.lookupType(Name); + Value *Existing = ST.lookup(V->getType(), Name); if (Existing) { // Inserting a name that is already defined??? // There is only one case where this is allowed: when we are refining an @@ -591,6 +587,71 @@ return false; } +// setTypeName - Set the specified type to the name given. The name may be +// null potentially, in which case this is a noop. The string passed in is +// assumed to be a malloc'd string buffer, and is freed by this function. +// +// This function returns true if the type has already been defined, but is +// allowed to be redefined in the specified context. If the name is a new name +// for the type plane, it is inserted and false is returned. +static bool setTypeName(Type *T, char *NameStr) { + if (NameStr == 0) return false; + + std::string Name(NameStr); // Copy string + free(NameStr); // Free old string + + // We don't allow assigning names to void type + if (T == Type::VoidTy) + ThrowException("Can't assign name '" + Name + "' to the null type!"); + + SymbolTable &ST = inFunctionScope() ? + CurFun.CurrentFunction->getSymbolTable() : + CurModule.CurrentModule->getSymbolTable(); + + Type *Existing = ST.lookupType(Name); + + if (Existing) { // Inserting a name that is already defined??? + // There is only one case where this is allowed: when we are refining an + // opaque type. In this case, Existing will be an opaque type. + if (const OpaqueType *OpTy = dyn_cast(Existing)) { + // We ARE replacing an opaque type! + ((OpaqueType*)OpTy)->refineAbstractTypeTo(T); + return true; + } + + // Otherwise, this is an attempt to redefine a type. That's okay if + // the redefinition is identical to the original. This will be so if + // Existing and T point to the same Type object. In this one case we + // allow the equivalent redefinition. + if (Existing == T) return true; // Yes, it's equal. + + // Any other kind of (non-equivalent) redefinition is an error. + ThrowException("Redefinition of type named '" + Name + "' in the '" + + T->getDescription() + "' type plane!"); + } + + // Okay, its a newly named type. Set its name. + T->setName(Name,&ST); + + // If we're in function scope + if (inFunctionScope()) { + // Look up the symbol in the function's local symboltable + Existing = CurFun.LocalSymtab.lookupType(Name); + + // If it already exists + if (Existing) { + // Bail + ThrowException("Redefinition of type named '" + Name + "' in the '" + + T->getDescription() + "' type plane in function scope!"); + + // otherwise, since it doesn't exist + } else { + // Insert it. + CurFun.LocalSymtab.insert(Name,T); + } + } + return false; +} //===----------------------------------------------------------------------===// // Code for handling upreferences in type names... @@ -1352,7 +1413,7 @@ ResolveTypeTo($2, $4->get()); // TODO: FIXME when Type are not const - if (!setValueName(const_cast($4->get()), $2)) { + if (!setTypeName(const_cast($4->get()), $2)) { // If this is not a redefinition of a type... if (!$2) { InsertType($4->get(), From llvm at cs.uiuc.edu Wed May 26 16:59:02 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Wed May 26 16:59:02 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200405262156.QAA31193@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.131 -> 1.132 --- Log message: Several clean ups suggested by Chris: remove tabs, make SlotMachine do lazy initialization so we don't scan large Modules/Functions needlessly, tighten up restrictions on what can be put in SlotMachine (no Constants that aren't GlobalValues). --- Diffs of the changes: (+97 -94) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.131 llvm/lib/VMCore/AsmWriter.cpp:1.132 --- llvm/lib/VMCore/AsmWriter.cpp:1.131 Wed May 26 02:18:52 2004 +++ llvm/lib/VMCore/AsmWriter.cpp Wed May 26 16:56:09 2004 @@ -74,7 +74,7 @@ /// Return the slot number of the specified value in it's type /// plane. Its an error to ask for something not in the SlotMachine. /// Its an error to ask for a Type* - unsigned getSlot(const Value *V) const; + unsigned getSlot(const Value *V) ; /// @} /// @name Mutators @@ -82,7 +82,7 @@ public: /// If you'd like to deal with a function instead of just a module, use /// this method to get its data into the SlotMachine. - void incorporateFunction(const Function *F); + void incorporateFunction(const Function *F) { TheFunction = F; } /// After calling incorporateFunction, use this method to remove the /// most recently incorporated function from the SlotMachine. This @@ -93,6 +93,9 @@ /// @name Implementation Details /// @{ private: + /// This function does the actual initialization. + inline void initialize(); + /// Values can be crammed into here at will. If they haven't /// been inserted already, they get inserted, otherwise they are ignored. /// Either way, the slot number for the Value* is returned. @@ -107,6 +110,9 @@ /// and function declarations, but not the contents of those functions. void processModule(); + /// Add all of the functions arguments, basic blocks, and instructions + void processFunction(); + SlotMachine(const SlotMachine &); // DO NOT IMPLEMENT void operator=(const SlotMachine &); // DO NOT IMPLEMENT @@ -116,10 +122,10 @@ public: /// @brief The module for which we are holding slot numbers - const Module *TheModule; + const Module* TheModule; - /// @brief Whether or not we have a function incorporated - bool FunctionIncorporated; + /// @brief The function for which we are holding slot numbers + const Function* TheFunction; /// @brief The TypePlanes map for the module level data TypedPlanes mMap; @@ -210,8 +216,8 @@ // const Type *Ty = cast(TI->second); if (!isa(Ty) || - !cast(Ty)->getElementType()->isPrimitiveType() || - isa(cast(Ty)->getElementType())) + !cast(Ty)->getElementType()->isPrimitiveType() || + isa(cast(Ty)->getElementType())) TypeNames.insert(std::make_pair(Ty, getLLVMName(TI->first))); } } @@ -494,7 +500,7 @@ } else { int Slot; if (Machine) { - Slot = Machine->getSlot(V); + Slot = Machine->getSlot(V); } else { if (const Type *Ty = dyn_cast(V)) { Out << Ty->getDescription(); @@ -504,8 +510,8 @@ Machine = createSlotMachine(V); if (Machine == 0) { Out << "BAD VALUE TYPE!"; return; } - Slot = Machine->getSlot(V); - delete Machine; + Slot = Machine->getSlot(V); + delete Machine; } Out << "%" << Slot; } @@ -639,7 +645,7 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType, - bool PrintName) { + bool PrintName) { if (PrintType) { *Out << " "; printType(Operand->getType()); } WriteAsOperandInternal(*Out, Operand, PrintName, TypeNames, &Machine); } @@ -719,7 +725,7 @@ for (; VI != VE; ++VI) { const Value *V = VI->second; if (const Constant *CPV = dyn_cast(V)) { - printConstant(CPV); + printConstant(CPV); } } } @@ -1168,26 +1174,30 @@ // Module level constructor. Causes the contents of the Module (sans functions) // to be added to the slot table. SlotMachine::SlotMachine(const Module *M) - : TheModule(M) - , FunctionIncorporated(false) + : TheModule(M) ///< Saved for lazy initialization. + , TheFunction(0) , mMap() , fMap() { - if ( M != 0 ) - processModule(); } // Function level constructor. Causes the contents of the Module and the one // function provided to be added to the slot table. SlotMachine::SlotMachine(const Function *F ) - : TheModule( F ? F->getParent() : 0 ) - , FunctionIncorporated(true) + : TheModule( F ? F->getParent() : 0 ) ///< Saved for lazy initialization + , TheFunction(F) ///< Saved for lazy initialization , mMap() , fMap() { - if ( TheModule ) { - processModule(); // Process module level stuff - incorporateFunction(F); // Start out in incorporated state +} + +inline void SlotMachine::initialize(void) { + if ( TheModule) { + processModule(); + TheModule = 0; ///< Prevent re-processing next time we're called. + } + if ( TheFunction ) { + processFunction(); } } @@ -1206,32 +1216,24 @@ I != E; ++I) createSlot(I); - // Add all of the module level constants used as initializers - for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend(); - I != E; ++I) - if (I->hasInitializer()) - createSlot(I->getInitializer()); - SC_DEBUG("end processModule!\n"); } -// Incorporate the arguments, basic blocks, and instructions of a function. -// This is the *only* way to get the FunctionIncorporated flag set. -void SlotMachine::incorporateFunction(const Function *F) { +// Process the arguments, basic blocks, and instructions of a function. +void SlotMachine::processFunction() { SC_DEBUG("begin processFunction!\n"); - FunctionIncorporated = true; - // Add all the function arguments - for(Function::const_aiterator AI = F->abegin(), - AE = F->aend(); AI != AE; ++AI) + for(Function::const_aiterator AI = TheFunction->abegin(), + AE = TheFunction->aend(); AI != AE; ++AI) createSlot(AI); SC_DEBUG("Inserting Instructions:\n"); // Add all of the basic blocks and instructions - for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { + for (Function::const_iterator BB = TheFunction->begin(), + E = TheFunction->end(); BB != E; ++BB) { createSlot(BB); for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) { createSlot(I); @@ -1242,20 +1244,27 @@ } // Clean up after incorporating a function. This is the only way -// (other than construction) to get the FunctionIncorporated flag cleared. +// to get out of the function incorporation state that affects the +// getSlot/createSlot lock. Function incorporation state is indicated +// by TheFunction != 0. void SlotMachine::purgeFunction() { SC_DEBUG("begin purgeFunction!\n"); fMap.clear(); // Simply discard the function level map - FunctionIncorporated = false; + TheFunction = 0; SC_DEBUG("end purgeFunction!\n"); } /// Get the slot number for a value. This function will assert if you /// ask for a Value that hasn't previously been inserted with createSlot. /// Types are forbidden because Type does not inherit from Value (any more). -unsigned SlotMachine::getSlot(const Value *V) const { +unsigned SlotMachine::getSlot(const Value *V) { assert( V && "Can't get slot for null Value" ); assert( !isa(V) && "Can't get slot for a type" ); + assert(!isa(V) || isa(V) && + "Can't insert a non-GlobalValue Constant into SlotMachine"); + + // Check for uninitialized state and do lazy initialization + this->initialize(); // Do not number CPR's at all. They are an abomination if ( const ConstantPointerRef* CPR = dyn_cast(V) ) @@ -1267,7 +1276,7 @@ // Find the type plane in the module map TypedPlanes::const_iterator MI = mMap.find(VTy); - if ( FunctionIncorporated ) { + if ( TheFunction ) { // Lookup the type in the function map too TypedPlanes::const_iterator FI = fMap.find(VTy); // If there is a corresponding type plane in the function map @@ -1276,19 +1285,19 @@ ValueMap::const_iterator FVI = FI->second.map.find(V); // If the value doesn't exist in the function map if ( FVI == FI->second.map.end() ) { - // Look up the value in the module map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we didn't find it, it wasn't inserted - assert( MVI != MI->second.map.end() && "Value not found"); - // We found it only at the module level - return MVI->second; + // Look up the value in the module map + ValueMap::const_iterator MVI = MI->second.map.find(V); + // If we didn't find it, it wasn't inserted + assert( MVI != MI->second.map.end() && "Value not found"); + // We found it only at the module level + return MVI->second; // else the value exists in the function map } else { - // Return the slot number as the module's contribution to - // the type plane plus the index in the function's contribution - // to the type plane. - return MI->second.next_slot + FVI->second; + // Return the slot number as the module's contribution to + // the type plane plus the index in the function's contribution + // to the type plane. + return MI->second.next_slot + FVI->second; } // else there is not a corresponding type plane in the function map @@ -1304,7 +1313,7 @@ } } - // N.B. Can only get here if !FunctionIncorporated + // N.B. Can only get here if !TheFunction // Make sure the type plane exists assert( MI != mMap.end() && "No such type plane!" ); @@ -1323,6 +1332,8 @@ unsigned SlotMachine::createSlot(const Value *V) { assert( V && "Can't insert a null Value to SlotMachine"); assert( !isa(V) && "Can't insert a Type into SlotMachine"); + assert(!isa(V) || isa(V) && + "Can't insert a non-GlobalValue Constant into SlotMachine"); const Type* VTy = V->getType(); @@ -1332,7 +1343,7 @@ // Look up the type plane for the Value's type from the module map TypedPlanes::const_iterator MI = mMap.find(VTy); - if ( FunctionIncorporated ) { + if ( TheFunction ) { // Get the type plane for the Value's type from the function map TypedPlanes::const_iterator FI = fMap.find(VTy); // If there is a corresponding type plane in the function map @@ -1341,50 +1352,50 @@ ValueMap::const_iterator FVI = FI->second.map.find(V); // If the value doesn't exist in the function map if ( FVI == FI->second.map.end() ) { - // If there is no corresponding type plane in the module map - if ( MI == mMap.end() ) - return insertValue(V); - // Look up the value in the module map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we didn't find it, it wasn't inserted - if ( MVI == MI->second.map.end() ) - return insertValue(V); - else - // We found it only at the module level - return MVI->second; + // If there is no corresponding type plane in the module map + if ( MI == mMap.end() ) + return insertValue(V); + // Look up the value in the module map + ValueMap::const_iterator MVI = MI->second.map.find(V); + // If we didn't find it, it wasn't inserted + if ( MVI == MI->second.map.end() ) + return insertValue(V); + else + // We found it only at the module level + return MVI->second; // else the value exists in the function map } else { - if ( MI == mMap.end() ) - return FVI->second; - else - // Return the slot number as the module's contribution to - // the type plane plus the index in the function's contribution - // to the type plane. - return MI->second.next_slot + FVI->second; + if ( MI == mMap.end() ) + return FVI->second; + else + // Return the slot number as the module's contribution to + // the type plane plus the index in the function's contribution + // to the type plane. + return MI->second.next_slot + FVI->second; } // else there is not a corresponding type plane in the function map } else { // If the type plane doesn't exists at the module level if ( MI == mMap.end() ) { - return insertValue(V); + return insertValue(V); // else type plane exists at the module level, examine it } else { - // Look up the value in the module's map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we didn't find it there either - if ( MVI == MI->second.map.end() ) - // Return the slot number as the module's contribution to - // the type plane plus the index of the function map insertion. - return MI->second.next_slot + insertValue(V); - else - return MVI->second; + // Look up the value in the module's map + ValueMap::const_iterator MVI = MI->second.map.find(V); + // If we didn't find it there either + if ( MVI == MI->second.map.end() ) + // Return the slot number as the module's contribution to + // the type plane plus the index of the function map insertion. + return MI->second.next_slot + insertValue(V); + else + return MVI->second; } } } - // N.B. Can only get here if !FunctionIncorporated + // N.B. Can only get here if !TheFunction // If the module map's type plane is not for the Value's type if ( MI != mMap.end() ) { @@ -1403,28 +1414,20 @@ unsigned SlotMachine::insertValue(const Value *V ) { assert(V && "Can't insert a null Value into SlotMachine!"); assert(!isa(V) && "Can't insert a Type into SlotMachine!"); + assert(!isa(V) || isa(V) && + "Can't insert a non-GlobalValue Constant into SlotMachine"); - // If this value does not contribute to a plane (is void or constant) + // If this value does not contribute to a plane (is void) // or if the value already has a name then ignore it. - if (V->getType() == Type::VoidTy || // Ignore void type nodes - (V->hasName() || isa(V)) ) { + if (V->getType() == Type::VoidTy || V->hasName() ) { SC_DEBUG("ignored value " << *V << "\n"); return 0; // FIXME: Wrong return value } - if (!isa(V)) // Initializers for globals are handled explicitly - if (const Constant *C = dyn_cast(V)) { - // This makes sure that if a constant has uses (for example an array of - // const ints), that they are inserted also. - for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); - I != E; ++I) - createSlot(*I); - } - const Type *VTy = V->getType(); unsigned DestSlot = 0; - if ( FunctionIncorporated ) { + if ( TheFunction ) { TypedPlanes::iterator I = fMap.find( VTy ); if ( I == fMap.end() ) I = fMap.insert(std::make_pair(VTy,Plane())).first; @@ -1437,7 +1440,7 @@ } SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" << - DestSlot << " ["); + DestSlot << " ["); // G = Global, C = Constant, T = Type, F = Function, o = other SC_DEBUG((isa(V) ? "G" : (isa(V) ? "C" : (isa(V) ? "F" : "o")))); From alkis at cs.uiuc.edu Wed May 26 17:10:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 17:10:03 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/iSwitch.cpp iBranch.cpp Message-ID: <200405262207.RAA31296@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: iSwitch.cpp updated: 1.12 -> 1.13 iBranch.cpp updated: 1.13 -> 1.14 --- Log message: Inline trivial constructors. --- Diffs of the changes: (+0 -33) Index: llvm/lib/VMCore/iSwitch.cpp diff -u llvm/lib/VMCore/iSwitch.cpp:1.12 llvm/lib/VMCore/iSwitch.cpp:1.13 --- llvm/lib/VMCore/iSwitch.cpp:1.12 Wed May 26 16:41:09 2004 +++ llvm/lib/VMCore/iSwitch.cpp Wed May 26 17:07:18 2004 @@ -22,17 +22,6 @@ Operands.push_back(Use(Default, this)); } -SwitchInst::SwitchInst(Value *V, BasicBlock *D, - Instruction *InsertBefore) - : TerminatorInst(Instruction::Switch, InsertBefore) { - init(V, D); -} - -SwitchInst::SwitchInst(Value *V, BasicBlock *D, BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Switch, InsertAtEnd) { - init(V, D); -} - SwitchInst::SwitchInst(const SwitchInst &SI) : TerminatorInst(Instruction::Switch) { Operands.reserve(SI.Operands.size()); Index: llvm/lib/VMCore/iBranch.cpp diff -u llvm/lib/VMCore/iBranch.cpp:1.13 llvm/lib/VMCore/iBranch.cpp:1.14 --- llvm/lib/VMCore/iBranch.cpp:1.13 Wed May 26 16:41:09 2004 +++ llvm/lib/VMCore/iBranch.cpp Wed May 26 17:07:18 2004 @@ -47,28 +47,6 @@ Operands.push_back(Use(Cond, this)); } -BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond, - Instruction *InsertBefore) - : TerminatorInst(Instruction::Br, InsertBefore) { - init(True, False, Cond); -} - -BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond, - BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Br, InsertAtEnd) { - init(True, False, Cond); -} - -BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore) - : TerminatorInst(Instruction::Br, InsertBefore) { - init(True); -} - -BranchInst::BranchInst(BasicBlock *True, BasicBlock *InsertAtEnd) - : TerminatorInst(Instruction::Br, InsertAtEnd) { - init(True); -} - BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) { Operands.reserve(BI.Operands.size()); Operands.push_back(Use(BI.Operands[0], this)); From alkis at cs.uiuc.edu Wed May 26 17:11:09 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 17:11:09 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/iTerminators.h Message-ID: <200405262207.RAA31303@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: iTerminators.h updated: 1.41 -> 1.42 --- Log message: Inline trivial constructors. --- Diffs of the changes: (+28 -8) Index: llvm/include/llvm/iTerminators.h diff -u llvm/include/llvm/iTerminators.h:1.41 llvm/include/llvm/iTerminators.h:1.42 --- llvm/include/llvm/iTerminators.h:1.41 Wed May 26 16:41:09 2004 +++ llvm/include/llvm/iTerminators.h Wed May 26 17:07:18 2004 @@ -99,12 +99,26 @@ // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I // BranchInst(BB* B, BB *I) - 'br B' insert at end // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end - BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); - BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *cond, - Instruction *InsertBefore = 0); - BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); - BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *cond, - BasicBlock *InsertAtEnd); + BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0) + : TerminatorInst(Instruction::Br, InsertBefore) { + init(IfTrue); + } + BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, + Instruction *InsertBefore = 0) + : TerminatorInst(Instruction::Br, InsertBefore) { + init(IfTrue, IfFalse, Cond); + } + + BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) + : TerminatorInst(Instruction::Br, InsertAtEnd) { + init(IfTrue); + } + + BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, + BasicBlock *InsertAtEnd) + : TerminatorInst(Instruction::Br, InsertAtEnd) { + init(IfTrue, IfFalse, Cond); + } virtual Instruction *clone() const { return new BranchInst(*this); } @@ -168,8 +182,14 @@ void init(Value *Value, BasicBlock *Default); public: - SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0); - SwitchInst(Value *Value, BasicBlock *Default, BasicBlock *InsertAtEnd); + SwitchInst(Value *Value, BasicBlock *Default, Instruction *InsertBefore = 0) + : TerminatorInst(Instruction::Switch, InsertBefore) { + init(Value, Default); + } + SwitchInst(Value *Value, BasicBlock *Default, BasicBlock *InsertAtEnd) + : TerminatorInst(Instruction::Switch, InsertAtEnd) { + init(Value, Default); + } virtual Instruction *clone() const { return new SwitchInst(*this); } From alkis at cs.uiuc.edu Wed May 26 17:54:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 17:54:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/CodeExtractor.cpp Message-ID: <200405262250.RAA04174@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: CodeExtractor.cpp updated: 1.23 -> 1.24 --- Log message: Do not pass a null pointer if this instruction is not prepended or appended anywhere. --- Diffs of the changes: (+2 -2) Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp diff -u llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.23 llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.24 --- llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.23 Wed May 12 11:26:18 2004 +++ llvm/lib/Transforms/Utils/CodeExtractor.cpp Wed May 26 17:50:28 2004 @@ -394,7 +394,7 @@ Indices.push_back(ConstantUInt::get(Type::UIntTy, i)); GetElementPtrInst *GEP = new GetElementPtrInst(Struct, Indices, - "gep_" + StructValues[i]->getName(), 0); + "gep_" + StructValues[i]->getName()); codeReplacer->getInstList().push_back(GEP); StoreInst *SI = new StoreInst(StructValues[i], GEP); codeReplacer->getInstList().push_back(SI); @@ -420,7 +420,7 @@ Indices.push_back(ConstantUInt::get(Type::UIntTy, FirstOut + i)); GetElementPtrInst *GEP = new GetElementPtrInst(Struct, Indices, - "gep_reload_" + outputs[i]->getName(), 0); + "gep_reload_" + outputs[i]->getName()); codeReplacer->getInstList().push_back(GEP); Output = GEP; } else { From lattner at cs.uiuc.edu Wed May 26 18:55:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed May 26 18:55:02 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll Message-ID: <200405262351.SAA05100@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/SimplifyCFG: 2002-05-05-EmptyBlockMerge.ll updated: 1.3 -> 1.4 --- Log message: Fix a test that was "broken" by new optimizations. The transformation we are doing is certainly correct, its just that we didn't have the capability to do it when the testcase was written (no select instr) --- Diffs of the changes: (+4 -0) Index: llvm/test/Regression/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll diff -u llvm/test/Regression/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll:1.3 llvm/test/Regression/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll:1.4 --- llvm/test/Regression/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll:1.3 Tue Sep 16 10:29:52 2003 +++ llvm/test/Regression/Transforms/SimplifyCFG/2002-05-05-EmptyBlockMerge.ll Wed May 26 18:51:29 2004 @@ -2,6 +2,9 @@ ; ; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | grep 'br label' ; +declare void %foo() +implementation + void "cprop_test12"(int* %data) { bb0: %reg108 = load int* %data @@ -9,6 +12,7 @@ br bool %cond218, label %bb3, label %bb2 bb2: + call void %foo() br label %bb3 bb3: From alkis at cs.uiuc.edu Wed May 26 19:18:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 19:18:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/iOperators.cpp iMemory.cpp iCall.cpp Message-ID: <200405270015.TAA05235@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: iOperators.cpp updated: 1.26 -> 1.27 iMemory.cpp updated: 1.39 -> 1.40 iCall.cpp updated: 1.24 -> 1.25 --- Log message: Add constructors that take a BasicBlock to append to, to the rest of the llvm::Instruction hierarchy. --- Diffs of the changes: (+175 -45) Index: llvm/lib/VMCore/iOperators.cpp diff -u llvm/lib/VMCore/iOperators.cpp:1.26 llvm/lib/VMCore/iOperators.cpp:1.27 --- llvm/lib/VMCore/iOperators.cpp:1.26 Mon Feb 2 14:21:29 2004 +++ llvm/lib/VMCore/iOperators.cpp Wed May 26 19:15:23 2004 @@ -21,11 +21,8 @@ // BinaryOperator Class //===----------------------------------------------------------------------===// -BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2, - const Type *Ty, const std::string &Name, - Instruction *InsertBefore) - : Instruction(Ty, iType, Name, InsertBefore) { - +void BinaryOperator::init(BinaryOps iType, Value *S1, Value *S2) +{ Operands.reserve(2); Operands.push_back(Use(S1, this)); Operands.push_back(Use(S2, this)); @@ -36,30 +33,27 @@ case Add: case Sub: case Mul: case Div: case Rem: - assert(Ty == S1->getType() && + assert(getType() == S1->getType() && "Arithmetic operation should return same type as operands!"); - assert((Ty->isInteger() || Ty->isFloatingPoint()) && + assert((getType()->isInteger() || getType()->isFloatingPoint()) && "Tried to create an arithmetic operation on a non-arithmetic type!"); break; case And: case Or: case Xor: - assert(Ty == S1->getType() && + assert(getType() == S1->getType() && "Logical operation should return same type as operands!"); - assert(Ty->isIntegral() && + assert(getType()->isIntegral() && "Tried to create an logical operation on a non-integral type!"); break; case SetLT: case SetGT: case SetLE: case SetGE: case SetEQ: case SetNE: - assert(Ty == Type::BoolTy && "Setcc must return bool!"); + assert(getType() == Type::BoolTy && "Setcc must return bool!"); default: break; } #endif } - - - BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, const std::string &Name, Instruction *InsertBefore) { @@ -76,6 +70,22 @@ } } +BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2, + const std::string &Name, + BasicBlock *InsertAtEnd) { + assert(S1->getType() == S2->getType() && + "Cannot create binary operator with two operands of differing type!"); + switch (Op) { + // Binary comparison operators... + case SetLT: case SetGT: case SetLE: + case SetGE: case SetEQ: case SetNE: + return new SetCondInst(Op, S1, S2, Name, InsertAtEnd); + + default: + return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertAtEnd); + } +} + BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name, Instruction *InsertBefore) { if (!Op->getType()->isFloatingPoint()) @@ -88,6 +98,18 @@ Op->getType(), Name, InsertBefore); } +BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name, + BasicBlock *InsertAtEnd) { + if (!Op->getType()->isFloatingPoint()) + return new BinaryOperator(Instruction::Sub, + Constant::getNullValue(Op->getType()), Op, + Op->getType(), Name, InsertAtEnd); + else + return new BinaryOperator(Instruction::Sub, + ConstantFP::get(Op->getType(), -0.0), Op, + Op->getType(), Name, InsertAtEnd); +} + BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name, Instruction *InsertBefore) { return new BinaryOperator(Instruction::Xor, Op, @@ -95,6 +117,13 @@ Op->getType(), Name, InsertBefore); } +BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name, + BasicBlock *InsertAtEnd) { + return new BinaryOperator(Instruction::Xor, Op, + ConstantIntegral::getAllOnesValue(Op->getType()), + Op->getType(), Name, InsertAtEnd); +} + // isConstantAllOnes - Helper function for several functions below static inline bool isConstantAllOnes(const Value *V) { @@ -168,6 +197,14 @@ SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2, const std::string &Name, Instruction *InsertBefore) : BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertBefore) { + + // Make sure it's a valid type... getInverseCondition will assert out if not. + assert(getInverseCondition(Opcode)); +} + +SetCondInst::SetCondInst(BinaryOps Opcode, Value *S1, Value *S2, + const std::string &Name, BasicBlock *InsertAtEnd) + : BinaryOperator(Opcode, S1, S2, Type::BoolTy, Name, InsertAtEnd) { // Make sure it's a valid type... getInverseCondition will assert out if not. assert(getInverseCondition(Opcode)); Index: llvm/lib/VMCore/iMemory.cpp diff -u llvm/lib/VMCore/iMemory.cpp:1.39 llvm/lib/VMCore/iMemory.cpp:1.40 --- llvm/lib/VMCore/iMemory.cpp:1.39 Wed May 26 16:41:09 2004 +++ llvm/lib/VMCore/iMemory.cpp Wed May 26 19:15:23 2004 @@ -16,10 +16,8 @@ #include "llvm/DerivedTypes.h" using namespace llvm; -AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, - const std::string &Name, Instruction *InsertBef) - : Instruction(PointerType::get(Ty), iTy, Name, InsertBef) { - +void AllocationInst::init(const Type *Ty, Value *ArraySize, unsigned iTy) +{ // ArraySize defaults to 1. if (!ArraySize) ArraySize = ConstantUInt::get(Type::UIntTy, 1); @@ -30,6 +28,20 @@ Operands.push_back(Use(ArraySize, this)); } +AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, + const std::string &Name, + Instruction *InsertBefore) + : Instruction(PointerType::get(Ty), iTy, Name, InsertBefore) { + init(Ty, ArraySize, iTy); +} + +AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, + const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(PointerType::get(Ty), iTy, Name, InsertAtEnd) { + init(Ty, ArraySize, iTy); +} + bool AllocationInst::isArrayAllocation() const { return getOperand(0) != ConstantUInt::get(Type::UIntTy, 1); } @@ -52,13 +64,23 @@ // FreeInst Implementation //===----------------------------------------------------------------------===// -FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) - : Instruction(Type::VoidTy, Free, "", InsertBefore) { - assert(isa(Ptr->getType()) && "Can't free nonpointer!"); +void FreeInst::init(Value *Ptr) +{ + assert(Ptr && isa(Ptr->getType()) && "Can't free nonpointer!"); Operands.reserve(1); Operands.push_back(Use(Ptr, this)); } +FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) + : Instruction(Type::VoidTy, Free, "", InsertBefore) { + init(Ptr); +} + +FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd) + : Instruction(Type::VoidTy, Free, "", InsertAtEnd) { + init(Ptr); +} + //===----------------------------------------------------------------------===// // LoadInst Implementation @@ -70,6 +92,12 @@ init(Ptr); } +LoadInst::LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAE) + : Instruction(cast(Ptr->getType())->getElementType(), + Load, Name, InsertAE), Volatile(false) { + init(Ptr); +} + LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, Instruction *InsertBef) : Instruction(cast(Ptr->getType())->getElementType(), @@ -77,6 +105,13 @@ init(Ptr); } +LoadInst::LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, + BasicBlock *InsertAE) + : Instruction(cast(Ptr->getType())->getElementType(), + Load, Name, InsertAE), Volatile(isVolatile) { + init(Ptr); +} + //===----------------------------------------------------------------------===// // StoreInst Implementation //===----------------------------------------------------------------------===// @@ -86,12 +121,23 @@ init(Val, Ptr); } +StoreInst::StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd) + : Instruction(Type::VoidTy, Store, "", InsertAtEnd), Volatile(false) { + init(Val, Ptr); +} + StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile, Instruction *InsertBefore) : Instruction(Type::VoidTy, Store, "", InsertBefore), Volatile(isVolatile) { init(Val, Ptr); } +StoreInst::StoreInst(Value *Val, Value *Ptr, bool isVolatile, + BasicBlock *InsertAtEnd) + : Instruction(Type::VoidTy, Store, "", InsertAtEnd), Volatile(isVolatile) { + init(Val, Ptr); +} + //===----------------------------------------------------------------------===// // GetElementPtrInst Implementation @@ -119,6 +165,14 @@ : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), Idx, true))), GetElementPtr, Name, InBe) { + init(Ptr, Idx); +} + +GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector &Idx, + const std::string &Name, BasicBlock *IAE) + : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(), + Idx, true))), + GetElementPtr, Name, IAE) { init(Ptr, Idx); } Index: llvm/lib/VMCore/iCall.cpp diff -u llvm/lib/VMCore/iCall.cpp:1.24 llvm/lib/VMCore/iCall.cpp:1.25 --- llvm/lib/VMCore/iCall.cpp:1.24 Wed May 26 16:41:09 2004 +++ llvm/lib/VMCore/iCall.cpp Wed May 26 19:15:23 2004 @@ -23,29 +23,37 @@ // CallInst Implementation //===----------------------------------------------------------------------===// -CallInst::CallInst(Value *Func, const std::vector ¶ms, - const std::string &Name, Instruction *InsertBefore) - : Instruction(cast(cast(Func->getType()) - ->getElementType())->getReturnType(), - Instruction::Call, Name, InsertBefore) { - Operands.reserve(1+params.size()); +void CallInst::init(Value *Func, const std::vector &Params) +{ + Operands.reserve(1+Params.size()); Operands.push_back(Use(Func, this)); const FunctionType *FTy = cast(cast(Func->getType())->getElementType()); - assert((params.size() == FTy->getNumParams() || - (FTy->isVarArg() && params.size() > FTy->getNumParams())) && + assert((Params.size() == FTy->getNumParams() || + (FTy->isVarArg() && Params.size() > FTy->getNumParams())) && "Calling a function with bad signature"); - for (unsigned i = 0; i != params.size(); i++) - Operands.push_back(Use(params[i], this)); + for (unsigned i = 0; i != Params.size(); i++) + Operands.push_back(Use(Params[i], this)); } -CallInst::CallInst(Value *Func, const std::string &Name, - Instruction *InsertBefore) - : Instruction(cast(cast(Func->getType()) - ->getElementType())->getReturnType(), - Instruction::Call, Name, InsertBefore) { +void CallInst::init(Value *Func, Value *Actual) +{ + Operands.reserve(2); + Operands.push_back(Use(Func, this)); + + const FunctionType *MTy = + cast(cast(Func->getType())->getElementType()); + + assert((MTy->getNumParams() == 1 || + (MTy->isVarArg() && MTy->getNumParams() == 0)) && + "Calling a function with bad signature"); + Operands.push_back(Use(Actual, this)); +} + +void CallInst::init(Value *Func) +{ Operands.reserve(1); Operands.push_back(Use(Func, this)); @@ -55,21 +63,52 @@ assert(MTy->getNumParams() == 0 && "Calling a function with bad signature"); } -CallInst::CallInst(Value *Func, Value* A, const std::string &Name, +CallInst::CallInst(Value *Func, const std::vector &Params, + const std::string &Name, Instruction *InsertBefore) + : Instruction(cast(cast(Func->getType()) + ->getElementType())->getReturnType(), + Instruction::Call, Name, InsertBefore) { + init(Func, Params); +} + +CallInst::CallInst(Value *Func, const std::vector &Params, + const std::string &Name, BasicBlock *InsertAtEnd) + : Instruction(cast(cast(Func->getType()) + ->getElementType())->getReturnType(), + Instruction::Call, Name, InsertAtEnd) { + init(Func, Params); +} + +CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name, Instruction *InsertBefore) : Instruction(cast(cast(Func->getType()) ->getElementType())->getReturnType(), Instruction::Call, Name, InsertBefore) { - Operands.reserve(2); - Operands.push_back(Use(Func, this)); - - const FunctionType *MTy = - cast(cast(Func->getType())->getElementType()); + init(Func, Actual); +} - assert((MTy->getNumParams() == 1 || - (MTy->isVarArg() && MTy->getNumParams() == 0)) && - "Calling a function with bad signature"); - Operands.push_back(Use(A, this)); +CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(cast(cast(Func->getType()) + ->getElementType())->getReturnType(), + Instruction::Call, Name, InsertAtEnd) { + init(Func, Actual); +} + +CallInst::CallInst(Value *Func, const std::string &Name, + Instruction *InsertBefore) + : Instruction(cast(cast(Func->getType()) + ->getElementType())->getReturnType(), + Instruction::Call, Name, InsertBefore) { + init(Func); +} + +CallInst::CallInst(Value *Func, const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(cast(cast(Func->getType()) + ->getElementType())->getReturnType(), + Instruction::Call, Name, InsertAtEnd) { + init(Func); } CallInst::CallInst(const CallInst &CI) From alkis at cs.uiuc.edu Wed May 26 19:19:00 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 19:19:00 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/iPHINode.h iOther.h iOperators.h iMemory.h InstrTypes.h Message-ID: <200405270015.TAA05250@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: iPHINode.h updated: 1.16 -> 1.17 iOther.h updated: 1.45 -> 1.46 iOperators.h updated: 1.15 -> 1.16 iMemory.h updated: 1.45 -> 1.46 InstrTypes.h updated: 1.37 -> 1.38 --- Log message: Add constructors that take a BasicBlock to append to, to the rest of the llvm::Instruction hierarchy. --- Diffs of the changes: (+129 -28) Index: llvm/include/llvm/iPHINode.h diff -u llvm/include/llvm/iPHINode.h:1.16 llvm/include/llvm/iPHINode.h:1.17 --- llvm/include/llvm/iPHINode.h:1.16 Thu Feb 26 17:20:08 2004 +++ llvm/include/llvm/iPHINode.h Wed May 26 19:15:23 2004 @@ -36,6 +36,10 @@ : Instruction(Ty, Instruction::PHI, Name, InsertBefore) { } + PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) + : Instruction(Ty, Instruction::PHI, Name, InsertAtEnd) { + } + virtual Instruction *clone() const { return new PHINode(*this); } /// getNumIncomingValues - Return the number of incoming edges Index: llvm/include/llvm/iOther.h diff -u llvm/include/llvm/iOther.h:1.45 llvm/include/llvm/iOther.h:1.46 --- llvm/include/llvm/iOther.h:1.45 Thu Mar 11 23:51:05 2004 +++ llvm/include/llvm/iOther.h Wed May 26 19:15:23 2004 @@ -31,12 +31,20 @@ Operands.reserve(1); Operands.push_back(Use(CI.Operands[0], this)); } + void init(Value *S) { + Operands.reserve(1); + Operands.push_back(Use(S, this)); + } public: CastInst(Value *S, const Type *Ty, const std::string &Name = "", Instruction *InsertBefore = 0) : Instruction(Ty, Cast, Name, InsertBefore) { - Operands.reserve(1); - Operands.push_back(Use(S, this)); + init(S); + } + CastInst(Value *S, const Type *Ty, const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(Ty, Cast, Name, InsertAtEnd) { + init(S); } virtual Instruction *clone() const { return new CastInst(*this); } @@ -61,15 +69,25 @@ /// class CallInst : public Instruction { CallInst(const CallInst &CI); + void init(Value *Func, const std::vector &Params); + void init(Value *Func, Value *Actual); + void init(Value *Func); + public: CallInst(Value *F, const std::vector &Par, const std::string &Name = "", Instruction *InsertBefore = 0); + CallInst(Value *F, const std::vector &Par, + const std::string &Name, BasicBlock *InsertAtEnd); - // Alternate CallInst ctors w/ no actuals & one actual, respectively. - CallInst(Value *F, const std::string &Name = "", - Instruction *InsertBefore = 0); + // Alternate CallInst ctors w/ one actual & no actuals, respectively. CallInst(Value *F, Value *Actual, const std::string& Name = "", Instruction *InsertBefore = 0); + CallInst(Value *F, Value *Actual, const std::string& Name, + BasicBlock *InsertAtEnd); + explicit CallInst(Value *F, const std::string &Name = "", + Instruction *InsertBefore = 0); + explicit CallInst(Value *F, const std::string &Name, + BasicBlock *InsertAtEnd); virtual Instruction *clone() const { return new CallInst(*this); } bool mayWriteToMemory() const { return true; } @@ -106,16 +124,25 @@ Operands.push_back(Use(SI.Operands[0], this)); Operands.push_back(Use(SI.Operands[1], this)); } -public: - ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "", - Instruction *InsertBefore = 0) - : Instruction(S->getType(), Opcode, Name, InsertBefore) { + void init(OtherOps Opcode, Value *S, Value *SA) { assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!"); Operands.reserve(2); Operands.push_back(Use(S, this)); Operands.push_back(Use(SA, this)); } +public: + ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "", + Instruction *InsertBefore = 0) + : Instruction(S->getType(), Opcode, Name, InsertBefore) { + init(Opcode, S, SA); + } + ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(S->getType(), Opcode, Name, InsertAtEnd) { + init(Opcode, S, SA); + } + OtherOps getOpcode() const { return static_cast(Instruction::getOpcode()); } @@ -146,16 +173,25 @@ Operands.push_back(Use(SI.Operands[1], this)); Operands.push_back(Use(SI.Operands[2], this)); } -public: - SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "", - Instruction *InsertBefore = 0) - : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) { + void init(Value *C, Value *S1, Value *S2) { Operands.reserve(3); Operands.push_back(Use(C, this)); Operands.push_back(Use(S1, this)); Operands.push_back(Use(S2, this)); } +public: + SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "", + Instruction *InsertBefore = 0) + : Instruction(S1->getType(), Instruction::Select, Name, InsertBefore) { + init(C, S1, S2); + } + SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(S1->getType(), Instruction::Select, Name, InsertAtEnd) { + init(C, S1, S2); + } + Value *getCondition() const { return Operands[0]; } Value *getTrueValue() const { return Operands[1]; } Value *getFalseValue() const { return Operands[2]; } @@ -187,17 +223,25 @@ /// class VANextInst : public Instruction { PATypeHolder ArgTy; + void init(Value *List) { + Operands.reserve(1); + Operands.push_back(Use(List, this)); + } VANextInst(const VANextInst &VAN) : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) { - Operands.reserve(1); - Operands.push_back(Use(VAN.Operands[0], this)); + init(VAN.Operands[0]); } + public: VANextInst(Value *List, const Type *Ty, const std::string &Name = "", Instruction *InsertBefore = 0) : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) { - Operands.reserve(1); - Operands.push_back(Use(List, this)); + init(List); + } + VANextInst(Value *List, const Type *Ty, const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(List->getType(), VANext, Name, InsertAtEnd), ArgTy(Ty) { + init(List); } const Type *getArgType() const { return ArgTy; } @@ -223,17 +267,24 @@ /// an argument of the specified type given a va_list. /// class VAArgInst : public Instruction { + void init(Value* List) { + Operands.reserve(1); + Operands.push_back(Use(List, this)); + } VAArgInst(const VAArgInst &VAA) : Instruction(VAA.getType(), VAArg) { - Operands.reserve(1); - Operands.push_back(Use(VAA.Operands[0], this)); + init(VAA.Operands[0]); } public: VAArgInst(Value *List, const Type *Ty, const std::string &Name = "", Instruction *InsertBefore = 0) : Instruction(Ty, VAArg, Name, InsertBefore) { - Operands.reserve(1); - Operands.push_back(Use(List, this)); + init(List); + } + VAArgInst(Value *List, const Type *Ty, const std::string &Name, + BasicBlock *InsertAtEnd) + : Instruction(Ty, VAArg, Name, InsertAtEnd) { + init(List); } virtual Instruction *clone() const { return new VAArgInst(*this); } Index: llvm/include/llvm/iOperators.h diff -u llvm/include/llvm/iOperators.h:1.15 llvm/include/llvm/iOperators.h:1.16 --- llvm/include/llvm/iOperators.h:1.15 Tue Nov 11 16:41:30 2003 +++ llvm/include/llvm/iOperators.h Wed May 26 19:15:23 2004 @@ -26,6 +26,8 @@ public: SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS, const std::string &Name = "", Instruction *InsertBefore = 0); + SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS, + const std::string &Name, BasicBlock *InsertAtEnd); /// getInverseCondition - Return the inverse of the current condition opcode. /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc... Index: llvm/include/llvm/iMemory.h diff -u llvm/include/llvm/iMemory.h:1.45 llvm/include/llvm/iMemory.h:1.46 --- llvm/include/llvm/iMemory.h:1.45 Wed May 26 16:41:09 2004 +++ llvm/include/llvm/iMemory.h Wed May 26 19:15:23 2004 @@ -30,8 +30,12 @@ /// class AllocationInst : public Instruction { protected: + void init(const Type *Ty, Value *ArraySize, unsigned iTy); AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, const std::string &Name = "", Instruction *InsertBefore = 0); + AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, + const std::string &Name, BasicBlock *InsertAtEnd); + public: /// isArrayAllocation - Return true if there is an allocation size parameter @@ -79,9 +83,13 @@ class MallocInst : public AllocationInst { MallocInst(const MallocInst &MI); public: - MallocInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "", - Instruction *InsertBefore = 0) + explicit MallocInst(const Type *Ty, Value *ArraySize = 0, + const std::string &Name = "", + Instruction *InsertBefore = 0) : AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {} + MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name, + BasicBlock *InsertAtEnd) + : AllocationInst(Ty, ArraySize, Malloc, Name, InsertAtEnd) {} virtual Instruction *clone() const { return new MallocInst(*this); @@ -107,9 +115,13 @@ class AllocaInst : public AllocationInst { AllocaInst(const AllocaInst &); public: - AllocaInst(const Type *Ty, Value *ArraySize = 0, const std::string &Name = "", - Instruction *InsertBefore = 0) + explicit AllocaInst(const Type *Ty, Value *ArraySize = 0, + const std::string &Name = "", + Instruction *InsertBefore = 0) : AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {} + AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name, + BasicBlock *InsertAtEnd) + : AllocationInst(Ty, ArraySize, Alloca, Name, InsertAtEnd) {} virtual Instruction *clone() const { return new AllocaInst(*this); @@ -132,8 +144,12 @@ /// FreeInst - an instruction to deallocate memory /// -struct FreeInst : public Instruction { - FreeInst(Value *Ptr, Instruction *InsertBefore = 0); +class FreeInst : public Instruction { + void init(Value *Ptr); + +public: + explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0); + FreeInst(Value *Ptr, BasicBlock *InsertAfter); virtual Instruction *clone() const { return new FreeInst(Operands[0]); } @@ -169,8 +185,11 @@ } public: LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore); + LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd); LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false, Instruction *InsertBefore = 0); + LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, + BasicBlock *InsertAtEnd); /// isVolatile - Return true if this is a load from a volatile memory /// location. @@ -221,8 +240,10 @@ } public: StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); + StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, Instruction *InsertBefore = 0); + StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); /// isVolatile - Return true if this is a load from a volatile memory @@ -272,6 +293,8 @@ public: GetElementPtrInst(Value *Ptr, const std::vector &Idx, const std::string &Name = "", Instruction *InsertBefore =0); + GetElementPtrInst(Value *Ptr, const std::vector &Idx, + const std::string &Name, BasicBlock *InsertAtEnd); virtual Instruction *clone() const { return new GetElementPtrInst(*this); } // getType - Overload to return most specific pointer type... Index: llvm/include/llvm/InstrTypes.h diff -u llvm/include/llvm/InstrTypes.h:1.37 llvm/include/llvm/InstrTypes.h:1.38 --- llvm/include/llvm/InstrTypes.h:1.37 Wed May 26 16:41:09 2004 +++ llvm/include/llvm/InstrTypes.h Wed May 26 19:15:23 2004 @@ -76,8 +76,17 @@ class BinaryOperator : public Instruction { protected: + void init(BinaryOps iType, Value *S1, Value *S2); BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty, - const std::string &Name, Instruction *InsertBefore); + const std::string &Name, Instruction *InsertBefore) + : Instruction(Ty, iType, Name, InsertBefore) { + init(iType, S1, S2); + } + BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty, + const std::string &Name, BasicBlock *InsertAtEnd) + : Instruction(Ty, iType, Name, InsertAtEnd) { + init(iType, S1, S2); + } public: @@ -90,6 +99,14 @@ const std::string &Name = "", Instruction *InsertBefore = 0); + /// create() - Construct a binary instruction, given the opcode and the two + /// operands. Also automatically insert this instruction to the end of the + /// BasicBlock specified. + /// + static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2, + const std::string &Name, + BasicBlock *InsertAtEnd); + /// Helper functions to construct and inspect unary operations (NEG and NOT) /// via binary operators SUB and XOR: @@ -99,8 +116,12 @@ /// static BinaryOperator *createNeg(Value *Op, const std::string &Name = "", Instruction *InsertBefore = 0); + static BinaryOperator *createNeg(Value *Op, const std::string &Name, + BasicBlock *InsertAtEnd); static BinaryOperator *createNot(Value *Op, const std::string &Name = "", Instruction *InsertBefore = 0); + static BinaryOperator *createNot(Value *Op, const std::string &Name, + BasicBlock *InsertAtEnd); /// isNeg, isNot - Check if the given Value is a NEG or NOT instruction. /// From criswell at cs.uiuc.edu Wed May 26 19:59:01 2004 From: criswell at cs.uiuc.edu (John Criswell) Date: Wed May 26 19:59:01 2004 Subject: [llvm-commits] CVS: llvm/configure Message-ID: <200405270057.TAA19691@choi.cs.uiuc.edu> Changes in directory llvm: configure updated: 1.88 -> 1.89 --- Log message: Only give warnings if the user doesn't have mmap(). This is pretty much a hack that allows users to fight through a build if they don't have mmap(). When I get into the office, I'll make something better. --- Diffs of the changes: (+4 -6) Index: llvm/configure diff -u llvm/configure:1.88 llvm/configure:1.89 --- llvm/configure:1.88 Fri Apr 16 12:13:44 2004 +++ llvm/configure Wed May 26 19:57:44 2004 @@ -21368,9 +21368,8 @@ if test "$ac_cv_func_mmap_fixed_mapped" = "no" then - { { echo "$as_me:$LINENO: error: mmap() required but not found" >&5 -echo "$as_me: error: mmap() required but not found" >&2;} - { (exit 1); exit 1; }; } + { echo "$as_me:$LINENO: WARNING: mmap() required but not found" >&5 +echo "$as_me: WARNING: mmap() required but not found" >&2;} fi echo "$as_me:$LINENO: checking for mmap of files" >&5 echo $ECHO_N "checking for mmap of files... $ECHO_C" >&6 @@ -21460,9 +21459,8 @@ if test "$ac_cv_func_mmap_file" = "no" then - { { echo "$as_me:$LINENO: error: mmap() of files required but not found" >&5 -echo "$as_me: error: mmap() of files required but not found" >&2;} - { (exit 1); exit 1; }; } + { echo "$as_me:$LINENO: WARNING: mmap() of files required but not found" >&5 +echo "$as_me: WARNING: mmap() of files required but not found" >&2;} fi echo "$as_me:$LINENO: checking for MAP_ANONYMOUS vs. MAP_ANON" >&5 echo $ECHO_N "checking for MAP_ANONYMOUS vs. MAP_ANON... $ECHO_C" >&6 From criswell at cs.uiuc.edu Wed May 26 20:00:01 2004 From: criswell at cs.uiuc.edu (John Criswell) Date: Wed May 26 20:00:01 2004 Subject: [llvm-commits] CVS: llvm/autoconf/configure.ac Message-ID: <200405270058.TAA19699@choi.cs.uiuc.edu> Changes in directory llvm/autoconf: configure.ac updated: 1.86 -> 1.87 --- Log message: Only give warnings if the user doesn't have mmap(). This is pretty much a hack that allows users to fight through a build if they don't have mmap(). When I get into the office, I'll make something better. --- Diffs of the changes: (+2 -2) Index: llvm/autoconf/configure.ac diff -u llvm/autoconf/configure.ac:1.86 llvm/autoconf/configure.ac:1.87 --- llvm/autoconf/configure.ac:1.86 Fri Apr 16 12:13:33 2004 +++ llvm/autoconf/configure.ac Wed May 26 19:57:50 2004 @@ -273,12 +273,12 @@ AC_FUNC_MMAP if test "$ac_cv_func_mmap_fixed_mapped" = "no" then - AC_MSG_ERROR([mmap() required but not found]) + AC_MSG_WARN([mmap() required but not found]) fi AC_FUNC_MMAP_FILE if test "$ac_cv_func_mmap_file" = "no" then - AC_MSG_ERROR([mmap() of files required but not found]) + AC_MSG_WARN([mmap() of files required but not found]) fi AC_HEADER_MMAP_ANONYMOUS AC_TYPE_SIGNAL From alkis at cs.uiuc.edu Wed May 26 20:01:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 20:01:01 2004 Subject: [llvm-commits] CVS: llvm/docs/ProgrammersManual.html Message-ID: <200405270058.TAA05423@zion.cs.uiuc.edu> Changes in directory llvm/docs: ProgrammersManual.html updated: 1.58 -> 1.59 --- Log message: Add section on the newly added Instruction and subclasses constructor variant. --- Diffs of the changes: (+17 -2) Index: llvm/docs/ProgrammersManual.html diff -u llvm/docs/ProgrammersManual.html:1.58 llvm/docs/ProgrammersManual.html:1.59 --- llvm/docs/ProgrammersManual.html:1.58 Wed May 26 11:52:55 2004 +++ llvm/docs/ProgrammersManual.html Wed May 26 19:57:51 2004 @@ -808,7 +808,22 @@ BasicBlock, and a newly-created instruction we wish to insert before *pi, we do the following:

    -
      BasicBlock *pb = ...;
    Instruction *pi = ...;
    Instruction *newInst = new Instruction(...);
    pb->getInstList().insert(pi, newInst); // inserts newInst before pi in pb
    +
      BasicBlock *pb = ...;
    Instruction *pi = ...;
    Instruction *newInst = new Instruction(...);
    pb->getInstList().insert(pi, newInst); // inserts newInst before pi in pb
    + +

    Appending to the end of a BasicBlock is so common that + the Instruction class and Instruction-derived + classes provide constructors which take a pointer to a + BasicBlock to be appended to. For example code that + looked like:

    + +
      BasicBlock *pb = ...;
    Instruction *newInst = new Instruction(...);
    pb->getInstList().push_back(newInst); // appends newInst to pb
    + +

    becomes:

    + +
      BasicBlock *pb = ...;
    Instruction *newInst = new Instruction(..., pb);
    + +

    which is much cleaner, especially if you are creating + long instruction streams.

  • Insertion into an implicit instruction list @@ -2028,7 +2043,7 @@ Dinakar Dhurjati and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/26 16:52:55 $ + Last modified: $Date: 2004/05/27 00:57:51 $ From alkis at cs.uiuc.edu Wed May 26 20:07:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 20:07:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405270104.UAA05510@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.32 -> 1.33 --- Log message: Use the newly added Instruction and Instruction-subclass constructors. --- Diffs of the changes: (+44 -62) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.32 llvm-java/lib/Compiler/Compiler.cpp:1.33 --- llvm-java/lib/Compiler/Compiler.cpp:1.32 Tue May 25 20:29:08 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Wed May 26 20:04:20 2004 @@ -121,6 +121,9 @@ BasicBlock* prologue_; private: + BasicBlock* getBBAt(unsigned bcI) { return bc2bbMap_[bcI]; } + + private: const Type* getType(JType type) { switch (type) { // FIXME: this should really be a non-void type when the object @@ -170,13 +173,11 @@ Value* getOrCreateLocal(unsigned index, const Type* type) { if (!locals_[index]) { - Instruction* alloc = - new AllocaInst(type, NULL, "local" + utostr(index)); - locals_[index] = alloc; - Instruction* store = new StoreInst( - llvm::Constant::getNullValue(type), alloc); - prologue_->getInstList().push_back(alloc); - prologue_->getInstList().push_back(store); + locals_[index] = new AllocaInst(type, NULL, + "local" + utostr(index), + prologue_); + new StoreInst(llvm::Constant::getNullValue(type), + locals_[index], prologue_); } return locals_[index]; @@ -242,10 +243,8 @@ } void do_load(unsigned bcI, JType type, unsigned index) { - Instruction* in = - new LoadInst(getOrCreateLocal(index, getType(type)), TMP); - opStack_.push(in); - bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push(new LoadInst(getOrCreateLocal(index, getType(type)), + TMP, getBBAt(bcI))); } void do_aload(unsigned bcI, JType type) { @@ -254,10 +253,9 @@ void do_store(unsigned bcI, JType type, unsigned index) { Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = - new StoreInst(v1, getOrCreateLocal(index, getType(type))); - opStack_.push(in); - bc2bbMap_[bcI]->getInstList().push_back(in); + opStack_.push( + new StoreInst(v1, getOrCreateLocal(index, getType(type)), + getBBAt(bcI))); } @@ -418,31 +416,28 @@ // cast value to be shifted into its unsigned version do_swap(bcI); Value* value = opStack_.top(); opStack_.pop(); - Instruction* in = new CastInst - (value, value->getType()->getUnsignedVersion(), TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - opStack_.push(in); + value = new CastInst(value, + value->getType()->getUnsignedVersion(), + TMP, getBBAt(bcI)); + opStack_.push(value); do_swap(bcI); do_shift_common(bcI, Instruction::Shr); // cast shifted value back to its original signed version value = opStack_.top(); opStack_.pop(); - in = new CastInst - (value, value->getType()->getSignedVersion(), TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - opStack_.push(in); + value = new CastInst(value, + value->getType()->getSignedVersion(), + TMP, getBBAt(bcI)); + opStack_.push(value); } void do_shift_common(unsigned bcI, Instruction::OtherOps op) { Value* amount = opStack_.top(); opStack_.pop(); Value* value = opStack_.top(); opStack_.pop(); - Instruction* in = new CastInst(amount, Type::UByteTy, TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - amount = in; - in = new ShiftInst(op, value, amount, TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - opStack_.push(in); + amount = new CastInst(amount, Type::UByteTy, TMP, getBBAt(bcI)); + Value* result = new ShiftInst(op, value, amount, TMP, getBBAt(bcI)); + opStack_.push(result); } void do_and(unsigned bcI) { @@ -460,30 +455,25 @@ void do_binary_op_common(unsigned bcI, Instruction::BinaryOps op) { Value* v2 = opStack_.top(); opStack_.pop(); Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = BinaryOperator::create(op, v1, v2, TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - opStack_.push(in); + Value* r = BinaryOperator::create(op, v1, v2, TMP, getBBAt(bcI)); + opStack_.push(r); } void do_iinc(unsigned bcI, unsigned index, int amount) { - Instruction* in = - new LoadInst(getOrCreateLocal(index, Type::IntTy), TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - in = BinaryOperator::create(Instruction::Add, - in, - ConstantSInt::get(Type::IntTy, amount), - TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - in = new StoreInst(in, getOrCreateLocal(index, Type::IntTy)); - bc2bbMap_[bcI]->getInstList().push_back(in); + Value* v = new LoadInst(getOrCreateLocal(index, Type::IntTy), + TMP, getBBAt(bcI)); + BinaryOperator::create(Instruction::Add, v, + ConstantSInt::get(Type::IntTy, amount), + TMP, getBBAt(bcI)); + new StoreInst(v, getOrCreateLocal(index, Type::IntTy), + getBBAt(bcI)); } void do_convert(unsigned bcI, JType to) { Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = new CastInst(v1, getType(to), TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - opStack_.push(in); + Value* r = new CastInst(v1, getType(to), TMP, getBBAt(bcI)); + opStack_.push(r); } void do_cmp(unsigned bcI) { @@ -502,28 +492,20 @@ unsigned t, unsigned f) { Value* v2 = llvm::Constant::getNullValue(getType(type)); Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = new SetCondInst(getSetCC(cc), v1, v2, TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - new BranchInst(bc2bbMap_[t], - bc2bbMap_[f], - in, - bc2bbMap_[bcI]); + Value* c = new SetCondInst(getSetCC(cc), v1, v2, TMP, getBBAt(bcI)); + new BranchInst(getBBAt(t), getBBAt(f), c, getBBAt(bcI)); } void do_ifcmp(unsigned bcI, JSetCC cc, unsigned t, unsigned f) { Value* v2 = opStack_.top(); opStack_.pop(); Value* v1 = opStack_.top(); opStack_.pop(); - Instruction* in = new SetCondInst(getSetCC(cc), v1, v2, TMP); - bc2bbMap_[bcI]->getInstList().push_back(in); - new BranchInst(bc2bbMap_[t], - bc2bbMap_[f], - in, - bc2bbMap_[bcI]); + Value* c = new SetCondInst(getSetCC(cc), v1, v2, TMP, getBBAt(bcI)); + new BranchInst(getBBAt(t), getBBAt(f), c, getBBAt(bcI)); } void do_goto(unsigned bcI, unsigned target) { - new BranchInst(bc2bbMap_[target], bc2bbMap_[bcI]); + new BranchInst(getBBAt(target), getBBAt(bcI)); } void do_jsr(unsigned bcI, unsigned target) { @@ -539,19 +521,19 @@ const SwitchCases& sw) { Value* v1 = opStack_.top(); opStack_.pop(); SwitchInst* in = - new SwitchInst(v1, bc2bbMap_[defTarget], bc2bbMap_[bcI]); + new SwitchInst(v1, getBBAt(defTarget), getBBAt(bcI)); for (unsigned i = 0; i < sw.size(); ++i) in->addCase(ConstantSInt::get(Type::IntTy, sw[i].first), - bc2bbMap_[sw[i].second]); + getBBAt(sw[i].second)); } void do_return(unsigned bcI) { Value* v1 = opStack_.top(); opStack_.pop(); - new ReturnInst(v1, bc2bbMap_[bcI]); + new ReturnInst(v1, getBBAt(bcI)); } void do_return_void(unsigned bcI) { - new ReturnInst(NULL, bc2bbMap_[bcI]); + new ReturnInst(NULL, getBBAt(bcI)); } void do_getstatic(unsigned bcI, unsigned index) { From alkis at cs.uiuc.edu Wed May 26 20:15:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 20:15:01 2004 Subject: [llvm-commits] CVS: llvm-java/test/Compiler/Arithm.java Message-ID: <200405270112.UAA05617@zion.cs.uiuc.edu> Changes in directory llvm-java/test/Compiler: Arithm.java updated: 1.1 -> 1.2 --- Log message: Add code to generate the INEG bytecode. --- Diffs of the changes: (+1 -1) Index: llvm-java/test/Compiler/Arithm.java diff -u llvm-java/test/Compiler/Arithm.java:1.1 llvm-java/test/Compiler/Arithm.java:1.2 --- llvm-java/test/Compiler/Arithm.java:1.1 Tue May 25 16:46:18 2004 +++ llvm-java/test/Compiler/Arithm.java Wed May 26 20:12:17 2004 @@ -6,6 +6,6 @@ int one = 1; int two = 2; - return (one + two) - (two * two) + (two / one) + (two % one) + (two << one) - (two >> 1); // = 4 + return (one + two) - (two * two) + (two / one) + (two % one) + (two << one) - (two >> 1) + (-two); // = 2 } } From alkis at cs.uiuc.edu Wed May 26 20:16:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 20:16:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405270113.UAA05655@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.33 -> 1.34 --- Log message: Implement the unary neg. --- Diffs of the changes: (+3 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.33 llvm-java/lib/Compiler/Compiler.cpp:1.34 --- llvm-java/lib/Compiler/Compiler.cpp:1.33 Wed May 26 20:04:20 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Wed May 26 20:13:06 2004 @@ -401,7 +401,9 @@ } void do_neg(unsigned bcI) { - assert(0 && "not implemented"); + Value* v1 = opStack_.top(); opStack_.pop(); + opStack_.push( + BinaryOperator::createNeg(v1, TMP, getBBAt(bcI))); } void do_shl(unsigned bcI) { From lattner at cs.uiuc.edu Wed May 26 20:24:04 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed May 26 20:24:04 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/SystemUtils.cpp Message-ID: <200405270121.UAA05724@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: SystemUtils.cpp updated: 1.24 -> 1.25 --- Log message: Changes to make libSupport build on systems that don't have the wait syscall. --- Diffs of the changes: (+12 -30) Index: llvm/lib/Support/SystemUtils.cpp diff -u llvm/lib/Support/SystemUtils.cpp:1.24 llvm/lib/Support/SystemUtils.cpp:1.25 --- llvm/lib/Support/SystemUtils.cpp:1.24 Fri Apr 16 00:35:58 2004 +++ llvm/lib/Support/SystemUtils.cpp Wed May 26 20:20:55 2004 @@ -134,6 +134,7 @@ const std::string &StdErrFile) { // FIXME: install sigalarm handler here for timeout... +#ifdef HAVE_SYS_WAIT_H int Child = fork(); switch (Child) { case -1: @@ -179,6 +180,11 @@ exit(1); } return Status; + +#else + std::cerr << "RunProgramWithTimeout not implemented on this platform!\n"; + return -1; +#endif } @@ -220,12 +226,7 @@ // int llvm::ExecWait(const char * const old_argv[], const char * const old_envp[]) { - // Child process ID - register int child; - - // Status from child process when it exits - int status; - +#ifdef HAVE_SYS_WAIT_H // // Create local versions of the parameters that can be passed into execve() // without creating const problems. @@ -233,56 +234,37 @@ char ** const argv = (char ** const) old_argv; char ** const envp = (char ** const) old_envp; - // // Create a child process. - // - switch (child=fork()) - { - // + switch (fork()) { // An error occured: Return to the caller. - // case -1: return 1; break; - // // Child process: Execute the program. - // case 0: execve (argv[0], argv, envp); - - // // If the execve() failed, we should exit and let the parent pick up // our non-zero exit status. - // exit (1); - break; - // // Parent process: Break out of the switch to do our processing. - // default: break; } - // // Parent process: Wait for the child process to termiante. - // + int status; if ((wait (&status)) == -1) - { return 1; - } - // // If the program exited normally with a zero exit status, return success! - // if (WIFEXITED (status) && (WEXITSTATUS(status) == 0)) - { return 0; - } +#else + std::cerr << "llvm::ExecWait not implemented on this platform!\n"; +#endif - // // Otherwise, return failure. - // return 1; } From alkis at cs.uiuc.edu Wed May 26 21:33:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 26 21:33:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405270230.VAA06286@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.34 -> 1.35 --- Log message: A Java CHAR is an unsigned short not an unsigned byte. --- Diffs of the changes: (+1 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.34 llvm-java/lib/Compiler/Compiler.cpp:1.35 --- llvm-java/lib/Compiler/Compiler.cpp:1.34 Wed May 26 20:13:06 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Wed May 26 21:29:55 2004 @@ -130,7 +130,7 @@ // model is finalized case REFERENCE: return PointerType::get(Type::SByteTy); case BOOLEAN: return Type::BoolTy; - case CHAR: return Type::UByteTy; + case CHAR: return Type::UShortTy; case FLOAT: return Type::FloatTy; case DOUBLE: return Type::DoubleTy; case BYTE: return Type::SByteTy; From vadve at cs.uiuc.edu Wed May 26 22:58:01 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Wed May 26 22:58:01 2004 Subject: [llvm-commits] CVS: poolalloc/lib/PoolAllocate/Makefile Message-ID: <200405270357.WAA07399@psmith.cs.uiuc.edu> Changes in directory poolalloc/lib/PoolAllocate: Makefile updated: 1.2 -> 1.3 --- Log message: *** empty log message *** --- Diffs of the changes: (+1 -1) Index: poolalloc/lib/PoolAllocate/Makefile diff -u poolalloc/lib/PoolAllocate/Makefile:1.2 poolalloc/lib/PoolAllocate/Makefile:1.3 --- poolalloc/lib/PoolAllocate/Makefile:1.2 Thu Aug 21 11:05:04 2003 +++ poolalloc/lib/PoolAllocate/Makefile Wed May 26 22:57:13 2004 @@ -1,5 +1,5 @@ # -# Indicate where we are relative to the top of the source tree. + Indicate where we are relative to the top of the source tree. # LEVEL=../.. From vadve at cs.uiuc.edu Wed May 26 23:08:01 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Wed May 26 23:08:01 2004 Subject: [llvm-commits] CVS: poolalloc/lib/PoolAllocate/Makefile Message-ID: <200405270407.XAA07494@psmith.cs.uiuc.edu> Changes in directory poolalloc/lib/PoolAllocate: Makefile updated: 1.3 -> 1.4 --- Log message: Undo previous checkin, which was unintentional. --- Diffs of the changes: (+1 -1) Index: poolalloc/lib/PoolAllocate/Makefile diff -u poolalloc/lib/PoolAllocate/Makefile:1.3 poolalloc/lib/PoolAllocate/Makefile:1.4 --- poolalloc/lib/PoolAllocate/Makefile:1.3 Wed May 26 22:57:13 2004 +++ poolalloc/lib/PoolAllocate/Makefile Wed May 26 23:07:08 2004 @@ -1,5 +1,5 @@ # - Indicate where we are relative to the top of the source tree. +# Indicate where we are relative to the top of the source tree. # LEVEL=../.. From lattner at cs.uiuc.edu Thu May 27 00:32:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:32:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/System/ Message-ID: <200405270528.AAA13342@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/System: --- Log message: Directory /home/vadve/shared/PublicCVS/llvm/include/llvm/System added to the repository --- Diffs of the changes: (+0 -0) From lattner at cs.uiuc.edu Thu May 27 00:33:05 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:33:05 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/System/Signals.h Message-ID: <200405270530.AAA13363@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/System: Signals.h updated: 1.9 -> 1.10 --- Log message: Moved header from include/Support/ to include/llvm/System --- Diffs of the changes: (+3 -3) Index: llvm/include/llvm/System/Signals.h diff -u llvm/include/llvm/System/Signals.h:1.9 llvm/include/llvm/System/Signals.h:1.10 --- llvm/include/llvm/System/Signals.h:1.9 Thu Feb 19 14:03:08 2004 +++ llvm/include/llvm/System/Signals.h Thu May 27 00:30:18 2004 @@ -1,4 +1,4 @@ -//===- Support/Signals.h - Signal Handling support --------------*- C++ -*-===// +//===- llvm/System/Signals.h - Signal Handling support ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#ifndef SUPPORT_SIGNALS_H -#define SUPPORT_SIGNALS_H +#ifndef LLVM_SYSTEM_SIGNALS_H +#define LLVM_SYSTEM_SIGNALS_H #include From lattner at cs.uiuc.edu Thu May 27 00:35:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:35:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/Signals.cpp Message-ID: <200405270531.AAA13660@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: Signals.cpp updated: 1.17 -> 1.18 --- Log message: Signals.h header moved. Eventually this should move into a lib/System library, but not right now. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Support/Signals.cpp diff -u llvm/lib/Support/Signals.cpp:1.17 llvm/lib/Support/Signals.cpp:1.18 --- llvm/lib/Support/Signals.cpp:1.17 Sat Feb 21 15:51:41 2004 +++ llvm/lib/Support/Signals.cpp Thu May 27 00:31:24 2004 @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include #include From lattner at cs.uiuc.edu Thu May 27 00:40:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:40:03 2004 Subject: [llvm-commits] CVS: llvm/utils/TableGen/SimpleInstrSelEmitter.cpp TableGen.cpp Message-ID: <200405270537.AAA17985@zion.cs.uiuc.edu> Changes in directory llvm/utils/TableGen: SimpleInstrSelEmitter.cpp updated: 1.1 -> 1.2 TableGen.cpp updated: 1.26 -> 1.27 --- Log message: Header file moved --- Diffs of the changes: (+2 -2) Index: llvm/utils/TableGen/SimpleInstrSelEmitter.cpp diff -u llvm/utils/TableGen/SimpleInstrSelEmitter.cpp:1.1 llvm/utils/TableGen/SimpleInstrSelEmitter.cpp:1.2 --- llvm/utils/TableGen/SimpleInstrSelEmitter.cpp:1.1 Tue Apr 6 14:31:31 2004 +++ llvm/utils/TableGen/SimpleInstrSelEmitter.cpp Thu May 27 00:36:52 2004 @@ -22,7 +22,7 @@ #include "Record.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include "Support/FileUtilities.h" #include "CodeEmitterGen.h" #include "RegisterInfoEmitter.h" Index: llvm/utils/TableGen/TableGen.cpp diff -u llvm/utils/TableGen/TableGen.cpp:1.26 llvm/utils/TableGen/TableGen.cpp:1.27 --- llvm/utils/TableGen/TableGen.cpp:1.26 Tue Apr 6 14:30:56 2004 +++ llvm/utils/TableGen/TableGen.cpp Thu May 27 00:36:52 2004 @@ -17,7 +17,7 @@ #include "Record.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include "Support/FileUtilities.h" #include "CodeEmitterGen.h" #include "RegisterInfoEmitter.h" From lattner at cs.uiuc.edu Thu May 27 00:41:05 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:41:05 2004 Subject: [llvm-commits] CVS: llvm/projects/Stacker/tools/stkrc/stkrc.cpp Message-ID: <200405270537.AAA18173@zion.cs.uiuc.edu> Changes in directory llvm/projects/Stacker/tools/stkrc: stkrc.cpp updated: 1.1 -> 1.2 --- Log message: Header moved --- Diffs of the changes: (+1 -1) Index: llvm/projects/Stacker/tools/stkrc/stkrc.cpp diff -u llvm/projects/Stacker/tools/stkrc/stkrc.cpp:1.1 llvm/projects/Stacker/tools/stkrc/stkrc.cpp:1.2 --- llvm/projects/Stacker/tools/stkrc/stkrc.cpp:1.1 Sun Nov 23 12:01:26 2003 +++ llvm/projects/Stacker/tools/stkrc/stkrc.cpp Thu May 27 00:37:32 2004 @@ -22,7 +22,7 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Analysis/Verifier.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:42:04 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:42:04 2004 Subject: [llvm-commits] CVS: llvm/tools/opt/opt.cpp Message-ID: <200405270538.AAA19105@zion.cs.uiuc.edu> Changes in directory llvm/tools/opt: opt.cpp updated: 1.89 -> 1.90 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/opt/opt.cpp diff -u llvm/tools/opt/opt.cpp:1.89 llvm/tools/opt/opt.cpp:1.90 --- llvm/tools/opt/opt.cpp:1.89 Thu Apr 1 23:06:57 2004 +++ llvm/tools/opt/opt.cpp Thu May 27 00:38:39 2004 @@ -21,7 +21,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachineImpls.h" #include "llvm/Support/PassNameParser.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include "Support/SystemUtils.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:42:20 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:42:20 2004 Subject: [llvm-commits] CVS: llvm/tools/llvm-as/llvm-as.cpp Message-ID: <200405270538.AAA19112@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-as: llvm-as.cpp updated: 1.26 -> 1.27 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/llvm-as/llvm-as.cpp diff -u llvm/tools/llvm-as/llvm-as.cpp:1.26 llvm/tools/llvm-as/llvm-as.cpp:1.27 --- llvm/tools/llvm-as/llvm-as.cpp:1.26 Thu Feb 19 14:32:12 2004 +++ llvm/tools/llvm-as/llvm-as.cpp Thu May 27 00:38:45 2004 @@ -20,7 +20,7 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Analysis/Verifier.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:43:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:43:01 2004 Subject: [llvm-commits] CVS: llvm/tools/llvm-nm/llvm-nm.cpp Message-ID: <200405270539.AAA19161@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-nm: llvm-nm.cpp updated: 1.13 -> 1.14 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/llvm-nm/llvm-nm.cpp diff -u llvm/tools/llvm-nm/llvm-nm.cpp:1.13 llvm/tools/llvm-nm/llvm-nm.cpp:1.14 --- llvm/tools/llvm-nm/llvm-nm.cpp:1.13 Wed Apr 21 11:11:40 2004 +++ llvm/tools/llvm-nm/llvm-nm.cpp Thu May 27 00:39:25 2004 @@ -20,7 +20,7 @@ #include "llvm/Bytecode/Reader.h" #include "Support/CommandLine.h" #include "Support/FileUtilities.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include #include From lattner at cs.uiuc.edu Thu May 27 00:44:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:44:02 2004 Subject: [llvm-commits] CVS: llvm/tools/bugpoint/bugpoint.cpp Message-ID: <200405270540.AAA19209@zion.cs.uiuc.edu> Changes in directory llvm/tools/bugpoint: bugpoint.cpp updated: 1.15 -> 1.16 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/bugpoint/bugpoint.cpp diff -u llvm/tools/bugpoint/bugpoint.cpp:1.15 llvm/tools/bugpoint/bugpoint.cpp:1.16 --- llvm/tools/bugpoint/bugpoint.cpp:1.15 Thu Feb 19 14:33:00 2004 +++ llvm/tools/bugpoint/bugpoint.cpp Thu May 27 00:39:54 2004 @@ -17,7 +17,7 @@ #include "llvm/Support/PassNameParser.h" #include "llvm/Support/ToolRunner.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include "Config/unistd.h" #include using namespace llvm; From lattner at cs.uiuc.edu Thu May 27 00:45:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:45:02 2004 Subject: [llvm-commits] CVS: llvm/tools/gccas/gccas.cpp Message-ID: <200405270541.AAA19434@zion.cs.uiuc.edu> Changes in directory llvm/tools/gccas: gccas.cpp updated: 1.96 -> 1.97 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/gccas/gccas.cpp diff -u llvm/tools/gccas/gccas.cpp:1.96 llvm/tools/gccas/gccas.cpp:1.97 --- llvm/tools/gccas/gccas.cpp:1.96 Sun Apr 18 00:21:01 2004 +++ llvm/tools/gccas/gccas.cpp Thu May 27 00:40:58 2004 @@ -23,7 +23,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:45:11 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:45:11 2004 Subject: [llvm-commits] CVS: llvm/tools/llc/Makefile llc.cpp Message-ID: <200405270541.AAA19663@zion.cs.uiuc.edu> Changes in directory llvm/tools/llc: Makefile updated: 1.50 -> 1.51 llc.cpp updated: 1.96 -> 1.97 --- Log message: Header file moved --- Diffs of the changes: (+2 -1) Index: llvm/tools/llc/Makefile diff -u llvm/tools/llc/Makefile:1.50 llvm/tools/llc/Makefile:1.51 --- llvm/tools/llc/Makefile:1.50 Thu Mar 11 12:16:33 2004 +++ llvm/tools/llc/Makefile Thu May 27 00:41:36 2004 @@ -10,6 +10,7 @@ TOOLNAME = llc USEDLIBS = cwriter \ sparcv9 \ + sparcv8 \ x86 \ powerpc \ selectiondag \ Index: llvm/tools/llc/llc.cpp diff -u llvm/tools/llc/llc.cpp:1.96 llvm/tools/llc/llc.cpp:1.97 --- llvm/tools/llc/llc.cpp:1.96 Tue Mar 16 15:47:20 2004 +++ llvm/tools/llc/llc.cpp Thu May 27 00:41:36 2004 @@ -21,7 +21,7 @@ #include "llvm/PassManager.h" #include "llvm/Pass.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:46:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:46:01 2004 Subject: [llvm-commits] CVS: llvm/tools/extract/extract.cpp Message-ID: <200405270540.AAA19216@zion.cs.uiuc.edu> Changes in directory llvm/tools/extract: extract.cpp updated: 1.22 -> 1.23 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/extract/extract.cpp diff -u llvm/tools/extract/extract.cpp:1.22 llvm/tools/extract/extract.cpp:1.23 --- llvm/tools/extract/extract.cpp:1.22 Thu Apr 22 18:07:39 2004 +++ llvm/tools/extract/extract.cpp Thu May 27 00:39:58 2004 @@ -19,7 +19,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Target/TargetData.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include using namespace llvm; From lattner at cs.uiuc.edu Thu May 27 00:46:14 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:46:14 2004 Subject: [llvm-commits] CVS: llvm/tools/llvm-db/llvm-db.cpp Message-ID: <200405270539.AAA19168@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-db: llvm-db.cpp updated: 1.2 -> 1.3 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/llvm-db/llvm-db.cpp diff -u llvm/tools/llvm-db/llvm-db.cpp:1.2 llvm/tools/llvm-db/llvm-db.cpp:1.3 --- llvm/tools/llvm-db/llvm-db.cpp:1.2 Thu Feb 19 14:32:12 2004 +++ llvm/tools/llvm-db/llvm-db.cpp Thu May 27 00:39:32 2004 @@ -14,7 +14,7 @@ #include "CLIDebugger.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include using namespace llvm; From lattner at cs.uiuc.edu Thu May 27 00:47:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:47:02 2004 Subject: [llvm-commits] CVS: llvm/include/Support/Signals.h Message-ID: <200405270542.AAA19876@zion.cs.uiuc.edu> Changes in directory llvm/include/Support: Signals.h (r1.9) removed --- Log message: Beta-test moving a header from include/Support into the llvm hierarchy: it seems to work :) --- Diffs of the changes: (+0 -0) From lattner at cs.uiuc.edu Thu May 27 00:48:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:48:01 2004 Subject: [llvm-commits] CVS: llvm/tools/lli/lli.cpp Message-ID: <200405270539.AAA19175@zion.cs.uiuc.edu> Changes in directory llvm/tools/lli: lli.cpp updated: 1.42 -> 1.43 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/lli/lli.cpp diff -u llvm/tools/lli/lli.cpp:1.42 llvm/tools/lli/lli.cpp:1.43 --- llvm/tools/lli/lli.cpp:1.42 Thu Feb 19 14:32:37 2004 +++ llvm/tools/lli/lli.cpp Thu May 27 00:39:32 2004 @@ -20,7 +20,7 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" using namespace llvm; From lattner at cs.uiuc.edu Thu May 27 00:48:17 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:48:17 2004 Subject: [llvm-commits] CVS: llvm/tools/llvm-ar/llvm-ar.cpp Message-ID: <200405270538.AAA19119@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-ar: llvm-ar.cpp updated: 1.11 -> 1.12 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/llvm-ar/llvm-ar.cpp diff -u llvm/tools/llvm-ar/llvm-ar.cpp:1.11 llvm/tools/llvm-ar/llvm-ar.cpp:1.12 --- llvm/tools/llvm-ar/llvm-ar.cpp:1.11 Thu Feb 19 14:32:12 2004 +++ llvm/tools/llvm-ar/llvm-ar.cpp Thu May 27 00:38:45 2004 @@ -15,7 +15,7 @@ #include "llvm/Bytecode/Reader.h" #include "Support/CommandLine.h" #include "Support/FileUtilities.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include #include From lattner at cs.uiuc.edu Thu May 27 00:49:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:49:01 2004 Subject: [llvm-commits] CVS: llvm/tools/gccld/Linker.cpp gccld.cpp Message-ID: <200405270539.AAA19184@zion.cs.uiuc.edu> Changes in directory llvm/tools/gccld: Linker.cpp updated: 1.24 -> 1.25 gccld.cpp updated: 1.71 -> 1.72 --- Log message: Header file moved --- Diffs of the changes: (+2 -2) Index: llvm/tools/gccld/Linker.cpp diff -u llvm/tools/gccld/Linker.cpp:1.24 llvm/tools/gccld/Linker.cpp:1.25 --- llvm/tools/gccld/Linker.cpp:1.24 Thu Apr 15 10:23:45 2004 +++ llvm/tools/gccld/Linker.cpp Thu May 27 00:39:32 2004 @@ -24,7 +24,7 @@ #include "Config/config.h" #include "Support/CommandLine.h" #include "Support/FileUtilities.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include "Support/SystemUtils.h" #include #include Index: llvm/tools/gccld/gccld.cpp diff -u llvm/tools/gccld/gccld.cpp:1.71 llvm/tools/gccld/gccld.cpp:1.72 --- llvm/tools/gccld/gccld.cpp:1.71 Fri May 7 16:47:36 2004 +++ llvm/tools/gccld/gccld.cpp Thu May 27 00:39:32 2004 @@ -31,7 +31,7 @@ #include "llvm/Transforms/Utils/Linker.h" #include "Support/CommandLine.h" #include "Support/FileUtilities.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include "Support/SystemUtils.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:50:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:50:01 2004 Subject: [llvm-commits] CVS: llvm/tools/llvm-dis/llvm-dis.cpp Message-ID: <200405270538.AAA19126@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-dis: llvm-dis.cpp updated: 1.42 -> 1.43 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/llvm-dis/llvm-dis.cpp diff -u llvm/tools/llvm-dis/llvm-dis.cpp:1.42 llvm/tools/llvm-dis/llvm-dis.cpp:1.43 --- llvm/tools/llvm-dis/llvm-dis.cpp:1.42 Thu Feb 19 14:32:12 2004 +++ llvm/tools/llvm-dis/llvm-dis.cpp Thu May 27 00:38:45 2004 @@ -22,7 +22,7 @@ #include "llvm/Bytecode/Reader.h" #include "llvm/Assembly/PrintModulePass.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:50:10 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:50:10 2004 Subject: [llvm-commits] CVS: llvm/tools/llvm-prof/llvm-prof.cpp Message-ID: <200405270538.AAA19133@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-prof: llvm-prof.cpp updated: 1.19 -> 1.20 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/llvm-prof/llvm-prof.cpp diff -u llvm/tools/llvm-prof/llvm-prof.cpp:1.19 llvm/tools/llvm-prof/llvm-prof.cpp:1.20 --- llvm/tools/llvm-prof/llvm-prof.cpp:1.19 Mon Mar 8 14:04:32 2004 +++ llvm/tools/llvm-prof/llvm-prof.cpp Thu May 27 00:38:45 2004 @@ -19,7 +19,7 @@ #include "llvm/Analysis/ProfileInfoLoader.h" #include "llvm/Bytecode/Reader.h" #include "Support/CommandLine.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include #include From lattner at cs.uiuc.edu Thu May 27 00:51:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:51:01 2004 Subject: [llvm-commits] CVS: llvm/tools/llvm-link/llvm-link.cpp Message-ID: <200405270538.AAA19138@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-link: llvm-link.cpp updated: 1.35 -> 1.36 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/llvm-link/llvm-link.cpp diff -u llvm/tools/llvm-link/llvm-link.cpp:1.35 llvm/tools/llvm-link/llvm-link.cpp:1.36 --- llvm/tools/llvm-link/llvm-link.cpp:1.35 Thu Feb 19 14:32:12 2004 +++ llvm/tools/llvm-link/llvm-link.cpp Thu May 27 00:38:45 2004 @@ -19,7 +19,7 @@ #include "llvm/Transforms/Utils/Linker.h" #include "Support/CommandLine.h" #include "Support/FileUtilities.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include #include From lattner at cs.uiuc.edu Thu May 27 00:52:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:52:02 2004 Subject: [llvm-commits] CVS: llvm/tools/analyze/analyze.cpp Message-ID: <200405270539.AAA19201@zion.cs.uiuc.edu> Changes in directory llvm/tools/analyze: analyze.cpp updated: 1.57 -> 1.58 --- Log message: Header file moved --- Diffs of the changes: (+1 -1) Index: llvm/tools/analyze/analyze.cpp diff -u llvm/tools/analyze/analyze.cpp:1.57 llvm/tools/analyze/analyze.cpp:1.58 --- llvm/tools/analyze/analyze.cpp:1.57 Thu Feb 19 14:32:58 2004 +++ llvm/tools/analyze/analyze.cpp Thu May 27 00:39:49 2004 @@ -23,7 +23,7 @@ #include "llvm/Analysis/Verifier.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/PassNameParser.h" -#include "Support/Signals.h" +#include "llvm/System/Signals.h" #include "Support/Timer.h" #include From lattner at cs.uiuc.edu Thu May 27 00:52:11 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:52:11 2004 Subject: [llvm-commits] CVS: llvm/tools/llc/Makefile Message-ID: <200405270544.AAA20218@zion.cs.uiuc.edu> Changes in directory llvm/tools/llc: Makefile updated: 1.51 -> 1.52 --- Log message: Uhh, that doesn't exist. --- Diffs of the changes: (+0 -1) Index: llvm/tools/llc/Makefile diff -u llvm/tools/llc/Makefile:1.51 llvm/tools/llc/Makefile:1.52 --- llvm/tools/llc/Makefile:1.51 Thu May 27 00:41:36 2004 +++ llvm/tools/llc/Makefile Thu May 27 00:44:22 2004 @@ -10,7 +10,6 @@ TOOLNAME = llc USEDLIBS = cwriter \ sparcv9 \ - sparcv8 \ x86 \ powerpc \ selectiondag \ From lattner at cs.uiuc.edu Thu May 27 00:54:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:54:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/Generic/GC/alloc_loop.ll Message-ID: <200405270551.AAA20362@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/Generic/GC: alloc_loop.ll updated: 1.1 -> 1.2 --- Log message: gc_init now gets an argument --- Diffs of the changes: (+2 -2) Index: llvm/test/Regression/CodeGen/Generic/GC/alloc_loop.ll diff -u llvm/test/Regression/CodeGen/Generic/GC/alloc_loop.ll:1.1 llvm/test/Regression/CodeGen/Generic/GC/alloc_loop.ll:1.2 --- llvm/test/Regression/CodeGen/Generic/GC/alloc_loop.ll:1.1 Sun May 23 16:24:50 2004 +++ llvm/test/Regression/CodeGen/Generic/GC/alloc_loop.ll Thu May 27 00:51:00 2004 @@ -1,7 +1,7 @@ implementation declare sbyte* %llvm_gc_allocate(uint) -declare void %llvm_gc_initialize() +declare void %llvm_gc_initialize(uint) declare void %llvm.gcroot(sbyte**, sbyte*) declare void %llvm.gcwrite(sbyte*, sbyte**) @@ -11,7 +11,7 @@ %A = alloca sbyte* %B = alloca sbyte** - call void %llvm_gc_initialize() + call void %llvm_gc_initialize(uint 1048576) ; Start with 1MB heap ;; void *A; call void %llvm.gcroot(sbyte** %A, sbyte* null) From lattner at cs.uiuc.edu Thu May 27 00:55:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:55:02 2004 Subject: [llvm-commits] CVS: llvm/docs/GarbageCollection.html Message-ID: <200405270552.AAA20998@zion.cs.uiuc.edu> Changes in directory llvm/docs: GarbageCollection.html updated: 1.3 -> 1.4 --- Log message: Continue the exposition --- Diffs of the changes: (+134 -26) Index: llvm/docs/GarbageCollection.html diff -u llvm/docs/GarbageCollection.html:1.3 llvm/docs/GarbageCollection.html:1.4 --- llvm/docs/GarbageCollection.html:1.3 Tue May 25 03:45:31 2004 +++ llvm/docs/GarbageCollection.html Thu May 27 00:52:10 2004 @@ -21,7 +21,6 @@
  • Interfaces for user programs
    • Identifying GC roots on the stack: llvm.gcroot
    • -
    • GC descriptor format for heap objects
    • Allocating memory from the GC
    • Reading and writing references to the heap
    • Explicit invocation of the garbage collector
    • @@ -31,10 +30,13 @@
    • Implementing a garbage collector
    • +
    • GC implementations available +
        +
      • SemiSpace - A simple copying garbage collector
      • + - -
        - -

        -TODO: Either from root meta data, or from object headers. Front-end can provide a -call-back to get descriptor from object without meta-data. -

        - -
        - - - @@ -282,13 +270,14 @@
        - void %llvm_gc_initialize() + void %llvm_gc_initialize(unsigned %InitialHeapSize)

        The llvm_gc_initialize function should be called once before any other garbage collection functions are called. This gives the garbage collector the -chance to initialize itself and allocate the heap spaces. +chance to initialize itself and allocate the heap spaces. The initial heap size +to allocate should be specified as an argument.

        @@ -323,7 +312,14 @@

        -Implementing a garbage collector for LLVM is fairly straight-forward. The +Implementing a garbage collector for LLVM is fairly straight-forward. The LLVM +garbage collectors are provided in a form that makes them easy to link into the +language-specific runtime that a language front-end would use. They require +functionality from the language-specific runtime to get information about where pointers are located in heap objects. +

        + +

        The implementation must include the llvm_gc_allocate and llvm_gc_collect functions, and it must implement @@ -363,7 +359,15 @@

        + +Garbage collector implementations make use of call-back functions that are +implemented by other parts of the LLVM system. + + +
        @@ -380,25 +384,129 @@

        + + - -
        +
        +TODO +
        + + + + + +
        +

        +The three most common ways to keep track of where pointers live in heap objects +are (listed in order of space overhead required):

        + +
          +
        1. In languages with polymorphic objects, pointers from an object header are +usually used to identify the GC pointers in the heap object. This is common for +object-oriented languages like Self, Smalltalk, Java, or C#.
        2. + +
        3. If heap objects are not polymorphic, often the "shape" of the heap can be +determined from the roots of the heap or from some other meta-data [Appel89, Goldberg91, Tolmach94]. In this case, the garbage collector can +propagate the information around from meta data stored with the roots. This +often eliminates the need to have a header on objects in the heap. This is +common in the ML family.
        4. + +
        5. If all heap objects have pointers in the same locations, or pointers can be +distinguished just by looking at them (e.g., the low order bit is clear), no +book-keeping is needed at all. This is common for Lisp-like languages.
        6. +
        + +

        The LLVM garbage collectors are capable of supporting all of these styles of +language, including ones that mix various implementations. To do this, it +allows the source-language to associate meta-data with the stack roots, and the heap tracing routines can propagate the +information. In addition, LLVM allows the front-end to extract GC information +from in any form from a specific object pointer (this supports situations #1 and +#3). +

        + +

        Making this efficient

        + + + +
        + + + + + +

        To make this more concrete, the currently implemented LLVM garbage collectors -all live in the llvm/runtime/GC directory in the LLVM source-base. +all live in the llvm/runtime/GC/* directories in the LLVM source-base. +If you are interested in implementing an algorithm, there are many interesting +possibilities (mark/sweep, a generational collector, a reference counting +collector, etc), or you could choose to improve one of the existing algorithms.

        +
        + + + + +

        -TODO: Brief overview of each. +SemiSpace is a very simple copying collector. When it starts up, it allocates +two blocks of memory for the heap. It uses a simple bump-pointer allocator to +allocate memory from the first block until it runs out of space. When it runs +out of space, it traces through all of the roots of the program, copying blocks +to the other half of the memory space.

        + +
        + Possible Improvements +
        + +
        + +

        +If a collection cycle happens and the heap is not compacted very much (say less +than 25% of the allocated memory was freed), the memory regions should be +doubled in size.

        + +
        + + + + + +
        + +

        [Appel89] Runtime Tags Aren't Necessary. Andrew +W. Appel. Lisp and Symbolic Computation 19(7):703-705, July 1989.

        + +

        [Goldberg91] Tag-free garbage collection for +strongly typed programming languages. Benjamin Goldberg. ACM SIGPLAN +PLDI'91.

        + +

        [Tolmach94] Tag-free garbage collection using +explicit type parameters. Andrew Tolmach. Proceedings of the 1994 ACM +conference on LISP and functional programming.

        + +
        @@ -411,7 +519,7 @@ Chris Lattner
        LLVM Compiler Infrastructure
        - Last modified: $Date: 2004/05/25 08:45:31 $ + Last modified: $Date: 2004/05/27 05:52:10 $ From lattner at cs.uiuc.edu Thu May 27 00:55:10 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 00:55:10 2004 Subject: [llvm-commits] CVS: llvm/runtime/GC/SemiSpace/semispace.c Message-ID: <200405270551.AAA20378@zion.cs.uiuc.edu> Changes in directory llvm/runtime/GC/SemiSpace: semispace.c updated: 1.2 -> 1.3 --- Log message: Continue the implementation --- Diffs of the changes: (+61 -37) Index: llvm/runtime/GC/SemiSpace/semispace.c diff -u llvm/runtime/GC/SemiSpace/semispace.c:1.2 llvm/runtime/GC/SemiSpace/semispace.c:1.3 --- llvm/runtime/GC/SemiSpace/semispace.c:1.2 Sun May 23 18:02:35 2004 +++ llvm/runtime/GC/SemiSpace/semispace.c Thu May 27 00:51:31 2004 @@ -18,37 +18,7 @@ #include "../GCInterface.h" #include #include - -/* FIXME: This should be in a code-generator specific library! - */ -typedef struct GCRoot { - void **RootPtr; - void *Meta; -} GCRoot; - -typedef struct GCRoots { - struct GCRoots *Next; - unsigned NumRoots; - GCRoot RootRecords[]; -} GCRoots; -GCRoots *llvm_gc_root_chain; - -static void llvm_cg_walk_gcroots(void (*FP)(void **Root, void *Meta)) { - GCRoots *R = llvm_gc_root_chain; - for (; R; R = R->Next) { - unsigned i, e; - for (i = 0, e = R->NumRoots; i != e; ++i) - FP(R->RootRecords[i].RootPtr, R->RootRecords[i].Meta); - } -} -/* END FIXME! */ - - - -/* We use no read/write barriers */ -void *llvm_gc_read(void **P) { return *P; } -void llvm_gc_write(void *V, void **P) { *P = V; } - +#include /* AllocPtr - This points to the next byte that is available for allocation. */ @@ -59,9 +29,22 @@ */ static char *AllocEnd; -void llvm_gc_initialize() { - AllocPtr = calloc(1, 1000); - AllocEnd = AllocPtr + 1000; +/* CurSpace/OtherSpace - These pointers point to the two regions of memory that + * we switch between. The unallocated portion of the CurSpace is known to be + * zero'd out, but the OtherSpace contains junk. + */ +static void *CurSpace, *OtherSpace; + +/* SpaceSize - The size of each space. */ +static unsigned SpaceSize; + +/* llvm_gc_initialize - Allocate the two spaces that we plan to switch between. + */ +void llvm_gc_initialize(unsigned InitialHeapSize) { + SpaceSize = InitialHeapSize/2; + CurSpace = AllocPtr = calloc(1, SpaceSize); + OtherSpace = malloc(SpaceSize); + AllocEnd = AllocPtr + SpaceSize; } /* We always want to inline the fast path, but never want to inline the slow @@ -81,18 +64,59 @@ static void* llvm_gc_alloc_slow(unsigned Size) { llvm_gc_collect(); + if (AllocPtr+Size > AllocEnd) { + fprintf(stderr, "Garbage collector ran out of memory " + "allocating object of size: %d\n", Size); + exit(1); + } + return llvm_gc_allocate(Size); } -static void process_root(void **Root, void *Meta) { +static void process_pointer(void **Root, void *Meta) { printf("process_root[0x%X] = 0x%X\n", (unsigned) Root, (unsigned) *Root); } void llvm_gc_collect() { + // Clear out the space we will be copying into. + // FIXME: This should do the copy, then clear out whatever space is left. + memset(OtherSpace, 0, SpaceSize); + printf("Garbage collecting!!\n"); - llvm_cg_walk_gcroots(process_root); + llvm_cg_walk_gcroots(process_pointer); abort(); +} + +/* We use no read/write barriers */ +void *llvm_gc_read(void **P) { return *P; } +void llvm_gc_write(void *V, void **P) { *P = V; } + + +/*===----------------------------------------------------------------------===** + * FIXME: This should be in a code-generator specific library, but for now this + * will work for all code generators. + */ +typedef struct GCRoot { + void **RootPtr; + void *Meta; +} GCRoot; - /* TODO: Iterate through roots. */ +typedef struct GCRoots { + struct GCRoots *Next; + unsigned NumRoots; + GCRoot RootRecords[]; +} GCRoots; +GCRoots *llvm_gc_root_chain; + +void llvm_cg_walk_gcroots(void (*FP)(void **Root, void *Meta)) { + GCRoots *R = llvm_gc_root_chain; + for (; R; R = R->Next) { + unsigned i, e; + for (i = 0, e = R->NumRoots; i != e; ++i) + FP(R->RootRecords[i].RootPtr, R->RootRecords[i].Meta); + } } +/* END FIXME! */ + + From lattner at cs.uiuc.edu Thu May 27 01:17:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 01:17:03 2004 Subject: [llvm-commits] CVS: llvm/tools/analyze/AnalysisWrappers.cpp Message-ID: <200405270613.BAA23411@zion.cs.uiuc.edu> Changes in directory llvm/tools/analyze: AnalysisWrappers.cpp updated: 1.9 -> 1.10 --- Log message: Add a simple pass. --- Diffs of the changes: (+45 -0) Index: llvm/tools/analyze/AnalysisWrappers.cpp diff -u llvm/tools/analyze/AnalysisWrappers.cpp:1.9 llvm/tools/analyze/AnalysisWrappers.cpp:1.10 --- llvm/tools/analyze/AnalysisWrappers.cpp:1.9 Fri Apr 2 14:56:33 2004 +++ llvm/tools/analyze/AnalysisWrappers.cpp Thu May 27 01:13:36 2004 @@ -17,8 +17,10 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Analysis/InstForest.h" +#include "llvm/Support/CallSite.h" using namespace llvm; @@ -37,4 +39,47 @@ }; RegisterAnalysis P1("instforest", "InstForest Printer"); +} + +namespace { + /// ExternalFunctionsPassedConstants - This pass prints out call sites to + /// external functions that are called with constant arguments. This can be + /// useful when looking for standard library functions we should constant fold + /// or handle in alias analyses. + struct ExternalFunctionsPassedConstants : public Pass { + virtual bool run(Module &M) { + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (I->isExternal()) { + bool PrintedFn = false; + for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); + UI != E; ++UI) + if (Instruction *User = dyn_cast(*UI)) { + CallSite CS = CallSite::get(User); + if (CS.getInstruction()) { + for (CallSite::arg_iterator AI = CS.arg_begin(), + E = CS.arg_end(); AI != E; ++AI) + if (isa(*AI)) { + if (!PrintedFn) { + std::cerr << "Function '" << I->getName() << "':\n"; + PrintedFn = true; + } + std::cerr << *User; + break; + } + } + } + } + + return false; + } + + void print(std::ostream &OS) const {} + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + } + }; + + RegisterAnalysis + P2("externalfnconstants", "Print external fn callsites passed constants"); } From lattner at cs.uiuc.edu Thu May 27 01:30:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 01:30:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp Message-ID: <200405270626.BAA24630@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: Local.cpp updated: 1.22 -> 1.23 --- Log message: Restructure call constant folding code a bit to make it simpler Add support for acos/asin/atan. 188.ammp contains three calls to acos with constant arguments. Constant folding it allows elimination of those 3 calls and three FP divisions of the results. --- Diffs of the changes: (+40 -39) Index: llvm/lib/Transforms/Utils/Local.cpp diff -u llvm/lib/Transforms/Utils/Local.cpp:1.22 llvm/lib/Transforms/Utils/Local.cpp:1.23 --- llvm/lib/Transforms/Utils/Local.cpp:1.22 Wed Apr 21 11:11:40 2004 +++ llvm/lib/Transforms/Utils/Local.cpp Thu May 27 01:26:28 2004 @@ -235,7 +235,17 @@ bool llvm::canConstantFoldCallTo(Function *F) { const std::string &Name = F->getName(); return Name == "sin" || Name == "cos" || Name == "tan" || Name == "sqrt" || - Name == "log" || Name == "log10" || Name == "exp" || Name == "pow"; + Name == "log" || Name == "log10" || Name == "exp" || Name == "pow" || + Name == "acos" || Name == "asin"; +} + +static Constant *ConstantFoldFP(double (*NativeFP)(double), double V, + const Type *Ty) { + errno = 0; + V = NativeFP(V); + if (errno == 0) + return ConstantFP::get(Ty, V); + return 0; } /// ConstantFoldCall - Attempt to constant fold a call to the specified function @@ -245,49 +255,40 @@ const std::string &Name = F->getName(); const Type *Ty = F->getReturnType(); - if (Name == "sin") { - if (Operands.size() == 1) - if (ConstantFP *CFP = dyn_cast(Operands[0])) - return ConstantFP::get(Ty, sin(CFP->getValue())); - - } else if (Name == "cos") { - if (Operands.size() == 1) - if (ConstantFP *CFP = dyn_cast(Operands[0])) - return ConstantFP::get(Ty, cos(CFP->getValue())); - - } else if (Name == "tan") { - if (Operands.size() == 1) - if (ConstantFP *CFP = dyn_cast(Operands[0])) - return ConstantFP::get(Ty, tan(CFP->getValue())); - - } else if (Name == "sqrt") { - if (Operands.size() == 1) - if (ConstantFP *CFP = dyn_cast(Operands[0])) - if (CFP->getValue() >= 0) - return ConstantFP::get(Ty, sqrt(CFP->getValue())); - } else if (Name == "exp") { - if (Operands.size() == 1) - if (ConstantFP *CFP = dyn_cast(Operands[0])) - return ConstantFP::get(Ty, exp(CFP->getValue())); - } else if (Name == "log") { - if (Operands.size() == 1) - if (ConstantFP *CFP = dyn_cast(Operands[0])) - if (CFP->getValue() > 0) - return ConstantFP::get(Ty, log(CFP->getValue())); - } else if (Name == "log10") { - if (Operands.size() == 1) - if (ConstantFP *CFP = dyn_cast(Operands[0])) - if (CFP->getValue() > 0) - return ConstantFP::get(Ty, log10(CFP->getValue())); - } else if (Name == "pow") { - if (Operands.size() == 2) - if (ConstantFP *Op1 = dyn_cast(Operands[0])) - if (ConstantFP *Op2 = dyn_cast(Operands[1])) { + if (Operands.size() == 1) { + if (ConstantFP *Op = dyn_cast(Operands[0])) { + double V = Op->getValue(); + if (Name == "sin") + return ConstantFP::get(Ty, sin(V)); + else if (Name == "cos") + return ConstantFP::get(Ty, cos(V)); + else if (Name == "tan") + return ConstantFP::get(Ty, tan(V)); + else if (Name == "sqrt" && V >= 0) + return ConstantFP::get(Ty, sqrt(V)); + else if (Name == "exp") + return ConstantFP::get(Ty, exp(V)); + else if (Name == "log" && V > 0) + return ConstantFP::get(Ty, log(V)); + else if (Name == "log10") + return ConstantFoldFP(log10, V, Ty); + else if (Name == "acos") + return ConstantFoldFP(acos, V, Ty); + else if (Name == "asin") + return ConstantFoldFP(asin, V, Ty); + else if (Name == "atan") + return ConstantFP::get(Ty, atan(V)); + } + } else if (Operands.size() == 2) { + if (ConstantFP *Op1 = dyn_cast(Operands[0])) + if (ConstantFP *Op2 = dyn_cast(Operands[1])) { + if (Name == "pow") { errno = 0; double V = pow(Op1->getValue(), Op2->getValue()); if (errno == 0) return ConstantFP::get(Ty, V); } + } } return 0; } From lattner at cs.uiuc.edu Thu May 27 02:05:05 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 02:05:05 2004 Subject: [llvm-commits] CVS: llvm/tools/analyze/AnalysisWrappers.cpp Message-ID: <200405270643.BAA25045@zion.cs.uiuc.edu> Changes in directory llvm/tools/analyze: AnalysisWrappers.cpp updated: 1.10 -> 1.11 --- Log message: Right, globals aren't values yet.. --- Diffs of the changes: (+1 -1) Index: llvm/tools/analyze/AnalysisWrappers.cpp diff -u llvm/tools/analyze/AnalysisWrappers.cpp:1.10 llvm/tools/analyze/AnalysisWrappers.cpp:1.11 --- llvm/tools/analyze/AnalysisWrappers.cpp:1.10 Thu May 27 01:13:36 2004 +++ llvm/tools/analyze/AnalysisWrappers.cpp Thu May 27 01:43:37 2004 @@ -58,7 +58,7 @@ if (CS.getInstruction()) { for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end(); AI != E; ++AI) - if (isa(*AI)) { + if (isa(*AI) || isa(*AI)) { if (!PrintedFn) { std::cerr << "Function '" << I->getName() << "':\n"; PrintedFn = true; From lattner at cs.uiuc.edu Thu May 27 02:28:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 02:28:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp Message-ID: <200405270725.CAA02781@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: Local.cpp updated: 1.23 -> 1.24 --- Log message: Implement constant folding of fmod, which is used a lot in povray --- Diffs of the changes: (+9 -2) Index: llvm/lib/Transforms/Utils/Local.cpp diff -u llvm/lib/Transforms/Utils/Local.cpp:1.23 llvm/lib/Transforms/Utils/Local.cpp:1.24 --- llvm/lib/Transforms/Utils/Local.cpp:1.23 Thu May 27 01:26:28 2004 +++ llvm/lib/Transforms/Utils/Local.cpp Thu May 27 02:25:00 2004 @@ -236,7 +236,7 @@ const std::string &Name = F->getName(); return Name == "sin" || Name == "cos" || Name == "tan" || Name == "sqrt" || Name == "log" || Name == "log10" || Name == "exp" || Name == "pow" || - Name == "acos" || Name == "asin"; + Name == "acos" || Name == "asin" || Name == "atan" || Name == "fmod"; } static Constant *ConstantFoldFP(double (*NativeFP)(double), double V, @@ -282,9 +282,16 @@ } else if (Operands.size() == 2) { if (ConstantFP *Op1 = dyn_cast(Operands[0])) if (ConstantFP *Op2 = dyn_cast(Operands[1])) { + double Op1V = Op1->getValue(), Op2V = Op2->getValue(); + if (Name == "pow") { errno = 0; - double V = pow(Op1->getValue(), Op2->getValue()); + double V = pow(Op1V, Op2V); + if (errno == 0) + return ConstantFP::get(Ty, V); + } else if (Name == "fmod") { + errno = 0; + double V = fmod(Op1V, Op2V); if (errno == 0) return ConstantFP::get(Ty, V); } From lattner at cs.uiuc.edu Thu May 27 02:36:00 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 02:36:00 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Linker/2003-01-30-LinkerTypeRename.ll Message-ID: <200405270732.CAA02855@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Linker: 2003-01-30-LinkerTypeRename.ll updated: 1.3 -> 1.4 --- Log message: Correct test. use "not grep" instead of "grep -v" --- Diffs of the changes: (+2 -2) Index: llvm/test/Regression/Linker/2003-01-30-LinkerTypeRename.ll diff -u llvm/test/Regression/Linker/2003-01-30-LinkerTypeRename.ll:1.3 llvm/test/Regression/Linker/2003-01-30-LinkerTypeRename.ll:1.4 --- llvm/test/Regression/Linker/2003-01-30-LinkerTypeRename.ll:1.3 Mon Sep 15 15:04:28 2003 +++ llvm/test/Regression/Linker/2003-01-30-LinkerTypeRename.ll Thu May 27 02:32:25 2004 @@ -1,9 +1,9 @@ ; This fails because the linker renames the non-opaque type not the opaque ; one... -; RUN: echo "%Ty = type opaque" | llvm-as > %t.1.bc +; RUN: echo "%Ty = type opaque %GV = external global %Ty*" | llvm-as > %t.1.bc ; RUN: llvm-as < %s > %t.2.bc -; RUN: llvm-link %t.[12].bc | llvm-dis | grep '%Ty ' | grep -v opaque +; RUN: llvm-link %t.[12].bc | llvm-dis | grep '%Ty ' | not grep opaque %Ty = type int From lattner at cs.uiuc.edu Thu May 27 02:39:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 02:39:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Other/2002-03-11-ExprAssertion.ll 2002-03-14-ValueToLarge.ll Message-ID: <200405270736.CAA02899@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Other: 2002-03-11-ExprAssertion.ll (r1.1) removed 2002-03-14-ValueToLarge.ll (r1.1) removed --- Log message: The -exprs pass is no longer with LLVM. *sniff* --- Diffs of the changes: (+0 -0) From lattner at cs.uiuc.edu Thu May 27 02:41:00 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 02:41:00 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/CorrelatedExprs/nullpointer.ll Message-ID: <200405270737.CAA02930@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/CorrelatedExprs: nullpointer.ll updated: 1.3 -> 1.4 --- Log message: Make the test test what it is supposed to --- Diffs of the changes: (+5 -0) Index: llvm/test/Regression/Transforms/CorrelatedExprs/nullpointer.ll diff -u llvm/test/Regression/Transforms/CorrelatedExprs/nullpointer.ll:1.3 llvm/test/Regression/Transforms/CorrelatedExprs/nullpointer.ll:1.4 --- llvm/test/Regression/Transforms/CorrelatedExprs/nullpointer.ll:1.3 Tue Sep 16 10:29:23 2003 +++ llvm/test/Regression/Transforms/CorrelatedExprs/nullpointer.ll Thu May 27 02:37:45 2004 @@ -5,6 +5,9 @@ implementation ; Functions: +declare void %foo() +declare void %bar() + int %nullptr(int* %j) { bb0: store int 7, int* %j ; j != null @@ -12,7 +15,9 @@ br bool %cond220, label %bb3, label %bb4 ; direct branch bb3: + call void %foo() ret int 4 ; Dead code bb4: + call void %bar() ret int 3 ; Live code } From lattner at cs.uiuc.edu Thu May 27 02:43:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 02:43:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/phi.ll Message-ID: <200405270740.CAA02959@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: phi.ll updated: 1.9 -> 1.10 --- Log message: remove bogus test --- Diffs of the changes: (+0 -12) Index: llvm/test/Regression/Transforms/InstCombine/phi.ll diff -u llvm/test/Regression/Transforms/InstCombine/phi.ll:1.9 llvm/test/Regression/Transforms/InstCombine/phi.ll:1.10 --- llvm/test/Regression/Transforms/InstCombine/phi.ll:1.9 Fri Feb 27 23:26:06 2004 +++ llvm/test/Regression/Transforms/InstCombine/phi.ll Thu May 27 02:39:51 2004 @@ -43,15 +43,3 @@ br label %Loop } -bool %test4(bool %A) { - br bool %A, label %BB1, label %BB2 -BB1: - br label %Ret -BB2: - br label %Ret -Ret: - %B = phi int [1000, %BB1], [123, %BB2] - %C = cast int %B to bool - ret bool %C -} - From llvm at cs.uiuc.edu Thu May 27 03:29:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 03:29:01 2004 Subject: [llvm-commits] CVS: llvm/tools/opt/opt.cpp Message-ID: <200405270826.DAA03177@zion.cs.uiuc.edu> Changes in directory llvm/tools/opt: opt.cpp updated: 1.90 -> 1.91 --- Log message: Removed the -q option and the default message written to stderr. The output produces confusing results in TestRunner.sh --- Diffs of the changes: (+3 -6) Index: llvm/tools/opt/opt.cpp diff -u llvm/tools/opt/opt.cpp:1.90 llvm/tools/opt/opt.cpp:1.91 --- llvm/tools/opt/opt.cpp:1.90 Thu May 27 00:38:39 2004 +++ llvm/tools/opt/opt.cpp Thu May 27 03:26:22 2004 @@ -62,9 +62,6 @@ static cl::opt Quiet("q", cl::desc("Don't print 'program modified' message")); -static cl::alias -QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet)); - //===----------------------------------------------------------------------===// // main for opt @@ -164,8 +161,8 @@ Passes.add(new WriteBytecodePass(Out, Out != &std::cout)); // Now that we have all of the passes ready, run them. - if (Passes.run(*M.get()) && !Quiet) - std::cerr << "Program modified.\n"; + if (Passes.run(*M.get())) + return 0; - return 0; + return 1; } From llvm at cs.uiuc.edu Thu May 27 03:32:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 03:32:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/Generic/BasicInstrs.c Message-ID: <200405270828.DAA03206@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/Generic: BasicInstrs.c updated: 1.1 -> 1.2 --- Log message: Added a "RUN:" line so this file can be executed by TestRunner.sh --- Diffs of the changes: (+2 -0) Index: llvm/test/Regression/CodeGen/Generic/BasicInstrs.c diff -u llvm/test/Regression/CodeGen/Generic/BasicInstrs.c:1.1 llvm/test/Regression/CodeGen/Generic/BasicInstrs.c:1.2 --- llvm/test/Regression/CodeGen/Generic/BasicInstrs.c:1.1 Wed Apr 7 00:06:39 2004 +++ llvm/test/Regression/CodeGen/Generic/BasicInstrs.c Thu May 27 03:28:42 2004 @@ -1,5 +1,7 @@ // This file can be used to see what a native C compiler is generating for a // variety of interesting operations. +// +// RUN: $LLVMGCCDIR/bin/gcc -c %s unsigned int udiv(unsigned int X, unsigned int Y) { return X/Y; } From alkis at cs.uiuc.edu Thu May 27 07:54:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 07:54:01 2004 Subject: [llvm-commits] CVS: llvm-java/test/ClassFile/Simple.java Message-ID: <200405271250.HAA03935@zion.cs.uiuc.edu> Changes in directory llvm-java/test/ClassFile: Simple.java updated: 1.4 -> 1.5 --- Log message: Remove package from test cases as it only clutters the generated llvm code. --- Diffs of the changes: (+0 -2) Index: llvm-java/test/ClassFile/Simple.java diff -u llvm-java/test/ClassFile/Simple.java:1.4 llvm-java/test/ClassFile/Simple.java:1.5 --- llvm-java/test/ClassFile/Simple.java:1.4 Mon May 24 15:01:26 2004 +++ llvm-java/test/ClassFile/Simple.java Thu May 27 07:50:41 2004 @@ -1,5 +1,3 @@ -package edu.uiuc.cs.llvm; - public class Simple { public static int main(String[] args) { From alkis at cs.uiuc.edu Thu May 27 07:55:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 07:55:01 2004 Subject: [llvm-commits] CVS: llvm-java/test/Compiler/TableSwitch.java LookupSwitch.java If.java Arithm.java Message-ID: <200405271250.HAA03936@zion.cs.uiuc.edu> Changes in directory llvm-java/test/Compiler: TableSwitch.java updated: 1.1 -> 1.2 LookupSwitch.java updated: 1.1 -> 1.2 If.java updated: 1.1 -> 1.2 Arithm.java updated: 1.2 -> 1.3 --- Log message: Remove package from test cases as it only clutters the generated llvm code. --- Diffs of the changes: (+0 -8) Index: llvm-java/test/Compiler/TableSwitch.java diff -u llvm-java/test/Compiler/TableSwitch.java:1.1 llvm-java/test/Compiler/TableSwitch.java:1.2 --- llvm-java/test/Compiler/TableSwitch.java:1.1 Tue May 25 16:46:18 2004 +++ llvm-java/test/Compiler/TableSwitch.java Thu May 27 07:50:41 2004 @@ -1,5 +1,3 @@ -package edu.uiuc.cs.llvm; - public class TableSwitch { public static int main(String[] args) { Index: llvm-java/test/Compiler/LookupSwitch.java diff -u llvm-java/test/Compiler/LookupSwitch.java:1.1 llvm-java/test/Compiler/LookupSwitch.java:1.2 --- llvm-java/test/Compiler/LookupSwitch.java:1.1 Tue May 25 16:46:18 2004 +++ llvm-java/test/Compiler/LookupSwitch.java Thu May 27 07:50:41 2004 @@ -1,5 +1,3 @@ -package edu.uiuc.cs.llvm; - public class LookupSwitch { public static int main(String[] args) { Index: llvm-java/test/Compiler/If.java diff -u llvm-java/test/Compiler/If.java:1.1 llvm-java/test/Compiler/If.java:1.2 --- llvm-java/test/Compiler/If.java:1.1 Tue May 25 16:46:18 2004 +++ llvm-java/test/Compiler/If.java Thu May 27 07:50:41 2004 @@ -1,5 +1,3 @@ -package edu.uiuc.cs.llvm; - public class If { public static int main(String[] args) { Index: llvm-java/test/Compiler/Arithm.java diff -u llvm-java/test/Compiler/Arithm.java:1.2 llvm-java/test/Compiler/Arithm.java:1.3 --- llvm-java/test/Compiler/Arithm.java:1.2 Wed May 26 20:12:17 2004 +++ llvm-java/test/Compiler/Arithm.java Thu May 27 07:50:41 2004 @@ -1,5 +1,3 @@ -package edu.uiuc.cs.llvm; - public class Arithm { public static int main(String[] args) { From alkis at cs.uiuc.edu Thu May 27 10:06:05 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 10:06:05 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405271502.KAA04263@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.35 -> 1.36 --- Log message: Correct FIXME. --- Diffs of the changes: (+2 -2) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.35 llvm-java/lib/Compiler/Compiler.cpp:1.36 --- llvm-java/lib/Compiler/Compiler.cpp:1.35 Wed May 26 21:29:55 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Thu May 27 10:02:44 2004 @@ -126,8 +126,8 @@ private: const Type* getType(JType type) { switch (type) { - // FIXME: this should really be a non-void type when the object - // model is finalized + // FIXME: this should really be a pointer to an Object + // type when the object model is finalized case REFERENCE: return PointerType::get(Type::SByteTy); case BOOLEAN: return Type::BoolTy; case CHAR: return Type::UShortTy; From llvm at cs.uiuc.edu Thu May 27 11:32:04 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 11:32:04 2004 Subject: [llvm-commits] CVS: llvm/tools/opt/opt.cpp Message-ID: <200405271629.LAA05913@zion.cs.uiuc.edu> Changes in directory llvm/tools/opt: opt.cpp updated: 1.91 -> 1.92 --- Log message: Re-introduce the -q option and make opt always return 0, even if the optimization pasess fail. This is necessary to avoid breaking feature tests in the tests suite that depend on this behavior. *sigh* --- Diffs of the changes: (+7 -3) Index: llvm/tools/opt/opt.cpp diff -u llvm/tools/opt/opt.cpp:1.91 llvm/tools/opt/opt.cpp:1.92 --- llvm/tools/opt/opt.cpp:1.91 Thu May 27 03:26:22 2004 +++ llvm/tools/opt/opt.cpp Thu May 27 11:28:54 2004 @@ -62,6 +62,9 @@ static cl::opt Quiet("q", cl::desc("Don't print 'program modified' message")); +static cl::alias +QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet)); + //===----------------------------------------------------------------------===// // main for opt @@ -114,7 +117,8 @@ // If the output is set to be emitted to standard out, and standard out is a // console, print out a warning message and refuse to do it. We don't impress // anyone by spewing tons of binary goo to a terminal. - if (Out == &std::cout && isStandardOutAConsole() && !Force && !NoOutput) { + if (Out == &std::cout && isStandardOutAConsole() && !Force && !NoOutput + && !Quiet) { std::cerr << "WARNING: It looks like you're attempting to print out a " << "bytecode file. I'm\ngoing to pretend you didn't ask me to do" << " this (for your own good). If you\nREALLY want to taste LLVM" @@ -161,8 +165,8 @@ Passes.add(new WriteBytecodePass(Out, Out != &std::cout)); // Now that we have all of the passes ready, run them. - if (Passes.run(*M.get())) + if (Passes.run(*M.get()) ) return 0; - return 1; + return 0; } From lattner at cs.uiuc.edu Thu May 27 12:32:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 12:32:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/load.ll Message-ID: <200405271729.MAA05285@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: load.ll updated: 1.4 -> 1.5 --- Log message: Add another testcase --- Diffs of the changes: (+7 -5) Index: llvm/test/Regression/Transforms/InstCombine/load.ll diff -u llvm/test/Regression/Transforms/InstCombine/load.ll:1.4 llvm/test/Regression/Transforms/InstCombine/load.ll:1.5 --- llvm/test/Regression/Transforms/InstCombine/load.ll:1.4 Tue Sep 16 10:29:34 2003 +++ llvm/test/Regression/Transforms/InstCombine/load.ll Thu May 27 12:28:55 2004 @@ -6,10 +6,7 @@ %X = constant int 42 %Y = constant [2 x { int, float }] [ { int, float } { int 12, float 1.0 }, { int, float } { int 37, float 1.2312 } ] -int %test1() { - %B = load int* %X - ret int %B -} +%Z = constant [2 x { int, float }] zeroinitializer float %test2() { %A = getelementptr [2 x { int, float}]* %Y, long 0, long 1, ubyte 1 @@ -17,10 +14,15 @@ ret float %B } + int %test3() { %A = getelementptr [2 x { int, float}]* %Y, long 0, long 0, ubyte 0 %B = load int* %A ret int %B } - +int %test4() { + %A = getelementptr [2 x { int, float}]* %Z, long 0, long 1, ubyte 0 + %B = load int* %A + ret int %B +} From lattner at cs.uiuc.edu Thu May 27 12:34:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 12:34:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200405271730.MAA07957@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.205 -> 1.206 --- Log message: Fix InstCombine/load.ll & PR347: http://llvm.cs.uiuc.edu/PR347 . This code hadn't been updated after the "structs with more than 256 elements" related changes to the GEP instruction. Also it was not handling the ConstantAggregateZero class. Now it does! --- Diffs of the changes: (+24 -12) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.205 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.206 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.205 Tue May 25 01:32:08 2004 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu May 27 12:30:27 2004 @@ -2852,19 +2852,31 @@ // Loop over all of the operands, tracking down which value we are // addressing... - for (unsigned i = 2, e = CE->getNumOperands(); i != e; ++i) - if (ConstantUInt *CU = dyn_cast(CE->getOperand(i))) { - ConstantStruct *CS = dyn_cast(C); - if (CS == 0) return 0; - if (CU->getValue() >= CS->getValues().size()) return 0; - C = cast(CS->getValues()[CU->getValue()]); - } else if (ConstantSInt *CS = dyn_cast(CE->getOperand(i))) { - ConstantArray *CA = dyn_cast(C); - if (CA == 0) return 0; - if ((uint64_t)CS->getValue() >= CA->getValues().size()) return 0; - C = cast(CA->getValues()[CS->getValue()]); - } else + gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE); + for (++I; I != E; ++I) + if (const StructType *STy = dyn_cast(*I)) { + ConstantUInt *CU = cast(I.getOperand()); + assert(CU->getValue() < STy->getNumElements() && + "Struct index out of range!"); + if (ConstantStruct *CS = dyn_cast(C)) { + C = cast(CS->getValues()[CU->getValue()]); + } else if (isa(C)) { + C = Constant::getNullValue(STy->getElementType(CU->getValue())); + } else { + return 0; + } + } else if (ConstantInt *CI = dyn_cast(I.getOperand())) { + const ArrayType *ATy = cast(*I); + if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0; + if (ConstantArray *CA = dyn_cast(C)) + C = cast(CA->getValues()[CI->getRawValue()]); + else if (isa(C)) + C = Constant::getNullValue(ATy->getElementType()); + else + return 0; + } else { return 0; + } return C; } From lattner at cs.uiuc.edu Thu May 27 12:47:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 12:47:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/load.ll Message-ID: <200405271743.MAA08448@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: load.ll updated: 1.5 -> 1.6 --- Log message: Add back a test I accidentally removed --- Diffs of the changes: (+5 -0) Index: llvm/test/Regression/Transforms/InstCombine/load.ll diff -u llvm/test/Regression/Transforms/InstCombine/load.ll:1.5 llvm/test/Regression/Transforms/InstCombine/load.ll:1.6 --- llvm/test/Regression/Transforms/InstCombine/load.ll:1.5 Thu May 27 12:28:55 2004 +++ llvm/test/Regression/Transforms/InstCombine/load.ll Thu May 27 12:43:33 2004 @@ -8,6 +8,11 @@ { int, float } { int 37, float 1.2312 } ] %Z = constant [2 x { int, float }] zeroinitializer +int %test1() { + %B = load int* %X + ret int %B +} + float %test2() { %A = getelementptr [2 x { int, float}]* %Y, long 0, long 1, ubyte 1 %B = load float* %A From lattner at cs.uiuc.edu Thu May 27 12:48:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 12:48:01 2004 Subject: [llvm-commits] CVS: llvm/utils/TableGen/FileLexer.l Message-ID: <200405271744.MAA08546@zion.cs.uiuc.edu> Changes in directory llvm/utils/TableGen: FileLexer.l updated: 1.21 -> 1.22 --- Log message: Add support for dos style files. --- Diffs of the changes: (+1 -1) Index: llvm/utils/TableGen/FileLexer.l diff -u llvm/utils/TableGen/FileLexer.l:1.21 llvm/utils/TableGen/FileLexer.l:1.22 --- llvm/utils/TableGen/FileLexer.l:1.21 Fri Feb 13 10:37:43 2004 +++ llvm/utils/TableGen/FileLexer.l Thu May 27 12:44:18 2004 @@ -205,7 +205,7 @@ {Integer} { Filelval.IntVal = ParseInt(Filetext); return INTVAL; } -[ \t\n]+ { /* Ignore whitespace */ } +[ \t\n\r]+ { /* Ignore whitespace */ } "/*" { BEGIN(comment); CommentDepth++; } From lattner at cs.uiuc.edu Thu May 27 12:52:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 12:52:02 2004 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/Lexer.l Message-ID: <200405271749.MAA08790@zion.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: Lexer.l updated: 1.48 -> 1.49 --- Log message: Add support for dos-style files --- Diffs of the changes: (+1 -1) Index: llvm/lib/AsmParser/Lexer.l diff -u llvm/lib/AsmParser/Lexer.l:1.48 llvm/lib/AsmParser/Lexer.l:1.49 --- llvm/lib/AsmParser/Lexer.l:1.48 Tue Mar 30 21:48:33 2004 +++ llvm/lib/AsmParser/Lexer.l Thu May 27 12:49:14 2004 @@ -314,7 +314,7 @@ return EOF; } -[ \t\n] { /* Ignore whitespace */ } +[ \r\t\n] { /* Ignore whitespace */ } . { return yytext[0]; } %% From lattner at cs.uiuc.edu Thu May 27 13:02:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 13:02:02 2004 Subject: [llvm-commits] CVS: llvm/utils/getsrcs.sh Message-ID: <200405271758.MAA09216@zion.cs.uiuc.edu> Changes in directory llvm/utils: getsrcs.sh updated: 1.16 -> 1.17 --- Log message: doxygen no longer builds into the docs tree, and we no longer have boost in the tree --- Diffs of the changes: (+1 -1) Index: llvm/utils/getsrcs.sh diff -u llvm/utils/getsrcs.sh:1.16 llvm/utils/getsrcs.sh:1.17 --- llvm/utils/getsrcs.sh:1.16 Sun Apr 18 13:26:38 2004 +++ llvm/utils/getsrcs.sh Thu May 27 12:58:45 2004 @@ -4,7 +4,7 @@ find docs include lib tools utils projects -name \*.\[cdhyl\]\* | grep -v Lexer.cpp | \ grep -v llvmAsmParser.cpp | grep -v llvmAsmParser.h | grep -v '~$' | \ grep -v '\.ll$' | grep -v .flc | grep -v Sparc.burm.c | grep -v '\.d$' |\ - grep -v '\.dir$' | grep -v www/docs/doxygen | grep -v include/boost | \ + grep -v '\.dir$' | grep -v '\.la$' | \ grep -v /Burg/ | grep -v '\.lo' | grep -v '\.inc$' | grep -v '\.libs' | \ grep -v TableGen/FileParser.cpp | grep -v TableGen/FileParser.h From lattner at cs.uiuc.edu Thu May 27 13:07:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 13:07:02 2004 Subject: [llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/Emitter.cpp Message-ID: <200405271804.NAA09492@zion.cs.uiuc.edu> Changes in directory llvm/lib/ExecutionEngine/JIT: Emitter.cpp updated: 1.40 -> 1.41 --- Log message: This code is a real mess, but at least get the JIT *building* on platforms (such as plan 9) without mmap. Of course it won't RUN... but that's another step. :) --- Diffs of the changes: (+8 -0) Index: llvm/lib/ExecutionEngine/JIT/Emitter.cpp diff -u llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.40 llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.41 --- llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.40 Fri Apr 23 12:11:14 2004 +++ llvm/lib/ExecutionEngine/JIT/Emitter.cpp Thu May 27 13:03:56 2004 @@ -60,6 +60,7 @@ static const long pageSize = sysconf(_SC_PAGESIZE); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; +/* FIXME: This should use the proper autoconf flags */ #if defined(i386) || defined(__i386__) || defined(__x86__) /* Linux and *BSD tend to have these flags named differently. */ #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) @@ -70,8 +71,10 @@ #else std::cerr << "This architecture is not supported by the JIT!\n"; abort(); + return 0; #endif +#ifdef HAVE_MMAP int fd = -1; #if defined(__linux__) fd = 0; @@ -89,6 +92,11 @@ abort(); } return pa; +#else + std::cerr << "Do not know how to allocate mem for the JIT without mmap!\n"; + abort(); + return 0; +#endif } JITMemoryManager::JITMemoryManager() { From lattner at cs.uiuc.edu Thu May 27 13:32:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 13:32:02 2004 Subject: [llvm-commits] CVS: llvm/projects/Stacker/lib/compiler/Lexer.l Message-ID: <200405271828.NAA10780@zion.cs.uiuc.edu> Changes in directory llvm/projects/Stacker/lib/compiler: Lexer.l updated: 1.3 -> 1.4 --- Log message: Add support for dos-style files --- Diffs of the changes: (+1 -1) Index: llvm/projects/Stacker/lib/compiler/Lexer.l diff -u llvm/projects/Stacker/lib/compiler/Lexer.l:1.3 llvm/projects/Stacker/lib/compiler/Lexer.l:1.4 --- llvm/projects/Stacker/lib/compiler/Lexer.l:1.3 Sun May 9 18:20:19 2004 +++ llvm/projects/Stacker/lib/compiler/Lexer.l Thu May 27 13:28:32 2004 @@ -71,7 +71,7 @@ /* You can also embed them in ( ... ) */ Comment2 \(.*\) /* We ignore white space */ -White [ \t\n] +White [ \t\r\n] /* jdentifiers start with a % sign */ Identifier [A-Za-z][-A-Za-z0-9_]* From alkis at cs.uiuc.edu Thu May 27 14:41:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 14:41:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/ClassFile/ClassFile.cpp Message-ID: <200405271937.OAA19838@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/ClassFile: ClassFile.cpp updated: 1.9 -> 1.10 --- Log message: Fix constant pool parsing. Doubles and longs take two slots in the constant pool (yuck). --- Diffs of the changes: (+4 -2) Index: llvm-java/lib/ClassFile/ClassFile.cpp diff -u llvm-java/lib/ClassFile/ClassFile.cpp:1.9 llvm-java/lib/ClassFile/ClassFile.cpp:1.10 --- llvm-java/lib/ClassFile/ClassFile.cpp:1.9 Sat May 22 00:57:09 2004 +++ llvm-java/lib/ClassFile/ClassFile.cpp Thu May 27 14:37:27 2004 @@ -66,9 +66,11 @@ uint16_t count = readU2(is); cp.reserve(count); cp.push_back(NULL); - --count; - while (count--) + while (cp.size() < count) { cp.push_back(Constant::readConstant(cp, is)); + if (cp.back()->isDoubleSlot()) + cp.push_back(NULL); + } } void readClasses(Classes& i, const ConstantPool& cp, std::istream& is) From alkis at cs.uiuc.edu Thu May 27 14:41:12 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 14:41:12 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405271937.OAA19839@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.11 -> 1.12 --- Log message: Fix constant pool parsing. Doubles and longs take two slots in the constant pool (yuck). --- Diffs of the changes: (+4 -0) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.11 llvm-java/include/llvm/Java/ClassFile.h:1.12 --- llvm-java/include/llvm/Java/ClassFile.h:1.11 Mon May 24 17:03:22 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Thu May 27 14:37:27 2004 @@ -134,6 +134,8 @@ static Constant* readConstant(const ConstantPool& cp, std::istream& is); + virtual bool isSingleSlot() { return true; } + bool isDoubleSlot() { return !isSingleSlot(); } virtual ~Constant(); virtual std::ostream& dump(std::ostream& os) const = 0; @@ -214,6 +216,7 @@ int64_t value_; public: ConstantLong(const ConstantPool& cp, std::istream& is); + virtual bool isSingleSlot() { return false; } int64_t getValue() const { return value_; } std::ostream& dump(std::ostream& os) const; }; @@ -222,6 +225,7 @@ double value_; public: ConstantDouble(const ConstantPool& cp, std::istream& is); + virtual bool isSingleSlot() { return false; } double getValue() const { return value_; } std::ostream& dump(std::ostream& os) const; }; From llvm at cs.uiuc.edu Thu May 27 15:22:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 15:22:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Writer/Writer.cpp Message-ID: <200405272019.PAA20018@zion.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Writer: Writer.cpp updated: 1.64 -> 1.65 --- Log message: Use the SymbolTable::isEmpty() method instead of checking for no value planes. A SymbolTable could still have types in it! This fixes problems with two regression tests that failed because a symbol table that only contained types was being omitted from bytecode files. Thanks to Chris for the reduced test case that helped find this immediately. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Bytecode/Writer/Writer.cpp diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.64 llvm/lib/Bytecode/Writer/Writer.cpp:1.65 --- llvm/lib/Bytecode/Writer/Writer.cpp:1.64 Wed May 26 02:37:11 2004 +++ llvm/lib/Bytecode/Writer/Writer.cpp Thu May 27 15:18:51 2004 @@ -307,7 +307,7 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { // Do not output the Bytecode block for an empty symbol table, it just wastes // space! - if (MST.plane_begin() == MST.plane_end()) return; + if ( MST.isEmpty() ) return; BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTable, Out, true/* ElideIfEmpty*/); From alkis at cs.uiuc.edu Thu May 27 15:28:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 15:28:01 2004 Subject: [llvm-commits] CVS: llvm-java/test/Compiler/BigConstants.java Message-ID: <200405272024.PAA20079@zion.cs.uiuc.edu> Changes in directory llvm-java/test/Compiler: BigConstants.java added (r1.1) --- Log message: Add test case for testing LDC, LDC_W and LDC2_W bytecodes. --- Diffs of the changes: (+11 -0) Index: llvm-java/test/Compiler/BigConstants.java diff -c /dev/null llvm-java/test/Compiler/BigConstants.java:1.1 *** /dev/null Thu May 27 15:24:59 2004 --- llvm-java/test/Compiler/BigConstants.java Thu May 27 15:24:49 2004 *************** *** 0 **** --- 1,11 ---- + public class BigConstants + { + public static int main(String[] args) { + int i = 1234567890; + long l = 1234567890123456789L; + float f = -1.23456789e10F; + double d = 1.23456789e100; + + return 0; + } + } From lattner at cs.uiuc.edu Thu May 27 15:34:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 15:34:02 2004 Subject: [llvm-commits] CVS: llvm/test/QMTest/llvm.py Message-ID: <200405272030.PAA20129@zion.cs.uiuc.edu> Changes in directory llvm/test/QMTest: llvm.py updated: 1.26 -> 1.27 --- Log message: Stop passing the -q option to opt --- Diffs of the changes: (+2 -2) Index: llvm/test/QMTest/llvm.py diff -u llvm/test/QMTest/llvm.py:1.26 llvm/test/QMTest/llvm.py:1.27 --- llvm/test/QMTest/llvm.py:1.26 Fri Feb 13 17:34:59 2004 +++ llvm/test/QMTest/llvm.py Thu May 27 15:30:29 2004 @@ -517,7 +517,7 @@ # p=' | ' - estatus = os.system (as + ' < ' + file + p + opt + ' -q -inline -dce ' + flags + p + dis + p + as + ' > ' + 'bc.1') + estatus = os.system (as + ' < ' + file + p + opt + ' -inline -dce ' + flags + p + dis + p + as + ' > ' + 'bc.1') if (not ((os.WIFEXITED(estatus)) and ((os.WEXITSTATUS(estatus)) == 0))): result.Fail() return; @@ -525,7 +525,7 @@ # # Now, attempt to optimize the the program again. # - estatus=os.system (opt + ' -q ' + flags + ' < ' + 'bc.1 > ' + 'bc.2') + estatus=os.system (opt + ' ' + flags + ' < ' + 'bc.1 > ' + 'bc.2') if (not ((os.WIFEXITED(estatus)) and ((os.WEXITSTATUS(estatus)) == 0))): result.Fail() return From lattner at cs.uiuc.edu Thu May 27 15:35:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 15:35:02 2004 Subject: [llvm-commits] CVS: llvm/tools/opt/opt.cpp Message-ID: <200405272032.PAA20328@zion.cs.uiuc.edu> Changes in directory llvm/tools/opt: opt.cpp updated: 1.92 -> 1.93 --- Log message: Neuter the -q option. Stop printing the "program modified" message, ever --- Diffs of the changes: (+2 -3) Index: llvm/tools/opt/opt.cpp diff -u llvm/tools/opt/opt.cpp:1.92 llvm/tools/opt/opt.cpp:1.93 --- llvm/tools/opt/opt.cpp:1.92 Thu May 27 11:28:54 2004 +++ llvm/tools/opt/opt.cpp Thu May 27 15:32:10 2004 @@ -60,7 +60,7 @@ NoVerify("disable-verify", cl::desc("Do not verify result module"), cl::Hidden); static cl::opt -Quiet("q", cl::desc("Don't print 'program modified' message")); +Quiet("q", cl::desc("Obsolete option"), cl::Hidden); static cl::alias QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet)); @@ -165,8 +165,7 @@ Passes.add(new WriteBytecodePass(Out, Out != &std::cout)); // Now that we have all of the passes ready, run them. - if (Passes.run(*M.get()) ) - return 0; + Passes.run(*M.get()); return 0; } From criswell at cs.uiuc.edu Thu May 27 15:42:03 2004 From: criswell at cs.uiuc.edu (John Criswell) Date: Thu May 27 15:42:03 2004 Subject: [llvm-commits] CVS: llvm/autoconf/configure.ac Message-ID: <200405272040.PAA10306@choi.cs.uiuc.edu> Changes in directory llvm/autoconf: configure.ac updated: 1.87 -> 1.88 --- Log message: Added a check for a new header file. My apologies for changing config.h.in. Now you will all have to re-configure. --- Diffs of the changes: (+1 -1) Index: llvm/autoconf/configure.ac diff -u llvm/autoconf/configure.ac:1.87 llvm/autoconf/configure.ac:1.88 --- llvm/autoconf/configure.ac:1.87 Wed May 26 19:57:50 2004 +++ llvm/autoconf/configure.ac Thu May 27 15:40:39 2004 @@ -233,7 +233,7 @@ AC_HEADER_SYS_WAIT dnl Checks for POSIX and other various system-specific header files -AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h malloc.h sys/mman.h sys/resource.h dlfcn.h link.h execinfo.h) +AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h malloc.h sys/mman.h sys/resource.h dlfcn.h link.h execinfo.h windows.h) dnl Check for things that need to be included in public headers, and so dnl for which we may not have access to a HAVE_* preprocessor #define. From alkis at cs.uiuc.edu Thu May 27 15:42:13 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 15:42:13 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405272038.PAA20482@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.36 -> 1.37 --- Log message: Inline compileMethodInit and add a ClassFile* member to CompilerImpl. --- Diffs of the changes: (+14 -17) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.36 llvm-java/lib/Compiler/Compiler.cpp:1.37 --- llvm-java/lib/Compiler/Compiler.cpp:1.36 Thu May 27 10:02:44 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Thu May 27 15:38:21 2004 @@ -115,6 +115,7 @@ struct CompilerImpl : public BytecodeParser { private: + const ClassFile* cf_; OperandStack opStack_; Locals locals_; BC2BBMap bc2bbMap_; @@ -156,21 +157,6 @@ return static_cast(-1); } - void compileMethodInit(Function& function, - const ClassFile& cf, - const CodeAttribute& codeAttr) { - while (!opStack_.empty()) - opStack_.pop(); - - locals_.clear(); - locals_.assign(codeAttr.getMaxLocals(), NULL); - - Bytecode2BasicBlockMapper mapper(function, bc2bbMap_, codeAttr); - mapper.compute(); - - prologue_ = new BasicBlock("prologue"); - } - Value* getOrCreateLocal(unsigned index, const Type* type) { if (!locals_[index]) { locals_[index] = new AllocaInst(type, NULL, @@ -190,7 +176,9 @@ DEBUG(std::cerr << "compiling method: " << method.getName()->str() << '\n'); - std::string name = cf.getThisClass()->getName()->str(); + cf_ = &cf; + + std::string name = cf_->getThisClass()->getName()->str(); name += '/'; name += method.getName()->str(); name += method.getDescriptor()->str(); @@ -203,7 +191,16 @@ const Java::CodeAttribute* codeAttr = Java::getCodeAttribute(method.getAttributes()); - compileMethodInit(*function, cf, *codeAttr); + while (!opStack_.empty()) + opStack_.pop(); + + locals_.clear(); + locals_.assign(codeAttr->getMaxLocals(), NULL); + + Bytecode2BasicBlockMapper mapper(*function, bc2bbMap_, *codeAttr); + mapper.compute(); + + prologue_ = new BasicBlock("prologue"); parse(codeAttr->getCode(), codeAttr->getCodeSize()); From criswell at cs.uiuc.edu Thu May 27 15:43:01 2004 From: criswell at cs.uiuc.edu (John Criswell) Date: Thu May 27 15:43:01 2004 Subject: [llvm-commits] CVS: llvm/include/Config/config.h.in Message-ID: <200405272040.PAA10313@choi.cs.uiuc.edu> Changes in directory llvm/include/Config: config.h.in updated: 1.16 -> 1.17 --- Log message: Added a check for a new header file. My apologies for changing config.h.in. Now you will all have to re-configure. --- Diffs of the changes: (+3 -0) Index: llvm/include/Config/config.h.in diff -u llvm/include/Config/config.h.in:1.16 llvm/include/Config/config.h.in:1.17 --- llvm/include/Config/config.h.in:1.16 Fri Apr 2 15:26:03 2004 +++ llvm/include/Config/config.h.in Thu May 27 15:40:39 2004 @@ -131,6 +131,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to have the header file. */ +#undef HAVE_WINDOWS_H + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT From criswell at cs.uiuc.edu Thu May 27 15:44:01 2004 From: criswell at cs.uiuc.edu (John Criswell) Date: Thu May 27 15:44:01 2004 Subject: [llvm-commits] CVS: llvm/configure Message-ID: <200405272040.PAA10299@choi.cs.uiuc.edu> Changes in directory llvm: configure updated: 1.89 -> 1.90 --- Log message: Added a check for a new header file. My apologies for changing config.h.in. Now you will all have to re-configure. --- Diffs of the changes: (+2 -1) Index: llvm/configure diff -u llvm/configure:1.89 llvm/configure:1.90 --- llvm/configure:1.89 Wed May 26 19:57:44 2004 +++ llvm/configure Thu May 27 15:40:31 2004 @@ -18917,7 +18917,8 @@ -for ac_header in fcntl.h limits.h sys/time.h unistd.h malloc.h sys/mman.h sys/resource.h dlfcn.h link.h execinfo.h + +for ac_header in fcntl.h limits.h sys/time.h unistd.h malloc.h sys/mman.h sys/resource.h dlfcn.h link.h execinfo.h windows.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then From alkis at cs.uiuc.edu Thu May 27 15:52:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 15:52:03 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405272048.PAA21464@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.37 -> 1.38 --- Log message: Handle LDC, LDC_W and LDC2_W bytecodes. --- Diffs of the changes: (+17 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.37 llvm-java/lib/Compiler/Compiler.cpp:1.38 --- llvm-java/lib/Compiler/Compiler.cpp:1.37 Thu May 27 15:38:21 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Thu May 27 15:48:19 2004 @@ -236,7 +236,23 @@ } void do_ldc(unsigned bcI, unsigned index) { - assert(0 && "not implemented"); + const Constant* c = cf_->getConstantPool()[index]; + if (dynamic_cast(c)) + assert(0 && "not implemented"); + else if (const ConstantInteger* i = + dynamic_cast(c)) + opStack_.push(ConstantSInt::get(Type::IntTy, i->getValue())); + else if (const ConstantFloat* f = + dynamic_cast(c)) + opStack_.push(ConstantFP::get(Type::FloatTy, f->getValue())); + else if (const ConstantLong* l = + dynamic_cast(c)) + opStack_.push(ConstantSInt::get(Type::LongTy, l->getValue())); + else if (const ConstantDouble* d = + dynamic_cast(c)) + opStack_.push(ConstantFP::get(Type::DoubleTy, d->getValue())); + else + ; // FIXME: throw something } void do_load(unsigned bcI, JType type, unsigned index) { From llvm at cs.uiuc.edu Thu May 27 15:53:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 15:53:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/Generic/BasicInstrs.llx Message-ID: <200405272049.PAA25763@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/Generic: BasicInstrs.llx updated: 1.1 -> 1.2 --- Log message: Make the test pass by using the correct RUN: syntax. --- Diffs of the changes: (+1 -1) Index: llvm/test/Regression/CodeGen/Generic/BasicInstrs.llx diff -u llvm/test/Regression/CodeGen/Generic/BasicInstrs.llx:1.1 llvm/test/Regression/CodeGen/Generic/BasicInstrs.llx:1.2 --- llvm/test/Regression/CodeGen/Generic/BasicInstrs.llx:1.1 Tue Apr 6 23:08:21 2004 +++ llvm/test/Regression/CodeGen/Generic/BasicInstrs.llx Thu May 27 15:49:16 2004 @@ -1,7 +1,7 @@ ; New testcase, this contains a bunch of simple instructions that should be ; handled by a code generator. -; RUN: llvm-as < %S | llc +; RUN: llvm-as < %s | llc int %add(int %A, int %B) { %R = add int %A, %B From lattner at cs.uiuc.edu Thu May 27 15:55:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 15:55:01 2004 Subject: [llvm-commits] CVS: llvm/include/Config/windows.h Message-ID: <200405272051.PAA25828@zion.cs.uiuc.edu> Changes in directory llvm/include/Config: windows.h added (r1.1) --- Log message: An "autoconf wrapper" for the infamous windows.h file --- Diffs of the changes: (+23 -0) Index: llvm/include/Config/windows.h diff -c /dev/null llvm/include/Config/windows.h:1.1 *** /dev/null Thu May 27 15:51:32 2004 --- llvm/include/Config/windows.h Thu May 27 15:51:22 2004 *************** *** 0 **** --- 1,23 ---- + /* + * 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. + * + ****************************************************************************** + * + * Description: + * This header file is the autoconf replacement for windows.h (if it lives + * on the system). + */ + + #ifndef _CONFIG_DLFCN_H + #define _CONFIG_DLFCN_H + + #include "Config/config.h" + + #ifdef HAVE_WINDOWS_H + #include + #endif + + #endif From alkis at cs.uiuc.edu Thu May 27 15:55:13 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 15:55:13 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405272051.PAA25859@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.38 -> 1.39 --- Log message: Rename LCMP handler to do_lcmp. --- Diffs of the changes: (+1 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.38 llvm-java/lib/Compiler/Compiler.cpp:1.39 --- llvm-java/lib/Compiler/Compiler.cpp:1.38 Thu May 27 15:48:19 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Thu May 27 15:51:38 2004 @@ -491,7 +491,7 @@ opStack_.push(r); } - void do_cmp(unsigned bcI) { + void do_lcmp(unsigned bcI) { assert(0 && "not implemented"); } From alkis at cs.uiuc.edu Thu May 27 15:56:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 15:56:03 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/BytecodeParser.h Message-ID: <200405272051.PAA25866@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: BytecodeParser.h updated: 1.4 -> 1.5 --- Log message: Rename LCMP handler to do_lcmp. --- Diffs of the changes: (+2 -2) Index: llvm-java/include/llvm/Java/BytecodeParser.h diff -u llvm-java/include/llvm/Java/BytecodeParser.h:1.4 llvm-java/include/llvm/Java/BytecodeParser.h:1.5 --- llvm-java/include/llvm/Java/BytecodeParser.h:1.4 Tue May 25 19:53:37 2004 +++ llvm-java/include/llvm/Java/BytecodeParser.h Thu May 27 15:51:38 2004 @@ -398,7 +398,7 @@ THIS->do_convert(curBC, SHORT); break; case LCMP: - THIS->do_cmp(curBC); + THIS->do_lcmp(curBC); break; case FCMPL: THIS->do_cmpl(curBC); @@ -693,7 +693,7 @@ /// F2D, D2I, D2L, D2F, I2B, I2C, and I2S void do_convert(unsigned bcI, JType to) { } /// @brief called on LCMP - void do_cmp(unsigned bcI) { } + void do_lcmp(unsigned bcI) { } /// @brief called on FCMPL and DCMPL void do_cmpl(unsigned bcI) { } /// @brief called on FCMPG and DCMPG From lattner at cs.uiuc.edu Thu May 27 15:57:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 15:57:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/DynamicLinker.cpp Message-ID: <200405272053.PAA25963@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: DynamicLinker.cpp updated: 1.5 -> 1.6 --- Log message: Add DynamicLinker support for systems that provide windows.h --- Diffs of the changes: (+23 -8) Index: llvm/lib/Support/DynamicLinker.cpp diff -u llvm/lib/Support/DynamicLinker.cpp:1.5 llvm/lib/Support/DynamicLinker.cpp:1.6 --- llvm/lib/Support/DynamicLinker.cpp:1.5 Sun Dec 14 15:35:53 2003 +++ llvm/lib/Support/DynamicLinker.cpp Thu May 27 15:53:10 2004 @@ -21,6 +21,7 @@ #include "Support/DynamicLinker.h" #include "Config/dlfcn.h" +#include "Config/windows.h" #include using namespace llvm; @@ -31,6 +32,16 @@ return true; } return false; +#elif defined(HAVE_WINDOWS_H) + if (LoadLibrary(filename)) + return false; + if (ErrorMessage) { + char Buffer[100]; + // FIXME: This should use FormatMessage + sprintf(Buffer, "Windows error code %d\n", GetLastError()); + *ErrorMessage = Buffer; + } + return true; #else assert (0 && "Dynamic object linking not implemented for this platform"); #endif @@ -38,18 +49,22 @@ void *llvm::GetAddressOfSymbol (const char *symbolName) { #if defined (HAVE_DLOPEN) -#ifdef RTLD_DEFAULT - return dlsym (RTLD_DEFAULT, symbolName); -#else - static void* CurHandle = dlopen(0, RTLD_LAZY); - return dlsym(CurHandle, symbolName); -#endif +# ifdef RTLD_DEFAULT + return dlsym (RTLD_DEFAULT, symbolName); +# else + static void* CurHandle = dlopen(0, RTLD_LAZY); + return dlsym(CurHandle, symbolName); +# endif +#elif defined(HAVE_WINDOWS_H) + static HMODULE ModHandle = NULL; + if (ModHandle == 0) ModHandle = GetModuleHandle(NULL); + return (void*)GetProcAddress(ModHandle, symbolName); #else assert (0 && "Dynamic symbol lookup not implemented for this platform"); #endif } // soft, cushiony C++ interface. -void *llvm::GetAddressOfSymbol (const std::string &symbolName) { - return GetAddressOfSymbol (symbolName.c_str ()); +void *llvm::GetAddressOfSymbol(const std::string &symbolName) { + return GetAddressOfSymbol(symbolName.c_str()); } From lattner at cs.uiuc.edu Thu May 27 16:00:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 16:00:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Analysis/IPA/Andersens.cpp Message-ID: <200405272057.PAA26028@zion.cs.uiuc.edu> Changes in directory llvm/lib/Analysis/IPA: Andersens.cpp updated: 1.1 -> 1.2 --- Log message: Fix warnings about reaching end of non-void function --- Diffs of the changes: (+2 -0) Index: llvm/lib/Analysis/IPA/Andersens.cpp diff -u llvm/lib/Analysis/IPA/Andersens.cpp:1.1 llvm/lib/Analysis/IPA/Andersens.cpp:1.2 --- llvm/lib/Analysis/IPA/Andersens.cpp:1.1 Sun May 23 16:00:47 2004 +++ llvm/lib/Analysis/IPA/Andersens.cpp Thu May 27 15:57:01 2004 @@ -491,6 +491,7 @@ } else { assert(0 && "Unknown constant pointer!"); } + return 0; } /// getNodeForConstantPointerTarget - Return the node POINTED TO by the @@ -518,6 +519,7 @@ } else { assert(0 && "Unknown constant pointer!"); } + return 0; } /// AddGlobalInitializerConstraints - Add inclusion constraints for the memory From alkis at cs.uiuc.edu Thu May 27 16:12:08 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 16:12:08 2004 Subject: [llvm-commits] CVS: llvm-java/test/Compiler/LongCompare.java Message-ID: <200405272109.QAA20199@zion.cs.uiuc.edu> Changes in directory llvm-java/test/Compiler: LongCompare.java added (r1.1) --- Log message: Add test case for LCMP bytecode. --- Diffs of the changes: (+9 -0) Index: llvm-java/test/Compiler/LongCompare.java diff -c /dev/null llvm-java/test/Compiler/LongCompare.java:1.1 *** /dev/null Thu May 27 16:09:06 2004 --- llvm-java/test/Compiler/LongCompare.java Thu May 27 16:08:56 2004 *************** *** 0 **** --- 1,9 ---- + public class LongCompare + { + public static int main(String[] args) { + long l1 = 123456789123456789L; + long l2 = 987654321987654321L; + + return l1 == l2 ? 1 : 0; + } + } From alkis at cs.uiuc.edu Thu May 27 16:13:09 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 27 16:13:09 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405272109.QAA21432@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.39 -> 1.40 --- Log message: Implement the LCMP bytecode. --- Diffs of the changes: (+12 -1) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.39 llvm-java/lib/Compiler/Compiler.cpp:1.40 --- llvm-java/lib/Compiler/Compiler.cpp:1.39 Thu May 27 15:51:38 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Thu May 27 16:09:19 2004 @@ -492,7 +492,18 @@ } void do_lcmp(unsigned bcI) { - assert(0 && "not implemented"); + Value* v2 = opStack_.top(); opStack_.pop(); + Value* v1 = opStack_.top(); opStack_.pop(); + Value* c = + new SetCondInst(Instruction::SetGT, v1, v2, TMP, getBBAt(bcI)); + Value* r = + new SelectInst(c, ConstantSInt::get(Type::IntTy, 1), + ConstantSInt::get(Type::IntTy, 0), TMP, + getBBAt(bcI)); + c = new SetCondInst(Instruction::SetLT, v1, v2, TMP, getBBAt(bcI)); + r = new SelectInst(c, ConstantSInt::get(Type::IntTy, -1), r, TMP, + getBBAt(bcI)); + opStack_.push(r); } void do_cmpl(unsigned bcI) { From criswell at cs.uiuc.edu Thu May 27 16:18:03 2004 From: criswell at cs.uiuc.edu (John Criswell) Date: Thu May 27 16:18:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/DeadTypeElimination.cpp Message-ID: <200405272116.QAA21356@choi.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: DeadTypeElimination.cpp updated: 1.50 -> 1.51 --- Log message: Fix a bug in the -deadtypeelim pass. The SymbolTable re-write changed it to eliminate the wrong type. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Transforms/IPO/DeadTypeElimination.cpp diff -u llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.50 llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.51 --- llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.50 Tue May 25 03:51:03 2004 +++ llvm/lib/Transforms/IPO/DeadTypeElimination.cpp Thu May 27 16:16:46 2004 @@ -81,7 +81,7 @@ const Type *RHS = TI->second; if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) { SymbolTable::type_iterator ToRemove = TI++; - ST.remove(TI->second); + ST.remove(ToRemove->second); ++NumKilled; Changed = true; } else { From lattner at cs.uiuc.edu Thu May 27 16:28:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 16:28:03 2004 Subject: [llvm-commits] CVS: llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Message-ID: <200405272124.QAA06315@zion.cs.uiuc.edu> Changes in directory llvm/lib/ExecutionEngine/Interpreter: ExternalFunctions.cpp updated: 1.74 -> 1.75 --- Log message: These #includes are long dead --- Diffs of the changes: (+0 -2) Index: llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp diff -u llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.74 llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.75 --- llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.74 Tue May 25 03:46:15 2004 +++ llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp Thu May 27 16:24:38 2004 @@ -24,8 +24,6 @@ #include "llvm/Module.h" #include "llvm/Target/TargetData.h" #include "Support/DynamicLinker.h" -#include "Config/dlfcn.h" -#include "Config/link.h" #include #include #include From lattner at cs.uiuc.edu Thu May 27 16:29:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 16:29:03 2004 Subject: [llvm-commits] CVS: llvm/lib/ExecutionEngine/ExecutionEngine.cpp Message-ID: <200405272125.QAA07023@zion.cs.uiuc.edu> Changes in directory llvm/lib/ExecutionEngine: ExecutionEngine.cpp updated: 1.49 -> 1.50 --- Log message: Remove long unused #includes --- Diffs of the changes: (+0 -1) Index: llvm/lib/ExecutionEngine/ExecutionEngine.cpp diff -u llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.49 llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.50 --- llvm/lib/ExecutionEngine/ExecutionEngine.cpp:1.49 Tue Mar 16 02:38:56 2004 +++ llvm/lib/ExecutionEngine/ExecutionEngine.cpp Thu May 27 16:25:44 2004 @@ -26,7 +26,6 @@ #include "Support/Debug.h" #include "Support/Statistic.h" #include "Support/DynamicLinker.h" -#include "Config/dlfcn.h" using namespace llvm; namespace { From gaeke at cs.uiuc.edu Thu May 27 16:35:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 27 16:35:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceJIT/TraceJIT.h Message-ID: <200405272132.QAA12055@zion.cs.uiuc.edu> Changes in directory reopt/lib/TraceJIT: TraceJIT.h updated: 1.1 -> 1.2 --- Log message: Go go gadget uint64_t.... make these files compile on x86. --- Diffs of the changes: (+1 -0) Index: reopt/lib/TraceJIT/TraceJIT.h diff -u reopt/lib/TraceJIT/TraceJIT.h:1.1 reopt/lib/TraceJIT/TraceJIT.h:1.2 --- reopt/lib/TraceJIT/TraceJIT.h:1.1 Wed May 26 16:25:13 2004 +++ reopt/lib/TraceJIT/TraceJIT.h Thu May 27 16:32:10 2004 @@ -16,6 +16,7 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/PassManager.h" +#include "Support/DataTypes.h" #include namespace llvm { From gaeke at cs.uiuc.edu Thu May 27 16:36:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 27 16:36:01 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/UnpackTraceFunction.h Message-ID: <200405272132.QAA12056@zion.cs.uiuc.edu> Changes in directory reopt/include/reopt: UnpackTraceFunction.h updated: 1.1 -> 1.2 --- Log message: Go go gadget uint64_t.... make these files compile on x86. --- Diffs of the changes: (+1 -0) Index: reopt/include/reopt/UnpackTraceFunction.h diff -u reopt/include/reopt/UnpackTraceFunction.h:1.1 reopt/include/reopt/UnpackTraceFunction.h:1.2 --- reopt/include/reopt/UnpackTraceFunction.h:1.1 Sun May 23 05:08:38 2004 +++ reopt/include/reopt/UnpackTraceFunction.h Thu May 27 16:32:10 2004 @@ -8,6 +8,7 @@ #define REOPT_UNPACKTRACEFUNCTION_H #include "llvm/CodeGen/MachineFunctionPass.h" +#include "Support/DataTypes.h" #include namespace llvm { From gaeke at cs.uiuc.edu Thu May 27 16:43:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 27 16:43:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9RegisterInfo.h Message-ID: <200405272141.QAA16114@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9RegisterInfo.h updated: 1.2 -> 1.3 --- Log message: Make comment lines stick out less. --- Diffs of the changes: (+2 -2) Index: llvm/lib/Target/SparcV9/SparcV9RegisterInfo.h diff -u llvm/lib/Target/SparcV9/SparcV9RegisterInfo.h:1.2 llvm/lib/Target/SparcV9/SparcV9RegisterInfo.h:1.3 --- llvm/lib/Target/SparcV9/SparcV9RegisterInfo.h:1.2 Tue Apr 27 17:04:03 2004 +++ llvm/lib/Target/SparcV9/SparcV9RegisterInfo.h Thu May 27 16:41:48 2004 @@ -69,9 +69,9 @@ /* 5 */ o5, o7, l0, l1, l2, /* 10 */ l3, l4, l5, l6, l7, /* 15 */ i0, i1, i2, i3, i4, - /* 20 */ i5, i6, i7, g0, g1, // i6 is frame ptr, i7 is ret addr, g0 is zero + /* 20 */ i5, i6, i7, g0, g1, // i6 is frame ptr, i7 is ret addr, g0 is zero /* 25 */ g2, g3, g4, g5, g6, - /* 30 */ g7, o6, // o6 is stack ptr + /* 30 */ g7, o6, // o6 is stack ptr // SparcV9FloatRegClass(FloatRegClassID) // - regs 32 .. 63 are FPSingleRegType, 64 .. 95 are FPDoubleRegType From llvm at cs.uiuc.edu Thu May 27 17:01:36 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 17:01:36 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Verifier.cpp Message-ID: <200405272158.QAA14723@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Verifier.cpp updated: 1.101 -> 1.102 --- Log message: Fix for bug 348: http://llvm.cs.uiuc.edu/PR348 . The SymbolTable changes caused this one too. --- Diffs of the changes: (+1 -0) Index: llvm/lib/VMCore/Verifier.cpp diff -u llvm/lib/VMCore/Verifier.cpp:1.101 llvm/lib/VMCore/Verifier.cpp:1.102 --- llvm/lib/VMCore/Verifier.cpp:1.101 Tue May 25 03:53:29 2004 +++ llvm/lib/VMCore/Verifier.cpp Thu May 27 16:58:13 2004 @@ -216,6 +216,7 @@ WriteValue(V1); WriteType(T2); WriteValue(V3); + Broken = true; } }; From llvm at cs.uiuc.edu Thu May 27 17:09:44 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 17:09:44 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200405272204.RAA14762@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.132 -> 1.133 --- Log message: Clean up a comment. --- Diffs of the changes: (+1 -1) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.132 llvm/lib/VMCore/AsmWriter.cpp:1.133 --- llvm/lib/VMCore/AsmWriter.cpp:1.132 Wed May 26 16:56:09 2004 +++ llvm/lib/VMCore/AsmWriter.cpp Thu May 27 17:04:46 2004 @@ -600,7 +600,7 @@ // which slot it occupies. void printInfoComment(const Value &V); }; -} // end of anonymous namespace +} // end of llvm namespace /// printTypeAtLeastOneLevel - Print out one level of the possibly complex type /// without considering any symbolic types that we may have equal to it. From llvm at cs.uiuc.edu Thu May 27 17:10:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 17:10:01 2004 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y Message-ID: <200405272206.RAA14774@zion.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: llvmAsmParser.y updated: 1.166 -> 1.167 --- Log message: Remove an assertion that uses Type::TypeTy that is never hit and will break when Type::TypeTy goes away. Also remove a dead block of code and dead comments. --- Diffs of the changes: (+1 -12) Index: llvm/lib/AsmParser/llvmAsmParser.y diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.166 llvm/lib/AsmParser/llvmAsmParser.y:1.167 --- llvm/lib/AsmParser/llvmAsmParser.y:1.166 Wed May 26 16:48:31 2004 +++ llvm/lib/AsmParser/llvmAsmParser.y Thu May 27 17:05:50 2004 @@ -377,7 +377,6 @@ // real thing. // static Value *getVal(const Type *Ty, const ValID &D) { - assert(Ty != Type::TypeTy && "Should use getTypeVal for types!"); // See if the value has already been defined... Value *V = getValNonImprovising(Ty, D); @@ -519,17 +518,7 @@ Value *Existing = ST.lookup(V->getType(), Name); if (Existing) { // Inserting a name that is already defined??? - // There is only one case where this is allowed: when we are refining an - // opaque type. In this case, Existing will be an opaque type. - if (const Type *Ty = dyn_cast(Existing)) { - if (const OpaqueType *OpTy = dyn_cast(Ty)) { - // We ARE replacing an opaque type! - ((OpaqueType*)OpTy)->refineAbstractTypeTo(cast(V)); - return true; - } - } - - // Otherwise, we are a simple redefinition of a value, check to see if it + // We are a simple redefinition of a value, check to see if it // is defined the same as the old one... if (const Type *Ty = dyn_cast(Existing)) { if (Ty == cast(V)) return true; // Yes, it's equal. From llvm at cs.uiuc.edu Thu May 27 19:24:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Thu May 27 19:24:01 2004 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y Message-ID: <200405280021.TAA15168@zion.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: llvmAsmParser.y updated: 1.167 -> 1.168 --- Log message: Remove some more dead code resulting from adding setTypeName(). --- Diffs of the changes: (+1 -5) Index: llvm/lib/AsmParser/llvmAsmParser.y diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.167 llvm/lib/AsmParser/llvmAsmParser.y:1.168 --- llvm/lib/AsmParser/llvmAsmParser.y:1.167 Thu May 27 17:05:50 2004 +++ llvm/lib/AsmParser/llvmAsmParser.y Thu May 27 19:21:06 2004 @@ -520,11 +520,7 @@ if (Existing) { // Inserting a name that is already defined??? // We are a simple redefinition of a value, check to see if it // is defined the same as the old one... - if (const Type *Ty = dyn_cast(Existing)) { - if (Ty == cast(V)) return true; // Yes, it's equal. - // std::cerr << "Type: " << Ty->getDescription() << " != " - // << cast(V)->getDescription() << "!\n"; - } else if (const Constant *C = dyn_cast(Existing)) { + if (const Constant *C = dyn_cast(Existing)) { if (C == V) return true; // Constants are equal to themselves } else if (GlobalVariable *EGV = dyn_cast(Existing)) { // We are allowed to redefine a global variable in two circumstances: From lattner at cs.uiuc.edu Thu May 27 19:26:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 19:26:01 2004 Subject: [llvm-commits] CVS: llvm/include/Support/FileUtilities.h Message-ID: <200405280023.TAA15247@zion.cs.uiuc.edu> Changes in directory llvm/include/Support: FileUtilities.h updated: 1.16 -> 1.17 --- Log message: Add a pair of functions to hide system specific details of mapping a file in for reading. --- Diffs of the changes: (+11 -1) Index: llvm/include/Support/FileUtilities.h diff -u llvm/include/Support/FileUtilities.h:1.16 llvm/include/Support/FileUtilities.h:1.17 --- llvm/include/Support/FileUtilities.h:1.16 Wed Feb 18 14:20:52 2004 +++ llvm/include/Support/FileUtilities.h Thu May 27 19:23:11 2004 @@ -42,7 +42,7 @@ /// FileOpenable - Returns true IFF Filename names an existing regular file /// which we can successfully open. /// -bool FileOpenable (const std::string &Filename); +bool FileOpenable(const std::string &Filename); /// DiffFiles - Compare the two files specified, returning true if they are /// different or if there is a file error. If you specify a string to fill in @@ -92,6 +92,16 @@ /// updated since that last time the timestampt was aquired. If the file does /// not exist or there is an error getting the time-stamp, zero is returned. unsigned long long getFileTimestamp(const std::string &Filename); + +/// ReadFileIntoAddressSpace - Attempt to map the specific file into the +/// address space of the current process for reading. If this succeeds, +/// return the address of the buffer and the length of the file mapped. On +/// failure, return null. +void *ReadFileIntoAddressSpace(const std::string &Filename, unsigned &Length); + +/// UnmapFileFromAddressSpace - Remove the specified file from the current +/// address space. +void UnmapFileFromAddressSpace(void *Buffer, unsigned Length); /// FDHandle - Simple handle class to make sure a file descriptor gets closed From lattner at cs.uiuc.edu Thu May 27 19:27:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 19:27:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/FileUtilities.cpp Message-ID: <200405280023.TAA15298@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: FileUtilities.cpp updated: 1.19 -> 1.20 --- Log message: Add a pair of functions to hide system specific details of mapping a file in for reading. --- Diffs of the changes: (+34 -0) Index: llvm/lib/Support/FileUtilities.cpp diff -u llvm/lib/Support/FileUtilities.cpp:1.19 llvm/lib/Support/FileUtilities.cpp:1.20 --- llvm/lib/Support/FileUtilities.cpp:1.19 Wed Dec 31 00:15:37 2003 +++ llvm/lib/Support/FileUtilities.cpp Thu May 27 19:23:48 2004 @@ -14,8 +14,10 @@ #include "Support/FileUtilities.h" #include "Config/unistd.h" +#include "Config/fcntl.h" #include "Config/sys/stat.h" #include "Config/sys/types.h" +#include "Config/sys/mman.h" #include #include #include @@ -215,8 +217,40 @@ return StatBuf.st_mtime; } +/// ReadFileIntoAddressSpace - Attempt to map the specific file into the +/// address space of the current process for reading. If this succeeds, +/// return the address of the buffer and the length of the file mapped. On +/// failure, return null. +void *llvm::ReadFileIntoAddressSpace(const std::string &Filename, + unsigned &Length) { +#ifdef HAVE_MMAP_FILE + Length = getFileSize(Filename); + if ((int)Length == -1) return 0; + FDHandle FD(open(Filename.c_str(), O_RDONLY)); + if (FD == -1) return 0; + // mmap in the file all at once... + void *Buffer = (void*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0); + + if (Buffer == (void*)MAP_FAILED) + return 0; + return Buffer; +#else + // FIXME: implement with read/write + return 0; +#endif +} + +/// UnmapFileFromAddressSpace - Remove the specified file from the current +/// address space. +void llvm::UnmapFileFromAddressSpace(void *Buffer, unsigned Length) { +#ifdef HAVE_MMAP_FILE + munmap((char*)Buffer, Length); +#else + free(Buffer); +#endif +} //===----------------------------------------------------------------------===// // FDHandle class implementation From lattner at cs.uiuc.edu Thu May 27 19:28:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 19:28:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/ArchiveReader.cpp ReaderWrappers.cpp Message-ID: <200405280024.TAA15361@zion.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Reader: ArchiveReader.cpp updated: 1.16 -> 1.17 ReaderWrappers.cpp updated: 1.21 -> 1.22 --- Log message: Use the new FileUtilities.h API for mapping a file into an address space --- Diffs of the changes: (+15 -33) Index: llvm/lib/Bytecode/Reader/ArchiveReader.cpp diff -u llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.16 llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.17 --- llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.16 Wed Mar 31 13:51:00 2004 +++ llvm/lib/Bytecode/Reader/ArchiveReader.cpp Thu May 27 19:24:41 2004 @@ -19,8 +19,6 @@ #include "llvm/Bytecode/Reader.h" #include "llvm/Module.h" #include "Support/FileUtilities.h" -#include "Config/sys/mman.h" -#include "Config/fcntl.h" #include using namespace llvm; @@ -166,25 +164,21 @@ // bool llvm::ReadArchiveFile(const std::string &Filename, std::vector &Objects,std::string *ErrorStr){ - int Length = getFileSize(Filename); - if (Length == -1) - return Error(ErrorStr, "Error getting file length!"); - - int FD = open(Filename.c_str(), O_RDONLY); - if (FD == -1) - return Error(ErrorStr, "Error opening file!"); - + unsigned Length; + // mmap in the file all at once... - unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ, - MAP_PRIVATE, FD, 0); - if (Buffer == (unsigned char*)MAP_FAILED) - return Error(ErrorStr, "Error mmapping file!"); + unsigned char *Buffer = + (unsigned char*)ReadFileIntoAddressSpace(Filename, Length); + if (Buffer == 0) { + if (ErrorStr) *ErrorStr = "Error reading file '" + Filename + "'!"; + return true; + } // Parse the archive files we mmap'ped in bool Result = ReadArchiveBuffer(Filename, Buffer, Length, Objects, ErrorStr); // Unmmap the archive... - munmap((char*)Buffer, Length); + UnmapFileFromAddressSpace(Buffer, Length); if (Result) // Free any loaded objects while (!Objects.empty()) { Index: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp diff -u llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.21 llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.22 --- llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.21 Tue Dec 30 01:40:35 2003 +++ llvm/lib/Bytecode/Reader/ReaderWrappers.cpp Thu May 27 19:24:41 2004 @@ -18,9 +18,7 @@ #include "llvm/Instructions.h" #include "Support/FileUtilities.h" #include "Support/StringExtras.h" -#include "Config/fcntl.h" #include "Config/unistd.h" -#include "Config/sys/mman.h" #include using namespace llvm; @@ -34,7 +32,7 @@ class BytecodeFileReader : public BytecodeParser { private: unsigned char *Buffer; - int Length; + unsigned Length; BytecodeFileReader(const BytecodeFileReader&); // Do not implement void operator=(const BytecodeFileReader &BFR); // Do not implement @@ -50,32 +48,22 @@ } BytecodeFileReader::BytecodeFileReader(const std::string &Filename) { - Length = getFileSize(Filename); - if (Length == -1) - throw ErrnoMessage(errno, "stat '" + Filename + "'"); - - FDHandle FD(open(Filename.c_str(), O_RDONLY)); - if (FD == -1) - throw ErrnoMessage(errno, "open '" + Filename + "'"); - - // mmap in the file all at once... - Buffer = (unsigned char*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0); - - if (Buffer == (unsigned char*)MAP_FAILED) - throw ErrnoMessage(errno, "map '" + Filename + "' into memory"); + Buffer = (unsigned char*)ReadFileIntoAddressSpace(Filename, Length); + if (Buffer == 0) + throw "Error reading file '" + Filename + "'."; try { // Parse the bytecode we mmapped in ParseBytecode(Buffer, Length, Filename); } catch (...) { - munmap((char*)Buffer, Length); + UnmapFileFromAddressSpace(Buffer, Length); throw; } } BytecodeFileReader::~BytecodeFileReader() { // Unmmap the bytecode... - munmap((char*)Buffer, Length); + UnmapFileFromAddressSpace(Buffer, Length); } //===----------------------------------------------------------------------===// From lattner at cs.uiuc.edu Thu May 27 19:35:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 19:35:01 2004 Subject: [llvm-commits] CVS: llvm/utils/fpcmp/fpcmp.cpp Message-ID: <200405280031.TAA15541@zion.cs.uiuc.edu> Changes in directory llvm/utils/fpcmp: fpcmp.cpp updated: 1.4 -> 1.5 --- Log message: Use fileutilities instead of mmap directly --- Diffs of the changes: (+2 -16) Index: llvm/utils/fpcmp/fpcmp.cpp diff -u llvm/utils/fpcmp/fpcmp.cpp:1.4 llvm/utils/fpcmp/fpcmp.cpp:1.5 --- llvm/utils/fpcmp/fpcmp.cpp:1.4 Fri Apr 23 12:38:17 2004 +++ llvm/utils/fpcmp/fpcmp.cpp Thu May 27 19:31:36 2004 @@ -37,25 +37,11 @@ /// OpenFile - mmap the specified file into the address space for reading, and /// return the length and address of the buffer. static void OpenFile(const std::string &Filename, unsigned &Len, char* &BufPtr){ - int FD = open(Filename.c_str(), O_RDONLY); - if (FD == -1 || (Len = getFileSize(Filename)) == ~0U) { + BufPtr = (char*)ReadFileIntoAddressSpace(Filename, Len); + if (BufPtr == 0) { std::cerr << "Error: cannot open file '" << Filename << "'\n"; exit(2); } - - // mmap in the file all at once... - BufPtr = (char*)mmap(0, Len, PROT_READ, MAP_PRIVATE, FD, 0); - - if (BufPtr == (char*)MAP_FAILED) { - std::cerr << "Error: cannot open file '" << Filename << "'\n"; - exit(2); - } - - // If mmap decided that the files were empty, it might have returned a - // null pointer. If so, make a new, fake pointer -- it shouldn't matter - // what it contains, because Len is 0, and it should never be read. - if (BufPtr == 0 && Len == 0) - BufPtr = new char[1]; } static bool isNumberChar(char C) { From lattner at cs.uiuc.edu Thu May 27 19:38:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 19:38:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/FileUtilities.cpp Message-ID: <200405280034.TAA15603@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: FileUtilities.cpp updated: 1.20 -> 1.21 --- Log message: Add support for zero length files --- Diffs of the changes: (+10 -1) Index: llvm/lib/Support/FileUtilities.cpp diff -u llvm/lib/Support/FileUtilities.cpp:1.20 llvm/lib/Support/FileUtilities.cpp:1.21 --- llvm/lib/Support/FileUtilities.cpp:1.20 Thu May 27 19:23:48 2004 +++ llvm/lib/Support/FileUtilities.cpp Thu May 27 19:34:42 2004 @@ -230,11 +230,17 @@ FDHandle FD(open(Filename.c_str(), O_RDONLY)); if (FD == -1) return 0; + // If the file has a length of zero, mmap might return a null pointer. In + // this case, allocate a single byte of memory and return it instead. + if (Length == 0) + return malloc(1); + // mmap in the file all at once... void *Buffer = (void*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0); if (Buffer == (void*)MAP_FAILED) return 0; + return Buffer; #else // FIXME: implement with read/write @@ -246,7 +252,10 @@ /// address space. void llvm::UnmapFileFromAddressSpace(void *Buffer, unsigned Length) { #ifdef HAVE_MMAP_FILE - munmap((char*)Buffer, Length); + if (Length) + munmap((char*)Buffer, Length); + else + free(Buffer); // Zero byte files are malloc(1)'s. #else free(Buffer); #endif From lattner at cs.uiuc.edu Thu May 27 19:39:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 19:39:01 2004 Subject: [llvm-commits] CVS: llvm/utils/fpcmp/fpcmp.cpp Message-ID: <200405280036.TAA15635@zion.cs.uiuc.edu> Changes in directory llvm/utils/fpcmp: fpcmp.cpp updated: 1.5 -> 1.6 --- Log message: Right: the #includes are not needed either --- Diffs of the changes: (+0 -2) Index: llvm/utils/fpcmp/fpcmp.cpp diff -u llvm/utils/fpcmp/fpcmp.cpp:1.5 llvm/utils/fpcmp/fpcmp.cpp:1.6 --- llvm/utils/fpcmp/fpcmp.cpp:1.5 Thu May 27 19:31:36 2004 +++ llvm/utils/fpcmp/fpcmp.cpp Thu May 27 19:35:51 2004 @@ -14,8 +14,6 @@ #include "Support/CommandLine.h" #include "Support/FileUtilities.h" -#include "Config/fcntl.h" -#include "Config/sys/mman.h" #include #include From lattner at cs.uiuc.edu Thu May 27 20:01:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 20:01:02 2004 Subject: [llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/Emitter.cpp Message-ID: <200405280057.TAA15809@zion.cs.uiuc.edu> Changes in directory llvm/lib/ExecutionEngine/JIT: Emitter.cpp updated: 1.41 -> 1.42 --- Log message: Use the SystemUtils.h file to do our dirty work. --- Diffs of the changes: (+2 -52) Index: llvm/lib/ExecutionEngine/JIT/Emitter.cpp diff -u llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.41 llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.42 --- llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.41 Thu May 27 13:03:56 2004 +++ llvm/lib/ExecutionEngine/JIT/Emitter.cpp Thu May 27 19:57:27 2004 @@ -13,9 +13,6 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "jit" -#ifndef _POSIX_MAPPED_FILES -#define _POSIX_MAPPED_FILES -#endif #include "JIT.h" #include "llvm/Constant.h" #include "llvm/Module.h" @@ -25,8 +22,7 @@ #include "llvm/Target/TargetData.h" #include "Support/Debug.h" #include "Support/Statistic.h" -#include "Config/unistd.h" -#include "Config/sys/mman.h" +#include "Support/SystemUtils.h" using namespace llvm; namespace { @@ -53,55 +49,9 @@ }; } -// getMemory - Return a pointer to the specified number of bytes, which is -// mapped as executable readable and writable. -static void *getMemory(unsigned NumBytes) { - if (NumBytes == 0) return 0; - static const long pageSize = sysconf(_SC_PAGESIZE); - unsigned NumPages = (NumBytes+pageSize-1)/pageSize; - -/* FIXME: This should use the proper autoconf flags */ -#if defined(i386) || defined(__i386__) || defined(__x86__) - /* Linux and *BSD tend to have these flags named differently. */ -#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) -# define MAP_ANONYMOUS MAP_ANON -#endif /* defined(MAP_ANON) && !defined(MAP_ANONYMOUS) */ -#elif defined(sparc) || defined(__sparc__) || defined(__sparcv9) -/* nothing */ -#else - std::cerr << "This architecture is not supported by the JIT!\n"; - abort(); - return 0; -#endif - -#ifdef HAVE_MMAP - int fd = -1; -#if defined(__linux__) - fd = 0; -#endif - - unsigned mmapFlags = MAP_PRIVATE|MAP_ANONYMOUS; -#ifdef MAP_NORESERVE - mmapFlags |= MAP_NORESERVE; -#endif - - void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, - mmapFlags, fd, 0); - if (pa == MAP_FAILED) { - perror("mmap"); - abort(); - } - return pa; -#else - std::cerr << "Do not know how to allocate mem for the JIT without mmap!\n"; - abort(); - return 0; -#endif -} - JITMemoryManager::JITMemoryManager() { // Allocate a 16M block of memory... - MemBase = (unsigned char*)getMemory(16 << 20); + MemBase = (unsigned char*)AllocateRWXMemory(16 << 20); FunctionBase = MemBase + 512*1024; // Use 512k for stubs // Allocate stubs backwards from the function base, allocate functions forward From lattner at cs.uiuc.edu Thu May 27 20:02:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 20:02:01 2004 Subject: [llvm-commits] CVS: llvm/include/Support/SystemUtils.h Message-ID: <200405280058.TAA15889@zion.cs.uiuc.edu> Changes in directory llvm/include/Support: SystemUtils.h updated: 1.10 -> 1.11 --- Log message: Add a new function for the JIT --- Diffs of the changes: (+7 -0) Index: llvm/include/Support/SystemUtils.h diff -u llvm/include/Support/SystemUtils.h:1.10 llvm/include/Support/SystemUtils.h:1.11 --- llvm/include/Support/SystemUtils.h:1.10 Thu Apr 1 23:04:12 2004 +++ llvm/include/Support/SystemUtils.h Thu May 27 19:58:48 2004 @@ -52,6 +52,13 @@ /// int ExecWait (const char * const argv[], const char * const envp[]); +/// AllocateRWXMemory - Allocate a slab of memory with read/write/execute +/// permissions. This is typically used for JIT applications where we want +/// to emit code to the memory then jump to it. Getting this type of memory +/// is very OS specific. +/// +void *AllocateRWXMemory(unsigned NumBytes); + } // End llvm namespace #endif From lattner at cs.uiuc.edu Thu May 27 20:03:00 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 20:03:00 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/SystemUtils.cpp Message-ID: <200405280059.TAA15972@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: SystemUtils.cpp updated: 1.25 -> 1.26 --- Log message: Add a new function for the JIT. libsupport is now the only library that includes mman.h --- Diffs of the changes: (+53 -1) Index: llvm/lib/Support/SystemUtils.cpp diff -u llvm/lib/Support/SystemUtils.cpp:1.25 llvm/lib/Support/SystemUtils.cpp:1.26 --- llvm/lib/Support/SystemUtils.cpp:1.25 Wed May 26 20:20:55 2004 +++ llvm/lib/Support/SystemUtils.cpp Thu May 27 19:59:40 2004 @@ -12,13 +12,14 @@ // //===----------------------------------------------------------------------===// +#define _POSIX_MAPPED_FILES #include "Support/SystemUtils.h" #include "Config/sys/types.h" #include "Config/sys/stat.h" #include "Config/fcntl.h" #include "Config/sys/wait.h" +#include "Config/sys/mman.h" #include "Config/unistd.h" -#include "Config/config.h" #include #include #include @@ -268,3 +269,54 @@ // Otherwise, return failure. return 1; } + +/// AllocateRWXMemory - Allocate a slab of memory with read/write/execute +/// permissions. This is typically used for JIT applications where we want +/// to emit code to the memory then jump to it. Getting this type of memory +/// is very OS specific. +/// +void *llvm::AllocateRWXMemory(unsigned NumBytes) { + if (NumBytes == 0) return 0; + static const long pageSize = sysconf(_SC_PAGESIZE); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + +/* FIXME: This should use the proper autoconf flags */ +#if defined(i386) || defined(__i386__) || defined(__x86__) + /* Linux and *BSD tend to have these flags named differently. */ +#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) +# define MAP_ANONYMOUS MAP_ANON +#endif /* defined(MAP_ANON) && !defined(MAP_ANONYMOUS) */ +#elif defined(sparc) || defined(__sparc__) || defined(__sparcv9) +/* nothing */ +#else + std::cerr << "This architecture is not supported by the JIT!\n"; + abort(); + return 0; +#endif + +#ifdef HAVE_MMAP + int fd = -1; +#if defined(__linux__) + fd = 0; +#endif + + unsigned mmapFlags = MAP_PRIVATE|MAP_ANONYMOUS; +#ifdef MAP_NORESERVE + mmapFlags |= MAP_NORESERVE; +#endif + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + mmapFlags, fd, 0); + if (pa == MAP_FAILED) { + perror("mmap"); + abort(); + } + return pa; +#else + std::cerr << "Do not know how to allocate mem for the JIT without mmap!\n"; + abort(); + return 0; +#endif +} + + From lattner at cs.uiuc.edu Thu May 27 20:24:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 27 20:24:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/SystemUtils.cpp Message-ID: <200405280121.UAA27341@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: SystemUtils.cpp updated: 1.26 -> 1.27 --- Log message: Add support for getting executable memory on Windows. This is actually much easier than on unix. :) The only evil thing is that windows.h defines a macro named FindExecutable, which collides with one of our names. The JIT now runs on windows, but it cannot resolve external functions (like printf) yet. --- Diffs of the changes: (+14 -2) Index: llvm/lib/Support/SystemUtils.cpp diff -u llvm/lib/Support/SystemUtils.cpp:1.26 llvm/lib/Support/SystemUtils.cpp:1.27 --- llvm/lib/Support/SystemUtils.cpp:1.26 Thu May 27 19:59:40 2004 +++ llvm/lib/Support/SystemUtils.cpp Thu May 27 20:20:58 2004 @@ -25,6 +25,7 @@ #include #include #include +#include "Config/windows.h" using namespace llvm; /// isExecutableFile - This function returns true if the filename specified @@ -63,6 +64,7 @@ /// directory, nor in the PATH. If the executable cannot be found, return an /// empty string. /// +#undef FindExecutable // needed on windows :( std::string llvm::FindExecutable(const std::string &ExeName, const std::string &ProgramPath) { // First check the directory that bugpoint is in. We can do this if @@ -277,6 +279,17 @@ /// void *llvm::AllocateRWXMemory(unsigned NumBytes) { if (NumBytes == 0) return 0; + +#if defined(HAVE_WINDOWS_H) + // On windows we use VirtualAlloc. + void *P = VirtualAlloc(0, NumBytes, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + if (P == 0) { + std::cerr << "Error allocating executable memory!\n"; + abort(); + } + return P; + +#elif defined(HAVE_MMAP) static const long pageSize = sysconf(_SC_PAGESIZE); unsigned NumPages = (NumBytes+pageSize-1)/pageSize; @@ -289,12 +302,11 @@ #elif defined(sparc) || defined(__sparc__) || defined(__sparcv9) /* nothing */ #else - std::cerr << "This architecture is not supported by the JIT!\n"; + std::cerr << "This architecture has an unknown MMAP implementation!\n"; abort(); return 0; #endif -#ifdef HAVE_MMAP int fd = -1; #if defined(__linux__) fd = 0; From lattner at cs.uiuc.edu Fri May 28 00:06:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 00:06:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerInvoke.cpp Message-ID: <200405280502.AAA29545@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LowerInvoke.cpp updated: 1.15 -> 1.16 --- Log message: Fix one of the major things that is causing the C Backend to infinite loop --- Diffs of the changes: (+1 -0) Index: llvm/lib/Transforms/Scalar/LowerInvoke.cpp diff -u llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.15 llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.16 --- llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.15 Sun Apr 4 20:29:05 2004 +++ llvm/lib/Transforms/Scalar/LowerInvoke.cpp Fri May 28 00:02:13 2004 @@ -103,6 +103,7 @@ PATypeHolder JBLType(StructType::get(Elements)); OT->refineAbstractTypeTo(JBLType.get()); // Complete the cycle. JBLinkTy = JBLType.get(); + M.addTypeName("llvm.sjljeh.jmpbufty", JBLinkTy); } const Type *PtrJBList = PointerType::get(JBLinkTy); From lattner at cs.uiuc.edu Fri May 28 00:34:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 00:34:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/SymbolTable.h Message-ID: <200405280530.AAA01293@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: SymbolTable.h updated: 1.33 -> 1.34 --- Log message: Eliminate this form of SymbolTable::remove. It ignores the type argument anyway. Add a form that takes a type_iterator for the C backend. --- Diffs of the changes: (+3 -4) Index: llvm/include/llvm/SymbolTable.h diff -u llvm/include/llvm/SymbolTable.h:1.33 llvm/include/llvm/SymbolTable.h:1.34 --- llvm/include/llvm/SymbolTable.h:1.33 Wed May 26 16:46:18 2004 +++ llvm/include/llvm/SymbolTable.h Fri May 28 00:30:29 2004 @@ -207,11 +207,10 @@ return removeEntry(PI, PI->second.find(Name)); } - /// Remove a type with the specified name from the symbol table. + /// Remove a type at the specified position in the symbol table. /// @returns the removed Type. - /// @brief Remove a named tyep from the symbol table. - inline Type* remove(const std::string& Name, Type* T ) { - return removeEntry( tmap.find(Name) ); + inline Type* remove(type_iterator TI) { + return removeEntry(TI); } /// Removes a specific value from the symbol table. From lattner at cs.uiuc.edu Fri May 28 00:34:17 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 00:34:17 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200405280531.AAA01305@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.178 -> 1.179 --- Log message: Minor changes. Switch to a SymbolTable remove that does not take linear time --- Diffs of the changes: (+2 -2) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.178 llvm/lib/Target/CBackend/Writer.cpp:1.179 --- llvm/lib/Target/CBackend/Writer.cpp:1.178 Wed May 26 12:20:52 2004 +++ llvm/lib/Target/CBackend/Writer.cpp Fri May 28 00:30:51 2004 @@ -226,7 +226,7 @@ // If this is not used, remove it from the symbol table. std::set::iterator UTI = UT.find(STy); if (UTI == UT.end()) - MST.remove(I->first, (Type*)I->second); + MST.remove(I); else UT.erase(UTI); } @@ -239,7 +239,7 @@ for (std::set::const_iterator I = UT.begin(), E = UT.end(); I != E; ++I) if (const StructType *ST = dyn_cast(*I)) { - ((Value*)ST)->setName("unnamed", &MST); + const_cast(ST)->setName("unnamed", &MST); Changed = true; } return Changed; From lattner at cs.uiuc.edu Fri May 28 00:40:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 00:40:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Analysis/IPA/FindUsedTypes.cpp Message-ID: <200405280536.AAA01696@zion.cs.uiuc.edu> Changes in directory llvm/lib/Analysis/IPA: FindUsedTypes.cpp updated: 1.26 -> 1.27 --- Log message: Minor efficiency gain: do 1 nlogn lookup instead of two Code cleanup --- Diffs of the changes: (+4 -7) Index: llvm/lib/Analysis/IPA/FindUsedTypes.cpp diff -u llvm/lib/Analysis/IPA/FindUsedTypes.cpp:1.26 llvm/lib/Analysis/IPA/FindUsedTypes.cpp:1.27 --- llvm/lib/Analysis/IPA/FindUsedTypes.cpp:1.26 Sun May 9 01:22:29 2004 +++ llvm/lib/Analysis/IPA/FindUsedTypes.cpp Fri May 28 00:36:49 2004 @@ -32,12 +32,10 @@ // collection of used types. // void FindUsedTypes::IncorporateType(const Type *Ty) { - if (UsedTypes.count(Ty)) return; // Already contain Ty. + // If ty doesn't already exist in the used types map, add it now, otherwise + // return. + if (!UsedTypes.insert(Ty).second) return; // Already contain Ty. - // If ty doesn't already exist in the used types map, add it now. - // - UsedTypes.insert(Ty); - // Make sure to add any types this type references now. // for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end(); @@ -79,9 +77,8 @@ for (const_inst_iterator II = inst_begin(F), IE = inst_end(F); II != IE; ++II) { const Instruction &I = *II; - const Type *Ty = I.getType(); - IncorporateType(Ty); // Incorporate the type of the instruction + IncorporateType(I.getType()); // Incorporate the type of the instruction for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end(); OI != OE; ++OI) IncorporateValue(*OI); // Insert inst operand types as well From lattner at cs.uiuc.edu Fri May 28 00:44:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 00:44:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Type.cpp Message-ID: <200405280540.AAA01732@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Type.cpp updated: 1.99 -> 1.100 --- Log message: Don't use size() when you mean empty() --- Diffs of the changes: (+1 -2) Index: llvm/lib/VMCore/Type.cpp diff -u llvm/lib/VMCore/Type.cpp:1.99 llvm/lib/VMCore/Type.cpp:1.100 --- llvm/lib/VMCore/Type.cpp:1.99 Sun Apr 4 20:30:19 2004 +++ llvm/lib/VMCore/Type.cpp Fri May 28 00:40:19 2004 @@ -54,8 +54,7 @@ void Type::setName(const std::string &Name, SymbolTable *ST) { assert(ST && "Type::setName - Must provide symbol table argument!"); - - if (Name.size()) ST->insert(Name, this); + if (!Name.empty()) ST->insert(Name, this); } From lattner at cs.uiuc.edu Fri May 28 00:51:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 00:51:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200405280547.AAA02633@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.179 -> 1.180 --- Log message: Fix the big regression that has been killing the nightly tester these last few days. Apparently the old symbol table used to auto rename collisions in the type symbol table and the new one does not. It doesn't really make sense for the new one to do so, so we just make the client do it. --- Diffs of the changes: (+3 -1) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.179 llvm/lib/Target/CBackend/Writer.cpp:1.180 --- llvm/lib/Target/CBackend/Writer.cpp:1.179 Fri May 28 00:30:51 2004 +++ llvm/lib/Target/CBackend/Writer.cpp Fri May 28 00:47:27 2004 @@ -236,10 +236,12 @@ // structure types. // bool Changed = false; + unsigned RenameCounter = 0; for (std::set::const_iterator I = UT.begin(), E = UT.end(); I != E; ++I) if (const StructType *ST = dyn_cast(*I)) { - const_cast(ST)->setName("unnamed", &MST); + while (M.addTypeName("unnamed"+utostr(RenameCounter), ST)) + ++RenameCounter; Changed = true; } return Changed; From lattner at cs.uiuc.edu Fri May 28 02:30:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 02:30:01 2004 Subject: [llvm-commits] CVS: llvm-www/random-box.cgi Message-ID: <200405280726.CAA17113@zion.cs.uiuc.edu> Changes in directory llvm-www: random-box.cgi added (r1.1) --- Log message: New script --- Diffs of the changes: (+25 -0) Index: llvm-www/random-box.cgi diff -c /dev/null llvm-www/random-box.cgi:1.1 *** /dev/null Fri May 28 02:26:31 2004 --- llvm-www/random-box.cgi Fri May 28 02:26:21 2004 *************** *** 0 **** --- 1,25 ---- + #!/usr/bin/perl -w + + print "Content-type: text/html\n\n"; + + sub ReadFile { + undef $/; + if (open (FILE, $_[0])) { + my $Ret = ; + close FILE; + return $Ret; + } else { + print "Could not open file '$_[0]' for reading!"; + return ""; + } + } + + + opendir DH, "RandomBoxes" or die "Where'd RandomBoxes go?"; + @Files = grep /[0-9]/, readdir DH; + closedir DH; + + srand(time ^ $$); + print ReadFile "RandomBoxes/" . $Files[rand(@Files)]; + print "\n"; + exit(0); From lattner at cs.uiuc.edu Fri May 28 02:30:13 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 02:30:13 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/ Message-ID: <200405280726.CAA17118@zion.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: --- Log message: Directory /home/vadve/shared/InternalCVS/llvm-www/RandomBoxes added to the repository --- Diffs of the changes: (+0 -0) From lattner at cs.uiuc.edu Fri May 28 02:37:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 02:37:01 2004 Subject: [llvm-commits] CVS: llvm-www/img/llvmtv-logo.png Message-ID: <200405280733.CAA17777@zion.cs.uiuc.edu> Changes in directory llvm-www/img: llvmtv-logo.png added (r1.1) --- Log message: Add logo --- Diffs of the changes: (+0 -0) Index: llvm-www/img/llvmtv-logo.png From lattner at cs.uiuc.edu Fri May 28 02:50:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 02:50:01 2004 Subject: [llvm-commits] CVS: llvm-www/www-index.html Message-ID: <200405280746.CAA18448@zion.cs.uiuc.edu> Changes in directory llvm-www: www-index.html updated: 1.100 -> 1.101 --- Log message: Add the ability to print out a random cool use of LLVM. Think of it as a big quip. :) --- Diffs of the changes: (+10 -0) Index: llvm-www/www-index.html diff -u llvm-www/www-index.html:1.100 llvm-www/www-index.html:1.101 --- llvm-www/www-index.html:1.100 Mon May 24 20:34:50 2004 +++ llvm-www/www-index.html Fri May 28 02:46:25 2004 @@ -169,6 +169,16 @@

        +
        Neat uses of LLVM
        + +

        Here's a random cool application of LLVM:

        + +
        + +
        + +

        If you have an addition, please send it in.

        +
        Funding

        From lattner at cs.uiuc.edu Fri May 28 02:50:13 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 02:50:13 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/001-C++Compiler.html 002-LLVM-TV.html 003-Stacker.html 004-LLVA.html 005-Safety.html 006-LifeLong.html Message-ID: <200405280746.CAA19090@zion.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: 001-C++Compiler.html added (r1.1) 002-LLVM-TV.html added (r1.1) 003-Stacker.html added (r1.1) 004-LLVA.html added (r1.1) 005-Safety.html added (r1.1) 006-LifeLong.html added (r1.1) --- Log message: Here's a few to start with --- Diffs of the changes: (+22 -0) Index: llvm-www/RandomBoxes/001-C++Compiler.html diff -c /dev/null llvm-www/RandomBoxes/001-C++Compiler.html:1.1 *** /dev/null Fri May 28 02:46:47 2004 --- llvm-www/RandomBoxes/001-C++Compiler.html Fri May 28 02:46:37 2004 *************** *** 0 **** --- 1,3 ---- + Did you know that LLVM has a GCC 3.4 compatible C++ front-end and a great + optimizer? We find that LLVM is able to compile C++ into substantially better + code than GCC (for example). Index: llvm-www/RandomBoxes/002-LLVM-TV.html diff -c /dev/null llvm-www/RandomBoxes/002-LLVM-TV.html:1.1 *** /dev/null Fri May 28 02:46:47 2004 --- llvm-www/RandomBoxes/002-LLVM-TV.html Fri May 28 02:46:37 2004 *************** *** 0 **** --- 1,3 ---- + + Check out the LLVM Visualization Tool, a neat tool for graphically inspecting LLVM programs. It lets you view the CFG, Call Graph, SSA def-use chains, and data structures in a bytecode file. + Index: llvm-www/RandomBoxes/003-Stacker.html diff -c /dev/null llvm-www/RandomBoxes/003-Stacker.html:1.1 *** /dev/null Fri May 28 02:46:47 2004 --- llvm-www/RandomBoxes/003-Stacker.html Fri May 28 02:46:37 2004 *************** *** 0 **** --- 1,3 ---- + Stacker is a Forth-like language that targets + LLVM code. In fact, Stacker is a great little example language demonstrating + how to write a front-end for LLVM. Index: llvm-www/RandomBoxes/004-LLVA.html diff -c /dev/null llvm-www/RandomBoxes/004-LLVA.html:1.1 *** /dev/null Fri May 28 02:46:47 2004 --- llvm-www/RandomBoxes/004-LLVA.html Fri May 28 02:46:37 2004 *************** *** 0 **** --- 1,5 ---- + The LLVA project is looking at novel + microprocessor designs by exploiting the LLVM code representation as the + native interface from software to the processor. This style of processor + implementation allows the architects to freely change the ISA of the processor and + exposes key high-level information to it as well. Index: llvm-www/RandomBoxes/005-Safety.html diff -c /dev/null llvm-www/RandomBoxes/005-Safety.html:1.1 *** /dev/null Fri May 28 02:46:47 2004 --- llvm-www/RandomBoxes/005-Safety.html Fri May 28 02:46:37 2004 *************** *** 0 **** --- 1,4 ---- + The SAFECode project is using LLVM + as a framework for providing + memory safety without runtime checks or garbage collection. To do this it + makes use of LLVM's link-time whole-program analysis capabilities. Index: llvm-www/RandomBoxes/006-LifeLong.html diff -c /dev/null llvm-www/RandomBoxes/006-LifeLong.html:1.1 *** /dev/null Fri May 28 02:46:47 2004 --- llvm-www/RandomBoxes/006-LifeLong.html Fri May 28 02:46:37 2004 *************** *** 0 **** --- 1,4 ---- + LLVM has a novel lifelong compilation + model, which allows program analysis and transformation through-out the + lifetime of the program (compile-time, link-time, install-time, run-time, + offline) without requiring special makefiles. From lattner at cs.uiuc.edu Fri May 28 02:51:00 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 02:51:00 2004 Subject: [llvm-commits] CVS: llvm-www/www-index.html Message-ID: <200405280747.CAA19727@zion.cs.uiuc.edu> Changes in directory llvm-www: www-index.html updated: 1.101 -> 1.102 --- Log message: Minor change --- Diffs of the changes: (+2 -2) Index: llvm-www/www-index.html diff -u llvm-www/www-index.html:1.101 llvm-www/www-index.html:1.102 --- llvm-www/www-index.html:1.101 Fri May 28 02:46:25 2004 +++ llvm-www/www-index.html Fri May 28 02:47:39 2004 @@ -169,9 +169,9 @@

        -

        Neat uses of LLVM
        +
        Neat uses and features of LLVM
        -

        Here's a random cool application of LLVM:

        +

        Here is your random application or feature of LLVM:

        From lattner at cs.uiuc.edu Fri May 28 11:53:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 11:53:02 2004 Subject: [llvm-commits] CVS: llvm/docs/CommandGuide/bugpoint.html Message-ID: <200405281650.LAA22687@zion.cs.uiuc.edu> Changes in directory llvm/docs/CommandGuide: bugpoint.html updated: 1.29 -> 1.30 --- Log message: Unbreak the bugpoint image --- Diffs of the changes: (+1 -1) Index: llvm/docs/CommandGuide/bugpoint.html diff -u llvm/docs/CommandGuide/bugpoint.html:1.29 llvm/docs/CommandGuide/bugpoint.html:1.30 --- llvm/docs/CommandGuide/bugpoint.html:1.29 Tue May 4 16:13:35 2004 +++ llvm/docs/CommandGuide/bugpoint.html Fri May 28 11:49:54 2004 @@ -12,7 +12,7 @@

        SYNOPSIS

        bugpoint [options] [input LLVM ll/bc files] [LLVM passes] --args <program arguments>... - +

        DESCRIPTION

        The bugpoint tool narrows down the source of From lattner at cs.uiuc.edu Fri May 28 12:05:36 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 12:05:36 2004 Subject: [llvm-commits] CVS: llvm-www/img/logo-bugpoint.gif logo-llvmtv.png llvmtv-logo.png Message-ID: <200405281700.MAA23424@zion.cs.uiuc.edu> Changes in directory llvm-www/img: logo-bugpoint.gif added (r1.1) logo-llvmtv.png added (r1.1) llvmtv-logo.png (r1.1) removed --- Log message: Rename llvm-tv logo, add a bugpoint logo thing --- Diffs of the changes: (+0 -0) Index: llvm-www/img/logo-bugpoint.gif Index: llvm-www/img/logo-llvmtv.png From lattner at cs.uiuc.edu Fri May 28 12:06:05 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 12:06:05 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/007-Bugpoint.html 002-LLVM-TV.html Message-ID: <200405281701.MAA24086@zion.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: 007-Bugpoint.html added (r1.1) 002-LLVM-TV.html updated: 1.1 -> 1.2 --- Log message: Add bugpoint entry, rename llvmtv logo --- Diffs of the changes: (+4 -1) Index: llvm-www/RandomBoxes/007-Bugpoint.html diff -c /dev/null llvm-www/RandomBoxes/007-Bugpoint.html:1.1 *** /dev/null Fri May 28 12:01:13 2004 --- llvm-www/RandomBoxes/007-Bugpoint.html Fri May 28 12:01:03 2004 *************** *** 0 **** --- 1,3 ---- + + Bugpoint is a automated testcase reduction too that is extremely useful for debugging problems in LLVM optimizers and code generators. It can usually reduce an optimizer crash down to the few instructions needed to reproduce the problem or a miscompilation down to the specific loop nest or basic block in the program that is causing the problem. + Index: llvm-www/RandomBoxes/002-LLVM-TV.html diff -u llvm-www/RandomBoxes/002-LLVM-TV.html:1.1 llvm-www/RandomBoxes/002-LLVM-TV.html:1.2 --- llvm-www/RandomBoxes/002-LLVM-TV.html:1.1 Fri May 28 02:46:37 2004 +++ llvm-www/RandomBoxes/002-LLVM-TV.html Fri May 28 12:01:03 2004 @@ -1,3 +1,3 @@ - + Check out the LLVM Visualization Tool, a neat tool for graphically inspecting LLVM programs. It lets you view the CFG, Call Graph, SSA def-use chains, and data structures in a bytecode file. From alkis at niobe.cs.uiuc.edu Fri May 28 12:32:03 2004 From: alkis at niobe.cs.uiuc.edu (Alkis Evlogimenos) Date: Fri May 28 12:32:03 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/007-Bugpoint.html Message-ID: <200405281730.i4SHUjP30735@niobe.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: 007-Bugpoint.html updated: 1.1 -> 1.2 --- Log message: s/too/tool/ --- Diffs of the changes: (+1 -1) Index: llvm-www/RandomBoxes/007-Bugpoint.html diff -u llvm-www/RandomBoxes/007-Bugpoint.html:1.1 llvm-www/RandomBoxes/007-Bugpoint.html:1.2 --- llvm-www/RandomBoxes/007-Bugpoint.html:1.1 Fri May 28 12:01:03 2004 +++ llvm-www/RandomBoxes/007-Bugpoint.html Fri May 28 12:30:35 2004 @@ -1,3 +1,3 @@ -Bugpoint is a automated testcase reduction too that is extremely useful for debugging problems in LLVM optimizers and code generators. It can usually reduce an optimizer crash down to the few instructions needed to reproduce the problem or a miscompilation down to the specific loop nest or basic block in the program that is causing the problem. +Bugpoint is a automated testcase reduction tool that is extremely useful for debugging problems in LLVM optimizers and code generators. It can usually reduce an optimizer crash down to the few instructions needed to reproduce the problem or a miscompilation down to the specific loop nest or basic block in the program that is causing the problem. From lattner at cs.uiuc.edu Fri May 28 14:28:18 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 14:28:18 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/008-Interprocedural.html 009-AliasAnalysis.html 010-Docs.html 011-JIT.html 012-Modular.html 013-CompilerDev.html 001-C++Compiler.html Message-ID: <200405281925.OAA25694@zion.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: 008-Interprocedural.html added (r1.1) 009-AliasAnalysis.html added (r1.1) 010-Docs.html added (r1.1) 011-JIT.html added (r1.1) 012-Modular.html added (r1.1) 013-CompilerDev.html added (r1.1) 001-C++Compiler.html updated: 1.1 -> 1.2 --- Log message: Add a bunch of new blurbs --- Diffs of the changes: (+33 -1) Index: llvm-www/RandomBoxes/008-Interprocedural.html diff -c /dev/null llvm-www/RandomBoxes/008-Interprocedural.html:1.1 *** /dev/null Fri May 28 14:25:08 2004 --- llvm-www/RandomBoxes/008-Interprocedural.html Fri May 28 14:24:58 2004 *************** *** 0 **** --- 1,6 ---- + LLVM has great support for interprocedural analysis and optimization. It + provides standard classes like call graphs, and provides a mature + Alias Analysis Infrastructure as well. + LLVM includes several interprocedural optimizations, including inlining, IP constant + propagation, dead argument elimination, dead global elimination, global + variable constantization, by-ref to by-value argument promotion, etc. Index: llvm-www/RandomBoxes/009-AliasAnalysis.html diff -c /dev/null llvm-www/RandomBoxes/009-AliasAnalysis.html:1.1 *** /dev/null Fri May 28 14:25:08 2004 --- llvm-www/RandomBoxes/009-AliasAnalysis.html Fri May 28 14:24:58 2004 *************** *** 0 **** --- 1,6 ---- + LLVM includes a powerful Alias analysis + infrastructure, that makes it easy to experiment with implementation + of new alias analysis algorithms, and compare the results against standard + algorithms. LLVM also includes several alias-analysis-driven optimizations, + so that you can see how the precision of your analysis effects actual + running time of the program. Index: llvm-www/RandomBoxes/010-Docs.html diff -c /dev/null llvm-www/RandomBoxes/010-Docs.html:1.1 *** /dev/null Fri May 28 14:25:08 2004 --- llvm-www/RandomBoxes/010-Docs.html Fri May 28 14:24:58 2004 *************** *** 0 **** --- 1,6 ---- + LLVM has extensive Documentation + describing ithe high-level aspects of the compiler system in pretty good + detail. LLVM also includes doxygen and CVSWeb documentation for the + low-level aspects and individual API references. + LLVM is one of the best documented compilers available. Index: llvm-www/RandomBoxes/011-JIT.html diff -c /dev/null llvm-www/RandomBoxes/011-JIT.html:1.1 *** /dev/null Fri May 28 14:25:08 2004 --- llvm-www/RandomBoxes/011-JIT.html Fri May 28 14:24:58 2004 *************** *** 0 **** --- 1,5 ---- + LLVM includes a powerful Just-In-Time compilation system. You can even + dynamically generate portable LLVM code on the fly and dynamically compile + it to native code, without having to go to LLVM bytecode or assembly. + Consider a raytracer with a programmable shading model: JIT compilation + can speed up shader evaluation by orders of magnitude over interpretation. Index: llvm-www/RandomBoxes/012-Modular.html diff -c /dev/null llvm-www/RandomBoxes/012-Modular.html:1.1 *** /dev/null Fri May 28 14:25:08 2004 --- llvm-www/RandomBoxes/012-Modular.html Fri May 28 14:24:58 2004 *************** *** 0 **** --- 1,3 ---- + LLVM is a completely modular compiler infrastructure that allows you + build compiler related tools with ease. Simply pick the front-end, + optimizations, code generator, or other components that you need for your tool. Index: llvm-www/RandomBoxes/013-CompilerDev.html diff -c /dev/null llvm-www/RandomBoxes/013-CompilerDev.html:1.1 *** /dev/null Fri May 28 14:25:08 2004 --- llvm-www/RandomBoxes/013-CompilerDev.html Fri May 28 14:24:58 2004 *************** *** 0 **** --- 1,5 ---- + LLVM is a great platform for compiler research. It has a simple and easy to understand representation and a completely + modular system for adding passes to the compiler. LLVM also provides extensive assertions + to pinpoint bugs when they occur, an IR verifier, and tools + to automatically identify and narrow down bugs in arbitrary compiler transformations. Index: llvm-www/RandomBoxes/001-C++Compiler.html diff -u llvm-www/RandomBoxes/001-C++Compiler.html:1.1 llvm-www/RandomBoxes/001-C++Compiler.html:1.2 --- llvm-www/RandomBoxes/001-C++Compiler.html:1.1 Fri May 28 02:46:37 2004 +++ llvm-www/RandomBoxes/001-C++Compiler.html Fri May 28 14:24:58 2004 @@ -1,3 +1,4 @@ Did you know that LLVM has a GCC 3.4 compatible C++ front-end and a great optimizer? We find that LLVM is able to compile C++ into substantially better -code than GCC (for example). +code than GCC (for example). Also, because LLVM code can be converted to C, +you can even use LLVM as a C++-to-C translator. From lattner at cs.uiuc.edu Fri May 28 14:29:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 14:29:03 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/010-Docs.html Message-ID: <200405281926.OAA26349@zion.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: 010-Docs.html updated: 1.1 -> 1.2 --- Log message: fix typeo --- Diffs of the changes: (+1 -1) Index: llvm-www/RandomBoxes/010-Docs.html diff -u llvm-www/RandomBoxes/010-Docs.html:1.1 llvm-www/RandomBoxes/010-Docs.html:1.2 --- llvm-www/RandomBoxes/010-Docs.html:1.1 Fri May 28 14:24:58 2004 +++ llvm-www/RandomBoxes/010-Docs.html Fri May 28 14:26:03 2004 @@ -1,5 +1,5 @@ LLVM has extensive Documentation -describing ithe high-level aspects of the compiler system in pretty good +describing the high-level aspects of the compiler system in good detail. LLVM also includes doxygen and CVSWeb documentation for the low-level aspects and individual API references. From lattner at cs.uiuc.edu Fri May 28 14:32:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 14:32:01 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/014-WideRangeOfProjects.html Message-ID: <200405281928.OAA27013@zion.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: 014-WideRangeOfProjects.html added (r1.1) --- Log message: blurby --- Diffs of the changes: (+3 -0) Index: llvm-www/RandomBoxes/014-WideRangeOfProjects.html diff -c /dev/null llvm-www/RandomBoxes/014-WideRangeOfProjects.html:1.1 *** /dev/null Fri May 28 14:28:51 2004 --- llvm-www/RandomBoxes/014-WideRangeOfProjects.html Fri May 28 14:28:41 2004 *************** *** 0 **** --- 1,3 ---- + LLVM is currently being used for a broad range of compiler, architecture, + program safety, and operating systems research. Just think what a flexible + and adaptable compiler system can do for you! From gaeke at cs.uiuc.edu Fri May 28 14:35:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 28 14:35:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9TargetMachine.cpp Message-ID: <200405281934.OAA27076@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9TargetMachine.cpp updated: 1.111 -> 1.112 --- Log message: Make debugging output with -print-machineinstrs more useful: always print out the transformed LLVM code which is the input to the instruction selector. --- Diffs of the changes: (+5 -0) Index: llvm/lib/Target/SparcV9/SparcV9TargetMachine.cpp diff -u llvm/lib/Target/SparcV9/SparcV9TargetMachine.cpp:1.111 llvm/lib/Target/SparcV9/SparcV9TargetMachine.cpp:1.112 --- llvm/lib/Target/SparcV9/SparcV9TargetMachine.cpp:1.111 Sun May 23 16:23:33 2004 +++ llvm/lib/Target/SparcV9/SparcV9TargetMachine.cpp Fri May 28 14:33:59 2004 @@ -149,6 +149,11 @@ PM.add(createLICMPass()); PM.add(createGCSEPass()); + // If the user's trying to read the generated code, they'll need to see the + // transformed input. + if (PrintMachineCode) + PM.add(new PrintModulePass()); + // Construct and initialize the MachineFunction object for this fn. PM.add(createMachineCodeConstructionPass(*this)); From gaeke at cs.uiuc.edu Fri May 28 14:36:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 28 14:36:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Message-ID: <200405281934.OAA27083@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/InstrSelection: InstrSelection.cpp updated: 1.72 -> 1.73 --- Log message: Give PhiCp nodes better names in many cases. Simplify InsertPhiElimInstructions(), and give it a better doxygen comment. --- Diffs of the changes: (+7 -19) Index: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp diff -u llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.72 llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.73 --- llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.72 Fri Apr 23 13:15:47 2004 +++ llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Fri May 28 14:34:00 2004 @@ -220,8 +220,7 @@ for (MachineFunction::iterator BB = MF.begin(); BB != MF.end(); ++BB) { for (BasicBlock::const_iterator IIt = BB->getBasicBlock()->begin(); const PHINode *PN = dyn_cast(IIt); ++IIt) { - // FIXME: This is probably wrong... - Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:"); + Value *PhiCpRes = new PHINode(PN->getType(), PN->getName() + ":PhiCp"); // The leak detector shouldn't track these nodes. They are not garbage, // even though their parent field is never filled in. @@ -254,11 +253,10 @@ } // for all BBs in function } -//------------------------------------------------------------------------- -// Thid method inserts a copy instruction to a predecessor BB as a result -// of phi elimination. -//------------------------------------------------------------------------- - +/// InsertPhiElimInstructions - Inserts the instructions in CpVec into the +/// MachineBasicBlock corresponding to BB, just before its terminator +/// instruction. This is used by InsertCodeForPhis() to insert copies, above. +/// void InstructionSelection::InsertPhiElimInstructions(BasicBlock *BB, const std::vector& CpVec) @@ -268,19 +266,9 @@ MachineInstr *FirstMIOfTerm = MC4Term.front(); assert (FirstMIOfTerm && "No Machine Instrs for terminator"); - MachineFunction &MF = MachineFunction::get(BB->getParent()); - - // FIXME: if PHI instructions existed in the machine code, this would be - // unnecessary. - MachineBasicBlock *MBB = 0; - for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) - if (I->getBasicBlock() == BB) { - MBB = I; - break; - } - + MachineBasicBlock *MBB = FirstMIOfTerm->getParent(); + assert(MBB && "Machine BB for predecessor's terminator not found"); MachineBasicBlock::iterator MCIt = FirstMIOfTerm; - assert(MCIt != MBB->end() && "Start inst of terminator not found"); // insert the copy instructions just before the first machine instruction From tbrethou at cs.uiuc.edu Fri May 28 15:16:02 2004 From: tbrethou at cs.uiuc.edu (Tanya Brethour) Date: Fri May 28 15:16:02 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp ModuloScheduling.h Message-ID: <200405282014.PAA20249@seraph.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/ModuloScheduling: ModuloScheduling.cpp updated: 1.18 -> 1.19 ModuloScheduling.h updated: 1.13 -> 1.14 --- Log message: updates to ModuloSched --- Diffs of the changes: (+0 -0) From criswell at cs.uiuc.edu Fri May 28 15:24:01 2004 From: criswell at cs.uiuc.edu (John Criswell) Date: Fri May 28 15:24:01 2004 Subject: [llvm-commits] CVS: llvm-www/RandomBoxes/009-AliasAnalysis.html Message-ID: <200405282022.PAA03703@choi.cs.uiuc.edu> Changes in directory llvm-www/RandomBoxes: 009-AliasAnalysis.html updated: 1.1 -> 1.2 --- Log message: Fixed grammar and commas. --- Diffs of the changes: (+5 -5) Index: llvm-www/RandomBoxes/009-AliasAnalysis.html diff -u llvm-www/RandomBoxes/009-AliasAnalysis.html:1.1 llvm-www/RandomBoxes/009-AliasAnalysis.html:1.2 --- llvm-www/RandomBoxes/009-AliasAnalysis.html:1.1 Fri May 28 14:24:58 2004 +++ llvm-www/RandomBoxes/009-AliasAnalysis.html Fri May 28 15:22:21 2004 @@ -1,6 +1,6 @@ LLVM includes a powerful Alias analysis -infrastructure, that makes it easy to experiment with implementation -of new alias analysis algorithms, and compare the results against standard -algorithms. LLVM also includes several alias-analysis-driven optimizations, -so that you can see how the precision of your analysis effects actual -running time of the program. +infrastructure that makes it easy to experiment with implementations +of new alias analysis algorithms and compare the results against standard +algorithms. LLVM also includes several alias-analysis-driven optimizations +so that you can see how the precision of your analysis affects the actual +execution time of the program. From lattner at cs.uiuc.edu Fri May 28 15:34:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 15:34:02 2004 Subject: [llvm-commits] CVS: llvm/utils/NightlyTest.pl NightlyTestTemplate.html Message-ID: <200405282030.PAA27215@zion.cs.uiuc.edu> Changes in directory llvm/utils: NightlyTest.pl updated: 1.45 -> 1.46 NightlyTestTemplate.html updated: 1.23 -> 1.24 --- Log message: Changes to make the nightly tester run the regression tests at night, yaay! Change contributed by Reid Spencer. --- Diffs of the changes: (+156 -13) Index: llvm/utils/NightlyTest.pl diff -u llvm/utils/NightlyTest.pl:1.45 llvm/utils/NightlyTest.pl:1.46 --- llvm/utils/NightlyTest.pl:1.45 Mon Jan 12 10:55:30 2004 +++ llvm/utils/NightlyTest.pl Fri May 28 15:30:23 2004 @@ -13,12 +13,16 @@ # -nocheckout Do not create, checkout, update, or configure # the source tree. # -noremove Do not remove the BUILDDIR after it has been built. +# -nofeaturetests Do not run the feature tests. +# -noregressiontests Do not run the regression tests. # -notest Do not even attempt to run the test programs. Implies # -norunningtests. # -norunningtests Do not run the Olden benchmark suite with # LARGE_PROBLEM_SIZE enabled. # -parallel Run two parallel jobs with GNU Make. # -enable-linscan Enable linearscan tests +# -verbose Turn on some debug output +# -debug Print information useful only to maintainers of this script. # # CVSROOT is the CVS repository from which the tree will be checked out, # specified either in the full :method:user at host:/dir syntax, or @@ -36,9 +40,13 @@ my $HOME = $ENV{'HOME'}; my $CVSRootDir = $ENV{'CVSROOT'}; $CVSRootDir = "/home/vadve/shared/PublicCVS" - unless $CVSRootDir; -my $BuildDir = "$HOME/buildtest"; -my $WebDir = "$HOME/cvs/testresults-X86"; + unless $CVSRootDir; +my $BuildDir = $ENV{'BUILDDIR'}; + $BuildDir = "$HOME/buildtest" + unless $BuildDir; +my $WebDir = $ENV{'WEBDIR'}; + $WebDir = "$HOME/cvs/testresults-X86" + unless $WebDir; # Calculate the date prefix... @TIME = localtime; @@ -116,10 +124,14 @@ # Command line argument settings... my $NOCHECKOUT = 0; my $NOREMOVE = 0; +my $NOFEATURES = 0; +my $NOREGRESSIONS = 0; my $NOTEST = 0; my $NORUNNINGTESTS = 0; my $MAKEOPTS = ""; my $ENABLELINEARSCAN = ""; +my $VERBOSE = 0; +my $DEBUG = 0; # Parse arguments... while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { @@ -129,10 +141,14 @@ # List command line options here... if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; } if (/^-noremove$/) { $NOREMOVE = 1; next; } + if (/^-nofeaturetests$/) { $NOFEATURES = 1; next; } + if (/^-noregressiontests$/){ $NOREGRESSIONS = 1; next; } if (/^-notest$/) { $NOTEST = 1; $NORUNNINGTESTS = 1; next; } if (/^-norunningtests$/) { $NORUNNINGTESTS = 1; next; } if (/^-parallel$/) { $MAKEOPTS = "-j2 -l3.0"; next; } if (/^-enable-linscan$/) { $ENABLELINEARSCAN = "ENABLE_LINEARSCAN=1"; next; } + if (/^-verbose$/) { $VERBOSE = 1; next; } + if (/^-debug$/) { $DEBUG = 1; next; } print "Unknown option: $_ : ignoring!\n"; } @@ -145,10 +161,12 @@ $WebDir = $ARGV[2]; } + my $Template = "$BuildDir/llvm/utils/NightlyTestTemplate.html"; my $Prefix = "$WebDir/$DATE"; -if (0) { +if ($VERBOSE) { + print "INITIALIZED\n"; print "CVS Root = $CVSRootDir\n"; print "BuildDir = $BuildDir\n"; print "WebDir = $WebDir\n"; @@ -160,6 +178,13 @@ # Create the CVS repository directory # if (!$NOCHECKOUT) { + if (-d $BuildDir) { + if (!$NOREMOVE) { + rmdir $BuildDir or die "Could not remove CVS checkout directory $BuildDir!"; + } else { + die "CVS checkout directory $BuildDir already exists!"; + } + } mkdir $BuildDir or die "Could not create CVS checkout directory $BuildDir!"; } chdir $BuildDir or die "Could not change to CVS checkout directory $BuildDir!"; @@ -170,12 +195,17 @@ # $CVSOPT = ""; $CVSOPT = "-z3" if $CVSRootDir =~ /^:ext:/; # Use compression if going over ssh. -system "(time -p cvs $CVSOPT -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1" - if (!$NOCHECKOUT); +if (!$NOCHECKOUT) { + if ( $VERBOSE ) { print "CHECKOUT STAGE\n"; } + system "(time -p cvs $CVSOPT -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"; +} chdir "llvm" or die "Could not change into llvm directory!"; -system "cvs up -P -d > /dev/null 2>&1" if (!$NOCHECKOUT); +if (!$NOCHECKOUT) { + if ( $VERBOSE ) { print "UPDATE STAGE\n"; } + system "cvs update -P -d > /dev/null 2>&1" ; +} # Read in the HTML template file... my $TemplateContents = ReadFile $Template; @@ -193,8 +223,10 @@ # Build the entire tree, saving build messages to the build log # if (!$NOCHECKOUT) { + if ( $VERBOSE ) { print "CONFIGURE STAGE\n"; } system "(time -p ./configure --enable-jit --enable-spec --with-objroot=.) > $Prefix-Build-Log.txt 2>&1"; + if ( $VERBOSE ) { print "BUILD STAGE\n"; } # Build the entire tree, capturing the output into $Prefix-Build-Log.txt system "(time -p gmake $MAKEOPTS) >> $Prefix-Build-Log.txt 2>&1"; } @@ -232,6 +264,84 @@ print "BUILD ERROR\n"; } +sub GetQMTestResults { # (filename) + my ($filename) = @_; + my @lines; + my $firstline; + $/ = "\n"; #Make sure we're going line at a time. + if (open SRCHFILE, $filename) { + while ( ) { + if ( m/^--- TEST RESULTS/ ) { + push(@lines, $_); last; + } + } + while ( ) { + if ( length($_) > 1 ) { + if ( ! m/^gmake:/ && ! m/^ qmtest.target:/ && !/^ local/ ) { + push(@lines,$_); + } + } + } + close SRCHFILE; + } + my $content = join("", at lines); + return "
        \n at lines
        \n"; +} + + +# Get results of feature tests. +my $FeatureTestResults; # String containing the results of the feature tests +my $FeatureTime; # System+CPU Time for feature tests +my $FeatureWallTime; # Wall Clock Time for feature tests +if (!$NOFEATURES) { + if ( $VERBOSE ) { print "FEATURE TEST STAGE\n"; } + my $feature_output = "$Prefix-FeatureTests-Log.txt"; + + # Run the feature tests so we can summarize the results + system "(time -p gmake -C test Feature.t) > $feature_output 2>&1"; + + # Extract test results + $FeatureTestResults = GetQMTestResults("$feature_output"); + + # Extract time of feature tests + my $FeatureTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$feature_output"; + my $FeatureTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$feature_output"; + $FeatureTime = $FeatureTimeU+$FeatureTimeS; # FeatureTime = User+System + $FeatureWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$feature_output"; + # Run the regression tests so we can summarize the results +} else { + $FeatureTestResults = "Skipped by user choice."; + $FeatureTime = "0.0"; + $FeatureWallTime = "0.0"; +} + +if (!$NOREGRESSIONS) { + if ( $VERBOSE ) { print "REGRESSION TEST STAGE\n"; } + my $regression_output = "$Prefix-RegressionTests-Log.txt"; + + # Run the regression tests so we can summarize the results + system "(time -p gmake -C test Regression.t) > $regression_output 2>&1"; + + # Extract test results + $RegressionTestResults = GetQMTestResults("$regression_output"); + + # Extract time of regressions tests + my $RegressionTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$regression_output"; + my $RegressionTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$regression_output"; + $RegressionTime = $RegressionTimeU+$RegressionTimeS; # RegressionTime = User+System + $RegressionWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$regression_output"; +} else { + $RegressionTestResults = "Skipped by user choice."; + $RegressionTime = "0.0"; + $RegressionWallTime = "0.0"; +} + +if ($DEBUG) { + print $FeatureTestResults; + print $RegressionTestResults; +} + +if ( $VERBOSE ) { print "BUILD INFORMATION COLLECTION STAGE\n"; } # # Get warnings from the build # @@ -267,6 +377,7 @@ # # Get some statistics about CVS commits over the current day... # +if ($VERBOSE) { print "CVS HISTORY ANALYSIS STAGE\n"; } @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`; #print join "\n", @CVSHistory; print "\n"; @@ -361,13 +472,25 @@ # If we build the tree successfully, run the nightly programs tests... if ($BuildError eq "") { + if ( $VERBOSE ) { + print "SingleSource TEST STAGE\n"; + } $SingleSourceProgramsTable = TestDirectory("SingleSource"); + if ( $VERBOSE ) { + print "MultiSource TEST STAGE\n"; + } $MultiSourceProgramsTable = TestDirectory("MultiSource"); + if ( $VERBOSE ) { + print "External TEST STAGE\n"; + } $ExternalProgramsTable = TestDirectory("External"); system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ". " $Prefix-External-Tests.txt | sort > $Prefix-Tests.txt"; } +if ( $VERBOSE ) { + print "TEST INFORMATION COLLECTION STAGE\n"; +} my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","",""); if ($TestError) { @@ -493,6 +616,9 @@ AddRecord($LOC, "running_loc.txt"); AddRecord($BuildTime, "running_build_time.txt"); +if ( $VERBOSE ) { + print "GRAPH GENERATION STAGE\n"; +} # # Rebuild the graphs now... # @@ -509,12 +635,13 @@ # # Print out information... # -if (0) { +if ($VERBOSE) { print "DateString: $DateString\n"; print "CVS Checkout: $CVSCheckoutTime seconds\n"; print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n"; - print "Build Time: $BuildTime seconds\n"; + print "Feature Test Time: $FeatureTime seconds\n"; + print "Regression Test Time: $RegressionTime seconds\n"; print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n"; print "WARNINGS:\n $WarningsList\n"; @@ -532,6 +659,9 @@ # Output the files... # +if ( $VERBOSE ) { + print "OUTPUT STAGE\n"; +} # Main HTML file... my $Output; eval "\$Output = <Changes
        Trends
        Programs
        +Feature
        Regression
        @@ -65,6 +66,10 @@ ($ConfigWallTime seconds wall time)
        Time to build CVS tree: $BuildTime seconds ($BuildWallTime seconds wall time)
        + Time to run feature tests: $FeatureTime seconds + ($FeatureWallTime seconds wall time)
        + Time to run regression tests: $RegressionTime seconds + ($RegressionWallTime seconds wall time)
        Number of object files compiled: $NumObjects
        Number of libraries linked: $NumLibraries
        Number of executables linked: $NumExecutables
        @@ -233,13 +238,21 @@ -

        +

        Regression Tests -

        +Feature Test Results +

        +
        +$FeatureTestResults -Not yet implemented

        +

        +
        +
        Regression Tests +
        +
        +$RegressionTestResults From lattner at cs.uiuc.edu Fri May 28 15:34:13 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 15:34:13 2004 Subject: [llvm-commits] CVS: llvm/docs/OpenProjects.html Message-ID: <200405282030.PAA27858@zion.cs.uiuc.edu> Changes in directory llvm/docs: OpenProjects.html updated: 1.28 -> 1.29 --- Log message: Reid implemented this. --- Diffs of the changes: (+1 -20) Index: llvm/docs/OpenProjects.html diff -u llvm/docs/OpenProjects.html:1.28 llvm/docs/OpenProjects.html:1.29 --- llvm/docs/OpenProjects.html:1.28 Sun May 23 16:06:21 2004 +++ llvm/docs/OpenProjects.html Fri May 28 15:30:48 2004 @@ -16,7 +16,6 @@
      • Improving the current system
        1. Port glibc to LLVM
        2. -
        3. Improving the Nightly Tester
        4. Compile programs with the LLVM Compiler
        5. Extend the LLVM intermediate representation
        6. Miscellaneous Improvements
        7. @@ -99,24 +98,6 @@ - -
          - -

          The Nightly Tester is a simple perl script -(located in utils/NightlyTest.pl) which runs every night to generate a -daily report. It could use the following improvements:

          - -
            -
          1. Regression tests - We should run the regression tests in addition to the - program tests...
          2. -
          - -
          - - - @@ -333,7 +314,7 @@ Chris Lattner
          LLVM Compiler Infrastructure
          - Last modified: $Date: 2004/05/23 21:06:21 $ + Last modified: $Date: 2004/05/28 20:30:48 $ From lattner at cs.uiuc.edu Fri May 28 15:45:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 15:45:02 2004 Subject: [llvm-commits] CVS: llvm/docs/OpenProjects.html Message-ID: <200405282041.PAA28554@zion.cs.uiuc.edu> Changes in directory llvm/docs: OpenProjects.html updated: 1.29 -> 1.30 --- Log message: Add links to new-featuer and code-cleanup bugs --- Diffs of the changes: (+31 -1) Index: llvm/docs/OpenProjects.html diff -u llvm/docs/OpenProjects.html:1.29 llvm/docs/OpenProjects.html:1.30 --- llvm/docs/OpenProjects.html:1.29 Fri May 28 15:30:48 2004 +++ llvm/docs/OpenProjects.html Fri May 28 15:41:37 2004 @@ -15,6 +15,7 @@
        8. What is this?
        9. Improving the current system
            +
          1. Implementing Code Cleanup bugs
          2. Port glibc to LLVM
          3. Compile programs with the LLVM Compiler
          4. Extend the LLVM intermediate representation
          5. @@ -23,6 +24,7 @@
          6. Adding new capabilities to LLVM
              +
            1. Implementing new feature PRs
            2. Pointer and Alias Analysis
            3. Profile Guided Optimization
            4. New Transformations and Analyses
            5. @@ -81,6 +83,22 @@ + +
              + +

              +The LLVM bug tracker occasionally +has "code-cleanup" bugs filed in it. Taking one of these and fixing it is a good +way to get your feet wet in the LLVM code and discover how some of its components +work. +

              + +
              + + + @@ -176,6 +194,18 @@
      • + + + + +
        + +

        Many ideas for feature requests are stored in LLVM bugzilla. Just search for bugs with a "new-feature" keyword.

        + +
        +
        Pointer and Alias Analysis @@ -314,7 +344,7 @@ Chris Lattner
        LLVM Compiler Infrastructure
        - Last modified: $Date: 2004/05/28 20:30:48 $ + Last modified: $Date: 2004/05/28 20:41:37 $ From gaeke at cs.uiuc.edu Fri May 28 15:48:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 28 15:48:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405282046.PAA08767@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.41 -> 1.42 --- Log message: Set the TraceOptimizerDone hoook just before the branch stitching, not after, so that we can watch it happen. --- Diffs of the changes: (+1 -1) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.41 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.42 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.41 Wed May 26 16:23:37 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Fri May 28 15:46:36 2004 @@ -89,9 +89,9 @@ // will proceed from the optimized version of the code. DEBUG(std::cerr << "Writing branch at 0x" << std::hex << a << " to point to 0x" << traceStartAddr << std::dec << "\n"); + TraceOptimizerDone(a, traceStartAddr, TJIT->getEmitter ()->getCurrentPCValue ()); vm->writeBranchInstruction(a, traceStartAddr); doFlush (a, a + 4); - TraceOptimizerDone(a, traceStartAddr, TJIT->getEmitter ()->getCurrentPCValue ()); } } // end namespace llvm From gaeke at cs.uiuc.edu Fri May 28 15:49:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 28 15:49:02 2004 Subject: [llvm-commits] CVS: reopt/test/TEST.reopt.Makefile Message-ID: <200405282046.PAA08774@kain.cs.uiuc.edu> Changes in directory reopt/test: TEST.reopt.Makefile updated: 1.15 -> 1.16 --- Log message: Save debugging output from llc in a log file in the Output subdirectory. --- Diffs of the changes: (+2 -2) Index: reopt/test/TEST.reopt.Makefile diff -u reopt/test/TEST.reopt.Makefile:1.15 reopt/test/TEST.reopt.Makefile:1.16 --- reopt/test/TEST.reopt.Makefile:1.15 Wed May 26 16:21:02 2004 +++ reopt/test/TEST.reopt.Makefile Fri May 28 15:46:37 2004 @@ -76,8 +76,8 @@ @echo "===== Building Reoptimizer version of $(TESTNAME) =====" $(LOPT) -q -inline -lowerswitch -enable-correct-eh-support \ -lowerinvoke -branch-combine -emitfuncs -instloops $< | $(LLC) \ - $(LLCFLAGS) -disable-sched -disable-strip -f -enable-maps \ - -save-ra-state -o $@ + $(LLCFLAGS) -debug -dregalloc=y -print-machineinstrs -disable-sched \ + -disable-strip -f -enable-maps -save-ra-state -o $@ 2>$@.log # 2. Link the instrumented binary with the necessary parts of the # compiler. From lattner at cs.uiuc.edu Fri May 28 16:11:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 16:11:03 2004 Subject: [llvm-commits] CVS: llvm/include/Config/windows.h Message-ID: <200405282107.QAA28732@zion.cs.uiuc.edu> Changes in directory llvm/include/Config: windows.h updated: 1.1 -> 1.2 --- Log message: Fix bizzare problems when you include Config/dlfcn and Config/windows.h in the same xlation unit --- Diffs of the changes: (+2 -2) Index: llvm/include/Config/windows.h diff -u llvm/include/Config/windows.h:1.1 llvm/include/Config/windows.h:1.2 --- llvm/include/Config/windows.h:1.1 Thu May 27 15:51:22 2004 +++ llvm/include/Config/windows.h Fri May 28 16:07:11 2004 @@ -11,8 +11,8 @@ * on the system). */ -#ifndef _CONFIG_DLFCN_H -#define _CONFIG_DLFCN_H +#ifndef LLVM_CONFIG_WINDOWS_H +#define LLVM_CONFIG_WINDOWS_H #include "Config/config.h" From lattner at cs.uiuc.edu Fri May 28 18:39:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 18:39:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/PluginLoader.cpp Message-ID: <200405282335.SAA29110@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: PluginLoader.cpp updated: 1.9 -> 1.10 --- Log message: Prune #includes --- Diffs of the changes: (+1 -2) Index: llvm/lib/Support/PluginLoader.cpp diff -u llvm/lib/Support/PluginLoader.cpp:1.9 llvm/lib/Support/PluginLoader.cpp:1.10 --- llvm/lib/Support/PluginLoader.cpp:1.9 Mon Jan 26 14:59:33 2004 +++ llvm/lib/Support/PluginLoader.cpp Fri May 28 18:35:39 2004 @@ -19,8 +19,7 @@ #include "Support/DynamicLinker.h" #include "Support/CommandLine.h" -#include "Config/dlfcn.h" -#include "Config/link.h" +#include "Config/config.h" #include using namespace llvm; From lattner at cs.uiuc.edu Fri May 28 18:58:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 18:58:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/DynamicLinker.cpp Message-ID: <200405282354.SAA29197@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: DynamicLinker.cpp updated: 1.6 -> 1.7 --- Log message: Thoroughly rehack the dynamic linking mechanisms on Win32. The Win32 dynamic linker does not automatically search libraries when looking up symbols with GetProcAddress. Because of this we have to emulate it. The only detail is that there doesn't seem to be a way to enumerate the libraries loaded, so we have a gross hack (tm). This make the JIT functional on win32 under cygwin. --- Diffs of the changes: (+41 -16) Index: llvm/lib/Support/DynamicLinker.cpp diff -u llvm/lib/Support/DynamicLinker.cpp:1.6 llvm/lib/Support/DynamicLinker.cpp:1.7 --- llvm/lib/Support/DynamicLinker.cpp:1.6 Thu May 27 15:53:10 2004 +++ llvm/lib/Support/DynamicLinker.cpp Fri May 28 18:54:07 2004 @@ -12,8 +12,7 @@ // provides it. // // Possible future extensions include support for the HPUX shl_load() -// interface, the Mac OS X NSLinkModule() interface, and the Windows -// LoadLibrary() interface. +// interface, and the Mac OS X NSLinkModule() interface. // // Note that we assume that if dlopen() is available, then dlsym() is too. // @@ -23,18 +22,36 @@ #include "Config/dlfcn.h" #include "Config/windows.h" #include +#include using namespace llvm; -bool llvm::LinkDynamicObject (const char *filename, std::string *ErrorMessage) { -#if defined (HAVE_DLOPEN) - if (dlopen (filename, RTLD_NOW | RTLD_GLOBAL) == 0) { - if (ErrorMessage) *ErrorMessage = dlerror (); - return true; +#if defined(HAVE_WINDOWS_H) +// getLoadedLibs - Keep track of the shared objects that are loaded into the +// process address space, as the windows GetProcAddress function does not +// automatically search an entire address space, it only searches a specific +// object. +static std::vector &getLoadedLibHandles() { + static std::vector *LoadedLibHandles = 0; + if (LoadedLibHandles == 0) { + LoadedLibHandles = new std::vector(); + if (HMODULE H = GetModuleHandle(NULL)) // JIT symbols + LoadedLibHandles->push_back(H); + if (HMODULE MH = GetModuleHandle("cygwin1.dll")) // Cygwin symbols OR + LoadedLibHandles->push_back(MH); + else if (HMODULE MH = GetModuleHandle("msvcr80.dll")) // VC++ symbols + LoadedLibHandles->push_back(MH); } - return false; -#elif defined(HAVE_WINDOWS_H) - if (LoadLibrary(filename)) + return *LoadedLibHandles; +} +#endif + +bool llvm::LinkDynamicObject(const char *filename, std::string *ErrorMessage) { +#if defined(HAVE_WINDOWS_H) + if (HMODULE Handle = LoadLibrary(filename)) { + // Allow GetProcAddress in this module + getLoadedLibHandles().push_back(Handle); return false; + } if (ErrorMessage) { char Buffer[100]; // FIXME: This should use FormatMessage @@ -42,23 +59,31 @@ *ErrorMessage = Buffer; } return true; +#elif defined (HAVE_DLOPEN) + if (dlopen (filename, RTLD_NOW | RTLD_GLOBAL) == 0) { + if (ErrorMessage) *ErrorMessage = dlerror (); + return true; + } + return false; #else assert (0 && "Dynamic object linking not implemented for this platform"); #endif } -void *llvm::GetAddressOfSymbol (const char *symbolName) { -#if defined (HAVE_DLOPEN) +void *llvm::GetAddressOfSymbol(const char *symbolName) { +#if defined(HAVE_WINDOWS_H) + std::vector &LH = getLoadedLibHandles(); + for (unsigned i = 0, e = LH.size(); i != e; ++i) + if (void *Val = (void*)GetProcAddress(LH[i], symbolName)) + return Val; + return 0; +#elif defined(HAVE_DLOPEN) # ifdef RTLD_DEFAULT return dlsym (RTLD_DEFAULT, symbolName); # else static void* CurHandle = dlopen(0, RTLD_LAZY); return dlsym(CurHandle, symbolName); # endif -#elif defined(HAVE_WINDOWS_H) - static HMODULE ModHandle = NULL; - if (ModHandle == 0) ModHandle = GetModuleHandle(NULL); - return (void*)GetProcAddress(ModHandle, symbolName); #else assert (0 && "Dynamic symbol lookup not implemented for this platform"); #endif From lattner at cs.uiuc.edu Fri May 28 19:00:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 28 19:00:02 2004 Subject: [llvm-commits] CVS: llvm/test/Programs/LLVMSource/Hello.ll Message-ID: <200405282356.SAA29258@zion.cs.uiuc.edu> Changes in directory llvm/test/Programs/LLVMSource: Hello.ll added (r1.1) --- Log message: Add a sanity check program --- Diffs of the changes: (+11 -0) Index: llvm/test/Programs/LLVMSource/Hello.ll diff -c /dev/null llvm/test/Programs/LLVMSource/Hello.ll:1.1 *** /dev/null Fri May 28 18:56:54 2004 --- llvm/test/Programs/LLVMSource/Hello.ll Fri May 28 18:56:44 2004 *************** *** 0 **** --- 1,11 ---- + %.str_1 = internal constant [32 x sbyte] c"Hello world with %d arguments!\0A\00" + + implementation + + declare int %printf(sbyte*, ...) + + int %main(int %argc, sbyte** %argv) { + %tmp.0 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([32 x sbyte]* %.str_1, long 0, long 0), int %argc ) + ret int 0 + } + From alkis at cs.uiuc.edu Sat May 29 03:38:04 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 03:38:04 2004 Subject: [llvm-commits] CVS: llvm-java/tools/class2llvm/class2llvm.cpp Message-ID: <200405290834.DAA11629@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/class2llvm: class2llvm.cpp updated: 1.3 -> 1.4 --- Log message: Support/Signals.h now lives in llvm/System/Signals.h --- Diffs of the changes: (+1 -1) Index: llvm-java/tools/class2llvm/class2llvm.cpp diff -u llvm-java/tools/class2llvm/class2llvm.cpp:1.3 llvm-java/tools/class2llvm/class2llvm.cpp:1.4 --- llvm-java/tools/class2llvm/class2llvm.cpp:1.3 Mon May 24 13:34:52 2004 +++ llvm-java/tools/class2llvm/class2llvm.cpp Sat May 29 03:34:42 2004 @@ -16,8 +16,8 @@ #include #include #include +#include #include -#include #include #include From alkis at cs.uiuc.edu Sat May 29 03:39:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 03:39:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/classdump/classdump.cpp Message-ID: <200405290834.DAA11630@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/classdump: classdump.cpp updated: 1.7 -> 1.8 --- Log message: Support/Signals.h now lives in llvm/System/Signals.h --- Diffs of the changes: (+1 -1) Index: llvm-java/tools/classdump/classdump.cpp diff -u llvm-java/tools/classdump/classdump.cpp:1.7 llvm-java/tools/classdump/classdump.cpp:1.8 --- llvm-java/tools/classdump/classdump.cpp:1.7 Mon May 24 13:34:52 2004 +++ llvm-java/tools/classdump/classdump.cpp Sat May 29 03:34:42 2004 @@ -13,8 +13,8 @@ //===----------------------------------------------------------------------===// #include +#include #include -#include #include #include From alkis at cs.uiuc.edu Sat May 29 04:30:05 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 04:30:05 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405290926.EAA19357@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.40 -> 1.41 --- Log message: Use correct function signatures at least as far as primitives types are concerned. --- Diffs of the changes: (+45 -3) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.40 llvm-java/lib/Compiler/Compiler.cpp:1.41 --- llvm-java/lib/Compiler/Compiler.cpp:1.40 Thu May 27 16:09:19 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 29 04:26:15 2004 @@ -157,6 +157,44 @@ return static_cast(-1); } + const Type* getType(const ConstantUtf8* descr) { + unsigned i = 0; + return getTypeHelper(descr->str(), i); + } + + const Type* getTypeHelper(const std::string& descr, unsigned& i) { + assert(i < descr.size()); + switch (descr[i++]) { + case 'B': return Type::SByteTy; + case 'C': return Type::UShortTy; + case 'D': return Type::DoubleTy; + case 'F': return Type::FloatTy; + case 'I': return Type::IntTy; + case 'J': return Type::LongTy; + case 'S': return Type::ShortTy; + case 'Z': return Type::BoolTy; + case 'V': return Type::VoidTy; + case 'L': { + unsigned e = descr.find(';', i); + std::string className = descr.substr(i, e - i); + i = e + 1; + // FIXME: this should really be a pointer to an object + // of type className + return PointerType::get(Type::SByteTy); + } + case '[': return ArrayType::get(getTypeHelper(descr, i), 0); + case '(': { + std::vector params; + while (descr[i] != ')') + params.push_back(getTypeHelper(descr, i)); + return FunctionType::get(getTypeHelper(descr, ++i), + params, false); + } + // FIXME: Throw something + default: return NULL; + } + } + Value* getOrCreateLocal(unsigned index, const Type* type) { if (!locals_[index]) { locals_[index] = new AllocaInst(type, NULL, @@ -183,10 +221,14 @@ name += method.getName()->str(); name += method.getDescriptor()->str(); - // FIXME: use proper function type - // FIXME: emit with internal linkage if function is private Function* function = - module.getOrInsertFunction(name, Type::VoidTy, 0); + new Function( + cast(getType(method.getDescriptor())), + (method.isPrivate() ? + Function::InternalLinkage : + Function::ExternalLinkage), + name, + &module); const Java::CodeAttribute* codeAttr = Java::getCodeAttribute(method.getAttributes()); From alkis at cs.uiuc.edu Sat May 29 04:39:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 04:39:03 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405290935.EAA23521@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.41 -> 1.42 --- Log message: Simplify some code a bit. --- Diffs of the changes: (+7 -11) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.41 llvm-java/lib/Compiler/Compiler.cpp:1.42 --- llvm-java/lib/Compiler/Compiler.cpp:1.41 Sat May 29 04:26:15 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 29 04:35:21 2004 @@ -481,20 +481,18 @@ do_shift_common(bcI, Instruction::Shr); - // cast shifted value back to its original signed version value = opStack_.top(); opStack_.pop(); - value = new CastInst(value, - value->getType()->getSignedVersion(), - TMP, getBBAt(bcI)); - opStack_.push(value); + // cast shifted value back to its original signed version + opStack_.push(new CastInst(value, + value->getType()->getSignedVersion(), + TMP, getBBAt(bcI))); } void do_shift_common(unsigned bcI, Instruction::OtherOps op) { Value* amount = opStack_.top(); opStack_.pop(); Value* value = opStack_.top(); opStack_.pop(); amount = new CastInst(amount, Type::UByteTy, TMP, getBBAt(bcI)); - Value* result = new ShiftInst(op, value, amount, TMP, getBBAt(bcI)); - opStack_.push(result); + opStack_.push(new ShiftInst(op, value, amount, TMP, getBBAt(bcI))); } void do_and(unsigned bcI) { @@ -512,8 +510,7 @@ void do_binary_op_common(unsigned bcI, Instruction::BinaryOps op) { Value* v2 = opStack_.top(); opStack_.pop(); Value* v1 = opStack_.top(); opStack_.pop(); - Value* r = BinaryOperator::create(op, v1, v2, TMP, getBBAt(bcI)); - opStack_.push(r); + opStack_.push(BinaryOperator::create(op, v1, v2, TMP,getBBAt(bcI))); } @@ -529,8 +526,7 @@ void do_convert(unsigned bcI, JType to) { Value* v1 = opStack_.top(); opStack_.pop(); - Value* r = new CastInst(v1, getType(to), TMP, getBBAt(bcI)); - opStack_.push(r); + opStack_.push(new CastInst(v1, getType(to), TMP, getBBAt(bcI))); } void do_lcmp(unsigned bcI) { From alkis at cs.uiuc.edu Sat May 29 11:23:06 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 11:23:06 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/LiveIntervals.h LiveIntervals.cpp Message-ID: <200405291619.LAA10397@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: LiveIntervals.h updated: 1.23 -> 1.24 LiveIntervals.cpp updated: 1.73 -> 1.74 --- Log message: Remove defs vector from live intervals. --- Diffs of the changes: (+0 -20) Index: llvm/lib/CodeGen/LiveIntervals.h diff -u llvm/lib/CodeGen/LiveIntervals.h:1.23 llvm/lib/CodeGen/LiveIntervals.h:1.24 --- llvm/lib/CodeGen/LiveIntervals.h:1.23 Fri Apr 9 13:07:57 2004 +++ llvm/lib/CodeGen/LiveIntervals.h Sat May 29 11:18:57 2004 @@ -36,12 +36,10 @@ struct Interval { typedef std::pair Range; typedef std::vector Ranges; - typedef std::vector Defs; unsigned reg; // the register of this interval float weight; // weight of this interval (number of uses // * 10^loopDepth) Ranges ranges; // the ranges in which this register is live - Defs defs; Interval(unsigned r); bool empty() const { return ranges.empty(); } Index: llvm/lib/CodeGen/LiveIntervals.cpp diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.73 llvm/lib/CodeGen/LiveIntervals.cpp:1.74 --- llvm/lib/CodeGen/LiveIntervals.cpp:1.73 Fri May 7 22:49:35 2004 +++ llvm/lib/CodeGen/LiveIntervals.cpp Sat May 29 11:18:57 2004 @@ -137,11 +137,6 @@ rep(srcReg) == rep(dstReg)) { // remove from def list Interval& interval = getOrCreateInterval(rep(dstReg)); - unsigned defIndex = getInstructionIndex(mii); - Interval::Defs::iterator d = std::lower_bound( - interval.defs.begin(), interval.defs.end(), defIndex); - assert(*d == defIndex && "Def index not found in def list!"); - interval.defs.erase(d); // remove index -> MachineInstr and // MachineInstr -> index mappings Mi2IndexMap::iterator mi2i = mi2iMap_.find(mii); @@ -289,7 +284,6 @@ } unsigned baseIndex = getInstructionIndex(mi); - interval.defs.push_back(baseIndex); bool killedInDefiningBasicBlock = false; for (int i = 0, e = vi.Kills.size(); i != e; ++i) { @@ -329,7 +323,6 @@ MachineBasicBlock::iterator e = mbb->end(); unsigned baseIndex = getInstructionIndex(mi); - interval.defs.push_back(baseIndex); unsigned start = getDefIndex(baseIndex); unsigned end = start; @@ -663,11 +656,6 @@ cur = mergeRangesBackward(cur); } weight += other.weight; - Defs u; - std::set_union(defs.begin(), defs.end(), - other.defs.begin(), other.defs.end(), - std::back_inserter(u)); - defs = u; ++numJoins; } @@ -707,12 +695,6 @@ if (li.empty()) return os << "EMPTY"; - os << " {" << li.defs.front(); - for (LiveIntervals::Interval::Defs::const_iterator - i = next(li.defs.begin()), e = li.defs.end(); i != e; ++i) - os << "," << *i; - os << "}"; - os << " = "; for (LiveIntervals::Interval::Ranges::const_iterator i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) { From alkis at cs.uiuc.edu Sat May 29 14:07:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 14:07:02 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/VirtRegMap.h Message-ID: <200405291903.OAA10832@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: VirtRegMap.h updated: 1.9 -> 1.10 --- Log message: Add grow() member that grows the maps when the number of virtual registers in the function has changed. --- Diffs of the changes: (+6 -2) Index: llvm/lib/CodeGen/VirtRegMap.h diff -u llvm/lib/CodeGen/VirtRegMap.h:1.9 llvm/lib/CodeGen/VirtRegMap.h:1.10 --- llvm/lib/CodeGen/VirtRegMap.h:1.9 Mon Mar 1 17:18:15 2004 +++ llvm/lib/CodeGen/VirtRegMap.h Sat May 29 14:03:29 2004 @@ -54,8 +54,12 @@ : mf_(&mf), v2pMap_(NO_PHYS_REG), v2ssMap_(NO_STACK_SLOT) { - v2pMap_.grow(mf.getSSARegMap()->getLastVirtReg()); - v2ssMap_.grow(mf.getSSARegMap()->getLastVirtReg()); + grow(); + } + + void grow() { + v2pMap_.grow(mf_->getSSARegMap()->getLastVirtReg()); + v2ssMap_.grow(mf_->getSSARegMap()->getLastVirtReg()); } bool hasPhys(unsigned virtReg) const { From alkis at cs.uiuc.edu Sat May 29 14:57:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 14:57:01 2004 Subject: [llvm-commits] CVS: llvm/test/Programs/RunSafely.sh Message-ID: <200405291953.OAA10951@zion.cs.uiuc.edu> Changes in directory llvm/test/Programs: RunSafely.sh updated: 1.11 -> 1.12 --- Log message: Use head -n 1 instead of the obsolete head -1. --- Diffs of the changes: (+1 -1) Index: llvm/test/Programs/RunSafely.sh diff -u llvm/test/Programs/RunSafely.sh:1.11 llvm/test/Programs/RunSafely.sh:1.12 --- llvm/test/Programs/RunSafely.sh:1.11 Sun Aug 31 12:10:55 2003 +++ llvm/test/Programs/RunSafely.sh Sat May 29 14:53:36 2004 @@ -60,7 +60,7 @@ if ls | egrep "^core" > /dev/null then - corefile=`ls core* | head -1` + corefile=`ls core* | head -n 1` echo "where" > StackTrace.$$ $GDB -q -batch --command=StackTrace.$$ --core=$corefile $PROGRAM < /dev/null rm -f StackTrace.$$ $corefile From alkis at cs.uiuc.edu Sat May 29 15:42:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 29 15:42:01 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/VirtRegMap.h VirtRegMap.cpp Message-ID: <200405292038.PAA11219@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: VirtRegMap.h updated: 1.10 -> 1.11 VirtRegMap.cpp updated: 1.11 -> 1.12 --- Log message: Add method to assign stack slot to virtual register without creating a new one. --- Diffs of the changes: (+9 -0) Index: llvm/lib/CodeGen/VirtRegMap.h diff -u llvm/lib/CodeGen/VirtRegMap.h:1.10 llvm/lib/CodeGen/VirtRegMap.h:1.11 --- llvm/lib/CodeGen/VirtRegMap.h:1.10 Sat May 29 14:03:29 2004 +++ llvm/lib/CodeGen/VirtRegMap.h Sat May 29 15:38:05 2004 @@ -97,6 +97,7 @@ } int assignVirt2StackSlot(unsigned virtReg); + void assignVirt2StackSlot(unsigned virtReg, int frameIndex); void virtFolded(unsigned virtReg, MachineInstr* oldMI, Index: llvm/lib/CodeGen/VirtRegMap.cpp diff -u llvm/lib/CodeGen/VirtRegMap.cpp:1.11 llvm/lib/CodeGen/VirtRegMap.cpp:1.12 --- llvm/lib/CodeGen/VirtRegMap.cpp:1.11 Tue Mar 9 02:35:13 2004 +++ llvm/lib/CodeGen/VirtRegMap.cpp Sat May 29 15:38:05 2004 @@ -61,6 +61,14 @@ return frameIndex; } +void VirtRegMap::assignVirt2StackSlot(unsigned virtReg, int frameIndex) +{ + assert(MRegisterInfo::isVirtualRegister(virtReg)); + assert(v2ssMap_[virtReg] == NO_STACK_SLOT && + "attempt to assign stack slot to already spilled register"); + v2ssMap_[virtReg] = frameIndex; +} + void VirtRegMap::virtFolded(unsigned virtReg, MachineInstr* oldMI, MachineInstr* newMI) From gaeke at cs.uiuc.edu Sat May 29 17:23:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 29 17:23:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Message-ID: <200405292221.RAA17574@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/InstrSelection: InstrSelection.cpp updated: 1.73 -> 1.74 --- Log message: Give InsertCodeForPhis() a new documentation comment. --- Diffs of the changes: (+7 -9) Index: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp diff -u llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.73 llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.74 --- llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.73 Fri May 28 14:34:00 2004 +++ llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Sat May 29 17:20:59 2004 @@ -207,15 +207,13 @@ return true; } - -//------------------------------------------------------------------------- -// This method inserts phi elimination code for all BBs in a method -//------------------------------------------------------------------------- - -void -InstructionSelection::InsertCodeForPhis(Function &F) { - // for all basic blocks in function - // +/// InsertCodeForPhis - This method inserts Phi elimination code for +/// all Phi nodes in the given function. After this method is called, +/// the Phi nodes still exist in the LLVM code, but copies are added to the +/// machine code. +/// +void InstructionSelection::InsertCodeForPhis(Function &F) { + // Iterate over every Phi node PN in F: MachineFunction &MF = MachineFunction::get(&F); for (MachineFunction::iterator BB = MF.begin(); BB != MF.end(); ++BB) { for (BasicBlock::const_iterator IIt = BB->getBasicBlock()->begin(); From gaeke at cs.uiuc.edu Sat May 29 17:51:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 29 17:51:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Message-ID: <200405292250.RAA17616@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/InstrSelection: InstrSelection.cpp updated: 1.74 -> 1.75 --- Log message: Trim whitespace. --- Diffs of the changes: (+0 -11) Index: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp diff -u llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.74 llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.75 --- llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.74 Sat May 29 17:20:59 2004 +++ llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Sat May 29 17:49:51 2004 @@ -84,7 +84,6 @@ }; } - TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi, Value *s1, Value *s2, const std::string &name) : Instruction(s1->getType(), Instruction::UserOp1, name) @@ -146,11 +145,8 @@ } } - // // Build the instruction trees to be given as inputs to BURG. - // InstrForest instrForest(&F); - if (SelectDebugLevel >= Select_DebugInstTrees) { std::cerr << "\n\n*** Input to instruction selection for function " << F.getName() << "\n\n" << F @@ -159,9 +155,7 @@ instrForest.dump(); } - // // Invoke BURG instruction selection for each tree - // for (InstrForest::const_root_iterator RI = instrForest.roots_begin(); RI != instrForest.roots_end(); ++RI) { InstructionNode* basicNode = *RI; @@ -169,7 +163,6 @@ // Invoke BURM to label each tree node with a state burm_label(basicNode); - if (SelectDebugLevel >= Select_DebugBurgTrees) { printcover(basicNode, 1, 0); std::cerr << "\nCover cost == " << treecost(basicNode, 1, 0) <<"\n\n"; @@ -180,11 +173,9 @@ SelectInstructionsForTree(basicNode, /*goalnt*/1); } - // // Create the MachineBasicBlock records and add all of the MachineInstrs // defined in the MachineCodeForInstruction objects to also live in the // MachineBasicBlock objects. - // MachineFunction &MF = MachineFunction::get(&F); for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) { MachineBasicBlock *MCBB = new MachineBasicBlock(BI); @@ -222,11 +213,9 @@ // The leak detector shouldn't track these nodes. They are not garbage, // even though their parent field is never filled in. - // LeakDetector::removeGarbageObject(PhiCpRes); // for each incoming value of the phi, insert phi elimination - // for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { // insert the copy instruction to the predecessor BB std::vector mvec, CpVec; From gaeke at cs.uiuc.edu Sat May 29 18:12:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 29 18:12:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Message-ID: <200405292310.SAA17635@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/InstrSelection: InstrSelection.cpp updated: 1.75 -> 1.76 --- Log message: Add comments. --- Diffs of the changes: (+6 -6) Index: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp diff -u llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.75 llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.76 --- llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.75 Sat May 29 17:49:51 2004 +++ llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Sat May 29 18:10:20 2004 @@ -209,15 +209,15 @@ for (MachineFunction::iterator BB = MF.begin(); BB != MF.end(); ++BB) { for (BasicBlock::const_iterator IIt = BB->getBasicBlock()->begin(); const PHINode *PN = dyn_cast(IIt); ++IIt) { - Value *PhiCpRes = new PHINode(PN->getType(), PN->getName() + ":PhiCp"); - + // Create a new temporary register to hold the result of the Phi copy. // The leak detector shouldn't track these nodes. They are not garbage, // even though their parent field is never filled in. + Value *PhiCpRes = new PHINode(PN->getType(), PN->getName() + ":PhiCp"); LeakDetector::removeGarbageObject(PhiCpRes); - // for each incoming value of the phi, insert phi elimination + // For each of PN's incoming values, insert a copy in the corresponding + // predecessor block. for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { - // insert the copy instruction to the predecessor BB std::vector mvec, CpVec; Target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, mvec); @@ -228,10 +228,10 @@ CpVec2.push_back(*MI); CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end()); } - + // Insert the copy instructions into the predecessor BB. InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); } - + // Insert a copy instruction from PhiCpRes to PN. std::vector mvec; Target.getRegInfo().cpValue2Value(PhiCpRes, const_cast(PN), mvec); From gaeke at cs.uiuc.edu Sat May 29 18:27:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 29 18:27:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/InstrSelection/InstrForest.cpp Message-ID: <200405292326.SAA17954@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/InstrSelection: InstrForest.cpp updated: 1.50 -> 1.51 --- Log message: Remove unused #include. --- Diffs of the changes: (+0 -1) Index: llvm/lib/Target/SparcV9/InstrSelection/InstrForest.cpp diff -u llvm/lib/Target/SparcV9/InstrSelection/InstrForest.cpp:1.50 llvm/lib/Target/SparcV9/InstrSelection/InstrForest.cpp:1.51 --- llvm/lib/Target/SparcV9/InstrSelection/InstrForest.cpp:1.50 Tue Nov 11 16:41:33 2003 +++ llvm/lib/Target/SparcV9/InstrSelection/InstrForest.cpp Sat May 29 18:26:13 2004 @@ -25,7 +25,6 @@ #include "llvm/iMemory.h" #include "llvm/Type.h" #include "llvm/CodeGen/InstrForest.h" -#include "llvm/CodeGen/MachineCodeForInstruction.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/STLExtras.h" #include "Config/alloca.h" From llvm at cs.uiuc.edu Sat May 29 19:12:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Sat May 29 19:12:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/SlotCalculator.cpp Message-ID: <200405300008.TAA11703@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: SlotCalculator.cpp (r1.55) removed --- Log message: Moved this file to lib/Bytecode/Writer because its used there only. --- Diffs of the changes: (+0 -0) From llvm at cs.uiuc.edu Sat May 29 19:13:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Sat May 29 19:13:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Support/SlotTable.cpp Message-ID: <200405300009.TAA11717@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: SlotTable.cpp (r1.3) removed --- Log message: Moved this file to lib/Bytecode/Writer because its used there only. --- Diffs of the changes: (+0 -0) From llvm at cs.uiuc.edu Sat May 29 19:21:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Sat May 29 19:21:01 2004 Subject: [llvm-commits] CVS: llvm/utils/NightlyTest.pl Message-ID: <200405300017.TAA11757@zion.cs.uiuc.edu> Changes in directory llvm/utils: NightlyTest.pl updated: 1.46 -> 1.47 --- Log message: Make the Regression/Feature test support excise all ": PASS" lines that indicate successful tests. We're really only interested in the bad news in this output :) --- Diffs of the changes: (+7 -2) Index: llvm/utils/NightlyTest.pl diff -u llvm/utils/NightlyTest.pl:1.46 llvm/utils/NightlyTest.pl:1.47 --- llvm/utils/NightlyTest.pl:1.46 Fri May 28 15:30:23 2004 +++ llvm/utils/NightlyTest.pl Sat May 29 19:17:47 2004 @@ -180,7 +180,7 @@ if (!$NOCHECKOUT) { if (-d $BuildDir) { if (!$NOREMOVE) { - rmdir $BuildDir or die "Could not remove CVS checkout directory $BuildDir!"; + system "rm -rf $BuildDir"; } else { die "CVS checkout directory $BuildDir already exists!"; } @@ -270,14 +270,19 @@ my $firstline; $/ = "\n"; #Make sure we're going line at a time. if (open SRCHFILE, $filename) { + # Skip stuff before ---TEST RESULTS while ( ) { if ( m/^--- TEST RESULTS/ ) { push(@lines, $_); last; } } + # Process test results while ( ) { if ( length($_) > 1 ) { - if ( ! m/^gmake:/ && ! m/^ qmtest.target:/ && !/^ local/ ) { + if ( ! m/: PASS[ ]*$/ && + ! m/^ qmtest.target:/ && + ! m/^ local/ && + ! m/^gmake:/ ) { push(@lines,$_); } } From llvm at cs.uiuc.edu Sat May 29 20:23:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Sat May 29 20:23:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Message-ID: <200405300119.UAA14920@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: ConstantFolding.cpp updated: 1.57 -> 1.58 --- Log message: Fix a bug that Chris asserts emphatically is a bug. The changed clause would always return false because the Type of a type value is always Type::TypeTY and can never be a floating point type. --- Diffs of the changes: (+1 -1) Index: llvm/lib/VMCore/ConstantFolding.cpp diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.57 llvm/lib/VMCore/ConstantFolding.cpp:1.58 --- llvm/lib/VMCore/ConstantFolding.cpp:1.57 Sat Apr 10 20:29:30 2004 +++ llvm/lib/VMCore/ConstantFolding.cpp Sat May 29 20:19:48 2004 @@ -539,7 +539,7 @@ // Try to not produce a cast of a cast, which is almost always redundant. if (!Op->getType()->isFloatingPoint() && !CE->getType()->isFloatingPoint() && - !DestTy->getType()->isFloatingPoint()) { + !DestTy->isFloatingPoint()) { unsigned S1 = getSize(Op->getType()), S2 = getSize(CE->getType()); unsigned S3 = getSize(DestTy); if (Op->getType() == DestTy && S3 >= S2) From gaeke at cs.uiuc.edu Sat May 29 22:35:04 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 29 22:35:04 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/MachineCodeForInstruction.cpp Message-ID: <200405300333.WAA20630@kain.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: MachineCodeForInstruction.cpp updated: 1.15 -> 1.16 --- Log message: Fix typo in head-of-file comment. --- Diffs of the changes: (+1 -1) Index: llvm/lib/CodeGen/MachineCodeForInstruction.cpp diff -u llvm/lib/CodeGen/MachineCodeForInstruction.cpp:1.15 llvm/lib/CodeGen/MachineCodeForInstruction.cpp:1.16 --- llvm/lib/CodeGen/MachineCodeForInstruction.cpp:1.15 Sun Feb 29 15:40:53 2004 +++ llvm/lib/CodeGen/MachineCodeForInstruction.cpp Sat May 29 22:33:48 2004 @@ -13,7 +13,7 @@ // machine instructions: // // "Temporary values" are intermediate values used in the machine instruction -// sequence, but not in the VM instruction Note that such values should be +// sequence, but not in the VM instruction. Note that such values should be // treated as pure SSA values with no interpretation of their operands (i.e., as // a TmpInstruction object which actually represents such a value). // From gaeke at cs.uiuc.edu Sat May 29 22:36:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 29 22:36:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Message-ID: <200405300333.WAA20637@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/InstrSelection: InstrSelection.cpp updated: 1.76 -> 1.77 --- Log message: Insert machine instructions generated for Phi nodes into their corresponding MachineCodeForInstruction vectors. I need to be able to get the register allocated for the thing which is called PhiCpRes in this code; this should make that task easier, plus, Phi nodes are no longer "special" in the sense that their MachineCodeForInstruction is empty. --- Diffs of the changes: (+3 -0) Index: llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp diff -u llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.76 llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.77 --- llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp:1.76 Sat May 29 18:10:20 2004 +++ llvm/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp Sat May 29 22:33:49 2004 @@ -217,6 +217,7 @@ // For each of PN's incoming values, insert a copy in the corresponding // predecessor block. + MachineCodeForInstruction &MCforPN = MachineCodeForInstruction::get (PN); for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { std::vector mvec, CpVec; Target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, @@ -230,12 +231,14 @@ } // Insert the copy instructions into the predecessor BB. InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); + MCforPN.insert (MCforPN.end (), CpVec.begin (), CpVec.end ()); } // Insert a copy instruction from PhiCpRes to PN. std::vector mvec; Target.getRegInfo().cpValue2Value(PhiCpRes, const_cast(PN), mvec); BB->insert(BB->begin(), mvec.begin(), mvec.end()); + MCforPN.insert (MCforPN.end (), mvec.begin (), mvec.end ()); } // for each Phi Instr in BB } // for all BBs in function } From gaeke at cs.uiuc.edu Sat May 29 23:24:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 29 23:24:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp PhyRegAlloc.h Message-ID: <200405300422.XAA22564@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/RegAlloc: PhyRegAlloc.cpp updated: 1.147 -> 1.148 PhyRegAlloc.h updated: 1.65 -> 1.66 --- Log message: Rename verifySavedState to dumpSavedState. Give it a new comment. Call it at a more appropriate point. --- Diffs of the changes: (+11 -9) Index: llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp diff -u llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp:1.147 llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp:1.148 --- llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp:1.147 Tue Apr 27 10:13:33 2004 +++ llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp Sat May 29 23:22:24 2004 @@ -1180,11 +1180,10 @@ } -/// Check the saved state filled in by saveState(), and abort if it looks -/// wrong. Only used when debugging. FIXME: Currently it just prints out -/// the state, which isn't quite as useful. +/// Dump the saved state filled in by saveState() out to stderr. Only +/// used when debugging. /// -void PhyRegAlloc::verifySavedState () { +void PhyRegAlloc::dumpSavedState () { std::vector &state = FnAllocState[Fn]; int ArgNum = 0; for (Function::const_aiterator i=Fn->abegin (), e=Fn->aend (); i != e; ++i) { @@ -1379,16 +1378,19 @@ // Save register allocation state for this function in a Constant. if (SaveRegAllocState) { saveState(); - if (DEBUG_RA) // Check our work. - verifySavedState (); - if (!SaveStateToModule) - finishSavingState (const_cast (*Fn->getParent ())); } // Now update the machine code with register names and add any additional // code inserted by the register allocator to the instruction stream. updateMachineCode(); + if (SaveRegAllocState) { + if (DEBUG_RA) // Check our work. + dumpSavedState (); + if (!SaveStateToModule) + finishSavingState (const_cast (*Fn->getParent ())); + } + if (DEBUG_RA) { std::cerr << "\n**** Machine Code After Register Allocation:\n\n"; MF->dump(); Index: llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h diff -u llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h:1.65 llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h:1.66 --- llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h:1.65 Fri Apr 23 13:15:47 2004 +++ llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h Sat May 29 23:22:24 2004 @@ -128,7 +128,7 @@ void saveStateForValue (std::vector &state, const Value *V, int Insn, int Opnd); void saveState(); - void verifySavedState(); + void dumpSavedState(); void finishSavingState(Module &M); void setCallInterferences(const MachineInstr *MI, From gaeke at cs.uiuc.edu Sun May 30 02:10:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 02:10:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp Message-ID: <200405300708.CAA25129@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9/RegAlloc: PhyRegAlloc.cpp updated: 1.148 -> 1.149 --- Log message: Reduce the amount of LLVM Values for which we save reg. allocator state. Also, save the state for the incoming register of each phi node. --- Diffs of the changes: (+14 -9) Index: llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp diff -u llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp:1.148 llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp:1.149 --- llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp:1.148 Sat May 29 23:22:24 2004 +++ llvm/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp Sun May 30 02:08:43 2004 @@ -28,6 +28,7 @@ #include "../LiveVar/FunctionLiveVarInfo.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/iPHINode.h" #include "llvm/iOther.h" #include "llvm/Module.h" #include "llvm/Type.h" @@ -1164,18 +1165,22 @@ saveStateForValue (state, Arg, -1, ArgNum); ++ArgNum; } - unsigned Insn = 0; + unsigned InstCount = 0; // Instructions themselves encoded as operand # -1 for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II){ - saveStateForValue (state, (&*II), Insn, -1); - for (unsigned i = 0; i < (*II).getNumOperands (); ++i) { - const Value *V = (*II).getOperand (i); - // Don't worry about it unless it's something whose reg. we'll need. - if (!isa (V) && !isa (V)) - continue; - saveStateForValue (state, V, Insn, i); + const Instruction *Inst = &*II; + saveStateForValue (state, Inst, InstCount, -1); + if (isa (Inst)) { + MachineCodeForInstruction &MCforPN = MachineCodeForInstruction::get(Inst); + // Last instr should be the copy...figure out what reg it is reading from + if (Value *PhiCpRes = MCforPN.back()->getOperand(0).getVRegValueOrNull()){ + if (DEBUG_RA) + std::cerr << "Found Phi copy result: " << PhiCpRes->getName() + << " in: " << *MCforPN.back() << "\n"; + saveStateForValue (state, PhiCpRes, InstCount, -2); + } } - ++Insn; + ++InstCount; } } From alkis at cs.uiuc.edu Sun May 30 02:28:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 30 02:28:02 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/RegAllocLinearScan.cpp LiveIntervals.h LiveIntervals.cpp Message-ID: <200405300724.CAA25474@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: RegAllocLinearScan.cpp updated: 1.72 -> 1.73 LiveIntervals.h updated: 1.24 -> 1.25 LiveIntervals.cpp updated: 1.74 -> 1.75 --- Log message: When spilling an register, introduce a new temporary for each of its spills. This allows for more flexibility when allocating registers for spill code. --- Diffs of the changes: (+83 -56) Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.72 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.73 --- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.72 Fri May 7 22:50:03 2004 +++ llvm/lib/CodeGen/RegAllocLinearScan.cpp Sun May 30 02:24:39 2004 @@ -27,6 +27,7 @@ #include #include #include +#include using namespace llvm; @@ -366,24 +367,26 @@ DEBUG(std::cerr << "\t\tregister with min weight: " << mri_->getName(minReg) << " (" << minWeight << ")\n"); - // if the current has the minimum weight, we need to modify it, - // push it back in unhandled and let the linear scan algorithm run - // again + // if the current has the minimum weight, we need to spill it and + // add any added intervals back to unhandled, and restart + // linearscan. if (cur->weight <= minWeight) { DEBUG(std::cerr << "\t\t\tspilling(c): " << *cur << '\n';); int slot = vrm_->assignVirt2StackSlot(cur->reg); - li_->updateSpilledInterval(*cur, *vrm_, slot); + std::vector added = + li_->addIntervalsForSpills(*cur, *vrm_, slot); - // if we didn't eliminate the interval find where to add it - // back to unhandled. We need to scan since unhandled are - // sorted on earliest start point and we may have changed our - // start point. - if (!cur->empty()) { - IntervalPtrs::iterator it = unhandled_.begin(); - while (it != unhandled_.end() && (*it)->start() < cur->start()) - ++it; - unhandled_.insert(it, cur); + // merge added with unhandled + std::vector::iterator addedIt = added.begin(); + std::vector::iterator addedItEnd = added.end(); + for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end(); + i != e && addedIt != addedItEnd; ++i) { + if ((*i)->start() > (*addedIt)->start()) + i = unhandled_.insert(i, *(addedIt++)); } + while (addedIt != addedItEnd) + unhandled_.push_back(*(addedIt++)); + return; } @@ -395,6 +398,7 @@ // otherwise we spill all intervals aliasing the register with // minimum weight, rollback to the interval with the earliest // start point and let the linear scan algorithm run again + std::vector added; assert(MRegisterInfo::isPhysicalRegister(minReg) && "did not choose a register to spill?"); std::vector toSpill(mri_->getNumRegs(), false); @@ -403,6 +407,8 @@ toSpill[*as] = true; unsigned earliestStart = cur->start(); + std::set spilled; + for (IntervalPtrs::iterator i = active_.begin(); i != active_.end(); ++i) { unsigned reg = (*i)->reg; if (MRegisterInfo::isVirtualRegister(reg) && @@ -411,7 +417,10 @@ DEBUG(std::cerr << "\t\t\tspilling(a): " << **i << '\n'); earliestStart = std::min(earliestStart, (*i)->start()); int slot = vrm_->assignVirt2StackSlot((*i)->reg); - li_->updateSpilledInterval(**i, *vrm_, slot); + std::vector newIs = + li_->addIntervalsForSpills(**i, *vrm_, slot); + std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); + spilled.insert(reg); } } for (IntervalPtrs::iterator i = inactive_.begin(); @@ -423,7 +432,10 @@ DEBUG(std::cerr << "\t\t\tspilling(i): " << **i << '\n'); earliestStart = std::min(earliestStart, (*i)->start()); int slot = vrm_->assignVirt2StackSlot((*i)->reg); - li_->updateSpilledInterval(**i, *vrm_, slot); + std::vector newIs = + li_->addIntervalsForSpills(**i, *vrm_, slot); + std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); + spilled.insert(reg); } } @@ -433,7 +445,7 @@ while (!handled_.empty()) { IntervalPtrs::value_type i = handled_.back(); // if this interval starts before t we are done - if (!i->empty() && i->start() < earliestStart) + if (i->start() < earliestStart) break; DEBUG(std::cerr << "\t\t\tundo changes for: " << *i << '\n'); handled_.pop_back(); @@ -445,20 +457,10 @@ unhandled_.push_front(i); } else { + if (!spilled.count(i->reg)) + unhandled_.push_front(i); prt_->delRegUse(vrm_->getPhys(i->reg)); vrm_->clearVirt(i->reg); - if (i->spilled()) { - if (!i->empty()) { - IntervalPtrs::iterator it = unhandled_.begin(); - while (it != unhandled_.end() && - (*it)->start() < i->start()) - ++it; - unhandled_.insert(it, i); - } - } - else - unhandled_.push_front(i); - } } else if ((it = find(inactive_.begin(), inactive_.end(), i)) != inactive_.end()) { @@ -466,18 +468,9 @@ if (MRegisterInfo::isPhysicalRegister(i->reg)) unhandled_.push_front(i); else { - vrm_->clearVirt(i->reg); - if (i->spilled()) { - if (!i->empty()) { - IntervalPtrs::iterator it = unhandled_.begin(); - while (it != unhandled_.end() && - (*it)->start() < i->start()) - ++it; - unhandled_.insert(it, i); - } - } - else + if (!spilled.count(i->reg)) unhandled_.push_front(i); + vrm_->clearVirt(i->reg); } } else { @@ -501,6 +494,19 @@ prt_->addRegUse(vrm_->getPhys((*i)->reg)); } } + + std::sort(added.begin(), added.end(), LiveIntervals::StartPointPtrComp()); + // merge added with unhandled + std::vector::iterator addedIt = added.begin(); + std::vector::iterator addedItEnd = added.end(); + for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end(); + i != e && addedIt != addedItEnd; ++i) { + if ((*i)->start() > (*addedIt)->start()) + i = unhandled_.insert(i, *(addedIt++)); + } + while (addedIt != addedItEnd) + unhandled_.push_back(*(addedIt++)); + } unsigned RA::getFreePhysReg(IntervalPtrs::value_type cur) Index: llvm/lib/CodeGen/LiveIntervals.h diff -u llvm/lib/CodeGen/LiveIntervals.h:1.24 llvm/lib/CodeGen/LiveIntervals.h:1.25 --- llvm/lib/CodeGen/LiveIntervals.h:1.24 Sat May 29 11:18:57 2004 +++ llvm/lib/CodeGen/LiveIntervals.h Sun May 30 02:24:39 2004 @@ -80,9 +80,9 @@ } }; - struct EndPointComp { - bool operator()(const Interval& lhs, const Interval& rhs) { - return lhs.ranges.back().second < rhs.ranges.back().second; + struct StartPointPtrComp { + bool operator()(const Interval* lhs, const Interval* rhs) { + return lhs->ranges.front().first < rhs->ranges.front().first; } }; @@ -164,7 +164,9 @@ Intervals& getIntervals() { return intervals_; } - void updateSpilledInterval(Interval& i, VirtRegMap& vrm, int slot); + std::vector addIntervalsForSpills(const Interval& i, + VirtRegMap& vrm, + int slot); private: /// computeIntervals - compute live intervals Index: llvm/lib/CodeGen/LiveIntervals.cpp diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.74 llvm/lib/CodeGen/LiveIntervals.cpp:1.75 --- llvm/lib/CodeGen/LiveIntervals.cpp:1.74 Sat May 29 11:18:57 2004 +++ llvm/lib/CodeGen/LiveIntervals.cpp Sun May 30 02:24:39 2004 @@ -186,19 +186,23 @@ return true; } -void LiveIntervals::updateSpilledInterval(Interval& li, - VirtRegMap& vrm, - int slot) +std::vector +LiveIntervals::addIntervalsForSpills(const Interval& li, + VirtRegMap& vrm, + int slot) { + std::vector added; + assert(li.weight != HUGE_VAL && "attempt to spill already spilled interval!"); - Interval::Ranges oldRanges; - swap(oldRanges, li.ranges); - DEBUG(std::cerr << "\t\t\t\tupdating interval: " << li); + DEBUG(std::cerr << "\t\t\t\tadding intervals for spills for interval: " + << li << '\n'); + + const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(li.reg); - for (Interval::Ranges::iterator i = oldRanges.begin(), e = oldRanges.end(); - i != e; ++i) { + for (Interval::Ranges::const_iterator + i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) { unsigned index = getBaseIndex(i->first); unsigned end = getBaseIndex(i->second-1) + InstrSlots::NUM; for (; index < end; index += InstrSlots::NUM) { @@ -240,16 +244,31 @@ unsigned end = 1 + (mop.isDef() ? getUseIndex(index+InstrSlots::NUM) : getUseIndex(index)); - li.addRange(start, end); + + // create a new register for this spill + unsigned nReg = + mf_->getSSARegMap()->createVirtualRegister(rc); + mi->SetMachineOperandReg(i, nReg); + vrm.grow(); + vrm.assignVirt2StackSlot(nReg, slot); + Interval& nI = getOrCreateInterval(nReg); + assert(nI.empty()); + // the spill weight is now infinity as it + // cannot be spilled again + nI.weight = HUGE_VAL; + nI.addRange(start, end); + added.push_back(&nI); + // update live variables + lv_->addVirtualRegisterKilled(nReg, mi->getParent(),mi); + DEBUG(std::cerr << "\t\t\t\tadded new interval: " + << nI << '\n'); } } } } } - // the new spill weight is now infinity as it cannot be spilled again - li.weight = HUGE_VAL; - DEBUG(std::cerr << '\n'); - DEBUG(std::cerr << "\t\t\t\tupdated interval: " << li << '\n'); + + return added; } void LiveIntervals::printRegName(unsigned reg) const From gaeke at cs.uiuc.edu Sun May 30 02:35:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 02:35:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9InstrInfo.cpp Message-ID: <200405300734.CAA27609@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9InstrInfo.cpp updated: 1.63 -> 1.64 --- Log message: Transform an occurrence of if(...) { assert (0) }. --- Diffs of the changes: (+2 -4) Index: llvm/lib/Target/SparcV9/SparcV9InstrInfo.cpp diff -u llvm/lib/Target/SparcV9/SparcV9InstrInfo.cpp:1.63 llvm/lib/Target/SparcV9/SparcV9InstrInfo.cpp:1.64 --- llvm/lib/Target/SparcV9/SparcV9InstrInfo.cpp:1.63 Sun Apr 25 02:04:49 2004 +++ llvm/lib/Target/SparcV9/SparcV9InstrInfo.cpp Sun May 30 02:34:01 2004 @@ -676,10 +676,8 @@ const Type* resultType = dest->getType(); MachineOpCode opCode = ChooseAddInstructionByType(resultType); - if (opCode == V9::INVALID_OPCODE) { - assert(0 && "Unsupported result type in CreateCopyInstructionsByType()"); - return; - } + assert (opCode != V9::INVALID_OPCODE + && "Unsupported result type in CreateCopyInstructionsByType()"); // if `src' is a constant that doesn't fit in the immed field or if it is // a global variable (i.e., a constant address), generate a load From alkis at cs.uiuc.edu Sun May 30 02:49:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 30 02:49:01 2004 Subject: [llvm-commits] CVS: llvm/include/Support/STLExtras.h Message-ID: <200405300745.CAA25565@zion.cs.uiuc.edu> Changes in directory llvm/include/Support: STLExtras.h updated: 1.15 -> 1.16 --- Log message: Add comparator useful for natural comparisons on collections with pointers to objects. --- Diffs of the changes: (+6 -0) Index: llvm/include/Support/STLExtras.h diff -u llvm/include/Support/STLExtras.h:1.15 llvm/include/Support/STLExtras.h:1.16 --- llvm/include/Support/STLExtras.h:1.15 Mon Feb 23 21:47:25 2004 +++ llvm/include/Support/STLExtras.h Sun May 30 02:45:09 2004 @@ -53,6 +53,12 @@ } }; +template +struct less_ptr : public std::binary_function { + bool operator()(const Ty* left, const Ty* right) const { + return *left < *right; + } +}; // deleter - Very very very simple method that is used to invoke operator // delete on something. It is used like this: From alkis at cs.uiuc.edu Sun May 30 02:50:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 30 02:50:02 2004 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/RegAllocLinearScan.cpp LiveIntervals.h LiveIntervals.cpp Message-ID: <200405300746.CAA25629@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: RegAllocLinearScan.cpp updated: 1.73 -> 1.74 LiveIntervals.h updated: 1.25 -> 1.26 LiveIntervals.cpp updated: 1.75 -> 1.76 --- Log message: Pull Interval class out of LiveIntervals. --- Diffs of the changes: (+67 -80) Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.73 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.74 --- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.73 Sun May 30 02:24:39 2004 +++ llvm/lib/CodeGen/RegAllocLinearScan.cpp Sun May 30 02:46:27 2004 @@ -21,6 +21,7 @@ #include "llvm/Target/MRegisterInfo.h" #include "llvm/Target/TargetMachine.h" #include "Support/Debug.h" +#include "Support/STLExtras.h" #include "LiveIntervals.h" #include "PhysRegTracker.h" #include "VirtRegMap.h" @@ -38,7 +39,7 @@ const TargetMachine* tm_; const MRegisterInfo* mri_; LiveIntervals* li_; - typedef std::list IntervalPtrs; + typedef std::list IntervalPtrs; IntervalPtrs unhandled_, fixed_, active_, inactive_, handled_; std::auto_ptr prt_; @@ -122,7 +123,7 @@ // if (MRegisterInfo::isVirtualRegister(i->second) && // (i->second == i2->second || // mri_->areAliases(i->second, i2->second))) { -// const LiveIntervals::Interval +// const Interval // &in = li_->getInterval(i->second), // &in2 = li_->getInterval(i2->second); // if (in.overlaps(in2)) { @@ -373,12 +374,12 @@ if (cur->weight <= minWeight) { DEBUG(std::cerr << "\t\t\tspilling(c): " << *cur << '\n';); int slot = vrm_->assignVirt2StackSlot(cur->reg); - std::vector added = + std::vector added = li_->addIntervalsForSpills(*cur, *vrm_, slot); // merge added with unhandled - std::vector::iterator addedIt = added.begin(); - std::vector::iterator addedItEnd = added.end(); + std::vector::iterator addedIt = added.begin(); + std::vector::iterator addedItEnd = added.end(); for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end(); i != e && addedIt != addedItEnd; ++i) { if ((*i)->start() > (*addedIt)->start()) @@ -398,7 +399,7 @@ // otherwise we spill all intervals aliasing the register with // minimum weight, rollback to the interval with the earliest // start point and let the linear scan algorithm run again - std::vector added; + std::vector added; assert(MRegisterInfo::isPhysicalRegister(minReg) && "did not choose a register to spill?"); std::vector toSpill(mri_->getNumRegs(), false); @@ -417,7 +418,7 @@ DEBUG(std::cerr << "\t\t\tspilling(a): " << **i << '\n'); earliestStart = std::min(earliestStart, (*i)->start()); int slot = vrm_->assignVirt2StackSlot((*i)->reg); - std::vector newIs = + std::vector newIs = li_->addIntervalsForSpills(**i, *vrm_, slot); std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); spilled.insert(reg); @@ -432,7 +433,7 @@ DEBUG(std::cerr << "\t\t\tspilling(i): " << **i << '\n'); earliestStart = std::min(earliestStart, (*i)->start()); int slot = vrm_->assignVirt2StackSlot((*i)->reg); - std::vector newIs = + std::vector newIs = li_->addIntervalsForSpills(**i, *vrm_, slot); std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); spilled.insert(reg); @@ -495,10 +496,10 @@ } } - std::sort(added.begin(), added.end(), LiveIntervals::StartPointPtrComp()); + std::sort(added.begin(), added.end(), less_ptr()); // merge added with unhandled - std::vector::iterator addedIt = added.begin(); - std::vector::iterator addedItEnd = added.end(); + std::vector::iterator addedIt = added.begin(); + std::vector::iterator addedItEnd = added.end(); for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end(); i != e && addedIt != addedItEnd; ++i) { if ((*i)->start() > (*addedIt)->start()) Index: llvm/lib/CodeGen/LiveIntervals.h diff -u llvm/lib/CodeGen/LiveIntervals.h:1.25 llvm/lib/CodeGen/LiveIntervals.h:1.26 --- llvm/lib/CodeGen/LiveIntervals.h:1.25 Sun May 30 02:24:39 2004 +++ llvm/lib/CodeGen/LiveIntervals.h Sun May 30 02:46:27 2004 @@ -30,62 +30,60 @@ class MRegisterInfo; class VirtRegMap; - class LiveIntervals : public MachineFunctionPass - { - public: - struct Interval { - typedef std::pair Range; - typedef std::vector Ranges; - unsigned reg; // the register of this interval - float weight; // weight of this interval (number of uses - // * 10^loopDepth) - Ranges ranges; // the ranges in which this register is live - Interval(unsigned r); + struct Interval { + typedef std::pair Range; + typedef std::vector Ranges; + unsigned reg; // the register of this interval + float weight; // weight of this interval: + // (number of uses *10^loopDepth) + Ranges ranges; // the ranges in which this register is live - bool empty() const { return ranges.empty(); } + explicit Interval(unsigned r); - bool spilled() const; + bool empty() const { return ranges.empty(); } - unsigned start() const { - assert(!empty() && "empty interval for register"); - return ranges.front().first; - } + bool spilled() const; - unsigned end() const { - assert(!empty() && "empty interval for register"); - return ranges.back().second; - } + unsigned start() const { + assert(!empty() && "empty interval for register"); + return ranges.front().first; + } - bool expiredAt(unsigned index) const { - return end() <= (index + 1); - } + unsigned end() const { + assert(!empty() && "empty interval for register"); + return ranges.back().second; + } - bool liveAt(unsigned index) const; + bool expiredAt(unsigned index) const { + return end() <= (index + 1); + } - bool overlaps(const Interval& other) const; + bool liveAt(unsigned index) const; - void addRange(unsigned start, unsigned end); + bool overlaps(const Interval& other) const; - void join(const Interval& other); + void addRange(unsigned start, unsigned end); - private: - Ranges::iterator mergeRangesForward(Ranges::iterator it); + void join(const Interval& other); - Ranges::iterator mergeRangesBackward(Ranges::iterator it); - }; + bool operator<(const Interval& other) const { + return start() < other.start(); + } - struct StartPointComp { - bool operator()(const Interval& lhs, const Interval& rhs) { - return lhs.ranges.front().first < rhs.ranges.front().first; - } - }; + bool operator==(const Interval& other) const { + return reg == other.reg; + } - struct StartPointPtrComp { - bool operator()(const Interval* lhs, const Interval* rhs) { - return lhs->ranges.front().first < rhs->ranges.front().first; - } - }; + private: + Ranges::iterator mergeRangesForward(Ranges::iterator it); + Ranges::iterator mergeRangesBackward(Ranges::iterator it); + }; + std::ostream& operator<<(std::ostream& os, const Interval& li); + + class LiveIntervals : public MachineFunctionPass + { + public: typedef std::list Intervals; private: @@ -205,14 +203,6 @@ void printRegName(unsigned reg) const; }; - inline bool operator==(const LiveIntervals::Interval& lhs, - const LiveIntervals::Interval& rhs) { - return lhs.reg == rhs.reg; - } - - std::ostream& operator<<(std::ostream& os, - const LiveIntervals::Interval& li); - } // End llvm namespace #endif Index: llvm/lib/CodeGen/LiveIntervals.cpp diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.75 llvm/lib/CodeGen/LiveIntervals.cpp:1.76 --- llvm/lib/CodeGen/LiveIntervals.cpp:1.75 Sun May 30 02:24:39 2004 +++ llvm/lib/CodeGen/LiveIntervals.cpp Sun May 30 02:46:27 2004 @@ -167,7 +167,7 @@ } } - intervals_.sort(StartPointComp()); + intervals_.sort(); DEBUG(std::cerr << "********** INTERVALS **********\n"); DEBUG(std::copy(intervals_.begin(), intervals_.end(), std::ostream_iterator(std::cerr, "\n"))); @@ -186,10 +186,9 @@ return true; } -std::vector -LiveIntervals::addIntervalsForSpills(const Interval& li, - VirtRegMap& vrm, - int slot) +std::vector LiveIntervals::addIntervalsForSpills(const Interval& li, + VirtRegMap& vrm, + int slot) { std::vector added; @@ -554,7 +553,7 @@ return false; } -LiveIntervals::Interval& LiveIntervals::getOrCreateInterval(unsigned reg) +Interval& LiveIntervals::getOrCreateInterval(unsigned reg) { Reg2IntervalMap::iterator r2iit = r2iMap_.lower_bound(reg); if (r2iit == r2iMap_.end() || r2iit->first != reg) { @@ -565,13 +564,13 @@ return *r2iit->second; } -LiveIntervals::Interval::Interval(unsigned r) +Interval::Interval(unsigned r) : reg(r), weight((MRegisterInfo::isPhysicalRegister(r) ? HUGE_VAL : 0.0F)) { } -bool LiveIntervals::Interval::spilled() const +bool Interval::spilled() const { return (weight == HUGE_VAL && MRegisterInfo::isVirtualRegister(reg)); @@ -584,7 +583,7 @@ // definition of the variable it represents. This is because slot 1 is // used (def slot) and spans up to slot 3 (store slot). // -bool LiveIntervals::Interval::liveAt(unsigned index) const +bool Interval::liveAt(unsigned index) const { Range dummy(index, index+1); Ranges::const_iterator r = std::upper_bound(ranges.begin(), @@ -611,7 +610,7 @@ // // A->overlaps(C) should return false since we want to be able to join // A and C. -bool LiveIntervals::Interval::overlaps(const Interval& other) const +bool Interval::overlaps(const Interval& other) const { Ranges::const_iterator i = ranges.begin(); Ranges::const_iterator ie = ranges.end(); @@ -649,7 +648,7 @@ return false; } -void LiveIntervals::Interval::addRange(unsigned start, unsigned end) +void Interval::addRange(unsigned start, unsigned end) { assert(start < end && "Invalid range to add!"); DEBUG(std::cerr << " +[" << start << ',' << end << ")"); @@ -663,7 +662,7 @@ it = mergeRangesBackward(it); } -void LiveIntervals::Interval::join(const LiveIntervals::Interval& other) +void Interval::join(const Interval& other) { DEBUG(std::cerr << "\t\tjoining " << *this << " with " << other << '\n'); Ranges::iterator cur = ranges.begin(); @@ -678,8 +677,7 @@ ++numJoins; } -LiveIntervals::Interval::Ranges::iterator -LiveIntervals::Interval::mergeRangesForward(Ranges::iterator it) +Interval::Ranges::iterator Interval::mergeRangesForward(Ranges::iterator it) { Ranges::iterator n; while ((n = next(it)) != ranges.end()) { @@ -691,8 +689,7 @@ return it; } -LiveIntervals::Interval::Ranges::iterator -LiveIntervals::Interval::mergeRangesBackward(Ranges::iterator it) +Interval::Ranges::iterator Interval::mergeRangesBackward(Ranges::iterator it) { while (it != ranges.begin()) { Ranges::iterator p = prior(it); @@ -707,15 +704,14 @@ return it; } -std::ostream& llvm::operator<<(std::ostream& os, - const LiveIntervals::Interval& li) +std::ostream& llvm::operator<<(std::ostream& os, const Interval& li) { os << "%reg" << li.reg << ',' << li.weight; if (li.empty()) return os << "EMPTY"; os << " = "; - for (LiveIntervals::Interval::Ranges::const_iterator + for (Interval::Ranges::const_iterator i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) { os << "[" << i->first << "," << i->second << ")"; } From gaeke at cs.uiuc.edu Sun May 30 03:31:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 03:31:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9InstrInfo.h Message-ID: <200405300829.DAA15952@kain.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9InstrInfo.h updated: 1.6 -> 1.7 --- Log message: There is no "mcff" here; delete the confusing comments that refer to it. --- Diffs of the changes: (+0 -6) Index: llvm/lib/Target/SparcV9/SparcV9InstrInfo.h diff -u llvm/lib/Target/SparcV9/SparcV9InstrInfo.h:1.6 llvm/lib/Target/SparcV9/SparcV9InstrInfo.h:1.7 --- llvm/lib/Target/SparcV9/SparcV9InstrInfo.h:1.6 Sun Apr 25 02:04:49 2004 +++ llvm/lib/Target/SparcV9/SparcV9InstrInfo.h Sun May 30 03:29:16 2004 @@ -103,7 +103,6 @@ // GlobalValue, viz., the constant address of a global variable or function. // The generated instructions are returned in `mvec'. // Any temp. registers (TmpInstruction) created are recorded in mcfi. - // Any stack space required is allocated via mcff. // virtual void CreateCodeToLoadConst(const TargetMachine& target, Function* F, @@ -117,7 +116,6 @@ // val must be an integral type. dest must be a Float or Double. // The generated instructions are returned in `mvec'. // Any temp. registers (TmpInstruction) created are recorded in mcfi. - // Any stack space required is allocated via mcff. // virtual void CreateCodeToCopyIntToFloat(const TargetMachine& target, Function* F, @@ -130,7 +128,6 @@ // `val' to an integer value `dest' by copying to memory and back. // The generated instructions are returned in `mvec'. // Any temp. registers (TmpInstruction) created are recorded in mcfi. - // Any stack space required is allocated via mcff. // virtual void CreateCodeToCopyFloatToInt(const TargetMachine& target, Function* F, @@ -142,7 +139,6 @@ // Create instruction(s) to copy src to dest, for arbitrary types // The generated instructions are returned in `mvec'. // Any temp. registers (TmpInstruction) created are recorded in mcfi. - // Any stack space required is allocated via mcff. // virtual void CreateCopyInstructionsByType(const TargetMachine& target, Function* F, @@ -155,7 +151,6 @@ // from an arbitrary sized value (sized in bits, not bytes). // The generated instructions are appended to `mvec'. // Any temp. registers (TmpInstruction) created are recorded in mcfi. - // Any stack space required is allocated via mcff. // virtual void CreateSignExtensionInstructions(const TargetMachine& target, Function* F, @@ -169,7 +164,6 @@ // from an arbitrary sized value (sized in bits, not bytes). // The generated instructions are appended to `mvec'. // Any temp. registers (TmpInstruction) created are recorded in mcfi. - // Any stack space required is allocated via mcff. // virtual void CreateZeroExtensionInstructions(const TargetMachine& target, Function* F, From gaeke at cs.uiuc.edu Sun May 30 03:45:06 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 03:45:06 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405300843.DAA16878@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.73 -> 1.74 --- Log message: Bunch of simple clean-ups... Fold insertBranchMachineInstrs() into its only call-site. Move def of getValueAllocState below its helper functions. Remove forward decls of its helper functions. Untabify portions of getValueAllocStateFromModule(). Fix an incorrect comment in getValueAllocStateFromGlobal(). Add forward decl of getValueAllocState() just before rewriteProlog(). Remove unnecessary parens from stackOffsetForReg(). Use three-operand form of BuildMI(MBB,...) instead of MBB.push_back(BuildMI(...)). --- Diffs of the changes: (+35 -52) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.73 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.74 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.73 Wed May 26 04:43:49 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 30 03:43:11 2004 @@ -114,25 +114,6 @@ B.push_back (*i); } -/// Append to B a branch from the end of B to TargetAddr. -/// -void UnpackTraceFunction::insertBranchMachineInstrs (uint64_t Target, - MachineBasicBlock &B) { - // If the target is close enough to fit into the 19-bit disp of a "ba" - // instruction, then we really DO get a "ba" instruction. We get the backend - // to calculate the PC-relative address from the absolute address upon - // emitting it to memory, by handing it a Constant and telling the backend - // it's a PC-relative MachineOperand. If the target is NOT close enough to - // fit in a "ba" instruction, the SparcV9CodeEmitter will automatically turn - // it into an indirect jump through a register. - - // ba - Constant *TargetAsConstant = (ConstantUInt::get (Type::ULongTy, Target)); - B.push_back (BuildMI (V9::BA, 1).addPCDisp (TargetAsConstant)); - // nop - B.push_back (BuildMI (V9::NOP, 0)); -} - /// Returns a pointer to the return instruction in B, if B contains /// one, or null otherwise. /// @@ -147,9 +128,6 @@ return 0; } -static AllocInfo getValueAllocStateFromModule (Function *F, Value *V); -static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V); - /// Fill in the set of registers used in this function, which is kept in /// 'RegsToRestore' in the UnpackTraceFunction Pass object, and is used by /// rewriteProlog() and rewriteEpilog(). Registers are @@ -200,20 +178,14 @@ std::cerr << " )\n"); } -/// getValueAllocState - Returns a pair containing the -/// saved register allocator state for a value. -/// -static std::pair -getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true) { - return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V), - getValueAllocStateFromGlobal (TF->TraceFn, - TF->getCorrespondingValue (V, preferLiveIn))); -} unsigned UnpackTraceFunction::stackOffsetForReg (unsigned R) { - return (2047 + StaticStackSize + 176 + (R) * 8); + return 2047 + StaticStackSize + 176 + R * 8; } +static std::pair +getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true); + void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) { const TargetRegInfo &TRI = TM->getRegInfo (); @@ -226,12 +198,12 @@ E.clear (); // 0. Save caller's stack pointer in %g1. - E.push_back (BuildMI (V9::ORr, 3).addMReg (sp).addZImm (0).addMReg (g1, - MachineOperand::Def)); + BuildMI (&E, V9::ORr, 3).addMReg (sp).addZImm (0) + .addMReg (g1, MachineOperand::Def); // 1. Emit ADD instruction to allocate the right amount of stack space. - E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize) - .addMReg (sp, MachineOperand::Def)); + BuildMI (&E, V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize) + .addMReg (sp, MachineOperand::Def); // 2. Get the saved register allocator state for all live-in variables. // We are going to need to save live-in values which reside in registers @@ -280,8 +252,8 @@ } // Caller's stack pointer becomes our frame pointer. - E.push_back (BuildMI (V9::ORr, 3).addMReg (g1).addZImm (0).addMReg (fp, - MachineOperand::Def)); + BuildMI (&E, V9::ORr, 3).addMReg (g1).addZImm (0) + .addMReg (fp, MachineOperand::Def); // 4. Insert a copy for each live-in variable to copy it from the stack // to the register that was allocated for it in the TraceFn. @@ -392,16 +364,15 @@ // _llvm_regAllocState.functions[FI] for a tuple that starts with // (InstructionKey, OperandKey, ...): for (unsigned i = 0; i < FAllocState->numTuples; ++i) { - OperandAllocState &T = FAllocState->tuples[i]; - if (T.Instruction == InstructionKey && T.Operand == OperandKey) { - AllocInfo AI (T.Instruction, T.Operand, - (AllocInfo::AllocStateTy) T.AllocState, T.Placement); - DEBUG (std::cerr << "Alloc state saved in module for " - << F->getName () << ":" << V->getName () << " (key = " - << InstructionKey << "," << OperandKey << ") is " << AI - << "\n"); - return AI; - } + OperandAllocState &T = FAllocState->tuples[i]; + if (T.Instruction == InstructionKey && T.Operand == OperandKey) { + AllocInfo AI (T.Instruction, T.Operand, + (AllocInfo::AllocStateTy) T.AllocState, T.Placement); + DEBUG (std::cerr << "Alloc state saved in module for " << F->getName () + << ":" << V->getName () << " (key = " << InstructionKey << "," + << OperandKey << ") is " << AI << "\n"); + return AI; + } } // By this time we had better have found it, otherwise we are about to do bad // things. @@ -431,7 +402,7 @@ abort (); } // Figure out the indices (VI, VO) that can be used to look up V, - // which is an operand of some instruction in F, in FState: + // which is some instruction producing a value in F, in FState: Instruction *Instr = cast (V); InstructionKey = getSavedStateIndexOfInstruction (F, Instr); } @@ -454,6 +425,16 @@ abort (); } +/// getValueAllocState - Returns a pair containing the +/// saved register allocator state for a value. +/// +static std::pair +getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn) { + return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V), + getValueAllocStateFromGlobal (TF->TraceFn, + TF->getCorrespondingValue (V, preferLiveIn))); +} + void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB) { const TargetRegInfo &TRI = TM->getRegInfo (); @@ -518,8 +499,8 @@ } // Restore stack pointer. - MBB.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (TotalStackSize) - .addMReg (sp, MachineOperand::Def)); + BuildMI (&MBB, V9::ADDi, 3).addMReg (sp).addSImm (TotalStackSize) + .addMReg (sp, MachineOperand::Def); // Let ReturnAddress be the address in memory of the compiled // code for the MachineBasicBlock in MatrixF that RI would have @@ -537,7 +518,9 @@ << " 0x" << std::hex << BlockAddrs.first << ", end of block = 0x" << BlockAddrs.second << std::dec << "\n"); // Insert a branch back to the return BasicBlock of the matrix fn. - insertBranchMachineInstrs (ReturnAddress, MBB); + BuildMI (&MBB, V9::BA, 1) + .addPCDisp (ConstantUInt::get (Type::ULongTy, ReturnAddress)); + BuildMI (&MBB, V9::NOP, 0); } /// runOnMachineFunction - Prepare MF, which is the machine code for From gaeke at cs.uiuc.edu Sun May 30 03:48:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 03:48:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405300847.DAA17132@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.74 -> 1.75 --- Log message: Remove insertCopyMachineInstrs(), which is no longer called. Something like it will be needed in the future, but this is just not quite how it will need to be implemented, and in the meantime, we go for simplicity. --- Diffs of the changes: (+0 -52) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.74 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.75 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.74 Sun May 30 03:43:11 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 30 03:47:11 2004 @@ -64,56 +64,6 @@ return staticStackSize; } -/// Insert the appropriate machine instruction(s) that copies the value in -/// Source to the location specified by Target, at the beginning of B. -/// -void UnpackTraceFunction::insertCopyMachineInstrs (AllocInfo &Source, - AllocInfo &Target, - MachineBasicBlock &B, - const Type *Ty) { - const TargetRegInfo &TRI = TM->getRegInfo (); - std::vector mvec; - int RegType; - // Guess what kind of reg the register was allocated to. - if (Ty == Type::FloatTy) - RegType = SparcV9RegInfo::FPSingleRegType; - else if (Ty == Type::DoubleTy) - RegType = SparcV9RegInfo::FPDoubleRegType; - else - RegType = SparcV9RegInfo::IntRegType; - const unsigned FramePtrReg = TRI.getFramePointer (); - const unsigned StackPtrReg = TRI.getStackPointer (); - if (Source.AllocState == AllocInfo::Spilled - && Target.AllocState == AllocInfo::Allocated) { - // Emit load instruction from stack loc. Source into register Target - TRI.cpMem2RegMI (mvec, FramePtrReg, Source.Placement, Target.Placement, - RegType); - } else if (Source.AllocState == AllocInfo::Allocated - && Target.AllocState == AllocInfo::Allocated) { - // Emit move instruction from register Source to register Target - TRI.cpReg2RegMI (mvec, Source.Placement, Target.Placement, RegType); - } else if (Source.AllocState == AllocInfo::Allocated - && Target.AllocState == AllocInfo::Spilled) { - // Emit store instruction from register Source to stack loc. Target - TRI.cpReg2MemMI (mvec, Source.Placement, FramePtrReg, Target.Placement, - RegType); - } else if (Source.AllocState == AllocInfo::Spilled - && Target.AllocState == AllocInfo::Spilled) { - const unsigned TempReg = - TRI.getUnifiedRegNum (SparcV9RegInfo::IntRegClassID, - SparcV9IntRegClass::g1); // just pick one? - // Emit load instruction from stack loc. Source into register TempReg - TRI.cpMem2RegMI (mvec, FramePtrReg, Source.Placement, TempReg, RegType); - // Emit store instruction from register TempReg to stack loc. Target - TRI.cpReg2MemMI (mvec, TempReg, FramePtrReg, Target.Placement, RegType); - } - // Add whatever the TargetRegInfo gave us to the MachineBasicBlock we are - // working on. - for (std::vector::iterator i = mvec.begin (), - e = mvec.end (); i != e; ++i) - B.push_back (*i); -} - /// Returns a pointer to the return instruction in B, if B contains /// one, or null otherwise. /// @@ -264,8 +214,6 @@ AllocInfo &Source = ai.first, &Target = ai.second; assert (Target.AllocState == AllocInfo::Allocated && "FIXME: can't do mem-->mem copy of live-ins yet"); - // FIXME: The following should really be using insertCopyMachineInstrs or - // something like it. mvec.clear (); assert (TRI.getRegType (Target.Placement) == TRI.getRegType (Source.Placement) From gaeke at cs.uiuc.edu Sun May 30 04:03:05 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 04:03:05 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/ValueAllocState.cpp UnpackTraceFunction.cpp Message-ID: <200405300901.EAA18119@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: ValueAllocState.cpp added (r1.1) UnpackTraceFunction.cpp updated: 1.75 -> 1.76 --- Log message: Move getValueAllocState and all its helper functions and private data structures to ValueAllocState.cpp, a new file. Capitalize its name and make it non-static. --- Diffs of the changes: (+188 -160) Index: reopt/lib/LightWtProfiling/ValueAllocState.cpp diff -c /dev/null reopt/lib/LightWtProfiling/ValueAllocState.cpp:1.1 *** /dev/null Sun May 30 04:01:39 2004 --- reopt/lib/LightWtProfiling/ValueAllocState.cpp Sun May 30 04:01:28 2004 *************** *** 0 **** --- 1,183 ---- + //===- ValueAllocState.cpp - Access saved state of PhyRegAlloc ----*- C++ -*-=// + // + // 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. + // + //===----------------------------------------------------------------------===// + // + // Routines for accessing the global mapping between registers and LLVM Values + // created by the traditional SparcV9 graph-coloring register allocator. The + // main entry point for this code is the GetValueAllocState() global function. + // + //===----------------------------------------------------------------------===// + + #include "reopt/TraceToFunction.h" + #include "reopt/MappingInfo.h" + #include "llvm/Module.h" + #include "llvm/Argument.h" + #include "llvm/Support/InstIterator.h" + #include "Support/Debug.h" + #include "../../../../lib/Target/SparcV9/RegAlloc/AllocInfo.h" + #include "../../../../lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h" + + namespace llvm { + + /// Data structures describing the register allocator state + /// that gets saved by -save-ra-state. + /// + extern "C" { + struct OperandAllocState { + int Instruction; + int Operand; + unsigned AllocState; + int Placement; + }; + struct FunctionAllocState { + unsigned numTuples; + struct OperandAllocState tuples[0]; // variable length + }; + struct ModuleAllocState { + unsigned numFunctions; + struct FunctionAllocState *functions[0]; // variable length + }; + /// This global is filled in by PhyRegAlloc's -save-ra-state option + /// in LLC output: + /// + extern struct ModuleAllocState _llvm_regAllocState; + }; + + /// This global is filled in by PhyRegAlloc's -save-ra-state option in JIT + /// output: + /// + extern PhyRegAlloc::SavedStateMapTy ExportedFnAllocState; + + /// Returns the index of the given Instruction in the given Function. + /// + static unsigned getSavedStateIndexOfInstruction (const Function *F, + const Instruction *I) { + unsigned Key = 0; + for (const_inst_iterator II=inst_begin (F), IE=inst_end (F); II!=IE; ++II) { + if (&*II == I) + return Key; + ++Key; + } + // By this time we had better have found it, otherwise we are about to do bad + // things. + std::cerr << "ERROR: UnpackTraceFunction: Cannot find index of Value " + << F->getName() << "() in its parent Function using inst_iterator, " + << "in getSavedStateIndexOfInstruction()\n"; + abort (); + } + + /// Returns the index of the given Argument in the given Function's + /// argument list. + /// + static int getNumberOfFunctionArg (const Function *F, const Argument *Arg) + { + int ArgNum = 0; + for (Function::const_aiterator i = F->abegin (), e = F->aend (); i != e; ++i){ + if (Arg == &*i) return ArgNum; + ++ArgNum; + } + std::cerr << "ERROR: getNumberOfFunctionArg couldn't find arg\n"; + abort (); + } + + /// Returns the register number or stack position where V can be found in the + /// machine code for the function F, which it finds by searching the global + /// variable _llvm_regAllocState written out by PhyRegAlloc.cpp during a + /// previous invocation of llc. + /// + static AllocInfo getValueAllocStateFromModule (Function *F, Value *V) { + unsigned FI = getLLVMFunctionPositionInfo (F); + FunctionAllocState *FAllocState = _llvm_regAllocState.functions[FI]; + assert (FAllocState->numTuples > 0 + && "Reg. alloc state for function is empty"); + int InstructionKey = -1, OperandKey = -1; + if (Argument *A = dyn_cast (V)) { + // Find the alloc state of an argument. + OperandKey = getNumberOfFunctionArg (F, A); + } else { + // Figure out the indices (FI, VI, VO) that can be used to look up V, which + // is an operand of some instruction in F, in _llvm_regAllocState: + Instruction *Instr = cast (V); + InstructionKey = getSavedStateIndexOfInstruction (F, Instr); + } + // Reconstruct the AllocInfo for V by searching + // _llvm_regAllocState.functions[FI] for a tuple that starts with + // (InstructionKey, OperandKey, ...): + for (unsigned i = 0; i < FAllocState->numTuples; ++i) { + OperandAllocState &T = FAllocState->tuples[i]; + if (T.Instruction == InstructionKey && T.Operand == OperandKey) { + AllocInfo AI (T.Instruction, T.Operand, + (AllocInfo::AllocStateTy) T.AllocState, T.Placement); + DEBUG (std::cerr << "Alloc state saved in module for " << F->getName () + << ":" << V->getName () << " (key = " << InstructionKey << "," + << OperandKey << ") is " << AI << "\n"); + return AI; + } + } + // By this time we had better have found it, otherwise we are about to do bad + // things. + std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for " + << F->getName () << "()'s value " << *V + << " in getValueAllocStateFromModule()\n"; + abort (); + } + + /// Returns the register number or stack position where V can be found in the + /// machine code for the function F, which it finds by searching the global + /// variable ExportedFnAllocState exported by PhyRegAlloc.cpp. + /// + static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) { + // Get the saved PhyRegAlloc state for F out of ExportedFnAllocState: + std::vector &FState = ExportedFnAllocState[F]; + assert (FState.size () > 0 && "Reg. alloc state for function is empty"); + int InstructionKey = -1, OperandKey = -1; + if (Argument *A = dyn_cast (V)) { + // Find the alloc state of an argument. + OperandKey = getNumberOfFunctionArg (F, A); + } else { + if (! isa (V)) { + std::cerr + << "ERROR: Don't know how to look up alloc state for this Value:\n\t" + << *V << "\n"; + abort (); + } + // Figure out the indices (VI, VO) that can be used to look up V, + // which is some instruction producing a value in F, in FState: + Instruction *Instr = cast (V); + InstructionKey = getSavedStateIndexOfInstruction (F, Instr); + } + // Reconstruct the AllocInfo for V by searching + // FState for a tuple that starts with (InstructionKey, OperandKey, ...): + for (unsigned i = 0, s = FState.size (); i < s; ++i) { + AllocInfo &T = FState[i]; + if (T.Instruction == InstructionKey && T.Operand == OperandKey) { + DEBUG (std::cerr << "Alloc state saved in global for " << F->getName () + << ":" << V->getName () << " (key = " << InstructionKey << "," + << OperandKey << ") is " << T << "\n"); + return T; + } + } + // By this time we had better have found it, otherwise we are about to do bad + // things. + std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for " + << F->getName () << "()'s value " << *V + << " in getValueAllocStateFromGlobal()\n"; + abort (); + } + + /// GetValueAllocState - Returns a pair containing the + /// saved register allocator state for a value. + /// + std::pair + GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn) { + return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V), + getValueAllocStateFromGlobal (TF->TraceFn, + TF->getCorrespondingValue (V, preferLiveIn))); + } + + } // end namespace llvm Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.75 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.76 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.75 Sun May 30 03:47:11 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 30 04:01:27 2004 @@ -133,8 +133,9 @@ return 2047 + StaticStackSize + 176 + R * 8; } -static std::pair -getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true); +// defined in ValueAllocState.cpp: +extern std::pair +GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true); void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) { @@ -165,7 +166,7 @@ ++SI) { Value *V = *SI; std::pair > as = - std::make_pair (V, getValueAllocState (TF, V)); + std::make_pair (V, GetValueAllocState (TF, V)); AllocStates.insert (as); AllocInfo &Source = as.second.first, &Target = as.second.second; assert (Source.AllocState == AllocInfo::Allocated && @@ -227,162 +228,6 @@ } } -/// Data structures describing the register allocator state -/// that gets saved by -save-ra-state. -/// -extern "C" { - struct OperandAllocState { - int Instruction; - int Operand; - unsigned AllocState; - int Placement; - }; - struct FunctionAllocState { - unsigned numTuples; - struct OperandAllocState tuples[0]; // variable length - }; - struct ModuleAllocState { - unsigned numFunctions; - struct FunctionAllocState *functions[0]; // variable length - }; - /// This global is filled in by PhyRegAlloc's -save-ra-state option - /// in LLC output: - /// - extern struct ModuleAllocState _llvm_regAllocState; -}; - -/// This global is filled in by PhyRegAlloc's -save-ra-state option in JIT -/// output: -/// -extern PhyRegAlloc::SavedStateMapTy ExportedFnAllocState; - -/// Returns the index of the given Instruction in the given Function. -/// -static unsigned getSavedStateIndexOfInstruction (const Function *F, - const Instruction *I) { - unsigned Key = 0; - for (const_inst_iterator II=inst_begin (F), IE=inst_end (F); II!=IE; ++II) { - if (&*II == I) - return Key; - ++Key; - } - // By this time we had better have found it, otherwise we are about to do bad - // things. - std::cerr << "ERROR: UnpackTraceFunction: Cannot find index of Value " - << F->getName() << "() in its parent Function using inst_iterator, " - << "in getSavedStateIndexOfInstruction()\n"; - abort (); -} - -/// Returns the index of the given Argument in the given Function's -/// argument list. -/// -static int getNumberOfFunctionArg (const Function *F, const Argument *Arg) -{ - int ArgNum = 0; - for (Function::const_aiterator i = F->abegin (), e = F->aend (); i != e; ++i){ - if (Arg == &*i) return ArgNum; - ++ArgNum; - } - std::cerr << "ERROR: getNumberOfFunctionArg couldn't find arg\n"; - abort (); -} - -/// Returns the register number or stack position where V can be found in the -/// machine code for the function F, which it finds by searching the global -/// variable _llvm_regAllocState written out by PhyRegAlloc.cpp during a -/// previous invocation of llc. -/// -static AllocInfo getValueAllocStateFromModule (Function *F, Value *V) { - unsigned FI = getLLVMFunctionPositionInfo (F); - FunctionAllocState *FAllocState = _llvm_regAllocState.functions[FI]; - assert (FAllocState->numTuples > 0 - && "Reg. alloc state for function is empty"); - int InstructionKey = -1, OperandKey = -1; - if (Argument *A = dyn_cast (V)) { - // Find the alloc state of an argument. - OperandKey = getNumberOfFunctionArg (F, A); - } else { - // Figure out the indices (FI, VI, VO) that can be used to look up V, which - // is an operand of some instruction in F, in _llvm_regAllocState: - Instruction *Instr = cast (V); - InstructionKey = getSavedStateIndexOfInstruction (F, Instr); - } - // Reconstruct the AllocInfo for V by searching - // _llvm_regAllocState.functions[FI] for a tuple that starts with - // (InstructionKey, OperandKey, ...): - for (unsigned i = 0; i < FAllocState->numTuples; ++i) { - OperandAllocState &T = FAllocState->tuples[i]; - if (T.Instruction == InstructionKey && T.Operand == OperandKey) { - AllocInfo AI (T.Instruction, T.Operand, - (AllocInfo::AllocStateTy) T.AllocState, T.Placement); - DEBUG (std::cerr << "Alloc state saved in module for " << F->getName () - << ":" << V->getName () << " (key = " << InstructionKey << "," - << OperandKey << ") is " << AI << "\n"); - return AI; - } - } - // By this time we had better have found it, otherwise we are about to do bad - // things. - std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for " - << F->getName () << "()'s value " << *V - << " in getValueAllocStateFromModule()\n"; - abort (); -} - -/// Returns the register number or stack position where V can be found in the -/// machine code for the function F, which it finds by searching the global -/// variable ExportedFnAllocState exported by PhyRegAlloc.cpp. -/// -static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) { - // Get the saved PhyRegAlloc state for F out of ExportedFnAllocState: - std::vector &FState = ExportedFnAllocState[F]; - assert (FState.size () > 0 && "Reg. alloc state for function is empty"); - int InstructionKey = -1, OperandKey = -1; - if (Argument *A = dyn_cast (V)) { - // Find the alloc state of an argument. - OperandKey = getNumberOfFunctionArg (F, A); - } else { - if (! isa (V)) { - std::cerr - << "ERROR: Don't know how to look up alloc state for this Value:\n\t" - << *V << "\n"; - abort (); - } - // Figure out the indices (VI, VO) that can be used to look up V, - // which is some instruction producing a value in F, in FState: - Instruction *Instr = cast (V); - InstructionKey = getSavedStateIndexOfInstruction (F, Instr); - } - // Reconstruct the AllocInfo for V by searching - // FState for a tuple that starts with (InstructionKey, OperandKey, ...): - for (unsigned i = 0, s = FState.size (); i < s; ++i) { - AllocInfo &T = FState[i]; - if (T.Instruction == InstructionKey && T.Operand == OperandKey) { - DEBUG (std::cerr << "Alloc state saved in global for " << F->getName () - << ":" << V->getName () << " (key = " << InstructionKey << "," - << OperandKey << ") is " << T << "\n"); - return T; - } - } - // By this time we had better have found it, otherwise we are about to do bad - // things. - std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for " - << F->getName () << "()'s value " << *V - << " in getValueAllocStateFromGlobal()\n"; - abort (); -} - -/// getValueAllocState - Returns a pair containing the -/// saved register allocator state for a value. -/// -static std::pair -getValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn) { - return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V), - getValueAllocStateFromGlobal (TF->TraceFn, - TF->getCorrespondingValue (V, preferLiveIn))); -} - void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB) { const TargetRegInfo &TRI = TM->getRegInfo (); @@ -401,7 +246,7 @@ for (LiveVariableSet::iterator SI = So.begin (), SE = So.end (); SI != SE; ++SI) { Value *V = *SI; - std::pair ai = getValueAllocState (TF, V, false); + std::pair ai = GetValueAllocState (TF, V, false); // Source is traceFn's register, Target is matrixFn's register AllocInfo &Target = ai.first, &Source = ai.second; assert (Target.AllocState == AllocInfo::Allocated From gaeke at cs.uiuc.edu Sun May 30 04:21:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 04:21:01 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/UnpackTraceFunction.h Message-ID: <200405300919.EAA19633@kain.cs.uiuc.edu> Changes in directory reopt/include/reopt: UnpackTraceFunction.h updated: 1.2 -> 1.3 --- Log message: New, improved UnpackTraceFunction: now with fewer private methods! --- Diffs of the changes: (+0 -3) Index: reopt/include/reopt/UnpackTraceFunction.h diff -u reopt/include/reopt/UnpackTraceFunction.h:1.2 reopt/include/reopt/UnpackTraceFunction.h:1.3 --- reopt/include/reopt/UnpackTraceFunction.h:1.2 Thu May 27 16:32:10 2004 +++ reopt/include/reopt/UnpackTraceFunction.h Sun May 30 04:19:30 2004 @@ -46,9 +46,6 @@ unsigned getStaticStackSize (MachineFunction &MF); unsigned stackOffsetForReg (unsigned R); void findRegsToRestore (MachineFunction &MF); - void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target, - MachineBasicBlock &B, const Type *Ty); - void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B); const MachineInstr *containsReturnInstr (MachineBasicBlock &B); void rewriteProlog (MachineFunction &MF, MachineBasicBlock &MBB); void rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB); From gaeke at cs.uiuc.edu Sun May 30 14:37:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 14:37:03 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405301936.OAA05959@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.76 -> 1.77 --- Log message: Merge RegsToRestore into RegsToSave; rename findRegsToRestore to findRegsToSave. Hack AllocStates into a data member of the UnpackTraceFunction pass. Clear out both RegsToSave and AllocStates before filling them. Get rid of CopyInfo, which is now unused. --- Diffs of the changes: (+40 -63) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.76 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.77 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.76 Sun May 30 04:01:27 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 30 14:36:14 2004 @@ -29,26 +29,6 @@ namespace llvm { -/// Structure describing a single live variable copy. -/// -struct CopyInfo { - AllocInfo Src; - AllocInfo Targ; - MachineBasicBlock *Blk; - const Type *Ty; - CopyInfo (AllocInfo &_Src, AllocInfo &_Targ, MachineBasicBlock *_Blk, - const Type *_Ty) : Src (_Src), Targ (_Targ), Blk (_Blk), - Ty (_Ty) {} -}; - -/// Print method for CopyInfo objects. -/// -std::ostream &operator<< (std::ostream &OS, CopyInfo &CI) { - OS << "(Src " << CI.Src << " Targ " << CI.Targ << " Blk " << CI.Blk - << " Ty " << *CI.Ty << ")"; - return OS; -} - // Ripped off from SparcV9PrologEpilogInserter unsigned UnpackTraceFunction::getStaticStackSize (MachineFunction &MF) { const TargetFrameInfo& frameInfo = MF.getTarget().getFrameInfo(); @@ -78,16 +58,20 @@ return 0; } +// defined in ValueAllocState.cpp: +extern std::pair +GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true); + /// Fill in the set of registers used in this function, which is kept in -/// 'RegsToRestore' in the UnpackTraceFunction Pass object, and is used by +/// 'RegsToSave' in the UnpackTraceFunction Pass object, and is used by /// rewriteProlog() and rewriteEpilog(). Registers are /// represented by their 'unified register numbers' as used in the SPARCv9 /// back-end. /// -void -UnpackTraceFunction::findRegsToRestore (MachineFunction &MF) { +void UnpackTraceFunction::findRegsToSave (MachineFunction &MF) { const TargetRegInfo &TRI = TM->getRegInfo (); bool intCCRegSeen = false, floatCCRegSeen = false; + RegsToSave.clear (); for (MachineFunction::iterator fi = MF.begin (), fe = MF.end (); fi != fe; ++fi) for (MachineBasicBlock::iterator bi = fi->begin (), be = fi->end (); @@ -103,7 +87,7 @@ floatCCRegSeen = true; } else if (regNo != SparcV9::g0 && regNo != SparcV9::o6 /* sp */) { // Defs of certain registers are ignored - RegsToRestore.insert (regNo); + RegsToSave.insert (regNo); } } } @@ -113,18 +97,37 @@ // If the intcc regs are used, then we only put %ccr in the // set, not the individual intcc regs. if (floatCCRegSeen) - RegsToRestore.insert (SparcV9::fsr); + RegsToSave.insert (SparcV9::fsr); if (intCCRegSeen) - RegsToRestore.insert (SparcV9::ccr); + RegsToSave.insert (SparcV9::ccr); // Always put fp in the set because it is restored unconditionally. static const unsigned fp = SparcV9::i6; - RegsToRestore.insert (fp); + RegsToSave.insert (fp); + + // Get the saved register allocator state for all live-in variables. + // We are going to need to save live-in values which reside in registers + // on the stack, so we need to dig their register numbers out now. + LiveVariableSet &Si = TF->LiveInSet; + AllocStates.clear (); + for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; + ++SI) { + Value *V = *SI; + std::pair > as = + std::make_pair (V, GetValueAllocState (TF, V)); + AllocStates.insert (as); + AllocInfo &Source = as.second.first, &Target = as.second.second; + assert (Source.AllocState == AllocInfo::Allocated && + Target.AllocState == AllocInfo::Allocated && + "Only handle live-in values in registers for now!"); + RegsToSave.insert (Source.Placement); + RegsToSave.insert (Target.Placement); + } - DEBUG(std::cerr << "findRegsToRestore: RegsToRestore (size " - << RegsToRestore.size () << ") contains: ("; - for (std::set::iterator i = RegsToRestore.begin (), - e = RegsToRestore.end (); i != e; ++i) { std::cerr << *i << " "; } + DEBUG(std::cerr << "findRegsToSave: RegsToSave (size " + << RegsToSave.size () << ") contains: ("; + for (std::set::iterator i = RegsToSave.begin (), + e = RegsToSave.end (); i != e; ++i) { std::cerr << *i << " "; } std::cerr << " )\n"); } @@ -133,10 +136,6 @@ return 2047 + StaticStackSize + 176 + R * 8; } -// defined in ValueAllocState.cpp: -extern std::pair -GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true); - void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) { const TargetRegInfo &TRI = TM->getRegInfo (); @@ -156,29 +155,7 @@ BuildMI (&E, V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize) .addMReg (sp, MachineOperand::Def); - // 2. Get the saved register allocator state for all live-in variables. - // We are going to need to save live-in values which reside in registers - // on the stack, so we need to dig their register numbers out now. - RegsToSave = RegsToRestore; - LiveVariableSet &Si = TF->LiveInSet; - std::map > AllocStates; - for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; - ++SI) { - Value *V = *SI; - std::pair > as = - std::make_pair (V, GetValueAllocState (TF, V)); - AllocStates.insert (as); - AllocInfo &Source = as.second.first, &Target = as.second.second; - assert (Source.AllocState == AllocInfo::Allocated && - Target.AllocState == AllocInfo::Allocated && - "Only handle live-in values in registers for now!"); - DEBUG (std::cerr << "rewriteProlog: Need to save incoming live value " - << "in reg " << Source.Placement << " onto the stack\n"); - RegsToSave.insert (Source.Placement); - RegsToSave.insert (Target.Placement); - } - - // 3. Save used registers onto the stack. + // 2. Save used registers onto the stack. std::vector mvec; int RegType; for (std::set::iterator i = RegsToSave.begin (), @@ -202,12 +179,13 @@ E.push_back (*vi); } - // Caller's stack pointer becomes our frame pointer. + // 3. Caller's stack pointer becomes our frame pointer. BuildMI (&E, V9::ORr, 3).addMReg (g1).addZImm (0) .addMReg (fp, MachineOperand::Def); // 4. Insert a copy for each live-in variable to copy it from the stack // to the register that was allocated for it in the TraceFn. + LiveVariableSet &Si = TF->LiveInSet; for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; ++SI) { Value *V = *SI; @@ -332,10 +310,9 @@ DEBUG(std::cerr << "UnpackTraceFunction: unpacking " << MF.getFunction()->getName() << "()\n"); - // Initialize RegsToRestore with the set of registers we'll need to restore - // in the epilog. This is a subset of the registers we'll need to save on the - // stack in the prolog! - findRegsToRestore (MF); + // Initialize RegsToSave with the set of registers we'll need to save in the + // prolog and restore in the epilog. + findRegsToSave (MF); // Calculate the stack size. // The actual amount we will allocate is (Static Stack Frame Size + Slop + From gaeke at cs.uiuc.edu Sun May 30 14:38:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 14:38:02 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/UnpackTraceFunction.h Message-ID: <200405301936.OAA05956@kain.cs.uiuc.edu> Changes in directory reopt/include/reopt: UnpackTraceFunction.h updated: 1.3 -> 1.4 --- Log message: Merge RegsToRestore into RegsToSave; rename findRegsToRestore to findRegsToSave. Hack AllocStates into a data member of the UnpackTraceFunction pass. Clear out both RegsToSave and AllocStates before filling them. Get rid of CopyInfo, which is now unused. --- Diffs of the changes: (+4 -2) Index: reopt/include/reopt/UnpackTraceFunction.h diff -u reopt/include/reopt/UnpackTraceFunction.h:1.3 reopt/include/reopt/UnpackTraceFunction.h:1.4 --- reopt/include/reopt/UnpackTraceFunction.h:1.3 Sun May 30 04:19:30 2004 +++ reopt/include/reopt/UnpackTraceFunction.h Sun May 30 14:36:14 2004 @@ -7,6 +7,7 @@ #ifndef REOPT_UNPACKTRACEFUNCTION_H #define REOPT_UNPACKTRACEFUNCTION_H +#include "../../../../lib/Target/SparcV9/RegAlloc/AllocInfo.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "Support/DataTypes.h" #include @@ -40,12 +41,13 @@ /// Registers clobbered in the trace. Filled in by findRegsUsedInFunction (). /// - std::set RegsToRestore; std::set RegsToSave; + std::map > AllocStates; + unsigned getStaticStackSize (MachineFunction &MF); unsigned stackOffsetForReg (unsigned R); - void findRegsToRestore (MachineFunction &MF); + void findRegsToSave (MachineFunction &MF); const MachineInstr *containsReturnInstr (MachineBasicBlock &B); void rewriteProlog (MachineFunction &MF, MachineBasicBlock &MBB); void rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB); From gaeke at cs.uiuc.edu Sun May 30 14:41:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 14:41:02 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/UnpackTraceFunction.h Message-ID: <200405301940.OAA06306@kain.cs.uiuc.edu> Changes in directory reopt/include/reopt: UnpackTraceFunction.h updated: 1.4 -> 1.5 --- Log message: Constify stackOffsetForReg. --- Diffs of the changes: (+1 -1) Index: reopt/include/reopt/UnpackTraceFunction.h diff -u reopt/include/reopt/UnpackTraceFunction.h:1.4 reopt/include/reopt/UnpackTraceFunction.h:1.5 --- reopt/include/reopt/UnpackTraceFunction.h:1.4 Sun May 30 14:36:14 2004 +++ reopt/include/reopt/UnpackTraceFunction.h Sun May 30 14:39:49 2004 @@ -46,7 +46,7 @@ std::map > AllocStates; unsigned getStaticStackSize (MachineFunction &MF); - unsigned stackOffsetForReg (unsigned R); + unsigned stackOffsetForReg (const unsigned R) const; void findRegsToSave (MachineFunction &MF); const MachineInstr *containsReturnInstr (MachineBasicBlock &B); void rewriteProlog (MachineFunction &MF, MachineBasicBlock &MBB); From gaeke at cs.uiuc.edu Sun May 30 14:42:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 30 14:42:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405301940.OAA06305@kain.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.77 -> 1.78 --- Log message: Constify stackOffsetForReg. --- Diffs of the changes: (+1 -1) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.77 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.78 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.77 Sun May 30 14:36:14 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 30 14:39:49 2004 @@ -132,7 +132,7 @@ } -unsigned UnpackTraceFunction::stackOffsetForReg (unsigned R) { +unsigned UnpackTraceFunction::stackOffsetForReg (const unsigned R) const { return 2047 + StaticStackSize + 176 + R * 8; }