Commit Graph

6913 Commits

Author SHA1 Message Date
Chris Lattner
dd68469382 Implement folding of expressions like 'uint cast (int* getelementptr (int*
null, uint 1) to uint)' to a constant integer.  We can only do this with
primitive LLVM types, because other types have target-specific sizes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14837 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 01:16:59 +00:00
Chris Lattner
8bfc2f11a4 Now that we codegen the portable "sizeof" efficiently, we can use it for
malloc lowering.  This means that lowerallocations doesn't need targetdata
anymore.  yaay.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14835 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 01:08:08 +00:00
Chris Lattner
d2995df5b7 Improve codegen for the LLVM offsetof/sizeof "operator". Before we compiled
this LLVM function:

int %foo() {
        ret int cast (int** getelementptr (int** null, int 1) to int)
}

into:

foo:
        mov %EAX, 0
        lea %EAX, DWORD PTR [%EAX + 4]
        ret

now we compile it into:

foo:
        mov %EAX, 4
        ret

This sequence is frequently generated by the MSIL front-end, and soon the malloc lowering pass and
Java front-ends as well..

-Chris


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14834 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 00:58:53 +00:00
Chris Lattner
0f01bbc3b2 This is logically part of the last patch. Just more really horrible code
that is made unnecessary by it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14831 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 23:07:13 +00:00
Chris Lattner
a09000db75 ** Finally DeclareNewGlobalValue is dead!
* Simplify a lot of code because type's cannot be in function symbol tables
* Fix memory leaks in handling of redefined function prototypes
* Don't use SymbolTable directly for stuff that we can go through the Module
  for.
* Fix some minor bugs on obscure testcases like:
      test/Feature/globalredefinition.ll
* Do not create GlobalVariable objects for forward referenced Functions!
* When forward referencing a function in a constant expression, do not create
  a placeholder, add a bunch of references to it, then turn around and
  replaceAllUsesOfWith on it with a new global, deleting the placeholder.
  Instead, when we find the real definition of the global, just use the
  placeholder instead of creating a new object.

This substantially simplifies the asmwriter and should even speed it up on
cases heavy in constantexprs (like C++, Java, MSIL)...


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14830 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 23:03:46 +00:00
Chris Lattner
8a32784ad4 * Fairly substantial change. Instead of creating new globalvariables, then
replaceAllUsesWith'ing any forward references, just use the forward
  reference if it exists.

This introduces GetForwardRefForGlobal, which will eventually completely
replace the horrible DeclareNewGlobalValue function.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14828 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 21:44:00 +00:00
Chris Lattner
cb9d6a8f73 Fold setValueNameMergingDuplicates into ParseGlobalVariable, allowing us
to substantially simplify the result.  In particular, we no longer create
GlobalVariables and then immediately destroy them when they are duplciate
definitions.

