Should I use a hyphen to connect the following words? What is the general rule about that?
environment friendly --> environment-friendly
frontend --> front-end
backend --> back-end
speedup --> speed-up
Two words are joined by a hyphen when the collocation occurs in a non-standard context. For instance, we speak of the front end (space, no hyphen) of a car when this acts a noun phrase:
The front end of my Chrysler was dented.
My Chrysler was hit on the front end.
But when we use front end as an attributive, we hyphenate it:
My Chrysler suffered a front-end collision.
This lets the reader understand that we are speaking of a collision involving the front end rather than an "end collision" (whatever that might be - it has no obvious meaning) at the front.
In the same way, the phrasal verb is always speed up (space, no hyphen) when we use it as a verb:
Whenever we're behind schedule we speed up.
But if we want to use speed up as a noun, we hyphenate it.
We were behind schedule, so the foreman ordered a speed-up.
Two words are compounded - stuck together with neither a hyphen nor a space - when the collocation acquires a distinct sense, or the phrase becomes so common that it is felt to be a single word rather than two separate words. For instance, a dead line or dead-line was originally a line around a military prison which a prisoner could be shot for crossing; but when the phrase came to be applied metaphorically to the point by which a project must be completed, and became very common in the sense, it turned into the single word deadline.
Hyphens are used in English in a number of distinct ways. Here are a few:
They are used to form compound nouns. For example "the be-all and end-all" or "back-formation". Most often compound nouns are just written as one word with no hyphen. It's best to check a dictionary to see which form is preferred.
They are used to join a prefix to a proper noun. For example "non-Einsteinian". It's also very common that people use hyphens to join prefixes to nouns that aren't proper or compound, but that's usually just poor spelling. It's often best to check a dictionary. For example, it's "excommunicate", but "ex-parrot", and "ex officio".
They are sometimes stuck in the middle of a word to show where one syllable ends and the next begins. E.g. "co-occur".
They are used to show that an adjective modifies another modifier and the two together modify something else. For example a "long-running show" is a show that is long running, whereas a "long running show" is a running show that is long. A "white-collar worker" is a worker with a white collar, while a "white collar worker" is a collar worker who is white. A Norwegian-heavy-metal fan is a fan of Norwegian heavy metal; a Norwegian heavy-metal fan is a fan of heavy-metal who is Norwegian; and a Norwegian heavy metal fan is a metal fan that is heavy and that is from Norway.
In the last case the hyphen is only used when it is really needed, which is why I said "a show that is long running", rather than "a show that is long-running". There is nothing that "long" could modify other than "running". So no hyphen is used.
Most of your examples depend on context. You would say.
This is an environment-friendly detergent.
because an "environment friendly detergent" is some kind of friendly detergent. Note though that you say
This is an environmentally friendly detergent.
because "environmentally" is an adverb and adverbs can only modify adjectives (and verbs of course) but not nouns. There is no chance that you are saying the friendly detergent is environmentally.
You would write
the front end of a compiler
because "front" must modify "end". No need for a hyphen. But you should write
because you mean that the optimization is done in the front end of the compiler, not that the end optimization is front. You wouldn't write
for the simple reason that "frontend" is not a word. Someday it may be, but for now it's not. The great thing here is that you can check the dictionary. If it's not in the dictionary, it's likely not a word.
You could write that
the speed-up was 10 times
In this case you have a noun "speed-up" made up of two words. But you could also write
the speedup was 10 times
I checked two dictionaries. One preferred "speed-up", the other "speedup". On the other hand it is
If you are going to outrun that bear you had better speed up.
In this case "speed" is a verb and "up" is an adverb. Two words; no hyphen.
They are written as you wrote there.
Please note that these are compound nouns (except the first one which is noun+adjective and the last one which is a phrasal verb) and can be written without the hyphens as well as described in Oxforddictionaries.com
A compound noun is one consisting of two component nouns. In principle, such nouns can be written in one of three different ways. For instance - playgroup, play group, or play-group.