The real point of this patch though is that it gets us closer to the
DeclareNewGlobalValue calls...


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14827 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 20:42:57 +00:00
Brian Gaeke
fe2102b61d Actually set the endian/pointersize flags on the module being read in!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14826 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 20:33:13 +00:00
Chris Lattner
f70770abd5 Simplify logic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14825 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 20:27:12 +00:00
Chris Lattner
d9ce6adfcc Fix a regression from last night. Apparently the CFE is broken and outputs
functions multiple times, expecting them to be merged.  This should be fixed
in the CFE, then here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14823 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 19:33:47 +00:00
Misha Brukman
5f8cce1348 Make sure MTSPR instruction is inserted into the BasicBlock
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14822 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 18:26:31 +00:00
Chris Lattner
33af23d902 Implement new helper methods for creating two-index GEP instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14821 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 18:14:33 +00:00
Misha Brukman
32caa8de62 Don't define the same register twice when loading a ConstantPointerRef to a reg
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14819 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 17:57:04 +00:00
Misha Brukman
8d442c2dc4 * Fix multiplication by powers of two and otherwise
* Clarify variable name (StoreInst SI instead of LI)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14818 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 15:29:51 +00:00
Chris Lattner
d88998db01 Pull out code shared between GV forward-decl and definition processing.
This gives us only a single call site for setValueNameMergingDuplicates.
The next stage is the start merging them together.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14811 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 08:23:52 +00:00
Chris Lattner
66028f208e Simplify code. Do not allow functions to be redefined more than once.
Since the stupid '%X = const int 4' thing is gone, we can now simplify
setValueNameMergingDuplicates a bit more.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14810 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 07:12:48 +00:00
Chris Lattner
e002694ce2 Remove a gross and crufty "feature" that was never documented and doesn't work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14809 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 06:44:56 +00:00
Chris Lattner
8642763f11 Finegrainify namespacification
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14808 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 06:39:48 +00:00
Chris Lattner
2e2ed2995a Revamp handling of labels. In particular, if we create a forward reference
for a basic block, use it when the block is defined instead of deleting it
and creating a new one.  Also, only create at most ONE forward reference
for any block, instead of one for each forward reference.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14807 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 06:28:35 +00:00
Brian Gaeke
d94b6d3fa5 Add Machine-CFG edges to SparcV9 MachineBasicBlocks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14806 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 05:40:50 +00:00
Chris Lattner
64116f980e Split the basic block handling case out of getVal into getBBVal.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14805 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-14 01:33:11 +00:00
Chris Lattner
144d9baf5e Make Argument::print more resilient to non-verifiable IR
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14801 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 23:14:34 +00:00
Chris Lattner
b4091e548e Catch aggregates passed by value sooner rather than later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14800 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 20:09:51 +00:00
Misha Brukman
a596f8c3aa * Specify that FP arith options have 3 operands
* Correctly load FP constants from the constant pool, should be refactored


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14799 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 15:35:45 +00:00
Chris Lattner
65cd4b0fa7 Fine-grainify namespacification, prune #include
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14792 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 08:42:12 +00:00
Chris Lattner
22ae232d98 Fix typeo and refactor bb productions to make it possible for us to reuse any
forward reference blocks if they have been created (instead of creating a new
block, replaceAllUsesOfWith, then nuking the placeholder).   This is not yet
implemented.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14791 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 08:39:15 +00:00
Chris Lattner
bc721ed100 Eliminate some mega-cruft here. There is no reason to DERIVE FROM IR CLASSES
just to keep track of some per-object state!  Gaah!  Whoever wrote this stuff...
oh wait, that would be me.  Never mind.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14790 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 08:28:21 +00:00
Chris Lattner
c9aea52ae4 Inline the now trivial setValueNameInternal function into both callers
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14789 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 08:12:39 +00:00
Chris Lattner
8c89a0a1fd Now that basic blocks are eagerly inserted into the Function, we can use
the funciton symbol table to check for conflicts instead of having to
keep a shadow named LocalSymtab.  Totally eliminate LocalSymtab.  Verified
that this did not cause a regression on the testcase for PR107.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14788 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 08:10:10 +00:00
Chris Lattner
8ab406d5bd A couple of substantial cleanup fixes:
1. Split setValueName into two separate functions, one that is only used
     at function scope and doesn't have to deal with duplicates, and one
     that can be used either at global or function scope but that does deal
     with conflicts.  Conflicts were only in there because of the crappy old
     CFE and probably should be entirely eliminated.
  2. Insert BasicBlock's into the parent functions when they are created
     instead of when they are complete.  This effects name lookup (for the
     better), which will be exploited in the next patch.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14787 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 07:59:27 +00:00
Brian Gaeke
0859e52582 Fix warning on SparcV9, where sizeof (int) != sizeof (void *).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14786 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 07:37:43 +00:00
Chris Lattner
38ab6bff5d Replace a bunch of complex ConstantPointerRef referring code with simple
code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14785 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 06:58:07 +00:00
Chris Lattner
b89e071aea Factor some code to handle "load (constantexpr cast foo)" just like
"load (cast foo)".  This allows us to compile C++ code like this:

class Bclass {
  public: virtual int operator()() { return 666; }
};

class Dclass: public Bclass {
  public: virtual int operator()() { return 667; }
} ;

int main(int argc, char** argv) {
  Dclass x;
  return x();
}

Into this:

int %main(int %argc, sbyte** %argv) {
entry:
        call void %__main( )
        ret int 667
}

Instead of this:

int %main(int %argc, sbyte** %argv) {
entry:
        %x = alloca "struct.std::bad_typeid"            ; <"struct.std::bad_typeid"*> [#uses=3]
        call void %__main( )
        %tmp.1.i.i = getelementptr "struct.std::bad_typeid"* %x, uint 0, uint 0, uint 0         ; <int (...)***> [#uses=1]
        store int (...)** getelementptr ([3 x int (...)*]*  %vtable for Bclass, int 0, long 2), int (...)*** %tmp.1.i.i
        %tmp.3.i = getelementptr "struct.std::bad_typeid"* %x, int 0, uint 0, uint 0            ; <int (...)***> [#uses=1]
        store int (...)** getelementptr ([3 x int (...)*]*  %vtable for Dclass, int 0, long 2), int (...)*** %tmp.3.i
        %tmp.5 = load int ("struct.std::bad_typeid"*)** cast (int (...)** getelementptr ([3 x int (...)*]*  %vtable for Dclass, int 0, long 2) to int
("struct.std::bad_typeid"*)**)          ; <int ("struct.std::bad_typeid"*)*> [#uses=1]
        %tmp.6 = call int %tmp.5( "struct.std::bad_typeid"* %x )                ; <int> [#uses=1]
	ret int %tmp.6
        ret int 0
}

In order words, we now resolve the virtual function call.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14783 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 01:49:43 +00:00
Misha Brukman
d9aa7836e2 Correctly load FP constants out of the constant pool.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14782 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-12 23:49:47 +00:00
Misha Brukman
f028f82a58 Apple's MacOS X is another OS which does not provide alloca() via <alloca.h>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14781 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-12 23:37:18 +00:00
Misha Brukman
01eca8d2c2 Implement getModuleMatchQuality and getJITMatchQuality() for PowerPC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14780 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-12 23:36:12 +00:00
Chris Lattner
b370c7a41a implement new helper method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14776 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-12 20:35:11 +00:00
Chris Lattner
aec6dd5bbc Fix unused var warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14775 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-12 20:29:52 +00:00
Chris Lattner
88e2b780cb Fix a really nasty logic error that VC noticed.
Reid, this might matter to you :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14774 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-12 20:27:31 +00:00
Chris Lattner
1c2fe31483 Implement new method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14767 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-12 01:17:34 +00:00
Reid Spencer
46b002cd9b Various cleanups:
- Remove tabs
- Standardize use of space around ( and ).
- Consolidate the ConstantPlaceHolder class
- Rename two methods to be more meaningful (ParseType, ParseTypes)
- Correct indentation of blocks
- Add documentation
- Convert input dependent asserts to error(...) so it throws instead.
Provide placeholder implementations of read_float and read_double that
still read in platform-specific endianess. When I figure out how to do
this without knowing the endianess of the platform, it will get implemented
correctly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14765 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 17:28:43 +00:00
Reid Spencer
66906518ed - Rename two methods to give them more meaning
- Add read_float and read_double in preparation for a correct
  implementation of bytecode floating point support.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14764 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 17:24:05 +00:00
Reid Spencer
1d9349a783 Remove tabs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14763 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 17:22:51 +00:00
Reid Spencer
87bc418334 Prepare the writer for a non-broken implementation of writing floating
point values. This will be fixed when I figure out how to do it correctly
without depending on knowing the endianess of a platform.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14762 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 17:22:07 +00:00
Chris Lattner
beff74f821 The cleanup is done. Update comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14761 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 08:24:02 +00:00
Chris Lattner
5f90cb8c98 Make add constantexprs work with all types, fixing the regressions from last night
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14760 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 08:01:11 +00:00
Chris Lattner
7c38def077 Implement TargetRegistrationListener
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14759 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 06:03:21 +00:00
Chris Lattner
68905bb6fc Delete the allocate*TargetMachine function, which is now dead.
The shared command line options are now in a header that makes sense.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14757 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 04:17:58 +00:00
Chris Lattner
0cf0c37469 Delete the allocate*TargetMachine function, which is now dead .
The shared command line options are now in a header that makes sense.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14756 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 04:17:10 +00:00
Chris Lattner
4e547ec8bf Delete the allocate*TargetMachine function, which is now dead .
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14755 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-11 04:16:31 +00:00